@cipherstash/stack 0.18.0 → 1.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/CHANGELOG.md +704 -0
  2. package/README.md +97 -79
  3. package/dist/adapter-kit.cjs +923 -0
  4. package/dist/adapter-kit.cjs.map +1 -0
  5. package/dist/adapter-kit.d.cts +82 -0
  6. package/dist/adapter-kit.d.ts +82 -0
  7. package/dist/adapter-kit.js +47 -0
  8. package/dist/adapter-kit.js.map +1 -0
  9. package/dist/base-operation-AOAIvsSB.d.cts +32 -0
  10. package/dist/base-operation-FXEzUXIq.d.ts +32 -0
  11. package/dist/{chunk-VPOTNP4K.js → chunk-3B5ZX3IS.js} +3 -1
  12. package/dist/chunk-3B5ZX3IS.js.map +1 -0
  13. package/dist/chunk-7333ZC6L.js +48 -0
  14. package/dist/chunk-7333ZC6L.js.map +1 -0
  15. package/dist/{chunk-XWPGAHBZ.js → chunk-BNO32ZMV.js} +1 -1
  16. package/dist/chunk-BNO32ZMV.js.map +1 -0
  17. package/dist/chunk-CLM7E4I6.js +4439 -0
  18. package/dist/chunk-CLM7E4I6.js.map +1 -0
  19. package/dist/{chunk-LLCCNKDL.js → chunk-HQANMV7R.js} +3 -3
  20. package/dist/{chunk-LLCCNKDL.js.map → chunk-HQANMV7R.js.map} +1 -1
  21. package/dist/chunk-JSG2AMDI.js +17 -0
  22. package/dist/chunk-JSG2AMDI.js.map +1 -0
  23. package/dist/chunk-OFQ555AX.js +191 -0
  24. package/dist/chunk-OFQ555AX.js.map +1 -0
  25. package/dist/chunk-PZ5AY32C.js +10 -0
  26. package/dist/chunk-PZ5AY32C.js.map +1 -0
  27. package/dist/chunk-V2Q3NYIH.js +494 -0
  28. package/dist/chunk-V2Q3NYIH.js.map +1 -0
  29. package/dist/chunk-X3JRXEIB.js +98 -0
  30. package/dist/chunk-X3JRXEIB.js.map +1 -0
  31. package/dist/{chunk-ZYOZHZMJ.js → chunk-ZTP5QJ27.js} +193 -169
  32. package/dist/chunk-ZTP5QJ27.js.map +1 -0
  33. package/dist/client.cjs +4124 -49
  34. package/dist/client.cjs.map +1 -1
  35. package/dist/client.d.cts +6 -5
  36. package/dist/client.d.ts +6 -5
  37. package/dist/client.js +3 -1
  38. package/dist/columns-D2_YzrCX.d.cts +622 -0
  39. package/dist/columns-rZc7fQHI.d.ts +622 -0
  40. package/dist/dynamodb/index.cjs +19 -12
  41. package/dist/dynamodb/index.cjs.map +1 -1
  42. package/dist/dynamodb/index.d.cts +3 -2
  43. package/dist/dynamodb/index.d.ts +3 -2
  44. package/dist/dynamodb/index.js +8 -10
  45. package/dist/dynamodb/index.js.map +1 -1
  46. package/dist/encryption/index.cjs +4496 -222
  47. package/dist/encryption/index.cjs.map +1 -1
  48. package/dist/encryption/index.d.cts +807 -6
  49. package/dist/encryption/index.d.ts +807 -6
  50. package/dist/encryption/index.js +15 -7
  51. package/dist/encryption/v3.cjs +7896 -0
  52. package/dist/encryption/v3.cjs.map +1 -0
  53. package/dist/encryption/v3.d.cts +103 -0
  54. package/dist/encryption/v3.d.ts +103 -0
  55. package/dist/encryption/v3.js +189 -0
  56. package/dist/encryption/v3.js.map +1 -0
  57. package/dist/eql/v3/index.cjs +663 -0
  58. package/dist/eql/v3/index.cjs.map +1 -0
  59. package/dist/eql/v3/index.d.cts +173 -0
  60. package/dist/eql/v3/index.d.ts +173 -0
  61. package/dist/eql/v3/index.js +99 -0
  62. package/dist/eql/v3/index.js.map +1 -0
  63. package/dist/errors/index.js +1 -0
  64. package/dist/identity/index.cjs +55 -35
  65. package/dist/identity/index.cjs.map +1 -1
  66. package/dist/identity/index.d.cts +54 -30
  67. package/dist/identity/index.d.ts +54 -30
  68. package/dist/identity/index.js +9 -177
  69. package/dist/identity/index.js.map +1 -1
  70. package/dist/index-BquA71_Y.d.ts +24 -0
  71. package/dist/index-fhWTOV0K.d.cts +24 -0
  72. package/dist/index.cjs +4547 -243
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/index.d.cts +18 -19
  75. package/dist/index.d.ts +18 -19
  76. package/dist/index.js +20 -5
  77. package/dist/index.js.map +1 -1
  78. package/dist/schema/index.cjs +4128 -49
  79. package/dist/schema/index.cjs.map +1 -1
  80. package/dist/schema/index.d.cts +1 -1
  81. package/dist/schema/index.d.ts +1 -1
  82. package/dist/schema/index.js +3 -1
  83. package/dist/{types-public-BTxqjmtv.d.cts → types-public-QMjYNfQO.d.cts} +448 -251
  84. package/dist/{types-public-BTxqjmtv.d.ts → types-public-QMjYNfQO.d.ts} +448 -251
  85. package/dist/types-public.cjs.map +1 -1
  86. package/dist/types-public.d.cts +2 -2
  87. package/dist/types-public.d.ts +2 -2
  88. package/dist/types-public.js +2 -1
  89. package/dist/wasm-inline.d.ts +1643 -0
  90. package/dist/wasm-inline.js +4901 -0
  91. package/dist/wasm-inline.js.map +1 -0
  92. package/package.json +74 -52
  93. package/dist/chunk-VPOTNP4K.js.map +0 -1
  94. package/dist/chunk-XWPGAHBZ.js.map +0 -1
  95. package/dist/chunk-YWQXTZ5M.js +0 -383
  96. package/dist/chunk-YWQXTZ5M.js.map +0 -1
  97. package/dist/chunk-ZYOZHZMJ.js.map +0 -1
  98. package/dist/client-CIsfZ2zg.d.ts +0 -692
  99. package/dist/client-Dt98Rugc.d.cts +0 -692
  100. package/dist/drizzle/index.cjs +0 -1558
  101. package/dist/drizzle/index.cjs.map +0 -1
  102. package/dist/drizzle/index.d.cts +0 -358
  103. package/dist/drizzle/index.d.ts +0 -358
  104. package/dist/drizzle/index.js +0 -1215
  105. package/dist/drizzle/index.js.map +0 -1
  106. package/dist/supabase/index.cjs +0 -1526
  107. package/dist/supabase/index.cjs.map +0 -1
  108. package/dist/supabase/index.d.cts +0 -144
  109. package/dist/supabase/index.d.ts +0 -144
  110. package/dist/supabase/index.js +0 -899
  111. package/dist/supabase/index.js.map +0 -1
@@ -0,0 +1,4901 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/wasm-inline.ts
8
+ import {
9
+ AccessKeyStrategy
10
+ } from "@cipherstash/auth/wasm-inline";
11
+ import {
12
+ decrypt as wasmDecrypt,
13
+ encrypt as wasmEncrypt,
14
+ isEncrypted as wasmIsEncrypted,
15
+ newClient as wasmNewClient
16
+ } from "@cipherstash/protect-ffi/wasm-inline";
17
+
18
+ // src/schema/match-defaults.ts
19
+ function defaultMatchOpts() {
20
+ return {
21
+ tokenizer: { kind: "ngram", token_length: 3 },
22
+ token_filters: [{ kind: "downcase" }],
23
+ k: 6,
24
+ m: 2048,
25
+ include_original: true
26
+ };
27
+ }
28
+
29
+ // src/eql/v3/columns.ts
30
+ var STORAGE_ONLY = {
31
+ equality: false,
32
+ orderAndRange: false,
33
+ freeTextSearch: false
34
+ };
35
+ var EQUALITY_ONLY = {
36
+ equality: true,
37
+ orderAndRange: false,
38
+ freeTextSearch: false
39
+ };
40
+ var ORDER_AND_RANGE = {
41
+ equality: true,
42
+ orderAndRange: true,
43
+ freeTextSearch: false
44
+ };
45
+ var MATCH_ONLY = {
46
+ equality: false,
47
+ orderAndRange: false,
48
+ freeTextSearch: true
49
+ };
50
+ var TEXT_SEARCH = {
51
+ equality: true,
52
+ orderAndRange: true,
53
+ freeTextSearch: true
54
+ };
55
+ var TEXT_SEARCH_EQL_TYPE = "public.eql_v3_text_search";
56
+ var INTEGER = {
57
+ eqlType: "public.eql_v3_integer",
58
+ castAs: "number",
59
+ capabilities: STORAGE_ONLY
60
+ };
61
+ var INTEGER_EQ = {
62
+ eqlType: "public.eql_v3_integer_eq",
63
+ castAs: "number",
64
+ capabilities: EQUALITY_ONLY
65
+ };
66
+ var INTEGER_ORD_ORE = {
67
+ eqlType: "public.eql_v3_integer_ord_ore",
68
+ castAs: "number",
69
+ capabilities: ORDER_AND_RANGE
70
+ };
71
+ var INTEGER_ORD = {
72
+ eqlType: "public.eql_v3_integer_ord",
73
+ castAs: "number",
74
+ capabilities: ORDER_AND_RANGE
75
+ };
76
+ var SMALLINT = {
77
+ eqlType: "public.eql_v3_smallint",
78
+ castAs: "number",
79
+ capabilities: STORAGE_ONLY
80
+ };
81
+ var SMALLINT_EQ = {
82
+ eqlType: "public.eql_v3_smallint_eq",
83
+ castAs: "number",
84
+ capabilities: EQUALITY_ONLY
85
+ };
86
+ var SMALLINT_ORD_ORE = {
87
+ eqlType: "public.eql_v3_smallint_ord_ore",
88
+ castAs: "number",
89
+ capabilities: ORDER_AND_RANGE
90
+ };
91
+ var SMALLINT_ORD = {
92
+ eqlType: "public.eql_v3_smallint_ord",
93
+ castAs: "number",
94
+ capabilities: ORDER_AND_RANGE
95
+ };
96
+ var BIGINT = {
97
+ eqlType: "public.eql_v3_bigint",
98
+ castAs: "bigint",
99
+ capabilities: STORAGE_ONLY
100
+ };
101
+ var BIGINT_EQ = {
102
+ eqlType: "public.eql_v3_bigint_eq",
103
+ castAs: "bigint",
104
+ capabilities: EQUALITY_ONLY
105
+ };
106
+ var BIGINT_ORD_ORE = {
107
+ eqlType: "public.eql_v3_bigint_ord_ore",
108
+ castAs: "bigint",
109
+ capabilities: ORDER_AND_RANGE
110
+ };
111
+ var BIGINT_ORD = {
112
+ eqlType: "public.eql_v3_bigint_ord",
113
+ castAs: "bigint",
114
+ capabilities: ORDER_AND_RANGE
115
+ };
116
+ var DATE = {
117
+ eqlType: "public.eql_v3_date",
118
+ castAs: "date",
119
+ capabilities: STORAGE_ONLY
120
+ };
121
+ var DATE_EQ = {
122
+ eqlType: "public.eql_v3_date_eq",
123
+ castAs: "date",
124
+ capabilities: EQUALITY_ONLY
125
+ };
126
+ var DATE_ORD_ORE = {
127
+ eqlType: "public.eql_v3_date_ord_ore",
128
+ castAs: "date",
129
+ capabilities: ORDER_AND_RANGE
130
+ };
131
+ var DATE_ORD = {
132
+ eqlType: "public.eql_v3_date_ord",
133
+ castAs: "date",
134
+ capabilities: ORDER_AND_RANGE
135
+ };
136
+ var TIMESTAMP = {
137
+ eqlType: "public.eql_v3_timestamp",
138
+ castAs: "timestamp",
139
+ capabilities: STORAGE_ONLY
140
+ };
141
+ var TIMESTAMP_EQ = {
142
+ eqlType: "public.eql_v3_timestamp_eq",
143
+ castAs: "timestamp",
144
+ capabilities: EQUALITY_ONLY
145
+ };
146
+ var TIMESTAMP_ORD_ORE = {
147
+ eqlType: "public.eql_v3_timestamp_ord_ore",
148
+ castAs: "timestamp",
149
+ capabilities: ORDER_AND_RANGE
150
+ };
151
+ var TIMESTAMP_ORD = {
152
+ eqlType: "public.eql_v3_timestamp_ord",
153
+ castAs: "timestamp",
154
+ capabilities: ORDER_AND_RANGE
155
+ };
156
+ var NUMERIC = {
157
+ eqlType: "public.eql_v3_numeric",
158
+ castAs: "number",
159
+ capabilities: STORAGE_ONLY
160
+ };
161
+ var NUMERIC_EQ = {
162
+ eqlType: "public.eql_v3_numeric_eq",
163
+ castAs: "number",
164
+ capabilities: EQUALITY_ONLY
165
+ };
166
+ var NUMERIC_ORD_ORE = {
167
+ eqlType: "public.eql_v3_numeric_ord_ore",
168
+ castAs: "number",
169
+ capabilities: ORDER_AND_RANGE
170
+ };
171
+ var NUMERIC_ORD = {
172
+ eqlType: "public.eql_v3_numeric_ord",
173
+ castAs: "number",
174
+ capabilities: ORDER_AND_RANGE
175
+ };
176
+ var TEXT = {
177
+ eqlType: "public.eql_v3_text",
178
+ castAs: "string",
179
+ capabilities: STORAGE_ONLY
180
+ };
181
+ var TEXT_EQ = {
182
+ eqlType: "public.eql_v3_text_eq",
183
+ castAs: "string",
184
+ capabilities: EQUALITY_ONLY
185
+ };
186
+ var TEXT_MATCH = {
187
+ eqlType: "public.eql_v3_text_match",
188
+ castAs: "string",
189
+ capabilities: MATCH_ONLY
190
+ };
191
+ var TEXT_ORD_ORE = {
192
+ eqlType: "public.eql_v3_text_ord_ore",
193
+ castAs: "string",
194
+ capabilities: ORDER_AND_RANGE
195
+ };
196
+ var TEXT_ORD = {
197
+ eqlType: "public.eql_v3_text_ord",
198
+ castAs: "string",
199
+ capabilities: ORDER_AND_RANGE
200
+ };
201
+ var BOOLEAN = {
202
+ eqlType: "public.eql_v3_boolean",
203
+ castAs: "boolean",
204
+ capabilities: STORAGE_ONLY
205
+ };
206
+ var REAL = {
207
+ eqlType: "public.eql_v3_real",
208
+ castAs: "number",
209
+ capabilities: STORAGE_ONLY
210
+ };
211
+ var REAL_EQ = {
212
+ eqlType: "public.eql_v3_real_eq",
213
+ castAs: "number",
214
+ capabilities: EQUALITY_ONLY
215
+ };
216
+ var REAL_ORD_ORE = {
217
+ eqlType: "public.eql_v3_real_ord_ore",
218
+ castAs: "number",
219
+ capabilities: ORDER_AND_RANGE
220
+ };
221
+ var REAL_ORD = {
222
+ eqlType: "public.eql_v3_real_ord",
223
+ castAs: "number",
224
+ capabilities: ORDER_AND_RANGE
225
+ };
226
+ var DOUBLE = {
227
+ eqlType: "public.eql_v3_double",
228
+ castAs: "number",
229
+ capabilities: STORAGE_ONLY
230
+ };
231
+ var DOUBLE_EQ = {
232
+ eqlType: "public.eql_v3_double_eq",
233
+ castAs: "number",
234
+ capabilities: EQUALITY_ONLY
235
+ };
236
+ var DOUBLE_ORD_ORE = {
237
+ eqlType: "public.eql_v3_double_ord_ore",
238
+ castAs: "number",
239
+ capabilities: ORDER_AND_RANGE
240
+ };
241
+ var DOUBLE_ORD = {
242
+ eqlType: "public.eql_v3_double_ord",
243
+ castAs: "number",
244
+ capabilities: ORDER_AND_RANGE
245
+ };
246
+ function indexesForCapabilities(capabilities, castAs, ordering) {
247
+ const indexes = {};
248
+ if (capabilities.equality && (!capabilities.orderAndRange || castAs === "string")) {
249
+ indexes.unique = { token_filters: [] };
250
+ }
251
+ if (capabilities.orderAndRange) {
252
+ indexes[ordering] = {};
253
+ }
254
+ if (capabilities.freeTextSearch) {
255
+ indexes.match = { ...defaultMatchOpts(), include_original: false };
256
+ }
257
+ if (capabilities.searchableJson) {
258
+ indexes.ste_vec = {
259
+ prefix: "enabled",
260
+ array_index_mode: { item: true, wildcard: true, position: false },
261
+ mode: "compat"
262
+ };
263
+ }
264
+ return indexes;
265
+ }
266
+ function orderingForEqlType(eqlType) {
267
+ return eqlType.endsWith("_ord_ore") ? "ore" : "ope";
268
+ }
269
+ function isQueryableCapabilities(capabilities) {
270
+ return capabilities.equality || capabilities.orderAndRange || capabilities.freeTextSearch || (capabilities.searchableJson ?? false);
271
+ }
272
+ var EncryptedV3Column = class {
273
+ constructor(columnName, definition) {
274
+ this.columnName = columnName;
275
+ this.definition = definition;
276
+ }
277
+ columnName;
278
+ definition;
279
+ getName() {
280
+ return this.columnName;
281
+ }
282
+ /** The concrete EQL v3 domain name. Metadata only; not emitted by `build()`. */
283
+ getEqlType() {
284
+ return this.definition.eqlType;
285
+ }
286
+ /** The semantic query capabilities this domain exposes. Metadata only. */
287
+ getQueryCapabilities() {
288
+ return this.definition.capabilities;
289
+ }
290
+ /** `true` when this domain can produce at least one kind of query term. */
291
+ isQueryable() {
292
+ return isQueryableCapabilities(
293
+ this.definition.capabilities
294
+ );
295
+ }
296
+ /** Emit the encrypt-config column: `cast_as` plus capability-derived indexes. */
297
+ build() {
298
+ return {
299
+ cast_as: this.definition.castAs,
300
+ indexes: indexesForCapabilities(
301
+ this.definition.capabilities,
302
+ this.definition.castAs,
303
+ orderingForEqlType(this.definition.eqlType)
304
+ )
305
+ };
306
+ }
307
+ };
308
+ var TEXT_SEARCH_DOMAIN = {
309
+ eqlType: TEXT_SEARCH_EQL_TYPE,
310
+ castAs: "string",
311
+ capabilities: TEXT_SEARCH
312
+ };
313
+ var EncryptedTextSearchColumn = class extends EncryptedV3Column {
314
+ constructor(columnName) {
315
+ super(columnName, TEXT_SEARCH_DOMAIN);
316
+ }
317
+ };
318
+ var EncryptedIntegerColumn = class extends EncryptedV3Column {
319
+ };
320
+ var EncryptedIntegerEqColumn = class extends EncryptedV3Column {
321
+ };
322
+ var EncryptedIntegerOrdOreColumn = class extends EncryptedV3Column {
323
+ };
324
+ var EncryptedIntegerOrdColumn = class extends EncryptedV3Column {
325
+ };
326
+ var EncryptedSmallintColumn = class extends EncryptedV3Column {
327
+ };
328
+ var EncryptedSmallintEqColumn = class extends EncryptedV3Column {
329
+ };
330
+ var EncryptedSmallintOrdOreColumn = class extends EncryptedV3Column {
331
+ };
332
+ var EncryptedSmallintOrdColumn = class extends EncryptedV3Column {
333
+ };
334
+ var EncryptedBigintColumn = class extends EncryptedV3Column {
335
+ };
336
+ var EncryptedBigintEqColumn = class extends EncryptedV3Column {
337
+ };
338
+ var EncryptedBigintOrdOreColumn = class extends EncryptedV3Column {
339
+ };
340
+ var EncryptedBigintOrdColumn = class extends EncryptedV3Column {
341
+ };
342
+ var EncryptedDateColumn = class extends EncryptedV3Column {
343
+ };
344
+ var EncryptedDateEqColumn = class extends EncryptedV3Column {
345
+ };
346
+ var EncryptedDateOrdOreColumn = class extends EncryptedV3Column {
347
+ };
348
+ var EncryptedDateOrdColumn = class extends EncryptedV3Column {
349
+ };
350
+ var EncryptedTimestampColumn = class extends EncryptedV3Column {
351
+ };
352
+ var EncryptedTimestampEqColumn = class extends EncryptedV3Column {
353
+ };
354
+ var EncryptedTimestampOrdOreColumn = class extends EncryptedV3Column {
355
+ };
356
+ var EncryptedTimestampOrdColumn = class extends EncryptedV3Column {
357
+ };
358
+ var EncryptedNumericColumn = class extends EncryptedV3Column {
359
+ };
360
+ var EncryptedNumericEqColumn = class extends EncryptedV3Column {
361
+ };
362
+ var EncryptedNumericOrdOreColumn = class extends EncryptedV3Column {
363
+ };
364
+ var EncryptedNumericOrdColumn = class extends EncryptedV3Column {
365
+ };
366
+ var EncryptedTextColumn = class extends EncryptedV3Column {
367
+ };
368
+ var EncryptedTextEqColumn = class extends EncryptedV3Column {
369
+ };
370
+ var EncryptedTextMatchColumn = class extends EncryptedV3Column {
371
+ };
372
+ var EncryptedTextOrdOreColumn = class extends EncryptedV3Column {
373
+ };
374
+ var EncryptedTextOrdColumn = class extends EncryptedV3Column {
375
+ };
376
+ var EncryptedBooleanColumn = class extends EncryptedV3Column {
377
+ };
378
+ var EncryptedRealColumn = class extends EncryptedV3Column {
379
+ };
380
+ var EncryptedRealEqColumn = class extends EncryptedV3Column {
381
+ };
382
+ var EncryptedRealOrdOreColumn = class extends EncryptedV3Column {
383
+ };
384
+ var EncryptedRealOrdColumn = class extends EncryptedV3Column {
385
+ };
386
+ var EncryptedDoubleColumn = class extends EncryptedV3Column {
387
+ };
388
+ var EncryptedDoubleEqColumn = class extends EncryptedV3Column {
389
+ };
390
+ var EncryptedDoubleOrdOreColumn = class extends EncryptedV3Column {
391
+ };
392
+ var EncryptedDoubleOrdColumn = class extends EncryptedV3Column {
393
+ };
394
+ var JSON_DOMAIN = {
395
+ eqlType: "public.eql_v3_json",
396
+ castAs: "json",
397
+ capabilities: {
398
+ equality: false,
399
+ orderAndRange: false,
400
+ freeTextSearch: false,
401
+ searchableJson: true
402
+ }
403
+ };
404
+ var EncryptedJsonColumn = class extends EncryptedV3Column {
405
+ constructor(columnName) {
406
+ super(columnName, JSON_DOMAIN);
407
+ }
408
+ };
409
+
410
+ // src/eql/v3/table.ts
411
+ var EncryptedTable = class {
412
+ constructor(tableName, columnBuilders) {
413
+ this.tableName = tableName;
414
+ this.columnBuilders = columnBuilders;
415
+ }
416
+ tableName;
417
+ columnBuilders;
418
+ build() {
419
+ const builtColumns = /* @__PURE__ */ Object.create(null);
420
+ for (const builder of Object.values(this.columnBuilders)) {
421
+ const name = builder.getName();
422
+ if (Object.hasOwn(builtColumns, name)) {
423
+ throw new Error(
424
+ `[eql/v3]: duplicate column name "${name}" in table "${this.tableName}" \u2014 two columns resolve to the same DB name`
425
+ );
426
+ }
427
+ builtColumns[name] = builder.build();
428
+ }
429
+ return {
430
+ tableName: this.tableName,
431
+ columns: builtColumns
432
+ };
433
+ }
434
+ /**
435
+ * Map each column's JS property name to its DB column name (`getName()`).
436
+ * The model path matches user models by property name but must address the
437
+ * encrypt config and FFI by DB name — `build()` keys columns by DB name, so
438
+ * the two only agree when property == name. This recovers the mapping that
439
+ * `build()` discards.
440
+ *
441
+ * NULL PROTOTYPE — load-bearing. Callers index this map by a column name that
442
+ * ultimately comes from the database (`addJsonbCastsV3`, `filterColumnName`,
443
+ * the mutation transform). On a plain object literal, a column named
444
+ * `constructor` / `toString` / `valueOf` / `__proto__` resolves to an
445
+ * inherited `Object.prototype` member, which is truthy — so a *plaintext*
446
+ * column with such a name would be mistaken for a mapped encrypted column and
447
+ * its `Object.prototype` value interpolated into the emitted select string.
448
+ * `encryptedTable()` rejects such names as JS *properties*, but nothing
449
+ * constrains the DB column names a table may contain.
450
+ */
451
+ buildColumnKeyMap() {
452
+ const map = /* @__PURE__ */ Object.create(null);
453
+ for (const [property, builder] of Object.entries(this.columnBuilders)) {
454
+ map[property] = builder.getName();
455
+ }
456
+ return map;
457
+ }
458
+ };
459
+ var RESERVED_TABLE_KEYS = /* @__PURE__ */ new Set([
460
+ "tableName",
461
+ "columnBuilders",
462
+ "_columnType",
463
+ "build",
464
+ "buildColumnKeyMap"
465
+ ]);
466
+ function isReservedTableKey(tableBuilder, colName) {
467
+ return RESERVED_TABLE_KEYS.has(colName) || colName in tableBuilder;
468
+ }
469
+ function encryptedTable(tableName, columns) {
470
+ const tableBuilder = new EncryptedTable(
471
+ tableName,
472
+ columns
473
+ );
474
+ for (const [colName, colBuilder] of Object.entries(columns)) {
475
+ if (isReservedTableKey(tableBuilder, colName)) {
476
+ throw new Error(
477
+ `Column name "${colName}" collides with a reserved EncryptedTable property`
478
+ );
479
+ }
480
+ ;
481
+ tableBuilder[colName] = colBuilder;
482
+ }
483
+ return tableBuilder;
484
+ }
485
+ function buildEncryptConfig(...tables) {
486
+ const config = {
487
+ v: 1,
488
+ tables: {}
489
+ };
490
+ for (const tb of tables) {
491
+ const tableDef = tb.build();
492
+ if (Object.hasOwn(config.tables, tableDef.tableName)) {
493
+ throw new Error(
494
+ `[eql/v3]: duplicate table name "${tableDef.tableName}" passed to buildEncryptConfig \u2014 each table must have a unique name`
495
+ );
496
+ }
497
+ config.tables[tableDef.tableName] = tableDef.columns;
498
+ }
499
+ return config;
500
+ }
501
+
502
+ // src/eql/v3/types.ts
503
+ var types = {
504
+ // integer
505
+ Integer: (name) => new EncryptedIntegerColumn(name, INTEGER),
506
+ IntegerEq: (name) => new EncryptedIntegerEqColumn(name, INTEGER_EQ),
507
+ IntegerOrdOre: (name) => new EncryptedIntegerOrdOreColumn(name, INTEGER_ORD_ORE),
508
+ IntegerOrd: (name) => new EncryptedIntegerOrdColumn(name, INTEGER_ORD),
509
+ // smallint
510
+ Smallint: (name) => new EncryptedSmallintColumn(name, SMALLINT),
511
+ SmallintEq: (name) => new EncryptedSmallintEqColumn(name, SMALLINT_EQ),
512
+ SmallintOrdOre: (name) => new EncryptedSmallintOrdOreColumn(name, SMALLINT_ORD_ORE),
513
+ SmallintOrd: (name) => new EncryptedSmallintOrdColumn(name, SMALLINT_ORD),
514
+ // bigint (int8) — plaintext is a JS `bigint`, round-tripped losslessly by
515
+ // the native protect-ffi boundary (see ./columns)
516
+ Bigint: (name) => new EncryptedBigintColumn(name, BIGINT),
517
+ BigintEq: (name) => new EncryptedBigintEqColumn(name, BIGINT_EQ),
518
+ BigintOrdOre: (name) => new EncryptedBigintOrdOreColumn(name, BIGINT_ORD_ORE),
519
+ BigintOrd: (name) => new EncryptedBigintOrdColumn(name, BIGINT_ORD),
520
+ // date
521
+ Date: (name) => new EncryptedDateColumn(name, DATE),
522
+ DateEq: (name) => new EncryptedDateEqColumn(name, DATE_EQ),
523
+ DateOrdOre: (name) => new EncryptedDateOrdOreColumn(name, DATE_ORD_ORE),
524
+ DateOrd: (name) => new EncryptedDateOrdColumn(name, DATE_ORD),
525
+ // timestamp
526
+ Timestamp: (name) => new EncryptedTimestampColumn(name, TIMESTAMP),
527
+ TimestampEq: (name) => new EncryptedTimestampEqColumn(name, TIMESTAMP_EQ),
528
+ TimestampOrdOre: (name) => new EncryptedTimestampOrdOreColumn(name, TIMESTAMP_ORD_ORE),
529
+ TimestampOrd: (name) => new EncryptedTimestampOrdColumn(name, TIMESTAMP_ORD),
530
+ // numeric
531
+ Numeric: (name) => new EncryptedNumericColumn(name, NUMERIC),
532
+ NumericEq: (name) => new EncryptedNumericEqColumn(name, NUMERIC_EQ),
533
+ NumericOrdOre: (name) => new EncryptedNumericOrdOreColumn(name, NUMERIC_ORD_ORE),
534
+ NumericOrd: (name) => new EncryptedNumericOrdColumn(name, NUMERIC_ORD),
535
+ // text
536
+ Text: (name) => new EncryptedTextColumn(name, TEXT),
537
+ TextEq: (name) => new EncryptedTextEqColumn(name, TEXT_EQ),
538
+ TextMatch: (name) => new EncryptedTextMatchColumn(name, TEXT_MATCH),
539
+ TextOrdOre: (name) => new EncryptedTextOrdOreColumn(name, TEXT_ORD_ORE),
540
+ TextOrd: (name) => new EncryptedTextOrdColumn(name, TEXT_ORD),
541
+ TextSearch: (name) => new EncryptedTextSearchColumn(name),
542
+ // boolean
543
+ Boolean: (name) => new EncryptedBooleanColumn(name, BOOLEAN),
544
+ // real
545
+ Real: (name) => new EncryptedRealColumn(name, REAL),
546
+ RealEq: (name) => new EncryptedRealEqColumn(name, REAL_EQ),
547
+ RealOrdOre: (name) => new EncryptedRealOrdOreColumn(name, REAL_ORD_ORE),
548
+ RealOrd: (name) => new EncryptedRealOrdColumn(name, REAL_ORD),
549
+ // double
550
+ Double: (name) => new EncryptedDoubleColumn(name, DOUBLE),
551
+ DoubleEq: (name) => new EncryptedDoubleEqColumn(name, DOUBLE_EQ),
552
+ DoubleOrdOre: (name) => new EncryptedDoubleOrdOreColumn(name, DOUBLE_ORD_ORE),
553
+ DoubleOrd: (name) => new EncryptedDoubleOrdColumn(name, DOUBLE_ORD),
554
+ // json (encrypted JSONB document, ste_vec containment)
555
+ Json: (name) => new EncryptedJsonColumn(name)
556
+ // `satisfies` is load-bearing, not decoration: `DOMAIN_REGISTRY` derives itself
557
+ // by calling every value here at module load. A non-factory export would throw
558
+ // during module evaluation and take the supabase introspect/schema-build/verify
559
+ // path down with it. This turns that into a compile error at the offending line.
560
+ // `as const` applies first, so literal key inference is preserved.
561
+ };
562
+
563
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
564
+ var external_exports = {};
565
+ __export(external_exports, {
566
+ BRAND: () => BRAND,
567
+ DIRTY: () => DIRTY,
568
+ EMPTY_PATH: () => EMPTY_PATH,
569
+ INVALID: () => INVALID,
570
+ NEVER: () => NEVER,
571
+ OK: () => OK,
572
+ ParseStatus: () => ParseStatus,
573
+ Schema: () => ZodType,
574
+ ZodAny: () => ZodAny,
575
+ ZodArray: () => ZodArray,
576
+ ZodBigInt: () => ZodBigInt,
577
+ ZodBoolean: () => ZodBoolean,
578
+ ZodBranded: () => ZodBranded,
579
+ ZodCatch: () => ZodCatch,
580
+ ZodDate: () => ZodDate,
581
+ ZodDefault: () => ZodDefault,
582
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
583
+ ZodEffects: () => ZodEffects,
584
+ ZodEnum: () => ZodEnum,
585
+ ZodError: () => ZodError,
586
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
587
+ ZodFunction: () => ZodFunction,
588
+ ZodIntersection: () => ZodIntersection,
589
+ ZodIssueCode: () => ZodIssueCode,
590
+ ZodLazy: () => ZodLazy,
591
+ ZodLiteral: () => ZodLiteral,
592
+ ZodMap: () => ZodMap,
593
+ ZodNaN: () => ZodNaN,
594
+ ZodNativeEnum: () => ZodNativeEnum,
595
+ ZodNever: () => ZodNever,
596
+ ZodNull: () => ZodNull,
597
+ ZodNullable: () => ZodNullable,
598
+ ZodNumber: () => ZodNumber,
599
+ ZodObject: () => ZodObject,
600
+ ZodOptional: () => ZodOptional,
601
+ ZodParsedType: () => ZodParsedType,
602
+ ZodPipeline: () => ZodPipeline,
603
+ ZodPromise: () => ZodPromise,
604
+ ZodReadonly: () => ZodReadonly,
605
+ ZodRecord: () => ZodRecord,
606
+ ZodSchema: () => ZodType,
607
+ ZodSet: () => ZodSet,
608
+ ZodString: () => ZodString,
609
+ ZodSymbol: () => ZodSymbol,
610
+ ZodTransformer: () => ZodEffects,
611
+ ZodTuple: () => ZodTuple,
612
+ ZodType: () => ZodType,
613
+ ZodUndefined: () => ZodUndefined,
614
+ ZodUnion: () => ZodUnion,
615
+ ZodUnknown: () => ZodUnknown,
616
+ ZodVoid: () => ZodVoid,
617
+ addIssueToContext: () => addIssueToContext,
618
+ any: () => anyType,
619
+ array: () => arrayType,
620
+ bigint: () => bigIntType,
621
+ boolean: () => booleanType,
622
+ coerce: () => coerce,
623
+ custom: () => custom,
624
+ date: () => dateType,
625
+ datetimeRegex: () => datetimeRegex,
626
+ defaultErrorMap: () => en_default,
627
+ discriminatedUnion: () => discriminatedUnionType,
628
+ effect: () => effectsType,
629
+ enum: () => enumType,
630
+ function: () => functionType,
631
+ getErrorMap: () => getErrorMap,
632
+ getParsedType: () => getParsedType,
633
+ instanceof: () => instanceOfType,
634
+ intersection: () => intersectionType,
635
+ isAborted: () => isAborted,
636
+ isAsync: () => isAsync,
637
+ isDirty: () => isDirty,
638
+ isValid: () => isValid,
639
+ late: () => late,
640
+ lazy: () => lazyType,
641
+ literal: () => literalType,
642
+ makeIssue: () => makeIssue,
643
+ map: () => mapType,
644
+ nan: () => nanType,
645
+ nativeEnum: () => nativeEnumType,
646
+ never: () => neverType,
647
+ null: () => nullType,
648
+ nullable: () => nullableType,
649
+ number: () => numberType,
650
+ object: () => objectType,
651
+ objectUtil: () => objectUtil,
652
+ oboolean: () => oboolean,
653
+ onumber: () => onumber,
654
+ optional: () => optionalType,
655
+ ostring: () => ostring,
656
+ pipeline: () => pipelineType,
657
+ preprocess: () => preprocessType,
658
+ promise: () => promiseType,
659
+ quotelessJson: () => quotelessJson,
660
+ record: () => recordType,
661
+ set: () => setType,
662
+ setErrorMap: () => setErrorMap,
663
+ strictObject: () => strictObjectType,
664
+ string: () => stringType,
665
+ symbol: () => symbolType,
666
+ transformer: () => effectsType,
667
+ tuple: () => tupleType,
668
+ undefined: () => undefinedType,
669
+ union: () => unionType,
670
+ unknown: () => unknownType,
671
+ util: () => util,
672
+ void: () => voidType
673
+ });
674
+
675
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
676
+ var util;
677
+ (function(util2) {
678
+ util2.assertEqual = (_) => {
679
+ };
680
+ function assertIs(_arg) {
681
+ }
682
+ util2.assertIs = assertIs;
683
+ function assertNever(_x) {
684
+ throw new Error();
685
+ }
686
+ util2.assertNever = assertNever;
687
+ util2.arrayToEnum = (items) => {
688
+ const obj = {};
689
+ for (const item of items) {
690
+ obj[item] = item;
691
+ }
692
+ return obj;
693
+ };
694
+ util2.getValidEnumValues = (obj) => {
695
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
696
+ const filtered = {};
697
+ for (const k of validKeys) {
698
+ filtered[k] = obj[k];
699
+ }
700
+ return util2.objectValues(filtered);
701
+ };
702
+ util2.objectValues = (obj) => {
703
+ return util2.objectKeys(obj).map(function(e) {
704
+ return obj[e];
705
+ });
706
+ };
707
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
708
+ const keys = [];
709
+ for (const key in object) {
710
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
711
+ keys.push(key);
712
+ }
713
+ }
714
+ return keys;
715
+ };
716
+ util2.find = (arr, checker) => {
717
+ for (const item of arr) {
718
+ if (checker(item))
719
+ return item;
720
+ }
721
+ return void 0;
722
+ };
723
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
724
+ function joinValues(array, separator = " | ") {
725
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
726
+ }
727
+ util2.joinValues = joinValues;
728
+ util2.jsonStringifyReplacer = (_, value) => {
729
+ if (typeof value === "bigint") {
730
+ return value.toString();
731
+ }
732
+ return value;
733
+ };
734
+ })(util || (util = {}));
735
+ var objectUtil;
736
+ (function(objectUtil2) {
737
+ objectUtil2.mergeShapes = (first, second) => {
738
+ return {
739
+ ...first,
740
+ ...second
741
+ // second overwrites first
742
+ };
743
+ };
744
+ })(objectUtil || (objectUtil = {}));
745
+ var ZodParsedType = util.arrayToEnum([
746
+ "string",
747
+ "nan",
748
+ "number",
749
+ "integer",
750
+ "float",
751
+ "boolean",
752
+ "date",
753
+ "bigint",
754
+ "symbol",
755
+ "function",
756
+ "undefined",
757
+ "null",
758
+ "array",
759
+ "object",
760
+ "unknown",
761
+ "promise",
762
+ "void",
763
+ "never",
764
+ "map",
765
+ "set"
766
+ ]);
767
+ var getParsedType = (data) => {
768
+ const t = typeof data;
769
+ switch (t) {
770
+ case "undefined":
771
+ return ZodParsedType.undefined;
772
+ case "string":
773
+ return ZodParsedType.string;
774
+ case "number":
775
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
776
+ case "boolean":
777
+ return ZodParsedType.boolean;
778
+ case "function":
779
+ return ZodParsedType.function;
780
+ case "bigint":
781
+ return ZodParsedType.bigint;
782
+ case "symbol":
783
+ return ZodParsedType.symbol;
784
+ case "object":
785
+ if (Array.isArray(data)) {
786
+ return ZodParsedType.array;
787
+ }
788
+ if (data === null) {
789
+ return ZodParsedType.null;
790
+ }
791
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
792
+ return ZodParsedType.promise;
793
+ }
794
+ if (typeof Map !== "undefined" && data instanceof Map) {
795
+ return ZodParsedType.map;
796
+ }
797
+ if (typeof Set !== "undefined" && data instanceof Set) {
798
+ return ZodParsedType.set;
799
+ }
800
+ if (typeof Date !== "undefined" && data instanceof Date) {
801
+ return ZodParsedType.date;
802
+ }
803
+ return ZodParsedType.object;
804
+ default:
805
+ return ZodParsedType.unknown;
806
+ }
807
+ };
808
+
809
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
810
+ var ZodIssueCode = util.arrayToEnum([
811
+ "invalid_type",
812
+ "invalid_literal",
813
+ "custom",
814
+ "invalid_union",
815
+ "invalid_union_discriminator",
816
+ "invalid_enum_value",
817
+ "unrecognized_keys",
818
+ "invalid_arguments",
819
+ "invalid_return_type",
820
+ "invalid_date",
821
+ "invalid_string",
822
+ "too_small",
823
+ "too_big",
824
+ "invalid_intersection_types",
825
+ "not_multiple_of",
826
+ "not_finite"
827
+ ]);
828
+ var quotelessJson = (obj) => {
829
+ const json = JSON.stringify(obj, null, 2);
830
+ return json.replace(/"([^"]+)":/g, "$1:");
831
+ };
832
+ var ZodError = class _ZodError extends Error {
833
+ get errors() {
834
+ return this.issues;
835
+ }
836
+ constructor(issues) {
837
+ super();
838
+ this.issues = [];
839
+ this.addIssue = (sub) => {
840
+ this.issues = [...this.issues, sub];
841
+ };
842
+ this.addIssues = (subs = []) => {
843
+ this.issues = [...this.issues, ...subs];
844
+ };
845
+ const actualProto = new.target.prototype;
846
+ if (Object.setPrototypeOf) {
847
+ Object.setPrototypeOf(this, actualProto);
848
+ } else {
849
+ this.__proto__ = actualProto;
850
+ }
851
+ this.name = "ZodError";
852
+ this.issues = issues;
853
+ }
854
+ format(_mapper) {
855
+ const mapper = _mapper || function(issue) {
856
+ return issue.message;
857
+ };
858
+ const fieldErrors = { _errors: [] };
859
+ const processError = (error) => {
860
+ for (const issue of error.issues) {
861
+ if (issue.code === "invalid_union") {
862
+ issue.unionErrors.map(processError);
863
+ } else if (issue.code === "invalid_return_type") {
864
+ processError(issue.returnTypeError);
865
+ } else if (issue.code === "invalid_arguments") {
866
+ processError(issue.argumentsError);
867
+ } else if (issue.path.length === 0) {
868
+ fieldErrors._errors.push(mapper(issue));
869
+ } else {
870
+ let curr = fieldErrors;
871
+ let i = 0;
872
+ while (i < issue.path.length) {
873
+ const el = issue.path[i];
874
+ const terminal = i === issue.path.length - 1;
875
+ if (!terminal) {
876
+ curr[el] = curr[el] || { _errors: [] };
877
+ } else {
878
+ curr[el] = curr[el] || { _errors: [] };
879
+ curr[el]._errors.push(mapper(issue));
880
+ }
881
+ curr = curr[el];
882
+ i++;
883
+ }
884
+ }
885
+ }
886
+ };
887
+ processError(this);
888
+ return fieldErrors;
889
+ }
890
+ static assert(value) {
891
+ if (!(value instanceof _ZodError)) {
892
+ throw new Error(`Not a ZodError: ${value}`);
893
+ }
894
+ }
895
+ toString() {
896
+ return this.message;
897
+ }
898
+ get message() {
899
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
900
+ }
901
+ get isEmpty() {
902
+ return this.issues.length === 0;
903
+ }
904
+ flatten(mapper = (issue) => issue.message) {
905
+ const fieldErrors = {};
906
+ const formErrors = [];
907
+ for (const sub of this.issues) {
908
+ if (sub.path.length > 0) {
909
+ const firstEl = sub.path[0];
910
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
911
+ fieldErrors[firstEl].push(mapper(sub));
912
+ } else {
913
+ formErrors.push(mapper(sub));
914
+ }
915
+ }
916
+ return { formErrors, fieldErrors };
917
+ }
918
+ get formErrors() {
919
+ return this.flatten();
920
+ }
921
+ };
922
+ ZodError.create = (issues) => {
923
+ const error = new ZodError(issues);
924
+ return error;
925
+ };
926
+
927
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
928
+ var errorMap = (issue, _ctx) => {
929
+ let message;
930
+ switch (issue.code) {
931
+ case ZodIssueCode.invalid_type:
932
+ if (issue.received === ZodParsedType.undefined) {
933
+ message = "Required";
934
+ } else {
935
+ message = `Expected ${issue.expected}, received ${issue.received}`;
936
+ }
937
+ break;
938
+ case ZodIssueCode.invalid_literal:
939
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
940
+ break;
941
+ case ZodIssueCode.unrecognized_keys:
942
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
943
+ break;
944
+ case ZodIssueCode.invalid_union:
945
+ message = `Invalid input`;
946
+ break;
947
+ case ZodIssueCode.invalid_union_discriminator:
948
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
949
+ break;
950
+ case ZodIssueCode.invalid_enum_value:
951
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
952
+ break;
953
+ case ZodIssueCode.invalid_arguments:
954
+ message = `Invalid function arguments`;
955
+ break;
956
+ case ZodIssueCode.invalid_return_type:
957
+ message = `Invalid function return type`;
958
+ break;
959
+ case ZodIssueCode.invalid_date:
960
+ message = `Invalid date`;
961
+ break;
962
+ case ZodIssueCode.invalid_string:
963
+ if (typeof issue.validation === "object") {
964
+ if ("includes" in issue.validation) {
965
+ message = `Invalid input: must include "${issue.validation.includes}"`;
966
+ if (typeof issue.validation.position === "number") {
967
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
968
+ }
969
+ } else if ("startsWith" in issue.validation) {
970
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
971
+ } else if ("endsWith" in issue.validation) {
972
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
973
+ } else {
974
+ util.assertNever(issue.validation);
975
+ }
976
+ } else if (issue.validation !== "regex") {
977
+ message = `Invalid ${issue.validation}`;
978
+ } else {
979
+ message = "Invalid";
980
+ }
981
+ break;
982
+ case ZodIssueCode.too_small:
983
+ if (issue.type === "array")
984
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
985
+ else if (issue.type === "string")
986
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
987
+ else if (issue.type === "number")
988
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
989
+ else if (issue.type === "bigint")
990
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
991
+ else if (issue.type === "date")
992
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
993
+ else
994
+ message = "Invalid input";
995
+ break;
996
+ case ZodIssueCode.too_big:
997
+ if (issue.type === "array")
998
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
999
+ else if (issue.type === "string")
1000
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
1001
+ else if (issue.type === "number")
1002
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1003
+ else if (issue.type === "bigint")
1004
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1005
+ else if (issue.type === "date")
1006
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
1007
+ else
1008
+ message = "Invalid input";
1009
+ break;
1010
+ case ZodIssueCode.custom:
1011
+ message = `Invalid input`;
1012
+ break;
1013
+ case ZodIssueCode.invalid_intersection_types:
1014
+ message = `Intersection results could not be merged`;
1015
+ break;
1016
+ case ZodIssueCode.not_multiple_of:
1017
+ message = `Number must be a multiple of ${issue.multipleOf}`;
1018
+ break;
1019
+ case ZodIssueCode.not_finite:
1020
+ message = "Number must be finite";
1021
+ break;
1022
+ default:
1023
+ message = _ctx.defaultError;
1024
+ util.assertNever(issue);
1025
+ }
1026
+ return { message };
1027
+ };
1028
+ var en_default = errorMap;
1029
+
1030
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
1031
+ var overrideErrorMap = en_default;
1032
+ function setErrorMap(map) {
1033
+ overrideErrorMap = map;
1034
+ }
1035
+ function getErrorMap() {
1036
+ return overrideErrorMap;
1037
+ }
1038
+
1039
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
1040
+ var makeIssue = (params) => {
1041
+ const { data, path, errorMaps, issueData } = params;
1042
+ const fullPath = [...path, ...issueData.path || []];
1043
+ const fullIssue = {
1044
+ ...issueData,
1045
+ path: fullPath
1046
+ };
1047
+ if (issueData.message !== void 0) {
1048
+ return {
1049
+ ...issueData,
1050
+ path: fullPath,
1051
+ message: issueData.message
1052
+ };
1053
+ }
1054
+ let errorMessage = "";
1055
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
1056
+ for (const map of maps) {
1057
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
1058
+ }
1059
+ return {
1060
+ ...issueData,
1061
+ path: fullPath,
1062
+ message: errorMessage
1063
+ };
1064
+ };
1065
+ var EMPTY_PATH = [];
1066
+ function addIssueToContext(ctx, issueData) {
1067
+ const overrideMap = getErrorMap();
1068
+ const issue = makeIssue({
1069
+ issueData,
1070
+ data: ctx.data,
1071
+ path: ctx.path,
1072
+ errorMaps: [
1073
+ ctx.common.contextualErrorMap,
1074
+ // contextual error map is first priority
1075
+ ctx.schemaErrorMap,
1076
+ // then schema-bound map if available
1077
+ overrideMap,
1078
+ // then global override map
1079
+ overrideMap === en_default ? void 0 : en_default
1080
+ // then global default map
1081
+ ].filter((x) => !!x)
1082
+ });
1083
+ ctx.common.issues.push(issue);
1084
+ }
1085
+ var ParseStatus = class _ParseStatus {
1086
+ constructor() {
1087
+ this.value = "valid";
1088
+ }
1089
+ dirty() {
1090
+ if (this.value === "valid")
1091
+ this.value = "dirty";
1092
+ }
1093
+ abort() {
1094
+ if (this.value !== "aborted")
1095
+ this.value = "aborted";
1096
+ }
1097
+ static mergeArray(status, results) {
1098
+ const arrayValue = [];
1099
+ for (const s of results) {
1100
+ if (s.status === "aborted")
1101
+ return INVALID;
1102
+ if (s.status === "dirty")
1103
+ status.dirty();
1104
+ arrayValue.push(s.value);
1105
+ }
1106
+ return { status: status.value, value: arrayValue };
1107
+ }
1108
+ static async mergeObjectAsync(status, pairs) {
1109
+ const syncPairs = [];
1110
+ for (const pair of pairs) {
1111
+ const key = await pair.key;
1112
+ const value = await pair.value;
1113
+ syncPairs.push({
1114
+ key,
1115
+ value
1116
+ });
1117
+ }
1118
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
1119
+ }
1120
+ static mergeObjectSync(status, pairs) {
1121
+ const finalObject = {};
1122
+ for (const pair of pairs) {
1123
+ const { key, value } = pair;
1124
+ if (key.status === "aborted")
1125
+ return INVALID;
1126
+ if (value.status === "aborted")
1127
+ return INVALID;
1128
+ if (key.status === "dirty")
1129
+ status.dirty();
1130
+ if (value.status === "dirty")
1131
+ status.dirty();
1132
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
1133
+ finalObject[key.value] = value.value;
1134
+ }
1135
+ }
1136
+ return { status: status.value, value: finalObject };
1137
+ }
1138
+ };
1139
+ var INVALID = Object.freeze({
1140
+ status: "aborted"
1141
+ });
1142
+ var DIRTY = (value) => ({ status: "dirty", value });
1143
+ var OK = (value) => ({ status: "valid", value });
1144
+ var isAborted = (x) => x.status === "aborted";
1145
+ var isDirty = (x) => x.status === "dirty";
1146
+ var isValid = (x) => x.status === "valid";
1147
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
1148
+
1149
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
1150
+ var errorUtil;
1151
+ (function(errorUtil2) {
1152
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1153
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
1154
+ })(errorUtil || (errorUtil = {}));
1155
+
1156
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
1157
+ var ParseInputLazyPath = class {
1158
+ constructor(parent, value, path, key) {
1159
+ this._cachedPath = [];
1160
+ this.parent = parent;
1161
+ this.data = value;
1162
+ this._path = path;
1163
+ this._key = key;
1164
+ }
1165
+ get path() {
1166
+ if (!this._cachedPath.length) {
1167
+ if (Array.isArray(this._key)) {
1168
+ this._cachedPath.push(...this._path, ...this._key);
1169
+ } else {
1170
+ this._cachedPath.push(...this._path, this._key);
1171
+ }
1172
+ }
1173
+ return this._cachedPath;
1174
+ }
1175
+ };
1176
+ var handleResult = (ctx, result) => {
1177
+ if (isValid(result)) {
1178
+ return { success: true, data: result.value };
1179
+ } else {
1180
+ if (!ctx.common.issues.length) {
1181
+ throw new Error("Validation failed but no issues detected.");
1182
+ }
1183
+ return {
1184
+ success: false,
1185
+ get error() {
1186
+ if (this._error)
1187
+ return this._error;
1188
+ const error = new ZodError(ctx.common.issues);
1189
+ this._error = error;
1190
+ return this._error;
1191
+ }
1192
+ };
1193
+ }
1194
+ };
1195
+ function processCreateParams(params) {
1196
+ if (!params)
1197
+ return {};
1198
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
1199
+ if (errorMap2 && (invalid_type_error || required_error)) {
1200
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
1201
+ }
1202
+ if (errorMap2)
1203
+ return { errorMap: errorMap2, description };
1204
+ const customMap = (iss, ctx) => {
1205
+ const { message } = params;
1206
+ if (iss.code === "invalid_enum_value") {
1207
+ return { message: message ?? ctx.defaultError };
1208
+ }
1209
+ if (typeof ctx.data === "undefined") {
1210
+ return { message: message ?? required_error ?? ctx.defaultError };
1211
+ }
1212
+ if (iss.code !== "invalid_type")
1213
+ return { message: ctx.defaultError };
1214
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
1215
+ };
1216
+ return { errorMap: customMap, description };
1217
+ }
1218
+ var ZodType = class {
1219
+ get description() {
1220
+ return this._def.description;
1221
+ }
1222
+ _getType(input) {
1223
+ return getParsedType(input.data);
1224
+ }
1225
+ _getOrReturnCtx(input, ctx) {
1226
+ return ctx || {
1227
+ common: input.parent.common,
1228
+ data: input.data,
1229
+ parsedType: getParsedType(input.data),
1230
+ schemaErrorMap: this._def.errorMap,
1231
+ path: input.path,
1232
+ parent: input.parent
1233
+ };
1234
+ }
1235
+ _processInputParams(input) {
1236
+ return {
1237
+ status: new ParseStatus(),
1238
+ ctx: {
1239
+ common: input.parent.common,
1240
+ data: input.data,
1241
+ parsedType: getParsedType(input.data),
1242
+ schemaErrorMap: this._def.errorMap,
1243
+ path: input.path,
1244
+ parent: input.parent
1245
+ }
1246
+ };
1247
+ }
1248
+ _parseSync(input) {
1249
+ const result = this._parse(input);
1250
+ if (isAsync(result)) {
1251
+ throw new Error("Synchronous parse encountered promise.");
1252
+ }
1253
+ return result;
1254
+ }
1255
+ _parseAsync(input) {
1256
+ const result = this._parse(input);
1257
+ return Promise.resolve(result);
1258
+ }
1259
+ parse(data, params) {
1260
+ const result = this.safeParse(data, params);
1261
+ if (result.success)
1262
+ return result.data;
1263
+ throw result.error;
1264
+ }
1265
+ safeParse(data, params) {
1266
+ const ctx = {
1267
+ common: {
1268
+ issues: [],
1269
+ async: params?.async ?? false,
1270
+ contextualErrorMap: params?.errorMap
1271
+ },
1272
+ path: params?.path || [],
1273
+ schemaErrorMap: this._def.errorMap,
1274
+ parent: null,
1275
+ data,
1276
+ parsedType: getParsedType(data)
1277
+ };
1278
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
1279
+ return handleResult(ctx, result);
1280
+ }
1281
+ "~validate"(data) {
1282
+ const ctx = {
1283
+ common: {
1284
+ issues: [],
1285
+ async: !!this["~standard"].async
1286
+ },
1287
+ path: [],
1288
+ schemaErrorMap: this._def.errorMap,
1289
+ parent: null,
1290
+ data,
1291
+ parsedType: getParsedType(data)
1292
+ };
1293
+ if (!this["~standard"].async) {
1294
+ try {
1295
+ const result = this._parseSync({ data, path: [], parent: ctx });
1296
+ return isValid(result) ? {
1297
+ value: result.value
1298
+ } : {
1299
+ issues: ctx.common.issues
1300
+ };
1301
+ } catch (err) {
1302
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
1303
+ this["~standard"].async = true;
1304
+ }
1305
+ ctx.common = {
1306
+ issues: [],
1307
+ async: true
1308
+ };
1309
+ }
1310
+ }
1311
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
1312
+ value: result.value
1313
+ } : {
1314
+ issues: ctx.common.issues
1315
+ });
1316
+ }
1317
+ async parseAsync(data, params) {
1318
+ const result = await this.safeParseAsync(data, params);
1319
+ if (result.success)
1320
+ return result.data;
1321
+ throw result.error;
1322
+ }
1323
+ async safeParseAsync(data, params) {
1324
+ const ctx = {
1325
+ common: {
1326
+ issues: [],
1327
+ contextualErrorMap: params?.errorMap,
1328
+ async: true
1329
+ },
1330
+ path: params?.path || [],
1331
+ schemaErrorMap: this._def.errorMap,
1332
+ parent: null,
1333
+ data,
1334
+ parsedType: getParsedType(data)
1335
+ };
1336
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
1337
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
1338
+ return handleResult(ctx, result);
1339
+ }
1340
+ refine(check, message) {
1341
+ const getIssueProperties = (val) => {
1342
+ if (typeof message === "string" || typeof message === "undefined") {
1343
+ return { message };
1344
+ } else if (typeof message === "function") {
1345
+ return message(val);
1346
+ } else {
1347
+ return message;
1348
+ }
1349
+ };
1350
+ return this._refinement((val, ctx) => {
1351
+ const result = check(val);
1352
+ const setError = () => ctx.addIssue({
1353
+ code: ZodIssueCode.custom,
1354
+ ...getIssueProperties(val)
1355
+ });
1356
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
1357
+ return result.then((data) => {
1358
+ if (!data) {
1359
+ setError();
1360
+ return false;
1361
+ } else {
1362
+ return true;
1363
+ }
1364
+ });
1365
+ }
1366
+ if (!result) {
1367
+ setError();
1368
+ return false;
1369
+ } else {
1370
+ return true;
1371
+ }
1372
+ });
1373
+ }
1374
+ refinement(check, refinementData) {
1375
+ return this._refinement((val, ctx) => {
1376
+ if (!check(val)) {
1377
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
1378
+ return false;
1379
+ } else {
1380
+ return true;
1381
+ }
1382
+ });
1383
+ }
1384
+ _refinement(refinement) {
1385
+ return new ZodEffects({
1386
+ schema: this,
1387
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
1388
+ effect: { type: "refinement", refinement }
1389
+ });
1390
+ }
1391
+ superRefine(refinement) {
1392
+ return this._refinement(refinement);
1393
+ }
1394
+ constructor(def) {
1395
+ this.spa = this.safeParseAsync;
1396
+ this._def = def;
1397
+ this.parse = this.parse.bind(this);
1398
+ this.safeParse = this.safeParse.bind(this);
1399
+ this.parseAsync = this.parseAsync.bind(this);
1400
+ this.safeParseAsync = this.safeParseAsync.bind(this);
1401
+ this.spa = this.spa.bind(this);
1402
+ this.refine = this.refine.bind(this);
1403
+ this.refinement = this.refinement.bind(this);
1404
+ this.superRefine = this.superRefine.bind(this);
1405
+ this.optional = this.optional.bind(this);
1406
+ this.nullable = this.nullable.bind(this);
1407
+ this.nullish = this.nullish.bind(this);
1408
+ this.array = this.array.bind(this);
1409
+ this.promise = this.promise.bind(this);
1410
+ this.or = this.or.bind(this);
1411
+ this.and = this.and.bind(this);
1412
+ this.transform = this.transform.bind(this);
1413
+ this.brand = this.brand.bind(this);
1414
+ this.default = this.default.bind(this);
1415
+ this.catch = this.catch.bind(this);
1416
+ this.describe = this.describe.bind(this);
1417
+ this.pipe = this.pipe.bind(this);
1418
+ this.readonly = this.readonly.bind(this);
1419
+ this.isNullable = this.isNullable.bind(this);
1420
+ this.isOptional = this.isOptional.bind(this);
1421
+ this["~standard"] = {
1422
+ version: 1,
1423
+ vendor: "zod",
1424
+ validate: (data) => this["~validate"](data)
1425
+ };
1426
+ }
1427
+ optional() {
1428
+ return ZodOptional.create(this, this._def);
1429
+ }
1430
+ nullable() {
1431
+ return ZodNullable.create(this, this._def);
1432
+ }
1433
+ nullish() {
1434
+ return this.nullable().optional();
1435
+ }
1436
+ array() {
1437
+ return ZodArray.create(this);
1438
+ }
1439
+ promise() {
1440
+ return ZodPromise.create(this, this._def);
1441
+ }
1442
+ or(option) {
1443
+ return ZodUnion.create([this, option], this._def);
1444
+ }
1445
+ and(incoming) {
1446
+ return ZodIntersection.create(this, incoming, this._def);
1447
+ }
1448
+ transform(transform) {
1449
+ return new ZodEffects({
1450
+ ...processCreateParams(this._def),
1451
+ schema: this,
1452
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
1453
+ effect: { type: "transform", transform }
1454
+ });
1455
+ }
1456
+ default(def) {
1457
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
1458
+ return new ZodDefault({
1459
+ ...processCreateParams(this._def),
1460
+ innerType: this,
1461
+ defaultValue: defaultValueFunc,
1462
+ typeName: ZodFirstPartyTypeKind.ZodDefault
1463
+ });
1464
+ }
1465
+ brand() {
1466
+ return new ZodBranded({
1467
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
1468
+ type: this,
1469
+ ...processCreateParams(this._def)
1470
+ });
1471
+ }
1472
+ catch(def) {
1473
+ const catchValueFunc = typeof def === "function" ? def : () => def;
1474
+ return new ZodCatch({
1475
+ ...processCreateParams(this._def),
1476
+ innerType: this,
1477
+ catchValue: catchValueFunc,
1478
+ typeName: ZodFirstPartyTypeKind.ZodCatch
1479
+ });
1480
+ }
1481
+ describe(description) {
1482
+ const This = this.constructor;
1483
+ return new This({
1484
+ ...this._def,
1485
+ description
1486
+ });
1487
+ }
1488
+ pipe(target) {
1489
+ return ZodPipeline.create(this, target);
1490
+ }
1491
+ readonly() {
1492
+ return ZodReadonly.create(this);
1493
+ }
1494
+ isOptional() {
1495
+ return this.safeParse(void 0).success;
1496
+ }
1497
+ isNullable() {
1498
+ return this.safeParse(null).success;
1499
+ }
1500
+ };
1501
+ var cuidRegex = /^c[^\s-]{8,}$/i;
1502
+ var cuid2Regex = /^[0-9a-z]+$/;
1503
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
1504
+ var 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;
1505
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
1506
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
1507
+ var 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)?)??$/;
1508
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
1509
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1510
+ var emojiRegex;
1511
+ var 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])$/;
1512
+ var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
1513
+ var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
1514
+ var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
1515
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
1516
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
1517
+ var 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])))`;
1518
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
1519
+ function timeRegexSource(args) {
1520
+ let secondsRegexSource = `[0-5]\\d`;
1521
+ if (args.precision) {
1522
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
1523
+ } else if (args.precision == null) {
1524
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
1525
+ }
1526
+ const secondsQuantifier = args.precision ? "+" : "?";
1527
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
1528
+ }
1529
+ function timeRegex(args) {
1530
+ return new RegExp(`^${timeRegexSource(args)}$`);
1531
+ }
1532
+ function datetimeRegex(args) {
1533
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
1534
+ const opts = [];
1535
+ opts.push(args.local ? `Z?` : `Z`);
1536
+ if (args.offset)
1537
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
1538
+ regex = `${regex}(${opts.join("|")})`;
1539
+ return new RegExp(`^${regex}$`);
1540
+ }
1541
+ function isValidIP(ip, version) {
1542
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
1543
+ return true;
1544
+ }
1545
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
1546
+ return true;
1547
+ }
1548
+ return false;
1549
+ }
1550
+ function isValidJWT(jwt, alg) {
1551
+ if (!jwtRegex.test(jwt))
1552
+ return false;
1553
+ try {
1554
+ const [header] = jwt.split(".");
1555
+ if (!header)
1556
+ return false;
1557
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
1558
+ const decoded = JSON.parse(atob(base64));
1559
+ if (typeof decoded !== "object" || decoded === null)
1560
+ return false;
1561
+ if ("typ" in decoded && decoded?.typ !== "JWT")
1562
+ return false;
1563
+ if (!decoded.alg)
1564
+ return false;
1565
+ if (alg && decoded.alg !== alg)
1566
+ return false;
1567
+ return true;
1568
+ } catch {
1569
+ return false;
1570
+ }
1571
+ }
1572
+ function isValidCidr(ip, version) {
1573
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
1574
+ return true;
1575
+ }
1576
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
1577
+ return true;
1578
+ }
1579
+ return false;
1580
+ }
1581
+ var ZodString = class _ZodString extends ZodType {
1582
+ _parse(input) {
1583
+ if (this._def.coerce) {
1584
+ input.data = String(input.data);
1585
+ }
1586
+ const parsedType = this._getType(input);
1587
+ if (parsedType !== ZodParsedType.string) {
1588
+ const ctx2 = this._getOrReturnCtx(input);
1589
+ addIssueToContext(ctx2, {
1590
+ code: ZodIssueCode.invalid_type,
1591
+ expected: ZodParsedType.string,
1592
+ received: ctx2.parsedType
1593
+ });
1594
+ return INVALID;
1595
+ }
1596
+ const status = new ParseStatus();
1597
+ let ctx = void 0;
1598
+ for (const check of this._def.checks) {
1599
+ if (check.kind === "min") {
1600
+ if (input.data.length < check.value) {
1601
+ ctx = this._getOrReturnCtx(input, ctx);
1602
+ addIssueToContext(ctx, {
1603
+ code: ZodIssueCode.too_small,
1604
+ minimum: check.value,
1605
+ type: "string",
1606
+ inclusive: true,
1607
+ exact: false,
1608
+ message: check.message
1609
+ });
1610
+ status.dirty();
1611
+ }
1612
+ } else if (check.kind === "max") {
1613
+ if (input.data.length > check.value) {
1614
+ ctx = this._getOrReturnCtx(input, ctx);
1615
+ addIssueToContext(ctx, {
1616
+ code: ZodIssueCode.too_big,
1617
+ maximum: check.value,
1618
+ type: "string",
1619
+ inclusive: true,
1620
+ exact: false,
1621
+ message: check.message
1622
+ });
1623
+ status.dirty();
1624
+ }
1625
+ } else if (check.kind === "length") {
1626
+ const tooBig = input.data.length > check.value;
1627
+ const tooSmall = input.data.length < check.value;
1628
+ if (tooBig || tooSmall) {
1629
+ ctx = this._getOrReturnCtx(input, ctx);
1630
+ if (tooBig) {
1631
+ addIssueToContext(ctx, {
1632
+ code: ZodIssueCode.too_big,
1633
+ maximum: check.value,
1634
+ type: "string",
1635
+ inclusive: true,
1636
+ exact: true,
1637
+ message: check.message
1638
+ });
1639
+ } else if (tooSmall) {
1640
+ addIssueToContext(ctx, {
1641
+ code: ZodIssueCode.too_small,
1642
+ minimum: check.value,
1643
+ type: "string",
1644
+ inclusive: true,
1645
+ exact: true,
1646
+ message: check.message
1647
+ });
1648
+ }
1649
+ status.dirty();
1650
+ }
1651
+ } else if (check.kind === "email") {
1652
+ if (!emailRegex.test(input.data)) {
1653
+ ctx = this._getOrReturnCtx(input, ctx);
1654
+ addIssueToContext(ctx, {
1655
+ validation: "email",
1656
+ code: ZodIssueCode.invalid_string,
1657
+ message: check.message
1658
+ });
1659
+ status.dirty();
1660
+ }
1661
+ } else if (check.kind === "emoji") {
1662
+ if (!emojiRegex) {
1663
+ emojiRegex = new RegExp(_emojiRegex, "u");
1664
+ }
1665
+ if (!emojiRegex.test(input.data)) {
1666
+ ctx = this._getOrReturnCtx(input, ctx);
1667
+ addIssueToContext(ctx, {
1668
+ validation: "emoji",
1669
+ code: ZodIssueCode.invalid_string,
1670
+ message: check.message
1671
+ });
1672
+ status.dirty();
1673
+ }
1674
+ } else if (check.kind === "uuid") {
1675
+ if (!uuidRegex.test(input.data)) {
1676
+ ctx = this._getOrReturnCtx(input, ctx);
1677
+ addIssueToContext(ctx, {
1678
+ validation: "uuid",
1679
+ code: ZodIssueCode.invalid_string,
1680
+ message: check.message
1681
+ });
1682
+ status.dirty();
1683
+ }
1684
+ } else if (check.kind === "nanoid") {
1685
+ if (!nanoidRegex.test(input.data)) {
1686
+ ctx = this._getOrReturnCtx(input, ctx);
1687
+ addIssueToContext(ctx, {
1688
+ validation: "nanoid",
1689
+ code: ZodIssueCode.invalid_string,
1690
+ message: check.message
1691
+ });
1692
+ status.dirty();
1693
+ }
1694
+ } else if (check.kind === "cuid") {
1695
+ if (!cuidRegex.test(input.data)) {
1696
+ ctx = this._getOrReturnCtx(input, ctx);
1697
+ addIssueToContext(ctx, {
1698
+ validation: "cuid",
1699
+ code: ZodIssueCode.invalid_string,
1700
+ message: check.message
1701
+ });
1702
+ status.dirty();
1703
+ }
1704
+ } else if (check.kind === "cuid2") {
1705
+ if (!cuid2Regex.test(input.data)) {
1706
+ ctx = this._getOrReturnCtx(input, ctx);
1707
+ addIssueToContext(ctx, {
1708
+ validation: "cuid2",
1709
+ code: ZodIssueCode.invalid_string,
1710
+ message: check.message
1711
+ });
1712
+ status.dirty();
1713
+ }
1714
+ } else if (check.kind === "ulid") {
1715
+ if (!ulidRegex.test(input.data)) {
1716
+ ctx = this._getOrReturnCtx(input, ctx);
1717
+ addIssueToContext(ctx, {
1718
+ validation: "ulid",
1719
+ code: ZodIssueCode.invalid_string,
1720
+ message: check.message
1721
+ });
1722
+ status.dirty();
1723
+ }
1724
+ } else if (check.kind === "url") {
1725
+ try {
1726
+ new URL(input.data);
1727
+ } catch {
1728
+ ctx = this._getOrReturnCtx(input, ctx);
1729
+ addIssueToContext(ctx, {
1730
+ validation: "url",
1731
+ code: ZodIssueCode.invalid_string,
1732
+ message: check.message
1733
+ });
1734
+ status.dirty();
1735
+ }
1736
+ } else if (check.kind === "regex") {
1737
+ check.regex.lastIndex = 0;
1738
+ const testResult = check.regex.test(input.data);
1739
+ if (!testResult) {
1740
+ ctx = this._getOrReturnCtx(input, ctx);
1741
+ addIssueToContext(ctx, {
1742
+ validation: "regex",
1743
+ code: ZodIssueCode.invalid_string,
1744
+ message: check.message
1745
+ });
1746
+ status.dirty();
1747
+ }
1748
+ } else if (check.kind === "trim") {
1749
+ input.data = input.data.trim();
1750
+ } else if (check.kind === "includes") {
1751
+ if (!input.data.includes(check.value, check.position)) {
1752
+ ctx = this._getOrReturnCtx(input, ctx);
1753
+ addIssueToContext(ctx, {
1754
+ code: ZodIssueCode.invalid_string,
1755
+ validation: { includes: check.value, position: check.position },
1756
+ message: check.message
1757
+ });
1758
+ status.dirty();
1759
+ }
1760
+ } else if (check.kind === "toLowerCase") {
1761
+ input.data = input.data.toLowerCase();
1762
+ } else if (check.kind === "toUpperCase") {
1763
+ input.data = input.data.toUpperCase();
1764
+ } else if (check.kind === "startsWith") {
1765
+ if (!input.data.startsWith(check.value)) {
1766
+ ctx = this._getOrReturnCtx(input, ctx);
1767
+ addIssueToContext(ctx, {
1768
+ code: ZodIssueCode.invalid_string,
1769
+ validation: { startsWith: check.value },
1770
+ message: check.message
1771
+ });
1772
+ status.dirty();
1773
+ }
1774
+ } else if (check.kind === "endsWith") {
1775
+ if (!input.data.endsWith(check.value)) {
1776
+ ctx = this._getOrReturnCtx(input, ctx);
1777
+ addIssueToContext(ctx, {
1778
+ code: ZodIssueCode.invalid_string,
1779
+ validation: { endsWith: check.value },
1780
+ message: check.message
1781
+ });
1782
+ status.dirty();
1783
+ }
1784
+ } else if (check.kind === "datetime") {
1785
+ const regex = datetimeRegex(check);
1786
+ if (!regex.test(input.data)) {
1787
+ ctx = this._getOrReturnCtx(input, ctx);
1788
+ addIssueToContext(ctx, {
1789
+ code: ZodIssueCode.invalid_string,
1790
+ validation: "datetime",
1791
+ message: check.message
1792
+ });
1793
+ status.dirty();
1794
+ }
1795
+ } else if (check.kind === "date") {
1796
+ const regex = dateRegex;
1797
+ if (!regex.test(input.data)) {
1798
+ ctx = this._getOrReturnCtx(input, ctx);
1799
+ addIssueToContext(ctx, {
1800
+ code: ZodIssueCode.invalid_string,
1801
+ validation: "date",
1802
+ message: check.message
1803
+ });
1804
+ status.dirty();
1805
+ }
1806
+ } else if (check.kind === "time") {
1807
+ const regex = timeRegex(check);
1808
+ if (!regex.test(input.data)) {
1809
+ ctx = this._getOrReturnCtx(input, ctx);
1810
+ addIssueToContext(ctx, {
1811
+ code: ZodIssueCode.invalid_string,
1812
+ validation: "time",
1813
+ message: check.message
1814
+ });
1815
+ status.dirty();
1816
+ }
1817
+ } else if (check.kind === "duration") {
1818
+ if (!durationRegex.test(input.data)) {
1819
+ ctx = this._getOrReturnCtx(input, ctx);
1820
+ addIssueToContext(ctx, {
1821
+ validation: "duration",
1822
+ code: ZodIssueCode.invalid_string,
1823
+ message: check.message
1824
+ });
1825
+ status.dirty();
1826
+ }
1827
+ } else if (check.kind === "ip") {
1828
+ if (!isValidIP(input.data, check.version)) {
1829
+ ctx = this._getOrReturnCtx(input, ctx);
1830
+ addIssueToContext(ctx, {
1831
+ validation: "ip",
1832
+ code: ZodIssueCode.invalid_string,
1833
+ message: check.message
1834
+ });
1835
+ status.dirty();
1836
+ }
1837
+ } else if (check.kind === "jwt") {
1838
+ if (!isValidJWT(input.data, check.alg)) {
1839
+ ctx = this._getOrReturnCtx(input, ctx);
1840
+ addIssueToContext(ctx, {
1841
+ validation: "jwt",
1842
+ code: ZodIssueCode.invalid_string,
1843
+ message: check.message
1844
+ });
1845
+ status.dirty();
1846
+ }
1847
+ } else if (check.kind === "cidr") {
1848
+ if (!isValidCidr(input.data, check.version)) {
1849
+ ctx = this._getOrReturnCtx(input, ctx);
1850
+ addIssueToContext(ctx, {
1851
+ validation: "cidr",
1852
+ code: ZodIssueCode.invalid_string,
1853
+ message: check.message
1854
+ });
1855
+ status.dirty();
1856
+ }
1857
+ } else if (check.kind === "base64") {
1858
+ if (!base64Regex.test(input.data)) {
1859
+ ctx = this._getOrReturnCtx(input, ctx);
1860
+ addIssueToContext(ctx, {
1861
+ validation: "base64",
1862
+ code: ZodIssueCode.invalid_string,
1863
+ message: check.message
1864
+ });
1865
+ status.dirty();
1866
+ }
1867
+ } else if (check.kind === "base64url") {
1868
+ if (!base64urlRegex.test(input.data)) {
1869
+ ctx = this._getOrReturnCtx(input, ctx);
1870
+ addIssueToContext(ctx, {
1871
+ validation: "base64url",
1872
+ code: ZodIssueCode.invalid_string,
1873
+ message: check.message
1874
+ });
1875
+ status.dirty();
1876
+ }
1877
+ } else {
1878
+ util.assertNever(check);
1879
+ }
1880
+ }
1881
+ return { status: status.value, value: input.data };
1882
+ }
1883
+ _regex(regex, validation, message) {
1884
+ return this.refinement((data) => regex.test(data), {
1885
+ validation,
1886
+ code: ZodIssueCode.invalid_string,
1887
+ ...errorUtil.errToObj(message)
1888
+ });
1889
+ }
1890
+ _addCheck(check) {
1891
+ return new _ZodString({
1892
+ ...this._def,
1893
+ checks: [...this._def.checks, check]
1894
+ });
1895
+ }
1896
+ email(message) {
1897
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1898
+ }
1899
+ url(message) {
1900
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1901
+ }
1902
+ emoji(message) {
1903
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1904
+ }
1905
+ uuid(message) {
1906
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1907
+ }
1908
+ nanoid(message) {
1909
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1910
+ }
1911
+ cuid(message) {
1912
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1913
+ }
1914
+ cuid2(message) {
1915
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1916
+ }
1917
+ ulid(message) {
1918
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1919
+ }
1920
+ base64(message) {
1921
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1922
+ }
1923
+ base64url(message) {
1924
+ return this._addCheck({
1925
+ kind: "base64url",
1926
+ ...errorUtil.errToObj(message)
1927
+ });
1928
+ }
1929
+ jwt(options) {
1930
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1931
+ }
1932
+ ip(options) {
1933
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1934
+ }
1935
+ cidr(options) {
1936
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1937
+ }
1938
+ datetime(options) {
1939
+ if (typeof options === "string") {
1940
+ return this._addCheck({
1941
+ kind: "datetime",
1942
+ precision: null,
1943
+ offset: false,
1944
+ local: false,
1945
+ message: options
1946
+ });
1947
+ }
1948
+ return this._addCheck({
1949
+ kind: "datetime",
1950
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1951
+ offset: options?.offset ?? false,
1952
+ local: options?.local ?? false,
1953
+ ...errorUtil.errToObj(options?.message)
1954
+ });
1955
+ }
1956
+ date(message) {
1957
+ return this._addCheck({ kind: "date", message });
1958
+ }
1959
+ time(options) {
1960
+ if (typeof options === "string") {
1961
+ return this._addCheck({
1962
+ kind: "time",
1963
+ precision: null,
1964
+ message: options
1965
+ });
1966
+ }
1967
+ return this._addCheck({
1968
+ kind: "time",
1969
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1970
+ ...errorUtil.errToObj(options?.message)
1971
+ });
1972
+ }
1973
+ duration(message) {
1974
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1975
+ }
1976
+ regex(regex, message) {
1977
+ return this._addCheck({
1978
+ kind: "regex",
1979
+ regex,
1980
+ ...errorUtil.errToObj(message)
1981
+ });
1982
+ }
1983
+ includes(value, options) {
1984
+ return this._addCheck({
1985
+ kind: "includes",
1986
+ value,
1987
+ position: options?.position,
1988
+ ...errorUtil.errToObj(options?.message)
1989
+ });
1990
+ }
1991
+ startsWith(value, message) {
1992
+ return this._addCheck({
1993
+ kind: "startsWith",
1994
+ value,
1995
+ ...errorUtil.errToObj(message)
1996
+ });
1997
+ }
1998
+ endsWith(value, message) {
1999
+ return this._addCheck({
2000
+ kind: "endsWith",
2001
+ value,
2002
+ ...errorUtil.errToObj(message)
2003
+ });
2004
+ }
2005
+ min(minLength, message) {
2006
+ return this._addCheck({
2007
+ kind: "min",
2008
+ value: minLength,
2009
+ ...errorUtil.errToObj(message)
2010
+ });
2011
+ }
2012
+ max(maxLength, message) {
2013
+ return this._addCheck({
2014
+ kind: "max",
2015
+ value: maxLength,
2016
+ ...errorUtil.errToObj(message)
2017
+ });
2018
+ }
2019
+ length(len, message) {
2020
+ return this._addCheck({
2021
+ kind: "length",
2022
+ value: len,
2023
+ ...errorUtil.errToObj(message)
2024
+ });
2025
+ }
2026
+ /**
2027
+ * Equivalent to `.min(1)`
2028
+ */
2029
+ nonempty(message) {
2030
+ return this.min(1, errorUtil.errToObj(message));
2031
+ }
2032
+ trim() {
2033
+ return new _ZodString({
2034
+ ...this._def,
2035
+ checks: [...this._def.checks, { kind: "trim" }]
2036
+ });
2037
+ }
2038
+ toLowerCase() {
2039
+ return new _ZodString({
2040
+ ...this._def,
2041
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
2042
+ });
2043
+ }
2044
+ toUpperCase() {
2045
+ return new _ZodString({
2046
+ ...this._def,
2047
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
2048
+ });
2049
+ }
2050
+ get isDatetime() {
2051
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
2052
+ }
2053
+ get isDate() {
2054
+ return !!this._def.checks.find((ch) => ch.kind === "date");
2055
+ }
2056
+ get isTime() {
2057
+ return !!this._def.checks.find((ch) => ch.kind === "time");
2058
+ }
2059
+ get isDuration() {
2060
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
2061
+ }
2062
+ get isEmail() {
2063
+ return !!this._def.checks.find((ch) => ch.kind === "email");
2064
+ }
2065
+ get isURL() {
2066
+ return !!this._def.checks.find((ch) => ch.kind === "url");
2067
+ }
2068
+ get isEmoji() {
2069
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
2070
+ }
2071
+ get isUUID() {
2072
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
2073
+ }
2074
+ get isNANOID() {
2075
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
2076
+ }
2077
+ get isCUID() {
2078
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
2079
+ }
2080
+ get isCUID2() {
2081
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
2082
+ }
2083
+ get isULID() {
2084
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
2085
+ }
2086
+ get isIP() {
2087
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
2088
+ }
2089
+ get isCIDR() {
2090
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
2091
+ }
2092
+ get isBase64() {
2093
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
2094
+ }
2095
+ get isBase64url() {
2096
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
2097
+ }
2098
+ get minLength() {
2099
+ let min = null;
2100
+ for (const ch of this._def.checks) {
2101
+ if (ch.kind === "min") {
2102
+ if (min === null || ch.value > min)
2103
+ min = ch.value;
2104
+ }
2105
+ }
2106
+ return min;
2107
+ }
2108
+ get maxLength() {
2109
+ let max = null;
2110
+ for (const ch of this._def.checks) {
2111
+ if (ch.kind === "max") {
2112
+ if (max === null || ch.value < max)
2113
+ max = ch.value;
2114
+ }
2115
+ }
2116
+ return max;
2117
+ }
2118
+ };
2119
+ ZodString.create = (params) => {
2120
+ return new ZodString({
2121
+ checks: [],
2122
+ typeName: ZodFirstPartyTypeKind.ZodString,
2123
+ coerce: params?.coerce ?? false,
2124
+ ...processCreateParams(params)
2125
+ });
2126
+ };
2127
+ function floatSafeRemainder(val, step) {
2128
+ const valDecCount = (val.toString().split(".")[1] || "").length;
2129
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
2130
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
2131
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
2132
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
2133
+ return valInt % stepInt / 10 ** decCount;
2134
+ }
2135
+ var ZodNumber = class _ZodNumber extends ZodType {
2136
+ constructor() {
2137
+ super(...arguments);
2138
+ this.min = this.gte;
2139
+ this.max = this.lte;
2140
+ this.step = this.multipleOf;
2141
+ }
2142
+ _parse(input) {
2143
+ if (this._def.coerce) {
2144
+ input.data = Number(input.data);
2145
+ }
2146
+ const parsedType = this._getType(input);
2147
+ if (parsedType !== ZodParsedType.number) {
2148
+ const ctx2 = this._getOrReturnCtx(input);
2149
+ addIssueToContext(ctx2, {
2150
+ code: ZodIssueCode.invalid_type,
2151
+ expected: ZodParsedType.number,
2152
+ received: ctx2.parsedType
2153
+ });
2154
+ return INVALID;
2155
+ }
2156
+ let ctx = void 0;
2157
+ const status = new ParseStatus();
2158
+ for (const check of this._def.checks) {
2159
+ if (check.kind === "int") {
2160
+ if (!util.isInteger(input.data)) {
2161
+ ctx = this._getOrReturnCtx(input, ctx);
2162
+ addIssueToContext(ctx, {
2163
+ code: ZodIssueCode.invalid_type,
2164
+ expected: "integer",
2165
+ received: "float",
2166
+ message: check.message
2167
+ });
2168
+ status.dirty();
2169
+ }
2170
+ } else if (check.kind === "min") {
2171
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2172
+ if (tooSmall) {
2173
+ ctx = this._getOrReturnCtx(input, ctx);
2174
+ addIssueToContext(ctx, {
2175
+ code: ZodIssueCode.too_small,
2176
+ minimum: check.value,
2177
+ type: "number",
2178
+ inclusive: check.inclusive,
2179
+ exact: false,
2180
+ message: check.message
2181
+ });
2182
+ status.dirty();
2183
+ }
2184
+ } else if (check.kind === "max") {
2185
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2186
+ if (tooBig) {
2187
+ ctx = this._getOrReturnCtx(input, ctx);
2188
+ addIssueToContext(ctx, {
2189
+ code: ZodIssueCode.too_big,
2190
+ maximum: check.value,
2191
+ type: "number",
2192
+ inclusive: check.inclusive,
2193
+ exact: false,
2194
+ message: check.message
2195
+ });
2196
+ status.dirty();
2197
+ }
2198
+ } else if (check.kind === "multipleOf") {
2199
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
2200
+ ctx = this._getOrReturnCtx(input, ctx);
2201
+ addIssueToContext(ctx, {
2202
+ code: ZodIssueCode.not_multiple_of,
2203
+ multipleOf: check.value,
2204
+ message: check.message
2205
+ });
2206
+ status.dirty();
2207
+ }
2208
+ } else if (check.kind === "finite") {
2209
+ if (!Number.isFinite(input.data)) {
2210
+ ctx = this._getOrReturnCtx(input, ctx);
2211
+ addIssueToContext(ctx, {
2212
+ code: ZodIssueCode.not_finite,
2213
+ message: check.message
2214
+ });
2215
+ status.dirty();
2216
+ }
2217
+ } else {
2218
+ util.assertNever(check);
2219
+ }
2220
+ }
2221
+ return { status: status.value, value: input.data };
2222
+ }
2223
+ gte(value, message) {
2224
+ return this.setLimit("min", value, true, errorUtil.toString(message));
2225
+ }
2226
+ gt(value, message) {
2227
+ return this.setLimit("min", value, false, errorUtil.toString(message));
2228
+ }
2229
+ lte(value, message) {
2230
+ return this.setLimit("max", value, true, errorUtil.toString(message));
2231
+ }
2232
+ lt(value, message) {
2233
+ return this.setLimit("max", value, false, errorUtil.toString(message));
2234
+ }
2235
+ setLimit(kind, value, inclusive, message) {
2236
+ return new _ZodNumber({
2237
+ ...this._def,
2238
+ checks: [
2239
+ ...this._def.checks,
2240
+ {
2241
+ kind,
2242
+ value,
2243
+ inclusive,
2244
+ message: errorUtil.toString(message)
2245
+ }
2246
+ ]
2247
+ });
2248
+ }
2249
+ _addCheck(check) {
2250
+ return new _ZodNumber({
2251
+ ...this._def,
2252
+ checks: [...this._def.checks, check]
2253
+ });
2254
+ }
2255
+ int(message) {
2256
+ return this._addCheck({
2257
+ kind: "int",
2258
+ message: errorUtil.toString(message)
2259
+ });
2260
+ }
2261
+ positive(message) {
2262
+ return this._addCheck({
2263
+ kind: "min",
2264
+ value: 0,
2265
+ inclusive: false,
2266
+ message: errorUtil.toString(message)
2267
+ });
2268
+ }
2269
+ negative(message) {
2270
+ return this._addCheck({
2271
+ kind: "max",
2272
+ value: 0,
2273
+ inclusive: false,
2274
+ message: errorUtil.toString(message)
2275
+ });
2276
+ }
2277
+ nonpositive(message) {
2278
+ return this._addCheck({
2279
+ kind: "max",
2280
+ value: 0,
2281
+ inclusive: true,
2282
+ message: errorUtil.toString(message)
2283
+ });
2284
+ }
2285
+ nonnegative(message) {
2286
+ return this._addCheck({
2287
+ kind: "min",
2288
+ value: 0,
2289
+ inclusive: true,
2290
+ message: errorUtil.toString(message)
2291
+ });
2292
+ }
2293
+ multipleOf(value, message) {
2294
+ return this._addCheck({
2295
+ kind: "multipleOf",
2296
+ value,
2297
+ message: errorUtil.toString(message)
2298
+ });
2299
+ }
2300
+ finite(message) {
2301
+ return this._addCheck({
2302
+ kind: "finite",
2303
+ message: errorUtil.toString(message)
2304
+ });
2305
+ }
2306
+ safe(message) {
2307
+ return this._addCheck({
2308
+ kind: "min",
2309
+ inclusive: true,
2310
+ value: Number.MIN_SAFE_INTEGER,
2311
+ message: errorUtil.toString(message)
2312
+ })._addCheck({
2313
+ kind: "max",
2314
+ inclusive: true,
2315
+ value: Number.MAX_SAFE_INTEGER,
2316
+ message: errorUtil.toString(message)
2317
+ });
2318
+ }
2319
+ get minValue() {
2320
+ let min = null;
2321
+ for (const ch of this._def.checks) {
2322
+ if (ch.kind === "min") {
2323
+ if (min === null || ch.value > min)
2324
+ min = ch.value;
2325
+ }
2326
+ }
2327
+ return min;
2328
+ }
2329
+ get maxValue() {
2330
+ let max = null;
2331
+ for (const ch of this._def.checks) {
2332
+ if (ch.kind === "max") {
2333
+ if (max === null || ch.value < max)
2334
+ max = ch.value;
2335
+ }
2336
+ }
2337
+ return max;
2338
+ }
2339
+ get isInt() {
2340
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
2341
+ }
2342
+ get isFinite() {
2343
+ let max = null;
2344
+ let min = null;
2345
+ for (const ch of this._def.checks) {
2346
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
2347
+ return true;
2348
+ } else if (ch.kind === "min") {
2349
+ if (min === null || ch.value > min)
2350
+ min = ch.value;
2351
+ } else if (ch.kind === "max") {
2352
+ if (max === null || ch.value < max)
2353
+ max = ch.value;
2354
+ }
2355
+ }
2356
+ return Number.isFinite(min) && Number.isFinite(max);
2357
+ }
2358
+ };
2359
+ ZodNumber.create = (params) => {
2360
+ return new ZodNumber({
2361
+ checks: [],
2362
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
2363
+ coerce: params?.coerce || false,
2364
+ ...processCreateParams(params)
2365
+ });
2366
+ };
2367
+ var ZodBigInt = class _ZodBigInt extends ZodType {
2368
+ constructor() {
2369
+ super(...arguments);
2370
+ this.min = this.gte;
2371
+ this.max = this.lte;
2372
+ }
2373
+ _parse(input) {
2374
+ if (this._def.coerce) {
2375
+ try {
2376
+ input.data = BigInt(input.data);
2377
+ } catch {
2378
+ return this._getInvalidInput(input);
2379
+ }
2380
+ }
2381
+ const parsedType = this._getType(input);
2382
+ if (parsedType !== ZodParsedType.bigint) {
2383
+ return this._getInvalidInput(input);
2384
+ }
2385
+ let ctx = void 0;
2386
+ const status = new ParseStatus();
2387
+ for (const check of this._def.checks) {
2388
+ if (check.kind === "min") {
2389
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2390
+ if (tooSmall) {
2391
+ ctx = this._getOrReturnCtx(input, ctx);
2392
+ addIssueToContext(ctx, {
2393
+ code: ZodIssueCode.too_small,
2394
+ type: "bigint",
2395
+ minimum: check.value,
2396
+ inclusive: check.inclusive,
2397
+ message: check.message
2398
+ });
2399
+ status.dirty();
2400
+ }
2401
+ } else if (check.kind === "max") {
2402
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2403
+ if (tooBig) {
2404
+ ctx = this._getOrReturnCtx(input, ctx);
2405
+ addIssueToContext(ctx, {
2406
+ code: ZodIssueCode.too_big,
2407
+ type: "bigint",
2408
+ maximum: check.value,
2409
+ inclusive: check.inclusive,
2410
+ message: check.message
2411
+ });
2412
+ status.dirty();
2413
+ }
2414
+ } else if (check.kind === "multipleOf") {
2415
+ if (input.data % check.value !== BigInt(0)) {
2416
+ ctx = this._getOrReturnCtx(input, ctx);
2417
+ addIssueToContext(ctx, {
2418
+ code: ZodIssueCode.not_multiple_of,
2419
+ multipleOf: check.value,
2420
+ message: check.message
2421
+ });
2422
+ status.dirty();
2423
+ }
2424
+ } else {
2425
+ util.assertNever(check);
2426
+ }
2427
+ }
2428
+ return { status: status.value, value: input.data };
2429
+ }
2430
+ _getInvalidInput(input) {
2431
+ const ctx = this._getOrReturnCtx(input);
2432
+ addIssueToContext(ctx, {
2433
+ code: ZodIssueCode.invalid_type,
2434
+ expected: ZodParsedType.bigint,
2435
+ received: ctx.parsedType
2436
+ });
2437
+ return INVALID;
2438
+ }
2439
+ gte(value, message) {
2440
+ return this.setLimit("min", value, true, errorUtil.toString(message));
2441
+ }
2442
+ gt(value, message) {
2443
+ return this.setLimit("min", value, false, errorUtil.toString(message));
2444
+ }
2445
+ lte(value, message) {
2446
+ return this.setLimit("max", value, true, errorUtil.toString(message));
2447
+ }
2448
+ lt(value, message) {
2449
+ return this.setLimit("max", value, false, errorUtil.toString(message));
2450
+ }
2451
+ setLimit(kind, value, inclusive, message) {
2452
+ return new _ZodBigInt({
2453
+ ...this._def,
2454
+ checks: [
2455
+ ...this._def.checks,
2456
+ {
2457
+ kind,
2458
+ value,
2459
+ inclusive,
2460
+ message: errorUtil.toString(message)
2461
+ }
2462
+ ]
2463
+ });
2464
+ }
2465
+ _addCheck(check) {
2466
+ return new _ZodBigInt({
2467
+ ...this._def,
2468
+ checks: [...this._def.checks, check]
2469
+ });
2470
+ }
2471
+ positive(message) {
2472
+ return this._addCheck({
2473
+ kind: "min",
2474
+ value: BigInt(0),
2475
+ inclusive: false,
2476
+ message: errorUtil.toString(message)
2477
+ });
2478
+ }
2479
+ negative(message) {
2480
+ return this._addCheck({
2481
+ kind: "max",
2482
+ value: BigInt(0),
2483
+ inclusive: false,
2484
+ message: errorUtil.toString(message)
2485
+ });
2486
+ }
2487
+ nonpositive(message) {
2488
+ return this._addCheck({
2489
+ kind: "max",
2490
+ value: BigInt(0),
2491
+ inclusive: true,
2492
+ message: errorUtil.toString(message)
2493
+ });
2494
+ }
2495
+ nonnegative(message) {
2496
+ return this._addCheck({
2497
+ kind: "min",
2498
+ value: BigInt(0),
2499
+ inclusive: true,
2500
+ message: errorUtil.toString(message)
2501
+ });
2502
+ }
2503
+ multipleOf(value, message) {
2504
+ return this._addCheck({
2505
+ kind: "multipleOf",
2506
+ value,
2507
+ message: errorUtil.toString(message)
2508
+ });
2509
+ }
2510
+ get minValue() {
2511
+ let min = null;
2512
+ for (const ch of this._def.checks) {
2513
+ if (ch.kind === "min") {
2514
+ if (min === null || ch.value > min)
2515
+ min = ch.value;
2516
+ }
2517
+ }
2518
+ return min;
2519
+ }
2520
+ get maxValue() {
2521
+ let max = null;
2522
+ for (const ch of this._def.checks) {
2523
+ if (ch.kind === "max") {
2524
+ if (max === null || ch.value < max)
2525
+ max = ch.value;
2526
+ }
2527
+ }
2528
+ return max;
2529
+ }
2530
+ };
2531
+ ZodBigInt.create = (params) => {
2532
+ return new ZodBigInt({
2533
+ checks: [],
2534
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
2535
+ coerce: params?.coerce ?? false,
2536
+ ...processCreateParams(params)
2537
+ });
2538
+ };
2539
+ var ZodBoolean = class extends ZodType {
2540
+ _parse(input) {
2541
+ if (this._def.coerce) {
2542
+ input.data = Boolean(input.data);
2543
+ }
2544
+ const parsedType = this._getType(input);
2545
+ if (parsedType !== ZodParsedType.boolean) {
2546
+ const ctx = this._getOrReturnCtx(input);
2547
+ addIssueToContext(ctx, {
2548
+ code: ZodIssueCode.invalid_type,
2549
+ expected: ZodParsedType.boolean,
2550
+ received: ctx.parsedType
2551
+ });
2552
+ return INVALID;
2553
+ }
2554
+ return OK(input.data);
2555
+ }
2556
+ };
2557
+ ZodBoolean.create = (params) => {
2558
+ return new ZodBoolean({
2559
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
2560
+ coerce: params?.coerce || false,
2561
+ ...processCreateParams(params)
2562
+ });
2563
+ };
2564
+ var ZodDate = class _ZodDate extends ZodType {
2565
+ _parse(input) {
2566
+ if (this._def.coerce) {
2567
+ input.data = new Date(input.data);
2568
+ }
2569
+ const parsedType = this._getType(input);
2570
+ if (parsedType !== ZodParsedType.date) {
2571
+ const ctx2 = this._getOrReturnCtx(input);
2572
+ addIssueToContext(ctx2, {
2573
+ code: ZodIssueCode.invalid_type,
2574
+ expected: ZodParsedType.date,
2575
+ received: ctx2.parsedType
2576
+ });
2577
+ return INVALID;
2578
+ }
2579
+ if (Number.isNaN(input.data.getTime())) {
2580
+ const ctx2 = this._getOrReturnCtx(input);
2581
+ addIssueToContext(ctx2, {
2582
+ code: ZodIssueCode.invalid_date
2583
+ });
2584
+ return INVALID;
2585
+ }
2586
+ const status = new ParseStatus();
2587
+ let ctx = void 0;
2588
+ for (const check of this._def.checks) {
2589
+ if (check.kind === "min") {
2590
+ if (input.data.getTime() < check.value) {
2591
+ ctx = this._getOrReturnCtx(input, ctx);
2592
+ addIssueToContext(ctx, {
2593
+ code: ZodIssueCode.too_small,
2594
+ message: check.message,
2595
+ inclusive: true,
2596
+ exact: false,
2597
+ minimum: check.value,
2598
+ type: "date"
2599
+ });
2600
+ status.dirty();
2601
+ }
2602
+ } else if (check.kind === "max") {
2603
+ if (input.data.getTime() > check.value) {
2604
+ ctx = this._getOrReturnCtx(input, ctx);
2605
+ addIssueToContext(ctx, {
2606
+ code: ZodIssueCode.too_big,
2607
+ message: check.message,
2608
+ inclusive: true,
2609
+ exact: false,
2610
+ maximum: check.value,
2611
+ type: "date"
2612
+ });
2613
+ status.dirty();
2614
+ }
2615
+ } else {
2616
+ util.assertNever(check);
2617
+ }
2618
+ }
2619
+ return {
2620
+ status: status.value,
2621
+ value: new Date(input.data.getTime())
2622
+ };
2623
+ }
2624
+ _addCheck(check) {
2625
+ return new _ZodDate({
2626
+ ...this._def,
2627
+ checks: [...this._def.checks, check]
2628
+ });
2629
+ }
2630
+ min(minDate, message) {
2631
+ return this._addCheck({
2632
+ kind: "min",
2633
+ value: minDate.getTime(),
2634
+ message: errorUtil.toString(message)
2635
+ });
2636
+ }
2637
+ max(maxDate, message) {
2638
+ return this._addCheck({
2639
+ kind: "max",
2640
+ value: maxDate.getTime(),
2641
+ message: errorUtil.toString(message)
2642
+ });
2643
+ }
2644
+ get minDate() {
2645
+ let min = null;
2646
+ for (const ch of this._def.checks) {
2647
+ if (ch.kind === "min") {
2648
+ if (min === null || ch.value > min)
2649
+ min = ch.value;
2650
+ }
2651
+ }
2652
+ return min != null ? new Date(min) : null;
2653
+ }
2654
+ get maxDate() {
2655
+ let max = null;
2656
+ for (const ch of this._def.checks) {
2657
+ if (ch.kind === "max") {
2658
+ if (max === null || ch.value < max)
2659
+ max = ch.value;
2660
+ }
2661
+ }
2662
+ return max != null ? new Date(max) : null;
2663
+ }
2664
+ };
2665
+ ZodDate.create = (params) => {
2666
+ return new ZodDate({
2667
+ checks: [],
2668
+ coerce: params?.coerce || false,
2669
+ typeName: ZodFirstPartyTypeKind.ZodDate,
2670
+ ...processCreateParams(params)
2671
+ });
2672
+ };
2673
+ var ZodSymbol = class extends ZodType {
2674
+ _parse(input) {
2675
+ const parsedType = this._getType(input);
2676
+ if (parsedType !== ZodParsedType.symbol) {
2677
+ const ctx = this._getOrReturnCtx(input);
2678
+ addIssueToContext(ctx, {
2679
+ code: ZodIssueCode.invalid_type,
2680
+ expected: ZodParsedType.symbol,
2681
+ received: ctx.parsedType
2682
+ });
2683
+ return INVALID;
2684
+ }
2685
+ return OK(input.data);
2686
+ }
2687
+ };
2688
+ ZodSymbol.create = (params) => {
2689
+ return new ZodSymbol({
2690
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
2691
+ ...processCreateParams(params)
2692
+ });
2693
+ };
2694
+ var ZodUndefined = class extends ZodType {
2695
+ _parse(input) {
2696
+ const parsedType = this._getType(input);
2697
+ if (parsedType !== ZodParsedType.undefined) {
2698
+ const ctx = this._getOrReturnCtx(input);
2699
+ addIssueToContext(ctx, {
2700
+ code: ZodIssueCode.invalid_type,
2701
+ expected: ZodParsedType.undefined,
2702
+ received: ctx.parsedType
2703
+ });
2704
+ return INVALID;
2705
+ }
2706
+ return OK(input.data);
2707
+ }
2708
+ };
2709
+ ZodUndefined.create = (params) => {
2710
+ return new ZodUndefined({
2711
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
2712
+ ...processCreateParams(params)
2713
+ });
2714
+ };
2715
+ var ZodNull = class extends ZodType {
2716
+ _parse(input) {
2717
+ const parsedType = this._getType(input);
2718
+ if (parsedType !== ZodParsedType.null) {
2719
+ const ctx = this._getOrReturnCtx(input);
2720
+ addIssueToContext(ctx, {
2721
+ code: ZodIssueCode.invalid_type,
2722
+ expected: ZodParsedType.null,
2723
+ received: ctx.parsedType
2724
+ });
2725
+ return INVALID;
2726
+ }
2727
+ return OK(input.data);
2728
+ }
2729
+ };
2730
+ ZodNull.create = (params) => {
2731
+ return new ZodNull({
2732
+ typeName: ZodFirstPartyTypeKind.ZodNull,
2733
+ ...processCreateParams(params)
2734
+ });
2735
+ };
2736
+ var ZodAny = class extends ZodType {
2737
+ constructor() {
2738
+ super(...arguments);
2739
+ this._any = true;
2740
+ }
2741
+ _parse(input) {
2742
+ return OK(input.data);
2743
+ }
2744
+ };
2745
+ ZodAny.create = (params) => {
2746
+ return new ZodAny({
2747
+ typeName: ZodFirstPartyTypeKind.ZodAny,
2748
+ ...processCreateParams(params)
2749
+ });
2750
+ };
2751
+ var ZodUnknown = class extends ZodType {
2752
+ constructor() {
2753
+ super(...arguments);
2754
+ this._unknown = true;
2755
+ }
2756
+ _parse(input) {
2757
+ return OK(input.data);
2758
+ }
2759
+ };
2760
+ ZodUnknown.create = (params) => {
2761
+ return new ZodUnknown({
2762
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
2763
+ ...processCreateParams(params)
2764
+ });
2765
+ };
2766
+ var ZodNever = class extends ZodType {
2767
+ _parse(input) {
2768
+ const ctx = this._getOrReturnCtx(input);
2769
+ addIssueToContext(ctx, {
2770
+ code: ZodIssueCode.invalid_type,
2771
+ expected: ZodParsedType.never,
2772
+ received: ctx.parsedType
2773
+ });
2774
+ return INVALID;
2775
+ }
2776
+ };
2777
+ ZodNever.create = (params) => {
2778
+ return new ZodNever({
2779
+ typeName: ZodFirstPartyTypeKind.ZodNever,
2780
+ ...processCreateParams(params)
2781
+ });
2782
+ };
2783
+ var ZodVoid = class extends ZodType {
2784
+ _parse(input) {
2785
+ const parsedType = this._getType(input);
2786
+ if (parsedType !== ZodParsedType.undefined) {
2787
+ const ctx = this._getOrReturnCtx(input);
2788
+ addIssueToContext(ctx, {
2789
+ code: ZodIssueCode.invalid_type,
2790
+ expected: ZodParsedType.void,
2791
+ received: ctx.parsedType
2792
+ });
2793
+ return INVALID;
2794
+ }
2795
+ return OK(input.data);
2796
+ }
2797
+ };
2798
+ ZodVoid.create = (params) => {
2799
+ return new ZodVoid({
2800
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2801
+ ...processCreateParams(params)
2802
+ });
2803
+ };
2804
+ var ZodArray = class _ZodArray extends ZodType {
2805
+ _parse(input) {
2806
+ const { ctx, status } = this._processInputParams(input);
2807
+ const def = this._def;
2808
+ if (ctx.parsedType !== ZodParsedType.array) {
2809
+ addIssueToContext(ctx, {
2810
+ code: ZodIssueCode.invalid_type,
2811
+ expected: ZodParsedType.array,
2812
+ received: ctx.parsedType
2813
+ });
2814
+ return INVALID;
2815
+ }
2816
+ if (def.exactLength !== null) {
2817
+ const tooBig = ctx.data.length > def.exactLength.value;
2818
+ const tooSmall = ctx.data.length < def.exactLength.value;
2819
+ if (tooBig || tooSmall) {
2820
+ addIssueToContext(ctx, {
2821
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2822
+ minimum: tooSmall ? def.exactLength.value : void 0,
2823
+ maximum: tooBig ? def.exactLength.value : void 0,
2824
+ type: "array",
2825
+ inclusive: true,
2826
+ exact: true,
2827
+ message: def.exactLength.message
2828
+ });
2829
+ status.dirty();
2830
+ }
2831
+ }
2832
+ if (def.minLength !== null) {
2833
+ if (ctx.data.length < def.minLength.value) {
2834
+ addIssueToContext(ctx, {
2835
+ code: ZodIssueCode.too_small,
2836
+ minimum: def.minLength.value,
2837
+ type: "array",
2838
+ inclusive: true,
2839
+ exact: false,
2840
+ message: def.minLength.message
2841
+ });
2842
+ status.dirty();
2843
+ }
2844
+ }
2845
+ if (def.maxLength !== null) {
2846
+ if (ctx.data.length > def.maxLength.value) {
2847
+ addIssueToContext(ctx, {
2848
+ code: ZodIssueCode.too_big,
2849
+ maximum: def.maxLength.value,
2850
+ type: "array",
2851
+ inclusive: true,
2852
+ exact: false,
2853
+ message: def.maxLength.message
2854
+ });
2855
+ status.dirty();
2856
+ }
2857
+ }
2858
+ if (ctx.common.async) {
2859
+ return Promise.all([...ctx.data].map((item, i) => {
2860
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2861
+ })).then((result2) => {
2862
+ return ParseStatus.mergeArray(status, result2);
2863
+ });
2864
+ }
2865
+ const result = [...ctx.data].map((item, i) => {
2866
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2867
+ });
2868
+ return ParseStatus.mergeArray(status, result);
2869
+ }
2870
+ get element() {
2871
+ return this._def.type;
2872
+ }
2873
+ min(minLength, message) {
2874
+ return new _ZodArray({
2875
+ ...this._def,
2876
+ minLength: { value: minLength, message: errorUtil.toString(message) }
2877
+ });
2878
+ }
2879
+ max(maxLength, message) {
2880
+ return new _ZodArray({
2881
+ ...this._def,
2882
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
2883
+ });
2884
+ }
2885
+ length(len, message) {
2886
+ return new _ZodArray({
2887
+ ...this._def,
2888
+ exactLength: { value: len, message: errorUtil.toString(message) }
2889
+ });
2890
+ }
2891
+ nonempty(message) {
2892
+ return this.min(1, message);
2893
+ }
2894
+ };
2895
+ ZodArray.create = (schema, params) => {
2896
+ return new ZodArray({
2897
+ type: schema,
2898
+ minLength: null,
2899
+ maxLength: null,
2900
+ exactLength: null,
2901
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2902
+ ...processCreateParams(params)
2903
+ });
2904
+ };
2905
+ function deepPartialify(schema) {
2906
+ if (schema instanceof ZodObject) {
2907
+ const newShape = {};
2908
+ for (const key in schema.shape) {
2909
+ const fieldSchema = schema.shape[key];
2910
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2911
+ }
2912
+ return new ZodObject({
2913
+ ...schema._def,
2914
+ shape: () => newShape
2915
+ });
2916
+ } else if (schema instanceof ZodArray) {
2917
+ return new ZodArray({
2918
+ ...schema._def,
2919
+ type: deepPartialify(schema.element)
2920
+ });
2921
+ } else if (schema instanceof ZodOptional) {
2922
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
2923
+ } else if (schema instanceof ZodNullable) {
2924
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
2925
+ } else if (schema instanceof ZodTuple) {
2926
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2927
+ } else {
2928
+ return schema;
2929
+ }
2930
+ }
2931
+ var ZodObject = class _ZodObject extends ZodType {
2932
+ constructor() {
2933
+ super(...arguments);
2934
+ this._cached = null;
2935
+ this.nonstrict = this.passthrough;
2936
+ this.augment = this.extend;
2937
+ }
2938
+ _getCached() {
2939
+ if (this._cached !== null)
2940
+ return this._cached;
2941
+ const shape = this._def.shape();
2942
+ const keys = util.objectKeys(shape);
2943
+ this._cached = { shape, keys };
2944
+ return this._cached;
2945
+ }
2946
+ _parse(input) {
2947
+ const parsedType = this._getType(input);
2948
+ if (parsedType !== ZodParsedType.object) {
2949
+ const ctx2 = this._getOrReturnCtx(input);
2950
+ addIssueToContext(ctx2, {
2951
+ code: ZodIssueCode.invalid_type,
2952
+ expected: ZodParsedType.object,
2953
+ received: ctx2.parsedType
2954
+ });
2955
+ return INVALID;
2956
+ }
2957
+ const { status, ctx } = this._processInputParams(input);
2958
+ const { shape, keys: shapeKeys } = this._getCached();
2959
+ const extraKeys = [];
2960
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2961
+ for (const key in ctx.data) {
2962
+ if (!shapeKeys.includes(key)) {
2963
+ extraKeys.push(key);
2964
+ }
2965
+ }
2966
+ }
2967
+ const pairs = [];
2968
+ for (const key of shapeKeys) {
2969
+ const keyValidator = shape[key];
2970
+ const value = ctx.data[key];
2971
+ pairs.push({
2972
+ key: { status: "valid", value: key },
2973
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2974
+ alwaysSet: key in ctx.data
2975
+ });
2976
+ }
2977
+ if (this._def.catchall instanceof ZodNever) {
2978
+ const unknownKeys = this._def.unknownKeys;
2979
+ if (unknownKeys === "passthrough") {
2980
+ for (const key of extraKeys) {
2981
+ pairs.push({
2982
+ key: { status: "valid", value: key },
2983
+ value: { status: "valid", value: ctx.data[key] }
2984
+ });
2985
+ }
2986
+ } else if (unknownKeys === "strict") {
2987
+ if (extraKeys.length > 0) {
2988
+ addIssueToContext(ctx, {
2989
+ code: ZodIssueCode.unrecognized_keys,
2990
+ keys: extraKeys
2991
+ });
2992
+ status.dirty();
2993
+ }
2994
+ } else if (unknownKeys === "strip") {
2995
+ } else {
2996
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2997
+ }
2998
+ } else {
2999
+ const catchall = this._def.catchall;
3000
+ for (const key of extraKeys) {
3001
+ const value = ctx.data[key];
3002
+ pairs.push({
3003
+ key: { status: "valid", value: key },
3004
+ value: catchall._parse(
3005
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
3006
+ //, ctx.child(key), value, getParsedType(value)
3007
+ ),
3008
+ alwaysSet: key in ctx.data
3009
+ });
3010
+ }
3011
+ }
3012
+ if (ctx.common.async) {
3013
+ return Promise.resolve().then(async () => {
3014
+ const syncPairs = [];
3015
+ for (const pair of pairs) {
3016
+ const key = await pair.key;
3017
+ const value = await pair.value;
3018
+ syncPairs.push({
3019
+ key,
3020
+ value,
3021
+ alwaysSet: pair.alwaysSet
3022
+ });
3023
+ }
3024
+ return syncPairs;
3025
+ }).then((syncPairs) => {
3026
+ return ParseStatus.mergeObjectSync(status, syncPairs);
3027
+ });
3028
+ } else {
3029
+ return ParseStatus.mergeObjectSync(status, pairs);
3030
+ }
3031
+ }
3032
+ get shape() {
3033
+ return this._def.shape();
3034
+ }
3035
+ strict(message) {
3036
+ errorUtil.errToObj;
3037
+ return new _ZodObject({
3038
+ ...this._def,
3039
+ unknownKeys: "strict",
3040
+ ...message !== void 0 ? {
3041
+ errorMap: (issue, ctx) => {
3042
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
3043
+ if (issue.code === "unrecognized_keys")
3044
+ return {
3045
+ message: errorUtil.errToObj(message).message ?? defaultError
3046
+ };
3047
+ return {
3048
+ message: defaultError
3049
+ };
3050
+ }
3051
+ } : {}
3052
+ });
3053
+ }
3054
+ strip() {
3055
+ return new _ZodObject({
3056
+ ...this._def,
3057
+ unknownKeys: "strip"
3058
+ });
3059
+ }
3060
+ passthrough() {
3061
+ return new _ZodObject({
3062
+ ...this._def,
3063
+ unknownKeys: "passthrough"
3064
+ });
3065
+ }
3066
+ // const AugmentFactory =
3067
+ // <Def extends ZodObjectDef>(def: Def) =>
3068
+ // <Augmentation extends ZodRawShape>(
3069
+ // augmentation: Augmentation
3070
+ // ): ZodObject<
3071
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
3072
+ // Def["unknownKeys"],
3073
+ // Def["catchall"]
3074
+ // > => {
3075
+ // return new ZodObject({
3076
+ // ...def,
3077
+ // shape: () => ({
3078
+ // ...def.shape(),
3079
+ // ...augmentation,
3080
+ // }),
3081
+ // }) as any;
3082
+ // };
3083
+ extend(augmentation) {
3084
+ return new _ZodObject({
3085
+ ...this._def,
3086
+ shape: () => ({
3087
+ ...this._def.shape(),
3088
+ ...augmentation
3089
+ })
3090
+ });
3091
+ }
3092
+ /**
3093
+ * Prior to zod@1.0.12 there was a bug in the
3094
+ * inferred type of merged objects. Please
3095
+ * upgrade if you are experiencing issues.
3096
+ */
3097
+ merge(merging) {
3098
+ const merged = new _ZodObject({
3099
+ unknownKeys: merging._def.unknownKeys,
3100
+ catchall: merging._def.catchall,
3101
+ shape: () => ({
3102
+ ...this._def.shape(),
3103
+ ...merging._def.shape()
3104
+ }),
3105
+ typeName: ZodFirstPartyTypeKind.ZodObject
3106
+ });
3107
+ return merged;
3108
+ }
3109
+ // merge<
3110
+ // Incoming extends AnyZodObject,
3111
+ // Augmentation extends Incoming["shape"],
3112
+ // NewOutput extends {
3113
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
3114
+ // ? Augmentation[k]["_output"]
3115
+ // : k extends keyof Output
3116
+ // ? Output[k]
3117
+ // : never;
3118
+ // },
3119
+ // NewInput extends {
3120
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
3121
+ // ? Augmentation[k]["_input"]
3122
+ // : k extends keyof Input
3123
+ // ? Input[k]
3124
+ // : never;
3125
+ // }
3126
+ // >(
3127
+ // merging: Incoming
3128
+ // ): ZodObject<
3129
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3130
+ // Incoming["_def"]["unknownKeys"],
3131
+ // Incoming["_def"]["catchall"],
3132
+ // NewOutput,
3133
+ // NewInput
3134
+ // > {
3135
+ // const merged: any = new ZodObject({
3136
+ // unknownKeys: merging._def.unknownKeys,
3137
+ // catchall: merging._def.catchall,
3138
+ // shape: () =>
3139
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3140
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
3141
+ // }) as any;
3142
+ // return merged;
3143
+ // }
3144
+ setKey(key, schema) {
3145
+ return this.augment({ [key]: schema });
3146
+ }
3147
+ // merge<Incoming extends AnyZodObject>(
3148
+ // merging: Incoming
3149
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
3150
+ // ZodObject<
3151
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3152
+ // Incoming["_def"]["unknownKeys"],
3153
+ // Incoming["_def"]["catchall"]
3154
+ // > {
3155
+ // // const mergedShape = objectUtil.mergeShapes(
3156
+ // // this._def.shape(),
3157
+ // // merging._def.shape()
3158
+ // // );
3159
+ // const merged: any = new ZodObject({
3160
+ // unknownKeys: merging._def.unknownKeys,
3161
+ // catchall: merging._def.catchall,
3162
+ // shape: () =>
3163
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3164
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
3165
+ // }) as any;
3166
+ // return merged;
3167
+ // }
3168
+ catchall(index) {
3169
+ return new _ZodObject({
3170
+ ...this._def,
3171
+ catchall: index
3172
+ });
3173
+ }
3174
+ pick(mask) {
3175
+ const shape = {};
3176
+ for (const key of util.objectKeys(mask)) {
3177
+ if (mask[key] && this.shape[key]) {
3178
+ shape[key] = this.shape[key];
3179
+ }
3180
+ }
3181
+ return new _ZodObject({
3182
+ ...this._def,
3183
+ shape: () => shape
3184
+ });
3185
+ }
3186
+ omit(mask) {
3187
+ const shape = {};
3188
+ for (const key of util.objectKeys(this.shape)) {
3189
+ if (!mask[key]) {
3190
+ shape[key] = this.shape[key];
3191
+ }
3192
+ }
3193
+ return new _ZodObject({
3194
+ ...this._def,
3195
+ shape: () => shape
3196
+ });
3197
+ }
3198
+ /**
3199
+ * @deprecated
3200
+ */
3201
+ deepPartial() {
3202
+ return deepPartialify(this);
3203
+ }
3204
+ partial(mask) {
3205
+ const newShape = {};
3206
+ for (const key of util.objectKeys(this.shape)) {
3207
+ const fieldSchema = this.shape[key];
3208
+ if (mask && !mask[key]) {
3209
+ newShape[key] = fieldSchema;
3210
+ } else {
3211
+ newShape[key] = fieldSchema.optional();
3212
+ }
3213
+ }
3214
+ return new _ZodObject({
3215
+ ...this._def,
3216
+ shape: () => newShape
3217
+ });
3218
+ }
3219
+ required(mask) {
3220
+ const newShape = {};
3221
+ for (const key of util.objectKeys(this.shape)) {
3222
+ if (mask && !mask[key]) {
3223
+ newShape[key] = this.shape[key];
3224
+ } else {
3225
+ const fieldSchema = this.shape[key];
3226
+ let newField = fieldSchema;
3227
+ while (newField instanceof ZodOptional) {
3228
+ newField = newField._def.innerType;
3229
+ }
3230
+ newShape[key] = newField;
3231
+ }
3232
+ }
3233
+ return new _ZodObject({
3234
+ ...this._def,
3235
+ shape: () => newShape
3236
+ });
3237
+ }
3238
+ keyof() {
3239
+ return createZodEnum(util.objectKeys(this.shape));
3240
+ }
3241
+ };
3242
+ ZodObject.create = (shape, params) => {
3243
+ return new ZodObject({
3244
+ shape: () => shape,
3245
+ unknownKeys: "strip",
3246
+ catchall: ZodNever.create(),
3247
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3248
+ ...processCreateParams(params)
3249
+ });
3250
+ };
3251
+ ZodObject.strictCreate = (shape, params) => {
3252
+ return new ZodObject({
3253
+ shape: () => shape,
3254
+ unknownKeys: "strict",
3255
+ catchall: ZodNever.create(),
3256
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3257
+ ...processCreateParams(params)
3258
+ });
3259
+ };
3260
+ ZodObject.lazycreate = (shape, params) => {
3261
+ return new ZodObject({
3262
+ shape,
3263
+ unknownKeys: "strip",
3264
+ catchall: ZodNever.create(),
3265
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3266
+ ...processCreateParams(params)
3267
+ });
3268
+ };
3269
+ var ZodUnion = class extends ZodType {
3270
+ _parse(input) {
3271
+ const { ctx } = this._processInputParams(input);
3272
+ const options = this._def.options;
3273
+ function handleResults(results) {
3274
+ for (const result of results) {
3275
+ if (result.result.status === "valid") {
3276
+ return result.result;
3277
+ }
3278
+ }
3279
+ for (const result of results) {
3280
+ if (result.result.status === "dirty") {
3281
+ ctx.common.issues.push(...result.ctx.common.issues);
3282
+ return result.result;
3283
+ }
3284
+ }
3285
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
3286
+ addIssueToContext(ctx, {
3287
+ code: ZodIssueCode.invalid_union,
3288
+ unionErrors
3289
+ });
3290
+ return INVALID;
3291
+ }
3292
+ if (ctx.common.async) {
3293
+ return Promise.all(options.map(async (option) => {
3294
+ const childCtx = {
3295
+ ...ctx,
3296
+ common: {
3297
+ ...ctx.common,
3298
+ issues: []
3299
+ },
3300
+ parent: null
3301
+ };
3302
+ return {
3303
+ result: await option._parseAsync({
3304
+ data: ctx.data,
3305
+ path: ctx.path,
3306
+ parent: childCtx
3307
+ }),
3308
+ ctx: childCtx
3309
+ };
3310
+ })).then(handleResults);
3311
+ } else {
3312
+ let dirty = void 0;
3313
+ const issues = [];
3314
+ for (const option of options) {
3315
+ const childCtx = {
3316
+ ...ctx,
3317
+ common: {
3318
+ ...ctx.common,
3319
+ issues: []
3320
+ },
3321
+ parent: null
3322
+ };
3323
+ const result = option._parseSync({
3324
+ data: ctx.data,
3325
+ path: ctx.path,
3326
+ parent: childCtx
3327
+ });
3328
+ if (result.status === "valid") {
3329
+ return result;
3330
+ } else if (result.status === "dirty" && !dirty) {
3331
+ dirty = { result, ctx: childCtx };
3332
+ }
3333
+ if (childCtx.common.issues.length) {
3334
+ issues.push(childCtx.common.issues);
3335
+ }
3336
+ }
3337
+ if (dirty) {
3338
+ ctx.common.issues.push(...dirty.ctx.common.issues);
3339
+ return dirty.result;
3340
+ }
3341
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
3342
+ addIssueToContext(ctx, {
3343
+ code: ZodIssueCode.invalid_union,
3344
+ unionErrors
3345
+ });
3346
+ return INVALID;
3347
+ }
3348
+ }
3349
+ get options() {
3350
+ return this._def.options;
3351
+ }
3352
+ };
3353
+ ZodUnion.create = (types2, params) => {
3354
+ return new ZodUnion({
3355
+ options: types2,
3356
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
3357
+ ...processCreateParams(params)
3358
+ });
3359
+ };
3360
+ var getDiscriminator = (type) => {
3361
+ if (type instanceof ZodLazy) {
3362
+ return getDiscriminator(type.schema);
3363
+ } else if (type instanceof ZodEffects) {
3364
+ return getDiscriminator(type.innerType());
3365
+ } else if (type instanceof ZodLiteral) {
3366
+ return [type.value];
3367
+ } else if (type instanceof ZodEnum) {
3368
+ return type.options;
3369
+ } else if (type instanceof ZodNativeEnum) {
3370
+ return util.objectValues(type.enum);
3371
+ } else if (type instanceof ZodDefault) {
3372
+ return getDiscriminator(type._def.innerType);
3373
+ } else if (type instanceof ZodUndefined) {
3374
+ return [void 0];
3375
+ } else if (type instanceof ZodNull) {
3376
+ return [null];
3377
+ } else if (type instanceof ZodOptional) {
3378
+ return [void 0, ...getDiscriminator(type.unwrap())];
3379
+ } else if (type instanceof ZodNullable) {
3380
+ return [null, ...getDiscriminator(type.unwrap())];
3381
+ } else if (type instanceof ZodBranded) {
3382
+ return getDiscriminator(type.unwrap());
3383
+ } else if (type instanceof ZodReadonly) {
3384
+ return getDiscriminator(type.unwrap());
3385
+ } else if (type instanceof ZodCatch) {
3386
+ return getDiscriminator(type._def.innerType);
3387
+ } else {
3388
+ return [];
3389
+ }
3390
+ };
3391
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
3392
+ _parse(input) {
3393
+ const { ctx } = this._processInputParams(input);
3394
+ if (ctx.parsedType !== ZodParsedType.object) {
3395
+ addIssueToContext(ctx, {
3396
+ code: ZodIssueCode.invalid_type,
3397
+ expected: ZodParsedType.object,
3398
+ received: ctx.parsedType
3399
+ });
3400
+ return INVALID;
3401
+ }
3402
+ const discriminator = this.discriminator;
3403
+ const discriminatorValue = ctx.data[discriminator];
3404
+ const option = this.optionsMap.get(discriminatorValue);
3405
+ if (!option) {
3406
+ addIssueToContext(ctx, {
3407
+ code: ZodIssueCode.invalid_union_discriminator,
3408
+ options: Array.from(this.optionsMap.keys()),
3409
+ path: [discriminator]
3410
+ });
3411
+ return INVALID;
3412
+ }
3413
+ if (ctx.common.async) {
3414
+ return option._parseAsync({
3415
+ data: ctx.data,
3416
+ path: ctx.path,
3417
+ parent: ctx
3418
+ });
3419
+ } else {
3420
+ return option._parseSync({
3421
+ data: ctx.data,
3422
+ path: ctx.path,
3423
+ parent: ctx
3424
+ });
3425
+ }
3426
+ }
3427
+ get discriminator() {
3428
+ return this._def.discriminator;
3429
+ }
3430
+ get options() {
3431
+ return this._def.options;
3432
+ }
3433
+ get optionsMap() {
3434
+ return this._def.optionsMap;
3435
+ }
3436
+ /**
3437
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
3438
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
3439
+ * have a different value for each object in the union.
3440
+ * @param discriminator the name of the discriminator property
3441
+ * @param types an array of object schemas
3442
+ * @param params
3443
+ */
3444
+ static create(discriminator, options, params) {
3445
+ const optionsMap = /* @__PURE__ */ new Map();
3446
+ for (const type of options) {
3447
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3448
+ if (!discriminatorValues.length) {
3449
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3450
+ }
3451
+ for (const value of discriminatorValues) {
3452
+ if (optionsMap.has(value)) {
3453
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
3454
+ }
3455
+ optionsMap.set(value, type);
3456
+ }
3457
+ }
3458
+ return new _ZodDiscriminatedUnion({
3459
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
3460
+ discriminator,
3461
+ options,
3462
+ optionsMap,
3463
+ ...processCreateParams(params)
3464
+ });
3465
+ }
3466
+ };
3467
+ function mergeValues(a, b) {
3468
+ const aType = getParsedType(a);
3469
+ const bType = getParsedType(b);
3470
+ if (a === b) {
3471
+ return { valid: true, data: a };
3472
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
3473
+ const bKeys = util.objectKeys(b);
3474
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
3475
+ const newObj = { ...a, ...b };
3476
+ for (const key of sharedKeys) {
3477
+ const sharedValue = mergeValues(a[key], b[key]);
3478
+ if (!sharedValue.valid) {
3479
+ return { valid: false };
3480
+ }
3481
+ newObj[key] = sharedValue.data;
3482
+ }
3483
+ return { valid: true, data: newObj };
3484
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
3485
+ if (a.length !== b.length) {
3486
+ return { valid: false };
3487
+ }
3488
+ const newArray = [];
3489
+ for (let index = 0; index < a.length; index++) {
3490
+ const itemA = a[index];
3491
+ const itemB = b[index];
3492
+ const sharedValue = mergeValues(itemA, itemB);
3493
+ if (!sharedValue.valid) {
3494
+ return { valid: false };
3495
+ }
3496
+ newArray.push(sharedValue.data);
3497
+ }
3498
+ return { valid: true, data: newArray };
3499
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
3500
+ return { valid: true, data: a };
3501
+ } else {
3502
+ return { valid: false };
3503
+ }
3504
+ }
3505
+ var ZodIntersection = class extends ZodType {
3506
+ _parse(input) {
3507
+ const { status, ctx } = this._processInputParams(input);
3508
+ const handleParsed = (parsedLeft, parsedRight) => {
3509
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
3510
+ return INVALID;
3511
+ }
3512
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
3513
+ if (!merged.valid) {
3514
+ addIssueToContext(ctx, {
3515
+ code: ZodIssueCode.invalid_intersection_types
3516
+ });
3517
+ return INVALID;
3518
+ }
3519
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
3520
+ status.dirty();
3521
+ }
3522
+ return { status: status.value, value: merged.data };
3523
+ };
3524
+ if (ctx.common.async) {
3525
+ return Promise.all([
3526
+ this._def.left._parseAsync({
3527
+ data: ctx.data,
3528
+ path: ctx.path,
3529
+ parent: ctx
3530
+ }),
3531
+ this._def.right._parseAsync({
3532
+ data: ctx.data,
3533
+ path: ctx.path,
3534
+ parent: ctx
3535
+ })
3536
+ ]).then(([left, right]) => handleParsed(left, right));
3537
+ } else {
3538
+ return handleParsed(this._def.left._parseSync({
3539
+ data: ctx.data,
3540
+ path: ctx.path,
3541
+ parent: ctx
3542
+ }), this._def.right._parseSync({
3543
+ data: ctx.data,
3544
+ path: ctx.path,
3545
+ parent: ctx
3546
+ }));
3547
+ }
3548
+ }
3549
+ };
3550
+ ZodIntersection.create = (left, right, params) => {
3551
+ return new ZodIntersection({
3552
+ left,
3553
+ right,
3554
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
3555
+ ...processCreateParams(params)
3556
+ });
3557
+ };
3558
+ var ZodTuple = class _ZodTuple extends ZodType {
3559
+ _parse(input) {
3560
+ const { status, ctx } = this._processInputParams(input);
3561
+ if (ctx.parsedType !== ZodParsedType.array) {
3562
+ addIssueToContext(ctx, {
3563
+ code: ZodIssueCode.invalid_type,
3564
+ expected: ZodParsedType.array,
3565
+ received: ctx.parsedType
3566
+ });
3567
+ return INVALID;
3568
+ }
3569
+ if (ctx.data.length < this._def.items.length) {
3570
+ addIssueToContext(ctx, {
3571
+ code: ZodIssueCode.too_small,
3572
+ minimum: this._def.items.length,
3573
+ inclusive: true,
3574
+ exact: false,
3575
+ type: "array"
3576
+ });
3577
+ return INVALID;
3578
+ }
3579
+ const rest = this._def.rest;
3580
+ if (!rest && ctx.data.length > this._def.items.length) {
3581
+ addIssueToContext(ctx, {
3582
+ code: ZodIssueCode.too_big,
3583
+ maximum: this._def.items.length,
3584
+ inclusive: true,
3585
+ exact: false,
3586
+ type: "array"
3587
+ });
3588
+ status.dirty();
3589
+ }
3590
+ const items = [...ctx.data].map((item, itemIndex) => {
3591
+ const schema = this._def.items[itemIndex] || this._def.rest;
3592
+ if (!schema)
3593
+ return null;
3594
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
3595
+ }).filter((x) => !!x);
3596
+ if (ctx.common.async) {
3597
+ return Promise.all(items).then((results) => {
3598
+ return ParseStatus.mergeArray(status, results);
3599
+ });
3600
+ } else {
3601
+ return ParseStatus.mergeArray(status, items);
3602
+ }
3603
+ }
3604
+ get items() {
3605
+ return this._def.items;
3606
+ }
3607
+ rest(rest) {
3608
+ return new _ZodTuple({
3609
+ ...this._def,
3610
+ rest
3611
+ });
3612
+ }
3613
+ };
3614
+ ZodTuple.create = (schemas, params) => {
3615
+ if (!Array.isArray(schemas)) {
3616
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
3617
+ }
3618
+ return new ZodTuple({
3619
+ items: schemas,
3620
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
3621
+ rest: null,
3622
+ ...processCreateParams(params)
3623
+ });
3624
+ };
3625
+ var ZodRecord = class _ZodRecord extends ZodType {
3626
+ get keySchema() {
3627
+ return this._def.keyType;
3628
+ }
3629
+ get valueSchema() {
3630
+ return this._def.valueType;
3631
+ }
3632
+ _parse(input) {
3633
+ const { status, ctx } = this._processInputParams(input);
3634
+ if (ctx.parsedType !== ZodParsedType.object) {
3635
+ addIssueToContext(ctx, {
3636
+ code: ZodIssueCode.invalid_type,
3637
+ expected: ZodParsedType.object,
3638
+ received: ctx.parsedType
3639
+ });
3640
+ return INVALID;
3641
+ }
3642
+ const pairs = [];
3643
+ const keyType = this._def.keyType;
3644
+ const valueType = this._def.valueType;
3645
+ for (const key in ctx.data) {
3646
+ pairs.push({
3647
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3648
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3649
+ alwaysSet: key in ctx.data
3650
+ });
3651
+ }
3652
+ if (ctx.common.async) {
3653
+ return ParseStatus.mergeObjectAsync(status, pairs);
3654
+ } else {
3655
+ return ParseStatus.mergeObjectSync(status, pairs);
3656
+ }
3657
+ }
3658
+ get element() {
3659
+ return this._def.valueType;
3660
+ }
3661
+ static create(first, second, third) {
3662
+ if (second instanceof ZodType) {
3663
+ return new _ZodRecord({
3664
+ keyType: first,
3665
+ valueType: second,
3666
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3667
+ ...processCreateParams(third)
3668
+ });
3669
+ }
3670
+ return new _ZodRecord({
3671
+ keyType: ZodString.create(),
3672
+ valueType: first,
3673
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3674
+ ...processCreateParams(second)
3675
+ });
3676
+ }
3677
+ };
3678
+ var ZodMap = class extends ZodType {
3679
+ get keySchema() {
3680
+ return this._def.keyType;
3681
+ }
3682
+ get valueSchema() {
3683
+ return this._def.valueType;
3684
+ }
3685
+ _parse(input) {
3686
+ const { status, ctx } = this._processInputParams(input);
3687
+ if (ctx.parsedType !== ZodParsedType.map) {
3688
+ addIssueToContext(ctx, {
3689
+ code: ZodIssueCode.invalid_type,
3690
+ expected: ZodParsedType.map,
3691
+ received: ctx.parsedType
3692
+ });
3693
+ return INVALID;
3694
+ }
3695
+ const keyType = this._def.keyType;
3696
+ const valueType = this._def.valueType;
3697
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
3698
+ return {
3699
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
3700
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
3701
+ };
3702
+ });
3703
+ if (ctx.common.async) {
3704
+ const finalMap = /* @__PURE__ */ new Map();
3705
+ return Promise.resolve().then(async () => {
3706
+ for (const pair of pairs) {
3707
+ const key = await pair.key;
3708
+ const value = await pair.value;
3709
+ if (key.status === "aborted" || value.status === "aborted") {
3710
+ return INVALID;
3711
+ }
3712
+ if (key.status === "dirty" || value.status === "dirty") {
3713
+ status.dirty();
3714
+ }
3715
+ finalMap.set(key.value, value.value);
3716
+ }
3717
+ return { status: status.value, value: finalMap };
3718
+ });
3719
+ } else {
3720
+ const finalMap = /* @__PURE__ */ new Map();
3721
+ for (const pair of pairs) {
3722
+ const key = pair.key;
3723
+ const value = pair.value;
3724
+ if (key.status === "aborted" || value.status === "aborted") {
3725
+ return INVALID;
3726
+ }
3727
+ if (key.status === "dirty" || value.status === "dirty") {
3728
+ status.dirty();
3729
+ }
3730
+ finalMap.set(key.value, value.value);
3731
+ }
3732
+ return { status: status.value, value: finalMap };
3733
+ }
3734
+ }
3735
+ };
3736
+ ZodMap.create = (keyType, valueType, params) => {
3737
+ return new ZodMap({
3738
+ valueType,
3739
+ keyType,
3740
+ typeName: ZodFirstPartyTypeKind.ZodMap,
3741
+ ...processCreateParams(params)
3742
+ });
3743
+ };
3744
+ var ZodSet = class _ZodSet extends ZodType {
3745
+ _parse(input) {
3746
+ const { status, ctx } = this._processInputParams(input);
3747
+ if (ctx.parsedType !== ZodParsedType.set) {
3748
+ addIssueToContext(ctx, {
3749
+ code: ZodIssueCode.invalid_type,
3750
+ expected: ZodParsedType.set,
3751
+ received: ctx.parsedType
3752
+ });
3753
+ return INVALID;
3754
+ }
3755
+ const def = this._def;
3756
+ if (def.minSize !== null) {
3757
+ if (ctx.data.size < def.minSize.value) {
3758
+ addIssueToContext(ctx, {
3759
+ code: ZodIssueCode.too_small,
3760
+ minimum: def.minSize.value,
3761
+ type: "set",
3762
+ inclusive: true,
3763
+ exact: false,
3764
+ message: def.minSize.message
3765
+ });
3766
+ status.dirty();
3767
+ }
3768
+ }
3769
+ if (def.maxSize !== null) {
3770
+ if (ctx.data.size > def.maxSize.value) {
3771
+ addIssueToContext(ctx, {
3772
+ code: ZodIssueCode.too_big,
3773
+ maximum: def.maxSize.value,
3774
+ type: "set",
3775
+ inclusive: true,
3776
+ exact: false,
3777
+ message: def.maxSize.message
3778
+ });
3779
+ status.dirty();
3780
+ }
3781
+ }
3782
+ const valueType = this._def.valueType;
3783
+ function finalizeSet(elements2) {
3784
+ const parsedSet = /* @__PURE__ */ new Set();
3785
+ for (const element of elements2) {
3786
+ if (element.status === "aborted")
3787
+ return INVALID;
3788
+ if (element.status === "dirty")
3789
+ status.dirty();
3790
+ parsedSet.add(element.value);
3791
+ }
3792
+ return { status: status.value, value: parsedSet };
3793
+ }
3794
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
3795
+ if (ctx.common.async) {
3796
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
3797
+ } else {
3798
+ return finalizeSet(elements);
3799
+ }
3800
+ }
3801
+ min(minSize, message) {
3802
+ return new _ZodSet({
3803
+ ...this._def,
3804
+ minSize: { value: minSize, message: errorUtil.toString(message) }
3805
+ });
3806
+ }
3807
+ max(maxSize, message) {
3808
+ return new _ZodSet({
3809
+ ...this._def,
3810
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
3811
+ });
3812
+ }
3813
+ size(size, message) {
3814
+ return this.min(size, message).max(size, message);
3815
+ }
3816
+ nonempty(message) {
3817
+ return this.min(1, message);
3818
+ }
3819
+ };
3820
+ ZodSet.create = (valueType, params) => {
3821
+ return new ZodSet({
3822
+ valueType,
3823
+ minSize: null,
3824
+ maxSize: null,
3825
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3826
+ ...processCreateParams(params)
3827
+ });
3828
+ };
3829
+ var ZodFunction = class _ZodFunction extends ZodType {
3830
+ constructor() {
3831
+ super(...arguments);
3832
+ this.validate = this.implement;
3833
+ }
3834
+ _parse(input) {
3835
+ const { ctx } = this._processInputParams(input);
3836
+ if (ctx.parsedType !== ZodParsedType.function) {
3837
+ addIssueToContext(ctx, {
3838
+ code: ZodIssueCode.invalid_type,
3839
+ expected: ZodParsedType.function,
3840
+ received: ctx.parsedType
3841
+ });
3842
+ return INVALID;
3843
+ }
3844
+ function makeArgsIssue(args, error) {
3845
+ return makeIssue({
3846
+ data: args,
3847
+ path: ctx.path,
3848
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
3849
+ issueData: {
3850
+ code: ZodIssueCode.invalid_arguments,
3851
+ argumentsError: error
3852
+ }
3853
+ });
3854
+ }
3855
+ function makeReturnsIssue(returns, error) {
3856
+ return makeIssue({
3857
+ data: returns,
3858
+ path: ctx.path,
3859
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
3860
+ issueData: {
3861
+ code: ZodIssueCode.invalid_return_type,
3862
+ returnTypeError: error
3863
+ }
3864
+ });
3865
+ }
3866
+ const params = { errorMap: ctx.common.contextualErrorMap };
3867
+ const fn = ctx.data;
3868
+ if (this._def.returns instanceof ZodPromise) {
3869
+ const me = this;
3870
+ return OK(async function(...args) {
3871
+ const error = new ZodError([]);
3872
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
3873
+ error.addIssue(makeArgsIssue(args, e));
3874
+ throw error;
3875
+ });
3876
+ const result = await Reflect.apply(fn, this, parsedArgs);
3877
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3878
+ error.addIssue(makeReturnsIssue(result, e));
3879
+ throw error;
3880
+ });
3881
+ return parsedReturns;
3882
+ });
3883
+ } else {
3884
+ const me = this;
3885
+ return OK(function(...args) {
3886
+ const parsedArgs = me._def.args.safeParse(args, params);
3887
+ if (!parsedArgs.success) {
3888
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3889
+ }
3890
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3891
+ const parsedReturns = me._def.returns.safeParse(result, params);
3892
+ if (!parsedReturns.success) {
3893
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3894
+ }
3895
+ return parsedReturns.data;
3896
+ });
3897
+ }
3898
+ }
3899
+ parameters() {
3900
+ return this._def.args;
3901
+ }
3902
+ returnType() {
3903
+ return this._def.returns;
3904
+ }
3905
+ args(...items) {
3906
+ return new _ZodFunction({
3907
+ ...this._def,
3908
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
3909
+ });
3910
+ }
3911
+ returns(returnType) {
3912
+ return new _ZodFunction({
3913
+ ...this._def,
3914
+ returns: returnType
3915
+ });
3916
+ }
3917
+ implement(func) {
3918
+ const validatedFunc = this.parse(func);
3919
+ return validatedFunc;
3920
+ }
3921
+ strictImplement(func) {
3922
+ const validatedFunc = this.parse(func);
3923
+ return validatedFunc;
3924
+ }
3925
+ static create(args, returns, params) {
3926
+ return new _ZodFunction({
3927
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3928
+ returns: returns || ZodUnknown.create(),
3929
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3930
+ ...processCreateParams(params)
3931
+ });
3932
+ }
3933
+ };
3934
+ var ZodLazy = class extends ZodType {
3935
+ get schema() {
3936
+ return this._def.getter();
3937
+ }
3938
+ _parse(input) {
3939
+ const { ctx } = this._processInputParams(input);
3940
+ const lazySchema = this._def.getter();
3941
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3942
+ }
3943
+ };
3944
+ ZodLazy.create = (getter, params) => {
3945
+ return new ZodLazy({
3946
+ getter,
3947
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3948
+ ...processCreateParams(params)
3949
+ });
3950
+ };
3951
+ var ZodLiteral = class extends ZodType {
3952
+ _parse(input) {
3953
+ if (input.data !== this._def.value) {
3954
+ const ctx = this._getOrReturnCtx(input);
3955
+ addIssueToContext(ctx, {
3956
+ received: ctx.data,
3957
+ code: ZodIssueCode.invalid_literal,
3958
+ expected: this._def.value
3959
+ });
3960
+ return INVALID;
3961
+ }
3962
+ return { status: "valid", value: input.data };
3963
+ }
3964
+ get value() {
3965
+ return this._def.value;
3966
+ }
3967
+ };
3968
+ ZodLiteral.create = (value, params) => {
3969
+ return new ZodLiteral({
3970
+ value,
3971
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3972
+ ...processCreateParams(params)
3973
+ });
3974
+ };
3975
+ function createZodEnum(values, params) {
3976
+ return new ZodEnum({
3977
+ values,
3978
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3979
+ ...processCreateParams(params)
3980
+ });
3981
+ }
3982
+ var ZodEnum = class _ZodEnum extends ZodType {
3983
+ _parse(input) {
3984
+ if (typeof input.data !== "string") {
3985
+ const ctx = this._getOrReturnCtx(input);
3986
+ const expectedValues = this._def.values;
3987
+ addIssueToContext(ctx, {
3988
+ expected: util.joinValues(expectedValues),
3989
+ received: ctx.parsedType,
3990
+ code: ZodIssueCode.invalid_type
3991
+ });
3992
+ return INVALID;
3993
+ }
3994
+ if (!this._cache) {
3995
+ this._cache = new Set(this._def.values);
3996
+ }
3997
+ if (!this._cache.has(input.data)) {
3998
+ const ctx = this._getOrReturnCtx(input);
3999
+ const expectedValues = this._def.values;
4000
+ addIssueToContext(ctx, {
4001
+ received: ctx.data,
4002
+ code: ZodIssueCode.invalid_enum_value,
4003
+ options: expectedValues
4004
+ });
4005
+ return INVALID;
4006
+ }
4007
+ return OK(input.data);
4008
+ }
4009
+ get options() {
4010
+ return this._def.values;
4011
+ }
4012
+ get enum() {
4013
+ const enumValues = {};
4014
+ for (const val of this._def.values) {
4015
+ enumValues[val] = val;
4016
+ }
4017
+ return enumValues;
4018
+ }
4019
+ get Values() {
4020
+ const enumValues = {};
4021
+ for (const val of this._def.values) {
4022
+ enumValues[val] = val;
4023
+ }
4024
+ return enumValues;
4025
+ }
4026
+ get Enum() {
4027
+ const enumValues = {};
4028
+ for (const val of this._def.values) {
4029
+ enumValues[val] = val;
4030
+ }
4031
+ return enumValues;
4032
+ }
4033
+ extract(values, newDef = this._def) {
4034
+ return _ZodEnum.create(values, {
4035
+ ...this._def,
4036
+ ...newDef
4037
+ });
4038
+ }
4039
+ exclude(values, newDef = this._def) {
4040
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
4041
+ ...this._def,
4042
+ ...newDef
4043
+ });
4044
+ }
4045
+ };
4046
+ ZodEnum.create = createZodEnum;
4047
+ var ZodNativeEnum = class extends ZodType {
4048
+ _parse(input) {
4049
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
4050
+ const ctx = this._getOrReturnCtx(input);
4051
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
4052
+ const expectedValues = util.objectValues(nativeEnumValues);
4053
+ addIssueToContext(ctx, {
4054
+ expected: util.joinValues(expectedValues),
4055
+ received: ctx.parsedType,
4056
+ code: ZodIssueCode.invalid_type
4057
+ });
4058
+ return INVALID;
4059
+ }
4060
+ if (!this._cache) {
4061
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
4062
+ }
4063
+ if (!this._cache.has(input.data)) {
4064
+ const expectedValues = util.objectValues(nativeEnumValues);
4065
+ addIssueToContext(ctx, {
4066
+ received: ctx.data,
4067
+ code: ZodIssueCode.invalid_enum_value,
4068
+ options: expectedValues
4069
+ });
4070
+ return INVALID;
4071
+ }
4072
+ return OK(input.data);
4073
+ }
4074
+ get enum() {
4075
+ return this._def.values;
4076
+ }
4077
+ };
4078
+ ZodNativeEnum.create = (values, params) => {
4079
+ return new ZodNativeEnum({
4080
+ values,
4081
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
4082
+ ...processCreateParams(params)
4083
+ });
4084
+ };
4085
+ var ZodPromise = class extends ZodType {
4086
+ unwrap() {
4087
+ return this._def.type;
4088
+ }
4089
+ _parse(input) {
4090
+ const { ctx } = this._processInputParams(input);
4091
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
4092
+ addIssueToContext(ctx, {
4093
+ code: ZodIssueCode.invalid_type,
4094
+ expected: ZodParsedType.promise,
4095
+ received: ctx.parsedType
4096
+ });
4097
+ return INVALID;
4098
+ }
4099
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
4100
+ return OK(promisified.then((data) => {
4101
+ return this._def.type.parseAsync(data, {
4102
+ path: ctx.path,
4103
+ errorMap: ctx.common.contextualErrorMap
4104
+ });
4105
+ }));
4106
+ }
4107
+ };
4108
+ ZodPromise.create = (schema, params) => {
4109
+ return new ZodPromise({
4110
+ type: schema,
4111
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
4112
+ ...processCreateParams(params)
4113
+ });
4114
+ };
4115
+ var ZodEffects = class extends ZodType {
4116
+ innerType() {
4117
+ return this._def.schema;
4118
+ }
4119
+ sourceType() {
4120
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
4121
+ }
4122
+ _parse(input) {
4123
+ const { status, ctx } = this._processInputParams(input);
4124
+ const effect = this._def.effect || null;
4125
+ const checkCtx = {
4126
+ addIssue: (arg) => {
4127
+ addIssueToContext(ctx, arg);
4128
+ if (arg.fatal) {
4129
+ status.abort();
4130
+ } else {
4131
+ status.dirty();
4132
+ }
4133
+ },
4134
+ get path() {
4135
+ return ctx.path;
4136
+ }
4137
+ };
4138
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
4139
+ if (effect.type === "preprocess") {
4140
+ const processed = effect.transform(ctx.data, checkCtx);
4141
+ if (ctx.common.async) {
4142
+ return Promise.resolve(processed).then(async (processed2) => {
4143
+ if (status.value === "aborted")
4144
+ return INVALID;
4145
+ const result = await this._def.schema._parseAsync({
4146
+ data: processed2,
4147
+ path: ctx.path,
4148
+ parent: ctx
4149
+ });
4150
+ if (result.status === "aborted")
4151
+ return INVALID;
4152
+ if (result.status === "dirty")
4153
+ return DIRTY(result.value);
4154
+ if (status.value === "dirty")
4155
+ return DIRTY(result.value);
4156
+ return result;
4157
+ });
4158
+ } else {
4159
+ if (status.value === "aborted")
4160
+ return INVALID;
4161
+ const result = this._def.schema._parseSync({
4162
+ data: processed,
4163
+ path: ctx.path,
4164
+ parent: ctx
4165
+ });
4166
+ if (result.status === "aborted")
4167
+ return INVALID;
4168
+ if (result.status === "dirty")
4169
+ return DIRTY(result.value);
4170
+ if (status.value === "dirty")
4171
+ return DIRTY(result.value);
4172
+ return result;
4173
+ }
4174
+ }
4175
+ if (effect.type === "refinement") {
4176
+ const executeRefinement = (acc) => {
4177
+ const result = effect.refinement(acc, checkCtx);
4178
+ if (ctx.common.async) {
4179
+ return Promise.resolve(result);
4180
+ }
4181
+ if (result instanceof Promise) {
4182
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
4183
+ }
4184
+ return acc;
4185
+ };
4186
+ if (ctx.common.async === false) {
4187
+ const inner = this._def.schema._parseSync({
4188
+ data: ctx.data,
4189
+ path: ctx.path,
4190
+ parent: ctx
4191
+ });
4192
+ if (inner.status === "aborted")
4193
+ return INVALID;
4194
+ if (inner.status === "dirty")
4195
+ status.dirty();
4196
+ executeRefinement(inner.value);
4197
+ return { status: status.value, value: inner.value };
4198
+ } else {
4199
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
4200
+ if (inner.status === "aborted")
4201
+ return INVALID;
4202
+ if (inner.status === "dirty")
4203
+ status.dirty();
4204
+ return executeRefinement(inner.value).then(() => {
4205
+ return { status: status.value, value: inner.value };
4206
+ });
4207
+ });
4208
+ }
4209
+ }
4210
+ if (effect.type === "transform") {
4211
+ if (ctx.common.async === false) {
4212
+ const base = this._def.schema._parseSync({
4213
+ data: ctx.data,
4214
+ path: ctx.path,
4215
+ parent: ctx
4216
+ });
4217
+ if (!isValid(base))
4218
+ return INVALID;
4219
+ const result = effect.transform(base.value, checkCtx);
4220
+ if (result instanceof Promise) {
4221
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
4222
+ }
4223
+ return { status: status.value, value: result };
4224
+ } else {
4225
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
4226
+ if (!isValid(base))
4227
+ return INVALID;
4228
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
4229
+ status: status.value,
4230
+ value: result
4231
+ }));
4232
+ });
4233
+ }
4234
+ }
4235
+ util.assertNever(effect);
4236
+ }
4237
+ };
4238
+ ZodEffects.create = (schema, effect, params) => {
4239
+ return new ZodEffects({
4240
+ schema,
4241
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
4242
+ effect,
4243
+ ...processCreateParams(params)
4244
+ });
4245
+ };
4246
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
4247
+ return new ZodEffects({
4248
+ schema,
4249
+ effect: { type: "preprocess", transform: preprocess },
4250
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
4251
+ ...processCreateParams(params)
4252
+ });
4253
+ };
4254
+ var ZodOptional = class extends ZodType {
4255
+ _parse(input) {
4256
+ const parsedType = this._getType(input);
4257
+ if (parsedType === ZodParsedType.undefined) {
4258
+ return OK(void 0);
4259
+ }
4260
+ return this._def.innerType._parse(input);
4261
+ }
4262
+ unwrap() {
4263
+ return this._def.innerType;
4264
+ }
4265
+ };
4266
+ ZodOptional.create = (type, params) => {
4267
+ return new ZodOptional({
4268
+ innerType: type,
4269
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
4270
+ ...processCreateParams(params)
4271
+ });
4272
+ };
4273
+ var ZodNullable = class extends ZodType {
4274
+ _parse(input) {
4275
+ const parsedType = this._getType(input);
4276
+ if (parsedType === ZodParsedType.null) {
4277
+ return OK(null);
4278
+ }
4279
+ return this._def.innerType._parse(input);
4280
+ }
4281
+ unwrap() {
4282
+ return this._def.innerType;
4283
+ }
4284
+ };
4285
+ ZodNullable.create = (type, params) => {
4286
+ return new ZodNullable({
4287
+ innerType: type,
4288
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
4289
+ ...processCreateParams(params)
4290
+ });
4291
+ };
4292
+ var ZodDefault = class extends ZodType {
4293
+ _parse(input) {
4294
+ const { ctx } = this._processInputParams(input);
4295
+ let data = ctx.data;
4296
+ if (ctx.parsedType === ZodParsedType.undefined) {
4297
+ data = this._def.defaultValue();
4298
+ }
4299
+ return this._def.innerType._parse({
4300
+ data,
4301
+ path: ctx.path,
4302
+ parent: ctx
4303
+ });
4304
+ }
4305
+ removeDefault() {
4306
+ return this._def.innerType;
4307
+ }
4308
+ };
4309
+ ZodDefault.create = (type, params) => {
4310
+ return new ZodDefault({
4311
+ innerType: type,
4312
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
4313
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4314
+ ...processCreateParams(params)
4315
+ });
4316
+ };
4317
+ var ZodCatch = class extends ZodType {
4318
+ _parse(input) {
4319
+ const { ctx } = this._processInputParams(input);
4320
+ const newCtx = {
4321
+ ...ctx,
4322
+ common: {
4323
+ ...ctx.common,
4324
+ issues: []
4325
+ }
4326
+ };
4327
+ const result = this._def.innerType._parse({
4328
+ data: newCtx.data,
4329
+ path: newCtx.path,
4330
+ parent: {
4331
+ ...newCtx
4332
+ }
4333
+ });
4334
+ if (isAsync(result)) {
4335
+ return result.then((result2) => {
4336
+ return {
4337
+ status: "valid",
4338
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
4339
+ get error() {
4340
+ return new ZodError(newCtx.common.issues);
4341
+ },
4342
+ input: newCtx.data
4343
+ })
4344
+ };
4345
+ });
4346
+ } else {
4347
+ return {
4348
+ status: "valid",
4349
+ value: result.status === "valid" ? result.value : this._def.catchValue({
4350
+ get error() {
4351
+ return new ZodError(newCtx.common.issues);
4352
+ },
4353
+ input: newCtx.data
4354
+ })
4355
+ };
4356
+ }
4357
+ }
4358
+ removeCatch() {
4359
+ return this._def.innerType;
4360
+ }
4361
+ };
4362
+ ZodCatch.create = (type, params) => {
4363
+ return new ZodCatch({
4364
+ innerType: type,
4365
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
4366
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
4367
+ ...processCreateParams(params)
4368
+ });
4369
+ };
4370
+ var ZodNaN = class extends ZodType {
4371
+ _parse(input) {
4372
+ const parsedType = this._getType(input);
4373
+ if (parsedType !== ZodParsedType.nan) {
4374
+ const ctx = this._getOrReturnCtx(input);
4375
+ addIssueToContext(ctx, {
4376
+ code: ZodIssueCode.invalid_type,
4377
+ expected: ZodParsedType.nan,
4378
+ received: ctx.parsedType
4379
+ });
4380
+ return INVALID;
4381
+ }
4382
+ return { status: "valid", value: input.data };
4383
+ }
4384
+ };
4385
+ ZodNaN.create = (params) => {
4386
+ return new ZodNaN({
4387
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
4388
+ ...processCreateParams(params)
4389
+ });
4390
+ };
4391
+ var BRAND = /* @__PURE__ */ Symbol("zod_brand");
4392
+ var ZodBranded = class extends ZodType {
4393
+ _parse(input) {
4394
+ const { ctx } = this._processInputParams(input);
4395
+ const data = ctx.data;
4396
+ return this._def.type._parse({
4397
+ data,
4398
+ path: ctx.path,
4399
+ parent: ctx
4400
+ });
4401
+ }
4402
+ unwrap() {
4403
+ return this._def.type;
4404
+ }
4405
+ };
4406
+ var ZodPipeline = class _ZodPipeline extends ZodType {
4407
+ _parse(input) {
4408
+ const { status, ctx } = this._processInputParams(input);
4409
+ if (ctx.common.async) {
4410
+ const handleAsync = async () => {
4411
+ const inResult = await this._def.in._parseAsync({
4412
+ data: ctx.data,
4413
+ path: ctx.path,
4414
+ parent: ctx
4415
+ });
4416
+ if (inResult.status === "aborted")
4417
+ return INVALID;
4418
+ if (inResult.status === "dirty") {
4419
+ status.dirty();
4420
+ return DIRTY(inResult.value);
4421
+ } else {
4422
+ return this._def.out._parseAsync({
4423
+ data: inResult.value,
4424
+ path: ctx.path,
4425
+ parent: ctx
4426
+ });
4427
+ }
4428
+ };
4429
+ return handleAsync();
4430
+ } else {
4431
+ const inResult = this._def.in._parseSync({
4432
+ data: ctx.data,
4433
+ path: ctx.path,
4434
+ parent: ctx
4435
+ });
4436
+ if (inResult.status === "aborted")
4437
+ return INVALID;
4438
+ if (inResult.status === "dirty") {
4439
+ status.dirty();
4440
+ return {
4441
+ status: "dirty",
4442
+ value: inResult.value
4443
+ };
4444
+ } else {
4445
+ return this._def.out._parseSync({
4446
+ data: inResult.value,
4447
+ path: ctx.path,
4448
+ parent: ctx
4449
+ });
4450
+ }
4451
+ }
4452
+ }
4453
+ static create(a, b) {
4454
+ return new _ZodPipeline({
4455
+ in: a,
4456
+ out: b,
4457
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
4458
+ });
4459
+ }
4460
+ };
4461
+ var ZodReadonly = class extends ZodType {
4462
+ _parse(input) {
4463
+ const result = this._def.innerType._parse(input);
4464
+ const freeze = (data) => {
4465
+ if (isValid(data)) {
4466
+ data.value = Object.freeze(data.value);
4467
+ }
4468
+ return data;
4469
+ };
4470
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
4471
+ }
4472
+ unwrap() {
4473
+ return this._def.innerType;
4474
+ }
4475
+ };
4476
+ ZodReadonly.create = (type, params) => {
4477
+ return new ZodReadonly({
4478
+ innerType: type,
4479
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
4480
+ ...processCreateParams(params)
4481
+ });
4482
+ };
4483
+ function cleanParams(params, data) {
4484
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
4485
+ const p2 = typeof p === "string" ? { message: p } : p;
4486
+ return p2;
4487
+ }
4488
+ function custom(check, _params = {}, fatal) {
4489
+ if (check)
4490
+ return ZodAny.create().superRefine((data, ctx) => {
4491
+ const r = check(data);
4492
+ if (r instanceof Promise) {
4493
+ return r.then((r2) => {
4494
+ if (!r2) {
4495
+ const params = cleanParams(_params, data);
4496
+ const _fatal = params.fatal ?? fatal ?? true;
4497
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4498
+ }
4499
+ });
4500
+ }
4501
+ if (!r) {
4502
+ const params = cleanParams(_params, data);
4503
+ const _fatal = params.fatal ?? fatal ?? true;
4504
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4505
+ }
4506
+ return;
4507
+ });
4508
+ return ZodAny.create();
4509
+ }
4510
+ var late = {
4511
+ object: ZodObject.lazycreate
4512
+ };
4513
+ var ZodFirstPartyTypeKind;
4514
+ (function(ZodFirstPartyTypeKind2) {
4515
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
4516
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
4517
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
4518
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
4519
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
4520
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
4521
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
4522
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
4523
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
4524
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
4525
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
4526
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
4527
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
4528
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
4529
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
4530
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
4531
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
4532
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
4533
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
4534
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
4535
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
4536
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
4537
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
4538
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
4539
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
4540
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
4541
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
4542
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
4543
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
4544
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
4545
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
4546
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
4547
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
4548
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
4549
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
4550
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
4551
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4552
+ var instanceOfType = (cls, params = {
4553
+ message: `Input not instance of ${cls.name}`
4554
+ }) => custom((data) => data instanceof cls, params);
4555
+ var stringType = ZodString.create;
4556
+ var numberType = ZodNumber.create;
4557
+ var nanType = ZodNaN.create;
4558
+ var bigIntType = ZodBigInt.create;
4559
+ var booleanType = ZodBoolean.create;
4560
+ var dateType = ZodDate.create;
4561
+ var symbolType = ZodSymbol.create;
4562
+ var undefinedType = ZodUndefined.create;
4563
+ var nullType = ZodNull.create;
4564
+ var anyType = ZodAny.create;
4565
+ var unknownType = ZodUnknown.create;
4566
+ var neverType = ZodNever.create;
4567
+ var voidType = ZodVoid.create;
4568
+ var arrayType = ZodArray.create;
4569
+ var objectType = ZodObject.create;
4570
+ var strictObjectType = ZodObject.strictCreate;
4571
+ var unionType = ZodUnion.create;
4572
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
4573
+ var intersectionType = ZodIntersection.create;
4574
+ var tupleType = ZodTuple.create;
4575
+ var recordType = ZodRecord.create;
4576
+ var mapType = ZodMap.create;
4577
+ var setType = ZodSet.create;
4578
+ var functionType = ZodFunction.create;
4579
+ var lazyType = ZodLazy.create;
4580
+ var literalType = ZodLiteral.create;
4581
+ var enumType = ZodEnum.create;
4582
+ var nativeEnumType = ZodNativeEnum.create;
4583
+ var promiseType = ZodPromise.create;
4584
+ var effectsType = ZodEffects.create;
4585
+ var optionalType = ZodOptional.create;
4586
+ var nullableType = ZodNullable.create;
4587
+ var preprocessType = ZodEffects.createWithPreprocess;
4588
+ var pipelineType = ZodPipeline.create;
4589
+ var ostring = () => stringType().optional();
4590
+ var onumber = () => numberType().optional();
4591
+ var oboolean = () => booleanType().optional();
4592
+ var coerce = {
4593
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4594
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4595
+ boolean: ((arg) => ZodBoolean.create({
4596
+ ...arg,
4597
+ coerce: true
4598
+ })),
4599
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4600
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
4601
+ };
4602
+ var NEVER = INVALID;
4603
+
4604
+ // src/schema/index.ts
4605
+ var eqlCastAsEnum = external_exports.enum([
4606
+ "text",
4607
+ "int",
4608
+ "small_int",
4609
+ "big_int",
4610
+ "real",
4611
+ "double",
4612
+ "boolean",
4613
+ "date",
4614
+ "timestamp",
4615
+ "jsonb"
4616
+ ]).default("text");
4617
+ var castAsEnum = external_exports.enum([
4618
+ "bigint",
4619
+ "boolean",
4620
+ "date",
4621
+ "timestamp",
4622
+ "number",
4623
+ "string",
4624
+ "json",
4625
+ "text"
4626
+ ]).default("text");
4627
+ function toEqlCastAs(value) {
4628
+ switch (value) {
4629
+ case "string":
4630
+ return "text";
4631
+ case "text":
4632
+ return "text";
4633
+ case "number":
4634
+ return "double";
4635
+ case "bigint":
4636
+ return "big_int";
4637
+ case "boolean":
4638
+ return "boolean";
4639
+ case "date":
4640
+ return "date";
4641
+ case "timestamp":
4642
+ return "timestamp";
4643
+ case "json":
4644
+ return "jsonb";
4645
+ }
4646
+ }
4647
+ var tokenFilterSchema = external_exports.object({
4648
+ kind: external_exports.literal("downcase")
4649
+ });
4650
+ var tokenizerSchema = external_exports.union([
4651
+ external_exports.object({
4652
+ kind: external_exports.literal("standard")
4653
+ }),
4654
+ external_exports.object({
4655
+ kind: external_exports.literal("ngram"),
4656
+ token_length: external_exports.number()
4657
+ })
4658
+ ]).default({ kind: "ngram", token_length: 3 }).optional();
4659
+ var oreIndexOptsSchema = external_exports.object({});
4660
+ var opeIndexOptsSchema = external_exports.object({});
4661
+ var uniqueIndexOptsSchema = external_exports.object({
4662
+ token_filters: external_exports.array(tokenFilterSchema).default([]).optional()
4663
+ });
4664
+ var matchIndexOptsSchema = external_exports.object({
4665
+ tokenizer: tokenizerSchema,
4666
+ token_filters: external_exports.array(tokenFilterSchema).default([]).optional(),
4667
+ k: external_exports.number().default(6).optional(),
4668
+ m: external_exports.number().default(2048).optional(),
4669
+ include_original: external_exports.boolean().default(false).optional()
4670
+ });
4671
+ var arrayIndexModeSchema = external_exports.union([
4672
+ external_exports.literal("all"),
4673
+ external_exports.literal("none"),
4674
+ external_exports.object({
4675
+ item: external_exports.boolean().optional(),
4676
+ wildcard: external_exports.boolean().optional(),
4677
+ position: external_exports.boolean().optional()
4678
+ })
4679
+ ]);
4680
+ var steVecIndexOptsSchema = external_exports.object({
4681
+ prefix: external_exports.string(),
4682
+ array_index_mode: arrayIndexModeSchema.optional(),
4683
+ mode: external_exports.enum(["compat", "standard"]).optional()
4684
+ });
4685
+ var indexesSchema = external_exports.object({
4686
+ ore: oreIndexOptsSchema.optional(),
4687
+ ope: opeIndexOptsSchema.optional(),
4688
+ unique: uniqueIndexOptsSchema.optional(),
4689
+ match: matchIndexOptsSchema.optional(),
4690
+ ste_vec: steVecIndexOptsSchema.optional()
4691
+ }).default({});
4692
+ var columnSchema = external_exports.object({
4693
+ cast_as: castAsEnum,
4694
+ indexes: indexesSchema
4695
+ }).default({});
4696
+ var tableSchema = external_exports.record(columnSchema).default({});
4697
+ var tablesSchema = external_exports.record(tableSchema).default({});
4698
+ var encryptConfigSchema = external_exports.object({
4699
+ v: external_exports.number(),
4700
+ tables: tablesSchema
4701
+ });
4702
+
4703
+ // src/wasm-inline.ts
4704
+ import {
4705
+ AccessKeyStrategy as AccessKeyStrategy2,
4706
+ OidcFederationStrategy
4707
+ } from "@cipherstash/auth/wasm-inline";
4708
+ function isEncrypted(value) {
4709
+ return wasmIsEncrypted(value);
4710
+ }
4711
+ var INTERNAL_CONSTRUCT = /* @__PURE__ */ Symbol("cs-wasm-client");
4712
+ var WasmEncryptionClient = class {
4713
+ /** @internal */
4714
+ client;
4715
+ /**
4716
+ * @internal Gated by the module-scoped {@link INTERNAL_CONSTRUCT}
4717
+ * symbol: external callers can't obtain it, so {@link Encryption} is
4718
+ * effectively the only constructor. (A `private` constructor would
4719
+ * block {@link Encryption} too, since it lives outside the class.)
4720
+ */
4721
+ constructor(token, client) {
4722
+ if (token !== INTERNAL_CONSTRUCT) {
4723
+ throw new Error(
4724
+ "[encryption]: WasmEncryptionClient cannot be constructed directly \u2014 use the Encryption() factory."
4725
+ );
4726
+ }
4727
+ this.client = client;
4728
+ }
4729
+ async encrypt(plaintext, opts) {
4730
+ const ffiOpts = {
4731
+ plaintext,
4732
+ table: opts.table.tableName,
4733
+ column: getColumnName(opts.column)
4734
+ };
4735
+ return await wasmEncrypt(
4736
+ this.client,
4737
+ ffiOpts
4738
+ );
4739
+ }
4740
+ async decrypt(encrypted) {
4741
+ return await wasmDecrypt(
4742
+ this.client,
4743
+ {
4744
+ ciphertext: encrypted
4745
+ }
4746
+ );
4747
+ }
4748
+ isEncrypted(value) {
4749
+ return wasmIsEncrypted(value);
4750
+ }
4751
+ };
4752
+ async function Encryption(config) {
4753
+ const { schemas, config: clientConfig } = config;
4754
+ if (!schemas.length) {
4755
+ throw new Error(
4756
+ "[encryption]: At least one encryptedTable must be provided to initialize the encryption client"
4757
+ );
4758
+ }
4759
+ for (const table of schemas) {
4760
+ const isV3 = typeof table.buildColumnKeyMap === "function";
4761
+ if (!isV3) {
4762
+ throw new Error(
4763
+ "[encryption]: `@cipherstash/stack/wasm-inline` is EQL v3 only \u2014 author schemas with `types` / `encryptedTable` from this entry. (EQL v2 is available on the native `@cipherstash/stack` entry.)"
4764
+ );
4765
+ }
4766
+ }
4767
+ const encryptConfig = encryptConfigSchema.parse(
4768
+ buildEncryptConfig(...schemas)
4769
+ );
4770
+ const strategy = resolveStrategy(clientConfig);
4771
+ const client = await wasmNewClient({
4772
+ strategy,
4773
+ encryptConfig: normalizeCastAs(encryptConfig),
4774
+ clientId: clientConfig.clientId,
4775
+ clientKey: clientConfig.clientKey,
4776
+ eqlVersion: 3
4777
+ });
4778
+ return new WasmEncryptionClient(INTERNAL_CONSTRUCT, client);
4779
+ }
4780
+ function normalizeCastAs(config) {
4781
+ const tables = {};
4782
+ for (const [tableName, columns] of Object.entries(config.tables)) {
4783
+ const normalised = {};
4784
+ for (const [colName, col] of Object.entries(columns)) {
4785
+ if (col.cast_as) {
4786
+ const eqlCastAs = toEqlCastAs(col.cast_as);
4787
+ if (eqlCastAs === void 0) {
4788
+ throw new Error(
4789
+ `[encryption]: unrecognised cast_as value "${col.cast_as}" on ${tableName}.${colName} \u2014 update toEqlCastAs() to map it to an EQL variant.`
4790
+ );
4791
+ }
4792
+ normalised[colName] = { ...col, cast_as: eqlCastAs };
4793
+ } else {
4794
+ normalised[colName] = col;
4795
+ }
4796
+ }
4797
+ tables[tableName] = normalised;
4798
+ }
4799
+ return { ...config, tables };
4800
+ }
4801
+ function getColumnName(col) {
4802
+ if (typeof col?.getName === "function") {
4803
+ return col.getName();
4804
+ }
4805
+ throw new Error(
4806
+ "[encryption]: opts.column must be a column builder exposing getName()"
4807
+ );
4808
+ }
4809
+ var warnedStrategyDeprecated = false;
4810
+ function warnStrategyDeprecated() {
4811
+ if (warnedStrategyDeprecated) return;
4812
+ warnedStrategyDeprecated = true;
4813
+ console.warn(
4814
+ "[encryption]: `config.strategy` is deprecated and will be removed in a future release \u2014 use `config.authStrategy` instead."
4815
+ );
4816
+ }
4817
+ function __resetStrategyDeprecationWarningForTests() {
4818
+ warnedStrategyDeprecated = false;
4819
+ }
4820
+ function resolveStrategy(cfg) {
4821
+ if (cfg.strategy) {
4822
+ warnStrategyDeprecated();
4823
+ }
4824
+ const authStrategy = cfg.authStrategy ?? cfg.strategy;
4825
+ if (authStrategy && cfg.accessKey) {
4826
+ const field = cfg.authStrategy ? "authStrategy" : "strategy";
4827
+ throw new Error(
4828
+ `[encryption]: \`config.${field}\` and \`config.accessKey\` are mutually exclusive \u2014 pass exactly one.`
4829
+ );
4830
+ }
4831
+ if (authStrategy) return authStrategy;
4832
+ if (!cfg.workspaceCrn || !cfg.accessKey) {
4833
+ throw new Error(
4834
+ "[encryption]: `config.workspaceCrn` and `config.accessKey` are required when no auth strategy is provided."
4835
+ );
4836
+ }
4837
+ const result = AccessKeyStrategy.create(cfg.workspaceCrn, cfg.accessKey);
4838
+ if (result.failure) {
4839
+ throw new Error(
4840
+ `[encryption]: failed to construct \`AccessKeyStrategy\` from \`config.workspaceCrn\` / \`config.accessKey\` (${result.failure.type}): ${result.failure.error.message}`
4841
+ );
4842
+ }
4843
+ return result.data;
4844
+ }
4845
+ export {
4846
+ AccessKeyStrategy2 as AccessKeyStrategy,
4847
+ EncryptedBigintColumn,
4848
+ EncryptedBigintEqColumn,
4849
+ EncryptedBigintOrdColumn,
4850
+ EncryptedBigintOrdOreColumn,
4851
+ EncryptedBooleanColumn,
4852
+ EncryptedDateColumn,
4853
+ EncryptedDateEqColumn,
4854
+ EncryptedDateOrdColumn,
4855
+ EncryptedDateOrdOreColumn,
4856
+ EncryptedDoubleColumn,
4857
+ EncryptedDoubleEqColumn,
4858
+ EncryptedDoubleOrdColumn,
4859
+ EncryptedDoubleOrdOreColumn,
4860
+ EncryptedIntegerColumn,
4861
+ EncryptedIntegerEqColumn,
4862
+ EncryptedIntegerOrdColumn,
4863
+ EncryptedIntegerOrdOreColumn,
4864
+ EncryptedJsonColumn,
4865
+ EncryptedNumericColumn,
4866
+ EncryptedNumericEqColumn,
4867
+ EncryptedNumericOrdColumn,
4868
+ EncryptedNumericOrdOreColumn,
4869
+ EncryptedRealColumn,
4870
+ EncryptedRealEqColumn,
4871
+ EncryptedRealOrdColumn,
4872
+ EncryptedRealOrdOreColumn,
4873
+ EncryptedSmallintColumn,
4874
+ EncryptedSmallintEqColumn,
4875
+ EncryptedSmallintOrdColumn,
4876
+ EncryptedSmallintOrdOreColumn,
4877
+ EncryptedTable,
4878
+ EncryptedTextColumn,
4879
+ EncryptedTextEqColumn,
4880
+ EncryptedTextMatchColumn,
4881
+ EncryptedTextOrdColumn,
4882
+ EncryptedTextOrdOreColumn,
4883
+ EncryptedTextSearchColumn,
4884
+ EncryptedTimestampColumn,
4885
+ EncryptedTimestampEqColumn,
4886
+ EncryptedTimestampOrdColumn,
4887
+ EncryptedTimestampOrdOreColumn,
4888
+ Encryption,
4889
+ OidcFederationStrategy,
4890
+ TEXT_SEARCH_EQL_TYPE,
4891
+ WasmEncryptionClient,
4892
+ __resetStrategyDeprecationWarningForTests,
4893
+ buildEncryptConfig,
4894
+ encryptedTable,
4895
+ getColumnName,
4896
+ isEncrypted,
4897
+ normalizeCastAs,
4898
+ resolveStrategy,
4899
+ types
4900
+ };
4901
+ //# sourceMappingURL=wasm-inline.js.map