@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
@@ -54,7 +54,7 @@ const visitorKeys = [
54
54
  * Builds a type guard that matches nodes of the given `kind`.
55
55
  */
56
56
  function isKind(kind) {
57
- return (node) => node.kind === kind;
57
+ return (node) => node?.kind === kind;
58
58
  }
59
59
  /**
60
60
  * Defines a node once and derives its `create` builder, `is` guard, and traversal
@@ -79,8 +79,8 @@ function isKind(kind) {
79
79
  */
80
80
  function defineNode(config) {
81
81
  const { kind, defaults, build, children, visitorKey } = config;
82
- function create(input, dialect) {
83
- const base = build ? build(input, dialect) : input;
82
+ function create(input) {
83
+ const base = build ? build(input) : input;
84
84
  return {
85
85
  ...defaults,
86
86
  ...base,
@@ -96,142 +96,6 @@ function defineNode(config) {
96
96
  };
97
97
  }
98
98
  //#endregion
99
- //#region src/nodes/schema.ts
100
- /**
101
- * Maps schema `type` to its underlying `primitive`.
102
- * Primitive types map to themselves. Special string formats map to `'string'`.
103
- * Complex types (`ref`, `enum`, `union`, `intersection`, `tuple`, `blob`) are left unset.
104
- */
105
- const TYPE_TO_PRIMITIVE = {
106
- string: "string",
107
- number: "number",
108
- integer: "integer",
109
- bigint: "bigint",
110
- boolean: "boolean",
111
- null: "null",
112
- any: "any",
113
- unknown: "unknown",
114
- void: "void",
115
- never: "never",
116
- object: "object",
117
- array: "array",
118
- date: "date",
119
- uuid: "string",
120
- email: "string",
121
- url: "string",
122
- datetime: "string",
123
- time: "string"
124
- };
125
- /**
126
- * Definition for the {@link SchemaNode}. Object schemas default `properties` to an
127
- * empty array, and `primitive` is inferred from `type` when not explicitly provided.
128
- */
129
- const schemaDef = defineNode({
130
- kind: "Schema",
131
- build: (props) => {
132
- if (props.type === "object") return {
133
- properties: [],
134
- primitive: "object",
135
- ...props
136
- };
137
- return {
138
- primitive: TYPE_TO_PRIMITIVE[props.type],
139
- ...props
140
- };
141
- },
142
- children: [
143
- "properties",
144
- "items",
145
- "members",
146
- "additionalProperties"
147
- ],
148
- visitorKey: "schema"
149
- });
150
- function createSchema(props) {
151
- return schemaDef.create(props);
152
- }
153
- //#endregion
154
- //#region ../../internals/utils/src/casing.ts
155
- /**
156
- * Shared implementation for camelCase and PascalCase conversion.
157
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
158
- * and capitalizes each word according to `pascal`.
159
- *
160
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
161
- */
162
- function toCamelOrPascal(text, pascal) {
163
- return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
164
- if (word.length > 1 && word === word.toUpperCase()) return word;
165
- return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
166
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
167
- }
168
- /**
169
- * Converts `text` to camelCase.
170
- *
171
- * @example Word boundaries
172
- * `camelCase('hello-world') // 'helloWorld'`
173
- *
174
- * @example With a prefix
175
- * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
176
- */
177
- function camelCase(text, { prefix = "", suffix = "" } = {}) {
178
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
179
- }
180
- /**
181
- * Converts `text` to PascalCase.
182
- *
183
- * @example Word boundaries
184
- * `pascalCase('hello-world') // 'HelloWorld'`
185
- *
186
- * @example With a suffix
187
- * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
188
- */
189
- function pascalCase(text, { prefix = "", suffix = "" } = {}) {
190
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
191
- }
192
- //#endregion
193
- //#region ../../internals/utils/src/fs.ts
194
- /**
195
- * Strips the file extension from a path or file name.
196
- * Only removes the last `.ext` segment when the dot is not part of a directory name.
197
- *
198
- * @example
199
- * trimExtName('petStore.ts') // 'petStore'
200
- * trimExtName('/src/models/pet.ts') // '/src/models/pet'
201
- * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
202
- * trimExtName('noExtension') // 'noExtension'
203
- */
204
- function trimExtName(text) {
205
- const dotIndex = text.lastIndexOf(".");
206
- if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
207
- return text;
208
- }
209
- //#endregion
210
- //#region src/utils/extractStringsFromNodes.ts
211
- /**
212
- * Extracts all string content from a `CodeNode` tree recursively.
213
- *
214
- * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
215
- * and nested node content. Used to build the full source string for import filtering.
216
- */
217
- function extractStringsFromNodes(nodes) {
218
- if (!nodes?.length) return "";
219
- return nodes.map((node) => {
220
- if (typeof node === "string") return node;
221
- if (node.kind === "Text") return node.value;
222
- if (node.kind === "Break") return "";
223
- if (node.kind === "Jsx") return node.value;
224
- const parts = [];
225
- if ("params" in node && node.params) parts.push(node.params);
226
- if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics);
227
- if ("returnType" in node && node.returnType) parts.push(node.returnType);
228
- if ("type" in node && typeof node.type === "string") parts.push(node.type);
229
- const nested = extractStringsFromNodes(node.nodes);
230
- if (nested) parts.push(nested);
231
- return parts.join("\n");
232
- }).filter(Boolean).join("\n");
233
- }
234
- //#endregion
235
99
  //#region src/nodes/code.ts
236
100
  /**
237
101
  * Definition for the {@link ConstNode}.
@@ -356,6 +220,87 @@ const contentDef = defineNode({
356
220
  */
357
221
  const createContent = contentDef.create;
358
222
  //#endregion
223
+ //#region ../../internals/utils/src/casing.ts
224
+ /**
225
+ * Shared implementation for camelCase and PascalCase conversion.
226
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
227
+ * and capitalizes each word according to `pascal`.
228
+ *
229
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
230
+ */
231
+ function toCamelOrPascal(text, pascal) {
232
+ return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
233
+ if (word.length > 1 && word === word.toUpperCase()) return word;
234
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
235
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
236
+ }
237
+ /**
238
+ * Converts `text` to camelCase.
239
+ *
240
+ * @example Word boundaries
241
+ * `camelCase('hello-world') // 'helloWorld'`
242
+ *
243
+ * @example With a prefix
244
+ * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
245
+ */
246
+ function camelCase(text, { prefix = "", suffix = "" } = {}) {
247
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
248
+ }
249
+ /**
250
+ * Converts `text` to PascalCase.
251
+ *
252
+ * @example Word boundaries
253
+ * `pascalCase('hello-world') // 'HelloWorld'`
254
+ *
255
+ * @example With a suffix
256
+ * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
257
+ */
258
+ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
259
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
260
+ }
261
+ //#endregion
262
+ //#region ../../internals/utils/src/fs.ts
263
+ /**
264
+ * Strips the file extension from a path or file name.
265
+ * Only removes the last `.ext` segment when the dot is not part of a directory name.
266
+ *
267
+ * @example
268
+ * trimExtName('petStore.ts') // 'petStore'
269
+ * trimExtName('/src/models/pet.ts') // '/src/models/pet'
270
+ * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
271
+ * trimExtName('noExtension') // 'noExtension'
272
+ */
273
+ function trimExtName(text) {
274
+ const dotIndex = text.lastIndexOf(".");
275
+ if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
276
+ return text;
277
+ }
278
+ //#endregion
279
+ //#region src/utils/extractStringsFromNodes.ts
280
+ /**
281
+ * Extracts all string content from a `CodeNode` tree recursively.
282
+ *
283
+ * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
284
+ * and nested node content. Used to build the full source string for import filtering.
285
+ */
286
+ function extractStringsFromNodes(nodes) {
287
+ if (!nodes?.length) return "";
288
+ return nodes.map((node) => {
289
+ if (typeof node === "string") return node;
290
+ if (node.kind === "Text") return node.value;
291
+ if (node.kind === "Break") return "";
292
+ if (node.kind === "Jsx") return node.value;
293
+ const parts = [];
294
+ if ("params" in node && node.params) parts.push(node.params);
295
+ if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics);
296
+ if ("returnType" in node && node.returnType) parts.push(node.returnType);
297
+ if ("type" in node && typeof node.type === "string") parts.push(node.type);
298
+ const nested = extractStringsFromNodes(node.nodes);
299
+ if (nested) parts.push(nested);
300
+ return parts.join("\n");
301
+ }).filter(Boolean).join("\n");
302
+ }
303
+ //#endregion
359
304
  //#region src/utils/fileMerge.ts
360
305
  function sourceKey(source) {
361
306
  return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`;
@@ -381,9 +326,9 @@ function sortKey(node) {
381
326
  return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`;
382
327
  }
383
328
  /**
384
- * Deduplicates and merges `SourceNode` objects by `name + isExportable + isTypeOnly`.
385
- *
386
- * Unnamed sources are deduplicated by object reference. Returns a deduplicated array in original order.
329
+ * Deduplicates `SourceNode` objects by `name + isExportable + isTypeOnly`, keeping the first of each
330
+ * key. Unnamed sources fall back to their extracted node strings as the name part of the key. Returns
331
+ * the deduplicated array in original order.
387
332
  */
388
333
  function combineSources(sources) {
389
334
  const seen = /* @__PURE__ */ new Map();
@@ -825,20 +770,33 @@ function createOutput(overrides = {}) {
825
770
  return outputDef.create(overrides);
826
771
  }
827
772
  //#endregion
773
+ //#region src/optionality.ts
774
+ /**
775
+ * Generic JSON Schema optionality: a non-required field is optional, and a
776
+ * non-required nullable field is nullish.
777
+ */
778
+ function optionality(schema, required) {
779
+ const nullable = schema.nullable ?? false;
780
+ return {
781
+ ...schema,
782
+ optional: !required && !nullable ? true : void 0,
783
+ nullish: !required && nullable ? true : void 0
784
+ };
785
+ }
786
+ //#endregion
828
787
  //#region src/nodes/parameter.ts
829
788
  /**
830
- * Definition for the {@link ParameterNode}. `required` defaults to `false`. When a `dialect` is
831
- * passed to `create`, the schema's `optional`/`nullish` flags are derived through its
832
- * `optionality`; without one, the schema is left as-is.
789
+ * Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's
790
+ * `optional`/`nullish` flags are derived from it through {@link optionality}.
833
791
  */
834
792
  const parameterDef = defineNode({
835
793
  kind: "Parameter",
836
- build: (props, dialect) => {
794
+ build: (props) => {
837
795
  const required = props.required ?? false;
838
796
  return {
839
797
  ...props,
840
798
  required,
841
- schema: dialect ? dialect.schema.optionality(props.schema, required) : props.schema
799
+ schema: optionality(props.schema, required)
842
800
  };
843
801
  },
844
802
  children: ["schema"],
@@ -861,18 +819,17 @@ const createParameter = parameterDef.create;
861
819
  //#endregion
862
820
  //#region src/nodes/property.ts
863
821
  /**
864
- * Definition for the {@link PropertyNode}. `required` defaults to `false`. When a `dialect` is
865
- * passed to `create`, the schema's `optional`/`nullish` flags are derived through its
866
- * `optionality`; without one, the schema is left as-is.
822
+ * Definition for the {@link PropertyNode}. `required` defaults to `false`, and the schema's
823
+ * `optional`/`nullish` flags are derived from it through {@link optionality}.
867
824
  */
868
825
  const propertyDef = defineNode({
869
826
  kind: "Property",
870
- build: (props, dialect) => {
827
+ build: (props) => {
871
828
  const required = props.required ?? false;
872
829
  return {
873
830
  ...props,
874
831
  required,
875
- schema: dialect ? dialect.schema.optionality(props.schema, required) : props.schema
832
+ schema: optionality(props.schema, required)
876
833
  };
877
834
  },
878
835
  children: ["schema"],
@@ -928,6 +885,61 @@ const responseDef = defineNode({
928
885
  */
929
886
  const createResponse = responseDef.create;
930
887
  //#endregion
888
+ //#region src/nodes/schema.ts
889
+ /**
890
+ * Maps schema `type` to its underlying `primitive`.
891
+ * Primitive types map to themselves and special string formats map to `'string'`.
892
+ * Any type not listed here (such as `ref`, `enum`, `union`, `intersection`, `tuple`, `ipv4`, `ipv6`, `blob`) has no `primitive`.
893
+ */
894
+ const TYPE_TO_PRIMITIVE = {
895
+ string: "string",
896
+ number: "number",
897
+ integer: "integer",
898
+ bigint: "bigint",
899
+ boolean: "boolean",
900
+ null: "null",
901
+ any: "any",
902
+ unknown: "unknown",
903
+ void: "void",
904
+ never: "never",
905
+ object: "object",
906
+ array: "array",
907
+ date: "date",
908
+ uuid: "string",
909
+ email: "string",
910
+ url: "string",
911
+ datetime: "string",
912
+ time: "string"
913
+ };
914
+ /**
915
+ * Definition for the {@link SchemaNode}. Object schemas default `properties` to an
916
+ * empty array, and `primitive` is inferred from `type` when not explicitly provided.
917
+ */
918
+ const schemaDef = defineNode({
919
+ kind: "Schema",
920
+ build: (props) => {
921
+ if (props.type === "object") return {
922
+ properties: [],
923
+ primitive: "object",
924
+ ...props
925
+ };
926
+ return {
927
+ primitive: TYPE_TO_PRIMITIVE[props.type],
928
+ ...props
929
+ };
930
+ },
931
+ children: [
932
+ "properties",
933
+ "items",
934
+ "members",
935
+ "additionalProperties"
936
+ ],
937
+ visitorKey: "schema"
938
+ });
939
+ function createSchema(props) {
940
+ return schemaDef.create(props);
941
+ }
942
+ //#endregion
931
943
  Object.defineProperty(exports, "__exportAll", {
932
944
  enumerable: true,
933
945
  get: function() {
@@ -1198,6 +1210,12 @@ Object.defineProperty(exports, "operationDef", {
1198
1210
  return operationDef;
1199
1211
  }
1200
1212
  });
1213
+ Object.defineProperty(exports, "optionality", {
1214
+ enumerable: true,
1215
+ get: function() {
1216
+ return optionality;
1217
+ }
1218
+ });
1201
1219
  Object.defineProperty(exports, "outputDef", {
1202
1220
  enumerable: true,
1203
1221
  get: function() {
@@ -1271,4 +1289,4 @@ Object.defineProperty(exports, "visitorKeys", {
1271
1289
  }
1272
1290
  });
1273
1291
 
1274
- //# sourceMappingURL=response-BeG6hq2D.cjs.map
1292
+ //# sourceMappingURL=schema-BkvrrOAr.cjs.map