@temporary-name/zod 1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8 → 1.9.3-alpha.102eab0800942eb736f7669a86c850ebfdfcd4a3

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