fix: keep ajv codegen out of flow-schema barrel - #26
Merged
Conversation
The package barrel ran `ajv.compile(schema)` at module top level, so any import of `@wavekat/flow-schema` pulled Ajv's runtime code generation into the consumer's module graph. Runtimes that disallow code-generation-from-strings — notably the Cloudflare Workers isolate the platform API runs on — threw `EvalError: Code generation from strings disallowed` at import time and failed to boot, even though the Worker only uses the hand-written `checkFlow`/`stampIdentity` surface and never calls `validateStructure`. Move `validateStructure` (and its Ajv import/compile) into a new `src/structure.ts`, exposed via a `./structure` subpath export. The main entry is now Ajv-free and safe to bundle on the edge; Node-side consumers opt into structural validation explicitly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
@wavekat/flow-schemaranajv.compile(schema)at the top level of the package barrel (src/index.ts). Ajv builds a validator by generating JavaScript source andnew Function-ing it, so importing the barrel pulled runtime code generation into the consumer's module graph.The platform API runs on the Cloudflare Workers isolate, which disallows code-generation-from-strings. Since the compile happened at import time, the Worker crashed at boot with:
— even though the Worker only uses the hand-written
checkFlow/stampIdentitysurface and never callsvalidateStructure. It was paying for a code path it doesn't use, just because it shared the barrel.Fix
Move
validateStructure+StructuralResult+ the Ajv import/compile into a newsrc/structure.ts, exposed via a./structuresubpath export. The main entry (.) is now Ajv-free and safe to bundle on the edge; Node-side consumers opt into structural validation explicitly withimport { validateStructure } from '@wavekat/flow-schema/structure'.Verification
pnpm typecheckclean;pnpm testgreen (79 passed).--disallow-code-generation-from-strings(the same restriction the Workers isolate enforces):./dist/index.js) → imports cleanly;checkFlow/stampIdentity/flowV1Schemapresent ✓./structure→ still throwsEvalError✓ (confirms the Ajv codegen moved fully off the Worker path and is only paid when opted into)Notes
./structureis Node-only; not safe to import from a Workers/edge bundle. Documented in the module header.fix:commit cuts0.0.4, which the platform then bumps to.🤖 Generated with Claude Code