Repository navigation
Convert the codebase to TypeScript with stripped dist output - #37
Merged
Merged
Conversation
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
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
…r tests 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
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
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
…hrottle tests 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
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
4 tasks done
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):src/,scripts/,test/andbenchmarks/, strict (erasableSyntaxOnly,verbatimModuleSyntax,noUncheckedIndexedAccess,exactOptionalPropertyTypes, NodeNext), zeroany, casts only at trust boundaries with a comment each..tsdirectly through Node's type stripping (npm run dev,npm testwith thedevelopmentexport condition). Contributors need Node 22.18+; consumers'enginesare unchanged.dist/, emitted bynpm run buildwith Node'sstripTypeScriptTypes: types become whitespace, so eachdist/x.jsis line-for-line the source with.tsspecifiers rewritten.bin,exports(withtypes,developmentanddefaultconditions) andfilespoint atdist.dist/is never committed.dist/typesfor 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.disthashes; abuild-fidelityCI job builds twice and diffs.docs/RELEASE-SECURITY.mddescribes it.node:imports, enforced by the check script and an eslint rule.Performance (
docs/PERFORMANCE.md, measured on Node 22.22.2, baseline7ae390evsdist/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.tsdirectly (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
isBase64Encodedon 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 stringundefined(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, fulltsc, 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): passednpm run buildtwice anddiff -r: identicalsync-agent-lists --checkreports lists up to dateCompatibility and security
Consumers:
binandexportsresolve todist/; theurlcodecommand and every subpath keep their names. Type declarations require@types/nodeon the consumer side (documented).Contributors: Node 22.18+,
npm run buildbefore packaging,npm run typecheckis part ofverify.Release pipeline:
npm run buildprecedes 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 whatnpm packproduces.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