@temporary-name/zod 1.9.3-alpha.afd18ec2afa743b08cf1b5c2eb6252ded18a1f43 → 1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b

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.mjs CHANGED
@@ -1,42 +1,320 @@
1
- import { custom, ZodFirstPartyTypeKind } from 'zod/v3';
2
- import wcmatch from 'wildcard-match';
3
- import { isObject, guard, toArray } from '@temporary-name/shared';
4
- import { JsonSchemaXNativeType } from '@temporary-name/json-schema';
5
- import { JSONSchemaFormat } from '@temporary-name/server/openapi';
6
- import escapeStringRegexp from 'escape-string-regexp';
1
+ import * as core from 'zod/v4/core';
2
+ import { $ZodError, util, _overwrite, _regex, _includes, _startsWith, _endsWith, _minLength, _maxLength, _length, _lowercase, _uppercase, _trim, _normalize, _toLowerCase, _toUpperCase, _gt, _gte, _lt, _lte, _multipleOf } from 'zod/v4/core';
3
+ export { core };
4
+ export { _endsWith as endsWith, _gt as gt, _gte as gte, _includes as includes, _length as length, _lowercase as lowercase, _lt as lt, _lte as lte, _maxLength as maxLength, _maxSize as maxSize, _mime as mime, _minLength as minLength, _minSize as minSize, _multipleOf as multipleOf, _negative as negative, _nonnegative as nonnegative, _nonpositive as nonpositive, _normalize as normalize, _overwrite as overwrite, _positive as positive, _property as property, _regex as regex, _size as size, _startsWith as startsWith, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _trim as trim, _uppercase as uppercase } from 'zod/v4/core';
5
+ import { AsyncLocalStorage } from 'node:async_hooks';
6
+ import { custom as custom$1 } from 'zod/v3';
7
7
 
8
- const CUSTOM_JSON_SCHEMA_SYMBOL = Symbol("ORPC_CUSTOM_JSON_SCHEMA");
9
- const CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol("ORPC_CUSTOM_JSON_SCHEMA_INPUT");
10
- const CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol("ORPC_CUSTOM_JSON_SCHEMA_OUTPUT");
11
- function getCustomJsonSchema(def, options) {
12
- if (options.strategy === "input" && CUSTOM_JSON_SCHEMA_INPUT_SYMBOL in def) {
13
- return def[CUSTOM_JSON_SCHEMA_INPUT_SYMBOL];
8
+ const initializer = (inst, issues) => {
9
+ $ZodError.init(inst, issues);
10
+ inst.name = "ZodError";
11
+ Object.defineProperties(inst, {
12
+ format: {
13
+ value: (mapper) => core.formatError(inst, mapper)
14
+ // enumerable: false,
15
+ },
16
+ flatten: {
17
+ value: (mapper) => core.flattenError(inst, mapper)
18
+ // enumerable: false,
19
+ },
20
+ addIssue: {
21
+ value: (issue) => {
22
+ inst.issues.push(issue);
23
+ inst.message = JSON.stringify(inst.issues, core.util.jsonStringifyReplacer, 2);
24
+ }
25
+ // enumerable: false,
26
+ },
27
+ addIssues: {
28
+ value: (issues2) => {
29
+ inst.issues.push(...issues2);
30
+ inst.message = JSON.stringify(inst.issues, core.util.jsonStringifyReplacer, 2);
31
+ }
32
+ // enumerable: false,
33
+ },
34
+ isEmpty: {
35
+ get() {
36
+ return inst.issues.length === 0;
37
+ }
38
+ // enumerable: false,
39
+ }
40
+ });
41
+ };
42
+ const ZodError = core.$constructor("ZodError", initializer);
43
+ const ZodRealError = core.$constructor("ZodError", initializer, {
44
+ Parent: Error
45
+ });
46
+
47
+ const parse = /* @__PURE__ */ core._parse(ZodRealError);
48
+ const parseAsync = /* @__PURE__ */ core._parseAsync(ZodRealError);
49
+ const safeParse = /* @__PURE__ */ core._safeParse(ZodRealError);
50
+ const safeParseAsync = /* @__PURE__ */ core._safeParseAsync(ZodRealError);
51
+ const encode = /* @__PURE__ */ core._encode(ZodRealError);
52
+ const decode = /* @__PURE__ */ core._decode(ZodRealError);
53
+ const encodeAsync = /* @__PURE__ */ core._encodeAsync(ZodRealError);
54
+ const decodeAsync = /* @__PURE__ */ core._decodeAsync(ZodRealError);
55
+ const safeEncode = /* @__PURE__ */ core._safeEncode(ZodRealError);
56
+ const safeDecode = /* @__PURE__ */ core._safeDecode(ZodRealError);
57
+ const safeEncodeAsync = /* @__PURE__ */ core._safeEncodeAsync(ZodRealError);
58
+ const safeDecodeAsync = /* @__PURE__ */ core._safeDecodeAsync(ZodRealError);
59
+
60
+ const ZodISODateTime = /* @__PURE__ */ core.$constructor(
61
+ "ZodISODateTime",
62
+ (inst, def) => {
63
+ const coreInit = core.$ZodISODateTime.init;
64
+ coreInit(inst, def);
65
+ ZodStringFormat.init(inst, def);
66
+ }
67
+ );
68
+ function datetime(params) {
69
+ return core._isoDateTime(ZodISODateTime, params);
70
+ }
71
+ const ZodISODate = /* @__PURE__ */ core.$constructor(
72
+ "ZodISODate",
73
+ (inst, def) => {
74
+ const coreInit = core.$ZodISODate.init;
75
+ coreInit(inst, def);
76
+ ZodStringFormat.init(inst, def);
14
77
  }
15
- if (options.strategy === "output" && CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL in def) {
16
- return def[CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL];
78
+ );
79
+ function date$1(params) {
80
+ return core._isoDate(ZodISODate, params);
81
+ }
82
+ const ZodISOTime = /* @__PURE__ */ core.$constructor(
83
+ "ZodISOTime",
84
+ (inst, def) => {
85
+ const coreInit = core.$ZodISOTime.init;
86
+ coreInit(inst, def);
87
+ ZodStringFormat.init(inst, def);
17
88
  }
18
- if (CUSTOM_JSON_SCHEMA_SYMBOL in def) {
19
- return def[CUSTOM_JSON_SCHEMA_SYMBOL];
89
+ );
90
+ function time(params) {
91
+ return core._isoTime(ZodISOTime, params);
92
+ }
93
+ const ZodISODuration = /* @__PURE__ */ core.$constructor(
94
+ "ZodISODuration",
95
+ (inst, def) => {
96
+ const coreInit = core.$ZodISODuration.init;
97
+ coreInit(inst, def);
98
+ ZodStringFormat.init(inst, def);
20
99
  }
21
- return void 0;
100
+ );
101
+ function duration(params) {
102
+ return core._isoDuration(ZodISODuration, params);
22
103
  }
23
- function customJsonSchema(schema, custom, options = {}) {
24
- const SYMBOL = options.strategy === "input" ? CUSTOM_JSON_SCHEMA_INPUT_SYMBOL : options.strategy === "output" ? CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL : CUSTOM_JSON_SCHEMA_SYMBOL;
25
- const This = schema.constructor;
26
- const newSchema = new This({
27
- ...schema._def,
28
- [SYMBOL]: custom
104
+
105
+ const gatingContext = new AsyncLocalStorage();
106
+ function isGateIssueRaw(issue) {
107
+ return issue.code === "invalid_type" && issue.expected === "never" && issue.inst instanceof ZodGate;
108
+ }
109
+ function isGateIssue(issue) {
110
+ return issue.code === "invalid_type" && issue.expected === "never" && issue.path?.length === 0;
111
+ }
112
+ const ZodGate = /* @__PURE__ */ core.$constructor("ZodGate", (inst, def) => {
113
+ const coreInit = core.$ZodOptional.init;
114
+ coreInit(inst, def);
115
+ KrustyType.init(inst, def);
116
+ inst._zod.parse = (payload, ctx) => {
117
+ const gateEnabled = gatingContext.getStore()?.(def.gateName);
118
+ if (gateEnabled) {
119
+ return def.innerType._zod.run(payload, ctx);
120
+ } else if (payload.value !== void 0) {
121
+ payload.issues.push({
122
+ expected: "never",
123
+ code: "invalid_type",
124
+ input: payload.value,
125
+ inst
126
+ });
127
+ }
128
+ return payload;
129
+ };
130
+ });
131
+ function gate(innerType, gateName) {
132
+ return new ZodGate({
133
+ type: "optional",
134
+ innerType,
135
+ gateName
136
+ });
137
+ }
138
+
139
+ function handleGating(payload) {
140
+ for (let i = 0; i < payload.issues.length; i++) {
141
+ const issue = payload.issues[i];
142
+ if (issue?.code === "invalid_union") {
143
+ const newErrors = issue.errors.filter((innerIssues) => !innerIssues.some(isGateIssue));
144
+ issue.errors.splice(0, Infinity, ...newErrors);
145
+ }
146
+ }
147
+ return payload;
148
+ }
149
+ const ZodUnion = /* @__PURE__ */ core.$constructor(
150
+ "ZodUnion",
151
+ (inst, def) => {
152
+ const coreInit = core.$ZodUnion.init;
153
+ coreInit(inst, def);
154
+ KrustyType.init(inst, def);
155
+ inst.options = def.options;
156
+ const origParse = inst._zod.parse;
157
+ inst._zod.parse = (payload, ctx) => {
158
+ const res = origParse(payload, ctx);
159
+ if (res instanceof Promise) {
160
+ return res.then((r) => handleGating(r));
161
+ } else {
162
+ return handleGating(res);
163
+ }
164
+ };
165
+ }
166
+ );
167
+ function union(options, params) {
168
+ return new ZodUnion({
169
+ type: "union",
170
+ options,
171
+ ...util.normalizeParams(params)
172
+ });
173
+ }
174
+ const ZodDiscriminatedUnion = /* @__PURE__ */ core.$constructor("ZodDiscriminatedUnion", (inst, def) => {
175
+ ZodUnion.init(inst, def);
176
+ const coreInit = core.$ZodDiscriminatedUnion.init;
177
+ coreInit(inst, def);
178
+ });
179
+ function discriminatedUnion(discriminator, options, params) {
180
+ return new ZodDiscriminatedUnion({
181
+ type: "union",
182
+ options,
183
+ discriminator,
184
+ ...util.normalizeParams(params)
185
+ });
186
+ }
187
+
188
+ function handlePropertyResult(result, final, key, input) {
189
+ if (result.issues.length) {
190
+ final.issues.push(...util.prefixIssues(key, result.issues));
191
+ }
192
+ if (result.value === void 0) {
193
+ if (key in input) {
194
+ final.value[key] = void 0;
195
+ }
196
+ } else {
197
+ final.value[key] = result.value;
198
+ }
199
+ }
200
+ const ZodObject = /* @__PURE__ */ core.$constructor(
201
+ "ZodObject",
202
+ (inst, def) => {
203
+ const coreInit = core.$ZodObjectJIT.init;
204
+ coreInit(inst, def);
205
+ KrustyType.init(inst, def);
206
+ util.defineLazy(inst, "shape", () => {
207
+ return def.shape;
208
+ });
209
+ inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
210
+ inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
211
+ inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
212
+ inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
213
+ inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
214
+ inst.strip = () => inst.clone({ ...inst._zod.def, catchall: void 0 });
215
+ inst.extend = (incoming) => {
216
+ return util.extend(inst, incoming);
217
+ };
218
+ inst.safeExtend = (incoming) => {
219
+ return util.safeExtend(inst, incoming);
220
+ };
221
+ inst.merge = (other) => util.merge(inst, other);
222
+ inst.pick = (mask) => util.pick(inst, mask);
223
+ inst.omit = (mask) => util.omit(inst, mask);
224
+ inst.partial = (...args) => util.partial(ZodOptional, inst, args[0]);
225
+ inst.required = (...args) => util.required(ZodNonOptional, inst, args[0]);
226
+ function handleGating(input, payload, ctx) {
227
+ const _catchall = def.catchall?._zod;
228
+ const t = _catchall?.def.type;
229
+ let newIssues = null;
230
+ const proms = [];
231
+ const newUnrecognizedKeys = [];
232
+ for (let i = 0; i < payload.issues.length; i++) {
233
+ const issue = payload.issues[i];
234
+ if (!isGateIssueRaw(issue)) {
235
+ continue;
236
+ }
237
+ newIssues ??= [...payload.issues];
238
+ newIssues[i] = null;
239
+ const key = issue.path[0];
240
+ if (!_catchall) {
241
+ delete payload.value[key];
242
+ } else if (t === "never") {
243
+ newUnrecognizedKeys.push(key);
244
+ } else {
245
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
246
+ if (r instanceof Promise) {
247
+ proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input)));
248
+ } else {
249
+ handlePropertyResult(r, payload, key, input);
250
+ }
251
+ }
252
+ }
253
+ if (newIssues) {
254
+ payload.issues = newIssues.filter(Boolean);
255
+ }
256
+ if (newUnrecognizedKeys.length > 0) {
257
+ const missingKeyIssue = payload.issues.find(
258
+ (issue) => issue.code === "unrecognized_keys" && !issue.path
259
+ );
260
+ if (missingKeyIssue) {
261
+ missingKeyIssue.keys.push(...newUnrecognizedKeys);
262
+ } else {
263
+ payload.issues.push({
264
+ code: "unrecognized_keys",
265
+ keys: newUnrecognizedKeys,
266
+ input,
267
+ inst
268
+ });
269
+ }
270
+ }
271
+ if (proms.length > 0) {
272
+ return Promise.all(proms).then(() => payload);
273
+ } else {
274
+ return payload;
275
+ }
276
+ }
277
+ const origParse = inst._zod.parse;
278
+ inst._zod.parse = (payload, ctx) => {
279
+ const input = payload.value;
280
+ const res = origParse(payload, ctx);
281
+ if (res instanceof Promise) {
282
+ return res.then((r) => handleGating(input, r, ctx));
283
+ } else {
284
+ return handleGating(input, res, ctx);
285
+ }
286
+ };
287
+ }
288
+ );
289
+ function object(shape, params) {
290
+ const def = {
291
+ type: "object",
292
+ shape: shape ?? {},
293
+ ...util.normalizeParams(params)
294
+ };
295
+ return new ZodObject(def);
296
+ }
297
+ function strictObject(shape, params) {
298
+ return new ZodObject({
299
+ type: "object",
300
+ shape,
301
+ catchall: never(),
302
+ ...util.normalizeParams(params)
303
+ });
304
+ }
305
+ function looseObject(shape, params) {
306
+ return new ZodObject({
307
+ type: "object",
308
+ shape,
309
+ catchall: unknown(),
310
+ ...util.normalizeParams(params)
29
311
  });
30
- return newSchema;
31
312
  }
32
313
 
33
314
  const CUSTOM_ZOD_DEF_SYMBOL = Symbol("ORPC_CUSTOM_ZOD_DEF");
34
315
  function setCustomZodDef(def, custom) {
35
316
  Object.assign(def, { [CUSTOM_ZOD_DEF_SYMBOL]: custom });
36
317
  }
37
- function getCustomZodDef(def) {
38
- return def[CUSTOM_ZOD_DEF_SYMBOL];
39
- }
40
318
  function composeParams(defaultMessage, params) {
41
319
  return (val) => {
42
320
  const message = defaultMessage(val);
@@ -64,7 +342,7 @@ function composeParams(defaultMessage, params) {
64
342
  }
65
343
 
66
344
  function blob(params) {
67
- const schema = custom(
345
+ const schema = custom$1(
68
346
  (val) => val instanceof Blob,
69
347
  composeParams(
70
348
  () => "Input is not a blob",
@@ -75,33 +353,8 @@ function blob(params) {
75
353
  return schema;
76
354
  }
77
355
 
78
- function file(params) {
79
- const schema = custom(
80
- (val) => val instanceof File,
81
- composeParams(
82
- () => "Input is not a file",
83
- params
84
- )
85
- );
86
- setCustomZodDef(schema._def, { type: "file" });
87
- return Object.assign(schema, {
88
- type: (mimeType, params2) => {
89
- const isMatch = wcmatch(mimeType);
90
- const refinedSchema = schema.refine(
91
- (val) => isMatch(val.type.split(";")[0]),
92
- composeParams(
93
- (val) => `Expected a file of type ${mimeType} but got a file of type ${val.type || "unknown"}`,
94
- params2
95
- )
96
- );
97
- setCustomZodDef(refinedSchema._def, { type: "file", mimeType });
98
- return refinedSchema;
99
- }
100
- });
101
- }
102
-
103
356
  function regexp(params) {
104
- const schema = custom(
357
+ const schema = custom$1(
105
358
  (val) => val instanceof RegExp,
106
359
  composeParams(
107
360
  () => "Input is not a regexp",
@@ -112,844 +365,1232 @@ function regexp(params) {
112
365
  return schema;
113
366
  }
114
367
 
368
+ const KrustyType = /* @__PURE__ */ core.$constructor(
369
+ "KrustyType",
370
+ (inst, def) => {
371
+ const coreInit = core.$ZodType.init;
372
+ coreInit(inst, def);
373
+ inst.def = def;
374
+ inst.type = def.type;
375
+ Object.defineProperty(inst, "_def", { value: def });
376
+ inst.check = (...checks2) => {
377
+ return inst.clone(
378
+ util.mergeDefs(def, {
379
+ checks: [
380
+ ...def.checks ?? [],
381
+ ...checks2.map(
382
+ (ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
383
+ )
384
+ ]
385
+ })
386
+ );
387
+ };
388
+ inst.clone = (def2, params) => core.clone(inst, def2, params);
389
+ inst.brand = () => inst;
390
+ inst.register = ((reg, meta) => {
391
+ reg.add(inst, meta);
392
+ return inst;
393
+ });
394
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
395
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
396
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
397
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
398
+ inst.spa = inst.safeParseAsync;
399
+ inst.encode = (data, params) => encode(inst, data, params);
400
+ inst.decode = (data, params) => decode(inst, data, params);
401
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
402
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
403
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
404
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
405
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
406
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
407
+ inst.refine = (check2, params) => inst.check(refine(check2, params));
408
+ inst.superRefine = (refinement) => inst.check(superRefine(refinement));
409
+ inst.overwrite = (fn) => inst.check(_overwrite(fn));
410
+ inst.gate = (gateName) => gate(inst, gateName);
411
+ inst.optional = () => optional(inst);
412
+ inst.nullable = () => nullable(inst);
413
+ inst.nullish = () => optional(nullable(inst));
414
+ inst.nonoptional = (params) => nonoptional(inst, params);
415
+ inst.array = () => array(inst);
416
+ inst.or = (arg) => union([inst, arg]);
417
+ inst.and = (arg) => intersection(inst, arg);
418
+ inst.transform = (tx) => pipe(inst, transform(tx));
419
+ inst.default = (def2) => _default(inst, def2);
420
+ inst.prefault = (def2) => prefault(inst, def2);
421
+ inst.catch = (params) => _catch(inst, params);
422
+ inst.pipe = (target) => pipe(inst, target);
423
+ inst.readonly = () => readonly(inst);
424
+ inst.describe = (description) => {
425
+ const cl = inst.clone();
426
+ core.globalRegistry.add(cl, { description });
427
+ return cl;
428
+ };
429
+ Object.defineProperty(inst, "description", {
430
+ get() {
431
+ return core.globalRegistry.get(inst)?.description;
432
+ },
433
+ configurable: true
434
+ });
435
+ inst.meta = (...args) => {
436
+ if (args.length === 0) {
437
+ return core.globalRegistry.get(inst);
438
+ }
439
+ const cl = inst.clone();
440
+ core.globalRegistry.add(cl, args[0]);
441
+ return cl;
442
+ };
443
+ return inst;
444
+ }
445
+ );
446
+ const _ZodString = /* @__PURE__ */ core.$constructor(
447
+ "_ZodString",
448
+ (inst, def) => {
449
+ const coreInit = core.$ZodString.init;
450
+ coreInit(inst, def);
451
+ KrustyType.init(inst, def);
452
+ const bag = inst._zod.bag;
453
+ inst.format = bag.format ?? null;
454
+ inst.minLength = bag.minimum ?? null;
455
+ inst.maxLength = bag.maximum ?? null;
456
+ inst.regex = (...args) => inst.check(_regex(...args));
457
+ inst.includes = (...args) => inst.check(_includes(...args));
458
+ inst.startsWith = (...args) => inst.check(_startsWith(...args));
459
+ inst.endsWith = (...args) => inst.check(_endsWith(...args));
460
+ inst.min = (...args) => inst.check(_minLength(...args));
461
+ inst.max = (...args) => inst.check(_maxLength(...args));
462
+ inst.length = (...args) => inst.check(_length(...args));
463
+ inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
464
+ inst.lowercase = (params) => inst.check(_lowercase(params));
465
+ inst.uppercase = (params) => inst.check(_uppercase(params));
466
+ inst.trim = () => inst.check(_trim());
467
+ inst.normalize = (...args) => inst.check(_normalize(...args));
468
+ inst.toLowerCase = () => inst.check(_toLowerCase());
469
+ inst.toUpperCase = () => inst.check(_toUpperCase());
470
+ }
471
+ );
472
+ const ZodString = /* @__PURE__ */ core.$constructor(
473
+ "ZodString",
474
+ (inst, def) => {
475
+ const coreInit = core.$ZodString.init;
476
+ coreInit(inst, def);
477
+ _ZodString.init(inst, def);
478
+ inst.email = (params) => inst.check(core._email(ZodEmail, params));
479
+ inst.url = (params) => inst.check(core._url(ZodURL, params));
480
+ inst.jwt = (params) => inst.check(core._jwt(ZodJWT, params));
481
+ inst.emoji = (params) => inst.check(core._emoji(ZodEmoji, params));
482
+ inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
483
+ inst.uuid = (params) => inst.check(core._uuid(ZodUUID, params));
484
+ inst.uuidv4 = (params) => inst.check(core._uuidv4(ZodUUID, params));
485
+ inst.uuidv6 = (params) => inst.check(core._uuidv6(ZodUUID, params));
486
+ inst.uuidv7 = (params) => inst.check(core._uuidv7(ZodUUID, params));
487
+ inst.nanoid = (params) => inst.check(core._nanoid(ZodNanoID, params));
488
+ inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
489
+ inst.cuid = (params) => inst.check(core._cuid(ZodCUID, params));
490
+ inst.cuid2 = (params) => inst.check(core._cuid2(ZodCUID2, params));
491
+ inst.ulid = (params) => inst.check(core._ulid(ZodULID, params));
492
+ inst.base64 = (params) => inst.check(core._base64(ZodBase64, params));
493
+ inst.base64url = (params) => inst.check(core._base64url(ZodBase64URL, params));
494
+ inst.xid = (params) => inst.check(core._xid(ZodXID, params));
495
+ inst.ksuid = (params) => inst.check(core._ksuid(ZodKSUID, params));
496
+ inst.ipv4 = (params) => inst.check(core._ipv4(ZodIPv4, params));
497
+ inst.ipv6 = (params) => inst.check(core._ipv6(ZodIPv6, params));
498
+ inst.cidrv4 = (params) => inst.check(core._cidrv4(ZodCIDRv4, params));
499
+ inst.cidrv6 = (params) => inst.check(core._cidrv6(ZodCIDRv6, params));
500
+ inst.e164 = (params) => inst.check(core._e164(ZodE164, params));
501
+ inst.datetime = (params) => inst.check(datetime(params));
502
+ inst.date = (params) => inst.check(date$1(params));
503
+ inst.time = (params) => inst.check(time(params));
504
+ inst.duration = (params) => inst.check(duration(params));
505
+ }
506
+ );
507
+ function string(params) {
508
+ return core._string(ZodString, params);
509
+ }
510
+ const ZodStringFormat = /* @__PURE__ */ core.$constructor(
511
+ "ZodStringFormat",
512
+ (inst, def) => {
513
+ const coreInit = core.$ZodStringFormat.init;
514
+ coreInit(inst, def);
515
+ _ZodString.init(inst, def);
516
+ }
517
+ );
518
+ const ZodEmail = /* @__PURE__ */ core.$constructor(
519
+ "ZodEmail",
520
+ (inst, def) => {
521
+ const coreInit = core.$ZodEmail.init;
522
+ coreInit(inst, def);
523
+ ZodStringFormat.init(inst, def);
524
+ }
525
+ );
526
+ function email(params) {
527
+ return core._email(ZodEmail, params);
528
+ }
529
+ const ZodGUID = /* @__PURE__ */ core.$constructor("ZodGUID", (inst, def) => {
530
+ const coreInit = core.$ZodGUID.init;
531
+ coreInit(inst, def);
532
+ ZodStringFormat.init(inst, def);
533
+ });
534
+ function guid(params) {
535
+ return core._guid(ZodGUID, params);
536
+ }
537
+ const ZodUUID = /* @__PURE__ */ core.$constructor("ZodUUID", (inst, def) => {
538
+ const coreInit = core.$ZodUUID.init;
539
+ coreInit(inst, def);
540
+ ZodStringFormat.init(inst, def);
541
+ });
542
+ function uuid(params) {
543
+ return core._uuid(ZodUUID, params);
544
+ }
545
+ function uuidv4(params) {
546
+ return core._uuidv4(ZodUUID, params);
547
+ }
548
+ function uuidv6(params) {
549
+ return core._uuidv6(ZodUUID, params);
550
+ }
551
+ function uuidv7(params) {
552
+ return core._uuidv7(ZodUUID, params);
553
+ }
554
+ const ZodURL = /* @__PURE__ */ core.$constructor("ZodURL", (inst, def) => {
555
+ const coreInit = core.$ZodURL.init;
556
+ coreInit(inst, def);
557
+ ZodStringFormat.init(inst, def);
558
+ });
115
559
  function url(params) {
116
- const schema = custom(
117
- (val) => val instanceof URL,
118
- composeParams(
119
- () => "Input is not a URL",
120
- params
121
- )
122
- );
123
- setCustomZodDef(schema._def, { type: "url" });
124
- return schema;
560
+ return core._url(ZodURL, params);
125
561
  }
126
-
127
- class ZodSmartCoercionPlugin {
128
- init(options) {
129
- options.clientInterceptors ??= [];
130
- options.clientInterceptors.unshift((options2) => {
131
- const inputSchema = options2.procedure["~orpc"].inputSchema;
132
- if (!inputSchema || inputSchema["~standard"].vendor !== "zod" || "_zod" in inputSchema) {
133
- return options2.next();
134
- }
135
- const coercedInput = zodCoerceInternal(inputSchema, options2.input);
136
- return options2.next({ ...options2, input: coercedInput });
562
+ function httpUrl(params) {
563
+ return core._url(ZodURL, {
564
+ protocol: /^https?$/,
565
+ hostname: core.regexes.domain,
566
+ ...util.normalizeParams(params)
567
+ });
568
+ }
569
+ const ZodEmoji = /* @__PURE__ */ core.$constructor(
570
+ "ZodEmoji",
571
+ (inst, def) => {
572
+ const coreInit = core.$ZodEmoji.init;
573
+ coreInit(inst, def);
574
+ ZodStringFormat.init(inst, def);
575
+ }
576
+ );
577
+ function emoji(params) {
578
+ return core._emoji(ZodEmoji, params);
579
+ }
580
+ const ZodNanoID = /* @__PURE__ */ core.$constructor(
581
+ "ZodNanoID",
582
+ (inst, def) => {
583
+ const coreInit = core.$ZodNanoID.init;
584
+ coreInit(inst, def);
585
+ ZodStringFormat.init(inst, def);
586
+ }
587
+ );
588
+ function nanoid(params) {
589
+ return core._nanoid(ZodNanoID, params);
590
+ }
591
+ const ZodCUID = /* @__PURE__ */ core.$constructor("ZodCUID", (inst, def) => {
592
+ const coreInit = core.$ZodCUID.init;
593
+ coreInit(inst, def);
594
+ ZodStringFormat.init(inst, def);
595
+ });
596
+ function cuid(params) {
597
+ return core._cuid(ZodCUID, params);
598
+ }
599
+ const ZodCUID2 = /* @__PURE__ */ core.$constructor(
600
+ "ZodCUID2",
601
+ (inst, def) => {
602
+ const coreInit = core.$ZodCUID2.init;
603
+ coreInit(inst, def);
604
+ ZodStringFormat.init(inst, def);
605
+ }
606
+ );
607
+ function cuid2(params) {
608
+ return core._cuid2(ZodCUID2, params);
609
+ }
610
+ const ZodULID = /* @__PURE__ */ core.$constructor("ZodULID", (inst, def) => {
611
+ const coreInit = core.$ZodULID.init;
612
+ coreInit(inst, def);
613
+ ZodStringFormat.init(inst, def);
614
+ });
615
+ function ulid(params) {
616
+ return core._ulid(ZodULID, params);
617
+ }
618
+ const ZodXID = /* @__PURE__ */ core.$constructor("ZodXID", (inst, def) => {
619
+ const coreInit = core.$ZodXID.init;
620
+ coreInit(inst, def);
621
+ ZodStringFormat.init(inst, def);
622
+ });
623
+ function xid(params) {
624
+ return core._xid(ZodXID, params);
625
+ }
626
+ const ZodKSUID = /* @__PURE__ */ core.$constructor(
627
+ "ZodKSUID",
628
+ (inst, def) => {
629
+ const coreInit = core.$ZodKSUID.init;
630
+ coreInit(inst, def);
631
+ ZodStringFormat.init(inst, def);
632
+ }
633
+ );
634
+ function ksuid(params) {
635
+ return core._ksuid(ZodKSUID, params);
636
+ }
637
+ const ZodIPv4 = /* @__PURE__ */ core.$constructor("ZodIPv4", (inst, def) => {
638
+ const coreInit = core.$ZodIPv4.init;
639
+ coreInit(inst, def);
640
+ ZodStringFormat.init(inst, def);
641
+ });
642
+ function ipv4(params) {
643
+ return core._ipv4(ZodIPv4, params);
644
+ }
645
+ const ZodIPv6 = /* @__PURE__ */ core.$constructor("ZodIPv6", (inst, def) => {
646
+ const coreInit = core.$ZodIPv6.init;
647
+ coreInit(inst, def);
648
+ ZodStringFormat.init(inst, def);
649
+ });
650
+ function ipv6(params) {
651
+ return core._ipv6(ZodIPv6, params);
652
+ }
653
+ const ZodCIDRv4 = /* @__PURE__ */ core.$constructor(
654
+ "ZodCIDRv4",
655
+ (inst, def) => {
656
+ const coreInit = core.$ZodCIDRv4.init;
657
+ coreInit(inst, def);
658
+ ZodStringFormat.init(inst, def);
659
+ }
660
+ );
661
+ function cidrv4(params) {
662
+ return core._cidrv4(ZodCIDRv4, params);
663
+ }
664
+ const ZodCIDRv6 = /* @__PURE__ */ core.$constructor(
665
+ "ZodCIDRv6",
666
+ (inst, def) => {
667
+ const coreInit = core.$ZodCIDRv6.init;
668
+ coreInit(inst, def);
669
+ ZodStringFormat.init(inst, def);
670
+ }
671
+ );
672
+ function cidrv6(params) {
673
+ return core._cidrv6(ZodCIDRv6, params);
674
+ }
675
+ const ZodBase64 = /* @__PURE__ */ core.$constructor(
676
+ "ZodBase64",
677
+ (inst, def) => {
678
+ const coreInit = core.$ZodBase64.init;
679
+ coreInit(inst, def);
680
+ ZodStringFormat.init(inst, def);
681
+ }
682
+ );
683
+ function base64(params) {
684
+ return core._base64(ZodBase64, params);
685
+ }
686
+ const ZodBase64URL = /* @__PURE__ */ core.$constructor(
687
+ "ZodBase64URL",
688
+ (inst, def) => {
689
+ const coreInit = core.$ZodBase64URL.init;
690
+ coreInit(inst, def);
691
+ ZodStringFormat.init(inst, def);
692
+ }
693
+ );
694
+ function base64url(params) {
695
+ return core._base64url(ZodBase64URL, params);
696
+ }
697
+ const ZodE164 = /* @__PURE__ */ core.$constructor("ZodE164", (inst, def) => {
698
+ const coreInit = core.$ZodE164.init;
699
+ coreInit(inst, def);
700
+ ZodStringFormat.init(inst, def);
701
+ });
702
+ function e164(params) {
703
+ return core._e164(ZodE164, params);
704
+ }
705
+ const ZodJWT = /* @__PURE__ */ core.$constructor("ZodJWT", (inst, def) => {
706
+ const coreInit = core.$ZodJWT.init;
707
+ coreInit(inst, def);
708
+ ZodStringFormat.init(inst, def);
709
+ });
710
+ function jwt(params) {
711
+ return core._jwt(ZodJWT, params);
712
+ }
713
+ const ZodCustomStringFormat = /* @__PURE__ */ core.$constructor("ZodCustomStringFormat", (inst, def) => {
714
+ const coreInit = core.$ZodCustomStringFormat.init;
715
+ coreInit(inst, def);
716
+ ZodStringFormat.init(inst, def);
717
+ });
718
+ function stringFormat(format, fnOrRegex, _params = {}) {
719
+ return core._stringFormat(ZodCustomStringFormat, format, fnOrRegex, _params);
720
+ }
721
+ function hostname(_params) {
722
+ return core._stringFormat(ZodCustomStringFormat, "hostname", core.regexes.hostname, _params);
723
+ }
724
+ function hex(_params) {
725
+ return core._stringFormat(ZodCustomStringFormat, "hex", core.regexes.hex, _params);
726
+ }
727
+ function hash(alg, params) {
728
+ const enc = params?.enc ?? "hex";
729
+ const format = `${alg}_${enc}`;
730
+ const regex = core.regexes[format];
731
+ if (!regex) throw new Error(`Unrecognized hash format: ${format}`);
732
+ return core._stringFormat(ZodCustomStringFormat, format, regex, params);
733
+ }
734
+ const ZodNumber = /* @__PURE__ */ core.$constructor(
735
+ "ZodNumber",
736
+ (inst, def) => {
737
+ const coreInit = core.$ZodNumber.init;
738
+ coreInit(inst, def);
739
+ KrustyType.init(inst, def);
740
+ inst.gt = (value, params) => inst.check(_gt(value, params));
741
+ inst.gte = (value, params) => inst.check(_gte(value, params));
742
+ inst.min = (value, params) => inst.check(_gte(value, params));
743
+ inst.lt = (value, params) => inst.check(_lt(value, params));
744
+ inst.lte = (value, params) => inst.check(_lte(value, params));
745
+ inst.max = (value, params) => inst.check(_lte(value, params));
746
+ inst.int = (params) => inst.check(int(params));
747
+ inst.safe = (params) => inst.check(int(params));
748
+ inst.positive = (params) => inst.check(_gt(0, params));
749
+ inst.nonnegative = (params) => inst.check(_gte(0, params));
750
+ inst.negative = (params) => inst.check(_lt(0, params));
751
+ inst.nonpositive = (params) => inst.check(_lte(0, params));
752
+ inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
753
+ inst.step = (value, params) => inst.check(_multipleOf(value, params));
754
+ inst.finite = () => inst;
755
+ const bag = inst._zod.bag;
756
+ inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
757
+ inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
758
+ inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
759
+ inst.isFinite = true;
760
+ inst.format = bag.format ?? null;
761
+ }
762
+ );
763
+ function number(params) {
764
+ return core._number(ZodNumber, params);
765
+ }
766
+ const ZodNumberFormat = /* @__PURE__ */ core.$constructor(
767
+ "ZodNumberFormat",
768
+ (inst, def) => {
769
+ const coreInit = core.$ZodNumberFormat.init;
770
+ coreInit(inst, def);
771
+ ZodNumber.init(inst, def);
772
+ }
773
+ );
774
+ function int(params) {
775
+ return core._int(ZodNumberFormat, params);
776
+ }
777
+ function float32(params) {
778
+ return core._float32(ZodNumberFormat, params);
779
+ }
780
+ function float64(params) {
781
+ return core._float64(ZodNumberFormat, params);
782
+ }
783
+ function int32(params) {
784
+ return core._int32(ZodNumberFormat, params);
785
+ }
786
+ function uint32(params) {
787
+ return core._uint32(ZodNumberFormat, params);
788
+ }
789
+ const ZodBoolean = /* @__PURE__ */ core.$constructor(
790
+ "ZodBoolean",
791
+ (inst, def) => {
792
+ const coreInit = core.$ZodBoolean.init;
793
+ coreInit(inst, def);
794
+ KrustyType.init(inst, def);
795
+ }
796
+ );
797
+ function boolean(params) {
798
+ return core._boolean(ZodBoolean, params);
799
+ }
800
+ const ZodBigInt = /* @__PURE__ */ core.$constructor(
801
+ "ZodBigInt",
802
+ (inst, def) => {
803
+ const coreInit = core.$ZodBigInt.init;
804
+ coreInit(inst, def);
805
+ KrustyType.init(inst, def);
806
+ inst.gte = (value, params) => inst.check(_gte(value, params));
807
+ inst.min = (value, params) => inst.check(_gte(value, params));
808
+ inst.gt = (value, params) => inst.check(_gt(value, params));
809
+ inst.gte = (value, params) => inst.check(_gte(value, params));
810
+ inst.min = (value, params) => inst.check(_gte(value, params));
811
+ inst.lt = (value, params) => inst.check(_lt(value, params));
812
+ inst.lte = (value, params) => inst.check(_lte(value, params));
813
+ inst.max = (value, params) => inst.check(_lte(value, params));
814
+ inst.positive = (params) => inst.check(_gt(BigInt(0), params));
815
+ inst.negative = (params) => inst.check(_lt(BigInt(0), params));
816
+ inst.nonpositive = (params) => inst.check(_lte(BigInt(0), params));
817
+ inst.nonnegative = (params) => inst.check(_gte(BigInt(0), params));
818
+ inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
819
+ const bag = inst._zod.bag;
820
+ inst.minValue = bag.minimum ?? null;
821
+ inst.maxValue = bag.maximum ?? null;
822
+ inst.format = bag.format ?? null;
823
+ }
824
+ );
825
+ function bigint(params) {
826
+ return core._bigint(ZodBigInt, params);
827
+ }
828
+ const ZodBigIntFormat = /* @__PURE__ */ core.$constructor(
829
+ "ZodBigIntFormat",
830
+ (inst, def) => {
831
+ const coreInit = core.$ZodBigIntFormat.init;
832
+ coreInit(inst, def);
833
+ ZodBigInt.init(inst, def);
834
+ }
835
+ );
836
+ function int64(params) {
837
+ return core._int64(ZodBigIntFormat, params);
838
+ }
839
+ function uint64(params) {
840
+ return core._uint64(ZodBigIntFormat, params);
841
+ }
842
+ const ZodSymbol = /* @__PURE__ */ core.$constructor(
843
+ "ZodSymbol",
844
+ (inst, def) => {
845
+ const coreInit = core.$ZodSymbol.init;
846
+ coreInit(inst, def);
847
+ KrustyType.init(inst, def);
848
+ }
849
+ );
850
+ function symbol(params) {
851
+ return core._symbol(ZodSymbol, params);
852
+ }
853
+ const ZodUndefined = /* @__PURE__ */ core.$constructor(
854
+ "ZodUndefined",
855
+ (inst, def) => {
856
+ const coreInit = core.$ZodUndefined.init;
857
+ coreInit(inst, def);
858
+ KrustyType.init(inst, def);
859
+ }
860
+ );
861
+ function _undefined(params) {
862
+ return core._undefined(ZodUndefined, params);
863
+ }
864
+ const ZodNull = /* @__PURE__ */ core.$constructor("ZodNull", (inst, def) => {
865
+ const coreInit = core.$ZodNull.init;
866
+ coreInit(inst, def);
867
+ KrustyType.init(inst, def);
868
+ });
869
+ function _null(params) {
870
+ return core._null(ZodNull, params);
871
+ }
872
+ const ZodAny = /* @__PURE__ */ core.$constructor("ZodAny", (inst, def) => {
873
+ const coreInit = core.$ZodAny.init;
874
+ coreInit(inst, def);
875
+ KrustyType.init(inst, def);
876
+ });
877
+ function any() {
878
+ return core._any(ZodAny);
879
+ }
880
+ const ZodUnknown = /* @__PURE__ */ core.$constructor(
881
+ "ZodUnknown",
882
+ (inst, def) => {
883
+ const coreInit = core.$ZodUnknown.init;
884
+ coreInit(inst, def);
885
+ KrustyType.init(inst, def);
886
+ }
887
+ );
888
+ function unknown() {
889
+ return core._unknown(ZodUnknown);
890
+ }
891
+ const ZodNever = /* @__PURE__ */ core.$constructor(
892
+ "ZodNever",
893
+ (inst, def) => {
894
+ const coreInit = core.$ZodNever.init;
895
+ coreInit(inst, def);
896
+ KrustyType.init(inst, def);
897
+ }
898
+ );
899
+ function never(params) {
900
+ return core._never(ZodNever, params);
901
+ }
902
+ const ZodVoid = /* @__PURE__ */ core.$constructor("ZodVoid", (inst, def) => {
903
+ const coreInit = core.$ZodVoid.init;
904
+ coreInit(inst, def);
905
+ KrustyType.init(inst, def);
906
+ });
907
+ function _void(params) {
908
+ return core._void(ZodVoid, params);
909
+ }
910
+ const ZodDate = /* @__PURE__ */ core.$constructor("ZodDate", (inst, def) => {
911
+ const coreInit = core.$ZodDate.init;
912
+ coreInit(inst, def);
913
+ KrustyType.init(inst, def);
914
+ inst.min = (value, params) => inst.check(_gte(value, params));
915
+ inst.max = (value, params) => inst.check(_lte(value, params));
916
+ const c = inst._zod.bag;
917
+ inst.minDate = c.minimum ? new Date(c.minimum) : null;
918
+ inst.maxDate = c.maximum ? new Date(c.maximum) : null;
919
+ });
920
+ function date(params) {
921
+ return core._date(ZodDate, params);
922
+ }
923
+ const ZodArray = /* @__PURE__ */ core.$constructor(
924
+ "ZodArray",
925
+ (inst, def) => {
926
+ const coreInit = core.$ZodArray.init;
927
+ coreInit(inst, def);
928
+ KrustyType.init(inst, def);
929
+ inst.element = def.element;
930
+ inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
931
+ inst.nonempty = (params) => inst.check(_minLength(1, params));
932
+ inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
933
+ inst.length = (len, params) => inst.check(_length(len, params));
934
+ inst.unwrap = () => inst.element;
935
+ }
936
+ );
937
+ function array(element, params) {
938
+ return core._array(ZodArray, element, params);
939
+ }
940
+ function keyof(schema) {
941
+ const shape = schema._zod.def.shape;
942
+ return _enum(Object.keys(shape));
943
+ }
944
+ const ZodIntersection = /* @__PURE__ */ core.$constructor(
945
+ "ZodIntersection",
946
+ (inst, def) => {
947
+ const coreInit = core.$ZodIntersection.init;
948
+ coreInit(inst, def);
949
+ KrustyType.init(inst, def);
950
+ }
951
+ );
952
+ function intersection(left, right) {
953
+ return new ZodIntersection({
954
+ type: "intersection",
955
+ left,
956
+ right
957
+ });
958
+ }
959
+ const ZodTuple = /* @__PURE__ */ core.$constructor(
960
+ "ZodTuple",
961
+ (inst, def) => {
962
+ const coreInit = core.$ZodTuple.init;
963
+ coreInit(inst, def);
964
+ KrustyType.init(inst, def);
965
+ inst.rest = (rest) => inst.clone({
966
+ ...inst._zod.def,
967
+ rest
137
968
  });
138
969
  }
970
+ );
971
+ function tuple(items, _paramsOrRest, _params) {
972
+ const hasRest = _paramsOrRest instanceof core.$ZodType;
973
+ const params = hasRest ? _params : _paramsOrRest;
974
+ const rest = hasRest ? _paramsOrRest : null;
975
+ return new ZodTuple({
976
+ type: "tuple",
977
+ items,
978
+ rest,
979
+ ...util.normalizeParams(params)
980
+ });
139
981
  }
140
- function zodCoerceInternal(schema, value) {
141
- const customZodDef = getCustomZodDef(schema._def);
142
- switch (customZodDef?.type) {
143
- case "regexp": {
144
- if (typeof value === "string") {
145
- return safeToRegExp(value);
146
- }
147
- return value;
148
- }
149
- case "url": {
150
- if (typeof value === "string") {
151
- return safeToURL(value);
152
- }
153
- return value;
154
- }
982
+ const ZodRecord = /* @__PURE__ */ core.$constructor(
983
+ "ZodRecord",
984
+ (inst, def) => {
985
+ const coreInit = core.$ZodRecord.init;
986
+ coreInit(inst, def);
987
+ KrustyType.init(inst, def);
988
+ inst.keyType = def.keyType;
989
+ inst.valueType = def.valueType;
155
990
  }
156
- const typeName = schema._def.typeName;
157
- switch (typeName) {
158
- case ZodFirstPartyTypeKind.ZodNumber: {
159
- if (typeof value === "string") {
160
- return safeToNumber(value);
161
- }
162
- return value;
163
- }
164
- case ZodFirstPartyTypeKind.ZodBigInt: {
165
- if (typeof value === "string") {
166
- return safeToBigInt(value);
167
- }
168
- return value;
169
- }
170
- case ZodFirstPartyTypeKind.ZodBoolean: {
171
- if (typeof value === "string") {
172
- return safeToBoolean(value);
173
- }
174
- return value;
175
- }
176
- case ZodFirstPartyTypeKind.ZodDate: {
177
- if (typeof value === "string") {
178
- return safeToDate(value);
179
- }
180
- return value;
991
+ );
992
+ function record(keyType, valueType, params) {
993
+ return new ZodRecord({
994
+ type: "record",
995
+ keyType,
996
+ valueType,
997
+ ...util.normalizeParams(params)
998
+ });
999
+ }
1000
+ function partialRecord(keyType, valueType, params) {
1001
+ const k = core.clone(keyType);
1002
+ k._zod.values = void 0;
1003
+ return new ZodRecord({
1004
+ type: "record",
1005
+ keyType: k,
1006
+ valueType,
1007
+ ...util.normalizeParams(params)
1008
+ });
1009
+ }
1010
+ const ZodMap = /* @__PURE__ */ core.$constructor("ZodMap", (inst, def) => {
1011
+ const coreInit = core.$ZodMap.init;
1012
+ coreInit(inst, def);
1013
+ KrustyType.init(inst, def);
1014
+ inst.keyType = def.keyType;
1015
+ inst.valueType = def.valueType;
1016
+ });
1017
+ function map(keyType, valueType, params) {
1018
+ return new ZodMap({
1019
+ type: "map",
1020
+ keyType,
1021
+ valueType,
1022
+ ...util.normalizeParams(params)
1023
+ });
1024
+ }
1025
+ const ZodSet = /* @__PURE__ */ core.$constructor("ZodSet", (inst, def) => {
1026
+ const coreInit = core.$ZodSet.init;
1027
+ coreInit(inst, def);
1028
+ KrustyType.init(inst, def);
1029
+ inst.min = (...args) => inst.check(core._minSize(...args));
1030
+ inst.nonempty = (params) => inst.check(core._minSize(1, params));
1031
+ inst.max = (...args) => inst.check(core._maxSize(...args));
1032
+ inst.size = (...args) => inst.check(core._size(...args));
1033
+ });
1034
+ function set(valueType, params) {
1035
+ return new ZodSet({
1036
+ type: "set",
1037
+ valueType,
1038
+ ...util.normalizeParams(params)
1039
+ });
1040
+ }
1041
+ const ZodEnum = /* @__PURE__ */ core.$constructor("ZodEnum", (inst, def) => {
1042
+ const coreInit = core.$ZodEnum.init;
1043
+ coreInit(inst, def);
1044
+ KrustyType.init(inst, def);
1045
+ inst.enum = def.entries;
1046
+ inst.options = Object.values(def.entries);
1047
+ const keys = new Set(Object.keys(def.entries));
1048
+ inst.extract = (values, params) => {
1049
+ const newEntries = {};
1050
+ for (const value of values) {
1051
+ if (keys.has(value)) {
1052
+ newEntries[value] = def.entries[value];
1053
+ } else throw new Error(`Key ${value} not found in enum`);
181
1054
  }
182
- case ZodFirstPartyTypeKind.ZodLiteral: {
183
- const schema_ = schema;
184
- const expectedValue = schema_._def.value;
185
- if (typeof value === "string" && typeof expectedValue !== "string") {
186
- if (typeof expectedValue === "bigint") {
187
- return safeToBigInt(value);
188
- } else if (typeof expectedValue === "number") {
189
- return safeToNumber(value);
190
- } else if (typeof expectedValue === "boolean") {
191
- return safeToBoolean(value);
192
- }
193
- }
194
- return value;
1055
+ return new ZodEnum({
1056
+ ...def,
1057
+ checks: [],
1058
+ ...util.normalizeParams(params),
1059
+ entries: newEntries
1060
+ });
1061
+ };
1062
+ inst.exclude = (values, params) => {
1063
+ const newEntries = { ...def.entries };
1064
+ for (const value of values) {
1065
+ if (keys.has(value)) {
1066
+ delete newEntries[value];
1067
+ } else throw new Error(`Key ${value} not found in enum`);
195
1068
  }
196
- case ZodFirstPartyTypeKind.ZodNativeEnum: {
197
- const schema_ = schema;
198
- if (Object.values(schema_._def.values).includes(value)) {
199
- return value;
200
- }
201
- if (typeof value === "string") {
202
- for (const expectedValue of Object.values(schema_._def.values)) {
203
- if (expectedValue.toString() === value) {
204
- return expectedValue;
205
- }
1069
+ return new ZodEnum({
1070
+ ...def,
1071
+ checks: [],
1072
+ ...util.normalizeParams(params),
1073
+ entries: newEntries
1074
+ });
1075
+ };
1076
+ });
1077
+ function _enum(values, params) {
1078
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
1079
+ return new ZodEnum({
1080
+ type: "enum",
1081
+ entries,
1082
+ ...util.normalizeParams(params)
1083
+ });
1084
+ }
1085
+ function nativeEnum(entries, params) {
1086
+ return new ZodEnum({
1087
+ type: "enum",
1088
+ entries,
1089
+ ...util.normalizeParams(params)
1090
+ });
1091
+ }
1092
+ const ZodLiteral = /* @__PURE__ */ core.$constructor(
1093
+ "ZodLiteral",
1094
+ (inst, def) => {
1095
+ const coreInit = core.$ZodLiteral.init;
1096
+ coreInit(inst, def);
1097
+ KrustyType.init(inst, def);
1098
+ inst.values = new Set(def.values);
1099
+ Object.defineProperty(inst, "value", {
1100
+ get() {
1101
+ if (def.values.length > 1) {
1102
+ throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
206
1103
  }
1104
+ return def.values[0];
207
1105
  }
208
- return value;
209
- }
210
- case ZodFirstPartyTypeKind.ZodObject: {
211
- const schema_ = schema;
212
- if (isObject(value)) {
213
- const newObj = {};
214
- const keys = /* @__PURE__ */ new Set([...Object.keys(value), ...Object.keys(schema_.shape)]);
215
- for (const k of keys) {
216
- newObj[k] = zodCoerceInternal(schema_.shape[k] ?? schema_._def.catchall, value[k]);
217
- }
218
- return newObj;
1106
+ });
1107
+ }
1108
+ );
1109
+ function literal(value, params) {
1110
+ return new ZodLiteral({
1111
+ type: "literal",
1112
+ values: Array.isArray(value) ? value : [value],
1113
+ ...util.normalizeParams(params)
1114
+ });
1115
+ }
1116
+ const ZodFile = /* @__PURE__ */ core.$constructor("ZodFile", (inst, def) => {
1117
+ const coreInit = core.$ZodFile.init;
1118
+ coreInit(inst, def);
1119
+ KrustyType.init(inst, def);
1120
+ inst.min = (size, params) => inst.check(core._minSize(size, params));
1121
+ inst.max = (size, params) => inst.check(core._maxSize(size, params));
1122
+ inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params));
1123
+ });
1124
+ function file(params) {
1125
+ return core._file(ZodFile, params);
1126
+ }
1127
+ const ZodTransform = /* @__PURE__ */ core.$constructor(
1128
+ "ZodTransform",
1129
+ (inst, def) => {
1130
+ const coreInit = core.$ZodTransform.init;
1131
+ coreInit(inst, def);
1132
+ KrustyType.init(inst, def);
1133
+ inst._zod.parse = (payload, _ctx) => {
1134
+ if (_ctx.direction === "backward") {
1135
+ throw new core.$ZodEncodeError(inst.constructor.name);
219
1136
  }
220
- return value;
221
- }
222
- case ZodFirstPartyTypeKind.ZodRecord: {
223
- const schema_ = schema;
224
- if (isObject(value)) {
225
- const newObj = {};
226
- for (const [k, v] of Object.entries(value)) {
227
- const key = zodCoerceInternal(schema_._def.keyType, k);
228
- const val = zodCoerceInternal(schema_._def.valueType, v);
229
- newObj[key] = val;
1137
+ payload.addIssue = (issue) => {
1138
+ if (typeof issue === "string") {
1139
+ payload.issues.push(util.issue(issue, payload.value, def));
1140
+ } else {
1141
+ const _issue = issue;
1142
+ if (_issue.fatal) _issue.continue = false;
1143
+ _issue.code ??= "custom";
1144
+ _issue.input ??= payload.value;
1145
+ _issue.inst ??= inst;
1146
+ payload.issues.push(util.issue(_issue));
230
1147
  }
231
- return newObj;
232
- }
233
- return value;
234
- }
235
- case ZodFirstPartyTypeKind.ZodArray: {
236
- const schema_ = schema;
237
- if (Array.isArray(value)) {
238
- return value.map((v) => zodCoerceInternal(schema_._def.type, v));
239
- }
240
- return value;
241
- }
242
- case ZodFirstPartyTypeKind.ZodTuple: {
243
- const schema_ = schema;
244
- if (Array.isArray(value)) {
245
- return value.map((v, i) => {
246
- const s = schema_._def.items[i] ?? schema_._def.rest;
247
- return s ? zodCoerceInternal(s, v) : v;
1148
+ };
1149
+ const output = def.transform(payload.value, payload);
1150
+ if (output instanceof Promise) {
1151
+ return output.then((output2) => {
1152
+ payload.value = output2;
1153
+ return payload;
248
1154
  });
249
1155
  }
250
- return value;
251
- }
252
- case ZodFirstPartyTypeKind.ZodSet: {
253
- const schema_ = schema;
254
- if (Array.isArray(value)) {
255
- return new Set(value.map((v) => zodCoerceInternal(schema_._def.valueType, v)));
256
- }
257
- return value;
258
- }
259
- case ZodFirstPartyTypeKind.ZodMap: {
260
- const schema_ = schema;
261
- if (Array.isArray(value) && value.every((i) => Array.isArray(i) && i.length === 2)) {
262
- return new Map(
263
- value.map(([k, v]) => [
264
- zodCoerceInternal(schema_._def.keyType, k),
265
- zodCoerceInternal(schema_._def.valueType, v)
266
- ])
267
- );
268
- }
269
- return value;
270
- }
271
- case ZodFirstPartyTypeKind.ZodUnion:
272
- case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
273
- const schema_ = schema;
274
- if (schema_.safeParse(value).success) {
275
- return value;
276
- }
277
- const results = [];
278
- for (const s of schema_._def.options) {
279
- const newValue = zodCoerceInternal(s, value);
280
- const result = schema_.safeParse(newValue);
281
- if (result.success) {
282
- return newValue;
283
- }
284
- results.push([newValue, result.error.issues.length]);
285
- }
286
- if (results.length === 0) {
287
- return value;
288
- }
289
- return results.sort((a, b) => a[1] - b[1])[0][0];
290
- }
291
- case ZodFirstPartyTypeKind.ZodIntersection: {
292
- const schema_ = schema;
293
- return zodCoerceInternal(schema_._def.right, zodCoerceInternal(schema_._def.left, value));
294
- }
295
- case ZodFirstPartyTypeKind.ZodReadonly: {
296
- const schema_ = schema;
297
- return zodCoerceInternal(schema_._def.innerType, value);
298
- }
299
- case ZodFirstPartyTypeKind.ZodPipeline: {
300
- const schema_ = schema;
301
- return zodCoerceInternal(schema_._def.in, value);
302
- }
303
- case ZodFirstPartyTypeKind.ZodEffects: {
304
- const schema_ = schema;
305
- return zodCoerceInternal(schema_._def.schema, value);
306
- }
307
- case ZodFirstPartyTypeKind.ZodBranded: {
308
- const schema_ = schema;
309
- return zodCoerceInternal(schema_._def.type, value);
310
- }
311
- case ZodFirstPartyTypeKind.ZodCatch: {
312
- const schema_ = schema;
313
- return zodCoerceInternal(schema_._def.innerType, value);
314
- }
315
- case ZodFirstPartyTypeKind.ZodDefault: {
316
- const schema_ = schema;
317
- return zodCoerceInternal(schema_._def.innerType, value);
318
- }
319
- case ZodFirstPartyTypeKind.ZodNullable: {
320
- if (value === null) {
321
- return null;
322
- }
323
- const schema_ = schema;
324
- return zodCoerceInternal(schema_._def.innerType, value);
325
- }
326
- case ZodFirstPartyTypeKind.ZodOptional: {
327
- if (value === void 0) {
328
- return void 0;
329
- }
330
- const schema_ = schema;
331
- return zodCoerceInternal(schema_._def.innerType, value);
1156
+ payload.value = output;
1157
+ return payload;
1158
+ };
1159
+ }
1160
+ );
1161
+ function transform(fn) {
1162
+ return new ZodTransform({
1163
+ type: "transform",
1164
+ transform: fn
1165
+ });
1166
+ }
1167
+ const ZodOptional = /* @__PURE__ */ core.$constructor(
1168
+ "ZodOptional",
1169
+ (inst, def) => {
1170
+ const coreInit = core.$ZodOptional.init;
1171
+ coreInit(inst, def);
1172
+ KrustyType.init(inst, def);
1173
+ inst.unwrap = () => inst._zod.def.innerType;
1174
+ }
1175
+ );
1176
+ function optional(innerType) {
1177
+ return new ZodOptional({
1178
+ type: "optional",
1179
+ innerType
1180
+ });
1181
+ }
1182
+ const ZodNullable = /* @__PURE__ */ core.$constructor(
1183
+ "ZodNullable",
1184
+ (inst, def) => {
1185
+ const coreInit = core.$ZodNullable.init;
1186
+ coreInit(inst, def);
1187
+ KrustyType.init(inst, def);
1188
+ inst.unwrap = () => inst._zod.def.innerType;
1189
+ }
1190
+ );
1191
+ function nullable(innerType) {
1192
+ return new ZodNullable({
1193
+ type: "nullable",
1194
+ innerType
1195
+ });
1196
+ }
1197
+ function nullish(innerType) {
1198
+ return optional(nullable(innerType));
1199
+ }
1200
+ const ZodDefault = /* @__PURE__ */ core.$constructor(
1201
+ "ZodDefault",
1202
+ (inst, def) => {
1203
+ const coreInit = core.$ZodDefault.init;
1204
+ coreInit(inst, def);
1205
+ KrustyType.init(inst, def);
1206
+ inst.unwrap = () => inst._zod.def.innerType;
1207
+ inst.removeDefault = inst.unwrap;
1208
+ }
1209
+ );
1210
+ function _default(innerType, defaultValue) {
1211
+ return new ZodDefault({
1212
+ type: "default",
1213
+ innerType,
1214
+ get defaultValue() {
1215
+ return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
332
1216
  }
333
- case ZodFirstPartyTypeKind.ZodLazy: {
334
- const schema_ = schema;
335
- if (value !== void 0) {
336
- return zodCoerceInternal(schema_._def.getter(), value);
337
- }
338
- return value;
1217
+ });
1218
+ }
1219
+ const ZodPrefault = /* @__PURE__ */ core.$constructor(
1220
+ "ZodPrefault",
1221
+ (inst, def) => {
1222
+ const coreInit = core.$ZodPrefault.init;
1223
+ coreInit(inst, def);
1224
+ KrustyType.init(inst, def);
1225
+ inst.unwrap = () => inst._zod.def.innerType;
1226
+ }
1227
+ );
1228
+ function prefault(innerType, defaultValue) {
1229
+ return new ZodPrefault({
1230
+ type: "prefault",
1231
+ innerType,
1232
+ get defaultValue() {
1233
+ return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
339
1234
  }
1235
+ });
1236
+ }
1237
+ const ZodNonOptional = /* @__PURE__ */ core.$constructor(
1238
+ "ZodNonOptional",
1239
+ (inst, def) => {
1240
+ const coreInit = core.$ZodNonOptional.init;
1241
+ coreInit(inst, def);
1242
+ KrustyType.init(inst, def);
1243
+ inst.unwrap = () => inst._zod.def.innerType;
340
1244
  }
341
- return value;
1245
+ );
1246
+ function nonoptional(innerType, params) {
1247
+ return new ZodNonOptional({
1248
+ type: "nonoptional",
1249
+ innerType,
1250
+ ...util.normalizeParams(params)
1251
+ });
342
1252
  }
343
- function safeToBigInt(value) {
344
- return guard(() => BigInt(value)) ?? value;
1253
+ const ZodSuccess = /* @__PURE__ */ core.$constructor(
1254
+ "ZodSuccess",
1255
+ (inst, def) => {
1256
+ const coreInit = core.$ZodSuccess.init;
1257
+ coreInit(inst, def);
1258
+ KrustyType.init(inst, def);
1259
+ inst.unwrap = () => inst._zod.def.innerType;
1260
+ }
1261
+ );
1262
+ function success(innerType) {
1263
+ return new ZodSuccess({
1264
+ type: "success",
1265
+ innerType
1266
+ });
1267
+ }
1268
+ const ZodCatch = /* @__PURE__ */ core.$constructor(
1269
+ "ZodCatch",
1270
+ (inst, def) => {
1271
+ const coreInit = core.$ZodCatch.init;
1272
+ coreInit(inst, def);
1273
+ KrustyType.init(inst, def);
1274
+ inst.unwrap = () => inst._zod.def.innerType;
1275
+ inst.removeCatch = inst.unwrap;
1276
+ }
1277
+ );
1278
+ function _catch(innerType, catchValue) {
1279
+ return new ZodCatch({
1280
+ type: "catch",
1281
+ innerType,
1282
+ catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
1283
+ });
1284
+ }
1285
+ const ZodNaN = /* @__PURE__ */ core.$constructor("ZodNaN", (inst, def) => {
1286
+ const coreInit = core.$ZodNaN.init;
1287
+ coreInit(inst, def);
1288
+ KrustyType.init(inst, def);
1289
+ });
1290
+ function nan(params) {
1291
+ return core._nan(ZodNaN, params);
345
1292
  }
346
- function safeToNumber(value) {
347
- const num = Number(value);
348
- return Number.isNaN(num) || num.toString() !== value ? value : num;
1293
+ const ZodPipe = /* @__PURE__ */ core.$constructor("ZodPipe", (inst, def) => {
1294
+ const coreInit = core.$ZodPipe.init;
1295
+ coreInit(inst, def);
1296
+ KrustyType.init(inst, def);
1297
+ inst.in = def.in;
1298
+ inst.out = def.out;
1299
+ });
1300
+ function pipe(in_, out) {
1301
+ return new ZodPipe({
1302
+ type: "pipe",
1303
+ in: in_,
1304
+ out
1305
+ // ...util.normalizeParams(params),
1306
+ });
349
1307
  }
350
- function safeToBoolean(value) {
351
- const lower = value.toLowerCase();
352
- if (lower === "false" || lower === "off" || lower === "f") {
353
- return false;
1308
+ const ZodCodec = /* @__PURE__ */ core.$constructor(
1309
+ "ZodCodec",
1310
+ (inst, def) => {
1311
+ ZodPipe.init(inst, def);
1312
+ const coreInit = core.$ZodCodec.init;
1313
+ coreInit(inst, def);
354
1314
  }
355
- if (lower === "true" || lower === "on" || lower === "t") {
356
- return true;
1315
+ );
1316
+ function codec(in_, out, params) {
1317
+ return new ZodCodec({
1318
+ type: "pipe",
1319
+ in: in_,
1320
+ out,
1321
+ transform: params.decode,
1322
+ reverseTransform: params.encode
1323
+ });
1324
+ }
1325
+ const ZodReadonly = /* @__PURE__ */ core.$constructor(
1326
+ "ZodReadonly",
1327
+ (inst, def) => {
1328
+ const coreInit = core.$ZodReadonly.init;
1329
+ coreInit(inst, def);
1330
+ KrustyType.init(inst, def);
1331
+ inst.unwrap = () => inst._zod.def.innerType;
357
1332
  }
358
- return value;
1333
+ );
1334
+ function readonly(innerType) {
1335
+ return new ZodReadonly({
1336
+ type: "readonly",
1337
+ innerType
1338
+ });
359
1339
  }
360
- function safeToRegExp(value) {
361
- if (value.startsWith("/")) {
362
- const match = value.match(/^\/(.*)\/([a-z]*)$/);
363
- if (match) {
364
- const [, pattern, flags] = match;
365
- return new RegExp(pattern, flags);
366
- }
1340
+ const ZodTemplateLiteral = /* @__PURE__ */ core.$constructor(
1341
+ "ZodTemplateLiteral",
1342
+ (inst, def) => {
1343
+ const coreInit = core.$ZodTemplateLiteral.init;
1344
+ coreInit(inst, def);
1345
+ KrustyType.init(inst, def);
1346
+ }
1347
+ );
1348
+ function templateLiteral(parts, params) {
1349
+ return new ZodTemplateLiteral({
1350
+ type: "template_literal",
1351
+ parts,
1352
+ ...util.normalizeParams(params)
1353
+ });
1354
+ }
1355
+ const ZodLazy = /* @__PURE__ */ core.$constructor("ZodLazy", (inst, def) => {
1356
+ const coreInit = core.$ZodLazy.init;
1357
+ coreInit(inst, def);
1358
+ KrustyType.init(inst, def);
1359
+ inst.unwrap = () => inst._zod.def.getter();
1360
+ });
1361
+ function lazy(getter) {
1362
+ return new ZodLazy({
1363
+ type: "lazy",
1364
+ getter
1365
+ });
1366
+ }
1367
+ const ZodPromise = /* @__PURE__ */ core.$constructor(
1368
+ "ZodPromise",
1369
+ (inst, def) => {
1370
+ const coreInit = core.$ZodPromise.init;
1371
+ coreInit(inst, def);
1372
+ KrustyType.init(inst, def);
1373
+ inst.unwrap = () => inst._zod.def.innerType;
367
1374
  }
368
- return value;
1375
+ );
1376
+ function promise(innerType) {
1377
+ return new ZodPromise({
1378
+ type: "promise",
1379
+ innerType
1380
+ });
369
1381
  }
370
- function safeToURL(value) {
371
- return guard(() => new URL(value)) ?? value;
1382
+ const ZodFunction = /* @__PURE__ */ core.$constructor(
1383
+ "ZodFunction",
1384
+ (inst, def) => {
1385
+ const coreInit = core.$ZodFunction.init;
1386
+ coreInit(inst, def);
1387
+ KrustyType.init(inst, def);
1388
+ }
1389
+ );
1390
+ function _function(params) {
1391
+ return new ZodFunction({
1392
+ type: "function",
1393
+ input: Array.isArray(params?.input) ? tuple(params?.input) : params?.input ?? array(unknown()),
1394
+ output: params?.output ?? unknown()
1395
+ });
372
1396
  }
373
- function safeToDate(value) {
374
- const date = new Date(value);
375
- if (!Number.isNaN(date.getTime()) && date.toISOString().startsWith(value)) {
376
- return date;
1397
+ const ZodCustom = /* @__PURE__ */ core.$constructor(
1398
+ "ZodCustom",
1399
+ (inst, def) => {
1400
+ const coreInit = core.$ZodCustom.init;
1401
+ coreInit(inst, def);
1402
+ KrustyType.init(inst, def);
377
1403
  }
378
- return value;
1404
+ );
1405
+ function check(fn) {
1406
+ const ch = new core.$ZodCheck({
1407
+ check: "custom"
1408
+ // ...util.normalizeParams(params),
1409
+ });
1410
+ ch._zod.check = fn;
1411
+ return ch;
1412
+ }
1413
+ function custom(fn, _params) {
1414
+ return core._custom(ZodCustom, fn ?? (() => true), _params);
1415
+ }
1416
+ function refine(fn, _params = {}) {
1417
+ return core._refine(ZodCustom, fn, _params);
1418
+ }
1419
+ function superRefine(fn) {
1420
+ return core._superRefine(fn);
1421
+ }
1422
+ function _instanceof(cls, params = {
1423
+ error: `Input not instance of ${cls.name}`
1424
+ }) {
1425
+ const inst = new ZodCustom({
1426
+ type: "custom",
1427
+ check: "custom",
1428
+ fn: (data) => data instanceof cls,
1429
+ abort: true,
1430
+ ...util.normalizeParams(params)
1431
+ });
1432
+ inst._zod.bag.Class = cls;
1433
+ return inst;
1434
+ }
1435
+ const stringbool = (...args) => core._stringbool(
1436
+ {
1437
+ Codec: ZodCodec,
1438
+ Boolean: ZodBoolean,
1439
+ String: ZodString
1440
+ },
1441
+ ...args
1442
+ );
1443
+ function json(params) {
1444
+ const jsonSchema = lazy(() => {
1445
+ return union([
1446
+ string(params),
1447
+ number(),
1448
+ boolean(),
1449
+ _null(),
1450
+ array(jsonSchema),
1451
+ record(string(), jsonSchema)
1452
+ ]);
1453
+ });
1454
+ return jsonSchema;
1455
+ }
1456
+ function preprocess(fn, schema) {
1457
+ return pipe(transform(fn), schema);
379
1458
  }
380
1459
 
381
- class ZodToJsonSchemaConverter {
382
- maxLazyDepth;
383
- maxStructureDepth;
384
- unsupportedJsonSchema;
385
- anyJsonSchema;
386
- constructor(options = {}) {
387
- this.maxLazyDepth = options.maxLazyDepth ?? 3;
388
- this.maxStructureDepth = options.maxStructureDepth ?? 10;
389
- this.unsupportedJsonSchema = options.unsupportedJsonSchema ?? { not: {} };
390
- this.anyJsonSchema = options.anyJsonSchema ?? {};
391
- }
392
- condition(schema) {
393
- return schema !== void 0 && schema["~standard"].vendor === "zod" && !("_zod" in schema);
394
- }
395
- convert(schema, options, lazyDepth = 0, isHandledCustomJSONSchema = false, isHandledZodDescription = false, structureDepth = 0) {
396
- const def = schema._def;
397
- if (structureDepth > this.maxStructureDepth) {
398
- return [false, this.anyJsonSchema];
399
- }
400
- if (!options.minStructureDepthForRef || options.minStructureDepthForRef <= structureDepth) {
401
- const components = toArray(options.components);
402
- for (const component of components) {
403
- if (component.schema === schema && component.allowedStrategies.includes(options.strategy)) {
404
- return [component.required, { $ref: component.ref }];
405
- }
406
- }
407
- }
408
- if (!isHandledZodDescription && "description" in def && typeof def.description === "string") {
409
- const [required, json] = this.convert(
410
- schema,
411
- options,
412
- lazyDepth,
413
- isHandledCustomJSONSchema,
414
- true,
415
- structureDepth
416
- );
417
- return [required, { ...json, description: def.description }];
418
- }
419
- if (!isHandledCustomJSONSchema) {
420
- const customJSONSchema = getCustomJsonSchema(def, options);
421
- if (customJSONSchema) {
422
- const [required, json] = this.convert(
423
- schema,
424
- options,
425
- lazyDepth,
426
- true,
427
- isHandledZodDescription,
428
- structureDepth
429
- );
430
- return [required, { ...json, ...customJSONSchema }];
431
- }
432
- }
433
- const customSchema = this.#handleCustomZodDef(def);
434
- if (customSchema) {
435
- return [true, customSchema];
436
- }
437
- const typeName = this.#getZodTypeName(def);
438
- switch (typeName) {
439
- case ZodFirstPartyTypeKind.ZodString: {
440
- const schema_ = schema;
441
- const json = { type: "string" };
442
- for (const check of schema_._def.checks) {
443
- switch (check.kind) {
444
- case "base64":
445
- json.contentEncoding = "base64";
446
- break;
447
- case "cuid":
448
- json.pattern = "^[0-9A-HJKMNP-TV-Z]{26}$";
449
- break;
450
- case "email":
451
- json.format = JSONSchemaFormat.Email;
452
- break;
453
- case "url":
454
- json.format = JSONSchemaFormat.URI;
455
- break;
456
- case "uuid":
457
- json.format = JSONSchemaFormat.UUID;
458
- break;
459
- case "regex":
460
- json.pattern = check.regex.source;
461
- break;
462
- case "min":
463
- json.minLength = check.value;
464
- break;
465
- case "max":
466
- json.maxLength = check.value;
467
- break;
468
- case "length":
469
- json.minLength = check.value;
470
- json.maxLength = check.value;
471
- break;
472
- case "includes":
473
- json.pattern = escapeStringRegexp(check.value);
474
- break;
475
- case "startsWith":
476
- json.pattern = `^${escapeStringRegexp(check.value)}`;
477
- break;
478
- case "endsWith":
479
- json.pattern = `${escapeStringRegexp(check.value)}$`;
480
- break;
481
- case "emoji":
482
- json.pattern = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
483
- break;
484
- case "nanoid":
485
- json.pattern = "^[a-zA-Z0-9_-]{21}$";
486
- break;
487
- case "cuid2":
488
- json.pattern = "^[0-9a-z]+$";
489
- break;
490
- case "ulid":
491
- json.pattern = "^[0-9A-HJKMNP-TV-Z]{26}$";
492
- break;
493
- case "datetime":
494
- json.format = JSONSchemaFormat.DateTime;
495
- break;
496
- case "date":
497
- json.format = JSONSchemaFormat.Date;
498
- break;
499
- case "time":
500
- json.format = JSONSchemaFormat.Time;
501
- break;
502
- case "duration":
503
- json.format = JSONSchemaFormat.Duration;
504
- break;
505
- case "ip": {
506
- if (check.version === "v4") {
507
- json.format = JSONSchemaFormat.IPv4;
508
- } else if (check.version === "v6") {
509
- json.format = JSONSchemaFormat.IPv6;
510
- } else {
511
- json.anyOf = [{ format: JSONSchemaFormat.IPv4 }, { format: JSONSchemaFormat.IPv6 }];
512
- }
513
- break;
514
- }
515
- case "jwt":
516
- json.pattern = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$";
517
- break;
518
- case "base64url":
519
- json.pattern = "^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$";
520
- break;
521
- default: {
522
- check.kind;
523
- }
524
- }
525
- }
526
- return [true, json];
527
- }
528
- case ZodFirstPartyTypeKind.ZodNumber: {
529
- const schema_ = schema;
530
- const json = { type: "number" };
531
- for (const check of schema_._def.checks) {
532
- switch (check.kind) {
533
- case "int":
534
- json.type = "integer";
535
- break;
536
- case "min":
537
- json.minimum = check.value;
538
- break;
539
- case "max":
540
- json.maximum = check.value;
541
- break;
542
- case "multipleOf":
543
- json.multipleOf = check.value;
544
- break;
545
- default: {
546
- check.kind;
547
- }
548
- }
549
- }
550
- return [true, json];
551
- }
552
- case ZodFirstPartyTypeKind.ZodBigInt: {
553
- const json = {
554
- type: "string",
555
- pattern: "^-?[0-9]+$",
556
- "x-native-type": JsonSchemaXNativeType.BigInt
557
- };
558
- return [true, json];
559
- }
560
- case ZodFirstPartyTypeKind.ZodNaN: {
561
- return options.strategy === "input" ? [true, this.unsupportedJsonSchema] : [true, { type: "null" }];
562
- }
563
- case ZodFirstPartyTypeKind.ZodBoolean: {
564
- return [true, { type: "boolean" }];
565
- }
566
- case ZodFirstPartyTypeKind.ZodDate: {
567
- const schema2 = {
568
- type: "string",
569
- format: JSONSchemaFormat.DateTime,
570
- "x-native-type": JsonSchemaXNativeType.Date
571
- };
572
- return [true, schema2];
573
- }
574
- case ZodFirstPartyTypeKind.ZodNull: {
575
- return [true, { type: "null" }];
576
- }
577
- case ZodFirstPartyTypeKind.ZodLiteral: {
578
- const schema_ = schema;
579
- if (schema_._def.value === void 0) {
580
- return [false, this.unsupportedJsonSchema];
581
- }
582
- return [true, { const: schema_._def.value }];
583
- }
584
- case ZodFirstPartyTypeKind.ZodVoid:
585
- case ZodFirstPartyTypeKind.ZodUndefined: {
586
- return [false, this.unsupportedJsonSchema];
587
- }
588
- case ZodFirstPartyTypeKind.ZodUnknown:
589
- case ZodFirstPartyTypeKind.ZodAny: {
590
- return [false, this.anyJsonSchema];
591
- }
592
- case ZodFirstPartyTypeKind.ZodEnum: {
593
- const schema_ = schema;
594
- return [true, { enum: schema_._def.values }];
595
- }
596
- case ZodFirstPartyTypeKind.ZodNativeEnum: {
597
- const schema_ = schema;
598
- return [true, { enum: Object.values(schema_._def.values) }];
599
- }
600
- case ZodFirstPartyTypeKind.ZodArray: {
601
- const schema_ = schema;
602
- const def2 = schema_._def;
603
- const json = { type: "array" };
604
- const [itemRequired, itemJson] = this.convert(
605
- def2.type,
606
- options,
607
- lazyDepth,
608
- false,
609
- false,
610
- structureDepth + 1
611
- );
612
- json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
613
- if (def2.exactLength) {
614
- json.maxItems = def2.exactLength.value;
615
- json.minItems = def2.exactLength.value;
616
- }
617
- if (def2.minLength) {
618
- json.minItems = def2.minLength.value;
619
- }
620
- if (def2.maxLength) {
621
- json.maxItems = def2.maxLength.value;
622
- }
623
- return [true, json];
624
- }
625
- case ZodFirstPartyTypeKind.ZodTuple: {
626
- const schema_ = schema;
627
- const prefixItems = [];
628
- const json = { type: "array" };
629
- for (const item of schema_._def.items) {
630
- const [itemRequired, itemJson] = this.convert(
631
- item,
632
- options,
633
- lazyDepth,
634
- false,
635
- false,
636
- structureDepth + 1
637
- );
638
- prefixItems.push(this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy));
639
- }
640
- if (prefixItems?.length) {
641
- json.prefixItems = prefixItems;
642
- }
643
- if (schema_._def.rest) {
644
- const [itemRequired, itemJson] = this.convert(
645
- schema_._def.rest,
646
- options,
647
- lazyDepth,
648
- false,
649
- false,
650
- structureDepth + 1
651
- );
652
- json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
653
- }
654
- return [true, json];
655
- }
656
- case ZodFirstPartyTypeKind.ZodObject: {
657
- const schema_ = schema;
658
- const json = { type: "object" };
659
- const properties = {};
660
- const required = [];
661
- for (const [key, value] of Object.entries(schema_.shape)) {
662
- const [itemRequired, itemJson] = this.convert(
663
- value,
664
- options,
665
- lazyDepth,
666
- false,
667
- false,
668
- structureDepth + 1
669
- );
670
- properties[key] = itemJson;
671
- if (itemRequired) {
672
- required.push(key);
673
- }
674
- }
675
- if (Object.keys(properties).length) {
676
- json.properties = properties;
677
- }
678
- if (required.length) {
679
- json.required = required;
680
- }
681
- const catchAllTypeName = this.#getZodTypeName(schema_._def.catchall._def);
682
- if (catchAllTypeName === ZodFirstPartyTypeKind.ZodNever) {
683
- if (schema_._def.unknownKeys === "strict") {
684
- json.additionalProperties = false;
685
- }
686
- } else {
687
- const [_, addJson] = this.convert(
688
- schema_._def.catchall,
689
- options,
690
- lazyDepth,
691
- false,
692
- false,
693
- structureDepth + 1
694
- );
695
- json.additionalProperties = addJson;
696
- }
697
- return [true, json];
698
- }
699
- case ZodFirstPartyTypeKind.ZodRecord: {
700
- const schema_ = schema;
701
- const json = { type: "object" };
702
- const [__, keyJson] = this.convert(
703
- schema_._def.keyType,
704
- options,
705
- lazyDepth,
706
- false,
707
- false,
708
- structureDepth + 1
709
- );
710
- if (Object.entries(keyJson).some(([k, v]) => k !== "type" || v !== "string")) {
711
- json.propertyNames = keyJson;
712
- }
713
- const [_, itemJson] = this.convert(
714
- schema_._def.valueType,
715
- options,
716
- lazyDepth,
717
- false,
718
- false,
719
- structureDepth + 1
720
- );
721
- json.additionalProperties = itemJson;
722
- return [true, json];
723
- }
724
- case ZodFirstPartyTypeKind.ZodSet: {
725
- const schema_ = schema;
726
- const json = {
727
- type: "array",
728
- uniqueItems: true,
729
- "x-native-type": JsonSchemaXNativeType.Set
730
- };
731
- const [itemRequired, itemJson] = this.convert(
732
- schema_._def.valueType,
733
- options,
734
- lazyDepth,
735
- false,
736
- false,
737
- structureDepth + 1
738
- );
739
- json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
740
- return [true, json];
741
- }
742
- case ZodFirstPartyTypeKind.ZodMap: {
743
- const schema_ = schema;
744
- const [keyRequired, keyJson] = this.convert(
745
- schema_._def.keyType,
746
- options,
747
- lazyDepth,
748
- false,
749
- false,
750
- structureDepth + 1
751
- );
752
- const [valueRequired, valueJson] = this.convert(
753
- schema_._def.valueType,
754
- options,
755
- lazyDepth,
756
- false,
757
- false,
758
- structureDepth + 1
759
- );
760
- const json = {
761
- type: "array",
762
- items: {
763
- type: "array",
764
- prefixItems: [
765
- this.#toArrayItemJsonSchema(keyRequired, keyJson, options.strategy),
766
- this.#toArrayItemJsonSchema(valueRequired, valueJson, options.strategy)
767
- ],
768
- maxItems: 2,
769
- minItems: 2
770
- },
771
- "x-native-type": JsonSchemaXNativeType.Map
772
- };
773
- return [true, json];
774
- }
775
- case ZodFirstPartyTypeKind.ZodUnion:
776
- case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
777
- const schema_ = schema;
778
- const anyOf = [];
779
- let required = true;
780
- for (const item of schema_._def.options) {
781
- const [itemRequired, itemJson] = this.convert(
782
- item,
783
- options,
784
- lazyDepth,
785
- false,
786
- false,
787
- structureDepth
788
- );
789
- if (!itemRequired) {
790
- required = false;
791
- if (itemJson !== this.unsupportedJsonSchema) {
792
- anyOf.push(itemJson);
793
- }
794
- } else {
795
- anyOf.push(itemJson);
796
- }
797
- }
798
- if (anyOf.length === 1) {
799
- return [required, anyOf[0]];
800
- }
801
- return [required, { anyOf }];
802
- }
803
- case ZodFirstPartyTypeKind.ZodIntersection: {
804
- const schema_ = schema;
805
- const allOf = [];
806
- let required = false;
807
- for (const item of [schema_._def.left, schema_._def.right]) {
808
- const [itemRequired, itemJson] = this.convert(
809
- item,
810
- options,
811
- lazyDepth,
812
- false,
813
- false,
814
- structureDepth
815
- );
816
- allOf.push(itemJson);
817
- if (itemRequired) {
818
- required = true;
819
- }
820
- }
821
- return [required, { allOf }];
822
- }
823
- case ZodFirstPartyTypeKind.ZodLazy: {
824
- const currentLazyDepth = lazyDepth + 1;
825
- if (currentLazyDepth > this.maxLazyDepth) {
826
- return [false, this.anyJsonSchema];
827
- }
828
- const schema_ = schema;
829
- return this.convert(schema_._def.getter(), options, currentLazyDepth, false, false, structureDepth);
830
- }
831
- case ZodFirstPartyTypeKind.ZodOptional: {
832
- const schema_ = schema;
833
- const [_, inner] = this.convert(
834
- schema_._def.innerType,
835
- options,
836
- lazyDepth,
837
- false,
838
- false,
839
- structureDepth
840
- );
841
- return [false, inner];
842
- }
843
- case ZodFirstPartyTypeKind.ZodReadonly: {
844
- const schema_ = schema;
845
- const [required, json] = this.convert(
846
- schema_._def.innerType,
847
- options,
848
- lazyDepth,
849
- false,
850
- false,
851
- structureDepth
852
- );
853
- return [required, { ...json, readOnly: true }];
854
- }
855
- case ZodFirstPartyTypeKind.ZodDefault: {
856
- const schema_ = schema;
857
- const [_, json] = this.convert(
858
- schema_._def.innerType,
859
- options,
860
- lazyDepth,
861
- false,
862
- false,
863
- structureDepth
864
- );
865
- return [false, { default: schema_._def.defaultValue(), ...json }];
866
- }
867
- case ZodFirstPartyTypeKind.ZodEffects: {
868
- const schema_ = schema;
869
- if (schema_._def.effect.type === "transform" && options.strategy === "output") {
870
- return [false, this.anyJsonSchema];
871
- }
872
- return this.convert(schema_._def.schema, options, lazyDepth, false, false, structureDepth);
873
- }
874
- case ZodFirstPartyTypeKind.ZodCatch: {
875
- const schema_ = schema;
876
- return this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
877
- }
878
- case ZodFirstPartyTypeKind.ZodBranded: {
879
- const schema_ = schema;
880
- return this.convert(schema_._def.type, options, lazyDepth, false, false, structureDepth);
881
- }
882
- case ZodFirstPartyTypeKind.ZodPipeline: {
883
- const schema_ = schema;
884
- return this.convert(
885
- options.strategy === "input" ? schema_._def.in : schema_._def.out,
886
- options,
887
- lazyDepth,
888
- false,
889
- false,
890
- structureDepth
891
- );
892
- }
893
- case ZodFirstPartyTypeKind.ZodNullable: {
894
- const schema_ = schema;
895
- const [required, json] = this.convert(
896
- schema_._def.innerType,
897
- options,
898
- lazyDepth,
899
- false,
900
- false,
901
- structureDepth
902
- );
903
- return [required, { anyOf: [json, { type: "null" }] }];
904
- }
905
- }
906
- return [true, this.unsupportedJsonSchema];
1460
+ class SchemaClass {
1461
+ string(params) {
1462
+ return string(params);
907
1463
  }
908
- #handleCustomZodDef(def) {
909
- const customZodDef = getCustomZodDef(def);
910
- if (!customZodDef) {
911
- return void 0;
912
- }
913
- switch (customZodDef.type) {
914
- case "blob": {
915
- return { type: "string", contentMediaType: "*/*" };
916
- }
917
- case "file": {
918
- return { type: "string", contentMediaType: customZodDef.mimeType ?? "*/*" };
919
- }
920
- case "regexp": {
921
- return {
922
- type: "string",
923
- pattern: "^\\/(.*)\\/([a-z]*)$",
924
- "x-native-type": JsonSchemaXNativeType.RegExp
925
- };
926
- }
927
- case "url": {
928
- return {
929
- type: "string",
930
- format: JSONSchemaFormat.URI,
931
- "x-native-type": JsonSchemaXNativeType.Url
932
- };
933
- }
934
- }
1464
+ number(params) {
1465
+ return number(params);
935
1466
  }
936
- #getZodTypeName(def) {
937
- return def.typeName;
1467
+ int(params) {
1468
+ return this.number().int(params);
938
1469
  }
939
- #toArrayItemJsonSchema(required, schema, strategy) {
940
- if (required) {
941
- return schema;
942
- }
943
- return strategy === "input" ? { anyOf: [schema, this.unsupportedJsonSchema] } : { anyOf: [schema, { type: "null" }] };
1470
+ boolean(params) {
1471
+ return boolean(params);
1472
+ }
1473
+ null(params) {
1474
+ return _null(params);
1475
+ }
1476
+ array(element, params) {
1477
+ return array(element, params);
1478
+ }
1479
+ record(keyType, valueType, params) {
1480
+ return record(keyType, valueType, params);
944
1481
  }
1482
+ union(options, params) {
1483
+ return union(options, params);
1484
+ }
1485
+ discriminatedUnion(discriminator, options, params) {
1486
+ return discriminatedUnion(discriminator, options, params);
1487
+ }
1488
+ object(shape, params) {
1489
+ return object(shape, params);
1490
+ }
1491
+ // TODO: make this a codec?
1492
+ date(params) {
1493
+ return date(params);
1494
+ }
1495
+ any() {
1496
+ return any();
1497
+ }
1498
+ unknown() {
1499
+ return unknown();
1500
+ }
1501
+ never(params) {
1502
+ return never(params);
1503
+ }
1504
+ lazy(getter) {
1505
+ return lazy(getter);
1506
+ }
1507
+ json(params) {
1508
+ return json(params);
1509
+ }
1510
+ /**
1511
+ * TODO: def need to expose
1512
+ * file
1513
+ * literal
1514
+ * nativeEnum
1515
+ */
1516
+ /**
1517
+ * TODO: decide how to handle non-serializeable values
1518
+ * TODO: decide what types to expose
1519
+ * function
1520
+ * promise
1521
+ * readonly
1522
+ * nan
1523
+ * success
1524
+ * set
1525
+ * map
1526
+ * partialRecord
1527
+ * tuple
1528
+ * intersection
1529
+ * keyof
1530
+ * symbol
1531
+ * bigint
1532
+ * blob
1533
+ */
1534
+ /**
1535
+ * TODO: decide what non-chained format helpers to expose
1536
+ * -- OBJECT
1537
+ * strictObject
1538
+ * looseObject
1539
+ * -- STRING
1540
+ * url
1541
+ * regexp
1542
+ * email
1543
+ * guid
1544
+ * uuid
1545
+ * uuidv4
1546
+ * uuidv6
1547
+ * uuidv7
1548
+ * url
1549
+ * httpUrl
1550
+ * emoji
1551
+ * nanoid
1552
+ * cuid
1553
+ * cuid2
1554
+ * ulid
1555
+ * xid
1556
+ * ksuid
1557
+ * jwt
1558
+ * hostname
1559
+ * hex
1560
+ * hash
1561
+ * ipv4
1562
+ * ipv6
1563
+ * cidrv4
1564
+ * cidrv6
1565
+ * base64
1566
+ * base64url
1567
+ * e164
1568
+ * -- NUMBER
1569
+ * float32
1570
+ * float64
1571
+ * int32
1572
+ * uint32
1573
+ * int64
1574
+ * uint64
1575
+ */
1576
+ /**
1577
+ * TODO: decide what other helper methods to expose
1578
+ * preprocess
1579
+ * refine
1580
+ * superRefine
1581
+ * custom
1582
+ * check
1583
+ * codec
1584
+ * pipe
1585
+ * nonoptional
1586
+ * prefault
1587
+ * default
1588
+ * nullish
1589
+ * nullable
1590
+ * optional
1591
+ * transform
1592
+ * stringFormat
1593
+ */
945
1594
  }
946
1595
 
947
- const oz = {
948
- file,
949
- blob,
950
- url,
951
- regexp,
952
- openapi: customJsonSchema
953
- };
954
-
955
- export { ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
1596
+ export { KrustyType, SchemaClass, ZodAny, ZodArray, ZodBase64, ZodBase64URL, ZodBigInt, ZodBigIntFormat, ZodBoolean, ZodCIDRv4, ZodCIDRv6, ZodCUID, ZodCUID2, ZodCatch, ZodCodec, ZodCustom, ZodCustomStringFormat, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodE164, ZodEmail, ZodEmoji, ZodEnum, ZodError, ZodFile, ZodFunction, ZodGUID, ZodGate, ZodIPv4, ZodIPv6, ZodIntersection, ZodJWT, ZodKSUID, ZodLazy, ZodLiteral, ZodMap, ZodNaN, ZodNanoID, ZodNever, ZodNonOptional, ZodNull, ZodNullable, ZodNumber, ZodNumberFormat, ZodObject, ZodOptional, ZodPipe, ZodPrefault, ZodPromise, ZodReadonly, ZodRealError, ZodRecord, ZodSet, ZodString, ZodStringFormat, ZodSuccess, ZodSymbol, ZodTemplateLiteral, ZodTransform, ZodTuple, ZodULID, ZodURL, ZodUUID, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, ZodXID, _ZodString, _default, _function, any, array, base64, base64url, bigint, blob, boolean, _catch as catch, check, cidrv4, cidrv6, codec, cuid, cuid2, custom, date, decode, decodeAsync, discriminatedUnion, e164, email, emoji, encode, encodeAsync, _enum as enum, file, float32, float64, _function as function, gate, gatingContext, guid, hash, hex, hostname, httpUrl, _instanceof as instanceof, int, int32, int64, intersection, ipv4, ipv6, isGateIssue, isGateIssueRaw, json, jwt, keyof, ksuid, lazy, literal, looseObject, map, nan, nanoid, nativeEnum, never, nonoptional, _null as null, nullable, nullish, number, object, optional, parse, parseAsync, partialRecord, pipe, prefault, preprocess, promise, readonly, record, refine, regexp, safeDecode, safeDecodeAsync, safeEncode, safeEncodeAsync, safeParse, safeParseAsync, set, strictObject, string, stringFormat, stringbool, success, superRefine, symbol, templateLiteral, transform, tuple, uint32, uint64, ulid, _undefined as undefined, union, unknown, url, uuid, uuidv4, uuidv6, uuidv7, _void as void, xid };