@kubb/ast 5.0.0-beta.62 → 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 (92) hide show
  1. package/dist/{defineMacro-CNkUpxia.js → defineMacro-B76LsJwO.js} +4 -4
  2. package/dist/defineMacro-B76LsJwO.js.map +1 -0
  3. package/dist/{defineMacro-Vw-xQvq7.d.ts → defineMacro-B7qm3zTd.d.ts} +5 -6
  4. package/dist/{defineMacro-BryDiuQl.cjs → defineMacro-CEZHaCXE.cjs} +5 -5
  5. package/dist/defineMacro-CEZHaCXE.cjs.map +1 -0
  6. package/dist/factory-wJLzHeXT.d.ts +27 -0
  7. package/dist/factory.cjs +56 -56
  8. package/dist/factory.cjs.map +1 -1
  9. package/dist/factory.d.ts +3 -27
  10. package/dist/factory.js +6 -6
  11. package/dist/factory.js.map +1 -1
  12. package/dist/{index-CTaN_ee_.d.ts → index-BKD4drsX.d.ts} +47 -114
  13. package/dist/index.cjs +193 -270
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +31 -21
  16. package/dist/index.js +154 -236
  17. package/dist/index.js.map +1 -1
  18. package/dist/macros.cjs +12 -12
  19. package/dist/macros.cjs.map +1 -1
  20. package/dist/macros.d.ts +3 -3
  21. package/dist/macros.js +5 -5
  22. package/dist/macros.js.map +1 -1
  23. package/dist/{operationParams-B44p6EQy.d.ts → operationParams-ByVfpYr7.d.ts} +10 -3
  24. package/dist/{visitor-DepQEKyp.js → refs-Dx6U5LoE.js} +116 -121
  25. package/dist/refs-Dx6U5LoE.js.map +1 -0
  26. package/dist/{visitor-B7Zlnp4c.cjs → refs-u5SDdyV7.cjs} +139 -144
  27. package/dist/refs-u5SDdyV7.cjs.map +1 -0
  28. package/dist/{response-BeG6hq2D.cjs → schema-BkvrrOAr.cjs} +171 -153
  29. package/dist/schema-BkvrrOAr.cjs.map +1 -0
  30. package/dist/{response-Rd1uisM1.js → schema-YNbOtTCM.js} +167 -155
  31. package/dist/schema-YNbOtTCM.js.map +1 -0
  32. package/dist/{types-DQTgVSwE.d.ts → types-BP9BZoq-.d.ts} +56 -80
  33. package/dist/types.d.ts +5 -5
  34. package/dist/{utils-DW9rnfsD.js → utils-BJi0y-xg.js} +57 -50
  35. package/dist/utils-BJi0y-xg.js.map +1 -0
  36. package/dist/{utils-BDI3kXlb.cjs → utils-CEepwqmb.cjs} +74 -67
  37. package/dist/utils-CEepwqmb.cjs.map +1 -0
  38. package/dist/utils.cjs +11 -11
  39. package/dist/utils.d.ts +45 -30
  40. package/dist/utils.js +3 -3
  41. package/package.json +1 -2
  42. package/dist/defineMacro-BryDiuQl.cjs.map +0 -1
  43. package/dist/defineMacro-CNkUpxia.js.map +0 -1
  44. package/dist/response-BeG6hq2D.cjs.map +0 -1
  45. package/dist/response-Rd1uisM1.js.map +0 -1
  46. package/dist/utils-BDI3kXlb.cjs.map +0 -1
  47. package/dist/utils-DW9rnfsD.js.map +0 -1
  48. package/dist/visitor-B7Zlnp4c.cjs.map +0 -1
  49. package/dist/visitor-DepQEKyp.js.map +0 -1
  50. package/src/constants.ts +0 -153
  51. package/src/dedupe.ts +0 -231
  52. package/src/defineMacro.ts +0 -139
  53. package/src/defineNode.ts +0 -105
  54. package/src/definePrinter.ts +0 -256
  55. package/src/dialect.ts +0 -76
  56. package/src/factory.ts +0 -44
  57. package/src/guards.ts +0 -28
  58. package/src/index.ts +0 -13
  59. package/src/infer.ts +0 -132
  60. package/src/macros/index.ts +0 -3
  61. package/src/macros/macroDiscriminatorEnum.ts +0 -50
  62. package/src/macros/macroEnumName.ts +0 -33
  63. package/src/macros/macroSimplifyUnion.ts +0 -60
  64. package/src/nodes/base.ts +0 -49
  65. package/src/nodes/code.ts +0 -352
  66. package/src/nodes/content.ts +0 -51
  67. package/src/nodes/file.ts +0 -379
  68. package/src/nodes/function.ts +0 -283
  69. package/src/nodes/index.ts +0 -93
  70. package/src/nodes/input.ts +0 -144
  71. package/src/nodes/operation.ts +0 -165
  72. package/src/nodes/output.ts +0 -49
  73. package/src/nodes/parameter.ts +0 -71
  74. package/src/nodes/property.ts +0 -67
  75. package/src/nodes/requestBody.ts +0 -54
  76. package/src/nodes/response.ts +0 -173
  77. package/src/nodes/schema.ts +0 -732
  78. package/src/registry.ts +0 -75
  79. package/src/signature.ts +0 -207
  80. package/src/types.ts +0 -9
  81. package/src/utils/codegen.ts +0 -104
  82. package/src/utils/extractStringsFromNodes.ts +0 -35
  83. package/src/utils/fileMerge.ts +0 -184
  84. package/src/utils/index.ts +0 -11
  85. package/src/utils/operationParams.ts +0 -353
  86. package/src/utils/refs.ts +0 -138
  87. package/src/utils/schemaGraph.ts +0 -169
  88. package/src/utils/schemaMerge.ts +0 -34
  89. package/src/utils/schemaTraversal.ts +0 -86
  90. package/src/utils/strings.ts +0 -139
  91. package/src/visitor.ts +0 -519
  92. /package/dist/{chunk-CNktS9qV.js → rolldown-runtime-CNktS9qV.js} +0 -0
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, cn as defineDialect, 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, on as Dialect, ot as ArraySchemaNode, pt as PrimitiveSchemaType, q as SourceNode, rn as defineNode, rt as ContentNode, sn as SchemaDialect, 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-CTaN_ee_.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-Vw-xQvq7.js";
5
- import { a as definePrinter, c as DedupePlan, i as createPrinterFactory, l as applyDedupe, n as PrinterFactoryOptions, o as DedupeCanonical, r as PrinterPartial, s as DedupeLookups, t as Printer, u as buildDedupePlan } from "./types-DQTgVSwE.js";
6
- import { n as OperationParamsResolver } from "./operationParams-B44p6EQy.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
  /**
@@ -28,6 +28,13 @@ declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | u
28
28
  */
29
29
  declare function isHttpOperationNode(node: OperationNode): node is HttpOperationNode;
30
30
  //#endregion
31
+ //#region src/optionality.d.ts
32
+ /**
33
+ * Generic JSON Schema optionality: a non-required field is optional, and a
34
+ * non-required nullable field is nullish.
35
+ */
36
+ declare function optionality(schema: SchemaNode, required: boolean): SchemaNode;
37
+ //#endregion
31
38
  //#region src/signature.d.ts
32
39
  /**
33
40
  * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas
@@ -49,18 +56,7 @@ declare function signatureOf(node: SchemaNode): string;
49
56
  * Every node definition. Adding a node means adding its `defineNode` to one
50
57
  * `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
51
58
  */
52
- 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, {
53
- [key: string]: unknown;
54
- operationId: string;
55
- method?: HttpOperationNode["method"];
56
- path?: HttpOperationNode["path"];
57
- requestBody?: Omit<RequestBodyNode, "kind">;
58
- }> | NodeDef<ContentNode, Omit<ContentNode, "kind">> | NodeDef<ResponseNode, Pick<ResponseNode, "statusCode"> & Partial<Omit<ResponseNode, "kind" | "content" | "statusCode">> & {
59
- content?: Array<ContentNode>;
60
- schema?: SchemaNode;
61
- mediaType?: string | null;
62
- keysToOmit?: Array<string> | null;
63
- }> | NodeDef<SchemaNode, (Omit<ObjectSchemaNode, "kind" | "primitive" | "properties"> & {
59
+ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<SchemaNode, (Omit<ObjectSchemaNode, "kind" | "primitive" | "properties"> & {
64
60
  properties?: Array<PropertyNode>;
65
61
  primitive?: "object";
66
62
  }) | DistributiveOmit<ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | (BaseNode & {
@@ -116,7 +112,18 @@ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<Input
116
112
  format?: string;
117
113
  } & {
118
114
  type: "ipv6";
119
- }) | 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, {
120
127
  name: string;
121
128
  type?: TypeExpression;
122
129
  optional?: boolean;
@@ -130,7 +137,10 @@ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<Input
130
137
  }>;
131
138
  optional?: boolean;
132
139
  default?: string;
133
- }> | 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
+ }
134
144
  //#endregion
135
- export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type DedupeCanonical, type DedupeLookups, type DedupePlan, 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, applyDedupe, applyMacros, arrowFunctionDef, breakDef, buildDedupePlan, 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, 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 };
136
146
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,10 +1,113 @@
1
- import "./chunk-CNktS9qV.js";
2
- import { a as nodeDefs, c as extractRefName, g as schemaTypes, i as walk, m as narrowSchema, n as collectLazy, p as isHttpOperationNode, r as transform, t as collect } from "./visitor-DepQEKyp.js";
3
- import { $ as schemaDef, A as fileDef, C as objectBindingPatternDef, F as arrowFunctionDef, G as functionDef, I as breakDef, J as typeDef, K as jsxDef, L as constDef, M as sourceDef, N as contentDef, Q as createSchema, S as indexedAccessTypeDef, b as functionParameterDef, c as outputDef, et as defineNode, f as requestBodyDef, i as propertyDef, j as importDef, k as exportDef, m as inputDef, n as responseDef, o as parameterDef, q as textDef, u as operationDef, w as typeLiteralDef, x as functionParametersDef } from "./response-Rd1uisM1.js";
4
- import "./utils-DW9rnfsD.js";
5
- import { n as composeMacros, r as defineMacro, t as applyMacros } from "./defineMacro-CNkUpxia.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/defineDialect.ts
9
+ /**
10
+ * Types a {@link DefineDialect} for an adapter. Adds no runtime behavior and only pins the
11
+ * dialect's type for inference.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * export const oasDialect = defineDialect({
16
+ * name: 'oas',
17
+ * schema: {
18
+ * isNullable,
19
+ * isReference,
20
+ * isDiscriminator,
21
+ * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',
22
+ * resolveRef,
23
+ * },
24
+ * dedupe: { plan },
25
+ * })
26
+ * ```
27
+ */
28
+ function defineDialect(dialect) {
29
+ return dialect;
30
+ }
31
+ //#endregion
32
+ //#region src/definePrinter.ts
33
+ /**
34
+ * Defines a schema printer: a function that takes a `SchemaNode` and emits
35
+ * code in your target language. Each plugin that produces code from schemas
36
+ * (TypeScript types, Zod schemas, Faker factories) ships a printer built
37
+ * with this helper.
38
+ *
39
+ * The builder receives resolved options and returns:
40
+ *
41
+ * - `name` unique identifier for the printer.
42
+ * - `options` stored on the returned printer instance.
43
+ * - `nodes` map of `SchemaType` → handler. Handlers return the rendered
44
+ * output (a string, a TypeScript AST node, ...) for that schema type.
45
+ * - `print` (optional), top-level override exposed as `printer.print`.
46
+ * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
47
+ *
48
+ * Without a `print` override, `printer.print` falls back to `printer.transform`
49
+ * (the node-level dispatcher).
50
+ *
51
+ * @example Tiny Zod printer
52
+ * ```ts
53
+ * import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'
54
+ *
55
+ * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
56
+ *
57
+ * export const zodPrinter = definePrinter<PrinterZod>((options) => ({
58
+ * name: 'zod',
59
+ * options: { strict: options.strict ?? true },
60
+ * nodes: {
61
+ * string: () => 'z.string()',
62
+ * object(node) {
63
+ * const props = node.properties
64
+ * .map((p) => `${p.name}: ${this.transform(p.schema)}`)
65
+ * .join(', ')
66
+ * return `z.object({ ${props} })`
67
+ * },
68
+ * },
69
+ * }))
70
+ * ```
71
+ */
72
+ function definePrinter(build) {
73
+ return createPrinterFactory((node) => node.type)(build);
74
+ }
75
+ /**
76
+ * Generic printer factory behind `definePrinter`. Pass a `getKey` function that maps a node to its
77
+ * handler key, and it returns a `definePrinter`-style helper for that node and key type. `definePrinter`
78
+ * itself is this factory keyed by `node.type`.
79
+ *
80
+ * @example Key a printer by `node.kind` instead of `node.type`
81
+ * ```ts
82
+ * const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(
83
+ * (node) => node.kind,
84
+ * )
85
+ * ```
86
+ */
87
+ function createPrinterFactory(getKey) {
88
+ return function(build) {
89
+ return (options) => {
90
+ const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? {});
91
+ const context = {
92
+ options: resolvedOptions,
93
+ transform: (node) => {
94
+ const key = getKey(node);
95
+ if (key === null) return null;
96
+ const handler = nodes[key];
97
+ if (!handler) return null;
98
+ return handler.call(context, node);
99
+ }
100
+ };
101
+ return {
102
+ name,
103
+ options: resolvedOptions,
104
+ transform: context.transform,
105
+ print: printOverride ? printOverride.bind(context) : context.transform
106
+ };
107
+ };
108
+ };
109
+ }
110
+ //#endregion
8
111
  //#region src/signature.ts
9
112
  /**
10
113
  * The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.
@@ -257,237 +360,52 @@ function signatureOf(node) {
257
360
  return signature;
258
361
  }
259
362
  //#endregion
260
- //#region src/dedupe.ts
261
- /**
262
- * Builds the shared `ref` replacement for a duplicate occurrence, carrying the
263
- * usage-slot and documentation fields that are not part of the canonical type.
264
- */
265
- function createRefNode(node, canonical) {
266
- return createSchema({
267
- type: "ref",
268
- name: canonical.name,
269
- ref: canonical.ref,
270
- optional: node.optional,
271
- nullish: node.nullish,
272
- readOnly: node.readOnly,
273
- writeOnly: node.writeOnly,
274
- deprecated: node.deprecated,
275
- description: node.description,
276
- default: node.default,
277
- example: node.example
278
- });
279
- }
280
- function applyDedupe(node, plan, skipRootMatch = false) {
281
- const { canonicalBySignature, aliasNames } = plan;
282
- if (canonicalBySignature.size === 0 && aliasNames.size === 0) return node;
283
- const root = node;
284
- return transform(node, { schema(schemaNode) {
285
- if (schemaNode.type === "ref") {
286
- const target = schemaNode.ref ? extractRefName(schemaNode.ref) : schemaNode.name;
287
- const canonical = target ? aliasNames.get(target) : void 0;
288
- return canonical ? {
289
- ...schemaNode,
290
- name: canonical.name,
291
- ref: canonical.ref
292
- } : void 0;
293
- }
294
- const signature = signatureOf(schemaNode);
295
- if (skipRootMatch && schemaNode === root) return void 0;
296
- const canonical = canonicalBySignature.get(signature);
297
- if (!canonical) return void 0;
298
- return createRefNode(schemaNode, canonical);
299
- } });
300
- }
301
- /**
302
- * Strips usage-slot flags from a hoisted definition and applies its canonical name.
303
- * A standalone definition is never optional, so `optional`/`nullish` are cleared.
304
- */
305
- function cleanDefinition(node, name) {
306
- return {
307
- ...node,
308
- name,
309
- optional: void 0,
310
- nullish: void 0
311
- };
312
- }
313
- /**
314
- * Scans a forest of schema and operation nodes and produces a {@link DedupePlan}.
315
- *
316
- * A shape that occurs at least `minOccurrences` times is deduplicated: if any occurrence
317
- * is a named top-level schema, the first one becomes the canonical (so other top-level
318
- * duplicates and inline copies turn into references to it). Every other top-level name with
319
- * the same content is recorded in `aliasNames`, so refs to it can be repointed at the
320
- * canonical. Otherwise a new definition is hoisted using `nameFor`. The plan is then applied
321
- * per node with {@link applyDedupe}.
322
- *
323
- * @example
324
- * ```ts
325
- * const plan = buildDedupePlan([...schemaNodes, ...operationNodes], {
326
- * isCandidate: (node) => node.type === 'enum' || node.type === 'object',
327
- * nameFor: (node) => node.name ?? null,
328
- * refFor: (name) => `#/components/schemas/${name}`,
329
- * })
330
- * ```
331
- */
332
- function buildDedupePlan(roots, options) {
333
- const { isCandidate, nameFor, refFor, minOccurrences = 2 } = options;
334
- const topLevelNodes = /* @__PURE__ */ new Set();
335
- const groups = /* @__PURE__ */ new Map();
336
- function record(schemaNode) {
337
- if (!isCandidate(schemaNode)) return;
338
- const signature = signatureOf(schemaNode);
339
- const isTopLevel = topLevelNodes.has(schemaNode) && !!schemaNode.name;
340
- const group = groups.get(signature);
341
- if (group) {
342
- group.count++;
343
- if (isTopLevel) group.topLevelNames.push(schemaNode.name);
344
- } else groups.set(signature, {
345
- count: 1,
346
- representative: schemaNode,
347
- topLevelNames: isTopLevel ? [schemaNode.name] : []
348
- });
349
- }
350
- for (const root of roots) {
351
- if (root.kind === "Schema") topLevelNodes.add(root);
352
- for (const schemaNode of collectLazy(root, { schema: (node) => node })) record(schemaNode);
353
- }
354
- const canonicalBySignature = /* @__PURE__ */ new Map();
355
- const aliasNames = /* @__PURE__ */ new Map();
356
- const pendingHoists = [];
357
- for (const [signature, group] of groups) {
358
- if (group.count < minOccurrences) continue;
359
- const [firstName, ...duplicateNames] = group.topLevelNames;
360
- if (firstName) {
361
- const canonical = {
362
- name: firstName,
363
- ref: refFor(firstName)
364
- };
365
- canonicalBySignature.set(signature, canonical);
366
- for (const duplicate of duplicateNames) aliasNames.set(duplicate, canonical);
367
- continue;
368
- }
369
- const name = nameFor(group.representative, signature);
370
- if (!name) continue;
371
- canonicalBySignature.set(signature, {
372
- name,
373
- ref: refFor(name)
374
- });
375
- pendingHoists.push({
376
- name,
377
- representative: group.representative
378
- });
379
- }
380
- return {
381
- canonicalBySignature,
382
- aliasNames,
383
- hoisted: pendingHoists.map(({ name, representative }) => cleanDefinition(applyDedupe(representative, {
384
- canonicalBySignature,
385
- aliasNames
386
- }, true), name))
387
- };
388
- }
389
- //#endregion
390
- //#region src/dialect.ts
391
- /**
392
- * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the
393
- * dialect's type for inference.
394
- *
395
- * @example
396
- * ```ts
397
- * export const oasDialect = defineDialect({
398
- * name: 'oas',
399
- * schema: {
400
- * isNullable,
401
- * isReference,
402
- * isDiscriminator,
403
- * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',
404
- * resolveRef,
405
- * optionality,
406
- * },
407
- * })
408
- * ```
409
- */
410
- function defineDialect(dialect) {
411
- return dialect;
412
- }
413
- //#endregion
414
- //#region src/definePrinter.ts
415
- /**
416
- * Defines a schema printer: a function that takes a `SchemaNode` and emits
417
- * code in your target language. Each plugin that produces code from schemas
418
- * (TypeScript types, Zod schemas, Faker factories) ships a printer built
419
- * with this helper.
420
- *
421
- * The builder receives resolved options and returns:
422
- *
423
- * - `name` unique identifier for the printer.
424
- * - `options` stored on the returned printer instance.
425
- * - `nodes` map of `SchemaType` → handler. Handlers return the rendered
426
- * output (a string, a TypeScript AST node, ...) for that schema type.
427
- * - `print` (optional), top-level override exposed as `printer.print`.
428
- * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
429
- *
430
- * Without a `print` override, `printer.print` falls back to `printer.transform`
431
- * (the node-level dispatcher).
432
- *
433
- * @example Tiny Zod printer
434
- * ```ts
435
- * import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'
436
- *
437
- * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
438
- *
439
- * export const zodPrinter = definePrinter<PrinterZod>((options) => ({
440
- * name: 'zod',
441
- * options: { strict: options.strict ?? true },
442
- * nodes: {
443
- * string: () => 'z.string()',
444
- * object(node) {
445
- * const props = node.properties
446
- * .map((p) => `${p.name}: ${this.transform(p.schema)}`)
447
- * .join(', ')
448
- * return `z.object({ ${props} })`
449
- * },
450
- * },
451
- * }))
452
- * ```
453
- */
454
- function definePrinter(build) {
455
- return createPrinterFactory((node) => node.type)(build);
456
- }
457
- /**
458
- * Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.
459
- *
460
- * @example
461
- * ```ts
462
- * export const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(
463
- * (node) => node.kind,
464
- * )
465
- * ```
466
- */
467
- function createPrinterFactory(getKey) {
468
- return function(build) {
469
- return (options) => {
470
- const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? {});
471
- const context = {
472
- options: resolvedOptions,
473
- transform: (node) => {
474
- const key = getKey(node);
475
- if (key === null) return null;
476
- const handler = nodes[key];
477
- if (!handler) return null;
478
- return handler.call(context, node);
479
- }
480
- };
481
- return {
482
- name,
483
- options: resolvedOptions,
484
- transform: context.transform,
485
- print: printOverride ? printOverride.bind(context) : context.transform
486
- };
487
- };
488
- };
489
- }
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
+ });
490
408
  //#endregion
491
- export { applyDedupe, applyMacros, arrowFunctionDef, breakDef, buildDedupePlan, 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, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, signatureOf, sourceDef, textDef, transform, typeDef, typeLiteralDef, walk };
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 };
492
410
 
493
411
  //# sourceMappingURL=index.js.map