@kubb/ast 5.22.0 → 5.23.1
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/base-IpYuh3ZP.d.cts +173 -0
- package/dist/base-IpYuh3ZP.d.ts +173 -0
- package/dist/constants-Ckeonm-D.js +141 -0
- package/dist/constants-Ckeonm-D.js.map +1 -0
- package/dist/constants-CquR083U.cjs +152 -0
- package/dist/constants-CquR083U.cjs.map +1 -0
- package/dist/factory.cjs +23 -0
- package/dist/factory.d.cts +4 -0
- package/dist/factory.d.ts +4 -0
- package/dist/factory.js +4 -0
- package/dist/file-BVqSiSvV.d.cts +624 -0
- package/dist/file-Cg0T6cgz.cjs +319 -0
- package/dist/file-Cg0T6cgz.cjs.map +1 -0
- package/dist/file-CnuL8oUj.js +283 -0
- package/dist/file-CnuL8oUj.js.map +1 -0
- package/dist/file-CvlMAp_d.js +131 -0
- package/dist/file-CvlMAp_d.js.map +1 -0
- package/dist/file-Dd50jPkH.cjs +142 -0
- package/dist/file-Dd50jPkH.cjs.map +1 -0
- package/dist/file-xJnBQPGq.d.ts +624 -0
- package/dist/file.cjs +3 -0
- package/dist/file.d.cts +2 -0
- package/dist/file.d.ts +2 -0
- package/dist/file.js +1 -0
- package/dist/graph-BcwFCvei.js +144 -0
- package/dist/graph-BcwFCvei.js.map +1 -0
- package/dist/graph-DcIY6tQb.cjs +173 -0
- package/dist/graph-DcIY6tQb.cjs.map +1 -0
- package/dist/graph.cjs +6 -0
- package/dist/graph.d.cts +2 -0
- package/dist/graph.d.ts +2 -0
- package/dist/graph.js +1 -0
- package/dist/guards-B8qDgSaT.d.cts +23 -0
- package/dist/guards-COVJE6TU.cjs +41 -0
- package/dist/guards-COVJE6TU.cjs.map +1 -0
- package/dist/guards-D-h9R_sV.d.ts +23 -0
- package/dist/guards-DlJkKsT1.js +30 -0
- package/dist/guards-DlJkKsT1.js.map +1 -0
- package/dist/http-Bm5lhVK4.cjs +12 -0
- package/dist/http-Bm5lhVK4.cjs.map +1 -0
- package/dist/http-DwboM6pK.js +7 -0
- package/dist/http-DwboM6pK.js.map +1 -0
- package/dist/http.cjs +4 -0
- package/dist/http.d.cts +3 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.js +2 -0
- package/dist/index-BWd95onW.d.cts +5 -0
- package/dist/index-Bb1kqq8H.d.cts +20 -0
- package/dist/index-BngGJux5.d.cts +12 -0
- package/dist/index-BwnMIoLl.d.ts +24 -0
- package/dist/index-C-vhkzwR.d.cts +79 -0
- package/dist/index-CAGuKv6t.d.ts +74 -0
- package/dist/index-CFH4ZC7q.d.ts +44 -0
- package/dist/index-CIqwy4EE.d.cts +74 -0
- package/dist/index-Cc2K3OzU.d.cts +11 -0
- package/dist/index-Cc2K3OzU.d.ts +11 -0
- package/dist/index-Csf8xsCc.d.cts +46 -0
- package/dist/index-D3M2spDR.d.ts +12 -0
- package/dist/index-DNiIem0x.d.ts +79 -0
- package/dist/index-DSVef1pp.d.cts +24 -0
- package/dist/index-DU_jYpBt.d.cts +44 -0
- package/dist/index-DYDha-3I.d.cts +67 -0
- package/dist/index-DaHsMJ_S.d.ts +5 -0
- package/dist/index-Dp50LM3a.d.ts +67 -0
- package/dist/index-cpjUxIik.d.ts +46 -0
- package/dist/index-eGkM4FE9.d.ts +20 -0
- package/dist/index.cjs +87 -2131
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -2745
- package/dist/index.d.ts +25 -2745
- package/dist/index.js +40 -2052
- package/dist/index.js.map +1 -1
- package/dist/json-DH7_lcWm.js +74 -0
- package/dist/json-DH7_lcWm.js.map +1 -0
- package/dist/json-DURdtz9A.cjs +91 -0
- package/dist/json-DURdtz9A.cjs.map +1 -0
- package/dist/json.cjs +4 -0
- package/dist/json.d.cts +2 -0
- package/dist/json.d.ts +2 -0
- package/dist/json.js +1 -0
- package/dist/macro-D0KfNtff.js +104 -0
- package/dist/macro-D0KfNtff.js.map +1 -0
- package/dist/macro-DrTBT7fh.cjs +127 -0
- package/dist/macro-DrTBT7fh.cjs.map +1 -0
- package/dist/macro.cjs +4 -0
- package/dist/macro.d.cts +2 -0
- package/dist/macro.d.ts +2 -0
- package/dist/macro.js +1 -0
- package/dist/mediaType-CRjggmoG.js +19 -0
- package/dist/mediaType-CRjggmoG.js.map +1 -0
- package/dist/mediaType-D8uIO8sG.cjs +35 -0
- package/dist/mediaType-D8uIO8sG.cjs.map +1 -0
- package/dist/mediaType.cjs +4 -0
- package/dist/mediaType.d.cts +2 -0
- package/dist/mediaType.d.ts +2 -0
- package/dist/mediaType.js +1 -0
- package/dist/node-DjcETnc8.cjs +19 -0
- package/dist/node-DjcETnc8.cjs.map +1 -0
- package/dist/node-Djh-mZB2.js +14 -0
- package/dist/node-Djh-mZB2.js.map +1 -0
- package/dist/node.cjs +9 -0
- package/dist/node.d.cts +4 -0
- package/dist/node.d.ts +4 -0
- package/dist/node.js +5 -0
- package/dist/nodeText-DRb_rVd1.cjs +58 -0
- package/dist/nodeText-DRb_rVd1.cjs.map +1 -0
- package/dist/nodeText-DVVDZQjF.js +47 -0
- package/dist/nodeText-DVVDZQjF.js.map +1 -0
- package/dist/nodes-BB60Bq2H.cjs +320 -0
- package/dist/nodes-BB60Bq2H.cjs.map +1 -0
- package/dist/nodes-CWMa9xhW.js +231 -0
- package/dist/nodes-CWMa9xhW.js.map +1 -0
- package/dist/operation-BgRyVS7z.d.ts +1272 -0
- package/dist/operation-X7chCdL2.d.cts +1272 -0
- package/dist/optionality-D-zqzVMH.cjs +22 -0
- package/dist/optionality-D-zqzVMH.cjs.map +1 -0
- package/dist/optionality-DISn8ytP.js +17 -0
- package/dist/optionality-DISn8ytP.js.map +1 -0
- package/dist/promise-BOdlgT0N.cjs +50 -0
- package/dist/promise-BOdlgT0N.cjs.map +1 -0
- package/dist/promise-RpnEev9D.js +45 -0
- package/dist/promise-RpnEev9D.js.map +1 -0
- package/dist/ref-Bu7PoHar.js +22 -0
- package/dist/ref-Bu7PoHar.js.map +1 -0
- package/dist/ref-P0ZLT1Bg.cjs +39 -0
- package/dist/ref-P0ZLT1Bg.cjs.map +1 -0
- package/dist/ref.cjs +7 -0
- package/dist/ref.d.cts +2 -0
- package/dist/ref.d.ts +2 -0
- package/dist/ref.js +3 -0
- package/dist/refs-CYHpRlQo.cjs +131 -0
- package/dist/refs-CYHpRlQo.cjs.map +1 -0
- package/dist/refs-YCV3CznS.js +102 -0
- package/dist/refs-YCV3CznS.js.map +1 -0
- package/dist/rolldown-runtime-BV8xUvPy.cjs +52 -0
- package/dist/rolldown-runtime-BYyVTPww.js +16 -0
- package/dist/schema-2ZAQk7qE.js +44 -0
- package/dist/schema-2ZAQk7qE.js.map +1 -0
- package/dist/schema-BIErWqgc.cjs +214 -0
- package/dist/schema-BIErWqgc.cjs.map +1 -0
- package/dist/schema-DloctnMm.js +179 -0
- package/dist/schema-DloctnMm.js.map +1 -0
- package/dist/schema-hxMlgCrV.cjs +49 -0
- package/dist/schema-hxMlgCrV.cjs.map +1 -0
- package/dist/schema.cjs +16 -0
- package/dist/schema.d.cts +5 -0
- package/dist/schema.d.ts +5 -0
- package/dist/schema.js +6 -0
- package/dist/visitor-BZozlXBF.d.ts +179 -0
- package/dist/visitor-Bw_opzjF.d.cts +179 -0
- package/dist/visitor-DTrzvA3R.cjs +382 -0
- package/dist/visitor-DTrzvA3R.cjs.map +1 -0
- package/dist/visitor-NoQSUQTu.js +347 -0
- package/dist/visitor-NoQSUQTu.js.map +1 -0
- package/package.json +101 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-DH7_lcWm.js","names":[],"sources":["../src/json/index.ts"],"sourcesContent":["import { nodeKinds, schemaTypes } from '../constants.ts'\nimport type { InputNode } from '../nodes/input.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\nconst version = 1\n\ntype JsonDocument = {\n version: number\n input: InputNode\n targets: Array<SchemaNode>\n}\n\nfunction isRef(value: unknown): value is { schema: unknown } {\n const node = value as { kind?: unknown; type?: unknown } | null\n return node?.kind === nodeKinds.schema && node.type === schemaTypes.ref\n}\n\n/**\n * Turns an `InputNode` into JSON text that `parse` reads back. Every schema a ref points at is written once,\n * where a plain `JSON.stringify(input)` writes it again at every ref.\n *\n * @example\n * ```ts\n * await writeFile('input.json', ast.json.stringify(input))\n * ```\n */\nexport function stringify(input: InputNode): string {\n const ids = new Map<unknown, number>()\n const targets: Array<unknown> = []\n\n function replacer(this: unknown, key: string, value: unknown): unknown {\n if (key !== 'schema' || !isRef(this)) return value\n // Spec data such as a `default` can look like a ref node. Its number is wrapped, so `parse` does not read it as a target.\n if (typeof value === 'number') return [value]\n if (typeof value !== 'object' || value === null) return value\n if (!ids.has(value)) {\n ids.set(value, targets.length)\n targets.push(value)\n }\n return ids.get(value)\n }\n\n const root = JSON.stringify(input, replacer)\n const encoded: Array<string> = []\n // A target can hold refs to targets not seen yet, so the list grows while this loop reads it.\n for (const target of targets) encoded.push(JSON.stringify(target, replacer))\n\n return `{\"version\":${version},\"input\":${root},\"targets\":[${encoded.join(',')}]}`\n}\n\n/**\n * Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.\n * Throws on another format version, or on a ref whose target is missing.\n */\nexport function parse(text: string): InputNode {\n // Plain `JSON.parse` and one loop over the tree: a reviver made this about 5 times slower on a large spec.\n const document = JSON.parse(text) as Partial<JsonDocument> | null\n\n if (document?.version !== version) {\n throw new Error(`Cannot read this AST JSON: expected format version ${version}, got ${JSON.stringify(document?.version)}.`)\n }\n if (!document.input || !Array.isArray(document.targets)) {\n throw new Error('Cannot read this AST JSON: `input` or `targets` is missing.')\n }\n\n const targets = document.targets\n const stack: Array<unknown> = [document.input, ...targets]\n while (stack.length) {\n const value = stack.pop() as Record<string, unknown>\n const ref = isRef(value)\n for (const key in value) {\n const child = value[key]\n if (ref && key === 'schema') {\n if (Array.isArray(child)) {\n value.schema = child[0]\n continue\n }\n if (typeof child === 'number') {\n const target = targets[child]\n if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${child}, which is missing.`)\n value.schema = target\n continue\n }\n }\n if (typeof child === 'object' && child !== null) stack.push(child)\n }\n }\n\n return document.input\n}\n"],"mappings":";;;;;;;AAIA,MAAM,UAAU;AAQhB,SAAS,MAAM,OAA8C;CAC3D,MAAM,OAAO;CACb,OAAO,MAAM,SAAS,UAAU,UAAU,KAAK,SAAS,YAAY;AACtE;;;;;;;;;;AAWA,SAAgB,UAAU,OAA0B;CAClD,MAAM,sBAAM,IAAI,IAAqB;CACrC,MAAM,UAA0B,CAAC;CAEjC,SAAS,SAAwB,KAAa,OAAyB;EACrE,IAAI,QAAQ,YAAY,CAAC,MAAM,IAAI,GAAG,OAAO;EAE7C,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC,KAAK;EAC5C,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;EACxD,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG;GACnB,IAAI,IAAI,OAAO,QAAQ,MAAM;GAC7B,QAAQ,KAAK,KAAK;EACpB;EACA,OAAO,IAAI,IAAI,KAAK;CACtB;CAEA,MAAM,OAAO,KAAK,UAAU,OAAO,QAAQ;CAC3C,MAAM,UAAyB,CAAC;CAEhC,KAAK,MAAM,UAAU,SAAS,QAAQ,KAAK,KAAK,UAAU,QAAQ,QAAQ,CAAC;CAE3E,OAAO,cAAc,QAAQ,WAAW,KAAK,cAAc,QAAQ,KAAK,GAAG,EAAE;AAC/E;;;;;AAMA,SAAgB,MAAM,MAAyB;CAE7C,MAAM,WAAW,KAAK,MAAM,IAAI;CAEhC,IAAI,UAAU,YAAY,SACxB,MAAM,IAAI,MAAM,sDAAsD,QAAQ,QAAQ,KAAK,UAAU,UAAU,OAAO,EAAE,EAAE;CAE5H,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,QAAQ,SAAS,OAAO,GACpD,MAAM,IAAI,MAAM,6DAA6D;CAG/E,MAAM,UAAU,SAAS;CACzB,MAAM,QAAwB,CAAC,SAAS,OAAO,GAAG,OAAO;CACzD,OAAO,MAAM,QAAQ;EACnB,MAAM,QAAQ,MAAM,IAAI;EACxB,MAAM,MAAM,MAAM,KAAK;EACvB,KAAK,MAAM,OAAO,OAAO;GACvB,MAAM,QAAQ,MAAM;GACpB,IAAI,OAAO,QAAQ,UAAU;IAC3B,IAAI,MAAM,QAAQ,KAAK,GAAG;KACxB,MAAM,SAAS,MAAM;KACrB;IACF;IACA,IAAI,OAAO,UAAU,UAAU;KAC7B,MAAM,SAAS,QAAQ;KACvB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD,MAAM,oBAAoB;KAC5G,MAAM,SAAS;KACf;IACF;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,KAAK,KAAK;EACnE;CACF;CAEA,OAAO,SAAS;AAClB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
|
+
const require_constants = require("./constants-CquR083U.cjs");
|
|
3
|
+
// src/json/index.ts
|
|
4
|
+
var json_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
5
|
+
parse: () => parse,
|
|
6
|
+
stringify: () => stringify
|
|
7
|
+
});
|
|
8
|
+
const version = 1;
|
|
9
|
+
function isRef(value) {
|
|
10
|
+
const node = value;
|
|
11
|
+
return node?.kind === require_constants.nodeKinds.schema && node.type === require_constants.schemaTypes.ref;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Turns an `InputNode` into JSON text that `parse` reads back. Every schema a ref points at is written once,
|
|
15
|
+
* where a plain `JSON.stringify(input)` writes it again at every ref.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* await writeFile('input.json', ast.json.stringify(input))
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function stringify(input) {
|
|
23
|
+
const ids = /* @__PURE__ */ new Map();
|
|
24
|
+
const targets = [];
|
|
25
|
+
function replacer(key, value) {
|
|
26
|
+
if (key !== "schema" || !isRef(this)) return value;
|
|
27
|
+
if (typeof value === "number") return [value];
|
|
28
|
+
if (typeof value !== "object" || value === null) return value;
|
|
29
|
+
if (!ids.has(value)) {
|
|
30
|
+
ids.set(value, targets.length);
|
|
31
|
+
targets.push(value);
|
|
32
|
+
}
|
|
33
|
+
return ids.get(value);
|
|
34
|
+
}
|
|
35
|
+
const root = JSON.stringify(input, replacer);
|
|
36
|
+
const encoded = [];
|
|
37
|
+
for (const target of targets) encoded.push(JSON.stringify(target, replacer));
|
|
38
|
+
return `{"version":${version},"input":${root},"targets":[${encoded.join(",")}]}`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.
|
|
42
|
+
* Throws on another format version, or on a ref whose target is missing.
|
|
43
|
+
*/
|
|
44
|
+
function parse(text) {
|
|
45
|
+
const document = JSON.parse(text);
|
|
46
|
+
if (document?.version !== version) throw new Error(`Cannot read this AST JSON: expected format version ${version}, got ${JSON.stringify(document?.version)}.`);
|
|
47
|
+
if (!document.input || !Array.isArray(document.targets)) throw new Error("Cannot read this AST JSON: `input` or `targets` is missing.");
|
|
48
|
+
const targets = document.targets;
|
|
49
|
+
const stack = [document.input, ...targets];
|
|
50
|
+
while (stack.length) {
|
|
51
|
+
const value = stack.pop();
|
|
52
|
+
const ref = isRef(value);
|
|
53
|
+
for (const key in value) {
|
|
54
|
+
const child = value[key];
|
|
55
|
+
if (ref && key === "schema") {
|
|
56
|
+
if (Array.isArray(child)) {
|
|
57
|
+
value.schema = child[0];
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (typeof child === "number") {
|
|
61
|
+
const target = targets[child];
|
|
62
|
+
if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${child}, which is missing.`);
|
|
63
|
+
value.schema = target;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (typeof child === "object" && child !== null) stack.push(child);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return document.input;
|
|
71
|
+
}
|
|
72
|
+
Object.defineProperty(exports, "json_exports", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function() {
|
|
75
|
+
return json_exports;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "parse", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function() {
|
|
81
|
+
return parse;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "stringify", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function() {
|
|
87
|
+
return stringify;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=json-DURdtz9A.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-DURdtz9A.cjs","names":["nodeKinds","schemaTypes"],"sources":["../src/json/index.ts"],"sourcesContent":["import { nodeKinds, schemaTypes } from '../constants.ts'\nimport type { InputNode } from '../nodes/input.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\nconst version = 1\n\ntype JsonDocument = {\n version: number\n input: InputNode\n targets: Array<SchemaNode>\n}\n\nfunction isRef(value: unknown): value is { schema: unknown } {\n const node = value as { kind?: unknown; type?: unknown } | null\n return node?.kind === nodeKinds.schema && node.type === schemaTypes.ref\n}\n\n/**\n * Turns an `InputNode` into JSON text that `parse` reads back. Every schema a ref points at is written once,\n * where a plain `JSON.stringify(input)` writes it again at every ref.\n *\n * @example\n * ```ts\n * await writeFile('input.json', ast.json.stringify(input))\n * ```\n */\nexport function stringify(input: InputNode): string {\n const ids = new Map<unknown, number>()\n const targets: Array<unknown> = []\n\n function replacer(this: unknown, key: string, value: unknown): unknown {\n if (key !== 'schema' || !isRef(this)) return value\n // Spec data such as a `default` can look like a ref node. Its number is wrapped, so `parse` does not read it as a target.\n if (typeof value === 'number') return [value]\n if (typeof value !== 'object' || value === null) return value\n if (!ids.has(value)) {\n ids.set(value, targets.length)\n targets.push(value)\n }\n return ids.get(value)\n }\n\n const root = JSON.stringify(input, replacer)\n const encoded: Array<string> = []\n // A target can hold refs to targets not seen yet, so the list grows while this loop reads it.\n for (const target of targets) encoded.push(JSON.stringify(target, replacer))\n\n return `{\"version\":${version},\"input\":${root},\"targets\":[${encoded.join(',')}]}`\n}\n\n/**\n * Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.\n * Throws on another format version, or on a ref whose target is missing.\n */\nexport function parse(text: string): InputNode {\n // Plain `JSON.parse` and one loop over the tree: a reviver made this about 5 times slower on a large spec.\n const document = JSON.parse(text) as Partial<JsonDocument> | null\n\n if (document?.version !== version) {\n throw new Error(`Cannot read this AST JSON: expected format version ${version}, got ${JSON.stringify(document?.version)}.`)\n }\n if (!document.input || !Array.isArray(document.targets)) {\n throw new Error('Cannot read this AST JSON: `input` or `targets` is missing.')\n }\n\n const targets = document.targets\n const stack: Array<unknown> = [document.input, ...targets]\n while (stack.length) {\n const value = stack.pop() as Record<string, unknown>\n const ref = isRef(value)\n for (const key in value) {\n const child = value[key]\n if (ref && key === 'schema') {\n if (Array.isArray(child)) {\n value.schema = child[0]\n continue\n }\n if (typeof child === 'number') {\n const target = targets[child]\n if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${child}, which is missing.`)\n value.schema = target\n continue\n }\n }\n if (typeof child === 'object' && child !== null) stack.push(child)\n }\n }\n\n return document.input\n}\n"],"mappings":";;;;;;;AAIA,MAAM,UAAU;AAQhB,SAAS,MAAM,OAA8C;CAC3D,MAAM,OAAO;CACb,OAAO,MAAM,SAASA,kBAAAA,UAAU,UAAU,KAAK,SAASC,kBAAAA,YAAY;AACtE;;;;;;;;;;AAWA,SAAgB,UAAU,OAA0B;CAClD,MAAM,sBAAM,IAAI,IAAqB;CACrC,MAAM,UAA0B,CAAC;CAEjC,SAAS,SAAwB,KAAa,OAAyB;EACrE,IAAI,QAAQ,YAAY,CAAC,MAAM,IAAI,GAAG,OAAO;EAE7C,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC,KAAK;EAC5C,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;EACxD,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG;GACnB,IAAI,IAAI,OAAO,QAAQ,MAAM;GAC7B,QAAQ,KAAK,KAAK;EACpB;EACA,OAAO,IAAI,IAAI,KAAK;CACtB;CAEA,MAAM,OAAO,KAAK,UAAU,OAAO,QAAQ;CAC3C,MAAM,UAAyB,CAAC;CAEhC,KAAK,MAAM,UAAU,SAAS,QAAQ,KAAK,KAAK,UAAU,QAAQ,QAAQ,CAAC;CAE3E,OAAO,cAAc,QAAQ,WAAW,KAAK,cAAc,QAAQ,KAAK,GAAG,EAAE;AAC/E;;;;;AAMA,SAAgB,MAAM,MAAyB;CAE7C,MAAM,WAAW,KAAK,MAAM,IAAI;CAEhC,IAAI,UAAU,YAAY,SACxB,MAAM,IAAI,MAAM,sDAAsD,QAAQ,QAAQ,KAAK,UAAU,UAAU,OAAO,EAAE,EAAE;CAE5H,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,QAAQ,SAAS,OAAO,GACpD,MAAM,IAAI,MAAM,6DAA6D;CAG/E,MAAM,UAAU,SAAS;CACzB,MAAM,QAAwB,CAAC,SAAS,OAAO,GAAG,OAAO;CACzD,OAAO,MAAM,QAAQ;EACnB,MAAM,QAAQ,MAAM,IAAI;EACxB,MAAM,MAAM,MAAM,KAAK;EACvB,KAAK,MAAM,OAAO,OAAO;GACvB,MAAM,QAAQ,MAAM;GACpB,IAAI,OAAO,QAAQ,UAAU;IAC3B,IAAI,MAAM,QAAQ,KAAK,GAAG;KACxB,MAAM,SAAS,MAAM;KACrB;IACF;IACA,IAAI,OAAO,UAAU,UAAU;KAC7B,MAAM,SAAS,QAAQ;KACvB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD,MAAM,oBAAoB;KAC5G,MAAM,SAAS;KACf;IACF;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,KAAK,KAAK;EACnE;CACF;CAEA,OAAO,SAAS;AAClB"}
|
package/dist/json.cjs
ADDED
package/dist/json.d.cts
ADDED
package/dist/json.d.ts
ADDED
package/dist/json.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as parse, r as stringify } from "./json-DH7_lcWm.js";
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
|
|
2
|
+
import { a as visitorKeys, r as transform } from "./visitor-NoQSUQTu.js";
|
|
3
|
+
// src/defineMacro.ts
|
|
4
|
+
/**
|
|
5
|
+
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
6
|
+
* list keeps its authored order.
|
|
7
|
+
*/
|
|
8
|
+
function enforceWeight(enforce) {
|
|
9
|
+
if (enforce === "pre") return 0;
|
|
10
|
+
if (enforce === "post") return 2;
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Compares two `enforce` hints for `Array.prototype.sort`: `pre` first, unmarked next, `post`
|
|
15
|
+
* last. Equal hints compare as `0`, so a stable sort keeps authored order within a bucket.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* `plugins.sort((a, b) => compareMacroOrder(a.enforce, b.enforce))`
|
|
19
|
+
*/
|
|
20
|
+
function compareMacroOrder(a, b) {
|
|
21
|
+
return enforceWeight(a) - enforceWeight(b);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Types a macro for inference and a single construction site, mirroring `defineExtension`.
|
|
25
|
+
* Adds no runtime behavior.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const macroUntagged = defineMacro({
|
|
30
|
+
* name: 'untagged',
|
|
31
|
+
* operation(node) {
|
|
32
|
+
* return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }
|
|
33
|
+
* },
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function defineMacro(macro) {
|
|
38
|
+
return macro;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Runs every macro's callback for one node kind in order, chaining the result so each macro sees
|
|
42
|
+
* the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the
|
|
43
|
+
* original reference (structural sharing).
|
|
44
|
+
*/
|
|
45
|
+
function chain({ macros, key, node, context }) {
|
|
46
|
+
let current = node;
|
|
47
|
+
for (const macro of macros) {
|
|
48
|
+
const callback = macro[key];
|
|
49
|
+
if (!callback) continue;
|
|
50
|
+
if (macro.match && !macro.match(current)) continue;
|
|
51
|
+
const next = callback(current, context);
|
|
52
|
+
if (next != null) current = next;
|
|
53
|
+
}
|
|
54
|
+
return current === node ? void 0 : current;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Folds an ordered list of macros into a single {@link Visitor} for `transform`. Macros are
|
|
58
|
+
* stable-sorted by `enforce`, then applied sequentially per node so later macros see earlier output.
|
|
59
|
+
*/
|
|
60
|
+
function composeMacros(macros) {
|
|
61
|
+
const ordered = [...macros].sort((a, b) => compareMacroOrder(a.enforce, b.enforce));
|
|
62
|
+
const visitor = {};
|
|
63
|
+
for (const key of visitorKeys) {
|
|
64
|
+
if (!ordered.some((macro) => typeof macro[key] === "function")) continue;
|
|
65
|
+
const callback = (node, context) => chain({
|
|
66
|
+
macros: ordered,
|
|
67
|
+
key,
|
|
68
|
+
node,
|
|
69
|
+
context
|
|
70
|
+
});
|
|
71
|
+
visitor[key] = callback;
|
|
72
|
+
}
|
|
73
|
+
return visitor;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s
|
|
77
|
+
* structural sharing, so an empty or no-op macro list returns the same reference. Pass
|
|
78
|
+
* `depth: 'shallow'` to skip the children of every schema node; non-schema nodes, such as an operation's parameters and responses, are still rewritten.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const next = applyMacros(root, [macroIntegerToString])
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example Rewrite a schema without walking its children
|
|
86
|
+
* ```ts
|
|
87
|
+
* const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
function applyMacros(root, macros, options) {
|
|
91
|
+
if (macros.length === 0) return root;
|
|
92
|
+
return transform(root, {
|
|
93
|
+
...composeMacros(macros),
|
|
94
|
+
...options
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// src/macro/index.ts
|
|
98
|
+
var macro_exports = /* @__PURE__ */ __exportAll({
|
|
99
|
+
apply: () => applyMacros,
|
|
100
|
+
compareOrder: () => compareMacroOrder
|
|
101
|
+
});
|
|
102
|
+
export { defineMacro as i, applyMacros as n, compareMacroOrder as r, macro_exports as t };
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=macro-D0KfNtff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"macro-D0KfNtff.js","names":[],"sources":["../src/defineMacro.ts","../src/macro/index.ts"],"sourcesContent":["import type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext, VisitorDepth, VisitorKey } from './visitor.ts'\nimport { transform, visitorKeys } 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 * Compares two `enforce` hints for `Array.prototype.sort`: `pre` first, unmarked next, `post`\n * last. Equal hints compare as `0`, so a stable sort keeps authored order within a bucket.\n *\n * @example\n * `plugins.sort((a, b) => compareMacroOrder(a.enforce, b.enforce))`\n */\nexport function compareMacroOrder(a?: Enforce, b?: Enforce): number {\n return enforceWeight(a) - enforceWeight(b)\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 `match` predicate. Macros run on the shared AST, so the same macro works across every\n * adapter 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 `'dedupe-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 * Predicate checked against the current node before any callback runs. Returning `false`\n * skips the macro for that node.\n */\n match?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `defineExtension`.\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.match && !macro.match(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} for `transform`. Macros are\n * stable-sorted by `enforce`, then applied sequentially per node so later macros see earlier output.\n */\nfunction composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => compareMacroOrder(a.enforce, 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 skip the children of every schema node; non-schema nodes, such as an operation's parameters and responses, are still rewritten.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Rewrite a schema without walking its children\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","export { applyMacros as apply, compareMacroOrder as compareOrder } from '../defineMacro.ts'\n"],"mappings":";;;;;;;AAcA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;AASA,SAAgB,kBAAkB,GAAa,GAAqB;CAClE,OAAO,cAAc,CAAC,IAAI,cAAc,CAAC;AAC3C;;;;;;;;;;;;;;;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,SAAS,CAAC,MAAM,MAAM,OAAO,GAAG;EAE1C,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;AAMA,SAAS,cAAc,QAAuC;CAC5D,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,kBAAkB,EAAE,SAAS,EAAE,OAAO,CAAC;CAElF,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;EACrG,QAA8C,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"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
|
+
const require_visitor = require("./visitor-DTrzvA3R.cjs");
|
|
3
|
+
// src/defineMacro.ts
|
|
4
|
+
/**
|
|
5
|
+
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
6
|
+
* list keeps its authored order.
|
|
7
|
+
*/
|
|
8
|
+
function enforceWeight(enforce) {
|
|
9
|
+
if (enforce === "pre") return 0;
|
|
10
|
+
if (enforce === "post") return 2;
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Compares two `enforce` hints for `Array.prototype.sort`: `pre` first, unmarked next, `post`
|
|
15
|
+
* last. Equal hints compare as `0`, so a stable sort keeps authored order within a bucket.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* `plugins.sort((a, b) => compareMacroOrder(a.enforce, b.enforce))`
|
|
19
|
+
*/
|
|
20
|
+
function compareMacroOrder(a, b) {
|
|
21
|
+
return enforceWeight(a) - enforceWeight(b);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Types a macro for inference and a single construction site, mirroring `defineExtension`.
|
|
25
|
+
* Adds no runtime behavior.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const macroUntagged = defineMacro({
|
|
30
|
+
* name: 'untagged',
|
|
31
|
+
* operation(node) {
|
|
32
|
+
* return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }
|
|
33
|
+
* },
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function defineMacro(macro) {
|
|
38
|
+
return macro;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Runs every macro's callback for one node kind in order, chaining the result so each macro sees
|
|
42
|
+
* the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the
|
|
43
|
+
* original reference (structural sharing).
|
|
44
|
+
*/
|
|
45
|
+
function chain({ macros, key, node, context }) {
|
|
46
|
+
let current = node;
|
|
47
|
+
for (const macro of macros) {
|
|
48
|
+
const callback = macro[key];
|
|
49
|
+
if (!callback) continue;
|
|
50
|
+
if (macro.match && !macro.match(current)) continue;
|
|
51
|
+
const next = callback(current, context);
|
|
52
|
+
if (next != null) current = next;
|
|
53
|
+
}
|
|
54
|
+
return current === node ? void 0 : current;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Folds an ordered list of macros into a single {@link Visitor} for `transform`. Macros are
|
|
58
|
+
* stable-sorted by `enforce`, then applied sequentially per node so later macros see earlier output.
|
|
59
|
+
*/
|
|
60
|
+
function composeMacros(macros) {
|
|
61
|
+
const ordered = [...macros].sort((a, b) => compareMacroOrder(a.enforce, b.enforce));
|
|
62
|
+
const visitor = {};
|
|
63
|
+
for (const key of require_visitor.visitorKeys) {
|
|
64
|
+
if (!ordered.some((macro) => typeof macro[key] === "function")) continue;
|
|
65
|
+
const callback = (node, context) => chain({
|
|
66
|
+
macros: ordered,
|
|
67
|
+
key,
|
|
68
|
+
node,
|
|
69
|
+
context
|
|
70
|
+
});
|
|
71
|
+
visitor[key] = callback;
|
|
72
|
+
}
|
|
73
|
+
return visitor;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s
|
|
77
|
+
* structural sharing, so an empty or no-op macro list returns the same reference. Pass
|
|
78
|
+
* `depth: 'shallow'` to skip the children of every schema node; non-schema nodes, such as an operation's parameters and responses, are still rewritten.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const next = applyMacros(root, [macroIntegerToString])
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example Rewrite a schema without walking its children
|
|
86
|
+
* ```ts
|
|
87
|
+
* const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
function applyMacros(root, macros, options) {
|
|
91
|
+
if (macros.length === 0) return root;
|
|
92
|
+
return require_visitor.transform(root, {
|
|
93
|
+
...composeMacros(macros),
|
|
94
|
+
...options
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// src/macro/index.ts
|
|
98
|
+
var macro_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
99
|
+
apply: () => applyMacros,
|
|
100
|
+
compareOrder: () => compareMacroOrder
|
|
101
|
+
});
|
|
102
|
+
Object.defineProperty(exports, "applyMacros", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function() {
|
|
105
|
+
return applyMacros;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(exports, "compareMacroOrder", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function() {
|
|
111
|
+
return compareMacroOrder;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(exports, "defineMacro", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function() {
|
|
117
|
+
return defineMacro;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(exports, "macro_exports", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function() {
|
|
123
|
+
return macro_exports;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=macro-DrTBT7fh.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"macro-DrTBT7fh.cjs","names":["visitorKeys","transform"],"sources":["../src/defineMacro.ts","../src/macro/index.ts"],"sourcesContent":["import type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext, VisitorDepth, VisitorKey } from './visitor.ts'\nimport { transform, visitorKeys } 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 * Compares two `enforce` hints for `Array.prototype.sort`: `pre` first, unmarked next, `post`\n * last. Equal hints compare as `0`, so a stable sort keeps authored order within a bucket.\n *\n * @example\n * `plugins.sort((a, b) => compareMacroOrder(a.enforce, b.enforce))`\n */\nexport function compareMacroOrder(a?: Enforce, b?: Enforce): number {\n return enforceWeight(a) - enforceWeight(b)\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 `match` predicate. Macros run on the shared AST, so the same macro works across every\n * adapter 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 `'dedupe-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 * Predicate checked against the current node before any callback runs. Returning `false`\n * skips the macro for that node.\n */\n match?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `defineExtension`.\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.match && !macro.match(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} for `transform`. Macros are\n * stable-sorted by `enforce`, then applied sequentially per node so later macros see earlier output.\n */\nfunction composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => compareMacroOrder(a.enforce, 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 skip the children of every schema node; non-schema nodes, such as an operation's parameters and responses, are still rewritten.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Rewrite a schema without walking its children\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","export { applyMacros as apply, compareMacroOrder as compareOrder } from '../defineMacro.ts'\n"],"mappings":";;;;;;;AAcA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;AASA,SAAgB,kBAAkB,GAAa,GAAqB;CAClE,OAAO,cAAc,CAAC,IAAI,cAAc,CAAC;AAC3C;;;;;;;;;;;;;;;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,SAAS,CAAC,MAAM,MAAM,OAAO,GAAG;EAE1C,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;AAMA,SAAS,cAAc,QAAuC;CAC5D,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,kBAAkB,EAAE,SAAS,EAAE,OAAO,CAAC;CAElF,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;EACrG,QAA8C,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"}
|
package/dist/macro.cjs
ADDED
package/dist/macro.d.cts
ADDED
package/dist/macro.d.ts
ADDED
package/dist/macro.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as apply, r as compareOrder } from "./macro-D0KfNtff.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
|
|
2
|
+
// src/mediaType/index.ts
|
|
3
|
+
var mediaType_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
getBase: () => getBase,
|
|
5
|
+
isJson: () => isJson
|
|
6
|
+
});
|
|
7
|
+
const jsonMediaTypes = /* @__PURE__ */ new Set(["application/json", "text/json"]);
|
|
8
|
+
/** The media type without its parameters, in lower case: `Text/Plain; charset=utf-8` gives `text/plain`. */
|
|
9
|
+
function getBase(mediaType) {
|
|
10
|
+
return (typeof mediaType === "string" ? mediaType : mediaType.contentType).split(";")[0].trim().toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
/** Whether the media type is `application/json`, `text/json`, or has a `+json` suffix. */
|
|
13
|
+
function isJson(mediaType) {
|
|
14
|
+
const baseType = getBase(mediaType);
|
|
15
|
+
return jsonMediaTypes.has(baseType) || baseType.endsWith("+json");
|
|
16
|
+
}
|
|
17
|
+
export { isJson as n, mediaType_exports as r, getBase as t };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=mediaType-CRjggmoG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaType-CRjggmoG.js","names":[],"sources":["../src/mediaType/index.ts"],"sourcesContent":["type MediaTypeInput = string | { contentType: string }\n\nconst jsonMediaTypes = new Set(['application/json', 'text/json'])\n\n/** The media type without its parameters, in lower case: `Text/Plain; charset=utf-8` gives `text/plain`. */\nexport function getBase(mediaType: MediaTypeInput): string {\n const value = typeof mediaType === 'string' ? mediaType : mediaType.contentType\n return value.split(';')[0]!.trim().toLowerCase()\n}\n\n/** Whether the media type is `application/json`, `text/json`, or has a `+json` suffix. */\nexport function isJson(mediaType: MediaTypeInput): boolean {\n const baseType = getBase(mediaType)\n return jsonMediaTypes.has(baseType) || baseType.endsWith('+json')\n}\n"],"mappings":";;;;;;AAEA,MAAM,iCAAiB,IAAI,IAAI,CAAC,oBAAoB,WAAW,CAAC;;AAGhE,SAAgB,QAAQ,WAAmC;CAEzD,QADc,OAAO,cAAc,WAAW,YAAY,UAAU,YAAA,CACvD,MAAM,GAAG,CAAC,CAAC,EAAE,CAAE,KAAK,CAAC,CAAC,YAAY;AACjD;;AAGA,SAAgB,OAAO,WAAoC;CACzD,MAAM,WAAW,QAAQ,SAAS;CAClC,OAAO,eAAe,IAAI,QAAQ,KAAK,SAAS,SAAS,OAAO;AAClE"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/mediaType/index.ts
|
|
2
|
+
var mediaType_exports = /* @__PURE__ */ require("./rolldown-runtime-BV8xUvPy.cjs").__exportAll({
|
|
3
|
+
getBase: () => getBase,
|
|
4
|
+
isJson: () => isJson
|
|
5
|
+
});
|
|
6
|
+
const jsonMediaTypes = /* @__PURE__ */ new Set(["application/json", "text/json"]);
|
|
7
|
+
/** The media type without its parameters, in lower case: `Text/Plain; charset=utf-8` gives `text/plain`. */
|
|
8
|
+
function getBase(mediaType) {
|
|
9
|
+
return (typeof mediaType === "string" ? mediaType : mediaType.contentType).split(";")[0].trim().toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
/** Whether the media type is `application/json`, `text/json`, or has a `+json` suffix. */
|
|
12
|
+
function isJson(mediaType) {
|
|
13
|
+
const baseType = getBase(mediaType);
|
|
14
|
+
return jsonMediaTypes.has(baseType) || baseType.endsWith("+json");
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(exports, "getBase", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function() {
|
|
19
|
+
return getBase;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "isJson", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function() {
|
|
25
|
+
return isJson;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "mediaType_exports", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function() {
|
|
31
|
+
return mediaType_exports;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=mediaType-D8uIO8sG.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaType-D8uIO8sG.cjs","names":[],"sources":["../src/mediaType/index.ts"],"sourcesContent":["type MediaTypeInput = string | { contentType: string }\n\nconst jsonMediaTypes = new Set(['application/json', 'text/json'])\n\n/** The media type without its parameters, in lower case: `Text/Plain; charset=utf-8` gives `text/plain`. */\nexport function getBase(mediaType: MediaTypeInput): string {\n const value = typeof mediaType === 'string' ? mediaType : mediaType.contentType\n return value.split(';')[0]!.trim().toLowerCase()\n}\n\n/** Whether the media type is `application/json`, `text/json`, or has a `+json` suffix. */\nexport function isJson(mediaType: MediaTypeInput): boolean {\n const baseType = getBase(mediaType)\n return jsonMediaTypes.has(baseType) || baseType.endsWith('+json')\n}\n"],"mappings":";;;;;AAEA,MAAM,iCAAiB,IAAI,IAAI,CAAC,oBAAoB,WAAW,CAAC;;AAGhE,SAAgB,QAAQ,WAAmC;CAEzD,QADc,OAAO,cAAc,WAAW,YAAY,UAAU,YAAA,CACvD,MAAM,GAAG,CAAC,CAAC,EAAE,CAAE,KAAK,CAAC,CAAC,YAAY;AACjD;;AAGA,SAAgB,OAAO,WAAoC;CACzD,MAAM,WAAW,QAAQ,SAAS;CAClC,OAAO,eAAe,IAAI,QAAQ,KAAK,SAAS,SAAS,OAAO;AAClE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as getBase, n as isJson } from "./mediaType-CRjggmoG.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
|
+
const require_constants = require("./constants-CquR083U.cjs");
|
|
3
|
+
const require_nodeText = require("./nodeText-DRb_rVd1.cjs");
|
|
4
|
+
const require_visitor = require("./visitor-DTrzvA3R.cjs");
|
|
5
|
+
// src/node/index.ts
|
|
6
|
+
var node_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
7
|
+
collect: () => require_visitor.collect,
|
|
8
|
+
getText: () => require_nodeText.getNodeText,
|
|
9
|
+
kinds: () => require_constants.nodeKinds,
|
|
10
|
+
transform: () => require_visitor.transform
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "node_exports", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function() {
|
|
15
|
+
return node_exports;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=node-DjcETnc8.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-DjcETnc8.cjs","names":[],"sources":["../src/node/index.ts"],"sourcesContent":["export { nodeKinds as kinds } from '../constants.ts'\nexport { getNodeText as getText } from '../utils/nodeText.ts'\nexport { collect, transform } from '../visitor.ts'\n"],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
|
|
2
|
+
import { t as nodeKinds } from "./constants-Ckeonm-D.js";
|
|
3
|
+
import { n as getNodeText } from "./nodeText-DVVDZQjF.js";
|
|
4
|
+
import { r as transform, t as collect } from "./visitor-NoQSUQTu.js";
|
|
5
|
+
// src/node/index.ts
|
|
6
|
+
var node_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
collect: () => collect,
|
|
8
|
+
getText: () => getNodeText,
|
|
9
|
+
kinds: () => nodeKinds,
|
|
10
|
+
transform: () => transform
|
|
11
|
+
});
|
|
12
|
+
export { node_exports as t };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=node-Djh-mZB2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-Djh-mZB2.js","names":[],"sources":["../src/node/index.ts"],"sourcesContent":["export { nodeKinds as kinds } from '../constants.ts'\nexport { getNodeText as getText } from '../utils/nodeText.ts'\nexport { collect, transform } from '../visitor.ts'\n"],"mappings":""}
|
package/dist/node.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_constants = require("./constants-CquR083U.cjs");
|
|
3
|
+
const require_visitor = require("./visitor-DTrzvA3R.cjs");
|
|
4
|
+
const require_nodeText = require("./nodeText-DRb_rVd1.cjs");
|
|
5
|
+
require("./node-DjcETnc8.cjs");
|
|
6
|
+
exports.collect = require_visitor.collect;
|
|
7
|
+
exports.getText = require_nodeText.getNodeText;
|
|
8
|
+
exports.kinds = require_constants.nodeKinds;
|
|
9
|
+
exports.transform = require_visitor.transform;
|
package/dist/node.d.cts
ADDED
package/dist/node.d.ts
ADDED
package/dist/node.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { t as nodeKinds } from "./constants-Ckeonm-D.js";
|
|
2
|
+
import { r as transform, t as collect } from "./visitor-NoQSUQTu.js";
|
|
3
|
+
import { n as getNodeText } from "./nodeText-DVVDZQjF.js";
|
|
4
|
+
import "./node-Djh-mZB2.js";
|
|
5
|
+
export { collect, getNodeText as getText, nodeKinds as kinds, transform };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
|
+
const require_constants = require("./constants-CquR083U.cjs");
|
|
3
|
+
// src/utils/nodeText.ts
|
|
4
|
+
const CODE_NODE_TEXT_FIELDS = {
|
|
5
|
+
Text: ["value"],
|
|
6
|
+
Jsx: ["value"],
|
|
7
|
+
Function: [
|
|
8
|
+
"params",
|
|
9
|
+
"generics",
|
|
10
|
+
"returnType"
|
|
11
|
+
],
|
|
12
|
+
ArrowFunction: [
|
|
13
|
+
"params",
|
|
14
|
+
"generics",
|
|
15
|
+
"returnType"
|
|
16
|
+
],
|
|
17
|
+
Const: ["type"]
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Extracts all string content from a `CodeNode` tree recursively.
|
|
21
|
+
* Collects the text fields and nested node content, to build the source string for import filtering.
|
|
22
|
+
*/
|
|
23
|
+
function getNodeText(nodes) {
|
|
24
|
+
if (!nodes?.length) return "";
|
|
25
|
+
const collected = [];
|
|
26
|
+
for (const node of nodes) {
|
|
27
|
+
if (typeof node === "string") {
|
|
28
|
+
if (node) collected.push(node);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (node.kind === require_constants.nodeKinds.break) continue;
|
|
32
|
+
const parts = [];
|
|
33
|
+
const record = node;
|
|
34
|
+
for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {
|
|
35
|
+
const value = record[field];
|
|
36
|
+
if (Array.isArray(value)) parts.push(value.join(", "));
|
|
37
|
+
if (typeof value === "string" && value) parts.push(value);
|
|
38
|
+
}
|
|
39
|
+
const nested = "nodes" in node ? getNodeText(node.nodes) : "";
|
|
40
|
+
if (nested) parts.push(nested);
|
|
41
|
+
if (parts.length) collected.push(parts.join("\n"));
|
|
42
|
+
}
|
|
43
|
+
return collected.join("\n");
|
|
44
|
+
}
|
|
45
|
+
Object.defineProperty(exports, "CODE_NODE_TEXT_FIELDS", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function() {
|
|
48
|
+
return CODE_NODE_TEXT_FIELDS;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "getNodeText", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return getNodeText;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=nodeText-DRb_rVd1.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeText-DRb_rVd1.cjs","names":["nodeKinds"],"sources":["../src/utils/nodeText.ts"],"sourcesContent":["import { nodeKinds } from '../constants.ts'\nimport type { NodeKind } from '../nodes/base.ts'\nimport type { CodeNode } from '../nodes/code.ts'\n\nexport const CODE_NODE_TEXT_FIELDS: Partial<Record<NodeKind, ReadonlyArray<string>>> = {\n Text: ['value'],\n Jsx: ['value'],\n Function: ['params', 'generics', 'returnType'],\n ArrowFunction: ['params', 'generics', 'returnType'],\n Const: ['type'],\n}\n\n/**\n * Extracts all string content from a `CodeNode` tree recursively.\n * Collects the text fields and nested node content, to build the source string for import filtering.\n */\nexport function getNodeText(nodes: Array<CodeNode> | undefined): string {\n if (!nodes?.length) return ''\n\n // One flat pass: this runs over every code node during file assembly, so it skips `map().filter().join()` allocations.\n const collected: Array<string> = []\n\n for (const node of nodes) {\n // Backward-compat: compiled plugins may still pass bare strings at runtime\n if (typeof node === 'string') {\n if (node) collected.push(node as string)\n continue\n }\n if (node.kind === nodeKinds.break) continue\n\n const parts: Array<string> = []\n const record = node as unknown as Record<string, unknown>\n for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {\n const value = record[field]\n if (Array.isArray(value)) parts.push(value.join(', '))\n if (typeof value === 'string' && value) parts.push(value)\n }\n\n const nested = 'nodes' in node ? getNodeText(node.nodes) : ''\n if (nested) parts.push(nested)\n\n if (parts.length) collected.push(parts.join('\\n'))\n }\n\n return collected.join('\\n')\n}\n"],"mappings":";;;AAIA,MAAa,wBAA0E;CACrF,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,OAAO;CACb,UAAU;EAAC;EAAU;EAAY;CAAY;CAC7C,eAAe;EAAC;EAAU;EAAY;CAAY;CAClD,OAAO,CAAC,MAAM;AAChB;;;;;AAMA,SAAgB,YAAY,OAA4C;CACtE,IAAI,CAAC,OAAO,QAAQ,OAAO;CAG3B,MAAM,YAA2B,CAAC;CAElC,KAAK,MAAM,QAAQ,OAAO;EAExB,IAAI,OAAO,SAAS,UAAU;GAC5B,IAAI,MAAM,UAAU,KAAK,IAAc;GACvC;EACF;EACA,IAAI,KAAK,SAASA,kBAAAA,UAAU,OAAO;EAEnC,MAAM,QAAuB,CAAC;EAC9B,MAAM,SAAS;EACf,KAAK,MAAM,SAAS,sBAAsB,KAAK,SAAS,CAAC,GAAG;GAC1D,MAAM,QAAQ,OAAO;GACrB,IAAI,MAAM,QAAQ,KAAK,GAAG,MAAM,KAAK,MAAM,KAAK,IAAI,CAAC;GACrD,IAAI,OAAO,UAAU,YAAY,OAAO,MAAM,KAAK,KAAK;EAC1D;EAEA,MAAM,SAAS,WAAW,OAAO,YAAY,KAAK,KAAK,IAAI;EAC3D,IAAI,QAAQ,MAAM,KAAK,MAAM;EAE7B,IAAI,MAAM,QAAQ,UAAU,KAAK,MAAM,KAAK,IAAI,CAAC;CACnD;CAEA,OAAO,UAAU,KAAK,IAAI;AAC5B"}
|