@kubb/ast 5.21.1 → 5.22.0

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/index.d.cts CHANGED
@@ -2258,7 +2258,7 @@ declare function mergeRefWithSchema$1(node: RefSchemaNode): SchemaNode;
2258
2258
  * referenced schema variable with those modifiers already applied.
2259
2259
  */
2260
2260
  declare function isBareRef$1(node: SchemaNode | null | undefined, keysToOmit?: Array<string> | null): boolean;
2261
- declare namespace index_d_exports$9 {
2261
+ declare namespace index_d_exports$10 {
2262
2262
  export { getName, resolveRef$1 as getSchema, isBareRef$1 as isAlias, mergeSchema };
2263
2263
  }
2264
2264
  /** A resolved ref merged with its target schema, so usage-site fields such as `description` win. Other nodes come back unchanged. */
@@ -2517,7 +2517,7 @@ type LiteralValue = string | number | boolean | null;
2517
2517
  * literal value, the same shape a declared OpenAPI `discriminator` already narrows on.
2518
2518
  */
2519
2519
  declare function inferDiscriminatorPropertyName$1(members: ReadonlyArray<SchemaNode>): string | undefined;
2520
- declare namespace index_d_exports$10 {
2520
+ declare namespace index_d_exports$11 {
2521
2521
  export { applyOptionality, findSchema$1 as find, resolveSchemaProperties$1 as findProperties, getEmbeddedJson, getSchemaLiteralValues$1 as getLiterals, getNumberBounds, inferDiscriminatorPropertyName$1 as inferDiscriminator, isString, narrowSchema$1 as narrow, schemaTypes$1 as types };
2522
2522
  }
2523
2523
  /** Whether a schema prints as a plain `string`: string-like types, and `date` or `time` with a `'string'` representation. */
@@ -2797,7 +2797,7 @@ declare function defineMacro$1(macro: Macro): Macro;
2797
2797
  declare function applyMacros$1<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: {
2798
2798
  depth?: VisitorDepth;
2799
2799
  }): TNode;
2800
- declare namespace index_d_exports$6 {
2800
+ declare namespace index_d_exports$7 {
2801
2801
  export { applyMacros$1 as apply, compareMacroOrder as compareOrder };
2802
2802
  }
2803
2803
  /**
@@ -2805,7 +2805,7 @@ declare namespace index_d_exports$6 {
2805
2805
  * Collects the text fields and nested node content, to build the source string for import filtering.
2806
2806
  */
2807
2807
  declare function getNodeText(nodes: Array<CodeNode> | undefined): string;
2808
- declare namespace index_d_exports$8 {
2808
+ declare namespace index_d_exports$9 {
2809
2809
  export { collect$1 as collect, getNodeText as getText, nodeKinds$1 as kinds, transform$1 as transform };
2810
2810
  }
2811
2811
  declare namespace index_d_exports$3 {
@@ -2927,7 +2927,25 @@ declare function getRequirements({ auth, schemes }: {
2927
2927
  auth: ReadonlyArray<AuthRequirement> | undefined;
2928
2928
  schemes: ReadonlyArray<AuthScheme> | undefined;
2929
2929
  }): Array<Array<ResolvedScheme>>;
2930
- declare namespace index_d_exports$7 {
2930
+ declare namespace index_d_exports$6 {
2931
+ export { parse, stringify };
2932
+ }
2933
+ /**
2934
+ * Turns an `InputNode` into JSON text that `parse` reads back. Every schema a ref points at is written once,
2935
+ * where a plain `JSON.stringify(input)` writes it again at every ref.
2936
+ *
2937
+ * @example
2938
+ * ```ts
2939
+ * await writeFile('input.json', ast.json.stringify(input))
2940
+ * ```
2941
+ */
2942
+ declare function stringify(input: InputNode): string;
2943
+ /**
2944
+ * Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.
2945
+ * Throws on another format version, or on a ref whose target is missing.
2946
+ */
2947
+ declare function parse(text: string): InputNode;
2948
+ declare namespace index_d_exports$8 {
2931
2949
  export { getBase, isJson, isStream };
2932
2950
  }
2933
2951
  type MediaTypeInput = string | {
@@ -2939,7 +2957,7 @@ declare function getBase(mediaType: MediaTypeInput): string;
2939
2957
  declare function isJson(mediaType: MediaTypeInput): boolean;
2940
2958
  /** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
2941
2959
  declare function isStream(mediaType: MediaTypeInput): boolean;
2942
- declare namespace index_d_exports$11 {
2960
+ declare namespace index_d_exports$12 {
2943
2961
  export { get, groupByName };
2944
2962
  }
2945
2963
  /** The server at `index`, else the first one. */
@@ -3016,6 +3034,6 @@ type ParserOptions = {
3016
3034
  enumSuffix: 'enum' | (string & {});
3017
3035
  };
3018
3036
  declare namespace index_d_exports {
3019
- export { ArraySchemaNode, ArrowFunctionNode, AuthCredential, AuthRequirement, AuthScheme, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, EncodingNode, Enforce, EnumSchemaNode, ExampleNode, ExportNode, ExternalDocs, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InlineLanguage, InputMeta, InputNode, InputServer, InputTag, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, OAuthFlow, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseLink, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, index_d_exports$1 as auth, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, compareEnforce, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$2 as factory, index_d_exports$3 as file, findCircularSchemas, findSchema, getSchemaLiteralValues, index_d_exports$4 as graph, index_d_exports$5 as http, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, index_d_exports$6 as macro, index_d_exports$7 as mediaType, mergeRefWithSchema, narrowSchema, index_d_exports$8 as node, nodeKinds, optionality, index_d_exports$9 as ref, refName, resolveRef, resolveRefName, resolveSchemaProperties, index_d_exports$10 as schema, schemaTypes, index_d_exports$11 as server, transform };
3037
+ export { ArraySchemaNode, ArrowFunctionNode, AuthCredential, AuthRequirement, AuthScheme, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, EncodingNode, Enforce, EnumSchemaNode, ExampleNode, ExportNode, ExternalDocs, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InlineLanguage, InputMeta, InputNode, InputServer, InputTag, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, OAuthFlow, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseLink, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, index_d_exports$1 as auth, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, compareEnforce, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$2 as factory, index_d_exports$3 as file, findCircularSchemas, findSchema, getSchemaLiteralValues, index_d_exports$4 as graph, index_d_exports$5 as http, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, index_d_exports$6 as json, index_d_exports$7 as macro, index_d_exports$8 as mediaType, mergeRefWithSchema, narrowSchema, index_d_exports$9 as node, nodeKinds, optionality, index_d_exports$10 as ref, refName, resolveRef, resolveRefName, resolveSchemaProperties, index_d_exports$11 as schema, schemaTypes, index_d_exports$12 as server, transform };
3020
3038
  }
3021
- export { type ArraySchemaNode, type ArrowFunctionNode, type AuthCredential, type AuthRequirement, type AuthScheme, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type EncodingNode, type Enforce, type EnumSchemaNode, type ExampleNode, type ExportNode, type ExternalDocs, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InlineLanguage, type InputMeta, type InputNode, type InputServer, type InputTag, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type OAuthFlow, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseLink, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as auth, index_d_exports$2 as factory, index_d_exports$3 as file, index_d_exports$4 as graph, index_d_exports$5 as http, index_d_exports$6 as macro, index_d_exports$7 as mediaType, index_d_exports$8 as node, index_d_exports$9 as ref, index_d_exports$10 as schema, index_d_exports$11 as server };
3039
+ export { type ArraySchemaNode, type ArrowFunctionNode, type AuthCredential, type AuthRequirement, type AuthScheme, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type EncodingNode, type Enforce, type EnumSchemaNode, type ExampleNode, type ExportNode, type ExternalDocs, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InlineLanguage, type InputMeta, type InputNode, type InputServer, type InputTag, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type OAuthFlow, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseLink, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as auth, index_d_exports$2 as factory, index_d_exports$3 as file, index_d_exports$4 as graph, index_d_exports$5 as http, index_d_exports$6 as json, index_d_exports$7 as macro, index_d_exports$8 as mediaType, index_d_exports$9 as node, index_d_exports$10 as ref, index_d_exports$11 as schema, index_d_exports$12 as server };
package/dist/index.d.ts CHANGED
@@ -2258,7 +2258,7 @@ declare function mergeRefWithSchema$1(node: RefSchemaNode): SchemaNode;
2258
2258
  * referenced schema variable with those modifiers already applied.
2259
2259
  */
2260
2260
  declare function isBareRef$1(node: SchemaNode | null | undefined, keysToOmit?: Array<string> | null): boolean;
2261
- declare namespace index_d_exports$9 {
2261
+ declare namespace index_d_exports$10 {
2262
2262
  export { getName, resolveRef$1 as getSchema, isBareRef$1 as isAlias, mergeSchema };
2263
2263
  }
2264
2264
  /** A resolved ref merged with its target schema, so usage-site fields such as `description` win. Other nodes come back unchanged. */
@@ -2517,7 +2517,7 @@ type LiteralValue = string | number | boolean | null;
2517
2517
  * literal value, the same shape a declared OpenAPI `discriminator` already narrows on.
2518
2518
  */
2519
2519
  declare function inferDiscriminatorPropertyName$1(members: ReadonlyArray<SchemaNode>): string | undefined;
2520
- declare namespace index_d_exports$10 {
2520
+ declare namespace index_d_exports$11 {
2521
2521
  export { applyOptionality, findSchema$1 as find, resolveSchemaProperties$1 as findProperties, getEmbeddedJson, getSchemaLiteralValues$1 as getLiterals, getNumberBounds, inferDiscriminatorPropertyName$1 as inferDiscriminator, isString, narrowSchema$1 as narrow, schemaTypes$1 as types };
2522
2522
  }
2523
2523
  /** Whether a schema prints as a plain `string`: string-like types, and `date` or `time` with a `'string'` representation. */
@@ -2797,7 +2797,7 @@ declare function defineMacro$1(macro: Macro): Macro;
2797
2797
  declare function applyMacros$1<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: {
2798
2798
  depth?: VisitorDepth;
2799
2799
  }): TNode;
2800
- declare namespace index_d_exports$6 {
2800
+ declare namespace index_d_exports$7 {
2801
2801
  export { applyMacros$1 as apply, compareMacroOrder as compareOrder };
2802
2802
  }
2803
2803
  /**
@@ -2805,7 +2805,7 @@ declare namespace index_d_exports$6 {
2805
2805
  * Collects the text fields and nested node content, to build the source string for import filtering.
2806
2806
  */
2807
2807
  declare function getNodeText(nodes: Array<CodeNode> | undefined): string;
2808
- declare namespace index_d_exports$8 {
2808
+ declare namespace index_d_exports$9 {
2809
2809
  export { collect$1 as collect, getNodeText as getText, nodeKinds$1 as kinds, transform$1 as transform };
2810
2810
  }
2811
2811
  declare namespace index_d_exports$3 {
@@ -2927,7 +2927,25 @@ declare function getRequirements({ auth, schemes }: {
2927
2927
  auth: ReadonlyArray<AuthRequirement> | undefined;
2928
2928
  schemes: ReadonlyArray<AuthScheme> | undefined;
2929
2929
  }): Array<Array<ResolvedScheme>>;
2930
- declare namespace index_d_exports$7 {
2930
+ declare namespace index_d_exports$6 {
2931
+ export { parse, stringify };
2932
+ }
2933
+ /**
2934
+ * Turns an `InputNode` into JSON text that `parse` reads back. Every schema a ref points at is written once,
2935
+ * where a plain `JSON.stringify(input)` writes it again at every ref.
2936
+ *
2937
+ * @example
2938
+ * ```ts
2939
+ * await writeFile('input.json', ast.json.stringify(input))
2940
+ * ```
2941
+ */
2942
+ declare function stringify(input: InputNode): string;
2943
+ /**
2944
+ * Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.
2945
+ * Throws on another format version, or on a ref whose target is missing.
2946
+ */
2947
+ declare function parse(text: string): InputNode;
2948
+ declare namespace index_d_exports$8 {
2931
2949
  export { getBase, isJson, isStream };
2932
2950
  }
2933
2951
  type MediaTypeInput = string | {
@@ -2939,7 +2957,7 @@ declare function getBase(mediaType: MediaTypeInput): string;
2939
2957
  declare function isJson(mediaType: MediaTypeInput): boolean;
2940
2958
  /** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
2941
2959
  declare function isStream(mediaType: MediaTypeInput): boolean;
2942
- declare namespace index_d_exports$11 {
2960
+ declare namespace index_d_exports$12 {
2943
2961
  export { get, groupByName };
2944
2962
  }
2945
2963
  /** The server at `index`, else the first one. */
@@ -3016,6 +3034,6 @@ type ParserOptions = {
3016
3034
  enumSuffix: 'enum' | (string & {});
3017
3035
  };
3018
3036
  declare namespace index_d_exports {
3019
- export { ArraySchemaNode, ArrowFunctionNode, AuthCredential, AuthRequirement, AuthScheme, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, EncodingNode, Enforce, EnumSchemaNode, ExampleNode, ExportNode, ExternalDocs, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InlineLanguage, InputMeta, InputNode, InputServer, InputTag, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, OAuthFlow, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseLink, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, index_d_exports$1 as auth, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, compareEnforce, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$2 as factory, index_d_exports$3 as file, findCircularSchemas, findSchema, getSchemaLiteralValues, index_d_exports$4 as graph, index_d_exports$5 as http, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, index_d_exports$6 as macro, index_d_exports$7 as mediaType, mergeRefWithSchema, narrowSchema, index_d_exports$8 as node, nodeKinds, optionality, index_d_exports$9 as ref, refName, resolveRef, resolveRefName, resolveSchemaProperties, index_d_exports$10 as schema, schemaTypes, index_d_exports$11 as server, transform };
3037
+ export { ArraySchemaNode, ArrowFunctionNode, AuthCredential, AuthRequirement, AuthScheme, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, EncodingNode, Enforce, EnumSchemaNode, ExampleNode, ExportNode, ExternalDocs, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InlineLanguage, InputMeta, InputNode, InputServer, InputTag, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, OAuthFlow, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseLink, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, index_d_exports$1 as auth, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, compareEnforce, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$2 as factory, index_d_exports$3 as file, findCircularSchemas, findSchema, getSchemaLiteralValues, index_d_exports$4 as graph, index_d_exports$5 as http, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, index_d_exports$6 as json, index_d_exports$7 as macro, index_d_exports$8 as mediaType, mergeRefWithSchema, narrowSchema, index_d_exports$9 as node, nodeKinds, optionality, index_d_exports$10 as ref, refName, resolveRef, resolveRefName, resolveSchemaProperties, index_d_exports$11 as schema, schemaTypes, index_d_exports$12 as server, transform };
3020
3038
  }
3021
- export { type ArraySchemaNode, type ArrowFunctionNode, type AuthCredential, type AuthRequirement, type AuthScheme, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type EncodingNode, type Enforce, type EnumSchemaNode, type ExampleNode, type ExportNode, type ExternalDocs, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InlineLanguage, type InputMeta, type InputNode, type InputServer, type InputTag, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type OAuthFlow, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseLink, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as auth, index_d_exports$2 as factory, index_d_exports$3 as file, index_d_exports$4 as graph, index_d_exports$5 as http, index_d_exports$6 as macro, index_d_exports$7 as mediaType, index_d_exports$8 as node, index_d_exports$9 as ref, index_d_exports$10 as schema, index_d_exports$11 as server };
3039
+ export { type ArraySchemaNode, type ArrowFunctionNode, type AuthCredential, type AuthRequirement, type AuthScheme, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type EncodingNode, type Enforce, type EnumSchemaNode, type ExampleNode, type ExportNode, type ExternalDocs, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InlineLanguage, type InputMeta, type InputNode, type InputServer, type InputTag, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type OAuthFlow, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseLink, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as auth, index_d_exports$2 as factory, index_d_exports$3 as file, index_d_exports$4 as graph, index_d_exports$5 as http, index_d_exports$6 as json, index_d_exports$7 as macro, index_d_exports$8 as mediaType, index_d_exports$9 as node, index_d_exports$10 as ref, index_d_exports$11 as schema, index_d_exports$12 as server };
package/dist/index.js CHANGED
@@ -2079,6 +2079,75 @@ var nodes_exports = /* @__PURE__ */ __exportAll({
2079
2079
  createText: () => createText,
2080
2080
  createType: () => createType
2081
2081
  });
2082
+ // src/json/index.ts
2083
+ var json_exports = /* @__PURE__ */ __exportAll({
2084
+ parse: () => parse,
2085
+ stringify: () => stringify
2086
+ });
2087
+ const version = 1;
2088
+ function isRef(value) {
2089
+ const node = value;
2090
+ return node?.kind === nodeKinds$1.schema && node.type === schemaTypes$1.ref;
2091
+ }
2092
+ /**
2093
+ * Turns an `InputNode` into JSON text that `parse` reads back. Every schema a ref points at is written once,
2094
+ * where a plain `JSON.stringify(input)` writes it again at every ref.
2095
+ *
2096
+ * @example
2097
+ * ```ts
2098
+ * await writeFile('input.json', ast.json.stringify(input))
2099
+ * ```
2100
+ */
2101
+ function stringify(input) {
2102
+ const ids = /* @__PURE__ */ new Map();
2103
+ const targets = [];
2104
+ function replacer(key, value) {
2105
+ if (key !== "schema" || !isRef(this)) return value;
2106
+ if (typeof value === "number") return [value];
2107
+ if (typeof value !== "object" || value === null) return value;
2108
+ if (!ids.has(value)) {
2109
+ ids.set(value, targets.length);
2110
+ targets.push(value);
2111
+ }
2112
+ return ids.get(value);
2113
+ }
2114
+ const root = JSON.stringify(input, replacer);
2115
+ const encoded = [];
2116
+ for (const target of targets) encoded.push(JSON.stringify(target, replacer));
2117
+ return `{"version":${version},"input":${root},"targets":[${encoded.join(",")}]}`;
2118
+ }
2119
+ /**
2120
+ * Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.
2121
+ * Throws on another format version, or on a ref whose target is missing.
2122
+ */
2123
+ function parse(text) {
2124
+ const document = JSON.parse(text);
2125
+ if (document?.version !== version) throw new Error(`Cannot read this AST JSON: expected format version ${version}, got ${JSON.stringify(document?.version)}.`);
2126
+ if (!document.input || !Array.isArray(document.targets)) throw new Error("Cannot read this AST JSON: `input` or `targets` is missing.");
2127
+ const targets = document.targets;
2128
+ const stack = [document.input, ...targets];
2129
+ while (stack.length) {
2130
+ const value = stack.pop();
2131
+ const ref = isRef(value);
2132
+ for (const key in value) {
2133
+ const child = value[key];
2134
+ if (ref && key === "schema") {
2135
+ if (Array.isArray(child)) {
2136
+ value.schema = child[0];
2137
+ continue;
2138
+ }
2139
+ if (typeof child === "number") {
2140
+ const target = targets[child];
2141
+ if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${child}, which is missing.`);
2142
+ value.schema = target;
2143
+ continue;
2144
+ }
2145
+ }
2146
+ if (typeof child === "object" && child !== null) stack.push(child);
2147
+ }
2148
+ }
2149
+ return document.input;
2150
+ }
2082
2151
  // src/server/index.ts
2083
2152
  var server_exports = /* @__PURE__ */ __exportAll({
2084
2153
  get: () => get,
@@ -2119,6 +2188,7 @@ var src_exports = /* @__PURE__ */ __exportAll({
2119
2188
  inlineFiles: () => inlineFiles,
2120
2189
  isBareRef: () => isBareRef,
2121
2190
  isHttpOperationNode: () => isHttpOperationNode,
2191
+ json: () => json_exports,
2122
2192
  macro: () => macro_exports,
2123
2193
  mediaType: () => mediaType_exports,
2124
2194
  mergeRefWithSchema: () => mergeRefWithSchema,
@@ -2136,6 +2206,6 @@ var src_exports = /* @__PURE__ */ __exportAll({
2136
2206
  server: () => server_exports,
2137
2207
  transform: () => transform
2138
2208
  });
2139
- export { applyMacros, src_exports as ast, auth_exports as auth, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, compareEnforce, createPrinter, defineMacro, extractStringsFromNodes, nodes_exports as factory, file_exports as file, findCircularSchemas, findSchema, getSchemaLiteralValues, graph_exports as graph, http_exports as http, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, macro_exports as macro, mediaType_exports as mediaType, mergeRefWithSchema, narrowSchema, node_exports as node, nodeKinds, optionality, ref_exports as ref, refName, resolveRef, resolveRefName, resolveSchemaProperties, schema_exports as schema, schemaTypes, server_exports as server, transform };
2209
+ export { applyMacros, src_exports as ast, auth_exports as auth, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, compareEnforce, createPrinter, defineMacro, extractStringsFromNodes, nodes_exports as factory, file_exports as file, findCircularSchemas, findSchema, getSchemaLiteralValues, graph_exports as graph, http_exports as http, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, json_exports as json, macro_exports as macro, mediaType_exports as mediaType, mergeRefWithSchema, narrowSchema, node_exports as node, nodeKinds, optionality, ref_exports as ref, refName, resolveRef, resolveRefName, resolveSchemaProperties, schema_exports as schema, schemaTypes, server_exports as server, transform };
2140
2210
 
2141
2211
  //# sourceMappingURL=index.js.map