{"_id":"@ahmedrowaihi/fn-schema-transformer","_rev":"3-5edb3d97a14c68c523cedd38f830e9ae","name":"@ahmedrowaihi/fn-schema-transformer","dist-tags":{"latest":"0.2.1"},"versions":{"0.2.0":{"name":"@ahmedrowaihi/fn-schema-transformer","version":"0.2.0","keywords":["json-schema","function-signature","typescript-transformer","compile-time"],"author":{"name":"Ahmed Rowaihi","email":"ahmedrowaihi@gmail.com"},"license":"MIT","_id":"@ahmedrowaihi/fn-schema-transformer@0.2.0","maintainers":[{"name":"ahmedrowaihi","email":"ahmedrowaihi1@gmail.com"}],"homepage":"https://github.com/ahmedrowaihi/contract-kit/tree/main/packages/fn-schema/transformer","bugs":{"url":"https://github.com/ahmedrowaihi/contract-kit/issues"},"dist":{"shasum":"c3b6e9e7ffb4fd4727732d25405b4f7b48f90960","tarball":"https://registry.npmjs.org/@ahmedrowaihi/fn-schema-transformer/-/fn-schema-transformer-0.2.0.tgz","fileCount":11,"integrity":"sha512-+2xNaXrF+YoSx/evVX/MWwfBuK4CJOQD5DCwfxbOjqZue132k4RqgvXskqKaMuc1TPMHRaRrW1SAdfxe/NMfPw==","signatures":[{"sig":"MEQCID+9K9ePcJG3jgXJyH8exa2iGFrGdP8C/ZjGx24O0C+ZAiBTrvBz8U6oPHFqooXTie7lFsV//9pqOZyRR9QxvSeyJA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ahmedrowaihi%2ffn-schema-transformer@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":20781},"main":"./dist/index.js","type":"module","_from":"file:ahmedrowaihi-fn-schema-transformer-0.2.0.tgz","types":"./dist/index.d.ts","engines":{"node":">=20.19.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./runtime":{"types":"./dist/runtime.d.ts","import":"./dist/runtime.js"},"./package.json":"./package.json"},"scripts":{"dev":"tsc -p tsconfig.build.json --watch","test":"vitest run --passWithNoTests","build":"tsc -p tsconfig.build.json","typecheck":"tsc --noEmit"},"_npmUser":{"name":"ahmedrowaihi","email":"ahmedrowaihi1@gmail.com"},"_resolved":"/tmp/aa6f638c1839212271798c86baa9dc36/ahmedrowaihi-fn-schema-transformer-0.2.0.tgz","_integrity":"sha512-+2xNaXrF+YoSx/evVX/MWwfBuK4CJOQD5DCwfxbOjqZue132k4RqgvXskqKaMuc1TPMHRaRrW1SAdfxe/NMfPw==","repository":{"url":"git+https://github.com/ahmedrowaihi/contract-kit.git","type":"git","directory":"packages/fn-schema/transformer"},"_npmVersion":"10.8.2","description":"TypeScript compiler-API transformer that inlines fn-schema results into emitted code. Replaces `schemaOf(myFunction)` calls with the literal JSON Schema at build time, eliminating runtime extraction cost. Plug into ts-patch, swc, esbuild, or any tool that","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"@ahmedrowaihi/fn-schema-core":"0.2.0","@ahmedrowaihi/fn-schema-typescript":"0.2.0"},"publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^4.0.0","typescript":"5.9.3","@types/node":"^22","@ahmedrowaihi/tsconfig":"0.0.0"},"peerDependencies":{"typescript":">=5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/fn-schema-transformer_0.2.0_1777918213155_0.5486584716035252","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Moved to @ir-kit/fn-schema-transformer. See https://github.com/ir-kit/ir-kit for migration."},"0.2.1":{"name":"@ahmedrowaihi/fn-schema-transformer","version":"0.2.1","keywords":["json-schema","function-signature","typescript-transformer","compile-time"],"author":{"name":"Ahmed Rowaihi","email":"ahmedrowaihi@gmail.com"},"license":"MIT","_id":"@ahmedrowaihi/fn-schema-transformer@0.2.1","maintainers":[{"name":"ahmedrowaihi","email":"ahmedrowaihi1@gmail.com"}],"homepage":"https://github.com/ahmedrowaihi/contract-kit/tree/main/packages/fn-schema/transformer","bugs":{"url":"https://github.com/ahmedrowaihi/contract-kit/issues"},"dist":{"shasum":"fd5cb70b3de9d9513bdd76e873dd8365f01c277d","tarball":"https://registry.npmjs.org/@ahmedrowaihi/fn-schema-transformer/-/fn-schema-transformer-0.2.1.tgz","fileCount":11,"integrity":"sha512-fxZARlfMIirSW6EJUbjI4zy1gGUKH7TsmP51in4QDGXWhxLxGisqkyzCHCytAugnSBbCUTOhkwcDG8lIX63eOw==","signatures":[{"sig":"MEYCIQCM1qGK+5j09+7xH2Pf+lb5XU08kiu1rrpPXnJdOmrJ8gIhAIgB7pj+4/nCTwIAg8QmGm2fE8W0I99L6EDfoEvvuVag","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ahmedrowaihi%2ffn-schema-transformer@0.2.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":20789},"main":"./dist/index.js","type":"module","_from":"file:ahmedrowaihi-fn-schema-transformer-0.2.1.tgz","types":"./dist/index.d.ts","engines":{"node":">=20.19.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./runtime":{"types":"./dist/runtime.d.ts","import":"./dist/runtime.js"},"./package.json":"./package.json"},"scripts":{"dev":"tsc -p tsconfig.build.json --watch","test":"vitest run --passWithNoTests","build":"tsc -p tsconfig.build.json","typecheck":"tsc --noEmit"},"_npmUser":{"name":"ahmedrowaihi","email":"ahmedrowaihi1@gmail.com"},"_resolved":"/tmp/e49c1deb41d46e8969c0f5ef8749ce0d/ahmedrowaihi-fn-schema-transformer-0.2.1.tgz","_integrity":"sha512-fxZARlfMIirSW6EJUbjI4zy1gGUKH7TsmP51in4QDGXWhxLxGisqkyzCHCytAugnSBbCUTOhkwcDG8lIX63eOw==","repository":{"url":"git+https://github.com/ahmedrowaihi/contract-kit.git","type":"git","directory":"packages/fn-schema/transformer"},"_npmVersion":"10.8.2","description":"TypeScript compiler-API transformer that inlines fn-schema results into emitted code. Replaces `schemaOf(myFunction)` calls with the literal JSON Schema at build time, eliminating runtime extraction cost. Plug into ts-patch, swc, esbuild, or any tool that","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"@ahmedrowaihi/fn-schema-core":"0.3.0","@ahmedrowaihi/fn-schema-typescript":"0.2.1"},"publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^4.0.0","typescript":"5.9.3","@types/node":"^22","@ahmedrowaihi/tsconfig":"0.0.0"},"peerDependencies":{"typescript":">=5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/fn-schema-transformer_0.2.1_1777978693405_0.5083857465564694","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Moved to @ir-kit/fn-schema-transformer. See https://github.com/ir-kit/ir-kit for migration."}},"time":{"created":"2026-05-04T18:10:13.066Z","modified":"2026-05-21T09:19:24.706Z","0.2.0":"2026-05-04T18:10:13.364Z","0.2.1":"2026-05-05T10:58:13.542Z"},"bugs":{"url":"https://github.com/ahmedrowaihi/contract-kit/issues"},"author":{"name":"Ahmed Rowaihi","email":"ahmedrowaihi@gmail.com"},"license":"MIT","homepage":"https://github.com/ahmedrowaihi/contract-kit/tree/main/packages/fn-schema/transformer","keywords":["json-schema","function-signature","typescript-transformer","compile-time"],"repository":{"url":"git+https://github.com/ahmedrowaihi/contract-kit.git","type":"git","directory":"packages/fn-schema/transformer"},"description":"TypeScript compiler-API transformer that inlines fn-schema results into emitted code. Replaces `schemaOf(myFunction)` calls with the literal JSON Schema at build time, eliminating runtime extraction cost. Plug into ts-patch, swc, esbuild, or any tool that","maintainers":[{"name":"ahmedrowaihi","email":"ahmedrowaihi1@gmail.com"}],"readme":"# @ahmedrowaihi/fn-schema-transformer\n\nTypeScript compiler-API transformer that **inlines fn-schema results into emitted JS at compile time**. Replaces every `schemaOf(fn)` call with a literal JSON Schema object pulled from a pre-extracted bundle.\n\n## When to use this — and when not to\n\nUse it when you want zero runtime cost: no `JSON.parse` on cold start, no `schemas.json` artifact at runtime, no ts-morph dep in your shipped bundle.\n\nFor 95% of users the [`loader`](../loader/README.md) is the right answer — simpler to set up and works in every TS toolchain. Only reach for the transformer when you've measured a real cost (cold-start latency, bundle size) or your deployment target forbids JSON files.\n\n|                          | loader                    | transformer                        |\n| ------------------------ | ------------------------- | ---------------------------------- |\n| setup                    | `import`                  | `ts-patch` + tsconfig plugin entry |\n| runtime cost             | one `JSON.parse`          | none                               |\n| live updates             | yes (re-extract + import) | no (rebuild required)              |\n| works with vanilla `tsc` | yes                       | no (needs `tspc`)                  |\n\n## Install\n\n```bash\npnpm add -D @ahmedrowaihi/fn-schema-transformer ts-patch\n```\n\n## Setup\n\n### 1. Produce a bundle\n\nEither path works — the transformer just needs a `schemas.json` on disk before tsc runs.\n\n**Programmatic** (in a build script):\n\n```ts\nimport { extract } from \"@ahmedrowaihi/fn-schema-typescript\";\nimport { emit } from \"@ahmedrowaihi/fn-schema-core\";\nimport { writeFile, mkdir } from \"node:fs/promises\";\n\nconst result = await extract({ files: [\"src/api/**/*.ts\"] });\nawait mkdir(\"generated\", { recursive: true });\nawait writeFile(\"generated/schemas.json\", emit.toBundle(result));\n```\n\n**CLI**:\n\n```bash\nnpx fn-schema extract 'src/api/**/*.ts' --bundle generated/schemas.json --pretty\n```\n\n### 2. Configure ts-patch\n\n```jsonc\n// tsconfig.json\n{\n  \"compilerOptions\": {\n    \"plugins\": [\n      {\n        \"transform\": \"@ahmedrowaihi/fn-schema-transformer\",\n        \"bundlePath\": \"./generated/schemas.json\",\n      },\n    ],\n  },\n}\n```\n\n```jsonc\n// package.json — bundle must exist before tspc runs\n{\n  \"scripts\": {\n    \"build:schemas\": \"node scripts/extract.mjs\",\n    \"build:ts\": \"tspc\",\n    \"build\": \"pnpm build:schemas && pnpm build:ts\",\n  },\n}\n```\n\n`tspc` is `ts-patch`'s patched compiler (replaces `tsc`).\n\n### 3. Use the runtime markers\n\n```ts\nimport {\n  schemaOf,\n  inputSchemaOf,\n  outputSchemaOf,\n} from \"@ahmedrowaihi/fn-schema-transformer/runtime\";\nimport { createUser } from \"./api/handlers\";\n\nconst meta = schemaOf(createUser);\nconst inputSchema = inputSchemaOf(createUser);\nconst outputSchema = outputSchemaOf(createUser);\n```\n\nAfter transformation, the emitted JS has:\n\n```js\nconst meta = { input: { type: \"object\", properties: { ... } }, output: { ... } }\nconst inputSchema = { type: \"object\", properties: { ... } }\nconst outputSchema = { ... }\n```\n\nThe runtime stubs return `undefined` if the transformer is NOT applied, so dev tooling that doesn't run the transformer (`tsx`, `vitest`, etc.) doesn't break — calls just return `undefined`.\n\n## What gets replaced\n\nDirect calls only:\n\n```ts\nschemaOf(myFunction); // ✅ inlined\ninputSchemaOf(myFunction); // ✅\noutputSchemaOf(myFunction); // ✅\n\nconst fn = myFunction;\nschemaOf(fn); // ❌ not inlined (argument is a binding, not the original identifier)\n\nschemaOf(makeFn()); // ❌ not inlined (call expression)\n```\n\nLookup is by the argument identifier's name. If `myFunction` isn't in the bundle, the call is left alone — no error, but you get `undefined` at runtime via the stub.\n\n## Limitations\n\n- TS transformers are **synchronous**. The bundle must exist on disk before tsc runs — wire your build chain so extraction completes first.\n- Doesn't work with vanilla `tsc` — needs [`ts-patch`](https://github.com/nonara/ts-patch)'s `tspc` (or another tool supporting custom transformers).\n- Source-map fidelity is best-effort.\n","readmeFilename":"README.md"}