@kubb/plugin-valibot 0.0.0-stage → 0.0.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.js ADDED
@@ -0,0 +1,2096 @@
1
+ import { Diagnostics, Resolver, addGenerator, ast, casing, createPrinter, createResolver, defineExtension, defineGenerator, setMacros, setResolver, text } from "@kubb/kit";
2
+ import { Const, File, Function, Type, jsxRenderer } from "@kubb/renderer-jsx";
3
+ import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
4
+ // ../../internals/utils/src/reserved.ts
5
+ /**
6
+ * JavaScript and Java reserved words.
7
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
8
+ */
9
+ const reservedWords = /* @__PURE__ */ new Set([
10
+ "abstract",
11
+ "arguments",
12
+ "await",
13
+ "boolean",
14
+ "break",
15
+ "byte",
16
+ "case",
17
+ "catch",
18
+ "char",
19
+ "class",
20
+ "const",
21
+ "continue",
22
+ "debugger",
23
+ "default",
24
+ "delete",
25
+ "do",
26
+ "double",
27
+ "else",
28
+ "enum",
29
+ "eval",
30
+ "export",
31
+ "extends",
32
+ "false",
33
+ "final",
34
+ "finally",
35
+ "float",
36
+ "for",
37
+ "function",
38
+ "goto",
39
+ "if",
40
+ "implements",
41
+ "import",
42
+ "in",
43
+ "instanceof",
44
+ "int",
45
+ "interface",
46
+ "let",
47
+ "long",
48
+ "native",
49
+ "new",
50
+ "null",
51
+ "package",
52
+ "private",
53
+ "protected",
54
+ "public",
55
+ "return",
56
+ "short",
57
+ "static",
58
+ "super",
59
+ "switch",
60
+ "synchronized",
61
+ "this",
62
+ "throw",
63
+ "throws",
64
+ "transient",
65
+ "true",
66
+ "try",
67
+ "typeof",
68
+ "var",
69
+ "void",
70
+ "volatile",
71
+ "while",
72
+ "with",
73
+ "yield",
74
+ "Array",
75
+ "Date",
76
+ "hasOwnProperty",
77
+ "Infinity",
78
+ "isFinite",
79
+ "isNaN",
80
+ "isPrototypeOf",
81
+ "length",
82
+ "Math",
83
+ "name",
84
+ "NaN",
85
+ "Number",
86
+ "Object",
87
+ "prototype",
88
+ "String",
89
+ "toString",
90
+ "undefined",
91
+ "valueOf"
92
+ ]);
93
+ /**
94
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * isValidVarName('status') // true
99
+ * isValidVarName('class') // false (reserved word)
100
+ * isValidVarName('42foo') // false (starts with digit)
101
+ * ```
102
+ */
103
+ function isValidVarName(name) {
104
+ if (!name || reservedWords.has(name)) return false;
105
+ return isIdentifier(name);
106
+ }
107
+ /**
108
+ * Returns `name` when it's a syntactically valid JavaScript variable name,
109
+ * otherwise prefixes it with `_` so the result is a valid identifier.
110
+ *
111
+ * Useful for sanitizing OpenAPI schema names or operation IDs that start with
112
+ * a digit (e.g. `409`, `504AccountCancel`) before using them as exported
113
+ * variable, type, or function names.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * ensureValidVarName('409') // '_409'
118
+ * ensureValidVarName('504AccountCancel') // '_504AccountCancel'
119
+ * ensureValidVarName('Pet') // 'Pet'
120
+ * ensureValidVarName('class') // '_class'
121
+ * ```
122
+ */
123
+ function ensureValidVarName(name) {
124
+ if (!name || isValidVarName(name)) return name;
125
+ return `_${name}`;
126
+ }
127
+ /**
128
+ * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
129
+ *
130
+ * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
131
+ * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
132
+ * deciding whether an object key needs quoting.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * isIdentifier('name') // true
137
+ * isIdentifier('x-total')// false
138
+ * ```
139
+ */
140
+ function isIdentifier(name) {
141
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
142
+ }
143
+ // ../../internals/utils/src/codegen.ts
144
+ /**
145
+ * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
146
+ * level and closing the brace at column zero. Entries that are themselves multi-line objects indent
147
+ * cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * buildObject(['id: z.number()', 'name: z.string()'])
152
+ * // '{\n id: z.number(),\n name: z.string(),\n}'
153
+ * ```
154
+ */
155
+ function buildObject(entries) {
156
+ if (entries.length === 0) return "{}";
157
+ return `{\n${entries.map((entry) => `${text.indent({ text: entry })},`).join("\n")}\n}`;
158
+ }
159
+ /**
160
+ * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
161
+ * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
162
+ * one level with a trailing comma and the closing bracket at column zero. Used for member lists such
163
+ * as `z.union([…])` and `z.array([…])`.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * buildList(['z.string()', 'z.number()'])
168
+ * // '[z.string(), z.number()]'
169
+ * ```
170
+ */
171
+ function buildList(items, brackets = ["[", "]"]) {
172
+ const [open, close] = brackets;
173
+ if (items.length === 0) return `${open}${close}`;
174
+ if (!items.some((item) => item.includes("\n"))) return `${open}${items.join(", ")}${close}`;
175
+ return `${open}\n${items.map((item) => `${text.indent({ text: item })},`).join("\n")}\n${close}`;
176
+ }
177
+ /**
178
+ * An object key, quoted only when it is not identifier-shaped. Reserved words such as `class` stay bare.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * objectKey('x-total') // "'x-total'"
183
+ * ```
184
+ */
185
+ function objectKey(name) {
186
+ return isIdentifier(name) ? name : text.quote(name);
187
+ }
188
+ // ../../internals/utils/src/fs.ts
189
+ /**
190
+ * Builds a nested file path from a dotted name. Splits on dots that precede a letter
191
+ * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
192
+ * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
193
+ *
194
+ * Empty segments are dropped before joining. They arise when the name starts with a dot
195
+ * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
196
+ * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
197
+ * absolute path, letting generated files escape the configured output directory.
198
+ *
199
+ * @example Nested path from a dotted name
200
+ * `toFilePath('pet.petId') // 'pet/petId'`
201
+ *
202
+ * @example PascalCase the final segment
203
+ * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
204
+ *
205
+ * @example Suffix applied to the final segment only
206
+ * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
207
+ */
208
+ function toFilePath(name, caseLast = casing.camel) {
209
+ const parts = name.split(/\.(?=[a-zA-Z])/);
210
+ return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : casing.camel(part)).filter(Boolean).join("/");
211
+ }
212
+ // ../../internals/utils/src/strings.ts
213
+ const NEEDS_UNICODE = /(?<!\\)(?:\\\\)*\\[pPu]\{|[\u{10000}-\u{10FFFF}]/u;
214
+ const KEPT_ESCAPE = /[A-Za-z0-9^$\\.*+?()[\]{}|/]/;
215
+ /**
216
+ * Drops the backslash from escapes that the `u` flag rejects: an escaped punctuation character that is
217
+ * not a syntax character, and `\-` outside a class. Both match the same character without the backslash.
218
+ */
219
+ function dropIdentityEscapes(pattern) {
220
+ let inClass = false;
221
+ return pattern.replace(/\\(.)|[[\]]/gs, (match, escaped) => {
222
+ if (escaped === void 0) {
223
+ inClass = match === "[";
224
+ return match;
225
+ }
226
+ return KEPT_ESCAPE.test(escaped) || escaped === "-" && inClass ? match : escaped;
227
+ });
228
+ }
229
+ /**
230
+ * Builds the `RegExp` for a pattern, adding the `u` flag when it uses `\p{...}`, `\P{...}` or `\u{...}`, or
231
+ * holds a character outside the BMP. A pattern that is not valid under `u` keeps the flags it came with.
232
+ */
233
+ function toRegExp(pattern, flags) {
234
+ if (flags?.includes("u") || !NEEDS_UNICODE.test(pattern)) return new RegExp(pattern, flags);
235
+ try {
236
+ return new RegExp(dropIdentityEscapes(pattern), `${flags ?? ""}u`);
237
+ } catch {
238
+ return new RegExp(pattern, flags);
239
+ }
240
+ }
241
+ /**
242
+ * Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.
243
+ * Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.
244
+ * Pass `null` as the second argument to emit a `/pattern/flags` literal instead.
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * toRegExpString('^(?im)foo') // 'new RegExp("^foo", "im")'
249
+ * toRegExpString('^(?im)foo', null) // '/^foo/im'
250
+ * ```
251
+ */
252
+ function toRegExpString(pattern, func = "RegExp") {
253
+ const raw = text.unquote(pattern);
254
+ const match = raw.match(/^\^(\(\?([igmsuy]+)\))/i);
255
+ const replacementTarget = match?.[1] ?? "";
256
+ const matchedFlags = match?.[2];
257
+ const { source, flags } = toRegExp(raw.replace(/^\\?\//, "").replace(/\\?\/$/, "").replace(replacementTarget, ""), matchedFlags);
258
+ if (func === null) return `/${source}/${flags}`;
259
+ return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ""})`;
260
+ }
261
+ /**
262
+ * Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
263
+ * Editors render `\@` as `@` in hovers.
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * jsDocEscape('intro\n@example value') // 'intro\n\\@example value'
268
+ * ```
269
+ */
270
+ function jsDocEscape(input) {
271
+ return `${input}`.replace(/^(\s*)@/gm, "$1\\@");
272
+ }
273
+ // ../../internals/shared/src/operation.ts
274
+ /**
275
+ * Builds the `ResolverFileParams` every operation generator passes to
276
+ * `resolver.file`: a file named `name`, tagged by the operation's first
277
+ * tag (or `'default'`), at the operation's path. Centralizes the entry object
278
+ * that was repeated at dozens of call sites across the client and query plugins.
279
+ *
280
+ * @example
281
+ * ```ts
282
+ * resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
283
+ * ```
284
+ */
285
+ function operationFileEntry(node, name, extname = ".ts") {
286
+ return {
287
+ name,
288
+ extname,
289
+ tag: node.tags[0] ?? "default",
290
+ path: node.path
291
+ };
292
+ }
293
+ /**
294
+ * Resolves the file a schema-emitting plugin (`plugin-ts`, `plugin-zod`, `plugin-faker`) writes
295
+ * `node` to, cached in `ctx.memo` under the resolver's plugin name and the
296
+ * operation. The plugin itself and every plugin that imports from it call this, so they all get
297
+ * the same path.
298
+ *
299
+ * When that path matches the file of a component schema in `ctx.schemas`, ignoring case, the file name
300
+ * gets an `Operation` suffix: operation `point` goes to `PointOperation.ts` next to schema `Point.ts`.
301
+ * Otherwise the two merge into one file, or overwrite each other on a case-insensitive file system.
302
+ * Only the file name changes. The declarations keep their names.
303
+ *
304
+ * @example Resolve `plugin-ts`'s file for the current operation
305
+ * ```ts
306
+ * const fileTs = resolveOperationFile({ ctx, node, resolver: tsResolver, root, output })
307
+ * ```
308
+ */
309
+ function resolveOperationFile(options) {
310
+ const { ctx, node, resolver, root, output } = options;
311
+ const { memo } = ctx;
312
+ const location = {
313
+ root,
314
+ output,
315
+ group: options.group ?? void 0
316
+ };
317
+ return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () => {
318
+ const schemaPaths = memo(`${resolver.pluginName}:schemaFilePaths`, () => new Set(ctx.schemas.flatMap((schema) => schema.name ? [resolver.file({
319
+ name: schema.name,
320
+ extname: ".ts",
321
+ ...location
322
+ }).path.toLowerCase()] : [])));
323
+ let file = resolver.file({
324
+ ...operationFileEntry(node, node.operationId),
325
+ ...location
326
+ });
327
+ for (let name = `${node.operationId}Operation`; schemaPaths.has(file.path.toLowerCase()); name += "Operation") {
328
+ const next = resolver.file({
329
+ ...operationFileEntry(node, name),
330
+ ...location
331
+ });
332
+ if (next.path === file.path) break;
333
+ file = next;
334
+ }
335
+ return file;
336
+ });
337
+ }
338
+ /**
339
+ * How a content entry is framed as a stream: `'events'` for Server-Sent Events, `'lines'` for JSON Lines.
340
+ */
341
+ function getStreamFraming(entry) {
342
+ if (ast.mediaType.getBase(entry) === "text/event-stream") return "events";
343
+ return entry.stream && ast.mediaType.isStream(entry) ? "lines" : void 0;
344
+ }
345
+ /**
346
+ * Parser for one response content entry.
347
+ *
348
+ * JSON stays unset so the runtime detects it. `text/event-stream` and JSON Lines are streams. A binary schema
349
+ * (`format: binary` / `contentMediaType`) is a blob even when the media type is not a well-known
350
+ * binary type. Other `text/*` is text, and `application/octet-stream`, `application/pdf`,
351
+ * `image/*`, `audio/*`, and `video/*` are blobs.
352
+ */
353
+ function responseTypeForContent(entry) {
354
+ const baseType = ast.mediaType.getBase(entry);
355
+ if (!baseType) return void 0;
356
+ if (getStreamFraming(entry)) return "stream";
357
+ if (ast.mediaType.isJson(baseType)) return void 0;
358
+ if (entry.schema?.type === "blob") return "blob";
359
+ if (baseType.startsWith("text/")) return "text";
360
+ if (isBinaryContentType(baseType)) return "blob";
361
+ }
362
+ function isBinaryContentType(baseType) {
363
+ return baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType);
364
+ }
365
+ /**
366
+ * Maps a content type to the PascalCase suffix used to name per-content-type variants
367
+ * (e.g. `application/json` → `Json`, `application/xml` → `Xml`, `multipart/form-data` → `FormData`).
368
+ */
369
+ function getContentTypeSuffix(contentType) {
370
+ const baseType = contentType.split(";")[0].trim();
371
+ if (baseType === "application/json") return "Json";
372
+ if (baseType === "multipart/form-data") return "FormData";
373
+ if (baseType === "application/x-www-form-urlencoded") return "FormUrlEncoded";
374
+ const parts = (baseType.split("/").pop() ?? baseType).split(/[^a-zA-Z0-9]+/).filter(Boolean);
375
+ if (parts.length === 0) return "Unknown";
376
+ return parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
377
+ }
378
+ /**
379
+ * Appends a content-type suffix to a base name, keeping a trailing `Data` segment last
380
+ * (e.g. `AddPetData` + `Json` → `AddPetJsonData`, `AddPetStatus200` + `Xml` → `AddPetStatus200Xml`).
381
+ */
382
+ function getPerContentTypeName(baseName, suffix) {
383
+ if (baseName.endsWith("Data")) return suffix.endsWith("Data") ? baseName.slice(0, -4) + suffix : `${baseName.slice(0, -4)}${suffix}Data`;
384
+ return baseName + suffix;
385
+ }
386
+ /**
387
+ * Returns the entry with the schema of the value the client returns: `string` for a body read as text, such as `Pet` on
388
+ * `application/xml`, and `blob` for `image/*`, `audio/*`, `video/*`, PDF, and octet-stream. A binary schema elsewhere is a `Blob`
389
+ * only through `parseAs: 'blob'`, which needs every entry in `entries` binary. JSON, vendor (`application/vnd.*`), stream,
390
+ * schemaless, and wildcard entries keep their schema. `entries` is the response's full list of content types.
391
+ */
392
+ function toResponseContent(entry, entries = [entry]) {
393
+ const { contentType, schema } = entry;
394
+ if (!schema || entry.stream) return entry;
395
+ const baseType = ast.mediaType.getBase(contentType);
396
+ const resolved = ast.ref.getSchema(schema);
397
+ if (isBinaryContentType(baseType)) return resolved.type === "blob" ? entry : {
398
+ ...entry,
399
+ schema: ast.factory.createSchema({ type: "blob" }),
400
+ keysToOmit: null
401
+ };
402
+ const isPlainMediaType = Boolean(baseType) && !ast.mediaType.isJson(baseType) && !baseType.includes("*");
403
+ if (resolved.type === "blob") return isPlainMediaType && !entries.every((item) => item.schema?.type === "blob") ? {
404
+ ...entry,
405
+ schema: ast.factory.createSchema({ type: "string" }),
406
+ keysToOmit: null
407
+ } : entry;
408
+ if (resolved.primitive === "string") return entry;
409
+ const responseType = responseTypeForContent(entry);
410
+ if (responseType !== "text" && (resolved.type === "unknown" || resolved.type === "any" || resolved.type === "void")) return entry;
411
+ const isVendorJson = /^[^/]+\/vnd\./.test(baseType) && !/(xml|yaml|yml|csv)$/.test(baseType);
412
+ return responseType === "text" || !responseType && isPlainMediaType && !isVendorJson ? {
413
+ ...entry,
414
+ schema: ast.factory.createSchema({ type: "string" }),
415
+ keysToOmit: null
416
+ } : entry;
417
+ }
418
+ /**
419
+ * Resolves per-content-type variant names for a set of content entries, deduplicating suffix
420
+ * collisions with a numeric counter. Entries without a schema are skipped. The returned `suffix` is
421
+ * the final (possibly counter-augmented) value, so callers can derive parallel names in another
422
+ * namespace (e.g. plugin-faker deriving the matching plugin-ts type name).
423
+ */
424
+ function resolveContentTypeVariants(entries, baseName) {
425
+ const usedNames = /* @__PURE__ */ new Set();
426
+ return entries.filter((entry) => entry.schema).map((entry) => {
427
+ const baseSuffix = getContentTypeSuffix(entry.contentType);
428
+ let suffix = baseSuffix;
429
+ let name = getPerContentTypeName(baseName, suffix);
430
+ let counter = 2;
431
+ while (usedNames.has(name)) {
432
+ suffix = `${baseSuffix}${counter++}`;
433
+ name = getPerContentTypeName(baseName, suffix);
434
+ }
435
+ usedNames.add(name);
436
+ return {
437
+ name,
438
+ suffix,
439
+ schema: entry.schema,
440
+ keysToOmit: entry.keysToOmit,
441
+ contentType: entry.contentType
442
+ };
443
+ });
444
+ }
445
+ /**
446
+ * Whether the operation declares more than one request media type with a schema, so a caller must pick one on `contentType`.
447
+ */
448
+ function hasRequestContentTypeChoice(node) {
449
+ return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
450
+ }
451
+ /**
452
+ * Builds the combined `{ body, path, query, headers, cookies }` options object schema for an operation,
453
+ * referencing the already-resolved body and grouped param names. `cookies` appears only on an operation
454
+ * with a cookie parameter, and stays optional because a browser sends its cookies itself. Shared by `@kubb/plugin-ts`'s
455
+ * `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same shape from the same inputs.
456
+ * `primitive: 'object'` is a no-op for the TS printer and tells the Zod printer to emit `z.object(…)` rather
457
+ * than a record.
458
+ */
459
+ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
460
+ const { path, query, header, cookie } = ast.http.groupParameters(node);
461
+ const hasBody = Boolean(ast.http.requestBody.getSchema(node));
462
+ const createNever = () => ast.factory.createSchema({
463
+ type: "never",
464
+ primitive: void 0,
465
+ optional: true
466
+ });
467
+ const groups = [
468
+ {
469
+ name: "path",
470
+ params: path,
471
+ resolve: resolver.param.path
472
+ },
473
+ {
474
+ name: "query",
475
+ params: query,
476
+ resolve: resolver.param.query
477
+ },
478
+ {
479
+ name: "headers",
480
+ params: header,
481
+ resolve: resolver.param.headers
482
+ },
483
+ {
484
+ name: "cookies",
485
+ params: cookie,
486
+ resolve: resolver.param.cookies
487
+ }
488
+ ];
489
+ const createOptions = (body, extra = []) => ast.factory.createSchema({
490
+ type: "object",
491
+ primitive: "object",
492
+ deprecated: node.deprecated,
493
+ properties: [
494
+ ast.factory.createProperty({
495
+ name: "body",
496
+ required: hasBody && node.requestBody?.required === true,
497
+ schema: body
498
+ }),
499
+ ...groups.filter(({ name, params }) => name !== "cookies" || params.length > 0).map(({ name, params, resolve }) => {
500
+ const required = name !== "cookies" && params.some((param) => param.required);
501
+ return ast.factory.createProperty({
502
+ name,
503
+ required,
504
+ schema: params.length > 0 ? ast.factory.createSchema({
505
+ type: "ref",
506
+ name: resolve.call(resolver.param, node, params[0]),
507
+ optional: !required
508
+ }) : createNever()
509
+ });
510
+ }),
511
+ ...extra
512
+ ]
513
+ });
514
+ const variants = pairContentTypes && hasRequestContentTypeChoice(node) ? resolveContentTypeVariants(node.requestBody?.content ?? [], resolver.response.body(node)) : [];
515
+ if (variants.length < 2) return createOptions(hasBody ? ast.factory.createSchema({
516
+ type: "ref",
517
+ name: resolver.response.body(node)
518
+ }) : createNever());
519
+ return ast.factory.createSchema({
520
+ type: "union",
521
+ members: variants.map((variant, index) => {
522
+ const contentType = ast.factory.createSchema({
523
+ type: "enum",
524
+ enumValues: [variant.contentType]
525
+ });
526
+ return createOptions(ast.factory.createSchema({
527
+ type: "ref",
528
+ name: variant.name
529
+ }), [ast.factory.createProperty({
530
+ name: "contentType",
531
+ required: index > 0,
532
+ schema: ast.factory.createSchema({
533
+ type: "union",
534
+ members: [contentType, ast.factory.createSchema({
535
+ type: "object",
536
+ primitive: "object",
537
+ properties: [ast.factory.createProperty({
538
+ name: "request",
539
+ required: true,
540
+ schema: contentType
541
+ })]
542
+ })]
543
+ })
544
+ })]);
545
+ })
546
+ });
547
+ }
548
+ /**
549
+ * The schema a status occupies in the `<Name>Responses` record. A status that documents several
550
+ * content types becomes a `{ contentType; data }` union so the runtime can surface the negotiated type
551
+ * on `result.parsed`, while the standalone `<Name>StatusNNN` alias stays the plain body union that the
552
+ * query hooks and `result.data` use. With `streamData`, the stream variant of a 2xx status holds that schema, since the
553
+ * client returns its body unread.
554
+ */
555
+ function buildResponseRecordEntry(node, res, resolver, streamData) {
556
+ const statusName = resolver.response.status(node, res.statusCode);
557
+ const variants = (res.content ?? []).filter((entry) => entry.schema);
558
+ if (variants.length <= 1) return ast.factory.createSchema({
559
+ type: "ref",
560
+ name: statusName
561
+ });
562
+ return ast.factory.createSchema({
563
+ type: "union",
564
+ members: resolveContentTypeVariants(variants, statusName).map((variant) => ast.factory.createSchema({
565
+ type: "object",
566
+ primitive: "object",
567
+ properties: [ast.factory.createProperty({
568
+ name: "contentType",
569
+ required: true,
570
+ schema: ast.factory.createSchema({
571
+ type: "enum",
572
+ enumValues: [ast.mediaType.getBase(variant)]
573
+ })
574
+ }), ast.factory.createProperty({
575
+ name: "data",
576
+ required: true,
577
+ schema: streamData && ast.http.status.isSuccess(res) && ast.mediaType.isStream(variant) ? streamData : ast.factory.createSchema({
578
+ type: "ref",
579
+ name: variant.name
580
+ })
581
+ })]
582
+ }))
583
+ });
584
+ }
585
+ /**
586
+ * Builds the per-status `<Name>Responses` record for an operation, referencing the already-resolved
587
+ * `<Name>StatusNNN` names. Shared by `@kubb/plugin-ts`'s `Responses` type and `@kubb/plugin-zod`'s
588
+ * inferred responses schema, so both emit the same shape from the same inputs.
589
+ *
590
+ * Always emits the keyed record, even when an operation declares no responses. An operation with no
591
+ * responses renders as an empty object, which keeps every consumer's import (for example the axios
592
+ * SDK's `RequestResult<XResponses>`) resolvable instead of pointing at a missing export.
593
+ *
594
+ * `streamData` is the type of a stream variant's `data`, such as a `ReadableStream<Uint8Array>` reference.
595
+ */
596
+ function buildResponses(node, resolver, { streamData } = {}) {
597
+ return ast.factory.createSchema({
598
+ type: "object",
599
+ primitive: "object",
600
+ properties: node.responses.map((res) => ast.factory.createProperty({
601
+ name: String(res.statusCode),
602
+ required: true,
603
+ schema: buildResponseRecordEntry(node, res, resolver, streamData)
604
+ }))
605
+ });
606
+ }
607
+ /**
608
+ * One object schema for a list of parameters or response headers, with each schema inline.
609
+ */
610
+ function buildParamsSchema(params) {
611
+ return ast.factory.createSchema({
612
+ type: "object",
613
+ primitive: "object",
614
+ properties: params.map((param) => ast.factory.createProperty({
615
+ name: param.name,
616
+ required: param.required,
617
+ schema: param.schema
618
+ }))
619
+ });
620
+ }
621
+ /**
622
+ * One object schema for the parameters of an operation, where each key points at the const of
623
+ * that parameter. The const already has its optional wrapper, so every key is required here.
624
+ */
625
+ function buildParamRefsSchema({ node, params, resolver }) {
626
+ return ast.factory.createSchema({
627
+ type: "object",
628
+ primitive: "object",
629
+ properties: params.map((param) => ast.factory.createProperty({
630
+ name: param.name,
631
+ required: true,
632
+ schema: ast.factory.createSchema({
633
+ type: "ref",
634
+ name: resolver.param.name(node, param)
635
+ })
636
+ }))
637
+ });
638
+ }
639
+ /**
640
+ * The schemas a name with several content types needs: one per content type, then the union of
641
+ * them under `baseName`.
642
+ */
643
+ function buildContentTypeEntries(entries, baseName, decorate = (schema) => schema) {
644
+ const variants = resolveContentTypeVariants(entries, baseName);
645
+ const union = ast.factory.createSchema({
646
+ type: "union",
647
+ members: variants.map((variant) => ast.factory.createSchema({
648
+ type: "ref",
649
+ name: variant.name
650
+ }))
651
+ });
652
+ return [...variants.map((variant) => ({
653
+ schema: decorate(variant.schema),
654
+ name: variant.name,
655
+ keysToOmit: variant.keysToOmit
656
+ })), {
657
+ schema: union,
658
+ name: baseName
659
+ }];
660
+ }
661
+ /**
662
+ * The schema behind a response or error name: a union of the per-status schemas. Returns `null`
663
+ * when a response is a `$ref` to a component whose name is already `name`, which would declare it twice.
664
+ */
665
+ function buildResponseUnionSchema({ node, responses, name, resolver, fallbackUnknown }) {
666
+ if (new Set(ast.http.responses.getImportedNames(responses).map((refName) => resolver.name(refName))).has(name)) return null;
667
+ const members = responses.map((res) => ast.factory.createSchema({
668
+ type: "ref",
669
+ name: resolver.response.status(node, res.statusCode)
670
+ }));
671
+ if (members.length === 0) return fallbackUnknown ? ast.factory.createSchema({ type: "unknown" }) : null;
672
+ return members.length === 1 ? members[0] : ast.factory.createSchema({
673
+ type: "union",
674
+ members
675
+ });
676
+ }
677
+ // ../../internals/shared/src/adapter.ts
678
+ /**
679
+ * Narrows the generic `Adapter` from a generator context to the OpenAPI adapter,
680
+ * so OAS-only options (`dateType`, `enums`) and the parsed `document` are typed.
681
+ *
682
+ * Throws when a non-OAS adapter is configured, turning a silently wrong cast into a
683
+ * clear, actionable error at the point of use.
684
+ *
685
+ * @example
686
+ * ```ts
687
+ * const { dateType } = getOasAdapter(ctx.adapter).options
688
+ * ```
689
+ */
690
+ function getOasAdapter(adapter) {
691
+ if (adapter.name !== "oas") throw new Diagnostics.Error({
692
+ code: Diagnostics.code.adapterRequired,
693
+ severity: "error",
694
+ message: `Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}".`,
695
+ help: "Set `adapter: adapterOas()` in kubb.config.ts.",
696
+ location: { kind: "config" }
697
+ });
698
+ return adapter;
699
+ }
700
+ // ../../internals/shared/src/resolver.ts
701
+ /**
702
+ * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
703
+ * it is, so two of them never share an allocation even when a custom resolver gives both the same
704
+ * name. Leave `scope` empty for the operation's own declaration.
705
+ *
706
+ * The key starts from the operation's input `pointer`, which macros keep, so a plugin whose macro
707
+ * rewrites the method or path still resolves another plugin's names for the same operation.
708
+ *
709
+ * @example
710
+ * ```ts
711
+ * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
712
+ * ```
713
+ */
714
+ function operationKey(node, ...scope) {
715
+ return [
716
+ "operation",
717
+ ...node.pointer ? [node.pointer] : [node.method, node.path],
718
+ ...scope.map(String)
719
+ ];
720
+ }
721
+ /**
722
+ * Builds the shared `param` namespace. Spread the result into `createResolver`
723
+ * and override individual methods next to it when a plugin deviates.
724
+ *
725
+ * @example
726
+ * ```ts
727
+ * createResolver<PluginTs>({ param: createOperationParamResolver(), ... })
728
+ * ```
729
+ */
730
+ function createOperationParamResolver() {
731
+ return {
732
+ name(node, param) {
733
+ const name = this.name(`${node.operationId} ${param.in} ${param.name}`);
734
+ return this.resolveName({
735
+ key: operationKey(node, "param", "name", param.in, param.name),
736
+ name
737
+ });
738
+ },
739
+ path(node) {
740
+ const name = this.name(`${node.operationId} Path`);
741
+ return this.resolveName({
742
+ key: operationKey(node, "param", "path"),
743
+ name
744
+ });
745
+ },
746
+ query(node) {
747
+ const name = this.name(`${node.operationId} Query`);
748
+ return this.resolveName({
749
+ key: operationKey(node, "param", "query"),
750
+ name
751
+ });
752
+ },
753
+ headers(node) {
754
+ const name = this.name(`${node.operationId} Headers`);
755
+ return this.resolveName({
756
+ key: operationKey(node, "param", "headers"),
757
+ name
758
+ });
759
+ },
760
+ cookies(node) {
761
+ const name = this.name(`${node.operationId} Cookies`);
762
+ return this.resolveName({
763
+ key: operationKey(node, "param", "cookies"),
764
+ name
765
+ });
766
+ }
767
+ };
768
+ }
769
+ /**
770
+ * Builds the shared `response` namespace. Spread the result into
771
+ * `createResolver` and add plugin-specific methods (`options`, `error`) next
772
+ * to it.
773
+ *
774
+ * @example
775
+ * ```ts
776
+ * createResolver<PluginTs>({ response: { ...createOperationResponseResolver(), options(node) {...} }, ... })
777
+ * ```
778
+ */
779
+ function createOperationResponseResolver() {
780
+ return {
781
+ status(node, statusCode) {
782
+ const name = this.name(`${node.operationId} Status ${statusCode}`);
783
+ return this.resolveName({
784
+ key: operationKey(node, "response", "status", statusCode),
785
+ name
786
+ });
787
+ },
788
+ headers(node, statusCode) {
789
+ const name = this.name(`${node.operationId} Status ${statusCode} Headers`);
790
+ return this.resolveName({
791
+ key: operationKey(node, "response", "headers", statusCode),
792
+ name
793
+ });
794
+ },
795
+ body(node) {
796
+ const name = this.name(`${node.operationId} Body`);
797
+ return this.resolveName({
798
+ key: operationKey(node, "response", "body"),
799
+ name
800
+ });
801
+ },
802
+ responses(node) {
803
+ const name = this.name(`${node.operationId} Responses`);
804
+ return this.resolveName({
805
+ key: operationKey(node, "response", "responses"),
806
+ name
807
+ });
808
+ },
809
+ response(node) {
810
+ const name = this.name(`${node.operationId} Response`);
811
+ return this.resolveName({
812
+ key: operationKey(node, "response", "response"),
813
+ name
814
+ });
815
+ }
816
+ };
817
+ }
818
+ /**
819
+ * Builds a resolver `file` override whose base name runs every path segment
820
+ * through `toFilePath`, casing the final segment with `caseLast`.
821
+ *
822
+ * @example
823
+ * ```ts
824
+ * createResolver<PluginTs>({ file: createCasedFile(pascalCase), ... })
825
+ * ```
826
+ */
827
+ function createCasedFile(caseLast) {
828
+ return { baseName({ name, extname }) {
829
+ return this.memo(`file:${name}\0${extname}`, () => `${toFilePath(name, caseLast)}${extname}`);
830
+ } };
831
+ }
832
+ /**
833
+ * Names of the schemas in a circular reference chain, computed once per build.
834
+ */
835
+ function getCircularNames(ctx) {
836
+ return ctx.memo("circularNames:set", () => ast.graph.getCircularNames(ctx.schemas));
837
+ }
838
+ // ../../internals/shared/src/schema.ts
839
+ /**
840
+ * Whether the node is a plain inline object whose properties can merge into another object schema.
841
+ * Input checks, `additionalProperties`, `patternProperties`, `propertyNames`, and a nullable or
842
+ * optional wrapper rule it out.
843
+ */
844
+ function isPlainInlineObject(node) {
845
+ if (node.type !== "object") return false;
846
+ if (hasInputChecks(node)) return false;
847
+ if (node.nullable || node.optional || node.nullish) return false;
848
+ const hasAdditionalProperties = node.additionalProperties !== void 0;
849
+ const hasPatternProperties = Boolean(node.patternProperties);
850
+ return !hasAdditionalProperties && !hasPatternProperties && !node.propertyNames;
851
+ }
852
+ /**
853
+ * Whether a node prints as a plain object schema, which other schemas can extend or discriminate on.
854
+ * Covers object nodes, a `$ref` that resolves to an object or is still unresolved, a union with one
855
+ * object member, and an object-composable `allOf`.
856
+ *
857
+ * A nullable or optional node, a node with input checks, and a ref into `cyclicSchemas` do not count.
858
+ */
859
+ function isObjectSchemaNode(node, cyclicSchemas) {
860
+ if (node.nullable || node.optional || node.nullish) return false;
861
+ if (hasInputChecks(node)) return false;
862
+ if (node.type === "object") {
863
+ const hasProperties = Boolean(node.properties?.length);
864
+ const hasTypedAdditionalProperties = Boolean(node.additionalProperties && node.additionalProperties !== true);
865
+ const hasPatternProperties = Boolean(node.patternProperties);
866
+ return !(!hasProperties && (hasTypedAdditionalProperties || hasPatternProperties || node.propertyNames));
867
+ }
868
+ if (node.type === "ref") {
869
+ const refName = ast.ref.getName(node);
870
+ if (refName && cyclicSchemas?.has(refName)) return false;
871
+ const resolved = ast.ref.mergeSchema(node);
872
+ return resolved.type === "ref" || isObjectSchemaNode(resolved, cyclicSchemas);
873
+ }
874
+ if (node.type === "union") {
875
+ const members = node.members ?? [];
876
+ return members.length === 1 && isObjectSchemaNode(members[0], cyclicSchemas);
877
+ }
878
+ return isObjectComposableIntersection(node, cyclicSchemas);
879
+ }
880
+ /**
881
+ * Whether an `allOf` is an object base plus inline object members, so it can print as one object
882
+ * schema and not as an intersection.
883
+ */
884
+ function isObjectComposableIntersection(node, cyclicSchemas) {
885
+ if (node.type !== "intersection") return false;
886
+ const [first, ...rest] = node.members ?? [];
887
+ return !!first && isObjectSchemaNode(first, cyclicSchemas) && rest.every(isPlainInlineObject);
888
+ }
889
+ /**
890
+ * Marks a property required in a later `allOf` member when an earlier member already requires it.
891
+ */
892
+ function preserveRequiredProperties(members) {
893
+ const hasRequiredProperty = ({ node, propertyName, seen = /* @__PURE__ */ new Set() }) => {
894
+ if (seen.has(node)) return false;
895
+ seen.add(node);
896
+ const resolved = ast.ref.mergeSchema(node);
897
+ const composition = ast.schema.narrow(resolved, ast.schema.types.intersection) ?? ast.schema.narrow(resolved, ast.schema.types.union);
898
+ if (composition) {
899
+ if (composition.type === ast.schema.types.union && composition.members?.length !== 1) return false;
900
+ return composition.members?.some((child) => hasRequiredProperty({
901
+ node: child,
902
+ propertyName,
903
+ seen
904
+ })) ?? false;
905
+ }
906
+ return ast.schema.findProperties({
907
+ node: resolved,
908
+ propertyName
909
+ }).some((property) => property.required !== false && !property.schema.optional && !property.schema.nullish);
910
+ };
911
+ return members.map((member, index) => {
912
+ const object = ast.schema.narrow(member, ast.schema.types.object);
913
+ if (!object || index === 0) return member;
914
+ return {
915
+ ...object,
916
+ properties: object.properties.map((property) => {
917
+ if (!members.slice(0, index).some((base) => hasRequiredProperty({
918
+ node: base,
919
+ propertyName: property.name
920
+ }))) return property;
921
+ return {
922
+ ...property,
923
+ required: true,
924
+ schema: {
925
+ ...property.schema,
926
+ optional: false,
927
+ nullish: false,
928
+ nullable: property.schema.nullable || property.schema.nullish
929
+ }
930
+ };
931
+ })
932
+ };
933
+ });
934
+ }
935
+ /**
936
+ * Format a default value as a code-level literal.
937
+ * Arrays and objects keep their contents as a JSON literal, primitives become their string
938
+ * representation, strings are quoted.
939
+ */
940
+ function formatDefault(value) {
941
+ if (typeof value === "string") return text.quote(value);
942
+ if (typeof value === "object" && value !== null) return JSON.stringify(value);
943
+ return String(value ?? "");
944
+ }
945
+ /**
946
+ * Formats a default so the literal matches the type of the generated schema, or returns `null` when
947
+ * the default should be dropped.
948
+ *
949
+ * An OpenAPI `default` does not always agree with its schema: a `bigint` field (`format: int64`)
950
+ * carries a `number` default, and a spec may put `default: {}` on an `array`. Printed as they are,
951
+ * those do not typecheck, so a bigint default becomes a `BigInt(...)` literal and a non-array default
952
+ * on an array is dropped.
953
+ */
954
+ function defaultLiteral(node, value) {
955
+ if (value === null) return null;
956
+ const resolved = node ? ast.ref.mergeSchema(node) : void 0;
957
+ if (resolved?.type === "blob") return null;
958
+ if (resolved && ast.schema.narrow(resolved, "bigint")) {
959
+ if (typeof value === "bigint" || typeof value === "number" && Number.isInteger(value)) return `BigInt('${BigInt(value)}')`;
960
+ return null;
961
+ }
962
+ if (resolved && ast.schema.narrow(resolved, "array")) return Array.isArray(value) ? JSON.stringify(value) : null;
963
+ const enumNode = resolved ? ast.schema.narrow(resolved, "enum") : void 0;
964
+ if (enumNode) {
965
+ const values = ast.schema.getLiterals(enumNode);
966
+ if (values.length) {
967
+ const match = values.find((member) => member === value || String(member) === String(value));
968
+ return match != null ? formatDefault(match) : null;
969
+ }
970
+ }
971
+ return formatDefault(value);
972
+ }
973
+ /**
974
+ * Digit pattern for a `type: 'string'` schema that carries an integer `format`, the way ProtoJSON
975
+ * encodes 64-bit integers. Returns `undefined` for every other format, and a `pattern` from the
976
+ * spec takes precedence over this fallback.
977
+ *
978
+ * @example
979
+ * ```ts
980
+ * integerFormatPattern('uint64') // '^\\d+$'
981
+ * ```
982
+ */
983
+ function integerFormatPattern(format) {
984
+ if (format === "int32" || format === "int64") return "^-?\\d+$";
985
+ if (format === "uint64") return "^\\d+$";
986
+ }
987
+ /**
988
+ * Numeric bounds for a bigint: the inclusive, whole, safe bounds faker mocks against, and a whole, safe `multipleOf`.
989
+ */
990
+ function bigintConstraints({ min, max, exclusive, multipleOf }) {
991
+ return {
992
+ ...ast.schema.getNumberBounds({
993
+ min,
994
+ max,
995
+ exclusive,
996
+ integer: true
997
+ }),
998
+ multipleOf: Number.isSafeInteger(multipleOf) ? multipleOf : void 0
999
+ };
1000
+ }
1001
+ const integerFormatRanges = {
1002
+ integer: {
1003
+ int8: [-(2n ** 7n), 2n ** 7n - 1n],
1004
+ uint8: [0n, 2n ** 8n - 1n],
1005
+ int16: [-(2n ** 15n), 2n ** 15n - 1n],
1006
+ uint16: [0n, 2n ** 16n - 1n],
1007
+ int32: [-(2n ** 31n), 2n ** 31n - 1n],
1008
+ uint32: [0n, 2n ** 32n - 1n]
1009
+ },
1010
+ bigint: {
1011
+ int64: [-(2n ** 63n), 2n ** 63n - 1n],
1012
+ uint64: [0n, 2n ** 64n - 1n]
1013
+ }
1014
+ };
1015
+ /**
1016
+ * Adds the range of an integer `format` to a schema's limits. A bound from the spec stays when it
1017
+ * is at least as tight as the format's.
1018
+ *
1019
+ * @example
1020
+ * ```ts
1021
+ * withFormatRange({ format: 'int32', min: 0 }, 'integer') // { format: 'int32', min: 0, max: '2147483647' }
1022
+ * ```
1023
+ */
1024
+ function withFormatRange(node, type) {
1025
+ const range = node.format ? integerFormatRanges[type][node.format] : void 0;
1026
+ if (!range) return node;
1027
+ const [min, max] = range;
1028
+ return {
1029
+ ...node,
1030
+ min: node.min === void 0 || node.min < Number(min) ? String(min) : node.min,
1031
+ max: node.max === void 0 || node.max > Number(max) ? String(max) : node.max
1032
+ };
1033
+ }
1034
+ /**
1035
+ * Whether `propertyNames` needs its own check. A record schema checks its keys, but an object with
1036
+ * `properties` and a record keyed by `patternProperties` do not.
1037
+ */
1038
+ function hasKeyCheck(node) {
1039
+ if (node.type !== "object" || !node.propertyNames) return false;
1040
+ const hasTypedAdditionalProperties = Boolean(node.additionalProperties && node.additionalProperties !== true);
1041
+ return node.properties.length > 0 || Boolean(node.patternProperties) && !hasTypedAdditionalProperties;
1042
+ }
1043
+ /**
1044
+ * Whether the node has checks that run on the raw input: `conditionals`, property counts, or a key check.
1045
+ */
1046
+ function hasInputChecks(node) {
1047
+ return Boolean(node.conditionals?.length) || node.type === "object" && (node.min !== void 0 || node.max !== void 0) || hasKeyCheck(node);
1048
+ }
1049
+ /**
1050
+ * Marks an inline `oneOf` object strict, so a value with the keys of another member does not match it.
1051
+ */
1052
+ function strictOneOfNode(node) {
1053
+ return node.type === "object" && node.additionalProperties === void 0 ? {
1054
+ ...node,
1055
+ additionalProperties: false
1056
+ } : node;
1057
+ }
1058
+ /**
1059
+ * Whether the `coercion` option turns on conversion for a type.
1060
+ */
1061
+ function shouldCoerce(coercion, type) {
1062
+ return coercion === true || typeof coercion === "object" && Boolean(coercion[type]);
1063
+ }
1064
+ /**
1065
+ * A numeric bound as source code. A bigint bound prints as `BigInt('…')`, which is exact and
1066
+ * compiles below ES2020, where a `1n` literal does not.
1067
+ */
1068
+ function numericLiteral(value, isBigint) {
1069
+ return isBigint ? `BigInt('${value}')` : value;
1070
+ }
1071
+ /**
1072
+ * The JSDoc lines above a schema const: its description, and `@deprecated` when the spec says so.
1073
+ * A `$ref` const gets none, because the const it points to has them.
1074
+ */
1075
+ function schemaComments(node) {
1076
+ if (node.type === ast.schema.types.ref) return [];
1077
+ return [node.description && jsDocEscape(node.description), node.deprecated && "@deprecated"].filter((comment) => Boolean(comment));
1078
+ }
1079
+ // src/components/Valibot.tsx
1080
+ function Valibot({ name, node, printer, inferTypeName, inferKind = "InferOutput", typeGuards, isName, assertName, cyclic, comments = [] }) {
1081
+ const output = printer.print(node);
1082
+ const printerImports = printer.drainImports();
1083
+ if (!output) return;
1084
+ const guardType = `v.InferInput<typeof ${name}>`;
1085
+ const shouldGenerateIs = isName && (typeof typeGuards === "object" ? typeGuards.is ?? true : Boolean(typeGuards));
1086
+ const shouldGenerateAssert = assertName && (typeof typeGuards === "object" ? typeGuards.assert ?? true : Boolean(typeGuards));
1087
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1088
+ printerImports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
1089
+ name: imp.name,
1090
+ path: imp.path,
1091
+ root: imp.root,
1092
+ isTypeOnly: imp.isTypeOnly,
1093
+ isNameSpace: imp.isNameSpace
1094
+ }, [
1095
+ name,
1096
+ imp.path,
1097
+ imp.name
1098
+ ].join("-"))),
1099
+ /* @__PURE__ */ jsx(File.Source, {
1100
+ name,
1101
+ isExportable: true,
1102
+ isIndexable: true,
1103
+ children: /* @__PURE__ */ jsx(Const, {
1104
+ export: true,
1105
+ name,
1106
+ type: cyclic ? "v.GenericSchema" : void 0,
1107
+ JSDoc: comments.length ? { comments } : void 0,
1108
+ children: output
1109
+ })
1110
+ }),
1111
+ inferTypeName && /* @__PURE__ */ jsx(File.Source, {
1112
+ name: inferTypeName,
1113
+ isExportable: true,
1114
+ isIndexable: true,
1115
+ isTypeOnly: true,
1116
+ children: /* @__PURE__ */ jsx(Type, {
1117
+ export: true,
1118
+ name: inferTypeName,
1119
+ children: `v.${inferKind}<typeof ${name}>`
1120
+ })
1121
+ }),
1122
+ shouldGenerateIs && /* @__PURE__ */ jsx(File.Source, {
1123
+ name: isName,
1124
+ isExportable: true,
1125
+ isIndexable: true,
1126
+ children: /* @__PURE__ */ jsx(Const, {
1127
+ export: true,
1128
+ name: isName,
1129
+ JSDoc: { comments: [`Type guard for {@link ${name}}`] },
1130
+ children: `(data: unknown): data is ${guardType} => v.is(${name}, data)`
1131
+ })
1132
+ }),
1133
+ shouldGenerateAssert && /* @__PURE__ */ jsx(File.Source, {
1134
+ name: assertName,
1135
+ isExportable: true,
1136
+ isIndexable: true,
1137
+ children: /* @__PURE__ */ jsx(Function, {
1138
+ export: true,
1139
+ name: assertName,
1140
+ params: "data: unknown",
1141
+ returnType: `asserts data is ${guardType}`,
1142
+ JSDoc: { comments: [`Asserter for {@link ${name}}`, "@throws {v.ValiError} If data is invalid"] },
1143
+ children: `v.assert(${name}, data)`
1144
+ })
1145
+ })
1146
+ ] });
1147
+ }
1148
+ // src/printers/printerValibot.ts
1149
+ const UNKNOWN = "v.unknown()";
1150
+ const NOT_OBJECT = "typeof value !== \"object\" || value === null || Array.isArray(value)";
1151
+ const stringFormatActions = /* @__PURE__ */ new Map([
1152
+ ["byte", "v.base64()"],
1153
+ ["base64", "v.base64()"],
1154
+ ["ulid", "v.ulid()"]
1155
+ ]);
1156
+ function pipe(base, actions) {
1157
+ const list = actions.filter(Boolean);
1158
+ return list.length ? `v.pipe(${[base, ...list].join(", ")})` : base;
1159
+ }
1160
+ function lengthActions({ min, max, pattern }, regexType) {
1161
+ return [
1162
+ min !== void 0 && `v.minLength(${min})`,
1163
+ max !== void 0 && `v.maxLength(${max})`,
1164
+ pattern !== void 0 && `v.regex(${toRegExpString(pattern, regexType === "constructor" ? "RegExp" : null)})`
1165
+ ].filter((action) => Boolean(action));
1166
+ }
1167
+ function numberActions({ min, max, exclusive, multipleOf }, isBigint = false) {
1168
+ const literal = (value) => numericLiteral(value, isBigint);
1169
+ return [
1170
+ min !== void 0 && `v.minValue(${literal(min)})`,
1171
+ max !== void 0 && `v.maxValue(${literal(max)})`,
1172
+ exclusive?.min !== void 0 && `v.gtValue(${literal(exclusive.min)})`,
1173
+ exclusive?.max !== void 0 && `v.ltValue(${literal(exclusive.max)})`,
1174
+ multipleOf !== void 0 && `v.multipleOf(${literal(multipleOf)})`
1175
+ ].filter((action) => Boolean(action));
1176
+ }
1177
+ function memberActions({ member, base, regexType }) {
1178
+ if (hasChecks(member)) return [];
1179
+ if (member.primitive === "string") return lengthActions(ast.schema.narrow(member, "string") ?? {}, regexType);
1180
+ if (member.primitive === "number" || member.primitive === "integer") {
1181
+ const numeric = ast.schema.narrow(member, "number") ?? ast.schema.narrow(member, "integer") ?? {};
1182
+ if (base.type === ast.schema.types.bigint) return numberActions(bigintConstraints(numeric), true);
1183
+ return [...member.primitive === "integer" && base.type !== ast.schema.types.integer ? ["v.integer()"] : [], ...numberActions(numeric)];
1184
+ }
1185
+ if (member.primitive === "array") {
1186
+ const array = ast.schema.narrow(member, "array");
1187
+ return array && !array.contains ? lengthActions({
1188
+ min: array.min,
1189
+ max: array.max
1190
+ }, regexType) : [];
1191
+ }
1192
+ return [];
1193
+ }
1194
+ function buildLiteral(value) {
1195
+ if (value === null) return "v.null()";
1196
+ if (Array.isArray(value)) return `v.strictTuple([${value.map((item) => buildLiteral(item)).join(", ")}])`;
1197
+ if (typeof value === "object") return `v.strictObject({${Object.entries(value).map(([name, item]) => `${JSON.stringify(name)}: ${buildLiteral(item)}`).join(", ")}})`;
1198
+ return `v.literal(${formatDefault(value)})`;
1199
+ }
1200
+ function buildEnum(values) {
1201
+ if (values.length === 1) return buildLiteral(values[0]);
1202
+ if (values.every((value) => typeof value === "string" || typeof value === "number")) return `v.picklist([${values.map((value) => formatDefault(value)).join(", ")}])`;
1203
+ return `v.union([${values.map((value) => buildLiteral(value)).join(", ")}])`;
1204
+ }
1205
+ function expectsDate(node, direction) {
1206
+ const resolved = ast.ref.mergeSchema(node);
1207
+ return direction === "encode" && (resolved.type === "date" || resolved.type === "time") && resolved.representation !== "string";
1208
+ }
1209
+ function hasPatternKeyCheck(node) {
1210
+ return node.type === "object" && node.additionalProperties === false && node.properties.length > 0 && Boolean(node.patternProperties);
1211
+ }
1212
+ function hasChecks(node) {
1213
+ return hasInputChecks(node) || hasPatternKeyCheck(node);
1214
+ }
1215
+ function countChecks(node) {
1216
+ const object = ast.schema.narrow(node, "object");
1217
+ return Number(object?.min !== void 0) + Number(object?.max !== void 0) + Number(hasKeyCheck(node)) + Number(hasPatternKeyCheck(node)) + (node.conditionals?.length ?? 0);
1218
+ }
1219
+ function applyModifiers({ value, schema, nullable, optional, nullish, defaultValue, title, description, examples, direction }) {
1220
+ const metadata = [
1221
+ title && `v.title(${text.quote(title)})`,
1222
+ description && `v.description(${text.quote(description)})`,
1223
+ examples?.length && `v.metadata({ examples: [${examples.map((example) => example === null ? "null" : formatDefault(example)).join(", ")}] })`
1224
+ ].filter(Boolean);
1225
+ const described = metadata.length ? `v.pipe(${value}, ${metadata.join(", ")})` : value;
1226
+ const inner = nullable || nullish ? `v.nullable(${described})` : described;
1227
+ const literal = defaultValue !== void 0 && !expectsDate(schema, direction) ? defaultLiteral(schema, defaultValue) : null;
1228
+ if (literal !== null) return `v.optional(${inner}, ${literal})`;
1229
+ return optional || nullish ? `v.optional(${inner})` : inner;
1230
+ }
1231
+ function hasMetadata(node) {
1232
+ return node.type !== ast.schema.types.ref && Boolean(node.title || node.description || node.examples?.length);
1233
+ }
1234
+ function unwrapChain(node, direction) {
1235
+ const ref = ast.schema.narrow(node, "ref");
1236
+ if (!ref) return "";
1237
+ const target = ref.schema ?? ref;
1238
+ const meta = ast.ref.mergeSchema(target);
1239
+ const hasDefault = meta.default !== void 0 && !expectsDate(target, direction) && defaultLiteral(target, meta.default) !== null;
1240
+ const depth = Number(Boolean(meta.nullable || meta.nullish)) + Number(Boolean(meta.optional || meta.nullish || hasDefault));
1241
+ const inner = target !== ref && target.type === ast.schema.types.ref ? unwrapChain(target, direction) : "";
1242
+ return `${".wrapped".repeat(depth)}${inner}${hasMetadata(target) ? ".pipe[0]" : ""}`;
1243
+ }
1244
+ function objectEntries(ctx, properties) {
1245
+ return properties.map(({ name, schema, required }) => {
1246
+ const meta = ast.ref.mergeSchema(schema);
1247
+ const value = applyModifiers({
1248
+ value: ctx.transform(schema) ?? UNKNOWN,
1249
+ schema,
1250
+ nullable: meta.nullable,
1251
+ optional: schema.optional || required === false,
1252
+ nullish: schema.nullish,
1253
+ defaultValue: meta.default,
1254
+ title: schema.type === ast.schema.types.ref ? void 0 : schema.title,
1255
+ description: schema.type !== ast.schema.types.ref && meta.type === ast.schema.types.ref ? void 0 : meta.description,
1256
+ examples: meta.examples,
1257
+ direction: ctx.options.direction
1258
+ });
1259
+ return `${objectKey(name)}: ${value}`;
1260
+ });
1261
+ }
1262
+ function strictMember({ member, node, cyclicSchemas }) {
1263
+ if (node.type !== ast.schema.types.ref) return member;
1264
+ const refName = ast.ref.getName(node);
1265
+ if (refName && cyclicSchemas?.has(refName)) return member;
1266
+ const schema = ast.ref.mergeSchema(node);
1267
+ const isWrapped = schema.nullable || schema.optional || schema.nullish || schema.default !== void 0 || node.nullable || node.optional;
1268
+ return schema.type === ast.schema.types.object && (schema.additionalProperties === void 0 || schema.additionalProperties === false) && !schema.patternProperties && !schema.propertyNames && !hasChecks(schema) && !isWrapped ? `v.strictObject(${member}.entries)` : member;
1269
+ }
1270
+ function containsCheck(ctx, { schema, min = 1, max }) {
1271
+ if (min === 0 && max === void 0) return false;
1272
+ const bounds = [`count >= ${min}`, max !== void 0 && `count <= ${max}`].filter(Boolean).join(" && ");
1273
+ const message = max !== void 0 ? `Array must contain ${min} to ${max} matching items` : `Array must contain at least ${min} matching items`;
1274
+ return `v.check((items) => { const count = items.filter((item) => v.is(${ctx.transform(schema) ?? UNKNOWN}, item)).length; return ${bounds} }, ${JSON.stringify(message)})`;
1275
+ }
1276
+ function conditionExpression(ctx, schema) {
1277
+ if (!schema) return "true";
1278
+ const object = ast.schema.narrow(schema, ast.schema.types.object);
1279
+ const keyOnlyNames = object?.properties.filter((property) => property.required && property.schema.type === ast.schema.types.unknown).map((property) => property.name) ?? [];
1280
+ const restSchema = object ? {
1281
+ ...object,
1282
+ properties: object.properties.filter((property) => !keyOnlyNames.includes(property.name))
1283
+ } : schema;
1284
+ const isOnlyKeys = keyOnlyNames.length > 0 && restSchema.type === "object" && restSchema.properties.length === 0 && restSchema.additionalProperties === void 0 && !restSchema.patternProperties && !restSchema.propertyNames && !hasChecks(restSchema);
1285
+ return [keyOnlyNames.length > 0 && `typeof value === "object" && value !== null && ${JSON.stringify(keyOnlyNames)}.every((key) => key in value)`, !isOnlyKeys && `v.is(${ctx.transform(restSchema) ?? UNKNOWN}, value)`].filter(Boolean).join(" && ");
1286
+ }
1287
+ function inputChecks(ctx, node) {
1288
+ const { min, max } = node.type === "object" ? node : {};
1289
+ const keySchema = hasKeyCheck(node) ? ctx.transform(node.propertyNames) : null;
1290
+ const patternKeys = hasPatternKeyCheck(node) ? `${JSON.stringify(node.properties.map((property) => property.name))}.includes(key) || ${Object.keys(node.patternProperties).map((pattern) => `${toRegExpString(pattern, ctx.options.regexType === "constructor" ? "RegExp" : null)}.test(key)`).join(" || ")}` : null;
1291
+ return [
1292
+ min !== void 0 && `v.check((value) => ${NOT_OBJECT} || Object.keys(value).length >= ${min}, "Object must have at least ${min} properties")`,
1293
+ max !== void 0 && `v.check((value) => ${NOT_OBJECT} || Object.keys(value).length <= ${max}, "Object must have at most ${max} properties")`,
1294
+ keySchema && `v.check((value) => ${NOT_OBJECT} || Object.keys(value).every((key) => v.is(${keySchema}, key)), "Object keys must match the property names schema")`,
1295
+ patternKeys && `v.check((value) => ${NOT_OBJECT} || Object.keys(value).every((key) => ${patternKeys}), "Object keys must be declared or match a pattern")`,
1296
+ ...(node.conditionals ?? []).map((entry) => `v.check((value) => (${conditionExpression(ctx, entry.if)} ? ${conditionExpression(ctx, entry.then)} : ${conditionExpression(ctx, entry.else)}), "Value does not meet a conditional schema")`)
1297
+ ].filter((check) => Boolean(check));
1298
+ }
1299
+ function withInputChecks(nodes, isSkipped) {
1300
+ const wrapHandler = (type) => {
1301
+ const handler = nodes[type];
1302
+ if (!handler) return [];
1303
+ const checkedHandler = function(node) {
1304
+ const output = handler.call(this, node);
1305
+ if (!output || isSkipped(node) || !hasChecks(node)) return output;
1306
+ return pipe(UNKNOWN, [...inputChecks(this, node), output]);
1307
+ };
1308
+ return [[type, checkedHandler]];
1309
+ };
1310
+ return Object.fromEntries(Object.values(ast.schema.types).flatMap(wrapHandler));
1311
+ }
1312
+ /**
1313
+ * The handlers that print differently per direction. `date` and `time` decode a wire string into a
1314
+ * `Date` on responses and encode it back on requests. Only `representation: 'date'` fields convert.
1315
+ * `time` has no date part, so it decodes onto `1970-01-01` and encodes back to `HH:mm:ssZ`, with milliseconds when it has them.
1316
+ */
1317
+ const directionalNodes = {
1318
+ date(node) {
1319
+ if (node.representation !== "date") return "v.pipe(v.string(), v.isoDate())";
1320
+ if (this.options.direction === "encode") return node.format === "date" ? "v.pipe(v.date(), v.transform((value) => value.toISOString().slice(0, 10)))" : "v.pipe(v.date(), v.transform((value) => value.toISOString()))";
1321
+ if (shouldCoerce(this.options.coercion, "dates")) return "v.pipe(v.unknown(), v.toDate())";
1322
+ return node.format === "date" ? "v.pipe(v.string(), v.isoDate(), v.transform((value) => new Date(value)))" : "v.pipe(v.string(), v.isoTimestamp(), v.transform((value) => new Date(value)))";
1323
+ },
1324
+ time(node) {
1325
+ if (node.representation === "string") return "v.string()";
1326
+ if (this.options.direction === "encode") return "v.pipe(v.date(), v.transform((value) => value.toISOString().slice(11).replace(\".000Z\", \"Z\")))";
1327
+ return "v.pipe(v.string(), v.transform((value) => new Date(`1970-01-01T${value}${/(?:z|[+-]\\d{2}:\\d{2})$/i.test(value) ? \"\" : \"Z\"}`)), v.date())";
1328
+ }
1329
+ };
1330
+ function variesByDirection({ node, printerOptions }) {
1331
+ const handler = printerOptions.nodes?.[node.type] ?? directionalNodes[node.type];
1332
+ if (!handler) return false;
1333
+ const call = (direction) => {
1334
+ const context = {
1335
+ options: {
1336
+ ...printerOptions,
1337
+ direction
1338
+ },
1339
+ transform: () => null,
1340
+ base: () => null,
1341
+ import: () => {}
1342
+ };
1343
+ return handler.call(context, node);
1344
+ };
1345
+ return call("decode") !== call("encode");
1346
+ }
1347
+ /**
1348
+ * Whether the schema contains a node that prints differently per direction, so it decodes on
1349
+ * responses and encodes on requests. Follows a `$ref` through its resolved schema.
1350
+ */
1351
+ function containsDirectionalNode({ node, printerOptions }) {
1352
+ if (!node) return false;
1353
+ const { resolver, nodes, coercion, dateType } = printerOptions;
1354
+ const cache = resolver && !nodes ? resolver.memo(`valibotDirectionalNodes:${shouldCoerce(coercion, "dates")}:${dateType}`, () => /* @__PURE__ */ new WeakMap()) : void 0;
1355
+ return ast.schema.find(node, {
1356
+ predicate: (schema) => variesByDirection({
1357
+ node: schema,
1358
+ printerOptions
1359
+ }),
1360
+ followRefs: true,
1361
+ cache
1362
+ }) !== void 0;
1363
+ }
1364
+ /**
1365
+ * Names of the `$ref` schemas a request schema reads from their `${name}InputSchema` variant.
1366
+ */
1367
+ function collectDirectionalRefNames({ node, printerOptions }) {
1368
+ return ast.node.collect(node, { schema: (n) => n.type === ast.schema.types.ref && n.ref && containsDirectionalNode({
1369
+ node: n,
1370
+ printerOptions
1371
+ }) ? ast.ref.getName(n) ?? void 0 : void 0 });
1372
+ }
1373
+ /**
1374
+ * Valibot v1 printer. Turns a `SchemaNode` into the code of a Valibot schema.
1375
+ *
1376
+ * @example
1377
+ * ```ts
1378
+ * const printer = printerValibot({})
1379
+ *
1380
+ * printer.print(ast.factory.createSchema({ type: 'string', min: 1 })) // 'v.pipe(v.string(), v.minLength(1))'
1381
+ * ```
1382
+ */
1383
+ const printerValibot = createPrinter((options) => {
1384
+ const { cyclicSchemas } = options;
1385
+ const isObjectNode = (node) => {
1386
+ const resolved = ast.ref.mergeSchema(node);
1387
+ return isObjectSchemaNode(node, cyclicSchemas) && resolved.default === void 0 && !hasPatternKeyCheck(resolved);
1388
+ };
1389
+ let uncheckedNode = null;
1390
+ const unionsWithSiblings = /* @__PURE__ */ new WeakSet();
1391
+ const printNullable = (schema, output) => output && schema.nullable ? `v.nullable(${output})` : output;
1392
+ const formatString = (action, node) => pipe("v.string()", [action, ...lengthActions(node, options.regexType)]);
1393
+ const mergesToObject = (node) => {
1394
+ const [first, ...rest] = ast.schema.narrow(node, ast.schema.types.intersection)?.members ?? [];
1395
+ if (!first || rest.length === 0) return false;
1396
+ const baseObject = ast.schema.narrow(ast.ref.mergeSchema(first), ast.schema.types.object);
1397
+ return !(Boolean(baseObject?.patternProperties) || baseObject?.additionalProperties !== void 0 && typeof baseObject.additionalProperties !== "boolean") && isObjectNode(first) && isObjectComposableIntersection(node, cyclicSchemas);
1398
+ };
1399
+ const printsEntries = (node) => {
1400
+ const ref = ast.schema.narrow(node, ast.schema.types.ref);
1401
+ if (ref?.schema && ref.schema !== ref) return printsEntries(ref.schema);
1402
+ if (ref) return true;
1403
+ return node.type === ast.schema.types.object ? node.properties.length > 0 : mergesToObject(node);
1404
+ };
1405
+ function omitKeys({ node, transformed, keysToOmit }) {
1406
+ const target = ast.schema.narrow(node, "ref")?.schema ?? node;
1407
+ const keys = `[${keysToOmit.map((key) => text.quote(key)).join(", ")}]`;
1408
+ if (transformed.startsWith("v.lazy(")) return transformed;
1409
+ const base = `${transformed}${unwrapChain(node, this.options.direction)}`;
1410
+ if (!hasChecks(target)) return `v.omit(${base}, ${keys})`;
1411
+ if (node.type === ast.schema.types.ref) {
1412
+ const count = countChecks(target);
1413
+ const checks = Array.from({ length: count }, (_, index) => `${base}.pipe[${index + 1}]`);
1414
+ return pipe(UNKNOWN, [...checks, `v.omit(${base}.pipe[${count + 1}], ${keys})`]);
1415
+ }
1416
+ uncheckedNode = node;
1417
+ try {
1418
+ return pipe(UNKNOWN, [...inputChecks(this, node), `v.omit(${this.transform(node)}, ${keys})`]);
1419
+ } finally {
1420
+ uncheckedNode = null;
1421
+ }
1422
+ }
1423
+ return {
1424
+ name: "valibot",
1425
+ options,
1426
+ nodes: withInputChecks({
1427
+ any: () => "v.any()",
1428
+ unknown: () => UNKNOWN,
1429
+ void: () => "v.void()",
1430
+ never: () => "v.never()",
1431
+ boolean: () => "v.boolean()",
1432
+ null: () => "v.null()",
1433
+ blob: () => "v.blob()",
1434
+ ipv4: () => "v.pipe(v.string(), v.ipv4())",
1435
+ ipv6: () => "v.pipe(v.string(), v.ipv6())",
1436
+ string(node) {
1437
+ const coerce = shouldCoerce(this.options.coercion, "strings");
1438
+ const format = stringFormatActions.get(node.format) ?? (node.content?.encoding?.toLowerCase() === "base64" ? "v.base64()" : void 0);
1439
+ const pattern = node.pattern ?? integerFormatPattern(node.format);
1440
+ const actions = [
1441
+ coerce && "v.toString()",
1442
+ format,
1443
+ ...lengthActions({
1444
+ ...node,
1445
+ pattern
1446
+ }, this.options.regexType)
1447
+ ];
1448
+ const contentNode = ast.schema.getEmbeddedJson(node);
1449
+ if (!contentNode) return pipe(coerce ? UNKNOWN : "v.string()", actions);
1450
+ const { direction } = this.options;
1451
+ this.options.direction = "decode";
1452
+ let content;
1453
+ try {
1454
+ content = this.transform(contentNode);
1455
+ } finally {
1456
+ this.options.direction = direction;
1457
+ }
1458
+ return pipe(coerce ? UNKNOWN : "v.string()", [...actions, content && `v.check((value) => { try { return v.is(${content}, JSON.parse(value)) } catch { return false } }, "String must hold JSON that matches its content schema")`]);
1459
+ },
1460
+ uuid: (node) => formatString("v.uuid()", node),
1461
+ email: (node) => formatString("v.email()", node),
1462
+ url: (node) => formatString("v.url()", node),
1463
+ number(node) {
1464
+ const coerce = shouldCoerce(this.options.coercion, "numbers");
1465
+ return pipe(coerce ? UNKNOWN : "v.number()", [coerce && "v.toNumber()", ...numberActions(node)]);
1466
+ },
1467
+ integer(node) {
1468
+ const coerce = shouldCoerce(this.options.coercion, "numbers");
1469
+ return pipe(coerce ? UNKNOWN : "v.number()", [
1470
+ coerce && "v.toNumber()",
1471
+ "v.integer()",
1472
+ ...numberActions(withFormatRange(node, "integer"))
1473
+ ]);
1474
+ },
1475
+ bigint(node) {
1476
+ return pipe("v.union([v.bigint(), v.number(), v.string()])", ["v.toBigint()", ...numberActions(withFormatRange({
1477
+ ...bigintConstraints(node),
1478
+ format: node.format
1479
+ }, "bigint"), true)]);
1480
+ },
1481
+ ...directionalNodes,
1482
+ datetime(node) {
1483
+ return node.local || this.options.dateType === "stringLocal" ? "v.string()" : "v.pipe(v.string(), v.isoTimestamp())";
1484
+ },
1485
+ enum(node) {
1486
+ return buildEnum(ast.schema.getLiterals(node).filter((value) => value !== null));
1487
+ },
1488
+ ref(node) {
1489
+ if (!node.name) return null;
1490
+ const refName = ast.ref.getName(node);
1491
+ if (!refName) return null;
1492
+ const useInputVariant = node.ref != null && this.options.direction === "encode" && containsDirectionalNode({
1493
+ node,
1494
+ printerOptions: this.options
1495
+ });
1496
+ const resolver = this.options.resolver;
1497
+ const resolvedName = node.ref ? (useInputVariant ? resolver?.schema.inputName(refName) : resolver?.name(refName)) ?? refName : node.name;
1498
+ return node.ref && cyclicSchemas?.has(refName) ? `v.lazy(() => ${resolvedName})` : resolvedName;
1499
+ },
1500
+ object(node) {
1501
+ const hasProperties = node.properties.length > 0;
1502
+ const patterns = node.patternProperties ? Object.entries(node.patternProperties) : [];
1503
+ const shape = buildObject(objectEntries(this, node.properties));
1504
+ const keySchema = node.propertyNames ? this.transform(node.propertyNames) : null;
1505
+ const isStrict = node.additionalProperties === false && patterns.length === 0;
1506
+ if (node.additionalProperties && node.additionalProperties !== true) {
1507
+ const rest = this.transform(node.additionalProperties);
1508
+ if (rest) return hasProperties ? `v.objectWithRest(${shape}, ${rest})` : `v.record(${keySchema ?? "v.string()"}, ${rest})`;
1509
+ }
1510
+ if (isStrict) return `v.strictObject(${shape})`;
1511
+ if (!hasProperties && patterns.length === 0 && keySchema) return `v.record(${keySchema}, ${UNKNOWN})`;
1512
+ if (node.additionalProperties === true) return `v.looseObject(${shape})`;
1513
+ if (patterns.length > 0) {
1514
+ const values = [...new Set(patterns.map(([, schema]) => printNullable(schema, this.transform(schema) ?? UNKNOWN)))];
1515
+ const value = values.length === 1 ? values[0] : `v.union(${buildList(values)})`;
1516
+ if (hasProperties) return `v.objectWithRest(${shape}, ${value})`;
1517
+ return `v.record(${pipe("v.string()", lengthActions({ pattern: patterns.length === 1 ? patterns[0][0] : patterns.map(([pattern]) => `(${pattern})`).join("|") }, this.options.regexType))}, ${value})`;
1518
+ }
1519
+ return `v.object(${shape})`;
1520
+ },
1521
+ array(node) {
1522
+ const items = (node.items ?? []).map((item) => printNullable(item, this.transform(item))).filter((item) => Boolean(item));
1523
+ return pipe(`v.array(${items.length > 1 ? `v.union(${buildList(items)})` : items[0] ?? UNKNOWN})`, [
1524
+ ...lengthActions({
1525
+ min: node.min,
1526
+ max: node.max
1527
+ }, this.options.regexType),
1528
+ node.unique && "v.check((items) => new Set(items).size === items.length, \"Array entries must be unique\")",
1529
+ node.contains && containsCheck(this, node.contains)
1530
+ ]);
1531
+ },
1532
+ tuple(node) {
1533
+ const items = buildList((node.items ?? []).map((item) => printNullable(item, this.transform(item))).filter((item) => Boolean(item)));
1534
+ const rest = node.rest ? this.transform(node.rest) : null;
1535
+ return pipe(rest ? `v.tupleWithRest(${items}, ${rest})` : `v.tuple(${items})`, [node.contains && containsCheck(this, node.contains)]);
1536
+ },
1537
+ union(node) {
1538
+ const nodeMembers = node.members ?? [];
1539
+ const { discriminatorPropertyName } = node;
1540
+ const isDiscriminated = !!discriminatorPropertyName && nodeMembers.every(isObjectNode);
1541
+ const isXor = node.strategy === "one" && !isDiscriminated && this.options.oneOfType === "xor";
1542
+ const isStrict = node.strategy === "one" && !isXor && !isDiscriminated && !unionsWithSiblings.has(node);
1543
+ const members = nodeMembers.map((member) => {
1544
+ const output = this.transform(isStrict ? strictOneOfNode(member) : member);
1545
+ return printNullable(member, output && isStrict ? strictMember({
1546
+ member: output,
1547
+ node: member,
1548
+ cyclicSchemas
1549
+ }) : output);
1550
+ }).filter((member) => Boolean(member));
1551
+ if (members.length === 0) return "";
1552
+ if (members.length === 1) return members[0];
1553
+ if (isDiscriminated) return `v.variant(${text.quote(discriminatorPropertyName)}, ${buildList(members)})`;
1554
+ const union = `v.union(${buildList(members)})`;
1555
+ return isXor ? `((schema) => v.pipe(v.unknown(), v.check((value) => schema.options.filter((member) => v.is(member, value)).length === 1, "Value must match exactly one schema"), schema))(${union})` : union;
1556
+ },
1557
+ intersection(node) {
1558
+ const members = node.members ?? [];
1559
+ const [first, ...rest] = members;
1560
+ if (!first) return "";
1561
+ const hasSiblingProperties = members.some((member) => member.type === ast.schema.types.object && member.properties.length > 0);
1562
+ const transform = (member) => {
1563
+ if (!hasSiblingProperties) return this.transform(member);
1564
+ unionsWithSiblings.add(member);
1565
+ try {
1566
+ return this.transform(member);
1567
+ } finally {
1568
+ unionsWithSiblings.delete(member);
1569
+ }
1570
+ };
1571
+ const firstBase = transform(first);
1572
+ if (!firstBase) return "";
1573
+ const base = ast.ref.mergeSchema(first);
1574
+ const baseObject = ast.schema.narrow(base, ast.schema.types.object);
1575
+ if (mergesToObject(node)) {
1576
+ const discriminator = ast.schema.narrow(first, ast.schema.types.union)?.discriminatorPropertyName;
1577
+ const properties = new Map(preserveRequiredProperties(members).slice(1).flatMap((member) => ast.schema.narrow(member, ast.schema.types.object)?.properties ?? []).filter((property) => property.name !== discriminator).map((property) => [property.name, property]));
1578
+ const additional = baseObject?.additionalProperties;
1579
+ return `${additional === true ? "v.looseObject" : additional === false ? "v.strictObject" : "v.object"}(${buildObject([`...${firstBase}.entries`, ...objectEntries(this, [...properties.values()])])})`;
1580
+ }
1581
+ const schemas = [firstBase];
1582
+ const actions = [];
1583
+ for (const member of rest) {
1584
+ const constraints = memberActions({
1585
+ member,
1586
+ base,
1587
+ regexType: this.options.regexType
1588
+ });
1589
+ const transformed = constraints.length ? null : transform(member);
1590
+ actions.push(...constraints);
1591
+ if (transformed) schemas.push(transformed);
1592
+ }
1593
+ return pipe(schemas.length > 1 ? `v.intersect(${buildList(schemas)})` : firstBase, actions);
1594
+ }
1595
+ }, (node) => node === uncheckedNode),
1596
+ overrides: options.nodes,
1597
+ print(node) {
1598
+ const transformed = this.transform(node);
1599
+ if (!transformed) return null;
1600
+ const { keysToOmit, direction } = this.options;
1601
+ const meta = ast.ref.mergeSchema(node);
1602
+ return applyModifiers({
1603
+ value: keysToOmit?.length && printsEntries(node) ? omitKeys.call(this, {
1604
+ node,
1605
+ transformed,
1606
+ keysToOmit
1607
+ }) : transformed,
1608
+ schema: node,
1609
+ nullable: meta.nullable,
1610
+ optional: meta.optional,
1611
+ nullish: meta.nullish,
1612
+ defaultValue: meta.default,
1613
+ title: hasMetadata(node) ? meta.title : void 0,
1614
+ description: hasMetadata(node) ? meta.description : void 0,
1615
+ examples: hasMetadata(node) ? meta.examples : void 0,
1616
+ direction
1617
+ });
1618
+ }
1619
+ };
1620
+ });
1621
+ // src/generators/valibotGenerator.tsx
1622
+ /**
1623
+ * The printer for one direction, built once per plugin per build. A `keysToOmit` list and a
1624
+ * `printer.nodes` override differ per node and have no string key, so they get a fresh printer.
1625
+ */
1626
+ function getPrinter(resolver, options, direction) {
1627
+ const build = () => printerValibot({
1628
+ ...options,
1629
+ direction
1630
+ });
1631
+ if (options.nodes || options.keysToOmit?.length) return build();
1632
+ return resolver.memo(`valibotPrinter:${[
1633
+ direction,
1634
+ JSON.stringify(options.coercion),
1635
+ options.regexType,
1636
+ options.oneOfType,
1637
+ options.dateType
1638
+ ].join(":")}`, build);
1639
+ }
1640
+ const inferKinds = {
1641
+ encode: "InferInput",
1642
+ decode: "InferOutput"
1643
+ };
1644
+ /**
1645
+ * Built-in generator for `@kubb/plugin-valibot`. Emits one Valibot schema per schema in the spec,
1646
+ * plus the parameter, request, and response schemas of each operation.
1647
+ */
1648
+ const valibotGenerator = defineGenerator({
1649
+ name: "valibot",
1650
+ renderer: jsxRenderer,
1651
+ schema(node, ctx) {
1652
+ const { adapter, config, resolver, root } = ctx;
1653
+ const { output, regexType, oneOfType, coercion, inferred, typeGuards, importPath, group, printer } = ctx.options;
1654
+ if (!node.name) return;
1655
+ const cyclicSchemas = getCircularNames(ctx);
1656
+ const printerOptions = {
1657
+ regexType,
1658
+ oneOfType,
1659
+ coercion,
1660
+ dateType: getOasAdapter(adapter).options.dateType,
1661
+ resolver,
1662
+ cyclicSchemas,
1663
+ nodes: printer?.nodes
1664
+ };
1665
+ const hasDirectionalNode = containsDirectionalNode({
1666
+ node,
1667
+ printerOptions
1668
+ });
1669
+ const inputImports = hasDirectionalNode ? collectDirectionalRefNames({
1670
+ node,
1671
+ printerOptions
1672
+ }).map((schemaName) => ({
1673
+ name: [resolver.schema.inputName(schemaName)],
1674
+ path: resolver.file({
1675
+ name: schemaName,
1676
+ extname: ".ts",
1677
+ root,
1678
+ output,
1679
+ group: group ?? void 0
1680
+ }).path
1681
+ })) : [];
1682
+ const imports = [...new Map([...resolver.imports({
1683
+ node,
1684
+ root,
1685
+ output,
1686
+ group: group ?? void 0,
1687
+ checks: true
1688
+ }), ...inputImports].map((imp) => [`${Array.isArray(imp.name) ? imp.name.join(",") : imp.name}|${imp.path}`, imp])).values()];
1689
+ const inputName = resolver.schema.inputName(node.name);
1690
+ const meta = {
1691
+ name: resolver.name(node.name),
1692
+ file: resolver.file({
1693
+ name: node.name,
1694
+ extname: ".ts",
1695
+ root,
1696
+ output,
1697
+ group: group ?? void 0
1698
+ })
1699
+ };
1700
+ return /* @__PURE__ */ jsxs(File, {
1701
+ baseName: meta.file.baseName,
1702
+ path: meta.file.path,
1703
+ meta: meta.file.meta,
1704
+ banner: resolver.default.banner(ctx.meta, {
1705
+ output,
1706
+ config,
1707
+ file: {
1708
+ path: meta.file.path,
1709
+ baseName: meta.file.baseName
1710
+ }
1711
+ }),
1712
+ footer: resolver.default.footer(ctx.meta, {
1713
+ output,
1714
+ config,
1715
+ file: {
1716
+ path: meta.file.path,
1717
+ baseName: meta.file.baseName
1718
+ }
1719
+ }),
1720
+ children: [
1721
+ /* @__PURE__ */ jsx(File.Import, {
1722
+ name: "v",
1723
+ path: importPath,
1724
+ isNameSpace: true
1725
+ }),
1726
+ imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
1727
+ root: meta.file.path,
1728
+ path: imp.path,
1729
+ name: imp.name
1730
+ }, [
1731
+ node.name,
1732
+ imp.path,
1733
+ imp.name
1734
+ ].join("-"))),
1735
+ /* @__PURE__ */ jsx(Valibot, {
1736
+ name: meta.name,
1737
+ node,
1738
+ printer: getPrinter(resolver, printerOptions, "decode"),
1739
+ inferTypeName: inferred ? resolver.schema.typeName(node.name) : null,
1740
+ typeGuards,
1741
+ isName: resolver.schema.isName(node.name),
1742
+ assertName: resolver.schema.assertName(node.name),
1743
+ cyclic: cyclicSchemas.has(node.name),
1744
+ comments: schemaComments(node)
1745
+ }),
1746
+ hasDirectionalNode && /* @__PURE__ */ jsx(Valibot, {
1747
+ name: inputName,
1748
+ node,
1749
+ printer: getPrinter(resolver, printerOptions, "encode"),
1750
+ inferTypeName: inferred ? resolver.schema.inputTypeName(node.name) : null,
1751
+ inferKind: "InferInput",
1752
+ typeGuards,
1753
+ isName: resolver.schema.isName(inputName),
1754
+ assertName: resolver.schema.assertName(inputName),
1755
+ cyclic: cyclicSchemas.has(node.name),
1756
+ comments: schemaComments(node)
1757
+ })
1758
+ ]
1759
+ });
1760
+ },
1761
+ operation(node, ctx) {
1762
+ if (!ast.http.isOperation(node)) return null;
1763
+ const { adapter, config, resolver, root } = ctx;
1764
+ const { output, regexType, oneOfType, coercion, inferred, importPath, group, printer } = ctx.options;
1765
+ const dateType = getOasAdapter(adapter).options.dateType;
1766
+ const meta = { file: resolveOperationFile({
1767
+ ctx,
1768
+ node,
1769
+ resolver,
1770
+ root,
1771
+ output,
1772
+ group
1773
+ }) };
1774
+ const cyclicSchemas = getCircularNames(ctx);
1775
+ const printerOptions = {
1776
+ regexType,
1777
+ oneOfType,
1778
+ coercion,
1779
+ dateType,
1780
+ resolver,
1781
+ cyclicSchemas,
1782
+ nodes: printer?.nodes
1783
+ };
1784
+ function renderSchemaEntry({ schema, name, keysToOmit, direction = "decode" }) {
1785
+ if (!schema) return null;
1786
+ const refName = schema.type === "ref" ? ast.ref.getName(schema) : null;
1787
+ const target = schema.type === "ref" ? schema.schema : void 0;
1788
+ if (keysToOmit?.length && target && refName && cyclicSchemas.has(refName)) {
1789
+ const declaresKey = (node) => keysToOmit.some((propertyName) => ast.schema.findProperties({
1790
+ node,
1791
+ propertyName
1792
+ }).length > 0);
1793
+ const withoutKeys = (node, seen = /* @__PURE__ */ new Set()) => {
1794
+ if (node.type === "object") return {
1795
+ ...node,
1796
+ properties: node.properties.filter((property) => !keysToOmit.includes(property.name))
1797
+ };
1798
+ if (node.type === "intersection") return {
1799
+ ...node,
1800
+ members: (node.members ?? []).map((member) => withoutKeys(member, seen))
1801
+ };
1802
+ if (node.type !== "ref" || !node.schema || seen.has(node.schema) || !declaresKey(node.schema)) return node;
1803
+ return withoutKeys(node.schema, new Set(seen).add(node.schema));
1804
+ };
1805
+ const inline = withoutKeys(target);
1806
+ if (inline.type === "object" || inline.type === "intersection") return renderSchemaEntry({
1807
+ schema: inline,
1808
+ name,
1809
+ direction
1810
+ });
1811
+ }
1812
+ const inputRefNames = direction === "encode" ? new Set(collectDirectionalRefNames({
1813
+ node: schema,
1814
+ printerOptions
1815
+ })) : null;
1816
+ const imports = resolver.imports({
1817
+ node: schema,
1818
+ root,
1819
+ output,
1820
+ group: group ?? void 0,
1821
+ checks: true,
1822
+ name: (schemaName) => inputRefNames?.has(schemaName) ? resolver.schema.inputName(schemaName) : resolver.name(schemaName)
1823
+ });
1824
+ return /* @__PURE__ */ jsxs(Fragment, { children: [imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
1825
+ root: meta.file.path,
1826
+ path: imp.path,
1827
+ name: imp.name
1828
+ }, [
1829
+ name,
1830
+ imp.path,
1831
+ imp.name
1832
+ ].join("-"))), /* @__PURE__ */ jsx(Valibot, {
1833
+ name,
1834
+ node: schema,
1835
+ printer: getPrinter(resolver, {
1836
+ ...printerOptions,
1837
+ keysToOmit
1838
+ }, direction),
1839
+ inferTypeName: inferred ? resolver.schema.type(name) : null,
1840
+ inferKind: inferKinds[direction],
1841
+ comments: schemaComments(schema)
1842
+ })] });
1843
+ }
1844
+ const renderContentTypeVariants = (entries, baseName, direction) => /* @__PURE__ */ jsx(Fragment, { children: buildContentTypeEntries(entries, baseName).map((entry) => renderSchemaEntry({
1845
+ ...entry,
1846
+ direction
1847
+ })) });
1848
+ const renderResponseUnion = (responses, name, fallbackUnknown) => renderSchemaEntry({
1849
+ schema: buildResponseUnionSchema({
1850
+ node,
1851
+ responses,
1852
+ name,
1853
+ resolver,
1854
+ fallbackUnknown
1855
+ }),
1856
+ name
1857
+ });
1858
+ const paramSchemas = node.parameters.map((param) => renderSchemaEntry({
1859
+ schema: param.schema,
1860
+ name: resolver.param.name(node, param),
1861
+ direction: "encode"
1862
+ }));
1863
+ const responseSchemas = node.responses.map((res) => {
1864
+ const content = (res.content ?? []).map((entry, _, content) => toResponseContent(entry, content));
1865
+ const variants = content.filter((entry) => entry.schema);
1866
+ if (variants.length > 1) return renderContentTypeVariants(content, resolver.response.status(node, res.statusCode));
1867
+ const primary = variants[0] ?? content[0];
1868
+ return renderSchemaEntry({
1869
+ schema: primary?.schema ?? null,
1870
+ name: resolver.response.status(node, res.statusCode),
1871
+ keysToOmit: primary?.keysToOmit
1872
+ });
1873
+ });
1874
+ const responseHeaderSchemas = node.responses.map((res) => res.headers?.length ? renderSchemaEntry({
1875
+ schema: buildParamsSchema(res.headers),
1876
+ name: resolver.response.headers(node, res.statusCode)
1877
+ }) : null);
1878
+ const responsesWithSchema = node.responses.filter((res) => res.content?.some((entry) => entry.schema));
1879
+ const successResponsesWithSchema = responsesWithSchema.filter((res) => ast.http.status.isSuccess(res));
1880
+ const responseUnionSchema = responsesWithSchema.length > 0 ? renderResponseUnion(successResponsesWithSchema, resolver.response.response(node), true) : null;
1881
+ const errorResponsesWithSchema = responsesWithSchema.filter((res) => !ast.http.status.isSuccess(res));
1882
+ const errorUnionSchema = errorResponsesWithSchema.length > 0 ? renderResponseUnion(errorResponsesWithSchema, resolver.response.error(node), false) : null;
1883
+ const requestBodyContent = node.requestBody?.content ?? [];
1884
+ const requestSchema = (() => {
1885
+ if (requestBodyContent.length === 0) return null;
1886
+ if (requestBodyContent.length === 1) {
1887
+ const entry = requestBodyContent[0];
1888
+ if (!entry.schema) return null;
1889
+ return renderSchemaEntry({
1890
+ schema: entry.schema,
1891
+ name: resolver.response.body(node),
1892
+ keysToOmit: entry.keysToOmit,
1893
+ direction: "encode"
1894
+ });
1895
+ }
1896
+ return renderContentTypeVariants(requestBodyContent, resolver.response.body(node), "encode");
1897
+ })();
1898
+ const { path, query, header, cookie } = ast.http.groupParameters(node);
1899
+ const paramGroupSchemas = [
1900
+ {
1901
+ kind: "path",
1902
+ params: path
1903
+ },
1904
+ {
1905
+ kind: "query",
1906
+ params: query
1907
+ },
1908
+ {
1909
+ kind: "headers",
1910
+ params: header
1911
+ },
1912
+ {
1913
+ kind: "cookies",
1914
+ params: cookie
1915
+ }
1916
+ ].filter(({ params }) => params.length > 0).map(({ kind, params }) => renderSchemaEntry({
1917
+ schema: buildParamRefsSchema({
1918
+ node,
1919
+ params,
1920
+ resolver
1921
+ }),
1922
+ name: resolver.param[kind](node, params[0]),
1923
+ direction: "encode"
1924
+ }));
1925
+ const optionsSchema = inferred ? renderSchemaEntry({
1926
+ schema: buildOptionsSchema(node, resolver),
1927
+ name: resolver.name(`${node.operationId} Options`),
1928
+ direction: "encode"
1929
+ }) : null;
1930
+ const responsesSchema = inferred ? renderSchemaEntry({
1931
+ schema: buildResponses(node, resolver),
1932
+ name: resolver.response.responses(node)
1933
+ }) : null;
1934
+ return /* @__PURE__ */ jsxs(File, {
1935
+ baseName: meta.file.baseName,
1936
+ path: meta.file.path,
1937
+ meta: meta.file.meta,
1938
+ banner: resolver.default.banner(ctx.meta, {
1939
+ output,
1940
+ config,
1941
+ file: {
1942
+ path: meta.file.path,
1943
+ baseName: meta.file.baseName
1944
+ }
1945
+ }),
1946
+ footer: resolver.default.footer(ctx.meta, {
1947
+ output,
1948
+ config,
1949
+ file: {
1950
+ path: meta.file.path,
1951
+ baseName: meta.file.baseName
1952
+ }
1953
+ }),
1954
+ children: [
1955
+ /* @__PURE__ */ jsx(File.Import, {
1956
+ name: "v",
1957
+ path: importPath,
1958
+ isNameSpace: true
1959
+ }),
1960
+ paramSchemas,
1961
+ responseSchemas,
1962
+ responseHeaderSchemas,
1963
+ responseUnionSchema,
1964
+ errorUnionSchema,
1965
+ requestSchema,
1966
+ paramGroupSchemas,
1967
+ optionsSchema,
1968
+ responsesSchema
1969
+ ]
1970
+ });
1971
+ }
1972
+ });
1973
+ // kubb-extension.json
1974
+ var compatibility = {
1975
+ "kubb": ">=5.19.0",
1976
+ "node": ">=22.22"
1977
+ };
1978
+ // package.json
1979
+ var version = "0.0.0";
1980
+ // src/resolvers/resolverValibot.ts
1981
+ /**
1982
+ * Default resolver for `@kubb/plugin-valibot`. Schema and file names are camelCase with a `Schema`
1983
+ * suffix, and inferred types are PascalCase.
1984
+ *
1985
+ * @example
1986
+ * ```ts
1987
+ * resolverValibot.name('list pets') // 'listPetsSchema'
1988
+ * resolverValibot.schema.typeName('pet') // 'PetSchemaType'
1989
+ * ```
1990
+ */
1991
+ const resolverValibot = createResolver({
1992
+ pluginName: "plugin-valibot",
1993
+ name(name) {
1994
+ return this.memo(`name:${name}`, () => ensureValidVarName(casing.camel(name, { suffix: "schema" })));
1995
+ },
1996
+ file: createCasedFile((part) => casing.camel(part, { suffix: "schema" })),
1997
+ schema: {
1998
+ typeName(name) {
1999
+ return this.memo(`typeName:${name}`, () => ensureValidVarName(casing.pascal(name, { suffix: "schema type" })));
2000
+ },
2001
+ type(name) {
2002
+ return this.memo(`type:${name}`, () => ensureValidVarName(casing.pascal(name, { suffix: "type" })));
2003
+ },
2004
+ inputName(name) {
2005
+ return this.name(`${name} input`);
2006
+ },
2007
+ inputTypeName(name) {
2008
+ return this.schema.typeName(`${name} input`);
2009
+ },
2010
+ isName(name) {
2011
+ return ensureValidVarName(casing.camel(name, { prefix: "is" }));
2012
+ },
2013
+ assertName(name) {
2014
+ return ensureValidVarName(casing.camel(name, { prefix: "assert" }));
2015
+ }
2016
+ },
2017
+ param: createOperationParamResolver(),
2018
+ response: {
2019
+ ...createOperationResponseResolver(),
2020
+ error(node) {
2021
+ const name = this.name(`${node.operationId} Error`);
2022
+ return this.resolveName({
2023
+ key: operationKey(node, "response", "error"),
2024
+ name
2025
+ });
2026
+ },
2027
+ options(node) {
2028
+ const name = this.schema.type(this.name(`${node.operationId} Options`));
2029
+ return this.resolveName({
2030
+ key: operationKey(node, "response", "options"),
2031
+ name
2032
+ });
2033
+ }
2034
+ }
2035
+ });
2036
+ // src/plugin.ts
2037
+ /**
2038
+ * Canonical plugin name for `@kubb/plugin-valibot`. Used for driver lookups and cross-plugin
2039
+ * dependency references.
2040
+ */
2041
+ const pluginValibotName = "plugin-valibot";
2042
+ /**
2043
+ * Generates Valibot v1 schemas from an OpenAPI spec. Use them to validate API responses at
2044
+ * runtime, build form schemas, or pass them to any library that takes a Standard Schema.
2045
+ *
2046
+ * @example
2047
+ * ```ts
2048
+ * import { defineConfig } from 'kubb/config'
2049
+ * import { pluginValibot } from '@kubb/plugin-valibot'
2050
+ *
2051
+ * export default defineConfig({
2052
+ * input: './petStore.yaml',
2053
+ * output: { path: './src/gen' },
2054
+ * plugins: [
2055
+ * pluginValibot({
2056
+ * output: { path: './valibot' },
2057
+ * inferred: true,
2058
+ * }),
2059
+ * ],
2060
+ * })
2061
+ * ```
2062
+ */
2063
+ const pluginValibot = defineExtension({
2064
+ kind: "plugin",
2065
+ meta: {
2066
+ name: pluginValibotName,
2067
+ version,
2068
+ compatibility
2069
+ },
2070
+ setup(options) {
2071
+ const { output = {
2072
+ path: "valibot",
2073
+ barrel: { type: "named" }
2074
+ }, group, exclude = [], include, override = [], importPath = "valibot", inferred = false, regexType = "literal", oneOfType = "union", coercion = false, typeGuards = false, printer, resolver: userResolver, macros: userMacros } = options;
2075
+ setResolver(userResolver ? Resolver.merge(resolverValibot, userResolver) : resolverValibot);
2076
+ if (userMacros?.length) setMacros(userMacros);
2077
+ addGenerator(valibotGenerator);
2078
+ return {
2079
+ output,
2080
+ exclude,
2081
+ include,
2082
+ override,
2083
+ group: group ?? null,
2084
+ importPath,
2085
+ inferred,
2086
+ regexType,
2087
+ oneOfType,
2088
+ coercion,
2089
+ typeGuards,
2090
+ printer
2091
+ };
2092
+ }
2093
+ });
2094
+ export { pluginValibot as default, pluginValibot, pluginValibotName, printerValibot, resolverValibot, valibotGenerator };
2095
+
2096
+ //# sourceMappingURL=index.js.map