@originator-profile/sign 0.5.3 → 0.6.0-beta.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.
package/dist/index.js ADDED
@@ -0,0 +1,2429 @@
1
+ import { signJwtVc } from '@originator-profile/securing-mechanism';
2
+ import { UnsignedWebsiteProfile, UnsignedWebsiteProfileSet } from '@originator-profile/model';
3
+
4
+ const supportedHashAlgorithms = {
5
+ /** SHA-256 hash algorithm */
6
+ sha256: "SHA-256",
7
+ /** SHA-384 hash algorithm */
8
+ sha384: "SHA-384",
9
+ /** SHA-512 hash algorithm */
10
+ sha512: "SHA-512"
11
+ };
12
+ const IntegrityMetadataRegex = /^(?<alg>sha256|sha384|sha512)-(?<val>(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?)(?:[?](?<opt>[\x21-\x7e]*))?$/;
13
+ class IntegrityMetadata {
14
+ /** Hash algorithm */
15
+ alg;
16
+ /** The base64-encoded hash value of the resource */
17
+ val;
18
+ /** Optional additional attributes */
19
+ opt;
20
+ /**
21
+ * Creates an instance of `IntegrityMetadata` from a given object or string.
22
+ * @param integrity The integrity metadata input, which can be a string or object.
23
+ * @example
24
+ * ```js
25
+ * new IntegrityMetadata("sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=")
26
+ * ```
27
+ *
28
+ * or
29
+ *
30
+ * ```js
31
+ * new IntegrityMetadata({
32
+ * alg: "sha256",
33
+ * val: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=",
34
+ * })
35
+ * ```
36
+ */
37
+ constructor(integrity) {
38
+ const integrityString = typeof integrity === "object" && integrity !== null ? IntegrityMetadata.stringify(integrity) : String(integrity ?? "").trim();
39
+ const {
40
+ alg = "",
41
+ val = "",
42
+ opt
43
+ } = IntegrityMetadataRegex.exec(integrityString)?.groups ?? {};
44
+ Object.assign(this, {
45
+ alg,
46
+ val,
47
+ opt: opt?.split("?") ?? []
48
+ });
49
+ }
50
+ /**
51
+ * Compares the current integrity metadata with another object or string.
52
+ * @param integrity The integrity metadata to compare with.
53
+ * @returns `true` if the integrity metadata matches, `false` otherwise.
54
+ * @example
55
+ * ```js
56
+ * integrityMetadata.match("sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=")
57
+ * ```
58
+ *
59
+ * or
60
+ *
61
+ * ```js
62
+ * integrityMetadata.match({
63
+ * alg: "sha256",
64
+ * val: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=",
65
+ * })
66
+ * ```
67
+ */
68
+ match(integrity) {
69
+ const { alg, val } = new IntegrityMetadata(integrity);
70
+ if (!alg) return false;
71
+ if (!val) return false;
72
+ if (!(alg in supportedHashAlgorithms)) return false;
73
+ return alg === this.alg && val === this.val;
74
+ }
75
+ /**
76
+ * Converts the integrity metadata into a string representation.
77
+ * @returns The string representation of the integrity metadata.
78
+ */
79
+ toString() {
80
+ return IntegrityMetadata.stringify(this);
81
+ }
82
+ /**
83
+ * Converts the integrity metadata into a JSON string.
84
+ * @returns The JSON string representation of the integrity metadata.
85
+ */
86
+ toJSON() {
87
+ return this.toString();
88
+ }
89
+ /**
90
+ * Static method to stringify an integrity metadata object.
91
+ * @param integrity The integrity metadata object to stringify.
92
+ * @returns The stringified integrity metadata.
93
+ * @example
94
+ * ```js
95
+ * IntegrityMetadata.stringify({
96
+ * alg: "sha256",
97
+ * val: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=",
98
+ * }) // "sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM="
99
+ * ```
100
+ */
101
+ static stringify({ alg, val, opt = [] }) {
102
+ if (!alg) return "";
103
+ if (!val) return "";
104
+ if (!(alg in supportedHashAlgorithms)) return "";
105
+ return `${alg}-${[val, ...opt].join("?")}`;
106
+ }
107
+ }
108
+ async function createIntegrityMetadata(hashAlgorithm, data, opt = []) {
109
+ const alg = hashAlgorithm.toLowerCase();
110
+ if (!(alg in supportedHashAlgorithms)) {
111
+ return new IntegrityMetadata("");
112
+ }
113
+ const hashAlgorithmIdentifier = supportedHashAlgorithms[alg];
114
+ const arrayBuffer = await crypto.subtle.digest(hashAlgorithmIdentifier, data);
115
+ const val = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
116
+ const integrity = IntegrityMetadata.stringify({ alg, val, opt });
117
+ return new IntegrityMetadata(integrity);
118
+ }
119
+
120
+ async function createDigestSri(alg, resource, fetcher = fetch) {
121
+ if (!(alg in supportedHashAlgorithms)) {
122
+ return { id: resource.id };
123
+ }
124
+ const meta = await Promise.all(
125
+ [resource.content ?? resource.id].flat().map(async (content) => {
126
+ const res = await fetcher(content);
127
+ const data = await res.arrayBuffer();
128
+ return await createIntegrityMetadata(alg, data);
129
+ })
130
+ );
131
+ return {
132
+ id: resource.id,
133
+ digestSRI: meta.join(" ")
134
+ };
135
+ }
136
+
137
+ class FetchFailed extends Error {
138
+ static get code() {
139
+ return "ERR_FETCH_FAILED";
140
+ }
141
+ code = FetchFailed.code;
142
+ ok = false;
143
+ error;
144
+ constructor(message, error) {
145
+ super(message);
146
+ this.error = error;
147
+ }
148
+ }
149
+
150
+ async function fetchAndSetDigestSri(alg, content) {
151
+ if (!content) return content;
152
+ if (typeof content.digestSRI !== "string") {
153
+ Object.assign(
154
+ content,
155
+ await createDigestSri(alg, content)
156
+ );
157
+ }
158
+ delete content.content;
159
+ return content;
160
+ }
161
+
162
+ const fetchHtmlContent = async (elements) => {
163
+ const text = elements.map((element) => element.outerHTML).join("");
164
+ return [new Response(text)];
165
+ };
166
+ const fetchTextContent = async (elements) => {
167
+ const text = elements.map((element) => element.textContent ?? "").join("");
168
+ return [new Response(text)];
169
+ };
170
+ const fetchVisibleTextContent = async (elements) => {
171
+ const text = elements.map((element) => element.innerText).join("");
172
+ return [new Response(text)];
173
+ };
174
+ const fetchExternalResource = async (elements, fetcher = fetch) => {
175
+ return await Promise.all(
176
+ elements.map(async (element) => {
177
+ const el = element;
178
+ const src = el.currentSrc || el.src;
179
+ if (!src) {
180
+ throw new Error("Element has no src or currentSrc property");
181
+ }
182
+ try {
183
+ return await fetcher(src);
184
+ } catch (e) {
185
+ if (e instanceof Error || e instanceof window.Error) {
186
+ throw new FetchFailed(`Failed to fetch`, e);
187
+ }
188
+ throw e;
189
+ }
190
+ })
191
+ );
192
+ };
193
+ const selectByCss = (params) => {
194
+ return Array.from(
195
+ params.document.querySelectorAll(params.cssSelector)
196
+ );
197
+ };
198
+ const selectByIntegrity = (params) => {
199
+ return selectByCss({
200
+ ...params,
201
+ cssSelector: `[integrity=${JSON.stringify(String(params.integrity))}]`
202
+ });
203
+ };
204
+ async function createIntegrity(alg, { content = "", ...target }, doc) {
205
+ if (![
206
+ "TextTargetIntegrity",
207
+ "VisibleTextTargetIntegrity",
208
+ "HtmlTargetIntegrity",
209
+ "ExternalResourceTargetIntegrity"
210
+ ].includes(target.type)) {
211
+ return null;
212
+ }
213
+ if (!(alg in supportedHashAlgorithms)) {
214
+ return null;
215
+ }
216
+ if (target.type === "ExternalResourceTargetIntegrity") {
217
+ const meta2 = await Promise.all(
218
+ [content].flat().map(async (content2) => {
219
+ const res2 = URL.canParse(content2) ? await fetch(content2) : new Response(content2);
220
+ const data2 = await res2.arrayBuffer();
221
+ return await createIntegrityMetadata(alg, data2);
222
+ })
223
+ );
224
+ return {
225
+ ...target,
226
+ integrity: meta2.join(" ")
227
+ };
228
+ }
229
+ doc ??= document;
230
+ const { contentFetcher, elementSelector } = {
231
+ HtmlTargetIntegrity: {
232
+ contentFetcher: fetchHtmlContent,
233
+ elementSelector: selectByCss
234
+ },
235
+ TextTargetIntegrity: {
236
+ contentFetcher: fetchTextContent,
237
+ elementSelector: selectByCss
238
+ },
239
+ VisibleTextTargetIntegrity: {
240
+ contentFetcher: fetchVisibleTextContent,
241
+ elementSelector: selectByCss
242
+ }
243
+ }[target.type];
244
+ const elements = elementSelector({ ...target, document: doc });
245
+ if (elements.length === 0) return null;
246
+ const [res] = await contentFetcher(elements);
247
+ if (!res) return null;
248
+ const data = await res.arrayBuffer();
249
+ const meta = await createIntegrityMetadata(alg, data);
250
+ return {
251
+ ...target,
252
+ integrity: meta.toString()
253
+ };
254
+ }
255
+
256
+ class IntegrityCalculationError extends Error {
257
+ }
258
+ async function fetchAndSetTargetIntegrity(alg, obj, documentProvider = async () => document) {
259
+ const target = await Promise.all(
260
+ obj.target.map(async (raw, i) => {
261
+ if (raw.integrity) {
262
+ const { content: _, ...target3 } = raw;
263
+ return target3;
264
+ }
265
+ const doc = raw.type === "ExternalResourceTargetIntegrity" ? void 0 : await documentProvider(raw);
266
+ const target2 = await createIntegrity(alg, raw, doc);
267
+ if (!target2) {
268
+ throw new IntegrityCalculationError(
269
+ `Failed to create integrity for element target[${i}].`
270
+ );
271
+ }
272
+ return target2;
273
+ })
274
+ );
275
+ return Object.assign(obj, { target });
276
+ }
277
+
278
+ async function signCa(uca, privateKey, {
279
+ alg = "ES256",
280
+ issuedAt = /* @__PURE__ */ new Date(),
281
+ expiredAt,
282
+ integrityAlg = "sha256",
283
+ documentProvider = async () => document
284
+ }) {
285
+ await fetchAndSetDigestSri(integrityAlg, uca.credentialSubject.image);
286
+ await fetchAndSetTargetIntegrity(integrityAlg, uca, documentProvider);
287
+ return await signJwtVc(uca, privateKey, { alg, issuedAt, expiredAt });
288
+ }
289
+
290
+ async function signCp(cp, privateKey, options) {
291
+ return signJwtVc(cp, privateKey, options);
292
+ }
293
+
294
+ var _a$1;
295
+ // @__NO_SIDE_EFFECTS__
296
+ function $constructor(name, initializer, params) {
297
+ function init(inst, def) {
298
+ if (!inst._zod) {
299
+ Object.defineProperty(inst, "_zod", {
300
+ value: {
301
+ def,
302
+ constr: _,
303
+ traits: /* @__PURE__ */ new Set()
304
+ },
305
+ enumerable: false
306
+ });
307
+ }
308
+ if (inst._zod.traits.has(name)) {
309
+ return;
310
+ }
311
+ inst._zod.traits.add(name);
312
+ initializer(inst, def);
313
+ const proto = _.prototype;
314
+ const keys = Object.keys(proto);
315
+ for (let i = 0; i < keys.length; i++) {
316
+ const k = keys[i];
317
+ if (!(k in inst)) {
318
+ inst[k] = proto[k].bind(inst);
319
+ }
320
+ }
321
+ }
322
+ const Parent = params?.Parent ?? Object;
323
+ class Definition extends Parent {
324
+ }
325
+ Object.defineProperty(Definition, "name", { value: name });
326
+ function _(def) {
327
+ var _a2;
328
+ const inst = params?.Parent ? new Definition() : this;
329
+ init(inst, def);
330
+ (_a2 = inst._zod).deferred ?? (_a2.deferred = []);
331
+ for (const fn of inst._zod.deferred) {
332
+ fn();
333
+ }
334
+ return inst;
335
+ }
336
+ Object.defineProperty(_, "init", { value: init });
337
+ Object.defineProperty(_, Symbol.hasInstance, {
338
+ value: (inst) => {
339
+ if (params?.Parent && inst instanceof params.Parent)
340
+ return true;
341
+ return inst?._zod?.traits?.has(name);
342
+ }
343
+ });
344
+ Object.defineProperty(_, "name", { value: name });
345
+ return _;
346
+ }
347
+ class $ZodAsyncError extends Error {
348
+ constructor() {
349
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
350
+ }
351
+ }
352
+ class $ZodEncodeError extends Error {
353
+ constructor(name) {
354
+ super(`Encountered unidirectional transform during encode: ${name}`);
355
+ this.name = "ZodEncodeError";
356
+ }
357
+ }
358
+ (_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
359
+ const globalConfig = globalThis.__zod_globalConfig;
360
+ function config(newConfig) {
361
+ return globalConfig;
362
+ }
363
+
364
+ function jsonStringifyReplacer(_, value) {
365
+ if (typeof value === "bigint")
366
+ return value.toString();
367
+ return value;
368
+ }
369
+ function nullish(input) {
370
+ return input === null || input === void 0;
371
+ }
372
+ function cleanRegex(source) {
373
+ const start = source.startsWith("^") ? 1 : 0;
374
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
375
+ return source.slice(start, end);
376
+ }
377
+ const EVALUATING = /* @__PURE__ */ Symbol("evaluating");
378
+ function defineLazy(object, key, getter) {
379
+ let value = void 0;
380
+ Object.defineProperty(object, key, {
381
+ get() {
382
+ if (value === EVALUATING) {
383
+ return void 0;
384
+ }
385
+ if (value === void 0) {
386
+ value = EVALUATING;
387
+ value = getter();
388
+ }
389
+ return value;
390
+ },
391
+ set(v) {
392
+ Object.defineProperty(object, key, {
393
+ value: v
394
+ // configurable: true,
395
+ });
396
+ },
397
+ configurable: true
398
+ });
399
+ }
400
+ function mergeDefs(...defs) {
401
+ const mergedDescriptors = {};
402
+ for (const def of defs) {
403
+ const descriptors = Object.getOwnPropertyDescriptors(def);
404
+ Object.assign(mergedDescriptors, descriptors);
405
+ }
406
+ return Object.defineProperties({}, mergedDescriptors);
407
+ }
408
+ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {
409
+ };
410
+ function isObject(data) {
411
+ return typeof data === "object" && data !== null && !Array.isArray(data);
412
+ }
413
+ function isPlainObject(o) {
414
+ if (isObject(o) === false)
415
+ return false;
416
+ const ctor = o.constructor;
417
+ if (ctor === void 0)
418
+ return true;
419
+ if (typeof ctor !== "function")
420
+ return true;
421
+ const prot = ctor.prototype;
422
+ if (isObject(prot) === false)
423
+ return false;
424
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
425
+ return false;
426
+ }
427
+ return true;
428
+ }
429
+ function shallowClone(o) {
430
+ if (isPlainObject(o))
431
+ return { ...o };
432
+ if (Array.isArray(o))
433
+ return [...o];
434
+ if (o instanceof Map)
435
+ return new Map(o);
436
+ if (o instanceof Set)
437
+ return new Set(o);
438
+ return o;
439
+ }
440
+ function clone(inst, def, params) {
441
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
442
+ if (!def || params?.parent)
443
+ cl._zod.parent = inst;
444
+ return cl;
445
+ }
446
+ function normalizeParams(_params) {
447
+ const params = _params;
448
+ if (!params)
449
+ return {};
450
+ if (typeof params === "string")
451
+ return { error: () => params };
452
+ if (params?.message !== void 0) {
453
+ if (params?.error !== void 0)
454
+ throw new Error("Cannot specify both `message` and `error` params");
455
+ params.error = params.message;
456
+ }
457
+ delete params.message;
458
+ if (typeof params.error === "string")
459
+ return { ...params, error: () => params.error };
460
+ return params;
461
+ }
462
+ function aborted(x, startIndex = 0) {
463
+ if (x.aborted === true)
464
+ return true;
465
+ for (let i = startIndex; i < x.issues.length; i++) {
466
+ if (x.issues[i]?.continue !== true) {
467
+ return true;
468
+ }
469
+ }
470
+ return false;
471
+ }
472
+ function explicitlyAborted(x, startIndex = 0) {
473
+ if (x.aborted === true)
474
+ return true;
475
+ for (let i = startIndex; i < x.issues.length; i++) {
476
+ if (x.issues[i]?.continue === false) {
477
+ return true;
478
+ }
479
+ }
480
+ return false;
481
+ }
482
+ function prefixIssues(path, issues) {
483
+ return issues.map((iss) => {
484
+ var _a;
485
+ (_a = iss).path ?? (_a.path = []);
486
+ iss.path.unshift(path);
487
+ return iss;
488
+ });
489
+ }
490
+ function unwrapMessage(message) {
491
+ return typeof message === "string" ? message : message?.message;
492
+ }
493
+ function finalizeIssue(iss, ctx, config) {
494
+ const message = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
495
+ const { inst: _inst, continue: _continue, input: _input, ...rest } = iss;
496
+ rest.path ?? (rest.path = []);
497
+ rest.message = message;
498
+ if (ctx?.reportInput) {
499
+ rest.input = _input;
500
+ }
501
+ return rest;
502
+ }
503
+ function getLengthableOrigin(input) {
504
+ if (Array.isArray(input))
505
+ return "array";
506
+ if (typeof input === "string")
507
+ return "string";
508
+ return "unknown";
509
+ }
510
+ function issue(...args) {
511
+ const [iss, input, inst] = args;
512
+ if (typeof iss === "string") {
513
+ return {
514
+ message: iss,
515
+ code: "custom",
516
+ input,
517
+ inst
518
+ };
519
+ }
520
+ return { ...iss };
521
+ }
522
+
523
+ const initializer$1 = (inst, def) => {
524
+ inst.name = "$ZodError";
525
+ Object.defineProperty(inst, "_zod", {
526
+ value: inst._zod,
527
+ enumerable: false
528
+ });
529
+ Object.defineProperty(inst, "issues", {
530
+ value: def,
531
+ enumerable: false
532
+ });
533
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
534
+ Object.defineProperty(inst, "toString", {
535
+ value: () => inst.message,
536
+ enumerable: false
537
+ });
538
+ };
539
+ const $ZodError = $constructor("$ZodError", initializer$1);
540
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
541
+ function flattenError(error, mapper = (issue) => issue.message) {
542
+ const fieldErrors = {};
543
+ const formErrors = [];
544
+ for (const sub of error.issues) {
545
+ if (sub.path.length > 0) {
546
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
547
+ fieldErrors[sub.path[0]].push(mapper(sub));
548
+ } else {
549
+ formErrors.push(mapper(sub));
550
+ }
551
+ }
552
+ return { formErrors, fieldErrors };
553
+ }
554
+ function formatError(error, mapper = (issue) => issue.message) {
555
+ const fieldErrors = { _errors: [] };
556
+ const processError = (error2, path = []) => {
557
+ for (const issue of error2.issues) {
558
+ if (issue.code === "invalid_union" && issue.errors.length) {
559
+ issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
560
+ } else if (issue.code === "invalid_key") {
561
+ processError({ issues: issue.issues }, [...path, ...issue.path]);
562
+ } else if (issue.code === "invalid_element") {
563
+ processError({ issues: issue.issues }, [...path, ...issue.path]);
564
+ } else {
565
+ const fullpath = [...path, ...issue.path];
566
+ if (fullpath.length === 0) {
567
+ fieldErrors._errors.push(mapper(issue));
568
+ } else {
569
+ let curr = fieldErrors;
570
+ let i = 0;
571
+ while (i < fullpath.length) {
572
+ const el = fullpath[i];
573
+ const terminal = i === fullpath.length - 1;
574
+ if (!terminal) {
575
+ curr[el] = curr[el] || { _errors: [] };
576
+ } else {
577
+ curr[el] = curr[el] || { _errors: [] };
578
+ curr[el]._errors.push(mapper(issue));
579
+ }
580
+ curr = curr[el];
581
+ i++;
582
+ }
583
+ }
584
+ }
585
+ }
586
+ };
587
+ processError(error);
588
+ return fieldErrors;
589
+ }
590
+
591
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
592
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
593
+ const result = schema._zod.run({ value, issues: [] }, ctx);
594
+ if (result instanceof Promise) {
595
+ throw new $ZodAsyncError();
596
+ }
597
+ if (result.issues.length) {
598
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
599
+ captureStackTrace(e, _params?.callee);
600
+ throw e;
601
+ }
602
+ return result.value;
603
+ };
604
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
605
+ const ctx = _ctx ? { ..._ctx, async: true } : { async: true };
606
+ let result = schema._zod.run({ value, issues: [] }, ctx);
607
+ if (result instanceof Promise)
608
+ result = await result;
609
+ if (result.issues.length) {
610
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
611
+ captureStackTrace(e, params?.callee);
612
+ throw e;
613
+ }
614
+ return result.value;
615
+ };
616
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
617
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
618
+ const result = schema._zod.run({ value, issues: [] }, ctx);
619
+ if (result instanceof Promise) {
620
+ throw new $ZodAsyncError();
621
+ }
622
+ return result.issues.length ? {
623
+ success: false,
624
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
625
+ } : { success: true, data: result.value };
626
+ };
627
+ const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
628
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
629
+ const ctx = _ctx ? { ..._ctx, async: true } : { async: true };
630
+ let result = schema._zod.run({ value, issues: [] }, ctx);
631
+ if (result instanceof Promise)
632
+ result = await result;
633
+ return result.issues.length ? {
634
+ success: false,
635
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
636
+ } : { success: true, data: result.value };
637
+ };
638
+ const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
639
+ const _encode = (_Err) => (schema, value, _ctx) => {
640
+ const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
641
+ return _parse(_Err)(schema, value, ctx);
642
+ };
643
+ const _decode = (_Err) => (schema, value, _ctx) => {
644
+ return _parse(_Err)(schema, value, _ctx);
645
+ };
646
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
647
+ const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
648
+ return _parseAsync(_Err)(schema, value, ctx);
649
+ };
650
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
651
+ return _parseAsync(_Err)(schema, value, _ctx);
652
+ };
653
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
654
+ const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
655
+ return _safeParse(_Err)(schema, value, ctx);
656
+ };
657
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
658
+ return _safeParse(_Err)(schema, value, _ctx);
659
+ };
660
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
661
+ const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
662
+ return _safeParseAsync(_Err)(schema, value, ctx);
663
+ };
664
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
665
+ return _safeParseAsync(_Err)(schema, value, _ctx);
666
+ };
667
+
668
+ const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
669
+ var _a;
670
+ inst._zod ?? (inst._zod = {});
671
+ inst._zod.def = def;
672
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
673
+ });
674
+ const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
675
+ var _a;
676
+ $ZodCheck.init(inst, def);
677
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
678
+ const val = payload.value;
679
+ return !nullish(val) && val.length !== void 0;
680
+ });
681
+ inst._zod.onattach.push((inst2) => {
682
+ const curr = inst2._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
683
+ if (def.maximum < curr)
684
+ inst2._zod.bag.maximum = def.maximum;
685
+ });
686
+ inst._zod.check = (payload) => {
687
+ const input = payload.value;
688
+ const length = input.length;
689
+ if (length <= def.maximum)
690
+ return;
691
+ const origin = getLengthableOrigin(input);
692
+ payload.issues.push({
693
+ origin,
694
+ code: "too_big",
695
+ maximum: def.maximum,
696
+ inclusive: true,
697
+ input,
698
+ inst,
699
+ continue: !def.abort
700
+ });
701
+ };
702
+ });
703
+ const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
704
+ var _a;
705
+ $ZodCheck.init(inst, def);
706
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
707
+ const val = payload.value;
708
+ return !nullish(val) && val.length !== void 0;
709
+ });
710
+ inst._zod.onattach.push((inst2) => {
711
+ const curr = inst2._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
712
+ if (def.minimum > curr)
713
+ inst2._zod.bag.minimum = def.minimum;
714
+ });
715
+ inst._zod.check = (payload) => {
716
+ const input = payload.value;
717
+ const length = input.length;
718
+ if (length >= def.minimum)
719
+ return;
720
+ const origin = getLengthableOrigin(input);
721
+ payload.issues.push({
722
+ origin,
723
+ code: "too_small",
724
+ minimum: def.minimum,
725
+ inclusive: true,
726
+ input,
727
+ inst,
728
+ continue: !def.abort
729
+ });
730
+ };
731
+ });
732
+ const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
733
+ var _a;
734
+ $ZodCheck.init(inst, def);
735
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
736
+ const val = payload.value;
737
+ return !nullish(val) && val.length !== void 0;
738
+ });
739
+ inst._zod.onattach.push((inst2) => {
740
+ const bag = inst2._zod.bag;
741
+ bag.minimum = def.length;
742
+ bag.maximum = def.length;
743
+ bag.length = def.length;
744
+ });
745
+ inst._zod.check = (payload) => {
746
+ const input = payload.value;
747
+ const length = input.length;
748
+ if (length === def.length)
749
+ return;
750
+ const origin = getLengthableOrigin(input);
751
+ const tooBig = length > def.length;
752
+ payload.issues.push({
753
+ origin,
754
+ ...tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length },
755
+ inclusive: true,
756
+ exact: true,
757
+ input: payload.value,
758
+ inst,
759
+ continue: !def.abort
760
+ });
761
+ };
762
+ });
763
+ const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
764
+ $ZodCheck.init(inst, def);
765
+ inst._zod.check = (payload) => {
766
+ payload.value = def.tx(payload.value);
767
+ };
768
+ });
769
+
770
+ const version = {
771
+ major: 4,
772
+ minor: 4,
773
+ patch: 3
774
+ };
775
+
776
+ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
777
+ var _a;
778
+ inst ?? (inst = {});
779
+ inst._zod.def = def;
780
+ inst._zod.bag = inst._zod.bag || {};
781
+ inst._zod.version = version;
782
+ const checks2 = [...inst._zod.def.checks ?? []];
783
+ if (inst._zod.traits.has("$ZodCheck")) {
784
+ checks2.unshift(inst);
785
+ }
786
+ for (const ch of checks2) {
787
+ for (const fn of ch._zod.onattach) {
788
+ fn(inst);
789
+ }
790
+ }
791
+ if (checks2.length === 0) {
792
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
793
+ inst._zod.deferred?.push(() => {
794
+ inst._zod.run = inst._zod.parse;
795
+ });
796
+ } else {
797
+ const runChecks = (payload, checks3, ctx) => {
798
+ let isAborted = aborted(payload);
799
+ let asyncResult;
800
+ for (const ch of checks3) {
801
+ if (ch._zod.def.when) {
802
+ if (explicitlyAborted(payload))
803
+ continue;
804
+ const shouldRun = ch._zod.def.when(payload);
805
+ if (!shouldRun)
806
+ continue;
807
+ } else if (isAborted) {
808
+ continue;
809
+ }
810
+ const currLen = payload.issues.length;
811
+ const _ = ch._zod.check(payload);
812
+ if (_ instanceof Promise && ctx?.async === false) {
813
+ throw new $ZodAsyncError();
814
+ }
815
+ if (asyncResult || _ instanceof Promise) {
816
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
817
+ await _;
818
+ const nextLen = payload.issues.length;
819
+ if (nextLen === currLen)
820
+ return;
821
+ if (!isAborted)
822
+ isAborted = aborted(payload, currLen);
823
+ });
824
+ } else {
825
+ const nextLen = payload.issues.length;
826
+ if (nextLen === currLen)
827
+ continue;
828
+ if (!isAborted)
829
+ isAborted = aborted(payload, currLen);
830
+ }
831
+ }
832
+ if (asyncResult) {
833
+ return asyncResult.then(() => {
834
+ return payload;
835
+ });
836
+ }
837
+ return payload;
838
+ };
839
+ const handleCanaryResult = (canary, payload, ctx) => {
840
+ if (aborted(canary)) {
841
+ canary.aborted = true;
842
+ return canary;
843
+ }
844
+ const checkResult = runChecks(payload, checks2, ctx);
845
+ if (checkResult instanceof Promise) {
846
+ if (ctx.async === false)
847
+ throw new $ZodAsyncError();
848
+ return checkResult.then((checkResult2) => inst._zod.parse(checkResult2, ctx));
849
+ }
850
+ return inst._zod.parse(checkResult, ctx);
851
+ };
852
+ inst._zod.run = (payload, ctx) => {
853
+ if (ctx.skipChecks) {
854
+ return inst._zod.parse(payload, ctx);
855
+ }
856
+ if (ctx.direction === "backward") {
857
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
858
+ if (canary instanceof Promise) {
859
+ return canary.then((canary2) => {
860
+ return handleCanaryResult(canary2, payload, ctx);
861
+ });
862
+ }
863
+ return handleCanaryResult(canary, payload, ctx);
864
+ }
865
+ const result = inst._zod.parse(payload, ctx);
866
+ if (result instanceof Promise) {
867
+ if (ctx.async === false)
868
+ throw new $ZodAsyncError();
869
+ return result.then((result2) => runChecks(result2, checks2, ctx));
870
+ }
871
+ return runChecks(result, checks2, ctx);
872
+ };
873
+ }
874
+ defineLazy(inst, "~standard", () => ({
875
+ validate: (value) => {
876
+ try {
877
+ const r = safeParse$1(inst, value);
878
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
879
+ } catch (_) {
880
+ return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
881
+ }
882
+ },
883
+ vendor: "zod",
884
+ version: 1
885
+ }));
886
+ });
887
+ function handleArrayResult(result, final, index) {
888
+ if (result.issues.length) {
889
+ final.issues.push(...prefixIssues(index, result.issues));
890
+ }
891
+ final.value[index] = result.value;
892
+ }
893
+ const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
894
+ $ZodType.init(inst, def);
895
+ inst._zod.parse = (payload, ctx) => {
896
+ const input = payload.value;
897
+ if (!Array.isArray(input)) {
898
+ payload.issues.push({
899
+ expected: "array",
900
+ code: "invalid_type",
901
+ input,
902
+ inst
903
+ });
904
+ return payload;
905
+ }
906
+ payload.value = Array(input.length);
907
+ const proms = [];
908
+ for (let i = 0; i < input.length; i++) {
909
+ const item = input[i];
910
+ const result = def.element._zod.run({
911
+ value: item,
912
+ issues: []
913
+ }, ctx);
914
+ if (result instanceof Promise) {
915
+ proms.push(result.then((result2) => handleArrayResult(result2, payload, i)));
916
+ } else {
917
+ handleArrayResult(result, payload, i);
918
+ }
919
+ }
920
+ if (proms.length) {
921
+ return Promise.all(proms).then(() => payload);
922
+ }
923
+ return payload;
924
+ };
925
+ });
926
+ function handleUnionResults(results, final, inst, ctx) {
927
+ for (const result of results) {
928
+ if (result.issues.length === 0) {
929
+ final.value = result.value;
930
+ return final;
931
+ }
932
+ }
933
+ const nonaborted = results.filter((r) => !aborted(r));
934
+ if (nonaborted.length === 1) {
935
+ final.value = nonaborted[0].value;
936
+ return nonaborted[0];
937
+ }
938
+ final.issues.push({
939
+ code: "invalid_union",
940
+ input: final.value,
941
+ inst,
942
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
943
+ });
944
+ return final;
945
+ }
946
+ const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
947
+ $ZodType.init(inst, def);
948
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
949
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
950
+ defineLazy(inst._zod, "values", () => {
951
+ if (def.options.every((o) => o._zod.values)) {
952
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
953
+ }
954
+ return void 0;
955
+ });
956
+ defineLazy(inst._zod, "pattern", () => {
957
+ if (def.options.every((o) => o._zod.pattern)) {
958
+ const patterns = def.options.map((o) => o._zod.pattern);
959
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
960
+ }
961
+ return void 0;
962
+ });
963
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
964
+ inst._zod.parse = (payload, ctx) => {
965
+ if (first) {
966
+ return first(payload, ctx);
967
+ }
968
+ let async = false;
969
+ const results = [];
970
+ for (const option of def.options) {
971
+ const result = option._zod.run({
972
+ value: payload.value,
973
+ issues: []
974
+ }, ctx);
975
+ if (result instanceof Promise) {
976
+ results.push(result);
977
+ async = true;
978
+ } else {
979
+ if (result.issues.length === 0)
980
+ return result;
981
+ results.push(result);
982
+ }
983
+ }
984
+ if (!async)
985
+ return handleUnionResults(results, payload, inst, ctx);
986
+ return Promise.all(results).then((results2) => {
987
+ return handleUnionResults(results2, payload, inst, ctx);
988
+ });
989
+ };
990
+ });
991
+ const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
992
+ $ZodType.init(inst, def);
993
+ inst._zod.parse = (payload, ctx) => {
994
+ const input = payload.value;
995
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
996
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
997
+ const async = left instanceof Promise || right instanceof Promise;
998
+ if (async) {
999
+ return Promise.all([left, right]).then(([left2, right2]) => {
1000
+ return handleIntersectionResults(payload, left2, right2);
1001
+ });
1002
+ }
1003
+ return handleIntersectionResults(payload, left, right);
1004
+ };
1005
+ });
1006
+ function mergeValues(a, b) {
1007
+ if (a === b) {
1008
+ return { valid: true, data: a };
1009
+ }
1010
+ if (a instanceof Date && b instanceof Date && +a === +b) {
1011
+ return { valid: true, data: a };
1012
+ }
1013
+ if (isPlainObject(a) && isPlainObject(b)) {
1014
+ const bKeys = Object.keys(b);
1015
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1016
+ const newObj = { ...a, ...b };
1017
+ for (const key of sharedKeys) {
1018
+ const sharedValue = mergeValues(a[key], b[key]);
1019
+ if (!sharedValue.valid) {
1020
+ return {
1021
+ valid: false,
1022
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1023
+ };
1024
+ }
1025
+ newObj[key] = sharedValue.data;
1026
+ }
1027
+ return { valid: true, data: newObj };
1028
+ }
1029
+ if (Array.isArray(a) && Array.isArray(b)) {
1030
+ if (a.length !== b.length) {
1031
+ return { valid: false, mergeErrorPath: [] };
1032
+ }
1033
+ const newArray = [];
1034
+ for (let index = 0; index < a.length; index++) {
1035
+ const itemA = a[index];
1036
+ const itemB = b[index];
1037
+ const sharedValue = mergeValues(itemA, itemB);
1038
+ if (!sharedValue.valid) {
1039
+ return {
1040
+ valid: false,
1041
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1042
+ };
1043
+ }
1044
+ newArray.push(sharedValue.data);
1045
+ }
1046
+ return { valid: true, data: newArray };
1047
+ }
1048
+ return { valid: false, mergeErrorPath: [] };
1049
+ }
1050
+ function handleIntersectionResults(result, left, right) {
1051
+ const unrecKeys = /* @__PURE__ */ new Map();
1052
+ let unrecIssue;
1053
+ for (const iss of left.issues) {
1054
+ if (iss.code === "unrecognized_keys") {
1055
+ unrecIssue ?? (unrecIssue = iss);
1056
+ for (const k of iss.keys) {
1057
+ if (!unrecKeys.has(k))
1058
+ unrecKeys.set(k, {});
1059
+ unrecKeys.get(k).l = true;
1060
+ }
1061
+ } else {
1062
+ result.issues.push(iss);
1063
+ }
1064
+ }
1065
+ for (const iss of right.issues) {
1066
+ if (iss.code === "unrecognized_keys") {
1067
+ for (const k of iss.keys) {
1068
+ if (!unrecKeys.has(k))
1069
+ unrecKeys.set(k, {});
1070
+ unrecKeys.get(k).r = true;
1071
+ }
1072
+ } else {
1073
+ result.issues.push(iss);
1074
+ }
1075
+ }
1076
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1077
+ if (bothKeys.length && unrecIssue) {
1078
+ result.issues.push({ ...unrecIssue, keys: bothKeys });
1079
+ }
1080
+ if (aborted(result))
1081
+ return result;
1082
+ const merged = mergeValues(left.value, right.value);
1083
+ if (!merged.valid) {
1084
+ throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
1085
+ }
1086
+ result.value = merged.data;
1087
+ return result;
1088
+ }
1089
+ const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
1090
+ $ZodType.init(inst, def);
1091
+ inst._zod.optin = "optional";
1092
+ inst._zod.parse = (payload, ctx) => {
1093
+ if (ctx.direction === "backward") {
1094
+ throw new $ZodEncodeError(inst.constructor.name);
1095
+ }
1096
+ const _out = def.transform(payload.value, payload);
1097
+ if (ctx.async) {
1098
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
1099
+ return output.then((output2) => {
1100
+ payload.value = output2;
1101
+ payload.fallback = true;
1102
+ return payload;
1103
+ });
1104
+ }
1105
+ if (_out instanceof Promise) {
1106
+ throw new $ZodAsyncError();
1107
+ }
1108
+ payload.value = _out;
1109
+ payload.fallback = true;
1110
+ return payload;
1111
+ };
1112
+ });
1113
+ function handleOptionalResult(result, input) {
1114
+ if (input === void 0 && (result.issues.length || result.fallback)) {
1115
+ return { issues: [], value: void 0 };
1116
+ }
1117
+ return result;
1118
+ }
1119
+ const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
1120
+ $ZodType.init(inst, def);
1121
+ inst._zod.optin = "optional";
1122
+ inst._zod.optout = "optional";
1123
+ defineLazy(inst._zod, "values", () => {
1124
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, void 0]) : void 0;
1125
+ });
1126
+ defineLazy(inst._zod, "pattern", () => {
1127
+ const pattern = def.innerType._zod.pattern;
1128
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
1129
+ });
1130
+ inst._zod.parse = (payload, ctx) => {
1131
+ if (def.innerType._zod.optin === "optional") {
1132
+ const input = payload.value;
1133
+ const result = def.innerType._zod.run(payload, ctx);
1134
+ if (result instanceof Promise)
1135
+ return result.then((r) => handleOptionalResult(r, input));
1136
+ return handleOptionalResult(result, input);
1137
+ }
1138
+ if (payload.value === void 0) {
1139
+ return payload;
1140
+ }
1141
+ return def.innerType._zod.run(payload, ctx);
1142
+ };
1143
+ });
1144
+ const $ZodExactOptional = /* @__PURE__ */ $constructor("$ZodExactOptional", (inst, def) => {
1145
+ $ZodOptional.init(inst, def);
1146
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1147
+ defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
1148
+ inst._zod.parse = (payload, ctx) => {
1149
+ return def.innerType._zod.run(payload, ctx);
1150
+ };
1151
+ });
1152
+ const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
1153
+ $ZodType.init(inst, def);
1154
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1155
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1156
+ defineLazy(inst._zod, "pattern", () => {
1157
+ const pattern = def.innerType._zod.pattern;
1158
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
1159
+ });
1160
+ defineLazy(inst._zod, "values", () => {
1161
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, null]) : void 0;
1162
+ });
1163
+ inst._zod.parse = (payload, ctx) => {
1164
+ if (payload.value === null)
1165
+ return payload;
1166
+ return def.innerType._zod.run(payload, ctx);
1167
+ };
1168
+ });
1169
+ const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
1170
+ $ZodType.init(inst, def);
1171
+ inst._zod.optin = "optional";
1172
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1173
+ inst._zod.parse = (payload, ctx) => {
1174
+ if (ctx.direction === "backward") {
1175
+ return def.innerType._zod.run(payload, ctx);
1176
+ }
1177
+ if (payload.value === void 0) {
1178
+ payload.value = def.defaultValue;
1179
+ return payload;
1180
+ }
1181
+ const result = def.innerType._zod.run(payload, ctx);
1182
+ if (result instanceof Promise) {
1183
+ return result.then((result2) => handleDefaultResult(result2, def));
1184
+ }
1185
+ return handleDefaultResult(result, def);
1186
+ };
1187
+ });
1188
+ function handleDefaultResult(payload, def) {
1189
+ if (payload.value === void 0) {
1190
+ payload.value = def.defaultValue;
1191
+ }
1192
+ return payload;
1193
+ }
1194
+ const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
1195
+ $ZodType.init(inst, def);
1196
+ inst._zod.optin = "optional";
1197
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1198
+ inst._zod.parse = (payload, ctx) => {
1199
+ if (ctx.direction === "backward") {
1200
+ return def.innerType._zod.run(payload, ctx);
1201
+ }
1202
+ if (payload.value === void 0) {
1203
+ payload.value = def.defaultValue;
1204
+ }
1205
+ return def.innerType._zod.run(payload, ctx);
1206
+ };
1207
+ });
1208
+ const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
1209
+ $ZodType.init(inst, def);
1210
+ defineLazy(inst._zod, "values", () => {
1211
+ const v = def.innerType._zod.values;
1212
+ return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
1213
+ });
1214
+ inst._zod.parse = (payload, ctx) => {
1215
+ const result = def.innerType._zod.run(payload, ctx);
1216
+ if (result instanceof Promise) {
1217
+ return result.then((result2) => handleNonOptionalResult(result2, inst));
1218
+ }
1219
+ return handleNonOptionalResult(result, inst);
1220
+ };
1221
+ });
1222
+ function handleNonOptionalResult(payload, inst) {
1223
+ if (!payload.issues.length && payload.value === void 0) {
1224
+ payload.issues.push({
1225
+ code: "invalid_type",
1226
+ expected: "nonoptional",
1227
+ input: payload.value,
1228
+ inst
1229
+ });
1230
+ }
1231
+ return payload;
1232
+ }
1233
+ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
1234
+ $ZodType.init(inst, def);
1235
+ inst._zod.optin = "optional";
1236
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1237
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1238
+ inst._zod.parse = (payload, ctx) => {
1239
+ if (ctx.direction === "backward") {
1240
+ return def.innerType._zod.run(payload, ctx);
1241
+ }
1242
+ const result = def.innerType._zod.run(payload, ctx);
1243
+ if (result instanceof Promise) {
1244
+ return result.then((result2) => {
1245
+ payload.value = result2.value;
1246
+ if (result2.issues.length) {
1247
+ payload.value = def.catchValue({
1248
+ ...payload,
1249
+ error: {
1250
+ issues: result2.issues.map((iss) => finalizeIssue(iss, ctx, config()))
1251
+ },
1252
+ input: payload.value
1253
+ });
1254
+ payload.issues = [];
1255
+ payload.fallback = true;
1256
+ }
1257
+ return payload;
1258
+ });
1259
+ }
1260
+ payload.value = result.value;
1261
+ if (result.issues.length) {
1262
+ payload.value = def.catchValue({
1263
+ ...payload,
1264
+ error: {
1265
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config()))
1266
+ },
1267
+ input: payload.value
1268
+ });
1269
+ payload.issues = [];
1270
+ payload.fallback = true;
1271
+ }
1272
+ return payload;
1273
+ };
1274
+ });
1275
+ const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
1276
+ $ZodType.init(inst, def);
1277
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
1278
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1279
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1280
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
1281
+ inst._zod.parse = (payload, ctx) => {
1282
+ if (ctx.direction === "backward") {
1283
+ const right = def.out._zod.run(payload, ctx);
1284
+ if (right instanceof Promise) {
1285
+ return right.then((right2) => handlePipeResult(right2, def.in, ctx));
1286
+ }
1287
+ return handlePipeResult(right, def.in, ctx);
1288
+ }
1289
+ const left = def.in._zod.run(payload, ctx);
1290
+ if (left instanceof Promise) {
1291
+ return left.then((left2) => handlePipeResult(left2, def.out, ctx));
1292
+ }
1293
+ return handlePipeResult(left, def.out, ctx);
1294
+ };
1295
+ });
1296
+ function handlePipeResult(left, next, ctx) {
1297
+ if (left.issues.length) {
1298
+ left.aborted = true;
1299
+ return left;
1300
+ }
1301
+ return next._zod.run({ value: left.value, issues: left.issues, fallback: left.fallback }, ctx);
1302
+ }
1303
+ const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
1304
+ $ZodType.init(inst, def);
1305
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1306
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1307
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
1308
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
1309
+ inst._zod.parse = (payload, ctx) => {
1310
+ if (ctx.direction === "backward") {
1311
+ return def.innerType._zod.run(payload, ctx);
1312
+ }
1313
+ const result = def.innerType._zod.run(payload, ctx);
1314
+ if (result instanceof Promise) {
1315
+ return result.then(handleReadonlyResult);
1316
+ }
1317
+ return handleReadonlyResult(result);
1318
+ };
1319
+ });
1320
+ function handleReadonlyResult(payload) {
1321
+ payload.value = Object.freeze(payload.value);
1322
+ return payload;
1323
+ }
1324
+ const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
1325
+ $ZodCheck.init(inst, def);
1326
+ $ZodType.init(inst, def);
1327
+ inst._zod.parse = (payload, _) => {
1328
+ return payload;
1329
+ };
1330
+ inst._zod.check = (payload) => {
1331
+ const input = payload.value;
1332
+ const r = def.fn(input);
1333
+ if (r instanceof Promise) {
1334
+ return r.then((r2) => handleRefineResult(r2, payload, input, inst));
1335
+ }
1336
+ handleRefineResult(r, payload, input, inst);
1337
+ return;
1338
+ };
1339
+ });
1340
+ function handleRefineResult(result, payload, input, inst) {
1341
+ if (!result) {
1342
+ const _iss = {
1343
+ code: "custom",
1344
+ input,
1345
+ inst,
1346
+ // incorporates params.error into issue reporting
1347
+ path: [...inst._zod.def.path ?? []],
1348
+ // incorporates params.error into issue reporting
1349
+ continue: !inst._zod.def.abort
1350
+ // params: inst._zod.def.params,
1351
+ };
1352
+ if (inst._zod.def.params)
1353
+ _iss.params = inst._zod.def.params;
1354
+ payload.issues.push(issue(_iss));
1355
+ }
1356
+ }
1357
+
1358
+ var _a;
1359
+ class $ZodRegistry {
1360
+ constructor() {
1361
+ this._map = /* @__PURE__ */ new WeakMap();
1362
+ this._idmap = /* @__PURE__ */ new Map();
1363
+ }
1364
+ add(schema, ..._meta) {
1365
+ const meta = _meta[0];
1366
+ this._map.set(schema, meta);
1367
+ if (meta && typeof meta === "object" && "id" in meta) {
1368
+ this._idmap.set(meta.id, schema);
1369
+ }
1370
+ return this;
1371
+ }
1372
+ clear() {
1373
+ this._map = /* @__PURE__ */ new WeakMap();
1374
+ this._idmap = /* @__PURE__ */ new Map();
1375
+ return this;
1376
+ }
1377
+ remove(schema) {
1378
+ const meta = this._map.get(schema);
1379
+ if (meta && typeof meta === "object" && "id" in meta) {
1380
+ this._idmap.delete(meta.id);
1381
+ }
1382
+ this._map.delete(schema);
1383
+ return this;
1384
+ }
1385
+ get(schema) {
1386
+ const p = schema._zod.parent;
1387
+ if (p) {
1388
+ const pm = { ...this.get(p) ?? {} };
1389
+ delete pm.id;
1390
+ const f = { ...pm, ...this._map.get(schema) };
1391
+ return Object.keys(f).length ? f : void 0;
1392
+ }
1393
+ return this._map.get(schema);
1394
+ }
1395
+ has(schema) {
1396
+ return this._map.has(schema);
1397
+ }
1398
+ }
1399
+ function registry() {
1400
+ return new $ZodRegistry();
1401
+ }
1402
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
1403
+ const globalRegistry = globalThis.__zod_globalRegistry;
1404
+
1405
+ // @__NO_SIDE_EFFECTS__
1406
+ function _maxLength(maximum, params) {
1407
+ const ch = new $ZodCheckMaxLength({
1408
+ check: "max_length",
1409
+ ...normalizeParams(params),
1410
+ maximum
1411
+ });
1412
+ return ch;
1413
+ }
1414
+ // @__NO_SIDE_EFFECTS__
1415
+ function _minLength(minimum, params) {
1416
+ return new $ZodCheckMinLength({
1417
+ check: "min_length",
1418
+ ...normalizeParams(params),
1419
+ minimum
1420
+ });
1421
+ }
1422
+ // @__NO_SIDE_EFFECTS__
1423
+ function _length(length, params) {
1424
+ return new $ZodCheckLengthEquals({
1425
+ check: "length_equals",
1426
+ ...normalizeParams(params),
1427
+ length
1428
+ });
1429
+ }
1430
+ // @__NO_SIDE_EFFECTS__
1431
+ function _overwrite(tx) {
1432
+ return new $ZodCheckOverwrite({
1433
+ check: "overwrite",
1434
+ tx
1435
+ });
1436
+ }
1437
+ // @__NO_SIDE_EFFECTS__
1438
+ function _array(Class, element, params) {
1439
+ return new Class({
1440
+ type: "array",
1441
+ element,
1442
+ // get element() {
1443
+ // return element;
1444
+ // },
1445
+ ...normalizeParams(params)
1446
+ });
1447
+ }
1448
+ // @__NO_SIDE_EFFECTS__
1449
+ function _refine(Class, fn, _params) {
1450
+ const schema = new Class({
1451
+ type: "custom",
1452
+ check: "custom",
1453
+ fn,
1454
+ ...normalizeParams(_params)
1455
+ });
1456
+ return schema;
1457
+ }
1458
+ // @__NO_SIDE_EFFECTS__
1459
+ function _superRefine(fn, params) {
1460
+ const ch = /* @__PURE__ */ _check((payload) => {
1461
+ payload.addIssue = (issue$1) => {
1462
+ if (typeof issue$1 === "string") {
1463
+ payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
1464
+ } else {
1465
+ const _issue = issue$1;
1466
+ if (_issue.fatal)
1467
+ _issue.continue = false;
1468
+ _issue.code ?? (_issue.code = "custom");
1469
+ _issue.input ?? (_issue.input = payload.value);
1470
+ _issue.inst ?? (_issue.inst = ch);
1471
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
1472
+ payload.issues.push(issue(_issue));
1473
+ }
1474
+ };
1475
+ return fn(payload.value, payload);
1476
+ }, params);
1477
+ return ch;
1478
+ }
1479
+ // @__NO_SIDE_EFFECTS__
1480
+ function _check(fn, params) {
1481
+ const ch = new $ZodCheck({
1482
+ check: "custom",
1483
+ ...normalizeParams(params)
1484
+ });
1485
+ ch._zod.check = fn;
1486
+ return ch;
1487
+ }
1488
+
1489
+ function initializeContext(params) {
1490
+ let target = params?.target ?? "draft-2020-12";
1491
+ if (target === "draft-4")
1492
+ target = "draft-04";
1493
+ if (target === "draft-7")
1494
+ target = "draft-07";
1495
+ return {
1496
+ processors: params.processors ?? {},
1497
+ metadataRegistry: params?.metadata ?? globalRegistry,
1498
+ target,
1499
+ unrepresentable: params?.unrepresentable ?? "throw",
1500
+ override: params?.override ?? (() => {
1501
+ }),
1502
+ io: params?.io ?? "output",
1503
+ counter: 0,
1504
+ seen: /* @__PURE__ */ new Map(),
1505
+ cycles: params?.cycles ?? "ref",
1506
+ reused: params?.reused ?? "inline",
1507
+ external: params?.external ?? void 0
1508
+ };
1509
+ }
1510
+ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
1511
+ var _a;
1512
+ const def = schema._zod.def;
1513
+ const seen = ctx.seen.get(schema);
1514
+ if (seen) {
1515
+ seen.count++;
1516
+ const isCycle = _params.schemaPath.includes(schema);
1517
+ if (isCycle) {
1518
+ seen.cycle = _params.path;
1519
+ }
1520
+ return seen.schema;
1521
+ }
1522
+ const result = { schema: {}, count: 1, cycle: void 0, path: _params.path };
1523
+ ctx.seen.set(schema, result);
1524
+ const overrideSchema = schema._zod.toJSONSchema?.();
1525
+ if (overrideSchema) {
1526
+ result.schema = overrideSchema;
1527
+ } else {
1528
+ const params = {
1529
+ ..._params,
1530
+ schemaPath: [..._params.schemaPath, schema],
1531
+ path: _params.path
1532
+ };
1533
+ if (schema._zod.processJSONSchema) {
1534
+ schema._zod.processJSONSchema(ctx, result.schema, params);
1535
+ } else {
1536
+ const _json = result.schema;
1537
+ const processor = ctx.processors[def.type];
1538
+ if (!processor) {
1539
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
1540
+ }
1541
+ processor(schema, ctx, _json, params);
1542
+ }
1543
+ const parent = schema._zod.parent;
1544
+ if (parent) {
1545
+ if (!result.ref)
1546
+ result.ref = parent;
1547
+ process(parent, ctx, params);
1548
+ ctx.seen.get(parent).isParent = true;
1549
+ }
1550
+ }
1551
+ const meta = ctx.metadataRegistry.get(schema);
1552
+ if (meta)
1553
+ Object.assign(result.schema, meta);
1554
+ if (ctx.io === "input" && isTransforming(schema)) {
1555
+ delete result.schema.examples;
1556
+ delete result.schema.default;
1557
+ }
1558
+ if (ctx.io === "input" && "_prefault" in result.schema)
1559
+ (_a = result.schema).default ?? (_a.default = result.schema._prefault);
1560
+ delete result.schema._prefault;
1561
+ const _result = ctx.seen.get(schema);
1562
+ return _result.schema;
1563
+ }
1564
+ function extractDefs(ctx, schema) {
1565
+ const root = ctx.seen.get(schema);
1566
+ if (!root)
1567
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
1568
+ const idToSchema = /* @__PURE__ */ new Map();
1569
+ for (const entry of ctx.seen.entries()) {
1570
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
1571
+ if (id) {
1572
+ const existing = idToSchema.get(id);
1573
+ if (existing && existing !== entry[0]) {
1574
+ throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
1575
+ }
1576
+ idToSchema.set(id, entry[0]);
1577
+ }
1578
+ }
1579
+ const makeURI = (entry) => {
1580
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
1581
+ if (ctx.external) {
1582
+ const externalId = ctx.external.registry.get(entry[0])?.id;
1583
+ const uriGenerator = ctx.external.uri ?? ((id2) => id2);
1584
+ if (externalId) {
1585
+ return { ref: uriGenerator(externalId) };
1586
+ }
1587
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
1588
+ entry[1].defId = id;
1589
+ return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
1590
+ }
1591
+ if (entry[1] === root) {
1592
+ return { ref: "#" };
1593
+ }
1594
+ const uriPrefix = `#`;
1595
+ const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
1596
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
1597
+ return { defId, ref: defUriPrefix + defId };
1598
+ };
1599
+ const extractToDef = (entry) => {
1600
+ if (entry[1].schema.$ref) {
1601
+ return;
1602
+ }
1603
+ const seen = entry[1];
1604
+ const { ref, defId } = makeURI(entry);
1605
+ seen.def = { ...seen.schema };
1606
+ if (defId)
1607
+ seen.defId = defId;
1608
+ const schema2 = seen.schema;
1609
+ for (const key in schema2) {
1610
+ delete schema2[key];
1611
+ }
1612
+ schema2.$ref = ref;
1613
+ };
1614
+ if (ctx.cycles === "throw") {
1615
+ for (const entry of ctx.seen.entries()) {
1616
+ const seen = entry[1];
1617
+ if (seen.cycle) {
1618
+ throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
1619
+
1620
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
1621
+ }
1622
+ }
1623
+ }
1624
+ for (const entry of ctx.seen.entries()) {
1625
+ const seen = entry[1];
1626
+ if (schema === entry[0]) {
1627
+ extractToDef(entry);
1628
+ continue;
1629
+ }
1630
+ if (ctx.external) {
1631
+ const ext = ctx.external.registry.get(entry[0])?.id;
1632
+ if (schema !== entry[0] && ext) {
1633
+ extractToDef(entry);
1634
+ continue;
1635
+ }
1636
+ }
1637
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
1638
+ if (id) {
1639
+ extractToDef(entry);
1640
+ continue;
1641
+ }
1642
+ if (seen.cycle) {
1643
+ extractToDef(entry);
1644
+ continue;
1645
+ }
1646
+ if (seen.count > 1) {
1647
+ if (ctx.reused === "ref") {
1648
+ extractToDef(entry);
1649
+ continue;
1650
+ }
1651
+ }
1652
+ }
1653
+ }
1654
+ function finalize(ctx, schema) {
1655
+ const root = ctx.seen.get(schema);
1656
+ if (!root)
1657
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
1658
+ const flattenRef = (zodSchema) => {
1659
+ const seen = ctx.seen.get(zodSchema);
1660
+ if (seen.ref === null)
1661
+ return;
1662
+ const schema2 = seen.def ?? seen.schema;
1663
+ const _cached = { ...schema2 };
1664
+ const ref = seen.ref;
1665
+ seen.ref = null;
1666
+ if (ref) {
1667
+ flattenRef(ref);
1668
+ const refSeen = ctx.seen.get(ref);
1669
+ const refSchema = refSeen.schema;
1670
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
1671
+ schema2.allOf = schema2.allOf ?? [];
1672
+ schema2.allOf.push(refSchema);
1673
+ } else {
1674
+ Object.assign(schema2, refSchema);
1675
+ }
1676
+ Object.assign(schema2, _cached);
1677
+ const isParentRef = zodSchema._zod.parent === ref;
1678
+ if (isParentRef) {
1679
+ for (const key in schema2) {
1680
+ if (key === "$ref" || key === "allOf")
1681
+ continue;
1682
+ if (!(key in _cached)) {
1683
+ delete schema2[key];
1684
+ }
1685
+ }
1686
+ }
1687
+ if (refSchema.$ref && refSeen.def) {
1688
+ for (const key in schema2) {
1689
+ if (key === "$ref" || key === "allOf")
1690
+ continue;
1691
+ if (key in refSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(refSeen.def[key])) {
1692
+ delete schema2[key];
1693
+ }
1694
+ }
1695
+ }
1696
+ }
1697
+ const parent = zodSchema._zod.parent;
1698
+ if (parent && parent !== ref) {
1699
+ flattenRef(parent);
1700
+ const parentSeen = ctx.seen.get(parent);
1701
+ if (parentSeen?.schema.$ref) {
1702
+ schema2.$ref = parentSeen.schema.$ref;
1703
+ if (parentSeen.def) {
1704
+ for (const key in schema2) {
1705
+ if (key === "$ref" || key === "allOf")
1706
+ continue;
1707
+ if (key in parentSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(parentSeen.def[key])) {
1708
+ delete schema2[key];
1709
+ }
1710
+ }
1711
+ }
1712
+ }
1713
+ }
1714
+ ctx.override({
1715
+ zodSchema,
1716
+ jsonSchema: schema2,
1717
+ path: seen.path ?? []
1718
+ });
1719
+ };
1720
+ for (const entry of [...ctx.seen.entries()].reverse()) {
1721
+ flattenRef(entry[0]);
1722
+ }
1723
+ const result = {};
1724
+ if (ctx.target === "draft-2020-12") {
1725
+ result.$schema = "https://json-schema.org/draft/2020-12/schema";
1726
+ } else if (ctx.target === "draft-07") {
1727
+ result.$schema = "http://json-schema.org/draft-07/schema#";
1728
+ } else if (ctx.target === "draft-04") {
1729
+ result.$schema = "http://json-schema.org/draft-04/schema#";
1730
+ } else if (ctx.target === "openapi-3.0") ; else ;
1731
+ if (ctx.external?.uri) {
1732
+ const id = ctx.external.registry.get(schema)?.id;
1733
+ if (!id)
1734
+ throw new Error("Schema is missing an `id` property");
1735
+ result.$id = ctx.external.uri(id);
1736
+ }
1737
+ Object.assign(result, root.def ?? root.schema);
1738
+ const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
1739
+ if (rootMetaId !== void 0 && result.id === rootMetaId)
1740
+ delete result.id;
1741
+ const defs = ctx.external?.defs ?? {};
1742
+ for (const entry of ctx.seen.entries()) {
1743
+ const seen = entry[1];
1744
+ if (seen.def && seen.defId) {
1745
+ if (seen.def.id === seen.defId)
1746
+ delete seen.def.id;
1747
+ defs[seen.defId] = seen.def;
1748
+ }
1749
+ }
1750
+ if (ctx.external) ; else {
1751
+ if (Object.keys(defs).length > 0) {
1752
+ if (ctx.target === "draft-2020-12") {
1753
+ result.$defs = defs;
1754
+ } else {
1755
+ result.definitions = defs;
1756
+ }
1757
+ }
1758
+ }
1759
+ try {
1760
+ const finalized = JSON.parse(JSON.stringify(result));
1761
+ Object.defineProperty(finalized, "~standard", {
1762
+ value: {
1763
+ ...schema["~standard"],
1764
+ jsonSchema: {
1765
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
1766
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
1767
+ }
1768
+ },
1769
+ enumerable: false,
1770
+ writable: false
1771
+ });
1772
+ return finalized;
1773
+ } catch (_err) {
1774
+ throw new Error("Error converting schema to JSON.");
1775
+ }
1776
+ }
1777
+ function isTransforming(_schema, _ctx) {
1778
+ const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
1779
+ if (ctx.seen.has(_schema))
1780
+ return false;
1781
+ ctx.seen.add(_schema);
1782
+ const def = _schema._zod.def;
1783
+ if (def.type === "transform")
1784
+ return true;
1785
+ if (def.type === "array")
1786
+ return isTransforming(def.element, ctx);
1787
+ if (def.type === "set")
1788
+ return isTransforming(def.valueType, ctx);
1789
+ if (def.type === "lazy")
1790
+ return isTransforming(def.getter(), ctx);
1791
+ if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") {
1792
+ return isTransforming(def.innerType, ctx);
1793
+ }
1794
+ if (def.type === "intersection") {
1795
+ return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
1796
+ }
1797
+ if (def.type === "record" || def.type === "map") {
1798
+ return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
1799
+ }
1800
+ if (def.type === "pipe") {
1801
+ if (_schema._zod.traits.has("$ZodCodec"))
1802
+ return true;
1803
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
1804
+ }
1805
+ if (def.type === "object") {
1806
+ for (const key in def.shape) {
1807
+ if (isTransforming(def.shape[key], ctx))
1808
+ return true;
1809
+ }
1810
+ return false;
1811
+ }
1812
+ if (def.type === "union") {
1813
+ for (const option of def.options) {
1814
+ if (isTransforming(option, ctx))
1815
+ return true;
1816
+ }
1817
+ return false;
1818
+ }
1819
+ if (def.type === "tuple") {
1820
+ for (const item of def.items) {
1821
+ if (isTransforming(item, ctx))
1822
+ return true;
1823
+ }
1824
+ if (def.rest && isTransforming(def.rest, ctx))
1825
+ return true;
1826
+ return false;
1827
+ }
1828
+ return false;
1829
+ }
1830
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
1831
+ const ctx = initializeContext({ ...params, processors });
1832
+ process(schema, ctx);
1833
+ extractDefs(ctx, schema);
1834
+ return finalize(ctx, schema);
1835
+ };
1836
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
1837
+ const { libraryOptions, target } = params ?? {};
1838
+ const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
1839
+ process(schema, ctx);
1840
+ extractDefs(ctx, schema);
1841
+ return finalize(ctx, schema);
1842
+ };
1843
+
1844
+ const customProcessor = (_schema, ctx, _json, _params) => {
1845
+ if (ctx.unrepresentable === "throw") {
1846
+ throw new Error("Custom types cannot be represented in JSON Schema");
1847
+ }
1848
+ };
1849
+ const transformProcessor = (_schema, ctx, _json, _params) => {
1850
+ if (ctx.unrepresentable === "throw") {
1851
+ throw new Error("Transforms cannot be represented in JSON Schema");
1852
+ }
1853
+ };
1854
+ const arrayProcessor = (schema, ctx, _json, params) => {
1855
+ const json = _json;
1856
+ const def = schema._zod.def;
1857
+ const { minimum, maximum } = schema._zod.bag;
1858
+ if (typeof minimum === "number")
1859
+ json.minItems = minimum;
1860
+ if (typeof maximum === "number")
1861
+ json.maxItems = maximum;
1862
+ json.type = "array";
1863
+ json.items = process(def.element, ctx, {
1864
+ ...params,
1865
+ path: [...params.path, "items"]
1866
+ });
1867
+ };
1868
+ const unionProcessor = (schema, ctx, json, params) => {
1869
+ const def = schema._zod.def;
1870
+ const isExclusive = def.inclusive === false;
1871
+ const options = def.options.map((x, i) => process(x, ctx, {
1872
+ ...params,
1873
+ path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
1874
+ }));
1875
+ if (isExclusive) {
1876
+ json.oneOf = options;
1877
+ } else {
1878
+ json.anyOf = options;
1879
+ }
1880
+ };
1881
+ const intersectionProcessor = (schema, ctx, json, params) => {
1882
+ const def = schema._zod.def;
1883
+ const a = process(def.left, ctx, {
1884
+ ...params,
1885
+ path: [...params.path, "allOf", 0]
1886
+ });
1887
+ const b = process(def.right, ctx, {
1888
+ ...params,
1889
+ path: [...params.path, "allOf", 1]
1890
+ });
1891
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
1892
+ const allOf = [
1893
+ ...isSimpleIntersection(a) ? a.allOf : [a],
1894
+ ...isSimpleIntersection(b) ? b.allOf : [b]
1895
+ ];
1896
+ json.allOf = allOf;
1897
+ };
1898
+ const nullableProcessor = (schema, ctx, json, params) => {
1899
+ const def = schema._zod.def;
1900
+ const inner = process(def.innerType, ctx, params);
1901
+ const seen = ctx.seen.get(schema);
1902
+ if (ctx.target === "openapi-3.0") {
1903
+ seen.ref = def.innerType;
1904
+ json.nullable = true;
1905
+ } else {
1906
+ json.anyOf = [inner, { type: "null" }];
1907
+ }
1908
+ };
1909
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
1910
+ const def = schema._zod.def;
1911
+ process(def.innerType, ctx, params);
1912
+ const seen = ctx.seen.get(schema);
1913
+ seen.ref = def.innerType;
1914
+ };
1915
+ const defaultProcessor = (schema, ctx, json, params) => {
1916
+ const def = schema._zod.def;
1917
+ process(def.innerType, ctx, params);
1918
+ const seen = ctx.seen.get(schema);
1919
+ seen.ref = def.innerType;
1920
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
1921
+ };
1922
+ const prefaultProcessor = (schema, ctx, json, params) => {
1923
+ const def = schema._zod.def;
1924
+ process(def.innerType, ctx, params);
1925
+ const seen = ctx.seen.get(schema);
1926
+ seen.ref = def.innerType;
1927
+ if (ctx.io === "input")
1928
+ json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
1929
+ };
1930
+ const catchProcessor = (schema, ctx, json, params) => {
1931
+ const def = schema._zod.def;
1932
+ process(def.innerType, ctx, params);
1933
+ const seen = ctx.seen.get(schema);
1934
+ seen.ref = def.innerType;
1935
+ let catchValue;
1936
+ try {
1937
+ catchValue = def.catchValue(void 0);
1938
+ } catch {
1939
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
1940
+ }
1941
+ json.default = catchValue;
1942
+ };
1943
+ const pipeProcessor = (schema, ctx, _json, params) => {
1944
+ const def = schema._zod.def;
1945
+ const inIsTransform = def.in._zod.traits.has("$ZodTransform");
1946
+ const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
1947
+ process(innerType, ctx, params);
1948
+ const seen = ctx.seen.get(schema);
1949
+ seen.ref = innerType;
1950
+ };
1951
+ const readonlyProcessor = (schema, ctx, json, params) => {
1952
+ const def = schema._zod.def;
1953
+ process(def.innerType, ctx, params);
1954
+ const seen = ctx.seen.get(schema);
1955
+ seen.ref = def.innerType;
1956
+ json.readOnly = true;
1957
+ };
1958
+ const optionalProcessor = (schema, ctx, _json, params) => {
1959
+ const def = schema._zod.def;
1960
+ process(def.innerType, ctx, params);
1961
+ const seen = ctx.seen.get(schema);
1962
+ seen.ref = def.innerType;
1963
+ };
1964
+
1965
+ const initializer = (inst, issues) => {
1966
+ $ZodError.init(inst, issues);
1967
+ inst.name = "ZodError";
1968
+ Object.defineProperties(inst, {
1969
+ format: {
1970
+ value: (mapper) => formatError(inst, mapper)
1971
+ // enumerable: false,
1972
+ },
1973
+ flatten: {
1974
+ value: (mapper) => flattenError(inst, mapper)
1975
+ // enumerable: false,
1976
+ },
1977
+ addIssue: {
1978
+ value: (issue) => {
1979
+ inst.issues.push(issue);
1980
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
1981
+ }
1982
+ // enumerable: false,
1983
+ },
1984
+ addIssues: {
1985
+ value: (issues2) => {
1986
+ inst.issues.push(...issues2);
1987
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
1988
+ }
1989
+ // enumerable: false,
1990
+ },
1991
+ isEmpty: {
1992
+ get() {
1993
+ return inst.issues.length === 0;
1994
+ }
1995
+ // enumerable: false,
1996
+ }
1997
+ });
1998
+ };
1999
+ const ZodRealError = /* @__PURE__ */ $constructor("ZodError", initializer, {
2000
+ Parent: Error
2001
+ });
2002
+
2003
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
2004
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
2005
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
2006
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
2007
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
2008
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
2009
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
2010
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
2011
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
2012
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
2013
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
2014
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
2015
+
2016
+ const _installedGroups = /* @__PURE__ */ new WeakMap();
2017
+ function _installLazyMethods(inst, group, methods) {
2018
+ const proto = Object.getPrototypeOf(inst);
2019
+ let installed = _installedGroups.get(proto);
2020
+ if (!installed) {
2021
+ installed = /* @__PURE__ */ new Set();
2022
+ _installedGroups.set(proto, installed);
2023
+ }
2024
+ if (installed.has(group))
2025
+ return;
2026
+ installed.add(group);
2027
+ for (const key in methods) {
2028
+ const fn = methods[key];
2029
+ Object.defineProperty(proto, key, {
2030
+ configurable: true,
2031
+ enumerable: false,
2032
+ get() {
2033
+ const bound = fn.bind(this);
2034
+ Object.defineProperty(this, key, {
2035
+ configurable: true,
2036
+ writable: true,
2037
+ enumerable: true,
2038
+ value: bound
2039
+ });
2040
+ return bound;
2041
+ },
2042
+ set(v) {
2043
+ Object.defineProperty(this, key, {
2044
+ configurable: true,
2045
+ writable: true,
2046
+ enumerable: true,
2047
+ value: v
2048
+ });
2049
+ }
2050
+ });
2051
+ }
2052
+ }
2053
+ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
2054
+ $ZodType.init(inst, def);
2055
+ Object.assign(inst["~standard"], {
2056
+ jsonSchema: {
2057
+ input: createStandardJSONSchemaMethod(inst, "input"),
2058
+ output: createStandardJSONSchemaMethod(inst, "output")
2059
+ }
2060
+ });
2061
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
2062
+ inst.def = def;
2063
+ inst.type = def.type;
2064
+ Object.defineProperty(inst, "_def", { value: def });
2065
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
2066
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
2067
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
2068
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
2069
+ inst.spa = inst.safeParseAsync;
2070
+ inst.encode = (data, params) => encode(inst, data, params);
2071
+ inst.decode = (data, params) => decode(inst, data, params);
2072
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
2073
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
2074
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
2075
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
2076
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
2077
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
2078
+ _installLazyMethods(inst, "ZodType", {
2079
+ check(...chks) {
2080
+ const def2 = this.def;
2081
+ return this.clone(mergeDefs(def2, {
2082
+ checks: [
2083
+ ...def2.checks ?? [],
2084
+ ...chks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch)
2085
+ ]
2086
+ }), { parent: true });
2087
+ },
2088
+ with(...chks) {
2089
+ return this.check(...chks);
2090
+ },
2091
+ clone(def2, params) {
2092
+ return clone(this, def2, params);
2093
+ },
2094
+ brand() {
2095
+ return this;
2096
+ },
2097
+ register(reg, meta2) {
2098
+ reg.add(this, meta2);
2099
+ return this;
2100
+ },
2101
+ refine(check2, params) {
2102
+ return this.check(refine(check2, params));
2103
+ },
2104
+ superRefine(refinement, params) {
2105
+ return this.check(superRefine(refinement, params));
2106
+ },
2107
+ overwrite(fn) {
2108
+ return this.check(_overwrite(fn));
2109
+ },
2110
+ optional() {
2111
+ return optional(this);
2112
+ },
2113
+ exactOptional() {
2114
+ return exactOptional(this);
2115
+ },
2116
+ nullable() {
2117
+ return nullable(this);
2118
+ },
2119
+ nullish() {
2120
+ return optional(nullable(this));
2121
+ },
2122
+ nonoptional(params) {
2123
+ return nonoptional(this, params);
2124
+ },
2125
+ array() {
2126
+ return array(this);
2127
+ },
2128
+ or(arg) {
2129
+ return union([this, arg]);
2130
+ },
2131
+ and(arg) {
2132
+ return intersection(this, arg);
2133
+ },
2134
+ transform(tx) {
2135
+ return pipe(this, transform(tx));
2136
+ },
2137
+ default(d) {
2138
+ return _default(this, d);
2139
+ },
2140
+ prefault(d) {
2141
+ return prefault(this, d);
2142
+ },
2143
+ catch(params) {
2144
+ return _catch(this, params);
2145
+ },
2146
+ pipe(target) {
2147
+ return pipe(this, target);
2148
+ },
2149
+ readonly() {
2150
+ return readonly(this);
2151
+ },
2152
+ describe(description) {
2153
+ const cl = this.clone();
2154
+ globalRegistry.add(cl, { description });
2155
+ return cl;
2156
+ },
2157
+ meta(...args) {
2158
+ if (args.length === 0)
2159
+ return globalRegistry.get(this);
2160
+ const cl = this.clone();
2161
+ globalRegistry.add(cl, args[0]);
2162
+ return cl;
2163
+ },
2164
+ isOptional() {
2165
+ return this.safeParse(void 0).success;
2166
+ },
2167
+ isNullable() {
2168
+ return this.safeParse(null).success;
2169
+ },
2170
+ apply(fn) {
2171
+ return fn(this);
2172
+ }
2173
+ });
2174
+ Object.defineProperty(inst, "description", {
2175
+ get() {
2176
+ return globalRegistry.get(inst)?.description;
2177
+ },
2178
+ configurable: true
2179
+ });
2180
+ return inst;
2181
+ });
2182
+ const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
2183
+ $ZodArray.init(inst, def);
2184
+ ZodType.init(inst, def);
2185
+ inst._zod.processJSONSchema = (ctx, json2, params) => arrayProcessor(inst, ctx, json2, params);
2186
+ inst.element = def.element;
2187
+ _installLazyMethods(inst, "ZodArray", {
2188
+ min(n, params) {
2189
+ return this.check(_minLength(n, params));
2190
+ },
2191
+ nonempty(params) {
2192
+ return this.check(_minLength(1, params));
2193
+ },
2194
+ max(n, params) {
2195
+ return this.check(_maxLength(n, params));
2196
+ },
2197
+ length(n, params) {
2198
+ return this.check(_length(n, params));
2199
+ },
2200
+ unwrap() {
2201
+ return this.element;
2202
+ }
2203
+ });
2204
+ });
2205
+ function array(element, params) {
2206
+ return _array(ZodArray, element, params);
2207
+ }
2208
+ const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
2209
+ $ZodUnion.init(inst, def);
2210
+ ZodType.init(inst, def);
2211
+ inst._zod.processJSONSchema = (ctx, json2, params) => unionProcessor(inst, ctx, json2, params);
2212
+ inst.options = def.options;
2213
+ });
2214
+ function union(options, params) {
2215
+ return new ZodUnion({
2216
+ type: "union",
2217
+ options,
2218
+ ...normalizeParams(params)
2219
+ });
2220
+ }
2221
+ const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
2222
+ $ZodIntersection.init(inst, def);
2223
+ ZodType.init(inst, def);
2224
+ inst._zod.processJSONSchema = (ctx, json2, params) => intersectionProcessor(inst, ctx, json2, params);
2225
+ });
2226
+ function intersection(left, right) {
2227
+ return new ZodIntersection({
2228
+ type: "intersection",
2229
+ left,
2230
+ right
2231
+ });
2232
+ }
2233
+ const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
2234
+ $ZodTransform.init(inst, def);
2235
+ ZodType.init(inst, def);
2236
+ inst._zod.processJSONSchema = (ctx, json2, params) => transformProcessor(inst, ctx);
2237
+ inst._zod.parse = (payload, _ctx) => {
2238
+ if (_ctx.direction === "backward") {
2239
+ throw new $ZodEncodeError(inst.constructor.name);
2240
+ }
2241
+ payload.addIssue = (issue$1) => {
2242
+ if (typeof issue$1 === "string") {
2243
+ payload.issues.push(issue(issue$1, payload.value, def));
2244
+ } else {
2245
+ const _issue = issue$1;
2246
+ if (_issue.fatal)
2247
+ _issue.continue = false;
2248
+ _issue.code ?? (_issue.code = "custom");
2249
+ _issue.input ?? (_issue.input = payload.value);
2250
+ _issue.inst ?? (_issue.inst = inst);
2251
+ payload.issues.push(issue(_issue));
2252
+ }
2253
+ };
2254
+ const output = def.transform(payload.value, payload);
2255
+ if (output instanceof Promise) {
2256
+ return output.then((output2) => {
2257
+ payload.value = output2;
2258
+ payload.fallback = true;
2259
+ return payload;
2260
+ });
2261
+ }
2262
+ payload.value = output;
2263
+ payload.fallback = true;
2264
+ return payload;
2265
+ };
2266
+ });
2267
+ function transform(fn) {
2268
+ return new ZodTransform({
2269
+ type: "transform",
2270
+ transform: fn
2271
+ });
2272
+ }
2273
+ const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
2274
+ $ZodOptional.init(inst, def);
2275
+ ZodType.init(inst, def);
2276
+ inst._zod.processJSONSchema = (ctx, json2, params) => optionalProcessor(inst, ctx, json2, params);
2277
+ inst.unwrap = () => inst._zod.def.innerType;
2278
+ });
2279
+ function optional(innerType) {
2280
+ return new ZodOptional({
2281
+ type: "optional",
2282
+ innerType
2283
+ });
2284
+ }
2285
+ const ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
2286
+ $ZodExactOptional.init(inst, def);
2287
+ ZodType.init(inst, def);
2288
+ inst._zod.processJSONSchema = (ctx, json2, params) => optionalProcessor(inst, ctx, json2, params);
2289
+ inst.unwrap = () => inst._zod.def.innerType;
2290
+ });
2291
+ function exactOptional(innerType) {
2292
+ return new ZodExactOptional({
2293
+ type: "optional",
2294
+ innerType
2295
+ });
2296
+ }
2297
+ const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
2298
+ $ZodNullable.init(inst, def);
2299
+ ZodType.init(inst, def);
2300
+ inst._zod.processJSONSchema = (ctx, json2, params) => nullableProcessor(inst, ctx, json2, params);
2301
+ inst.unwrap = () => inst._zod.def.innerType;
2302
+ });
2303
+ function nullable(innerType) {
2304
+ return new ZodNullable({
2305
+ type: "nullable",
2306
+ innerType
2307
+ });
2308
+ }
2309
+ const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
2310
+ $ZodDefault.init(inst, def);
2311
+ ZodType.init(inst, def);
2312
+ inst._zod.processJSONSchema = (ctx, json2, params) => defaultProcessor(inst, ctx, json2, params);
2313
+ inst.unwrap = () => inst._zod.def.innerType;
2314
+ inst.removeDefault = inst.unwrap;
2315
+ });
2316
+ function _default(innerType, defaultValue) {
2317
+ return new ZodDefault({
2318
+ type: "default",
2319
+ innerType,
2320
+ get defaultValue() {
2321
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
2322
+ }
2323
+ });
2324
+ }
2325
+ const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
2326
+ $ZodPrefault.init(inst, def);
2327
+ ZodType.init(inst, def);
2328
+ inst._zod.processJSONSchema = (ctx, json2, params) => prefaultProcessor(inst, ctx, json2, params);
2329
+ inst.unwrap = () => inst._zod.def.innerType;
2330
+ });
2331
+ function prefault(innerType, defaultValue) {
2332
+ return new ZodPrefault({
2333
+ type: "prefault",
2334
+ innerType,
2335
+ get defaultValue() {
2336
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
2337
+ }
2338
+ });
2339
+ }
2340
+ const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
2341
+ $ZodNonOptional.init(inst, def);
2342
+ ZodType.init(inst, def);
2343
+ inst._zod.processJSONSchema = (ctx, json2, params) => nonoptionalProcessor(inst, ctx, json2, params);
2344
+ inst.unwrap = () => inst._zod.def.innerType;
2345
+ });
2346
+ function nonoptional(innerType, params) {
2347
+ return new ZodNonOptional({
2348
+ type: "nonoptional",
2349
+ innerType,
2350
+ ...normalizeParams(params)
2351
+ });
2352
+ }
2353
+ const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
2354
+ $ZodCatch.init(inst, def);
2355
+ ZodType.init(inst, def);
2356
+ inst._zod.processJSONSchema = (ctx, json2, params) => catchProcessor(inst, ctx, json2, params);
2357
+ inst.unwrap = () => inst._zod.def.innerType;
2358
+ inst.removeCatch = inst.unwrap;
2359
+ });
2360
+ function _catch(innerType, catchValue) {
2361
+ return new ZodCatch({
2362
+ type: "catch",
2363
+ innerType,
2364
+ catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
2365
+ });
2366
+ }
2367
+ const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
2368
+ $ZodPipe.init(inst, def);
2369
+ ZodType.init(inst, def);
2370
+ inst._zod.processJSONSchema = (ctx, json2, params) => pipeProcessor(inst, ctx, json2, params);
2371
+ inst.in = def.in;
2372
+ inst.out = def.out;
2373
+ });
2374
+ function pipe(in_, out) {
2375
+ return new ZodPipe({
2376
+ type: "pipe",
2377
+ in: in_,
2378
+ out
2379
+ // ...util.normalizeParams(params),
2380
+ });
2381
+ }
2382
+ const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
2383
+ $ZodReadonly.init(inst, def);
2384
+ ZodType.init(inst, def);
2385
+ inst._zod.processJSONSchema = (ctx, json2, params) => readonlyProcessor(inst, ctx, json2, params);
2386
+ inst.unwrap = () => inst._zod.def.innerType;
2387
+ });
2388
+ function readonly(innerType) {
2389
+ return new ZodReadonly({
2390
+ type: "readonly",
2391
+ innerType
2392
+ });
2393
+ }
2394
+ const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
2395
+ $ZodCustom.init(inst, def);
2396
+ ZodType.init(inst, def);
2397
+ inst._zod.processJSONSchema = (ctx, json2, params) => customProcessor(inst, ctx);
2398
+ });
2399
+ function refine(fn, _params = {}) {
2400
+ return _refine(ZodCustom, fn, _params);
2401
+ }
2402
+ function superRefine(fn, params) {
2403
+ return _superRefine(fn, params);
2404
+ }
2405
+
2406
+ const UnsignedWebsiteProfileInput = union([
2407
+ UnsignedWebsiteProfile,
2408
+ UnsignedWebsiteProfileSet
2409
+ ]);
2410
+ async function signWsp(uwsp, privateKey, {
2411
+ alg = "ES256",
2412
+ issuedAt = /* @__PURE__ */ new Date(),
2413
+ expiredAt,
2414
+ integrityAlg = "sha256"
2415
+ }) {
2416
+ UnsignedWebsiteProfileInput.parse(uwsp);
2417
+ async function sign(item) {
2418
+ await fetchAndSetDigestSri(integrityAlg, item.credentialSubject.image);
2419
+ return await signJwtVc(item, privateKey, { alg, issuedAt, expiredAt });
2420
+ }
2421
+ if (Array.isArray(uwsp)) {
2422
+ const wsps = await Promise.all(uwsp.map(sign));
2423
+ return wsps;
2424
+ }
2425
+ const wsp = await sign(uwsp);
2426
+ return wsp;
2427
+ }
2428
+
2429
+ export { FetchFailed, IntegrityCalculationError, UnsignedWebsiteProfileInput, createDigestSri, createIntegrity, fetchAndSetDigestSri, fetchAndSetTargetIntegrity, fetchExternalResource, fetchHtmlContent, fetchTextContent, fetchVisibleTextContent, selectByCss, selectByIntegrity, signCa, signCp, signWsp };