@verdocs/web-sdk 4.1.14 → 4.1.16

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 (175) hide show
  1. package/dist/cjs/{EnvelopeStore-db4f3f17.js → EnvelopeStore-4aeb54e1.js} +1 -1
  2. package/dist/cjs/{TemplateStore-037833e5.js → TemplateStore-7c7f1c50.js} +1 -1
  3. package/dist/cjs/{index-a5472099.js → index-2a189d85.js} +0 -517
  4. package/dist/cjs/index-cfdfab36.js +12 -24
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/cjs/verdocs-build.cjs.entry.js +2 -2
  7. package/dist/cjs/{verdocs-button-panel.cjs.entry.js → verdocs-button-panel_2.cjs.entry.js} +21 -0
  8. package/dist/cjs/{verdocs-checkbox_3.cjs.entry.js → verdocs-checkbox_4.cjs.entry.js} +17 -2
  9. package/dist/cjs/{verdocs-dialog_2.cjs.entry.js → verdocs-dialog.cjs.entry.js} +0 -22
  10. package/dist/cjs/verdocs-envelope-recipient-link_2.cjs.entry.js +2 -2
  11. package/dist/cjs/verdocs-envelope-sidebar.cjs.entry.js +3 -4
  12. package/dist/cjs/verdocs-envelopes-list.cjs.entry.js +10 -11
  13. package/dist/cjs/verdocs-preview_10.cjs.entry.js +15 -13
  14. package/dist/cjs/verdocs-radio-button_3.cjs.entry.js +2 -2
  15. package/dist/cjs/verdocs-table.cjs.entry.js +28 -0
  16. package/dist/cjs/verdocs-templates-list.cjs.entry.js +2 -2
  17. package/dist/cjs/verdocs-view.cjs.entry.js +1 -1
  18. package/dist/cjs/verdocs-web-sdk.cjs.js +1 -1
  19. package/dist/collection/collection-manifest.json +0 -5
  20. package/dist/collection/components/embeds/verdocs-send/verdocs-send.js +13 -11
  21. package/dist/collection/components/embeds/verdocs-view/verdocs-view.js +1 -1
  22. package/dist/collection/components/envelopes/verdocs-envelope-sidebar/verdocs-envelope-sidebar.js +1 -2
  23. package/dist/collection/components/envelopes/verdocs-envelopes-list/verdocs-envelopes-list.js +10 -11
  24. package/dist/collection/components/templates/verdocs-templates-list/verdocs-templates-list.js +2 -2
  25. package/dist/components/EnvelopeStore.js +2 -2
  26. package/dist/components/TemplateFieldStore.js +1 -1
  27. package/dist/components/TemplateRoleStore.js +1 -1
  28. package/dist/components/TemplateStore.js +2 -2
  29. package/dist/components/index.js +0 -10
  30. package/dist/components/index3.js +166 -4207
  31. package/dist/components/index4.js +3692 -167
  32. package/dist/components/verdocs-dialog.js +37 -1
  33. package/dist/components/verdocs-envelope-sidebar.js +1 -2
  34. package/dist/components/verdocs-envelopes-list.js +10 -11
  35. package/dist/components/verdocs-send2.js +13 -11
  36. package/dist/components/verdocs-table.js +39 -1
  37. package/dist/components/verdocs-templates-list.js +2 -2
  38. package/dist/components/verdocs-view2.js +1 -1
  39. package/dist/custom-elements.json +2086 -0
  40. package/dist/esm/{EnvelopeStore-9df042b5.js → EnvelopeStore-1ed5dc8f.js} +1 -1
  41. package/dist/esm/{TemplateStore-78ad24d7.js → TemplateStore-7d41d941.js} +1 -1
  42. package/dist/esm/{index-7456b04f.js → index-7588a071.js} +1 -517
  43. package/dist/esm/index-b89cf6a4.js +12 -24
  44. package/dist/esm/loader.js +1 -1
  45. package/dist/esm/verdocs-build.entry.js +2 -2
  46. package/dist/esm/{verdocs-button-panel.entry.js → verdocs-button-panel_2.entry.js} +22 -2
  47. package/dist/esm/{verdocs-checkbox_3.entry.js → verdocs-checkbox_4.entry.js} +17 -3
  48. package/dist/{components/verdocs-dialog2.js → esm/verdocs-dialog.entry.js} +7 -21
  49. package/dist/esm/verdocs-envelope-recipient-link_2.entry.js +2 -2
  50. package/dist/esm/verdocs-envelope-sidebar.entry.js +3 -4
  51. package/dist/esm/verdocs-envelopes-list.entry.js +10 -11
  52. package/dist/esm/verdocs-preview_10.entry.js +15 -13
  53. package/dist/esm/verdocs-radio-button_3.entry.js +2 -2
  54. package/dist/{components/verdocs-table2.js → esm/verdocs-table.entry.js} +7 -24
  55. package/dist/esm/verdocs-templates-list.entry.js +2 -2
  56. package/dist/esm/verdocs-view.entry.js +1 -1
  57. package/dist/esm/verdocs-web-sdk.js +1 -1
  58. package/dist/esm-es5/{EnvelopeStore-9df042b5.js → EnvelopeStore-1ed5dc8f.js} +1 -1
  59. package/dist/esm-es5/{TemplateStore-78ad24d7.js → TemplateStore-7d41d941.js} +1 -1
  60. package/dist/esm-es5/index-7588a071.js +1 -0
  61. package/dist/esm-es5/index-b89cf6a4.js +1 -1
  62. package/dist/esm-es5/loader.js +1 -1
  63. package/dist/esm-es5/verdocs-build.entry.js +1 -1
  64. package/dist/esm-es5/verdocs-button-panel_2.entry.js +1 -0
  65. package/dist/esm-es5/verdocs-checkbox_4.entry.js +1 -0
  66. package/dist/esm-es5/{verdocs-dialog_2.entry.js → verdocs-dialog.entry.js} +1 -1
  67. package/dist/esm-es5/verdocs-envelope-recipient-link_2.entry.js +1 -1
  68. package/dist/esm-es5/verdocs-envelope-sidebar.entry.js +1 -1
  69. package/dist/esm-es5/verdocs-envelopes-list.entry.js +1 -1
  70. package/dist/esm-es5/verdocs-preview_10.entry.js +1 -1
  71. package/dist/esm-es5/verdocs-radio-button_3.entry.js +1 -1
  72. package/dist/esm-es5/verdocs-table.entry.js +1 -0
  73. package/dist/esm-es5/verdocs-templates-list.entry.js +1 -1
  74. package/dist/esm-es5/verdocs-view.entry.js +1 -1
  75. package/dist/esm-es5/verdocs-web-sdk.js +1 -1
  76. package/dist/types/components.d.ts +2 -322
  77. package/dist/verdocs-web-sdk/{p-5961ce51.entry.js → p-0d54abe5.entry.js} +1 -1
  78. package/dist/verdocs-web-sdk/p-1f771dad.entry.js +1 -0
  79. package/dist/verdocs-web-sdk/{p-95e90092.system.entry.js → p-2be9ba53.system.entry.js} +1 -1
  80. package/dist/verdocs-web-sdk/p-30513f94.entry.js +1 -0
  81. package/dist/verdocs-web-sdk/p-322fa613.system.js +1 -1
  82. package/dist/verdocs-web-sdk/p-3f4b3548.system.entry.js +1 -0
  83. package/dist/verdocs-web-sdk/{p-5309a156.system.entry.js → p-413ab8a1.system.entry.js} +1 -1
  84. package/dist/verdocs-web-sdk/{p-16850eac.system.entry.js → p-48fce604.system.entry.js} +1 -1
  85. package/dist/verdocs-web-sdk/p-61257cb2.entry.js +1 -0
  86. package/dist/verdocs-web-sdk/{p-225418c7.entry.js → p-687c07ad.entry.js} +1 -1
  87. package/dist/verdocs-web-sdk/p-73f45012.system.entry.js +1 -0
  88. package/dist/verdocs-web-sdk/{p-7fe48d2e.entry.js → p-78908c67.entry.js} +1 -1
  89. package/dist/verdocs-web-sdk/{p-5e3e9c4a.system.js → p-889cc411.system.js} +1 -1
  90. package/dist/verdocs-web-sdk/p-9440752e.system.entry.js +1 -0
  91. package/dist/verdocs-web-sdk/{p-f05a3654.system.entry.js → p-977a5a4b.system.entry.js} +1 -1
  92. package/dist/verdocs-web-sdk/{p-540d9467.entry.js → p-9d36d2ad.entry.js} +1 -1
  93. package/dist/verdocs-web-sdk/p-a706bac9.js +1 -0
  94. package/dist/verdocs-web-sdk/p-b3017cd6.entry.js +1 -0
  95. package/dist/verdocs-web-sdk/{p-316b550f.entry.js → p-b61842bd.entry.js} +1 -1
  96. package/dist/verdocs-web-sdk/{p-03aedbe9.system.entry.js → p-b6b6f12a.system.entry.js} +1 -1
  97. package/dist/verdocs-web-sdk/{p-0e022e75.system.entry.js → p-b7397955.system.entry.js} +1 -1
  98. package/dist/verdocs-web-sdk/p-ba6570b4.system.entry.js +1 -0
  99. package/dist/verdocs-web-sdk/{p-afbbdc2f.system.js → p-c8de3052.system.js} +1 -1
  100. package/dist/verdocs-web-sdk/p-cf7f4475.entry.js +1 -0
  101. package/dist/verdocs-web-sdk/{p-8a820b88.system.entry.js → p-d2feac5b.system.entry.js} +1 -1
  102. package/dist/verdocs-web-sdk/p-e7578fac.entry.js +1 -0
  103. package/dist/verdocs-web-sdk/{p-c28c4e43.js → p-f02e08da.js} +1 -1
  104. package/dist/verdocs-web-sdk/p-f5064e0c.system.js +1 -0
  105. package/dist/verdocs-web-sdk/{p-5df130eb.entry.js → p-f632ffac.entry.js} +1 -1
  106. package/dist/verdocs-web-sdk/{p-9ec464df.js → p-fc2ae858.js} +1 -1
  107. package/dist/verdocs-web-sdk/p-fc5e568d.system.entry.js +1 -0
  108. package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
  109. package/package.json +2 -3
  110. package/dist/cjs/verdocs-component-error.cjs.entry.js +0 -21
  111. package/dist/cjs/verdocs-settings-api-keys_4.cjs.entry.js +0 -542
  112. package/dist/cjs/verdocs-settings.cjs.entry.js +0 -42
  113. package/dist/cjs/verdocs-tabs.cjs.entry.js +0 -27
  114. package/dist/collection/components/embeds/verdocs-settings/verdocs-settings.css +0 -40
  115. package/dist/collection/components/embeds/verdocs-settings/verdocs-settings.js +0 -104
  116. package/dist/collection/components/settings/verdocs-settings-api-keys/verdocs-settings-api-keys.css +0 -64
  117. package/dist/collection/components/settings/verdocs-settings-api-keys/verdocs-settings-api-keys.js +0 -292
  118. package/dist/collection/components/settings/verdocs-settings-members/verdocs-settings-members.css +0 -80
  119. package/dist/collection/components/settings/verdocs-settings-members/verdocs-settings-members.js +0 -349
  120. package/dist/collection/components/settings/verdocs-settings-organization/TimeZones.js +0 -144
  121. package/dist/collection/components/settings/verdocs-settings-organization/verdocs-settings-organization.css +0 -44
  122. package/dist/collection/components/settings/verdocs-settings-organization/verdocs-settings-organization.js +0 -192
  123. package/dist/collection/components/settings/verdocs-settings-profile/verdocs-settings-profile.css +0 -44
  124. package/dist/collection/components/settings/verdocs-settings-profile/verdocs-settings-profile.js +0 -190
  125. package/dist/components/verdocs-settings-api-keys.d.ts +0 -11
  126. package/dist/components/verdocs-settings-api-keys.js +0 -6
  127. package/dist/components/verdocs-settings-api-keys2.js +0 -209
  128. package/dist/components/verdocs-settings-members.d.ts +0 -11
  129. package/dist/components/verdocs-settings-members.js +0 -6
  130. package/dist/components/verdocs-settings-members2.js +0 -273
  131. package/dist/components/verdocs-settings-organization.d.ts +0 -11
  132. package/dist/components/verdocs-settings-organization.js +0 -6
  133. package/dist/components/verdocs-settings-organization2.js +0 -142
  134. package/dist/components/verdocs-settings-profile.d.ts +0 -11
  135. package/dist/components/verdocs-settings-profile.js +0 -6
  136. package/dist/components/verdocs-settings-profile2.js +0 -140
  137. package/dist/components/verdocs-settings.d.ts +0 -11
  138. package/dist/components/verdocs-settings.js +0 -130
  139. package/dist/esm/verdocs-component-error.entry.js +0 -17
  140. package/dist/esm/verdocs-dialog_2.entry.js +0 -46
  141. package/dist/esm/verdocs-settings-api-keys_4.entry.js +0 -535
  142. package/dist/esm/verdocs-settings.entry.js +0 -38
  143. package/dist/esm/verdocs-tabs.entry.js +0 -23
  144. package/dist/esm-es5/index-7456b04f.js +0 -1
  145. package/dist/esm-es5/verdocs-button-panel.entry.js +0 -1
  146. package/dist/esm-es5/verdocs-checkbox_3.entry.js +0 -1
  147. package/dist/esm-es5/verdocs-component-error.entry.js +0 -1
  148. package/dist/esm-es5/verdocs-settings-api-keys_4.entry.js +0 -1
  149. package/dist/esm-es5/verdocs-settings.entry.js +0 -1
  150. package/dist/esm-es5/verdocs-tabs.entry.js +0 -1
  151. package/dist/types/components/embeds/verdocs-settings/verdocs-settings.d.ts +0 -26
  152. package/dist/types/components/settings/verdocs-settings-api-keys/verdocs-settings-api-keys.d.ts +0 -54
  153. package/dist/types/components/settings/verdocs-settings-members/verdocs-settings-members.d.ts +0 -58
  154. package/dist/types/components/settings/verdocs-settings-organization/TimeZones.d.ts +0 -1
  155. package/dist/types/components/settings/verdocs-settings-organization/verdocs-settings-organization.d.ts +0 -37
  156. package/dist/types/components/settings/verdocs-settings-profile/verdocs-settings-profile.d.ts +0 -37
  157. package/dist/verdocs-web-sdk/p-03f8d33f.entry.js +0 -1
  158. package/dist/verdocs-web-sdk/p-12c26b19.system.entry.js +0 -1
  159. package/dist/verdocs-web-sdk/p-141a992e.system.entry.js +0 -1
  160. package/dist/verdocs-web-sdk/p-3ecaea8a.system.entry.js +0 -1
  161. package/dist/verdocs-web-sdk/p-45cf0ab5.entry.js +0 -1
  162. package/dist/verdocs-web-sdk/p-4df630c2.system.entry.js +0 -1
  163. package/dist/verdocs-web-sdk/p-515ee177.system.entry.js +0 -1
  164. package/dist/verdocs-web-sdk/p-6fa08e21.system.entry.js +0 -1
  165. package/dist/verdocs-web-sdk/p-708b5430.system.entry.js +0 -1
  166. package/dist/verdocs-web-sdk/p-753d0e16.entry.js +0 -1
  167. package/dist/verdocs-web-sdk/p-952b88fb.system.js +0 -1
  168. package/dist/verdocs-web-sdk/p-971ab2d1.entry.js +0 -1
  169. package/dist/verdocs-web-sdk/p-e42587b7.entry.js +0 -1
  170. package/dist/verdocs-web-sdk/p-efc547dc.entry.js +0 -1
  171. package/dist/verdocs-web-sdk/p-f3b47dfc.js +0 -1
  172. package/dist/verdocs-web-sdk/p-f44b9bd0.entry.js +0 -1
  173. package/dist/verdocs-web-sdk/p-f73b68fb.entry.js +0 -1
  174. package/dist/verdocs-web-sdk/p-fbfdfcd4.system.entry.js +0 -1
  175. package/dist/verdocs-web-sdk/p-fe0c473d.entry.js +0 -1
@@ -1,4235 +1,194 @@
1
- var util;
2
- (function (util) {
3
- util.assertEqual = (val) => val;
4
- function assertIs(_arg) { }
5
- util.assertIs = assertIs;
6
- function assertNever(_x) {
7
- throw new Error();
8
- }
9
- util.assertNever = assertNever;
10
- util.arrayToEnum = (items) => {
11
- const obj = {};
12
- for (const item of items) {
13
- obj[item] = item;
14
- }
15
- return obj;
16
- };
17
- util.getValidEnumValues = (obj) => {
18
- const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
19
- const filtered = {};
20
- for (const k of validKeys) {
21
- filtered[k] = obj[k];
22
- }
23
- return util.objectValues(filtered);
24
- };
25
- util.objectValues = (obj) => {
26
- return util.objectKeys(obj).map(function (e) {
27
- return obj[e];
28
- });
29
- };
30
- util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
31
- ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
32
- : (object) => {
33
- const keys = [];
34
- for (const key in object) {
35
- if (Object.prototype.hasOwnProperty.call(object, key)) {
36
- keys.push(key);
37
- }
38
- }
39
- return keys;
40
- };
41
- util.find = (arr, checker) => {
42
- for (const item of arr) {
43
- if (checker(item))
44
- return item;
45
- }
46
- return undefined;
47
- };
48
- util.isInteger = typeof Number.isInteger === "function"
49
- ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
50
- : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
51
- function joinValues(array, separator = " | ") {
52
- return array
53
- .map((val) => (typeof val === "string" ? `'${val}'` : val))
54
- .join(separator);
55
- }
56
- util.joinValues = joinValues;
57
- util.jsonStringifyReplacer = (_, value) => {
58
- if (typeof value === "bigint") {
59
- return value.toString();
60
- }
61
- return value;
62
- };
63
- })(util || (util = {}));
64
- var objectUtil;
65
- (function (objectUtil) {
66
- objectUtil.mergeShapes = (first, second) => {
67
- return {
68
- ...first,
69
- ...second, // second overwrites first
70
- };
71
- };
72
- })(objectUtil || (objectUtil = {}));
73
- const ZodParsedType = util.arrayToEnum([
74
- "string",
75
- "nan",
76
- "number",
77
- "integer",
78
- "float",
79
- "boolean",
80
- "date",
81
- "bigint",
82
- "symbol",
83
- "function",
84
- "undefined",
85
- "null",
86
- "array",
87
- "object",
88
- "unknown",
89
- "promise",
90
- "void",
91
- "never",
92
- "map",
93
- "set",
94
- ]);
95
- const getParsedType = (data) => {
96
- const t = typeof data;
97
- switch (t) {
98
- case "undefined":
99
- return ZodParsedType.undefined;
100
- case "string":
101
- return ZodParsedType.string;
102
- case "number":
103
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
104
- case "boolean":
105
- return ZodParsedType.boolean;
106
- case "function":
107
- return ZodParsedType.function;
108
- case "bigint":
109
- return ZodParsedType.bigint;
110
- case "symbol":
111
- return ZodParsedType.symbol;
112
- case "object":
113
- if (Array.isArray(data)) {
114
- return ZodParsedType.array;
115
- }
116
- if (data === null) {
117
- return ZodParsedType.null;
118
- }
119
- if (data.then &&
120
- typeof data.then === "function" &&
121
- data.catch &&
122
- typeof data.catch === "function") {
123
- return ZodParsedType.promise;
124
- }
125
- if (typeof Map !== "undefined" && data instanceof Map) {
126
- return ZodParsedType.map;
127
- }
128
- if (typeof Set !== "undefined" && data instanceof Set) {
129
- return ZodParsedType.set;
130
- }
131
- if (typeof Date !== "undefined" && data instanceof Date) {
132
- return ZodParsedType.date;
133
- }
134
- return ZodParsedType.object;
135
- default:
136
- return ZodParsedType.unknown;
137
- }
138
- };
1
+ import { getRenderingRef, forceUpdate } from '@stencil/core/internal/client';
139
2
 
140
- const ZodIssueCode = util.arrayToEnum([
141
- "invalid_type",
142
- "invalid_literal",
143
- "custom",
144
- "invalid_union",
145
- "invalid_union_discriminator",
146
- "invalid_enum_value",
147
- "unrecognized_keys",
148
- "invalid_arguments",
149
- "invalid_return_type",
150
- "invalid_date",
151
- "invalid_string",
152
- "too_small",
153
- "too_big",
154
- "invalid_intersection_types",
155
- "not_multiple_of",
156
- "not_finite",
157
- ]);
158
- const quotelessJson = (obj) => {
159
- const json = JSON.stringify(obj, null, 2);
160
- return json.replace(/"([^"]+)":/g, "$1:");
161
- };
162
- class ZodError extends Error {
163
- constructor(issues) {
164
- super();
165
- this.issues = [];
166
- this.addIssue = (sub) => {
167
- this.issues = [...this.issues, sub];
168
- };
169
- this.addIssues = (subs = []) => {
170
- this.issues = [...this.issues, ...subs];
171
- };
172
- const actualProto = new.target.prototype;
173
- if (Object.setPrototypeOf) {
174
- // eslint-disable-next-line ban/ban
175
- Object.setPrototypeOf(this, actualProto);
176
- }
177
- else {
178
- this.__proto__ = actualProto;
179
- }
180
- this.name = "ZodError";
181
- this.issues = issues;
182
- }
183
- get errors() {
184
- return this.issues;
185
- }
186
- format(_mapper) {
187
- const mapper = _mapper ||
188
- function (issue) {
189
- return issue.message;
190
- };
191
- const fieldErrors = { _errors: [] };
192
- const processError = (error) => {
193
- for (const issue of error.issues) {
194
- if (issue.code === "invalid_union") {
195
- issue.unionErrors.map(processError);
196
- }
197
- else if (issue.code === "invalid_return_type") {
198
- processError(issue.returnTypeError);
199
- }
200
- else if (issue.code === "invalid_arguments") {
201
- processError(issue.argumentsError);
202
- }
203
- else if (issue.path.length === 0) {
204
- fieldErrors._errors.push(mapper(issue));
205
- }
206
- else {
207
- let curr = fieldErrors;
208
- let i = 0;
209
- while (i < issue.path.length) {
210
- const el = issue.path[i];
211
- const terminal = i === issue.path.length - 1;
212
- if (!terminal) {
213
- curr[el] = curr[el] || { _errors: [] };
214
- // if (typeof el === "string") {
215
- // curr[el] = curr[el] || { _errors: [] };
216
- // } else if (typeof el === "number") {
217
- // const errorArray: any = [];
218
- // errorArray._errors = [];
219
- // curr[el] = curr[el] || errorArray;
220
- // }
221
- }
222
- else {
223
- curr[el] = curr[el] || { _errors: [] };
224
- curr[el]._errors.push(mapper(issue));
225
- }
226
- curr = curr[el];
227
- i++;
228
- }
229
- }
230
- }
231
- };
232
- processError(this);
233
- return fieldErrors;
234
- }
235
- static assert(value) {
236
- if (!(value instanceof ZodError)) {
237
- throw new Error(`Not a ZodError: ${value}`);
238
- }
239
- }
240
- toString() {
241
- return this.message;
242
- }
243
- get message() {
244
- return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
245
- }
246
- get isEmpty() {
247
- return this.issues.length === 0;
248
- }
249
- flatten(mapper = (issue) => issue.message) {
250
- const fieldErrors = {};
251
- const formErrors = [];
252
- for (const sub of this.issues) {
253
- if (sub.path.length > 0) {
254
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
255
- fieldErrors[sub.path[0]].push(mapper(sub));
256
- }
257
- else {
258
- formErrors.push(mapper(sub));
259
- }
260
- }
261
- return { formErrors, fieldErrors };
3
+ const appendToMap = (map, propName, value) => {
4
+ const items = map.get(propName);
5
+ if (!items) {
6
+ map.set(propName, [value]);
262
7
  }
263
- get formErrors() {
264
- return this.flatten();
8
+ else if (!items.includes(value)) {
9
+ items.push(value);
265
10
  }
266
- }
267
- ZodError.create = (issues) => {
268
- const error = new ZodError(issues);
269
- return error;
270
11
  };
271
-
272
- const errorMap = (issue, _ctx) => {
273
- let message;
274
- switch (issue.code) {
275
- case ZodIssueCode.invalid_type:
276
- if (issue.received === ZodParsedType.undefined) {
277
- message = "Required";
278
- }
279
- else {
280
- message = `Expected ${issue.expected}, received ${issue.received}`;
281
- }
282
- break;
283
- case ZodIssueCode.invalid_literal:
284
- message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
285
- break;
286
- case ZodIssueCode.unrecognized_keys:
287
- message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
288
- break;
289
- case ZodIssueCode.invalid_union:
290
- message = `Invalid input`;
291
- break;
292
- case ZodIssueCode.invalid_union_discriminator:
293
- message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
294
- break;
295
- case ZodIssueCode.invalid_enum_value:
296
- message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
297
- break;
298
- case ZodIssueCode.invalid_arguments:
299
- message = `Invalid function arguments`;
300
- break;
301
- case ZodIssueCode.invalid_return_type:
302
- message = `Invalid function return type`;
303
- break;
304
- case ZodIssueCode.invalid_date:
305
- message = `Invalid date`;
306
- break;
307
- case ZodIssueCode.invalid_string:
308
- if (typeof issue.validation === "object") {
309
- if ("includes" in issue.validation) {
310
- message = `Invalid input: must include "${issue.validation.includes}"`;
311
- if (typeof issue.validation.position === "number") {
312
- message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
313
- }
314
- }
315
- else if ("startsWith" in issue.validation) {
316
- message = `Invalid input: must start with "${issue.validation.startsWith}"`;
317
- }
318
- else if ("endsWith" in issue.validation) {
319
- message = `Invalid input: must end with "${issue.validation.endsWith}"`;
320
- }
321
- else {
322
- util.assertNever(issue.validation);
323
- }
324
- }
325
- else if (issue.validation !== "regex") {
326
- message = `Invalid ${issue.validation}`;
327
- }
328
- else {
329
- message = "Invalid";
330
- }
331
- break;
332
- case ZodIssueCode.too_small:
333
- if (issue.type === "array")
334
- message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
335
- else if (issue.type === "string")
336
- message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
337
- else if (issue.type === "number")
338
- message = `Number must be ${issue.exact
339
- ? `exactly equal to `
340
- : issue.inclusive
341
- ? `greater than or equal to `
342
- : `greater than `}${issue.minimum}`;
343
- else if (issue.type === "date")
344
- message = `Date must be ${issue.exact
345
- ? `exactly equal to `
346
- : issue.inclusive
347
- ? `greater than or equal to `
348
- : `greater than `}${new Date(Number(issue.minimum))}`;
349
- else
350
- message = "Invalid input";
351
- break;
352
- case ZodIssueCode.too_big:
353
- if (issue.type === "array")
354
- message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
355
- else if (issue.type === "string")
356
- message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
357
- else if (issue.type === "number")
358
- message = `Number must be ${issue.exact
359
- ? `exactly`
360
- : issue.inclusive
361
- ? `less than or equal to`
362
- : `less than`} ${issue.maximum}`;
363
- else if (issue.type === "bigint")
364
- message = `BigInt must be ${issue.exact
365
- ? `exactly`
366
- : issue.inclusive
367
- ? `less than or equal to`
368
- : `less than`} ${issue.maximum}`;
369
- else if (issue.type === "date")
370
- message = `Date must be ${issue.exact
371
- ? `exactly`
372
- : issue.inclusive
373
- ? `smaller than or equal to`
374
- : `smaller than`} ${new Date(Number(issue.maximum))}`;
375
- else
376
- message = "Invalid input";
377
- break;
378
- case ZodIssueCode.custom:
379
- message = `Invalid input`;
380
- break;
381
- case ZodIssueCode.invalid_intersection_types:
382
- message = `Intersection results could not be merged`;
383
- break;
384
- case ZodIssueCode.not_multiple_of:
385
- message = `Number must be a multiple of ${issue.multipleOf}`;
386
- break;
387
- case ZodIssueCode.not_finite:
388
- message = "Number must be finite";
389
- break;
390
- default:
391
- message = _ctx.defaultError;
392
- util.assertNever(issue);
393
- }
394
- return { message };
12
+ const debounce = (fn, ms) => {
13
+ let timeoutId;
14
+ return (...args) => {
15
+ if (timeoutId) {
16
+ clearTimeout(timeoutId);
17
+ }
18
+ timeoutId = setTimeout(() => {
19
+ timeoutId = 0;
20
+ fn(...args);
21
+ }, ms);
22
+ };
395
23
  };
396
24
 
397
- let overrideErrorMap = errorMap;
398
- function setErrorMap(map) {
399
- overrideErrorMap = map;
400
- }
401
- function getErrorMap() {
402
- return overrideErrorMap;
403
- }
404
-
405
- const makeIssue = (params) => {
406
- const { data, path, errorMaps, issueData } = params;
407
- const fullPath = [...path, ...(issueData.path || [])];
408
- const fullIssue = {
409
- ...issueData,
410
- path: fullPath,
411
- };
412
- if (issueData.message !== undefined) {
413
- return {
414
- ...issueData,
415
- path: fullPath,
416
- message: issueData.message,
417
- };
418
- }
419
- let errorMessage = "";
420
- const maps = errorMaps
421
- .filter((m) => !!m)
422
- .slice()
423
- .reverse();
424
- for (const map of maps) {
425
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
25
+ /**
26
+ * Check if a possible element isConnected.
27
+ * The property might not be there, so we check for it.
28
+ *
29
+ * We want it to return true if isConnected is not a property,
30
+ * otherwise we would remove these elements and would not update.
31
+ *
32
+ * Better leak in Edge than to be useless.
33
+ */
34
+ const isConnected = (maybeElement) => !('isConnected' in maybeElement) || maybeElement.isConnected;
35
+ const cleanupElements = debounce((map) => {
36
+ for (let key of map.keys()) {
37
+ map.set(key, map.get(key).filter(isConnected));
38
+ }
39
+ }, 2000);
40
+ const stencilSubscription = () => {
41
+ if (typeof getRenderingRef !== 'function') {
42
+ // If we are not in a stencil project, we do nothing.
43
+ // This function is not really exported by @stencil/core.
44
+ return {};
426
45
  }
46
+ const elmsToUpdate = new Map();
427
47
  return {
428
- ...issueData,
429
- path: fullPath,
430
- message: errorMessage,
48
+ dispose: () => elmsToUpdate.clear(),
49
+ get: (propName) => {
50
+ const elm = getRenderingRef();
51
+ if (elm) {
52
+ appendToMap(elmsToUpdate, propName, elm);
53
+ }
54
+ },
55
+ set: (propName) => {
56
+ const elements = elmsToUpdate.get(propName);
57
+ if (elements) {
58
+ elmsToUpdate.set(propName, elements.filter(forceUpdate));
59
+ }
60
+ cleanupElements(elmsToUpdate);
61
+ },
62
+ reset: () => {
63
+ elmsToUpdate.forEach((elms) => elms.forEach(forceUpdate));
64
+ cleanupElements(elmsToUpdate);
65
+ },
431
66
  };
432
67
  };
433
- const EMPTY_PATH = [];
434
- function addIssueToContext(ctx, issueData) {
435
- const overrideMap = getErrorMap();
436
- const issue = makeIssue({
437
- issueData: issueData,
438
- data: ctx.data,
439
- path: ctx.path,
440
- errorMaps: [
441
- ctx.common.contextualErrorMap,
442
- ctx.schemaErrorMap,
443
- overrideMap,
444
- overrideMap === errorMap ? undefined : errorMap, // then global default map
445
- ].filter((x) => !!x),
446
- });
447
- ctx.common.issues.push(issue);
448
- }
449
- class ParseStatus {
450
- constructor() {
451
- this.value = "valid";
452
- }
453
- dirty() {
454
- if (this.value === "valid")
455
- this.value = "dirty";
456
- }
457
- abort() {
458
- if (this.value !== "aborted")
459
- this.value = "aborted";
460
- }
461
- static mergeArray(status, results) {
462
- const arrayValue = [];
463
- for (const s of results) {
464
- if (s.status === "aborted")
465
- return INVALID;
466
- if (s.status === "dirty")
467
- status.dirty();
468
- arrayValue.push(s.value);
469
- }
470
- return { status: status.value, value: arrayValue };
471
- }
472
- static async mergeObjectAsync(status, pairs) {
473
- const syncPairs = [];
474
- for (const pair of pairs) {
475
- const key = await pair.key;
476
- const value = await pair.value;
477
- syncPairs.push({
478
- key,
479
- value,
480
- });
481
- }
482
- return ParseStatus.mergeObjectSync(status, syncPairs);
483
- }
484
- static mergeObjectSync(status, pairs) {
485
- const finalObject = {};
486
- for (const pair of pairs) {
487
- const { key, value } = pair;
488
- if (key.status === "aborted")
489
- return INVALID;
490
- if (value.status === "aborted")
491
- return INVALID;
492
- if (key.status === "dirty")
493
- status.dirty();
494
- if (value.status === "dirty")
495
- status.dirty();
496
- if (key.value !== "__proto__" &&
497
- (typeof value.value !== "undefined" || pair.alwaysSet)) {
498
- finalObject[key.value] = value.value;
499
- }
500
- }
501
- return { status: status.value, value: finalObject };
502
- }
503
- }
504
- const INVALID = Object.freeze({
505
- status: "aborted",
506
- });
507
- const DIRTY = (value) => ({ status: "dirty", value });
508
- const OK = (value) => ({ status: "valid", value });
509
- const isAborted = (x) => x.status === "aborted";
510
- const isDirty = (x) => x.status === "dirty";
511
- const isValid = (x) => x.status === "valid";
512
- const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
513
-
514
- /******************************************************************************
515
- Copyright (c) Microsoft Corporation.
516
-
517
- Permission to use, copy, modify, and/or distribute this software for any
518
- purpose with or without fee is hereby granted.
519
-
520
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
521
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
522
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
523
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
524
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
525
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
526
- PERFORMANCE OF THIS SOFTWARE.
527
- ***************************************************************************** */
528
-
529
- function __classPrivateFieldGet(receiver, state, kind, f) {
530
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
531
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
532
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
533
- }
534
-
535
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
536
- if (kind === "m") throw new TypeError("Private method is not writable");
537
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
538
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
539
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
540
- }
541
-
542
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
543
- var e = new Error(message);
544
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
545
- };
546
68
 
547
- var errorUtil;
548
- (function (errorUtil) {
549
- errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
550
- errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
551
- })(errorUtil || (errorUtil = {}));
552
-
553
- var _ZodEnum_cache, _ZodNativeEnum_cache;
554
- class ParseInputLazyPath {
555
- constructor(parent, value, path, key) {
556
- this._cachedPath = [];
557
- this.parent = parent;
558
- this.data = value;
559
- this._path = path;
560
- this._key = key;
561
- }
562
- get path() {
563
- if (!this._cachedPath.length) {
564
- if (this._key instanceof Array) {
565
- this._cachedPath.push(...this._path, ...this._key);
566
- }
567
- else {
568
- this._cachedPath.push(...this._path, this._key);
569
- }
570
- }
571
- return this._cachedPath;
572
- }
573
- }
574
- const handleResult = (ctx, result) => {
575
- if (isValid(result)) {
576
- return { success: true, data: result.value };
577
- }
578
- else {
579
- if (!ctx.common.issues.length) {
580
- throw new Error("Validation failed but no issues detected.");
581
- }
582
- return {
583
- success: false,
584
- get error() {
585
- if (this._error)
586
- return this._error;
587
- const error = new ZodError(ctx.common.issues);
588
- this._error = error;
589
- return this._error;
590
- },
591
- };
592
- }
593
- };
594
- function processCreateParams(params) {
595
- if (!params)
596
- return {};
597
- const { errorMap, invalid_type_error, required_error, description } = params;
598
- if (errorMap && (invalid_type_error || required_error)) {
599
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
600
- }
601
- if (errorMap)
602
- return { errorMap: errorMap, description };
603
- const customMap = (iss, ctx) => {
604
- var _a, _b;
605
- const { message } = params;
606
- if (iss.code === "invalid_enum_value") {
607
- return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
608
- }
609
- if (typeof ctx.data === "undefined") {
610
- return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
69
+ const unwrap = (val) => (typeof val === 'function' ? val() : val);
70
+ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
71
+ const unwrappedState = unwrap(defaultState);
72
+ let states = new Map(Object.entries(unwrappedState !== null && unwrappedState !== void 0 ? unwrappedState : {}));
73
+ const handlers = {
74
+ dispose: [],
75
+ get: [],
76
+ set: [],
77
+ reset: [],
78
+ };
79
+ const reset = () => {
80
+ var _a;
81
+ // When resetting the state, the default state may be a function - unwrap it to invoke it.
82
+ // otherwise, the state won't be properly reset
83
+ states = new Map(Object.entries((_a = unwrap(defaultState)) !== null && _a !== void 0 ? _a : {}));
84
+ handlers.reset.forEach((cb) => cb());
85
+ };
86
+ const dispose = () => {
87
+ // Call first dispose as resetting the state would
88
+ // cause less updates ;)
89
+ handlers.dispose.forEach((cb) => cb());
90
+ reset();
91
+ };
92
+ const get = (propName) => {
93
+ handlers.get.forEach((cb) => cb(propName));
94
+ return states.get(propName);
95
+ };
96
+ const set = (propName, value) => {
97
+ const oldValue = states.get(propName);
98
+ if (shouldUpdate(value, oldValue, propName)) {
99
+ states.set(propName, value);
100
+ handlers.set.forEach((cb) => cb(propName, value, oldValue));
611
101
  }
612
- if (iss.code !== "invalid_type")
613
- return { message: ctx.defaultError };
614
- return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
615
102
  };
616
- return { errorMap: customMap, description };
617
- }
618
- class ZodType {
619
- constructor(def) {
620
- /** Alias of safeParseAsync */
621
- this.spa = this.safeParseAsync;
622
- this._def = def;
623
- this.parse = this.parse.bind(this);
624
- this.safeParse = this.safeParse.bind(this);
625
- this.parseAsync = this.parseAsync.bind(this);
626
- this.safeParseAsync = this.safeParseAsync.bind(this);
627
- this.spa = this.spa.bind(this);
628
- this.refine = this.refine.bind(this);
629
- this.refinement = this.refinement.bind(this);
630
- this.superRefine = this.superRefine.bind(this);
631
- this.optional = this.optional.bind(this);
632
- this.nullable = this.nullable.bind(this);
633
- this.nullish = this.nullish.bind(this);
634
- this.array = this.array.bind(this);
635
- this.promise = this.promise.bind(this);
636
- this.or = this.or.bind(this);
637
- this.and = this.and.bind(this);
638
- this.transform = this.transform.bind(this);
639
- this.brand = this.brand.bind(this);
640
- this.default = this.default.bind(this);
641
- this.catch = this.catch.bind(this);
642
- this.describe = this.describe.bind(this);
643
- this.pipe = this.pipe.bind(this);
644
- this.readonly = this.readonly.bind(this);
645
- this.isNullable = this.isNullable.bind(this);
646
- this.isOptional = this.isOptional.bind(this);
647
- }
648
- get description() {
649
- return this._def.description;
650
- }
651
- _getType(input) {
652
- return getParsedType(input.data);
653
- }
654
- _getOrReturnCtx(input, ctx) {
655
- return (ctx || {
656
- common: input.parent.common,
657
- data: input.data,
658
- parsedType: getParsedType(input.data),
659
- schemaErrorMap: this._def.errorMap,
660
- path: input.path,
661
- parent: input.parent,
662
- });
663
- }
664
- _processInputParams(input) {
665
- return {
666
- status: new ParseStatus(),
667
- ctx: {
668
- common: input.parent.common,
669
- data: input.data,
670
- parsedType: getParsedType(input.data),
671
- schemaErrorMap: this._def.errorMap,
672
- path: input.path,
673
- parent: input.parent,
103
+ const state = (typeof Proxy === 'undefined'
104
+ ? {}
105
+ : new Proxy(unwrappedState, {
106
+ get(_, propName) {
107
+ return get(propName);
674
108
  },
675
- };
676
- }
677
- _parseSync(input) {
678
- const result = this._parse(input);
679
- if (isAsync(result)) {
680
- throw new Error("Synchronous parse encountered promise.");
681
- }
682
- return result;
683
- }
684
- _parseAsync(input) {
685
- const result = this._parse(input);
686
- return Promise.resolve(result);
687
- }
688
- parse(data, params) {
689
- const result = this.safeParse(data, params);
690
- if (result.success)
691
- return result.data;
692
- throw result.error;
693
- }
694
- safeParse(data, params) {
695
- var _a;
696
- const ctx = {
697
- common: {
698
- issues: [],
699
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
700
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
109
+ ownKeys(_) {
110
+ return Array.from(states.keys());
701
111
  },
702
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
703
- schemaErrorMap: this._def.errorMap,
704
- parent: null,
705
- data,
706
- parsedType: getParsedType(data),
707
- };
708
- const result = this._parseSync({ data, path: ctx.path, parent: ctx });
709
- return handleResult(ctx, result);
710
- }
711
- async parseAsync(data, params) {
712
- const result = await this.safeParseAsync(data, params);
713
- if (result.success)
714
- return result.data;
715
- throw result.error;
716
- }
717
- async safeParseAsync(data, params) {
718
- const ctx = {
719
- common: {
720
- issues: [],
721
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
722
- async: true,
112
+ getOwnPropertyDescriptor() {
113
+ return {
114
+ enumerable: true,
115
+ configurable: true,
116
+ };
723
117
  },
724
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
725
- schemaErrorMap: this._def.errorMap,
726
- parent: null,
727
- data,
728
- parsedType: getParsedType(data),
729
- };
730
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
731
- const result = await (isAsync(maybeAsyncResult)
732
- ? maybeAsyncResult
733
- : Promise.resolve(maybeAsyncResult));
734
- return handleResult(ctx, result);
735
- }
736
- refine(check, message) {
737
- const getIssueProperties = (val) => {
738
- if (typeof message === "string" || typeof message === "undefined") {
739
- return { message };
740
- }
741
- else if (typeof message === "function") {
742
- return message(val);
743
- }
744
- else {
745
- return message;
746
- }
747
- };
748
- return this._refinement((val, ctx) => {
749
- const result = check(val);
750
- const setError = () => ctx.addIssue({
751
- code: ZodIssueCode.custom,
752
- ...getIssueProperties(val),
753
- });
754
- if (typeof Promise !== "undefined" && result instanceof Promise) {
755
- return result.then((data) => {
756
- if (!data) {
757
- setError();
758
- return false;
759
- }
760
- else {
761
- return true;
762
- }
763
- });
764
- }
765
- if (!result) {
766
- setError();
767
- return false;
768
- }
769
- else {
770
- return true;
771
- }
772
- });
773
- }
774
- refinement(check, refinementData) {
775
- return this._refinement((val, ctx) => {
776
- if (!check(val)) {
777
- ctx.addIssue(typeof refinementData === "function"
778
- ? refinementData(val, ctx)
779
- : refinementData);
780
- return false;
781
- }
782
- else {
118
+ has(_, propName) {
119
+ return states.has(propName);
120
+ },
121
+ set(_, propName, value) {
122
+ set(propName, value);
783
123
  return true;
124
+ },
125
+ }));
126
+ const on = (eventName, callback) => {
127
+ handlers[eventName].push(callback);
128
+ return () => {
129
+ removeFromArray(handlers[eventName], callback);
130
+ };
131
+ };
132
+ const onChange = (propName, cb) => {
133
+ const unSet = on('set', (key, newValue) => {
134
+ if (key === propName) {
135
+ cb(newValue);
784
136
  }
785
137
  });
786
- }
787
- _refinement(refinement) {
788
- return new ZodEffects({
789
- schema: this,
790
- typeName: ZodFirstPartyTypeKind.ZodEffects,
791
- effect: { type: "refinement", refinement },
792
- });
793
- }
794
- superRefine(refinement) {
795
- return this._refinement(refinement);
796
- }
797
- optional() {
798
- return ZodOptional.create(this, this._def);
799
- }
800
- nullable() {
801
- return ZodNullable.create(this, this._def);
802
- }
803
- nullish() {
804
- return this.nullable().optional();
805
- }
806
- array() {
807
- return ZodArray.create(this, this._def);
808
- }
809
- promise() {
810
- return ZodPromise.create(this, this._def);
811
- }
812
- or(option) {
813
- return ZodUnion.create([this, option], this._def);
814
- }
815
- and(incoming) {
816
- return ZodIntersection.create(this, incoming, this._def);
817
- }
818
- transform(transform) {
819
- return new ZodEffects({
820
- ...processCreateParams(this._def),
821
- schema: this,
822
- typeName: ZodFirstPartyTypeKind.ZodEffects,
823
- effect: { type: "transform", transform },
824
- });
825
- }
826
- default(def) {
827
- const defaultValueFunc = typeof def === "function" ? def : () => def;
828
- return new ZodDefault({
829
- ...processCreateParams(this._def),
830
- innerType: this,
831
- defaultValue: defaultValueFunc,
832
- typeName: ZodFirstPartyTypeKind.ZodDefault,
833
- });
834
- }
835
- brand() {
836
- return new ZodBranded({
837
- typeName: ZodFirstPartyTypeKind.ZodBranded,
838
- type: this,
839
- ...processCreateParams(this._def),
840
- });
841
- }
842
- catch(def) {
843
- const catchValueFunc = typeof def === "function" ? def : () => def;
844
- return new ZodCatch({
845
- ...processCreateParams(this._def),
846
- innerType: this,
847
- catchValue: catchValueFunc,
848
- typeName: ZodFirstPartyTypeKind.ZodCatch,
849
- });
850
- }
851
- describe(description) {
852
- const This = this.constructor;
853
- return new This({
854
- ...this._def,
855
- description,
856
- });
857
- }
858
- pipe(target) {
859
- return ZodPipeline.create(this, target);
860
- }
861
- readonly() {
862
- return ZodReadonly.create(this);
863
- }
864
- isOptional() {
865
- return this.safeParse(undefined).success;
866
- }
867
- isNullable() {
868
- return this.safeParse(null).success;
869
- }
870
- }
871
- const cuidRegex = /^c[^\s-]{8,}$/i;
872
- const cuid2Regex = /^[0-9a-z]+$/;
873
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
874
- // const uuidRegex =
875
- // /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
876
- const 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;
877
- const nanoidRegex = /^[a-z0-9_-]{21}$/i;
878
- const 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)?)??$/;
879
- // from https://stackoverflow.com/a/46181/1550155
880
- // old version: too slow, didn't support unicode
881
- // const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
882
- //old email regex
883
- // const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
884
- // eslint-disable-next-line
885
- // const emailRegex =
886
- // /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
887
- // const emailRegex =
888
- // /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
889
- // const emailRegex =
890
- // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
891
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
892
- // const emailRegex =
893
- // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
894
- // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
895
- const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
896
- let emojiRegex;
897
- // faster, simpler, safer
898
- const 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])$/;
899
- const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
900
- // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
901
- const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
902
- // simple
903
- // const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
904
- // no leap year validation
905
- // const dateRegexSource = `\\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\\d|2\\d))`;
906
- // with leap year validation
907
- const 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])))`;
908
- const dateRegex = new RegExp(`^${dateRegexSource}$`);
909
- function timeRegexSource(args) {
910
- // let regex = `\\d{2}:\\d{2}:\\d{2}`;
911
- let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
912
- if (args.precision) {
913
- regex = `${regex}\\.\\d{${args.precision}}`;
914
- }
915
- else if (args.precision == null) {
916
- regex = `${regex}(\\.\\d+)?`;
917
- }
918
- return regex;
919
- }
920
- function timeRegex(args) {
921
- return new RegExp(`^${timeRegexSource(args)}$`);
922
- }
923
- // Adapted from https://stackoverflow.com/a/3143231
924
- function datetimeRegex(args) {
925
- let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
926
- const opts = [];
927
- opts.push(args.local ? `Z?` : `Z`);
928
- if (args.offset)
929
- opts.push(`([+-]\\d{2}:?\\d{2})`);
930
- regex = `${regex}(${opts.join("|")})`;
931
- return new RegExp(`^${regex}$`);
932
- }
933
- function isValidIP(ip, version) {
934
- if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
935
- return true;
936
- }
937
- if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
938
- return true;
939
- }
940
- return false;
941
- }
942
- class ZodString extends ZodType {
943
- _parse(input) {
944
- if (this._def.coerce) {
945
- input.data = String(input.data);
946
- }
947
- const parsedType = this._getType(input);
948
- if (parsedType !== ZodParsedType.string) {
949
- const ctx = this._getOrReturnCtx(input);
950
- addIssueToContext(ctx, {
951
- code: ZodIssueCode.invalid_type,
952
- expected: ZodParsedType.string,
953
- received: ctx.parsedType,
954
- });
955
- return INVALID;
956
- }
957
- const status = new ParseStatus();
958
- let ctx = undefined;
959
- for (const check of this._def.checks) {
960
- if (check.kind === "min") {
961
- if (input.data.length < check.value) {
962
- ctx = this._getOrReturnCtx(input, ctx);
963
- addIssueToContext(ctx, {
964
- code: ZodIssueCode.too_small,
965
- minimum: check.value,
966
- type: "string",
967
- inclusive: true,
968
- exact: false,
969
- message: check.message,
970
- });
971
- status.dirty();
972
- }
973
- }
974
- else if (check.kind === "max") {
975
- if (input.data.length > check.value) {
976
- ctx = this._getOrReturnCtx(input, ctx);
977
- addIssueToContext(ctx, {
978
- code: ZodIssueCode.too_big,
979
- maximum: check.value,
980
- type: "string",
981
- inclusive: true,
982
- exact: false,
983
- message: check.message,
984
- });
985
- status.dirty();
986
- }
987
- }
988
- else if (check.kind === "length") {
989
- const tooBig = input.data.length > check.value;
990
- const tooSmall = input.data.length < check.value;
991
- if (tooBig || tooSmall) {
992
- ctx = this._getOrReturnCtx(input, ctx);
993
- if (tooBig) {
994
- addIssueToContext(ctx, {
995
- code: ZodIssueCode.too_big,
996
- maximum: check.value,
997
- type: "string",
998
- inclusive: true,
999
- exact: true,
1000
- message: check.message,
1001
- });
1002
- }
1003
- else if (tooSmall) {
1004
- addIssueToContext(ctx, {
1005
- code: ZodIssueCode.too_small,
1006
- minimum: check.value,
1007
- type: "string",
1008
- inclusive: true,
1009
- exact: true,
1010
- message: check.message,
1011
- });
1012
- }
1013
- status.dirty();
1014
- }
1015
- }
1016
- else if (check.kind === "email") {
1017
- if (!emailRegex.test(input.data)) {
1018
- ctx = this._getOrReturnCtx(input, ctx);
1019
- addIssueToContext(ctx, {
1020
- validation: "email",
1021
- code: ZodIssueCode.invalid_string,
1022
- message: check.message,
1023
- });
1024
- status.dirty();
1025
- }
1026
- }
1027
- else if (check.kind === "emoji") {
1028
- if (!emojiRegex) {
1029
- emojiRegex = new RegExp(_emojiRegex, "u");
1030
- }
1031
- if (!emojiRegex.test(input.data)) {
1032
- ctx = this._getOrReturnCtx(input, ctx);
1033
- addIssueToContext(ctx, {
1034
- validation: "emoji",
1035
- code: ZodIssueCode.invalid_string,
1036
- message: check.message,
1037
- });
1038
- status.dirty();
1039
- }
1040
- }
1041
- else if (check.kind === "uuid") {
1042
- if (!uuidRegex.test(input.data)) {
1043
- ctx = this._getOrReturnCtx(input, ctx);
1044
- addIssueToContext(ctx, {
1045
- validation: "uuid",
1046
- code: ZodIssueCode.invalid_string,
1047
- message: check.message,
1048
- });
1049
- status.dirty();
1050
- }
1051
- }
1052
- else if (check.kind === "nanoid") {
1053
- if (!nanoidRegex.test(input.data)) {
1054
- ctx = this._getOrReturnCtx(input, ctx);
1055
- addIssueToContext(ctx, {
1056
- validation: "nanoid",
1057
- code: ZodIssueCode.invalid_string,
1058
- message: check.message,
1059
- });
1060
- status.dirty();
1061
- }
1062
- }
1063
- else if (check.kind === "cuid") {
1064
- if (!cuidRegex.test(input.data)) {
1065
- ctx = this._getOrReturnCtx(input, ctx);
1066
- addIssueToContext(ctx, {
1067
- validation: "cuid",
1068
- code: ZodIssueCode.invalid_string,
1069
- message: check.message,
1070
- });
1071
- status.dirty();
1072
- }
1073
- }
1074
- else if (check.kind === "cuid2") {
1075
- if (!cuid2Regex.test(input.data)) {
1076
- ctx = this._getOrReturnCtx(input, ctx);
1077
- addIssueToContext(ctx, {
1078
- validation: "cuid2",
1079
- code: ZodIssueCode.invalid_string,
1080
- message: check.message,
1081
- });
1082
- status.dirty();
1083
- }
1084
- }
1085
- else if (check.kind === "ulid") {
1086
- if (!ulidRegex.test(input.data)) {
1087
- ctx = this._getOrReturnCtx(input, ctx);
1088
- addIssueToContext(ctx, {
1089
- validation: "ulid",
1090
- code: ZodIssueCode.invalid_string,
1091
- message: check.message,
1092
- });
1093
- status.dirty();
1094
- }
1095
- }
1096
- else if (check.kind === "url") {
1097
- try {
1098
- new URL(input.data);
1099
- }
1100
- catch (_a) {
1101
- ctx = this._getOrReturnCtx(input, ctx);
1102
- addIssueToContext(ctx, {
1103
- validation: "url",
1104
- code: ZodIssueCode.invalid_string,
1105
- message: check.message,
1106
- });
1107
- status.dirty();
1108
- }
1109
- }
1110
- else if (check.kind === "regex") {
1111
- check.regex.lastIndex = 0;
1112
- const testResult = check.regex.test(input.data);
1113
- if (!testResult) {
1114
- ctx = this._getOrReturnCtx(input, ctx);
1115
- addIssueToContext(ctx, {
1116
- validation: "regex",
1117
- code: ZodIssueCode.invalid_string,
1118
- message: check.message,
1119
- });
1120
- status.dirty();
1121
- }
1122
- }
1123
- else if (check.kind === "trim") {
1124
- input.data = input.data.trim();
1125
- }
1126
- else if (check.kind === "includes") {
1127
- if (!input.data.includes(check.value, check.position)) {
1128
- ctx = this._getOrReturnCtx(input, ctx);
1129
- addIssueToContext(ctx, {
1130
- code: ZodIssueCode.invalid_string,
1131
- validation: { includes: check.value, position: check.position },
1132
- message: check.message,
1133
- });
1134
- status.dirty();
1135
- }
1136
- }
1137
- else if (check.kind === "toLowerCase") {
1138
- input.data = input.data.toLowerCase();
1139
- }
1140
- else if (check.kind === "toUpperCase") {
1141
- input.data = input.data.toUpperCase();
1142
- }
1143
- else if (check.kind === "startsWith") {
1144
- if (!input.data.startsWith(check.value)) {
1145
- ctx = this._getOrReturnCtx(input, ctx);
1146
- addIssueToContext(ctx, {
1147
- code: ZodIssueCode.invalid_string,
1148
- validation: { startsWith: check.value },
1149
- message: check.message,
1150
- });
1151
- status.dirty();
1152
- }
1153
- }
1154
- else if (check.kind === "endsWith") {
1155
- if (!input.data.endsWith(check.value)) {
1156
- ctx = this._getOrReturnCtx(input, ctx);
1157
- addIssueToContext(ctx, {
1158
- code: ZodIssueCode.invalid_string,
1159
- validation: { endsWith: check.value },
1160
- message: check.message,
1161
- });
1162
- status.dirty();
1163
- }
1164
- }
1165
- else if (check.kind === "datetime") {
1166
- const regex = datetimeRegex(check);
1167
- if (!regex.test(input.data)) {
1168
- ctx = this._getOrReturnCtx(input, ctx);
1169
- addIssueToContext(ctx, {
1170
- code: ZodIssueCode.invalid_string,
1171
- validation: "datetime",
1172
- message: check.message,
1173
- });
1174
- status.dirty();
1175
- }
1176
- }
1177
- else if (check.kind === "date") {
1178
- const regex = dateRegex;
1179
- if (!regex.test(input.data)) {
1180
- ctx = this._getOrReturnCtx(input, ctx);
1181
- addIssueToContext(ctx, {
1182
- code: ZodIssueCode.invalid_string,
1183
- validation: "date",
1184
- message: check.message,
1185
- });
1186
- status.dirty();
1187
- }
1188
- }
1189
- else if (check.kind === "time") {
1190
- const regex = timeRegex(check);
1191
- if (!regex.test(input.data)) {
1192
- ctx = this._getOrReturnCtx(input, ctx);
1193
- addIssueToContext(ctx, {
1194
- code: ZodIssueCode.invalid_string,
1195
- validation: "time",
1196
- message: check.message,
1197
- });
1198
- status.dirty();
1199
- }
1200
- }
1201
- else if (check.kind === "duration") {
1202
- if (!durationRegex.test(input.data)) {
1203
- ctx = this._getOrReturnCtx(input, ctx);
1204
- addIssueToContext(ctx, {
1205
- validation: "duration",
1206
- code: ZodIssueCode.invalid_string,
1207
- message: check.message,
1208
- });
1209
- status.dirty();
1210
- }
1211
- }
1212
- else if (check.kind === "ip") {
1213
- if (!isValidIP(input.data, check.version)) {
1214
- ctx = this._getOrReturnCtx(input, ctx);
1215
- addIssueToContext(ctx, {
1216
- validation: "ip",
1217
- code: ZodIssueCode.invalid_string,
1218
- message: check.message,
1219
- });
1220
- status.dirty();
1221
- }
1222
- }
1223
- else if (check.kind === "base64") {
1224
- if (!base64Regex.test(input.data)) {
1225
- ctx = this._getOrReturnCtx(input, ctx);
1226
- addIssueToContext(ctx, {
1227
- validation: "base64",
1228
- code: ZodIssueCode.invalid_string,
1229
- message: check.message,
1230
- });
1231
- status.dirty();
1232
- }
138
+ // We need to unwrap the defaultState because it might be a function.
139
+ // Otherwise we might not be sending the right reset value.
140
+ const unReset = on('reset', () => cb(unwrap(defaultState)[propName]));
141
+ return () => {
142
+ unSet();
143
+ unReset();
144
+ };
145
+ };
146
+ const use = (...subscriptions) => {
147
+ const unsubs = subscriptions.reduce((unsubs, subscription) => {
148
+ if (subscription.set) {
149
+ unsubs.push(on('set', subscription.set));
1233
150
  }
1234
- else {
1235
- util.assertNever(check);
151
+ if (subscription.get) {
152
+ unsubs.push(on('get', subscription.get));
1236
153
  }
1237
- }
1238
- return { status: status.value, value: input.data };
1239
- }
1240
- _regex(regex, validation, message) {
1241
- return this.refinement((data) => regex.test(data), {
1242
- validation,
1243
- code: ZodIssueCode.invalid_string,
1244
- ...errorUtil.errToObj(message),
1245
- });
1246
- }
1247
- _addCheck(check) {
1248
- return new ZodString({
1249
- ...this._def,
1250
- checks: [...this._def.checks, check],
1251
- });
1252
- }
1253
- email(message) {
1254
- return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1255
- }
1256
- url(message) {
1257
- return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1258
- }
1259
- emoji(message) {
1260
- return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1261
- }
1262
- uuid(message) {
1263
- return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1264
- }
1265
- nanoid(message) {
1266
- return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1267
- }
1268
- cuid(message) {
1269
- return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1270
- }
1271
- cuid2(message) {
1272
- return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1273
- }
1274
- ulid(message) {
1275
- return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1276
- }
1277
- base64(message) {
1278
- return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1279
- }
1280
- ip(options) {
1281
- return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1282
- }
1283
- datetime(options) {
1284
- var _a, _b;
1285
- if (typeof options === "string") {
1286
- return this._addCheck({
1287
- kind: "datetime",
1288
- precision: null,
1289
- offset: false,
1290
- local: false,
1291
- message: options,
1292
- });
1293
- }
1294
- return this._addCheck({
1295
- kind: "datetime",
1296
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1297
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1298
- local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
1299
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1300
- });
1301
- }
1302
- date(message) {
1303
- return this._addCheck({ kind: "date", message });
1304
- }
1305
- time(options) {
1306
- if (typeof options === "string") {
1307
- return this._addCheck({
1308
- kind: "time",
1309
- precision: null,
1310
- message: options,
1311
- });
1312
- }
1313
- return this._addCheck({
1314
- kind: "time",
1315
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1316
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1317
- });
1318
- }
1319
- duration(message) {
1320
- return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1321
- }
1322
- regex(regex, message) {
1323
- return this._addCheck({
1324
- kind: "regex",
1325
- regex: regex,
1326
- ...errorUtil.errToObj(message),
1327
- });
1328
- }
1329
- includes(value, options) {
1330
- return this._addCheck({
1331
- kind: "includes",
1332
- value: value,
1333
- position: options === null || options === void 0 ? void 0 : options.position,
1334
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1335
- });
1336
- }
1337
- startsWith(value, message) {
1338
- return this._addCheck({
1339
- kind: "startsWith",
1340
- value: value,
1341
- ...errorUtil.errToObj(message),
1342
- });
1343
- }
1344
- endsWith(value, message) {
1345
- return this._addCheck({
1346
- kind: "endsWith",
1347
- value: value,
1348
- ...errorUtil.errToObj(message),
1349
- });
1350
- }
1351
- min(minLength, message) {
1352
- return this._addCheck({
1353
- kind: "min",
1354
- value: minLength,
1355
- ...errorUtil.errToObj(message),
1356
- });
1357
- }
1358
- max(maxLength, message) {
1359
- return this._addCheck({
1360
- kind: "max",
1361
- value: maxLength,
1362
- ...errorUtil.errToObj(message),
1363
- });
1364
- }
1365
- length(len, message) {
1366
- return this._addCheck({
1367
- kind: "length",
1368
- value: len,
1369
- ...errorUtil.errToObj(message),
1370
- });
1371
- }
1372
- /**
1373
- * @deprecated Use z.string().min(1) instead.
1374
- * @see {@link ZodString.min}
1375
- */
1376
- nonempty(message) {
1377
- return this.min(1, errorUtil.errToObj(message));
1378
- }
1379
- trim() {
1380
- return new ZodString({
1381
- ...this._def,
1382
- checks: [...this._def.checks, { kind: "trim" }],
1383
- });
1384
- }
1385
- toLowerCase() {
1386
- return new ZodString({
1387
- ...this._def,
1388
- checks: [...this._def.checks, { kind: "toLowerCase" }],
1389
- });
1390
- }
1391
- toUpperCase() {
1392
- return new ZodString({
1393
- ...this._def,
1394
- checks: [...this._def.checks, { kind: "toUpperCase" }],
1395
- });
1396
- }
1397
- get isDatetime() {
1398
- return !!this._def.checks.find((ch) => ch.kind === "datetime");
1399
- }
1400
- get isDate() {
1401
- return !!this._def.checks.find((ch) => ch.kind === "date");
1402
- }
1403
- get isTime() {
1404
- return !!this._def.checks.find((ch) => ch.kind === "time");
1405
- }
1406
- get isDuration() {
1407
- return !!this._def.checks.find((ch) => ch.kind === "duration");
1408
- }
1409
- get isEmail() {
1410
- return !!this._def.checks.find((ch) => ch.kind === "email");
1411
- }
1412
- get isURL() {
1413
- return !!this._def.checks.find((ch) => ch.kind === "url");
1414
- }
1415
- get isEmoji() {
1416
- return !!this._def.checks.find((ch) => ch.kind === "emoji");
1417
- }
1418
- get isUUID() {
1419
- return !!this._def.checks.find((ch) => ch.kind === "uuid");
1420
- }
1421
- get isNANOID() {
1422
- return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1423
- }
1424
- get isCUID() {
1425
- return !!this._def.checks.find((ch) => ch.kind === "cuid");
1426
- }
1427
- get isCUID2() {
1428
- return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1429
- }
1430
- get isULID() {
1431
- return !!this._def.checks.find((ch) => ch.kind === "ulid");
1432
- }
1433
- get isIP() {
1434
- return !!this._def.checks.find((ch) => ch.kind === "ip");
1435
- }
1436
- get isBase64() {
1437
- return !!this._def.checks.find((ch) => ch.kind === "base64");
1438
- }
1439
- get minLength() {
1440
- let min = null;
1441
- for (const ch of this._def.checks) {
1442
- if (ch.kind === "min") {
1443
- if (min === null || ch.value > min)
1444
- min = ch.value;
154
+ if (subscription.reset) {
155
+ unsubs.push(on('reset', subscription.reset));
1445
156
  }
1446
- }
1447
- return min;
1448
- }
1449
- get maxLength() {
1450
- let max = null;
1451
- for (const ch of this._def.checks) {
1452
- if (ch.kind === "max") {
1453
- if (max === null || ch.value < max)
1454
- max = ch.value;
157
+ if (subscription.dispose) {
158
+ unsubs.push(on('dispose', subscription.dispose));
1455
159
  }
1456
- }
1457
- return max;
1458
- }
1459
- }
1460
- ZodString.create = (params) => {
1461
- var _a;
1462
- return new ZodString({
1463
- checks: [],
1464
- typeName: ZodFirstPartyTypeKind.ZodString,
1465
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1466
- ...processCreateParams(params),
1467
- });
160
+ return unsubs;
161
+ }, []);
162
+ return () => unsubs.forEach((unsub) => unsub());
163
+ };
164
+ const forceUpdate = (key) => {
165
+ const oldValue = states.get(key);
166
+ handlers.set.forEach((cb) => cb(key, oldValue, oldValue));
167
+ };
168
+ return {
169
+ state,
170
+ get,
171
+ set,
172
+ on,
173
+ onChange,
174
+ use,
175
+ dispose,
176
+ reset,
177
+ forceUpdate,
178
+ };
1468
179
  };
1469
- // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
1470
- function floatSafeRemainder(val, step) {
1471
- const valDecCount = (val.toString().split(".")[1] || "").length;
1472
- const stepDecCount = (step.toString().split(".")[1] || "").length;
1473
- const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1474
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
1475
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1476
- return (valInt % stepInt) / Math.pow(10, decCount);
1477
- }
1478
- class ZodNumber extends ZodType {
1479
- constructor() {
1480
- super(...arguments);
1481
- this.min = this.gte;
1482
- this.max = this.lte;
1483
- this.step = this.multipleOf;
180
+ const removeFromArray = (array, item) => {
181
+ const index = array.indexOf(item);
182
+ if (index >= 0) {
183
+ array[index] = array[array.length - 1];
184
+ array.length--;
1484
185
  }
1485
- _parse(input) {
1486
- if (this._def.coerce) {
1487
- input.data = Number(input.data);
1488
- }
1489
- const parsedType = this._getType(input);
1490
- if (parsedType !== ZodParsedType.number) {
1491
- const ctx = this._getOrReturnCtx(input);
1492
- addIssueToContext(ctx, {
1493
- code: ZodIssueCode.invalid_type,
1494
- expected: ZodParsedType.number,
1495
- received: ctx.parsedType,
1496
- });
1497
- return INVALID;
1498
- }
1499
- let ctx = undefined;
1500
- const status = new ParseStatus();
1501
- for (const check of this._def.checks) {
1502
- if (check.kind === "int") {
1503
- if (!util.isInteger(input.data)) {
1504
- ctx = this._getOrReturnCtx(input, ctx);
1505
- addIssueToContext(ctx, {
1506
- code: ZodIssueCode.invalid_type,
1507
- expected: "integer",
1508
- received: "float",
1509
- message: check.message,
1510
- });
1511
- status.dirty();
1512
- }
1513
- }
1514
- else if (check.kind === "min") {
1515
- const tooSmall = check.inclusive
1516
- ? input.data < check.value
1517
- : input.data <= check.value;
1518
- if (tooSmall) {
1519
- ctx = this._getOrReturnCtx(input, ctx);
1520
- addIssueToContext(ctx, {
1521
- code: ZodIssueCode.too_small,
1522
- minimum: check.value,
1523
- type: "number",
1524
- inclusive: check.inclusive,
1525
- exact: false,
1526
- message: check.message,
1527
- });
1528
- status.dirty();
1529
- }
1530
- }
1531
- else if (check.kind === "max") {
1532
- const tooBig = check.inclusive
1533
- ? input.data > check.value
1534
- : input.data >= check.value;
1535
- if (tooBig) {
1536
- ctx = this._getOrReturnCtx(input, ctx);
1537
- addIssueToContext(ctx, {
1538
- code: ZodIssueCode.too_big,
1539
- maximum: check.value,
1540
- type: "number",
1541
- inclusive: check.inclusive,
1542
- exact: false,
1543
- message: check.message,
1544
- });
1545
- status.dirty();
1546
- }
1547
- }
1548
- else if (check.kind === "multipleOf") {
1549
- if (floatSafeRemainder(input.data, check.value) !== 0) {
1550
- ctx = this._getOrReturnCtx(input, ctx);
1551
- addIssueToContext(ctx, {
1552
- code: ZodIssueCode.not_multiple_of,
1553
- multipleOf: check.value,
1554
- message: check.message,
1555
- });
1556
- status.dirty();
1557
- }
1558
- }
1559
- else if (check.kind === "finite") {
1560
- if (!Number.isFinite(input.data)) {
1561
- ctx = this._getOrReturnCtx(input, ctx);
1562
- addIssueToContext(ctx, {
1563
- code: ZodIssueCode.not_finite,
1564
- message: check.message,
1565
- });
1566
- status.dirty();
1567
- }
1568
- }
1569
- else {
1570
- util.assertNever(check);
1571
- }
1572
- }
1573
- return { status: status.value, value: input.data };
1574
- }
1575
- gte(value, message) {
1576
- return this.setLimit("min", value, true, errorUtil.toString(message));
1577
- }
1578
- gt(value, message) {
1579
- return this.setLimit("min", value, false, errorUtil.toString(message));
1580
- }
1581
- lte(value, message) {
1582
- return this.setLimit("max", value, true, errorUtil.toString(message));
1583
- }
1584
- lt(value, message) {
1585
- return this.setLimit("max", value, false, errorUtil.toString(message));
1586
- }
1587
- setLimit(kind, value, inclusive, message) {
1588
- return new ZodNumber({
1589
- ...this._def,
1590
- checks: [
1591
- ...this._def.checks,
1592
- {
1593
- kind,
1594
- value,
1595
- inclusive,
1596
- message: errorUtil.toString(message),
1597
- },
1598
- ],
1599
- });
1600
- }
1601
- _addCheck(check) {
1602
- return new ZodNumber({
1603
- ...this._def,
1604
- checks: [...this._def.checks, check],
1605
- });
1606
- }
1607
- int(message) {
1608
- return this._addCheck({
1609
- kind: "int",
1610
- message: errorUtil.toString(message),
1611
- });
1612
- }
1613
- positive(message) {
1614
- return this._addCheck({
1615
- kind: "min",
1616
- value: 0,
1617
- inclusive: false,
1618
- message: errorUtil.toString(message),
1619
- });
1620
- }
1621
- negative(message) {
1622
- return this._addCheck({
1623
- kind: "max",
1624
- value: 0,
1625
- inclusive: false,
1626
- message: errorUtil.toString(message),
1627
- });
1628
- }
1629
- nonpositive(message) {
1630
- return this._addCheck({
1631
- kind: "max",
1632
- value: 0,
1633
- inclusive: true,
1634
- message: errorUtil.toString(message),
1635
- });
1636
- }
1637
- nonnegative(message) {
1638
- return this._addCheck({
1639
- kind: "min",
1640
- value: 0,
1641
- inclusive: true,
1642
- message: errorUtil.toString(message),
1643
- });
1644
- }
1645
- multipleOf(value, message) {
1646
- return this._addCheck({
1647
- kind: "multipleOf",
1648
- value: value,
1649
- message: errorUtil.toString(message),
1650
- });
1651
- }
1652
- finite(message) {
1653
- return this._addCheck({
1654
- kind: "finite",
1655
- message: errorUtil.toString(message),
1656
- });
1657
- }
1658
- safe(message) {
1659
- return this._addCheck({
1660
- kind: "min",
1661
- inclusive: true,
1662
- value: Number.MIN_SAFE_INTEGER,
1663
- message: errorUtil.toString(message),
1664
- })._addCheck({
1665
- kind: "max",
1666
- inclusive: true,
1667
- value: Number.MAX_SAFE_INTEGER,
1668
- message: errorUtil.toString(message),
1669
- });
1670
- }
1671
- get minValue() {
1672
- let min = null;
1673
- for (const ch of this._def.checks) {
1674
- if (ch.kind === "min") {
1675
- if (min === null || ch.value > min)
1676
- min = ch.value;
1677
- }
1678
- }
1679
- return min;
1680
- }
1681
- get maxValue() {
1682
- let max = null;
1683
- for (const ch of this._def.checks) {
1684
- if (ch.kind === "max") {
1685
- if (max === null || ch.value < max)
1686
- max = ch.value;
1687
- }
1688
- }
1689
- return max;
1690
- }
1691
- get isInt() {
1692
- return !!this._def.checks.find((ch) => ch.kind === "int" ||
1693
- (ch.kind === "multipleOf" && util.isInteger(ch.value)));
1694
- }
1695
- get isFinite() {
1696
- let max = null, min = null;
1697
- for (const ch of this._def.checks) {
1698
- if (ch.kind === "finite" ||
1699
- ch.kind === "int" ||
1700
- ch.kind === "multipleOf") {
1701
- return true;
1702
- }
1703
- else if (ch.kind === "min") {
1704
- if (min === null || ch.value > min)
1705
- min = ch.value;
1706
- }
1707
- else if (ch.kind === "max") {
1708
- if (max === null || ch.value < max)
1709
- max = ch.value;
1710
- }
1711
- }
1712
- return Number.isFinite(min) && Number.isFinite(max);
1713
- }
1714
- }
1715
- ZodNumber.create = (params) => {
1716
- return new ZodNumber({
1717
- checks: [],
1718
- typeName: ZodFirstPartyTypeKind.ZodNumber,
1719
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1720
- ...processCreateParams(params),
1721
- });
1722
186
  };
1723
- class ZodBigInt extends ZodType {
1724
- constructor() {
1725
- super(...arguments);
1726
- this.min = this.gte;
1727
- this.max = this.lte;
1728
- }
1729
- _parse(input) {
1730
- if (this._def.coerce) {
1731
- input.data = BigInt(input.data);
1732
- }
1733
- const parsedType = this._getType(input);
1734
- if (parsedType !== ZodParsedType.bigint) {
1735
- const ctx = this._getOrReturnCtx(input);
1736
- addIssueToContext(ctx, {
1737
- code: ZodIssueCode.invalid_type,
1738
- expected: ZodParsedType.bigint,
1739
- received: ctx.parsedType,
1740
- });
1741
- return INVALID;
1742
- }
1743
- let ctx = undefined;
1744
- const status = new ParseStatus();
1745
- for (const check of this._def.checks) {
1746
- if (check.kind === "min") {
1747
- const tooSmall = check.inclusive
1748
- ? input.data < check.value
1749
- : input.data <= check.value;
1750
- if (tooSmall) {
1751
- ctx = this._getOrReturnCtx(input, ctx);
1752
- addIssueToContext(ctx, {
1753
- code: ZodIssueCode.too_small,
1754
- type: "bigint",
1755
- minimum: check.value,
1756
- inclusive: check.inclusive,
1757
- message: check.message,
1758
- });
1759
- status.dirty();
1760
- }
1761
- }
1762
- else if (check.kind === "max") {
1763
- const tooBig = check.inclusive
1764
- ? input.data > check.value
1765
- : input.data >= check.value;
1766
- if (tooBig) {
1767
- ctx = this._getOrReturnCtx(input, ctx);
1768
- addIssueToContext(ctx, {
1769
- code: ZodIssueCode.too_big,
1770
- type: "bigint",
1771
- maximum: check.value,
1772
- inclusive: check.inclusive,
1773
- message: check.message,
1774
- });
1775
- status.dirty();
1776
- }
1777
- }
1778
- else if (check.kind === "multipleOf") {
1779
- if (input.data % check.value !== BigInt(0)) {
1780
- ctx = this._getOrReturnCtx(input, ctx);
1781
- addIssueToContext(ctx, {
1782
- code: ZodIssueCode.not_multiple_of,
1783
- multipleOf: check.value,
1784
- message: check.message,
1785
- });
1786
- status.dirty();
1787
- }
1788
- }
1789
- else {
1790
- util.assertNever(check);
1791
- }
1792
- }
1793
- return { status: status.value, value: input.data };
1794
- }
1795
- gte(value, message) {
1796
- return this.setLimit("min", value, true, errorUtil.toString(message));
1797
- }
1798
- gt(value, message) {
1799
- return this.setLimit("min", value, false, errorUtil.toString(message));
1800
- }
1801
- lte(value, message) {
1802
- return this.setLimit("max", value, true, errorUtil.toString(message));
1803
- }
1804
- lt(value, message) {
1805
- return this.setLimit("max", value, false, errorUtil.toString(message));
1806
- }
1807
- setLimit(kind, value, inclusive, message) {
1808
- return new ZodBigInt({
1809
- ...this._def,
1810
- checks: [
1811
- ...this._def.checks,
1812
- {
1813
- kind,
1814
- value,
1815
- inclusive,
1816
- message: errorUtil.toString(message),
1817
- },
1818
- ],
1819
- });
1820
- }
1821
- _addCheck(check) {
1822
- return new ZodBigInt({
1823
- ...this._def,
1824
- checks: [...this._def.checks, check],
1825
- });
1826
- }
1827
- positive(message) {
1828
- return this._addCheck({
1829
- kind: "min",
1830
- value: BigInt(0),
1831
- inclusive: false,
1832
- message: errorUtil.toString(message),
1833
- });
1834
- }
1835
- negative(message) {
1836
- return this._addCheck({
1837
- kind: "max",
1838
- value: BigInt(0),
1839
- inclusive: false,
1840
- message: errorUtil.toString(message),
1841
- });
1842
- }
1843
- nonpositive(message) {
1844
- return this._addCheck({
1845
- kind: "max",
1846
- value: BigInt(0),
1847
- inclusive: true,
1848
- message: errorUtil.toString(message),
1849
- });
1850
- }
1851
- nonnegative(message) {
1852
- return this._addCheck({
1853
- kind: "min",
1854
- value: BigInt(0),
1855
- inclusive: true,
1856
- message: errorUtil.toString(message),
1857
- });
1858
- }
1859
- multipleOf(value, message) {
1860
- return this._addCheck({
1861
- kind: "multipleOf",
1862
- value,
1863
- message: errorUtil.toString(message),
1864
- });
1865
- }
1866
- get minValue() {
1867
- let min = null;
1868
- for (const ch of this._def.checks) {
1869
- if (ch.kind === "min") {
1870
- if (min === null || ch.value > min)
1871
- min = ch.value;
1872
- }
1873
- }
1874
- return min;
1875
- }
1876
- get maxValue() {
1877
- let max = null;
1878
- for (const ch of this._def.checks) {
1879
- if (ch.kind === "max") {
1880
- if (max === null || ch.value < max)
1881
- max = ch.value;
1882
- }
1883
- }
1884
- return max;
1885
- }
1886
- }
1887
- ZodBigInt.create = (params) => {
1888
- var _a;
1889
- return new ZodBigInt({
1890
- checks: [],
1891
- typeName: ZodFirstPartyTypeKind.ZodBigInt,
1892
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1893
- ...processCreateParams(params),
1894
- });
1895
- };
1896
- class ZodBoolean extends ZodType {
1897
- _parse(input) {
1898
- if (this._def.coerce) {
1899
- input.data = Boolean(input.data);
1900
- }
1901
- const parsedType = this._getType(input);
1902
- if (parsedType !== ZodParsedType.boolean) {
1903
- const ctx = this._getOrReturnCtx(input);
1904
- addIssueToContext(ctx, {
1905
- code: ZodIssueCode.invalid_type,
1906
- expected: ZodParsedType.boolean,
1907
- received: ctx.parsedType,
1908
- });
1909
- return INVALID;
1910
- }
1911
- return OK(input.data);
1912
- }
1913
- }
1914
- ZodBoolean.create = (params) => {
1915
- return new ZodBoolean({
1916
- typeName: ZodFirstPartyTypeKind.ZodBoolean,
1917
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1918
- ...processCreateParams(params),
1919
- });
1920
- };
1921
- class ZodDate extends ZodType {
1922
- _parse(input) {
1923
- if (this._def.coerce) {
1924
- input.data = new Date(input.data);
1925
- }
1926
- const parsedType = this._getType(input);
1927
- if (parsedType !== ZodParsedType.date) {
1928
- const ctx = this._getOrReturnCtx(input);
1929
- addIssueToContext(ctx, {
1930
- code: ZodIssueCode.invalid_type,
1931
- expected: ZodParsedType.date,
1932
- received: ctx.parsedType,
1933
- });
1934
- return INVALID;
1935
- }
1936
- if (isNaN(input.data.getTime())) {
1937
- const ctx = this._getOrReturnCtx(input);
1938
- addIssueToContext(ctx, {
1939
- code: ZodIssueCode.invalid_date,
1940
- });
1941
- return INVALID;
1942
- }
1943
- const status = new ParseStatus();
1944
- let ctx = undefined;
1945
- for (const check of this._def.checks) {
1946
- if (check.kind === "min") {
1947
- if (input.data.getTime() < check.value) {
1948
- ctx = this._getOrReturnCtx(input, ctx);
1949
- addIssueToContext(ctx, {
1950
- code: ZodIssueCode.too_small,
1951
- message: check.message,
1952
- inclusive: true,
1953
- exact: false,
1954
- minimum: check.value,
1955
- type: "date",
1956
- });
1957
- status.dirty();
1958
- }
1959
- }
1960
- else if (check.kind === "max") {
1961
- if (input.data.getTime() > check.value) {
1962
- ctx = this._getOrReturnCtx(input, ctx);
1963
- addIssueToContext(ctx, {
1964
- code: ZodIssueCode.too_big,
1965
- message: check.message,
1966
- inclusive: true,
1967
- exact: false,
1968
- maximum: check.value,
1969
- type: "date",
1970
- });
1971
- status.dirty();
1972
- }
1973
- }
1974
- else {
1975
- util.assertNever(check);
1976
- }
1977
- }
1978
- return {
1979
- status: status.value,
1980
- value: new Date(input.data.getTime()),
1981
- };
1982
- }
1983
- _addCheck(check) {
1984
- return new ZodDate({
1985
- ...this._def,
1986
- checks: [...this._def.checks, check],
1987
- });
1988
- }
1989
- min(minDate, message) {
1990
- return this._addCheck({
1991
- kind: "min",
1992
- value: minDate.getTime(),
1993
- message: errorUtil.toString(message),
1994
- });
1995
- }
1996
- max(maxDate, message) {
1997
- return this._addCheck({
1998
- kind: "max",
1999
- value: maxDate.getTime(),
2000
- message: errorUtil.toString(message),
2001
- });
2002
- }
2003
- get minDate() {
2004
- let min = null;
2005
- for (const ch of this._def.checks) {
2006
- if (ch.kind === "min") {
2007
- if (min === null || ch.value > min)
2008
- min = ch.value;
2009
- }
2010
- }
2011
- return min != null ? new Date(min) : null;
2012
- }
2013
- get maxDate() {
2014
- let max = null;
2015
- for (const ch of this._def.checks) {
2016
- if (ch.kind === "max") {
2017
- if (max === null || ch.value < max)
2018
- max = ch.value;
2019
- }
2020
- }
2021
- return max != null ? new Date(max) : null;
2022
- }
2023
- }
2024
- ZodDate.create = (params) => {
2025
- return new ZodDate({
2026
- checks: [],
2027
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2028
- typeName: ZodFirstPartyTypeKind.ZodDate,
2029
- ...processCreateParams(params),
2030
- });
2031
- };
2032
- class ZodSymbol extends ZodType {
2033
- _parse(input) {
2034
- const parsedType = this._getType(input);
2035
- if (parsedType !== ZodParsedType.symbol) {
2036
- const ctx = this._getOrReturnCtx(input);
2037
- addIssueToContext(ctx, {
2038
- code: ZodIssueCode.invalid_type,
2039
- expected: ZodParsedType.symbol,
2040
- received: ctx.parsedType,
2041
- });
2042
- return INVALID;
2043
- }
2044
- return OK(input.data);
2045
- }
2046
- }
2047
- ZodSymbol.create = (params) => {
2048
- return new ZodSymbol({
2049
- typeName: ZodFirstPartyTypeKind.ZodSymbol,
2050
- ...processCreateParams(params),
2051
- });
2052
- };
2053
- class ZodUndefined extends ZodType {
2054
- _parse(input) {
2055
- const parsedType = this._getType(input);
2056
- if (parsedType !== ZodParsedType.undefined) {
2057
- const ctx = this._getOrReturnCtx(input);
2058
- addIssueToContext(ctx, {
2059
- code: ZodIssueCode.invalid_type,
2060
- expected: ZodParsedType.undefined,
2061
- received: ctx.parsedType,
2062
- });
2063
- return INVALID;
2064
- }
2065
- return OK(input.data);
2066
- }
2067
- }
2068
- ZodUndefined.create = (params) => {
2069
- return new ZodUndefined({
2070
- typeName: ZodFirstPartyTypeKind.ZodUndefined,
2071
- ...processCreateParams(params),
2072
- });
2073
- };
2074
- class ZodNull extends ZodType {
2075
- _parse(input) {
2076
- const parsedType = this._getType(input);
2077
- if (parsedType !== ZodParsedType.null) {
2078
- const ctx = this._getOrReturnCtx(input);
2079
- addIssueToContext(ctx, {
2080
- code: ZodIssueCode.invalid_type,
2081
- expected: ZodParsedType.null,
2082
- received: ctx.parsedType,
2083
- });
2084
- return INVALID;
2085
- }
2086
- return OK(input.data);
2087
- }
2088
- }
2089
- ZodNull.create = (params) => {
2090
- return new ZodNull({
2091
- typeName: ZodFirstPartyTypeKind.ZodNull,
2092
- ...processCreateParams(params),
2093
- });
2094
- };
2095
- class ZodAny extends ZodType {
2096
- constructor() {
2097
- super(...arguments);
2098
- // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
2099
- this._any = true;
2100
- }
2101
- _parse(input) {
2102
- return OK(input.data);
2103
- }
2104
- }
2105
- ZodAny.create = (params) => {
2106
- return new ZodAny({
2107
- typeName: ZodFirstPartyTypeKind.ZodAny,
2108
- ...processCreateParams(params),
2109
- });
2110
- };
2111
- class ZodUnknown extends ZodType {
2112
- constructor() {
2113
- super(...arguments);
2114
- // required
2115
- this._unknown = true;
2116
- }
2117
- _parse(input) {
2118
- return OK(input.data);
2119
- }
2120
- }
2121
- ZodUnknown.create = (params) => {
2122
- return new ZodUnknown({
2123
- typeName: ZodFirstPartyTypeKind.ZodUnknown,
2124
- ...processCreateParams(params),
2125
- });
2126
- };
2127
- class ZodNever extends ZodType {
2128
- _parse(input) {
2129
- const ctx = this._getOrReturnCtx(input);
2130
- addIssueToContext(ctx, {
2131
- code: ZodIssueCode.invalid_type,
2132
- expected: ZodParsedType.never,
2133
- received: ctx.parsedType,
2134
- });
2135
- return INVALID;
2136
- }
2137
- }
2138
- ZodNever.create = (params) => {
2139
- return new ZodNever({
2140
- typeName: ZodFirstPartyTypeKind.ZodNever,
2141
- ...processCreateParams(params),
2142
- });
2143
- };
2144
- class ZodVoid extends ZodType {
2145
- _parse(input) {
2146
- const parsedType = this._getType(input);
2147
- if (parsedType !== ZodParsedType.undefined) {
2148
- const ctx = this._getOrReturnCtx(input);
2149
- addIssueToContext(ctx, {
2150
- code: ZodIssueCode.invalid_type,
2151
- expected: ZodParsedType.void,
2152
- received: ctx.parsedType,
2153
- });
2154
- return INVALID;
2155
- }
2156
- return OK(input.data);
2157
- }
2158
- }
2159
- ZodVoid.create = (params) => {
2160
- return new ZodVoid({
2161
- typeName: ZodFirstPartyTypeKind.ZodVoid,
2162
- ...processCreateParams(params),
2163
- });
2164
- };
2165
- class ZodArray extends ZodType {
2166
- _parse(input) {
2167
- const { ctx, status } = this._processInputParams(input);
2168
- const def = this._def;
2169
- if (ctx.parsedType !== ZodParsedType.array) {
2170
- addIssueToContext(ctx, {
2171
- code: ZodIssueCode.invalid_type,
2172
- expected: ZodParsedType.array,
2173
- received: ctx.parsedType,
2174
- });
2175
- return INVALID;
2176
- }
2177
- if (def.exactLength !== null) {
2178
- const tooBig = ctx.data.length > def.exactLength.value;
2179
- const tooSmall = ctx.data.length < def.exactLength.value;
2180
- if (tooBig || tooSmall) {
2181
- addIssueToContext(ctx, {
2182
- code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2183
- minimum: (tooSmall ? def.exactLength.value : undefined),
2184
- maximum: (tooBig ? def.exactLength.value : undefined),
2185
- type: "array",
2186
- inclusive: true,
2187
- exact: true,
2188
- message: def.exactLength.message,
2189
- });
2190
- status.dirty();
2191
- }
2192
- }
2193
- if (def.minLength !== null) {
2194
- if (ctx.data.length < def.minLength.value) {
2195
- addIssueToContext(ctx, {
2196
- code: ZodIssueCode.too_small,
2197
- minimum: def.minLength.value,
2198
- type: "array",
2199
- inclusive: true,
2200
- exact: false,
2201
- message: def.minLength.message,
2202
- });
2203
- status.dirty();
2204
- }
2205
- }
2206
- if (def.maxLength !== null) {
2207
- if (ctx.data.length > def.maxLength.value) {
2208
- addIssueToContext(ctx, {
2209
- code: ZodIssueCode.too_big,
2210
- maximum: def.maxLength.value,
2211
- type: "array",
2212
- inclusive: true,
2213
- exact: false,
2214
- message: def.maxLength.message,
2215
- });
2216
- status.dirty();
2217
- }
2218
- }
2219
- if (ctx.common.async) {
2220
- return Promise.all([...ctx.data].map((item, i) => {
2221
- return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2222
- })).then((result) => {
2223
- return ParseStatus.mergeArray(status, result);
2224
- });
2225
- }
2226
- const result = [...ctx.data].map((item, i) => {
2227
- return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2228
- });
2229
- return ParseStatus.mergeArray(status, result);
2230
- }
2231
- get element() {
2232
- return this._def.type;
2233
- }
2234
- min(minLength, message) {
2235
- return new ZodArray({
2236
- ...this._def,
2237
- minLength: { value: minLength, message: errorUtil.toString(message) },
2238
- });
2239
- }
2240
- max(maxLength, message) {
2241
- return new ZodArray({
2242
- ...this._def,
2243
- maxLength: { value: maxLength, message: errorUtil.toString(message) },
2244
- });
2245
- }
2246
- length(len, message) {
2247
- return new ZodArray({
2248
- ...this._def,
2249
- exactLength: { value: len, message: errorUtil.toString(message) },
2250
- });
2251
- }
2252
- nonempty(message) {
2253
- return this.min(1, message);
2254
- }
2255
- }
2256
- ZodArray.create = (schema, params) => {
2257
- return new ZodArray({
2258
- type: schema,
2259
- minLength: null,
2260
- maxLength: null,
2261
- exactLength: null,
2262
- typeName: ZodFirstPartyTypeKind.ZodArray,
2263
- ...processCreateParams(params),
2264
- });
2265
- };
2266
- function deepPartialify(schema) {
2267
- if (schema instanceof ZodObject) {
2268
- const newShape = {};
2269
- for (const key in schema.shape) {
2270
- const fieldSchema = schema.shape[key];
2271
- newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2272
- }
2273
- return new ZodObject({
2274
- ...schema._def,
2275
- shape: () => newShape,
2276
- });
2277
- }
2278
- else if (schema instanceof ZodArray) {
2279
- return new ZodArray({
2280
- ...schema._def,
2281
- type: deepPartialify(schema.element),
2282
- });
2283
- }
2284
- else if (schema instanceof ZodOptional) {
2285
- return ZodOptional.create(deepPartialify(schema.unwrap()));
2286
- }
2287
- else if (schema instanceof ZodNullable) {
2288
- return ZodNullable.create(deepPartialify(schema.unwrap()));
2289
- }
2290
- else if (schema instanceof ZodTuple) {
2291
- return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2292
- }
2293
- else {
2294
- return schema;
2295
- }
2296
- }
2297
- class ZodObject extends ZodType {
2298
- constructor() {
2299
- super(...arguments);
2300
- this._cached = null;
2301
- /**
2302
- * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
2303
- * If you want to pass through unknown properties, use `.passthrough()` instead.
2304
- */
2305
- this.nonstrict = this.passthrough;
2306
- // extend<
2307
- // Augmentation extends ZodRawShape,
2308
- // NewOutput extends util.flatten<{
2309
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2310
- // ? Augmentation[k]["_output"]
2311
- // : k extends keyof Output
2312
- // ? Output[k]
2313
- // : never;
2314
- // }>,
2315
- // NewInput extends util.flatten<{
2316
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2317
- // ? Augmentation[k]["_input"]
2318
- // : k extends keyof Input
2319
- // ? Input[k]
2320
- // : never;
2321
- // }>
2322
- // >(
2323
- // augmentation: Augmentation
2324
- // ): ZodObject<
2325
- // extendShape<T, Augmentation>,
2326
- // UnknownKeys,
2327
- // Catchall,
2328
- // NewOutput,
2329
- // NewInput
2330
- // > {
2331
- // return new ZodObject({
2332
- // ...this._def,
2333
- // shape: () => ({
2334
- // ...this._def.shape(),
2335
- // ...augmentation,
2336
- // }),
2337
- // }) as any;
2338
- // }
2339
- /**
2340
- * @deprecated Use `.extend` instead
2341
- * */
2342
- this.augment = this.extend;
2343
- }
2344
- _getCached() {
2345
- if (this._cached !== null)
2346
- return this._cached;
2347
- const shape = this._def.shape();
2348
- const keys = util.objectKeys(shape);
2349
- return (this._cached = { shape, keys });
2350
- }
2351
- _parse(input) {
2352
- const parsedType = this._getType(input);
2353
- if (parsedType !== ZodParsedType.object) {
2354
- const ctx = this._getOrReturnCtx(input);
2355
- addIssueToContext(ctx, {
2356
- code: ZodIssueCode.invalid_type,
2357
- expected: ZodParsedType.object,
2358
- received: ctx.parsedType,
2359
- });
2360
- return INVALID;
2361
- }
2362
- const { status, ctx } = this._processInputParams(input);
2363
- const { shape, keys: shapeKeys } = this._getCached();
2364
- const extraKeys = [];
2365
- if (!(this._def.catchall instanceof ZodNever &&
2366
- this._def.unknownKeys === "strip")) {
2367
- for (const key in ctx.data) {
2368
- if (!shapeKeys.includes(key)) {
2369
- extraKeys.push(key);
2370
- }
2371
- }
2372
- }
2373
- const pairs = [];
2374
- for (const key of shapeKeys) {
2375
- const keyValidator = shape[key];
2376
- const value = ctx.data[key];
2377
- pairs.push({
2378
- key: { status: "valid", value: key },
2379
- value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2380
- alwaysSet: key in ctx.data,
2381
- });
2382
- }
2383
- if (this._def.catchall instanceof ZodNever) {
2384
- const unknownKeys = this._def.unknownKeys;
2385
- if (unknownKeys === "passthrough") {
2386
- for (const key of extraKeys) {
2387
- pairs.push({
2388
- key: { status: "valid", value: key },
2389
- value: { status: "valid", value: ctx.data[key] },
2390
- });
2391
- }
2392
- }
2393
- else if (unknownKeys === "strict") {
2394
- if (extraKeys.length > 0) {
2395
- addIssueToContext(ctx, {
2396
- code: ZodIssueCode.unrecognized_keys,
2397
- keys: extraKeys,
2398
- });
2399
- status.dirty();
2400
- }
2401
- }
2402
- else if (unknownKeys === "strip") ;
2403
- else {
2404
- throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2405
- }
2406
- }
2407
- else {
2408
- // run catchall validation
2409
- const catchall = this._def.catchall;
2410
- for (const key of extraKeys) {
2411
- const value = ctx.data[key];
2412
- pairs.push({
2413
- key: { status: "valid", value: key },
2414
- value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
2415
- ),
2416
- alwaysSet: key in ctx.data,
2417
- });
2418
- }
2419
- }
2420
- if (ctx.common.async) {
2421
- return Promise.resolve()
2422
- .then(async () => {
2423
- const syncPairs = [];
2424
- for (const pair of pairs) {
2425
- const key = await pair.key;
2426
- const value = await pair.value;
2427
- syncPairs.push({
2428
- key,
2429
- value,
2430
- alwaysSet: pair.alwaysSet,
2431
- });
2432
- }
2433
- return syncPairs;
2434
- })
2435
- .then((syncPairs) => {
2436
- return ParseStatus.mergeObjectSync(status, syncPairs);
2437
- });
2438
- }
2439
- else {
2440
- return ParseStatus.mergeObjectSync(status, pairs);
2441
- }
2442
- }
2443
- get shape() {
2444
- return this._def.shape();
2445
- }
2446
- strict(message) {
2447
- return new ZodObject({
2448
- ...this._def,
2449
- unknownKeys: "strict",
2450
- ...(message !== undefined
2451
- ? {
2452
- errorMap: (issue, ctx) => {
2453
- var _a, _b, _c, _d;
2454
- const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
2455
- if (issue.code === "unrecognized_keys")
2456
- return {
2457
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
2458
- };
2459
- return {
2460
- message: defaultError,
2461
- };
2462
- },
2463
- }
2464
- : {}),
2465
- });
2466
- }
2467
- strip() {
2468
- return new ZodObject({
2469
- ...this._def,
2470
- unknownKeys: "strip",
2471
- });
2472
- }
2473
- passthrough() {
2474
- return new ZodObject({
2475
- ...this._def,
2476
- unknownKeys: "passthrough",
2477
- });
2478
- }
2479
- // const AugmentFactory =
2480
- // <Def extends ZodObjectDef>(def: Def) =>
2481
- // <Augmentation extends ZodRawShape>(
2482
- // augmentation: Augmentation
2483
- // ): ZodObject<
2484
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2485
- // Def["unknownKeys"],
2486
- // Def["catchall"]
2487
- // > => {
2488
- // return new ZodObject({
2489
- // ...def,
2490
- // shape: () => ({
2491
- // ...def.shape(),
2492
- // ...augmentation,
2493
- // }),
2494
- // }) as any;
2495
- // };
2496
- extend(augmentation) {
2497
- return new ZodObject({
2498
- ...this._def,
2499
- shape: () => ({
2500
- ...this._def.shape(),
2501
- ...augmentation,
2502
- }),
2503
- });
2504
- }
2505
- /**
2506
- * Prior to zod@1.0.12 there was a bug in the
2507
- * inferred type of merged objects. Please
2508
- * upgrade if you are experiencing issues.
2509
- */
2510
- merge(merging) {
2511
- const merged = new ZodObject({
2512
- unknownKeys: merging._def.unknownKeys,
2513
- catchall: merging._def.catchall,
2514
- shape: () => ({
2515
- ...this._def.shape(),
2516
- ...merging._def.shape(),
2517
- }),
2518
- typeName: ZodFirstPartyTypeKind.ZodObject,
2519
- });
2520
- return merged;
2521
- }
2522
- // merge<
2523
- // Incoming extends AnyZodObject,
2524
- // Augmentation extends Incoming["shape"],
2525
- // NewOutput extends {
2526
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2527
- // ? Augmentation[k]["_output"]
2528
- // : k extends keyof Output
2529
- // ? Output[k]
2530
- // : never;
2531
- // },
2532
- // NewInput extends {
2533
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2534
- // ? Augmentation[k]["_input"]
2535
- // : k extends keyof Input
2536
- // ? Input[k]
2537
- // : never;
2538
- // }
2539
- // >(
2540
- // merging: Incoming
2541
- // ): ZodObject<
2542
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2543
- // Incoming["_def"]["unknownKeys"],
2544
- // Incoming["_def"]["catchall"],
2545
- // NewOutput,
2546
- // NewInput
2547
- // > {
2548
- // const merged: any = new ZodObject({
2549
- // unknownKeys: merging._def.unknownKeys,
2550
- // catchall: merging._def.catchall,
2551
- // shape: () =>
2552
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2553
- // typeName: ZodFirstPartyTypeKind.ZodObject,
2554
- // }) as any;
2555
- // return merged;
2556
- // }
2557
- setKey(key, schema) {
2558
- return this.augment({ [key]: schema });
2559
- }
2560
- // merge<Incoming extends AnyZodObject>(
2561
- // merging: Incoming
2562
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2563
- // ZodObject<
2564
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2565
- // Incoming["_def"]["unknownKeys"],
2566
- // Incoming["_def"]["catchall"]
2567
- // > {
2568
- // // const mergedShape = objectUtil.mergeShapes(
2569
- // // this._def.shape(),
2570
- // // merging._def.shape()
2571
- // // );
2572
- // const merged: any = new ZodObject({
2573
- // unknownKeys: merging._def.unknownKeys,
2574
- // catchall: merging._def.catchall,
2575
- // shape: () =>
2576
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2577
- // typeName: ZodFirstPartyTypeKind.ZodObject,
2578
- // }) as any;
2579
- // return merged;
2580
- // }
2581
- catchall(index) {
2582
- return new ZodObject({
2583
- ...this._def,
2584
- catchall: index,
2585
- });
2586
- }
2587
- pick(mask) {
2588
- const shape = {};
2589
- util.objectKeys(mask).forEach((key) => {
2590
- if (mask[key] && this.shape[key]) {
2591
- shape[key] = this.shape[key];
2592
- }
2593
- });
2594
- return new ZodObject({
2595
- ...this._def,
2596
- shape: () => shape,
2597
- });
2598
- }
2599
- omit(mask) {
2600
- const shape = {};
2601
- util.objectKeys(this.shape).forEach((key) => {
2602
- if (!mask[key]) {
2603
- shape[key] = this.shape[key];
2604
- }
2605
- });
2606
- return new ZodObject({
2607
- ...this._def,
2608
- shape: () => shape,
2609
- });
2610
- }
2611
- /**
2612
- * @deprecated
2613
- */
2614
- deepPartial() {
2615
- return deepPartialify(this);
2616
- }
2617
- partial(mask) {
2618
- const newShape = {};
2619
- util.objectKeys(this.shape).forEach((key) => {
2620
- const fieldSchema = this.shape[key];
2621
- if (mask && !mask[key]) {
2622
- newShape[key] = fieldSchema;
2623
- }
2624
- else {
2625
- newShape[key] = fieldSchema.optional();
2626
- }
2627
- });
2628
- return new ZodObject({
2629
- ...this._def,
2630
- shape: () => newShape,
2631
- });
2632
- }
2633
- required(mask) {
2634
- const newShape = {};
2635
- util.objectKeys(this.shape).forEach((key) => {
2636
- if (mask && !mask[key]) {
2637
- newShape[key] = this.shape[key];
2638
- }
2639
- else {
2640
- const fieldSchema = this.shape[key];
2641
- let newField = fieldSchema;
2642
- while (newField instanceof ZodOptional) {
2643
- newField = newField._def.innerType;
2644
- }
2645
- newShape[key] = newField;
2646
- }
2647
- });
2648
- return new ZodObject({
2649
- ...this._def,
2650
- shape: () => newShape,
2651
- });
2652
- }
2653
- keyof() {
2654
- return createZodEnum(util.objectKeys(this.shape));
2655
- }
2656
- }
2657
- ZodObject.create = (shape, params) => {
2658
- return new ZodObject({
2659
- shape: () => shape,
2660
- unknownKeys: "strip",
2661
- catchall: ZodNever.create(),
2662
- typeName: ZodFirstPartyTypeKind.ZodObject,
2663
- ...processCreateParams(params),
2664
- });
2665
- };
2666
- ZodObject.strictCreate = (shape, params) => {
2667
- return new ZodObject({
2668
- shape: () => shape,
2669
- unknownKeys: "strict",
2670
- catchall: ZodNever.create(),
2671
- typeName: ZodFirstPartyTypeKind.ZodObject,
2672
- ...processCreateParams(params),
2673
- });
2674
- };
2675
- ZodObject.lazycreate = (shape, params) => {
2676
- return new ZodObject({
2677
- shape,
2678
- unknownKeys: "strip",
2679
- catchall: ZodNever.create(),
2680
- typeName: ZodFirstPartyTypeKind.ZodObject,
2681
- ...processCreateParams(params),
2682
- });
2683
- };
2684
- class ZodUnion extends ZodType {
2685
- _parse(input) {
2686
- const { ctx } = this._processInputParams(input);
2687
- const options = this._def.options;
2688
- function handleResults(results) {
2689
- // return first issue-free validation if it exists
2690
- for (const result of results) {
2691
- if (result.result.status === "valid") {
2692
- return result.result;
2693
- }
2694
- }
2695
- for (const result of results) {
2696
- if (result.result.status === "dirty") {
2697
- // add issues from dirty option
2698
- ctx.common.issues.push(...result.ctx.common.issues);
2699
- return result.result;
2700
- }
2701
- }
2702
- // return invalid
2703
- const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2704
- addIssueToContext(ctx, {
2705
- code: ZodIssueCode.invalid_union,
2706
- unionErrors,
2707
- });
2708
- return INVALID;
2709
- }
2710
- if (ctx.common.async) {
2711
- return Promise.all(options.map(async (option) => {
2712
- const childCtx = {
2713
- ...ctx,
2714
- common: {
2715
- ...ctx.common,
2716
- issues: [],
2717
- },
2718
- parent: null,
2719
- };
2720
- return {
2721
- result: await option._parseAsync({
2722
- data: ctx.data,
2723
- path: ctx.path,
2724
- parent: childCtx,
2725
- }),
2726
- ctx: childCtx,
2727
- };
2728
- })).then(handleResults);
2729
- }
2730
- else {
2731
- let dirty = undefined;
2732
- const issues = [];
2733
- for (const option of options) {
2734
- const childCtx = {
2735
- ...ctx,
2736
- common: {
2737
- ...ctx.common,
2738
- issues: [],
2739
- },
2740
- parent: null,
2741
- };
2742
- const result = option._parseSync({
2743
- data: ctx.data,
2744
- path: ctx.path,
2745
- parent: childCtx,
2746
- });
2747
- if (result.status === "valid") {
2748
- return result;
2749
- }
2750
- else if (result.status === "dirty" && !dirty) {
2751
- dirty = { result, ctx: childCtx };
2752
- }
2753
- if (childCtx.common.issues.length) {
2754
- issues.push(childCtx.common.issues);
2755
- }
2756
- }
2757
- if (dirty) {
2758
- ctx.common.issues.push(...dirty.ctx.common.issues);
2759
- return dirty.result;
2760
- }
2761
- const unionErrors = issues.map((issues) => new ZodError(issues));
2762
- addIssueToContext(ctx, {
2763
- code: ZodIssueCode.invalid_union,
2764
- unionErrors,
2765
- });
2766
- return INVALID;
2767
- }
2768
- }
2769
- get options() {
2770
- return this._def.options;
2771
- }
2772
- }
2773
- ZodUnion.create = (types, params) => {
2774
- return new ZodUnion({
2775
- options: types,
2776
- typeName: ZodFirstPartyTypeKind.ZodUnion,
2777
- ...processCreateParams(params),
2778
- });
2779
- };
2780
- /////////////////////////////////////////////////////
2781
- /////////////////////////////////////////////////////
2782
- ////////// //////////
2783
- ////////// ZodDiscriminatedUnion //////////
2784
- ////////// //////////
2785
- /////////////////////////////////////////////////////
2786
- /////////////////////////////////////////////////////
2787
- const getDiscriminator = (type) => {
2788
- if (type instanceof ZodLazy) {
2789
- return getDiscriminator(type.schema);
2790
- }
2791
- else if (type instanceof ZodEffects) {
2792
- return getDiscriminator(type.innerType());
2793
- }
2794
- else if (type instanceof ZodLiteral) {
2795
- return [type.value];
2796
- }
2797
- else if (type instanceof ZodEnum) {
2798
- return type.options;
2799
- }
2800
- else if (type instanceof ZodNativeEnum) {
2801
- // eslint-disable-next-line ban/ban
2802
- return util.objectValues(type.enum);
2803
- }
2804
- else if (type instanceof ZodDefault) {
2805
- return getDiscriminator(type._def.innerType);
2806
- }
2807
- else if (type instanceof ZodUndefined) {
2808
- return [undefined];
2809
- }
2810
- else if (type instanceof ZodNull) {
2811
- return [null];
2812
- }
2813
- else if (type instanceof ZodOptional) {
2814
- return [undefined, ...getDiscriminator(type.unwrap())];
2815
- }
2816
- else if (type instanceof ZodNullable) {
2817
- return [null, ...getDiscriminator(type.unwrap())];
2818
- }
2819
- else if (type instanceof ZodBranded) {
2820
- return getDiscriminator(type.unwrap());
2821
- }
2822
- else if (type instanceof ZodReadonly) {
2823
- return getDiscriminator(type.unwrap());
2824
- }
2825
- else if (type instanceof ZodCatch) {
2826
- return getDiscriminator(type._def.innerType);
2827
- }
2828
- else {
2829
- return [];
2830
- }
2831
- };
2832
- class ZodDiscriminatedUnion extends ZodType {
2833
- _parse(input) {
2834
- const { ctx } = this._processInputParams(input);
2835
- if (ctx.parsedType !== ZodParsedType.object) {
2836
- addIssueToContext(ctx, {
2837
- code: ZodIssueCode.invalid_type,
2838
- expected: ZodParsedType.object,
2839
- received: ctx.parsedType,
2840
- });
2841
- return INVALID;
2842
- }
2843
- const discriminator = this.discriminator;
2844
- const discriminatorValue = ctx.data[discriminator];
2845
- const option = this.optionsMap.get(discriminatorValue);
2846
- if (!option) {
2847
- addIssueToContext(ctx, {
2848
- code: ZodIssueCode.invalid_union_discriminator,
2849
- options: Array.from(this.optionsMap.keys()),
2850
- path: [discriminator],
2851
- });
2852
- return INVALID;
2853
- }
2854
- if (ctx.common.async) {
2855
- return option._parseAsync({
2856
- data: ctx.data,
2857
- path: ctx.path,
2858
- parent: ctx,
2859
- });
2860
- }
2861
- else {
2862
- return option._parseSync({
2863
- data: ctx.data,
2864
- path: ctx.path,
2865
- parent: ctx,
2866
- });
2867
- }
2868
- }
2869
- get discriminator() {
2870
- return this._def.discriminator;
2871
- }
2872
- get options() {
2873
- return this._def.options;
2874
- }
2875
- get optionsMap() {
2876
- return this._def.optionsMap;
2877
- }
2878
- /**
2879
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2880
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2881
- * have a different value for each object in the union.
2882
- * @param discriminator the name of the discriminator property
2883
- * @param types an array of object schemas
2884
- * @param params
2885
- */
2886
- static create(discriminator, options, params) {
2887
- // Get all the valid discriminator values
2888
- const optionsMap = new Map();
2889
- // try {
2890
- for (const type of options) {
2891
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2892
- if (!discriminatorValues.length) {
2893
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
2894
- }
2895
- for (const value of discriminatorValues) {
2896
- if (optionsMap.has(value)) {
2897
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
2898
- }
2899
- optionsMap.set(value, type);
2900
- }
2901
- }
2902
- return new ZodDiscriminatedUnion({
2903
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2904
- discriminator,
2905
- options,
2906
- optionsMap,
2907
- ...processCreateParams(params),
2908
- });
2909
- }
2910
- }
2911
- function mergeValues(a, b) {
2912
- const aType = getParsedType(a);
2913
- const bType = getParsedType(b);
2914
- if (a === b) {
2915
- return { valid: true, data: a };
2916
- }
2917
- else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2918
- const bKeys = util.objectKeys(b);
2919
- const sharedKeys = util
2920
- .objectKeys(a)
2921
- .filter((key) => bKeys.indexOf(key) !== -1);
2922
- const newObj = { ...a, ...b };
2923
- for (const key of sharedKeys) {
2924
- const sharedValue = mergeValues(a[key], b[key]);
2925
- if (!sharedValue.valid) {
2926
- return { valid: false };
2927
- }
2928
- newObj[key] = sharedValue.data;
2929
- }
2930
- return { valid: true, data: newObj };
2931
- }
2932
- else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2933
- if (a.length !== b.length) {
2934
- return { valid: false };
2935
- }
2936
- const newArray = [];
2937
- for (let index = 0; index < a.length; index++) {
2938
- const itemA = a[index];
2939
- const itemB = b[index];
2940
- const sharedValue = mergeValues(itemA, itemB);
2941
- if (!sharedValue.valid) {
2942
- return { valid: false };
2943
- }
2944
- newArray.push(sharedValue.data);
2945
- }
2946
- return { valid: true, data: newArray };
2947
- }
2948
- else if (aType === ZodParsedType.date &&
2949
- bType === ZodParsedType.date &&
2950
- +a === +b) {
2951
- return { valid: true, data: a };
2952
- }
2953
- else {
2954
- return { valid: false };
2955
- }
2956
- }
2957
- class ZodIntersection extends ZodType {
2958
- _parse(input) {
2959
- const { status, ctx } = this._processInputParams(input);
2960
- const handleParsed = (parsedLeft, parsedRight) => {
2961
- if (isAborted(parsedLeft) || isAborted(parsedRight)) {
2962
- return INVALID;
2963
- }
2964
- const merged = mergeValues(parsedLeft.value, parsedRight.value);
2965
- if (!merged.valid) {
2966
- addIssueToContext(ctx, {
2967
- code: ZodIssueCode.invalid_intersection_types,
2968
- });
2969
- return INVALID;
2970
- }
2971
- if (isDirty(parsedLeft) || isDirty(parsedRight)) {
2972
- status.dirty();
2973
- }
2974
- return { status: status.value, value: merged.data };
2975
- };
2976
- if (ctx.common.async) {
2977
- return Promise.all([
2978
- this._def.left._parseAsync({
2979
- data: ctx.data,
2980
- path: ctx.path,
2981
- parent: ctx,
2982
- }),
2983
- this._def.right._parseAsync({
2984
- data: ctx.data,
2985
- path: ctx.path,
2986
- parent: ctx,
2987
- }),
2988
- ]).then(([left, right]) => handleParsed(left, right));
2989
- }
2990
- else {
2991
- return handleParsed(this._def.left._parseSync({
2992
- data: ctx.data,
2993
- path: ctx.path,
2994
- parent: ctx,
2995
- }), this._def.right._parseSync({
2996
- data: ctx.data,
2997
- path: ctx.path,
2998
- parent: ctx,
2999
- }));
3000
- }
3001
- }
3002
- }
3003
- ZodIntersection.create = (left, right, params) => {
3004
- return new ZodIntersection({
3005
- left: left,
3006
- right: right,
3007
- typeName: ZodFirstPartyTypeKind.ZodIntersection,
3008
- ...processCreateParams(params),
3009
- });
3010
- };
3011
- class ZodTuple extends ZodType {
3012
- _parse(input) {
3013
- const { status, ctx } = this._processInputParams(input);
3014
- if (ctx.parsedType !== ZodParsedType.array) {
3015
- addIssueToContext(ctx, {
3016
- code: ZodIssueCode.invalid_type,
3017
- expected: ZodParsedType.array,
3018
- received: ctx.parsedType,
3019
- });
3020
- return INVALID;
3021
- }
3022
- if (ctx.data.length < this._def.items.length) {
3023
- addIssueToContext(ctx, {
3024
- code: ZodIssueCode.too_small,
3025
- minimum: this._def.items.length,
3026
- inclusive: true,
3027
- exact: false,
3028
- type: "array",
3029
- });
3030
- return INVALID;
3031
- }
3032
- const rest = this._def.rest;
3033
- if (!rest && ctx.data.length > this._def.items.length) {
3034
- addIssueToContext(ctx, {
3035
- code: ZodIssueCode.too_big,
3036
- maximum: this._def.items.length,
3037
- inclusive: true,
3038
- exact: false,
3039
- type: "array",
3040
- });
3041
- status.dirty();
3042
- }
3043
- const items = [...ctx.data]
3044
- .map((item, itemIndex) => {
3045
- const schema = this._def.items[itemIndex] || this._def.rest;
3046
- if (!schema)
3047
- return null;
3048
- return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
3049
- })
3050
- .filter((x) => !!x); // filter nulls
3051
- if (ctx.common.async) {
3052
- return Promise.all(items).then((results) => {
3053
- return ParseStatus.mergeArray(status, results);
3054
- });
3055
- }
3056
- else {
3057
- return ParseStatus.mergeArray(status, items);
3058
- }
3059
- }
3060
- get items() {
3061
- return this._def.items;
3062
- }
3063
- rest(rest) {
3064
- return new ZodTuple({
3065
- ...this._def,
3066
- rest,
3067
- });
3068
- }
3069
- }
3070
- ZodTuple.create = (schemas, params) => {
3071
- if (!Array.isArray(schemas)) {
3072
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
3073
- }
3074
- return new ZodTuple({
3075
- items: schemas,
3076
- typeName: ZodFirstPartyTypeKind.ZodTuple,
3077
- rest: null,
3078
- ...processCreateParams(params),
3079
- });
3080
- };
3081
- class ZodRecord extends ZodType {
3082
- get keySchema() {
3083
- return this._def.keyType;
3084
- }
3085
- get valueSchema() {
3086
- return this._def.valueType;
3087
- }
3088
- _parse(input) {
3089
- const { status, ctx } = this._processInputParams(input);
3090
- if (ctx.parsedType !== ZodParsedType.object) {
3091
- addIssueToContext(ctx, {
3092
- code: ZodIssueCode.invalid_type,
3093
- expected: ZodParsedType.object,
3094
- received: ctx.parsedType,
3095
- });
3096
- return INVALID;
3097
- }
3098
- const pairs = [];
3099
- const keyType = this._def.keyType;
3100
- const valueType = this._def.valueType;
3101
- for (const key in ctx.data) {
3102
- pairs.push({
3103
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3104
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3105
- alwaysSet: key in ctx.data,
3106
- });
3107
- }
3108
- if (ctx.common.async) {
3109
- return ParseStatus.mergeObjectAsync(status, pairs);
3110
- }
3111
- else {
3112
- return ParseStatus.mergeObjectSync(status, pairs);
3113
- }
3114
- }
3115
- get element() {
3116
- return this._def.valueType;
3117
- }
3118
- static create(first, second, third) {
3119
- if (second instanceof ZodType) {
3120
- return new ZodRecord({
3121
- keyType: first,
3122
- valueType: second,
3123
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3124
- ...processCreateParams(third),
3125
- });
3126
- }
3127
- return new ZodRecord({
3128
- keyType: ZodString.create(),
3129
- valueType: first,
3130
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3131
- ...processCreateParams(second),
3132
- });
3133
- }
3134
- }
3135
- class ZodMap extends ZodType {
3136
- get keySchema() {
3137
- return this._def.keyType;
3138
- }
3139
- get valueSchema() {
3140
- return this._def.valueType;
3141
- }
3142
- _parse(input) {
3143
- const { status, ctx } = this._processInputParams(input);
3144
- if (ctx.parsedType !== ZodParsedType.map) {
3145
- addIssueToContext(ctx, {
3146
- code: ZodIssueCode.invalid_type,
3147
- expected: ZodParsedType.map,
3148
- received: ctx.parsedType,
3149
- });
3150
- return INVALID;
3151
- }
3152
- const keyType = this._def.keyType;
3153
- const valueType = this._def.valueType;
3154
- const pairs = [...ctx.data.entries()].map(([key, value], index) => {
3155
- return {
3156
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
3157
- value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
3158
- };
3159
- });
3160
- if (ctx.common.async) {
3161
- const finalMap = new Map();
3162
- return Promise.resolve().then(async () => {
3163
- for (const pair of pairs) {
3164
- const key = await pair.key;
3165
- const value = await pair.value;
3166
- if (key.status === "aborted" || value.status === "aborted") {
3167
- return INVALID;
3168
- }
3169
- if (key.status === "dirty" || value.status === "dirty") {
3170
- status.dirty();
3171
- }
3172
- finalMap.set(key.value, value.value);
3173
- }
3174
- return { status: status.value, value: finalMap };
3175
- });
3176
- }
3177
- else {
3178
- const finalMap = new Map();
3179
- for (const pair of pairs) {
3180
- const key = pair.key;
3181
- const value = pair.value;
3182
- if (key.status === "aborted" || value.status === "aborted") {
3183
- return INVALID;
3184
- }
3185
- if (key.status === "dirty" || value.status === "dirty") {
3186
- status.dirty();
3187
- }
3188
- finalMap.set(key.value, value.value);
3189
- }
3190
- return { status: status.value, value: finalMap };
3191
- }
3192
- }
3193
- }
3194
- ZodMap.create = (keyType, valueType, params) => {
3195
- return new ZodMap({
3196
- valueType,
3197
- keyType,
3198
- typeName: ZodFirstPartyTypeKind.ZodMap,
3199
- ...processCreateParams(params),
3200
- });
3201
- };
3202
- class ZodSet extends ZodType {
3203
- _parse(input) {
3204
- const { status, ctx } = this._processInputParams(input);
3205
- if (ctx.parsedType !== ZodParsedType.set) {
3206
- addIssueToContext(ctx, {
3207
- code: ZodIssueCode.invalid_type,
3208
- expected: ZodParsedType.set,
3209
- received: ctx.parsedType,
3210
- });
3211
- return INVALID;
3212
- }
3213
- const def = this._def;
3214
- if (def.minSize !== null) {
3215
- if (ctx.data.size < def.minSize.value) {
3216
- addIssueToContext(ctx, {
3217
- code: ZodIssueCode.too_small,
3218
- minimum: def.minSize.value,
3219
- type: "set",
3220
- inclusive: true,
3221
- exact: false,
3222
- message: def.minSize.message,
3223
- });
3224
- status.dirty();
3225
- }
3226
- }
3227
- if (def.maxSize !== null) {
3228
- if (ctx.data.size > def.maxSize.value) {
3229
- addIssueToContext(ctx, {
3230
- code: ZodIssueCode.too_big,
3231
- maximum: def.maxSize.value,
3232
- type: "set",
3233
- inclusive: true,
3234
- exact: false,
3235
- message: def.maxSize.message,
3236
- });
3237
- status.dirty();
3238
- }
3239
- }
3240
- const valueType = this._def.valueType;
3241
- function finalizeSet(elements) {
3242
- const parsedSet = new Set();
3243
- for (const element of elements) {
3244
- if (element.status === "aborted")
3245
- return INVALID;
3246
- if (element.status === "dirty")
3247
- status.dirty();
3248
- parsedSet.add(element.value);
3249
- }
3250
- return { status: status.value, value: parsedSet };
3251
- }
3252
- const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
3253
- if (ctx.common.async) {
3254
- return Promise.all(elements).then((elements) => finalizeSet(elements));
3255
- }
3256
- else {
3257
- return finalizeSet(elements);
3258
- }
3259
- }
3260
- min(minSize, message) {
3261
- return new ZodSet({
3262
- ...this._def,
3263
- minSize: { value: minSize, message: errorUtil.toString(message) },
3264
- });
3265
- }
3266
- max(maxSize, message) {
3267
- return new ZodSet({
3268
- ...this._def,
3269
- maxSize: { value: maxSize, message: errorUtil.toString(message) },
3270
- });
3271
- }
3272
- size(size, message) {
3273
- return this.min(size, message).max(size, message);
3274
- }
3275
- nonempty(message) {
3276
- return this.min(1, message);
3277
- }
3278
- }
3279
- ZodSet.create = (valueType, params) => {
3280
- return new ZodSet({
3281
- valueType,
3282
- minSize: null,
3283
- maxSize: null,
3284
- typeName: ZodFirstPartyTypeKind.ZodSet,
3285
- ...processCreateParams(params),
3286
- });
3287
- };
3288
- class ZodFunction extends ZodType {
3289
- constructor() {
3290
- super(...arguments);
3291
- this.validate = this.implement;
3292
- }
3293
- _parse(input) {
3294
- const { ctx } = this._processInputParams(input);
3295
- if (ctx.parsedType !== ZodParsedType.function) {
3296
- addIssueToContext(ctx, {
3297
- code: ZodIssueCode.invalid_type,
3298
- expected: ZodParsedType.function,
3299
- received: ctx.parsedType,
3300
- });
3301
- return INVALID;
3302
- }
3303
- function makeArgsIssue(args, error) {
3304
- return makeIssue({
3305
- data: args,
3306
- path: ctx.path,
3307
- errorMaps: [
3308
- ctx.common.contextualErrorMap,
3309
- ctx.schemaErrorMap,
3310
- getErrorMap(),
3311
- errorMap,
3312
- ].filter((x) => !!x),
3313
- issueData: {
3314
- code: ZodIssueCode.invalid_arguments,
3315
- argumentsError: error,
3316
- },
3317
- });
3318
- }
3319
- function makeReturnsIssue(returns, error) {
3320
- return makeIssue({
3321
- data: returns,
3322
- path: ctx.path,
3323
- errorMaps: [
3324
- ctx.common.contextualErrorMap,
3325
- ctx.schemaErrorMap,
3326
- getErrorMap(),
3327
- errorMap,
3328
- ].filter((x) => !!x),
3329
- issueData: {
3330
- code: ZodIssueCode.invalid_return_type,
3331
- returnTypeError: error,
3332
- },
3333
- });
3334
- }
3335
- const params = { errorMap: ctx.common.contextualErrorMap };
3336
- const fn = ctx.data;
3337
- if (this._def.returns instanceof ZodPromise) {
3338
- // Would love a way to avoid disabling this rule, but we need
3339
- // an alias (using an arrow function was what caused 2651).
3340
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3341
- const me = this;
3342
- return OK(async function (...args) {
3343
- const error = new ZodError([]);
3344
- const parsedArgs = await me._def.args
3345
- .parseAsync(args, params)
3346
- .catch((e) => {
3347
- error.addIssue(makeArgsIssue(args, e));
3348
- throw error;
3349
- });
3350
- const result = await Reflect.apply(fn, this, parsedArgs);
3351
- const parsedReturns = await me._def.returns._def.type
3352
- .parseAsync(result, params)
3353
- .catch((e) => {
3354
- error.addIssue(makeReturnsIssue(result, e));
3355
- throw error;
3356
- });
3357
- return parsedReturns;
3358
- });
3359
- }
3360
- else {
3361
- // Would love a way to avoid disabling this rule, but we need
3362
- // an alias (using an arrow function was what caused 2651).
3363
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3364
- const me = this;
3365
- return OK(function (...args) {
3366
- const parsedArgs = me._def.args.safeParse(args, params);
3367
- if (!parsedArgs.success) {
3368
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3369
- }
3370
- const result = Reflect.apply(fn, this, parsedArgs.data);
3371
- const parsedReturns = me._def.returns.safeParse(result, params);
3372
- if (!parsedReturns.success) {
3373
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3374
- }
3375
- return parsedReturns.data;
3376
- });
3377
- }
3378
- }
3379
- parameters() {
3380
- return this._def.args;
3381
- }
3382
- returnType() {
3383
- return this._def.returns;
3384
- }
3385
- args(...items) {
3386
- return new ZodFunction({
3387
- ...this._def,
3388
- args: ZodTuple.create(items).rest(ZodUnknown.create()),
3389
- });
3390
- }
3391
- returns(returnType) {
3392
- return new ZodFunction({
3393
- ...this._def,
3394
- returns: returnType,
3395
- });
3396
- }
3397
- implement(func) {
3398
- const validatedFunc = this.parse(func);
3399
- return validatedFunc;
3400
- }
3401
- strictImplement(func) {
3402
- const validatedFunc = this.parse(func);
3403
- return validatedFunc;
3404
- }
3405
- static create(args, returns, params) {
3406
- return new ZodFunction({
3407
- args: (args
3408
- ? args
3409
- : ZodTuple.create([]).rest(ZodUnknown.create())),
3410
- returns: returns || ZodUnknown.create(),
3411
- typeName: ZodFirstPartyTypeKind.ZodFunction,
3412
- ...processCreateParams(params),
3413
- });
3414
- }
3415
- }
3416
- class ZodLazy extends ZodType {
3417
- get schema() {
3418
- return this._def.getter();
3419
- }
3420
- _parse(input) {
3421
- const { ctx } = this._processInputParams(input);
3422
- const lazySchema = this._def.getter();
3423
- return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3424
- }
3425
- }
3426
- ZodLazy.create = (getter, params) => {
3427
- return new ZodLazy({
3428
- getter: getter,
3429
- typeName: ZodFirstPartyTypeKind.ZodLazy,
3430
- ...processCreateParams(params),
3431
- });
3432
- };
3433
- class ZodLiteral extends ZodType {
3434
- _parse(input) {
3435
- if (input.data !== this._def.value) {
3436
- const ctx = this._getOrReturnCtx(input);
3437
- addIssueToContext(ctx, {
3438
- received: ctx.data,
3439
- code: ZodIssueCode.invalid_literal,
3440
- expected: this._def.value,
3441
- });
3442
- return INVALID;
3443
- }
3444
- return { status: "valid", value: input.data };
3445
- }
3446
- get value() {
3447
- return this._def.value;
3448
- }
3449
- }
3450
- ZodLiteral.create = (value, params) => {
3451
- return new ZodLiteral({
3452
- value: value,
3453
- typeName: ZodFirstPartyTypeKind.ZodLiteral,
3454
- ...processCreateParams(params),
3455
- });
3456
- };
3457
- function createZodEnum(values, params) {
3458
- return new ZodEnum({
3459
- values,
3460
- typeName: ZodFirstPartyTypeKind.ZodEnum,
3461
- ...processCreateParams(params),
3462
- });
3463
- }
3464
- class ZodEnum extends ZodType {
3465
- constructor() {
3466
- super(...arguments);
3467
- _ZodEnum_cache.set(this, void 0);
3468
- }
3469
- _parse(input) {
3470
- if (typeof input.data !== "string") {
3471
- const ctx = this._getOrReturnCtx(input);
3472
- const expectedValues = this._def.values;
3473
- addIssueToContext(ctx, {
3474
- expected: util.joinValues(expectedValues),
3475
- received: ctx.parsedType,
3476
- code: ZodIssueCode.invalid_type,
3477
- });
3478
- return INVALID;
3479
- }
3480
- if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
3481
- __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
3482
- }
3483
- if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
3484
- const ctx = this._getOrReturnCtx(input);
3485
- const expectedValues = this._def.values;
3486
- addIssueToContext(ctx, {
3487
- received: ctx.data,
3488
- code: ZodIssueCode.invalid_enum_value,
3489
- options: expectedValues,
3490
- });
3491
- return INVALID;
3492
- }
3493
- return OK(input.data);
3494
- }
3495
- get options() {
3496
- return this._def.values;
3497
- }
3498
- get enum() {
3499
- const enumValues = {};
3500
- for (const val of this._def.values) {
3501
- enumValues[val] = val;
3502
- }
3503
- return enumValues;
3504
- }
3505
- get Values() {
3506
- const enumValues = {};
3507
- for (const val of this._def.values) {
3508
- enumValues[val] = val;
3509
- }
3510
- return enumValues;
3511
- }
3512
- get Enum() {
3513
- const enumValues = {};
3514
- for (const val of this._def.values) {
3515
- enumValues[val] = val;
3516
- }
3517
- return enumValues;
3518
- }
3519
- extract(values, newDef = this._def) {
3520
- return ZodEnum.create(values, {
3521
- ...this._def,
3522
- ...newDef,
3523
- });
3524
- }
3525
- exclude(values, newDef = this._def) {
3526
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3527
- ...this._def,
3528
- ...newDef,
3529
- });
3530
- }
3531
- }
3532
- _ZodEnum_cache = new WeakMap();
3533
- ZodEnum.create = createZodEnum;
3534
- class ZodNativeEnum extends ZodType {
3535
- constructor() {
3536
- super(...arguments);
3537
- _ZodNativeEnum_cache.set(this, void 0);
3538
- }
3539
- _parse(input) {
3540
- const nativeEnumValues = util.getValidEnumValues(this._def.values);
3541
- const ctx = this._getOrReturnCtx(input);
3542
- if (ctx.parsedType !== ZodParsedType.string &&
3543
- ctx.parsedType !== ZodParsedType.number) {
3544
- const expectedValues = util.objectValues(nativeEnumValues);
3545
- addIssueToContext(ctx, {
3546
- expected: util.joinValues(expectedValues),
3547
- received: ctx.parsedType,
3548
- code: ZodIssueCode.invalid_type,
3549
- });
3550
- return INVALID;
3551
- }
3552
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
3553
- __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
3554
- }
3555
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
3556
- const expectedValues = util.objectValues(nativeEnumValues);
3557
- addIssueToContext(ctx, {
3558
- received: ctx.data,
3559
- code: ZodIssueCode.invalid_enum_value,
3560
- options: expectedValues,
3561
- });
3562
- return INVALID;
3563
- }
3564
- return OK(input.data);
3565
- }
3566
- get enum() {
3567
- return this._def.values;
3568
- }
3569
- }
3570
- _ZodNativeEnum_cache = new WeakMap();
3571
- ZodNativeEnum.create = (values, params) => {
3572
- return new ZodNativeEnum({
3573
- values: values,
3574
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3575
- ...processCreateParams(params),
3576
- });
3577
- };
3578
- class ZodPromise extends ZodType {
3579
- unwrap() {
3580
- return this._def.type;
3581
- }
3582
- _parse(input) {
3583
- const { ctx } = this._processInputParams(input);
3584
- if (ctx.parsedType !== ZodParsedType.promise &&
3585
- ctx.common.async === false) {
3586
- addIssueToContext(ctx, {
3587
- code: ZodIssueCode.invalid_type,
3588
- expected: ZodParsedType.promise,
3589
- received: ctx.parsedType,
3590
- });
3591
- return INVALID;
3592
- }
3593
- const promisified = ctx.parsedType === ZodParsedType.promise
3594
- ? ctx.data
3595
- : Promise.resolve(ctx.data);
3596
- return OK(promisified.then((data) => {
3597
- return this._def.type.parseAsync(data, {
3598
- path: ctx.path,
3599
- errorMap: ctx.common.contextualErrorMap,
3600
- });
3601
- }));
3602
- }
3603
- }
3604
- ZodPromise.create = (schema, params) => {
3605
- return new ZodPromise({
3606
- type: schema,
3607
- typeName: ZodFirstPartyTypeKind.ZodPromise,
3608
- ...processCreateParams(params),
3609
- });
3610
- };
3611
- class ZodEffects extends ZodType {
3612
- innerType() {
3613
- return this._def.schema;
3614
- }
3615
- sourceType() {
3616
- return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
3617
- ? this._def.schema.sourceType()
3618
- : this._def.schema;
3619
- }
3620
- _parse(input) {
3621
- const { status, ctx } = this._processInputParams(input);
3622
- const effect = this._def.effect || null;
3623
- const checkCtx = {
3624
- addIssue: (arg) => {
3625
- addIssueToContext(ctx, arg);
3626
- if (arg.fatal) {
3627
- status.abort();
3628
- }
3629
- else {
3630
- status.dirty();
3631
- }
3632
- },
3633
- get path() {
3634
- return ctx.path;
3635
- },
3636
- };
3637
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3638
- if (effect.type === "preprocess") {
3639
- const processed = effect.transform(ctx.data, checkCtx);
3640
- if (ctx.common.async) {
3641
- return Promise.resolve(processed).then(async (processed) => {
3642
- if (status.value === "aborted")
3643
- return INVALID;
3644
- const result = await this._def.schema._parseAsync({
3645
- data: processed,
3646
- path: ctx.path,
3647
- parent: ctx,
3648
- });
3649
- if (result.status === "aborted")
3650
- return INVALID;
3651
- if (result.status === "dirty")
3652
- return DIRTY(result.value);
3653
- if (status.value === "dirty")
3654
- return DIRTY(result.value);
3655
- return result;
3656
- });
3657
- }
3658
- else {
3659
- if (status.value === "aborted")
3660
- return INVALID;
3661
- const result = this._def.schema._parseSync({
3662
- data: processed,
3663
- path: ctx.path,
3664
- parent: ctx,
3665
- });
3666
- if (result.status === "aborted")
3667
- return INVALID;
3668
- if (result.status === "dirty")
3669
- return DIRTY(result.value);
3670
- if (status.value === "dirty")
3671
- return DIRTY(result.value);
3672
- return result;
3673
- }
3674
- }
3675
- if (effect.type === "refinement") {
3676
- const executeRefinement = (acc) => {
3677
- const result = effect.refinement(acc, checkCtx);
3678
- if (ctx.common.async) {
3679
- return Promise.resolve(result);
3680
- }
3681
- if (result instanceof Promise) {
3682
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3683
- }
3684
- return acc;
3685
- };
3686
- if (ctx.common.async === false) {
3687
- const inner = this._def.schema._parseSync({
3688
- data: ctx.data,
3689
- path: ctx.path,
3690
- parent: ctx,
3691
- });
3692
- if (inner.status === "aborted")
3693
- return INVALID;
3694
- if (inner.status === "dirty")
3695
- status.dirty();
3696
- // return value is ignored
3697
- executeRefinement(inner.value);
3698
- return { status: status.value, value: inner.value };
3699
- }
3700
- else {
3701
- return this._def.schema
3702
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3703
- .then((inner) => {
3704
- if (inner.status === "aborted")
3705
- return INVALID;
3706
- if (inner.status === "dirty")
3707
- status.dirty();
3708
- return executeRefinement(inner.value).then(() => {
3709
- return { status: status.value, value: inner.value };
3710
- });
3711
- });
3712
- }
3713
- }
3714
- if (effect.type === "transform") {
3715
- if (ctx.common.async === false) {
3716
- const base = this._def.schema._parseSync({
3717
- data: ctx.data,
3718
- path: ctx.path,
3719
- parent: ctx,
3720
- });
3721
- if (!isValid(base))
3722
- return base;
3723
- const result = effect.transform(base.value, checkCtx);
3724
- if (result instanceof Promise) {
3725
- throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3726
- }
3727
- return { status: status.value, value: result };
3728
- }
3729
- else {
3730
- return this._def.schema
3731
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3732
- .then((base) => {
3733
- if (!isValid(base))
3734
- return base;
3735
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
3736
- });
3737
- }
3738
- }
3739
- util.assertNever(effect);
3740
- }
3741
- }
3742
- ZodEffects.create = (schema, effect, params) => {
3743
- return new ZodEffects({
3744
- schema,
3745
- typeName: ZodFirstPartyTypeKind.ZodEffects,
3746
- effect,
3747
- ...processCreateParams(params),
3748
- });
3749
- };
3750
- ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3751
- return new ZodEffects({
3752
- schema,
3753
- effect: { type: "preprocess", transform: preprocess },
3754
- typeName: ZodFirstPartyTypeKind.ZodEffects,
3755
- ...processCreateParams(params),
3756
- });
3757
- };
3758
- class ZodOptional extends ZodType {
3759
- _parse(input) {
3760
- const parsedType = this._getType(input);
3761
- if (parsedType === ZodParsedType.undefined) {
3762
- return OK(undefined);
3763
- }
3764
- return this._def.innerType._parse(input);
3765
- }
3766
- unwrap() {
3767
- return this._def.innerType;
3768
- }
3769
- }
3770
- ZodOptional.create = (type, params) => {
3771
- return new ZodOptional({
3772
- innerType: type,
3773
- typeName: ZodFirstPartyTypeKind.ZodOptional,
3774
- ...processCreateParams(params),
3775
- });
3776
- };
3777
- class ZodNullable extends ZodType {
3778
- _parse(input) {
3779
- const parsedType = this._getType(input);
3780
- if (parsedType === ZodParsedType.null) {
3781
- return OK(null);
3782
- }
3783
- return this._def.innerType._parse(input);
3784
- }
3785
- unwrap() {
3786
- return this._def.innerType;
3787
- }
3788
- }
3789
- ZodNullable.create = (type, params) => {
3790
- return new ZodNullable({
3791
- innerType: type,
3792
- typeName: ZodFirstPartyTypeKind.ZodNullable,
3793
- ...processCreateParams(params),
3794
- });
3795
- };
3796
- class ZodDefault extends ZodType {
3797
- _parse(input) {
3798
- const { ctx } = this._processInputParams(input);
3799
- let data = ctx.data;
3800
- if (ctx.parsedType === ZodParsedType.undefined) {
3801
- data = this._def.defaultValue();
3802
- }
3803
- return this._def.innerType._parse({
3804
- data,
3805
- path: ctx.path,
3806
- parent: ctx,
3807
- });
3808
- }
3809
- removeDefault() {
3810
- return this._def.innerType;
3811
- }
3812
- }
3813
- ZodDefault.create = (type, params) => {
3814
- return new ZodDefault({
3815
- innerType: type,
3816
- typeName: ZodFirstPartyTypeKind.ZodDefault,
3817
- defaultValue: typeof params.default === "function"
3818
- ? params.default
3819
- : () => params.default,
3820
- ...processCreateParams(params),
3821
- });
3822
- };
3823
- class ZodCatch extends ZodType {
3824
- _parse(input) {
3825
- const { ctx } = this._processInputParams(input);
3826
- // newCtx is used to not collect issues from inner types in ctx
3827
- const newCtx = {
3828
- ...ctx,
3829
- common: {
3830
- ...ctx.common,
3831
- issues: [],
3832
- },
3833
- };
3834
- const result = this._def.innerType._parse({
3835
- data: newCtx.data,
3836
- path: newCtx.path,
3837
- parent: {
3838
- ...newCtx,
3839
- },
3840
- });
3841
- if (isAsync(result)) {
3842
- return result.then((result) => {
3843
- return {
3844
- status: "valid",
3845
- value: result.status === "valid"
3846
- ? result.value
3847
- : this._def.catchValue({
3848
- get error() {
3849
- return new ZodError(newCtx.common.issues);
3850
- },
3851
- input: newCtx.data,
3852
- }),
3853
- };
3854
- });
3855
- }
3856
- else {
3857
- return {
3858
- status: "valid",
3859
- value: result.status === "valid"
3860
- ? result.value
3861
- : this._def.catchValue({
3862
- get error() {
3863
- return new ZodError(newCtx.common.issues);
3864
- },
3865
- input: newCtx.data,
3866
- }),
3867
- };
3868
- }
3869
- }
3870
- removeCatch() {
3871
- return this._def.innerType;
3872
- }
3873
- }
3874
- ZodCatch.create = (type, params) => {
3875
- return new ZodCatch({
3876
- innerType: type,
3877
- typeName: ZodFirstPartyTypeKind.ZodCatch,
3878
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3879
- ...processCreateParams(params),
3880
- });
3881
- };
3882
- class ZodNaN extends ZodType {
3883
- _parse(input) {
3884
- const parsedType = this._getType(input);
3885
- if (parsedType !== ZodParsedType.nan) {
3886
- const ctx = this._getOrReturnCtx(input);
3887
- addIssueToContext(ctx, {
3888
- code: ZodIssueCode.invalid_type,
3889
- expected: ZodParsedType.nan,
3890
- received: ctx.parsedType,
3891
- });
3892
- return INVALID;
3893
- }
3894
- return { status: "valid", value: input.data };
3895
- }
3896
- }
3897
- ZodNaN.create = (params) => {
3898
- return new ZodNaN({
3899
- typeName: ZodFirstPartyTypeKind.ZodNaN,
3900
- ...processCreateParams(params),
3901
- });
3902
- };
3903
- const BRAND = Symbol("zod_brand");
3904
- class ZodBranded extends ZodType {
3905
- _parse(input) {
3906
- const { ctx } = this._processInputParams(input);
3907
- const data = ctx.data;
3908
- return this._def.type._parse({
3909
- data,
3910
- path: ctx.path,
3911
- parent: ctx,
3912
- });
3913
- }
3914
- unwrap() {
3915
- return this._def.type;
3916
- }
3917
- }
3918
- class ZodPipeline extends ZodType {
3919
- _parse(input) {
3920
- const { status, ctx } = this._processInputParams(input);
3921
- if (ctx.common.async) {
3922
- const handleAsync = async () => {
3923
- const inResult = await this._def.in._parseAsync({
3924
- data: ctx.data,
3925
- path: ctx.path,
3926
- parent: ctx,
3927
- });
3928
- if (inResult.status === "aborted")
3929
- return INVALID;
3930
- if (inResult.status === "dirty") {
3931
- status.dirty();
3932
- return DIRTY(inResult.value);
3933
- }
3934
- else {
3935
- return this._def.out._parseAsync({
3936
- data: inResult.value,
3937
- path: ctx.path,
3938
- parent: ctx,
3939
- });
3940
- }
3941
- };
3942
- return handleAsync();
3943
- }
3944
- else {
3945
- const inResult = this._def.in._parseSync({
3946
- data: ctx.data,
3947
- path: ctx.path,
3948
- parent: ctx,
3949
- });
3950
- if (inResult.status === "aborted")
3951
- return INVALID;
3952
- if (inResult.status === "dirty") {
3953
- status.dirty();
3954
- return {
3955
- status: "dirty",
3956
- value: inResult.value,
3957
- };
3958
- }
3959
- else {
3960
- return this._def.out._parseSync({
3961
- data: inResult.value,
3962
- path: ctx.path,
3963
- parent: ctx,
3964
- });
3965
- }
3966
- }
3967
- }
3968
- static create(a, b) {
3969
- return new ZodPipeline({
3970
- in: a,
3971
- out: b,
3972
- typeName: ZodFirstPartyTypeKind.ZodPipeline,
3973
- });
3974
- }
3975
- }
3976
- class ZodReadonly extends ZodType {
3977
- _parse(input) {
3978
- const result = this._def.innerType._parse(input);
3979
- const freeze = (data) => {
3980
- if (isValid(data)) {
3981
- data.value = Object.freeze(data.value);
3982
- }
3983
- return data;
3984
- };
3985
- return isAsync(result)
3986
- ? result.then((data) => freeze(data))
3987
- : freeze(result);
3988
- }
3989
- unwrap() {
3990
- return this._def.innerType;
3991
- }
3992
- }
3993
- ZodReadonly.create = (type, params) => {
3994
- return new ZodReadonly({
3995
- innerType: type,
3996
- typeName: ZodFirstPartyTypeKind.ZodReadonly,
3997
- ...processCreateParams(params),
3998
- });
3999
- };
4000
- function custom(check, params = {},
4001
- /**
4002
- * @deprecated
4003
- *
4004
- * Pass `fatal` into the params object instead:
4005
- *
4006
- * ```ts
4007
- * z.string().custom((val) => val.length > 5, { fatal: false })
4008
- * ```
4009
- *
4010
- */
4011
- fatal) {
4012
- if (check)
4013
- return ZodAny.create().superRefine((data, ctx) => {
4014
- var _a, _b;
4015
- if (!check(data)) {
4016
- const p = typeof params === "function"
4017
- ? params(data)
4018
- : typeof params === "string"
4019
- ? { message: params }
4020
- : params;
4021
- const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
4022
- const p2 = typeof p === "string" ? { message: p } : p;
4023
- ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
4024
- }
4025
- });
4026
- return ZodAny.create();
4027
- }
4028
- const late = {
4029
- object: ZodObject.lazycreate,
4030
- };
4031
- var ZodFirstPartyTypeKind;
4032
- (function (ZodFirstPartyTypeKind) {
4033
- ZodFirstPartyTypeKind["ZodString"] = "ZodString";
4034
- ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
4035
- ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
4036
- ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
4037
- ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
4038
- ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
4039
- ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
4040
- ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
4041
- ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
4042
- ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
4043
- ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
4044
- ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
4045
- ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
4046
- ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
4047
- ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
4048
- ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
4049
- ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
4050
- ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
4051
- ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
4052
- ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
4053
- ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
4054
- ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
4055
- ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
4056
- ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
4057
- ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
4058
- ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
4059
- ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
4060
- ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
4061
- ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
4062
- ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
4063
- ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
4064
- ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
4065
- ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
4066
- ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
4067
- ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
4068
- ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
4069
- })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4070
- const instanceOfType = (
4071
- // const instanceOfType = <T extends new (...args: any[]) => any>(
4072
- cls, params = {
4073
- message: `Input not instance of ${cls.name}`,
4074
- }) => custom((data) => data instanceof cls, params);
4075
- const stringType = ZodString.create;
4076
- const numberType = ZodNumber.create;
4077
- const nanType = ZodNaN.create;
4078
- const bigIntType = ZodBigInt.create;
4079
- const booleanType = ZodBoolean.create;
4080
- const dateType = ZodDate.create;
4081
- const symbolType = ZodSymbol.create;
4082
- const undefinedType = ZodUndefined.create;
4083
- const nullType = ZodNull.create;
4084
- const anyType = ZodAny.create;
4085
- const unknownType = ZodUnknown.create;
4086
- const neverType = ZodNever.create;
4087
- const voidType = ZodVoid.create;
4088
- const arrayType = ZodArray.create;
4089
- const objectType = ZodObject.create;
4090
- const strictObjectType = ZodObject.strictCreate;
4091
- const unionType = ZodUnion.create;
4092
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
4093
- const intersectionType = ZodIntersection.create;
4094
- const tupleType = ZodTuple.create;
4095
- const recordType = ZodRecord.create;
4096
- const mapType = ZodMap.create;
4097
- const setType = ZodSet.create;
4098
- const functionType = ZodFunction.create;
4099
- const lazyType = ZodLazy.create;
4100
- const literalType = ZodLiteral.create;
4101
- const enumType = ZodEnum.create;
4102
- const nativeEnumType = ZodNativeEnum.create;
4103
- const promiseType = ZodPromise.create;
4104
- const effectsType = ZodEffects.create;
4105
- const optionalType = ZodOptional.create;
4106
- const nullableType = ZodNullable.create;
4107
- const preprocessType = ZodEffects.createWithPreprocess;
4108
- const pipelineType = ZodPipeline.create;
4109
- const ostring = () => stringType().optional();
4110
- const onumber = () => numberType().optional();
4111
- const oboolean = () => booleanType().optional();
4112
- const coerce = {
4113
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4114
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4115
- boolean: ((arg) => ZodBoolean.create({
4116
- ...arg,
4117
- coerce: true,
4118
- })),
4119
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4120
- date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
4121
- };
4122
- const NEVER = INVALID;
4123
187
 
4124
- var z = /*#__PURE__*/Object.freeze({
4125
- __proto__: null,
4126
- defaultErrorMap: errorMap,
4127
- setErrorMap: setErrorMap,
4128
- getErrorMap: getErrorMap,
4129
- makeIssue: makeIssue,
4130
- EMPTY_PATH: EMPTY_PATH,
4131
- addIssueToContext: addIssueToContext,
4132
- ParseStatus: ParseStatus,
4133
- INVALID: INVALID,
4134
- DIRTY: DIRTY,
4135
- OK: OK,
4136
- isAborted: isAborted,
4137
- isDirty: isDirty,
4138
- isValid: isValid,
4139
- isAsync: isAsync,
4140
- get util () { return util; },
4141
- get objectUtil () { return objectUtil; },
4142
- ZodParsedType: ZodParsedType,
4143
- getParsedType: getParsedType,
4144
- ZodType: ZodType,
4145
- datetimeRegex: datetimeRegex,
4146
- ZodString: ZodString,
4147
- ZodNumber: ZodNumber,
4148
- ZodBigInt: ZodBigInt,
4149
- ZodBoolean: ZodBoolean,
4150
- ZodDate: ZodDate,
4151
- ZodSymbol: ZodSymbol,
4152
- ZodUndefined: ZodUndefined,
4153
- ZodNull: ZodNull,
4154
- ZodAny: ZodAny,
4155
- ZodUnknown: ZodUnknown,
4156
- ZodNever: ZodNever,
4157
- ZodVoid: ZodVoid,
4158
- ZodArray: ZodArray,
4159
- ZodObject: ZodObject,
4160
- ZodUnion: ZodUnion,
4161
- ZodDiscriminatedUnion: ZodDiscriminatedUnion,
4162
- ZodIntersection: ZodIntersection,
4163
- ZodTuple: ZodTuple,
4164
- ZodRecord: ZodRecord,
4165
- ZodMap: ZodMap,
4166
- ZodSet: ZodSet,
4167
- ZodFunction: ZodFunction,
4168
- ZodLazy: ZodLazy,
4169
- ZodLiteral: ZodLiteral,
4170
- ZodEnum: ZodEnum,
4171
- ZodNativeEnum: ZodNativeEnum,
4172
- ZodPromise: ZodPromise,
4173
- ZodEffects: ZodEffects,
4174
- ZodTransformer: ZodEffects,
4175
- ZodOptional: ZodOptional,
4176
- ZodNullable: ZodNullable,
4177
- ZodDefault: ZodDefault,
4178
- ZodCatch: ZodCatch,
4179
- ZodNaN: ZodNaN,
4180
- BRAND: BRAND,
4181
- ZodBranded: ZodBranded,
4182
- ZodPipeline: ZodPipeline,
4183
- ZodReadonly: ZodReadonly,
4184
- custom: custom,
4185
- Schema: ZodType,
4186
- ZodSchema: ZodType,
4187
- late: late,
4188
- get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
4189
- coerce: coerce,
4190
- any: anyType,
4191
- array: arrayType,
4192
- bigint: bigIntType,
4193
- boolean: booleanType,
4194
- date: dateType,
4195
- discriminatedUnion: discriminatedUnionType,
4196
- effect: effectsType,
4197
- 'enum': enumType,
4198
- 'function': functionType,
4199
- 'instanceof': instanceOfType,
4200
- intersection: intersectionType,
4201
- lazy: lazyType,
4202
- literal: literalType,
4203
- map: mapType,
4204
- nan: nanType,
4205
- nativeEnum: nativeEnumType,
4206
- never: neverType,
4207
- 'null': nullType,
4208
- nullable: nullableType,
4209
- number: numberType,
4210
- object: objectType,
4211
- oboolean: oboolean,
4212
- onumber: onumber,
4213
- optional: optionalType,
4214
- ostring: ostring,
4215
- pipeline: pipelineType,
4216
- preprocess: preprocessType,
4217
- promise: promiseType,
4218
- record: recordType,
4219
- set: setType,
4220
- strictObject: strictObjectType,
4221
- string: stringType,
4222
- symbol: symbolType,
4223
- transformer: effectsType,
4224
- tuple: tupleType,
4225
- 'undefined': undefinedType,
4226
- union: unionType,
4227
- unknown: unknownType,
4228
- 'void': voidType,
4229
- NEVER: NEVER,
4230
- ZodIssueCode: ZodIssueCode,
4231
- quotelessJson: quotelessJson,
4232
- ZodError: ZodError
4233
- });
188
+ const createStore = (defaultState, shouldUpdate) => {
189
+ const map = createObservableMap(defaultState, shouldUpdate);
190
+ map.use(stencilSubscription());
191
+ return map;
192
+ };
4234
193
 
4235
- export { undefinedType as u, z };
194
+ export { createStore as c };