matrix-nodejs-homeserver 0.2.0 → 0.3.1

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 (78) hide show
  1. package/README.md +29 -7
  2. package/dist/api/account.js +385 -351
  3. package/dist/api/admin.js +76 -60
  4. package/dist/api/appservice.js +37 -25
  5. package/dist/api/backup.js +73 -62
  6. package/dist/api/federation.js +172 -138
  7. package/dist/api/filters.js +4 -3
  8. package/dist/api/legacy.js +91 -78
  9. package/dist/api/media.js +70 -54
  10. package/dist/api/misc.js +46 -37
  11. package/dist/api/preview.js +4 -3
  12. package/dist/api/profile.js +108 -97
  13. package/dist/api/push.js +114 -99
  14. package/dist/api/relationships.js +64 -58
  15. package/dist/api/rooms.js +703 -580
  16. package/dist/api/rtc.d.ts +0 -1
  17. package/dist/api/rtc.js +48 -34
  18. package/dist/api/search.js +133 -127
  19. package/dist/api/slidingsync.js +41 -31
  20. package/dist/api/spaces.js +82 -77
  21. package/dist/api/sync.js +59 -50
  22. package/dist/api/threadsubs.js +72 -61
  23. package/dist/api/threepid.js +99 -66
  24. package/dist/api/uia.js +17 -16
  25. package/dist/api/user.js +221 -178
  26. package/dist/core/admin.d.ts +0 -1
  27. package/dist/core/admin.js +6 -5
  28. package/dist/core/adminroom.js +9 -8
  29. package/dist/core/appservices.d.ts +2 -1
  30. package/dist/core/appservices.js +5 -4
  31. package/dist/core/audit.d.ts +0 -1
  32. package/dist/core/authrules.js +26 -25
  33. package/dist/core/delayed.js +2 -1
  34. package/dist/core/events.js +11 -10
  35. package/dist/core/invitefilter.js +2 -1
  36. package/dist/core/keys.js +2 -1
  37. package/dist/core/m.d.ts +209 -0
  38. package/dist/core/m.js +182 -0
  39. package/dist/core/partialstate.js +2 -1
  40. package/dist/core/policy.js +4 -3
  41. package/dist/core/push.d.ts +0 -1
  42. package/dist/core/push.js +12 -11
  43. package/dist/core/pushrules.js +36 -35
  44. package/dist/core/rooms.js +76 -74
  45. package/dist/core/stateres.js +7 -6
  46. package/dist/federation/client.js +2 -1
  47. package/dist/federation/index.d.ts +1 -1
  48. package/dist/federation/index.js +30 -29
  49. package/dist/homeserver.d.ts +2 -1
  50. package/dist/homeserver.js +1 -0
  51. package/dist/http/handler.js +2 -23
  52. package/dist/http/input.js +2 -2
  53. package/dist/http/procedure.js +25 -0
  54. package/dist/http/router.d.ts +9 -26
  55. package/dist/http/router.js +10 -30
  56. package/dist/index.d.ts +2 -1
  57. package/dist/index.js +2 -1
  58. package/dist/vendor/zod/LICENSE +21 -0
  59. package/dist/vendor/zod/v4/classic/errors.js +54 -0
  60. package/dist/vendor/zod/v4/classic/parse.js +17 -0
  61. package/dist/vendor/zod/v4/classic/schemas.js +865 -0
  62. package/dist/vendor/zod/v4/core/api.js +512 -0
  63. package/dist/vendor/zod/v4/core/checks.js +300 -0
  64. package/dist/vendor/zod/v4/core/core.js +109 -0
  65. package/dist/vendor/zod/v4/core/doc.js +35 -0
  66. package/dist/vendor/zod/v4/core/errors.js +118 -0
  67. package/dist/vendor/zod/v4/core/json-schema-processors.js +428 -0
  68. package/dist/vendor/zod/v4/core/memoizer.js +255 -0
  69. package/dist/vendor/zod/v4/core/parse.js +206 -0
  70. package/dist/vendor/zod/v4/core/regexes.js +73 -0
  71. package/dist/vendor/zod/v4/core/registries.js +48 -0
  72. package/dist/vendor/zod/v4/core/schemas.js +1378 -0
  73. package/dist/vendor/zod/v4/core/to-json-schema.js +448 -0
  74. package/dist/vendor/zod/v4/core/util.js +537 -0
  75. package/dist/vendor/zod/v4/core/versions.js +8 -0
  76. package/dist/vendor/zod/v4/locales/en.js +110 -0
  77. package/package.json +3 -5
  78. package/dist/core/pushrules.d.ts +0 -1
@@ -0,0 +1,1378 @@
1
+ import { aborted, allowsEval, assignProp, attachSchema, cached, cleanRegex, defineLazyInternal, esc, escapeRegex, explicitlyAborted, finalizeIssue, getEnumValues, hide, isObject, isPlainObject, issue, optionalKeys, own, prefixIssues, propertyKeyTypes, sizeCaps } from "./util.js";
2
+ import { $ZodAsyncError, $ZodEncodeError, $constructor, config, globalConfig } from "./core.js";
3
+ import { anyString, boolean, cidrv4, cidrv6, cuid, cuid2, date, datetime, duration, e164, email, emoji, guid, httpProtocol, ipv4, ipv6, ksuid, nanoid, nanoidOfLength, number, time, ulid, uuid, xid } from "./regexes.js";
4
+ import { $ZodCheck, $ZodCheckNumberFormat, $ZodCheckStringFormat } from "./checks.js";
5
+ import { Doc } from "./doc.js";
6
+ import { version } from "./versions.js";
7
+ //#region node_modules/zod/v4/core/schemas.js
8
+ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
9
+ var _a;
10
+ inst ?? (inst = {});
11
+ inst._zod.def = def;
12
+ inst._zod.bag = inst._zod.bag || {};
13
+ inst._zod.version = version;
14
+ const defChecks = inst._zod.def.checks;
15
+ const checks = inst._zod.traits.has("$ZodCheck") ? [inst, ...defChecks ?? []] : defChecks?.length ? [...defChecks] : [];
16
+ for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
17
+ if (checks.length === 0) {
18
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
19
+ inst._zod.deferred?.push(() => {
20
+ inst._zod.run = inst._zod.parse;
21
+ });
22
+ } else {
23
+ const runChecks = (payload, checks, ctx) => {
24
+ if (payload.memo) return payload;
25
+ let isAborted = aborted(payload);
26
+ let asyncResult;
27
+ for (const ch of checks) {
28
+ if (ch._zod.def.when) {
29
+ if (explicitlyAborted(payload)) continue;
30
+ if (!ch._zod.def.when(payload)) continue;
31
+ } else if (isAborted) continue;
32
+ const currLen = payload.issues.length;
33
+ const _ = ch._zod.check(payload);
34
+ if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
35
+ if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
36
+ await _;
37
+ if (payload.issues.length === currLen) return;
38
+ attachSchema(payload.issues, currLen, inst);
39
+ if (!isAborted) isAborted = aborted(payload, currLen);
40
+ });
41
+ else {
42
+ if (payload.issues.length === currLen) continue;
43
+ attachSchema(payload.issues, currLen, inst);
44
+ if (!isAborted) isAborted = aborted(payload, currLen);
45
+ }
46
+ }
47
+ if (asyncResult) return asyncResult.then(() => {
48
+ return payload;
49
+ });
50
+ return payload;
51
+ };
52
+ const handleCanaryResult = (canary, payload, ctx) => {
53
+ if (aborted(canary)) {
54
+ canary.aborted = true;
55
+ return canary;
56
+ }
57
+ const checkResult = runChecks(payload, checks, ctx);
58
+ if (checkResult instanceof Promise) {
59
+ if (ctx.async === false) throw new $ZodAsyncError();
60
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
61
+ }
62
+ return inst._zod.parse(checkResult, ctx);
63
+ };
64
+ inst._zod.run = (payload, ctx) => {
65
+ if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
66
+ if (ctx.direction === "backward") {
67
+ const canary = inst._zod.parse({
68
+ value: payload.value,
69
+ issues: []
70
+ }, {
71
+ ...ctx,
72
+ skipChecks: true
73
+ });
74
+ if (canary instanceof Promise) return canary.then((canary) => {
75
+ return handleCanaryResult(canary, payload, ctx);
76
+ });
77
+ return handleCanaryResult(canary, payload, ctx);
78
+ }
79
+ const result = inst._zod.parse(payload, ctx);
80
+ if (result instanceof Promise) {
81
+ if (ctx.async === false) throw new $ZodAsyncError();
82
+ return result.then((result) => runChecks(result, checks, ctx));
83
+ }
84
+ return runChecks(result, checks, ctx);
85
+ };
86
+ }
87
+ }, {
88
+ get "~standard"() {
89
+ return hide(this, "~standard", standardProps(this));
90
+ },
91
+ set "~standard"(value) {
92
+ own(this, "~standard", value);
93
+ }
94
+ });
95
+ /** The Standard Schema surface for `inst`. Shared so wrappers can extend it without forcing it. */
96
+ const toStandardResult = (r, ctx) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx, config())) } : { value: r.value };
97
+ async function validateAsync(inst, value) {
98
+ const ctx = { async: true };
99
+ return toStandardResult(await inst._zod.run({
100
+ value,
101
+ issues: []
102
+ }, ctx), ctx);
103
+ }
104
+ function standardProps(inst) {
105
+ return {
106
+ validate: (value) => {
107
+ const ctx = { async: false };
108
+ try {
109
+ const r = inst._zod.run({
110
+ value,
111
+ issues: []
112
+ }, ctx);
113
+ if (!(r instanceof Promise)) return toStandardResult(r, ctx);
114
+ } catch (_) {}
115
+ return validateAsync(inst, value);
116
+ },
117
+ vendor: "zod",
118
+ version: 1
119
+ };
120
+ }
121
+ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
122
+ $ZodType.init(inst, def);
123
+ inst._zod.pattern = def.pattern ?? anyString;
124
+ inst._zod.parse = (payload, _) => {
125
+ if (def.coerce) try {
126
+ payload.value = String(payload.value);
127
+ } catch (_) {}
128
+ if (typeof payload.value === "string") return payload;
129
+ payload.issues.push({
130
+ expected: "string",
131
+ code: "invalid_type",
132
+ input: payload.value,
133
+ inst
134
+ });
135
+ return payload;
136
+ };
137
+ });
138
+ const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
139
+ $ZodCheckStringFormat.init(inst, def);
140
+ $ZodString.init(inst, def);
141
+ });
142
+ const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
143
+ def.pattern ?? (def.pattern = guid);
144
+ $ZodStringFormat.init(inst, def);
145
+ });
146
+ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
147
+ if (def.version) {
148
+ const v = {
149
+ v1: 1,
150
+ v2: 2,
151
+ v3: 3,
152
+ v4: 4,
153
+ v5: 5,
154
+ v6: 6,
155
+ v7: 7,
156
+ v8: 8
157
+ }[def.version];
158
+ if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
159
+ def.pattern ?? (def.pattern = uuid(v));
160
+ } else def.pattern ?? (def.pattern = uuid());
161
+ $ZodStringFormat.init(inst, def);
162
+ });
163
+ const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
164
+ def.pattern ?? (def.pattern = email);
165
+ $ZodStringFormat.init(inst, def);
166
+ });
167
+ function canParseURL(input) {
168
+ try {
169
+ if (typeof URL !== "undefined" && typeof URL.canParse === "function") return URL.canParse(input);
170
+ new URL(input);
171
+ return true;
172
+ } catch {
173
+ return false;
174
+ }
175
+ }
176
+ function validateURL(trimmed, def) {
177
+ if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def)) return canParseURL(trimmed) || 2;
178
+ return parseURLObject(trimmed, def);
179
+ }
180
+ /** Parses a URL while preserving the non-normalizing HTTP guard. */
181
+ function parseURLObject(trimmed, def) {
182
+ if (!def.normalize && def.protocol?.source === httpProtocol.source && !/^https?:\/\//i.test(trimmed)) return 1;
183
+ try {
184
+ if (typeof URL !== "undefined") {
185
+ const URLStatic = URL;
186
+ if (typeof URLStatic.parse === "function") return URLStatic.parse(trimmed) ?? 2;
187
+ }
188
+ return new URL(trimmed);
189
+ } catch {
190
+ return 2;
191
+ }
192
+ }
193
+ const asciiTabOrNewline = /[\t\n\r]/g;
194
+ /** The URL parser deletes every ASCII tab, LF and CR from its input before it parses, so `new URL("https://exa\nmple.com")` reports on `example.com`. Applying the same deletion to the returned value closes the half of that divergence which can move the host; the parser's other rewrite, stripping C0 controls at the edges, cannot. */
195
+ function stripTabAndNewline(value) {
196
+ return value.replace(asciiTabOrNewline, "");
197
+ }
198
+ function urlHostnameOk(url, hostname) {
199
+ hostname.lastIndex = 0;
200
+ return hostname.test(url.hostname);
201
+ }
202
+ function urlProtocolOk(url, protocol) {
203
+ protocol.lastIndex = 0;
204
+ return protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol);
205
+ }
206
+ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
207
+ $ZodStringFormat.init(inst, def);
208
+ inst._zod.check = (payload) => {
209
+ try {
210
+ const trimmed = payload.value.trim();
211
+ const url = validateURL(trimmed, def);
212
+ if (url === 1) {
213
+ payload.issues.push({
214
+ code: "invalid_format",
215
+ format: "url",
216
+ note: "Invalid URL format",
217
+ input: payload.value,
218
+ inst,
219
+ continue: !def.abort
220
+ });
221
+ return;
222
+ }
223
+ if (url === 2) {
224
+ payload.issues.push({
225
+ code: "invalid_format",
226
+ format: "url",
227
+ input: payload.value,
228
+ inst,
229
+ continue: !def.abort
230
+ });
231
+ return;
232
+ }
233
+ if (url === true) {
234
+ payload.value = stripTabAndNewline(trimmed);
235
+ return;
236
+ }
237
+ if (def.hostname && !urlHostnameOk(url, def.hostname)) payload.issues.push({
238
+ code: "invalid_format",
239
+ format: "url",
240
+ note: "Invalid hostname",
241
+ pattern: def.hostname.source,
242
+ input: payload.value,
243
+ inst,
244
+ continue: !def.abort
245
+ });
246
+ if (def.protocol && !urlProtocolOk(url, def.protocol)) payload.issues.push({
247
+ code: "invalid_format",
248
+ format: "url",
249
+ note: "Invalid protocol",
250
+ pattern: def.protocol.source,
251
+ input: payload.value,
252
+ inst,
253
+ continue: !def.abort
254
+ });
255
+ payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
256
+ return;
257
+ } catch (_) {
258
+ payload.issues.push({
259
+ code: "invalid_format",
260
+ format: "url",
261
+ input: payload.value,
262
+ inst,
263
+ continue: !def.abort
264
+ });
265
+ }
266
+ };
267
+ });
268
+ const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
269
+ def.pattern ?? (def.pattern = emoji());
270
+ $ZodStringFormat.init(inst, def);
271
+ });
272
+ const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
273
+ if (def.length !== void 0 && (!Number.isInteger(def.length) || def.length < 1)) throw new Error(`Invalid nanoid length: ${def.length}`);
274
+ def.pattern ?? (def.pattern = def.length === void 0 ? nanoid : nanoidOfLength(def.length));
275
+ $ZodStringFormat.init(inst, def);
276
+ });
277
+ /**
278
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
279
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
280
+ * See https://github.com/paralleldrive/cuid.
281
+ */
282
+ const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
283
+ def.pattern ?? (def.pattern = cuid);
284
+ $ZodStringFormat.init(inst, def);
285
+ });
286
+ const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
287
+ def.pattern ?? (def.pattern = cuid2);
288
+ $ZodStringFormat.init(inst, def);
289
+ });
290
+ const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
291
+ def.pattern ?? (def.pattern = ulid);
292
+ $ZodStringFormat.init(inst, def);
293
+ });
294
+ const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
295
+ def.pattern ?? (def.pattern = xid);
296
+ $ZodStringFormat.init(inst, def);
297
+ });
298
+ const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
299
+ def.pattern ?? (def.pattern = ksuid);
300
+ $ZodStringFormat.init(inst, def);
301
+ });
302
+ const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
303
+ def.pattern ?? (def.pattern = datetime(def));
304
+ $ZodStringFormat.init(inst, def);
305
+ });
306
+ const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
307
+ def.pattern ?? (def.pattern = date);
308
+ $ZodStringFormat.init(inst, def);
309
+ });
310
+ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
311
+ def.pattern ?? (def.pattern = time(def));
312
+ $ZodStringFormat.init(inst, def);
313
+ });
314
+ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
315
+ def.pattern ?? (def.pattern = duration);
316
+ $ZodStringFormat.init(inst, def);
317
+ });
318
+ const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
319
+ def.pattern ?? (def.pattern = ipv4);
320
+ $ZodStringFormat.init(inst, def);
321
+ });
322
+ /** An IPv6 address is written with hex digits, colons and dots, and nothing else. The guard is what makes the check below an IPv6 check: `new URL("http://[...]")` parses an authority, not an address, so `@` and `\` re-delimit it and `"::@1\\"` validates against the host `0.0.0.1`. The URL parser also deletes ASCII tab, LF and CR rather than failing, which is how `"::1\n"` validated as `::1`. */
323
+ const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
324
+ function isValidIPv6(value) {
325
+ if (!ipv6Alphabet.test(value)) return false;
326
+ return canParseURL(`http://[${value}]`);
327
+ }
328
+ const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
329
+ def.pattern ?? (def.pattern = ipv6);
330
+ $ZodStringFormat.init(inst, def);
331
+ inst._zod.check = (payload) => {
332
+ if (!isValidIPv6(payload.value)) payload.issues.push({
333
+ code: "invalid_format",
334
+ format: "ipv6",
335
+ input: payload.value,
336
+ inst,
337
+ continue: !def.abort
338
+ });
339
+ };
340
+ });
341
+ const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
342
+ def.pattern ?? (def.pattern = cidrv4);
343
+ $ZodStringFormat.init(inst, def);
344
+ });
345
+ function isValidCIDRv6(value) {
346
+ const parts = value.split("/");
347
+ if (parts.length !== 2) return false;
348
+ const [address, prefix] = parts;
349
+ if (!prefix) return false;
350
+ const prefixNum = Number(prefix);
351
+ if (`${prefixNum}` !== prefix) return false;
352
+ if (prefixNum < 0 || prefixNum > 128) return false;
353
+ return isValidIPv6(address);
354
+ }
355
+ const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
356
+ def.pattern ?? (def.pattern = cidrv6);
357
+ $ZodStringFormat.init(inst, def);
358
+ inst._zod.check = (payload) => {
359
+ if (!isValidCIDRv6(payload.value)) payload.issues.push({
360
+ code: "invalid_format",
361
+ format: "cidrv6",
362
+ input: payload.value,
363
+ inst,
364
+ continue: !def.abort
365
+ });
366
+ };
367
+ });
368
+ function isValidBase64(data) {
369
+ if (data === "") return true;
370
+ if (/\s/.test(data)) return false;
371
+ if (data.length % 4 !== 0) return false;
372
+ try {
373
+ atob(data);
374
+ return true;
375
+ } catch {
376
+ return false;
377
+ }
378
+ }
379
+ const base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
380
+ const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
381
+ def.pattern ?? (def.pattern = base64Charset);
382
+ $ZodStringFormat.init(inst, def);
383
+ inst._zod.check = (payload) => {
384
+ if (isValidBase64(payload.value)) return;
385
+ payload.issues.push({
386
+ code: "invalid_format",
387
+ format: "base64",
388
+ input: payload.value,
389
+ inst,
390
+ continue: !def.abort
391
+ });
392
+ };
393
+ });
394
+ const base64urlCharset = /^[A-Za-z0-9_-]*$/;
395
+ function isValidBase64URL(data) {
396
+ if (!base64urlCharset.test(data)) return false;
397
+ const base64 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
398
+ return isValidBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
399
+ }
400
+ const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
401
+ def.pattern ?? (def.pattern = base64urlCharset);
402
+ $ZodStringFormat.init(inst, def);
403
+ inst._zod.check = (payload) => {
404
+ if (isValidBase64URL(payload.value)) return;
405
+ payload.issues.push({
406
+ code: "invalid_format",
407
+ format: "base64url",
408
+ input: payload.value,
409
+ inst,
410
+ continue: !def.abort
411
+ });
412
+ };
413
+ });
414
+ const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
415
+ def.pattern ?? (def.pattern = e164);
416
+ $ZodStringFormat.init(inst, def);
417
+ });
418
+ function isValidJWT(token, algorithm = null) {
419
+ try {
420
+ const tokensParts = token.split(".");
421
+ if (tokensParts.length !== 3) return false;
422
+ const [header] = tokensParts;
423
+ if (!header) return false;
424
+ const parsedHeader = JSON.parse(atob(header));
425
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
426
+ if (!parsedHeader.alg) return false;
427
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
428
+ return true;
429
+ } catch {
430
+ return false;
431
+ }
432
+ }
433
+ const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
434
+ $ZodStringFormat.init(inst, def);
435
+ inst._zod.check = (payload) => {
436
+ if (isValidJWT(payload.value, def.alg)) return;
437
+ payload.issues.push({
438
+ code: "invalid_format",
439
+ format: "jwt",
440
+ input: payload.value,
441
+ inst,
442
+ continue: !def.abort
443
+ });
444
+ };
445
+ });
446
+ const $ZodNumber = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) => {
447
+ $ZodType.init(inst, def);
448
+ inst._zod.pattern = number;
449
+ inst._zod.parse = (payload, _ctx) => {
450
+ if (def.coerce) try {
451
+ payload.value = Number(payload.value);
452
+ } catch (_) {}
453
+ const input = payload.value;
454
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) return payload;
455
+ const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? String(input) : void 0 : void 0;
456
+ payload.issues.push({
457
+ expected: "number",
458
+ code: "invalid_type",
459
+ input,
460
+ inst,
461
+ ...received ? { received } : {}
462
+ });
463
+ return payload;
464
+ };
465
+ });
466
+ const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, def) => {
467
+ $ZodCheckNumberFormat.init(inst, def);
468
+ $ZodNumber.init(inst, def);
469
+ });
470
+ const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
471
+ $ZodType.init(inst, def);
472
+ inst._zod.pattern = boolean;
473
+ inst._zod.parse = (payload, _ctx) => {
474
+ if (def.coerce) try {
475
+ payload.value = Boolean(payload.value);
476
+ } catch (_) {}
477
+ const input = payload.value;
478
+ if (typeof input === "boolean") return payload;
479
+ payload.issues.push({
480
+ expected: "boolean",
481
+ code: "invalid_type",
482
+ input,
483
+ inst
484
+ });
485
+ return payload;
486
+ };
487
+ });
488
+ const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
489
+ $ZodType.init(inst, def);
490
+ inst._zod.parse = (payload) => payload;
491
+ });
492
+ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
493
+ $ZodType.init(inst, def);
494
+ inst._zod.parse = (payload, _ctx) => {
495
+ payload.issues.push({
496
+ expected: "never",
497
+ code: "invalid_type",
498
+ input: payload.value,
499
+ inst
500
+ });
501
+ return payload;
502
+ };
503
+ });
504
+ function capSize(inst, size) {
505
+ const caps = sizeCaps(inst._zod.def.checks);
506
+ if (!caps.length) return;
507
+ const cap = Math.min(...caps.map((c) => c[0]));
508
+ const parse = inst._zod.parse;
509
+ inst._zod.parse = (payload, ctx) => {
510
+ const n = size(payload.value);
511
+ if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
512
+ for (const [max, ch] of sizeCaps(inst._zod.def.checks)) if (n > max && ch._zod.def.when(payload)) {
513
+ const start = payload.issues.length;
514
+ ch._zod.check(payload);
515
+ payload.issues[start].continue = false;
516
+ attachSchema(payload.issues, start, inst);
517
+ return payload;
518
+ }
519
+ }
520
+ return parse(payload, ctx);
521
+ };
522
+ }
523
+ const arraySize = (input) => Array.isArray(input) ? input.length : -1;
524
+ function handleArrayResult(result, final, index) {
525
+ if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
526
+ final.value[index] = result.value;
527
+ }
528
+ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
529
+ $ZodType.init(inst, def);
530
+ const memo = globalConfig.memoizer;
531
+ memo?.attach(inst);
532
+ inst._zod.parse = (payload, ctx) => {
533
+ const input = payload.value;
534
+ if (!Array.isArray(input)) {
535
+ payload.issues.push({
536
+ expected: "array",
537
+ code: "invalid_type",
538
+ input,
539
+ inst
540
+ });
541
+ return payload;
542
+ }
543
+ payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
544
+ const proms = [];
545
+ const abortEarly = ctx?.abortEarly;
546
+ for (let i = 0; i < input.length; i++) {
547
+ const item = input[i];
548
+ const result = def.element._zod.run({
549
+ value: item,
550
+ issues: []
551
+ }, ctx);
552
+ if (result instanceof Promise) proms.push(result.then((result) => handleArrayResult(result, payload, i)));
553
+ else {
554
+ handleArrayResult(result, payload, i);
555
+ if (abortEarly && result.issues.length !== 0 && aborted(result)) break;
556
+ }
557
+ }
558
+ if (proms.length) return Promise.all(proms).then(() => payload);
559
+ return payload;
560
+ };
561
+ capSize(inst, arraySize);
562
+ });
563
+ function handlePropertyResult(result, final, key, input, optin, optout) {
564
+ const isPresent = key in input;
565
+ const isOptionalOut = optout === "optional";
566
+ if (!isPresent && isOptionalOut && optin === "optional") return;
567
+ if (result.issues.length) {
568
+ if (optin !== void 0 && isOptionalOut && !isPresent) return;
569
+ final.issues.push(...prefixIssues(key, result.issues));
570
+ }
571
+ if (!isPresent && optin === void 0) {
572
+ if (!result.issues.length) final.issues.push({
573
+ code: "invalid_type",
574
+ expected: "nonoptional",
575
+ input: void 0,
576
+ path: [key]
577
+ });
578
+ return;
579
+ }
580
+ if (result.value === void 0) {
581
+ if (isPresent || optin === "defaulted" && !isOptionalOut) final.value[key] = void 0;
582
+ } else final.value[key] = result.value;
583
+ }
584
+ const NO_SYMBOL_KEYS = [];
585
+ function normalizeDef(def) {
586
+ const keys = Object.keys(def.shape);
587
+ const ownSymbols = Object.getOwnPropertySymbols(def.shape);
588
+ const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
589
+ const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
590
+ for (const k of allKeys) if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
591
+ const okeys = optionalKeys(def.shape);
592
+ return {
593
+ ...def,
594
+ allKeys,
595
+ symbolKeys,
596
+ keySet: new Set(keys),
597
+ numKeys: keys.length,
598
+ optionalKeys: new Set(okeys)
599
+ };
600
+ }
601
+ function handleCatchall(proms, input, payload, ctx, def, inst, abortEarly) {
602
+ const unrecognized = [];
603
+ const keySet = def.keySet;
604
+ const _catchall = def.catchall._zod;
605
+ const t = _catchall.def.type;
606
+ const optin = _catchall.optin;
607
+ const optout = _catchall.optout;
608
+ let seen = 0;
609
+ for (const key in input) {
610
+ if (abortEarly && payload.issues.length !== seen) {
611
+ if (aborted(payload, seen)) break;
612
+ seen = payload.issues.length;
613
+ }
614
+ if (keySet.has(key)) continue;
615
+ if (key === "__proto__") {
616
+ if (t === "never") unrecognized.push(key);
617
+ continue;
618
+ }
619
+ if (t === "never") {
620
+ unrecognized.push(key);
621
+ continue;
622
+ }
623
+ const r = _catchall.run({
624
+ value: input[key],
625
+ issues: []
626
+ }, ctx);
627
+ if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
628
+ else handlePropertyResult(r, payload, key, input, optin, optout);
629
+ }
630
+ if (unrecognized.length) payload.issues.push({
631
+ code: "unrecognized_keys",
632
+ keys: unrecognized,
633
+ input,
634
+ inst,
635
+ continue: true
636
+ });
637
+ if (!proms.length) return payload;
638
+ return Promise.all(proms).then(() => {
639
+ return payload;
640
+ });
641
+ }
642
+ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
643
+ $ZodType.init(inst, def);
644
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
645
+ const sh = desc?.get ? desc.get.raw : def.shape ?? {};
646
+ if (sh) {
647
+ const get = () => {
648
+ const newSh = { ...sh };
649
+ Object.defineProperty(def, "shape", { value: newSh });
650
+ get.raw = newSh;
651
+ return newSh;
652
+ };
653
+ get.raw = sh;
654
+ Object.defineProperty(def, "shape", { get });
655
+ }
656
+ const _normalized = cached(() => normalizeDef(def));
657
+ defineLazyInternal(inst, "propValues", (zod) => {
658
+ const shape = zod.def.shape;
659
+ const propValues = {};
660
+ for (const key in shape) {
661
+ const field = shape[key]._zod;
662
+ if (field.values) {
663
+ if (!Object.prototype.hasOwnProperty.call(propValues, key)) assignProp(propValues, key, /* @__PURE__ */ new Set());
664
+ for (const v of field.values) propValues[key].add(v);
665
+ if (field.optin !== void 0) propValues[key].add(void 0);
666
+ }
667
+ }
668
+ return propValues;
669
+ });
670
+ const isObject$1 = isObject;
671
+ const catchall = def.catchall;
672
+ let value;
673
+ const memo = globalConfig.memoizer;
674
+ memo?.attach(inst);
675
+ inst._zod.parse = (payload, ctx) => {
676
+ value ?? (value = _normalized.value);
677
+ const input = payload.value;
678
+ if (!isObject$1(input)) {
679
+ payload.issues.push({
680
+ expected: "object",
681
+ code: "invalid_type",
682
+ input,
683
+ inst
684
+ });
685
+ return payload;
686
+ }
687
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
688
+ const proms = [];
689
+ const shape = value.shape;
690
+ const abortEarly = ctx?.abortEarly;
691
+ let seen = payload.issues.length;
692
+ for (const key of value.allKeys) {
693
+ if (abortEarly && payload.issues.length !== seen) {
694
+ if (aborted(payload, seen)) break;
695
+ seen = payload.issues.length;
696
+ }
697
+ if (key === "__proto__") continue;
698
+ const el = shape[key];
699
+ const optin = el._zod.optin;
700
+ const optout = el._zod.optout;
701
+ const r = el._zod.run({
702
+ value: input[key],
703
+ issues: []
704
+ }, ctx);
705
+ if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
706
+ else handlePropertyResult(r, payload, key, input, optin, optout);
707
+ }
708
+ if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
709
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, abortEarly === true);
710
+ };
711
+ });
712
+ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) => {
713
+ $ZodObject.init(inst, def);
714
+ const superParse = inst._zod.parse;
715
+ const _normalized = cached(() => normalizeDef(def));
716
+ const memo = globalConfig.memoizer;
717
+ const generateFastpass = (shape) => {
718
+ const normalized = _normalized.value;
719
+ const syms = normalized.symbolKeys;
720
+ const doc = new Doc(["payload", "ctx"], {
721
+ shape,
722
+ inst,
723
+ memo,
724
+ syms
725
+ });
726
+ const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
727
+ const prefixStr = (id, k) => `
728
+ let ${id}_ab = false;
729
+ for (let i = 0; i < ${id}.issues.length; i++) {
730
+ const iss = ${id}.issues[i];
731
+ iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
732
+ payload.issues.push(iss);
733
+ if (iss.continue !== true) ${id}_ab = true;
734
+ }
735
+ if (${id}_ab && ctx && ctx.abortEarly) {
736
+ payload.value = newResult;
737
+ return payload;
738
+ }`;
739
+ doc.write(`const input = payload.value;`);
740
+ const ids = Object.create(null);
741
+ let counter = 0;
742
+ for (const key of normalized.allKeys) ids[key] = `key_${counter++}`;
743
+ doc.write(memo ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
744
+ for (const key of normalized.allKeys) {
745
+ if (key === "__proto__") continue;
746
+ const id = ids[key];
747
+ const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : esc(key);
748
+ const isPresent = `${k} in input`;
749
+ const schema = shape[key];
750
+ const optin = schema?._zod?.optin;
751
+ const isOptionalIn = optin !== void 0;
752
+ const isOptionalOut = schema?._zod?.optout === "optional";
753
+ doc.write(`const ${id} = ${parseStr(k)};`);
754
+ if (isOptionalIn && isOptionalOut) {
755
+ const assign = optin === "optional" ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
756
+ doc.write(`
757
+ const ${id}_present = ${isPresent};
758
+ if (!${id}.issues.length || ${id}_present) {
759
+ if (${id}.issues.length) {${prefixStr(id, k)}
760
+ }
761
+
762
+ if (${assign}) {
763
+ newResult[${k}] = ${id}.value;
764
+ }
765
+ }
766
+
767
+ `);
768
+ } else if (!isOptionalIn) doc.write(`
769
+ const ${id}_present = ${isPresent};
770
+ if (${id}.issues.length) {${prefixStr(id, k)}
771
+ }
772
+ if (!${id}_present && !${id}.issues.length) {
773
+ payload.issues.push({
774
+ code: "invalid_type",
775
+ expected: "nonoptional",
776
+ input: undefined,
777
+ path: [${k}]
778
+ });
779
+ if (ctx && ctx.abortEarly) {
780
+ payload.value = newResult;
781
+ return payload;
782
+ }
783
+ }
784
+
785
+ if (${id}_present) {
786
+ newResult[${k}] = ${id}.value;
787
+ }
788
+
789
+ `);
790
+ else {
791
+ doc.write(`
792
+ if (${id}.issues.length) {${prefixStr(id, k)}
793
+ }
794
+ `);
795
+ if (optin === "defaulted") doc.write(`newResult[${k}] = ${id}.value;`);
796
+ else doc.write(`
797
+ if (${id}.value !== undefined || ${isPresent}) {
798
+ newResult[${k}] = ${id}.value;
799
+ }
800
+ `);
801
+ }
802
+ }
803
+ doc.write(`payload.value = newResult;`);
804
+ doc.write(`return payload;`);
805
+ return doc.compile();
806
+ };
807
+ let fastpass;
808
+ const isObject$2 = isObject;
809
+ const jit = !globalConfig.jitless;
810
+ const fastEnabled = jit && allowsEval.value;
811
+ const catchall = def.catchall;
812
+ let value;
813
+ inst._zod.parse = (payload, ctx) => {
814
+ value ?? (value = _normalized.value);
815
+ const input = payload.value;
816
+ if (!isObject$2(input)) {
817
+ payload.issues.push({
818
+ expected: "object",
819
+ code: "invalid_type",
820
+ input,
821
+ inst
822
+ });
823
+ return payload;
824
+ }
825
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
826
+ if (!fastpass) fastpass = generateFastpass(def.shape);
827
+ payload = fastpass(payload, ctx);
828
+ if (!catchall) return payload;
829
+ return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
830
+ }
831
+ return superParse(payload, ctx);
832
+ };
833
+ });
834
+ function handleUnionResults(results, final, inst, ctx) {
835
+ for (const result of results) if (result.issues.length === 0) {
836
+ final.value = result.value;
837
+ return final;
838
+ }
839
+ const nonaborted = results.filter((r) => !aborted(r));
840
+ if (nonaborted.length === 1) {
841
+ final.value = nonaborted[0].value;
842
+ return nonaborted[0];
843
+ }
844
+ final.issues.push({
845
+ code: "invalid_union",
846
+ input: final.value,
847
+ inst,
848
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
849
+ });
850
+ return final;
851
+ }
852
+ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
853
+ $ZodType.init(inst, def);
854
+ defineLazyInternal(inst, "optin", (zod) => zod.def.options.some((o) => o._zod.optin === "defaulted") ? "defaulted" : zod.def.options.some((o) => o._zod.optin !== void 0) ? "optional" : void 0);
855
+ defineLazyInternal(inst, "optout", (zod) => zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
856
+ defineLazyInternal(inst, "values", (zod) => {
857
+ if (zod.def.options.every((o) => o._zod.values)) return new Set(zod.def.options.flatMap((option) => Array.from(option._zod.values)));
858
+ });
859
+ defineLazyInternal(inst, "pattern", (zod) => {
860
+ if (zod.def.options.every((o) => o._zod.pattern)) {
861
+ const patterns = zod.def.options.map((o) => o._zod.pattern);
862
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
863
+ }
864
+ });
865
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
866
+ inst._zod.parse = (payload, ctx) => {
867
+ if (first) return first(payload, ctx);
868
+ let async = false;
869
+ const results = [];
870
+ for (const option of def.options) {
871
+ const result = option._zod.run({
872
+ value: payload.value,
873
+ issues: []
874
+ }, ctx);
875
+ if (result instanceof Promise) {
876
+ results.push(result);
877
+ async = true;
878
+ } else {
879
+ if (result.issues.length === 0) return result;
880
+ results.push(result);
881
+ }
882
+ }
883
+ if (!async) return handleUnionResults(results, payload, inst, ctx);
884
+ return Promise.all(results).then((results) => {
885
+ return handleUnionResults(results, payload, inst, ctx);
886
+ });
887
+ };
888
+ });
889
+ const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
890
+ $ZodType.init(inst, def);
891
+ inst._zod.parse = (payload, ctx) => {
892
+ const input = payload.value;
893
+ const left = def.left._zod.run({
894
+ value: input,
895
+ issues: []
896
+ }, ctx);
897
+ const right = def.right._zod.run({
898
+ value: input,
899
+ issues: []
900
+ }, ctx);
901
+ if (left instanceof Promise || right instanceof Promise) return Promise.all([left, right]).then(([left, right]) => {
902
+ return handleIntersectionResults(payload, left, right);
903
+ });
904
+ return handleIntersectionResults(payload, left, right);
905
+ };
906
+ });
907
+ function mergeValues(a, b) {
908
+ if (a === b) return {
909
+ valid: true,
910
+ data: a
911
+ };
912
+ if (a instanceof Date && b instanceof Date && +a === +b) return {
913
+ valid: true,
914
+ data: a
915
+ };
916
+ if (isPlainObject(a) && isPlainObject(b)) {
917
+ const bKeys = Object.keys(b);
918
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
919
+ const newObj = {
920
+ ...a,
921
+ ...b
922
+ };
923
+ if (Object.prototype.hasOwnProperty.call(newObj, "__proto__")) delete newObj.__proto__;
924
+ for (const key of sharedKeys) {
925
+ if (key === "__proto__") continue;
926
+ const sharedValue = mergeValues(a[key], b[key]);
927
+ if (!sharedValue.valid) return {
928
+ valid: false,
929
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
930
+ };
931
+ newObj[key] = sharedValue.data;
932
+ }
933
+ return {
934
+ valid: true,
935
+ data: newObj
936
+ };
937
+ }
938
+ if (Array.isArray(a) && Array.isArray(b)) {
939
+ if (a.length !== b.length) return {
940
+ valid: false,
941
+ mergeErrorPath: []
942
+ };
943
+ const newArray = [];
944
+ for (let index = 0; index < a.length; index++) {
945
+ const itemA = a[index];
946
+ const itemB = b[index];
947
+ const sharedValue = mergeValues(itemA, itemB);
948
+ if (!sharedValue.valid) return {
949
+ valid: false,
950
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
951
+ };
952
+ newArray.push(sharedValue.data);
953
+ }
954
+ return {
955
+ valid: true,
956
+ data: newArray
957
+ };
958
+ }
959
+ return {
960
+ valid: false,
961
+ mergeErrorPath: []
962
+ };
963
+ }
964
+ function handleIntersectionResults(result, left, right) {
965
+ const unrecKeys = /* @__PURE__ */ new Map();
966
+ let unrecIssue;
967
+ const keyIssues = /* @__PURE__ */ new Map();
968
+ const collect = (iss, side) => {
969
+ let keys;
970
+ if (iss.code === "unrecognized_keys" && !iss.path?.length) {
971
+ unrecIssue ?? (unrecIssue = iss);
972
+ keys = iss.keys;
973
+ } else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
974
+ const k = String(iss.path[0]);
975
+ if (!keyIssues.has(k)) keyIssues.set(k, iss);
976
+ keys = [k];
977
+ } else return false;
978
+ for (const k of keys) {
979
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
980
+ unrecKeys.get(k)[side] = true;
981
+ }
982
+ return true;
983
+ };
984
+ for (const iss of left.issues) if (!collect(iss, "l")) result.issues.push(iss);
985
+ for (const iss of right.issues) if (!collect(iss, "r")) result.issues.push(iss);
986
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
987
+ if (bothKeys.length) {
988
+ const aggregated = unrecIssue ? bothKeys.filter((k) => unrecIssue.keys.includes(k)) : [];
989
+ if (aggregated.length) result.issues.push({
990
+ ...unrecIssue,
991
+ keys: aggregated
992
+ });
993
+ for (const k of bothKeys) if (!aggregated.includes(k) && keyIssues.has(k)) result.issues.push(keyIssues.get(k));
994
+ }
995
+ const merged = mergeValues(left.value, right.value);
996
+ if (!merged.valid) {
997
+ if (aborted(result)) return result;
998
+ throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
999
+ }
1000
+ result.value = merged.data;
1001
+ return result;
1002
+ }
1003
+ const $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
1004
+ $ZodType.init(inst, def);
1005
+ const memo = globalConfig.memoizer;
1006
+ memo?.attach(inst);
1007
+ inst._zod.parse = (payload, ctx) => {
1008
+ const input = payload.value;
1009
+ if (!isPlainObject(input)) {
1010
+ payload.issues.push({
1011
+ expected: "record",
1012
+ code: "invalid_type",
1013
+ input,
1014
+ inst
1015
+ });
1016
+ return payload;
1017
+ }
1018
+ const proms = [];
1019
+ const values = def.keyType._zod.values;
1020
+ if (values && !def.partial) {
1021
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1022
+ const recordKeys = /* @__PURE__ */ new Set();
1023
+ for (const key of values) if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1024
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
1025
+ if (key === "__proto__") continue;
1026
+ const keyResult = def.keyType._zod.run({
1027
+ value: key,
1028
+ issues: []
1029
+ }, ctx);
1030
+ if (keyResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
1031
+ if (keyResult.issues.length) {
1032
+ payload.issues.push({
1033
+ code: "invalid_key",
1034
+ origin: "record",
1035
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
1036
+ input: key,
1037
+ path: [key],
1038
+ inst
1039
+ });
1040
+ continue;
1041
+ }
1042
+ const outKey = keyResult.value;
1043
+ if (outKey === "__proto__") continue;
1044
+ const result = def.valueType._zod.run({
1045
+ value: input[key],
1046
+ issues: []
1047
+ }, ctx);
1048
+ if (result instanceof Promise) proms.push(result.then((result) => {
1049
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
1050
+ payload.value[outKey] = result.value;
1051
+ }));
1052
+ else {
1053
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
1054
+ payload.value[outKey] = result.value;
1055
+ }
1056
+ }
1057
+ let unrecognized;
1058
+ for (const key in input) if (!recordKeys.has(key)) {
1059
+ if (def.mode === "loose") {
1060
+ if (key === "__proto__") continue;
1061
+ payload.value[key] = input[key];
1062
+ } else {
1063
+ unrecognized = unrecognized ?? [];
1064
+ unrecognized.push(key);
1065
+ }
1066
+ }
1067
+ if (unrecognized && unrecognized.length > 0) payload.issues.push({
1068
+ code: "unrecognized_keys",
1069
+ input,
1070
+ inst,
1071
+ keys: unrecognized,
1072
+ continue: true
1073
+ });
1074
+ } else {
1075
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1076
+ let unrecognized;
1077
+ for (const key of Reflect.ownKeys(input)) {
1078
+ if (key === "__proto__") continue;
1079
+ if (!Object.prototype.propertyIsEnumerable.call(input, key)) continue;
1080
+ let keyResult = def.keyType._zod.run({
1081
+ value: key,
1082
+ issues: []
1083
+ }, ctx);
1084
+ if (keyResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
1085
+ if (typeof key === "string" && number.test(key) && keyResult.issues.length) {
1086
+ const retryResult = def.keyType._zod.run({
1087
+ value: Number(key),
1088
+ issues: []
1089
+ }, ctx);
1090
+ if (retryResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
1091
+ if (retryResult.issues.length === 0) keyResult = retryResult;
1092
+ }
1093
+ if (keyResult.issues.length) {
1094
+ if (def.mode === "loose") payload.value[key] = input[key];
1095
+ else if (values) {
1096
+ unrecognized = unrecognized ?? [];
1097
+ unrecognized.push(key);
1098
+ } else payload.issues.push({
1099
+ code: "invalid_key",
1100
+ origin: "record",
1101
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
1102
+ input: key,
1103
+ path: [key],
1104
+ inst
1105
+ });
1106
+ continue;
1107
+ }
1108
+ const outKey = keyResult.value;
1109
+ if (outKey === "__proto__") continue;
1110
+ const result = def.valueType._zod.run({
1111
+ value: input[key],
1112
+ issues: []
1113
+ }, ctx);
1114
+ if (result instanceof Promise) proms.push(result.then((result) => {
1115
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
1116
+ payload.value[outKey] = result.value;
1117
+ }));
1118
+ else {
1119
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
1120
+ payload.value[outKey] = result.value;
1121
+ }
1122
+ }
1123
+ if (unrecognized && unrecognized.length > 0) payload.issues.push({
1124
+ code: "unrecognized_keys",
1125
+ input,
1126
+ inst,
1127
+ keys: unrecognized,
1128
+ continue: true
1129
+ });
1130
+ }
1131
+ if (proms.length) return Promise.all(proms).then(() => payload);
1132
+ return payload;
1133
+ };
1134
+ });
1135
+ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
1136
+ $ZodType.init(inst, def);
1137
+ const values = getEnumValues(def.entries);
1138
+ const valuesSet = new Set(values);
1139
+ inst._zod.values = valuesSet;
1140
+ defineLazyInternal(inst, "pattern", (zod) => {
1141
+ const patternValues = getEnumValues(zod.def.entries).filter((k) => propertyKeyTypes.has(typeof k));
1142
+ return new RegExp(patternValues.length ? `^(${patternValues.map((o) => escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
1143
+ });
1144
+ inst._zod.parse = (payload, _ctx) => {
1145
+ const input = payload.value;
1146
+ if (valuesSet.has(input)) return payload;
1147
+ payload.issues.push({
1148
+ code: "invalid_value",
1149
+ values,
1150
+ input,
1151
+ inst
1152
+ });
1153
+ return payload;
1154
+ };
1155
+ });
1156
+ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
1157
+ $ZodType.init(inst, def);
1158
+ inst._zod.optin = "optional";
1159
+ globalConfig.memoizer?.guard(inst);
1160
+ inst._zod.parse = (payload, ctx) => {
1161
+ if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
1162
+ const _out = def.transform(payload.value, payload);
1163
+ if (ctx.async) return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
1164
+ payload.value = output;
1165
+ return payload;
1166
+ });
1167
+ if (_out instanceof Promise) throw new $ZodAsyncError();
1168
+ payload.value = _out;
1169
+ return payload;
1170
+ };
1171
+ });
1172
+ function handleOptionalResult(payload, result) {
1173
+ payload.value = result.issues.length ? void 0 : result.value;
1174
+ return payload;
1175
+ }
1176
+ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
1177
+ $ZodType.init(inst, def);
1178
+ defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
1179
+ inst._zod.optout = "optional";
1180
+ defineLazyInternal(inst, "values", (zod) => {
1181
+ const values = zod.def.innerType._zod.values;
1182
+ return values ? /* @__PURE__ */ new Set([...values, void 0]) : void 0;
1183
+ });
1184
+ defineLazyInternal(inst, "pattern", (zod) => {
1185
+ const pattern = zod.def.innerType._zod.pattern;
1186
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
1187
+ });
1188
+ inst._zod.parse = (payload, ctx) => {
1189
+ if (payload.value === void 0) {
1190
+ if (def.innerType._zod.optin !== "defaulted") return payload;
1191
+ const result = def.innerType._zod.run({
1192
+ value: payload.value,
1193
+ issues: []
1194
+ }, ctx);
1195
+ if (result instanceof Promise) return result.then((result) => handleOptionalResult(payload, result));
1196
+ return handleOptionalResult(payload, result);
1197
+ }
1198
+ return def.innerType._zod.run(payload, ctx);
1199
+ };
1200
+ });
1201
+ const $ZodExactOptional = /*@__PURE__*/ $constructor("$ZodExactOptional", (inst, def) => {
1202
+ $ZodOptional.init(inst, def);
1203
+ defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1204
+ defineLazyInternal(inst, "pattern", (zod) => zod.def.innerType._zod.pattern);
1205
+ inst._zod.parse = (payload, ctx) => {
1206
+ return def.innerType._zod.run(payload, ctx);
1207
+ };
1208
+ });
1209
+ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
1210
+ $ZodType.init(inst, def);
1211
+ defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
1212
+ defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
1213
+ defineLazyInternal(inst, "pattern", (zod) => {
1214
+ const pattern = zod.def.innerType._zod.pattern;
1215
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
1216
+ });
1217
+ defineLazyInternal(inst, "values", (zod) => {
1218
+ return zod.def.innerType._zod.values ? /* @__PURE__ */ new Set([...zod.def.innerType._zod.values, null]) : void 0;
1219
+ });
1220
+ inst._zod.parse = (payload, ctx) => {
1221
+ if (payload.value === null) return payload;
1222
+ return def.innerType._zod.run(payload, ctx);
1223
+ };
1224
+ });
1225
+ const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
1226
+ $ZodType.init(inst, def);
1227
+ inst._zod.optin = "defaulted";
1228
+ defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1229
+ inst._zod.parse = (payload, ctx) => {
1230
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1231
+ if (payload.value === void 0) {
1232
+ payload.value = def.defaultValue;
1233
+ /**
1234
+ * $ZodDefault returns the default value immediately in forward direction.
1235
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
1236
+ return payload;
1237
+ }
1238
+ const result = def.innerType._zod.run(payload, ctx);
1239
+ if (result instanceof Promise) return result.then((result) => handleDefaultResult(result, def));
1240
+ return handleDefaultResult(result, def);
1241
+ };
1242
+ });
1243
+ function handleDefaultResult(payload, def) {
1244
+ if (payload.value === void 0) payload.value = def.defaultValue;
1245
+ return payload;
1246
+ }
1247
+ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
1248
+ $ZodType.init(inst, def);
1249
+ inst._zod.optin = "defaulted";
1250
+ defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1251
+ inst._zod.parse = (payload, ctx) => {
1252
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1253
+ if (payload.value === void 0) payload.value = def.defaultValue;
1254
+ return def.innerType._zod.run(payload, ctx);
1255
+ };
1256
+ });
1257
+ const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
1258
+ $ZodType.init(inst, def);
1259
+ defineLazyInternal(inst, "values", (zod) => {
1260
+ const v = zod.def.innerType._zod.values;
1261
+ return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
1262
+ });
1263
+ inst._zod.parse = (payload, ctx) => {
1264
+ const result = def.innerType._zod.run(payload, ctx);
1265
+ if (result instanceof Promise) return result.then((result) => handleNonOptionalResult(result, inst));
1266
+ return handleNonOptionalResult(result, inst);
1267
+ };
1268
+ });
1269
+ function handleNonOptionalResult(payload, inst) {
1270
+ if (!payload.issues.length && payload.value === void 0) payload.issues.push({
1271
+ code: "invalid_type",
1272
+ expected: "nonoptional",
1273
+ input: payload.value,
1274
+ inst
1275
+ });
1276
+ return payload;
1277
+ }
1278
+ function handleCatchResult(payload, result, def, ctx) {
1279
+ if (!result.issues.length) {
1280
+ payload.value = result.value;
1281
+ if (result.memo) payload.memo = true;
1282
+ return payload;
1283
+ }
1284
+ payload.value = def.catchValue({
1285
+ ...result,
1286
+ value: payload.value,
1287
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1288
+ input: payload.value
1289
+ });
1290
+ return payload;
1291
+ }
1292
+ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
1293
+ $ZodType.init(inst, def);
1294
+ defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
1295
+ defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
1296
+ defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1297
+ inst._zod.parse = (payload, ctx) => {
1298
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1299
+ const result = def.innerType._zod.run({
1300
+ value: payload.value,
1301
+ issues: []
1302
+ }, ctx);
1303
+ if (result instanceof Promise) return result.then((result) => handleCatchResult(payload, result, def, ctx));
1304
+ return handleCatchResult(payload, result, def, ctx);
1305
+ };
1306
+ });
1307
+ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
1308
+ $ZodType.init(inst, def);
1309
+ defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
1310
+ defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
1311
+ defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
1312
+ defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
1313
+ inst._zod.parse = (payload, ctx) => {
1314
+ if (ctx.direction === "backward") {
1315
+ const right = def.out._zod.run(payload, ctx);
1316
+ if (right instanceof Promise) return right.then((right) => handlePipeResult(right, def.in, ctx));
1317
+ return handlePipeResult(right, def.in, ctx);
1318
+ }
1319
+ const left = def.in._zod.run(payload, ctx);
1320
+ if (left instanceof Promise) return left.then((left) => handlePipeResult(left, def.out, ctx));
1321
+ return handlePipeResult(left, def.out, ctx);
1322
+ };
1323
+ });
1324
+ function handlePipeResult(left, next, ctx) {
1325
+ if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
1326
+ left.aborted = true;
1327
+ return left;
1328
+ }
1329
+ return next._zod.run({
1330
+ value: left.value,
1331
+ issues: left.issues
1332
+ }, ctx);
1333
+ }
1334
+ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
1335
+ $ZodType.init(inst, def);
1336
+ defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
1337
+ defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1338
+ defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
1339
+ defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
1340
+ inst._zod.parse = (payload, ctx) => {
1341
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1342
+ const result = def.innerType._zod.run(payload, ctx);
1343
+ if (result instanceof Promise) return result.then(handleReadonlyResult);
1344
+ return handleReadonlyResult(result);
1345
+ };
1346
+ });
1347
+ function handleReadonlyResult(payload) {
1348
+ if (!payload.memo) payload.value = Object.freeze(payload.value);
1349
+ return payload;
1350
+ }
1351
+ const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
1352
+ $ZodCheck.init(inst, def);
1353
+ $ZodType.init(inst, def);
1354
+ inst._zod.parse = (payload, _) => {
1355
+ return payload;
1356
+ };
1357
+ inst._zod.check = (payload) => {
1358
+ const input = payload.value;
1359
+ const r = def.fn(input);
1360
+ if (r instanceof Promise) return r.then((r) => handleRefineResult(r, payload, input, inst));
1361
+ handleRefineResult(r, payload, input, inst);
1362
+ };
1363
+ });
1364
+ function handleRefineResult(result, payload, input, inst) {
1365
+ if (!result) {
1366
+ const _iss = {
1367
+ code: "custom",
1368
+ input,
1369
+ inst,
1370
+ path: [...inst._zod.def.path ?? []],
1371
+ continue: !inst._zod.def.abort
1372
+ };
1373
+ if (inst._zod.def.params) _iss.params = inst._zod.def.params;
1374
+ payload.issues.push(issue(_iss));
1375
+ }
1376
+ }
1377
+ //#endregion
1378
+ export { $ZodArray, $ZodBase64, $ZodBase64URL, $ZodBoolean, $ZodCIDRv4, $ZodCIDRv6, $ZodCUID, $ZodCUID2, $ZodCatch, $ZodCustom, $ZodDefault, $ZodE164, $ZodEmail, $ZodEmoji, $ZodEnum, $ZodExactOptional, $ZodGUID, $ZodIPv4, $ZodIPv6, $ZodISODate, $ZodISODateTime, $ZodISODuration, $ZodISOTime, $ZodIntersection, $ZodJWT, $ZodKSUID, $ZodNanoID, $ZodNever, $ZodNonOptional, $ZodNullable, $ZodNumber, $ZodNumberFormat, $ZodObject, $ZodObjectJIT, $ZodOptional, $ZodPipe, $ZodPrefault, $ZodReadonly, $ZodRecord, $ZodString, $ZodStringFormat, $ZodTransform, $ZodType, $ZodULID, $ZodURL, $ZodUUID, $ZodUnion, $ZodUnknown, $ZodXID, base64Charset, base64urlCharset, canParseURL, isValidBase64, isValidBase64URL, isValidCIDRv6, isValidIPv6, isValidJWT, mergeValues, parseURLObject, standardProps, stripTabAndNewline, urlHostnameOk, urlProtocolOk, validateURL };