@kubb/ast 5.28.6 → 5.29.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/README.md +19 -10
- package/dist/factory.cjs +6 -6
- package/dist/factory.d.cts +2 -2
- package/dist/factory.d.ts +2 -2
- package/dist/factory.js +2 -2
- package/dist/{combineFileMembers-B-mdjXrG.js → file-AcKQt60j.js} +137 -123
- package/dist/file-AcKQt60j.js.map +1 -0
- package/dist/{file-DJqd2j3y.d.cts → file-CLh8vdcR.d.cts} +20 -29
- package/dist/{file-lssk85C8.cjs → file-DVw2Htda.cjs} +13 -13
- package/dist/{file-lssk85C8.cjs.map → file-DVw2Htda.cjs.map} +1 -1
- package/dist/{combineFileMembers-DZCKxAN0.cjs → file-Db_PYobC.cjs} +136 -122
- package/dist/file-Db_PYobC.cjs.map +1 -0
- package/dist/{file-Dg70hXm3.d.ts → file-VRwu7Set.d.ts} +20 -29
- package/dist/{file-CO9KnOvT.js → file-pjdyWLJ0.js} +2 -2
- package/dist/{file-CO9KnOvT.js.map → file-pjdyWLJ0.js.map} +1 -1
- package/dist/file.cjs +6 -6
- package/dist/file.d.cts +1 -1
- package/dist/file.d.ts +1 -1
- package/dist/file.js +2 -2
- package/dist/{graph-DWlCmvm6.js → graph-Cu2-NiKi.js} +78 -15
- package/dist/graph-Cu2-NiKi.js.map +1 -0
- package/dist/{graph-D6Ffy9YD.cjs → graph-CymJtC1M.cjs} +78 -15
- package/dist/graph-CymJtC1M.cjs.map +1 -0
- package/dist/graph.cjs +1 -1
- package/dist/graph.d.cts +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/graph.js +1 -1
- package/dist/{index-BGhhO3z8.d.ts → index-B4DY8ewx.d.ts} +2 -2
- package/dist/{index-DjwCRndP.d.ts → index-BEvWuiSq.d.ts} +1 -1
- package/dist/{index-DphKh9u9.d.ts → index-BXHrCLGe.d.ts} +1 -1
- package/dist/{index-C4ZZnf_X.d.cts → index-BgmSdJKJ.d.cts} +2 -2
- package/dist/{index-CKd3ogUZ.d.cts → index-C0YF5kEb.d.cts} +2 -2
- package/dist/{index-Ck6nqnxZ.d.cts → index-CGvAotBX.d.cts} +2 -2
- package/dist/{index-DVX6E3vZ.d.ts → index-CHilsNw-.d.ts} +2 -2
- package/dist/{index-C0_Y9yA1.d.ts → index-CsySa8TT.d.ts} +2 -2
- package/dist/{index-BM3jzSca.d.ts → index-DA-Ztg07.d.ts} +1 -1
- package/dist/{index-CiVsdeOh.d.cts → index-DPGecgel.d.cts} +1 -1
- package/dist/{index-DdD4PIY8.d.cts → index-Dbtc7izw.d.cts} +1 -1
- package/dist/{index-DSW89P6k.d.cts → index-QDfAzfWY.d.cts} +1 -1
- package/dist/{index-B8ZxUpy4.d.ts → index-QZa0vqFW.d.ts} +1 -1
- package/dist/{index-7A3j-6Np.d.cts → index-oY3-BSwC.d.cts} +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +8 -8
- package/dist/isRecord-CwlfDtHp.cjs +16 -0
- package/dist/isRecord-CwlfDtHp.cjs.map +1 -0
- package/dist/isRecord-DaSp13D_.js +11 -0
- package/dist/isRecord-DaSp13D_.js.map +1 -0
- package/dist/{json-DeqPhPUQ.js → json-IKokiUCp.js} +34 -19
- package/dist/json-IKokiUCp.js.map +1 -0
- package/dist/{json-KV2VhBue.cjs → json-mEYdjumm.cjs} +34 -19
- package/dist/json-mEYdjumm.cjs.map +1 -0
- package/dist/json.cjs +1 -1
- package/dist/json.d.cts +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/json.js +1 -1
- package/dist/{macro-3uGSg-ic.js → macro-DhgoqDs6.js} +2 -2
- package/dist/{macro-3uGSg-ic.js.map → macro-DhgoqDs6.js.map} +1 -1
- package/dist/{macro-Ywn4-0s5.cjs → macro-h3bm9G48.cjs} +2 -2
- package/dist/{macro-Ywn4-0s5.cjs.map → macro-h3bm9G48.cjs.map} +1 -1
- package/dist/macro.cjs +1 -1
- package/dist/macro.d.cts +1 -1
- package/dist/macro.d.ts +1 -1
- package/dist/macro.js +1 -1
- package/dist/{node-BeccjrHH.cjs → node-Dhh4jTDv.cjs} +2 -2
- package/dist/{node-BeccjrHH.cjs.map → node-Dhh4jTDv.cjs.map} +1 -1
- package/dist/{node-Dm56432_.js → node-Dy0mq_hi.js} +2 -2
- package/dist/{node-Dm56432_.js.map → node-Dy0mq_hi.js.map} +1 -1
- package/dist/node.cjs +2 -2
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +2 -2
- package/dist/{nodes-KgbYiyJQ.js → nodes-B-MW8yk-.js} +2 -2
- package/dist/{nodes-KgbYiyJQ.js.map → nodes-B-MW8yk-.js.map} +1 -1
- package/dist/{nodes-BGxHocS_.cjs → nodes-BjVv21pb.cjs} +12 -12
- package/dist/{nodes-BGxHocS_.cjs.map → nodes-BjVv21pb.cjs.map} +1 -1
- package/dist/promise-DMQPWp6M.cjs.map +1 -1
- package/dist/promise-bi4pc8Xr.js.map +1 -1
- package/dist/{schema-XGRiAvok.cjs → schema-CMe0Dvgd.cjs} +2 -2
- package/dist/{schema-XGRiAvok.cjs.map → schema-CMe0Dvgd.cjs.map} +1 -1
- package/dist/{schema-B05JSQRq.js → schema-CVIk19Mh.js} +2 -2
- package/dist/{schema-B05JSQRq.js.map → schema-CVIk19Mh.js.map} +1 -1
- package/dist/schema.cjs +2 -2
- package/dist/schema.d.cts +2 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +2 -2
- package/dist/{visitor-xxcbpM5-.d.ts → visitor-BWHpwRgc.d.ts} +2 -2
- package/dist/{visitor-BIldddZd.d.cts → visitor-CPlsMCPZ.d.cts} +2 -2
- package/dist/{visitor-DA5yfOJz.js → visitor-CitcdWu0.js} +5 -10
- package/dist/visitor-CitcdWu0.js.map +1 -0
- package/dist/{visitor-DhuKS-7x.cjs → visitor-DT712cxr.cjs} +5 -10
- package/dist/visitor-DT712cxr.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/combineFileMembers-B-mdjXrG.js.map +0 -1
- package/dist/combineFileMembers-DZCKxAN0.cjs.map +0 -1
- package/dist/graph-D6Ffy9YD.cjs.map +0 -1
- package/dist/graph-DWlCmvm6.js.map +0 -1
- package/dist/json-DeqPhPUQ.js.map +0 -1
- package/dist/json-KV2VhBue.cjs.map +0 -1
- package/dist/visitor-DA5yfOJz.js.map +0 -1
- package/dist/visitor-DhuKS-7x.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as nodeKinds } from "./base-A-xF4pUL.js";
|
|
2
|
-
import { g as CodeNode } from "./file-
|
|
3
|
-
import { a as collect, s as transform } from "./visitor-
|
|
2
|
+
import { g as CodeNode } from "./file-VRwu7Set.js";
|
|
3
|
+
import { a as collect, s as transform } from "./visitor-BWHpwRgc.js";
|
|
4
4
|
/**
|
|
5
5
|
* Extracts all string content from a `CodeNode` tree recursively.
|
|
6
6
|
* Collects the text fields and nested node content, to build the source string for import filtering.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ImportNode, c as Space, n as ExportNode, o as ModuleName, r as FileNode, s as SourceNode } from "./file-
|
|
1
|
+
import { a as ImportNode, c as Space, n as ExportNode, o as ModuleName, r as FileNode, s as SourceNode } from "./file-VRwu7Set.js";
|
|
2
2
|
type InlineFilesResult = {
|
|
3
3
|
/**
|
|
4
4
|
* Files that imported an inline name, rewritten to hold its definition.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { K as SchemaNode, Y as StringSchemaNode, et as PropertyNode } from "./operation-B86IER5K.cjs";
|
|
2
2
|
import { a as schemaTypes } from "./base-CyJhBRMi.cjs";
|
|
3
3
|
import { n as narrowSchema } from "./guards-EpQMJGyF.cjs";
|
|
4
|
-
import { o as findSchema } from "./visitor-
|
|
4
|
+
import { o as findSchema } from "./visitor-CPlsMCPZ.cjs";
|
|
5
5
|
/**
|
|
6
6
|
* Generic JSON Schema optionality: a non-required field is optional, and a
|
|
7
7
|
* non-required nullable field is nullish.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, S as TypeNode, T as createConst, _ as ConstNode, a as ImportNode, b as JsxNode, c as Space, d as
|
|
1
|
+
import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, S as TypeNode, T as createConst, _ as ConstNode, a as ImportNode, b as JsxNode, c as Space, d as createSource, f as createExport, h as BreakNode, i as ImportInput, k as createType, l as UserFileNode, m as ArrowFunctionNode, n as ExportNode, o as ModuleName, p as createImport, r as FileNode, s as SourceNode, t as ExportInput, u as createFile, v as FunctionNode, w as createBreak, x as TextNode } from "./file-CLh8vdcR.cjs";
|
|
2
2
|
import { $ as createSchema, D as InputNode, K as SchemaNode, _ as createParameter, a as OperationsNode, d as createResponse, et as PropertyNode, f as RequestBodyNode, h as ParameterNode, i as OperationNode, j as createInput, l as ResponseNode, o as createOperation, p as createRequestBody, s as createOperations, tt as createProperty, v as ContentNode, x as createContent } from "./operation-B86IER5K.cjs";
|
|
3
3
|
declare namespace index_d_exports {
|
|
4
4
|
export { ExportInput, ImportInput, ModuleName, Node, Space, UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOperations, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
|
@@ -14,7 +14,7 @@ declare namespace index_d_exports {
|
|
|
14
14
|
declare function stringify(input: InputNode): string;
|
|
15
15
|
/**
|
|
16
16
|
* Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.
|
|
17
|
-
* Throws on another format version, or
|
|
17
|
+
* Throws on another format version, a malformed `input` or `targets`, or a ref whose target is missing.
|
|
18
18
|
*/
|
|
19
19
|
declare function parse(text: string): InputNode;
|
|
20
20
|
export { parse as n, stringify as r, index_d_exports as t };
|
|
@@ -14,7 +14,7 @@ declare namespace index_d_exports {
|
|
|
14
14
|
declare function stringify(input: InputNode): string;
|
|
15
15
|
/**
|
|
16
16
|
* Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.
|
|
17
|
-
* Throws on another format version, or
|
|
17
|
+
* Throws on another format version, a malformed `input` or `targets`, or a ref whose target is missing.
|
|
18
18
|
*/
|
|
19
19
|
declare function parse(text: string): InputNode;
|
|
20
20
|
export { parse as n, stringify as r, index_d_exports as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ImportNode, c as Space, n as ExportNode, o as ModuleName, r as FileNode, s as SourceNode } from "./file-
|
|
1
|
+
import { a as ImportNode, c as Space, n as ExportNode, o as ModuleName, r as FileNode, s as SourceNode } from "./file-CLh8vdcR.cjs";
|
|
2
2
|
type InlineFilesResult = {
|
|
3
3
|
/**
|
|
4
4
|
* Files that imported an inline name, rewritten to hold its definition.
|
package/dist/index.cjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
3
|
-
const require_graph = require("./graph-
|
|
3
|
+
const require_graph = require("./graph-CymJtC1M.cjs");
|
|
4
4
|
const require_constants = require("./constants-BCRkFAiy.cjs");
|
|
5
5
|
const require_ref = require("./ref-CGeCLkAk.cjs");
|
|
6
|
-
const require_visitor = require("./visitor-
|
|
7
|
-
const require_schema = require("./schema-
|
|
6
|
+
const require_visitor = require("./visitor-DT712cxr.cjs");
|
|
7
|
+
const require_schema = require("./schema-CMe0Dvgd.cjs");
|
|
8
8
|
const require_refs = require("./refs-CJZBa9hL.cjs");
|
|
9
9
|
const require_guards = require("./guards-4drgx10i.cjs");
|
|
10
|
-
const require_macro = require("./macro-
|
|
11
|
-
const require_node = require("./node-
|
|
10
|
+
const require_macro = require("./macro-h3bm9G48.cjs");
|
|
11
|
+
const require_node = require("./node-Dhh4jTDv.cjs");
|
|
12
12
|
const require_optionality = require("./optionality-C-qULYxo.cjs");
|
|
13
|
-
const require_file = require("./file-
|
|
14
|
-
const require_nodes = require("./nodes-
|
|
13
|
+
const require_file = require("./file-DVw2Htda.cjs");
|
|
14
|
+
const require_nodes = require("./nodes-BjVv21pb.cjs");
|
|
15
15
|
const require_nodeText = require("./nodeText-DH4dLGUb.cjs");
|
|
16
16
|
const require_http = require("./http-Dv8py6wh.cjs");
|
|
17
|
-
const require_json = require("./json-
|
|
17
|
+
const require_json = require("./json-mEYdjumm.cjs");
|
|
18
18
|
const require_mediaType = require("./mediaType-BbIfudh0.cjs");
|
|
19
19
|
// src/createPrinter.ts
|
|
20
20
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { o as InlineLanguage, s as inlineFiles$1, t as index_d_exports$2 } from "./index-
|
|
2
|
-
import { a as findCircularSchemas$1, i as collectUsedSchemaNames$1, n as collectImportedRefNames$1, r as collectSchemaRefs$1, t as index_d_exports$3 } from "./index-
|
|
1
|
+
import { o as InlineLanguage, s as inlineFiles$1, t as index_d_exports$2 } from "./index-oY3-BSwC.cjs";
|
|
2
|
+
import { a as findCircularSchemas$1, i as collectUsedSchemaNames$1, n as collectImportedRefNames$1, r as collectSchemaRefs$1, t as index_d_exports$3 } from "./index-BgmSdJKJ.cjs";
|
|
3
3
|
import { t as index_d_exports$4 } from "./index-DT-_5NUx.cjs";
|
|
4
4
|
import { a as mergeRefWithSchema$1, i as isBareRef$1, n as index_d_exports$9, o as resolveRef$1, t as getName } from "./index-BXv0B9Pd.cjs";
|
|
5
5
|
import { n as narrowSchema$1, t as isHttpOperationNode$1 } from "./guards-EpQMJGyF.cjs";
|
|
6
|
-
import { a as resolveSchemaProperties$1, d as applyOptionality, i as inferDiscriminatorPropertyName$1, r as getSchemaLiteralValues$1, t as index_d_exports$10 } from "./index-
|
|
7
|
-
import { S as TypeNode, _ as ConstNode, a as ImportNode, b as JsxNode, c as Space, g as CodeNode, h as BreakNode, i as ImportInput, l as UserFileNode, m as ArrowFunctionNode, n as ExportNode, o as ModuleName, r as FileNode, s as SourceNode, t as ExportInput, v as FunctionNode, x as TextNode, y as JSDocNode } from "./file-
|
|
6
|
+
import { a as resolveSchemaProperties$1, d as applyOptionality, i as inferDiscriminatorPropertyName$1, r as getSchemaLiteralValues$1, t as index_d_exports$10 } from "./index-DPGecgel.cjs";
|
|
7
|
+
import { S as TypeNode, _ as ConstNode, a as ImportNode, b as JsxNode, c as Space, g as CodeNode, h as BreakNode, i as ImportInput, l as UserFileNode, m as ArrowFunctionNode, n as ExportNode, o as ModuleName, r as FileNode, s as SourceNode, t as ExportInput, v as FunctionNode, x as TextNode, y as JSDocNode } from "./file-CLh8vdcR.cjs";
|
|
8
8
|
import { A as OAuthFlow, B as NumberSchemaNode, C as AuthRequirement, D as InputNode, E as InputMeta, F as DateSchemaNode, G as ScalarSchemaType, H as PrimitiveSchemaType, I as DatetimeSchemaNode, J as SchemaType, K as SchemaNode, L as EnumSchemaNode, M as ArraySchemaNode, N as BlobSchemaNode, O as InputServer, P as CreateSchemaInput, Q as UrlSchemaNode, R as IntersectionSchemaNode, S as AuthCredential, T as ExternalDocs, U as RefSchemaNode, V as ObjectSchemaNode, W as ScalarSchemaNode, X as TimeSchemaNode, Y as StringSchemaNode, Z as UnionSchemaNode, a as OperationsNode, b as ExampleNode, c as ResponseLink, et as PropertyNode, f as RequestBodyNode, g as ParameterStyle, h as ParameterNode, i as OperationNode, k as InputTag, l as ResponseNode, m as ParameterLocation, n as HttpMethod, q as SchemaNodeByType, r as HttpOperationNode, t as GenericOperationNode, u as StatusCode, v as ContentNode, w as AuthScheme, y as EncodingNode, z as NotSchemaNode } from "./operation-B86IER5K.cjs";
|
|
9
|
-
import { a as compareMacroOrder, i as applyMacros$1, n as Enforce, o as defineMacro$1, r as Macro, t as index_d_exports$6 } from "./index-
|
|
10
|
-
import { n as getNodeText, t as index_d_exports$8 } from "./index-
|
|
11
|
-
import { n as index_d_exports$1, t as Node } from "./index-
|
|
12
|
-
import { t as index_d_exports$5 } from "./index-
|
|
9
|
+
import { a as compareMacroOrder, i as applyMacros$1, n as Enforce, o as defineMacro$1, r as Macro, t as index_d_exports$6 } from "./index-C0YF5kEb.cjs";
|
|
10
|
+
import { n as getNodeText, t as index_d_exports$8 } from "./index-CGvAotBX.cjs";
|
|
11
|
+
import { n as index_d_exports$1, t as Node } from "./index-Dbtc7izw.cjs";
|
|
12
|
+
import { t as index_d_exports$5 } from "./index-QDfAzfWY.cjs";
|
|
13
13
|
import { r as index_d_exports$7 } from "./index-OfWkiJ5O.cjs";
|
|
14
14
|
import { n as DistributiveOmit, r as NodeKind } from "./base-CyJhBRMi.cjs";
|
|
15
|
-
import { a as collect$1, n as VisitorContext, o as findSchema$1, s as transform$1, t as Visitor } from "./visitor-
|
|
15
|
+
import { a as collect$1, n as VisitorContext, o as findSchema$1, s as transform$1, t as Visitor } from "./visitor-CPlsMCPZ.cjs";
|
|
16
16
|
/**
|
|
17
17
|
* Runtime context passed to printer handlers, both as `this` and as the second argument.
|
|
18
18
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { o as InlineLanguage, s as inlineFiles$1, t as index_d_exports$2 } from "./index-
|
|
2
|
-
import { a as findCircularSchemas$1, i as collectUsedSchemaNames$1, n as collectImportedRefNames$1, r as collectSchemaRefs$1, t as index_d_exports$3 } from "./index-
|
|
1
|
+
import { o as InlineLanguage, s as inlineFiles$1, t as index_d_exports$2 } from "./index-DA-Ztg07.js";
|
|
2
|
+
import { a as findCircularSchemas$1, i as collectUsedSchemaNames$1, n as collectImportedRefNames$1, r as collectSchemaRefs$1, t as index_d_exports$3 } from "./index-B4DY8ewx.js";
|
|
3
3
|
import { t as index_d_exports$4 } from "./index-kxuajWM1.js";
|
|
4
4
|
import { a as mergeRefWithSchema$1, i as isBareRef$1, n as index_d_exports$9, o as resolveRef$1, t as getName } from "./index-CuQPyRve.js";
|
|
5
5
|
import { n as narrowSchema$1, t as isHttpOperationNode$1 } from "./guards-CTqHwyNs.js";
|
|
6
|
-
import { a as resolveSchemaProperties$1, d as applyOptionality, i as inferDiscriminatorPropertyName$1, r as getSchemaLiteralValues$1, t as index_d_exports$10 } from "./index-
|
|
7
|
-
import { S as TypeNode, _ as ConstNode, a as ImportNode, b as JsxNode, c as Space, g as CodeNode, h as BreakNode, i as ImportInput, l as UserFileNode, m as ArrowFunctionNode, n as ExportNode, o as ModuleName, r as FileNode, s as SourceNode, t as ExportInput, v as FunctionNode, x as TextNode, y as JSDocNode } from "./file-
|
|
6
|
+
import { a as resolveSchemaProperties$1, d as applyOptionality, i as inferDiscriminatorPropertyName$1, r as getSchemaLiteralValues$1, t as index_d_exports$10 } from "./index-BXHrCLGe.js";
|
|
7
|
+
import { S as TypeNode, _ as ConstNode, a as ImportNode, b as JsxNode, c as Space, g as CodeNode, h as BreakNode, i as ImportInput, l as UserFileNode, m as ArrowFunctionNode, n as ExportNode, o as ModuleName, r as FileNode, s as SourceNode, t as ExportInput, v as FunctionNode, x as TextNode, y as JSDocNode } from "./file-VRwu7Set.js";
|
|
8
8
|
import { A as OAuthFlow, B as NumberSchemaNode, C as AuthRequirement, D as InputNode, E as InputMeta, F as DateSchemaNode, G as ScalarSchemaType, H as PrimitiveSchemaType, I as DatetimeSchemaNode, J as SchemaType, K as SchemaNode, L as EnumSchemaNode, M as ArraySchemaNode, N as BlobSchemaNode, O as InputServer, P as CreateSchemaInput, Q as UrlSchemaNode, R as IntersectionSchemaNode, S as AuthCredential, T as ExternalDocs, U as RefSchemaNode, V as ObjectSchemaNode, W as ScalarSchemaNode, X as TimeSchemaNode, Y as StringSchemaNode, Z as UnionSchemaNode, a as OperationsNode, b as ExampleNode, c as ResponseLink, et as PropertyNode, f as RequestBodyNode, g as ParameterStyle, h as ParameterNode, i as OperationNode, k as InputTag, l as ResponseNode, m as ParameterLocation, n as HttpMethod, q as SchemaNodeByType, r as HttpOperationNode, t as GenericOperationNode, u as StatusCode, v as ContentNode, w as AuthScheme, y as EncodingNode, z as NotSchemaNode } from "./operation-DJ7F0cFp.js";
|
|
9
|
-
import { a as compareMacroOrder, i as applyMacros$1, n as Enforce, o as defineMacro$1, r as Macro, t as index_d_exports$6 } from "./index-
|
|
10
|
-
import { n as getNodeText, t as index_d_exports$8 } from "./index-
|
|
11
|
-
import { n as index_d_exports$1, t as Node } from "./index-
|
|
12
|
-
import { t as index_d_exports$5 } from "./index-
|
|
9
|
+
import { a as compareMacroOrder, i as applyMacros$1, n as Enforce, o as defineMacro$1, r as Macro, t as index_d_exports$6 } from "./index-CHilsNw-.js";
|
|
10
|
+
import { n as getNodeText, t as index_d_exports$8 } from "./index-CsySa8TT.js";
|
|
11
|
+
import { n as index_d_exports$1, t as Node } from "./index-BEvWuiSq.js";
|
|
12
|
+
import { t as index_d_exports$5 } from "./index-QZa0vqFW.js";
|
|
13
13
|
import { r as index_d_exports$7 } from "./index-D3yqgtiN.js";
|
|
14
14
|
import { n as DistributiveOmit, r as NodeKind } from "./base-A-xF4pUL.js";
|
|
15
|
-
import { a as collect$1, n as VisitorContext, o as findSchema$1, s as transform$1, t as Visitor } from "./visitor-
|
|
15
|
+
import { a as collect$1, n as VisitorContext, o as findSchema$1, s as transform$1, t as Visitor } from "./visitor-BWHpwRgc.js";
|
|
16
16
|
/**
|
|
17
17
|
* Runtime context passed to printer handlers, both as `this` and as the second argument.
|
|
18
18
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { n as __name, t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
|
|
2
|
-
import { a as findCircularSchemas$1, i as collectUsedSchemaNames$1, n as collectImportedRefNames$1, r as collectSchemaRefs$1, t as graph_exports } from "./graph-
|
|
2
|
+
import { a as findCircularSchemas$1, i as collectUsedSchemaNames$1, n as collectImportedRefNames$1, r as collectSchemaRefs$1, t as graph_exports } from "./graph-Cu2-NiKi.js";
|
|
3
3
|
import { n as schemaTypes$1, t as nodeKinds$1 } from "./constants-UorsTFsa.js";
|
|
4
4
|
import { r as ref_exports, t as getName } from "./ref-BU7sfEFr.js";
|
|
5
|
-
import { n as findSchema$1, r as transform$1, t as collect$1 } from "./visitor-
|
|
6
|
-
import { a as resolveSchemaProperties$1, i as inferDiscriminatorPropertyName$1, n as schema_exports, r as getSchemaLiteralValues$1 } from "./schema-
|
|
5
|
+
import { n as findSchema$1, r as transform$1, t as collect$1 } from "./visitor-CitcdWu0.js";
|
|
6
|
+
import { a as resolveSchemaProperties$1, i as inferDiscriminatorPropertyName$1, n as schema_exports, r as getSchemaLiteralValues$1 } from "./schema-CVIk19Mh.js";
|
|
7
7
|
import { i as resolveRef$1, n as mergeRefWithSchema$1, t as isBareRef$1 } from "./refs-C0hb_qu-.js";
|
|
8
8
|
import { n as narrowSchema$1, t as isHttpOperationNode$1 } from "./guards-DKw4uwc5.js";
|
|
9
|
-
import { i as defineMacro$1, n as applyMacros$1, r as compareMacroOrder, t as macro_exports } from "./macro-
|
|
10
|
-
import { t as node_exports } from "./node-
|
|
9
|
+
import { i as defineMacro$1, n as applyMacros$1, r as compareMacroOrder, t as macro_exports } from "./macro-DhgoqDs6.js";
|
|
10
|
+
import { t as node_exports } from "./node-Dy0mq_hi.js";
|
|
11
11
|
import { t as applyOptionality } from "./optionality-FkRredTC.js";
|
|
12
|
-
import { n as inlineFiles$1, t as file_exports } from "./file-
|
|
13
|
-
import { t as nodes_exports } from "./nodes-
|
|
12
|
+
import { n as inlineFiles$1, t as file_exports } from "./file-pjdyWLJ0.js";
|
|
13
|
+
import { t as nodes_exports } from "./nodes-B-MW8yk-.js";
|
|
14
14
|
import { n as getNodeText } from "./nodeText-DFak5VpX.js";
|
|
15
15
|
import { t as http_exports } from "./http-CAWf6TAJ.js";
|
|
16
|
-
import { t as json_exports } from "./json-
|
|
16
|
+
import { t as json_exports } from "./json-IKokiUCp.js";
|
|
17
17
|
import { r as mediaType_exports } from "./mediaType-DXQCNYdM.js";
|
|
18
18
|
// src/createPrinter.ts
|
|
19
19
|
/**
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
|
+
// src/utils/isRecord.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` for an object that is not an array.
|
|
5
|
+
*/
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(exports, "isRecord", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return isRecord;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=isRecord-CwlfDtHp.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isRecord-CwlfDtHp.cjs","names":[],"sources":["../src/utils/isRecord.ts"],"sourcesContent":["/**\n * Returns `true` for an object that is not an array.\n */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n"],"mappings":";;;;;AAGA,SAAgB,SAAS,OAAkD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "./rolldown-runtime-BYyVTPww.js";
|
|
2
|
+
// src/utils/isRecord.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` for an object that is not an array.
|
|
5
|
+
*/
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
export { isRecord as t };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=isRecord-DaSp13D_.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isRecord-DaSp13D_.js","names":[],"sources":["../src/utils/isRecord.ts"],"sourcesContent":["/**\n * Returns `true` for an object that is not an array.\n */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n"],"mappings":";;;;;AAGA,SAAgB,SAAS,OAAkD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
|
|
2
2
|
import { n as schemaTypes, t as nodeKinds } from "./constants-UorsTFsa.js";
|
|
3
|
+
import { t as isRecord } from "./isRecord-DaSp13D_.js";
|
|
3
4
|
// src/json/index.ts
|
|
4
5
|
var json_exports = /* @__PURE__ */ __exportAll({
|
|
5
6
|
parse: () => parse,
|
|
6
7
|
stringify: () => stringify
|
|
7
8
|
});
|
|
8
9
|
const version = 1;
|
|
10
|
+
function isInputNode(value) {
|
|
11
|
+
return isRecord(value) && value.kind === nodeKinds.input && Array.isArray(value.schemas) && Array.isArray(value.operations);
|
|
12
|
+
}
|
|
9
13
|
function isRef(value) {
|
|
10
14
|
const node = value;
|
|
11
15
|
return node?.kind === nodeKinds.schema && node.type === schemaTypes.ref;
|
|
@@ -37,38 +41,49 @@ function stringify(input) {
|
|
|
37
41
|
for (const target of targets) encoded.push(JSON.stringify(target, replacer));
|
|
38
42
|
return `{"version":${version},"input":${root},"targets":[${encoded.join(",")}]}`;
|
|
39
43
|
}
|
|
44
|
+
function readDocument(parsed) {
|
|
45
|
+
const document = isRecord(parsed) ? parsed : {};
|
|
46
|
+
if (document.version !== version) throw new Error(`Cannot read this AST JSON: expected format version ${version}, got ${JSON.stringify(document.version)}.`);
|
|
47
|
+
const { input, targets } = document;
|
|
48
|
+
if (!input || !Array.isArray(targets)) throw new Error("Cannot read this AST JSON: `input` or `targets` is missing.");
|
|
49
|
+
if (!isInputNode(input)) throw new Error("Cannot read this AST JSON: `input` is not an Input node with `schemas` and `operations` arrays.");
|
|
50
|
+
const badTarget = targets.findIndex((target) => typeof target !== "object" || target === null);
|
|
51
|
+
if (badTarget !== -1) throw new Error(`Cannot read this AST JSON: target ${badTarget} is not an object.`);
|
|
52
|
+
return {
|
|
53
|
+
input,
|
|
54
|
+
targets
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function refSchema({ stored, targets }) {
|
|
58
|
+
if (Array.isArray(stored)) return stored[0];
|
|
59
|
+
const target = targets[stored];
|
|
60
|
+
if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${stored}, which is missing.`);
|
|
61
|
+
return target;
|
|
62
|
+
}
|
|
40
63
|
/**
|
|
41
64
|
* Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.
|
|
42
|
-
* Throws on another format version, or
|
|
65
|
+
* Throws on another format version, a malformed `input` or `targets`, or a ref whose target is missing.
|
|
43
66
|
*/
|
|
44
67
|
function parse(text) {
|
|
45
|
-
const
|
|
46
|
-
|
|
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];
|
|
68
|
+
const { input, targets } = readDocument(JSON.parse(text));
|
|
69
|
+
const stack = [input, ...targets];
|
|
50
70
|
while (stack.length) {
|
|
51
71
|
const value = stack.pop();
|
|
52
72
|
const ref = isRef(value);
|
|
53
73
|
for (const key in value) {
|
|
54
74
|
const child = value[key];
|
|
55
|
-
if (ref && key === "schema") {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
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
|
-
}
|
|
75
|
+
if (ref && key === "schema" && (Array.isArray(child) || typeof child === "number")) {
|
|
76
|
+
value.schema = refSchema({
|
|
77
|
+
stored: child,
|
|
78
|
+
targets
|
|
79
|
+
});
|
|
80
|
+
continue;
|
|
66
81
|
}
|
|
67
82
|
if (typeof child === "object" && child !== null) stack.push(child);
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
|
-
return
|
|
85
|
+
return input;
|
|
71
86
|
}
|
|
72
87
|
export { parse as n, stringify as r, json_exports as t };
|
|
73
88
|
|
|
74
|
-
//# sourceMappingURL=json-
|
|
89
|
+
//# sourceMappingURL=json-IKokiUCp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-IKokiUCp.js","names":[],"sources":["../src/json/index.ts"],"sourcesContent":["import { nodeKinds, schemaTypes } from '../constants.ts'\nimport type { InputNode } from '../nodes/input.ts'\nimport { isRecord } from '../utils/isRecord.ts'\n\nconst version = 1\n\nfunction isInputNode(value: unknown): value is InputNode {\n return isRecord(value) && value.kind === nodeKinds.input && Array.isArray(value.schemas) && Array.isArray(value.operations)\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\nfunction readDocument(parsed: unknown): { input: InputNode; targets: Array<unknown> } {\n const document = isRecord(parsed) ? parsed : {}\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 const { input, targets } = document\n if (!input || !Array.isArray(targets)) {\n throw new Error('Cannot read this AST JSON: `input` or `targets` is missing.')\n }\n if (!isInputNode(input)) {\n throw new Error('Cannot read this AST JSON: `input` is not an Input node with `schemas` and `operations` arrays.')\n }\n // A target is usually a Schema node, but spec data shaped like a ref, such as an example, writes a plain object.\n const badTarget = targets.findIndex((target) => typeof target !== 'object' || target === null)\n if (badTarget !== -1) {\n throw new Error(`Cannot read this AST JSON: target ${badTarget} is not an object.`)\n }\n return { input, targets }\n}\n\n// A wrapped value is spec data that only looks like a ref. A bare number is an index into `targets`.\nfunction refSchema({ stored, targets }: { stored: Array<unknown> | number; targets: Array<unknown> }): unknown {\n if (Array.isArray(stored)) return stored[0]\n const target = targets[stored]\n if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${stored}, which is missing.`)\n return target\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, a malformed `input` or `targets`, or 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 { input, targets } = readDocument(JSON.parse(text))\n\n const stack: Array<unknown> = [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' && (Array.isArray(child) || typeof child === 'number')) {\n value.schema = refSchema({ stored: child, targets })\n continue\n }\n if (typeof child === 'object' && child !== null) stack.push(child)\n }\n }\n\n return input\n}\n"],"mappings":";;;;;;;;AAIA,MAAM,UAAU;AAEhB,SAAS,YAAY,OAAoC;CACvD,OAAO,SAAS,KAAK,KAAK,MAAM,SAAS,UAAU,SAAS,MAAM,QAAQ,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM,UAAU;AAC5H;AAEA,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;AAEA,SAAS,aAAa,QAAgE;CACpF,MAAM,WAAW,SAAS,MAAM,IAAI,SAAS,CAAC;CAC9C,IAAI,SAAS,YAAY,SACvB,MAAM,IAAI,MAAM,sDAAsD,QAAQ,QAAQ,KAAK,UAAU,SAAS,OAAO,EAAE,EAAE;CAE3H,MAAM,EAAE,OAAO,YAAY;CAC3B,IAAI,CAAC,SAAS,CAAC,MAAM,QAAQ,OAAO,GAClC,MAAM,IAAI,MAAM,6DAA6D;CAE/E,IAAI,CAAC,YAAY,KAAK,GACpB,MAAM,IAAI,MAAM,iGAAiG;CAGnH,MAAM,YAAY,QAAQ,WAAW,WAAW,OAAO,WAAW,YAAY,WAAW,IAAI;CAC7F,IAAI,cAAc,IAChB,MAAM,IAAI,MAAM,qCAAqC,UAAU,mBAAmB;CAEpF,OAAO;EAAE;EAAO;CAAQ;AAC1B;AAGA,SAAS,UAAU,EAAE,QAAQ,WAAkF;CAC7G,IAAI,MAAM,QAAQ,MAAM,GAAG,OAAO,OAAO;CACzC,MAAM,SAAS,QAAQ;CACvB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD,OAAO,oBAAoB;CAC7G,OAAO;AACT;;;;;AAMA,SAAgB,MAAM,MAAyB;CAE7C,MAAM,EAAE,OAAO,YAAY,aAAa,KAAK,MAAM,IAAI,CAAC;CAExD,MAAM,QAAwB,CAAC,OAAO,GAAG,OAAO;CAChD,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,aAAa,MAAM,QAAQ,KAAK,KAAK,OAAO,UAAU,WAAW;IAClF,MAAM,SAAS,UAAU;KAAE,QAAQ;KAAO;IAAQ,CAAC;IACnD;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,KAAK,KAAK;EACnE;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
2
|
const require_constants = require("./constants-BCRkFAiy.cjs");
|
|
3
|
+
const require_isRecord = require("./isRecord-CwlfDtHp.cjs");
|
|
3
4
|
// src/json/index.ts
|
|
4
5
|
var json_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
5
6
|
parse: () => parse,
|
|
6
7
|
stringify: () => stringify
|
|
7
8
|
});
|
|
8
9
|
const version = 1;
|
|
10
|
+
function isInputNode(value) {
|
|
11
|
+
return require_isRecord.isRecord(value) && value.kind === require_constants.nodeKinds.input && Array.isArray(value.schemas) && Array.isArray(value.operations);
|
|
12
|
+
}
|
|
9
13
|
function isRef(value) {
|
|
10
14
|
const node = value;
|
|
11
15
|
return node?.kind === require_constants.nodeKinds.schema && node.type === require_constants.schemaTypes.ref;
|
|
@@ -37,37 +41,48 @@ function stringify(input) {
|
|
|
37
41
|
for (const target of targets) encoded.push(JSON.stringify(target, replacer));
|
|
38
42
|
return `{"version":${version},"input":${root},"targets":[${encoded.join(",")}]}`;
|
|
39
43
|
}
|
|
44
|
+
function readDocument(parsed) {
|
|
45
|
+
const document = require_isRecord.isRecord(parsed) ? parsed : {};
|
|
46
|
+
if (document.version !== version) throw new Error(`Cannot read this AST JSON: expected format version ${version}, got ${JSON.stringify(document.version)}.`);
|
|
47
|
+
const { input, targets } = document;
|
|
48
|
+
if (!input || !Array.isArray(targets)) throw new Error("Cannot read this AST JSON: `input` or `targets` is missing.");
|
|
49
|
+
if (!isInputNode(input)) throw new Error("Cannot read this AST JSON: `input` is not an Input node with `schemas` and `operations` arrays.");
|
|
50
|
+
const badTarget = targets.findIndex((target) => typeof target !== "object" || target === null);
|
|
51
|
+
if (badTarget !== -1) throw new Error(`Cannot read this AST JSON: target ${badTarget} is not an object.`);
|
|
52
|
+
return {
|
|
53
|
+
input,
|
|
54
|
+
targets
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function refSchema({ stored, targets }) {
|
|
58
|
+
if (Array.isArray(stored)) return stored[0];
|
|
59
|
+
const target = targets[stored];
|
|
60
|
+
if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${stored}, which is missing.`);
|
|
61
|
+
return target;
|
|
62
|
+
}
|
|
40
63
|
/**
|
|
41
64
|
* Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.
|
|
42
|
-
* Throws on another format version, or
|
|
65
|
+
* Throws on another format version, a malformed `input` or `targets`, or a ref whose target is missing.
|
|
43
66
|
*/
|
|
44
67
|
function parse(text) {
|
|
45
|
-
const
|
|
46
|
-
|
|
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];
|
|
68
|
+
const { input, targets } = readDocument(JSON.parse(text));
|
|
69
|
+
const stack = [input, ...targets];
|
|
50
70
|
while (stack.length) {
|
|
51
71
|
const value = stack.pop();
|
|
52
72
|
const ref = isRef(value);
|
|
53
73
|
for (const key in value) {
|
|
54
74
|
const child = value[key];
|
|
55
|
-
if (ref && key === "schema") {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
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
|
-
}
|
|
75
|
+
if (ref && key === "schema" && (Array.isArray(child) || typeof child === "number")) {
|
|
76
|
+
value.schema = refSchema({
|
|
77
|
+
stored: child,
|
|
78
|
+
targets
|
|
79
|
+
});
|
|
80
|
+
continue;
|
|
66
81
|
}
|
|
67
82
|
if (typeof child === "object" && child !== null) stack.push(child);
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
|
-
return
|
|
85
|
+
return input;
|
|
71
86
|
}
|
|
72
87
|
Object.defineProperty(exports, "json_exports", {
|
|
73
88
|
enumerable: true,
|
|
@@ -88,4 +103,4 @@ Object.defineProperty(exports, "stringify", {
|
|
|
88
103
|
}
|
|
89
104
|
});
|
|
90
105
|
|
|
91
|
-
//# sourceMappingURL=json-
|
|
106
|
+
//# sourceMappingURL=json-mEYdjumm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-mEYdjumm.cjs","names":["isRecord","nodeKinds","schemaTypes"],"sources":["../src/json/index.ts"],"sourcesContent":["import { nodeKinds, schemaTypes } from '../constants.ts'\nimport type { InputNode } from '../nodes/input.ts'\nimport { isRecord } from '../utils/isRecord.ts'\n\nconst version = 1\n\nfunction isInputNode(value: unknown): value is InputNode {\n return isRecord(value) && value.kind === nodeKinds.input && Array.isArray(value.schemas) && Array.isArray(value.operations)\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\nfunction readDocument(parsed: unknown): { input: InputNode; targets: Array<unknown> } {\n const document = isRecord(parsed) ? parsed : {}\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 const { input, targets } = document\n if (!input || !Array.isArray(targets)) {\n throw new Error('Cannot read this AST JSON: `input` or `targets` is missing.')\n }\n if (!isInputNode(input)) {\n throw new Error('Cannot read this AST JSON: `input` is not an Input node with `schemas` and `operations` arrays.')\n }\n // A target is usually a Schema node, but spec data shaped like a ref, such as an example, writes a plain object.\n const badTarget = targets.findIndex((target) => typeof target !== 'object' || target === null)\n if (badTarget !== -1) {\n throw new Error(`Cannot read this AST JSON: target ${badTarget} is not an object.`)\n }\n return { input, targets }\n}\n\n// A wrapped value is spec data that only looks like a ref. A bare number is an index into `targets`.\nfunction refSchema({ stored, targets }: { stored: Array<unknown> | number; targets: Array<unknown> }): unknown {\n if (Array.isArray(stored)) return stored[0]\n const target = targets[stored]\n if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${stored}, which is missing.`)\n return target\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, a malformed `input` or `targets`, or 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 { input, targets } = readDocument(JSON.parse(text))\n\n const stack: Array<unknown> = [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' && (Array.isArray(child) || typeof child === 'number')) {\n value.schema = refSchema({ stored: child, targets })\n continue\n }\n if (typeof child === 'object' && child !== null) stack.push(child)\n }\n }\n\n return input\n}\n"],"mappings":";;;;;;;;AAIA,MAAM,UAAU;AAEhB,SAAS,YAAY,OAAoC;CACvD,OAAOA,iBAAAA,SAAS,KAAK,KAAK,MAAM,SAASC,kBAAAA,UAAU,SAAS,MAAM,QAAQ,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM,UAAU;AAC5H;AAEA,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;AAEA,SAAS,aAAa,QAAgE;CACpF,MAAM,WAAWF,iBAAAA,SAAS,MAAM,IAAI,SAAS,CAAC;CAC9C,IAAI,SAAS,YAAY,SACvB,MAAM,IAAI,MAAM,sDAAsD,QAAQ,QAAQ,KAAK,UAAU,SAAS,OAAO,EAAE,EAAE;CAE3H,MAAM,EAAE,OAAO,YAAY;CAC3B,IAAI,CAAC,SAAS,CAAC,MAAM,QAAQ,OAAO,GAClC,MAAM,IAAI,MAAM,6DAA6D;CAE/E,IAAI,CAAC,YAAY,KAAK,GACpB,MAAM,IAAI,MAAM,iGAAiG;CAGnH,MAAM,YAAY,QAAQ,WAAW,WAAW,OAAO,WAAW,YAAY,WAAW,IAAI;CAC7F,IAAI,cAAc,IAChB,MAAM,IAAI,MAAM,qCAAqC,UAAU,mBAAmB;CAEpF,OAAO;EAAE;EAAO;CAAQ;AAC1B;AAGA,SAAS,UAAU,EAAE,QAAQ,WAAkF;CAC7G,IAAI,MAAM,QAAQ,MAAM,GAAG,OAAO,OAAO;CACzC,MAAM,SAAS,QAAQ;CACvB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD,OAAO,oBAAoB;CAC7G,OAAO;AACT;;;;;AAMA,SAAgB,MAAM,MAAyB;CAE7C,MAAM,EAAE,OAAO,YAAY,aAAa,KAAK,MAAM,IAAI,CAAC;CAExD,MAAM,QAAwB,CAAC,OAAO,GAAG,OAAO;CAChD,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,aAAa,MAAM,QAAQ,KAAK,KAAK,OAAO,UAAU,WAAW;IAClF,MAAM,SAAS,UAAU;KAAE,QAAQ;KAAO;IAAQ,CAAC;IACnD;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,KAAK,KAAK;EACnE;CACF;CAEA,OAAO;AACT"}
|
package/dist/json.cjs
CHANGED
package/dist/json.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as parse, r as stringify } from "./index-
|
|
1
|
+
import { n as parse, r as stringify } from "./index-QDfAzfWY.cjs";
|
|
2
2
|
export { parse, stringify };
|
package/dist/json.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as parse, r as stringify } from "./index-
|
|
1
|
+
import { n as parse, r as stringify } from "./index-QZa0vqFW.js";
|
|
2
2
|
export { parse, stringify };
|
package/dist/json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as parse, r as stringify } from "./json-
|
|
1
|
+
export { n as parse, r as stringify } from "./json-IKokiUCp.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
|
|
2
|
-
import { a as visitorKeys, r as transform } from "./visitor-
|
|
2
|
+
import { a as visitorKeys, r as transform } from "./visitor-CitcdWu0.js";
|
|
3
3
|
// src/defineMacro.ts
|
|
4
4
|
/**
|
|
5
5
|
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
@@ -101,4 +101,4 @@ var macro_exports = /* @__PURE__ */ __exportAll({
|
|
|
101
101
|
});
|
|
102
102
|
export { defineMacro as i, applyMacros as n, compareMacroOrder as r, macro_exports as t };
|
|
103
103
|
|
|
104
|
-
//# sourceMappingURL=macro-
|
|
104
|
+
//# sourceMappingURL=macro-DhgoqDs6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macro-
|
|
1
|
+
{"version":3,"file":"macro-DhgoqDs6.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 * The {@link Visitor} callbacks with `this` typed as the {@link VisitorContext}. A macro callback gets\n * the context both as `this` and as its second argument.\n */\nexport type MacroCallbacks = {\n [K in VisitorKey]?: (this: VisitorContext, ...args: Parameters<NonNullable<Visitor[K]>>) => ReturnType<NonNullable<Visitor[K]>>\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 = MacroCallbacks & {\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 = (this: VisitorContext, 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.call(context, 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;;;;;;;;;;;;;;;AA+CA,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,KAAK,SAAS,SAAS,OAAO;EACpD,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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
|
-
const require_visitor = require("./visitor-
|
|
2
|
+
const require_visitor = require("./visitor-DT712cxr.cjs");
|
|
3
3
|
// src/defineMacro.ts
|
|
4
4
|
/**
|
|
5
5
|
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
@@ -124,4 +124,4 @@ Object.defineProperty(exports, "macro_exports", {
|
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
//# sourceMappingURL=macro-
|
|
127
|
+
//# sourceMappingURL=macro-h3bm9G48.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macro-
|
|
1
|
+
{"version":3,"file":"macro-h3bm9G48.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 * The {@link Visitor} callbacks with `this` typed as the {@link VisitorContext}. A macro callback gets\n * the context both as `this` and as its second argument.\n */\nexport type MacroCallbacks = {\n [K in VisitorKey]?: (this: VisitorContext, ...args: Parameters<NonNullable<Visitor[K]>>) => ReturnType<NonNullable<Visitor[K]>>\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 = MacroCallbacks & {\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 = (this: VisitorContext, 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.call(context, 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;;;;;;;;;;;;;;;AA+CA,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,KAAK,SAAS,SAAS,OAAO;EACpD,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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_macro = require("./macro-
|
|
2
|
+
const require_macro = require("./macro-h3bm9G48.cjs");
|
|
3
3
|
exports.apply = require_macro.applyMacros;
|
|
4
4
|
exports.compareOrder = require_macro.compareMacroOrder;
|
package/dist/macro.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as compareMacroOrder, i as applyMacros } from "./index-
|
|
1
|
+
import { a as compareMacroOrder, i as applyMacros } from "./index-C0YF5kEb.cjs";
|
|
2
2
|
export { applyMacros as apply, compareMacroOrder as compareOrder };
|
package/dist/macro.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as compareMacroOrder, i as applyMacros } from "./index-
|
|
1
|
+
import { a as compareMacroOrder, i as applyMacros } from "./index-CHilsNw-.js";
|
|
2
2
|
export { applyMacros as apply, compareMacroOrder as compareOrder };
|
package/dist/macro.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as apply, r as compareOrder } from "./macro-
|
|
1
|
+
export { n as apply, r as compareOrder } from "./macro-DhgoqDs6.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
2
|
const require_constants = require("./constants-BCRkFAiy.cjs");
|
|
3
3
|
const require_nodeText = require("./nodeText-DH4dLGUb.cjs");
|
|
4
|
-
const require_visitor = require("./visitor-
|
|
4
|
+
const require_visitor = require("./visitor-DT712cxr.cjs");
|
|
5
5
|
// src/node/index.ts
|
|
6
6
|
var node_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
7
7
|
collect: () => require_visitor.collect,
|
|
@@ -16,4 +16,4 @@ Object.defineProperty(exports, "node_exports", {
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
//# sourceMappingURL=node-
|
|
19
|
+
//# sourceMappingURL=node-Dhh4jTDv.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-
|
|
1
|
+
{"version":3,"file":"node-Dhh4jTDv.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":""}
|