@kubb/ast 5.0.0-beta.7 → 5.0.0-beta.71

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.
Files changed (65) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +53 -27
  3. package/dist/defineMacro-5Dvct8k_.cjs +114 -0
  4. package/dist/defineMacro-5Dvct8k_.cjs.map +1 -0
  5. package/dist/defineMacro-BXpTwp0y.d.ts +466 -0
  6. package/dist/defineMacro-VfsvblGi.js +98 -0
  7. package/dist/defineMacro-VfsvblGi.js.map +1 -0
  8. package/dist/index-DJEyS5y6.d.ts +2428 -0
  9. package/dist/index.cjs +198 -2239
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +98 -3400
  12. package/dist/index.js +149 -2160
  13. package/dist/index.js.map +1 -1
  14. package/dist/macros.cjs +130 -0
  15. package/dist/macros.cjs.map +1 -0
  16. package/dist/macros.d.ts +61 -0
  17. package/dist/macros.js +128 -0
  18. package/dist/macros.js.map +1 -0
  19. package/dist/operationParams-BaY12i2I.d.ts +148 -0
  20. package/dist/refs-D18OeCgb.js +117 -0
  21. package/dist/refs-D18OeCgb.js.map +1 -0
  22. package/dist/refs-DuP3_Leg.cjs +157 -0
  23. package/dist/refs-DuP3_Leg.cjs.map +1 -0
  24. package/dist/rolldown-runtime-CNktS9qV.js +17 -0
  25. package/dist/types-BsP1SK9j.d.ts +244 -0
  26. package/dist/types.cjs +0 -0
  27. package/dist/types.d.ts +5 -0
  28. package/dist/types.js +1 -0
  29. package/dist/utils.cjs +803 -0
  30. package/dist/utils.cjs.map +1 -0
  31. package/dist/utils.d.ts +354 -0
  32. package/dist/utils.js +777 -0
  33. package/dist/utils.js.map +1 -0
  34. package/dist/visitor-CQdSiClY.cjs +1749 -0
  35. package/dist/visitor-CQdSiClY.cjs.map +1 -0
  36. package/dist/visitor-dcVC5TOW.js +1313 -0
  37. package/dist/visitor-dcVC5TOW.js.map +1 -0
  38. package/package.json +17 -5
  39. package/dist/chunk--u3MIqq1.js +0 -8
  40. package/src/constants.ts +0 -228
  41. package/src/factory.ts +0 -742
  42. package/src/guards.ts +0 -110
  43. package/src/index.ts +0 -46
  44. package/src/infer.ts +0 -130
  45. package/src/mocks.ts +0 -176
  46. package/src/nodes/base.ts +0 -56
  47. package/src/nodes/code.ts +0 -304
  48. package/src/nodes/file.ts +0 -230
  49. package/src/nodes/function.ts +0 -223
  50. package/src/nodes/http.ts +0 -119
  51. package/src/nodes/index.ts +0 -86
  52. package/src/nodes/operation.ts +0 -111
  53. package/src/nodes/output.ts +0 -26
  54. package/src/nodes/parameter.ts +0 -41
  55. package/src/nodes/property.ts +0 -34
  56. package/src/nodes/response.ts +0 -43
  57. package/src/nodes/root.ts +0 -64
  58. package/src/nodes/schema.ts +0 -656
  59. package/src/printer.ts +0 -250
  60. package/src/refs.ts +0 -67
  61. package/src/resolvers.ts +0 -45
  62. package/src/transformers.ts +0 -159
  63. package/src/types.ts +0 -70
  64. package/src/utils.ts +0 -915
  65. package/src/visitor.ts +0 -592
@@ -0,0 +1,244 @@
1
+ import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
2
+ import { _t as SchemaNode, vt as SchemaNodeByType, yt as SchemaType } from "./index-DJEyS5y6.js";
3
+
4
+ //#region src/defineDialect.d.ts
5
+ /**
6
+ * The spec-specific questions a schema parser answers while turning a source document into Kubb
7
+ * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where
8
+ * OpenAPI, AsyncAPI, and plain JSON Schema differ.
9
+ */
10
+ type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {
11
+ /**
12
+ * Whether the schema is nullable.
13
+ */
14
+ isNullable(schema?: TSchema): boolean;
15
+ /**
16
+ * Whether the value is a `$ref` pointer.
17
+ */
18
+ isReference(value?: unknown): value is TRef;
19
+ /**
20
+ * Whether the schema carries a discriminator for polymorphism.
21
+ */
22
+ isDiscriminator(value?: unknown): value is TDiscriminated;
23
+ /**
24
+ * Whether the schema is binary data, converted to a `blob` node.
25
+ */
26
+ isBinary(schema: TSchema): boolean;
27
+ /**
28
+ * Resolves a local `$ref` against the document, or nullish when it cannot.
29
+ */
30
+ resolveRef<TResolved>(document: TDocument, ref: string): TResolved | null | undefined;
31
+ };
32
+ /**
33
+ * A spec adapter's dialect. `name` identifies it in logs and diagnostics, and `schema` holds the
34
+ * spec-specific schema questions the parser answers.
35
+ */
36
+ type Dialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {
37
+ /**
38
+ * Identifies the dialect in logs and diagnostics.
39
+ */
40
+ name: string;
41
+ /**
42
+ * The spec-specific schema behavior. See {@link SchemaDialect}.
43
+ */
44
+ schema: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>;
45
+ };
46
+ /**
47
+ * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the
48
+ * dialect's type for inference.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * export const oasDialect = defineDialect({
53
+ * name: 'oas',
54
+ * schema: {
55
+ * isNullable,
56
+ * isReference,
57
+ * isDiscriminator,
58
+ * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',
59
+ * resolveRef,
60
+ * },
61
+ * })
62
+ * ```
63
+ */
64
+ declare function defineDialect<TSchema, TRef, TDiscriminated, TDocument>(dialect: Dialect<TSchema, TRef, TDiscriminated, TDocument>): Dialect<TSchema, TRef, TDiscriminated, TDocument>;
65
+ //#endregion
66
+ //#region src/createPrinter.d.ts
67
+ /**
68
+ * Runtime context passed as `this` to printer handlers.
69
+ *
70
+ * `this.transform` dispatches to node-level handlers from `nodes`.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const context: PrinterHandlerContext<string, {}> = {
75
+ * options: {},
76
+ * transform: () => 'value',
77
+ * }
78
+ * ```
79
+ */
80
+ type PrinterHandlerContext<TOutput, TOptions extends object> = {
81
+ /**
82
+ * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.
83
+ * Use `this.transform` inside `nodes` handlers and inside the `print` override.
84
+ */
85
+ transform: (node: SchemaNode) => TOutput | null;
86
+ /**
87
+ * Options for this printer instance.
88
+ */
89
+ options: TOptions;
90
+ };
91
+ /**
92
+ * Handler for one schema node type.
93
+ *
94
+ * Use a regular function (not an arrow function) if you need `this`.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const handler: PrinterHandler<string, {}, 'string'> = function () {
99
+ * return 'string'
100
+ * }
101
+ * ```
102
+ */
103
+ type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null;
104
+ /**
105
+ * Partial map of per-node-type handler overrides for a printer.
106
+ *
107
+ * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).
108
+ * Supply only the handlers you want to replace. The printer's built-in
109
+ * defaults fill in the rest.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * pluginZod({
114
+ * printer: {
115
+ * nodes: {
116
+ * date(): string {
117
+ * return 'z.string().date()'
118
+ * },
119
+ * } satisfies PrinterPartial<string, PrinterZodOptions>,
120
+ * },
121
+ * })
122
+ * ```
123
+ */
124
+ type PrinterPartial<TOutput, TOptions extends object> = Partial<{ [K in SchemaType]: PrinterHandler<TOutput, TOptions, K> }>;
125
+ /**
126
+ * Generic shape used by `definePrinter`.
127
+ *
128
+ * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)
129
+ * - `TOptions` options passed to and stored on the printer instance
130
+ * - `TOutput` the type emitted by node handlers
131
+ * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>
136
+ * ```
137
+ */
138
+ type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
139
+ name: TName;
140
+ options: TOptions;
141
+ output: TOutput;
142
+ printOutput: TPrintOutput;
143
+ };
144
+ /**
145
+ * Printer instance returned by a printer factory.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})
150
+ * ```
151
+ */
152
+ type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
153
+ /**
154
+ * Unique identifier supplied at creation time.
155
+ */
156
+ name: T['name'];
157
+ /**
158
+ * Options for this printer instance.
159
+ */
160
+ options: T['options'];
161
+ /**
162
+ * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
163
+ * Always dispatches through the `nodes` map. Never calls the `print` override.
164
+ * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
165
+ */
166
+ transform: (node: SchemaNode) => T['output'] | null;
167
+ /**
168
+ * Public printer. If the builder provides a root-level `print`, this calls that
169
+ * higher-level function (which may produce full declarations).
170
+ * Otherwise, falls back to the node-level dispatcher.
171
+ */
172
+ print: (node: SchemaNode) => T['printOutput'] | null;
173
+ };
174
+ /**
175
+ * Builder function passed to `definePrinter`.
176
+ *
177
+ * It receives resolved options and returns:
178
+ * - `name`
179
+ * - `options`
180
+ * - `nodes` handlers
181
+ * - optional top-level `print` override
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })
186
+ * ```
187
+ */
188
+ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
189
+ name: T['name'];
190
+ /**
191
+ * Options to store on the printer.
192
+ */
193
+ options: T['options'];
194
+ nodes: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
195
+ /**
196
+ * Optional root-level print override. When provided, becomes the public `printer.print`.
197
+ * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
198
+ * not the override itself, so recursion is safe.
199
+ */
200
+ print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null;
201
+ };
202
+ /**
203
+ * Creates a schema printer: a function that takes a `SchemaNode` and emits
204
+ * code in your target language. Each plugin that produces code from schemas
205
+ * (TypeScript types, Zod schemas, Faker factories) ships a printer built
206
+ * with this helper.
207
+ *
208
+ * The builder receives resolved options and returns:
209
+ *
210
+ * - `name` unique identifier for the printer.
211
+ * - `options` stored on the returned printer instance.
212
+ * - `nodes` map of `SchemaType` → handler. Handlers return the rendered
213
+ * output (a string, a TypeScript AST node, ...) for that schema type.
214
+ * - `print` (optional), top-level override exposed as `printer.print`.
215
+ * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
216
+ *
217
+ * Without a `print` override, `printer.print` falls back to `printer.transform`
218
+ * (the node-level dispatcher).
219
+ *
220
+ * @example Tiny Zod printer
221
+ * ```ts
222
+ * import { createPrinter, type PrinterFactoryOptions } from '@kubb/ast'
223
+ *
224
+ * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
225
+ *
226
+ * export const zodPrinter = createPrinter<PrinterZod>((options) => ({
227
+ * name: 'zod',
228
+ * options: { strict: options.strict ?? true },
229
+ * nodes: {
230
+ * string: () => 'z.string()',
231
+ * object(node) {
232
+ * const props = node.properties
233
+ * .map((p) => `${p.name}: ${this.transform(p.schema)}`)
234
+ * .join(', ')
235
+ * return `z.object({ ${props} })`
236
+ * },
237
+ * },
238
+ * }))
239
+ * ```
240
+ */
241
+ declare function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
242
+ //#endregion
243
+ export { Dialect as a, createPrinter as i, PrinterFactoryOptions as n, SchemaDialect as o, PrinterPartial as r, defineDialect as s, Printer as t };
244
+ //# sourceMappingURL=types-BsP1SK9j.d.ts.map
package/dist/types.cjs ADDED
File without changes
@@ -0,0 +1,5 @@
1
+ import { c as VisitorContext, n as Macro, o as ParentOf, s as Visitor, t as Enforce } from "./defineMacro-BXpTwp0y.js";
2
+ import { a as Dialect, n as PrinterFactoryOptions, o as SchemaDialect, r as PrinterPartial, t as Printer } from "./types-BsP1SK9j.js";
3
+ import { A as IndexedAccessTypeNode, At as InferSchemaNode, Bt as TypeNode, C as ParameterNode, Ct as UrlSchemaNode, D as FunctionParamNode, E as FunctionParamKind, Et as PropertyNode, Ft as ConstNode, G as FileNode, It as FunctionNode, J as UserFileNode, K as ImportNode, Lt as JSDocNode, M as TypeExpression, Mt as ArrowFunctionNode, N as TypeLiteralNode, Nt as BreakNode, O as FunctionParameterNode, Pt as CodeNode, Rt as JsxNode, S as ParameterLocation, St as UnionSchemaNode, W as ExportNode, _t as SchemaNode, a as InputMeta, an as NodeKind, bt as StringSchemaNode, ct as DatetimeSchemaNode, d as HttpOperationNode, dt as NumberSchemaNode, f as OperationNode, ft as ObjectSchemaNode, g as StatusCode, gt as ScalarSchemaType, h as ResponseNode, ht as ScalarSchemaNode, j as ObjectBindingPatternNode, jt as ParserOptions, k as FunctionParametersNode, l as GenericOperationNode, lt as EnumSchemaNode, mt as RefSchemaNode, n as OutputNode, nn as NodeDef, o as InputNode, ot as ArraySchemaNode, pt as PrimitiveSchemaType, q as SourceNode, rt as ContentNode, st as DateSchemaNode, t as Node, tn as DistributiveOmit, u as HttpMethod, ut as IntersectionSchemaNode, vt as SchemaNodeByType, xt as TimeSchemaNode, y as RequestBodyNode, yt as SchemaType, zt as TextNode } from "./index-DJEyS5y6.js";
4
+ import { t as OperationParamsResolver } from "./operationParams-BaY12i2I.js";
5
+ export type { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, Dialect, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, FunctionParamKind, FunctionParamNode, FunctionParameterNode, FunctionParametersNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, IndexedAccessTypeNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectBindingPatternNode, ObjectSchemaNode, OperationNode, OperationParamsResolver, OutputNode, ParameterLocation, ParameterNode, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaDialect, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeExpression, TypeLiteralNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};