@kubb/ast 5.0.0-beta.58 → 5.0.0-beta.59

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 (67) hide show
  1. package/README.md +10 -0
  2. package/dist/casing-BE2R1RXg.cjs +88 -0
  3. package/dist/casing-BE2R1RXg.cjs.map +1 -0
  4. package/dist/extractStringsFromNodes-WMYJ8nQL.d.ts +82 -0
  5. package/dist/factory-BmcGBdeg.cjs +1251 -0
  6. package/dist/factory-BmcGBdeg.cjs.map +1 -0
  7. package/dist/factory-Du7nEP4B.js +282 -0
  8. package/dist/factory-Du7nEP4B.js.map +1 -0
  9. package/dist/factory.cjs +25 -28
  10. package/dist/factory.d.ts +3 -3
  11. package/dist/factory.js +3 -3
  12. package/dist/{ast-ClnJg9BN.d.ts → index-BzjwdK2M.d.ts} +74 -372
  13. package/dist/index.cjs +445 -46
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +94 -59
  16. package/dist/index.js +7 -113
  17. package/dist/index.js.map +1 -1
  18. package/dist/operationParams-BZ07xDm0.d.ts +204 -0
  19. package/dist/response-DKxTr522.js +683 -0
  20. package/dist/response-DKxTr522.js.map +1 -0
  21. package/dist/{types-CB2oY8Dw.d.ts → types-olVl9v5p.d.ts} +222 -227
  22. package/dist/types.d.ts +4 -3
  23. package/dist/utils-BCtRXfhI.cjs +275 -0
  24. package/dist/utils-BCtRXfhI.cjs.map +1 -0
  25. package/dist/{utils-DN4XLVqz.js → utils-SdZU0F3H.js} +472 -1235
  26. package/dist/utils-SdZU0F3H.js.map +1 -0
  27. package/dist/utils.cjs +127 -22
  28. package/dist/utils.d.ts +112 -80
  29. package/dist/utils.js +3 -2
  30. package/package.json +1 -1
  31. package/src/constants.ts +8 -14
  32. package/src/dedupe.ts +8 -0
  33. package/src/factory.ts +1 -2
  34. package/src/guards.ts +1 -1
  35. package/src/index.ts +4 -13
  36. package/src/nodes/code.ts +29 -47
  37. package/src/nodes/content.ts +2 -2
  38. package/src/nodes/file.ts +28 -23
  39. package/src/nodes/function.ts +0 -15
  40. package/src/nodes/input.ts +6 -6
  41. package/src/nodes/operation.ts +1 -1
  42. package/src/nodes/parameter.ts +0 -3
  43. package/src/nodes/property.ts +0 -3
  44. package/src/nodes/requestBody.ts +3 -6
  45. package/src/nodes/schema.ts +3 -2
  46. package/src/printer.ts +1 -1
  47. package/src/registry.ts +31 -26
  48. package/src/signature.ts +3 -3
  49. package/src/transformers.ts +28 -1
  50. package/src/types.ts +2 -53
  51. package/src/utils/codegen.ts +104 -0
  52. package/src/utils/fileMerge.ts +184 -0
  53. package/src/utils/index.ts +7 -339
  54. package/src/utils/operationParams.ts +353 -0
  55. package/src/utils/refs.ts +112 -0
  56. package/src/utils/schemaGraph.ts +169 -0
  57. package/src/utils/strings.ts +139 -0
  58. package/src/visitor.ts +43 -19
  59. package/dist/extractStringsFromNodes-Bn9cOos9.d.ts +0 -14
  60. package/dist/factory-C5gHvtLU.js +0 -138
  61. package/dist/factory-C5gHvtLU.js.map +0 -1
  62. package/dist/factory-JN-Ylfl6.cjs +0 -155
  63. package/dist/factory-JN-Ylfl6.cjs.map +0 -1
  64. package/dist/utils-C8bWAzhv.cjs +0 -2696
  65. package/dist/utils-C8bWAzhv.cjs.map +0 -1
  66. package/dist/utils-DN4XLVqz.js.map +0 -1
  67. package/src/utils/ast.ts +0 -816
@@ -0,0 +1,275 @@
1
+ const require_casing = require("./casing-BE2R1RXg.cjs");
2
+ //#region src/guards.ts
3
+ /**
4
+ * Narrows a `SchemaNode` to the variant that matches `type`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const schema = createSchema({ type: 'string' })
9
+ * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
10
+ * ```
11
+ */
12
+ function narrowSchema(node, type) {
13
+ return node?.type === type ? node : null;
14
+ }
15
+ /**
16
+ * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * if (isHttpOperationNode(node)) {
21
+ * console.log(node.method, node.path)
22
+ * }
23
+ * ```
24
+ */
25
+ function isHttpOperationNode(node) {
26
+ return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
27
+ }
28
+ //#endregion
29
+ //#region src/utils/refs.ts
30
+ const plainStringTypes = new Set([
31
+ "string",
32
+ "uuid",
33
+ "email",
34
+ "url",
35
+ "datetime"
36
+ ]);
37
+ /**
38
+ * Returns the last path segment of a reference string.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * extractRefName('#/components/schemas/Pet') // 'Pet'
43
+ * ```
44
+ */
45
+ function extractRefName(ref) {
46
+ return ref.split("/").at(-1) ?? ref;
47
+ }
48
+ /**
49
+ * Builds a PascalCase child schema name by joining a parent name and property name.
50
+ * Returns `null` when there is no parent to nest under.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * childName('Order', 'shipping_address') // 'OrderShippingAddress'
55
+ * childName(undefined, 'params') // null
56
+ * ```
57
+ */
58
+ function childName(parentName, propName) {
59
+ return parentName ? require_casing.pascalCase([parentName, propName].join(" ")) : null;
60
+ }
61
+ /**
62
+ * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
63
+ * empty parts.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'
68
+ * ```
69
+ */
70
+ function enumPropName(parentName, propName, enumSuffix) {
71
+ return require_casing.pascalCase([
72
+ parentName,
73
+ propName,
74
+ enumSuffix
75
+ ].filter(Boolean).join(" "));
76
+ }
77
+ /**
78
+ * Type guard that returns `true` when a schema emits as a plain `string` type.
79
+ *
80
+ * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
81
+ * types, returns `true` only when `representation` is `'string'` rather than `'date'`.
82
+ */
83
+ function isStringType(node) {
84
+ if (plainStringTypes.has(node.type)) return true;
85
+ const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time");
86
+ if (temporal) return temporal.representation !== "date";
87
+ return false;
88
+ }
89
+ /**
90
+ * Derives a {@link ParamGroupType} for a query or header group from the resolver.
91
+ *
92
+ * Returns `null` when there is no resolver, no params, or the group name equals the
93
+ * individual param name (so there is no real group to emit).
94
+ */
95
+ function resolveGroupType({ node, params, group, resolver }) {
96
+ if (!resolver || !params.length) return null;
97
+ const firstParam = params[0];
98
+ const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
99
+ if (groupName === resolver.resolveParamName(node, firstParam)) return null;
100
+ return {
101
+ type: groupName,
102
+ optional: params.every((p) => !p.required)
103
+ };
104
+ }
105
+ //#endregion
106
+ Object.defineProperty(exports, "buildGroupParam", {
107
+ enumerable: true,
108
+ get: function() {
109
+ return buildGroupParam;
110
+ }
111
+ });
112
+ Object.defineProperty(exports, "buildJSDoc", {
113
+ enumerable: true,
114
+ get: function() {
115
+ return buildJSDoc;
116
+ }
117
+ });
118
+ Object.defineProperty(exports, "buildList", {
119
+ enumerable: true,
120
+ get: function() {
121
+ return buildList;
122
+ }
123
+ });
124
+ Object.defineProperty(exports, "buildObject", {
125
+ enumerable: true,
126
+ get: function() {
127
+ return buildObject;
128
+ }
129
+ });
130
+ Object.defineProperty(exports, "buildTypeLiteral", {
131
+ enumerable: true,
132
+ get: function() {
133
+ return buildTypeLiteral;
134
+ }
135
+ });
136
+ Object.defineProperty(exports, "caseParams", {
137
+ enumerable: true,
138
+ get: function() {
139
+ return caseParams;
140
+ }
141
+ });
142
+ Object.defineProperty(exports, "childName", {
143
+ enumerable: true,
144
+ get: function() {
145
+ return childName;
146
+ }
147
+ });
148
+ Object.defineProperty(exports, "collectUsedSchemaNames", {
149
+ enumerable: true,
150
+ get: function() {
151
+ return collectUsedSchemaNames;
152
+ }
153
+ });
154
+ Object.defineProperty(exports, "containsCircularRef", {
155
+ enumerable: true,
156
+ get: function() {
157
+ return containsCircularRef;
158
+ }
159
+ });
160
+ Object.defineProperty(exports, "createOperationParams", {
161
+ enumerable: true,
162
+ get: function() {
163
+ return createOperationParams;
164
+ }
165
+ });
166
+ Object.defineProperty(exports, "enumPropName", {
167
+ enumerable: true,
168
+ get: function() {
169
+ return enumPropName;
170
+ }
171
+ });
172
+ Object.defineProperty(exports, "extractRefName", {
173
+ enumerable: true,
174
+ get: function() {
175
+ return extractRefName;
176
+ }
177
+ });
178
+ Object.defineProperty(exports, "extractStringsFromNodes", {
179
+ enumerable: true,
180
+ get: function() {
181
+ return extractStringsFromNodes;
182
+ }
183
+ });
184
+ Object.defineProperty(exports, "findCircularSchemas", {
185
+ enumerable: true,
186
+ get: function() {
187
+ return findCircularSchemas;
188
+ }
189
+ });
190
+ Object.defineProperty(exports, "getNestedAccessor", {
191
+ enumerable: true,
192
+ get: function() {
193
+ return getNestedAccessor;
194
+ }
195
+ });
196
+ Object.defineProperty(exports, "isHttpOperationNode", {
197
+ enumerable: true,
198
+ get: function() {
199
+ return isHttpOperationNode;
200
+ }
201
+ });
202
+ Object.defineProperty(exports, "isStringType", {
203
+ enumerable: true,
204
+ get: function() {
205
+ return isStringType;
206
+ }
207
+ });
208
+ Object.defineProperty(exports, "isValidVarName", {
209
+ enumerable: true,
210
+ get: function() {
211
+ return isValidVarName;
212
+ }
213
+ });
214
+ Object.defineProperty(exports, "jsStringEscape", {
215
+ enumerable: true,
216
+ get: function() {
217
+ return jsStringEscape;
218
+ }
219
+ });
220
+ Object.defineProperty(exports, "narrowSchema", {
221
+ enumerable: true,
222
+ get: function() {
223
+ return narrowSchema;
224
+ }
225
+ });
226
+ Object.defineProperty(exports, "objectKey", {
227
+ enumerable: true,
228
+ get: function() {
229
+ return objectKey;
230
+ }
231
+ });
232
+ Object.defineProperty(exports, "resolveGroupType", {
233
+ enumerable: true,
234
+ get: function() {
235
+ return resolveGroupType;
236
+ }
237
+ });
238
+ Object.defineProperty(exports, "resolveParamType", {
239
+ enumerable: true,
240
+ get: function() {
241
+ return resolveParamType;
242
+ }
243
+ });
244
+ Object.defineProperty(exports, "stringify", {
245
+ enumerable: true,
246
+ get: function() {
247
+ return stringify;
248
+ }
249
+ });
250
+ Object.defineProperty(exports, "stringifyObject", {
251
+ enumerable: true,
252
+ get: function() {
253
+ return stringifyObject;
254
+ }
255
+ });
256
+ Object.defineProperty(exports, "syncSchemaRef", {
257
+ enumerable: true,
258
+ get: function() {
259
+ return syncSchemaRef;
260
+ }
261
+ });
262
+ Object.defineProperty(exports, "toRegExpString", {
263
+ enumerable: true,
264
+ get: function() {
265
+ return toRegExpString;
266
+ }
267
+ });
268
+ Object.defineProperty(exports, "trimQuotes", {
269
+ enumerable: true,
270
+ get: function() {
271
+ return trimQuotes;
272
+ }
273
+ });
274
+
275
+ //# sourceMappingURL=utils-BCtRXfhI.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-BCtRXfhI.cjs","names":["pascalCase"],"sources":["../src/guards.ts","../src/utils/refs.ts"],"sourcesContent":["import type { HttpOperationNode, OperationNode, SchemaNode, SchemaNodeByType } from './nodes/index.ts'\n\n/**\n * Narrows a `SchemaNode` to the variant that matches `type`.\n *\n * @example\n * ```ts\n * const schema = createSchema({ type: 'string' })\n * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null\n * ```\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null {\n return node?.type === type ? (node as SchemaNodeByType[T]) : null\n}\n\n/**\n * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.\n *\n * @example\n * ```ts\n * if (isHttpOperationNode(node)) {\n * console.log(node.method, node.path)\n * }\n * ```\n */\nexport function isHttpOperationNode(node: OperationNode): node is HttpOperationNode {\n return node.protocol === 'http' || (node.method !== undefined && node.path !== undefined)\n}\n","import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { OperationNode, ParameterNode, SchemaNode } from '../nodes/index.ts'\nimport type { SchemaType } from '../nodes/schema.ts'\nimport type { OperationParamsResolver, ParamGroupType } from './operationParams.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * ```ts\n * extractRefName('#/components/schemas/Pet') // 'Pet'\n * ```\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * ```ts\n * resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' })\n * // => 'Pet'\n * ```\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example\n * ```ts\n * childName('Order', 'shipping_address') // 'OrderShippingAddress'\n * childName(undefined, 'params') // null\n * ```\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * ```ts\n * enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'\n * ```\n */\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n\n/**\n * Derives a {@link ParamGroupType} for a query or header group from the resolver.\n *\n * Returns `null` when there is no resolver, no params, or the group name equals the\n * individual param name (so there is no real group to emit).\n */\nexport function resolveGroupType({\n node,\n params,\n group,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n group: 'query' | 'header'\n resolver: OperationParamsResolver | undefined\n}): ParamGroupType | null {\n if (!resolver || !params.length) {\n return null\n }\n const firstParam = params[0]!\n const groupMethod = group === 'query' ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName\n const groupName = groupMethod.call(resolver, node, firstParam)\n if (groupName === resolver.resolveParamName(node, firstParam)) {\n return null\n }\n return { type: groupName, optional: params.every((p) => !p.required) }\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,aAA2C,MAA8B,MAAqC;CAC5H,OAAO,MAAM,SAAS,OAAQ,OAA+B;AAC/D;;;;;;;;;;;AAYA,SAAgB,oBAAoB,MAAgD;CAClF,OAAO,KAAK,aAAa,UAAW,KAAK,WAAW,KAAA,KAAa,KAAK,SAAS,KAAA;AACjF;;;ACrBA,MAAM,mBAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAU;;;;;;;;;AAUpG,SAAgB,eAAe,KAAqB;CAClD,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;AAClC;;;;;;;;;;;AA8BA,SAAgB,UAAU,YAAuC,UAAiC;CAChG,OAAO,aAAaA,eAAAA,WAAW,CAAC,YAAY,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI;AACrE;;;;;;;;;;AAWA,SAAgB,aAAa,YAAuC,UAAkB,YAA4B;CAChH,OAAOA,eAAAA,WAAW;EAAC;EAAY;EAAU;CAAU,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC;AAChF;;;;;;;AAQA,SAAgB,aAAa,MAA2B;CACtD,IAAI,iBAAiB,IAAI,KAAK,IAAI,GAChC,OAAO;CAGT,MAAM,WAAW,aAAa,MAAM,MAAM,KAAK,aAAa,MAAM,MAAM;CACxE,IAAI,UACF,OAAO,SAAS,mBAAmB;CAGrC,OAAO;AACT;;;;;;;AAQA,SAAgB,iBAAiB,EAC/B,MACA,QACA,OACA,YAMwB;CACxB,IAAI,CAAC,YAAY,CAAC,OAAO,QACvB,OAAO;CAET,MAAM,aAAa,OAAO;CAE1B,MAAM,aADc,UAAU,UAAU,SAAS,yBAAyB,SAAS,wBAAA,CACrD,KAAK,UAAU,MAAM,UAAU;CAC7D,IAAI,cAAc,SAAS,iBAAiB,MAAM,UAAU,GAC1D,OAAO;CAET,OAAO;EAAE,MAAM;EAAW,UAAU,OAAO,OAAO,MAAM,CAAC,EAAE,QAAQ;CAAE;AACvE"}