@kubb/ast 5.0.0-beta.68 → 5.0.0-beta.69
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-DoMJxLWT.cjs → defineMacro-Bh5E_Il6.cjs} +4 -4
- package/dist/{defineMacro-DoMJxLWT.cjs.map → defineMacro-Bh5E_Il6.cjs.map} +1 -1
- package/dist/{defineMacro-_xJf504Y.js → defineMacro-CVrU3ajV.js} +2 -2
- package/dist/{defineMacro-_xJf504Y.js.map → defineMacro-CVrU3ajV.js.map} +1 -1
- package/dist/index.cjs +97 -354
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -33
- package/dist/index.js +3 -259
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +10 -9
- package/dist/macros.cjs.map +1 -1
- package/dist/macros.js +3 -2
- package/dist/macros.js.map +1 -1
- package/dist/refs-8IwpesXW.cjs +157 -0
- package/dist/refs-8IwpesXW.cjs.map +1 -0
- package/dist/refs-D2qwT5ck.js +117 -0
- package/dist/refs-D2qwT5ck.js.map +1 -0
- package/dist/{types-BOsOrEZf.d.ts → types-Df1jVmRy.d.ts} +7 -24
- package/dist/types.d.ts +2 -2
- package/dist/utils.cjs +800 -27
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.js +776 -2
- package/dist/utils.js.map +1 -0
- package/dist/{refs-DLBwxlrG.cjs → visitor-CLLDwBvv.cjs} +7 -155
- package/dist/visitor-CLLDwBvv.cjs.map +1 -0
- package/dist/{refs-CQNBUfBU.js → visitor-DG5ROqRx.js} +2 -114
- package/dist/visitor-DG5ROqRx.js.map +1 -0
- package/package.json +1 -1
- package/dist/refs-CQNBUfBU.js.map +0 -1
- package/dist/refs-DLBwxlrG.cjs.map +0 -1
- package/dist/utils-BjyHu4VI.cjs +0 -918
- package/dist/utils-BjyHu4VI.cjs.map +0 -1
- package/dist/utils-BlvDdD8y.js +0 -776
- package/dist/utils-BlvDdD8y.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_visitor = require("./visitor-CLLDwBvv.cjs");
|
|
2
2
|
//#region src/defineMacro.ts
|
|
3
3
|
/**
|
|
4
4
|
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
@@ -57,7 +57,7 @@ function chain({ macros, key, node, context }) {
|
|
|
57
57
|
function composeMacros(macros) {
|
|
58
58
|
const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce));
|
|
59
59
|
const visitor = {};
|
|
60
|
-
for (const key of
|
|
60
|
+
for (const key of require_visitor.visitorKeys) {
|
|
61
61
|
if (!ordered.some((macro) => typeof macro[key] === "function")) continue;
|
|
62
62
|
const callback = (node, context) => chain({
|
|
63
63
|
macros: ordered,
|
|
@@ -86,7 +86,7 @@ function composeMacros(macros) {
|
|
|
86
86
|
*/
|
|
87
87
|
function applyMacros(root, macros, options) {
|
|
88
88
|
if (macros.length === 0) return root;
|
|
89
|
-
return
|
|
89
|
+
return require_visitor.transform(root, {
|
|
90
90
|
...composeMacros(macros),
|
|
91
91
|
...options
|
|
92
92
|
});
|
|
@@ -111,4 +111,4 @@ Object.defineProperty(exports, "defineMacro", {
|
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
-
//# sourceMappingURL=defineMacro-
|
|
114
|
+
//# sourceMappingURL=defineMacro-Bh5E_Il6.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineMacro-
|
|
1
|
+
{"version":3,"file":"defineMacro-Bh5E_Il6.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,gBAAAA,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,gBAAAA,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import {
|
|
2
|
+
import { r as transform, st as visitorKeys } from "./visitor-DG5ROqRx.js";
|
|
3
3
|
//#region src/defineMacro.ts
|
|
4
4
|
/**
|
|
5
5
|
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
@@ -95,4 +95,4 @@ function applyMacros(root, macros, options) {
|
|
|
95
95
|
//#endregion
|
|
96
96
|
export { composeMacros as n, defineMacro as r, applyMacros as t };
|
|
97
97
|
|
|
98
|
-
//# sourceMappingURL=defineMacro-
|
|
98
|
+
//# sourceMappingURL=defineMacro-CVrU3ajV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineMacro-
|
|
1
|
+
{"version":3,"file":"defineMacro-CVrU3ajV.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/index.cjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
require("./
|
|
4
|
-
const require_defineMacro = require("./defineMacro-DoMJxLWT.cjs");
|
|
5
|
-
let node_crypto = require("node:crypto");
|
|
2
|
+
const require_visitor = require("./visitor-CLLDwBvv.cjs");
|
|
3
|
+
const require_defineMacro = require("./defineMacro-Bh5E_Il6.cjs");
|
|
6
4
|
//#region src/defineDialect.ts
|
|
7
5
|
/**
|
|
8
6
|
* Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the
|
|
@@ -19,7 +17,6 @@ let node_crypto = require("node:crypto");
|
|
|
19
17
|
* isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',
|
|
20
18
|
* resolveRef,
|
|
21
19
|
* },
|
|
22
|
-
* dedupe: { plan },
|
|
23
20
|
* })
|
|
24
21
|
* ```
|
|
25
22
|
*/
|
|
@@ -87,285 +84,33 @@ function createPrinter(build) {
|
|
|
87
84
|
};
|
|
88
85
|
}
|
|
89
86
|
//#endregion
|
|
90
|
-
//#region src/signature.ts
|
|
91
|
-
/**
|
|
92
|
-
* The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.
|
|
93
|
-
*/
|
|
94
|
-
function flagsDescriptor(node) {
|
|
95
|
-
return `${node.primitive ?? ""};${node.format ?? ""};${node.nullable ? 1 : 0}`;
|
|
96
|
-
}
|
|
97
|
-
function refTargetName(node) {
|
|
98
|
-
if (node.ref) return require_refs.extractRefName(node.ref);
|
|
99
|
-
return node.name ?? "";
|
|
100
|
-
}
|
|
101
|
-
const arrayTupleFields = [
|
|
102
|
-
{
|
|
103
|
-
kind: "children",
|
|
104
|
-
key: "items",
|
|
105
|
-
prefix: "i"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
kind: "child",
|
|
109
|
-
key: "rest",
|
|
110
|
-
prefix: "r"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
kind: "scalar",
|
|
114
|
-
key: "min",
|
|
115
|
-
prefix: "mn"
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
kind: "scalar",
|
|
119
|
-
key: "max",
|
|
120
|
-
prefix: "mx"
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
kind: "bool",
|
|
124
|
-
key: "unique",
|
|
125
|
-
prefix: "u"
|
|
126
|
-
}
|
|
127
|
-
];
|
|
128
|
-
const numericFields = [
|
|
129
|
-
{
|
|
130
|
-
kind: "scalar",
|
|
131
|
-
key: "min",
|
|
132
|
-
prefix: "mn"
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
kind: "scalar",
|
|
136
|
-
key: "max",
|
|
137
|
-
prefix: "mx"
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
kind: "scalar",
|
|
141
|
-
key: "exclusiveMinimum",
|
|
142
|
-
prefix: "emn"
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
kind: "scalar",
|
|
146
|
-
key: "exclusiveMaximum",
|
|
147
|
-
prefix: "emx"
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
kind: "scalar",
|
|
151
|
-
key: "multipleOf",
|
|
152
|
-
prefix: "mo"
|
|
153
|
-
}
|
|
154
|
-
];
|
|
155
|
-
const rangeFields = [{
|
|
156
|
-
kind: "scalar",
|
|
157
|
-
key: "min",
|
|
158
|
-
prefix: "mn"
|
|
159
|
-
}, {
|
|
160
|
-
kind: "scalar",
|
|
161
|
-
key: "max",
|
|
162
|
-
prefix: "mx"
|
|
163
|
-
}];
|
|
164
|
-
/**
|
|
165
|
-
* Maps each node `type` to its ordered shape-contributing fields. Types absent from the map
|
|
166
|
-
* (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.
|
|
167
|
-
*/
|
|
168
|
-
const SHAPE_KEYS = {
|
|
169
|
-
object: [
|
|
170
|
-
{ kind: "objectProps" },
|
|
171
|
-
{ kind: "additionalProps" },
|
|
172
|
-
{ kind: "patternProps" },
|
|
173
|
-
{
|
|
174
|
-
kind: "scalar",
|
|
175
|
-
key: "minProperties",
|
|
176
|
-
prefix: "mn"
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
kind: "scalar",
|
|
180
|
-
key: "maxProperties",
|
|
181
|
-
prefix: "mx"
|
|
182
|
-
}
|
|
183
|
-
],
|
|
184
|
-
array: arrayTupleFields,
|
|
185
|
-
tuple: arrayTupleFields,
|
|
186
|
-
union: [
|
|
187
|
-
{
|
|
188
|
-
kind: "scalar",
|
|
189
|
-
key: "strategy",
|
|
190
|
-
prefix: "s"
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
kind: "scalar",
|
|
194
|
-
key: "discriminatorPropertyName",
|
|
195
|
-
prefix: "d"
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
kind: "children",
|
|
199
|
-
key: "members",
|
|
200
|
-
prefix: "m"
|
|
201
|
-
}
|
|
202
|
-
],
|
|
203
|
-
intersection: [{
|
|
204
|
-
kind: "children",
|
|
205
|
-
key: "members",
|
|
206
|
-
prefix: "m"
|
|
207
|
-
}],
|
|
208
|
-
enum: [{ kind: "enumValues" }],
|
|
209
|
-
ref: [{ kind: "refTarget" }],
|
|
210
|
-
string: [
|
|
211
|
-
{
|
|
212
|
-
kind: "scalar",
|
|
213
|
-
key: "min",
|
|
214
|
-
prefix: "mn"
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
kind: "scalar",
|
|
218
|
-
key: "max",
|
|
219
|
-
prefix: "mx"
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
kind: "scalar",
|
|
223
|
-
key: "pattern",
|
|
224
|
-
prefix: "pt"
|
|
225
|
-
}
|
|
226
|
-
],
|
|
227
|
-
number: numericFields,
|
|
228
|
-
integer: numericFields,
|
|
229
|
-
bigint: numericFields,
|
|
230
|
-
url: [
|
|
231
|
-
{
|
|
232
|
-
kind: "scalar",
|
|
233
|
-
key: "path",
|
|
234
|
-
prefix: "path"
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
kind: "scalar",
|
|
238
|
-
key: "min",
|
|
239
|
-
prefix: "mn"
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
kind: "scalar",
|
|
243
|
-
key: "max",
|
|
244
|
-
prefix: "mx"
|
|
245
|
-
}
|
|
246
|
-
],
|
|
247
|
-
uuid: rangeFields,
|
|
248
|
-
email: rangeFields,
|
|
249
|
-
datetime: [{
|
|
250
|
-
kind: "bool",
|
|
251
|
-
key: "offset",
|
|
252
|
-
prefix: "o"
|
|
253
|
-
}, {
|
|
254
|
-
kind: "bool",
|
|
255
|
-
key: "local",
|
|
256
|
-
prefix: "l"
|
|
257
|
-
}],
|
|
258
|
-
date: [{
|
|
259
|
-
kind: "scalar",
|
|
260
|
-
key: "representation",
|
|
261
|
-
prefix: "rep"
|
|
262
|
-
}],
|
|
263
|
-
time: [{
|
|
264
|
-
kind: "scalar",
|
|
265
|
-
key: "representation",
|
|
266
|
-
prefix: "rep"
|
|
267
|
-
}]
|
|
268
|
-
};
|
|
269
|
-
function serializeShapeField(field, node, record) {
|
|
270
|
-
switch (field.kind) {
|
|
271
|
-
case "scalar": return `${field.prefix}:${record[field.key] ?? ""}`;
|
|
272
|
-
case "bool": return `${field.prefix}:${record[field.key] ? 1 : 0}`;
|
|
273
|
-
case "child": {
|
|
274
|
-
const child = record[field.key];
|
|
275
|
-
return `${field.prefix}:${child ? signatureOf(child) : ""}`;
|
|
276
|
-
}
|
|
277
|
-
case "children": {
|
|
278
|
-
const children = record[field.key] ?? [];
|
|
279
|
-
return `${field.prefix}[${children.map((c) => signatureOf(c)).join(",")}]`;
|
|
280
|
-
}
|
|
281
|
-
case "objectProps": return `p[${(node.properties ?? []).map((prop) => `${prop.name}${prop.required ? "!" : "?"}${signatureOf(prop.schema)}`).join(",")}]`;
|
|
282
|
-
case "additionalProps": {
|
|
283
|
-
const obj = node;
|
|
284
|
-
if (typeof obj.additionalProperties === "boolean") return `ab:${obj.additionalProperties}`;
|
|
285
|
-
if (obj.additionalProperties) return `as:${signatureOf(obj.additionalProperties)}`;
|
|
286
|
-
return "";
|
|
287
|
-
}
|
|
288
|
-
case "patternProps": {
|
|
289
|
-
const obj = node;
|
|
290
|
-
return `pp[${obj.patternProperties ? Object.keys(obj.patternProperties).sort().map((key) => `${key}=${signatureOf(obj.patternProperties[key])}`).join(",") : ""}]`;
|
|
291
|
-
}
|
|
292
|
-
case "enumValues": {
|
|
293
|
-
const en = node;
|
|
294
|
-
let values = "";
|
|
295
|
-
if (en.namedEnumValues?.length) values = en.namedEnumValues.map((entry) => `${entry.name}=${entry.primitive}:${String(entry.value)}`).join(",");
|
|
296
|
-
else if (en.enumValues?.length) values = en.enumValues.map((value) => `${value === null ? "null" : typeof value}:${String(value)}`).join(",");
|
|
297
|
-
return `v[${values}]`;
|
|
298
|
-
}
|
|
299
|
-
case "refTarget": return `->${refTargetName(node)}`;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,
|
|
304
|
-
* constraints, and its children's signatures.
|
|
305
|
-
*/
|
|
306
|
-
function describeShape(node) {
|
|
307
|
-
const flags = flagsDescriptor(node);
|
|
308
|
-
const fields = SHAPE_KEYS[node.type];
|
|
309
|
-
if (!fields) return `${node.type}|${flags}`;
|
|
310
|
-
const record = node;
|
|
311
|
-
const parts = [`${node.type}|${flags}`];
|
|
312
|
-
for (const field of fields) parts.push(serializeShapeField(field, node, record));
|
|
313
|
-
return parts.join("|");
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Caches the digest per node, keyed by identity. A `WeakMap` so entries die with the node, and so
|
|
317
|
-
* a tree hashed during dedupe planning is not walked again when it is rewritten during streaming.
|
|
318
|
-
* Reuse is safe because a signature depends only on content, and nodes are immutable once created.
|
|
319
|
-
*/
|
|
320
|
-
const signatureCache = /* @__PURE__ */ new WeakMap();
|
|
321
|
-
/**
|
|
322
|
-
* Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas
|
|
323
|
-
* share a signature when they are structurally identical, ignoring documentation (`name`, `title`,
|
|
324
|
-
* `description`, `examples`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,
|
|
325
|
-
* `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`
|
|
326
|
-
* nodes compare by target name, which also terminates on circular shapes.
|
|
327
|
-
*
|
|
328
|
-
* @example Two enums with different descriptions share a signature
|
|
329
|
-
* ```ts
|
|
330
|
-
* signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
|
|
331
|
-
* signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
|
|
332
|
-
* ```
|
|
333
|
-
*/
|
|
334
|
-
function signatureOf(node) {
|
|
335
|
-
const cached = signatureCache.get(node);
|
|
336
|
-
if (cached !== void 0) return cached;
|
|
337
|
-
const signature = (0, node_crypto.hash)("sha256", describeShape(node), "hex");
|
|
338
|
-
signatureCache.set(node, signature);
|
|
339
|
-
return signature;
|
|
340
|
-
}
|
|
341
|
-
//#endregion
|
|
342
87
|
//#region src/factory.ts
|
|
343
|
-
var factory_exports = /* @__PURE__ */
|
|
344
|
-
createArrowFunction: () =>
|
|
345
|
-
createBreak: () =>
|
|
346
|
-
createConst: () =>
|
|
347
|
-
createContent: () =>
|
|
348
|
-
createExport: () =>
|
|
349
|
-
createFile: () =>
|
|
350
|
-
createFunction: () =>
|
|
351
|
-
createFunctionParameter: () =>
|
|
352
|
-
createFunctionParameters: () =>
|
|
353
|
-
createImport: () =>
|
|
354
|
-
createIndexedAccessType: () =>
|
|
355
|
-
createInput: () =>
|
|
356
|
-
createJsx: () =>
|
|
357
|
-
createObjectBindingPattern: () =>
|
|
358
|
-
createOperation: () =>
|
|
359
|
-
createOutput: () =>
|
|
360
|
-
createParameter: () =>
|
|
361
|
-
createProperty: () =>
|
|
362
|
-
createRequestBody: () =>
|
|
363
|
-
createResponse: () =>
|
|
364
|
-
createSchema: () =>
|
|
365
|
-
createSource: () =>
|
|
366
|
-
createText: () =>
|
|
367
|
-
createType: () =>
|
|
368
|
-
createTypeLiteral: () =>
|
|
88
|
+
var factory_exports = /* @__PURE__ */ require_visitor.__exportAll({
|
|
89
|
+
createArrowFunction: () => require_visitor.createArrowFunction,
|
|
90
|
+
createBreak: () => require_visitor.createBreak,
|
|
91
|
+
createConst: () => require_visitor.createConst,
|
|
92
|
+
createContent: () => require_visitor.createContent,
|
|
93
|
+
createExport: () => require_visitor.createExport,
|
|
94
|
+
createFile: () => require_visitor.createFile,
|
|
95
|
+
createFunction: () => require_visitor.createFunction,
|
|
96
|
+
createFunctionParameter: () => require_visitor.createFunctionParameter,
|
|
97
|
+
createFunctionParameters: () => require_visitor.createFunctionParameters,
|
|
98
|
+
createImport: () => require_visitor.createImport,
|
|
99
|
+
createIndexedAccessType: () => require_visitor.createIndexedAccessType,
|
|
100
|
+
createInput: () => require_visitor.createInput,
|
|
101
|
+
createJsx: () => require_visitor.createJsx,
|
|
102
|
+
createObjectBindingPattern: () => require_visitor.createObjectBindingPattern,
|
|
103
|
+
createOperation: () => require_visitor.createOperation,
|
|
104
|
+
createOutput: () => require_visitor.createOutput,
|
|
105
|
+
createParameter: () => require_visitor.createParameter,
|
|
106
|
+
createProperty: () => require_visitor.createProperty,
|
|
107
|
+
createRequestBody: () => require_visitor.createRequestBody,
|
|
108
|
+
createResponse: () => require_visitor.createResponse,
|
|
109
|
+
createSchema: () => require_visitor.createSchema,
|
|
110
|
+
createSource: () => require_visitor.createSource,
|
|
111
|
+
createText: () => require_visitor.createText,
|
|
112
|
+
createType: () => require_visitor.createType,
|
|
113
|
+
createTypeLiteral: () => require_visitor.createTypeLiteral,
|
|
369
114
|
update: () => update
|
|
370
115
|
});
|
|
371
116
|
/**
|
|
@@ -393,101 +138,99 @@ function update(node, changes) {
|
|
|
393
138
|
}
|
|
394
139
|
//#endregion
|
|
395
140
|
//#region src/exports.ts
|
|
396
|
-
var exports_exports = /* @__PURE__ */
|
|
141
|
+
var exports_exports = /* @__PURE__ */ require_visitor.__exportAll({
|
|
397
142
|
applyMacros: () => require_defineMacro.applyMacros,
|
|
398
|
-
arrowFunctionDef: () =>
|
|
399
|
-
breakDef: () =>
|
|
400
|
-
collect: () =>
|
|
143
|
+
arrowFunctionDef: () => require_visitor.arrowFunctionDef,
|
|
144
|
+
breakDef: () => require_visitor.breakDef,
|
|
145
|
+
collect: () => require_visitor.collect,
|
|
401
146
|
composeMacros: () => require_defineMacro.composeMacros,
|
|
402
|
-
constDef: () =>
|
|
403
|
-
contentDef: () =>
|
|
147
|
+
constDef: () => require_visitor.constDef,
|
|
148
|
+
contentDef: () => require_visitor.contentDef,
|
|
404
149
|
createPrinter: () => createPrinter,
|
|
405
150
|
defineDialect: () => defineDialect,
|
|
406
151
|
defineMacro: () => require_defineMacro.defineMacro,
|
|
407
|
-
defineNode: () =>
|
|
408
|
-
exportDef: () =>
|
|
152
|
+
defineNode: () => require_visitor.defineNode,
|
|
153
|
+
exportDef: () => require_visitor.exportDef,
|
|
409
154
|
factory: () => factory_exports,
|
|
410
|
-
fileDef: () =>
|
|
411
|
-
functionDef: () =>
|
|
412
|
-
functionParameterDef: () =>
|
|
413
|
-
functionParametersDef: () =>
|
|
414
|
-
importDef: () =>
|
|
415
|
-
indexedAccessTypeDef: () =>
|
|
416
|
-
inputDef: () =>
|
|
417
|
-
isHttpOperationNode: () =>
|
|
418
|
-
jsxDef: () =>
|
|
419
|
-
narrowSchema: () =>
|
|
420
|
-
nodeDefs: () =>
|
|
421
|
-
objectBindingPatternDef: () =>
|
|
422
|
-
operationDef: () =>
|
|
423
|
-
optionality: () =>
|
|
424
|
-
outputDef: () =>
|
|
425
|
-
parameterDef: () =>
|
|
426
|
-
propertyDef: () =>
|
|
427
|
-
requestBodyDef: () =>
|
|
428
|
-
responseDef: () =>
|
|
429
|
-
schemaDef: () =>
|
|
430
|
-
schemaTypes: () =>
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
walk: () => require_refs.walk
|
|
155
|
+
fileDef: () => require_visitor.fileDef,
|
|
156
|
+
functionDef: () => require_visitor.functionDef,
|
|
157
|
+
functionParameterDef: () => require_visitor.functionParameterDef,
|
|
158
|
+
functionParametersDef: () => require_visitor.functionParametersDef,
|
|
159
|
+
importDef: () => require_visitor.importDef,
|
|
160
|
+
indexedAccessTypeDef: () => require_visitor.indexedAccessTypeDef,
|
|
161
|
+
inputDef: () => require_visitor.inputDef,
|
|
162
|
+
isHttpOperationNode: () => require_visitor.isHttpOperationNode,
|
|
163
|
+
jsxDef: () => require_visitor.jsxDef,
|
|
164
|
+
narrowSchema: () => require_visitor.narrowSchema,
|
|
165
|
+
nodeDefs: () => require_visitor.nodeDefs,
|
|
166
|
+
objectBindingPatternDef: () => require_visitor.objectBindingPatternDef,
|
|
167
|
+
operationDef: () => require_visitor.operationDef,
|
|
168
|
+
optionality: () => require_visitor.optionality,
|
|
169
|
+
outputDef: () => require_visitor.outputDef,
|
|
170
|
+
parameterDef: () => require_visitor.parameterDef,
|
|
171
|
+
propertyDef: () => require_visitor.propertyDef,
|
|
172
|
+
requestBodyDef: () => require_visitor.requestBodyDef,
|
|
173
|
+
responseDef: () => require_visitor.responseDef,
|
|
174
|
+
schemaDef: () => require_visitor.schemaDef,
|
|
175
|
+
schemaTypes: () => require_visitor.schemaTypes,
|
|
176
|
+
sourceDef: () => require_visitor.sourceDef,
|
|
177
|
+
textDef: () => require_visitor.textDef,
|
|
178
|
+
transform: () => require_visitor.transform,
|
|
179
|
+
typeDef: () => require_visitor.typeDef,
|
|
180
|
+
typeLiteralDef: () => require_visitor.typeLiteralDef,
|
|
181
|
+
walk: () => require_visitor.walk
|
|
438
182
|
});
|
|
439
183
|
//#endregion
|
|
440
184
|
exports.applyMacros = require_defineMacro.applyMacros;
|
|
441
|
-
exports.arrowFunctionDef =
|
|
185
|
+
exports.arrowFunctionDef = require_visitor.arrowFunctionDef;
|
|
442
186
|
Object.defineProperty(exports, "ast", {
|
|
443
187
|
enumerable: true,
|
|
444
188
|
get: function() {
|
|
445
189
|
return exports_exports;
|
|
446
190
|
}
|
|
447
191
|
});
|
|
448
|
-
exports.breakDef =
|
|
449
|
-
exports.collect =
|
|
192
|
+
exports.breakDef = require_visitor.breakDef;
|
|
193
|
+
exports.collect = require_visitor.collect;
|
|
450
194
|
exports.composeMacros = require_defineMacro.composeMacros;
|
|
451
|
-
exports.constDef =
|
|
452
|
-
exports.contentDef =
|
|
195
|
+
exports.constDef = require_visitor.constDef;
|
|
196
|
+
exports.contentDef = require_visitor.contentDef;
|
|
453
197
|
exports.createPrinter = createPrinter;
|
|
454
198
|
exports.defineDialect = defineDialect;
|
|
455
199
|
exports.defineMacro = require_defineMacro.defineMacro;
|
|
456
|
-
exports.defineNode =
|
|
457
|
-
exports.exportDef =
|
|
200
|
+
exports.defineNode = require_visitor.defineNode;
|
|
201
|
+
exports.exportDef = require_visitor.exportDef;
|
|
458
202
|
Object.defineProperty(exports, "factory", {
|
|
459
203
|
enumerable: true,
|
|
460
204
|
get: function() {
|
|
461
205
|
return factory_exports;
|
|
462
206
|
}
|
|
463
207
|
});
|
|
464
|
-
exports.fileDef =
|
|
465
|
-
exports.functionDef =
|
|
466
|
-
exports.functionParameterDef =
|
|
467
|
-
exports.functionParametersDef =
|
|
468
|
-
exports.importDef =
|
|
469
|
-
exports.indexedAccessTypeDef =
|
|
470
|
-
exports.inputDef =
|
|
471
|
-
exports.isHttpOperationNode =
|
|
472
|
-
exports.jsxDef =
|
|
473
|
-
exports.narrowSchema =
|
|
474
|
-
exports.nodeDefs =
|
|
475
|
-
exports.objectBindingPatternDef =
|
|
476
|
-
exports.operationDef =
|
|
477
|
-
exports.optionality =
|
|
478
|
-
exports.outputDef =
|
|
479
|
-
exports.parameterDef =
|
|
480
|
-
exports.propertyDef =
|
|
481
|
-
exports.requestBodyDef =
|
|
482
|
-
exports.responseDef =
|
|
483
|
-
exports.schemaDef =
|
|
484
|
-
exports.schemaTypes =
|
|
485
|
-
exports.
|
|
486
|
-
exports.
|
|
487
|
-
exports.
|
|
488
|
-
exports.
|
|
489
|
-
exports.
|
|
490
|
-
exports.
|
|
491
|
-
exports.walk = require_refs.walk;
|
|
208
|
+
exports.fileDef = require_visitor.fileDef;
|
|
209
|
+
exports.functionDef = require_visitor.functionDef;
|
|
210
|
+
exports.functionParameterDef = require_visitor.functionParameterDef;
|
|
211
|
+
exports.functionParametersDef = require_visitor.functionParametersDef;
|
|
212
|
+
exports.importDef = require_visitor.importDef;
|
|
213
|
+
exports.indexedAccessTypeDef = require_visitor.indexedAccessTypeDef;
|
|
214
|
+
exports.inputDef = require_visitor.inputDef;
|
|
215
|
+
exports.isHttpOperationNode = require_visitor.isHttpOperationNode;
|
|
216
|
+
exports.jsxDef = require_visitor.jsxDef;
|
|
217
|
+
exports.narrowSchema = require_visitor.narrowSchema;
|
|
218
|
+
exports.nodeDefs = require_visitor.nodeDefs;
|
|
219
|
+
exports.objectBindingPatternDef = require_visitor.objectBindingPatternDef;
|
|
220
|
+
exports.operationDef = require_visitor.operationDef;
|
|
221
|
+
exports.optionality = require_visitor.optionality;
|
|
222
|
+
exports.outputDef = require_visitor.outputDef;
|
|
223
|
+
exports.parameterDef = require_visitor.parameterDef;
|
|
224
|
+
exports.propertyDef = require_visitor.propertyDef;
|
|
225
|
+
exports.requestBodyDef = require_visitor.requestBodyDef;
|
|
226
|
+
exports.responseDef = require_visitor.responseDef;
|
|
227
|
+
exports.schemaDef = require_visitor.schemaDef;
|
|
228
|
+
exports.schemaTypes = require_visitor.schemaTypes;
|
|
229
|
+
exports.sourceDef = require_visitor.sourceDef;
|
|
230
|
+
exports.textDef = require_visitor.textDef;
|
|
231
|
+
exports.transform = require_visitor.transform;
|
|
232
|
+
exports.typeDef = require_visitor.typeDef;
|
|
233
|
+
exports.typeLiteralDef = require_visitor.typeLiteralDef;
|
|
234
|
+
exports.walk = require_visitor.walk;
|
|
492
235
|
|
|
493
236
|
//# sourceMappingURL=index.cjs.map
|