@kubb/ast 5.0.0-beta.61 → 5.0.0-beta.63
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/{defineMacro-BLIR6k-j.d.ts → defineMacro-BATi7xoC.d.ts} +11 -20
- package/dist/{defineMacro-Bv9R_9a2.cjs → defineMacro-CEZHaCXE.cjs} +13 -21
- package/dist/defineMacro-CEZHaCXE.cjs.map +1 -0
- package/dist/{defineMacro-BTXvS8nI.js → defineMacro-Shz8f6SG.js} +12 -19
- package/dist/defineMacro-Shz8f6SG.js.map +1 -0
- package/dist/factory.cjs +88 -28
- package/dist/factory.cjs.map +1 -0
- package/dist/factory.d.ts +6 -41
- package/dist/factory.js +58 -3
- package/dist/factory.js.map +1 -0
- package/dist/{index-BzjwdK2M.d.ts → index-B9cc8MBS.d.ts} +164 -194
- package/dist/index.cjs +144 -274
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +43 -37
- package/dist/index.js +109 -235
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +41 -28
- package/dist/macros.cjs.map +1 -1
- package/dist/macros.d.ts +14 -12
- package/dist/macros.js +34 -21
- package/dist/macros.js.map +1 -1
- package/dist/{operationParams-BZ07xDm0.d.ts → operationParams-k5CKwSWZ.d.ts} +9 -2
- package/dist/{visitor-DJ6ZEJvq.js → refs-BjNDuCBD.js} +116 -159
- package/dist/refs-BjNDuCBD.js.map +1 -0
- package/dist/{visitor-DpKZ9Tk0.cjs → refs-u5SDdyV7.cjs} +140 -195
- package/dist/refs-u5SDdyV7.cjs.map +1 -0
- package/dist/{response-hnSw2NKE.cjs → schema-BkvrrOAr.cjs} +496 -231
- package/dist/schema-BkvrrOAr.cjs.map +1 -0
- package/dist/{response-KUdWiDWw.js → schema-Cbnxmz4b.js} +472 -220
- package/dist/schema-Cbnxmz4b.js.map +1 -0
- package/dist/{types-DyDzizSf.d.ts → types-BB_xgRJ3.d.ts} +49 -123
- package/dist/types.d.ts +5 -6
- package/dist/{utils-BLJwyza-.cjs → utils-CEepwqmb.cjs} +76 -69
- package/dist/utils-CEepwqmb.cjs.map +1 -0
- package/dist/{utils-CF_-Pn_c.js → utils-DaXkewb1.js} +58 -51
- package/dist/utils-DaXkewb1.js.map +1 -0
- package/dist/utils.cjs +11 -11
- package/dist/utils.d.ts +53 -30
- package/dist/utils.js +3 -3
- package/package.json +1 -1
- package/src/constants.ts +3 -36
- package/src/defineMacro.ts +20 -13
- package/src/{node.ts → defineNode.ts} +12 -38
- package/src/{printer.ts → definePrinter.ts} +5 -3
- package/src/dialect.ts +52 -19
- package/src/factory.ts +7 -94
- package/src/index.ts +7 -9
- package/src/infer.ts +1 -1
- package/src/macros/macroDiscriminatorEnum.ts +7 -1
- package/src/macros/macroEnumName.ts +10 -2
- package/src/macros/macroSimplifyUnion.ts +29 -19
- package/src/nodes/code.ts +40 -80
- package/src/nodes/content.ts +2 -7
- package/src/nodes/file.ts +107 -18
- package/src/nodes/function.ts +46 -46
- package/src/nodes/index.ts +2 -3
- package/src/nodes/input.ts +13 -9
- package/src/nodes/operation.ts +8 -5
- package/src/nodes/output.ts +1 -1
- package/src/nodes/parameter.ts +5 -5
- package/src/nodes/property.ts +5 -5
- package/src/nodes/requestBody.ts +6 -13
- package/src/nodes/response.ts +93 -8
- package/src/nodes/schema.ts +5 -5
- package/src/optionality.ts +15 -0
- package/src/registry.ts +1 -1
- package/src/types.ts +4 -6
- package/src/utils/codegen.ts +6 -7
- package/src/utils/extractStringsFromNodes.ts +1 -0
- package/src/utils/fileMerge.ts +7 -8
- package/src/utils/operationParams.ts +9 -9
- package/src/utils/refs.ts +14 -18
- package/src/utils/schemaGraph.ts +41 -33
- package/src/utils/schemaMerge.ts +2 -2
- package/src/visitor.ts +3 -14
- package/dist/defineMacro-BTXvS8nI.js.map +0 -1
- package/dist/defineMacro-Bv9R_9a2.cjs.map +0 -1
- package/dist/extractStringsFromNodes-Cja-xxx5.js +0 -29
- package/dist/extractStringsFromNodes-Cja-xxx5.js.map +0 -1
- package/dist/extractStringsFromNodes-DKgDjFO0.cjs +0 -34
- package/dist/extractStringsFromNodes-DKgDjFO0.cjs.map +0 -1
- package/dist/extractStringsFromNodes-p4mX1TQD.d.ts +0 -14
- package/dist/factory-CZNOGI-N.js +0 -283
- package/dist/factory-CZNOGI-N.js.map +0 -1
- package/dist/factory-DG1CVkEb.cjs +0 -300
- package/dist/factory-DG1CVkEb.cjs.map +0 -1
- package/dist/response-KUdWiDWw.js.map +0 -1
- package/dist/response-hnSw2NKE.cjs.map +0 -1
- package/dist/utils-BLJwyza-.cjs.map +0 -1
- package/dist/utils-CF_-Pn_c.js.map +0 -1
- package/dist/visitor-DJ6ZEJvq.js.map +0 -1
- package/dist/visitor-DpKZ9Tk0.cjs.map +0 -1
- package/src/dedupe.ts +0 -239
- package/src/mocks.ts +0 -56
- package/src/nodes/http.ts +0 -85
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as __name } from "./chunk-CNktS9qV.js";
|
|
2
|
-
import { Et as PropertyNode, _t as SchemaNode, f as OperationNode, h as ResponseNode, n as OutputNode,
|
|
2
|
+
import { C as ParameterNode, Et as PropertyNode, _t as SchemaNode, f as OperationNode, h as ResponseNode, n as OutputNode, o as InputNode, rt as ContentNode, t as Node, y as RequestBodyNode } from "./index-B9cc8MBS.js";
|
|
3
3
|
|
|
4
4
|
//#region src/constants.d.ts
|
|
5
5
|
/**
|
|
@@ -13,7 +13,6 @@ type VisitorDepth = 'shallow' | 'deep';
|
|
|
13
13
|
* Schema type discriminators used by all AST schema nodes.
|
|
14
14
|
*
|
|
15
15
|
* Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
|
|
16
|
-
* Call `isScalarPrimitive()` to check for the scalar types.
|
|
17
16
|
*/
|
|
18
17
|
declare const schemaTypes: {
|
|
19
18
|
/**
|
|
@@ -121,19 +120,6 @@ declare const schemaTypes: {
|
|
|
121
120
|
*/
|
|
122
121
|
readonly never: "never";
|
|
123
122
|
};
|
|
124
|
-
/**
|
|
125
|
-
* HTTP method identifiers used by operation nodes.
|
|
126
|
-
*/
|
|
127
|
-
declare const httpMethods: {
|
|
128
|
-
readonly get: "GET";
|
|
129
|
-
readonly post: "POST";
|
|
130
|
-
readonly put: "PUT";
|
|
131
|
-
readonly patch: "PATCH";
|
|
132
|
-
readonly delete: "DELETE";
|
|
133
|
-
readonly head: "HEAD";
|
|
134
|
-
readonly options: "OPTIONS";
|
|
135
|
-
readonly trace: "TRACE";
|
|
136
|
-
};
|
|
137
123
|
//#endregion
|
|
138
124
|
//#region src/visitor.d.ts
|
|
139
125
|
/**
|
|
@@ -162,7 +148,7 @@ type ParentNodeMap = [[InputNode, undefined], [OutputNode, undefined], [Operatio
|
|
|
162
148
|
* @example
|
|
163
149
|
* ```ts
|
|
164
150
|
* type SchemaParent = ParentOf<SchemaNode>
|
|
165
|
-
* // InputNode |
|
|
151
|
+
* // InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode
|
|
166
152
|
* ```
|
|
167
153
|
*/
|
|
168
154
|
type ParentOf<T extends Node, TEntries extends ReadonlyArray<[Node, unknown]> = ParentNodeMap> = TEntries extends [infer TEntry extends [Node, unknown], ...infer TRest extends ReadonlyArray<[Node, unknown]>] ? T extends TEntry[0] ? TEntry[1] : ParentOf<T, TRest> : Node;
|
|
@@ -402,6 +388,11 @@ declare function transform(node: Node, options: TransformOptions): Node;
|
|
|
402
388
|
declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
|
|
403
389
|
//#endregion
|
|
404
390
|
//#region src/defineMacro.d.ts
|
|
391
|
+
/**
|
|
392
|
+
* Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,
|
|
393
|
+
* and `undefined` keeps declaration order.
|
|
394
|
+
*/
|
|
395
|
+
type Enforce = 'pre' | 'post';
|
|
405
396
|
/**
|
|
406
397
|
* A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a
|
|
407
398
|
* {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an
|
|
@@ -410,14 +401,14 @@ declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
|
|
|
410
401
|
*/
|
|
411
402
|
type Macro = Visitor & {
|
|
412
403
|
/**
|
|
413
|
-
* Macro identifier
|
|
404
|
+
* Macro identifier used to tell macros apart, for example `'simplify-union'`.
|
|
414
405
|
*/
|
|
415
406
|
name: string;
|
|
416
407
|
/**
|
|
417
408
|
* Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.
|
|
418
409
|
* Ordering within a bucket follows list order.
|
|
419
410
|
*/
|
|
420
|
-
enforce?:
|
|
411
|
+
enforce?: Enforce;
|
|
421
412
|
/**
|
|
422
413
|
* Gate checked against the current node before any callback runs. When it returns `false`
|
|
423
414
|
* the macro is skipped for that node.
|
|
@@ -471,5 +462,5 @@ declare function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyAr
|
|
|
471
462
|
depth?: VisitorDepth;
|
|
472
463
|
}): TNode;
|
|
473
464
|
//#endregion
|
|
474
|
-
export {
|
|
475
|
-
//# sourceMappingURL=defineMacro-
|
|
465
|
+
export { defineMacro as a, VisitorContext as c, walk as d, schemaTypes as f, composeMacros as i, collect as l, Macro as n, ParentOf as o, applyMacros as r, Visitor as s, Enforce as t, transform as u };
|
|
466
|
+
//# sourceMappingURL=defineMacro-BATi7xoC.d.ts.map
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
require("./
|
|
2
|
-
const
|
|
1
|
+
const require_schema = require("./schema-BkvrrOAr.cjs");
|
|
2
|
+
const require_refs = require("./refs-u5SDdyV7.cjs");
|
|
3
3
|
//#region src/defineMacro.ts
|
|
4
4
|
/**
|
|
5
|
-
* Visitor callback names a macro can implement, one per traversable node kind.
|
|
6
|
-
* Mirrors the keys of {@link Visitor}.
|
|
7
|
-
*/
|
|
8
|
-
const macroKeys = [
|
|
9
|
-
"input",
|
|
10
|
-
"output",
|
|
11
|
-
"operation",
|
|
12
|
-
"schema",
|
|
13
|
-
"property",
|
|
14
|
-
"parameter",
|
|
15
|
-
"response"
|
|
16
|
-
];
|
|
17
|
-
/**
|
|
18
5
|
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
19
6
|
* list keeps its authored order.
|
|
20
7
|
*/
|
|
@@ -45,7 +32,7 @@ function defineMacro(macro) {
|
|
|
45
32
|
* the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the
|
|
46
33
|
* original reference (structural sharing).
|
|
47
34
|
*/
|
|
48
|
-
function chain(macros, key, node, context) {
|
|
35
|
+
function chain({ macros, key, node, context }) {
|
|
49
36
|
let current = node;
|
|
50
37
|
for (const macro of macros) {
|
|
51
38
|
const callback = macro[key];
|
|
@@ -71,9 +58,14 @@ function chain(macros, key, node, context) {
|
|
|
71
58
|
function composeMacros(macros) {
|
|
72
59
|
const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce));
|
|
73
60
|
const visitor = {};
|
|
74
|
-
for (const key of
|
|
61
|
+
for (const key of require_schema.visitorKeys) {
|
|
75
62
|
if (!ordered.some((macro) => typeof macro[key] === "function")) continue;
|
|
76
|
-
const callback = (node, context) => chain(
|
|
63
|
+
const callback = (node, context) => chain({
|
|
64
|
+
macros: ordered,
|
|
65
|
+
key,
|
|
66
|
+
node,
|
|
67
|
+
context
|
|
68
|
+
});
|
|
77
69
|
visitor[key] = callback;
|
|
78
70
|
}
|
|
79
71
|
return visitor;
|
|
@@ -95,9 +87,9 @@ function composeMacros(macros) {
|
|
|
95
87
|
*/
|
|
96
88
|
function applyMacros(root, macros, options) {
|
|
97
89
|
if (macros.length === 0) return root;
|
|
98
|
-
return
|
|
90
|
+
return require_refs.transform(root, {
|
|
99
91
|
...composeMacros(macros),
|
|
100
|
-
|
|
92
|
+
...options
|
|
101
93
|
});
|
|
102
94
|
}
|
|
103
95
|
//#endregion
|
|
@@ -120,4 +112,4 @@ Object.defineProperty(exports, "defineMacro", {
|
|
|
120
112
|
}
|
|
121
113
|
});
|
|
122
114
|
|
|
123
|
-
//# sourceMappingURL=defineMacro-
|
|
115
|
+
//# sourceMappingURL=defineMacro-CEZHaCXE.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineMacro-CEZHaCXE.cjs","names":["visitorKeys","transform"],"sources":["../src/defineMacro.ts"],"sourcesContent":["import type { VisitorDepth } from './constants.ts'\nimport type { VisitorKey } from './defineNode.ts'\nimport { visitorKeys } from './defineNode.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext } from './visitor.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter\n * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = Visitor & {\n /**\n * Macro identifier used to tell macros apart, for example `'simplify-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Gate checked against the current node before any callback runs. When it returns `false`\n * the macro is skipped for that node.\n */\n when?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `definePlugin`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.when && !macro.when(current)) continue\n\n const next = callback(current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin\n * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied\n * sequentially per node so later macros see earlier output. This differs from a plain visitor, which\n * has no names, ordering, or composition.\n *\n * @example\n * ```ts\n * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])\n * const next = transform(root, visitor)\n * ```\n */\nexport function composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to rewrite the root node only.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Apply to the root node only\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n"],"mappings":";;;;;;;AAiBA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,QAAQ,CAAC,MAAM,KAAK,OAAO,GAAG;EAExC,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;;;;;;;;;AAcA,SAAgB,cAAc,QAAuC;CACnE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,cAAc,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,CAAC;CAE9F,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAOA,eAAAA,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACtG,QAA+C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAOC,aAAAA,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"}
|
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
import "./chunk-CNktS9qV.js";
|
|
2
|
-
import {
|
|
2
|
+
import { u as transform } from "./refs-BjNDuCBD.js";
|
|
3
|
+
import { nt as visitorKeys } from "./schema-Cbnxmz4b.js";
|
|
3
4
|
//#region src/defineMacro.ts
|
|
4
5
|
/**
|
|
5
|
-
* Visitor callback names a macro can implement, one per traversable node kind.
|
|
6
|
-
* Mirrors the keys of {@link Visitor}.
|
|
7
|
-
*/
|
|
8
|
-
const macroKeys = [
|
|
9
|
-
"input",
|
|
10
|
-
"output",
|
|
11
|
-
"operation",
|
|
12
|
-
"schema",
|
|
13
|
-
"property",
|
|
14
|
-
"parameter",
|
|
15
|
-
"response"
|
|
16
|
-
];
|
|
17
|
-
/**
|
|
18
6
|
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
19
7
|
* list keeps its authored order.
|
|
20
8
|
*/
|
|
@@ -45,7 +33,7 @@ function defineMacro(macro) {
|
|
|
45
33
|
* the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the
|
|
46
34
|
* original reference (structural sharing).
|
|
47
35
|
*/
|
|
48
|
-
function chain(macros, key, node, context) {
|
|
36
|
+
function chain({ macros, key, node, context }) {
|
|
49
37
|
let current = node;
|
|
50
38
|
for (const macro of macros) {
|
|
51
39
|
const callback = macro[key];
|
|
@@ -71,9 +59,14 @@ function chain(macros, key, node, context) {
|
|
|
71
59
|
function composeMacros(macros) {
|
|
72
60
|
const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce));
|
|
73
61
|
const visitor = {};
|
|
74
|
-
for (const key of
|
|
62
|
+
for (const key of visitorKeys) {
|
|
75
63
|
if (!ordered.some((macro) => typeof macro[key] === "function")) continue;
|
|
76
|
-
const callback = (node, context) => chain(
|
|
64
|
+
const callback = (node, context) => chain({
|
|
65
|
+
macros: ordered,
|
|
66
|
+
key,
|
|
67
|
+
node,
|
|
68
|
+
context
|
|
69
|
+
});
|
|
77
70
|
visitor[key] = callback;
|
|
78
71
|
}
|
|
79
72
|
return visitor;
|
|
@@ -97,10 +90,10 @@ function applyMacros(root, macros, options) {
|
|
|
97
90
|
if (macros.length === 0) return root;
|
|
98
91
|
return transform(root, {
|
|
99
92
|
...composeMacros(macros),
|
|
100
|
-
|
|
93
|
+
...options
|
|
101
94
|
});
|
|
102
95
|
}
|
|
103
96
|
//#endregion
|
|
104
97
|
export { composeMacros as n, defineMacro as r, applyMacros as t };
|
|
105
98
|
|
|
106
|
-
//# sourceMappingURL=defineMacro-
|
|
99
|
+
//# sourceMappingURL=defineMacro-Shz8f6SG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineMacro-Shz8f6SG.js","names":[],"sources":["../src/defineMacro.ts"],"sourcesContent":["import type { VisitorDepth } from './constants.ts'\nimport type { VisitorKey } from './defineNode.ts'\nimport { visitorKeys } from './defineNode.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext } from './visitor.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter\n * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = Visitor & {\n /**\n * Macro identifier used to tell macros apart, for example `'simplify-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Gate checked against the current node before any callback runs. When it returns `false`\n * the macro is skipped for that node.\n */\n when?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `definePlugin`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.when && !macro.when(current)) continue\n\n const next = callback(current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin\n * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied\n * sequentially per node so later macros see earlier output. This differs from a plain visitor, which\n * has no names, ordering, or composition.\n *\n * @example\n * ```ts\n * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])\n * const next = transform(root, visitor)\n * ```\n */\nexport function composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to rewrite the root node only.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Apply to the root node only\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n"],"mappings":";;;;;;;;AAiBA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,QAAQ,CAAC,MAAM,KAAK,OAAO,GAAG;EAExC,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;;;;;;;;;AAcA,SAAgB,cAAc,QAAuC;CACnE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,cAAc,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,CAAC;CAE9F,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAO,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACtG,QAA+C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAO,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"}
|
package/dist/factory.cjs
CHANGED
|
@@ -1,29 +1,89 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
const require_schema = require("./schema-BkvrrOAr.cjs");
|
|
3
|
+
//#region src/factory.ts
|
|
4
|
+
var factory_exports = /* @__PURE__ */ require_schema.__exportAll({
|
|
5
|
+
createArrowFunction: () => require_schema.createArrowFunction,
|
|
6
|
+
createBreak: () => require_schema.createBreak,
|
|
7
|
+
createConst: () => require_schema.createConst,
|
|
8
|
+
createContent: () => require_schema.createContent,
|
|
9
|
+
createExport: () => require_schema.createExport,
|
|
10
|
+
createFile: () => require_schema.createFile,
|
|
11
|
+
createFunction: () => require_schema.createFunction,
|
|
12
|
+
createFunctionParameter: () => require_schema.createFunctionParameter,
|
|
13
|
+
createFunctionParameters: () => require_schema.createFunctionParameters,
|
|
14
|
+
createImport: () => require_schema.createImport,
|
|
15
|
+
createIndexedAccessType: () => require_schema.createIndexedAccessType,
|
|
16
|
+
createInput: () => require_schema.createInput,
|
|
17
|
+
createJsx: () => require_schema.createJsx,
|
|
18
|
+
createObjectBindingPattern: () => require_schema.createObjectBindingPattern,
|
|
19
|
+
createOperation: () => require_schema.createOperation,
|
|
20
|
+
createOutput: () => require_schema.createOutput,
|
|
21
|
+
createParameter: () => require_schema.createParameter,
|
|
22
|
+
createProperty: () => require_schema.createProperty,
|
|
23
|
+
createRequestBody: () => require_schema.createRequestBody,
|
|
24
|
+
createResponse: () => require_schema.createResponse,
|
|
25
|
+
createSchema: () => require_schema.createSchema,
|
|
26
|
+
createSource: () => require_schema.createSource,
|
|
27
|
+
createText: () => require_schema.createText,
|
|
28
|
+
createType: () => require_schema.createType,
|
|
29
|
+
createTypeLiteral: () => require_schema.createTypeLiteral,
|
|
30
|
+
update: () => update
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Identity-preserving node update: returns `node` unchanged when every field in
|
|
34
|
+
* `changes` already equals (by reference) the current value, otherwise a new node
|
|
35
|
+
* with the changes applied.
|
|
36
|
+
*
|
|
37
|
+
* Mirrors the TypeScript compiler's `factory.updateX` contract. Pair it with the
|
|
38
|
+
* structural sharing in {@link transform} so a no-op rewrite does not allocate and
|
|
39
|
+
* downstream passes can detect "nothing changed" by identity. Comparison is shallow,
|
|
40
|
+
* so a structurally equal but newly allocated array or object counts as a change.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* update(node, { name: node.name }) // -> same `node` reference
|
|
45
|
+
* update(node, { name: 'renamed' }) // -> new node, `name` replaced
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
function update(node, changes) {
|
|
49
|
+
for (const key in changes) if (changes[key] !== node[key]) return {
|
|
50
|
+
...node,
|
|
51
|
+
...changes
|
|
52
|
+
};
|
|
53
|
+
return node;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.createArrowFunction = require_schema.createArrowFunction;
|
|
57
|
+
exports.createBreak = require_schema.createBreak;
|
|
58
|
+
exports.createConst = require_schema.createConst;
|
|
59
|
+
exports.createContent = require_schema.createContent;
|
|
60
|
+
exports.createExport = require_schema.createExport;
|
|
61
|
+
exports.createFile = require_schema.createFile;
|
|
62
|
+
exports.createFunction = require_schema.createFunction;
|
|
63
|
+
exports.createFunctionParameter = require_schema.createFunctionParameter;
|
|
64
|
+
exports.createFunctionParameters = require_schema.createFunctionParameters;
|
|
65
|
+
exports.createImport = require_schema.createImport;
|
|
66
|
+
exports.createIndexedAccessType = require_schema.createIndexedAccessType;
|
|
67
|
+
exports.createInput = require_schema.createInput;
|
|
68
|
+
exports.createJsx = require_schema.createJsx;
|
|
69
|
+
exports.createObjectBindingPattern = require_schema.createObjectBindingPattern;
|
|
70
|
+
exports.createOperation = require_schema.createOperation;
|
|
71
|
+
exports.createOutput = require_schema.createOutput;
|
|
72
|
+
exports.createParameter = require_schema.createParameter;
|
|
73
|
+
exports.createProperty = require_schema.createProperty;
|
|
74
|
+
exports.createRequestBody = require_schema.createRequestBody;
|
|
75
|
+
exports.createResponse = require_schema.createResponse;
|
|
76
|
+
exports.createSchema = require_schema.createSchema;
|
|
77
|
+
exports.createSource = require_schema.createSource;
|
|
78
|
+
exports.createText = require_schema.createText;
|
|
79
|
+
exports.createType = require_schema.createType;
|
|
80
|
+
exports.createTypeLiteral = require_schema.createTypeLiteral;
|
|
81
|
+
Object.defineProperty(exports, "factory_exports", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function() {
|
|
84
|
+
return factory_exports;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
exports.update = update;
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=factory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.cjs","names":[],"sources":["../src/factory.ts"],"sourcesContent":["import type { Node } from './nodes/index.ts'\n\n// Node constructors, grouped under the `factory` namespace the way the TypeScript compiler exposes\n// `ts.factory.createX`. Aggregating them here lets `export * as factory from './factory.ts'` in the\n// barrel surface every `createX` alongside the `createFile`/`update` helpers from a single module.\nexport { createArrowFunction, createBreak, createConst, createFunction, createJsx, createText, createType } from './nodes/code.ts'\nexport { createContent } from './nodes/content.ts'\nexport { createExport, createFile, createImport, createSource } from './nodes/file.ts'\nexport type { UserFileNode } from './nodes/file.ts'\nexport { createFunctionParameter, createFunctionParameters, createIndexedAccessType, createObjectBindingPattern, createTypeLiteral } from './nodes/function.ts'\nexport { createInput } from './nodes/input.ts'\nexport { createOperation } from './nodes/operation.ts'\nexport { createOutput } from './nodes/output.ts'\nexport { createParameter } from './nodes/parameter.ts'\nexport { createProperty } from './nodes/property.ts'\nexport { createRequestBody } from './nodes/requestBody.ts'\nexport { createResponse } from './nodes/response.ts'\nexport { createSchema } from './nodes/schema.ts'\n\n/**\n * Identity-preserving node update: returns `node` unchanged when every field in\n * `changes` already equals (by reference) the current value, otherwise a new node\n * with the changes applied.\n *\n * Mirrors the TypeScript compiler's `factory.updateX` contract. Pair it with the\n * structural sharing in {@link transform} so a no-op rewrite does not allocate and\n * downstream passes can detect \"nothing changed\" by identity. Comparison is shallow,\n * so a structurally equal but newly allocated array or object counts as a change.\n *\n * @example\n * ```ts\n * update(node, { name: node.name }) // -> same `node` reference\n * update(node, { name: 'renamed' }) // -> new node, `name` replaced\n * ```\n */\nexport function update<T extends Node>(node: T, changes: Partial<T>): T {\n for (const key in changes) {\n if (changes[key] !== node[key as keyof T]) {\n return { ...node, ...changes }\n }\n }\n\n return node\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,OAAuB,MAAS,SAAwB;CACtE,KAAK,MAAM,OAAO,SAChB,IAAI,QAAQ,SAAS,KAAK,MACxB,OAAO;EAAE,GAAG;EAAM,GAAG;CAAQ;CAIjC,OAAO;AACT"}
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as __name, t as __exportAll } from "./chunk-CNktS9qV.js";
|
|
2
|
-
import { F as
|
|
2
|
+
import { F as createFunctionParameters, Gt as createBreak, I as createIndexedAccessType, J as UserFileNode, Jt as createJsx, Kt as createConst, L as createObjectBindingPattern, Ot as createProperty, P as createFunctionParameter, Q as createSource, R as createTypeLiteral, Wt as createArrowFunction, X as createFile, Xt as createType, Y as createExport, Yt as createText, Z as createImport, _ as createResponse, at as createContent, b as createRequestBody, p as createOperation, qt as createFunction, r as createOutput, s as createInput, t as Node, w as createParameter, wt as createSchema } from "./index-B9cc8MBS.js";
|
|
3
3
|
|
|
4
4
|
//#region src/factory.d.ts
|
|
5
5
|
declare namespace factory_d_exports {
|
|
@@ -10,10 +10,10 @@ declare namespace factory_d_exports {
|
|
|
10
10
|
* `changes` already equals (by reference) the current value, otherwise a new node
|
|
11
11
|
* with the changes applied.
|
|
12
12
|
*
|
|
13
|
-
* Mirrors the TypeScript compiler's `factory.updateX` contract
|
|
14
|
-
* structural sharing in {@link transform} so a no-op rewrite
|
|
15
|
-
* downstream passes can detect "nothing changed" by identity. Comparison is
|
|
16
|
-
*
|
|
13
|
+
* Mirrors the TypeScript compiler's `factory.updateX` contract. Pair it with the
|
|
14
|
+
* structural sharing in {@link transform} so a no-op rewrite does not allocate and
|
|
15
|
+
* downstream passes can detect "nothing changed" by identity. Comparison is shallow,
|
|
16
|
+
* so a structurally equal but newly allocated array or object counts as a change.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
@@ -22,41 +22,6 @@ declare namespace factory_d_exports {
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
declare function update<T extends Node>(node: T, changes: Partial<T>): T;
|
|
25
|
-
/**
|
|
26
|
-
* Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed
|
|
27
|
-
* and `imports`/`exports`/`sources` are deduplicated.
|
|
28
|
-
*/
|
|
29
|
-
type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> & Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>;
|
|
30
|
-
/**
|
|
31
|
-
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
32
|
-
*
|
|
33
|
-
* Computes:
|
|
34
|
-
* - `id` SHA256 hash of the file path
|
|
35
|
-
* - `name` `baseName` without extension
|
|
36
|
-
* - `extname` extension extracted from `baseName`
|
|
37
|
-
*
|
|
38
|
-
* Deduplicates:
|
|
39
|
-
* - `sources` via `combineSources`
|
|
40
|
-
* - `exports` via `combineExports`
|
|
41
|
-
* - `imports` via `combineImports` (also filters unused imports)
|
|
42
|
-
*
|
|
43
|
-
* @throws {Error} when `baseName` has no extension.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* const file = createFile({
|
|
48
|
-
* baseName: 'petStore.ts',
|
|
49
|
-
* path: 'src/models/petStore.ts',
|
|
50
|
-
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
51
|
-
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
52
|
-
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
53
|
-
* })
|
|
54
|
-
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
55
|
-
* // file.name = 'petStore'
|
|
56
|
-
* // file.extname = '.ts'
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
|
|
60
25
|
//#endregion
|
|
61
|
-
export { UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createIndexedAccessType, createInput, createJsx, createObjectBindingPattern, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, createTypeLiteral, factory_d_exports as t, update };
|
|
26
|
+
export { type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createIndexedAccessType, createInput, createJsx, createObjectBindingPattern, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, createTypeLiteral, factory_d_exports as t, update };
|
|
62
27
|
//# sourceMappingURL=factory.d.ts.map
|
package/dist/factory.js
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as
|
|
3
|
-
|
|
1
|
+
import { t as __exportAll } from "./chunk-CNktS9qV.js";
|
|
2
|
+
import { A as createImport, B as createContent, G as createBreak, J as createJsx, K as createConst, O as createExport, S as createTypeLiteral, W as createArrowFunction, X as createType, Y as createText, a as createProperty, b as createIndexedAccessType, f as createOperation, g as createInput, j as createSource, k as createFile, m as createRequestBody, q as createFunction, r as createResponse, s as createParameter, t as createSchema, u as createOutput, v as createFunctionParameter, x as createObjectBindingPattern, y as createFunctionParameters } from "./schema-Cbnxmz4b.js";
|
|
3
|
+
//#region src/factory.ts
|
|
4
|
+
var factory_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
createArrowFunction: () => createArrowFunction,
|
|
6
|
+
createBreak: () => createBreak,
|
|
7
|
+
createConst: () => createConst,
|
|
8
|
+
createContent: () => createContent,
|
|
9
|
+
createExport: () => createExport,
|
|
10
|
+
createFile: () => createFile,
|
|
11
|
+
createFunction: () => createFunction,
|
|
12
|
+
createFunctionParameter: () => createFunctionParameter,
|
|
13
|
+
createFunctionParameters: () => createFunctionParameters,
|
|
14
|
+
createImport: () => createImport,
|
|
15
|
+
createIndexedAccessType: () => createIndexedAccessType,
|
|
16
|
+
createInput: () => createInput,
|
|
17
|
+
createJsx: () => createJsx,
|
|
18
|
+
createObjectBindingPattern: () => createObjectBindingPattern,
|
|
19
|
+
createOperation: () => createOperation,
|
|
20
|
+
createOutput: () => createOutput,
|
|
21
|
+
createParameter: () => createParameter,
|
|
22
|
+
createProperty: () => createProperty,
|
|
23
|
+
createRequestBody: () => createRequestBody,
|
|
24
|
+
createResponse: () => createResponse,
|
|
25
|
+
createSchema: () => createSchema,
|
|
26
|
+
createSource: () => createSource,
|
|
27
|
+
createText: () => createText,
|
|
28
|
+
createType: () => createType,
|
|
29
|
+
createTypeLiteral: () => createTypeLiteral,
|
|
30
|
+
update: () => update
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Identity-preserving node update: returns `node` unchanged when every field in
|
|
34
|
+
* `changes` already equals (by reference) the current value, otherwise a new node
|
|
35
|
+
* with the changes applied.
|
|
36
|
+
*
|
|
37
|
+
* Mirrors the TypeScript compiler's `factory.updateX` contract. Pair it with the
|
|
38
|
+
* structural sharing in {@link transform} so a no-op rewrite does not allocate and
|
|
39
|
+
* downstream passes can detect "nothing changed" by identity. Comparison is shallow,
|
|
40
|
+
* so a structurally equal but newly allocated array or object counts as a change.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* update(node, { name: node.name }) // -> same `node` reference
|
|
45
|
+
* update(node, { name: 'renamed' }) // -> new node, `name` replaced
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
function update(node, changes) {
|
|
49
|
+
for (const key in changes) if (changes[key] !== node[key]) return {
|
|
50
|
+
...node,
|
|
51
|
+
...changes
|
|
52
|
+
};
|
|
53
|
+
return node;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createIndexedAccessType, createInput, createJsx, createObjectBindingPattern, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, createTypeLiteral, factory_exports as t, update };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","names":[],"sources":["../src/factory.ts"],"sourcesContent":["import type { Node } from './nodes/index.ts'\n\n// Node constructors, grouped under the `factory` namespace the way the TypeScript compiler exposes\n// `ts.factory.createX`. Aggregating them here lets `export * as factory from './factory.ts'` in the\n// barrel surface every `createX` alongside the `createFile`/`update` helpers from a single module.\nexport { createArrowFunction, createBreak, createConst, createFunction, createJsx, createText, createType } from './nodes/code.ts'\nexport { createContent } from './nodes/content.ts'\nexport { createExport, createFile, createImport, createSource } from './nodes/file.ts'\nexport type { UserFileNode } from './nodes/file.ts'\nexport { createFunctionParameter, createFunctionParameters, createIndexedAccessType, createObjectBindingPattern, createTypeLiteral } from './nodes/function.ts'\nexport { createInput } from './nodes/input.ts'\nexport { createOperation } from './nodes/operation.ts'\nexport { createOutput } from './nodes/output.ts'\nexport { createParameter } from './nodes/parameter.ts'\nexport { createProperty } from './nodes/property.ts'\nexport { createRequestBody } from './nodes/requestBody.ts'\nexport { createResponse } from './nodes/response.ts'\nexport { createSchema } from './nodes/schema.ts'\n\n/**\n * Identity-preserving node update: returns `node` unchanged when every field in\n * `changes` already equals (by reference) the current value, otherwise a new node\n * with the changes applied.\n *\n * Mirrors the TypeScript compiler's `factory.updateX` contract. Pair it with the\n * structural sharing in {@link transform} so a no-op rewrite does not allocate and\n * downstream passes can detect \"nothing changed\" by identity. Comparison is shallow,\n * so a structurally equal but newly allocated array or object counts as a change.\n *\n * @example\n * ```ts\n * update(node, { name: node.name }) // -> same `node` reference\n * update(node, { name: 'renamed' }) // -> new node, `name` replaced\n * ```\n */\nexport function update<T extends Node>(node: T, changes: Partial<T>): T {\n for (const key in changes) {\n if (changes[key] !== node[key as keyof T]) {\n return { ...node, ...changes }\n }\n }\n\n return node\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,OAAuB,MAAS,SAAwB;CACtE,KAAK,MAAM,OAAO,SAChB,IAAI,QAAQ,SAAS,KAAK,MACxB,OAAO;EAAE,GAAG;EAAM,GAAG;CAAQ;CAIjC,OAAO;AACT"}
|