@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
package/README.md CHANGED
@@ -134,6 +134,16 @@ import { extractRefName } from '@kubb/ast/utils'
134
134
  extractRefName('#/components/schemas/Pet') // 'Pet'
135
135
  ```
136
136
 
137
+ ## Adding a node
138
+
139
+ Adding a node touches three files. The barrels and visitor tables derive the rest.
140
+
141
+ 1. Define the node in its own `src/nodes/*.ts` file. Call `defineNode` and export the resulting `fooDef`, the `createFoo` constructor, and the node's type.
142
+ 2. Add `fooDef` to the `nodeDefs` array in `src/registry.ts`.
143
+ 3. Re-export `createFoo` from `src/factory.ts`.
144
+
145
+ Everything else follows from there. `@kubb/ast/types` picks up the node type through `export type *`, the `@kubb/ast` barrel picks up `fooDef` through `export * from './registry.ts'`, and the visitor tables (`VISITOR_KEYS`, `VISITOR_KEY_BY_KIND`, `nodeRebuilders`) come from the def's `children`, `visitorKey`, and `rebuild` fields. `registry.test.ts` fails when a def has no matching `factory.create*`, so missing wiring is caught in CI.
146
+
137
147
  ## Supporting Kubb
138
148
 
139
149
  Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
@@ -0,0 +1,88 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", {
5
+ value,
6
+ configurable: true
7
+ });
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __exportAll = (all, no_symbols) => {
13
+ let target = {};
14
+ for (var name in all) __defProp(target, name, {
15
+ get: all[name],
16
+ enumerable: true
17
+ });
18
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
19
+ return target;
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
23
+ key = keys[i];
24
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
25
+ get: ((k) => from[k]).bind(null, key),
26
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
27
+ });
28
+ }
29
+ return to;
30
+ };
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
32
+ value: mod,
33
+ enumerable: true
34
+ }) : target, mod));
35
+ //#endregion
36
+ //#region ../../internals/utils/src/casing.ts
37
+ /**
38
+ * Shared implementation for camelCase and PascalCase conversion.
39
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
40
+ * and capitalizes each word according to `pascal`.
41
+ *
42
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
43
+ */
44
+ function toCamelOrPascal(text, pascal) {
45
+ 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) => {
46
+ if (word.length > 1 && word === word.toUpperCase()) return word;
47
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
48
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
49
+ }
50
+ /**
51
+ * Converts `text` to PascalCase.
52
+ *
53
+ * @example Word boundaries
54
+ * `pascalCase('hello-world') // 'HelloWorld'`
55
+ *
56
+ * @example With a suffix
57
+ * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
58
+ */
59
+ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
60
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
61
+ }
62
+ //#endregion
63
+ Object.defineProperty(exports, "__exportAll", {
64
+ enumerable: true,
65
+ get: function() {
66
+ return __exportAll;
67
+ }
68
+ });
69
+ Object.defineProperty(exports, "__name", {
70
+ enumerable: true,
71
+ get: function() {
72
+ return __name;
73
+ }
74
+ });
75
+ Object.defineProperty(exports, "__toESM", {
76
+ enumerable: true,
77
+ get: function() {
78
+ return __toESM;
79
+ }
80
+ });
81
+ Object.defineProperty(exports, "pascalCase", {
82
+ enumerable: true,
83
+ get: function() {
84
+ return pascalCase;
85
+ }
86
+ });
87
+
88
+ //# sourceMappingURL=casing-BE2R1RXg.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"casing-BE2R1RXg.cjs","names":[],"sources":["../../../internals/utils/src/casing.ts"],"sourcesContent":["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 toCamelOrPascal(text: string, pascal: boolean): string {\n return 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 .replace(/(\\d)([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 * 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,SAAS,gBAAgB,MAAc,QAAyB;CAC9D,OAAO,KACJ,KAAK,CAAC,CACN,QAAQ,qBAAqB,OAAO,CAAC,CACrC,QAAQ,yBAAyB,OAAO,CAAC,CACzC,QAAQ,gBAAgB,OAAO,CAAC,CAChC,MAAM,eAAe,CAAC,CACtB,OAAO,OAAO,CAAC,CACf,KAAK,MAAM,MAAM;EAChB,IAAI,KAAK,SAAS,KAAK,SAAS,KAAK,YAAY,GAAG,OAAO;EAE3D,QADa,MAAM,KAAK,CAAC,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,KAC9E,KAAK,MAAM,CAAC;CAC5B,CAAC,CAAC,CACD,KAAK,EAAE,CAAC,CACR,QAAQ,iBAAiB,EAAE;AAChC;;;;;;;;;;AAwBA,SAAgB,WAAW,MAAc,EAAE,SAAS,IAAI,SAAS,OAAgB,CAAC,GAAW;CAC3F,OAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,IAAI;AAC5D"}
@@ -0,0 +1,82 @@
1
+ import { n as __name } from "./chunk-CNktS9qV.js";
2
+ import { Pt as CodeNode, _t as SchemaNode } from "./index-BzjwdK2M.js";
3
+
4
+ //#region src/transformers.d.ts
5
+ /**
6
+ * Replaces a discriminator property's schema with a string enum of allowed values.
7
+ *
8
+ * If `node` is not an object schema, or if the property does not exist, the input
9
+ * node is returned as-is.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const schema = createSchema({
14
+ * type: 'object',
15
+ * properties: [createProperty({ name: 'type', required: true, schema: createSchema({ type: 'string' }) })],
16
+ * })
17
+ * const result = setDiscriminatorEnum({ node: schema, propertyName: 'type', values: ['dog', 'cat'] })
18
+ * ```
19
+ */
20
+ declare function setDiscriminatorEnum({
21
+ node,
22
+ propertyName,
23
+ values,
24
+ enumName
25
+ }: {
26
+ node: SchemaNode;
27
+ propertyName: string;
28
+ values: Array<string>;
29
+ enumName?: string;
30
+ }): SchemaNode;
31
+ /**
32
+ * Merges adjacent anonymous object members into a single anonymous object member.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const merged = mergeAdjacentObjects([
37
+ * createSchema({ type: 'object', properties: [createProperty({ name: 'a', schema: createSchema({ type: 'string' }) })] }),
38
+ * createSchema({ type: 'object', properties: [createProperty({ name: 'b', schema: createSchema({ type: 'number' }) })] }),
39
+ * ])
40
+ * ```
41
+ */
42
+ declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined>;
43
+ /**
44
+ * Removes enum members that are covered by broader scalar primitives in the same union.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const simplified = simplifyUnion([
49
+ * createSchema({ type: 'enum', primitive: 'string', enumValues: ['active'] }),
50
+ * createSchema({ type: 'string' }),
51
+ * ])
52
+ * // keeps only string member
53
+ * ```
54
+ */
55
+ declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
56
+ declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
57
+ /**
58
+ * Merges a ref node with its resolved schema, giving usage-site fields precedence.
59
+ *
60
+ * Usage-site fields (`description`, `readOnly`, `nullable`, `deprecated`) on the ref node override
61
+ * the same fields in the resolved `node.schema`. Non-ref nodes are returned unchanged.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * // Ref with description override
66
+ * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
67
+ * const merged = syncSchemaRef(ref) // merges with resolved Pet schema
68
+ * ```
69
+ */
70
+ declare function syncSchemaRef(node: SchemaNode): SchemaNode;
71
+ //#endregion
72
+ //#region src/utils/extractStringsFromNodes.d.ts
73
+ /**
74
+ * Extracts all string content from a `CodeNode` tree recursively.
75
+ *
76
+ * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
77
+ * and nested node content. Used to build the full source string for import filtering.
78
+ */
79
+ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
80
+ //#endregion
81
+ export { simplifyUnion as a, setEnumName as i, mergeAdjacentObjectsLazy as n, syncSchemaRef as o, setDiscriminatorEnum as r, extractStringsFromNodes as t };
82
+ //# sourceMappingURL=extractStringsFromNodes-WMYJ8nQL.d.ts.map