@kubb/ast 5.0.0-beta.63 → 5.0.0-beta.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/{defineMacro-Shz8f6SG.js → defineMacro-B76LsJwO.js} +4 -4
  2. package/dist/{defineMacro-Shz8f6SG.js.map → defineMacro-B76LsJwO.js.map} +1 -1
  3. package/dist/{defineMacro-BATi7xoC.d.ts → defineMacro-B7qm3zTd.d.ts} +3 -3
  4. package/dist/factory-wJLzHeXT.d.ts +27 -0
  5. package/dist/factory.d.ts +3 -27
  6. package/dist/factory.js +2 -2
  7. package/dist/{index-B9cc8MBS.d.ts → index-BKD4drsX.d.ts} +2 -2
  8. package/dist/index.cjs +54 -2
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +24 -21
  11. package/dist/index.js +54 -8
  12. package/dist/index.js.map +1 -1
  13. package/dist/macros.d.ts +2 -2
  14. package/dist/macros.js +4 -4
  15. package/dist/{operationParams-k5CKwSWZ.d.ts → operationParams-ByVfpYr7.d.ts} +3 -3
  16. package/dist/{refs-BjNDuCBD.js → refs-Dx6U5LoE.js} +3 -3
  17. package/dist/{refs-BjNDuCBD.js.map → refs-Dx6U5LoE.js.map} +1 -1
  18. package/dist/{schema-Cbnxmz4b.js → schema-YNbOtTCM.js} +2 -2
  19. package/dist/{schema-Cbnxmz4b.js.map → schema-YNbOtTCM.js.map} +1 -1
  20. package/dist/{types-BB_xgRJ3.d.ts → types-BP9BZoq-.d.ts} +8 -8
  21. package/dist/types.d.ts +5 -5
  22. package/dist/{utils-DaXkewb1.js → utils-BJi0y-xg.js} +4 -4
  23. package/dist/{utils-DaXkewb1.js.map → utils-BJi0y-xg.js.map} +1 -1
  24. package/dist/utils.d.ts +3 -3
  25. package/dist/utils.js +3 -3
  26. package/package.json +1 -2
  27. package/src/constants.ts +0 -150
  28. package/src/defineMacro.ts +0 -139
  29. package/src/defineNode.ts +0 -102
  30. package/src/definePrinter.ts +0 -258
  31. package/src/dialect.ts +0 -86
  32. package/src/factory.ts +0 -44
  33. package/src/guards.ts +0 -28
  34. package/src/index.ts +0 -13
  35. package/src/infer.ts +0 -132
  36. package/src/macros/index.ts +0 -3
  37. package/src/macros/macroDiscriminatorEnum.ts +0 -50
  38. package/src/macros/macroEnumName.ts +0 -33
  39. package/src/macros/macroSimplifyUnion.ts +0 -60
  40. package/src/nodes/base.ts +0 -49
  41. package/src/nodes/code.ts +0 -355
  42. package/src/nodes/content.ts +0 -51
  43. package/src/nodes/file.ts +0 -380
  44. package/src/nodes/function.ts +0 -283
  45. package/src/nodes/index.ts +0 -93
  46. package/src/nodes/input.ts +0 -144
  47. package/src/nodes/operation.ts +0 -168
  48. package/src/nodes/output.ts +0 -49
  49. package/src/nodes/parameter.ts +0 -71
  50. package/src/nodes/property.ts +0 -67
  51. package/src/nodes/requestBody.ts +0 -54
  52. package/src/nodes/response.ts +0 -173
  53. package/src/nodes/schema.ts +0 -732
  54. package/src/optionality.ts +0 -15
  55. package/src/registry.ts +0 -75
  56. package/src/signature.ts +0 -207
  57. package/src/types.ts +0 -8
  58. package/src/utils/codegen.ts +0 -103
  59. package/src/utils/extractStringsFromNodes.ts +0 -35
  60. package/src/utils/fileMerge.ts +0 -183
  61. package/src/utils/index.ts +0 -11
  62. package/src/utils/operationParams.ts +0 -353
  63. package/src/utils/refs.ts +0 -134
  64. package/src/utils/schemaGraph.ts +0 -177
  65. package/src/utils/schemaMerge.ts +0 -34
  66. package/src/utils/schemaTraversal.ts +0 -86
  67. package/src/utils/strings.ts +0 -139
  68. package/src/visitor.ts +0 -519
  69. /package/dist/{chunk-CNktS9qV.js → rolldown-runtime-CNktS9qV.js} +0 -0
@@ -1,6 +1,6 @@
1
- import "./chunk-CNktS9qV.js";
2
- import { u as transform } from "./refs-BjNDuCBD.js";
3
- import { nt as visitorKeys } from "./schema-Cbnxmz4b.js";
1
+ import "./rolldown-runtime-CNktS9qV.js";
2
+ import { u as transform } from "./refs-Dx6U5LoE.js";
3
+ import { nt as visitorKeys } from "./schema-YNbOtTCM.js";
4
4
  //#region src/defineMacro.ts
5
5
  /**
6
6
  * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
@@ -96,4 +96,4 @@ function applyMacros(root, macros, options) {
96
96
  //#endregion
97
97
  export { composeMacros as n, defineMacro as r, applyMacros as t };
98
98
 
99
- //# sourceMappingURL=defineMacro-Shz8f6SG.js.map
99
+ //# sourceMappingURL=defineMacro-B76LsJwO.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineMacro-Shz8f6SG.js","names":[],"sources":["../src/defineMacro.ts"],"sourcesContent":["import type { VisitorDepth } from './constants.ts'\nimport type { VisitorKey } from './defineNode.ts'\nimport { visitorKeys } from './defineNode.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext } from './visitor.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter\n * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = Visitor & {\n /**\n * Macro identifier used to tell macros apart, for example `'simplify-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Gate checked against the current node before any callback runs. When it returns `false`\n * the macro is skipped for that node.\n */\n when?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `definePlugin`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.when && !macro.when(current)) continue\n\n const next = callback(current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin\n * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied\n * sequentially per node so later macros see earlier output. This differs from a plain visitor, which\n * has no names, ordering, or composition.\n *\n * @example\n * ```ts\n * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])\n * const next = transform(root, visitor)\n * ```\n */\nexport function composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to rewrite the root node only.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Apply to the root node only\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n"],"mappings":";;;;;;;;AAiBA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,QAAQ,CAAC,MAAM,KAAK,OAAO,GAAG;EAExC,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;;;;;;;;;AAcA,SAAgB,cAAc,QAAuC;CACnE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,cAAc,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,CAAC;CAE9F,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAO,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACtG,QAA+C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAO,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"}
1
+ {"version":3,"file":"defineMacro-B76LsJwO.js","names":[],"sources":["../src/defineMacro.ts"],"sourcesContent":["import type { VisitorDepth } from './constants.ts'\nimport type { VisitorKey } from './defineNode.ts'\nimport { visitorKeys } from './defineNode.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext } from './visitor.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter\n * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = Visitor & {\n /**\n * Macro identifier used to tell macros apart, for example `'simplify-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Gate checked against the current node before any callback runs. When it returns `false`\n * the macro is skipped for that node.\n */\n when?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `definePlugin`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.when && !macro.when(current)) continue\n\n const next = callback(current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin\n * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied\n * sequentially per node so later macros see earlier output. This differs from a plain visitor, which\n * has no names, ordering, or composition.\n *\n * @example\n * ```ts\n * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])\n * const next = transform(root, visitor)\n * ```\n */\nexport function composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to rewrite the root node only.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Apply to the root node only\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n"],"mappings":";;;;;;;;AAiBA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,QAAQ,CAAC,MAAM,KAAK,OAAO,GAAG;EAExC,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;;;;;;;;;AAcA,SAAgB,cAAc,QAAuC;CACnE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,cAAc,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,CAAC;CAE9F,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAO,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACtG,QAA+C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAO,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"}
@@ -1,5 +1,5 @@
1
- import { n as __name } from "./chunk-CNktS9qV.js";
2
- import { C as ParameterNode, Et as PropertyNode, _t as SchemaNode, f as OperationNode, h as ResponseNode, n as OutputNode, o as InputNode, rt as ContentNode, t as Node, y as RequestBodyNode } from "./index-B9cc8MBS.js";
1
+ import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
2
+ import { C as ParameterNode, Et as PropertyNode, _t as SchemaNode, f as OperationNode, h as ResponseNode, n as OutputNode, o as InputNode, rt as ContentNode, t as Node, y as RequestBodyNode } from "./index-BKD4drsX.js";
3
3
 
4
4
  //#region src/constants.d.ts
5
5
  /**
@@ -463,4 +463,4 @@ declare function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyAr
463
463
  }): TNode;
464
464
  //#endregion
465
465
  export { defineMacro as a, VisitorContext as c, walk as d, schemaTypes as f, composeMacros as i, collect as l, Macro as n, ParentOf as o, applyMacros as r, Visitor as s, Enforce as t, transform as u };
466
- //# sourceMappingURL=defineMacro-BATi7xoC.d.ts.map
466
+ //# sourceMappingURL=defineMacro-B7qm3zTd.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { n as __name, t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
2
+ import { F as createFunctionParameters, Gt as createBreak, I as createIndexedAccessType, J as UserFileNode, Jt as createJsx, Kt as createConst, L as createObjectBindingPattern, Ot as createProperty, P as createFunctionParameter, Q as createSource, R as createTypeLiteral, Wt as createArrowFunction, X as createFile, Xt as createType, Y as createExport, Yt as createText, Z as createImport, _ as createResponse, at as createContent, b as createRequestBody, p as createOperation, qt as createFunction, r as createOutput, s as createInput, t as Node, w as createParameter, wt as createSchema } from "./index-BKD4drsX.js";
3
+
4
+ //#region src/factory.d.ts
5
+ declare namespace factory_d_exports {
6
+ export { UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createIndexedAccessType, createInput, createJsx, createObjectBindingPattern, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, createTypeLiteral, update };
7
+ }
8
+ /**
9
+ * Identity-preserving node update: returns `node` unchanged when every field in
10
+ * `changes` already equals (by reference) the current value, otherwise a new node
11
+ * with the changes applied.
12
+ *
13
+ * Mirrors the TypeScript compiler's `factory.updateX` contract. Pair it with the
14
+ * structural sharing in {@link transform} so a no-op rewrite does not allocate and
15
+ * downstream passes can detect "nothing changed" by identity. Comparison is shallow,
16
+ * so a structurally equal but newly allocated array or object counts as a change.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * update(node, { name: node.name }) // -> same `node` reference
21
+ * update(node, { name: 'renamed' }) // -> new node, `name` replaced
22
+ * ```
23
+ */
24
+ declare function update<T extends Node>(node: T, changes: Partial<T>): T;
25
+ //#endregion
26
+ export { update as n, factory_d_exports as t };
27
+ //# sourceMappingURL=factory-wJLzHeXT.d.ts.map
package/dist/factory.d.ts CHANGED
@@ -1,27 +1,3 @@
1
- import { n as __name, t as __exportAll } from "./chunk-CNktS9qV.js";
2
- import { F as createFunctionParameters, Gt as createBreak, I as createIndexedAccessType, J as UserFileNode, Jt as createJsx, Kt as createConst, L as createObjectBindingPattern, Ot as createProperty, P as createFunctionParameter, Q as createSource, R as createTypeLiteral, Wt as createArrowFunction, X as createFile, Xt as createType, Y as createExport, Yt as createText, Z as createImport, _ as createResponse, at as createContent, b as createRequestBody, p as createOperation, qt as createFunction, r as createOutput, s as createInput, t as Node, w as createParameter, wt as createSchema } from "./index-B9cc8MBS.js";
3
-
4
- //#region src/factory.d.ts
5
- declare namespace factory_d_exports {
6
- export { UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createIndexedAccessType, createInput, createJsx, createObjectBindingPattern, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, createTypeLiteral, update };
7
- }
8
- /**
9
- * Identity-preserving node update: returns `node` unchanged when every field in
10
- * `changes` already equals (by reference) the current value, otherwise a new node
11
- * with the changes applied.
12
- *
13
- * Mirrors the TypeScript compiler's `factory.updateX` contract. Pair it with the
14
- * structural sharing in {@link transform} so a no-op rewrite does not allocate and
15
- * downstream passes can detect "nothing changed" by identity. Comparison is shallow,
16
- * so a structurally equal but newly allocated array or object counts as a change.
17
- *
18
- * @example
19
- * ```ts
20
- * update(node, { name: node.name }) // -> same `node` reference
21
- * update(node, { name: 'renamed' }) // -> new node, `name` replaced
22
- * ```
23
- */
24
- declare function update<T extends Node>(node: T, changes: Partial<T>): T;
25
- //#endregion
26
- export { type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createIndexedAccessType, createInput, createJsx, createObjectBindingPattern, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, createTypeLiteral, factory_d_exports as t, update };
27
- //# sourceMappingURL=factory.d.ts.map
1
+ import { F as createFunctionParameters, Gt as createBreak, I as createIndexedAccessType, J as UserFileNode, Jt as createJsx, Kt as createConst, L as createObjectBindingPattern, Ot as createProperty, P as createFunctionParameter, Q as createSource, R as createTypeLiteral, Wt as createArrowFunction, X as createFile, Xt as createType, Y as createExport, Yt as createText, Z as createImport, _ as createResponse, at as createContent, b as createRequestBody, p as createOperation, qt as createFunction, r as createOutput, s as createInput, w as createParameter, wt as createSchema } from "./index-BKD4drsX.js";
2
+ import { n as update } from "./factory-wJLzHeXT.js";
3
+ export { type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createIndexedAccessType, createInput, createJsx, createObjectBindingPattern, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, createTypeLiteral, update };
package/dist/factory.js CHANGED
@@ -1,5 +1,5 @@
1
- import { t as __exportAll } from "./chunk-CNktS9qV.js";
2
- import { A as createImport, B as createContent, G as createBreak, J as createJsx, K as createConst, O as createExport, S as createTypeLiteral, W as createArrowFunction, X as createType, Y as createText, a as createProperty, b as createIndexedAccessType, f as createOperation, g as createInput, j as createSource, k as createFile, m as createRequestBody, q as createFunction, r as createResponse, s as createParameter, t as createSchema, u as createOutput, v as createFunctionParameter, x as createObjectBindingPattern, y as createFunctionParameters } from "./schema-Cbnxmz4b.js";
1
+ import { t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
2
+ import { A as createImport, B as createContent, G as createBreak, J as createJsx, K as createConst, O as createExport, S as createTypeLiteral, W as createArrowFunction, X as createType, Y as createText, a as createProperty, b as createIndexedAccessType, f as createOperation, g as createInput, j as createSource, k as createFile, m as createRequestBody, q as createFunction, r as createResponse, s as createParameter, t as createSchema, u as createOutput, v as createFunctionParameter, x as createObjectBindingPattern, y as createFunctionParameters } from "./schema-YNbOtTCM.js";
3
3
  //#region src/factory.ts
4
4
  var factory_exports = /* @__PURE__ */ __exportAll({
5
5
  createArrowFunction: () => createArrowFunction,
@@ -1,4 +1,4 @@
1
- import { n as __name } from "./chunk-CNktS9qV.js";
1
+ import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
2
2
 
3
3
  //#region src/nodes/base.d.ts
4
4
  /**
@@ -2400,4 +2400,4 @@ declare function createOutput(overrides?: Partial<Omit<OutputNode, 'kind'>>): Ou
2400
2400
  type Node = InputNode | OutputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | RequestBodyNode | ContentNode | FunctionParamNode | FileNode | ImportNode | ExportNode | SourceNode | ConstNode | TypeNode | FunctionNode | ArrowFunctionNode;
2401
2401
  //#endregion
2402
2402
  export { exportDef as $, textDef as $t, IndexedAccessTypeNode as A, InferSchemaNode as At, functionParametersDef as B, TypeNode as Bt, ParameterNode as C, UrlSchemaNode as Ct, FunctionParamNode as D, UserPropertyNode as Dt, FunctionParamKind as E, PropertyNode as Et, createFunctionParameters as F, ConstNode as Ft, FileNode as G, createBreak as Gt, objectBindingPatternDef as H, breakDef as Ht, createIndexedAccessType as I, FunctionNode as It, UserFileNode as J, createJsx as Jt, ImportNode as K, createConst as Kt, createObjectBindingPattern as L, JSDocNode as Lt, TypeExpression as M, ArrowFunctionNode as Mt, TypeLiteralNode as N, BreakNode as Nt, FunctionParameterNode as O, createProperty as Ot, createFunctionParameter as P, CodeNode as Pt, createSource as Q, jsxDef as Qt, createTypeLiteral as R, JsxNode as Rt, ParameterLocation as S, UnionSchemaNode as St, parameterDef as T, schemaDef as Tt, typeLiteralDef as U, constDef as Ut, indexedAccessTypeDef as V, arrowFunctionDef as Vt, ExportNode as W, createArrowFunction as Wt, createFile as X, createType as Xt, createExport as Y, createText as Yt, createImport as Z, functionDef as Zt, createResponse as _, SchemaNode as _t, InputMeta as a, NodeKind as an, createContent as at, createRequestBody as b, StringSchemaNode as bt, inputDef as c, DatetimeSchemaNode as ct, HttpOperationNode as d, NumberSchemaNode as dt, typeDef as en, fileDef as et, OperationNode as f, ObjectSchemaNode as ft, StatusCode as g, ScalarSchemaType as gt, ResponseNode as h, ScalarSchemaNode as ht, outputDef as i, BaseNode as in, contentDef as it, ObjectBindingPatternNode as j, ParserOptions as jt, FunctionParametersNode as k, propertyDef as kt, GenericOperationNode as l, EnumSchemaNode as lt, operationDef as m, RefSchemaNode as mt, OutputNode as n, NodeDef as nn, sourceDef as nt, InputNode as o, ArraySchemaNode as ot, createOperation as p, PrimitiveSchemaType as pt, SourceNode as q, createFunction as qt, createOutput as r, defineNode as rn, ContentNode as rt, createInput as s, DateSchemaNode as st, Node as t, DistributiveOmit as tn, importDef as tt, HttpMethod as u, IntersectionSchemaNode as ut, responseDef as v, SchemaNodeByType as vt, createParameter as w, createSchema as wt, requestBodyDef as x, TimeSchemaNode as xt, RequestBodyNode as y, SchemaType as yt, functionParameterDef as z, TextNode as zt };
2403
- //# sourceMappingURL=index-B9cc8MBS.d.ts.map
2403
+ //# sourceMappingURL=index-BKD4drsX.d.ts.map
package/dist/index.cjs CHANGED
@@ -5,9 +5,9 @@ require("./utils-CEepwqmb.cjs");
5
5
  const require_defineMacro = require("./defineMacro-CEZHaCXE.cjs");
6
6
  const require_factory = require("./factory.cjs");
7
7
  let node_crypto = require("node:crypto");
8
- //#region src/dialect.ts
8
+ //#region src/defineDialect.ts
9
9
  /**
10
- * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the
10
+ * Types a {@link DefineDialect} for an adapter. Adds no runtime behavior and only pins the
11
11
  * dialect's type for inference.
12
12
  *
13
13
  * @example
@@ -360,8 +360,60 @@ function signatureOf(node) {
360
360
  return signature;
361
361
  }
362
362
  //#endregion
363
+ //#region src/exports.ts
364
+ var exports_exports = /* @__PURE__ */ require_schema.__exportAll({
365
+ applyMacros: () => require_defineMacro.applyMacros,
366
+ arrowFunctionDef: () => require_schema.arrowFunctionDef,
367
+ breakDef: () => require_schema.breakDef,
368
+ collect: () => require_refs.collect,
369
+ composeMacros: () => require_defineMacro.composeMacros,
370
+ constDef: () => require_schema.constDef,
371
+ contentDef: () => require_schema.contentDef,
372
+ createPrinterFactory: () => createPrinterFactory,
373
+ defineDialect: () => defineDialect,
374
+ defineMacro: () => require_defineMacro.defineMacro,
375
+ defineNode: () => require_schema.defineNode,
376
+ definePrinter: () => definePrinter,
377
+ exportDef: () => require_schema.exportDef,
378
+ factory: () => require_factory.factory_exports,
379
+ fileDef: () => require_schema.fileDef,
380
+ functionDef: () => require_schema.functionDef,
381
+ functionParameterDef: () => require_schema.functionParameterDef,
382
+ functionParametersDef: () => require_schema.functionParametersDef,
383
+ importDef: () => require_schema.importDef,
384
+ indexedAccessTypeDef: () => require_schema.indexedAccessTypeDef,
385
+ inputDef: () => require_schema.inputDef,
386
+ isHttpOperationNode: () => require_refs.isHttpOperationNode,
387
+ jsxDef: () => require_schema.jsxDef,
388
+ narrowSchema: () => require_refs.narrowSchema,
389
+ nodeDefs: () => require_refs.nodeDefs,
390
+ objectBindingPatternDef: () => require_schema.objectBindingPatternDef,
391
+ operationDef: () => require_schema.operationDef,
392
+ optionality: () => require_schema.optionality,
393
+ outputDef: () => require_schema.outputDef,
394
+ parameterDef: () => require_schema.parameterDef,
395
+ propertyDef: () => require_schema.propertyDef,
396
+ requestBodyDef: () => require_schema.requestBodyDef,
397
+ responseDef: () => require_schema.responseDef,
398
+ schemaDef: () => require_schema.schemaDef,
399
+ schemaTypes: () => require_refs.schemaTypes,
400
+ signatureOf: () => signatureOf,
401
+ sourceDef: () => require_schema.sourceDef,
402
+ textDef: () => require_schema.textDef,
403
+ transform: () => require_refs.transform,
404
+ typeDef: () => require_schema.typeDef,
405
+ typeLiteralDef: () => require_schema.typeLiteralDef,
406
+ walk: () => require_refs.walk
407
+ });
408
+ //#endregion
363
409
  exports.applyMacros = require_defineMacro.applyMacros;
364
410
  exports.arrowFunctionDef = require_schema.arrowFunctionDef;
411
+ Object.defineProperty(exports, "ast", {
412
+ enumerable: true,
413
+ get: function() {
414
+ return exports_exports;
415
+ }
416
+ });
365
417
  exports.breakDef = require_schema.breakDef;
366
418
  exports.collect = require_refs.collect;
367
419
  exports.composeMacros = require_defineMacro.composeMacros;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["extractRefName","obj"],"sources":["../src/dialect.ts","../src/definePrinter.ts","../src/signature.ts"],"sourcesContent":["import type { Node } from './nodes/index.ts'\n\n/**\n * The spec-specific questions a schema parser answers while turning a source document into Kubb\n * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where\n * OpenAPI, AsyncAPI, and plain JSON Schema differ.\n */\nexport type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Whether the schema is nullable.\n */\n isNullable(schema?: TSchema): boolean\n /**\n * Whether the value is a `$ref` pointer.\n */\n isReference(value?: unknown): value is TRef\n /**\n * Whether the schema carries a discriminator for polymorphism.\n */\n isDiscriminator(value?: unknown): value is TDiscriminated\n /**\n * Whether the schema is binary data, converted to a `blob` node.\n */\n isBinary(schema: TSchema): boolean\n /**\n * Resolves a local `$ref` against the document, or nullish when it cannot.\n */\n resolveRef<TResolved>(document: TDocument, ref: string): TResolved | null | undefined\n}\n\n/**\n * How a dialect collapses structurally identical schemas into shared definitions. The contract is\n * generic over the plan and context types, which the adapter supplies. The mechanics live in the\n * adapter, not here, so `@kubb/ast` carries no dedupe logic. The returned plan owns the rewriting\n * behavior, so callers interact with one object.\n */\nexport type Dedupe<TPlan = unknown, TContext = unknown> = {\n /**\n * Scans a forest of nodes and produces a plan describing which shapes to share.\n */\n plan(roots: ReadonlyArray<Node>, context: TContext): TPlan\n}\n\n/**\n * A spec adapter's dialect. `name` identifies it in logs and diagnostics, `schema` holds the\n * spec-specific schema questions the parser answers, and `dedupe` is the schema-sharing seam.\n */\nexport type Dialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown, TDedupe extends Dedupe = Dedupe> = {\n /**\n * Identifies the dialect in logs and diagnostics.\n */\n name: string\n /**\n * The spec-specific schema behavior. See {@link SchemaDialect}.\n */\n schema: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>\n /**\n * The schema-sharing behavior. See {@link Dedupe}.\n */\n dedupe: TDedupe\n}\n\n/**\n * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the\n * dialect's type for inference.\n *\n * @example\n * ```ts\n * export const oasDialect = defineDialect({\n * name: 'oas',\n * schema: {\n * isNullable,\n * isReference,\n * isDiscriminator,\n * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',\n * resolveRef,\n * },\n * dedupe: { plan },\n * })\n * ```\n */\nexport function defineDialect<TSchema, TRef, TDiscriminated, TDocument, TDedupe extends Dedupe>(\n dialect: Dialect<TSchema, TRef, TDiscriminated, TDocument, TDedupe>,\n): Dialect<TSchema, TRef, TDiscriminated, TDocument, TDedupe> {\n return dialect\n}\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * }\n * ```\n */\ntype PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n */\n transform: (node: SchemaNode) => TOutput | null\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for one schema node type.\n *\n * Use a regular function (not an arrow function) if you need `this`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'string'> = function () {\n * return 'string'\n * }\n * ```\n */\ntype PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\ntype PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null\n}\n/**\n * Defines a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'\n *\n * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = definePrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return createPrinterFactory<SchemaNode, SchemaType, SchemaNodeByType>((node) => node.type)(build) as (options?: T['options']) => Printer<T>\n}\n\n/**\n * Generic printer factory behind `definePrinter`. Pass a `getKey` function that maps a node to its\n * handler key, and it returns a `definePrinter`-style helper for that node and key type. `definePrinter`\n * itself is this factory keyed by `node.type`.\n *\n * @example Key a printer by `node.kind` instead of `node.type`\n * ```ts\n * const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(\n * (node) => node.kind,\n * )\n * ```\n */\nexport function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | null) {\n return function <T extends PrinterFactoryOptions>(\n build: (options: T['options']) => {\n name: T['name']\n options: T['options']\n nodes: Partial<{\n [K in TKey]: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNodeByKey[K],\n ) => T['output'] | null\n }>\n print?: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNode,\n ) => T['printOutput'] | null\n },\n ): (options?: T['options']) => {\n name: T['name']\n options: T['options']\n transform: (node: TNode) => T['output'] | null\n print: (node: TNode) => T['printOutput'] | null\n } {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n transform: (node: TNode): T['output'] | null => {\n const key = getKey(node)\n if (key === null) return null\n\n const handler = nodes[key]\n\n if (!handler) return null\n\n return (handler as (this: typeof context, node: TNode) => T['output'] | null).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n transform: context.transform,\n print: (printOverride ? printOverride.bind(context) : context.transform) as (node: TNode) => T['printOutput'] | null,\n }\n }\n }\n}\n","import { hash } from 'node:crypto'\nimport type { SchemaNode } from './nodes/index.ts'\nimport { extractRefName } from './utils/index.ts'\n\n/**\n * The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.\n */\nfunction flagsDescriptor(node: SchemaNode): string {\n return `${node.primitive ?? ''};${node.format ?? ''};${node.nullable ? 1 : 0}`\n}\n\nfunction refTargetName(node: Extract<SchemaNode, { type: 'ref' }>): string {\n if (node.ref) return extractRefName(node.ref)\n return node.name ?? ''\n}\n\ntype ScalarField = { kind: 'scalar'; key: string; prefix: string }\ntype BoolField = { kind: 'bool'; key: string; prefix: string }\ntype ChildField = { kind: 'child'; key: string; prefix: string }\ntype ChildrenField = { kind: 'children'; key: string; prefix: string }\ntype ObjectPropsField = { kind: 'objectProps' }\ntype AdditionalPropsField = { kind: 'additionalProps' }\ntype PatternPropsField = { kind: 'patternProps' }\ntype EnumValuesField = { kind: 'enumValues' }\ntype RefTargetField = { kind: 'refTarget' }\n\ntype ShapeField =\n | ScalarField\n | BoolField\n | ChildField\n | ChildrenField\n | ObjectPropsField\n | AdditionalPropsField\n | PatternPropsField\n | EnumValuesField\n | RefTargetField\n\nconst arrayTupleFields: ReadonlyArray<ShapeField> = [\n { kind: 'children', key: 'items', prefix: 'i' },\n { kind: 'child', key: 'rest', prefix: 'r' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'bool', key: 'unique', prefix: 'u' },\n]\n\nconst numericFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'exclusiveMinimum', prefix: 'emn' },\n { kind: 'scalar', key: 'exclusiveMaximum', prefix: 'emx' },\n { kind: 'scalar', key: 'multipleOf', prefix: 'mo' },\n]\n\nconst rangeFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n]\n\n/**\n * Maps each node `type` to its ordered shape-contributing fields. Types absent from the map\n * (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.\n */\nconst SHAPE_KEYS: Partial<Record<SchemaNode['type'], ReadonlyArray<ShapeField>>> = {\n object: [\n { kind: 'objectProps' },\n { kind: 'additionalProps' },\n { kind: 'patternProps' },\n { kind: 'scalar', key: 'minProperties', prefix: 'mn' },\n { kind: 'scalar', key: 'maxProperties', prefix: 'mx' },\n ],\n array: arrayTupleFields,\n tuple: arrayTupleFields,\n union: [\n { kind: 'scalar', key: 'strategy', prefix: 's' },\n { kind: 'scalar', key: 'discriminatorPropertyName', prefix: 'd' },\n { kind: 'children', key: 'members', prefix: 'm' },\n ],\n intersection: [{ kind: 'children', key: 'members', prefix: 'm' }],\n enum: [{ kind: 'enumValues' }],\n ref: [{ kind: 'refTarget' }],\n string: [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'pattern', prefix: 'pt' },\n ],\n number: numericFields,\n integer: numericFields,\n bigint: numericFields,\n url: [\n { kind: 'scalar', key: 'path', prefix: 'path' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n ],\n uuid: rangeFields,\n email: rangeFields,\n datetime: [\n { kind: 'bool', key: 'offset', prefix: 'o' },\n { kind: 'bool', key: 'local', prefix: 'l' },\n ],\n date: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n time: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n}\n\nfunction serializeShapeField(field: ShapeField, node: SchemaNode, record: Record<string, unknown>): string {\n switch (field.kind) {\n case 'scalar':\n return `${field.prefix}:${record[field.key] ?? ''}`\n case 'bool':\n return `${field.prefix}:${record[field.key] ? 1 : 0}`\n case 'child': {\n const child = record[field.key] as SchemaNode | undefined\n return `${field.prefix}:${child ? signatureOf(child) : ''}`\n }\n case 'children': {\n const children = (record[field.key] as Array<SchemaNode> | undefined) ?? []\n return `${field.prefix}[${children.map((c) => signatureOf(c)).join(',')}]`\n }\n case 'objectProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const props = (obj.properties ?? []).map((prop) => `${prop.name}${prop.required ? '!' : '?'}${signatureOf(prop.schema)}`).join(',')\n return `p[${props}]`\n }\n case 'additionalProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n if (typeof obj.additionalProperties === 'boolean') return `ab:${obj.additionalProperties}`\n if (obj.additionalProperties) return `as:${signatureOf(obj.additionalProperties)}`\n return ''\n }\n case 'patternProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const pattern = obj.patternProperties\n ? Object.keys(obj.patternProperties)\n .sort()\n .map((key) => `${key}=${signatureOf(obj.patternProperties![key]!)}`)\n .join(',')\n : ''\n return `pp[${pattern}]`\n }\n case 'enumValues': {\n const en = node as Extract<SchemaNode, { type: 'enum' }>\n let values = ''\n if (en.namedEnumValues?.length) {\n values = en.namedEnumValues.map((entry) => `${entry.name}=${entry.primitive}:${String(entry.value)}`).join(',')\n } else if (en.enumValues?.length) {\n values = en.enumValues.map((value) => `${value === null ? 'null' : typeof value}:${String(value)}`).join(',')\n }\n return `v[${values}]`\n }\n case 'refTarget': {\n return `->${refTargetName(node as Extract<SchemaNode, { type: 'ref' }>)}`\n }\n }\n}\n\n/**\n * Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,\n * constraints, and its children's signatures.\n */\nfunction describeShape(node: SchemaNode): string {\n const flags = flagsDescriptor(node)\n const fields = SHAPE_KEYS[node.type]\n if (!fields) return `${node.type}|${flags}`\n\n const record = node as unknown as Record<string, unknown>\n const parts: Array<string> = [`${node.type}|${flags}`]\n for (const field of fields) {\n parts.push(serializeShapeField(field, node, record))\n }\n return parts.join('|')\n}\n\n/**\n * Caches the digest per node, keyed by identity. A `WeakMap` so entries die with the node, and so\n * a tree hashed during dedupe planning is not walked again when it is rewritten during streaming.\n * Reuse is safe because a signature depends only on content, and nodes are immutable once created.\n */\nconst signatureCache = new WeakMap<SchemaNode, string>()\n\n/**\n * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas\n * share a signature when they are structurally identical, ignoring documentation (`name`, `title`,\n * `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,\n * `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`\n * nodes compare by target name, which also terminates on circular shapes.\n *\n * @example Two enums with different descriptions share a signature\n * ```ts\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))\n * ```\n */\nexport function signatureOf(node: SchemaNode): string {\n const cached = signatureCache.get(node)\n if (cached !== undefined) return cached\n const signature = hash('sha256', describeShape(node), 'hex')\n signatureCache.set(node, signature)\n\n return signature\n}\n\n/**\n * Returns `true` when two schema nodes are structurally identical under shape-only equality,\n * meaning they produce the same TypeScript type.\n */\nexport function isSchemaEqual(a: SchemaNode, b: SchemaNode): boolean {\n return signatureOf(a) === signatureOf(b)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,cACd,SAC4D;CA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":3,"file":"index.cjs","names":["extractRefName","obj"],"sources":["../src/defineDialect.ts","../src/definePrinter.ts","../src/signature.ts","../src/exports.ts"],"sourcesContent":["import type { Node } from './nodes/index.ts'\n\n/**\n * The spec-specific questions a schema parser answers while turning a source document into Kubb\n * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where\n * OpenAPI, AsyncAPI, and plain JSON Schema differ.\n */\nexport type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Whether the schema is nullable.\n */\n isNullable(schema?: TSchema): boolean\n /**\n * Whether the value is a `$ref` pointer.\n */\n isReference(value?: unknown): value is TRef\n /**\n * Whether the schema carries a discriminator for polymorphism.\n */\n isDiscriminator(value?: unknown): value is TDiscriminated\n /**\n * Whether the schema is binary data, converted to a `blob` node.\n */\n isBinary(schema: TSchema): boolean\n /**\n * Resolves a local `$ref` against the document, or nullish when it cannot.\n */\n resolveRef<TResolved>(document: TDocument, ref: string): TResolved | null | undefined\n}\n\n/**\n * How a dialect collapses structurally identical schemas into shared definitions. The contract is\n * generic over the plan and context types, which the adapter supplies. The mechanics live in the\n * adapter, not here, so `@kubb/ast` carries no dedupe logic. The returned plan owns the rewriting\n * behavior, so callers interact with one object.\n */\nexport type Dedupe<TPlan = unknown, TContext = unknown> = {\n /**\n * Scans a forest of nodes and produces a plan describing which shapes to share.\n */\n plan(roots: ReadonlyArray<Node>, context: TContext): TPlan\n}\n\n/**\n * A spec adapter's dialect. `name` identifies it in logs and diagnostics, `schema` holds the\n * spec-specific schema questions the parser answers, and `dedupe` is the schema-sharing seam.\n */\nexport type DefineDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown, TDedupe extends Dedupe = Dedupe> = {\n /**\n * Identifies the dialect in logs and diagnostics.\n */\n name: string\n /**\n * The spec-specific schema behavior. See {@link SchemaDialect}.\n */\n schema: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>\n /**\n * The schema-sharing behavior. See {@link Dedupe}.\n */\n dedupe: TDedupe\n}\n\n/**\n * Types a {@link DefineDialect} for an adapter. Adds no runtime behavior and only pins the\n * dialect's type for inference.\n *\n * @example\n * ```ts\n * export const oasDialect = defineDialect({\n * name: 'oas',\n * schema: {\n * isNullable,\n * isReference,\n * isDiscriminator,\n * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',\n * resolveRef,\n * },\n * dedupe: { plan },\n * })\n * ```\n */\nexport function defineDialect<TSchema, TRef, TDiscriminated, TDocument, TDedupe extends Dedupe>(\n dialect: DefineDialect<TSchema, TRef, TDiscriminated, TDocument, TDedupe>,\n): DefineDialect<TSchema, TRef, TDiscriminated, TDocument, TDedupe> {\n return dialect\n}\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * }\n * ```\n */\ntype PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n */\n transform: (node: SchemaNode) => TOutput | null\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for one schema node type.\n *\n * Use a regular function (not an arrow function) if you need `this`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'string'> = function () {\n * return 'string'\n * }\n * ```\n */\ntype PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\ntype PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null\n}\n/**\n * Defines a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'\n *\n * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = definePrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return createPrinterFactory<SchemaNode, SchemaType, SchemaNodeByType>((node) => node.type)(build) as (options?: T['options']) => Printer<T>\n}\n\n/**\n * Generic printer factory behind `definePrinter`. Pass a `getKey` function that maps a node to its\n * handler key, and it returns a `definePrinter`-style helper for that node and key type. `definePrinter`\n * itself is this factory keyed by `node.type`.\n *\n * @example Key a printer by `node.kind` instead of `node.type`\n * ```ts\n * const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(\n * (node) => node.kind,\n * )\n * ```\n */\nexport function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | null) {\n return function <T extends PrinterFactoryOptions>(\n build: (options: T['options']) => {\n name: T['name']\n options: T['options']\n nodes: Partial<{\n [K in TKey]: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNodeByKey[K],\n ) => T['output'] | null\n }>\n print?: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNode,\n ) => T['printOutput'] | null\n },\n ): (options?: T['options']) => {\n name: T['name']\n options: T['options']\n transform: (node: TNode) => T['output'] | null\n print: (node: TNode) => T['printOutput'] | null\n } {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n transform: (node: TNode): T['output'] | null => {\n const key = getKey(node)\n if (key === null) return null\n\n const handler = nodes[key]\n\n if (!handler) return null\n\n return (handler as (this: typeof context, node: TNode) => T['output'] | null).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n transform: context.transform,\n print: (printOverride ? printOverride.bind(context) : context.transform) as (node: TNode) => T['printOutput'] | null,\n }\n }\n }\n}\n","import { hash } from 'node:crypto'\nimport type { SchemaNode } from './nodes/index.ts'\nimport { extractRefName } from './utils/index.ts'\n\n/**\n * The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.\n */\nfunction flagsDescriptor(node: SchemaNode): string {\n return `${node.primitive ?? ''};${node.format ?? ''};${node.nullable ? 1 : 0}`\n}\n\nfunction refTargetName(node: Extract<SchemaNode, { type: 'ref' }>): string {\n if (node.ref) return extractRefName(node.ref)\n return node.name ?? ''\n}\n\ntype ScalarField = { kind: 'scalar'; key: string; prefix: string }\ntype BoolField = { kind: 'bool'; key: string; prefix: string }\ntype ChildField = { kind: 'child'; key: string; prefix: string }\ntype ChildrenField = { kind: 'children'; key: string; prefix: string }\ntype ObjectPropsField = { kind: 'objectProps' }\ntype AdditionalPropsField = { kind: 'additionalProps' }\ntype PatternPropsField = { kind: 'patternProps' }\ntype EnumValuesField = { kind: 'enumValues' }\ntype RefTargetField = { kind: 'refTarget' }\n\ntype ShapeField =\n | ScalarField\n | BoolField\n | ChildField\n | ChildrenField\n | ObjectPropsField\n | AdditionalPropsField\n | PatternPropsField\n | EnumValuesField\n | RefTargetField\n\nconst arrayTupleFields: ReadonlyArray<ShapeField> = [\n { kind: 'children', key: 'items', prefix: 'i' },\n { kind: 'child', key: 'rest', prefix: 'r' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'bool', key: 'unique', prefix: 'u' },\n]\n\nconst numericFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'exclusiveMinimum', prefix: 'emn' },\n { kind: 'scalar', key: 'exclusiveMaximum', prefix: 'emx' },\n { kind: 'scalar', key: 'multipleOf', prefix: 'mo' },\n]\n\nconst rangeFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n]\n\n/**\n * Maps each node `type` to its ordered shape-contributing fields. Types absent from the map\n * (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.\n */\nconst SHAPE_KEYS: Partial<Record<SchemaNode['type'], ReadonlyArray<ShapeField>>> = {\n object: [\n { kind: 'objectProps' },\n { kind: 'additionalProps' },\n { kind: 'patternProps' },\n { kind: 'scalar', key: 'minProperties', prefix: 'mn' },\n { kind: 'scalar', key: 'maxProperties', prefix: 'mx' },\n ],\n array: arrayTupleFields,\n tuple: arrayTupleFields,\n union: [\n { kind: 'scalar', key: 'strategy', prefix: 's' },\n { kind: 'scalar', key: 'discriminatorPropertyName', prefix: 'd' },\n { kind: 'children', key: 'members', prefix: 'm' },\n ],\n intersection: [{ kind: 'children', key: 'members', prefix: 'm' }],\n enum: [{ kind: 'enumValues' }],\n ref: [{ kind: 'refTarget' }],\n string: [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'pattern', prefix: 'pt' },\n ],\n number: numericFields,\n integer: numericFields,\n bigint: numericFields,\n url: [\n { kind: 'scalar', key: 'path', prefix: 'path' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n ],\n uuid: rangeFields,\n email: rangeFields,\n datetime: [\n { kind: 'bool', key: 'offset', prefix: 'o' },\n { kind: 'bool', key: 'local', prefix: 'l' },\n ],\n date: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n time: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n}\n\nfunction serializeShapeField(field: ShapeField, node: SchemaNode, record: Record<string, unknown>): string {\n switch (field.kind) {\n case 'scalar':\n return `${field.prefix}:${record[field.key] ?? ''}`\n case 'bool':\n return `${field.prefix}:${record[field.key] ? 1 : 0}`\n case 'child': {\n const child = record[field.key] as SchemaNode | undefined\n return `${field.prefix}:${child ? signatureOf(child) : ''}`\n }\n case 'children': {\n const children = (record[field.key] as Array<SchemaNode> | undefined) ?? []\n return `${field.prefix}[${children.map((c) => signatureOf(c)).join(',')}]`\n }\n case 'objectProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const props = (obj.properties ?? []).map((prop) => `${prop.name}${prop.required ? '!' : '?'}${signatureOf(prop.schema)}`).join(',')\n return `p[${props}]`\n }\n case 'additionalProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n if (typeof obj.additionalProperties === 'boolean') return `ab:${obj.additionalProperties}`\n if (obj.additionalProperties) return `as:${signatureOf(obj.additionalProperties)}`\n return ''\n }\n case 'patternProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const pattern = obj.patternProperties\n ? Object.keys(obj.patternProperties)\n .sort()\n .map((key) => `${key}=${signatureOf(obj.patternProperties![key]!)}`)\n .join(',')\n : ''\n return `pp[${pattern}]`\n }\n case 'enumValues': {\n const en = node as Extract<SchemaNode, { type: 'enum' }>\n let values = ''\n if (en.namedEnumValues?.length) {\n values = en.namedEnumValues.map((entry) => `${entry.name}=${entry.primitive}:${String(entry.value)}`).join(',')\n } else if (en.enumValues?.length) {\n values = en.enumValues.map((value) => `${value === null ? 'null' : typeof value}:${String(value)}`).join(',')\n }\n return `v[${values}]`\n }\n case 'refTarget': {\n return `->${refTargetName(node as Extract<SchemaNode, { type: 'ref' }>)}`\n }\n }\n}\n\n/**\n * Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,\n * constraints, and its children's signatures.\n */\nfunction describeShape(node: SchemaNode): string {\n const flags = flagsDescriptor(node)\n const fields = SHAPE_KEYS[node.type]\n if (!fields) return `${node.type}|${flags}`\n\n const record = node as unknown as Record<string, unknown>\n const parts: Array<string> = [`${node.type}|${flags}`]\n for (const field of fields) {\n parts.push(serializeShapeField(field, node, record))\n }\n return parts.join('|')\n}\n\n/**\n * Caches the digest per node, keyed by identity. A `WeakMap` so entries die with the node, and so\n * a tree hashed during dedupe planning is not walked again when it is rewritten during streaming.\n * Reuse is safe because a signature depends only on content, and nodes are immutable once created.\n */\nconst signatureCache = new WeakMap<SchemaNode, string>()\n\n/**\n * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas\n * share a signature when they are structurally identical, ignoring documentation (`name`, `title`,\n * `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,\n * `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`\n * nodes compare by target name, which also terminates on circular shapes.\n *\n * @example Two enums with different descriptions share a signature\n * ```ts\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))\n * ```\n */\nexport function signatureOf(node: SchemaNode): string {\n const cached = signatureCache.get(node)\n if (cached !== undefined) return cached\n const signature = hash('sha256', describeShape(node), 'hex')\n signatureCache.set(node, signature)\n\n return signature\n}\n\n/**\n * Returns `true` when two schema nodes are structurally identical under shape-only equality,\n * meaning they produce the same TypeScript type.\n */\nexport function isSchemaEqual(a: SchemaNode, b: SchemaNode): boolean {\n return signatureOf(a) === signatureOf(b)\n}\n","export { schemaTypes } from './constants.ts'\nexport { defineDialect } from './defineDialect.ts'\nexport { isHttpOperationNode, narrowSchema } from './guards.ts'\nexport { applyMacros, composeMacros, defineMacro } from './defineMacro.ts'\nexport { defineNode } from './defineNode.ts'\nexport { optionality } from './optionality.ts'\nexport { createPrinterFactory, definePrinter } from './definePrinter.ts'\nexport { signatureOf } from './signature.ts'\nexport { collect, transform, walk } from './visitor.ts'\n\nexport * as factory from './factory.ts'\nexport * from './registry.ts'\nexport type * from './types.ts'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,cACd,SACkE;CAClE,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACuGA,SAAgB,cAAuE,OAAkE;CACvJ,OAAO,sBAAgE,SAAS,KAAK,IAAI,CAAC,CAAC,KAAK;AAClG;;;;;;;;;;;;;AAcA,SAAgB,qBAAkG,QAAsC;CACtJ,OAAO,SACL,OAyBA;EACA,QAAQ,YAAY;GAClB,MAAM,EAAE,MAAM,SAAS,iBAAiB,OAAO,OAAO,kBAAkB,MAAM,WAAY,CAAC,CAAkB;GAE7G,MAAM,UAAU;IACd,SAAS;IACT,YAAY,SAAoC;KAC9C,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zG,IAAI,GAAG,YAAY,QACxB,SAAS,GAAG,WAAW,KAAK,UAAU,GAAG,UAAU,OAAO,SAAS,OAAO,MAAM,GAAG,OAAO,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG;GAE9G,OAAO,KAAK,OAAO;EACrB;EACA,KAAK,aACH,OAAO,KAAK,cAAc,IAA4C;CAE1E;AACF;;;;;AAMA,SAAS,cAAc,MAA0B;CAC/C,MAAM,QAAQ,gBAAgB,IAAI;CAClC,MAAM,SAAS,WAAW,KAAK;CAC/B,IAAI,CAAC,QAAQ,OAAO,GAAG,KAAK,KAAK,GAAG;CAEpC,MAAM,SAAS;CACf,MAAM,QAAuB,CAAC,GAAG,KAAK,KAAK,GAAG,OAAO;CACrD,KAAK,MAAM,SAAS,QAClB,MAAM,KAAK,oBAAoB,OAAO,MAAM,MAAM,CAAC;CAErD,OAAO,MAAM,KAAK,GAAG;AACvB;;;;;;AAOA,MAAM,iCAAiB,IAAI,QAA4B;;;;;;;;;;;;;;AAevD,SAAgB,YAAY,MAA0B;CACpD,MAAM,SAAS,eAAe,IAAI,IAAI;CACtC,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,aAAA,GAAA,YAAA,KAAA,CAAiB,UAAU,cAAc,IAAI,GAAG,KAAK;CAC3D,eAAe,IAAI,MAAM,SAAS;CAElC,OAAO;AACT"}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { n as __name } from "./chunk-CNktS9qV.js";
2
- import { $ as exportDef, $t as textDef, A as IndexedAccessTypeNode, At as InferSchemaNode, B as functionParametersDef, Bt as TypeNode, C as ParameterNode, Ct as UrlSchemaNode, D as FunctionParamNode, Dt as UserPropertyNode, E as FunctionParamKind, Et as PropertyNode, Ft as ConstNode, G as FileNode, H as objectBindingPatternDef, Ht as breakDef, It as FunctionNode, J as UserFileNode, K as ImportNode, Lt as JSDocNode, M as TypeExpression, Mt as ArrowFunctionNode, N as TypeLiteralNode, Nt as BreakNode, O as FunctionParameterNode, Pt as CodeNode, Qt as jsxDef, Rt as JsxNode, S as ParameterLocation, St as UnionSchemaNode, T as parameterDef, Tt as schemaDef, U as typeLiteralDef, Ut as constDef, V as indexedAccessTypeDef, Vt as arrowFunctionDef, W as ExportNode, Zt as functionDef, _t as SchemaNode, a as InputMeta, an as NodeKind, bt as StringSchemaNode, c as inputDef, ct as DatetimeSchemaNode, d as HttpOperationNode, dt as NumberSchemaNode, en as typeDef, et as fileDef, f as OperationNode, ft as ObjectSchemaNode, g as StatusCode, gt as ScalarSchemaType, h as ResponseNode, ht as ScalarSchemaNode, i as outputDef, in as BaseNode, it as contentDef, j as ObjectBindingPatternNode, jt as ParserOptions, k as FunctionParametersNode, kt as propertyDef, l as GenericOperationNode, lt as EnumSchemaNode, m as operationDef, mt as RefSchemaNode, n as OutputNode, nn as NodeDef, nt as sourceDef, o as InputNode, ot as ArraySchemaNode, pt as PrimitiveSchemaType, q as SourceNode, rn as defineNode, rt as ContentNode, st as DateSchemaNode, t as Node, tn as DistributiveOmit, tt as importDef, u as HttpMethod, ut as IntersectionSchemaNode, v as responseDef, vt as SchemaNodeByType, x as requestBodyDef, xt as TimeSchemaNode, y as RequestBodyNode, yt as SchemaType, z as functionParameterDef, zt as TextNode } from "./index-B9cc8MBS.js";
3
- import { t as factory_d_exports } from "./factory.js";
4
- import { a as defineMacro, c as VisitorContext, d as walk, f as schemaTypes, i as composeMacros, l as collect, n as Macro, o as ParentOf, r as applyMacros, s as Visitor, t as Enforce, u as transform } from "./defineMacro-BATi7xoC.js";
5
- import { a as definePrinter, c as SchemaDialect, i as createPrinterFactory, l as defineDialect, n as PrinterFactoryOptions, o as Dedupe, r as PrinterPartial, s as Dialect, t as Printer } from "./types-BB_xgRJ3.js";
6
- import { n as OperationParamsResolver } from "./operationParams-k5CKwSWZ.js";
1
+ import { n as __name, t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
2
+ import { $ as exportDef, $t as textDef, A as IndexedAccessTypeNode, At as InferSchemaNode, B as functionParametersDef, Bt as TypeNode, C as ParameterNode, Ct as UrlSchemaNode, D as FunctionParamNode, Dt as UserPropertyNode, E as FunctionParamKind, Et as PropertyNode, Ft as ConstNode, G as FileNode, H as objectBindingPatternDef, Ht as breakDef, It as FunctionNode, J as UserFileNode, K as ImportNode, Lt as JSDocNode, M as TypeExpression, Mt as ArrowFunctionNode, N as TypeLiteralNode, Nt as BreakNode, O as FunctionParameterNode, Pt as CodeNode, Qt as jsxDef, Rt as JsxNode, S as ParameterLocation, St as UnionSchemaNode, T as parameterDef, Tt as schemaDef, U as typeLiteralDef, Ut as constDef, V as indexedAccessTypeDef, Vt as arrowFunctionDef, W as ExportNode, Zt as functionDef, _t as SchemaNode, a as InputMeta, an as NodeKind, bt as StringSchemaNode, c as inputDef, ct as DatetimeSchemaNode, d as HttpOperationNode, dt as NumberSchemaNode, en as typeDef, et as fileDef, f as OperationNode, ft as ObjectSchemaNode, g as StatusCode, gt as ScalarSchemaType, h as ResponseNode, ht as ScalarSchemaNode, i as outputDef, in as BaseNode, it as contentDef, j as ObjectBindingPatternNode, jt as ParserOptions, k as FunctionParametersNode, kt as propertyDef, l as GenericOperationNode, lt as EnumSchemaNode, m as operationDef, mt as RefSchemaNode, n as OutputNode, nn as NodeDef, nt as sourceDef, o as InputNode, ot as ArraySchemaNode, pt as PrimitiveSchemaType, q as SourceNode, rn as defineNode, rt as ContentNode, st as DateSchemaNode, t as Node, tn as DistributiveOmit, tt as importDef, u as HttpMethod, ut as IntersectionSchemaNode, v as responseDef, vt as SchemaNodeByType, x as requestBodyDef, xt as TimeSchemaNode, y as RequestBodyNode, yt as SchemaType, z as functionParameterDef, zt as TextNode } from "./index-BKD4drsX.js";
3
+ import { t as factory_d_exports } from "./factory-wJLzHeXT.js";
4
+ import { a as defineMacro, c as VisitorContext, d as walk, f as schemaTypes, i as composeMacros, l as collect, n as Macro, o as ParentOf, r as applyMacros, s as Visitor, t as Enforce, u as transform } from "./defineMacro-B7qm3zTd.js";
5
+ import { a as definePrinter, c as SchemaDialect, i as createPrinterFactory, l as defineDialect, n as PrinterFactoryOptions, o as Dedupe, r as PrinterPartial, s as DefineDialect, t as Printer } from "./types-BP9BZoq-.js";
6
+ import { n as OperationParamsResolver } from "./operationParams-ByVfpYr7.js";
7
7
 
8
8
  //#region src/guards.d.ts
9
9
  /**
@@ -56,18 +56,7 @@ declare function signatureOf(node: SchemaNode): string;
56
56
  * Every node definition. Adding a node means adding its `defineNode` to one
57
57
  * `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
58
58
  */
59
- declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<InputNode<false>, Partial<Omit<InputNode<false>, "kind">>> | NodeDef<OutputNode, Partial<Omit<OutputNode, "kind">>> | NodeDef<RequestBodyNode, Omit<RequestBodyNode, "kind">> | NodeDef<OperationNode, {
60
- [key: string]: unknown;
61
- operationId: string;
62
- method?: HttpOperationNode["method"];
63
- path?: HttpOperationNode["path"];
64
- requestBody?: Omit<RequestBodyNode, "kind">;
65
- }> | NodeDef<ContentNode, Omit<ContentNode, "kind">> | NodeDef<ResponseNode, Pick<ResponseNode, "statusCode"> & Partial<Omit<ResponseNode, "kind" | "content" | "statusCode">> & {
66
- content?: Array<ContentNode>;
67
- schema?: SchemaNode;
68
- mediaType?: string | null;
69
- keysToOmit?: Array<string> | null;
70
- }> | NodeDef<SchemaNode, (Omit<ObjectSchemaNode, "kind" | "primitive" | "properties"> & {
59
+ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<SchemaNode, (Omit<ObjectSchemaNode, "kind" | "primitive" | "properties"> & {
71
60
  properties?: Array<PropertyNode>;
72
61
  primitive?: "object";
73
62
  }) | DistributiveOmit<ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | (BaseNode & {
@@ -123,7 +112,18 @@ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<Input
123
112
  format?: string;
124
113
  } & {
125
114
  type: "ipv6";
126
- }) | ScalarSchemaNode, "kind">> | NodeDef<ParameterNode, Pick<ParameterNode, "name" | "schema" | "in"> & Partial<Omit<ParameterNode, "kind" | "name" | "schema" | "in">>> | NodeDef<ObjectBindingPatternNode, Pick<ObjectBindingPatternNode, "elements">> | NodeDef<TypeLiteralNode, Pick<TypeLiteralNode, "members">> | NodeDef<FunctionParameterNode, {
115
+ }) | ScalarSchemaNode, "kind">> | NodeDef<RequestBodyNode, Omit<RequestBodyNode, "kind">> | NodeDef<OutputNode, Partial<Omit<OutputNode, "kind">>> | NodeDef<ContentNode, Omit<ContentNode, "kind">> | NodeDef<ResponseNode, Pick<ResponseNode, "statusCode"> & Partial<Omit<ResponseNode, "kind" | "content" | "statusCode">> & {
116
+ content?: Array<ContentNode>;
117
+ schema?: SchemaNode;
118
+ mediaType?: string | null;
119
+ keysToOmit?: Array<string> | null;
120
+ }> | NodeDef<ParameterNode, Pick<ParameterNode, "name" | "schema" | "in"> & Partial<Omit<ParameterNode, "kind" | "name" | "schema" | "in">>> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<OperationNode, {
121
+ [key: string]: unknown;
122
+ operationId: string;
123
+ method?: HttpOperationNode["method"];
124
+ path?: HttpOperationNode["path"];
125
+ requestBody?: Omit<RequestBodyNode, "kind">;
126
+ }> | NodeDef<TypeLiteralNode, Pick<TypeLiteralNode, "members">> | NodeDef<IndexedAccessTypeNode, Omit<IndexedAccessTypeNode, "kind">> | NodeDef<ObjectBindingPatternNode, Pick<ObjectBindingPatternNode, "elements">> | NodeDef<FunctionParameterNode, {
127
127
  name: string;
128
128
  type?: TypeExpression;
129
129
  optional?: boolean;
@@ -137,7 +137,10 @@ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<Input
137
137
  }>;
138
138
  optional?: boolean;
139
139
  default?: string;
140
- }> | NodeDef<FunctionParametersNode, Partial<Omit<FunctionParametersNode, "kind">>> | NodeDef<IndexedAccessTypeNode, Omit<IndexedAccessTypeNode, "kind">> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[];
140
+ }> | NodeDef<FunctionParametersNode, Partial<Omit<FunctionParametersNode, "kind">>> | NodeDef<InputNode<false>, Partial<Omit<InputNode<false>, "kind">>>)[];
141
+ declare namespace exports_d_exports {
142
+ export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, Dedupe, DefineDialect, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, FunctionParamKind, FunctionParamNode, FunctionParameterNode, FunctionParametersNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, IndexedAccessTypeNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectBindingPatternNode, ObjectSchemaNode, OperationNode, OperationParamsResolver, OutputNode, ParameterLocation, ParameterNode, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaDialect, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeExpression, TypeLiteralNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, composeMacros, constDef, contentDef, createPrinterFactory, defineDialect, defineMacro, defineNode, definePrinter, exportDef, factory_d_exports as factory, fileDef, functionDef, functionParameterDef, functionParametersDef, importDef, indexedAccessTypeDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, objectBindingPatternDef, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, signatureOf, sourceDef, textDef, transform, typeDef, typeLiteralDef, walk };
143
+ }
141
144
  //#endregion
142
- export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type Dedupe, type Dialect, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type FunctionParamKind, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type IndexedAccessTypeNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectBindingPatternNode, type ObjectSchemaNode, type OperationNode, type OperationParamsResolver, type OutputNode, type ParameterLocation, type ParameterNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaDialect, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeExpression, type TypeLiteralNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, composeMacros, constDef, contentDef, createPrinterFactory, defineDialect, defineMacro, defineNode, definePrinter, exportDef, factory_d_exports as factory, fileDef, functionDef, functionParameterDef, functionParametersDef, importDef, indexedAccessTypeDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, objectBindingPatternDef, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, signatureOf, sourceDef, textDef, transform, typeDef, typeLiteralDef, walk };
145
+ export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type Dedupe, type DefineDialect, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type FunctionParamKind, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type IndexedAccessTypeNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectBindingPatternNode, type ObjectSchemaNode, type OperationNode, type OperationParamsResolver, type OutputNode, type ParameterLocation, type ParameterNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaDialect, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeExpression, type TypeLiteralNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, collect, composeMacros, constDef, contentDef, createPrinterFactory, defineDialect, defineMacro, defineNode, definePrinter, exportDef, factory_d_exports as factory, fileDef, functionDef, functionParameterDef, functionParametersDef, importDef, indexedAccessTypeDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, objectBindingPatternDef, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, signatureOf, sourceDef, textDef, transform, typeDef, typeLiteralDef, walk };
143
146
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import "./chunk-CNktS9qV.js";
2
- import { c as collect, d as walk, f as nodeDefs, g as schemaTypes, m as narrowSchema, p as isHttpOperationNode, r as extractRefName, u as transform } from "./refs-BjNDuCBD.js";
3
- import { $ as textDef, C as functionParameterDef, D as typeLiteralDef, E as objectBindingPatternDef, F as sourceDef, H as breakDef, M as exportDef, N as fileDef, P as importDef, Q as jsxDef, T as indexedAccessTypeDef, U as constDef, V as arrowFunctionDef, Z as functionDef, _ as inputDef, c as parameterDef, d as outputDef, et as typeDef, h as requestBodyDef, i as responseDef, l as optionality, n as schemaDef, o as propertyDef, p as operationDef, tt as defineNode, w as functionParametersDef, z as contentDef } from "./schema-Cbnxmz4b.js";
4
- import "./utils-DaXkewb1.js";
5
- import { n as composeMacros, r as defineMacro, t as applyMacros } from "./defineMacro-Shz8f6SG.js";
1
+ import { t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
2
+ import { c as collect, d as walk, f as nodeDefs, g as schemaTypes, m as narrowSchema, p as isHttpOperationNode, r as extractRefName, u as transform } from "./refs-Dx6U5LoE.js";
3
+ import { $ as textDef, C as functionParameterDef, D as typeLiteralDef, E as objectBindingPatternDef, F as sourceDef, H as breakDef, M as exportDef, N as fileDef, P as importDef, Q as jsxDef, T as indexedAccessTypeDef, U as constDef, V as arrowFunctionDef, Z as functionDef, _ as inputDef, c as parameterDef, d as outputDef, et as typeDef, h as requestBodyDef, i as responseDef, l as optionality, n as schemaDef, o as propertyDef, p as operationDef, tt as defineNode, w as functionParametersDef, z as contentDef } from "./schema-YNbOtTCM.js";
4
+ import "./utils-BJi0y-xg.js";
5
+ import { n as composeMacros, r as defineMacro, t as applyMacros } from "./defineMacro-B76LsJwO.js";
6
6
  import { t as factory_exports } from "./factory.js";
7
7
  import { hash } from "node:crypto";
8
- //#region src/dialect.ts
8
+ //#region src/defineDialect.ts
9
9
  /**
10
- * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the
10
+ * Types a {@link DefineDialect} for an adapter. Adds no runtime behavior and only pins the
11
11
  * dialect's type for inference.
12
12
  *
13
13
  * @example
@@ -360,6 +360,52 @@ function signatureOf(node) {
360
360
  return signature;
361
361
  }
362
362
  //#endregion
363
- export { applyMacros, arrowFunctionDef, breakDef, collect, composeMacros, constDef, contentDef, createPrinterFactory, defineDialect, defineMacro, defineNode, definePrinter, exportDef, factory_exports as factory, fileDef, functionDef, functionParameterDef, functionParametersDef, importDef, indexedAccessTypeDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, objectBindingPatternDef, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, signatureOf, sourceDef, textDef, transform, typeDef, typeLiteralDef, walk };
363
+ //#region src/exports.ts
364
+ var exports_exports = /* @__PURE__ */ __exportAll({
365
+ applyMacros: () => applyMacros,
366
+ arrowFunctionDef: () => arrowFunctionDef,
367
+ breakDef: () => breakDef,
368
+ collect: () => collect,
369
+ composeMacros: () => composeMacros,
370
+ constDef: () => constDef,
371
+ contentDef: () => contentDef,
372
+ createPrinterFactory: () => createPrinterFactory,
373
+ defineDialect: () => defineDialect,
374
+ defineMacro: () => defineMacro,
375
+ defineNode: () => defineNode,
376
+ definePrinter: () => definePrinter,
377
+ exportDef: () => exportDef,
378
+ factory: () => factory_exports,
379
+ fileDef: () => fileDef,
380
+ functionDef: () => functionDef,
381
+ functionParameterDef: () => functionParameterDef,
382
+ functionParametersDef: () => functionParametersDef,
383
+ importDef: () => importDef,
384
+ indexedAccessTypeDef: () => indexedAccessTypeDef,
385
+ inputDef: () => inputDef,
386
+ isHttpOperationNode: () => isHttpOperationNode,
387
+ jsxDef: () => jsxDef,
388
+ narrowSchema: () => narrowSchema,
389
+ nodeDefs: () => nodeDefs,
390
+ objectBindingPatternDef: () => objectBindingPatternDef,
391
+ operationDef: () => operationDef,
392
+ optionality: () => optionality,
393
+ outputDef: () => outputDef,
394
+ parameterDef: () => parameterDef,
395
+ propertyDef: () => propertyDef,
396
+ requestBodyDef: () => requestBodyDef,
397
+ responseDef: () => responseDef,
398
+ schemaDef: () => schemaDef,
399
+ schemaTypes: () => schemaTypes,
400
+ signatureOf: () => signatureOf,
401
+ sourceDef: () => sourceDef,
402
+ textDef: () => textDef,
403
+ transform: () => transform,
404
+ typeDef: () => typeDef,
405
+ typeLiteralDef: () => typeLiteralDef,
406
+ walk: () => walk
407
+ });
408
+ //#endregion
409
+ export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, collect, composeMacros, constDef, contentDef, createPrinterFactory, defineDialect, defineMacro, defineNode, definePrinter, exportDef, factory_exports as factory, fileDef, functionDef, functionParameterDef, functionParametersDef, importDef, indexedAccessTypeDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, objectBindingPatternDef, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, signatureOf, sourceDef, textDef, transform, typeDef, typeLiteralDef, walk };
364
410
 
365
411
  //# sourceMappingURL=index.js.map