@kubb/ast 5.0.0-beta.59 → 5.0.0-beta.60
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/dist/factory-Cl8Z7mcc.cjs +299 -0
- package/dist/factory-Cl8Z7mcc.cjs.map +1 -0
- package/dist/factory.cjs +26 -25
- package/dist/index.cjs +44 -548
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1 -1
- package/dist/{factory-BmcGBdeg.cjs → response-DS5S3IG4.cjs} +155 -348
- package/dist/response-DS5S3IG4.cjs.map +1 -0
- package/dist/utils-D83JA6Xx.cjs +1645 -0
- package/dist/utils-D83JA6Xx.cjs.map +1 -0
- package/dist/{utils-SdZU0F3H.js → utils-Dj_KoXMv.js} +55 -2
- package/dist/utils-Dj_KoXMv.js.map +1 -0
- package/dist/utils.cjs +28 -127
- package/dist/utils.d.ts +91 -2
- package/dist/utils.js +2 -2
- package/package.json +1 -2
- package/src/utils/index.ts +3 -1
- package/src/utils/schemaTraversal.ts +86 -0
- package/dist/casing-BE2R1RXg.cjs +0 -88
- package/dist/casing-BE2R1RXg.cjs.map +0 -1
- package/dist/factory-BmcGBdeg.cjs.map +0 -1
- package/dist/utils-BCtRXfhI.cjs +0 -275
- package/dist/utils-BCtRXfhI.cjs.map +0 -1
- package/dist/utils-SdZU0F3H.js.map +0 -1
|
@@ -1,7 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
5
36
|
//#region src/node.ts
|
|
6
37
|
/**
|
|
7
38
|
* Builds a type guard that matches nodes of the given `kind`.
|
|
@@ -127,23 +158,104 @@ function createSchema(props) {
|
|
|
127
158
|
return schemaDef.create(props);
|
|
128
159
|
}
|
|
129
160
|
//#endregion
|
|
130
|
-
//#region ../../internals/utils/src/
|
|
161
|
+
//#region ../../internals/utils/src/casing.ts
|
|
131
162
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
163
|
+
* Shared implementation for camelCase and PascalCase conversion.
|
|
164
|
+
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
165
|
+
* and capitalizes each word according to `pascal`.
|
|
134
166
|
*
|
|
135
|
-
*
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
167
|
+
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
168
|
+
*/
|
|
169
|
+
function toCamelOrPascal(text, pascal) {
|
|
170
|
+
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) => {
|
|
171
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
172
|
+
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
173
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Converts `text` to camelCase.
|
|
177
|
+
*
|
|
178
|
+
* @example Word boundaries
|
|
179
|
+
* `camelCase('hello-world') // 'helloWorld'`
|
|
180
|
+
*
|
|
181
|
+
* @example With a prefix
|
|
182
|
+
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
140
183
|
*/
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
184
|
+
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
185
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Converts `text` to PascalCase.
|
|
189
|
+
*
|
|
190
|
+
* @example Word boundaries
|
|
191
|
+
* `pascalCase('hello-world') // 'HelloWorld'`
|
|
192
|
+
*
|
|
193
|
+
* @example With a suffix
|
|
194
|
+
* `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
|
|
195
|
+
*/
|
|
196
|
+
function pascalCase(text, { prefix = "", suffix = "" } = {}) {
|
|
197
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/utils/extractStringsFromNodes.ts
|
|
201
|
+
/**
|
|
202
|
+
* Extracts all string content from a `CodeNode` tree recursively.
|
|
203
|
+
*
|
|
204
|
+
* Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
|
|
205
|
+
* and nested node content. Used to build the full source string for import filtering.
|
|
206
|
+
*/
|
|
207
|
+
function extractStringsFromNodes(nodes) {
|
|
208
|
+
if (!nodes?.length) return "";
|
|
209
|
+
return nodes.map((node) => {
|
|
210
|
+
if (typeof node === "string") return node;
|
|
211
|
+
if (node.kind === "Text") return node.value;
|
|
212
|
+
if (node.kind === "Break") return "";
|
|
213
|
+
if (node.kind === "Jsx") return node.value;
|
|
214
|
+
const parts = [];
|
|
215
|
+
if ("params" in node && node.params) parts.push(node.params);
|
|
216
|
+
if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics);
|
|
217
|
+
if ("returnType" in node && node.returnType) parts.push(node.returnType);
|
|
218
|
+
if ("type" in node && typeof node.type === "string") parts.push(node.type);
|
|
219
|
+
const nested = extractStringsFromNodes(node.nodes);
|
|
220
|
+
if (nested) parts.push(nested);
|
|
221
|
+
return parts.join("\n");
|
|
222
|
+
}).filter(Boolean).join("\n");
|
|
145
223
|
}
|
|
146
224
|
//#endregion
|
|
225
|
+
//#region src/nodes/property.ts
|
|
226
|
+
/**
|
|
227
|
+
* Definition for the {@link PropertyNode}. `required` defaults to `false` and the
|
|
228
|
+
* schema's `optional`/`nullish` flags are kept in sync with it.
|
|
229
|
+
*/
|
|
230
|
+
const propertyDef = defineNode({
|
|
231
|
+
kind: "Property",
|
|
232
|
+
build: (props) => {
|
|
233
|
+
const required = props.required ?? false;
|
|
234
|
+
return {
|
|
235
|
+
...props,
|
|
236
|
+
required,
|
|
237
|
+
schema: syncOptionality(props.schema, required)
|
|
238
|
+
};
|
|
239
|
+
},
|
|
240
|
+
children: ["schema"],
|
|
241
|
+
visitorKey: "property",
|
|
242
|
+
rebuild: true
|
|
243
|
+
});
|
|
244
|
+
/**
|
|
245
|
+
* Creates a `PropertyNode`.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* const property = createProperty({
|
|
250
|
+
* name: 'status',
|
|
251
|
+
* required: true,
|
|
252
|
+
* schema: createSchema({ type: 'string', nullable: true }),
|
|
253
|
+
* })
|
|
254
|
+
* // required=true, no optional/nullish
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
const createProperty = propertyDef.create;
|
|
258
|
+
//#endregion
|
|
147
259
|
//#region src/nodes/code.ts
|
|
148
260
|
/**
|
|
149
261
|
* Definition for the {@link ConstNode}.
|
|
@@ -565,40 +677,6 @@ const parameterDef = defineNode({
|
|
|
565
677
|
*/
|
|
566
678
|
const createParameter = parameterDef.create;
|
|
567
679
|
//#endregion
|
|
568
|
-
//#region src/nodes/property.ts
|
|
569
|
-
/**
|
|
570
|
-
* Definition for the {@link PropertyNode}. `required` defaults to `false` and the
|
|
571
|
-
* schema's `optional`/`nullish` flags are kept in sync with it.
|
|
572
|
-
*/
|
|
573
|
-
const propertyDef = defineNode({
|
|
574
|
-
kind: "Property",
|
|
575
|
-
build: (props) => {
|
|
576
|
-
const required = props.required ?? false;
|
|
577
|
-
return {
|
|
578
|
-
...props,
|
|
579
|
-
required,
|
|
580
|
-
schema: syncOptionality(props.schema, required)
|
|
581
|
-
};
|
|
582
|
-
},
|
|
583
|
-
children: ["schema"],
|
|
584
|
-
visitorKey: "property",
|
|
585
|
-
rebuild: true
|
|
586
|
-
});
|
|
587
|
-
/**
|
|
588
|
-
* Creates a `PropertyNode`.
|
|
589
|
-
*
|
|
590
|
-
* @example
|
|
591
|
-
* ```ts
|
|
592
|
-
* const property = createProperty({
|
|
593
|
-
* name: 'status',
|
|
594
|
-
* required: true,
|
|
595
|
-
* schema: createSchema({ type: 'string', nullable: true }),
|
|
596
|
-
* })
|
|
597
|
-
* // required=true, no optional/nullish
|
|
598
|
-
* ```
|
|
599
|
-
*/
|
|
600
|
-
const createProperty = propertyDef.create;
|
|
601
|
-
//#endregion
|
|
602
680
|
//#region src/nodes/response.ts
|
|
603
681
|
/**
|
|
604
682
|
* Definition for the {@link ResponseNode}. A single legacy `schema` (with optional
|
|
@@ -634,289 +712,24 @@ const responseDef = defineNode({
|
|
|
634
712
|
*/
|
|
635
713
|
const createResponse = responseDef.create;
|
|
636
714
|
//#endregion
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
* Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
|
|
642
|
-
* and nested node content. Used to build the full source string for import filtering.
|
|
643
|
-
*/
|
|
644
|
-
function extractStringsFromNodes(nodes) {
|
|
645
|
-
if (!nodes?.length) return "";
|
|
646
|
-
return nodes.map((node) => {
|
|
647
|
-
if (typeof node === "string") return node;
|
|
648
|
-
if (node.kind === "Text") return node.value;
|
|
649
|
-
if (node.kind === "Break") return "";
|
|
650
|
-
if (node.kind === "Jsx") return node.value;
|
|
651
|
-
const parts = [];
|
|
652
|
-
if ("params" in node && node.params) parts.push(node.params);
|
|
653
|
-
if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics);
|
|
654
|
-
if ("returnType" in node && node.returnType) parts.push(node.returnType);
|
|
655
|
-
if ("type" in node && typeof node.type === "string") parts.push(node.type);
|
|
656
|
-
const nested = extractStringsFromNodes(node.nodes);
|
|
657
|
-
if (nested) parts.push(nested);
|
|
658
|
-
return parts.join("\n");
|
|
659
|
-
}).filter(Boolean).join("\n");
|
|
660
|
-
}
|
|
661
|
-
//#endregion
|
|
662
|
-
//#region src/utils/fileMerge.ts
|
|
663
|
-
function sourceKey(source) {
|
|
664
|
-
return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`;
|
|
665
|
-
}
|
|
666
|
-
function pathTypeKey(path, isTypeOnly) {
|
|
667
|
-
return `${path}:${isTypeOnly ?? false}`;
|
|
668
|
-
}
|
|
669
|
-
function exportKey(path, name, isTypeOnly, asAlias) {
|
|
670
|
-
return `${path}:${name ?? ""}:${isTypeOnly ?? false}:${asAlias ?? ""}`;
|
|
671
|
-
}
|
|
672
|
-
function importKey(path, name, isTypeOnly) {
|
|
673
|
-
return `${path}:${name ?? ""}:${isTypeOnly ?? false}`;
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Computes a multi-level sort key for exports and imports:
|
|
677
|
-
* non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named.
|
|
678
|
-
*/
|
|
679
|
-
function sortKey(node) {
|
|
680
|
-
const isArray = Array.isArray(node.name) ? "1" : "0";
|
|
681
|
-
const typeOnly = node.isTypeOnly ? "0" : "1";
|
|
682
|
-
const hasName = node.name != null ? "1" : "0";
|
|
683
|
-
const name = Array.isArray(node.name) ? node.name.toSorted().join("\0") : node.name ?? "";
|
|
684
|
-
return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`;
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Deduplicates and merges `SourceNode` objects by `name + isExportable + isTypeOnly`.
|
|
688
|
-
*
|
|
689
|
-
* Unnamed sources are deduplicated by object reference. Returns a deduplicated array in original order.
|
|
690
|
-
*/
|
|
691
|
-
function combineSources(sources) {
|
|
692
|
-
const seen = /* @__PURE__ */ new Map();
|
|
693
|
-
for (const source of sources) {
|
|
694
|
-
const key = sourceKey(source);
|
|
695
|
-
if (!seen.has(key)) seen.set(key, source);
|
|
696
|
-
}
|
|
697
|
-
return [...seen.values()];
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Merges `incoming` names into `existing`, preserving order and dropping duplicates.
|
|
701
|
-
*
|
|
702
|
-
* Shared by `combineExports` and `combineImports` for the same-path name-merge case.
|
|
703
|
-
*/
|
|
704
|
-
function mergeNameArrays(existing, incoming) {
|
|
705
|
-
const merged = new Set(existing);
|
|
706
|
-
for (const name of incoming) merged.add(name);
|
|
707
|
-
return [...merged];
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Deduplicates and merges `ExportNode` objects by path and type.
|
|
711
|
-
*
|
|
712
|
-
* Named exports with the same path and `isTypeOnly` flag have their names merged into a single export.
|
|
713
|
-
* Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array.
|
|
714
|
-
*/
|
|
715
|
-
function combineExports(exports) {
|
|
716
|
-
const result = [];
|
|
717
|
-
const namedByPath = /* @__PURE__ */ new Map();
|
|
718
|
-
const seen = /* @__PURE__ */ new Set();
|
|
719
|
-
const keyed = exports.map((node) => ({
|
|
720
|
-
node,
|
|
721
|
-
key: sortKey(node)
|
|
722
|
-
}));
|
|
723
|
-
keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
724
|
-
for (const { node: curr } of keyed) {
|
|
725
|
-
const { name, path, isTypeOnly, asAlias } = curr;
|
|
726
|
-
if (Array.isArray(name)) {
|
|
727
|
-
if (!name.length) continue;
|
|
728
|
-
const key = pathTypeKey(path, isTypeOnly);
|
|
729
|
-
const existing = namedByPath.get(key);
|
|
730
|
-
if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name);
|
|
731
|
-
else {
|
|
732
|
-
const newItem = {
|
|
733
|
-
...curr,
|
|
734
|
-
name: [...new Set(name)]
|
|
735
|
-
};
|
|
736
|
-
result.push(newItem);
|
|
737
|
-
namedByPath.set(key, newItem);
|
|
738
|
-
}
|
|
739
|
-
} else {
|
|
740
|
-
const key = exportKey(path, name, isTypeOnly, asAlias);
|
|
741
|
-
if (!seen.has(key)) {
|
|
742
|
-
result.push(curr);
|
|
743
|
-
seen.add(key);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
715
|
+
Object.defineProperty(exports, "__exportAll", {
|
|
716
|
+
enumerable: true,
|
|
717
|
+
get: function() {
|
|
718
|
+
return __exportAll;
|
|
746
719
|
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
* Retains imports that are referenced in `source` or re-exported. Imports with the same path and
|
|
753
|
-
* `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array.
|
|
754
|
-
*/
|
|
755
|
-
function combineImports(imports, exports, source) {
|
|
756
|
-
const exportedNames = new Set(exports.flatMap((e) => Array.isArray(e.name) ? e.name : e.name ? [e.name] : []));
|
|
757
|
-
const isUsed = (importName) => !source || source.includes(importName) || exportedNames.has(importName);
|
|
758
|
-
const importNameMemo = /* @__PURE__ */ new Map();
|
|
759
|
-
const canonicalizeName = (n) => {
|
|
760
|
-
if (typeof n === "string") return n;
|
|
761
|
-
const key = `${n.propertyName}:${n.name ?? ""}`;
|
|
762
|
-
if (!importNameMemo.has(key)) importNameMemo.set(key, n);
|
|
763
|
-
return importNameMemo.get(key);
|
|
764
|
-
};
|
|
765
|
-
const pathsWithUsedNamedImport = /* @__PURE__ */ new Set();
|
|
766
|
-
for (const node of imports) {
|
|
767
|
-
if (!Array.isArray(node.name)) continue;
|
|
768
|
-
if (node.name.some((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName))) pathsWithUsedNamedImport.add(node.path);
|
|
720
|
+
});
|
|
721
|
+
Object.defineProperty(exports, "__name", {
|
|
722
|
+
enumerable: true,
|
|
723
|
+
get: function() {
|
|
724
|
+
return __name;
|
|
769
725
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
key: sortKey(node)
|
|
776
|
-
}));
|
|
777
|
-
keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
778
|
-
for (const { node: curr } of keyed) {
|
|
779
|
-
if (curr.path === curr.root) continue;
|
|
780
|
-
const { path, isTypeOnly } = curr;
|
|
781
|
-
let { name } = curr;
|
|
782
|
-
if (Array.isArray(name)) {
|
|
783
|
-
name = [...new Set(name.map(canonicalizeName))].filter((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName));
|
|
784
|
-
if (!name.length) continue;
|
|
785
|
-
const key = pathTypeKey(path, isTypeOnly);
|
|
786
|
-
const existing = namedByPath.get(key);
|
|
787
|
-
if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name);
|
|
788
|
-
else {
|
|
789
|
-
const newItem = {
|
|
790
|
-
...curr,
|
|
791
|
-
name
|
|
792
|
-
};
|
|
793
|
-
result.push(newItem);
|
|
794
|
-
namedByPath.set(key, newItem);
|
|
795
|
-
}
|
|
796
|
-
} else {
|
|
797
|
-
if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue;
|
|
798
|
-
const key = importKey(path, name, isTypeOnly);
|
|
799
|
-
if (!seen.has(key)) {
|
|
800
|
-
result.push(curr);
|
|
801
|
-
seen.add(key);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
726
|
+
});
|
|
727
|
+
Object.defineProperty(exports, "__toESM", {
|
|
728
|
+
enumerable: true,
|
|
729
|
+
get: function() {
|
|
730
|
+
return __toESM;
|
|
804
731
|
}
|
|
805
|
-
return result;
|
|
806
|
-
}
|
|
807
|
-
//#endregion
|
|
808
|
-
//#region src/factory.ts
|
|
809
|
-
var factory_exports = /* @__PURE__ */ require_casing.__exportAll({
|
|
810
|
-
createArrowFunction: () => createArrowFunction,
|
|
811
|
-
createBreak: () => createBreak,
|
|
812
|
-
createConst: () => createConst,
|
|
813
|
-
createContent: () => createContent,
|
|
814
|
-
createExport: () => createExport,
|
|
815
|
-
createFile: () => createFile,
|
|
816
|
-
createFunction: () => createFunction,
|
|
817
|
-
createFunctionParameter: () => createFunctionParameter,
|
|
818
|
-
createFunctionParameters: () => createFunctionParameters,
|
|
819
|
-
createImport: () => createImport,
|
|
820
|
-
createIndexedAccessType: () => createIndexedAccessType,
|
|
821
|
-
createInput: () => createInput,
|
|
822
|
-
createJsx: () => createJsx,
|
|
823
|
-
createObjectBindingPattern: () => createObjectBindingPattern,
|
|
824
|
-
createOperation: () => createOperation,
|
|
825
|
-
createOutput: () => createOutput,
|
|
826
|
-
createParameter: () => createParameter,
|
|
827
|
-
createProperty: () => createProperty,
|
|
828
|
-
createRequestBody: () => createRequestBody,
|
|
829
|
-
createResponse: () => createResponse,
|
|
830
|
-
createSchema: () => createSchema,
|
|
831
|
-
createSource: () => createSource,
|
|
832
|
-
createText: () => createText,
|
|
833
|
-
createType: () => createType,
|
|
834
|
-
createTypeLiteral: () => createTypeLiteral,
|
|
835
|
-
update: () => update
|
|
836
732
|
});
|
|
837
|
-
/**
|
|
838
|
-
* Identity-preserving node update: returns `node` unchanged when every field in
|
|
839
|
-
* `changes` already equals (by reference) the current value, otherwise a new node
|
|
840
|
-
* with the changes applied.
|
|
841
|
-
*
|
|
842
|
-
* Mirrors the TypeScript compiler's `factory.updateX` contract, pair it with the
|
|
843
|
-
* structural sharing in {@link transform} so a no-op rewrite doesn't allocate and
|
|
844
|
-
* downstream passes can detect "nothing changed" by identity. Comparison is
|
|
845
|
-
* shallow: a structurally-equal but newly-allocated array/object counts as a change.
|
|
846
|
-
*
|
|
847
|
-
* @example
|
|
848
|
-
* ```ts
|
|
849
|
-
* update(node, { name: node.name }) // -> same `node` reference
|
|
850
|
-
* update(node, { name: 'renamed' }) // -> new node, `name` replaced
|
|
851
|
-
* ```
|
|
852
|
-
*/
|
|
853
|
-
function update(node, changes) {
|
|
854
|
-
for (const key in changes) if (changes[key] !== node[key]) return {
|
|
855
|
-
...node,
|
|
856
|
-
...changes
|
|
857
|
-
};
|
|
858
|
-
return node;
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
|
-
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
862
|
-
*
|
|
863
|
-
* Computes:
|
|
864
|
-
* - `id` SHA256 hash of the file path
|
|
865
|
-
* - `name` `baseName` without extension
|
|
866
|
-
* - `extname` extension extracted from `baseName`
|
|
867
|
-
*
|
|
868
|
-
* Deduplicates:
|
|
869
|
-
* - `sources` via `combineSources`
|
|
870
|
-
* - `exports` via `combineExports`
|
|
871
|
-
* - `imports` via `combineImports` (also filters unused imports)
|
|
872
|
-
*
|
|
873
|
-
* @throws {Error} when `baseName` has no extension.
|
|
874
|
-
*
|
|
875
|
-
* @example
|
|
876
|
-
* ```ts
|
|
877
|
-
* const file = createFile({
|
|
878
|
-
* baseName: 'petStore.ts',
|
|
879
|
-
* path: 'src/models/petStore.ts',
|
|
880
|
-
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
881
|
-
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
882
|
-
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
883
|
-
* })
|
|
884
|
-
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
885
|
-
* // file.name = 'petStore'
|
|
886
|
-
* // file.extname = '.ts'
|
|
887
|
-
* ```
|
|
888
|
-
*/
|
|
889
|
-
function createFile(input) {
|
|
890
|
-
const extname = node_path.default.extname(input.baseName) || (input.baseName.startsWith(".") ? input.baseName : "");
|
|
891
|
-
if (!extname) throw new Error(`No extname found for ${input.baseName}`);
|
|
892
|
-
const source = (input.sources ?? []).flatMap((item) => item.nodes ?? []).map((node) => extractStringsFromNodes([node])).filter(Boolean).join("\n\n");
|
|
893
|
-
const resolvedExports = input.exports?.length ? combineExports(input.exports) : [];
|
|
894
|
-
const combinedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || void 0) : [];
|
|
895
|
-
const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name) => Boolean(name)));
|
|
896
|
-
const nameOf = (item) => typeof item === "string" ? item : item.name ?? item.propertyName;
|
|
897
|
-
const resolvedImports = combinedImports.filter((imp) => imp.path !== input.path).flatMap((imp) => {
|
|
898
|
-
if (!Array.isArray(imp.name)) return typeof imp.name === "string" && localNames.has(imp.name) ? [] : [imp];
|
|
899
|
-
const kept = imp.name.filter((item) => !localNames.has(nameOf(item)));
|
|
900
|
-
if (!kept.length) return [];
|
|
901
|
-
return [kept.length === imp.name.length ? imp : {
|
|
902
|
-
...imp,
|
|
903
|
-
name: kept
|
|
904
|
-
}];
|
|
905
|
-
});
|
|
906
|
-
const resolvedSources = input.sources?.length ? combineSources(input.sources) : [];
|
|
907
|
-
return {
|
|
908
|
-
kind: "File",
|
|
909
|
-
...input,
|
|
910
|
-
id: (0, node_crypto.hash)("sha256", input.path, "hex"),
|
|
911
|
-
name: trimExtName(input.baseName),
|
|
912
|
-
extname,
|
|
913
|
-
imports: resolvedImports,
|
|
914
|
-
exports: resolvedExports,
|
|
915
|
-
sources: resolvedSources,
|
|
916
|
-
meta: input.meta ?? {}
|
|
917
|
-
};
|
|
918
|
-
}
|
|
919
|
-
//#endregion
|
|
920
733
|
Object.defineProperty(exports, "arrowFunctionDef", {
|
|
921
734
|
enumerable: true,
|
|
922
735
|
get: function() {
|
|
@@ -929,6 +742,12 @@ Object.defineProperty(exports, "breakDef", {
|
|
|
929
742
|
return breakDef;
|
|
930
743
|
}
|
|
931
744
|
});
|
|
745
|
+
Object.defineProperty(exports, "camelCase", {
|
|
746
|
+
enumerable: true,
|
|
747
|
+
get: function() {
|
|
748
|
+
return camelCase;
|
|
749
|
+
}
|
|
750
|
+
});
|
|
932
751
|
Object.defineProperty(exports, "constDef", {
|
|
933
752
|
enumerable: true,
|
|
934
753
|
get: function() {
|
|
@@ -971,12 +790,6 @@ Object.defineProperty(exports, "createExport", {
|
|
|
971
790
|
return createExport;
|
|
972
791
|
}
|
|
973
792
|
});
|
|
974
|
-
Object.defineProperty(exports, "createFile", {
|
|
975
|
-
enumerable: true,
|
|
976
|
-
get: function() {
|
|
977
|
-
return createFile;
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
793
|
Object.defineProperty(exports, "createFunction", {
|
|
981
794
|
enumerable: true,
|
|
982
795
|
get: function() {
|
|
@@ -1109,12 +922,6 @@ Object.defineProperty(exports, "extractStringsFromNodes", {
|
|
|
1109
922
|
return extractStringsFromNodes;
|
|
1110
923
|
}
|
|
1111
924
|
});
|
|
1112
|
-
Object.defineProperty(exports, "factory_exports", {
|
|
1113
|
-
enumerable: true,
|
|
1114
|
-
get: function() {
|
|
1115
|
-
return factory_exports;
|
|
1116
|
-
}
|
|
1117
|
-
});
|
|
1118
925
|
Object.defineProperty(exports, "fileDef", {
|
|
1119
926
|
enumerable: true,
|
|
1120
927
|
get: function() {
|
|
@@ -1187,6 +994,12 @@ Object.defineProperty(exports, "parameterDef", {
|
|
|
1187
994
|
return parameterDef;
|
|
1188
995
|
}
|
|
1189
996
|
});
|
|
997
|
+
Object.defineProperty(exports, "pascalCase", {
|
|
998
|
+
enumerable: true,
|
|
999
|
+
get: function() {
|
|
1000
|
+
return pascalCase;
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1190
1003
|
Object.defineProperty(exports, "propertyDef", {
|
|
1191
1004
|
enumerable: true,
|
|
1192
1005
|
get: function() {
|
|
@@ -1241,11 +1054,5 @@ Object.defineProperty(exports, "typeLiteralDef", {
|
|
|
1241
1054
|
return typeLiteralDef;
|
|
1242
1055
|
}
|
|
1243
1056
|
});
|
|
1244
|
-
Object.defineProperty(exports, "update", {
|
|
1245
|
-
enumerable: true,
|
|
1246
|
-
get: function() {
|
|
1247
|
-
return update;
|
|
1248
|
-
}
|
|
1249
|
-
});
|
|
1250
1057
|
|
|
1251
|
-
//# sourceMappingURL=
|
|
1058
|
+
//# sourceMappingURL=response-DS5S3IG4.cjs.map
|