@orpc/zod 0.0.0-next.e9dc36e → 0.0.0-next.ed15210

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1,4 +1,362 @@
1
- // src/index.ts
1
+ // ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/getType.js
2
+ function getType(payload) {
3
+ return Object.prototype.toString.call(payload).slice(8, -1);
4
+ }
5
+
6
+ // ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/isPlainObject.js
7
+ function isPlainObject(payload) {
8
+ if (getType(payload) !== "Object")
9
+ return false;
10
+ const prototype = Object.getPrototypeOf(payload);
11
+ return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
12
+ }
13
+
14
+ // ../../node_modules/.pnpm/radash@12.1.0/node_modules/radash/dist/esm/async.mjs
15
+ var guard = (func, shouldGuard) => {
16
+ const _guard = (err) => {
17
+ if (shouldGuard && !shouldGuard(err))
18
+ throw err;
19
+ return void 0;
20
+ };
21
+ const isPromise2 = (result) => result instanceof Promise;
22
+ try {
23
+ const result = func();
24
+ return isPromise2(result) ? result.catch(_guard) : result;
25
+ } catch (err) {
26
+ return _guard(err);
27
+ }
28
+ };
29
+
30
+ // src/coercer.ts
31
+ import {
32
+ ZodFirstPartyTypeKind
33
+ } from "zod";
34
+ var ZodCoercer = class {
35
+ coerce(schema, value) {
36
+ if (!schema || schema["~standard"].vendor !== "zod") {
37
+ return value;
38
+ }
39
+ const zodSchema = schema;
40
+ const coerced = zodCoerceInternal(zodSchema, value, { bracketNotation: true });
41
+ return coerced;
42
+ }
43
+ };
44
+ function zodCoerceInternal(schema, value, options) {
45
+ const isRoot = options?.isRoot ?? true;
46
+ const options_ = { ...options, isRoot: false };
47
+ if (isRoot && options?.bracketNotation && Array.isArray(value) && value.length === 1) {
48
+ const newValue = zodCoerceInternal(schema, value[0], options_);
49
+ if (schema.safeParse(newValue).success) {
50
+ return newValue;
51
+ }
52
+ return zodCoerceInternal(schema, value, options_);
53
+ }
54
+ const customType = getCustomZodType(schema._def);
55
+ if (customType === "Invalid Date") {
56
+ if (typeof value === "string" && value.toLocaleLowerCase() === "invalid date") {
57
+ return /* @__PURE__ */ new Date("Invalid Date");
58
+ }
59
+ } else if (customType === "RegExp") {
60
+ if (typeof value === "string" && value.startsWith("/")) {
61
+ const match = value.match(/^\/(.*)\/([a-z]*)$/);
62
+ if (match) {
63
+ const [, pattern, flags] = match;
64
+ return new RegExp(pattern, flags);
65
+ }
66
+ }
67
+ } else if (customType === "URL") {
68
+ if (typeof value === "string") {
69
+ const url2 = guard(() => new URL(value));
70
+ if (url2 !== void 0) {
71
+ return url2;
72
+ }
73
+ }
74
+ }
75
+ if (schema._def.typeName === void 0) {
76
+ return value;
77
+ }
78
+ const typeName = schema._def.typeName;
79
+ if (typeName === ZodFirstPartyTypeKind.ZodNumber) {
80
+ if (options_?.bracketNotation && typeof value === "string") {
81
+ const num = Number(value);
82
+ if (!Number.isNaN(num)) {
83
+ return num;
84
+ }
85
+ }
86
+ } else if (typeName === ZodFirstPartyTypeKind.ZodNaN) {
87
+ if (typeof value === "string" && value.toLocaleLowerCase() === "nan") {
88
+ return Number.NaN;
89
+ }
90
+ } else if (typeName === ZodFirstPartyTypeKind.ZodBoolean) {
91
+ if (options_?.bracketNotation && typeof value === "string") {
92
+ const lower = value.toLowerCase();
93
+ if (lower === "false" || lower === "off" || lower === "f") {
94
+ return false;
95
+ }
96
+ if (lower === "true" || lower === "on" || lower === "t") {
97
+ return true;
98
+ }
99
+ }
100
+ } else if (typeName === ZodFirstPartyTypeKind.ZodNull) {
101
+ if (options_?.bracketNotation && typeof value === "string" && value.toLowerCase() === "null") {
102
+ return null;
103
+ }
104
+ } else if (typeName === ZodFirstPartyTypeKind.ZodUndefined || typeName === ZodFirstPartyTypeKind.ZodVoid) {
105
+ if (typeof value === "string" && value.toLowerCase() === "undefined") {
106
+ return void 0;
107
+ }
108
+ } else if (typeName === ZodFirstPartyTypeKind.ZodDate) {
109
+ if (typeof value === "string" && (value.includes("-") || value.includes(":") || value.toLocaleLowerCase() === "invalid date")) {
110
+ return new Date(value);
111
+ }
112
+ } else if (typeName === ZodFirstPartyTypeKind.ZodBigInt) {
113
+ if (typeof value === "string") {
114
+ const num = guard(() => BigInt(value));
115
+ if (num !== void 0) {
116
+ return num;
117
+ }
118
+ }
119
+ } else if (typeName === ZodFirstPartyTypeKind.ZodArray || typeName === ZodFirstPartyTypeKind.ZodTuple) {
120
+ const schema_ = schema;
121
+ if (Array.isArray(value)) {
122
+ return value.map((v) => zodCoerceInternal(schema_._def.type, v, options_));
123
+ }
124
+ if (options_?.bracketNotation) {
125
+ if (value === void 0) {
126
+ return [];
127
+ }
128
+ if (isPlainObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
129
+ const indexes = Object.keys(value).map((k) => Number(k)).sort((a, b) => a - b);
130
+ const arr = Array.from({ length: (indexes.at(-1) ?? -1) + 1 });
131
+ for (const i of indexes) {
132
+ arr[i] = zodCoerceInternal(schema_._def.type, value[i], options_);
133
+ }
134
+ return arr;
135
+ }
136
+ }
137
+ } else if (typeName === ZodFirstPartyTypeKind.ZodObject) {
138
+ const schema_ = schema;
139
+ if (isPlainObject(value)) {
140
+ const newObj = {};
141
+ const keys = /* @__PURE__ */ new Set([
142
+ ...Object.keys(value),
143
+ ...Object.keys(schema_.shape)
144
+ ]);
145
+ for (const k of keys) {
146
+ if (!(k in value))
147
+ continue;
148
+ const v = value[k];
149
+ newObj[k] = zodCoerceInternal(
150
+ schema_.shape[k] ?? schema_._def.catchall,
151
+ v,
152
+ options_
153
+ );
154
+ }
155
+ return newObj;
156
+ }
157
+ if (options_?.bracketNotation) {
158
+ if (value === void 0) {
159
+ return {};
160
+ }
161
+ if (Array.isArray(value) && value.length === 1) {
162
+ const emptySchema = schema_.shape[""] ?? schema_._def.catchall;
163
+ return { "": zodCoerceInternal(emptySchema, value[0], options_) };
164
+ }
165
+ }
166
+ } else if (typeName === ZodFirstPartyTypeKind.ZodSet) {
167
+ const schema_ = schema;
168
+ if (Array.isArray(value)) {
169
+ return new Set(
170
+ value.map((v) => zodCoerceInternal(schema_._def.valueType, v, options_))
171
+ );
172
+ }
173
+ if (options_?.bracketNotation) {
174
+ if (value === void 0) {
175
+ return /* @__PURE__ */ new Set();
176
+ }
177
+ if (isPlainObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
178
+ const indexes = Object.keys(value).map((k) => Number(k)).sort((a, b) => a - b);
179
+ const arr = Array.from({ length: (indexes.at(-1) ?? -1) + 1 });
180
+ for (const i of indexes) {
181
+ arr[i] = zodCoerceInternal(schema_._def.valueType, value[i], options_);
182
+ }
183
+ return new Set(arr);
184
+ }
185
+ }
186
+ } else if (typeName === ZodFirstPartyTypeKind.ZodMap) {
187
+ const schema_ = schema;
188
+ if (Array.isArray(value) && value.every((i) => Array.isArray(i) && i.length === 2)) {
189
+ return new Map(
190
+ value.map(([k, v]) => [
191
+ zodCoerceInternal(schema_._def.keyType, k, options_),
192
+ zodCoerceInternal(schema_._def.valueType, v, options_)
193
+ ])
194
+ );
195
+ }
196
+ if (options_?.bracketNotation) {
197
+ if (value === void 0) {
198
+ return /* @__PURE__ */ new Map();
199
+ }
200
+ if (isPlainObject(value)) {
201
+ const arr = Array.from({ length: Object.keys(value).length }).fill(void 0).map(
202
+ (_, i) => isPlainObject(value[i]) && Object.keys(value[i]).length === 2 && "0" in value[i] && "1" in value[i] ? [value[i]["0"], value[i]["1"]] : void 0
203
+ );
204
+ if (arr.every((v) => !!v)) {
205
+ return new Map(
206
+ arr.map(([k, v]) => [
207
+ zodCoerceInternal(schema_._def.keyType, k, options_),
208
+ zodCoerceInternal(schema_._def.valueType, v, options_)
209
+ ])
210
+ );
211
+ }
212
+ }
213
+ }
214
+ } else if (typeName === ZodFirstPartyTypeKind.ZodRecord) {
215
+ const schema_ = schema;
216
+ if (isPlainObject(value)) {
217
+ const newObj = {};
218
+ for (const [k, v] of Object.entries(value)) {
219
+ const key = zodCoerceInternal(schema_._def.keyType, k, options_);
220
+ const val = zodCoerceInternal(schema_._def.valueType, v, options_);
221
+ newObj[key] = val;
222
+ }
223
+ return newObj;
224
+ }
225
+ } else if (typeName === ZodFirstPartyTypeKind.ZodUnion || typeName === ZodFirstPartyTypeKind.ZodDiscriminatedUnion) {
226
+ const schema_ = schema;
227
+ if (schema_.safeParse(value).success) {
228
+ return value;
229
+ }
230
+ const results = [];
231
+ for (const s of schema_._def.options) {
232
+ const newValue = zodCoerceInternal(s, value, { ...options_, isRoot });
233
+ if (newValue === value)
234
+ continue;
235
+ const result = schema_.safeParse(newValue);
236
+ if (result.success) {
237
+ return newValue;
238
+ }
239
+ results.push([newValue, result.error.issues.length]);
240
+ }
241
+ if (results.length === 0) {
242
+ return value;
243
+ }
244
+ return results.sort((a, b) => a[1] - b[1])[0]?.[0];
245
+ } else if (typeName === ZodFirstPartyTypeKind.ZodIntersection) {
246
+ const schema_ = schema;
247
+ return zodCoerceInternal(
248
+ schema_._def.right,
249
+ zodCoerceInternal(schema_._def.left, value, { ...options_, isRoot }),
250
+ { ...options_, isRoot }
251
+ );
252
+ } else if (typeName === ZodFirstPartyTypeKind.ZodReadonly) {
253
+ const schema_ = schema;
254
+ return zodCoerceInternal(schema_._def.innerType, value, { ...options_, isRoot });
255
+ } else if (typeName === ZodFirstPartyTypeKind.ZodPipeline) {
256
+ const schema_ = schema;
257
+ return zodCoerceInternal(schema_._def.in, value, { ...options_, isRoot });
258
+ } else if (typeName === ZodFirstPartyTypeKind.ZodLazy) {
259
+ const schema_ = schema;
260
+ return zodCoerceInternal(schema_._def.getter(), value, { ...options_, isRoot });
261
+ } else if (typeName === ZodFirstPartyTypeKind.ZodEffects) {
262
+ const schema_ = schema;
263
+ return zodCoerceInternal(schema_._def.schema, value, { ...options_, isRoot });
264
+ } else if (typeName === ZodFirstPartyTypeKind.ZodBranded) {
265
+ const schema_ = schema;
266
+ return zodCoerceInternal(schema_._def.type, value, { ...options_, isRoot });
267
+ } else if (typeName === ZodFirstPartyTypeKind.ZodCatch) {
268
+ const schema_ = schema;
269
+ return zodCoerceInternal(schema_._def.innerType, value, { ...options_, isRoot });
270
+ } else if (typeName === ZodFirstPartyTypeKind.ZodDefault) {
271
+ const schema_ = schema;
272
+ return zodCoerceInternal(schema_._def.innerType, value, { ...options_, isRoot });
273
+ } else if (typeName === ZodFirstPartyTypeKind.ZodNullable) {
274
+ const schema_ = schema;
275
+ if (value === null) {
276
+ return null;
277
+ }
278
+ if (typeof value === "string" && value.toLowerCase() === "null") {
279
+ return schema_.safeParse(value).success ? value : null;
280
+ }
281
+ return zodCoerceInternal(schema_._def.innerType, value, { ...options_, isRoot });
282
+ } else if (typeName === ZodFirstPartyTypeKind.ZodOptional) {
283
+ const schema_ = schema;
284
+ if (value === void 0) {
285
+ return void 0;
286
+ }
287
+ if (typeof value === "string" && value.toLowerCase() === "undefined") {
288
+ return schema_.safeParse(value).success ? value : void 0;
289
+ }
290
+ return zodCoerceInternal(schema_._def.innerType, value, { ...options_, isRoot });
291
+ } else if (typeName === ZodFirstPartyTypeKind.ZodNativeEnum) {
292
+ const schema_ = schema;
293
+ if (Object.values(schema_._def.values).includes(value)) {
294
+ return value;
295
+ }
296
+ if (options?.bracketNotation && typeof value === "string") {
297
+ for (const expectedValue of Object.values(schema_._def.values)) {
298
+ if (expectedValue.toString() === value) {
299
+ return expectedValue;
300
+ }
301
+ }
302
+ }
303
+ } else if (typeName === ZodFirstPartyTypeKind.ZodLiteral) {
304
+ const schema_ = schema;
305
+ const expectedValue = schema_._def.value;
306
+ if (typeof value === "string" && typeof expectedValue !== "string") {
307
+ if (typeof expectedValue === "bigint") {
308
+ const num = guard(() => BigInt(value));
309
+ if (num !== void 0) {
310
+ return num;
311
+ }
312
+ } else if (expectedValue === void 0) {
313
+ if (value.toLocaleLowerCase() === "undefined") {
314
+ return void 0;
315
+ }
316
+ } else if (options?.bracketNotation) {
317
+ if (typeof expectedValue === "number") {
318
+ const num = Number(value);
319
+ if (!Number.isNaN(num)) {
320
+ return num;
321
+ }
322
+ } else if (typeof expectedValue === "boolean") {
323
+ const lower = value.toLowerCase();
324
+ if (lower === "false" || lower === "off" || lower === "f") {
325
+ return false;
326
+ }
327
+ if (lower === "true" || lower === "on" || lower === "t") {
328
+ return true;
329
+ }
330
+ } else if (expectedValue === null) {
331
+ if (value.toLocaleLowerCase() === "null") {
332
+ return null;
333
+ }
334
+ }
335
+ }
336
+ }
337
+ } else {
338
+ const _expected = typeName;
339
+ }
340
+ return value;
341
+ }
342
+
343
+ // src/converter.ts
344
+ import { JSONSchemaFormat } from "@orpc/openapi";
345
+
346
+ // ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
347
+ function escapeStringRegexp(string) {
348
+ if (typeof string !== "string") {
349
+ throw new TypeError("Expected a string");
350
+ }
351
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
352
+ }
353
+
354
+ // src/converter.ts
355
+ import {
356
+ ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
357
+ } from "zod";
358
+
359
+ // src/schemas.ts
2
360
  import wcmatch from "wildcard-match";
3
361
  import {
4
362
  custom
@@ -133,7 +491,473 @@ var oz = {
133
491
  regexp,
134
492
  url
135
493
  };
494
+
495
+ // src/converter.ts
496
+ var NON_LOGIC_KEYWORDS = [
497
+ // Core Documentation Keywords
498
+ "$anchor",
499
+ "$comment",
500
+ "$defs",
501
+ "$id",
502
+ "title",
503
+ "description",
504
+ // Value Keywords
505
+ "default",
506
+ "deprecated",
507
+ "examples",
508
+ // Metadata Keywords
509
+ "$schema",
510
+ "definitions",
511
+ // Legacy, but still used
512
+ "readOnly",
513
+ "writeOnly",
514
+ // Display and UI Hints
515
+ "contentMediaType",
516
+ "contentEncoding",
517
+ "format",
518
+ // Custom Extensions
519
+ "$vocabulary",
520
+ "$dynamicAnchor",
521
+ "$dynamicRef"
522
+ ];
523
+ var UNSUPPORTED_JSON_SCHEMA = { not: {} };
524
+ var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
525
+ function zodToJsonSchema(schema, options) {
526
+ if (schema["~standard"].vendor !== "zod") {
527
+ console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
528
+ return {};
529
+ }
530
+ const schema__ = schema;
531
+ if (!options?.isHandledZodDescription && "description" in schema__._def) {
532
+ const json = zodToJsonSchema(schema__, {
533
+ ...options,
534
+ isHandledZodDescription: true
535
+ });
536
+ return {
537
+ description: schema__._def.description,
538
+ ...json
539
+ };
540
+ }
541
+ if (!options?.isHandledCustomJSONSchema) {
542
+ const customJSONSchema = getCustomJSONSchema(schema__._def, options);
543
+ if (customJSONSchema) {
544
+ const json = zodToJsonSchema(schema__, {
545
+ ...options,
546
+ isHandledCustomJSONSchema: true
547
+ });
548
+ return {
549
+ ...json,
550
+ ...customJSONSchema
551
+ };
552
+ }
553
+ }
554
+ const childOptions = { ...options, isHandledCustomJSONSchema: false, isHandledZodDescription: false };
555
+ const customType = getCustomZodType(schema__._def);
556
+ switch (customType) {
557
+ case "Blob": {
558
+ return { type: "string", contentMediaType: "*/*" };
559
+ }
560
+ case "File": {
561
+ const mimeType = getCustomZodFileMimeType(schema__._def) ?? "*/*";
562
+ return { type: "string", contentMediaType: mimeType };
563
+ }
564
+ case "Invalid Date": {
565
+ return { const: "Invalid Date" };
566
+ }
567
+ case "RegExp": {
568
+ return {
569
+ type: "string",
570
+ pattern: "^\\/(.*)\\/([a-z]*)$"
571
+ };
572
+ }
573
+ case "URL": {
574
+ return { type: "string", format: JSONSchemaFormat.URI };
575
+ }
576
+ }
577
+ const _expectedCustomType = customType;
578
+ const typeName = schema__._def.typeName;
579
+ switch (typeName) {
580
+ case ZodFirstPartyTypeKind2.ZodString: {
581
+ const schema_ = schema__;
582
+ const json = { type: "string" };
583
+ for (const check of schema_._def.checks) {
584
+ switch (check.kind) {
585
+ case "base64":
586
+ json.contentEncoding = "base64";
587
+ break;
588
+ case "cuid":
589
+ json.pattern = "^[0-9A-HJKMNP-TV-Z]{26}$";
590
+ break;
591
+ case "email":
592
+ json.format = JSONSchemaFormat.Email;
593
+ break;
594
+ case "url":
595
+ json.format = JSONSchemaFormat.URI;
596
+ break;
597
+ case "uuid":
598
+ json.format = JSONSchemaFormat.UUID;
599
+ break;
600
+ case "regex":
601
+ json.pattern = check.regex.source;
602
+ break;
603
+ case "min":
604
+ json.minLength = check.value;
605
+ break;
606
+ case "max":
607
+ json.maxLength = check.value;
608
+ break;
609
+ case "length":
610
+ json.minLength = check.value;
611
+ json.maxLength = check.value;
612
+ break;
613
+ case "includes":
614
+ json.pattern = escapeStringRegexp(check.value);
615
+ break;
616
+ case "startsWith":
617
+ json.pattern = `^${escapeStringRegexp(check.value)}`;
618
+ break;
619
+ case "endsWith":
620
+ json.pattern = `${escapeStringRegexp(check.value)}$`;
621
+ break;
622
+ case "emoji":
623
+ json.pattern = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
624
+ break;
625
+ case "nanoid":
626
+ json.pattern = "^[a-zA-Z0-9_-]{21}$";
627
+ break;
628
+ case "cuid2":
629
+ json.pattern = "^[0-9a-z]+$";
630
+ break;
631
+ case "ulid":
632
+ json.pattern = "^[0-9A-HJKMNP-TV-Z]{26}$";
633
+ break;
634
+ case "datetime":
635
+ json.format = JSONSchemaFormat.DateTime;
636
+ break;
637
+ case "date":
638
+ json.format = JSONSchemaFormat.Date;
639
+ break;
640
+ case "time":
641
+ json.format = JSONSchemaFormat.Time;
642
+ break;
643
+ case "duration":
644
+ json.format = JSONSchemaFormat.Duration;
645
+ break;
646
+ case "ip":
647
+ json.format = JSONSchemaFormat.IPv4;
648
+ break;
649
+ case "jwt":
650
+ json.pattern = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$";
651
+ break;
652
+ case "base64url":
653
+ json.pattern = "^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$";
654
+ break;
655
+ default: {
656
+ const _expect = check.kind;
657
+ }
658
+ }
659
+ }
660
+ return json;
661
+ }
662
+ case ZodFirstPartyTypeKind2.ZodNumber: {
663
+ const schema_ = schema__;
664
+ const json = { type: "number" };
665
+ for (const check of schema_._def.checks) {
666
+ switch (check.kind) {
667
+ case "int":
668
+ json.type = "integer";
669
+ break;
670
+ case "min":
671
+ json.minimum = check.value;
672
+ break;
673
+ case "max":
674
+ json.maximum = check.value;
675
+ break;
676
+ case "multipleOf":
677
+ json.multipleOf = check.value;
678
+ break;
679
+ default: {
680
+ const _expect = check.kind;
681
+ }
682
+ }
683
+ }
684
+ return json;
685
+ }
686
+ case ZodFirstPartyTypeKind2.ZodNaN: {
687
+ return { const: "NaN" };
688
+ }
689
+ case ZodFirstPartyTypeKind2.ZodBigInt: {
690
+ const json = { type: "string", pattern: "^-?[0-9]+$" };
691
+ return json;
692
+ }
693
+ case ZodFirstPartyTypeKind2.ZodBoolean: {
694
+ return { type: "boolean" };
695
+ }
696
+ case ZodFirstPartyTypeKind2.ZodDate: {
697
+ const schema2 = { type: "string", format: JSONSchemaFormat.Date };
698
+ return schema2;
699
+ }
700
+ case ZodFirstPartyTypeKind2.ZodNull: {
701
+ return { type: "null" };
702
+ }
703
+ case ZodFirstPartyTypeKind2.ZodVoid:
704
+ case ZodFirstPartyTypeKind2.ZodUndefined: {
705
+ return UNDEFINED_JSON_SCHEMA;
706
+ }
707
+ case ZodFirstPartyTypeKind2.ZodLiteral: {
708
+ const schema_ = schema__;
709
+ return { const: schema_._def.value };
710
+ }
711
+ case ZodFirstPartyTypeKind2.ZodEnum: {
712
+ const schema_ = schema__;
713
+ return {
714
+ enum: schema_._def.values
715
+ };
716
+ }
717
+ case ZodFirstPartyTypeKind2.ZodNativeEnum: {
718
+ const schema_ = schema__;
719
+ return {
720
+ enum: Object.values(schema_._def.values)
721
+ };
722
+ }
723
+ case ZodFirstPartyTypeKind2.ZodArray: {
724
+ const schema_ = schema__;
725
+ const def = schema_._def;
726
+ const json = { type: "array" };
727
+ if (def.exactLength) {
728
+ json.maxItems = def.exactLength.value;
729
+ json.minItems = def.exactLength.value;
730
+ }
731
+ if (def.minLength) {
732
+ json.minItems = def.minLength.value;
733
+ }
734
+ if (def.maxLength) {
735
+ json.maxItems = def.maxLength.value;
736
+ }
737
+ return json;
738
+ }
739
+ case ZodFirstPartyTypeKind2.ZodTuple: {
740
+ const schema_ = schema__;
741
+ const prefixItems = [];
742
+ const json = { type: "array" };
743
+ for (const item of schema_._def.items) {
744
+ prefixItems.push(zodToJsonSchema(item, childOptions));
745
+ }
746
+ if (prefixItems?.length) {
747
+ json.prefixItems = prefixItems;
748
+ }
749
+ if (schema_._def.rest) {
750
+ const items = zodToJsonSchema(schema_._def.rest, childOptions);
751
+ if (items) {
752
+ json.items = items;
753
+ }
754
+ }
755
+ return json;
756
+ }
757
+ case ZodFirstPartyTypeKind2.ZodObject: {
758
+ const schema_ = schema__;
759
+ const json = { type: "object" };
760
+ const properties = {};
761
+ const required = [];
762
+ for (const [key, value] of Object.entries(schema_.shape)) {
763
+ const { schema: schema2, matches } = extractJSONSchema(
764
+ zodToJsonSchema(value, childOptions),
765
+ (schema3) => schema3 === UNDEFINED_JSON_SCHEMA
766
+ );
767
+ if (schema2) {
768
+ properties[key] = schema2;
769
+ }
770
+ if (matches.length === 0) {
771
+ required.push(key);
772
+ }
773
+ }
774
+ if (Object.keys(properties).length) {
775
+ json.properties = properties;
776
+ }
777
+ if (required.length) {
778
+ json.required = required;
779
+ }
780
+ const additionalProperties = zodToJsonSchema(
781
+ schema_._def.catchall,
782
+ childOptions
783
+ );
784
+ if (schema_._def.unknownKeys === "strict") {
785
+ json.additionalProperties = additionalProperties === UNSUPPORTED_JSON_SCHEMA ? false : additionalProperties;
786
+ } else {
787
+ if (additionalProperties && additionalProperties !== UNSUPPORTED_JSON_SCHEMA) {
788
+ json.additionalProperties = additionalProperties;
789
+ }
790
+ }
791
+ return json;
792
+ }
793
+ case ZodFirstPartyTypeKind2.ZodRecord: {
794
+ const schema_ = schema__;
795
+ const json = { type: "object" };
796
+ json.additionalProperties = zodToJsonSchema(
797
+ schema_._def.valueType,
798
+ childOptions
799
+ );
800
+ return json;
801
+ }
802
+ case ZodFirstPartyTypeKind2.ZodSet: {
803
+ const schema_ = schema__;
804
+ return {
805
+ type: "array",
806
+ items: zodToJsonSchema(schema_._def.valueType, childOptions)
807
+ };
808
+ }
809
+ case ZodFirstPartyTypeKind2.ZodMap: {
810
+ const schema_ = schema__;
811
+ return {
812
+ type: "array",
813
+ items: {
814
+ type: "array",
815
+ prefixItems: [
816
+ zodToJsonSchema(schema_._def.keyType, childOptions),
817
+ zodToJsonSchema(schema_._def.valueType, childOptions)
818
+ ],
819
+ maxItems: 2,
820
+ minItems: 2
821
+ }
822
+ };
823
+ }
824
+ case ZodFirstPartyTypeKind2.ZodUnion:
825
+ case ZodFirstPartyTypeKind2.ZodDiscriminatedUnion: {
826
+ const schema_ = schema__;
827
+ const anyOf = [];
828
+ for (const s of schema_._def.options) {
829
+ anyOf.push(zodToJsonSchema(s, childOptions));
830
+ }
831
+ return { anyOf };
832
+ }
833
+ case ZodFirstPartyTypeKind2.ZodIntersection: {
834
+ const schema_ = schema__;
835
+ const allOf = [];
836
+ for (const s of [schema_._def.left, schema_._def.right]) {
837
+ allOf.push(zodToJsonSchema(s, childOptions));
838
+ }
839
+ return { allOf };
840
+ }
841
+ case ZodFirstPartyTypeKind2.ZodLazy: {
842
+ const schema_ = schema__;
843
+ const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
844
+ const lazyDepth = childOptions?.lazyDepth ?? 0;
845
+ if (lazyDepth > maxLazyDepth) {
846
+ return {};
847
+ }
848
+ return zodToJsonSchema(schema_._def.getter(), {
849
+ ...childOptions,
850
+ lazyDepth: lazyDepth + 1
851
+ });
852
+ }
853
+ case ZodFirstPartyTypeKind2.ZodUnknown:
854
+ case ZodFirstPartyTypeKind2.ZodAny:
855
+ case void 0: {
856
+ return {};
857
+ }
858
+ case ZodFirstPartyTypeKind2.ZodOptional: {
859
+ const schema_ = schema__;
860
+ const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
861
+ return {
862
+ anyOf: [UNDEFINED_JSON_SCHEMA, inner]
863
+ };
864
+ }
865
+ case ZodFirstPartyTypeKind2.ZodReadonly: {
866
+ const schema_ = schema__;
867
+ return zodToJsonSchema(schema_._def.innerType, childOptions);
868
+ }
869
+ case ZodFirstPartyTypeKind2.ZodDefault: {
870
+ const schema_ = schema__;
871
+ return zodToJsonSchema(schema_._def.innerType, childOptions);
872
+ }
873
+ case ZodFirstPartyTypeKind2.ZodEffects: {
874
+ const schema_ = schema__;
875
+ if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
876
+ return {};
877
+ }
878
+ return zodToJsonSchema(schema_._def.schema, childOptions);
879
+ }
880
+ case ZodFirstPartyTypeKind2.ZodCatch: {
881
+ const schema_ = schema__;
882
+ return zodToJsonSchema(schema_._def.innerType, childOptions);
883
+ }
884
+ case ZodFirstPartyTypeKind2.ZodBranded: {
885
+ const schema_ = schema__;
886
+ return zodToJsonSchema(schema_._def.type, childOptions);
887
+ }
888
+ case ZodFirstPartyTypeKind2.ZodPipeline: {
889
+ const schema_ = schema__;
890
+ return zodToJsonSchema(
891
+ childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
892
+ childOptions
893
+ );
894
+ }
895
+ case ZodFirstPartyTypeKind2.ZodNullable: {
896
+ const schema_ = schema__;
897
+ const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
898
+ return {
899
+ anyOf: [{ type: "null" }, inner]
900
+ };
901
+ }
902
+ }
903
+ const _expected = typeName;
904
+ return UNSUPPORTED_JSON_SCHEMA;
905
+ }
906
+ function extractJSONSchema(schema, check, matches = []) {
907
+ if (check(schema)) {
908
+ matches.push(schema);
909
+ return { schema: void 0, matches };
910
+ }
911
+ if (typeof schema === "boolean") {
912
+ return { schema, matches };
913
+ }
914
+ if (schema.anyOf && Object.keys(schema).every(
915
+ (k) => k === "anyOf" || NON_LOGIC_KEYWORDS.includes(k)
916
+ )) {
917
+ const anyOf = schema.anyOf.map((s) => extractJSONSchema(s, check, matches).schema).filter((v) => !!v);
918
+ if (anyOf.length === 1 && typeof anyOf[0] === "object") {
919
+ return { schema: { ...schema, anyOf: void 0, ...anyOf[0] }, matches };
920
+ }
921
+ return {
922
+ schema: {
923
+ ...schema,
924
+ anyOf
925
+ },
926
+ matches
927
+ };
928
+ }
929
+ if (schema.oneOf && Object.keys(schema).every(
930
+ (k) => k === "oneOf" || NON_LOGIC_KEYWORDS.includes(k)
931
+ )) {
932
+ const oneOf = schema.oneOf.map((s) => extractJSONSchema(s, check, matches).schema).filter((v) => !!v);
933
+ if (oneOf.length === 1 && typeof oneOf[0] === "object") {
934
+ return { schema: { ...schema, oneOf: void 0, ...oneOf[0] }, matches };
935
+ }
936
+ return {
937
+ schema: {
938
+ ...schema,
939
+ oneOf
940
+ },
941
+ matches
942
+ };
943
+ }
944
+ return { schema, matches };
945
+ }
946
+ var ZodToJsonSchemaConverter = class {
947
+ condition(schema) {
948
+ return Boolean(schema && schema["~standard"].vendor === "zod");
949
+ }
950
+ convert(schema, options) {
951
+ const jsonSchema = schema;
952
+ return zodToJsonSchema(jsonSchema, { mode: options.strategy });
953
+ }
954
+ };
136
955
  export {
956
+ NON_LOGIC_KEYWORDS,
957
+ UNDEFINED_JSON_SCHEMA,
958
+ UNSUPPORTED_JSON_SCHEMA,
959
+ ZodCoercer,
960
+ ZodToJsonSchemaConverter,
137
961
  blob,
138
962
  file,
139
963
  getCustomJSONSchema,
@@ -143,6 +967,7 @@ export {
143
967
  openapi,
144
968
  oz,
145
969
  regexp,
146
- url
970
+ url,
971
+ zodToJsonSchema
147
972
  };
148
973
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ import type { Schema } from '@orpc/contract';
2
+ import type { SchemaCoercer } from '@orpc/openapi/fetch';
3
+ export declare class ZodCoercer implements SchemaCoercer {
4
+ coerce(schema: Schema, value: unknown): unknown;
5
+ }
6
+ //# sourceMappingURL=coercer.d.ts.map
@@ -0,0 +1,50 @@
1
+ import type { Schema } from '@orpc/contract';
2
+ import type { JSONSchema, SchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
3
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
4
+ export declare const NON_LOGIC_KEYWORDS: ("$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "contentEncoding" | "contentMediaType" | "default" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly")[];
5
+ export declare const UNSUPPORTED_JSON_SCHEMA: {
6
+ not: {};
7
+ };
8
+ export declare const UNDEFINED_JSON_SCHEMA: {
9
+ const: string;
10
+ };
11
+ export interface ZodToJsonSchemaOptions {
12
+ /**
13
+ * Max depth of lazy type, if it exceeds.
14
+ *
15
+ * Used `{}` when reach max depth
16
+ *
17
+ * @default 5
18
+ */
19
+ maxLazyDepth?: number;
20
+ /**
21
+ * The length used to track the depth of lazy type
22
+ *
23
+ * @internal
24
+ */
25
+ lazyDepth?: number;
26
+ /**
27
+ * The expected json schema for input or output zod schema
28
+ *
29
+ * @default input
30
+ */
31
+ mode?: 'input' | 'output';
32
+ /**
33
+ * Track if current level schema is handled custom json schema to prevent recursive
34
+ *
35
+ * @internal
36
+ */
37
+ isHandledCustomJSONSchema?: boolean;
38
+ /**
39
+ * Track if current level schema is handled zod description to prevent recursive
40
+ *
41
+ * @internal
42
+ */
43
+ isHandledZodDescription?: boolean;
44
+ }
45
+ export declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema.JSONSchema, boolean>;
46
+ export declare class ZodToJsonSchemaConverter implements SchemaConverter {
47
+ condition(schema: Schema): boolean;
48
+ convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
49
+ }
50
+ //# sourceMappingURL=converter.d.ts.map
@@ -1,31 +1,4 @@
1
- import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
2
- import { type CustomErrorParams, type input, type output, type ZodEffects, type ZodType, type ZodTypeAny, type ZodTypeDef } from 'zod';
3
- export type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL';
4
- type CustomParams = CustomErrorParams & {
5
- fatal?: boolean;
6
- };
7
- export declare function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined;
8
- export declare function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined;
9
- export declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
10
- mode?: 'input' | 'output';
11
- }): Exclude<JSONSchema, boolean> | undefined;
12
- export declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
13
- type: (mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)) => ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
14
- };
15
- export declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
16
- export declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
17
- export declare function regexp(options?: CustomParams): ZodType<RegExp, ZodTypeDef, RegExp>;
18
- export declare function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL>;
19
- export declare function openapi<T extends ZodTypeAny, TMode extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TMode extends 'input' ? input<T> : TMode extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
20
- mode: TMode;
21
- }): ReturnType<T['refine']>;
22
- export declare const oz: {
23
- openapi: typeof openapi;
24
- file: typeof file;
25
- blob: typeof blob;
26
- invalidDate: typeof invalidDate;
27
- regexp: typeof regexp;
28
- url: typeof url;
29
- };
30
- export {};
1
+ export * from './coercer';
2
+ export * from './converter';
3
+ export * from './schemas';
31
4
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,31 @@
1
+ import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
2
+ import { type CustomErrorParams, type input, type output, type ZodEffects, type ZodType, type ZodTypeAny, type ZodTypeDef } from 'zod';
3
+ export type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL';
4
+ type CustomParams = CustomErrorParams & {
5
+ fatal?: boolean;
6
+ };
7
+ export declare function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined;
8
+ export declare function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined;
9
+ export declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
10
+ mode?: 'input' | 'output';
11
+ }): Exclude<JSONSchema, boolean> | undefined;
12
+ export declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
13
+ type: (mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)) => ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
14
+ };
15
+ export declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
16
+ export declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
17
+ export declare function regexp(options?: CustomParams): ZodType<RegExp, ZodTypeDef, RegExp>;
18
+ export declare function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL>;
19
+ export declare function openapi<T extends ZodTypeAny, TMode extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TMode extends 'input' ? input<T> : TMode extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
20
+ mode: TMode;
21
+ }): ReturnType<T['refine']>;
22
+ export declare const oz: {
23
+ openapi: typeof openapi;
24
+ file: typeof file;
25
+ blob: typeof blob;
26
+ invalidDate: typeof invalidDate;
27
+ regexp: typeof regexp;
28
+ url: typeof url;
29
+ };
30
+ export {};
31
+ //# sourceMappingURL=schemas.d.ts.map
package/package.json CHANGED
@@ -1,21 +1,17 @@
1
1
  {
2
2
  "name": "@orpc/zod",
3
3
  "type": "module",
4
- "version": "0.0.0-next.e9dc36e",
5
- "author": {
6
- "name": "unnoq",
7
- "email": "contact@unnoq.com",
8
- "url": "https://unnoq.com"
9
- },
4
+ "version": "0.0.0-next.ed15210",
10
5
  "license": "MIT",
11
- "homepage": "https://github.com/unnoq/orpc",
6
+ "homepage": "https://orpc.unnoq.com",
12
7
  "repository": {
13
8
  "type": "git",
14
- "url": "https://github.com/unnoq/orpc.git",
9
+ "url": "git+https://github.com/unnoq/orpc.git",
15
10
  "directory": "packages/zod"
16
11
  },
17
12
  "keywords": [
18
- "unnoq"
13
+ "unnoq",
14
+ "orpc"
19
15
  ],
20
16
  "exports": {
21
17
  ".": {
@@ -28,13 +24,17 @@
28
24
  }
29
25
  },
30
26
  "files": [
31
- "dist",
32
- "src"
27
+ "!**/*.map",
28
+ "!**/*.tsbuildinfo",
29
+ "dist"
33
30
  ],
31
+ "peerDependencies": {
32
+ "@orpc/openapi": "0.0.0-next.ed15210"
33
+ },
34
34
  "dependencies": {
35
35
  "json-schema-typed": "^8.0.1",
36
36
  "wildcard-match": "^5.1.3",
37
- "zod": "^3.23.8"
37
+ "zod": "^3.24.1"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n\nimport type { JSONSchema } from 'json-schema-typed/draft-2020-12'\n\nimport wcmatch from 'wildcard-match'\nimport {\n custom,\n type CustomErrorParams,\n type input,\n type output,\n type ZodEffects,\n type ZodType,\n type ZodTypeAny,\n type ZodTypeDef,\n} from 'zod'\n\nexport type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL'\n\nconst customZodTypeSymbol = Symbol('customZodTypeSymbol')\n\nconst customZodFileMimeTypeSymbol = Symbol('customZodFileMimeTypeSymbol')\n\nconst CUSTOM_JSON_SCHEMA_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA')\nconst CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA_INPUT')\nconst CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA_OUTPUT')\n\ntype CustomParams = CustomErrorParams & {\n fatal?: boolean\n}\n\nexport function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined {\n return customZodTypeSymbol in def\n ? (def[customZodTypeSymbol] as CustomZodType)\n : undefined\n}\n\nexport function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined {\n return customZodFileMimeTypeSymbol in def\n ? (def[customZodFileMimeTypeSymbol] as string)\n : undefined\n}\n\nexport function getCustomJSONSchema(\n def: ZodTypeDef,\n options?: { mode?: 'input' | 'output' },\n): Exclude<JSONSchema, boolean> | undefined {\n if (options?.mode === 'input' && CUSTOM_JSON_SCHEMA_INPUT_SYMBOL in def) {\n return def[CUSTOM_JSON_SCHEMA_INPUT_SYMBOL] as Exclude<JSONSchema, boolean>\n }\n\n if (options?.mode === 'output' && CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL in def) {\n return def[CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL] as Exclude<JSONSchema, boolean>\n }\n\n if (CUSTOM_JSON_SCHEMA_SYMBOL in def) {\n return def[CUSTOM_JSON_SCHEMA_SYMBOL] as Exclude<JSONSchema, boolean>\n }\n\n return undefined\n}\n\nfunction composeParams<T = unknown>(options: {\n params?: string | CustomParams | ((input: T) => CustomParams)\n defaultMessage?: string | ((input: T) => string)\n}): (input: T) => CustomParams {\n return (val) => {\n const defaultMessage\n = typeof options.defaultMessage === 'function'\n ? options.defaultMessage(val)\n : options.defaultMessage\n\n if (!options.params) {\n return {\n message: defaultMessage,\n }\n }\n\n if (typeof options.params === 'function') {\n return {\n message: defaultMessage,\n ...options.params(val),\n }\n }\n\n if (typeof options.params === 'object') {\n return {\n message: defaultMessage,\n ...options.params,\n }\n }\n\n return {\n message: options.params,\n }\n }\n}\n\nexport function file(\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {\n type: (\n mimeType: string,\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n ) => ZodEffects<\n ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>,\n InstanceType<typeof File>,\n InstanceType<typeof File>\n >\n} {\n const schema = custom<InstanceType<typeof File>>(\n val => val instanceof File,\n composeParams({ params, defaultMessage: 'Input is not a file' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'File' satisfies CustomZodType,\n })\n\n return Object.assign(schema, {\n type: (\n mimeType: string,\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n ) => {\n const isMatch = wcmatch(mimeType)\n\n const refinedSchema = schema.refine(\n val => isMatch(val.type.split(';')[0]!),\n composeParams<InstanceType<typeof File>>({\n params,\n defaultMessage: val =>\n `Expected a file of type ${mimeType} but got a file of type ${val.type || 'unknown'}`,\n }),\n )\n\n Object.assign(refinedSchema._def, {\n [customZodTypeSymbol]: 'File' satisfies CustomZodType,\n [customZodFileMimeTypeSymbol]: mimeType,\n })\n\n return refinedSchema\n },\n })\n}\n\nexport function blob(\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>> {\n const schema = custom<InstanceType<typeof Blob>>(\n val => val instanceof Blob,\n composeParams({ params, defaultMessage: 'Input is not a blob' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'Blob' satisfies CustomZodType,\n })\n\n return schema\n}\n\nexport function invalidDate(\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n): ZodType<Date, ZodTypeDef, Date> {\n const schema = custom<Date>(\n val => val instanceof Date && Number.isNaN(val.getTime()),\n composeParams({ params, defaultMessage: 'Input is not an invalid date' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'Invalid Date' satisfies CustomZodType,\n })\n\n return schema\n}\n\nexport function regexp(\n options?: CustomParams,\n): ZodType<RegExp, ZodTypeDef, RegExp> {\n const schema = custom<RegExp>(\n val => val instanceof RegExp,\n composeParams({ params: options, defaultMessage: 'Input is not a regexp' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'RegExp' satisfies CustomZodType,\n })\n\n return schema\n}\n\nexport function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL> {\n const schema = custom<URL>(\n val => val instanceof URL,\n composeParams({ params: options, defaultMessage: 'Input is not a URL' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'URL' satisfies CustomZodType,\n })\n\n return schema\n}\n\nexport function openapi<\n T extends ZodTypeAny,\n TMode extends 'input' | 'output' | 'both' = 'both',\n>(\n schema: T,\n custom: Exclude<\n JSONSchema<\n TMode extends 'input'\n ? input<T>\n : TMode extends 'output'\n ? output<T>\n : input<T> & output<T>\n >,\n boolean\n >,\n options?: { mode: TMode },\n): ReturnType<T['refine']> {\n const newSchema = schema.refine(() => true) as ReturnType<T['refine']>\n\n const SYMBOL\n = options?.mode === 'input'\n ? CUSTOM_JSON_SCHEMA_INPUT_SYMBOL\n : options?.mode === 'output'\n ? CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL\n : CUSTOM_JSON_SCHEMA_SYMBOL\n\n Object.assign(newSchema._def, {\n [SYMBOL]: custom,\n })\n\n return newSchema\n}\n\nexport const oz = {\n openapi,\n file,\n blob,\n invalidDate,\n regexp,\n url,\n}\n"],"mappings":"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","names":["params","custom"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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"}
@@ -1 +0,0 @@
1
- {"fileNames":["../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../node_modules/.pnpm/@types+react@18.3.12/node_modules/@types/react/global.d.ts","../../../node_modules/.pnpm/csstype@3.1.3/node_modules/csstype/index.d.ts","../../../node_modules/.pnpm/@types+prop-types@15.7.13/node_modules/@types/prop-types/index.d.ts","../../../node_modules/.pnpm/@types+react@18.3.12/node_modules/@types/react/index.d.ts","../../../node_modules/.pnpm/@types+react@18.3.12/node_modules/@types/react/jsx-runtime.d.ts","../../../node_modules/.pnpm/json-schema-typed@8.0.1/node_modules/json-schema-typed/draft-2020-12.ts","../../../node_modules/.pnpm/wildcard-match@5.1.3/node_modules/wildcard-match/build/index.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/typeAliases.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/util.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/ZodError.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/locales/en.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/errors.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/parseUtil.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/enumUtil.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/errorUtil.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/partialUtil.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/types.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/external.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/index.d.ts","../src/index.ts"],"fileIdsList":[[59,60,61],[62],[63],[77],[66,67,77],[68,69],[66,67,68,70,71,75],[67,68],[76],[68],[66,67,68,71,72,73,74],[63,64,65,78]],"fileInfos":[{"version":"e41c290ef7dd7dab3493e6cbe5909e0148edf4a8dad0271be08edec368a0f7b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","impliedFormat":1},{"version":"feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","impliedFormat":1},{"version":"ee7bad0c15b58988daa84371e0b89d313b762ab83cb5b31b8a2d1162e8eb41c2","impliedFormat":1},{"version":"4fd3f3422b2d2a3dfd5cdd0f387b3a8ec45f006c6ea896a4cb41264c2100bb2c","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"62bb211266ee48b2d0edf0d8d1b191f0c24fc379a82bd4c1692a082c540bc6b1","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"936e80ad36a2ee83fc3caf008e7c4c5afe45b3cf3d5c24408f039c1d47bdc1df","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"fef8cfad2e2dc5f5b3d97a6f4f2e92848eb1b88e897bb7318cef0e2820bceaab","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"f1e2a172204962276504466a6393426d2ca9c54894b1ad0a6c9dad867a65f876","affectsGlobalScope":true,"impliedFormat":1},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true,"impliedFormat":1},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true,"impliedFormat":1},{"version":"52ada8e0b6e0482b728070b7639ee42e83a9b1c22d205992756fe020fd9f4a47","affectsGlobalScope":true,"impliedFormat":1},{"version":"3bdefe1bfd4d6dee0e26f928f93ccc128f1b64d5d501ff4a8cf3c6371200e5e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59fb2c069260b4ba00b5643b907ef5d5341b167e7d1dbf58dfd895658bda2867","affectsGlobalScope":true,"impliedFormat":1},{"version":"639e512c0dfc3fad96a84caad71b8834d66329a1f28dc95e3946c9b58176c73a","affectsGlobalScope":true,"impliedFormat":1},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true,"impliedFormat":1},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true,"impliedFormat":1},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true,"impliedFormat":1},{"version":"959d36cddf5e7d572a65045b876f2956c973a586da58e5d26cde519184fd9b8a","affectsGlobalScope":true,"impliedFormat":1},{"version":"965f36eae237dd74e6cca203a43e9ca801ce38824ead814728a2807b1910117d","affectsGlobalScope":true,"impliedFormat":1},{"version":"3925a6c820dcb1a06506c90b1577db1fdbf7705d65b62b99dce4be75c637e26b","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a3d63ef2b853447ec4f749d3f368ce642264246e02911fcb1590d8c161b8005","affectsGlobalScope":true,"impliedFormat":1},{"version":"b5ce7a470bc3628408429040c4e3a53a27755022a32fd05e2cb694e7015386c7","affectsGlobalScope":true,"impliedFormat":1},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true,"impliedFormat":1},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true,"impliedFormat":1},{"version":"b4b67b1a91182421f5df999988c690f14d813b9850b40acd06ed44691f6727ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"36a2e4c9a67439aca5f91bb304611d5ae6e20d420503e96c230cf8fcdc948d94","affectsGlobalScope":true,"impliedFormat":1},{"version":"8a8eb4ebffd85e589a1cc7c178e291626c359543403d58c9cd22b81fab5b1fb9","impliedFormat":1},{"version":"ed6b820c54de95b2510bb673490d61c7f2187f532a339d8d04981645a918961f","impliedFormat":1},{"version":"aa17748c522bd586f8712b1a308ea23af59c309b2fd278f6d4f406647c72e659","affectsGlobalScope":true,"impliedFormat":1},{"version":"42c169fb8c2d42f4f668c624a9a11e719d5d07dacbebb63cbcf7ef365b0a75b3","impliedFormat":1},{"version":"126783a400a891fce19c88533874b41073eb898725cb2a86a878e3b18e4e71f8","impliedFormat":99},{"version":"30b2bd1237547fbccd267bd8680d721dce8c71bd2f156d6987d599f9098e15d5","impliedFormat":1},{"version":"5487b97cfa28b26b4a9ef0770f872bdbebd4c46124858de00f242c3eed7519f4","impliedFormat":1},{"version":"c2869c4f2f79fd2d03278a68ce7c061a5a8f4aed59efb655e25fe502e3e471d5","impliedFormat":1},{"version":"b8fe42dbf4b0efba2eb4dbfb2b95a3712676717ff8469767dc439e75d0c1a3b6","impliedFormat":1},{"version":"8485b6da53ec35637d072e516631d25dae53984500de70a6989058f24354666f","impliedFormat":1},{"version":"ebe80346928736532e4a822154eb77f57ef3389dbe2b3ba4e571366a15448ef2","impliedFormat":1},{"version":"83306c97a4643d78420f082547ea0d488a0d134c922c8e65fc0b4f08ef66d92b","impliedFormat":1},{"version":"f672c876c1a04a223cf2023b3d91e8a52bb1544c576b81bf64a8fec82be9969c","impliedFormat":1},{"version":"98a9cc18f661d28e6bd31c436e1984f3980f35e0f0aa9cf795c54f8ccb667ffe","impliedFormat":1},{"version":"c76b0c5727302341d0bdfa2cc2cee4b19ff185b554edb6e8543f0661d8487116","impliedFormat":1},{"version":"dccd26a5c85325a011aff40f401e0892bd0688d44132ba79e803c67e68fffea5","impliedFormat":1},{"version":"f5ef066942e4f0bd98200aa6a6694b831e73200c9b3ade77ad0aa2409e8fe1b1","impliedFormat":1},{"version":"b9e99cd94f4166a245f5158f7286c05406e2a4c694619bceb7a4f3519d1d768e","impliedFormat":1},{"version":"5568d7c32e5cf5f35e092649f4e5e168c3114c800b1d7545b7ae5e0415704802","impliedFormat":1},{"version":"89f7baaef85d67be01d0c72b7ab82f843200f90ec7c22c2e076939e6782b64d1","signature":"fcd80ef2e1c0087c333eb0f1d71f07b24d5905e689703a9af79bf8ae2e0622ae"}],"root":[79],"options":{"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":true,"jsx":4,"module":7,"noImplicitOverride":true,"noUncheckedIndexedAccess":true,"noUncheckedSideEffectImports":true,"outDir":"./","skipLibCheck":true,"strict":true,"target":9,"useDefineForClassFields":true},"referencedMap":[[62,1],[63,2],[64,3],[78,4],[68,5],[70,6],[76,7],[71,8],[74,4],[77,9],[69,10],[75,11],[79,12]],"semanticDiagnosticsPerFile":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79],"latestChangedDtsFile":"./src/index.d.ts","checkPending":true,"version":"5.7.2"}
package/src/index.ts DELETED
@@ -1,243 +0,0 @@
1
- /// <reference lib="dom" />
2
-
3
- import type { JSONSchema } from 'json-schema-typed/draft-2020-12'
4
-
5
- import wcmatch from 'wildcard-match'
6
- import {
7
- custom,
8
- type CustomErrorParams,
9
- type input,
10
- type output,
11
- type ZodEffects,
12
- type ZodType,
13
- type ZodTypeAny,
14
- type ZodTypeDef,
15
- } from 'zod'
16
-
17
- export type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL'
18
-
19
- const customZodTypeSymbol = Symbol('customZodTypeSymbol')
20
-
21
- const customZodFileMimeTypeSymbol = Symbol('customZodFileMimeTypeSymbol')
22
-
23
- const CUSTOM_JSON_SCHEMA_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA')
24
- const CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA_INPUT')
25
- const CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA_OUTPUT')
26
-
27
- type CustomParams = CustomErrorParams & {
28
- fatal?: boolean
29
- }
30
-
31
- export function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined {
32
- return customZodTypeSymbol in def
33
- ? (def[customZodTypeSymbol] as CustomZodType)
34
- : undefined
35
- }
36
-
37
- export function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined {
38
- return customZodFileMimeTypeSymbol in def
39
- ? (def[customZodFileMimeTypeSymbol] as string)
40
- : undefined
41
- }
42
-
43
- export function getCustomJSONSchema(
44
- def: ZodTypeDef,
45
- options?: { mode?: 'input' | 'output' },
46
- ): Exclude<JSONSchema, boolean> | undefined {
47
- if (options?.mode === 'input' && CUSTOM_JSON_SCHEMA_INPUT_SYMBOL in def) {
48
- return def[CUSTOM_JSON_SCHEMA_INPUT_SYMBOL] as Exclude<JSONSchema, boolean>
49
- }
50
-
51
- if (options?.mode === 'output' && CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL in def) {
52
- return def[CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL] as Exclude<JSONSchema, boolean>
53
- }
54
-
55
- if (CUSTOM_JSON_SCHEMA_SYMBOL in def) {
56
- return def[CUSTOM_JSON_SCHEMA_SYMBOL] as Exclude<JSONSchema, boolean>
57
- }
58
-
59
- return undefined
60
- }
61
-
62
- function composeParams<T = unknown>(options: {
63
- params?: string | CustomParams | ((input: T) => CustomParams)
64
- defaultMessage?: string | ((input: T) => string)
65
- }): (input: T) => CustomParams {
66
- return (val) => {
67
- const defaultMessage
68
- = typeof options.defaultMessage === 'function'
69
- ? options.defaultMessage(val)
70
- : options.defaultMessage
71
-
72
- if (!options.params) {
73
- return {
74
- message: defaultMessage,
75
- }
76
- }
77
-
78
- if (typeof options.params === 'function') {
79
- return {
80
- message: defaultMessage,
81
- ...options.params(val),
82
- }
83
- }
84
-
85
- if (typeof options.params === 'object') {
86
- return {
87
- message: defaultMessage,
88
- ...options.params,
89
- }
90
- }
91
-
92
- return {
93
- message: options.params,
94
- }
95
- }
96
- }
97
-
98
- export function file(
99
- params?: string | CustomParams | ((input: unknown) => CustomParams),
100
- ): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
101
- type: (
102
- mimeType: string,
103
- params?: string | CustomParams | ((input: unknown) => CustomParams),
104
- ) => ZodEffects<
105
- ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>,
106
- InstanceType<typeof File>,
107
- InstanceType<typeof File>
108
- >
109
- } {
110
- const schema = custom<InstanceType<typeof File>>(
111
- val => val instanceof File,
112
- composeParams({ params, defaultMessage: 'Input is not a file' }),
113
- )
114
-
115
- Object.assign(schema._def, {
116
- [customZodTypeSymbol]: 'File' satisfies CustomZodType,
117
- })
118
-
119
- return Object.assign(schema, {
120
- type: (
121
- mimeType: string,
122
- params?: string | CustomParams | ((input: unknown) => CustomParams),
123
- ) => {
124
- const isMatch = wcmatch(mimeType)
125
-
126
- const refinedSchema = schema.refine(
127
- val => isMatch(val.type.split(';')[0]!),
128
- composeParams<InstanceType<typeof File>>({
129
- params,
130
- defaultMessage: val =>
131
- `Expected a file of type ${mimeType} but got a file of type ${val.type || 'unknown'}`,
132
- }),
133
- )
134
-
135
- Object.assign(refinedSchema._def, {
136
- [customZodTypeSymbol]: 'File' satisfies CustomZodType,
137
- [customZodFileMimeTypeSymbol]: mimeType,
138
- })
139
-
140
- return refinedSchema
141
- },
142
- })
143
- }
144
-
145
- export function blob(
146
- params?: string | CustomParams | ((input: unknown) => CustomParams),
147
- ): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>> {
148
- const schema = custom<InstanceType<typeof Blob>>(
149
- val => val instanceof Blob,
150
- composeParams({ params, defaultMessage: 'Input is not a blob' }),
151
- )
152
-
153
- Object.assign(schema._def, {
154
- [customZodTypeSymbol]: 'Blob' satisfies CustomZodType,
155
- })
156
-
157
- return schema
158
- }
159
-
160
- export function invalidDate(
161
- params?: string | CustomParams | ((input: unknown) => CustomParams),
162
- ): ZodType<Date, ZodTypeDef, Date> {
163
- const schema = custom<Date>(
164
- val => val instanceof Date && Number.isNaN(val.getTime()),
165
- composeParams({ params, defaultMessage: 'Input is not an invalid date' }),
166
- )
167
-
168
- Object.assign(schema._def, {
169
- [customZodTypeSymbol]: 'Invalid Date' satisfies CustomZodType,
170
- })
171
-
172
- return schema
173
- }
174
-
175
- export function regexp(
176
- options?: CustomParams,
177
- ): ZodType<RegExp, ZodTypeDef, RegExp> {
178
- const schema = custom<RegExp>(
179
- val => val instanceof RegExp,
180
- composeParams({ params: options, defaultMessage: 'Input is not a regexp' }),
181
- )
182
-
183
- Object.assign(schema._def, {
184
- [customZodTypeSymbol]: 'RegExp' satisfies CustomZodType,
185
- })
186
-
187
- return schema
188
- }
189
-
190
- export function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL> {
191
- const schema = custom<URL>(
192
- val => val instanceof URL,
193
- composeParams({ params: options, defaultMessage: 'Input is not a URL' }),
194
- )
195
-
196
- Object.assign(schema._def, {
197
- [customZodTypeSymbol]: 'URL' satisfies CustomZodType,
198
- })
199
-
200
- return schema
201
- }
202
-
203
- export function openapi<
204
- T extends ZodTypeAny,
205
- TMode extends 'input' | 'output' | 'both' = 'both',
206
- >(
207
- schema: T,
208
- custom: Exclude<
209
- JSONSchema<
210
- TMode extends 'input'
211
- ? input<T>
212
- : TMode extends 'output'
213
- ? output<T>
214
- : input<T> & output<T>
215
- >,
216
- boolean
217
- >,
218
- options?: { mode: TMode },
219
- ): ReturnType<T['refine']> {
220
- const newSchema = schema.refine(() => true) as ReturnType<T['refine']>
221
-
222
- const SYMBOL
223
- = options?.mode === 'input'
224
- ? CUSTOM_JSON_SCHEMA_INPUT_SYMBOL
225
- : options?.mode === 'output'
226
- ? CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL
227
- : CUSTOM_JSON_SCHEMA_SYMBOL
228
-
229
- Object.assign(newSchema._def, {
230
- [SYMBOL]: custom,
231
- })
232
-
233
- return newSchema
234
- }
235
-
236
- export const oz = {
237
- openapi,
238
- file,
239
- blob,
240
- invalidDate,
241
- regexp,
242
- url,
243
- }