Skip to content

Convert the codebase to TypeScript with stripped dist output - #37

Merged
jimhoyd merged 26 commits into
mainfrom
claude/happy-lamport-f6e6ba
Sep 17, 2026
Merged

jimhoyd merged 26 commits into
mainfrom
claude/happy-lamport-f6e6ba

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Problem and change

The runtime, scripts, tests and benchmarks were plain JavaScript with no type declarations, which embedders had flagged. With no external users yet this is the cheapest moment to convert the whole codebase, so this does.

Shape of the conversion (docs/TYPESCRIPT.md):

  • Source is TypeScript under src/, scripts/, test/ and benchmarks/, strict (erasableSyntaxOnly, verbatimModuleSyntax, noUncheckedIndexedAccess, exactOptionalPropertyTypes, NodeNext), zero any, casts only at trust boundaries with a comment each.
  • Development and tests run .ts directly through Node's type stripping (npm run dev, npm test with the development export condition). Contributors need Node 22.18+; consumers' engines are unchanged.
  • The package and container ship dist/, emitted by npm run build with Node's stripTypeScriptTypes: types become whitespace, so each dist/x.js is line-for-line the source with .ts specifiers rewritten. bin, exports (with types, development and default conditions) and files point at dist. dist/ is never committed.
  • Declarations ship in dist/types for every public export: urlcode, aws, cloudflare, prerender, vercel, plugins, policies, observability, compliance. The package smoke test installs the tarball and type-checks a consumer against them.
  • Provenance: the release container runs the build; the candidate manifest records the builder Node, TypeScript version and per-file dist hashes; a build-fidelity CI job builds twice and diffs. docs/RELEASE-SECURITY.md describes it.
  • The Cloudflare Worker closure stays free of node: imports, enforced by the check script and an eslint rule.
  • User-facing JavaScript (examples, starters, bundled agent list data) stays JavaScript.

Performance (docs/PERFORMANCE.md, measured on Node 22.22.2, baseline 7ae390e vs dist/cli.js): cold start 798.6 vs 797.8 ms (validate), 795.1 vs 770.9 ms (routes), 331.0 vs 328.4 ms (--help); routing benchmark throughput, RSS, p50 and p95 within noise. Running .ts directly (development only) costs about 24% on cold start and 40 MiB RSS, which is why it is never shipped.

Behavior changes found by the type checker, all minimal and called out: the Lambda adapter would have declared isBase64Encoded on a string body without encoding it (unreachable with current handlers); a redirect placeholder with no matching path input now yields an empty segment instead of the string undefined (unreachable through compiled routes, covered by a direct-call test). A handful of unreachable failure paths now raise a typed assertion instead of a TypeError with the same outward status.

Docs: contributor guides, install, AGENTS, release security, and the plugin, observability, compliance, policies, dynamic links and Cloudflare guides now name the shipped types with TypeScript examples that were compiled against dist/types; every source path named in the docs was swept and exists.

Includes the merge of main through #35 (v0.2.0 and the publish path fix).

Verification

  • npm run verify (lint, full tsc, syntax/JSON and Worker-closure check, generated reference, tests): 242 pass, 0 fail, 29 skipped (SQLite WAL on this Node, as before)
  • npm run test:package (builds, packs, installs, runs starter, cookbook, scaffold, prerender example and the new declaration consumer check): passed
  • cookbook: 35/35; audit ready at 25 routes
  • npm run build twice and diff -r: identical
  • Every CI and release workflow invocation was re-run locally with its arguments; sync-agent-lists --check reports lists up to date
  • Not measured: container time-to-ready (no Docker here); not run: real deployments

Compatibility and security

  • Consumers: bin and exports resolve to dist/; the urlcode command and every subpath keep their names. Type declarations require @types/node on the consumer side (documented).

  • Contributors: Node 22.18+, npm run build before packaging, npm run typecheck is part of verify.

  • Release pipeline: npm run build precedes verify and pack in candidate and release workflows; manifest gains build fields. Coordinate with the release owner before merging: v0.2.0 shipped from the JavaScript layout and this changes what npm pack produces.

  • No change to the guest sandbox, capabilities or the YAML contract.

  • Changes match the documented portable contract; docs/examples are updated where needed.

  • Relevant tests and package checks pass, or limitations are explained above.

  • No credentials, customer data or private project material are included.

  • Runtime/starter changes remain aligned where applicable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E


Generated by Claude Code

Add tsconfig.json (strict, erasableSyntaxOnly, verbatimModuleSyntax,
noUncheckedIndexedAccess, exactOptionalPropertyTypes, NodeNext),
tsconfig.build.json for declaration emit, scripts/build.ts (Node's own
type stripping into dist/), typescript-eslint, devEngines for Node
>=22.18 and the build/typecheck scripts. Tests now run with the
development export condition. Nothing is renamed yet.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
Mechanical pass: every module under src/, scripts/, test/ and
benchmarks/ becomes .ts with .ts relative specifiers, so development
and tests run the sources directly through Node's type stripping. No
type annotations yet; tsc is expected to be red until the modules are
typed.

The package, container and CI run the built dist/ instead: bin, exports
and files point at dist (with a development condition back to src for
the in-repo prerender example), the Dockerfile builds in a first stage
from the same pinned digest, CI builds before exercising the CLI and
proves the emit is deterministic, the release manifest records the
Node and TypeScript versions and per-file hashes of dist, and
scripts/check.ts verifies the Worker closure stays free of node:
imports. Docs name src/cli.ts for clone usage and dist/cli.js for
installed usage.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
errors, header-validation, client-address, match, http-response,
http-policy, policies/security, policies/agents, agent-lists,
sqlite-version, logging, link-records, link-events and guest-api now
carry strict types with no `any`: unknown plus narrowing at the YAML
and request boundaries, and a shared vocabulary (MatchableRoute,
CompiledParameter, RequestContext, HeadersLike, HandlerResult,
HeaderPair, HttpRoute) for the modules above them to widen. Runtime
behaviour is unchanged; the Worker-shipped modules keep a structural
ResponseWriter instead of importing node:http.

tsconfig.frontier.json lists the typed closure and `npm run
typecheck:frontier` gates it in verify until the whole tree
type-checks. test/match.test.ts and test/client-address.test.ts cover
the two modules that had no closed-graph tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
Define the worker protocols as discriminated unions beside their parents
(FunctionWorkerMessage/FunctionWorkerRequest in functions.ts,
LinkStoreCommand/LinkStoreReply in link-store.ts) and import them as types
from the workers. Only trust-boundary casts remain: workerData, guest JSON
and SQLite rows.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
Adds src/types.ts as the home of the shared document, compiled-route and
policy-contract types; types config.ts (ConfigWorkerResult as the worker
protocol) and the cache, compression and throttle policies.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
compileRoutes now produces CompiledRoute (types.ts); a redirect declared
with query.pass: false drops the key so match.ts's RedirectSpec holds.
The registry is typed per policy and erased to PolicyModule where the
compiled chain is built. Also restores the \uXXXX escapes in cache.ts
that the previous commit had written as literal control characters.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
Adds src/vendor.d.ts, an ambient declaration for mime-types (the one
dependency that ships no types); content-disposition carries its own.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
ManagementPrincipal/ManagementAuthorizer name what the policy file yields;
the management API and links CLI take typed stores and parsed flags. The
function pool reuses FunctionSources from function-sources.ts and the link
store's create() takes an unvalidated code, which the worker validates.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
Runtime/RuntimeOptions/RuntimeRequest/RequestTrace and Server/ServerOptions
are the public embedding surface; readiness names the plan, cases and
reports; the Worker artifact (Artifact/ArtifactRoute) is declared in
cloudflare.ts so the build imports it type-only and the Worker closure stays
free of node: modules. index.ts re-exports the public types for dist/types.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
Adds PolicyInventory, TestPlan and PlanInventoryEntry to types.ts (the
plan readiness.ts builds, declared structurally), types each compliance
rule as a ProjectRule or RouteRule, and moves the mime-types declaration
to types/mime-types.d.ts, referenced from assets.ts: scripts/check.ts
runs node --check over every .ts under src, which rejects ambient
declare statements.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
scripts/ and benchmarks/ now pass strict tsc with no `any`: JSON, npm and
node:sqlite results are cast once at the boundary and narrowed from there,
and the sync script declares the list, entry and source shapes it writes.
Behaviour is unchanged; each script still runs the way CI, the release
pipeline and the package smoke test invoke it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
Makes admission, assets, aws, cli, cloudflare, compliance, http-policy,
http, install, links, logging, middleware, monitoring and observability
strict-clean: typed helper results, narrowed JSON read back from the CLI
and stores, checked indexed reads, and typed event collectors. No test
name, assertion or skip changes; config and load were already clean.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
verify now runs tsc over the whole tree instead of the frontier subset,
the frontier tsconfig is gone, the build fails on any declaration-emit
error, CI runs the typed links suite under the development condition,
and the package smoke test type-checks a consumer that imports every
public subpath against the packed tarball's declarations.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
…ened

- LinkEvent.code admits null, which is what the server records for an
  invalid code; the cast in server.ts is gone.
- Reply.body is Uint8Array on every host; the two readers decode through
  Buffer.from, and the Worker hands its route to the HTTP policy directly.
- PluginRuntime.testPlan() returns TestPlan; PolicyLayer admits partial
  per-policy configs, which is what profiles and route layers hold.
- cache.onError matches PolicyModule.onError; createJsonLogger declares
  the sink members it uses; LinkApiOptions.log is a LogFn.
- Compliance builtinProfiles is keyed by the three profile names.
- The guest payload types live in guest-api.ts next to the bootstrap.
- examples/prerender ships a declaration file, so the test imports the
  recipe without a suppression.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
Contributor docs describe the type gate, the source-run developer loop
and the uncommitted dist; install docs say what the package and the
container run; the contract docs (plugins, observability, compliance,
policies, dynamic links) name their exported types with a TypeScript
example each; the Cloudflare page records the Worker closure check;
release security records the manifest hashes and the fidelity job.
A new docs/TYPESCRIPT.md covers the declarations, export conditions,
build, fidelity guarantee and the no-runtime-cost measurement, which
PERFORMANCE.md and ROADMAP.md also record. Stale test/*.test.js paths
in the docs now point at the .ts files. The two type re-exports the
docs name (plugin hook types, link event types) are added.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
The release re-uploads assets over an existing release, which is safe only
if a re-run packs the byte-identical tarball; with a build step that now
holds per builder Node version, which the release container pins.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
A fresh checkout has no dist/, and the packed tarball ships nothing else,
so the install test built its expectation from whatever an earlier
command had left behind. CI found it on a clean runner.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
@jimhoyd
jimhoyd merged commit 1637686 into main Sep 17, 2026
26 checks passed
@jimhoyd
jimhoyd deleted the claude/happy-lamport-f6e6ba branch September 17, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants