@kubb/ast 5.0.6 → 5.2.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.cjs +87 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +62 -14
- package/dist/index.js +86 -1
- package/dist/index.js.map +1 -1
- package/dist/{types-BPqinVNh.d.ts → types-DiCduvU8.d.ts} +38 -9
- package/dist/types.d.ts +2 -2
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as __name, t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import { $ as importDef, $t as
|
|
2
|
+
import { $ as importDef, $t as textDef, A as ResponseNode, At as InferSchemaNode, B as createParameter, Bt as TypeNode, C as inputDef, Ct as schemaDef, D as OperationNode, Dt as DateOnlyTypeValue, E as HttpOperationNode, Et as propertyDef, F as createRequestBody, Ft as ConstNode, G as SourceNode, Gt as createBreak, H as ExportNode, Ht as breakDef, I as requestBodyDef, It as FunctionNode, J as createFile, Jt as createJsx, K as UserFileNode, Kt as createConst, L as ParameterLocation, Lt as JSDocNode, M as createResponse, Mt as ArrowFunctionNode, N as responseDef, Nt as BreakNode, O as createOperation, Ot as DateTimeTypeValue, P as RequestBodyNode, Pt as CodeNode, Q as fileDef, Qt as jsxDef, R as ParameterNode, Rt as JsxNode, S as createInput, St as createSchema, T as HttpMethod, Tt as createProperty, U as FileNode, Ut as constDef, V as parameterDef, Vt as arrowFunctionDef, W as ImportNode, Wt as createArrowFunction, X as createSource, Xt as createType, Y as createImport, Yt as createText, Z as exportDef, Zt as functionDef, _ as OutputNode, _t as SchemaType, a as Enforce, an as NodeKind, at as DateSchemaNode, b as InputMeta, bt as UnionSchemaNode, c as composeMacros, ct as IntersectionSchemaNode, d as Visitor, dt as PrimitiveSchemaType, en as typeDef, et as sourceDef, f as VisitorContext, ft as RefSchemaNode, g as Node, gt as SchemaNodeByType, h as transform, ht as SchemaNode, i as createPrinter, in as BaseNode, it as ArraySchemaNode, j as StatusCode, jt as ParserOptions, k as operationDef, kt as DateTypeOptions, l as defineMacro, lt as NumberSchemaNode, m as collectSync, mt as ScalarSchemaType, n as PrinterFactoryOptions, nn as NodeDef, nt as contentDef, o as Macro, on as schemaTypes, ot as DatetimeSchemaNode, p as collect, pt as ScalarSchemaNode, q as createExport, qt as createFunction, r as PrinterPartial, rn as defineNode, rt as createContent, s as applyMacros, st as EnumSchemaNode, t as Printer, tn as DistributiveOmit, tt as ContentNode, u as ParentOf, ut as ObjectSchemaNode, v as createOutput, vt as StringSchemaNode, w as GenericOperationNode, wt as PropertyNode, x as InputNode, xt as UrlSchemaNode, y as outputDef, yt as TimeSchemaNode, z as ParameterStyle, zt as TextNode } from "./types-DiCduvU8.js";
|
|
3
3
|
//#region src/guards.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
@@ -10,7 +10,7 @@ import { $ as importDef, $t as DistributiveOmit, A as ResponseNode, At as ArrowF
|
|
|
10
10
|
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
|
-
declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null;
|
|
13
|
+
export declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null;
|
|
14
14
|
/**
|
|
15
15
|
* Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
|
|
16
16
|
*
|
|
@@ -21,14 +21,14 @@ declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | u
|
|
|
21
21
|
* }
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
declare function isHttpOperationNode(node: OperationNode): node is HttpOperationNode;
|
|
24
|
+
export declare function isHttpOperationNode(node: OperationNode): node is HttpOperationNode;
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region src/optionality.d.ts
|
|
27
27
|
/**
|
|
28
28
|
* Generic JSON Schema optionality: a non-required field is optional, and a
|
|
29
29
|
* non-required nullable field is nullish.
|
|
30
30
|
*/
|
|
31
|
-
declare function optionality(schema: SchemaNode, required: boolean): SchemaNode;
|
|
31
|
+
export declare function optionality(schema: SchemaNode, required: boolean): SchemaNode;
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/utils/extractStringsFromNodes.d.ts
|
|
34
34
|
/**
|
|
@@ -37,7 +37,7 @@ declare function optionality(schema: SchemaNode, required: boolean): SchemaNode;
|
|
|
37
37
|
* Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
|
|
38
38
|
* and nested node content. Used to build the full source string for import filtering.
|
|
39
39
|
*/
|
|
40
|
-
declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
|
|
40
|
+
export declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region src/utils/refs.d.ts
|
|
43
43
|
/**
|
|
@@ -53,7 +53,7 @@ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): st
|
|
|
53
53
|
* @example Collision-renamed target
|
|
54
54
|
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Order', targetName: 'OrderSchema' }) // 'OrderSchema'`
|
|
55
55
|
*/
|
|
56
|
-
declare function resolveRefName(node: SchemaNode | null | undefined): string | null;
|
|
56
|
+
export declare function resolveRefName(node: SchemaNode | null | undefined): string | null;
|
|
57
57
|
//#endregion
|
|
58
58
|
//#region src/utils/schemaGraph.d.ts
|
|
59
59
|
/**
|
|
@@ -73,7 +73,7 @@ declare function resolveRefName(node: SchemaNode | null | undefined): string | n
|
|
|
73
73
|
* // ['Category', 'Tag']
|
|
74
74
|
* ```
|
|
75
75
|
*/
|
|
76
|
-
declare const collectImportedRefNames: (key: SchemaNode) => readonly string[];
|
|
76
|
+
export declare const collectImportedRefNames: (key: SchemaNode) => readonly string[];
|
|
77
77
|
/**
|
|
78
78
|
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
79
79
|
*
|
|
@@ -94,7 +94,7 @@ declare const collectImportedRefNames: (key: SchemaNode) => readonly string[];
|
|
|
94
94
|
* }
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
|
-
declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
97
|
+
export declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
98
98
|
/**
|
|
99
99
|
* Finds every schema that takes part in a circular dependency chain in a schema dependency graph
|
|
100
100
|
* that maps each schema name to the names it references directly.
|
|
@@ -112,7 +112,7 @@ declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>
|
|
|
112
112
|
* findCircularSchemasFromGraph(graph) // Set { 'Pet', 'Category' }
|
|
113
113
|
* ```
|
|
114
114
|
*/
|
|
115
|
-
declare function findCircularSchemasFromGraph(graph: ReadonlyMap<string, ReadonlySet<string>>): Set<string>;
|
|
115
|
+
export declare function findCircularSchemasFromGraph(graph: ReadonlyMap<string, ReadonlySet<string>>): Set<string>;
|
|
116
116
|
/**
|
|
117
117
|
* Finds every schema that takes part in a circular dependency chain, including direct self-loops.
|
|
118
118
|
*
|
|
@@ -122,7 +122,55 @@ declare function findCircularSchemasFromGraph(graph: ReadonlyMap<string, Readonl
|
|
|
122
122
|
*
|
|
123
123
|
* @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.
|
|
124
124
|
*/
|
|
125
|
-
declare function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
125
|
+
export declare function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/utils/schemaProperties.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* Finds every matching property exposed by an object, resolved reference, or intersection.
|
|
130
|
+
*
|
|
131
|
+
* References are followed through their parsed `schema`. Circular references terminate without
|
|
132
|
+
* revisiting a node. Unions are not traversed because a property on one branch does not describe
|
|
133
|
+
* every branch.
|
|
134
|
+
*
|
|
135
|
+
* @example Faker discriminator narrowing
|
|
136
|
+
* ```ts
|
|
137
|
+
* const values = resolveSchemaProperties({ node: member, propertyName: union.discriminatorPropertyName }).flatMap(({ schema }) =>
|
|
138
|
+
* getSchemaLiteralValues(schema),
|
|
139
|
+
* )
|
|
140
|
+
* const typeName = `Extract<Pet, { type: ${values.map(JSON.stringify).join(' | ')} }>`
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @example Zod discriminated unions
|
|
144
|
+
* ```ts
|
|
145
|
+
* const canDiscriminate = union.members?.every(
|
|
146
|
+
* (member) => resolveSchemaProperties({ node: member, propertyName: 'type' }).length > 0,
|
|
147
|
+
* )
|
|
148
|
+
* const expression = canDiscriminate ? `z.discriminatedUnion('type', members)` : `z.union(members)`
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @example TypeScript property lookup
|
|
152
|
+
* ```ts
|
|
153
|
+
* const properties = resolveSchemaProperties({ node: schema, propertyName: 'status' })
|
|
154
|
+
* const statusSchemas = properties.map((property) => print(property.schema))
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function resolveSchemaProperties({ node, propertyName }: {
|
|
158
|
+
node: SchemaNode;
|
|
159
|
+
propertyName: string;
|
|
160
|
+
}): ReadonlyArray<PropertyNode>;
|
|
161
|
+
/**
|
|
162
|
+
* Reads the unique literal values represented by an enum, resolved reference, or union.
|
|
163
|
+
*
|
|
164
|
+
* Named enum values take precedence over simple enum values, matching how renderers consume
|
|
165
|
+
* `EnumSchemaNode`.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const values = getSchemaLiteralValues(enumNode)
|
|
170
|
+
* // ['cat', 'dog']
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export declare function getSchemaLiteralValues(node: SchemaNode): ReadonlyArray<string | number | boolean | null>;
|
|
126
174
|
declare namespace factory_d_exports {
|
|
127
175
|
export { UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, update };
|
|
128
176
|
}
|
|
@@ -149,7 +197,7 @@ declare function update<T extends Node>(node: T, changes: Partial<T>): T;
|
|
|
149
197
|
* Every node definition. Adding a node means adding its `defineNode` to one
|
|
150
198
|
* `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
|
|
151
199
|
*/
|
|
152
|
-
declare const nodeDefs: (NodeDef<InputNode, Partial<Omit<InputNode, "kind">>> | NodeDef<OutputNode, Partial<Omit<OutputNode, "kind">>> | NodeDef<RequestBodyNode, Omit<RequestBodyNode, "kind">> | NodeDef<OperationNode, {
|
|
200
|
+
export declare const nodeDefs: (NodeDef<InputNode, Partial<Omit<InputNode, "kind">>> | NodeDef<OutputNode, Partial<Omit<OutputNode, "kind">>> | NodeDef<RequestBodyNode, Omit<RequestBodyNode, "kind">> | NodeDef<OperationNode, {
|
|
153
201
|
[key: string]: unknown;
|
|
154
202
|
operationId: string;
|
|
155
203
|
method?: HttpOperationNode["method"];
|
|
@@ -216,10 +264,10 @@ declare const nodeDefs: (NodeDef<InputNode, Partial<Omit<InputNode, "kind">>> |
|
|
|
216
264
|
format?: string;
|
|
217
265
|
} & {
|
|
218
266
|
type: "ipv6";
|
|
219
|
-
}) | ScalarSchemaNode, "kind">> | NodeDef<PropertyNode,
|
|
267
|
+
}) | ScalarSchemaNode, "kind">> | NodeDef<PropertyNode, Pick<PropertyNode, "schema" | "name"> & Partial<Omit<PropertyNode, "schema" | "kind" | "name">>> | NodeDef<ParameterNode, Pick<ParameterNode, "schema" | "name" | "in"> & Partial<Omit<ParameterNode, "schema" | "kind" | "name" | "in">>> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[];
|
|
220
268
|
declare namespace exports_d_exports {
|
|
221
|
-
export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
|
|
269
|
+
export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, getSchemaLiteralValues, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, resolveSchemaProperties, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
|
|
222
270
|
}
|
|
223
271
|
//#endregion
|
|
224
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, 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, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, collect,
|
|
272
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, 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, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, collect, collectSync, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, factory_d_exports as factory, fileDef, functionDef, importDef, inputDef, jsxDef, operationDef, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
|
|
225
273
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1504,6 +1504,89 @@ function findCircularSchemas(schemas) {
|
|
|
1504
1504
|
return findCircularSchemasMemo(schemas);
|
|
1505
1505
|
}
|
|
1506
1506
|
//#endregion
|
|
1507
|
+
//#region src/utils/schemaProperties.ts
|
|
1508
|
+
/**
|
|
1509
|
+
* Finds every matching property exposed by an object, resolved reference, or intersection.
|
|
1510
|
+
*
|
|
1511
|
+
* References are followed through their parsed `schema`. Circular references terminate without
|
|
1512
|
+
* revisiting a node. Unions are not traversed because a property on one branch does not describe
|
|
1513
|
+
* every branch.
|
|
1514
|
+
*
|
|
1515
|
+
* @example Faker discriminator narrowing
|
|
1516
|
+
* ```ts
|
|
1517
|
+
* const values = resolveSchemaProperties({ node: member, propertyName: union.discriminatorPropertyName }).flatMap(({ schema }) =>
|
|
1518
|
+
* getSchemaLiteralValues(schema),
|
|
1519
|
+
* )
|
|
1520
|
+
* const typeName = `Extract<Pet, { type: ${values.map(JSON.stringify).join(' | ')} }>`
|
|
1521
|
+
* ```
|
|
1522
|
+
*
|
|
1523
|
+
* @example Zod discriminated unions
|
|
1524
|
+
* ```ts
|
|
1525
|
+
* const canDiscriminate = union.members?.every(
|
|
1526
|
+
* (member) => resolveSchemaProperties({ node: member, propertyName: 'type' }).length > 0,
|
|
1527
|
+
* )
|
|
1528
|
+
* const expression = canDiscriminate ? `z.discriminatedUnion('type', members)` : `z.union(members)`
|
|
1529
|
+
* ```
|
|
1530
|
+
*
|
|
1531
|
+
* @example TypeScript property lookup
|
|
1532
|
+
* ```ts
|
|
1533
|
+
* const properties = resolveSchemaProperties({ node: schema, propertyName: 'status' })
|
|
1534
|
+
* const statusSchemas = properties.map((property) => print(property.schema))
|
|
1535
|
+
* ```
|
|
1536
|
+
*/
|
|
1537
|
+
function resolveSchemaProperties({ node, propertyName }) {
|
|
1538
|
+
const properties = [];
|
|
1539
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
1540
|
+
function visit(current) {
|
|
1541
|
+
if (!current || visited.has(current)) return;
|
|
1542
|
+
visited.add(current);
|
|
1543
|
+
if (current.type === "object") {
|
|
1544
|
+
const property = current.properties.find((candidate) => candidate.name === propertyName);
|
|
1545
|
+
if (property) properties.push(property);
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
if (current.type === "ref") {
|
|
1549
|
+
visit(current.schema);
|
|
1550
|
+
return;
|
|
1551
|
+
}
|
|
1552
|
+
if (current.type === "intersection") for (const member of current.members ?? []) visit(member);
|
|
1553
|
+
}
|
|
1554
|
+
visit(node);
|
|
1555
|
+
return properties;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Reads the unique literal values represented by an enum, resolved reference, or union.
|
|
1559
|
+
*
|
|
1560
|
+
* Named enum values take precedence over simple enum values, matching how renderers consume
|
|
1561
|
+
* `EnumSchemaNode`.
|
|
1562
|
+
*
|
|
1563
|
+
* @example
|
|
1564
|
+
* ```ts
|
|
1565
|
+
* const values = getSchemaLiteralValues(enumNode)
|
|
1566
|
+
* // ['cat', 'dog']
|
|
1567
|
+
* ```
|
|
1568
|
+
*/
|
|
1569
|
+
function getSchemaLiteralValues(node) {
|
|
1570
|
+
const values = /* @__PURE__ */ new Set();
|
|
1571
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
1572
|
+
function visit(current) {
|
|
1573
|
+
if (!current || visited.has(current)) return;
|
|
1574
|
+
visited.add(current);
|
|
1575
|
+
if (current.type === "enum") {
|
|
1576
|
+
const enumValues = current.namedEnumValues?.map(({ value }) => value) ?? current.enumValues ?? [];
|
|
1577
|
+
for (const value of enumValues) values.add(value);
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
if (current.type === "ref") {
|
|
1581
|
+
visit(current.schema);
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1584
|
+
if (current.type === "union") for (const member of current.members ?? []) visit(member);
|
|
1585
|
+
}
|
|
1586
|
+
visit(node);
|
|
1587
|
+
return [...values];
|
|
1588
|
+
}
|
|
1589
|
+
//#endregion
|
|
1507
1590
|
//#region src/factory.ts
|
|
1508
1591
|
var factory_exports = /* @__PURE__ */ __exportAll({
|
|
1509
1592
|
createArrowFunction: () => createArrowFunction,
|
|
@@ -1574,6 +1657,7 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
1574
1657
|
findCircularSchemas: () => findCircularSchemas,
|
|
1575
1658
|
findCircularSchemasFromGraph: () => findCircularSchemasFromGraph,
|
|
1576
1659
|
functionDef: () => functionDef,
|
|
1660
|
+
getSchemaLiteralValues: () => getSchemaLiteralValues,
|
|
1577
1661
|
importDef: () => importDef,
|
|
1578
1662
|
inputDef: () => inputDef,
|
|
1579
1663
|
isHttpOperationNode: () => isHttpOperationNode,
|
|
@@ -1587,6 +1671,7 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
1587
1671
|
propertyDef: () => propertyDef,
|
|
1588
1672
|
requestBodyDef: () => requestBodyDef,
|
|
1589
1673
|
resolveRefName: () => resolveRefName,
|
|
1674
|
+
resolveSchemaProperties: () => resolveSchemaProperties,
|
|
1590
1675
|
responseDef: () => responseDef,
|
|
1591
1676
|
schemaDef: () => schemaDef,
|
|
1592
1677
|
schemaTypes: () => schemaTypes,
|
|
@@ -1596,6 +1681,6 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
1596
1681
|
typeDef: () => typeDef
|
|
1597
1682
|
});
|
|
1598
1683
|
//#endregion
|
|
1599
|
-
export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
|
|
1684
|
+
export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, getSchemaLiteralValues, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, resolveSchemaProperties, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
|
|
1600
1685
|
|
|
1601
1686
|
//# sourceMappingURL=index.js.map
|