Commit Graph
11 Commits
Author SHA1 Message Date
chrnx 3b1eceecb9 build: publish a real build to npm, and the source to JSR
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 10s
CI / build (pull_request) Successful in 18s
CI / runtimes (deno) (pull_request) Successful in 11s
CI / runtimes (edge) (pull_request) Successful in 9s
Every package exported `./src/index.ts` and had no build at all, which made the
npm half of the dual publish unusable. Measured against a staging registry with
`@green-tea/metrics` installed into a clean project: Node threw
ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING, `--experimental-strip-types` threw
the same error because Node refuses to strip types under `node_modules`
unconditionally, and Deno-via-npm threw it too. Only Bun could import it. The
release pipeline would have published that to both registries at once.

JSR needs no help — it transpiles on publish and hands Node an ESM package with
generated declarations — so `deno.json` keeps exporting `src/`. The build exists
for npm alone, as CJS and ESM: core is `"type": "commonjs"` and publishes both,
so a CJS application has to be able to `require()` a plugin.

Core stays external in the declarations. tsup bundles devDependencies by
default, and convention rule 8 puts core there, so without that line every
plugin would have shipped a frozen private copy of a contract core owns.

Verified by packing all three and consuming them from outside the workspace:
`require()` and `import` both resolve under Node, Bun and Deno, and `tsc`
type-checks clean under `node16` and `bundler` resolution.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-19 11:58:54 -05:00
chrnx de0081ddae feat(metrics): publish the collector and a transformer to serve it
CI / dco (pull_request) Successful in 5s
CI / build (pull_request) Failing after 8s
CI / runtimes (bun) (pull_request) Failing after 6s
CI / runtimes (deno) (pull_request) Failing after 7s
CI / runtimes (edge) (pull_request) Failing after 6s
The transformer is exported instead of a route: the path, the auth and whether
the endpoint exists are the application's decisions, and a plugin that mounted
/metrics itself would be taking them.

No onShutdown — a bus subscription is an entry in a set and keeps nothing alive,
which is what rule 7 asks about. Closes green-tea#68.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-18 13:27:08 -05:00
chrnx 5a74cad793 feat(metrics): count request:end, and only request:end
A failed request emits three lifecycle events. request:end is the terminal and
universal one, so it is the request counter; request:failed is additional and
gets its own series. Counting both as requests is the double count issue #64
was filed for.

Labels come from route, which the route table bounds, never from name, which
carries the arriving path and is bounded by nothing — issue #65.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-18 13:26:32 -05:00
chrnx 22e77ee452 feat(metrics): declare the package and what it refuses to label
The README carries the cardinality rule up front: label on route, which the
route table bounds, never on name, which nothing bounds. That is the mistake
issue #65 was filed for and the one a collector makes by default.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-18 13:25:48 -05:00
chrnx f72c391646 test(rate-limit): measure that close() lets the process exit
Rule 7 says nothing a plugin opens outlives close(), and the only portable probe
is a process: a leaked interval keeps all three runtimes alive, a cleared one
lets each exit in well under a second.

Verified the test fails with onShutdown removed — it reports the process still
alive after 2s — because a leak test that passes while leaking is worth nothing.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-18 13:25:17 -05:00
chrnx 8ac46fed61 feat(rate-limit): publish the limiter as a named plugin
Extracted from patitas-peludas onto the object contract. The node now takes the
name it provides — the original registered 'rate-limit' while providing
'rateLimit', so two instances shared a node name and rule 2 could not hold.

onShutdown closes the store this plugin built. One passed in owns its own
lifecycle, and is closed only if it offers a close().

Every test that builds an app closes it, through a helper that says why: the
sweep timer is deliberately not unref'ed, so an app left open keeps the test
runner alive after its assertions have passed. That is the same behaviour the
exit test measures, so these exercise the shutdown path in passing.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-18 13:22:45 -05:00
chrnx 14ed9c38be feat(rate-limit): carry the error brand instead of extending core
The original extended core's HttpError, which is a value import and makes the
published plugin need core at run time. The brand is a registry-wide symbol, so
core renders the 429 without this package depending on it, and it survives two
copies of core in one tree where instanceof would not.

The fields asserted here are exactly the ones HttpErrorLike declares. That core
really renders them is proven end to end in the limiter's own tests, which read
a 429 and its Retry-After back out of app.fetch.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-18 13:18:49 -05:00
chrnx 66afb59103 feat(rate-limit): sweep expired windows instead of walking the map
hit() called evictExpired on every new or expired key, which is a full walk of
the map — O(N^2) over N callers, and a client rotating addresses drives it on
purpose. A timer armed on the first hit does the same work off the hot path.

It is not unref'ed, deliberately: the timer holds the process open so that
failing to release it fails the exit test rather than leaking quietly.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-18 13:18:26 -05:00
chrnx b15ce29315 feat(rate-limit): declare the package and the runtimes it claims
No workerd: the default store counts per isolate, and an edge deployment has
many, so the limit it would enforce is not the one configured. The README says
so rather than leaving someone to find out.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-18 13:17:45 -05:00
chrnx 1c0b6bde91 feat(jwt): load signing keys at boot as a named plugin
Extracted from patitas-peludas onto the object plugin contract. Core is a type
import only, so installing the plugin never drags in a second core or a version
warning; a bad key still fails boot, which the contract tests now pin.

The extraction moves from jose 5 to jose 6, and that is not a version bump: jose
6 refuses a private CryptoKey in jwtVerify, where jose 5 accepted one and derived
the public half itself. The original keeps a single key per signer and verifies
with the key it signed with, which works on 5 and throws
"CryptoKey instances must be of type public" on 6 — for every asymmetric
algorithm, so ES*, RS*, PS* and EdDSA alike. Symmetric keys are unaffected, which
is exactly why one HS256 test would have shipped it.

importJWKKey now imports the key twice for an asymmetric pair: as given, to sign
with, and with the private fields stripped, to verify with. A symmetric key has
no public half, so it keeps one secret for both. The round-trip is covered per
algorithm family rather than once, because one algorithm is not coverage — it is
the gap the defect lived in.

The get() helper in the contract tests is generic in its body: Response.json()
is typed Promise<unknown>, so reaching into the payload did not typecheck.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-17 23:11:55 -05:00
chrnx 42a2f490e8 test: check each package against the plugin convention
Rules 8 and 9 are the two a reviewer cannot see from a diff: where core sits in
package.json, and whether engines, the README table and JSR still agree. A
static test makes a drift fail the build instead of reaching a user.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-17 23:02:12 -05:00