lkd-web-kit 0.4.3 → 0.4.5

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 (138) hide show
  1. package/dist/hooks/useZodConfig.cjs +21 -0
  2. package/dist/hooks/useZodConfig.js +17 -0
  3. package/dist/index.cjs +2 -0
  4. package/dist/index.d.ts +4 -3
  5. package/dist/index.js +1 -0
  6. package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.cjs +38 -33
  7. package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.js +38 -33
  8. package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.cjs +1 -1
  9. package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.js +1 -1
  10. package/dist/node_modules/zod/v4/classic/coerce.cjs +28 -0
  11. package/dist/node_modules/zod/v4/classic/coerce.js +20 -0
  12. package/dist/node_modules/zod/v4/classic/compat.cjs +37 -0
  13. package/dist/node_modules/zod/v4/classic/compat.js +30 -0
  14. package/dist/node_modules/zod/v4/classic/errors.cjs +49 -0
  15. package/dist/node_modules/zod/v4/classic/errors.js +44 -0
  16. package/dist/node_modules/zod/v4/classic/external.cjs +231 -0
  17. package/dist/node_modules/zod/v4/classic/external.js +28 -0
  18. package/dist/node_modules/zod/v4/classic/index.cjs +10 -0
  19. package/dist/node_modules/zod/v4/classic/index.js +5 -0
  20. package/dist/node_modules/zod/v4/classic/iso.cjs +46 -0
  21. package/dist/node_modules/zod/v4/classic/iso.js +35 -0
  22. package/dist/node_modules/zod/v4/classic/parse.cjs +16 -0
  23. package/dist/node_modules/zod/v4/classic/parse.js +9 -0
  24. package/dist/node_modules/zod/v4/classic/schemas.cjs +1155 -0
  25. package/dist/node_modules/zod/v4/classic/schemas.js +1006 -0
  26. package/dist/node_modules/zod/v4/core/api.cjs +1016 -0
  27. package/dist/node_modules/zod/v4/core/api.js +903 -0
  28. package/dist/node_modules/zod/v4/core/checks.cjs +587 -0
  29. package/dist/node_modules/zod/v4/core/checks.js +562 -0
  30. package/dist/node_modules/zod/v4/core/core.cjs +72 -0
  31. package/dist/node_modules/zod/v4/core/core.js +63 -0
  32. package/dist/node_modules/zod/v4/core/doc.cjs +41 -0
  33. package/dist/node_modules/zod/v4/core/doc.js +37 -0
  34. package/dist/node_modules/zod/v4/core/errors.cjs +204 -0
  35. package/dist/node_modules/zod/v4/core/errors.js +194 -0
  36. package/dist/node_modules/zod/v4/core/function.cjs +81 -0
  37. package/dist/node_modules/zod/v4/core/function.js +76 -0
  38. package/dist/node_modules/zod/v4/core/index.cjs +261 -0
  39. package/dist/node_modules/zod/v4/core/index.js +20 -0
  40. package/dist/node_modules/zod/v4/core/json-schema.cjs +2 -0
  41. package/dist/node_modules/zod/v4/core/json-schema.js +1 -0
  42. package/dist/node_modules/zod/v4/core/parse.cjs +71 -0
  43. package/dist/node_modules/zod/v4/core/parse.js +60 -0
  44. package/dist/node_modules/zod/v4/core/regexes.cjs +139 -0
  45. package/dist/node_modules/zod/v4/core/regexes.js +95 -0
  46. package/dist/node_modules/zod/v4/core/registries.cjs +52 -0
  47. package/dist/node_modules/zod/v4/core/registries.js +44 -0
  48. package/dist/node_modules/zod/v4/core/schemas.cjs +1793 -0
  49. package/dist/node_modules/zod/v4/core/schemas.js +1720 -0
  50. package/dist/node_modules/zod/v4/core/to-json-schema.cjs +823 -0
  51. package/dist/node_modules/zod/v4/core/to-json-schema.js +818 -0
  52. package/dist/node_modules/zod/v4/core/util.cjs +543 -0
  53. package/dist/node_modules/zod/v4/core/util.js +491 -0
  54. package/dist/node_modules/zod/v4/core/versions.cjs +11 -0
  55. package/dist/node_modules/zod/v4/core/versions.js +7 -0
  56. package/dist/node_modules/zod/v4/index.cjs +10 -0
  57. package/dist/node_modules/zod/v4/index.js +5 -0
  58. package/dist/node_modules/zod/v4/locales/ar.cjs +121 -0
  59. package/dist/node_modules/zod/v4/locales/ar.js +119 -0
  60. package/dist/node_modules/zod/v4/locales/az.cjs +120 -0
  61. package/dist/node_modules/zod/v4/locales/az.js +118 -0
  62. package/dist/node_modules/zod/v4/locales/be.cjs +169 -0
  63. package/dist/node_modules/zod/v4/locales/be.js +167 -0
  64. package/dist/node_modules/zod/v4/locales/ca.cjs +123 -0
  65. package/dist/node_modules/zod/v4/locales/ca.js +121 -0
  66. package/dist/node_modules/zod/v4/locales/cs.cjs +140 -0
  67. package/dist/node_modules/zod/v4/locales/cs.js +138 -0
  68. package/dist/node_modules/zod/v4/locales/de.cjs +121 -0
  69. package/dist/node_modules/zod/v4/locales/de.js +119 -0
  70. package/dist/node_modules/zod/v4/locales/en.cjs +125 -0
  71. package/dist/node_modules/zod/v4/locales/en.js +120 -0
  72. package/dist/node_modules/zod/v4/locales/eo.cjs +124 -0
  73. package/dist/node_modules/zod/v4/locales/eo.js +119 -0
  74. package/dist/node_modules/zod/v4/locales/es.cjs +122 -0
  75. package/dist/node_modules/zod/v4/locales/es.js +120 -0
  76. package/dist/node_modules/zod/v4/locales/fa.cjs +127 -0
  77. package/dist/node_modules/zod/v4/locales/fa.js +125 -0
  78. package/dist/node_modules/zod/v4/locales/fi.cjs +127 -0
  79. package/dist/node_modules/zod/v4/locales/fi.js +125 -0
  80. package/dist/node_modules/zod/v4/locales/fr-CA.cjs +122 -0
  81. package/dist/node_modules/zod/v4/locales/fr-CA.js +120 -0
  82. package/dist/node_modules/zod/v4/locales/fr.cjs +121 -0
  83. package/dist/node_modules/zod/v4/locales/fr.js +119 -0
  84. package/dist/node_modules/zod/v4/locales/he.cjs +122 -0
  85. package/dist/node_modules/zod/v4/locales/he.js +120 -0
  86. package/dist/node_modules/zod/v4/locales/hu.cjs +122 -0
  87. package/dist/node_modules/zod/v4/locales/hu.js +120 -0
  88. package/dist/node_modules/zod/v4/locales/id.cjs +121 -0
  89. package/dist/node_modules/zod/v4/locales/id.js +119 -0
  90. package/dist/node_modules/zod/v4/locales/index.cjs +85 -0
  91. package/dist/node_modules/zod/v4/locales/index.js +39 -0
  92. package/dist/node_modules/zod/v4/locales/it.cjs +122 -0
  93. package/dist/node_modules/zod/v4/locales/it.js +120 -0
  94. package/dist/node_modules/zod/v4/locales/ja.cjs +120 -0
  95. package/dist/node_modules/zod/v4/locales/ja.js +118 -0
  96. package/dist/node_modules/zod/v4/locales/kh.cjs +122 -0
  97. package/dist/node_modules/zod/v4/locales/kh.js +120 -0
  98. package/dist/node_modules/zod/v4/locales/ko.cjs +126 -0
  99. package/dist/node_modules/zod/v4/locales/ko.js +124 -0
  100. package/dist/node_modules/zod/v4/locales/mk.cjs +123 -0
  101. package/dist/node_modules/zod/v4/locales/mk.js +121 -0
  102. package/dist/node_modules/zod/v4/locales/ms.cjs +121 -0
  103. package/dist/node_modules/zod/v4/locales/ms.js +119 -0
  104. package/dist/node_modules/zod/v4/locales/nl.cjs +122 -0
  105. package/dist/node_modules/zod/v4/locales/nl.js +120 -0
  106. package/dist/node_modules/zod/v4/locales/no.cjs +121 -0
  107. package/dist/node_modules/zod/v4/locales/no.js +119 -0
  108. package/dist/node_modules/zod/v4/locales/ota.cjs +122 -0
  109. package/dist/node_modules/zod/v4/locales/ota.js +120 -0
  110. package/dist/node_modules/zod/v4/locales/pl.cjs +122 -0
  111. package/dist/node_modules/zod/v4/locales/pl.js +120 -0
  112. package/dist/node_modules/zod/v4/locales/ps.cjs +127 -0
  113. package/dist/node_modules/zod/v4/locales/ps.js +125 -0
  114. package/dist/node_modules/zod/v4/locales/pt.cjs +121 -0
  115. package/dist/node_modules/zod/v4/locales/pt.js +119 -0
  116. package/dist/node_modules/zod/v4/locales/ru.cjs +169 -0
  117. package/dist/node_modules/zod/v4/locales/ru.js +167 -0
  118. package/dist/node_modules/zod/v4/locales/sl.cjs +122 -0
  119. package/dist/node_modules/zod/v4/locales/sl.js +120 -0
  120. package/dist/node_modules/zod/v4/locales/sv.cjs +123 -0
  121. package/dist/node_modules/zod/v4/locales/sv.js +121 -0
  122. package/dist/node_modules/zod/v4/locales/ta.cjs +122 -0
  123. package/dist/node_modules/zod/v4/locales/ta.js +120 -0
  124. package/dist/node_modules/zod/v4/locales/th.cjs +122 -0
  125. package/dist/node_modules/zod/v4/locales/th.js +120 -0
  126. package/dist/node_modules/zod/v4/locales/tr.cjs +123 -0
  127. package/dist/node_modules/zod/v4/locales/tr.js +118 -0
  128. package/dist/node_modules/zod/v4/locales/ua.cjs +122 -0
  129. package/dist/node_modules/zod/v4/locales/ua.js +120 -0
  130. package/dist/node_modules/zod/v4/locales/ur.cjs +122 -0
  131. package/dist/node_modules/zod/v4/locales/ur.js +120 -0
  132. package/dist/node_modules/zod/v4/locales/vi.cjs +121 -0
  133. package/dist/node_modules/zod/v4/locales/vi.js +119 -0
  134. package/dist/node_modules/zod/v4/locales/zh-CN.cjs +121 -0
  135. package/dist/node_modules/zod/v4/locales/zh-CN.js +119 -0
  136. package/dist/node_modules/zod/v4/locales/zh-TW.cjs +122 -0
  137. package/dist/node_modules/zod/v4/locales/zh-TW.js +120 -0
  138. package/package.json +1 -1
@@ -0,0 +1,562 @@
1
+ import { $constructor } from './core.js';
2
+ import { integer, lowercase, uppercase } from './regexes.js';
3
+ import { floatSafeRemainder, NUMBER_FORMAT_RANGES, BIGINT_FORMAT_RANGES, nullish, getSizableOrigin, getLengthableOrigin, escapeRegex, prefixIssues } from './util.js';
4
+
5
+ // import { $ZodType } from "./schemas.js";
6
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
7
+ var _a;
8
+ inst._zod ?? (inst._zod = {});
9
+ inst._zod.def = def;
10
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
11
+ });
12
+ const numericOriginMap = {
13
+ number: "number",
14
+ bigint: "bigint",
15
+ object: "date",
16
+ };
17
+ const $ZodCheckLessThan = /*@__PURE__*/ $constructor("$ZodCheckLessThan", (inst, def) => {
18
+ $ZodCheck.init(inst, def);
19
+ const origin = numericOriginMap[typeof def.value];
20
+ inst._zod.onattach.push((inst) => {
21
+ const bag = inst._zod.bag;
22
+ const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
23
+ if (def.value < curr) {
24
+ if (def.inclusive)
25
+ bag.maximum = def.value;
26
+ else
27
+ bag.exclusiveMaximum = def.value;
28
+ }
29
+ });
30
+ inst._zod.check = (payload) => {
31
+ if (def.inclusive ? payload.value <= def.value : payload.value < def.value) {
32
+ return;
33
+ }
34
+ payload.issues.push({
35
+ origin,
36
+ code: "too_big",
37
+ maximum: def.value,
38
+ input: payload.value,
39
+ inclusive: def.inclusive,
40
+ inst,
41
+ continue: !def.abort,
42
+ });
43
+ };
44
+ });
45
+ const $ZodCheckGreaterThan = /*@__PURE__*/ $constructor("$ZodCheckGreaterThan", (inst, def) => {
46
+ $ZodCheck.init(inst, def);
47
+ const origin = numericOriginMap[typeof def.value];
48
+ inst._zod.onattach.push((inst) => {
49
+ const bag = inst._zod.bag;
50
+ const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
51
+ if (def.value > curr) {
52
+ if (def.inclusive)
53
+ bag.minimum = def.value;
54
+ else
55
+ bag.exclusiveMinimum = def.value;
56
+ }
57
+ });
58
+ inst._zod.check = (payload) => {
59
+ if (def.inclusive ? payload.value >= def.value : payload.value > def.value) {
60
+ return;
61
+ }
62
+ payload.issues.push({
63
+ origin,
64
+ code: "too_small",
65
+ minimum: def.value,
66
+ input: payload.value,
67
+ inclusive: def.inclusive,
68
+ inst,
69
+ continue: !def.abort,
70
+ });
71
+ };
72
+ });
73
+ const $ZodCheckMultipleOf =
74
+ /*@__PURE__*/ $constructor("$ZodCheckMultipleOf", (inst, def) => {
75
+ $ZodCheck.init(inst, def);
76
+ inst._zod.onattach.push((inst) => {
77
+ var _a;
78
+ (_a = inst._zod.bag).multipleOf ?? (_a.multipleOf = def.value);
79
+ });
80
+ inst._zod.check = (payload) => {
81
+ if (typeof payload.value !== typeof def.value)
82
+ throw new Error("Cannot mix number and bigint in multiple_of check.");
83
+ const isMultiple = typeof payload.value === "bigint"
84
+ ? payload.value % def.value === BigInt(0)
85
+ : floatSafeRemainder(payload.value, def.value) === 0;
86
+ if (isMultiple)
87
+ return;
88
+ payload.issues.push({
89
+ origin: typeof payload.value,
90
+ code: "not_multiple_of",
91
+ divisor: def.value,
92
+ input: payload.value,
93
+ inst,
94
+ continue: !def.abort,
95
+ });
96
+ };
97
+ });
98
+ const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat", (inst, def) => {
99
+ $ZodCheck.init(inst, def); // no format checks
100
+ def.format = def.format || "float64";
101
+ const isInt = def.format?.includes("int");
102
+ const origin = isInt ? "int" : "number";
103
+ const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
104
+ inst._zod.onattach.push((inst) => {
105
+ const bag = inst._zod.bag;
106
+ bag.format = def.format;
107
+ bag.minimum = minimum;
108
+ bag.maximum = maximum;
109
+ if (isInt)
110
+ bag.pattern = integer;
111
+ });
112
+ inst._zod.check = (payload) => {
113
+ const input = payload.value;
114
+ if (isInt) {
115
+ if (!Number.isInteger(input)) {
116
+ // invalid_format issue
117
+ // payload.issues.push({
118
+ // expected: def.format,
119
+ // format: def.format,
120
+ // code: "invalid_format",
121
+ // input,
122
+ // inst,
123
+ // });
124
+ // invalid_type issue
125
+ payload.issues.push({
126
+ expected: origin,
127
+ format: def.format,
128
+ code: "invalid_type",
129
+ input,
130
+ inst,
131
+ });
132
+ return;
133
+ // not_multiple_of issue
134
+ // payload.issues.push({
135
+ // code: "not_multiple_of",
136
+ // origin: "number",
137
+ // input,
138
+ // inst,
139
+ // divisor: 1,
140
+ // });
141
+ }
142
+ if (!Number.isSafeInteger(input)) {
143
+ if (input > 0) {
144
+ // too_big
145
+ payload.issues.push({
146
+ input,
147
+ code: "too_big",
148
+ maximum: Number.MAX_SAFE_INTEGER,
149
+ note: "Integers must be within the safe integer range.",
150
+ inst,
151
+ origin,
152
+ continue: !def.abort,
153
+ });
154
+ }
155
+ else {
156
+ // too_small
157
+ payload.issues.push({
158
+ input,
159
+ code: "too_small",
160
+ minimum: Number.MIN_SAFE_INTEGER,
161
+ note: "Integers must be within the safe integer range.",
162
+ inst,
163
+ origin,
164
+ continue: !def.abort,
165
+ });
166
+ }
167
+ return;
168
+ }
169
+ }
170
+ if (input < minimum) {
171
+ payload.issues.push({
172
+ origin: "number",
173
+ input,
174
+ code: "too_small",
175
+ minimum,
176
+ inclusive: true,
177
+ inst,
178
+ continue: !def.abort,
179
+ });
180
+ }
181
+ if (input > maximum) {
182
+ payload.issues.push({
183
+ origin: "number",
184
+ input,
185
+ code: "too_big",
186
+ maximum,
187
+ inst,
188
+ });
189
+ }
190
+ };
191
+ });
192
+ const $ZodCheckBigIntFormat = /*@__PURE__*/ $constructor("$ZodCheckBigIntFormat", (inst, def) => {
193
+ $ZodCheck.init(inst, def); // no format checks
194
+ const [minimum, maximum] = BIGINT_FORMAT_RANGES[def.format];
195
+ inst._zod.onattach.push((inst) => {
196
+ const bag = inst._zod.bag;
197
+ bag.format = def.format;
198
+ bag.minimum = minimum;
199
+ bag.maximum = maximum;
200
+ });
201
+ inst._zod.check = (payload) => {
202
+ const input = payload.value;
203
+ if (input < minimum) {
204
+ payload.issues.push({
205
+ origin: "bigint",
206
+ input,
207
+ code: "too_small",
208
+ minimum: minimum,
209
+ inclusive: true,
210
+ inst,
211
+ continue: !def.abort,
212
+ });
213
+ }
214
+ if (input > maximum) {
215
+ payload.issues.push({
216
+ origin: "bigint",
217
+ input,
218
+ code: "too_big",
219
+ maximum,
220
+ inst,
221
+ });
222
+ }
223
+ };
224
+ });
225
+ const $ZodCheckMaxSize = /*@__PURE__*/ $constructor("$ZodCheckMaxSize", (inst, def) => {
226
+ $ZodCheck.init(inst, def);
227
+ inst._zod.when = (payload) => {
228
+ const val = payload.value;
229
+ return !nullish(val) && val.size !== undefined;
230
+ };
231
+ inst._zod.onattach.push((inst) => {
232
+ const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
233
+ if (def.maximum < curr)
234
+ inst._zod.bag.maximum = def.maximum;
235
+ });
236
+ inst._zod.check = (payload) => {
237
+ const input = payload.value;
238
+ const size = input.size;
239
+ if (size <= def.maximum)
240
+ return;
241
+ payload.issues.push({
242
+ origin: getSizableOrigin(input),
243
+ code: "too_big",
244
+ maximum: def.maximum,
245
+ input,
246
+ inst,
247
+ continue: !def.abort,
248
+ });
249
+ };
250
+ });
251
+ const $ZodCheckMinSize = /*@__PURE__*/ $constructor("$ZodCheckMinSize", (inst, def) => {
252
+ $ZodCheck.init(inst, def);
253
+ inst._zod.when = (payload) => {
254
+ const val = payload.value;
255
+ return !nullish(val) && val.size !== undefined;
256
+ };
257
+ inst._zod.onattach.push((inst) => {
258
+ const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
259
+ if (def.minimum > curr)
260
+ inst._zod.bag.minimum = def.minimum;
261
+ });
262
+ inst._zod.check = (payload) => {
263
+ const input = payload.value;
264
+ const size = input.size;
265
+ if (size >= def.minimum)
266
+ return;
267
+ payload.issues.push({
268
+ origin: getSizableOrigin(input),
269
+ code: "too_small",
270
+ minimum: def.minimum,
271
+ input,
272
+ inst,
273
+ continue: !def.abort,
274
+ });
275
+ };
276
+ });
277
+ const $ZodCheckSizeEquals = /*@__PURE__*/ $constructor("$ZodCheckSizeEquals", (inst, def) => {
278
+ $ZodCheck.init(inst, def);
279
+ inst._zod.when = (payload) => {
280
+ const val = payload.value;
281
+ return !nullish(val) && val.size !== undefined;
282
+ };
283
+ inst._zod.onattach.push((inst) => {
284
+ const bag = inst._zod.bag;
285
+ bag.minimum = def.size;
286
+ bag.maximum = def.size;
287
+ bag.size = def.size;
288
+ });
289
+ inst._zod.check = (payload) => {
290
+ const input = payload.value;
291
+ const size = input.size;
292
+ if (size === def.size)
293
+ return;
294
+ const tooBig = size > def.size;
295
+ payload.issues.push({
296
+ origin: getSizableOrigin(input),
297
+ ...(tooBig ? { code: "too_big", maximum: def.size } : { code: "too_small", minimum: def.size }),
298
+ inclusive: true,
299
+ exact: true,
300
+ input: payload.value,
301
+ inst,
302
+ continue: !def.abort,
303
+ });
304
+ };
305
+ });
306
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
307
+ $ZodCheck.init(inst, def);
308
+ inst._zod.when = (payload) => {
309
+ const val = payload.value;
310
+ return !nullish(val) && val.length !== undefined;
311
+ };
312
+ inst._zod.onattach.push((inst) => {
313
+ const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
314
+ if (def.maximum < curr)
315
+ inst._zod.bag.maximum = def.maximum;
316
+ });
317
+ inst._zod.check = (payload) => {
318
+ const input = payload.value;
319
+ const length = input.length;
320
+ if (length <= def.maximum)
321
+ return;
322
+ const origin = getLengthableOrigin(input);
323
+ payload.issues.push({
324
+ origin,
325
+ code: "too_big",
326
+ maximum: def.maximum,
327
+ inclusive: true,
328
+ input,
329
+ inst,
330
+ continue: !def.abort,
331
+ });
332
+ };
333
+ });
334
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
335
+ $ZodCheck.init(inst, def);
336
+ inst._zod.when = (payload) => {
337
+ const val = payload.value;
338
+ return !nullish(val) && val.length !== undefined;
339
+ };
340
+ inst._zod.onattach.push((inst) => {
341
+ const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
342
+ if (def.minimum > curr)
343
+ inst._zod.bag.minimum = def.minimum;
344
+ });
345
+ inst._zod.check = (payload) => {
346
+ const input = payload.value;
347
+ const length = input.length;
348
+ if (length >= def.minimum)
349
+ return;
350
+ const origin = getLengthableOrigin(input);
351
+ payload.issues.push({
352
+ origin,
353
+ code: "too_small",
354
+ minimum: def.minimum,
355
+ inclusive: true,
356
+ input,
357
+ inst,
358
+ continue: !def.abort,
359
+ });
360
+ };
361
+ });
362
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
363
+ $ZodCheck.init(inst, def);
364
+ inst._zod.when = (payload) => {
365
+ const val = payload.value;
366
+ return !nullish(val) && val.length !== undefined;
367
+ };
368
+ inst._zod.onattach.push((inst) => {
369
+ const bag = inst._zod.bag;
370
+ bag.minimum = def.length;
371
+ bag.maximum = def.length;
372
+ bag.length = def.length;
373
+ });
374
+ inst._zod.check = (payload) => {
375
+ const input = payload.value;
376
+ const length = input.length;
377
+ if (length === def.length)
378
+ return;
379
+ const origin = getLengthableOrigin(input);
380
+ const tooBig = length > def.length;
381
+ payload.issues.push({
382
+ origin,
383
+ ...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
384
+ inclusive: true,
385
+ exact: true,
386
+ input: payload.value,
387
+ inst,
388
+ continue: !def.abort,
389
+ });
390
+ };
391
+ });
392
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
393
+ var _a, _b;
394
+ $ZodCheck.init(inst, def);
395
+ inst._zod.onattach.push((inst) => {
396
+ const bag = inst._zod.bag;
397
+ bag.format = def.format;
398
+ if (def.pattern) {
399
+ bag.patterns ?? (bag.patterns = new Set());
400
+ bag.patterns.add(def.pattern);
401
+ }
402
+ });
403
+ if (def.pattern)
404
+ (_a = inst._zod).check ?? (_a.check = (payload) => {
405
+ def.pattern.lastIndex = 0;
406
+ if (def.pattern.test(payload.value))
407
+ return;
408
+ payload.issues.push({
409
+ origin: "string",
410
+ code: "invalid_format",
411
+ format: def.format,
412
+ input: payload.value,
413
+ ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
414
+ inst,
415
+ continue: !def.abort,
416
+ });
417
+ });
418
+ else
419
+ (_b = inst._zod).check ?? (_b.check = () => { });
420
+ });
421
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
422
+ $ZodCheckStringFormat.init(inst, def);
423
+ inst._zod.check = (payload) => {
424
+ def.pattern.lastIndex = 0;
425
+ if (def.pattern.test(payload.value))
426
+ return;
427
+ payload.issues.push({
428
+ origin: "string",
429
+ code: "invalid_format",
430
+ format: "regex",
431
+ input: payload.value,
432
+ pattern: def.pattern.toString(),
433
+ inst,
434
+ continue: !def.abort,
435
+ });
436
+ };
437
+ });
438
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
439
+ def.pattern ?? (def.pattern = lowercase);
440
+ $ZodCheckStringFormat.init(inst, def);
441
+ });
442
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
443
+ def.pattern ?? (def.pattern = uppercase);
444
+ $ZodCheckStringFormat.init(inst, def);
445
+ });
446
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
447
+ $ZodCheck.init(inst, def);
448
+ const escapedRegex = escapeRegex(def.includes);
449
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
450
+ def.pattern = pattern;
451
+ inst._zod.onattach.push((inst) => {
452
+ const bag = inst._zod.bag;
453
+ bag.patterns ?? (bag.patterns = new Set());
454
+ bag.patterns.add(pattern);
455
+ });
456
+ inst._zod.check = (payload) => {
457
+ if (payload.value.includes(def.includes, def.position))
458
+ return;
459
+ payload.issues.push({
460
+ origin: "string",
461
+ code: "invalid_format",
462
+ format: "includes",
463
+ includes: def.includes,
464
+ input: payload.value,
465
+ inst,
466
+ continue: !def.abort,
467
+ });
468
+ };
469
+ });
470
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
471
+ $ZodCheck.init(inst, def);
472
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
473
+ def.pattern ?? (def.pattern = pattern);
474
+ inst._zod.onattach.push((inst) => {
475
+ const bag = inst._zod.bag;
476
+ bag.patterns ?? (bag.patterns = new Set());
477
+ bag.patterns.add(pattern);
478
+ });
479
+ inst._zod.check = (payload) => {
480
+ if (payload.value.startsWith(def.prefix))
481
+ return;
482
+ payload.issues.push({
483
+ origin: "string",
484
+ code: "invalid_format",
485
+ format: "starts_with",
486
+ prefix: def.prefix,
487
+ input: payload.value,
488
+ inst,
489
+ continue: !def.abort,
490
+ });
491
+ };
492
+ });
493
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
494
+ $ZodCheck.init(inst, def);
495
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
496
+ def.pattern ?? (def.pattern = pattern);
497
+ inst._zod.onattach.push((inst) => {
498
+ const bag = inst._zod.bag;
499
+ bag.patterns ?? (bag.patterns = new Set());
500
+ bag.patterns.add(pattern);
501
+ });
502
+ inst._zod.check = (payload) => {
503
+ if (payload.value.endsWith(def.suffix))
504
+ return;
505
+ payload.issues.push({
506
+ origin: "string",
507
+ code: "invalid_format",
508
+ format: "ends_with",
509
+ suffix: def.suffix,
510
+ input: payload.value,
511
+ inst,
512
+ continue: !def.abort,
513
+ });
514
+ };
515
+ });
516
+ ///////////////////////////////////
517
+ ///// $ZodCheckProperty /////
518
+ ///////////////////////////////////
519
+ function handleCheckPropertyResult(result, payload, property) {
520
+ if (result.issues.length) {
521
+ payload.issues.push(...prefixIssues(property, result.issues));
522
+ }
523
+ }
524
+ const $ZodCheckProperty = /*@__PURE__*/ $constructor("$ZodCheckProperty", (inst, def) => {
525
+ $ZodCheck.init(inst, def);
526
+ inst._zod.check = (payload) => {
527
+ const result = def.schema._zod.run({
528
+ value: payload.value[def.property],
529
+ issues: [],
530
+ }, {});
531
+ if (result instanceof Promise) {
532
+ return result.then((result) => handleCheckPropertyResult(result, payload, def.property));
533
+ }
534
+ handleCheckPropertyResult(result, payload, def.property);
535
+ return;
536
+ };
537
+ });
538
+ const $ZodCheckMimeType = /*@__PURE__*/ $constructor("$ZodCheckMimeType", (inst, def) => {
539
+ $ZodCheck.init(inst, def);
540
+ const mimeSet = new Set(def.mime);
541
+ inst._zod.onattach.push((inst) => {
542
+ inst._zod.bag.mime = def.mime;
543
+ });
544
+ inst._zod.check = (payload) => {
545
+ if (mimeSet.has(payload.value.type))
546
+ return;
547
+ payload.issues.push({
548
+ code: "invalid_value",
549
+ values: def.mime,
550
+ input: payload.value.type,
551
+ inst,
552
+ });
553
+ };
554
+ });
555
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
556
+ $ZodCheck.init(inst, def);
557
+ inst._zod.check = (payload) => {
558
+ payload.value = def.tx(payload.value);
559
+ };
560
+ });
561
+
562
+ export { $ZodCheck, $ZodCheckBigIntFormat, $ZodCheckEndsWith, $ZodCheckGreaterThan, $ZodCheckIncludes, $ZodCheckLengthEquals, $ZodCheckLessThan, $ZodCheckLowerCase, $ZodCheckMaxLength, $ZodCheckMaxSize, $ZodCheckMimeType, $ZodCheckMinLength, $ZodCheckMinSize, $ZodCheckMultipleOf, $ZodCheckNumberFormat, $ZodCheckOverwrite, $ZodCheckProperty, $ZodCheckRegex, $ZodCheckSizeEquals, $ZodCheckStartsWith, $ZodCheckStringFormat, $ZodCheckUpperCase };
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ /** A special constant with type `never` */
6
+ const NEVER = Object.freeze({
7
+ status: "aborted",
8
+ });
9
+ function $constructor(name, initializer, params) {
10
+ function init(inst, def) {
11
+ var _a;
12
+ Object.defineProperty(inst, "_zod", {
13
+ value: inst._zod ?? {},
14
+ enumerable: false,
15
+ });
16
+ (_a = inst._zod).traits ?? (_a.traits = new Set());
17
+ inst._zod.traits.add(name);
18
+ initializer(inst, def);
19
+ // support prototype modifications
20
+ for (const k in _.prototype) {
21
+ if (!(k in inst))
22
+ Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
23
+ }
24
+ inst._zod.constr = _;
25
+ inst._zod.def = def;
26
+ }
27
+ // doesn't work if Parent has a constructor with arguments
28
+ const Parent = params?.Parent ?? Object;
29
+ class Definition extends Parent {
30
+ }
31
+ Object.defineProperty(Definition, "name", { value: name });
32
+ function _(def) {
33
+ var _a;
34
+ const inst = params?.Parent ? new Definition() : this;
35
+ init(inst, def);
36
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
37
+ for (const fn of inst._zod.deferred) {
38
+ fn();
39
+ }
40
+ return inst;
41
+ }
42
+ Object.defineProperty(_, "init", { value: init });
43
+ Object.defineProperty(_, Symbol.hasInstance, {
44
+ value: (inst) => {
45
+ if (params?.Parent && inst instanceof params.Parent)
46
+ return true;
47
+ return inst?._zod?.traits?.has(name);
48
+ },
49
+ });
50
+ Object.defineProperty(_, "name", { value: name });
51
+ return _;
52
+ }
53
+ ////////////////////////////// UTILITIES ///////////////////////////////////////
54
+ const $brand = Symbol("zod_brand");
55
+ class $ZodAsyncError extends Error {
56
+ constructor() {
57
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
58
+ }
59
+ }
60
+ const globalConfig = {};
61
+ function config(newConfig) {
62
+ if (newConfig)
63
+ Object.assign(globalConfig, newConfig);
64
+ return globalConfig;
65
+ }
66
+
67
+ exports.$ZodAsyncError = $ZodAsyncError;
68
+ exports.$brand = $brand;
69
+ exports.$constructor = $constructor;
70
+ exports.NEVER = NEVER;
71
+ exports.config = config;
72
+ exports.globalConfig = globalConfig;
@@ -0,0 +1,63 @@
1
+ /** A special constant with type `never` */
2
+ const NEVER = Object.freeze({
3
+ status: "aborted",
4
+ });
5
+ function $constructor(name, initializer, params) {
6
+ function init(inst, def) {
7
+ var _a;
8
+ Object.defineProperty(inst, "_zod", {
9
+ value: inst._zod ?? {},
10
+ enumerable: false,
11
+ });
12
+ (_a = inst._zod).traits ?? (_a.traits = new Set());
13
+ inst._zod.traits.add(name);
14
+ initializer(inst, def);
15
+ // support prototype modifications
16
+ for (const k in _.prototype) {
17
+ if (!(k in inst))
18
+ Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
19
+ }
20
+ inst._zod.constr = _;
21
+ inst._zod.def = def;
22
+ }
23
+ // doesn't work if Parent has a constructor with arguments
24
+ const Parent = params?.Parent ?? Object;
25
+ class Definition extends Parent {
26
+ }
27
+ Object.defineProperty(Definition, "name", { value: name });
28
+ function _(def) {
29
+ var _a;
30
+ const inst = params?.Parent ? new Definition() : this;
31
+ init(inst, def);
32
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
33
+ for (const fn of inst._zod.deferred) {
34
+ fn();
35
+ }
36
+ return inst;
37
+ }
38
+ Object.defineProperty(_, "init", { value: init });
39
+ Object.defineProperty(_, Symbol.hasInstance, {
40
+ value: (inst) => {
41
+ if (params?.Parent && inst instanceof params.Parent)
42
+ return true;
43
+ return inst?._zod?.traits?.has(name);
44
+ },
45
+ });
46
+ Object.defineProperty(_, "name", { value: name });
47
+ return _;
48
+ }
49
+ ////////////////////////////// UTILITIES ///////////////////////////////////////
50
+ const $brand = Symbol("zod_brand");
51
+ class $ZodAsyncError extends Error {
52
+ constructor() {
53
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
54
+ }
55
+ }
56
+ const globalConfig = {};
57
+ function config(newConfig) {
58
+ if (newConfig)
59
+ Object.assign(globalConfig, newConfig);
60
+ return globalConfig;
61
+ }
62
+
63
+ export { $ZodAsyncError, $brand, $constructor, NEVER, config, globalConfig };