@kubb/ast 5.0.0-beta.80 → 5.0.0-beta.81
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 +2280 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +420 -18
- package/dist/index.js +2133 -15
- package/dist/index.js.map +1 -1
- package/dist/{index-Cu2zmNxv.d.ts → types-XcYJovdT.d.ts} +717 -2
- package/dist/types.d.ts +1 -3
- package/package.json +1 -9
- package/dist/defineMacro-CqX4m8Dq.js +0 -98
- package/dist/defineMacro-CqX4m8Dq.js.map +0 -1
- package/dist/defineMacro-DmGR7vfu.cjs +0 -114
- package/dist/defineMacro-DmGR7vfu.cjs.map +0 -1
- package/dist/defineMacro-DzsACbFo.d.ts +0 -466
- package/dist/macros.cjs +0 -130
- package/dist/macros.cjs.map +0 -1
- package/dist/macros.d.ts +0 -61
- package/dist/macros.js +0 -128
- package/dist/macros.js.map +0 -1
- package/dist/refs-Bg3rmujP.cjs +0 -135
- package/dist/refs-Bg3rmujP.cjs.map +0 -1
- package/dist/refs-BjBHwunY.js +0 -101
- package/dist/refs-BjBHwunY.js.map +0 -1
- package/dist/types-CWF7DV0f.d.ts +0 -259
- package/dist/utils.cjs +0 -613
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.ts +0 -353
- package/dist/utils.js +0 -589
- package/dist/utils.js.map +0 -1
- package/dist/visitor-Dk0DNLfC.js +0 -1203
- package/dist/visitor-Dk0DNLfC.js.map +0 -1
- package/dist/visitor-h6dEM3vR.cjs +0 -1567
- package/dist/visitor-h6dEM3vR.cjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { n as __name, t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as Dialect, i as createPrinter, n as PrinterFactoryOptions, o as SchemaDialect, r as PrinterPartial, s as defineDialect, t as Printer } from "./types-CWF7DV0f.js";
|
|
4
|
-
import { $ as ScalarSchemaType, A as SourceNode, At as createFunction, B as ContentNode, Bt as defineNode, C as ParameterNode, Ct as TypeNode, D as ExportNode, Dt as createArrowFunction, E as parameterDef, Et as constDef, F as createSource, Ft as jsxDef, G as DatetimeSchemaNode, H as createContent, Ht as NodeKind, I as exportDef, It as textDef, J as NumberSchemaNode, K as EnumSchemaNode, L as fileDef, Lt as typeDef, M as createExport, Mt as createText, N as createFile, Nt as createType, O as FileNode, Ot as createBreak, P as createImport, Pt as functionDef, Q as ScalarSchemaNode, R as importDef, Rt as DistributiveOmit, S as ParameterLocation, St as TextNode, T as createParameter, Tt as breakDef, U as ArraySchemaNode, V as contentDef, Vt as BaseNode, W as DateSchemaNode, X as PrimitiveSchemaType, Y as ObjectSchemaNode, Z as RefSchemaNode, _ as createResponse, _t as CodeNode, a as InputMeta, at as UnionSchemaNode, b as createRequestBody, bt as JSDocNode, c as inputDef, ct as schemaDef, d as HttpOperationNode, dt as createProperty, et as SchemaNode, f as OperationNode, ft as propertyDef, g as StatusCode, gt as BreakNode, h as ResponseNode, ht as ArrowFunctionNode, i as outputDef, it as TimeSchemaNode, j as UserFileNode, jt as createJsx, k as ImportNode, kt as createConst, l as GenericOperationNode, lt as PropertyNode, m as operationDef, mt as ParserOptions, n as OutputNode, nt as SchemaType, o as InputNode, ot as UrlSchemaNode, p as createOperation, pt as InferSchemaNode, q as IntersectionSchemaNode, r as createOutput, rt as StringSchemaNode, s as createInput, st as createSchema, t as Node, tt as SchemaNodeByType, u as HttpMethod, ut as UserPropertyNode, v as responseDef, vt as ConstNode, w as ParameterStyle, wt as arrowFunctionDef, x as requestBodyDef, xt as JsxNode, y as RequestBodyNode, yt as FunctionNode, z as sourceDef, zt as NodeDef } from "./index-Cu2zmNxv.js";
|
|
2
|
+
import { $ as importDef, $t as DistributiveOmit, A as ResponseNode, At as ArrowFunctionNode, B as createParameter, Bt as breakDef, C as inputDef, Ct as schemaDef, D as OperationNode, Dt as propertyDef, E as HttpOperationNode, Et as createProperty, F as createRequestBody, Ft as JSDocNode, G as SourceNode, Gt as createFunction, H as ExportNode, Ht as createArrowFunction, I as requestBodyDef, It as JsxNode, J as createFile, Jt as createType, K as UserFileNode, Kt as createJsx, L as ParameterLocation, Lt as TextNode, M as createResponse, Mt as CodeNode, N as responseDef, Nt as ConstNode, O as createOperation, Ot as InferSchemaNode, P as RequestBodyNode, Pt as FunctionNode, Q as fileDef, Qt as typeDef, R as ParameterNode, Rt as TypeNode, S as createInput, St as createSchema, T as HttpMethod, Tt as UserPropertyNode, U as FileNode, Ut as createBreak, V as parameterDef, Vt as constDef, W as ImportNode, Wt as createConst, X as createSource, Xt as jsxDef, Y as createImport, Yt as functionDef, Z as exportDef, Zt as textDef, _ as OutputNode, _t as SchemaType, a as Enforce, an as SchemaDialect, at as DateSchemaNode, b as InputMeta, bt as UnionSchemaNode, c as composeMacros, ct as IntersectionSchemaNode, d as Visitor, dt as PrimitiveSchemaType, en as NodeDef, et as sourceDef, f as VisitorContext, ft as RefSchemaNode, g as Node, gt as SchemaNodeByType, h as walk, ht as SchemaNode, i as createPrinter, in as Dialect, it as ArraySchemaNode, j as StatusCode, jt as BreakNode, k as operationDef, kt as ParserOptions, l as defineMacro, lt as NumberSchemaNode, m as transform, mt as ScalarSchemaType, n as PrinterFactoryOptions, nn as BaseNode, nt as contentDef, o as Macro, on as defineDialect, ot as DatetimeSchemaNode, p as collect, pt as ScalarSchemaNode, q as createExport, qt as createText, r as PrinterPartial, rn as NodeKind, rt as createContent, s as applyMacros, sn as schemaTypes, st as EnumSchemaNode, t as Printer, tn as defineNode, 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 arrowFunctionDef } from "./types-XcYJovdT.js";
|
|
5
3
|
|
|
4
|
+
//#region ../../internals/utils/src/reserved.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isValidVarName('status') // true
|
|
11
|
+
* isValidVarName('class') // false (reserved word)
|
|
12
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
declare function isValidVarName(name: string): boolean;
|
|
16
|
+
//#endregion
|
|
6
17
|
//#region src/guards.d.ts
|
|
7
18
|
/**
|
|
8
19
|
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
@@ -32,6 +43,397 @@ declare function isHttpOperationNode(node: OperationNode): node is HttpOperation
|
|
|
32
43
|
* non-required nullable field is nullish.
|
|
33
44
|
*/
|
|
34
45
|
declare function optionality(schema: SchemaNode, required: boolean): SchemaNode;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/utils/codegen.d.ts
|
|
48
|
+
/**
|
|
49
|
+
* Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no
|
|
50
|
+
* comments.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* buildJSDoc(['@type string', '@example hello'])
|
|
55
|
+
* // '/**\n * @type string\n * @example hello\n *\/\n '
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function buildJSDoc(comments: Array<string>, options?: {
|
|
59
|
+
/**
|
|
60
|
+
* String used to indent each comment line.
|
|
61
|
+
* @default ' * '
|
|
62
|
+
*/
|
|
63
|
+
indent?: string;
|
|
64
|
+
/**
|
|
65
|
+
* String appended after the closing tag.
|
|
66
|
+
* @default '\n '
|
|
67
|
+
*/
|
|
68
|
+
suffix?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Returned as-is when `comments` is empty.
|
|
71
|
+
* @default ' '
|
|
72
|
+
*/
|
|
73
|
+
fallback?: string;
|
|
74
|
+
}): string;
|
|
75
|
+
/**
|
|
76
|
+
* Renders an object key, quoting it with single quotes only when it is not a valid identifier.
|
|
77
|
+
* Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* objectKey('name') // 'name'
|
|
82
|
+
* objectKey('x-total') // "'x-total'"
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function objectKey(name: string): string;
|
|
86
|
+
/**
|
|
87
|
+
* Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
|
|
88
|
+
* level and closing the brace at column zero. Entries that are themselves multi-line objects indent
|
|
89
|
+
* cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* buildObject(['id: z.number()', 'name: z.string()'])
|
|
94
|
+
* // '{\n id: z.number(),\n name: z.string(),\n}'
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function buildObject(entries: Array<string>): string;
|
|
98
|
+
/**
|
|
99
|
+
* Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
|
|
100
|
+
* one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
|
|
101
|
+
* one level with a trailing comma and the closing bracket at column zero. Used for member lists such
|
|
102
|
+
* as `z.union([…])` and `z.array([…])`.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* buildList(['z.string()', 'z.number()'])
|
|
107
|
+
* // '[z.string(), z.number()]'
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
declare function buildList(items: Array<string>, brackets?: [open: string, close: string]): string;
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/utils/extractStringsFromNodes.d.ts
|
|
113
|
+
/**
|
|
114
|
+
* Extracts all string content from a `CodeNode` tree recursively.
|
|
115
|
+
*
|
|
116
|
+
* Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
|
|
117
|
+
* and nested node content. Used to build the full source string for import filtering.
|
|
118
|
+
*/
|
|
119
|
+
declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/utils/refs.d.ts
|
|
122
|
+
/**
|
|
123
|
+
* Returns the last path segment of a reference string.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
127
|
+
*/
|
|
128
|
+
declare function extractRefName(ref: string): string;
|
|
129
|
+
/**
|
|
130
|
+
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
131
|
+
* Returns `null` when there is no parent to nest under.
|
|
132
|
+
*
|
|
133
|
+
* @example Nested under a parent
|
|
134
|
+
* `childName('Order', 'shipping_address') // 'OrderShippingAddress'`
|
|
135
|
+
*
|
|
136
|
+
* @example No parent
|
|
137
|
+
* `childName(undefined, 'params') // null`
|
|
138
|
+
*/
|
|
139
|
+
declare function childName(parentName: string | null | undefined, propName: string): string | null;
|
|
140
|
+
/**
|
|
141
|
+
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
142
|
+
* empty parts.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`
|
|
146
|
+
*/
|
|
147
|
+
declare function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string;
|
|
148
|
+
/**
|
|
149
|
+
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
150
|
+
*
|
|
151
|
+
* Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the
|
|
152
|
+
* same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,
|
|
153
|
+
* `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref
|
|
154
|
+
* nodes and refs without a resolved `schema` are returned unchanged.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
159
|
+
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
declare function syncSchemaRef(node: SchemaNode): SchemaNode;
|
|
163
|
+
/**
|
|
164
|
+
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
165
|
+
*
|
|
166
|
+
* Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
|
|
167
|
+
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
168
|
+
*/
|
|
169
|
+
declare function isStringType(node: SchemaNode): boolean;
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/utils/schemaMerge.d.ts
|
|
172
|
+
/**
|
|
173
|
+
* Merges a run of adjacent anonymous object members into one. Named or non-object members break the
|
|
174
|
+
* run and pass through unchanged. The merge follows member order, so callers control which members
|
|
175
|
+
* combine by where they place them in the sequence.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined>;
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/utils/strings.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
|
|
187
|
+
* Returns the string unchanged when no balanced quote pair is found.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* trimQuotes('"hello"') // 'hello'
|
|
192
|
+
* trimQuotes('hello') // 'hello'
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
declare function trimQuotes(text: string): string;
|
|
196
|
+
/**
|
|
197
|
+
* Serializes a primitive to a single-quoted string literal, stripping any surrounding quotes first.
|
|
198
|
+
*
|
|
199
|
+
* Escaping runs through `JSON.stringify`, then the result switches to single quotes so the generated
|
|
200
|
+
* code matches the repo style without a formatter.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* stringify('hello') // "'hello'"
|
|
205
|
+
* stringify('"hello"') // "'hello'"
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
declare function stringify(value: string | number | boolean | undefined): string;
|
|
209
|
+
/**
|
|
210
|
+
* Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,
|
|
211
|
+
* and the Unicode line terminators U+2028 and U+2029.
|
|
212
|
+
*
|
|
213
|
+
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* jsStringEscape('say "hi"\nbye') // 'say \\"hi\\"\\nbye'
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare function jsStringEscape(input: unknown): string;
|
|
221
|
+
/**
|
|
222
|
+
* Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.
|
|
223
|
+
* Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.
|
|
224
|
+
* Pass `null` as the second argument to emit a `/pattern/flags` literal instead.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* toRegExpString('^(?im)foo') // 'new RegExp("^foo", "im")'
|
|
229
|
+
* toRegExpString('^(?im)foo', null) // '/^foo/im'
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
declare function toRegExpString(text: string, func?: string | null): string;
|
|
233
|
+
/**
|
|
234
|
+
* Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested
|
|
235
|
+
* objects recurse with fixed indentation, so the result drops straight into an object literal
|
|
236
|
+
* without re-parsing.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* stringifyObject({ foo: 'bar', nested: { a: 1 } })
|
|
241
|
+
* // 'foo: bar,\nnested: {\n a: 1\n }'
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
declare function stringifyObject(value: Record<string, unknown>): string;
|
|
245
|
+
/**
|
|
246
|
+
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
247
|
+
* `accessor`. Returns `null` for an empty path.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
252
|
+
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
declare function getNestedAccessor(param: string | Array<string>, accessor: string): string | null;
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/utils/schemaGraph.d.ts
|
|
258
|
+
/**
|
|
259
|
+
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
260
|
+
*
|
|
261
|
+
* An operation uses a schema when its parameters, request body, or responses reference it, directly
|
|
262
|
+
* or through other named schemas. Once a name is added to the result it is not revisited, so
|
|
263
|
+
* reference cycles terminate.
|
|
264
|
+
*
|
|
265
|
+
* Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.
|
|
266
|
+
*
|
|
267
|
+
* @example Only generate schemas referenced by included operations
|
|
268
|
+
* ```ts
|
|
269
|
+
* const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)
|
|
270
|
+
* const allowed = collectUsedSchemaNames(includedOps, schemas)
|
|
271
|
+
*
|
|
272
|
+
* for (const schema of schemas) {
|
|
273
|
+
* if (schema.name && !allowed.has(schema.name)) continue
|
|
274
|
+
* // generate schema
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
279
|
+
/**
|
|
280
|
+
* Finds every schema that takes part in a circular dependency chain, including direct self-loops.
|
|
281
|
+
*
|
|
282
|
+
* Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so
|
|
283
|
+
* the generated code does not recurse forever. Refs are followed by name only, so the walk stays
|
|
284
|
+
* linear in the size of the schema graph.
|
|
285
|
+
*
|
|
286
|
+
* @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.
|
|
287
|
+
*/
|
|
288
|
+
declare function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
289
|
+
/**
|
|
290
|
+
* Returns `true` when a schema, or anything nested inside it, references a circular schema.
|
|
291
|
+
*
|
|
292
|
+
* Pass `excludeName` to skip refs to a specific schema, which helps when self-references are handled
|
|
293
|
+
* on their own. Pair it with `findCircularSchemas()` to decide where lazy wrappers go.
|
|
294
|
+
*
|
|
295
|
+
* @note Stops at the first matching circular ref.
|
|
296
|
+
*/
|
|
297
|
+
declare function containsCircularRef(node: SchemaNode | undefined, {
|
|
298
|
+
circularSchemas,
|
|
299
|
+
excludeName
|
|
300
|
+
}: {
|
|
301
|
+
circularSchemas: ReadonlySet<string>;
|
|
302
|
+
excludeName?: string;
|
|
303
|
+
}): boolean;
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/utils/schemaTraversal.d.ts
|
|
306
|
+
/**
|
|
307
|
+
* Converts a child schema to printer output. Plugins instantiate it with their own output type:
|
|
308
|
+
* `string` for the zod and faker printers, `ts.TypeNode` for the TypeScript printer. A printer's
|
|
309
|
+
* `this.transform` fits directly, so its `null` for an empty result carries through to `output`.
|
|
310
|
+
*/
|
|
311
|
+
type SchemaTransform<TOutput> = (schema: SchemaNode) => TOutput;
|
|
312
|
+
/**
|
|
313
|
+
* A union or intersection member, or an array or tuple item, paired with its transformed output.
|
|
314
|
+
*/
|
|
315
|
+
type MappedSchema<TOutput> = {
|
|
316
|
+
/**
|
|
317
|
+
* The original child schema, kept so the printer can read its metadata for leaf formatting.
|
|
318
|
+
*/
|
|
319
|
+
schema: SchemaNode;
|
|
320
|
+
/**
|
|
321
|
+
* The child schema after being run through the transform.
|
|
322
|
+
*/
|
|
323
|
+
output: TOutput;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* An object property paired with its transformed output.
|
|
327
|
+
*/
|
|
328
|
+
type MappedProperty<TOutput> = {
|
|
329
|
+
/**
|
|
330
|
+
* The property name as written on the schema, before any identifier quoting.
|
|
331
|
+
*/
|
|
332
|
+
name: string;
|
|
333
|
+
/**
|
|
334
|
+
* The original property node, kept so the printer can read `required`, `schema`, and metadata.
|
|
335
|
+
*/
|
|
336
|
+
property: PropertyNode;
|
|
337
|
+
/**
|
|
338
|
+
* The property schema after being run through the transform.
|
|
339
|
+
*/
|
|
340
|
+
output: TOutput;
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Maps each property of an object schema to its transformed output. Pairs every result with the
|
|
344
|
+
* original property so the printer keeps full control over modifiers, getters, and key syntax.
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```ts
|
|
348
|
+
* const entries = mapSchemaProperties(node, (schema) => this.transform(schema))
|
|
349
|
+
* // entries: [{ name: 'id', property, output: 'z.number()' }, ...]
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
declare function mapSchemaProperties<TOutput>(node: ObjectSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedProperty<TOutput>>;
|
|
353
|
+
/**
|
|
354
|
+
* Maps each member of a union or intersection schema to its transformed output, pairing every
|
|
355
|
+
* result with the original member.
|
|
356
|
+
*/
|
|
357
|
+
declare function mapSchemaMembers<TOutput>(node: UnionSchemaNode | IntersectionSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>>;
|
|
358
|
+
/**
|
|
359
|
+
* Maps each item of an array or tuple schema to its transformed output, pairing every result with
|
|
360
|
+
* the original item.
|
|
361
|
+
*/
|
|
362
|
+
declare function mapSchemaItems<TOutput>(node: ArraySchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>>;
|
|
363
|
+
/**
|
|
364
|
+
* Emits a lazy getter for a circular-ref property position, `get name() { return body }`. The key
|
|
365
|
+
* is quoted only when it is not a valid identifier. Used by the string printers to defer evaluation
|
|
366
|
+
* of a recursive schema until first access.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* lazyGetter({ name: 'parent', body: 'z.lazy(() => Pet)' })
|
|
371
|
+
* // "get parent() { return z.lazy(() => Pet) }"
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
declare function lazyGetter({
|
|
375
|
+
name,
|
|
376
|
+
body
|
|
377
|
+
}: {
|
|
378
|
+
name: string;
|
|
379
|
+
body: string;
|
|
380
|
+
}): string;
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/macros/macroDiscriminatorEnum.d.ts
|
|
383
|
+
type Props$1 = {
|
|
384
|
+
propertyName: string;
|
|
385
|
+
values: Array<string>;
|
|
386
|
+
enumName?: string;
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* Builds a macro that replaces a discriminator property's schema with a string enum of the given
|
|
390
|
+
* values. Object schemas that lack the property are returned unchanged.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```ts
|
|
394
|
+
* const macro = macroDiscriminatorEnum({ propertyName: 'type', values: ['dog', 'cat'] })
|
|
395
|
+
* const next = applyMacros(objectSchema, [macro], { depth: 'shallow' })
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
declare function macroDiscriminatorEnum({
|
|
399
|
+
propertyName,
|
|
400
|
+
values,
|
|
401
|
+
enumName
|
|
402
|
+
}: Props$1): Macro;
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/macros/macroEnumName.d.ts
|
|
405
|
+
type Props = {
|
|
406
|
+
parentName: string | null | undefined;
|
|
407
|
+
propName: string;
|
|
408
|
+
enumSuffix: string;
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* Builds a macro that names an inline enum schema from its parent and property name. Boolean enums
|
|
412
|
+
* are left anonymous. Non-enum nodes are returned unchanged.
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```ts
|
|
416
|
+
* const macro = macroEnumName({ parentName: 'Pet', propName: 'status', enumSuffix: 'enum' })
|
|
417
|
+
* const named = applyMacros(propSchema, [macro], { depth: 'shallow' })
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
declare function macroEnumName({
|
|
421
|
+
parentName,
|
|
422
|
+
propName,
|
|
423
|
+
enumSuffix
|
|
424
|
+
}: Props): Macro;
|
|
425
|
+
//#endregion
|
|
426
|
+
//#region src/macros/macroSimplifyUnion.d.ts
|
|
427
|
+
/**
|
|
428
|
+
* Removes union members a broader scalar primitive already covers, such as a multi-value string enum
|
|
429
|
+
* sitting next to a plain `string`. Single-value enums are kept.
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```ts
|
|
433
|
+
* const next = applyMacros(unionSchema, [macroSimplifyUnion], { depth: 'shallow' })
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
declare const macroSimplifyUnion: Macro;
|
|
35
437
|
declare namespace factory_d_exports {
|
|
36
438
|
export { UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, update };
|
|
37
439
|
}
|
|
@@ -58,7 +460,18 @@ declare function update<T extends Node>(node: T, changes: Partial<T>): T;
|
|
|
58
460
|
* Every node definition. Adding a node means adding its `defineNode` to one
|
|
59
461
|
* `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
|
|
60
462
|
*/
|
|
61
|
-
declare const nodeDefs: (NodeDef<
|
|
463
|
+
declare const nodeDefs: (NodeDef<InputNode<false>, Partial<Omit<InputNode<false>, "kind">>> | NodeDef<OutputNode, Partial<Omit<OutputNode, "kind">>> | NodeDef<RequestBodyNode, Omit<RequestBodyNode, "kind">> | NodeDef<OperationNode, {
|
|
464
|
+
[key: string]: unknown;
|
|
465
|
+
operationId: string;
|
|
466
|
+
method?: HttpOperationNode["method"];
|
|
467
|
+
path?: HttpOperationNode["path"];
|
|
468
|
+
requestBody?: Omit<RequestBodyNode, "kind">;
|
|
469
|
+
}> | NodeDef<ContentNode, Omit<ContentNode, "kind">> | NodeDef<ResponseNode, Pick<ResponseNode, "statusCode"> & Partial<Omit<ResponseNode, "kind" | "content" | "statusCode">> & {
|
|
470
|
+
content?: Array<ContentNode>;
|
|
471
|
+
schema?: SchemaNode;
|
|
472
|
+
mediaType?: string | null;
|
|
473
|
+
keysToOmit?: Array<string> | null;
|
|
474
|
+
}> | NodeDef<SchemaNode, (Omit<ObjectSchemaNode, "kind" | "properties" | "primitive"> & {
|
|
62
475
|
properties?: Array<PropertyNode>;
|
|
63
476
|
primitive?: "object";
|
|
64
477
|
}) | DistributiveOmit<ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | (BaseNode & {
|
|
@@ -114,21 +527,10 @@ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<Const
|
|
|
114
527
|
format?: string;
|
|
115
528
|
} & {
|
|
116
529
|
type: "ipv6";
|
|
117
|
-
}) | ScalarSchemaNode, "kind">> | NodeDef<
|
|
118
|
-
[key: string]: unknown;
|
|
119
|
-
operationId: string;
|
|
120
|
-
method?: HttpOperationNode["method"];
|
|
121
|
-
path?: HttpOperationNode["path"];
|
|
122
|
-
requestBody?: Omit<RequestBodyNode, "kind">;
|
|
123
|
-
}> | NodeDef<ContentNode, Omit<ContentNode, "kind">> | NodeDef<ResponseNode, Pick<ResponseNode, "statusCode"> & Partial<Omit<ResponseNode, "kind" | "content" | "statusCode">> & {
|
|
124
|
-
content?: Array<ContentNode>;
|
|
125
|
-
schema?: SchemaNode;
|
|
126
|
-
mediaType?: string | null;
|
|
127
|
-
keysToOmit?: Array<string> | null;
|
|
128
|
-
}> | NodeDef<ParameterNode, Pick<ParameterNode, "name" | "schema" | "in"> & Partial<Omit<ParameterNode, "name" | "kind" | "schema" | "in">>> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[];
|
|
530
|
+
}) | ScalarSchemaNode, "kind">> | NodeDef<PropertyNode, UserPropertyNode> | 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">>)[];
|
|
129
531
|
declare namespace exports_d_exports {
|
|
130
|
-
export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, Dialect, 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, SchemaDialect, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, composeMacros, constDef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, exportDef, factory_d_exports as factory, fileDef, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef, walk };
|
|
532
|
+
export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, Dialect, 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, SchemaDialect, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, buildJSDoc, buildList, buildObject, childName, collect, collectUsedSchemaNames, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, functionDef, getNestedAccessor, importDef, inputDef, isHttpOperationNode, isStringType, isValidVarName, jsStringEscape, jsxDef, lazyGetter, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, objectKey, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, stringify, stringifyObject, syncSchemaRef, textDef, toRegExpString, transform, trimQuotes, typeDef, walk };
|
|
131
533
|
}
|
|
132
534
|
//#endregion
|
|
133
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type Dialect, 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 SchemaDialect, 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, composeMacros, constDef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, exportDef, factory_d_exports as factory, fileDef, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef, walk };
|
|
535
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type Dialect, 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 SchemaDialect, 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, buildJSDoc, buildList, buildObject, childName, collect, collectUsedSchemaNames, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, functionDef, getNestedAccessor, importDef, inputDef, isHttpOperationNode, isStringType, isValidVarName, jsStringEscape, jsxDef, lazyGetter, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, objectKey, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, stringify, stringifyObject, syncSchemaRef, textDef, toRegExpString, transform, trimQuotes, typeDef, walk };
|
|
134
536
|
//# sourceMappingURL=index.d.ts.map
|