{"_id":"@ahmedrowaihi/fn-schema-loader","_rev":"3-a57fc5fb0e89972176138eae2786011c","name":"@ahmedrowaihi/fn-schema-loader","dist-tags":{"latest":"0.2.1"},"versions":{"0.2.0":{"name":"@ahmedrowaihi/fn-schema-loader","version":"0.2.0","keywords":["json-schema","function-signature","reader","loader"],"author":{"name":"Ahmed Rowaihi","email":"ahmedrowaihi@gmail.com"},"license":"MIT","_id":"@ahmedrowaihi/fn-schema-loader@0.2.0","maintainers":[{"name":"ahmedrowaihi","email":"ahmedrowaihi1@gmail.com"}],"homepage":"https://github.com/ahmedrowaihi/contract-kit/tree/main/packages/fn-schema/loader","bugs":{"url":"https://github.com/ahmedrowaihi/contract-kit/issues"},"dist":{"shasum":"e1e40b36660f6605b9bd050b1f17f229debe7b9c","tarball":"https://registry.npmjs.org/@ahmedrowaihi/fn-schema-loader/-/fn-schema-loader-0.2.0.tgz","fileCount":15,"integrity":"sha512-WUS2xBC15v/ShqtUQ7j54Y4QPBLQ6eA9uT3a7W60/bN2uqXqpUKOM5f+lAEx3q3mboary41zXBbMnGPM2pab1Q==","signatures":[{"sig":"MEYCIQDdtqdd4Kfd6j2I5iJEAuZ7KzwxC+G2vVSMsJQkVyVbLQIhAJYAvpgTIEpLap31Z2TF82/bE2ssRqWMBFsaN704ypOC","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ahmedrowaihi%2ffn-schema-loader@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":17977},"main":"./dist/index.js","type":"module","_from":"file:ahmedrowaihi-fn-schema-loader-0.2.0.tgz","types":"./dist/index.d.ts","engines":{"node":">=20.19.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.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/76ce46dff91d96f26aeead878ca12e69/ahmedrowaihi-fn-schema-loader-0.2.0.tgz","_integrity":"sha512-WUS2xBC15v/ShqtUQ7j54Y4QPBLQ6eA9uT3a7W60/bN2uqXqpUKOM5f+lAEx3q3mboary41zXBbMnGPM2pab1Q==","repository":{"url":"git+https://github.com/ahmedrowaihi/contract-kit.git","type":"git","directory":"packages/fn-schema/loader"},"_npmVersion":"10.8.2","description":"Type-safe reader for fn-schema bundles. Resolves $ref pointers, indexes signatures by id and named types by identity keyword. Zero runtime dependencies — works in any JS runtime that can read JSON.","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"@ahmedrowaihi/fn-schema-core":"0.2.0"},"publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^4.0.0","@types/node":"^22","@ahmedrowaihi/tsconfig":"0.0.0"},"_npmOperationalInternal":{"tmp":"tmp/fn-schema-loader_0.2.0_1777918212947_0.20606254802205237","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Moved to @ir-kit/fn-schema-loader. See https://github.com/ir-kit/ir-kit for migration."},"0.2.1":{"name":"@ahmedrowaihi/fn-schema-loader","version":"0.2.1","keywords":["json-schema","function-signature","reader","loader"],"author":{"name":"Ahmed Rowaihi","email":"ahmedrowaihi@gmail.com"},"license":"MIT","_id":"@ahmedrowaihi/fn-schema-loader@0.2.1","maintainers":[{"name":"ahmedrowaihi","email":"ahmedrowaihi1@gmail.com"}],"homepage":"https://github.com/ahmedrowaihi/contract-kit/tree/main/packages/fn-schema/loader","bugs":{"url":"https://github.com/ahmedrowaihi/contract-kit/issues"},"dist":{"shasum":"0039066793190ce810741ec9274dbda9de7eedd3","tarball":"https://registry.npmjs.org/@ahmedrowaihi/fn-schema-loader/-/fn-schema-loader-0.2.1.tgz","fileCount":15,"integrity":"sha512-zt4EwakIT/kw/3PR5rqn7sPho/iTpTPaoOixGBA/rtUYZMqJniR5GBc4wR8Bdbp2dEZV8DdnNlPJRZ+37rmAuw==","signatures":[{"sig":"MEQCIC7tfNEyCVmEw1yUCIHHyiJoJBFzAvWVx7nxT7gyiBVEAiBvNPwItQ0T+1HcUt5l0AyKdFPGY5U9jVrslujovvsjnw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ahmedrowaihi%2ffn-schema-loader@0.2.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":17985},"main":"./dist/index.js","type":"module","_from":"file:ahmedrowaihi-fn-schema-loader-0.2.1.tgz","types":"./dist/index.d.ts","engines":{"node":">=20.19.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.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/26041dc70eabbaf4c7830d00bf8cd32a/ahmedrowaihi-fn-schema-loader-0.2.1.tgz","_integrity":"sha512-zt4EwakIT/kw/3PR5rqn7sPho/iTpTPaoOixGBA/rtUYZMqJniR5GBc4wR8Bdbp2dEZV8DdnNlPJRZ+37rmAuw==","repository":{"url":"git+https://github.com/ahmedrowaihi/contract-kit.git","type":"git","directory":"packages/fn-schema/loader"},"_npmVersion":"10.8.2","description":"Type-safe reader for fn-schema bundles. Resolves $ref pointers, indexes signatures by id and named types by identity keyword. Zero runtime dependencies — works in any JS runtime that can read JSON.","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"@ahmedrowaihi/fn-schema-core":"0.3.0"},"publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^4.0.0","@types/node":"^22","@ahmedrowaihi/tsconfig":"0.0.0"},"_npmOperationalInternal":{"tmp":"tmp/fn-schema-loader_0.2.1_1777978693387_0.3600413313520634","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Moved to @ir-kit/fn-schema-loader. See https://github.com/ir-kit/ir-kit for migration."}},"time":{"created":"2026-05-04T18:10:12.859Z","modified":"2026-05-21T09:19:21.276Z","0.2.0":"2026-05-04T18:10:13.097Z","0.2.1":"2026-05-05T10:58:13.531Z"},"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/loader","keywords":["json-schema","function-signature","reader","loader"],"repository":{"url":"git+https://github.com/ahmedrowaihi/contract-kit.git","type":"git","directory":"packages/fn-schema/loader"},"description":"Type-safe reader for fn-schema bundles. Resolves $ref pointers, indexes signatures by id and named types by identity keyword. Zero runtime dependencies — works in any JS runtime that can read JSON.","maintainers":[{"name":"ahmedrowaihi","email":"ahmedrowaihi1@gmail.com"}],"readme":"# @ahmedrowaihi/fn-schema-loader\n\nType-safe reader over a fn-schema bundle. Generic over the bundle type so signature ids and definition names land as literal-typed unions.\n\nZero runtime dependencies — works in any JS runtime that can read JSON.\n\n## When to use it\n\nYou have a fn-schema bundle (produced by the CLI or programmatically — doesn't matter which) and want ergonomic access from your app:\n\n- server endpoints looking up schemas by id\n- frontend form builders resolving `$ref` pointers\n- canvas tools matching types nominally via `findByIdentity`\n\nIf you're loading the JSON in one place and reading it once, the helper is overkill — just `JSON.parse` it.\n\n## Install\n\n```bash\npnpm add @ahmedrowaihi/fn-schema-loader\n```\n\n## Producing a bundle\n\nPick whichever fits your build chain — both produce the same JSON:\n\n### Programmatically\n\n```ts\nimport { extract } from \"@ahmedrowaihi/fn-schema-typescript\";\nimport { emit } from \"@ahmedrowaihi/fn-schema-core\";\nimport { writeFile } from \"node:fs/promises\";\n\nconst result = await extract({\n  files: [\"src/api/**/*.ts\"],\n  schema: { identity: \"x-fn-schema-ts\" },\n});\nawait writeFile(\n  \"generated/schemas.json\",\n  emit.toBundle(result, { pretty: true }),\n);\nawait writeFile(\n  \"generated/schemas.ts\",\n  emit.toBundleTypesModule(result, { jsonImport: \"./schemas.json\" }),\n);\n```\n\n### Via CLI\n\n```bash\nnpx fn-schema extract 'src/api/**/*.ts' --bundle generated/schemas.json --bundle-types --pretty\n```\n\nThe `.ts` wrapper next to `schemas.json` is what unlocks literal-typed lookups in the reader.\n\n## Reading\n\n```ts\nimport { createReader } from \"@ahmedrowaihi/fn-schema-loader\";\nimport schemas from \"./generated/schemas\"; // the typed wrapper\n\nconst reader = createReader(schemas);\n\nreader.get(\"createUser\"); // ✅ typed\nreader.get(\"createUserx\"); // ❌ TS error\nreader.has(\"listUsers\"); // type predicate\n\nreader.inputOf(\"createUser\"); // resolved (top-level $ref chased)\nreader.outputOf(\"createUser\");\nreader.resolveRef(\"#/definitions/User\");\n\n// canvas-style nominal-type matching (only when bundle was extracted with `identity`)\nreader.findByIdentity(\"User\", \"x-fn-schema-ts\");\n// → [{ signatureId: \"createUser\", position: \"output\", schema: {...} }, ...]\n```\n\n## API\n\n```ts\ninterface Reader<T extends Bundle> {\n  readonly bundle: T;\n  get<K extends SignatureId<T>>(id: K): T[\"signatures\"][K] | undefined;\n  has<K extends string>(id: K): id is K & SignatureId<T>;\n  resolve<K extends DefinitionName<T>>(\n    name: K,\n  ): T[\"definitions\"][K] | undefined;\n  resolveRef(ref: string): Record<string, unknown> | undefined;\n  inputOf<K extends SignatureId<T>>(id: K): unknown;\n  outputOf<K extends SignatureId<T>>(id: K): unknown;\n  findByIdentity(name: string, identityKey?: string): Match[];\n  listSignatures(): SignatureId<T>[];\n  listDefinitions(): DefinitionName<T>[];\n}\n```\n\n`identityKey` defaults to `\"x-fn-schema-ts\"`.\n\n## Without the typed wrapper\n\nWorks on any plain object too — you just lose autocomplete:\n\n```ts\nimport { readFileSync } from \"node:fs\";\nimport { createReader, type Bundle } from \"@ahmedrowaihi/fn-schema-loader\";\n\nconst raw = JSON.parse(readFileSync(\"./schemas.json\", \"utf-8\")) as Bundle;\nconst reader = createReader(raw);\n```\n\n## $ref resolution\n\n`inputOf` / `outputOf` chase a single top-level `$ref`. Nested `$ref`s inside the schema body are left intact — call `resolveRef` yourself if you need to chase further. Keeps the helper predictable; no cycle handling.\n","readmeFilename":"README.md"}