@kubb/kit 5.18.4 → 5.18.6

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.
package/README.md CHANGED
@@ -74,9 +74,9 @@ export const pluginExample = defineExtension({
74
74
 
75
75
  `ast` and `factory` are the node builders a generator calls to construct the file, schema, and operation nodes it returns. `Diagnostics` is the structured error a plugin throws to report a problem with a location and a fix suggestion, and `memoryStorage` and `fsStorage` are the built-in storage backends, useful in tests and custom configs.
76
76
 
77
- `macroDedupeUnion`, `macroDiscriminatorEnum`, `macroEnumName`, and `macroRenameSchema` are the built-in macro presets, ready to pass to `ast.applyMacros` or a plugin's `setMacros`. Build a custom macro with `ast.defineMacro` instead.
77
+ `macroDedupeUnion`, `macroDiscriminatorEnum`, `macroEnumName`, and `macroRenameSchema` are the built-in macro presets, ready to pass to `ast.macro.apply` or a plugin's `setMacros`. Build a custom macro with `ast.defineMacro` instead.
78
78
 
79
- `childName`, `enumPropName`, `extractRefName`, `isStringType`, `mergeAdjacentObjectsLazy`, `syncSchemaRef`, and `containsCircularRef` are schema-name and schema-graph helpers a generator or macro calls while shaping output, complementing the ref and graph helpers (`resolveRefName`, `findCircularSchemas`, `collectUsedSchemaNames`) that stay on `ast`.
79
+ `childName`, `enumPropName`, and `mergeAdjacentObjectsLazy` are schema-name helpers a generator or macro calls while shaping output. Ref and graph helpers live on `ast.ref` and `ast.graph`, such as `ast.ref.getName`, `ast.graph.getCircularNames`, and `ast.graph.getUsedNames`.
80
80
 
81
81
  Rounding out the package are the option and hook types every plugin, generator, adapter, resolver, and renderer author references, among them `PluginType`, `GeneratorContext`, `ResolveFileOptions`, `AdapterFactoryOptions`, `RendererFactory`, and `KubbHooks`.
82
82
 
package/dist/index.cjs CHANGED
@@ -5,9 +5,226 @@ var __name = (target, value) => __defProp(target, "name", {
5
5
  value,
6
6
  configurable: true
7
7
  });
8
+ var __exportAll = (all, no_symbols) => {
9
+ let target = {};
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
15
+ return target;
16
+ };
8
17
  let _kubb_ast = require("@kubb/ast");
9
- let node_crypto = require("node:crypto");
10
18
  let _kubb_core = require("@kubb/core");
19
+ let node_crypto = require("node:crypto");
20
+ // ../../internals/utils/src/casing.ts
21
+ /**
22
+ * Shared implementation for camelCase and PascalCase conversion.
23
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
24
+ * and capitalizes each word according to `pascal`.
25
+ *
26
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
27
+ */
28
+ function convert(text, pascal) {
29
+ return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)(?!xx(?![a-z]))([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
30
+ if (word.length > 1 && word === word.toUpperCase()) return word;
31
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
32
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
33
+ }
34
+ const cache = /* @__PURE__ */ new Map();
35
+ const cacheLimit = 1e5;
36
+ function toCamelOrPascal(text, pascal) {
37
+ const key = `${pascal ? "P" : "c"}${text}`;
38
+ const cached = cache.get(key);
39
+ if (cached !== void 0) return cached;
40
+ const result = convert(text, pascal);
41
+ if (cache.size >= cacheLimit) cache.clear();
42
+ cache.set(key, result);
43
+ return result;
44
+ }
45
+ /**
46
+ * Converts `text` to PascalCase.
47
+ *
48
+ * @example Word boundaries
49
+ * `pascalCase('hello-world') // 'HelloWorld'`
50
+ *
51
+ * @example With a suffix
52
+ * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
53
+ */
54
+ function pascalCase$1(text, { prefix = "", suffix = "" } = {}) {
55
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
56
+ }
57
+ __name(pascalCase$1, "pascalCase");
58
+ const wordStart = /(?<=[a-z\d])(?=[A-Z])|(?<=[A-Z]{2})(?=[A-Z][a-z]{2})/;
59
+ function words(text) {
60
+ return text.split(/[\s\-_./\\:]+/).filter(Boolean).flatMap((segment) => segment === segment.toUpperCase() ? segment : segment.split(wordStart));
61
+ }
62
+ /**
63
+ * Uppercases only the first character of `text`. Unlike `pascalCase` it never splits words or strips characters.
64
+ *
65
+ * @example
66
+ * `capitalize('getPetById') // 'GetPetById'`
67
+ */
68
+ function capitalize(text) {
69
+ return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
70
+ }
71
+ /**
72
+ * Converts `text` to snake_case.
73
+ *
74
+ * @example
75
+ * `snakeCase('helloWorld') // 'hello_world'`
76
+ */
77
+ function snakeCase(text, { prefix = "", suffix = "" } = {}) {
78
+ return words(`${prefix} ${text} ${suffix}`).map((word) => word.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()).filter(Boolean).join("_");
79
+ }
80
+ /**
81
+ * Converts `text` to SCREAMING_SNAKE_CASE.
82
+ *
83
+ * @example
84
+ * `screamingSnakeCase('helloWorld') // 'HELLO_WORLD'`
85
+ */
86
+ function screamingSnakeCase(text, { prefix = "", suffix = "" } = {}) {
87
+ return snakeCase(text, {
88
+ prefix,
89
+ suffix
90
+ }).toUpperCase();
91
+ }
92
+ // ../../internals/utils/src/text.ts
93
+ /**
94
+ * Indents every non-empty line of `text` by `unit`, leaving blank lines empty.
95
+ * @example
96
+ * `indent({ text: 'a\n\nb' }) // ' a\n\n b'`
97
+ */
98
+ function indent({ text, unit = " " }) {
99
+ if (!text) return "";
100
+ return text.split("\n").map((line) => line.trim() ? `${unit}${line}` : "").join("\n");
101
+ }
102
+ /**
103
+ * Strips the common leading whitespace and the surrounding blank lines, counting tabs and spaces alike, so indented template literals start at column zero.
104
+ */
105
+ function dedent(text) {
106
+ if (!text) return "";
107
+ if (!text.includes("\n")) return text.trim() ? text.trimStart() : "";
108
+ const lines = text.split("\n");
109
+ const indents = lines.map((line) => {
110
+ const indent = line.length - line.trimStart().length;
111
+ return indent === line.length ? -1 : indent;
112
+ });
113
+ const start = indents.findIndex((indent) => indent !== -1);
114
+ if (start === -1) return "";
115
+ const end = indents.findLastIndex((indent) => indent !== -1);
116
+ const min = indents.reduce((lowest, indent) => indent !== -1 && indent < lowest ? indent : lowest, Infinity);
117
+ return lines.slice(start, end + 1).map((line, i) => indents[start + i] === -1 ? "" : line.slice(min)).join("\n");
118
+ }
119
+ /**
120
+ * Strips one matching pair of `"`, `'` or `` ` `` from both ends of `text`. Returns `text` unchanged without a matching pair.
121
+ * @example
122
+ * `unquote('"hello"') // 'hello'`
123
+ */
124
+ function unquote(text) {
125
+ if (text.length < 2) return text;
126
+ const first = text[0];
127
+ return (first === "\"" || first === "'" || first === "`") && text.at(-1) === first ? text.slice(1, -1) : text;
128
+ }
129
+ // src/casing.ts
130
+ var casing_exports = /* @__PURE__ */ __exportAll({
131
+ camel: () => _kubb_core.camelCase,
132
+ capitalize: () => capitalize,
133
+ pascal: () => _kubb_core.pascalCase,
134
+ screamingSnake: () => screamingSnakeCase,
135
+ snake: () => snakeCase
136
+ });
137
+ // src/text.ts
138
+ var text_exports = /* @__PURE__ */ __exportAll({
139
+ dedent: () => dedent,
140
+ indent: () => indent,
141
+ quote: () => quote,
142
+ unquote: () => unquote
143
+ });
144
+ const quoteEscapes = /* @__PURE__ */ new Map([
145
+ ["\\", "\\\\"],
146
+ ["'", "\\'"],
147
+ ["\n", "\\n"],
148
+ ["\r", "\\r"]
149
+ ]);
150
+ /**
151
+ * A single-quoted string literal with backslashes, quotes and line breaks escaped. JavaScript, TypeScript and Python read it the same way.
152
+ */
153
+ function quote(value) {
154
+ if (value === void 0 || value === null) return "''";
155
+ return `'${Array.from(String(value), (char) => quoteEscapes.get(char) ?? char).join("")}'`;
156
+ }
157
+ // src/authoring.ts
158
+ const createPrinter = _kubb_ast.createPrinter;
159
+ const defineMacro = _kubb_ast.defineMacro;
160
+ // src/macros/macroDedupeUnion.ts
161
+ /**
162
+ * Drops members that repeat an earlier one, ignoring the source `pointer` so equal schemas from
163
+ * different places in the spec still match.
164
+ */
165
+ function dedupeMembers(members) {
166
+ const seen = /* @__PURE__ */ new Set();
167
+ const keys = /* @__PURE__ */ new WeakMap();
168
+ function key(value) {
169
+ if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "undefined";
170
+ if (value instanceof Date) return key(value.toJSON());
171
+ const cached = keys.get(value);
172
+ if (cached) return cached;
173
+ const node = value;
174
+ const skipsSchema = node.kind === _kubb_ast.ast.node.kinds.schema && node.type === _kubb_ast.ast.schema.types.ref && typeof node.ref === "string";
175
+ const entries = Array.isArray(value) ? value.map(key) : Object.entries(value).filter(([name, child]) => name !== "pointer" && child !== void 0 && !(skipsSchema && name === "schema")).map(([name, child]) => [name, key(child)]);
176
+ const result = (0, node_crypto.hash)("sha256", JSON.stringify([Array.isArray(value), entries]));
177
+ keys.set(value, result);
178
+ return result;
179
+ }
180
+ return members.filter((member) => {
181
+ const memberKey = key(member);
182
+ if (seen.has(memberKey)) return false;
183
+ seen.add(memberKey);
184
+ return true;
185
+ });
186
+ }
187
+ /**
188
+ * Removes union members that repeat an earlier one. Enum members next to a broader scalar, such as
189
+ * `anyOf: [string, enum]`, are kept so the known values survive in the generated code.
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * const next = applyMacros(unionSchema, [macroDedupeUnion], { depth: 'shallow' })
194
+ * ```
195
+ */
196
+ const macroDedupeUnion = defineMacro({
197
+ name: "dedupe-union",
198
+ schema(node) {
199
+ const unionNode = _kubb_ast.ast.schema.narrow(node, _kubb_ast.ast.schema.types.union);
200
+ if (!unionNode?.members?.length) return void 0;
201
+ const deduped = dedupeMembers(unionNode.members);
202
+ if (deduped.length === unionNode.members.length) return void 0;
203
+ return {
204
+ ...unionNode,
205
+ members: deduped
206
+ };
207
+ }
208
+ });
209
+ // src/deprecated.ts
210
+ /** @deprecated Use `casing.camel`. Removed in Kubb v6. */
211
+ const camelCase = _kubb_core.camelCase;
212
+ /** @deprecated Use `casing.pascal`. Removed in Kubb v6. */
213
+ const pascalCase = _kubb_core.pascalCase;
214
+ /** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */
215
+ const extractRefName = _kubb_ast.ast.ref.getName;
216
+ /** @deprecated Use `ast.ref.mergeSchema`. Removed in Kubb v6. */
217
+ const syncSchemaRef = _kubb_ast.ast.ref.mergeSchema;
218
+ /** @deprecated Use `ast.schema.isString`. Removed in Kubb v6. */
219
+ const isStringType = _kubb_ast.ast.schema.isString;
220
+ /** @deprecated Use `ast.graph.containsCircular`. Removed in Kubb v6. */
221
+ const containsCircularRef = _kubb_ast.ast.graph.containsCircular;
222
+ /**
223
+ * The name `macroDedupeUnion` had before 5.16. Kept so a plugin built against an older `@kubb/kit` keeps running.
224
+ *
225
+ * @deprecated Use `macroDedupeUnion`. Removed in the next major.
226
+ */
227
+ const macroSimplifyUnion = macroDedupeUnion;
11
228
  // src/Url.ts
12
229
  /**
13
230
  * Sanitizes a parameter name so it is safe to use as a `path-to-regexp` capture name, without
@@ -76,61 +293,6 @@ var Url = class {
76
293
  return `\`${prefix ?? ""}${result}\``;
77
294
  }
78
295
  };
79
- // src/macros/macroDedupeUnion.ts
80
- /**
81
- * Drops members that repeat an earlier one, ignoring the source `pointer` so equal schemas from
82
- * different places in the spec still match.
83
- */
84
- function dedupeMembers(members) {
85
- const seen = /* @__PURE__ */ new Set();
86
- const keys = /* @__PURE__ */ new WeakMap();
87
- function key(value) {
88
- if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "undefined";
89
- if (value instanceof Date) return key(value.toJSON());
90
- const cached = keys.get(value);
91
- if (cached) return cached;
92
- const node = value;
93
- const skipsSchema = node.kind === _kubb_ast.ast.nodeKinds.schema && node.type === _kubb_ast.ast.schemaTypes.ref && typeof node.ref === "string";
94
- const entries = Array.isArray(value) ? value.map(key) : Object.entries(value).filter(([name, child]) => name !== "pointer" && child !== void 0 && !(skipsSchema && name === "schema")).map(([name, child]) => [name, key(child)]);
95
- const result = (0, node_crypto.hash)("sha256", JSON.stringify([Array.isArray(value), entries]));
96
- keys.set(value, result);
97
- return result;
98
- }
99
- return members.filter((member) => {
100
- const memberKey = key(member);
101
- if (seen.has(memberKey)) return false;
102
- seen.add(memberKey);
103
- return true;
104
- });
105
- }
106
- /**
107
- * Removes union members that repeat an earlier one. Enum members next to a broader scalar, such as
108
- * `anyOf: [string, enum]`, are kept so the known values survive in the generated code.
109
- *
110
- * @example
111
- * ```ts
112
- * const next = applyMacros(unionSchema, [macroDedupeUnion], { depth: 'shallow' })
113
- * ```
114
- */
115
- const macroDedupeUnion = _kubb_ast.ast.defineMacro({
116
- name: "dedupe-union",
117
- schema(node) {
118
- const unionNode = _kubb_ast.ast.narrowSchema(node, _kubb_ast.ast.schemaTypes.union);
119
- if (!unionNode?.members?.length) return void 0;
120
- const deduped = dedupeMembers(unionNode.members);
121
- if (deduped.length === unionNode.members.length) return void 0;
122
- return {
123
- ...unionNode,
124
- members: deduped
125
- };
126
- }
127
- });
128
- /**
129
- * The name `macroDedupeUnion` had before 5.16. Kept so a plugin built against an older `@kubb/kit` keeps running.
130
- *
131
- * @deprecated Use `macroDedupeUnion`. Removed in the next major.
132
- */
133
- const macroSimplifyUnion = macroDedupeUnion;
134
296
  // src/macros/macroDiscriminatorEnum.ts
135
297
  /**
136
298
  * Picks the enum primitive from the type of the first value.
@@ -150,10 +312,10 @@ function enumPrimitive(values) {
150
312
  * ```
151
313
  */
152
314
  function macroDiscriminatorEnum({ propertyName, values, enumName }) {
153
- return _kubb_ast.ast.defineMacro({
315
+ return defineMacro({
154
316
  name: "discriminator-enum",
155
317
  schema(node) {
156
- const objectNode = _kubb_ast.ast.narrowSchema(node, "object");
318
+ const objectNode = _kubb_ast.ast.schema.narrow(node, "object");
157
319
  if (!objectNode?.properties?.length) return void 0;
158
320
  if (!objectNode.properties.some((prop) => prop.name === propertyName)) return void 0;
159
321
  return _kubb_ast.ast.factory.createSchema({
@@ -176,54 +338,7 @@ function macroDiscriminatorEnum({ propertyName, values, enumName }) {
176
338
  }
177
339
  });
178
340
  }
179
- // ../../internals/utils/src/casing.ts
180
- /**
181
- * Shared implementation for camelCase and PascalCase conversion.
182
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
183
- * and capitalizes each word according to `pascal`.
184
- *
185
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
186
- */
187
- function convert(text, pascal) {
188
- return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)(?!xx(?![a-z]))([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
189
- if (word.length > 1 && word === word.toUpperCase()) return word;
190
- return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
191
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
192
- }
193
- const cache = /* @__PURE__ */ new Map();
194
- const cacheLimit = 1e5;
195
- function toCamelOrPascal(text, pascal) {
196
- const key = `${pascal ? "P" : "c"}${text}`;
197
- const cached = cache.get(key);
198
- if (cached !== void 0) return cached;
199
- const result = convert(text, pascal);
200
- if (cache.size >= cacheLimit) cache.clear();
201
- cache.set(key, result);
202
- return result;
203
- }
204
- /**
205
- * Converts `text` to PascalCase.
206
- *
207
- * @example Word boundaries
208
- * `pascalCase('hello-world') // 'HelloWorld'`
209
- *
210
- * @example With a suffix
211
- * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
212
- */
213
- function pascalCase$1(text, { prefix = "", suffix = "" } = {}) {
214
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
215
- }
216
- __name(pascalCase$1, "pascalCase");
217
- // src/utils/refs.ts
218
- const plainStringTypes = /* @__PURE__ */ new Set([
219
- "string",
220
- "uuid",
221
- "email",
222
- "url",
223
- "datetime"
224
- ]);
225
- /** Returns the last path segment of a reference string, for example `'Pet'` for `#/components/schemas/Pet`. */
226
- const extractRefName = _kubb_ast.ast.refName;
341
+ // src/utils/names.ts
227
342
  /**
228
343
  * Builds a PascalCase child schema name by joining a parent name and property name.
229
344
  * Returns `null` when there is no parent to nest under.
@@ -251,33 +366,6 @@ function enumPropName(parentName, propName, enumSuffix) {
251
366
  enumSuffix
252
367
  ].filter(Boolean).join(" "));
253
368
  }
254
- /**
255
- * Applies `ast.mergeRefWithSchema()` to a resolved ref and rebuilds the result through
256
- * `ast.factory.createSchema()`. Non-ref nodes and unresolved refs are returned unchanged.
257
- *
258
- * @example
259
- * ```ts
260
- * const ref = ast.factory.createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
261
- * const merged = syncSchemaRef(ref) // merges with resolved Pet schema
262
- * ```
263
- */
264
- function syncSchemaRef(node) {
265
- const ref = _kubb_ast.ast.narrowSchema(node, "ref");
266
- if (!ref?.schema) return node;
267
- return _kubb_ast.ast.factory.createSchema(_kubb_ast.ast.mergeRefWithSchema(ref));
268
- }
269
- /**
270
- * Returns `true` when a schema emits as a plain `string` type.
271
- *
272
- * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
273
- * types, returns `true` only when `representation` is `'string'` rather than `'date'`.
274
- */
275
- function isStringType(node) {
276
- if (plainStringTypes.has(node.type)) return true;
277
- const temporal = _kubb_ast.ast.narrowSchema(node, "date") ?? _kubb_ast.ast.narrowSchema(node, "time");
278
- if (temporal) return temporal.representation !== "date";
279
- return false;
280
- }
281
369
  // src/macros/macroEnumName.ts
282
370
  /**
283
371
  * Builds a macro that names an inline enum schema from its parent and property name. Boolean enums
@@ -290,10 +378,10 @@ function isStringType(node) {
290
378
  * ```
291
379
  */
292
380
  function macroEnumName({ parentName, propName, enumSuffix }) {
293
- return _kubb_ast.ast.defineMacro({
381
+ return defineMacro({
294
382
  name: "enum-name",
295
383
  schema(node) {
296
- const enumNode = _kubb_ast.ast.narrowSchema(node, "enum");
384
+ const enumNode = _kubb_ast.ast.schema.narrow(node, "enum");
297
385
  if (enumNode?.primitive === "boolean") return {
298
386
  ...node,
299
387
  name: null
@@ -319,9 +407,9 @@ function macroEnumName({ parentName, propName, enumSuffix }) {
319
407
  function* mergeAdjacentObjectsLazy(members) {
320
408
  let acc;
321
409
  for (const member of members) {
322
- const objectMember = _kubb_ast.ast.narrowSchema(member, "object");
410
+ const objectMember = _kubb_ast.ast.schema.narrow(member, "object");
323
411
  if (objectMember && !objectMember.name && acc !== void 0) {
324
- const accObject = _kubb_ast.ast.narrowSchema(acc, "object");
412
+ const accObject = _kubb_ast.ast.schema.narrow(acc, "object");
325
413
  if (accObject && !accObject.name) {
326
414
  acc = _kubb_ast.ast.factory.createSchema({
327
415
  ...accObject,
@@ -335,20 +423,6 @@ function* mergeAdjacentObjectsLazy(members) {
335
423
  }
336
424
  if (acc !== void 0) yield acc;
337
425
  }
338
- // src/utils/schemaGraph.ts
339
- /**
340
- * Returns `true` when a schema, or anything nested inside it, references a circular schema.
341
- *
342
- * Pass `excludeName` to skip refs to a specific schema, which helps when self-references are handled
343
- * on their own. Pair it with `ast.findCircularSchemas()` to decide where lazy wrappers go.
344
- *
345
- * @note Reads the memoized `ast.collectSchemaRefs()` set, so a schema is scanned once across plugins.
346
- */
347
- function containsCircularRef(node, { circularSchemas, excludeName }) {
348
- if (!node || circularSchemas.size === 0) return false;
349
- for (const name of _kubb_ast.ast.collectSchemaRefs(node)) if (name !== excludeName && circularSchemas.has(name)) return true;
350
- return false;
351
- }
352
426
  Object.defineProperty(exports, "Diagnostics", {
353
427
  enumerable: true,
354
428
  get: function() {
@@ -392,10 +466,11 @@ Object.defineProperty(exports, "ast", {
392
466
  return _kubb_ast.ast;
393
467
  }
394
468
  });
395
- Object.defineProperty(exports, "camelCase", {
469
+ exports.camelCase = camelCase;
470
+ Object.defineProperty(exports, "casing", {
396
471
  enumerable: true,
397
472
  get: function() {
398
- return _kubb_core.camelCase;
473
+ return casing_exports;
399
474
  }
400
475
  });
401
476
  exports.childName = childName;
@@ -406,6 +481,7 @@ Object.defineProperty(exports, "createAdapter", {
406
481
  return _kubb_core.createAdapter;
407
482
  }
408
483
  });
484
+ exports.createPrinter = createPrinter;
409
485
  Object.defineProperty(exports, "createRenderer", {
410
486
  enumerable: true,
411
487
  get: function() {
@@ -436,6 +512,7 @@ Object.defineProperty(exports, "defineGenerator", {
436
512
  return _kubb_core.defineGenerator;
437
513
  }
438
514
  });
515
+ exports.defineMacro = defineMacro;
439
516
  Object.defineProperty(exports, "defineParser", {
440
517
  enumerable: true,
441
518
  get: function() {
@@ -499,12 +576,7 @@ Object.defineProperty(exports, "memoryStorage", {
499
576
  }
500
577
  });
501
578
  exports.mergeAdjacentObjectsLazy = mergeAdjacentObjectsLazy;
502
- Object.defineProperty(exports, "pascalCase", {
503
- enumerable: true,
504
- get: function() {
505
- return _kubb_core.pascalCase;
506
- }
507
- });
579
+ exports.pascalCase = pascalCase;
508
580
  Object.defineProperty(exports, "requirePlugin", {
509
581
  enumerable: true,
510
582
  get: function() {
@@ -530,6 +602,12 @@ Object.defineProperty(exports, "setResolver", {
530
602
  }
531
603
  });
532
604
  exports.syncSchemaRef = syncSchemaRef;
605
+ Object.defineProperty(exports, "text", {
606
+ enumerable: true,
607
+ get: function() {
608
+ return text_exports;
609
+ }
610
+ });
533
611
  Object.defineProperty(exports, "tryUseKubb", {
534
612
  enumerable: true,
535
613
  get: function() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["ast","hash","ast","pascalCase","ast","pascalCase","ast","ast","ast"],"sources":["../src/Url.ts","../src/macros/macroDedupeUnion.ts","../src/macros/macroDiscriminatorEnum.ts","../../../internals/utils/src/casing.ts","../src/utils/refs.ts","../src/macros/macroEnumName.ts","../src/utils/mergeAdjacentSchemas.ts","../src/utils/schemaGraph.ts"],"sourcesContent":["/**\n * Sanitizes a parameter name so it is safe to use as a `path-to-regexp` capture name, without\n * routing through {@link camelCase} (which keeps a leading `$` since it is a valid JS identifier\n * character). Runs of disallowed characters are treated as word boundaries; a boundary at the\n * very start of the name (e.g. the `$` in `$id`) still capitalizes the word that follows it.\n */\nfunction transformPathParam(raw: string): string {\n // `path-to-regexp` (used by MSW/Express) only accepts `[A-Za-z0-9_]` in a parameter name. It stops\n // reading at the first other character (a hyphen, a dot, a `$`, ...), which misparses the route or\n // throws \"Missing parameter name\".\n if (/^[A-Za-z0-9_]+$/.test(raw)) {\n return raw\n }\n\n const startsWithSafeChar = /^[A-Za-z_]/.test(raw)\n const words = raw.split(/[^A-Za-z0-9]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const capitalize = !startsWithSafeChar || i > 0\n return capitalize ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toLowerCase() + word.slice(1)\n })\n .join('')\n}\n\n/**\n * Renders how a grouped `path` object's member is accessed: dot access for an identifier (reserved\n * words are valid property names), bracket access with the raw name otherwise.\n */\nfunction groupedAccessor(name: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name) ? `.${name}` : `[${JSON.stringify(name)}]`\n}\n\n/**\n * Static helpers for OpenAPI/Swagger paths: template syntax conversion, parameter extraction, and URL composition.\n */\nexport class Url {\n /**\n * Converts an OpenAPI/Swagger path to Express-style colon syntax.\n *\n * Distinct parameter names that normalize to the same identifier (e.g. `{group-id}` and\n * `{group.id}` both becoming `groupId`) are deduplicated with an incrementing suffix so\n * `path-to-regexp` never sees two identically named captures.\n *\n * @example\n * Url.toPath('/pet/{petId}') // '/pet/:petId'\n *\n * @example\n * Url.toPath('/point/{point-id}') // '/point/:pointId'\n *\n * @example\n * Url.toPath('/groups/{group-id}/{group.id}.json') // '/groups/:groupId/:groupId2.json'\n */\n static toPath(path: string): string {\n const seen = new Map<string, number>()\n\n return path.replace(/\\{([^}]+)\\}/g, (_match, param: string) => {\n const base = transformPathParam(param)\n const count = (seen.get(base) ?? 0) + 1\n seen.set(base, count)\n\n return count === 1 ? `:${base}` : `:${base}${count}`\n })\n }\n\n /**\n * Converts an OpenAPI/Swagger path to a template literal that reads each parameter off a\n * grouped `path` request option, e.g. `/pet/{petId}` becomes `` `/pet/${path.petId}` ``.\n * Parameter names are kept exactly as they appear in the OpenAPI path; a name falls back to\n * bracket access (`` path['pet-id'] ``) only when it isn't a valid JS identifier.\n * `prefix` is prepended inside the literal. Shared by generators that pass a grouped `path` object.\n *\n * @example\n * Url.toGroupedTemplateString('/pet/{petId}') // '`/pet/${path.petId}`'\n *\n * @example\n * Url.toGroupedTemplateString('/user/{monetary-account-id}') // '`/user/${path[\"monetary-account-id\"]}`'\n */\n static toGroupedTemplateString(path: string, { prefix }: { prefix?: string | null } = {}): string {\n const parts = path.split(/\\{([^}]+)\\}/)\n const result = parts.map((part, i) => (i % 2 === 0 ? part : `\\${path${groupedAccessor(part)}}`)).join('')\n\n return `\\`${prefix ?? ''}${result}\\``\n }\n}\n","import { hash } from 'node:crypto'\nimport { ast } from '@kubb/ast'\nimport type { SchemaNode } from '@kubb/ast'\n\n/**\n * Drops members that repeat an earlier one, ignoring the source `pointer` so equal schemas from\n * different places in the spec still match.\n */\nfunction dedupeMembers(members: Array<SchemaNode>): Array<SchemaNode> {\n const seen = new Set<string>()\n const keys = new WeakMap<object, string>()\n\n function key(value: unknown): string {\n if (value === null || typeof value !== 'object') return JSON.stringify(value) ?? 'undefined'\n if (value instanceof Date) return key(value.toJSON())\n const cached = keys.get(value)\n if (cached) return cached\n\n // A ref node's `ref` pointer already identifies its target, so hashing its resolved `schema` as\n // well only walks the same component graph again for every union that references it. The `kind`\n // check keeps plain data under `default` or `examples` hashed in full.\n const node = value as Partial<SchemaNode>\n const skipsSchema = node.kind === ast.nodeKinds.schema && node.type === ast.schemaTypes.ref && typeof node.ref === 'string'\n // Hash each shared subtree once instead of expanding resolved refs into a giant string.\n const entries = Array.isArray(value)\n ? value.map(key)\n : Object.entries(value)\n .filter(([name, child]) => name !== 'pointer' && child !== undefined && !(skipsSchema && name === 'schema'))\n .map(([name, child]) => [name, key(child)])\n const result = hash('sha256', JSON.stringify([Array.isArray(value), entries]))\n keys.set(value, result)\n return result\n }\n\n return members.filter((member) => {\n const memberKey = key(member)\n if (seen.has(memberKey)) return false\n seen.add(memberKey)\n\n return true\n })\n}\n\n/**\n * Removes union members that repeat an earlier one. Enum members next to a broader scalar, such as\n * `anyOf: [string, enum]`, are kept so the known values survive in the generated code.\n *\n * @example\n * ```ts\n * const next = applyMacros(unionSchema, [macroDedupeUnion], { depth: 'shallow' })\n * ```\n */\nexport const macroDedupeUnion = ast.defineMacro({\n name: 'dedupe-union',\n schema(node) {\n const unionNode = ast.narrowSchema(node, ast.schemaTypes.union)\n if (!unionNode?.members?.length) return undefined\n\n const deduped = dedupeMembers(unionNode.members)\n if (deduped.length === unionNode.members.length) return undefined\n\n return { ...unionNode, members: deduped }\n },\n})\n\n/**\n * The name `macroDedupeUnion` had before 5.16. Kept so a plugin built against an older `@kubb/kit` keeps running.\n *\n * @deprecated Use `macroDedupeUnion`. Removed in the next major.\n */\nexport const macroSimplifyUnion = macroDedupeUnion\n","import { ast } from '@kubb/ast'\n\ntype Props = {\n propertyName: string\n values: Array<string | number | boolean>\n enumName?: string\n}\n\n/**\n * Picks the enum primitive from the type of the first value.\n */\nexport function enumPrimitive(values: Props['values']): 'string' | 'number' | 'boolean' {\n return typeof values[0] === 'number' ? 'number' : typeof values[0] === 'boolean' ? 'boolean' : 'string'\n}\n\n/**\n * Builds a macro that replaces a discriminator property's schema with an enum of the given\n * values. The enum is a string, number or boolean enum, following the first value. Object schemas\n * that lack the property are returned unchanged.\n *\n * @example\n * ```ts\n * const macro = macroDiscriminatorEnum({ propertyName: 'type', values: ['dog', 'cat'] })\n * const next = applyMacros(objectSchema, [macro], { depth: 'shallow' })\n * ```\n */\nexport function macroDiscriminatorEnum({ propertyName, values, enumName }: Props) {\n return ast.defineMacro({\n name: 'discriminator-enum',\n schema(node) {\n const objectNode = ast.narrowSchema(node, 'object')\n if (!objectNode?.properties?.length) return undefined\n if (!objectNode.properties.some((prop) => prop.name === propertyName)) return undefined\n\n return ast.factory.createSchema({\n ...objectNode,\n properties: objectNode.properties.map((prop) => {\n if (prop.name !== propertyName) return prop\n\n return ast.factory.createProperty({\n ...prop,\n schema: ast.factory.createSchema({\n type: 'enum',\n primitive: enumPrimitive(values),\n enumValues: values,\n name: enumName,\n readOnly: prop.schema.readOnly,\n writeOnly: prop.schema.writeOnly,\n }),\n })\n }),\n })\n },\n })\n}\n","type Options = {\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction convert(text: string, pascal: boolean): string {\n return (\n text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n // A status range such as `2xx` stays one word.\n .replace(/(\\d)(?!xx(?![a-z]))([a-z])/g, '$1 $2')\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .map((word, i) => {\n if (word.length > 1 && word === word.toUpperCase()) return word\n const head = i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()\n return head + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n )\n}\n\n// Plugins case the same names on every visit. Clearing at the limit bounds a long-running host.\nconst cache = new Map<string, string>()\nconst cacheLimit = 100_000\n\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const key = `${pascal ? 'P' : 'c'}${text}`\n const cached = cache.get(key)\n if (cached !== undefined) return cached\n\n const result = convert(text, pascal)\n if (cache.size >= cacheLimit) cache.clear()\n cache.set(key, result)\n return result\n}\n\n/**\n * Converts `text` to camelCase.\n *\n * @example Word boundaries\n * `camelCase('hello-world') // 'helloWorld'`\n *\n * @example With a prefix\n * `camelCase('tag', { prefix: 'create' }) // 'createTag'`\n */\nexport function camelCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n *\n * @example Word boundaries\n * `pascalCase('hello-world') // 'HelloWorld'`\n *\n * @example With a suffix\n * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`\n */\nexport function pascalCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","import { ast } from '@kubb/ast'\nimport type { SchemaNode, SchemaType } from '@kubb/ast'\nimport { pascalCase } from '@internals/utils'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/** Returns the last path segment of a reference string, for example `'Pet'` for `#/components/schemas/Pet`. */\nexport const extractRefName = ast.refName\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 Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\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 * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\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 * Applies `ast.mergeRefWithSchema()` to a resolved ref and rebuilds the result through\n * `ast.factory.createSchema()`. Non-ref nodes and unresolved refs are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = ast.factory.createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = ast.narrowSchema(node, 'ref')\n\n if (!ref?.schema) return node\n\n return ast.factory.createSchema(ast.mergeRefWithSchema(ref))\n}\n\n/**\n * 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 = ast.narrowSchema(node, 'date') ?? ast.narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n","import { ast } from '@kubb/ast'\nimport { enumPropName } from '../utils/refs.ts'\n\ntype Props = {\n parentName: string | null | undefined\n propName: string\n enumSuffix: string\n}\n\n/**\n * Builds a macro that names an inline enum schema from its parent and property name. Boolean enums\n * are left anonymous. Non-enum nodes are returned unchanged.\n *\n * @example\n * ```ts\n * const macro = macroEnumName({ parentName: 'Pet', propName: 'status', enumSuffix: 'enum' })\n * const named = applyMacros(propSchema, [macro], { depth: 'shallow' })\n * ```\n */\nexport function macroEnumName({ parentName, propName, enumSuffix }: Props) {\n return ast.defineMacro({\n name: 'enum-name',\n schema(node) {\n const enumNode = ast.narrowSchema(node, 'enum')\n\n if (enumNode?.primitive === 'boolean') return { ...node, name: null }\n if (enumNode) return { ...node, name: enumPropName(parentName, propName, enumSuffix) }\n\n return undefined\n },\n })\n}\n","import { ast } from '@kubb/ast'\nimport type { SchemaNode } from '@kubb/ast'\n\n/**\n * Merges a run of adjacent anonymous object members into one. Named or non-object members break the\n * run and pass through unchanged. The merge follows member order, so callers control which members\n * combine by where they place them in the sequence.\n *\n * @example\n * ```ts\n * const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]\n * ```\n */\nexport function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {\n let acc: SchemaNode | undefined\n\n for (const member of members) {\n const objectMember = ast.narrowSchema(member, 'object')\n if (objectMember && !objectMember.name && acc !== undefined) {\n const accObject = ast.narrowSchema(acc, 'object')\n if (accObject && !accObject.name) {\n acc = ast.factory.createSchema({\n ...accObject,\n properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n continue\n }\n }\n if (acc !== undefined) yield acc\n acc = member\n }\n\n if (acc !== undefined) yield acc\n}\n","import { ast } from '@kubb/ast'\nimport type { SchemaNode } from '@kubb/ast'\n\n/**\n * Returns `true` when a schema, or anything nested inside it, references a circular schema.\n *\n * Pass `excludeName` to skip refs to a specific schema, which helps when self-references are handled\n * on their own. Pair it with `ast.findCircularSchemas()` to decide where lazy wrappers go.\n *\n * @note Reads the memoized `ast.collectSchemaRefs()` set, so a schema is scanned once across plugins.\n */\nexport function containsCircularRef(\n node: SchemaNode | undefined,\n { circularSchemas, excludeName }: { circularSchemas: ReadonlySet<string>; excludeName?: string },\n): boolean {\n if (!node || circularSchemas.size === 0) return false\n\n for (const name of ast.collectSchemaRefs(node)) {\n if (name !== excludeName && circularSchemas.has(name)) return true\n }\n\n return false\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAMA,SAAS,mBAAmB,KAAqB;CAI/C,IAAI,kBAAkB,KAAK,GAAG,GAC5B,OAAO;CAGT,MAAM,qBAAqB,aAAa,KAAK,GAAG;CAGhD,OAFc,IAAI,MAAM,eAAe,CAAC,CAAC,OAAO,OAErC,CAAC,CACT,KAAK,MAAM,MAAM;EAEhB,OADmB,CAAC,sBAAsB,IAAI,IAC1B,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,KAAK,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,KAAK,MAAM,CAAC;CAChH,CAAC,CAAC,CACD,KAAK,EAAE;AACZ;;;;;AAMA,SAAS,gBAAgB,MAAsB;CAC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AAW,OAAO;IAAE,GAAG;IAAM,MAAM;GAAK;GACpE,IAAI,UAAU,OAAO;IAAE,GAAG;IAAM,MAAM,aAAa,YAAY,UAAU,UAAU;GAAE;EAGvF;CACF,CAAC;AACH;;;;;;;;;;;;AClBA,UAAiB,yBAAyB,SAAuE;CAC/G,IAAI;CAEJ,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,eAAeC,UAAAA,IAAI,aAAa,QAAQ,QAAQ;EACtD,IAAI,gBAAgB,CAAC,aAAa,QAAQ,QAAQ,KAAA,GAAW;GAC3D,MAAM,YAAYA,UAAAA,IAAI,aAAa,KAAK,QAAQ;GAChD,IAAI,aAAa,CAAC,UAAU,MAAM;IAChC,MAAMA,UAAAA,IAAI,QAAQ,aAAa;KAC7B,GAAG;KACH,YAAY,CAAC,GAAI,UAAU,cAAc,CAAC,GAAI,GAAI,aAAa,cAAc,CAAC,CAAE;IAClF,CAAC;IACD;GACF;EACF;EACA,IAAI,QAAQ,KAAA,GAAW,MAAM;EAC7B,MAAM;CACR;CAEA,IAAI,QAAQ,KAAA,GAAW,MAAM;AAC/B;;;;;;;;;;ACtBA,SAAgB,oBACd,MACA,EAAE,iBAAiB,eACV;CACT,IAAI,CAAC,QAAQ,gBAAgB,SAAS,GAAG,OAAO;CAEhD,KAAK,MAAM,QAAQC,UAAAA,IAAI,kBAAkB,IAAI,GAC3C,IAAI,SAAS,eAAe,gBAAgB,IAAI,IAAI,GAAG,OAAO;CAGhE,OAAO;AACT"}
1
+ {"version":3,"file":"index.cjs","names":["pascalCase","astCreatePrinter","astDefineMacro","ast","hash","camel","pascal","ast","ast","pascalCase","ast","ast"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/text.ts","../src/casing.ts","../src/text.ts","../src/authoring.ts","../src/macros/macroDedupeUnion.ts","../src/deprecated.ts","../src/Url.ts","../src/macros/macroDiscriminatorEnum.ts","../src/utils/names.ts","../src/macros/macroEnumName.ts","../src/utils/mergeAdjacentSchemas.ts"],"sourcesContent":["type Options = {\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction convert(text: string, pascal: boolean): string {\n return (\n text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n // A status range such as `2xx` stays one word.\n .replace(/(\\d)(?!xx(?![a-z]))([a-z])/g, '$1 $2')\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .map((word, i) => {\n if (word.length > 1 && word === word.toUpperCase()) return word\n const head = i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()\n return head + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n )\n}\n\n// Plugins case the same names on every visit. Clearing at the limit bounds a long-running host.\nconst cache = new Map<string, string>()\nconst cacheLimit = 100_000\n\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const key = `${pascal ? 'P' : 'c'}${text}`\n const cached = cache.get(key)\n if (cached !== undefined) return cached\n\n const result = convert(text, pascal)\n if (cache.size >= cacheLimit) cache.clear()\n cache.set(key, result)\n return result\n}\n\n/**\n * Converts `text` to camelCase.\n *\n * @example Word boundaries\n * `camelCase('hello-world') // 'helloWorld'`\n *\n * @example With a prefix\n * `camelCase('tag', { prefix: 'create' }) // 'createTag'`\n */\nexport function camelCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n *\n * @example Word boundaries\n * `pascalCase('hello-world') // 'HelloWorld'`\n *\n * @example With a suffix\n * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`\n */\nexport function pascalCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n// A word starts at `petType`, `sensor2Reading`, and `HTTPResponse`, while `IDs` and `OAuth` stay whole\nconst wordStart = /(?<=[a-z\\d])(?=[A-Z])|(?<=[A-Z]{2})(?=[A-Z][a-z]{2})/\n\n// A segment without lowercase letters, such as `COOL` or `2D`, stays one word, so a snake_case name is left unchanged.\nfunction words(text: string): Array<string> {\n return text\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .flatMap((segment) => (segment === segment.toUpperCase() ? segment : segment.split(wordStart)))\n}\n\n/**\n * Uppercases only the first character of `text`. Unlike `pascalCase` it never splits words or strips characters.\n *\n * @example\n * `capitalize('getPetById') // 'GetPetById'`\n */\nexport function capitalize(text: string): string {\n return `${text.charAt(0).toUpperCase()}${text.slice(1)}`\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * `snakeCase('helloWorld') // 'hello_world'`\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return words(`${prefix} ${text} ${suffix}`)\n .map((word) => word.replace(/[^a-zA-Z0-9]/g, '').toLowerCase())\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * `screamingSnakeCase('helloWorld') // 'HELLO_WORLD'`\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * Indents every non-empty line of `text` by `unit`, leaving blank lines empty.\n * @example\n * `indent({ text: 'a\\n\\nb' }) // ' a\\n\\n b'`\n */\nexport function indent({ text, unit = ' ' }: { text: string; unit?: string }): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${unit}${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Strips the common leading whitespace and the surrounding blank lines, counting tabs and spaces alike, so indented template literals start at column zero.\n */\nexport function dedent(text: string): string {\n if (!text) return ''\n // Most text nodes are one line, so the common indent is its leading whitespace.\n if (!text.includes('\\n')) return text.trim() ? text.trimStart() : ''\n\n const lines = text.split('\\n')\n const indents = lines.map((line) => {\n const indent = line.length - line.trimStart().length\n return indent === line.length ? -1 : indent\n })\n const start = indents.findIndex((indent) => indent !== -1)\n if (start === -1) return ''\n const end = indents.findLastIndex((indent) => indent !== -1)\n // `-1` marks a blank line. `reduce`, not `Math.min(...indents)`, which overflows the stack on very long text.\n const min = indents.reduce((lowest, indent) => (indent !== -1 && indent < lowest ? indent : lowest), Infinity)\n\n return lines\n .slice(start, end + 1)\n .map((line, i) => (indents[start + i] === -1 ? '' : line.slice(min)))\n .join('\\n')\n}\n\n/**\n * Strips one matching pair of `\"`, `'` or `` ` `` from both ends of `text`. Returns `text` unchanged without a matching pair.\n * @example\n * `unquote('\"hello\"') // 'hello'`\n */\nexport function unquote(text: string): string {\n if (text.length < 2) return text\n const first = text[0]\n return (first === '\"' || first === \"'\" || first === '`') && text.at(-1) === first ? text.slice(1, -1) : text\n}\n","export { camelCase as camel, pascalCase as pascal } from '@kubb/core'\nexport { capitalize, screamingSnakeCase as screamingSnake, snakeCase as snake } from '@internals/utils'\n","export { dedent, indent, unquote } from '@internals/utils'\n\n// A raw line break would end the literal.\nconst quoteEscapes = new Map([\n ['\\\\', '\\\\\\\\'],\n [\"'\", \"\\\\'\"],\n ['\\n', '\\\\n'],\n ['\\r', '\\\\r'],\n])\n\n/**\n * A single-quoted string literal with backslashes, quotes and line breaks escaped. JavaScript, TypeScript and Python read it the same way.\n */\nexport function quote(value: string | number | boolean | undefined | null): string {\n if (value === undefined || value === null) return \"''\"\n return `'${Array.from(String(value), (char) => quoteEscapes.get(char) ?? char).join('')}'`\n}\n","import { createPrinter as astCreatePrinter, defineMacro as astDefineMacro } from '@kubb/ast'\n\nexport const createPrinter: typeof astCreatePrinter = astCreatePrinter\nexport const defineMacro: typeof astDefineMacro = astDefineMacro\n","import { hash } from 'node:crypto'\nimport { ast } from '@kubb/ast'\nimport { defineMacro } from '../authoring.ts'\nimport type { SchemaNode } from '@kubb/ast'\n\n/**\n * Drops members that repeat an earlier one, ignoring the source `pointer` so equal schemas from\n * different places in the spec still match.\n */\nfunction dedupeMembers(members: Array<SchemaNode>): Array<SchemaNode> {\n const seen = new Set<string>()\n const keys = new WeakMap<object, string>()\n\n function key(value: unknown): string {\n if (value === null || typeof value !== 'object') return JSON.stringify(value) ?? 'undefined'\n if (value instanceof Date) return key(value.toJSON())\n const cached = keys.get(value)\n if (cached) return cached\n\n // A ref node's `ref` pointer already identifies its target, so hashing its resolved `schema` as\n // well only walks the same component graph again for every union that references it. The `kind`\n // check keeps plain data under `default` or `examples` hashed in full.\n const node = value as Partial<SchemaNode>\n const skipsSchema = node.kind === ast.node.kinds.schema && node.type === ast.schema.types.ref && typeof node.ref === 'string'\n // Hash each shared subtree once instead of expanding resolved refs into a giant string.\n const entries = Array.isArray(value)\n ? value.map(key)\n : Object.entries(value)\n .filter(([name, child]) => name !== 'pointer' && child !== undefined && !(skipsSchema && name === 'schema'))\n .map(([name, child]) => [name, key(child)])\n const result = hash('sha256', JSON.stringify([Array.isArray(value), entries]))\n keys.set(value, result)\n return result\n }\n\n return members.filter((member) => {\n const memberKey = key(member)\n if (seen.has(memberKey)) return false\n seen.add(memberKey)\n\n return true\n })\n}\n\n/**\n * Removes union members that repeat an earlier one. Enum members next to a broader scalar, such as\n * `anyOf: [string, enum]`, are kept so the known values survive in the generated code.\n *\n * @example\n * ```ts\n * const next = applyMacros(unionSchema, [macroDedupeUnion], { depth: 'shallow' })\n * ```\n */\nexport const macroDedupeUnion = defineMacro({\n name: 'dedupe-union',\n schema(node) {\n const unionNode = ast.schema.narrow(node, ast.schema.types.union)\n if (!unionNode?.members?.length) return undefined\n\n const deduped = dedupeMembers(unionNode.members)\n if (deduped.length === unionNode.members.length) return undefined\n\n return { ...unionNode, members: deduped }\n },\n})\n","import { ast } from '@kubb/ast'\nimport { camelCase as camel, pascalCase as pascal } from '@kubb/core'\nimport { macroDedupeUnion } from './macros/macroDedupeUnion.ts'\n\n/** @deprecated Use `casing.camel`. Removed in Kubb v6. */\nexport const camelCase = camel\n\n/** @deprecated Use `casing.pascal`. Removed in Kubb v6. */\nexport const pascalCase = pascal\n\n/** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */\nexport const extractRefName = ast.ref.getName\n\n/** @deprecated Use `ast.ref.mergeSchema`. Removed in Kubb v6. */\nexport const syncSchemaRef = ast.ref.mergeSchema\n\n/** @deprecated Use `ast.schema.isString`. Removed in Kubb v6. */\nexport const isStringType = ast.schema.isString\n\n/** @deprecated Use `ast.graph.containsCircular`. Removed in Kubb v6. */\nexport const containsCircularRef = ast.graph.containsCircular\n\n/**\n * The name `macroDedupeUnion` had before 5.16. Kept so a plugin built against an older `@kubb/kit` keeps running.\n *\n * @deprecated Use `macroDedupeUnion`. Removed in the next major.\n */\nexport const macroSimplifyUnion = macroDedupeUnion\n","/**\n * Sanitizes a parameter name so it is safe to use as a `path-to-regexp` capture name, without\n * routing through {@link camelCase} (which keeps a leading `$` since it is a valid JS identifier\n * character). Runs of disallowed characters are treated as word boundaries; a boundary at the\n * very start of the name (e.g. the `$` in `$id`) still capitalizes the word that follows it.\n */\nfunction transformPathParam(raw: string): string {\n // `path-to-regexp` (used by MSW/Express) only accepts `[A-Za-z0-9_]` in a parameter name. It stops\n // reading at the first other character (a hyphen, a dot, a `$`, ...), which misparses the route or\n // throws \"Missing parameter name\".\n if (/^[A-Za-z0-9_]+$/.test(raw)) {\n return raw\n }\n\n const startsWithSafeChar = /^[A-Za-z_]/.test(raw)\n const words = raw.split(/[^A-Za-z0-9]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const capitalize = !startsWithSafeChar || i > 0\n return capitalize ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toLowerCase() + word.slice(1)\n })\n .join('')\n}\n\n/**\n * Renders how a grouped `path` object's member is accessed: dot access for an identifier (reserved\n * words are valid property names), bracket access with the raw name otherwise.\n */\nfunction groupedAccessor(name: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name) ? `.${name}` : `[${JSON.stringify(name)}]`\n}\n\n/**\n * Static helpers for OpenAPI/Swagger paths: template syntax conversion, parameter extraction, and URL composition.\n */\nexport class Url {\n /**\n * Converts an OpenAPI/Swagger path to Express-style colon syntax.\n *\n * Distinct parameter names that normalize to the same identifier (e.g. `{group-id}` and\n * `{group.id}` both becoming `groupId`) are deduplicated with an incrementing suffix so\n * `path-to-regexp` never sees two identically named captures.\n *\n * @example\n * Url.toPath('/pet/{petId}') // '/pet/:petId'\n *\n * @example\n * Url.toPath('/point/{point-id}') // '/point/:pointId'\n *\n * @example\n * Url.toPath('/groups/{group-id}/{group.id}.json') // '/groups/:groupId/:groupId2.json'\n */\n static toPath(path: string): string {\n const seen = new Map<string, number>()\n\n return path.replace(/\\{([^}]+)\\}/g, (_match, param: string) => {\n const base = transformPathParam(param)\n const count = (seen.get(base) ?? 0) + 1\n seen.set(base, count)\n\n return count === 1 ? `:${base}` : `:${base}${count}`\n })\n }\n\n /**\n * Converts an OpenAPI/Swagger path to a template literal that reads each parameter off a\n * grouped `path` request option, e.g. `/pet/{petId}` becomes `` `/pet/${path.petId}` ``.\n * Parameter names are kept exactly as they appear in the OpenAPI path; a name falls back to\n * bracket access (`` path['pet-id'] ``) only when it isn't a valid JS identifier.\n * `prefix` is prepended inside the literal. Shared by generators that pass a grouped `path` object.\n *\n * @example\n * Url.toGroupedTemplateString('/pet/{petId}') // '`/pet/${path.petId}`'\n *\n * @example\n * Url.toGroupedTemplateString('/user/{monetary-account-id}') // '`/user/${path[\"monetary-account-id\"]}`'\n */\n static toGroupedTemplateString(path: string, { prefix }: { prefix?: string | null } = {}): string {\n const parts = path.split(/\\{([^}]+)\\}/)\n const result = parts.map((part, i) => (i % 2 === 0 ? part : `\\${path${groupedAccessor(part)}}`)).join('')\n\n return `\\`${prefix ?? ''}${result}\\``\n }\n}\n","import { ast } from '@kubb/ast'\nimport { defineMacro } from '../authoring.ts'\n\ntype Props = {\n propertyName: string\n values: Array<string | number | boolean>\n enumName?: string\n}\n\n/**\n * Picks the enum primitive from the type of the first value.\n */\nexport function enumPrimitive(values: Props['values']): 'string' | 'number' | 'boolean' {\n return typeof values[0] === 'number' ? 'number' : typeof values[0] === 'boolean' ? 'boolean' : 'string'\n}\n\n/**\n * Builds a macro that replaces a discriminator property's schema with an enum of the given\n * values. The enum is a string, number or boolean enum, following the first value. Object schemas\n * that lack the property are returned unchanged.\n *\n * @example\n * ```ts\n * const macro = macroDiscriminatorEnum({ propertyName: 'type', values: ['dog', 'cat'] })\n * const next = applyMacros(objectSchema, [macro], { depth: 'shallow' })\n * ```\n */\nexport function macroDiscriminatorEnum({ propertyName, values, enumName }: Props) {\n return defineMacro({\n name: 'discriminator-enum',\n schema(node) {\n const objectNode = ast.schema.narrow(node, 'object')\n if (!objectNode?.properties?.length) return undefined\n if (!objectNode.properties.some((prop) => prop.name === propertyName)) return undefined\n\n return ast.factory.createSchema({\n ...objectNode,\n properties: objectNode.properties.map((prop) => {\n if (prop.name !== propertyName) return prop\n\n return ast.factory.createProperty({\n ...prop,\n schema: ast.factory.createSchema({\n type: 'enum',\n primitive: enumPrimitive(values),\n enumValues: values,\n name: enumName,\n readOnly: prop.schema.readOnly,\n writeOnly: prop.schema.writeOnly,\n }),\n })\n }),\n })\n },\n })\n}\n","import { pascalCase } from '@internals/utils'\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 Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\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 * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\n */\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n","import { ast } from '@kubb/ast'\nimport { defineMacro } from '../authoring.ts'\nimport { enumPropName } from '../utils/names.ts'\n\ntype Props = {\n parentName: string | null | undefined\n propName: string\n enumSuffix: string\n}\n\n/**\n * Builds a macro that names an inline enum schema from its parent and property name. Boolean enums\n * are left anonymous. Non-enum nodes are returned unchanged.\n *\n * @example\n * ```ts\n * const macro = macroEnumName({ parentName: 'Pet', propName: 'status', enumSuffix: 'enum' })\n * const named = applyMacros(propSchema, [macro], { depth: 'shallow' })\n * ```\n */\nexport function macroEnumName({ parentName, propName, enumSuffix }: Props) {\n return defineMacro({\n name: 'enum-name',\n schema(node) {\n const enumNode = ast.schema.narrow(node, 'enum')\n\n if (enumNode?.primitive === 'boolean') return { ...node, name: null }\n if (enumNode) return { ...node, name: enumPropName(parentName, propName, enumSuffix) }\n\n return undefined\n },\n })\n}\n","import { ast } from '@kubb/ast'\nimport type { SchemaNode } from '@kubb/ast'\n\n/**\n * Merges a run of adjacent anonymous object members into one. Named or non-object members break the\n * run and pass through unchanged. The merge follows member order, so callers control which members\n * combine by where they place them in the sequence.\n *\n * @example\n * ```ts\n * const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]\n * ```\n */\nexport function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {\n let acc: SchemaNode | undefined\n\n for (const member of members) {\n const objectMember = ast.schema.narrow(member, 'object')\n if (objectMember && !objectMember.name && acc !== undefined) {\n const accObject = ast.schema.narrow(acc, 'object')\n if (accObject && !accObject.name) {\n acc = ast.factory.createSchema({\n ...accObject,\n properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n continue\n }\n }\n if (acc !== undefined) yield acc\n acc = member\n }\n\n if (acc !== undefined) y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