@loopstack/loopstack-studio 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/api/index.js +12 -10
  2. package/dist/api/secrets.js +16 -0
  3. package/dist/components/dynamic-form/ArrayController.js +68 -64
  4. package/dist/components/dynamic-form/Form.js +56 -27
  5. package/dist/components/dynamic-form/FormElement.js +1 -1
  6. package/dist/components/dynamic-form/FormElementHeader.js +2 -2
  7. package/dist/components/dynamic-form/InputController.js +3 -1
  8. package/dist/components/dynamic-form/ObjectController.js +24 -21
  9. package/dist/components/dynamic-form/fields/BaseFieldWrapper.js +1 -1
  10. package/dist/components/dynamic-form/fields/InputField.js +20 -19
  11. package/dist/components/dynamic-form/fields/MarkdownViewField.js +20 -0
  12. package/dist/components/dynamic-form/fields/RadioField.js +18 -18
  13. package/dist/components/dynamic-form/fields/SelectField.js +19 -19
  14. package/dist/components/dynamic-form/fields/TextareaField.js +17 -17
  15. package/dist/components/layout/MainLayout.js +18 -31
  16. package/dist/components/layout/StudioSidebar.js +168 -108
  17. package/dist/components/page/PageBreadcrumbs.js +79 -32
  18. package/dist/components/ui-widgets/UiWidget.js +36 -27
  19. package/dist/components/ui-widgets/widgets/SecretInput.js +42 -0
  20. package/dist/features/code-explorer/components/CodeExplorerTreeNode.js +80 -4
  21. package/dist/features/code-explorer/components/FileContentViewer.js +47 -30
  22. package/dist/features/code-explorer/components/FileTabsBar.js +3 -190
  23. package/dist/features/code-explorer/components/FileTabsBarBase.js +190 -0
  24. package/dist/features/code-explorer/index.js +2 -2
  25. package/dist/features/code-explorer/providers/CodeExplorerProvider.js +2 -162
  26. package/dist/features/code-explorer/utils/fileIcons.js +7 -4
  27. package/dist/features/debug/components/PipelineFlowViewer.js +46 -45
  28. package/dist/features/debug/components/pipeline-flow/WorkflowGraph.js +19 -19
  29. package/dist/features/documents/DocumentRenderer.js +20 -15
  30. package/dist/features/documents/components/DocumentList.js +5 -1
  31. package/dist/features/documents/renderers/AiMessage.js +11 -11
  32. package/dist/features/documents/renderers/ClaudeMessage.js +96 -0
  33. package/dist/features/documents/renderers/DocumentFormRenderer.js +17 -11
  34. package/dist/features/workbench/Workbench.js +64 -80
  35. package/dist/features/workbench/WorkflowItem.js +5 -5
  36. package/dist/features/workbench/components/RemoteFileTabsBar.js +18 -0
  37. package/dist/features/workbench/components/RemoteFileTree.js +90 -0
  38. package/dist/features/workbench/components/WorkbenchFilesPanel.js +67 -0
  39. package/dist/features/workbench/components/WorkbenchFloatingPanel.js +57 -49
  40. package/dist/features/workbench/components/WorkbenchFlowPanel.js +2 -2
  41. package/dist/features/workbench/components/WorkbenchIconSidebar.js +48 -28
  42. package/dist/features/workbench/components/WorkbenchSecretsPanel.js +182 -0
  43. package/dist/features/workbench/hooks/useWorkflowData.js +4 -4
  44. package/dist/features/workbench/providers/RemoteFileExplorerProvider.js +160 -0
  45. package/dist/features/workbench/providers/WorkbenchLayoutProvider.js +46 -43
  46. package/dist/features/workspaces/components/PipelineForm.js +1 -1
  47. package/dist/features/workspaces/components/WorkspaceHomePage.js +93 -0
  48. package/dist/hooks/index.js +1 -1
  49. package/dist/hooks/query-keys.js +41 -34
  50. package/dist/hooks/useFiles.js +1 -43
  51. package/dist/hooks/useSecrets.js +69 -0
  52. package/dist/index.d.ts +49 -0
  53. package/dist/index.js +3 -2
  54. package/dist/node_modules/@xyflow/react/dist/esm/index.js +1 -1
  55. package/dist/pages/DashboardPage.js +87 -35
  56. package/dist/pages/EmbedWorkbenchPage.js +43 -39
  57. package/dist/pages/PipelineDebugPage.js +1 -1
  58. package/dist/pages/PreviewWorkbenchPage.js +167 -70
  59. package/dist/pages/WorkspacePage.js +102 -50
  60. package/dist/pages/WorkspaceRunsPage.js +71 -0
  61. package/dist/routing/LocalRouter.js +6 -0
  62. package/dist/types/ai.types.js +13 -0
  63. package/package.json +2 -3
  64. package/dist/node_modules/@ai-sdk/provider/dist/index.js +0 -65
  65. package/dist/node_modules/@ai-sdk/provider-utils/dist/index.js +0 -1008
  66. package/dist/node_modules/ai/dist/index.js +0 -1083
  67. package/dist/node_modules/zod/v3/ZodError.js +0 -79
  68. package/dist/node_modules/zod/v3/errors.js +0 -6
  69. package/dist/node_modules/zod/v3/helpers/errorUtil.js +0 -5
  70. package/dist/node_modules/zod/v3/helpers/parseUtil.js +0 -90
  71. package/dist/node_modules/zod/v3/helpers/util.js +0 -72
  72. package/dist/node_modules/zod/v3/locales/en.js +0 -58
  73. package/dist/node_modules/zod/v3/types.js +0 -2425
  74. package/dist/node_modules/zod/v4/classic/errors.js +0 -21
  75. package/dist/node_modules/zod/v4/classic/iso.js +0 -29
  76. package/dist/node_modules/zod/v4/classic/parse.js +0 -4
  77. package/dist/node_modules/zod/v4/classic/schemas.js +0 -392
  78. package/dist/node_modules/zod/v4/core/api.js +0 -532
  79. package/dist/node_modules/zod/v4/core/checks.js +0 -283
  80. package/dist/node_modules/zod/v4/core/core.js +0 -44
  81. package/dist/node_modules/zod/v4/core/doc.js +0 -21
  82. package/dist/node_modules/zod/v4/core/errors.js +0 -40
  83. package/dist/node_modules/zod/v4/core/json-schema-processors.js +0 -305
  84. package/dist/node_modules/zod/v4/core/parse.js +0 -66
  85. package/dist/node_modules/zod/v4/core/regexes.js +0 -28
  86. package/dist/node_modules/zod/v4/core/registries.js +0 -38
  87. package/dist/node_modules/zod/v4/core/schemas.js +0 -863
  88. package/dist/node_modules/zod/v4/core/to-json-schema.js +0 -220
  89. package/dist/node_modules/zod/v4/core/util.js +0 -267
  90. package/dist/node_modules/zod/v4/core/versions.js +0 -6
@@ -1,2425 +0,0 @@
1
- import { ZodParsedType, getParsedType, util } from "./helpers/util.js";
2
- import { ZodError, ZodIssueCode } from "./ZodError.js";
3
- import en_default from "./locales/en.js";
4
- import { getErrorMap } from "./errors.js";
5
- import { DIRTY, INVALID, OK, ParseStatus, addIssueToContext, isAborted, isAsync, isDirty, isValid, makeIssue } from "./helpers/parseUtil.js";
6
- import { errorUtil } from "./helpers/errorUtil.js";
7
- var ParseInputLazyPath = class {
8
- constructor(m, U, W, G) {
9
- this._cachedPath = [], this.parent = m, this.data = U, this._path = W, this._key = G;
10
- }
11
- get path() {
12
- return this._cachedPath.length || (Array.isArray(this._key) ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
13
- }
14
- }, handleResult = (m, U) => {
15
- if (isValid(U)) return {
16
- success: !0,
17
- data: U.value
18
- };
19
- if (!m.common.issues.length) throw Error("Validation failed but no issues detected.");
20
- return {
21
- success: !1,
22
- get error() {
23
- return this._error ||= new ZodError(m.common.issues), this._error;
24
- }
25
- };
26
- };
27
- function processCreateParams(m) {
28
- if (!m) return {};
29
- let { errorMap: U, invalid_type_error: W, required_error: G, description: K } = m;
30
- if (U && (W || G)) throw Error("Can't use \"invalid_type_error\" or \"required_error\" in conjunction with custom error map.");
31
- return U ? {
32
- errorMap: U,
33
- description: K
34
- } : {
35
- errorMap: (U, K) => {
36
- let { message: q } = m;
37
- return U.code === "invalid_enum_value" ? { message: q ?? K.defaultError } : K.data === void 0 ? { message: q ?? G ?? K.defaultError } : U.code === "invalid_type" ? { message: q ?? W ?? K.defaultError } : { message: K.defaultError };
38
- },
39
- description: K
40
- };
41
- }
42
- var ZodType = class {
43
- get description() {
44
- return this._def.description;
45
- }
46
- _getType(m) {
47
- return getParsedType(m.data);
48
- }
49
- _getOrReturnCtx(m, W) {
50
- return W || {
51
- common: m.parent.common,
52
- data: m.data,
53
- parsedType: getParsedType(m.data),
54
- schemaErrorMap: this._def.errorMap,
55
- path: m.path,
56
- parent: m.parent
57
- };
58
- }
59
- _processInputParams(m) {
60
- return {
61
- status: new ParseStatus(),
62
- ctx: {
63
- common: m.parent.common,
64
- data: m.data,
65
- parsedType: getParsedType(m.data),
66
- schemaErrorMap: this._def.errorMap,
67
- path: m.path,
68
- parent: m.parent
69
- }
70
- };
71
- }
72
- _parseSync(m) {
73
- let U = this._parse(m);
74
- if (isAsync(U)) throw Error("Synchronous parse encountered promise.");
75
- return U;
76
- }
77
- _parseAsync(m) {
78
- let U = this._parse(m);
79
- return Promise.resolve(U);
80
- }
81
- parse(m, U) {
82
- let W = this.safeParse(m, U);
83
- if (W.success) return W.data;
84
- throw W.error;
85
- }
86
- safeParse(m, W) {
87
- let G = {
88
- common: {
89
- issues: [],
90
- async: W?.async ?? !1,
91
- contextualErrorMap: W?.errorMap
92
- },
93
- path: W?.path || [],
94
- schemaErrorMap: this._def.errorMap,
95
- parent: null,
96
- data: m,
97
- parsedType: getParsedType(m)
98
- };
99
- return handleResult(G, this._parseSync({
100
- data: m,
101
- path: G.path,
102
- parent: G
103
- }));
104
- }
105
- "~validate"(m) {
106
- let W = {
107
- common: {
108
- issues: [],
109
- async: !!this["~standard"].async
110
- },
111
- path: [],
112
- schemaErrorMap: this._def.errorMap,
113
- parent: null,
114
- data: m,
115
- parsedType: getParsedType(m)
116
- };
117
- if (!this["~standard"].async) try {
118
- let U = this._parseSync({
119
- data: m,
120
- path: [],
121
- parent: W
122
- });
123
- return isValid(U) ? { value: U.value } : { issues: W.common.issues };
124
- } catch (m) {
125
- m?.message?.toLowerCase()?.includes("encountered") && (this["~standard"].async = !0), W.common = {
126
- issues: [],
127
- async: !0
128
- };
129
- }
130
- return this._parseAsync({
131
- data: m,
132
- path: [],
133
- parent: W
134
- }).then((m) => isValid(m) ? { value: m.value } : { issues: W.common.issues });
135
- }
136
- async parseAsync(m, U) {
137
- let W = await this.safeParseAsync(m, U);
138
- if (W.success) return W.data;
139
- throw W.error;
140
- }
141
- async safeParseAsync(m, W) {
142
- let G = {
143
- common: {
144
- issues: [],
145
- contextualErrorMap: W?.errorMap,
146
- async: !0
147
- },
148
- path: W?.path || [],
149
- schemaErrorMap: this._def.errorMap,
150
- parent: null,
151
- data: m,
152
- parsedType: getParsedType(m)
153
- }, K = this._parse({
154
- data: m,
155
- path: G.path,
156
- parent: G
157
- });
158
- return handleResult(G, await (isAsync(K) ? K : Promise.resolve(K)));
159
- }
160
- refine(m, U) {
161
- let W = (m) => typeof U == "string" || U === void 0 ? { message: U } : typeof U == "function" ? U(m) : U;
162
- return this._refinement((U, G) => {
163
- let q = m(U), J = () => G.addIssue({
164
- code: ZodIssueCode.custom,
165
- ...W(U)
166
- });
167
- return typeof Promise < "u" && q instanceof Promise ? q.then((m) => m ? !0 : (J(), !1)) : q ? !0 : (J(), !1);
168
- });
169
- }
170
- refinement(m, U) {
171
- return this._refinement((W, G) => m(W) ? !0 : (G.addIssue(typeof U == "function" ? U(W, G) : U), !1));
172
- }
173
- _refinement(m) {
174
- return new ZodEffects({
175
- schema: this,
176
- typeName: ZodFirstPartyTypeKind.ZodEffects,
177
- effect: {
178
- type: "refinement",
179
- refinement: m
180
- }
181
- });
182
- }
183
- superRefine(m) {
184
- return this._refinement(m);
185
- }
186
- constructor(m) {
187
- this.spa = this.safeParseAsync, this._def = m, this.parse = this.parse.bind(this), this.safeParse = this.safeParse.bind(this), this.parseAsync = this.parseAsync.bind(this), this.safeParseAsync = this.safeParseAsync.bind(this), this.spa = this.spa.bind(this), this.refine = this.refine.bind(this), this.refinement = this.refinement.bind(this), this.superRefine = this.superRefine.bind(this), this.optional = this.optional.bind(this), this.nullable = this.nullable.bind(this), this.nullish = this.nullish.bind(this), this.array = this.array.bind(this), this.promise = this.promise.bind(this), this.or = this.or.bind(this), this.and = this.and.bind(this), this.transform = this.transform.bind(this), this.brand = this.brand.bind(this), this.default = this.default.bind(this), this.catch = this.catch.bind(this), this.describe = this.describe.bind(this), this.pipe = this.pipe.bind(this), this.readonly = this.readonly.bind(this), this.isNullable = this.isNullable.bind(this), this.isOptional = this.isOptional.bind(this), this["~standard"] = {
188
- version: 1,
189
- vendor: "zod",
190
- validate: (m) => this["~validate"](m)
191
- };
192
- }
193
- optional() {
194
- return ZodOptional.create(this, this._def);
195
- }
196
- nullable() {
197
- return ZodNullable.create(this, this._def);
198
- }
199
- nullish() {
200
- return this.nullable().optional();
201
- }
202
- array() {
203
- return ZodArray.create(this);
204
- }
205
- promise() {
206
- return ZodPromise.create(this, this._def);
207
- }
208
- or(m) {
209
- return ZodUnion.create([this, m], this._def);
210
- }
211
- and(m) {
212
- return ZodIntersection.create(this, m, this._def);
213
- }
214
- transform(m) {
215
- return new ZodEffects({
216
- ...processCreateParams(this._def),
217
- schema: this,
218
- typeName: ZodFirstPartyTypeKind.ZodEffects,
219
- effect: {
220
- type: "transform",
221
- transform: m
222
- }
223
- });
224
- }
225
- default(m) {
226
- let U = typeof m == "function" ? m : () => m;
227
- return new ZodDefault({
228
- ...processCreateParams(this._def),
229
- innerType: this,
230
- defaultValue: U,
231
- typeName: ZodFirstPartyTypeKind.ZodDefault
232
- });
233
- }
234
- brand() {
235
- return new ZodBranded({
236
- typeName: ZodFirstPartyTypeKind.ZodBranded,
237
- type: this,
238
- ...processCreateParams(this._def)
239
- });
240
- }
241
- catch(m) {
242
- let U = typeof m == "function" ? m : () => m;
243
- return new ZodCatch({
244
- ...processCreateParams(this._def),
245
- innerType: this,
246
- catchValue: U,
247
- typeName: ZodFirstPartyTypeKind.ZodCatch
248
- });
249
- }
250
- describe(m) {
251
- let U = this.constructor;
252
- return new U({
253
- ...this._def,
254
- description: m
255
- });
256
- }
257
- pipe(m) {
258
- return ZodPipeline.create(this, m);
259
- }
260
- readonly() {
261
- return ZodReadonly.create(this);
262
- }
263
- isOptional() {
264
- return this.safeParse(void 0).success;
265
- }
266
- isNullable() {
267
- return this.safeParse(null).success;
268
- }
269
- }, cuidRegex = /^c[^\s-]{8,}$/i, cuid2Regex = /^[0-9a-z]+$/, ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i, uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i, nanoidRegex = /^[a-z0-9_-]{21}$/i, jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/, durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/, emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, _emojiRegex = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", emojiRegex, ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/, ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/, ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/, ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/, base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/, dateRegexSource = "((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))", dateRegex = /* @__PURE__ */ RegExp(`^${dateRegexSource}$`);
270
- function timeRegexSource(m) {
271
- let U = "[0-5]\\d";
272
- m.precision ? U = `${U}\\.\\d{${m.precision}}` : m.precision ?? (U = `${U}(\\.\\d+)?`);
273
- let W = m.precision ? "+" : "?";
274
- return `([01]\\d|2[0-3]):[0-5]\\d(:${U})${W}`;
275
- }
276
- function timeRegex(m) {
277
- return /* @__PURE__ */ RegExp(`^${timeRegexSource(m)}$`);
278
- }
279
- function datetimeRegex(m) {
280
- let U = `${dateRegexSource}T${timeRegexSource(m)}`, W = [];
281
- return W.push(m.local ? "Z?" : "Z"), m.offset && W.push("([+-]\\d{2}:?\\d{2})"), U = `${U}(${W.join("|")})`, /* @__PURE__ */ RegExp(`^${U}$`);
282
- }
283
- function isValidIP(m, U) {
284
- return !!((U === "v4" || !U) && ipv4Regex.test(m) || (U === "v6" || !U) && ipv6Regex.test(m));
285
- }
286
- function isValidJWT(m, U) {
287
- if (!jwtRegex.test(m)) return !1;
288
- try {
289
- let [W] = m.split(".");
290
- if (!W) return !1;
291
- let G = W.replace(/-/g, "+").replace(/_/g, "/").padEnd(W.length + (4 - W.length % 4) % 4, "="), K = JSON.parse(atob(G));
292
- return !(typeof K != "object" || !K || "typ" in K && K?.typ !== "JWT" || !K.alg || U && K.alg !== U);
293
- } catch {
294
- return !1;
295
- }
296
- }
297
- function isValidCidr(m, U) {
298
- return !!((U === "v4" || !U) && ipv4CidrRegex.test(m) || (U === "v6" || !U) && ipv6CidrRegex.test(m));
299
- }
300
- var ZodString = class U extends ZodType {
301
- _parse(U) {
302
- if (this._def.coerce && (U.data = String(U.data)), this._getType(U) !== ZodParsedType.string) {
303
- let W = this._getOrReturnCtx(U);
304
- return addIssueToContext(W, {
305
- code: ZodIssueCode.invalid_type,
306
- expected: ZodParsedType.string,
307
- received: W.parsedType
308
- }), INVALID;
309
- }
310
- let G = new ParseStatus(), q;
311
- for (let m of this._def.checks) if (m.kind === "min") U.data.length < m.value && (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
312
- code: ZodIssueCode.too_small,
313
- minimum: m.value,
314
- type: "string",
315
- inclusive: !0,
316
- exact: !1,
317
- message: m.message
318
- }), G.dirty());
319
- else if (m.kind === "max") U.data.length > m.value && (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
320
- code: ZodIssueCode.too_big,
321
- maximum: m.value,
322
- type: "string",
323
- inclusive: !0,
324
- exact: !1,
325
- message: m.message
326
- }), G.dirty());
327
- else if (m.kind === "length") {
328
- let W = U.data.length > m.value, J = U.data.length < m.value;
329
- (W || J) && (q = this._getOrReturnCtx(U, q), W ? addIssueToContext(q, {
330
- code: ZodIssueCode.too_big,
331
- maximum: m.value,
332
- type: "string",
333
- inclusive: !0,
334
- exact: !0,
335
- message: m.message
336
- }) : J && addIssueToContext(q, {
337
- code: ZodIssueCode.too_small,
338
- minimum: m.value,
339
- type: "string",
340
- inclusive: !0,
341
- exact: !0,
342
- message: m.message
343
- }), G.dirty());
344
- } else if (m.kind === "email") emailRegex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
345
- validation: "email",
346
- code: ZodIssueCode.invalid_string,
347
- message: m.message
348
- }), G.dirty());
349
- else if (m.kind === "emoji") emojiRegex ||= new RegExp(_emojiRegex, "u"), emojiRegex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
350
- validation: "emoji",
351
- code: ZodIssueCode.invalid_string,
352
- message: m.message
353
- }), G.dirty());
354
- else if (m.kind === "uuid") uuidRegex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
355
- validation: "uuid",
356
- code: ZodIssueCode.invalid_string,
357
- message: m.message
358
- }), G.dirty());
359
- else if (m.kind === "nanoid") nanoidRegex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
360
- validation: "nanoid",
361
- code: ZodIssueCode.invalid_string,
362
- message: m.message
363
- }), G.dirty());
364
- else if (m.kind === "cuid") cuidRegex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
365
- validation: "cuid",
366
- code: ZodIssueCode.invalid_string,
367
- message: m.message
368
- }), G.dirty());
369
- else if (m.kind === "cuid2") cuid2Regex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
370
- validation: "cuid2",
371
- code: ZodIssueCode.invalid_string,
372
- message: m.message
373
- }), G.dirty());
374
- else if (m.kind === "ulid") ulidRegex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
375
- validation: "ulid",
376
- code: ZodIssueCode.invalid_string,
377
- message: m.message
378
- }), G.dirty());
379
- else if (m.kind === "url") try {
380
- new URL(U.data);
381
- } catch {
382
- q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
383
- validation: "url",
384
- code: ZodIssueCode.invalid_string,
385
- message: m.message
386
- }), G.dirty();
387
- }
388
- else m.kind === "regex" ? (m.regex.lastIndex = 0, m.regex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
389
- validation: "regex",
390
- code: ZodIssueCode.invalid_string,
391
- message: m.message
392
- }), G.dirty())) : m.kind === "trim" ? U.data = U.data.trim() : m.kind === "includes" ? U.data.includes(m.value, m.position) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
393
- code: ZodIssueCode.invalid_string,
394
- validation: {
395
- includes: m.value,
396
- position: m.position
397
- },
398
- message: m.message
399
- }), G.dirty()) : m.kind === "toLowerCase" ? U.data = U.data.toLowerCase() : m.kind === "toUpperCase" ? U.data = U.data.toUpperCase() : m.kind === "startsWith" ? U.data.startsWith(m.value) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
400
- code: ZodIssueCode.invalid_string,
401
- validation: { startsWith: m.value },
402
- message: m.message
403
- }), G.dirty()) : m.kind === "endsWith" ? U.data.endsWith(m.value) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
404
- code: ZodIssueCode.invalid_string,
405
- validation: { endsWith: m.value },
406
- message: m.message
407
- }), G.dirty()) : m.kind === "datetime" ? datetimeRegex(m).test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
408
- code: ZodIssueCode.invalid_string,
409
- validation: "datetime",
410
- message: m.message
411
- }), G.dirty()) : m.kind === "date" ? dateRegex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
412
- code: ZodIssueCode.invalid_string,
413
- validation: "date",
414
- message: m.message
415
- }), G.dirty()) : m.kind === "time" ? timeRegex(m).test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
416
- code: ZodIssueCode.invalid_string,
417
- validation: "time",
418
- message: m.message
419
- }), G.dirty()) : m.kind === "duration" ? durationRegex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
420
- validation: "duration",
421
- code: ZodIssueCode.invalid_string,
422
- message: m.message
423
- }), G.dirty()) : m.kind === "ip" ? isValidIP(U.data, m.version) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
424
- validation: "ip",
425
- code: ZodIssueCode.invalid_string,
426
- message: m.message
427
- }), G.dirty()) : m.kind === "jwt" ? isValidJWT(U.data, m.alg) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
428
- validation: "jwt",
429
- code: ZodIssueCode.invalid_string,
430
- message: m.message
431
- }), G.dirty()) : m.kind === "cidr" ? isValidCidr(U.data, m.version) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
432
- validation: "cidr",
433
- code: ZodIssueCode.invalid_string,
434
- message: m.message
435
- }), G.dirty()) : m.kind === "base64" ? base64Regex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
436
- validation: "base64",
437
- code: ZodIssueCode.invalid_string,
438
- message: m.message
439
- }), G.dirty()) : m.kind === "base64url" ? base64urlRegex.test(U.data) || (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
440
- validation: "base64url",
441
- code: ZodIssueCode.invalid_string,
442
- message: m.message
443
- }), G.dirty()) : util.assertNever(m);
444
- return {
445
- status: G.value,
446
- value: U.data
447
- };
448
- }
449
- _regex(m, U, W) {
450
- return this.refinement((U) => m.test(U), {
451
- validation: U,
452
- code: ZodIssueCode.invalid_string,
453
- ...errorUtil.errToObj(W)
454
- });
455
- }
456
- _addCheck(m) {
457
- return new U({
458
- ...this._def,
459
- checks: [...this._def.checks, m]
460
- });
461
- }
462
- email(m) {
463
- return this._addCheck({
464
- kind: "email",
465
- ...errorUtil.errToObj(m)
466
- });
467
- }
468
- url(m) {
469
- return this._addCheck({
470
- kind: "url",
471
- ...errorUtil.errToObj(m)
472
- });
473
- }
474
- emoji(m) {
475
- return this._addCheck({
476
- kind: "emoji",
477
- ...errorUtil.errToObj(m)
478
- });
479
- }
480
- uuid(m) {
481
- return this._addCheck({
482
- kind: "uuid",
483
- ...errorUtil.errToObj(m)
484
- });
485
- }
486
- nanoid(m) {
487
- return this._addCheck({
488
- kind: "nanoid",
489
- ...errorUtil.errToObj(m)
490
- });
491
- }
492
- cuid(m) {
493
- return this._addCheck({
494
- kind: "cuid",
495
- ...errorUtil.errToObj(m)
496
- });
497
- }
498
- cuid2(m) {
499
- return this._addCheck({
500
- kind: "cuid2",
501
- ...errorUtil.errToObj(m)
502
- });
503
- }
504
- ulid(m) {
505
- return this._addCheck({
506
- kind: "ulid",
507
- ...errorUtil.errToObj(m)
508
- });
509
- }
510
- base64(m) {
511
- return this._addCheck({
512
- kind: "base64",
513
- ...errorUtil.errToObj(m)
514
- });
515
- }
516
- base64url(m) {
517
- return this._addCheck({
518
- kind: "base64url",
519
- ...errorUtil.errToObj(m)
520
- });
521
- }
522
- jwt(m) {
523
- return this._addCheck({
524
- kind: "jwt",
525
- ...errorUtil.errToObj(m)
526
- });
527
- }
528
- ip(m) {
529
- return this._addCheck({
530
- kind: "ip",
531
- ...errorUtil.errToObj(m)
532
- });
533
- }
534
- cidr(m) {
535
- return this._addCheck({
536
- kind: "cidr",
537
- ...errorUtil.errToObj(m)
538
- });
539
- }
540
- datetime(m) {
541
- return typeof m == "string" ? this._addCheck({
542
- kind: "datetime",
543
- precision: null,
544
- offset: !1,
545
- local: !1,
546
- message: m
547
- }) : this._addCheck({
548
- kind: "datetime",
549
- precision: m?.precision === void 0 ? null : m?.precision,
550
- offset: m?.offset ?? !1,
551
- local: m?.local ?? !1,
552
- ...errorUtil.errToObj(m?.message)
553
- });
554
- }
555
- date(m) {
556
- return this._addCheck({
557
- kind: "date",
558
- message: m
559
- });
560
- }
561
- time(m) {
562
- return typeof m == "string" ? this._addCheck({
563
- kind: "time",
564
- precision: null,
565
- message: m
566
- }) : this._addCheck({
567
- kind: "time",
568
- precision: m?.precision === void 0 ? null : m?.precision,
569
- ...errorUtil.errToObj(m?.message)
570
- });
571
- }
572
- duration(m) {
573
- return this._addCheck({
574
- kind: "duration",
575
- ...errorUtil.errToObj(m)
576
- });
577
- }
578
- regex(m, U) {
579
- return this._addCheck({
580
- kind: "regex",
581
- regex: m,
582
- ...errorUtil.errToObj(U)
583
- });
584
- }
585
- includes(m, U) {
586
- return this._addCheck({
587
- kind: "includes",
588
- value: m,
589
- position: U?.position,
590
- ...errorUtil.errToObj(U?.message)
591
- });
592
- }
593
- startsWith(m, U) {
594
- return this._addCheck({
595
- kind: "startsWith",
596
- value: m,
597
- ...errorUtil.errToObj(U)
598
- });
599
- }
600
- endsWith(m, U) {
601
- return this._addCheck({
602
- kind: "endsWith",
603
- value: m,
604
- ...errorUtil.errToObj(U)
605
- });
606
- }
607
- min(m, U) {
608
- return this._addCheck({
609
- kind: "min",
610
- value: m,
611
- ...errorUtil.errToObj(U)
612
- });
613
- }
614
- max(m, U) {
615
- return this._addCheck({
616
- kind: "max",
617
- value: m,
618
- ...errorUtil.errToObj(U)
619
- });
620
- }
621
- length(m, U) {
622
- return this._addCheck({
623
- kind: "length",
624
- value: m,
625
- ...errorUtil.errToObj(U)
626
- });
627
- }
628
- nonempty(m) {
629
- return this.min(1, errorUtil.errToObj(m));
630
- }
631
- trim() {
632
- return new U({
633
- ...this._def,
634
- checks: [...this._def.checks, { kind: "trim" }]
635
- });
636
- }
637
- toLowerCase() {
638
- return new U({
639
- ...this._def,
640
- checks: [...this._def.checks, { kind: "toLowerCase" }]
641
- });
642
- }
643
- toUpperCase() {
644
- return new U({
645
- ...this._def,
646
- checks: [...this._def.checks, { kind: "toUpperCase" }]
647
- });
648
- }
649
- get isDatetime() {
650
- return !!this._def.checks.find((m) => m.kind === "datetime");
651
- }
652
- get isDate() {
653
- return !!this._def.checks.find((m) => m.kind === "date");
654
- }
655
- get isTime() {
656
- return !!this._def.checks.find((m) => m.kind === "time");
657
- }
658
- get isDuration() {
659
- return !!this._def.checks.find((m) => m.kind === "duration");
660
- }
661
- get isEmail() {
662
- return !!this._def.checks.find((m) => m.kind === "email");
663
- }
664
- get isURL() {
665
- return !!this._def.checks.find((m) => m.kind === "url");
666
- }
667
- get isEmoji() {
668
- return !!this._def.checks.find((m) => m.kind === "emoji");
669
- }
670
- get isUUID() {
671
- return !!this._def.checks.find((m) => m.kind === "uuid");
672
- }
673
- get isNANOID() {
674
- return !!this._def.checks.find((m) => m.kind === "nanoid");
675
- }
676
- get isCUID() {
677
- return !!this._def.checks.find((m) => m.kind === "cuid");
678
- }
679
- get isCUID2() {
680
- return !!this._def.checks.find((m) => m.kind === "cuid2");
681
- }
682
- get isULID() {
683
- return !!this._def.checks.find((m) => m.kind === "ulid");
684
- }
685
- get isIP() {
686
- return !!this._def.checks.find((m) => m.kind === "ip");
687
- }
688
- get isCIDR() {
689
- return !!this._def.checks.find((m) => m.kind === "cidr");
690
- }
691
- get isBase64() {
692
- return !!this._def.checks.find((m) => m.kind === "base64");
693
- }
694
- get isBase64url() {
695
- return !!this._def.checks.find((m) => m.kind === "base64url");
696
- }
697
- get minLength() {
698
- let m = null;
699
- for (let U of this._def.checks) U.kind === "min" && (m === null || U.value > m) && (m = U.value);
700
- return m;
701
- }
702
- get maxLength() {
703
- let m = null;
704
- for (let U of this._def.checks) U.kind === "max" && (m === null || U.value < m) && (m = U.value);
705
- return m;
706
- }
707
- };
708
- ZodString.create = (m) => new ZodString({
709
- checks: [],
710
- typeName: ZodFirstPartyTypeKind.ZodString,
711
- coerce: m?.coerce ?? !1,
712
- ...processCreateParams(m)
713
- });
714
- function floatSafeRemainder(m, U) {
715
- let W = (m.toString().split(".")[1] || "").length, G = (U.toString().split(".")[1] || "").length, K = W > G ? W : G;
716
- return Number.parseInt(m.toFixed(K).replace(".", "")) % Number.parseInt(U.toFixed(K).replace(".", "")) / 10 ** K;
717
- }
718
- var ZodNumber = class U extends ZodType {
719
- constructor() {
720
- super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
721
- }
722
- _parse(U) {
723
- if (this._def.coerce && (U.data = Number(U.data)), this._getType(U) !== ZodParsedType.number) {
724
- let W = this._getOrReturnCtx(U);
725
- return addIssueToContext(W, {
726
- code: ZodIssueCode.invalid_type,
727
- expected: ZodParsedType.number,
728
- received: W.parsedType
729
- }), INVALID;
730
- }
731
- let G, q = new ParseStatus();
732
- for (let m of this._def.checks) m.kind === "int" ? util.isInteger(U.data) || (G = this._getOrReturnCtx(U, G), addIssueToContext(G, {
733
- code: ZodIssueCode.invalid_type,
734
- expected: "integer",
735
- received: "float",
736
- message: m.message
737
- }), q.dirty()) : m.kind === "min" ? (m.inclusive ? U.data < m.value : U.data <= m.value) && (G = this._getOrReturnCtx(U, G), addIssueToContext(G, {
738
- code: ZodIssueCode.too_small,
739
- minimum: m.value,
740
- type: "number",
741
- inclusive: m.inclusive,
742
- exact: !1,
743
- message: m.message
744
- }), q.dirty()) : m.kind === "max" ? (m.inclusive ? U.data > m.value : U.data >= m.value) && (G = this._getOrReturnCtx(U, G), addIssueToContext(G, {
745
- code: ZodIssueCode.too_big,
746
- maximum: m.value,
747
- type: "number",
748
- inclusive: m.inclusive,
749
- exact: !1,
750
- message: m.message
751
- }), q.dirty()) : m.kind === "multipleOf" ? floatSafeRemainder(U.data, m.value) !== 0 && (G = this._getOrReturnCtx(U, G), addIssueToContext(G, {
752
- code: ZodIssueCode.not_multiple_of,
753
- multipleOf: m.value,
754
- message: m.message
755
- }), q.dirty()) : m.kind === "finite" ? Number.isFinite(U.data) || (G = this._getOrReturnCtx(U, G), addIssueToContext(G, {
756
- code: ZodIssueCode.not_finite,
757
- message: m.message
758
- }), q.dirty()) : util.assertNever(m);
759
- return {
760
- status: q.value,
761
- value: U.data
762
- };
763
- }
764
- gte(m, U) {
765
- return this.setLimit("min", m, !0, errorUtil.toString(U));
766
- }
767
- gt(m, U) {
768
- return this.setLimit("min", m, !1, errorUtil.toString(U));
769
- }
770
- lte(m, U) {
771
- return this.setLimit("max", m, !0, errorUtil.toString(U));
772
- }
773
- lt(m, U) {
774
- return this.setLimit("max", m, !1, errorUtil.toString(U));
775
- }
776
- setLimit(m, W, G, K) {
777
- return new U({
778
- ...this._def,
779
- checks: [...this._def.checks, {
780
- kind: m,
781
- value: W,
782
- inclusive: G,
783
- message: errorUtil.toString(K)
784
- }]
785
- });
786
- }
787
- _addCheck(m) {
788
- return new U({
789
- ...this._def,
790
- checks: [...this._def.checks, m]
791
- });
792
- }
793
- int(m) {
794
- return this._addCheck({
795
- kind: "int",
796
- message: errorUtil.toString(m)
797
- });
798
- }
799
- positive(m) {
800
- return this._addCheck({
801
- kind: "min",
802
- value: 0,
803
- inclusive: !1,
804
- message: errorUtil.toString(m)
805
- });
806
- }
807
- negative(m) {
808
- return this._addCheck({
809
- kind: "max",
810
- value: 0,
811
- inclusive: !1,
812
- message: errorUtil.toString(m)
813
- });
814
- }
815
- nonpositive(m) {
816
- return this._addCheck({
817
- kind: "max",
818
- value: 0,
819
- inclusive: !0,
820
- message: errorUtil.toString(m)
821
- });
822
- }
823
- nonnegative(m) {
824
- return this._addCheck({
825
- kind: "min",
826
- value: 0,
827
- inclusive: !0,
828
- message: errorUtil.toString(m)
829
- });
830
- }
831
- multipleOf(m, U) {
832
- return this._addCheck({
833
- kind: "multipleOf",
834
- value: m,
835
- message: errorUtil.toString(U)
836
- });
837
- }
838
- finite(m) {
839
- return this._addCheck({
840
- kind: "finite",
841
- message: errorUtil.toString(m)
842
- });
843
- }
844
- safe(m) {
845
- return this._addCheck({
846
- kind: "min",
847
- inclusive: !0,
848
- value: -(2 ** 53 - 1),
849
- message: errorUtil.toString(m)
850
- })._addCheck({
851
- kind: "max",
852
- inclusive: !0,
853
- value: 2 ** 53 - 1,
854
- message: errorUtil.toString(m)
855
- });
856
- }
857
- get minValue() {
858
- let m = null;
859
- for (let U of this._def.checks) U.kind === "min" && (m === null || U.value > m) && (m = U.value);
860
- return m;
861
- }
862
- get maxValue() {
863
- let m = null;
864
- for (let U of this._def.checks) U.kind === "max" && (m === null || U.value < m) && (m = U.value);
865
- return m;
866
- }
867
- get isInt() {
868
- return !!this._def.checks.find((m) => m.kind === "int" || m.kind === "multipleOf" && util.isInteger(m.value));
869
- }
870
- get isFinite() {
871
- let m = null, U = null;
872
- for (let W of this._def.checks) if (W.kind === "finite" || W.kind === "int" || W.kind === "multipleOf") return !0;
873
- else W.kind === "min" ? (U === null || W.value > U) && (U = W.value) : W.kind === "max" && (m === null || W.value < m) && (m = W.value);
874
- return Number.isFinite(U) && Number.isFinite(m);
875
- }
876
- };
877
- ZodNumber.create = (m) => new ZodNumber({
878
- checks: [],
879
- typeName: ZodFirstPartyTypeKind.ZodNumber,
880
- coerce: m?.coerce || !1,
881
- ...processCreateParams(m)
882
- });
883
- var ZodBigInt = class U extends ZodType {
884
- constructor() {
885
- super(...arguments), this.min = this.gte, this.max = this.lte;
886
- }
887
- _parse(U) {
888
- if (this._def.coerce) try {
889
- U.data = BigInt(U.data);
890
- } catch {
891
- return this._getInvalidInput(U);
892
- }
893
- if (this._getType(U) !== ZodParsedType.bigint) return this._getInvalidInput(U);
894
- let G, q = new ParseStatus();
895
- for (let m of this._def.checks) m.kind === "min" ? (m.inclusive ? U.data < m.value : U.data <= m.value) && (G = this._getOrReturnCtx(U, G), addIssueToContext(G, {
896
- code: ZodIssueCode.too_small,
897
- type: "bigint",
898
- minimum: m.value,
899
- inclusive: m.inclusive,
900
- message: m.message
901
- }), q.dirty()) : m.kind === "max" ? (m.inclusive ? U.data > m.value : U.data >= m.value) && (G = this._getOrReturnCtx(U, G), addIssueToContext(G, {
902
- code: ZodIssueCode.too_big,
903
- type: "bigint",
904
- maximum: m.value,
905
- inclusive: m.inclusive,
906
- message: m.message
907
- }), q.dirty()) : m.kind === "multipleOf" ? U.data % m.value !== BigInt(0) && (G = this._getOrReturnCtx(U, G), addIssueToContext(G, {
908
- code: ZodIssueCode.not_multiple_of,
909
- multipleOf: m.value,
910
- message: m.message
911
- }), q.dirty()) : util.assertNever(m);
912
- return {
913
- status: q.value,
914
- value: U.data
915
- };
916
- }
917
- _getInvalidInput(U) {
918
- let W = this._getOrReturnCtx(U);
919
- return addIssueToContext(W, {
920
- code: ZodIssueCode.invalid_type,
921
- expected: ZodParsedType.bigint,
922
- received: W.parsedType
923
- }), INVALID;
924
- }
925
- gte(m, U) {
926
- return this.setLimit("min", m, !0, errorUtil.toString(U));
927
- }
928
- gt(m, U) {
929
- return this.setLimit("min", m, !1, errorUtil.toString(U));
930
- }
931
- lte(m, U) {
932
- return this.setLimit("max", m, !0, errorUtil.toString(U));
933
- }
934
- lt(m, U) {
935
- return this.setLimit("max", m, !1, errorUtil.toString(U));
936
- }
937
- setLimit(m, W, G, K) {
938
- return new U({
939
- ...this._def,
940
- checks: [...this._def.checks, {
941
- kind: m,
942
- value: W,
943
- inclusive: G,
944
- message: errorUtil.toString(K)
945
- }]
946
- });
947
- }
948
- _addCheck(m) {
949
- return new U({
950
- ...this._def,
951
- checks: [...this._def.checks, m]
952
- });
953
- }
954
- positive(m) {
955
- return this._addCheck({
956
- kind: "min",
957
- value: BigInt(0),
958
- inclusive: !1,
959
- message: errorUtil.toString(m)
960
- });
961
- }
962
- negative(m) {
963
- return this._addCheck({
964
- kind: "max",
965
- value: BigInt(0),
966
- inclusive: !1,
967
- message: errorUtil.toString(m)
968
- });
969
- }
970
- nonpositive(m) {
971
- return this._addCheck({
972
- kind: "max",
973
- value: BigInt(0),
974
- inclusive: !0,
975
- message: errorUtil.toString(m)
976
- });
977
- }
978
- nonnegative(m) {
979
- return this._addCheck({
980
- kind: "min",
981
- value: BigInt(0),
982
- inclusive: !0,
983
- message: errorUtil.toString(m)
984
- });
985
- }
986
- multipleOf(m, U) {
987
- return this._addCheck({
988
- kind: "multipleOf",
989
- value: m,
990
- message: errorUtil.toString(U)
991
- });
992
- }
993
- get minValue() {
994
- let m = null;
995
- for (let U of this._def.checks) U.kind === "min" && (m === null || U.value > m) && (m = U.value);
996
- return m;
997
- }
998
- get maxValue() {
999
- let m = null;
1000
- for (let U of this._def.checks) U.kind === "max" && (m === null || U.value < m) && (m = U.value);
1001
- return m;
1002
- }
1003
- };
1004
- ZodBigInt.create = (m) => new ZodBigInt({
1005
- checks: [],
1006
- typeName: ZodFirstPartyTypeKind.ZodBigInt,
1007
- coerce: m?.coerce ?? !1,
1008
- ...processCreateParams(m)
1009
- });
1010
- var ZodBoolean = class extends ZodType {
1011
- _parse(U) {
1012
- if (this._def.coerce && (U.data = !!U.data), this._getType(U) !== ZodParsedType.boolean) {
1013
- let W = this._getOrReturnCtx(U);
1014
- return addIssueToContext(W, {
1015
- code: ZodIssueCode.invalid_type,
1016
- expected: ZodParsedType.boolean,
1017
- received: W.parsedType
1018
- }), INVALID;
1019
- }
1020
- return OK(U.data);
1021
- }
1022
- };
1023
- ZodBoolean.create = (m) => new ZodBoolean({
1024
- typeName: ZodFirstPartyTypeKind.ZodBoolean,
1025
- coerce: m?.coerce || !1,
1026
- ...processCreateParams(m)
1027
- });
1028
- var ZodDate = class U extends ZodType {
1029
- _parse(U) {
1030
- if (this._def.coerce && (U.data = new Date(U.data)), this._getType(U) !== ZodParsedType.date) {
1031
- let W = this._getOrReturnCtx(U);
1032
- return addIssueToContext(W, {
1033
- code: ZodIssueCode.invalid_type,
1034
- expected: ZodParsedType.date,
1035
- received: W.parsedType
1036
- }), INVALID;
1037
- }
1038
- if (Number.isNaN(U.data.getTime())) return addIssueToContext(this._getOrReturnCtx(U), { code: ZodIssueCode.invalid_date }), INVALID;
1039
- let G = new ParseStatus(), q;
1040
- for (let m of this._def.checks) m.kind === "min" ? U.data.getTime() < m.value && (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
1041
- code: ZodIssueCode.too_small,
1042
- message: m.message,
1043
- inclusive: !0,
1044
- exact: !1,
1045
- minimum: m.value,
1046
- type: "date"
1047
- }), G.dirty()) : m.kind === "max" ? U.data.getTime() > m.value && (q = this._getOrReturnCtx(U, q), addIssueToContext(q, {
1048
- code: ZodIssueCode.too_big,
1049
- message: m.message,
1050
- inclusive: !0,
1051
- exact: !1,
1052
- maximum: m.value,
1053
- type: "date"
1054
- }), G.dirty()) : util.assertNever(m);
1055
- return {
1056
- status: G.value,
1057
- value: new Date(U.data.getTime())
1058
- };
1059
- }
1060
- _addCheck(m) {
1061
- return new U({
1062
- ...this._def,
1063
- checks: [...this._def.checks, m]
1064
- });
1065
- }
1066
- min(m, U) {
1067
- return this._addCheck({
1068
- kind: "min",
1069
- value: m.getTime(),
1070
- message: errorUtil.toString(U)
1071
- });
1072
- }
1073
- max(m, U) {
1074
- return this._addCheck({
1075
- kind: "max",
1076
- value: m.getTime(),
1077
- message: errorUtil.toString(U)
1078
- });
1079
- }
1080
- get minDate() {
1081
- let m = null;
1082
- for (let U of this._def.checks) U.kind === "min" && (m === null || U.value > m) && (m = U.value);
1083
- return m == null ? null : new Date(m);
1084
- }
1085
- get maxDate() {
1086
- let m = null;
1087
- for (let U of this._def.checks) U.kind === "max" && (m === null || U.value < m) && (m = U.value);
1088
- return m == null ? null : new Date(m);
1089
- }
1090
- };
1091
- ZodDate.create = (m) => new ZodDate({
1092
- checks: [],
1093
- coerce: m?.coerce || !1,
1094
- typeName: ZodFirstPartyTypeKind.ZodDate,
1095
- ...processCreateParams(m)
1096
- });
1097
- var ZodSymbol = class extends ZodType {
1098
- _parse(U) {
1099
- if (this._getType(U) !== ZodParsedType.symbol) {
1100
- let W = this._getOrReturnCtx(U);
1101
- return addIssueToContext(W, {
1102
- code: ZodIssueCode.invalid_type,
1103
- expected: ZodParsedType.symbol,
1104
- received: W.parsedType
1105
- }), INVALID;
1106
- }
1107
- return OK(U.data);
1108
- }
1109
- };
1110
- ZodSymbol.create = (m) => new ZodSymbol({
1111
- typeName: ZodFirstPartyTypeKind.ZodSymbol,
1112
- ...processCreateParams(m)
1113
- });
1114
- var ZodUndefined = class extends ZodType {
1115
- _parse(U) {
1116
- if (this._getType(U) !== ZodParsedType.undefined) {
1117
- let W = this._getOrReturnCtx(U);
1118
- return addIssueToContext(W, {
1119
- code: ZodIssueCode.invalid_type,
1120
- expected: ZodParsedType.undefined,
1121
- received: W.parsedType
1122
- }), INVALID;
1123
- }
1124
- return OK(U.data);
1125
- }
1126
- };
1127
- ZodUndefined.create = (m) => new ZodUndefined({
1128
- typeName: ZodFirstPartyTypeKind.ZodUndefined,
1129
- ...processCreateParams(m)
1130
- });
1131
- var ZodNull = class extends ZodType {
1132
- _parse(U) {
1133
- if (this._getType(U) !== ZodParsedType.null) {
1134
- let W = this._getOrReturnCtx(U);
1135
- return addIssueToContext(W, {
1136
- code: ZodIssueCode.invalid_type,
1137
- expected: ZodParsedType.null,
1138
- received: W.parsedType
1139
- }), INVALID;
1140
- }
1141
- return OK(U.data);
1142
- }
1143
- };
1144
- ZodNull.create = (m) => new ZodNull({
1145
- typeName: ZodFirstPartyTypeKind.ZodNull,
1146
- ...processCreateParams(m)
1147
- });
1148
- var ZodAny = class extends ZodType {
1149
- constructor() {
1150
- super(...arguments), this._any = !0;
1151
- }
1152
- _parse(m) {
1153
- return OK(m.data);
1154
- }
1155
- };
1156
- ZodAny.create = (m) => new ZodAny({
1157
- typeName: ZodFirstPartyTypeKind.ZodAny,
1158
- ...processCreateParams(m)
1159
- });
1160
- var ZodUnknown = class extends ZodType {
1161
- constructor() {
1162
- super(...arguments), this._unknown = !0;
1163
- }
1164
- _parse(m) {
1165
- return OK(m.data);
1166
- }
1167
- };
1168
- ZodUnknown.create = (m) => new ZodUnknown({
1169
- typeName: ZodFirstPartyTypeKind.ZodUnknown,
1170
- ...processCreateParams(m)
1171
- });
1172
- var ZodNever = class extends ZodType {
1173
- _parse(U) {
1174
- let W = this._getOrReturnCtx(U);
1175
- return addIssueToContext(W, {
1176
- code: ZodIssueCode.invalid_type,
1177
- expected: ZodParsedType.never,
1178
- received: W.parsedType
1179
- }), INVALID;
1180
- }
1181
- };
1182
- ZodNever.create = (m) => new ZodNever({
1183
- typeName: ZodFirstPartyTypeKind.ZodNever,
1184
- ...processCreateParams(m)
1185
- });
1186
- var ZodVoid = class extends ZodType {
1187
- _parse(U) {
1188
- if (this._getType(U) !== ZodParsedType.undefined) {
1189
- let W = this._getOrReturnCtx(U);
1190
- return addIssueToContext(W, {
1191
- code: ZodIssueCode.invalid_type,
1192
- expected: ZodParsedType.void,
1193
- received: W.parsedType
1194
- }), INVALID;
1195
- }
1196
- return OK(U.data);
1197
- }
1198
- };
1199
- ZodVoid.create = (m) => new ZodVoid({
1200
- typeName: ZodFirstPartyTypeKind.ZodVoid,
1201
- ...processCreateParams(m)
1202
- });
1203
- var ZodArray = class U extends ZodType {
1204
- _parse(U) {
1205
- let { ctx: W, status: G } = this._processInputParams(U), q = this._def;
1206
- if (W.parsedType !== ZodParsedType.array) return addIssueToContext(W, {
1207
- code: ZodIssueCode.invalid_type,
1208
- expected: ZodParsedType.array,
1209
- received: W.parsedType
1210
- }), INVALID;
1211
- if (q.exactLength !== null) {
1212
- let m = W.data.length > q.exactLength.value, U = W.data.length < q.exactLength.value;
1213
- (m || U) && (addIssueToContext(W, {
1214
- code: m ? ZodIssueCode.too_big : ZodIssueCode.too_small,
1215
- minimum: U ? q.exactLength.value : void 0,
1216
- maximum: m ? q.exactLength.value : void 0,
1217
- type: "array",
1218
- inclusive: !0,
1219
- exact: !0,
1220
- message: q.exactLength.message
1221
- }), G.dirty());
1222
- }
1223
- if (q.minLength !== null && W.data.length < q.minLength.value && (addIssueToContext(W, {
1224
- code: ZodIssueCode.too_small,
1225
- minimum: q.minLength.value,
1226
- type: "array",
1227
- inclusive: !0,
1228
- exact: !1,
1229
- message: q.minLength.message
1230
- }), G.dirty()), q.maxLength !== null && W.data.length > q.maxLength.value && (addIssueToContext(W, {
1231
- code: ZodIssueCode.too_big,
1232
- maximum: q.maxLength.value,
1233
- type: "array",
1234
- inclusive: !0,
1235
- exact: !1,
1236
- message: q.maxLength.message
1237
- }), G.dirty()), W.common.async) return Promise.all([...W.data].map((m, U) => q.type._parseAsync(new ParseInputLazyPath(W, m, W.path, U)))).then((m) => ParseStatus.mergeArray(G, m));
1238
- let J = [...W.data].map((m, U) => q.type._parseSync(new ParseInputLazyPath(W, m, W.path, U)));
1239
- return ParseStatus.mergeArray(G, J);
1240
- }
1241
- get element() {
1242
- return this._def.type;
1243
- }
1244
- min(m, W) {
1245
- return new U({
1246
- ...this._def,
1247
- minLength: {
1248
- value: m,
1249
- message: errorUtil.toString(W)
1250
- }
1251
- });
1252
- }
1253
- max(m, W) {
1254
- return new U({
1255
- ...this._def,
1256
- maxLength: {
1257
- value: m,
1258
- message: errorUtil.toString(W)
1259
- }
1260
- });
1261
- }
1262
- length(m, W) {
1263
- return new U({
1264
- ...this._def,
1265
- exactLength: {
1266
- value: m,
1267
- message: errorUtil.toString(W)
1268
- }
1269
- });
1270
- }
1271
- nonempty(m) {
1272
- return this.min(1, m);
1273
- }
1274
- };
1275
- ZodArray.create = (m, U) => new ZodArray({
1276
- type: m,
1277
- minLength: null,
1278
- maxLength: null,
1279
- exactLength: null,
1280
- typeName: ZodFirstPartyTypeKind.ZodArray,
1281
- ...processCreateParams(U)
1282
- });
1283
- function deepPartialify(m) {
1284
- if (m instanceof ZodObject) {
1285
- let U = {};
1286
- for (let W in m.shape) {
1287
- let G = m.shape[W];
1288
- U[W] = ZodOptional.create(deepPartialify(G));
1289
- }
1290
- return new ZodObject({
1291
- ...m._def,
1292
- shape: () => U
1293
- });
1294
- } else if (m instanceof ZodArray) return new ZodArray({
1295
- ...m._def,
1296
- type: deepPartialify(m.element)
1297
- });
1298
- else if (m instanceof ZodOptional) return ZodOptional.create(deepPartialify(m.unwrap()));
1299
- else if (m instanceof ZodNullable) return ZodNullable.create(deepPartialify(m.unwrap()));
1300
- else if (m instanceof ZodTuple) return ZodTuple.create(m.items.map((m) => deepPartialify(m)));
1301
- else return m;
1302
- }
1303
- var ZodObject = class U extends ZodType {
1304
- constructor() {
1305
- super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
1306
- }
1307
- _getCached() {
1308
- if (this._cached !== null) return this._cached;
1309
- let m = this._def.shape();
1310
- return this._cached = {
1311
- shape: m,
1312
- keys: util.objectKeys(m)
1313
- }, this._cached;
1314
- }
1315
- _parse(U) {
1316
- if (this._getType(U) !== ZodParsedType.object) {
1317
- let W = this._getOrReturnCtx(U);
1318
- return addIssueToContext(W, {
1319
- code: ZodIssueCode.invalid_type,
1320
- expected: ZodParsedType.object,
1321
- received: W.parsedType
1322
- }), INVALID;
1323
- }
1324
- let { status: W, ctx: G } = this._processInputParams(U), { shape: q, keys: J } = this._getCached(), Y = [];
1325
- if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) for (let m in G.data) J.includes(m) || Y.push(m);
1326
- let X = [];
1327
- for (let m of J) {
1328
- let U = q[m], W = G.data[m];
1329
- X.push({
1330
- key: {
1331
- status: "valid",
1332
- value: m
1333
- },
1334
- value: U._parse(new ParseInputLazyPath(G, W, G.path, m)),
1335
- alwaysSet: m in G.data
1336
- });
1337
- }
1338
- if (this._def.catchall instanceof ZodNever) {
1339
- let m = this._def.unknownKeys;
1340
- if (m === "passthrough") for (let m of Y) X.push({
1341
- key: {
1342
- status: "valid",
1343
- value: m
1344
- },
1345
- value: {
1346
- status: "valid",
1347
- value: G.data[m]
1348
- }
1349
- });
1350
- else if (m === "strict") Y.length > 0 && (addIssueToContext(G, {
1351
- code: ZodIssueCode.unrecognized_keys,
1352
- keys: Y
1353
- }), W.dirty());
1354
- else if (m !== "strip") throw Error("Internal ZodObject error: invalid unknownKeys value.");
1355
- } else {
1356
- let m = this._def.catchall;
1357
- for (let U of Y) {
1358
- let W = G.data[U];
1359
- X.push({
1360
- key: {
1361
- status: "valid",
1362
- value: U
1363
- },
1364
- value: m._parse(new ParseInputLazyPath(G, W, G.path, U)),
1365
- alwaysSet: U in G.data
1366
- });
1367
- }
1368
- }
1369
- return G.common.async ? Promise.resolve().then(async () => {
1370
- let m = [];
1371
- for (let U of X) {
1372
- let W = await U.key, G = await U.value;
1373
- m.push({
1374
- key: W,
1375
- value: G,
1376
- alwaysSet: U.alwaysSet
1377
- });
1378
- }
1379
- return m;
1380
- }).then((m) => ParseStatus.mergeObjectSync(W, m)) : ParseStatus.mergeObjectSync(W, X);
1381
- }
1382
- get shape() {
1383
- return this._def.shape();
1384
- }
1385
- strict(m) {
1386
- return errorUtil.errToObj, new U({
1387
- ...this._def,
1388
- unknownKeys: "strict",
1389
- ...m === void 0 ? {} : { errorMap: (U, W) => {
1390
- let G = this._def.errorMap?.(U, W).message ?? W.defaultError;
1391
- return U.code === "unrecognized_keys" ? { message: errorUtil.errToObj(m).message ?? G } : { message: G };
1392
- } }
1393
- });
1394
- }
1395
- strip() {
1396
- return new U({
1397
- ...this._def,
1398
- unknownKeys: "strip"
1399
- });
1400
- }
1401
- passthrough() {
1402
- return new U({
1403
- ...this._def,
1404
- unknownKeys: "passthrough"
1405
- });
1406
- }
1407
- extend(m) {
1408
- return new U({
1409
- ...this._def,
1410
- shape: () => ({
1411
- ...this._def.shape(),
1412
- ...m
1413
- })
1414
- });
1415
- }
1416
- merge(m) {
1417
- return new U({
1418
- unknownKeys: m._def.unknownKeys,
1419
- catchall: m._def.catchall,
1420
- shape: () => ({
1421
- ...this._def.shape(),
1422
- ...m._def.shape()
1423
- }),
1424
- typeName: ZodFirstPartyTypeKind.ZodObject
1425
- });
1426
- }
1427
- setKey(m, U) {
1428
- return this.augment({ [m]: U });
1429
- }
1430
- catchall(m) {
1431
- return new U({
1432
- ...this._def,
1433
- catchall: m
1434
- });
1435
- }
1436
- pick(m) {
1437
- let G = {};
1438
- for (let U of util.objectKeys(m)) m[U] && this.shape[U] && (G[U] = this.shape[U]);
1439
- return new U({
1440
- ...this._def,
1441
- shape: () => G
1442
- });
1443
- }
1444
- omit(m) {
1445
- let G = {};
1446
- for (let U of util.objectKeys(this.shape)) m[U] || (G[U] = this.shape[U]);
1447
- return new U({
1448
- ...this._def,
1449
- shape: () => G
1450
- });
1451
- }
1452
- deepPartial() {
1453
- return deepPartialify(this);
1454
- }
1455
- partial(m) {
1456
- let G = {};
1457
- for (let U of util.objectKeys(this.shape)) {
1458
- let W = this.shape[U];
1459
- m && !m[U] ? G[U] = W : G[U] = W.optional();
1460
- }
1461
- return new U({
1462
- ...this._def,
1463
- shape: () => G
1464
- });
1465
- }
1466
- required(m) {
1467
- let G = {};
1468
- for (let U of util.objectKeys(this.shape)) if (m && !m[U]) G[U] = this.shape[U];
1469
- else {
1470
- let m = this.shape[U];
1471
- for (; m instanceof ZodOptional;) m = m._def.innerType;
1472
- G[U] = m;
1473
- }
1474
- return new U({
1475
- ...this._def,
1476
- shape: () => G
1477
- });
1478
- }
1479
- keyof() {
1480
- return createZodEnum(util.objectKeys(this.shape));
1481
- }
1482
- };
1483
- ZodObject.create = (m, U) => new ZodObject({
1484
- shape: () => m,
1485
- unknownKeys: "strip",
1486
- catchall: ZodNever.create(),
1487
- typeName: ZodFirstPartyTypeKind.ZodObject,
1488
- ...processCreateParams(U)
1489
- }), ZodObject.strictCreate = (m, U) => new ZodObject({
1490
- shape: () => m,
1491
- unknownKeys: "strict",
1492
- catchall: ZodNever.create(),
1493
- typeName: ZodFirstPartyTypeKind.ZodObject,
1494
- ...processCreateParams(U)
1495
- }), ZodObject.lazycreate = (m, U) => new ZodObject({
1496
- shape: m,
1497
- unknownKeys: "strip",
1498
- catchall: ZodNever.create(),
1499
- typeName: ZodFirstPartyTypeKind.ZodObject,
1500
- ...processCreateParams(U)
1501
- });
1502
- var ZodUnion = class extends ZodType {
1503
- _parse(m) {
1504
- let { ctx: U } = this._processInputParams(m), W = this._def.options;
1505
- function q(m) {
1506
- for (let U of m) if (U.result.status === "valid") return U.result;
1507
- for (let W of m) if (W.result.status === "dirty") return U.common.issues.push(...W.ctx.common.issues), W.result;
1508
- let W = m.map((m) => new ZodError(m.ctx.common.issues));
1509
- return addIssueToContext(U, {
1510
- code: ZodIssueCode.invalid_union,
1511
- unionErrors: W
1512
- }), INVALID;
1513
- }
1514
- if (U.common.async) return Promise.all(W.map(async (m) => {
1515
- let W = {
1516
- ...U,
1517
- common: {
1518
- ...U.common,
1519
- issues: []
1520
- },
1521
- parent: null
1522
- };
1523
- return {
1524
- result: await m._parseAsync({
1525
- data: U.data,
1526
- path: U.path,
1527
- parent: W
1528
- }),
1529
- ctx: W
1530
- };
1531
- })).then(q);
1532
- {
1533
- let m, q = [];
1534
- for (let G of W) {
1535
- let W = {
1536
- ...U,
1537
- common: {
1538
- ...U.common,
1539
- issues: []
1540
- },
1541
- parent: null
1542
- }, K = G._parseSync({
1543
- data: U.data,
1544
- path: U.path,
1545
- parent: W
1546
- });
1547
- if (K.status === "valid") return K;
1548
- K.status === "dirty" && !m && (m = {
1549
- result: K,
1550
- ctx: W
1551
- }), W.common.issues.length && q.push(W.common.issues);
1552
- }
1553
- if (m) return U.common.issues.push(...m.ctx.common.issues), m.result;
1554
- let J = q.map((m) => new ZodError(m));
1555
- return addIssueToContext(U, {
1556
- code: ZodIssueCode.invalid_union,
1557
- unionErrors: J
1558
- }), INVALID;
1559
- }
1560
- }
1561
- get options() {
1562
- return this._def.options;
1563
- }
1564
- };
1565
- ZodUnion.create = (m, U) => new ZodUnion({
1566
- options: m,
1567
- typeName: ZodFirstPartyTypeKind.ZodUnion,
1568
- ...processCreateParams(U)
1569
- });
1570
- var getDiscriminator = (m) => m instanceof ZodLazy ? getDiscriminator(m.schema) : m instanceof ZodEffects ? getDiscriminator(m.innerType()) : m instanceof ZodLiteral ? [m.value] : m instanceof ZodEnum ? m.options : m instanceof ZodNativeEnum ? util.objectValues(m.enum) : m instanceof ZodDefault ? getDiscriminator(m._def.innerType) : m instanceof ZodUndefined ? [void 0] : m instanceof ZodNull ? [null] : m instanceof ZodOptional ? [void 0, ...getDiscriminator(m.unwrap())] : m instanceof ZodNullable ? [null, ...getDiscriminator(m.unwrap())] : m instanceof ZodBranded || m instanceof ZodReadonly ? getDiscriminator(m.unwrap()) : m instanceof ZodCatch ? getDiscriminator(m._def.innerType) : [], ZodDiscriminatedUnion = class U extends ZodType {
1571
- _parse(U) {
1572
- let { ctx: W } = this._processInputParams(U);
1573
- if (W.parsedType !== ZodParsedType.object) return addIssueToContext(W, {
1574
- code: ZodIssueCode.invalid_type,
1575
- expected: ZodParsedType.object,
1576
- received: W.parsedType
1577
- }), INVALID;
1578
- let G = this.discriminator, q = W.data[G], J = this.optionsMap.get(q);
1579
- return J ? W.common.async ? J._parseAsync({
1580
- data: W.data,
1581
- path: W.path,
1582
- parent: W
1583
- }) : J._parseSync({
1584
- data: W.data,
1585
- path: W.path,
1586
- parent: W
1587
- }) : (addIssueToContext(W, {
1588
- code: ZodIssueCode.invalid_union_discriminator,
1589
- options: Array.from(this.optionsMap.keys()),
1590
- path: [G]
1591
- }), INVALID);
1592
- }
1593
- get discriminator() {
1594
- return this._def.discriminator;
1595
- }
1596
- get options() {
1597
- return this._def.options;
1598
- }
1599
- get optionsMap() {
1600
- return this._def.optionsMap;
1601
- }
1602
- static create(m, W, G) {
1603
- let K = /* @__PURE__ */ new Map();
1604
- for (let U of W) {
1605
- let W = getDiscriminator(U.shape[m]);
1606
- if (!W.length) throw Error(`A discriminator value for key \`${m}\` could not be extracted from all schema options`);
1607
- for (let G of W) {
1608
- if (K.has(G)) throw Error(`Discriminator property ${String(m)} has duplicate value ${String(G)}`);
1609
- K.set(G, U);
1610
- }
1611
- }
1612
- return new U({
1613
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
1614
- discriminator: m,
1615
- options: W,
1616
- optionsMap: K,
1617
- ...processCreateParams(G)
1618
- });
1619
- }
1620
- };
1621
- function mergeValues(G, K) {
1622
- let q = getParsedType(G), J = getParsedType(K);
1623
- if (G === K) return {
1624
- valid: !0,
1625
- data: G
1626
- };
1627
- if (q === ZodParsedType.object && J === ZodParsedType.object) {
1628
- let m = util.objectKeys(K), U = util.objectKeys(G).filter((U) => m.indexOf(U) !== -1), q = {
1629
- ...G,
1630
- ...K
1631
- };
1632
- for (let m of U) {
1633
- let U = mergeValues(G[m], K[m]);
1634
- if (!U.valid) return { valid: !1 };
1635
- q[m] = U.data;
1636
- }
1637
- return {
1638
- valid: !0,
1639
- data: q
1640
- };
1641
- } else if (q === ZodParsedType.array && J === ZodParsedType.array) {
1642
- if (G.length !== K.length) return { valid: !1 };
1643
- let m = [];
1644
- for (let U = 0; U < G.length; U++) {
1645
- let W = G[U], q = K[U], J = mergeValues(W, q);
1646
- if (!J.valid) return { valid: !1 };
1647
- m.push(J.data);
1648
- }
1649
- return {
1650
- valid: !0,
1651
- data: m
1652
- };
1653
- } else if (q === ZodParsedType.date && J === ZodParsedType.date && +G == +K) return {
1654
- valid: !0,
1655
- data: G
1656
- };
1657
- else return { valid: !1 };
1658
- }
1659
- var ZodIntersection = class extends ZodType {
1660
- _parse(m) {
1661
- let { status: U, ctx: W } = this._processInputParams(m), G = (m, G) => {
1662
- if (isAborted(m) || isAborted(G)) return INVALID;
1663
- let q = mergeValues(m.value, G.value);
1664
- return q.valid ? ((isDirty(m) || isDirty(G)) && U.dirty(), {
1665
- status: U.value,
1666
- value: q.data
1667
- }) : (addIssueToContext(W, { code: ZodIssueCode.invalid_intersection_types }), INVALID);
1668
- };
1669
- return W.common.async ? Promise.all([this._def.left._parseAsync({
1670
- data: W.data,
1671
- path: W.path,
1672
- parent: W
1673
- }), this._def.right._parseAsync({
1674
- data: W.data,
1675
- path: W.path,
1676
- parent: W
1677
- })]).then(([m, U]) => G(m, U)) : G(this._def.left._parseSync({
1678
- data: W.data,
1679
- path: W.path,
1680
- parent: W
1681
- }), this._def.right._parseSync({
1682
- data: W.data,
1683
- path: W.path,
1684
- parent: W
1685
- }));
1686
- }
1687
- };
1688
- ZodIntersection.create = (m, U, W) => new ZodIntersection({
1689
- left: m,
1690
- right: U,
1691
- typeName: ZodFirstPartyTypeKind.ZodIntersection,
1692
- ...processCreateParams(W)
1693
- });
1694
- var ZodTuple = class U extends ZodType {
1695
- _parse(U) {
1696
- let { status: W, ctx: G } = this._processInputParams(U);
1697
- if (G.parsedType !== ZodParsedType.array) return addIssueToContext(G, {
1698
- code: ZodIssueCode.invalid_type,
1699
- expected: ZodParsedType.array,
1700
- received: G.parsedType
1701
- }), INVALID;
1702
- if (G.data.length < this._def.items.length) return addIssueToContext(G, {
1703
- code: ZodIssueCode.too_small,
1704
- minimum: this._def.items.length,
1705
- inclusive: !0,
1706
- exact: !1,
1707
- type: "array"
1708
- }), INVALID;
1709
- !this._def.rest && G.data.length > this._def.items.length && (addIssueToContext(G, {
1710
- code: ZodIssueCode.too_big,
1711
- maximum: this._def.items.length,
1712
- inclusive: !0,
1713
- exact: !1,
1714
- type: "array"
1715
- }), W.dirty());
1716
- let q = [...G.data].map((m, U) => {
1717
- let W = this._def.items[U] || this._def.rest;
1718
- return W ? W._parse(new ParseInputLazyPath(G, m, G.path, U)) : null;
1719
- }).filter((m) => !!m);
1720
- return G.common.async ? Promise.all(q).then((m) => ParseStatus.mergeArray(W, m)) : ParseStatus.mergeArray(W, q);
1721
- }
1722
- get items() {
1723
- return this._def.items;
1724
- }
1725
- rest(m) {
1726
- return new U({
1727
- ...this._def,
1728
- rest: m
1729
- });
1730
- }
1731
- };
1732
- ZodTuple.create = (m, U) => {
1733
- if (!Array.isArray(m)) throw Error("You must pass an array of schemas to z.tuple([ ... ])");
1734
- return new ZodTuple({
1735
- items: m,
1736
- typeName: ZodFirstPartyTypeKind.ZodTuple,
1737
- rest: null,
1738
- ...processCreateParams(U)
1739
- });
1740
- };
1741
- var ZodRecord = class U extends ZodType {
1742
- get keySchema() {
1743
- return this._def.keyType;
1744
- }
1745
- get valueSchema() {
1746
- return this._def.valueType;
1747
- }
1748
- _parse(U) {
1749
- let { status: W, ctx: G } = this._processInputParams(U);
1750
- if (G.parsedType !== ZodParsedType.object) return addIssueToContext(G, {
1751
- code: ZodIssueCode.invalid_type,
1752
- expected: ZodParsedType.object,
1753
- received: G.parsedType
1754
- }), INVALID;
1755
- let q = [], J = this._def.keyType, Y = this._def.valueType;
1756
- for (let m in G.data) q.push({
1757
- key: J._parse(new ParseInputLazyPath(G, m, G.path, m)),
1758
- value: Y._parse(new ParseInputLazyPath(G, G.data[m], G.path, m)),
1759
- alwaysSet: m in G.data
1760
- });
1761
- return G.common.async ? ParseStatus.mergeObjectAsync(W, q) : ParseStatus.mergeObjectSync(W, q);
1762
- }
1763
- get element() {
1764
- return this._def.valueType;
1765
- }
1766
- static create(m, W, G) {
1767
- return W instanceof ZodType ? new U({
1768
- keyType: m,
1769
- valueType: W,
1770
- typeName: ZodFirstPartyTypeKind.ZodRecord,
1771
- ...processCreateParams(G)
1772
- }) : new U({
1773
- keyType: ZodString.create(),
1774
- valueType: m,
1775
- typeName: ZodFirstPartyTypeKind.ZodRecord,
1776
- ...processCreateParams(W)
1777
- });
1778
- }
1779
- }, ZodMap = class extends ZodType {
1780
- get keySchema() {
1781
- return this._def.keyType;
1782
- }
1783
- get valueSchema() {
1784
- return this._def.valueType;
1785
- }
1786
- _parse(U) {
1787
- let { status: W, ctx: G } = this._processInputParams(U);
1788
- if (G.parsedType !== ZodParsedType.map) return addIssueToContext(G, {
1789
- code: ZodIssueCode.invalid_type,
1790
- expected: ZodParsedType.map,
1791
- received: G.parsedType
1792
- }), INVALID;
1793
- let q = this._def.keyType, J = this._def.valueType, Y = [...G.data.entries()].map(([m, U], W) => ({
1794
- key: q._parse(new ParseInputLazyPath(G, m, G.path, [W, "key"])),
1795
- value: J._parse(new ParseInputLazyPath(G, U, G.path, [W, "value"]))
1796
- }));
1797
- if (G.common.async) {
1798
- let m = /* @__PURE__ */ new Map();
1799
- return Promise.resolve().then(async () => {
1800
- for (let U of Y) {
1801
- let G = await U.key, K = await U.value;
1802
- if (G.status === "aborted" || K.status === "aborted") return INVALID;
1803
- (G.status === "dirty" || K.status === "dirty") && W.dirty(), m.set(G.value, K.value);
1804
- }
1805
- return {
1806
- status: W.value,
1807
- value: m
1808
- };
1809
- });
1810
- } else {
1811
- let m = /* @__PURE__ */ new Map();
1812
- for (let U of Y) {
1813
- let G = U.key, K = U.value;
1814
- if (G.status === "aborted" || K.status === "aborted") return INVALID;
1815
- (G.status === "dirty" || K.status === "dirty") && W.dirty(), m.set(G.value, K.value);
1816
- }
1817
- return {
1818
- status: W.value,
1819
- value: m
1820
- };
1821
- }
1822
- }
1823
- };
1824
- ZodMap.create = (m, U, W) => new ZodMap({
1825
- valueType: U,
1826
- keyType: m,
1827
- typeName: ZodFirstPartyTypeKind.ZodMap,
1828
- ...processCreateParams(W)
1829
- });
1830
- var ZodSet = class U extends ZodType {
1831
- _parse(U) {
1832
- let { status: W, ctx: G } = this._processInputParams(U);
1833
- if (G.parsedType !== ZodParsedType.set) return addIssueToContext(G, {
1834
- code: ZodIssueCode.invalid_type,
1835
- expected: ZodParsedType.set,
1836
- received: G.parsedType
1837
- }), INVALID;
1838
- let q = this._def;
1839
- q.minSize !== null && G.data.size < q.minSize.value && (addIssueToContext(G, {
1840
- code: ZodIssueCode.too_small,
1841
- minimum: q.minSize.value,
1842
- type: "set",
1843
- inclusive: !0,
1844
- exact: !1,
1845
- message: q.minSize.message
1846
- }), W.dirty()), q.maxSize !== null && G.data.size > q.maxSize.value && (addIssueToContext(G, {
1847
- code: ZodIssueCode.too_big,
1848
- maximum: q.maxSize.value,
1849
- type: "set",
1850
- inclusive: !0,
1851
- exact: !1,
1852
- message: q.maxSize.message
1853
- }), W.dirty());
1854
- let J = this._def.valueType;
1855
- function Y(m) {
1856
- let U = /* @__PURE__ */ new Set();
1857
- for (let G of m) {
1858
- if (G.status === "aborted") return INVALID;
1859
- G.status === "dirty" && W.dirty(), U.add(G.value);
1860
- }
1861
- return {
1862
- status: W.value,
1863
- value: U
1864
- };
1865
- }
1866
- let X = [...G.data.values()].map((m, U) => J._parse(new ParseInputLazyPath(G, m, G.path, U)));
1867
- return G.common.async ? Promise.all(X).then((m) => Y(m)) : Y(X);
1868
- }
1869
- min(m, W) {
1870
- return new U({
1871
- ...this._def,
1872
- minSize: {
1873
- value: m,
1874
- message: errorUtil.toString(W)
1875
- }
1876
- });
1877
- }
1878
- max(m, W) {
1879
- return new U({
1880
- ...this._def,
1881
- maxSize: {
1882
- value: m,
1883
- message: errorUtil.toString(W)
1884
- }
1885
- });
1886
- }
1887
- size(m, U) {
1888
- return this.min(m, U).max(m, U);
1889
- }
1890
- nonempty(m) {
1891
- return this.min(1, m);
1892
- }
1893
- };
1894
- ZodSet.create = (m, U) => new ZodSet({
1895
- valueType: m,
1896
- minSize: null,
1897
- maxSize: null,
1898
- typeName: ZodFirstPartyTypeKind.ZodSet,
1899
- ...processCreateParams(U)
1900
- });
1901
- var ZodFunction = class U extends ZodType {
1902
- constructor() {
1903
- super(...arguments), this.validate = this.implement;
1904
- }
1905
- _parse(U) {
1906
- let { ctx: W } = this._processInputParams(U);
1907
- if (W.parsedType !== ZodParsedType.function) return addIssueToContext(W, {
1908
- code: ZodIssueCode.invalid_type,
1909
- expected: ZodParsedType.function,
1910
- received: W.parsedType
1911
- }), INVALID;
1912
- function Y(m, U) {
1913
- return makeIssue({
1914
- data: m,
1915
- path: W.path,
1916
- errorMaps: [
1917
- W.common.contextualErrorMap,
1918
- W.schemaErrorMap,
1919
- getErrorMap(),
1920
- en_default
1921
- ].filter((m) => !!m),
1922
- issueData: {
1923
- code: ZodIssueCode.invalid_arguments,
1924
- argumentsError: U
1925
- }
1926
- });
1927
- }
1928
- function Z(m, U) {
1929
- return makeIssue({
1930
- data: m,
1931
- path: W.path,
1932
- errorMaps: [
1933
- W.common.contextualErrorMap,
1934
- W.schemaErrorMap,
1935
- getErrorMap(),
1936
- en_default
1937
- ].filter((m) => !!m),
1938
- issueData: {
1939
- code: ZodIssueCode.invalid_return_type,
1940
- returnTypeError: U
1941
- }
1942
- });
1943
- }
1944
- let Q = { errorMap: W.common.contextualErrorMap }, $ = W.data;
1945
- if (this._def.returns instanceof ZodPromise) {
1946
- let m = this;
1947
- return OK(async function(...U) {
1948
- let W = new ZodError([]), K = await m._def.args.parseAsync(U, Q).catch((m) => {
1949
- throw W.addIssue(Y(U, m)), W;
1950
- }), q = await Reflect.apply($, this, K);
1951
- return await m._def.returns._def.type.parseAsync(q, Q).catch((m) => {
1952
- throw W.addIssue(Z(q, m)), W;
1953
- });
1954
- });
1955
- } else {
1956
- let m = this;
1957
- return OK(function(...U) {
1958
- let W = m._def.args.safeParse(U, Q);
1959
- if (!W.success) throw new ZodError([Y(U, W.error)]);
1960
- let K = Reflect.apply($, this, W.data), q = m._def.returns.safeParse(K, Q);
1961
- if (!q.success) throw new ZodError([Z(K, q.error)]);
1962
- return q.data;
1963
- });
1964
- }
1965
- }
1966
- parameters() {
1967
- return this._def.args;
1968
- }
1969
- returnType() {
1970
- return this._def.returns;
1971
- }
1972
- args(...m) {
1973
- return new U({
1974
- ...this._def,
1975
- args: ZodTuple.create(m).rest(ZodUnknown.create())
1976
- });
1977
- }
1978
- returns(m) {
1979
- return new U({
1980
- ...this._def,
1981
- returns: m
1982
- });
1983
- }
1984
- implement(m) {
1985
- return this.parse(m);
1986
- }
1987
- strictImplement(m) {
1988
- return this.parse(m);
1989
- }
1990
- static create(m, W, G) {
1991
- return new U({
1992
- args: m || ZodTuple.create([]).rest(ZodUnknown.create()),
1993
- returns: W || ZodUnknown.create(),
1994
- typeName: ZodFirstPartyTypeKind.ZodFunction,
1995
- ...processCreateParams(G)
1996
- });
1997
- }
1998
- }, ZodLazy = class extends ZodType {
1999
- get schema() {
2000
- return this._def.getter();
2001
- }
2002
- _parse(m) {
2003
- let { ctx: U } = this._processInputParams(m);
2004
- return this._def.getter()._parse({
2005
- data: U.data,
2006
- path: U.path,
2007
- parent: U
2008
- });
2009
- }
2010
- };
2011
- ZodLazy.create = (m, U) => new ZodLazy({
2012
- getter: m,
2013
- typeName: ZodFirstPartyTypeKind.ZodLazy,
2014
- ...processCreateParams(U)
2015
- });
2016
- var ZodLiteral = class extends ZodType {
2017
- _parse(m) {
2018
- if (m.data !== this._def.value) {
2019
- let U = this._getOrReturnCtx(m);
2020
- return addIssueToContext(U, {
2021
- received: U.data,
2022
- code: ZodIssueCode.invalid_literal,
2023
- expected: this._def.value
2024
- }), INVALID;
2025
- }
2026
- return {
2027
- status: "valid",
2028
- value: m.data
2029
- };
2030
- }
2031
- get value() {
2032
- return this._def.value;
2033
- }
2034
- };
2035
- ZodLiteral.create = (m, U) => new ZodLiteral({
2036
- value: m,
2037
- typeName: ZodFirstPartyTypeKind.ZodLiteral,
2038
- ...processCreateParams(U)
2039
- });
2040
- function createZodEnum(m, U) {
2041
- return new ZodEnum({
2042
- values: m,
2043
- typeName: ZodFirstPartyTypeKind.ZodEnum,
2044
- ...processCreateParams(U)
2045
- });
2046
- }
2047
- var ZodEnum = class m extends ZodType {
2048
- _parse(m) {
2049
- if (typeof m.data != "string") {
2050
- let U = this._getOrReturnCtx(m), G = this._def.values;
2051
- return addIssueToContext(U, {
2052
- expected: util.joinValues(G),
2053
- received: U.parsedType,
2054
- code: ZodIssueCode.invalid_type
2055
- }), INVALID;
2056
- }
2057
- if (this._cache ||= new Set(this._def.values), !this._cache.has(m.data)) {
2058
- let U = this._getOrReturnCtx(m), W = this._def.values;
2059
- return addIssueToContext(U, {
2060
- received: U.data,
2061
- code: ZodIssueCode.invalid_enum_value,
2062
- options: W
2063
- }), INVALID;
2064
- }
2065
- return OK(m.data);
2066
- }
2067
- get options() {
2068
- return this._def.values;
2069
- }
2070
- get enum() {
2071
- let m = {};
2072
- for (let U of this._def.values) m[U] = U;
2073
- return m;
2074
- }
2075
- get Values() {
2076
- let m = {};
2077
- for (let U of this._def.values) m[U] = U;
2078
- return m;
2079
- }
2080
- get Enum() {
2081
- let m = {};
2082
- for (let U of this._def.values) m[U] = U;
2083
- return m;
2084
- }
2085
- extract(U, W = this._def) {
2086
- return m.create(U, {
2087
- ...this._def,
2088
- ...W
2089
- });
2090
- }
2091
- exclude(U, W = this._def) {
2092
- return m.create(this.options.filter((m) => !U.includes(m)), {
2093
- ...this._def,
2094
- ...W
2095
- });
2096
- }
2097
- };
2098
- ZodEnum.create = createZodEnum;
2099
- var ZodNativeEnum = class extends ZodType {
2100
- _parse(U) {
2101
- let G = util.getValidEnumValues(this._def.values), q = this._getOrReturnCtx(U);
2102
- if (q.parsedType !== ZodParsedType.string && q.parsedType !== ZodParsedType.number) {
2103
- let m = util.objectValues(G);
2104
- return addIssueToContext(q, {
2105
- expected: util.joinValues(m),
2106
- received: q.parsedType,
2107
- code: ZodIssueCode.invalid_type
2108
- }), INVALID;
2109
- }
2110
- if (this._cache ||= new Set(util.getValidEnumValues(this._def.values)), !this._cache.has(U.data)) {
2111
- let m = util.objectValues(G);
2112
- return addIssueToContext(q, {
2113
- received: q.data,
2114
- code: ZodIssueCode.invalid_enum_value,
2115
- options: m
2116
- }), INVALID;
2117
- }
2118
- return OK(U.data);
2119
- }
2120
- get enum() {
2121
- return this._def.values;
2122
- }
2123
- };
2124
- ZodNativeEnum.create = (m, U) => new ZodNativeEnum({
2125
- values: m,
2126
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
2127
- ...processCreateParams(U)
2128
- });
2129
- var ZodPromise = class extends ZodType {
2130
- unwrap() {
2131
- return this._def.type;
2132
- }
2133
- _parse(U) {
2134
- let { ctx: W } = this._processInputParams(U);
2135
- return W.parsedType !== ZodParsedType.promise && W.common.async === !1 ? (addIssueToContext(W, {
2136
- code: ZodIssueCode.invalid_type,
2137
- expected: ZodParsedType.promise,
2138
- received: W.parsedType
2139
- }), INVALID) : OK((W.parsedType === ZodParsedType.promise ? W.data : Promise.resolve(W.data)).then((m) => this._def.type.parseAsync(m, {
2140
- path: W.path,
2141
- errorMap: W.common.contextualErrorMap
2142
- })));
2143
- }
2144
- };
2145
- ZodPromise.create = (m, U) => new ZodPromise({
2146
- type: m,
2147
- typeName: ZodFirstPartyTypeKind.ZodPromise,
2148
- ...processCreateParams(U)
2149
- });
2150
- var ZodEffects = class extends ZodType {
2151
- innerType() {
2152
- return this._def.schema;
2153
- }
2154
- sourceType() {
2155
- return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
2156
- }
2157
- _parse(m) {
2158
- let { status: U, ctx: G } = this._processInputParams(m), K = this._def.effect || null, q = {
2159
- addIssue: (m) => {
2160
- addIssueToContext(G, m), m.fatal ? U.abort() : U.dirty();
2161
- },
2162
- get path() {
2163
- return G.path;
2164
- }
2165
- };
2166
- if (q.addIssue = q.addIssue.bind(q), K.type === "preprocess") {
2167
- let m = K.transform(G.data, q);
2168
- if (G.common.async) return Promise.resolve(m).then(async (m) => {
2169
- if (U.value === "aborted") return INVALID;
2170
- let W = await this._def.schema._parseAsync({
2171
- data: m,
2172
- path: G.path,
2173
- parent: G
2174
- });
2175
- return W.status === "aborted" ? INVALID : W.status === "dirty" || U.value === "dirty" ? DIRTY(W.value) : W;
2176
- });
2177
- {
2178
- if (U.value === "aborted") return INVALID;
2179
- let W = this._def.schema._parseSync({
2180
- data: m,
2181
- path: G.path,
2182
- parent: G
2183
- });
2184
- return W.status === "aborted" ? INVALID : W.status === "dirty" || U.value === "dirty" ? DIRTY(W.value) : W;
2185
- }
2186
- }
2187
- if (K.type === "refinement") {
2188
- let m = (m) => {
2189
- let U = K.refinement(m, q);
2190
- if (G.common.async) return Promise.resolve(U);
2191
- if (U instanceof Promise) throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
2192
- return m;
2193
- };
2194
- if (G.common.async === !1) {
2195
- let W = this._def.schema._parseSync({
2196
- data: G.data,
2197
- path: G.path,
2198
- parent: G
2199
- });
2200
- return W.status === "aborted" ? INVALID : (W.status === "dirty" && U.dirty(), m(W.value), {
2201
- status: U.value,
2202
- value: W.value
2203
- });
2204
- } else return this._def.schema._parseAsync({
2205
- data: G.data,
2206
- path: G.path,
2207
- parent: G
2208
- }).then((W) => W.status === "aborted" ? INVALID : (W.status === "dirty" && U.dirty(), m(W.value).then(() => ({
2209
- status: U.value,
2210
- value: W.value
2211
- }))));
2212
- }
2213
- if (K.type === "transform") if (G.common.async === !1) {
2214
- let m = this._def.schema._parseSync({
2215
- data: G.data,
2216
- path: G.path,
2217
- parent: G
2218
- });
2219
- if (!isValid(m)) return INVALID;
2220
- let W = K.transform(m.value, q);
2221
- if (W instanceof Promise) throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
2222
- return {
2223
- status: U.value,
2224
- value: W
2225
- };
2226
- } else return this._def.schema._parseAsync({
2227
- data: G.data,
2228
- path: G.path,
2229
- parent: G
2230
- }).then((m) => isValid(m) ? Promise.resolve(K.transform(m.value, q)).then((m) => ({
2231
- status: U.value,
2232
- value: m
2233
- })) : INVALID);
2234
- util.assertNever(K);
2235
- }
2236
- };
2237
- ZodEffects.create = (m, U, W) => new ZodEffects({
2238
- schema: m,
2239
- typeName: ZodFirstPartyTypeKind.ZodEffects,
2240
- effect: U,
2241
- ...processCreateParams(W)
2242
- }), ZodEffects.createWithPreprocess = (m, U, W) => new ZodEffects({
2243
- schema: U,
2244
- effect: {
2245
- type: "preprocess",
2246
- transform: m
2247
- },
2248
- typeName: ZodFirstPartyTypeKind.ZodEffects,
2249
- ...processCreateParams(W)
2250
- });
2251
- var ZodOptional = class extends ZodType {
2252
- _parse(U) {
2253
- return this._getType(U) === ZodParsedType.undefined ? OK(void 0) : this._def.innerType._parse(U);
2254
- }
2255
- unwrap() {
2256
- return this._def.innerType;
2257
- }
2258
- };
2259
- ZodOptional.create = (m, U) => new ZodOptional({
2260
- innerType: m,
2261
- typeName: ZodFirstPartyTypeKind.ZodOptional,
2262
- ...processCreateParams(U)
2263
- });
2264
- var ZodNullable = class extends ZodType {
2265
- _parse(U) {
2266
- return this._getType(U) === ZodParsedType.null ? OK(null) : this._def.innerType._parse(U);
2267
- }
2268
- unwrap() {
2269
- return this._def.innerType;
2270
- }
2271
- };
2272
- ZodNullable.create = (m, U) => new ZodNullable({
2273
- innerType: m,
2274
- typeName: ZodFirstPartyTypeKind.ZodNullable,
2275
- ...processCreateParams(U)
2276
- });
2277
- var ZodDefault = class extends ZodType {
2278
- _parse(U) {
2279
- let { ctx: W } = this._processInputParams(U), G = W.data;
2280
- return W.parsedType === ZodParsedType.undefined && (G = this._def.defaultValue()), this._def.innerType._parse({
2281
- data: G,
2282
- path: W.path,
2283
- parent: W
2284
- });
2285
- }
2286
- removeDefault() {
2287
- return this._def.innerType;
2288
- }
2289
- };
2290
- ZodDefault.create = (m, U) => new ZodDefault({
2291
- innerType: m,
2292
- typeName: ZodFirstPartyTypeKind.ZodDefault,
2293
- defaultValue: typeof U.default == "function" ? U.default : () => U.default,
2294
- ...processCreateParams(U)
2295
- });
2296
- var ZodCatch = class extends ZodType {
2297
- _parse(m) {
2298
- let { ctx: U } = this._processInputParams(m), W = {
2299
- ...U,
2300
- common: {
2301
- ...U.common,
2302
- issues: []
2303
- }
2304
- }, K = this._def.innerType._parse({
2305
- data: W.data,
2306
- path: W.path,
2307
- parent: { ...W }
2308
- });
2309
- return isAsync(K) ? K.then((m) => ({
2310
- status: "valid",
2311
- value: m.status === "valid" ? m.value : this._def.catchValue({
2312
- get error() {
2313
- return new ZodError(W.common.issues);
2314
- },
2315
- input: W.data
2316
- })
2317
- })) : {
2318
- status: "valid",
2319
- value: K.status === "valid" ? K.value : this._def.catchValue({
2320
- get error() {
2321
- return new ZodError(W.common.issues);
2322
- },
2323
- input: W.data
2324
- })
2325
- };
2326
- }
2327
- removeCatch() {
2328
- return this._def.innerType;
2329
- }
2330
- };
2331
- ZodCatch.create = (m, U) => new ZodCatch({
2332
- innerType: m,
2333
- typeName: ZodFirstPartyTypeKind.ZodCatch,
2334
- catchValue: typeof U.catch == "function" ? U.catch : () => U.catch,
2335
- ...processCreateParams(U)
2336
- });
2337
- var ZodNaN = class extends ZodType {
2338
- _parse(U) {
2339
- if (this._getType(U) !== ZodParsedType.nan) {
2340
- let W = this._getOrReturnCtx(U);
2341
- return addIssueToContext(W, {
2342
- code: ZodIssueCode.invalid_type,
2343
- expected: ZodParsedType.nan,
2344
- received: W.parsedType
2345
- }), INVALID;
2346
- }
2347
- return {
2348
- status: "valid",
2349
- value: U.data
2350
- };
2351
- }
2352
- };
2353
- ZodNaN.create = (m) => new ZodNaN({
2354
- typeName: ZodFirstPartyTypeKind.ZodNaN,
2355
- ...processCreateParams(m)
2356
- });
2357
- var ZodBranded = class extends ZodType {
2358
- _parse(m) {
2359
- let { ctx: U } = this._processInputParams(m), W = U.data;
2360
- return this._def.type._parse({
2361
- data: W,
2362
- path: U.path,
2363
- parent: U
2364
- });
2365
- }
2366
- unwrap() {
2367
- return this._def.type;
2368
- }
2369
- }, ZodPipeline = class m extends ZodType {
2370
- _parse(m) {
2371
- let { status: U, ctx: W } = this._processInputParams(m);
2372
- if (W.common.async) return (async () => {
2373
- let m = await this._def.in._parseAsync({
2374
- data: W.data,
2375
- path: W.path,
2376
- parent: W
2377
- });
2378
- return m.status === "aborted" ? INVALID : m.status === "dirty" ? (U.dirty(), DIRTY(m.value)) : this._def.out._parseAsync({
2379
- data: m.value,
2380
- path: W.path,
2381
- parent: W
2382
- });
2383
- })();
2384
- {
2385
- let m = this._def.in._parseSync({
2386
- data: W.data,
2387
- path: W.path,
2388
- parent: W
2389
- });
2390
- return m.status === "aborted" ? INVALID : m.status === "dirty" ? (U.dirty(), {
2391
- status: "dirty",
2392
- value: m.value
2393
- }) : this._def.out._parseSync({
2394
- data: m.value,
2395
- path: W.path,
2396
- parent: W
2397
- });
2398
- }
2399
- }
2400
- static create(U, W) {
2401
- return new m({
2402
- in: U,
2403
- out: W,
2404
- typeName: ZodFirstPartyTypeKind.ZodPipeline
2405
- });
2406
- }
2407
- }, ZodReadonly = class extends ZodType {
2408
- _parse(m) {
2409
- let U = this._def.innerType._parse(m), W = (m) => (isValid(m) && (m.value = Object.freeze(m.value)), m);
2410
- return isAsync(U) ? U.then((m) => W(m)) : W(U);
2411
- }
2412
- unwrap() {
2413
- return this._def.innerType;
2414
- }
2415
- };
2416
- ZodReadonly.create = (m, U) => new ZodReadonly({
2417
- innerType: m,
2418
- typeName: ZodFirstPartyTypeKind.ZodReadonly,
2419
- ...processCreateParams(U)
2420
- }), ZodObject.lazycreate;
2421
- var ZodFirstPartyTypeKind;
2422
- (function(m) {
2423
- m.ZodString = "ZodString", m.ZodNumber = "ZodNumber", m.ZodNaN = "ZodNaN", m.ZodBigInt = "ZodBigInt", m.ZodBoolean = "ZodBoolean", m.ZodDate = "ZodDate", m.ZodSymbol = "ZodSymbol", m.ZodUndefined = "ZodUndefined", m.ZodNull = "ZodNull", m.ZodAny = "ZodAny", m.ZodUnknown = "ZodUnknown", m.ZodNever = "ZodNever", m.ZodVoid = "ZodVoid", m.ZodArray = "ZodArray", m.ZodObject = "ZodObject", m.ZodUnion = "ZodUnion", m.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", m.ZodIntersection = "ZodIntersection", m.ZodTuple = "ZodTuple", m.ZodRecord = "ZodRecord", m.ZodMap = "ZodMap", m.ZodSet = "ZodSet", m.ZodFunction = "ZodFunction", m.ZodLazy = "ZodLazy", m.ZodLiteral = "ZodLiteral", m.ZodEnum = "ZodEnum", m.ZodEffects = "ZodEffects", m.ZodNativeEnum = "ZodNativeEnum", m.ZodOptional = "ZodOptional", m.ZodNullable = "ZodNullable", m.ZodDefault = "ZodDefault", m.ZodCatch = "ZodCatch", m.ZodPromise = "ZodPromise", m.ZodBranded = "ZodBranded", m.ZodPipeline = "ZodPipeline", m.ZodReadonly = "ZodReadonly";
2424
- })(ZodFirstPartyTypeKind ||= {}), ZodString.create, ZodNumber.create, ZodNaN.create, ZodBigInt.create, ZodBoolean.create, ZodDate.create, ZodSymbol.create, ZodUndefined.create, ZodNull.create, ZodAny.create, ZodUnknown.create, ZodNever.create, ZodVoid.create, ZodArray.create, ZodObject.create, ZodObject.strictCreate, ZodUnion.create, ZodDiscriminatedUnion.create, ZodIntersection.create, ZodTuple.create, ZodRecord.create, ZodMap.create, ZodSet.create, ZodFunction.create, ZodLazy.create, ZodLiteral.create, ZodEnum.create, ZodNativeEnum.create, ZodPromise.create, ZodEffects.create, ZodOptional.create, ZodNullable.create, ZodEffects.createWithPreprocess, ZodPipeline.create;
2425
- export { ZodFirstPartyTypeKind };