@kubb/ast 5.0.0-beta.8 → 5.0.0-beta.80

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 (64) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +53 -27
  3. package/dist/defineMacro-CqX4m8Dq.js +98 -0
  4. package/dist/defineMacro-CqX4m8Dq.js.map +1 -0
  5. package/dist/defineMacro-DmGR7vfu.cjs +114 -0
  6. package/dist/defineMacro-DmGR7vfu.cjs.map +1 -0
  7. package/dist/defineMacro-DzsACbFo.d.ts +466 -0
  8. package/dist/index-Cu2zmNxv.d.ts +2188 -0
  9. package/dist/index.cjs +194 -2239
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +88 -3405
  12. package/dist/index.js +150 -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/refs-Bg3rmujP.cjs +135 -0
  20. package/dist/refs-Bg3rmujP.cjs.map +1 -0
  21. package/dist/refs-BjBHwunY.js +101 -0
  22. package/dist/refs-BjBHwunY.js.map +1 -0
  23. package/dist/rolldown-runtime-CNktS9qV.js +17 -0
  24. package/dist/types-CWF7DV0f.d.ts +259 -0
  25. package/dist/types.cjs +0 -0
  26. package/dist/types.d.ts +4 -0
  27. package/dist/types.js +1 -0
  28. package/dist/utils.cjs +613 -0
  29. package/dist/utils.cjs.map +1 -0
  30. package/dist/utils.d.ts +353 -0
  31. package/dist/utils.js +589 -0
  32. package/dist/utils.js.map +1 -0
  33. package/dist/visitor-Dk0DNLfC.js +1203 -0
  34. package/dist/visitor-Dk0DNLfC.js.map +1 -0
  35. package/dist/visitor-h6dEM3vR.cjs +1567 -0
  36. package/dist/visitor-h6dEM3vR.cjs.map +1 -0
  37. package/package.json +17 -5
  38. package/dist/chunk--u3MIqq1.js +0 -8
  39. package/src/constants.ts +0 -228
  40. package/src/factory.ts +0 -742
  41. package/src/guards.ts +0 -110
  42. package/src/index.ts +0 -46
  43. package/src/infer.ts +0 -130
  44. package/src/mocks.ts +0 -176
  45. package/src/nodes/base.ts +0 -56
  46. package/src/nodes/code.ts +0 -304
  47. package/src/nodes/file.ts +0 -230
  48. package/src/nodes/function.ts +0 -223
  49. package/src/nodes/http.ts +0 -119
  50. package/src/nodes/index.ts +0 -86
  51. package/src/nodes/operation.ts +0 -111
  52. package/src/nodes/output.ts +0 -26
  53. package/src/nodes/parameter.ts +0 -41
  54. package/src/nodes/property.ts +0 -34
  55. package/src/nodes/response.ts +0 -43
  56. package/src/nodes/root.ts +0 -64
  57. package/src/nodes/schema.ts +0 -656
  58. package/src/printer.ts +0 -250
  59. package/src/refs.ts +0 -67
  60. package/src/resolvers.ts +0 -45
  61. package/src/transformers.ts +0 -159
  62. package/src/types.ts +0 -70
  63. package/src/utils.ts +0 -915
  64. package/src/visitor.ts +0 -592
@@ -0,0 +1,259 @@
1
+ import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
2
+ import { et as SchemaNode, nt as SchemaType, tt as SchemaNodeByType } from "./index-Cu2zmNxv.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, so this is the one seam where source formats
8
+ * 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
+ * Run the printer's built-in handler for the node, ignoring any override for its type.
88
+ * Inside an override, `this.base(node)` returns what the printer would have emitted,
89
+ * so the override can wrap it instead of re-implementing the handler. Nested nodes
90
+ * still dispatch through the overrides.
91
+ */
92
+ base: (node: SchemaNode) => TOutput | null;
93
+ /**
94
+ * Options for this printer instance.
95
+ */
96
+ options: TOptions;
97
+ };
98
+ /**
99
+ * Handler for one schema node type.
100
+ *
101
+ * Use a regular function (not an arrow function) if you need `this`.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * const handler: PrinterHandler<string, {}, 'string'> = function () {
106
+ * return 'string'
107
+ * }
108
+ * ```
109
+ */
110
+ type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null;
111
+ /**
112
+ * Partial map of per-node-type handler overrides for a printer.
113
+ *
114
+ * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).
115
+ * Supply only the handlers you want to replace. The printer's built-in
116
+ * defaults fill in the rest.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * pluginZod({
121
+ * printer: {
122
+ * nodes: {
123
+ * date(): string {
124
+ * return 'z.string().date()'
125
+ * },
126
+ * } satisfies PrinterPartial<string, PrinterZodOptions>,
127
+ * },
128
+ * })
129
+ * ```
130
+ */
131
+ type PrinterPartial<TOutput, TOptions extends object> = Partial<{ [K in SchemaType]: PrinterHandler<TOutput, TOptions, K> }>;
132
+ /**
133
+ * Generic shape used by `definePrinter`.
134
+ *
135
+ * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)
136
+ * - `TOptions` options passed to and stored on the printer instance
137
+ * - `TOutput` the type emitted by node handlers
138
+ * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>
143
+ * ```
144
+ */
145
+ type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
146
+ name: TName;
147
+ options: TOptions;
148
+ output: TOutput;
149
+ printOutput: TPrintOutput;
150
+ };
151
+ /**
152
+ * Printer instance returned by a printer factory.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})
157
+ * ```
158
+ */
159
+ type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
160
+ /**
161
+ * Unique identifier supplied at creation time.
162
+ */
163
+ name: T['name'];
164
+ /**
165
+ * Options for this printer instance.
166
+ */
167
+ options: T['options'];
168
+ /**
169
+ * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
170
+ * Always dispatches through the `nodes` map. Never calls the `print` override.
171
+ * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
172
+ */
173
+ transform: (node: SchemaNode) => T['output'] | null;
174
+ /**
175
+ * Public printer. If the builder provides a root-level `print`, this calls that
176
+ * higher-level function (which may produce full declarations).
177
+ * Otherwise, falls back to the node-level dispatcher.
178
+ */
179
+ print: (node: SchemaNode) => T['printOutput'] | null;
180
+ };
181
+ /**
182
+ * Builder function passed to `definePrinter`.
183
+ *
184
+ * It receives resolved options and returns:
185
+ * - `name`
186
+ * - `options`
187
+ * - `nodes` handlers
188
+ * - optional top-level `print` override
189
+ *
190
+ * @example
191
+ * ```ts
192
+ * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })
193
+ * ```
194
+ */
195
+ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
196
+ name: T['name'];
197
+ /**
198
+ * Options to store on the printer.
199
+ */
200
+ options: T['options'];
201
+ nodes: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
202
+ /**
203
+ * User-supplied handler overrides. An override wins over the matching `nodes` handler,
204
+ * and can call `this.base(node)` to reuse the handler it replaced. Pass overrides here
205
+ * instead of spreading them into `nodes`, otherwise `this.base` cannot find the original.
206
+ */
207
+ overrides?: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
208
+ /**
209
+ * Optional root-level print override. When provided, becomes the public `printer.print`.
210
+ * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
211
+ * not the override itself, so recursion is safe.
212
+ */
213
+ print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null;
214
+ };
215
+ /**
216
+ * Creates a schema printer: a function that takes a `SchemaNode` and emits
217
+ * code in your target language. Each plugin that produces code from schemas
218
+ * (TypeScript types, Zod schemas, Faker factories) ships a printer built
219
+ * with this helper.
220
+ *
221
+ * The builder receives resolved options and returns:
222
+ *
223
+ * - `name` unique identifier for the printer.
224
+ * - `options` stored on the returned printer instance.
225
+ * - `nodes` map of `SchemaType` → handler. Handlers return the rendered
226
+ * output (a string, a TypeScript AST node, ...) for that schema type.
227
+ * - `overrides` (optional), user-supplied handlers that win over `nodes`.
228
+ * An override can call `this.base(node)` to reuse the handler it replaced.
229
+ * - `print` (optional), top-level override exposed as `printer.print`.
230
+ * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
231
+ *
232
+ * Without a `print` override, `printer.print` falls back to `printer.transform`
233
+ * (the node-level dispatcher).
234
+ *
235
+ * @example Tiny Zod printer
236
+ * ```ts
237
+ * import { createPrinter, type PrinterFactoryOptions } from '@kubb/ast'
238
+ *
239
+ * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
240
+ *
241
+ * export const zodPrinter = createPrinter<PrinterZod>((options) => ({
242
+ * name: 'zod',
243
+ * options: { strict: options.strict ?? true },
244
+ * nodes: {
245
+ * string: () => 'z.string()',
246
+ * object(node) {
247
+ * const props = node.properties
248
+ * .map((p) => `${p.name}: ${this.transform(p.schema)}`)
249
+ * .join(', ')
250
+ * return `z.object({ ${props} })`
251
+ * },
252
+ * },
253
+ * }))
254
+ * ```
255
+ */
256
+ declare function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
257
+ //#endregion
258
+ export { Dialect as a, createPrinter as i, PrinterFactoryOptions as n, SchemaDialect as o, PrinterPartial as r, defineDialect as s, Printer as t };
259
+ //# sourceMappingURL=types-CWF7DV0f.d.ts.map
package/dist/types.cjs ADDED
File without changes
@@ -0,0 +1,4 @@
1
+ import { c as VisitorContext, n as Macro, o as ParentOf, s as Visitor, t as Enforce } from "./defineMacro-DzsACbFo.js";
2
+ import { a as Dialect, n as PrinterFactoryOptions, o as SchemaDialect, r as PrinterPartial, t as Printer } from "./types-CWF7DV0f.js";
3
+ import { $ as ScalarSchemaType, A as SourceNode, B as ContentNode, C as ParameterNode, Ct as TypeNode, D as ExportNode, G as DatetimeSchemaNode, Ht as NodeKind, J as NumberSchemaNode, K as EnumSchemaNode, O as FileNode, Q as ScalarSchemaNode, Rt as DistributiveOmit, S as ParameterLocation, St as TextNode, U as ArraySchemaNode, W as DateSchemaNode, X as PrimitiveSchemaType, Y as ObjectSchemaNode, Z as RefSchemaNode, _t as CodeNode, a as InputMeta, at as UnionSchemaNode, bt as JSDocNode, d as HttpOperationNode, et as SchemaNode, f as OperationNode, g as StatusCode, gt as BreakNode, h as ResponseNode, ht as ArrowFunctionNode, it as TimeSchemaNode, j as UserFileNode, k as ImportNode, l as GenericOperationNode, lt as PropertyNode, mt as ParserOptions, n as OutputNode, nt as SchemaType, o as InputNode, ot as UrlSchemaNode, pt as InferSchemaNode, q as IntersectionSchemaNode, rt as StringSchemaNode, t as Node, tt as SchemaNodeByType, u as HttpMethod, vt as ConstNode, w as ParameterStyle, xt as JsxNode, y as RequestBodyNode, yt as FunctionNode, zt as NodeDef } from "./index-Cu2zmNxv.js";
4
+ export type { 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 };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};