@sekuire/sdk 0.1.5 → 0.1.7

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 (3) hide show
  1. package/dist/index.esm.js +3946 -35
  2. package/dist/index.js +3948 -37
  3. package/package.json +28 -20
package/dist/index.esm.js CHANGED
@@ -18,7 +18,6 @@ import * as path$4 from 'node:path';
18
18
  import * as https from 'https';
19
19
  import * as http from 'http';
20
20
  import { URL as URL$1 } from 'url';
21
- import { z } from 'zod';
22
21
 
23
22
  /**
24
23
  * 🛡️ Sekuire Compliance Enforcement System for TypeScript
@@ -6136,7 +6135,7 @@ const readEnv$1 = (env) => {
6136
6135
  };
6137
6136
 
6138
6137
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
6139
- var _BaseAnthropic_instances, _a$2, _BaseAnthropic_encoder, _BaseAnthropic_baseURLOverridden;
6138
+ var _BaseAnthropic_instances, _a$3, _BaseAnthropic_encoder, _BaseAnthropic_baseURLOverridden;
6140
6139
  const HUMAN_PROMPT = '\\n\\nHuman:';
6141
6140
  const AI_PROMPT = '\\n\\nAssistant:';
6142
6141
  /**
@@ -6170,7 +6169,7 @@ class BaseAnthropic {
6170
6169
  throw new AnthropicError("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n");
6171
6170
  }
6172
6171
  this.baseURL = options.baseURL;
6173
- this.timeout = options.timeout ?? _a$2.DEFAULT_TIMEOUT /* 10 minutes */;
6172
+ this.timeout = options.timeout ?? _a$3.DEFAULT_TIMEOUT /* 10 minutes */;
6174
6173
  this.logger = options.logger ?? console;
6175
6174
  const defaultLogLevel = 'warn';
6176
6175
  // Set default logLevel early so that we can log a warning in parseLogLevel.
@@ -6619,10 +6618,10 @@ class BaseAnthropic {
6619
6618
  }
6620
6619
  }
6621
6620
  }
6622
- _a$2 = BaseAnthropic, _BaseAnthropic_encoder = new WeakMap(), _BaseAnthropic_instances = new WeakSet(), _BaseAnthropic_baseURLOverridden = function _BaseAnthropic_baseURLOverridden() {
6621
+ _a$3 = BaseAnthropic, _BaseAnthropic_encoder = new WeakMap(), _BaseAnthropic_instances = new WeakSet(), _BaseAnthropic_baseURLOverridden = function _BaseAnthropic_baseURLOverridden() {
6623
6622
  return this.baseURL !== 'https://api.anthropic.com';
6624
6623
  };
6625
- BaseAnthropic.Anthropic = _a$2;
6624
+ BaseAnthropic.Anthropic = _a$3;
6626
6625
  BaseAnthropic.HUMAN_PROMPT = HUMAN_PROMPT;
6627
6626
  BaseAnthropic.AI_PROMPT = AI_PROMPT;
6628
6627
  BaseAnthropic.DEFAULT_TIMEOUT = 600000; // 10 minutes
@@ -9134,7 +9133,7 @@ const hex_table = /* @__PURE__ */ (() => {
9134
9133
  return array;
9135
9134
  })();
9136
9135
  const limit = 1024;
9137
- const encode = (str, _defaultEncoder, charset, _kind, format) => {
9136
+ const encode$1 = (str, _defaultEncoder, charset, _kind, format) => {
9138
9137
  // This code was originally written by Brian White for the io.js core querystring library.
9139
9138
  // It has been adapted here for stricter adherence to RFC 3986
9140
9139
  if (str.length === 0) {
@@ -9238,7 +9237,7 @@ const defaults = {
9238
9237
  delimiter: '&',
9239
9238
  encode: true,
9240
9239
  encodeDotInKeys: false,
9241
- encoder: encode,
9240
+ encoder: encode$1,
9242
9241
  encodeValuesOnly: false,
9243
9242
  format: default_format,
9244
9243
  formatter: default_formatter,
@@ -12565,7 +12564,7 @@ const readEnv = (env) => {
12565
12564
  return undefined;
12566
12565
  };
12567
12566
 
12568
- var _AssistantStream_instances, _a$1, _AssistantStream_events, _AssistantStream_runStepSnapshots, _AssistantStream_messageSnapshots, _AssistantStream_messageSnapshot, _AssistantStream_finalRun, _AssistantStream_currentContentIndex, _AssistantStream_currentContent, _AssistantStream_currentToolCallIndex, _AssistantStream_currentToolCall, _AssistantStream_currentEvent, _AssistantStream_currentRunSnapshot, _AssistantStream_currentRunStepSnapshot, _AssistantStream_addEvent, _AssistantStream_endRequest, _AssistantStream_handleMessage, _AssistantStream_handleRunStep, _AssistantStream_handleEvent, _AssistantStream_accumulateRunStep, _AssistantStream_accumulateMessage, _AssistantStream_accumulateContent, _AssistantStream_handleRun;
12567
+ var _AssistantStream_instances, _a$2, _AssistantStream_events, _AssistantStream_runStepSnapshots, _AssistantStream_messageSnapshots, _AssistantStream_messageSnapshot, _AssistantStream_finalRun, _AssistantStream_currentContentIndex, _AssistantStream_currentContent, _AssistantStream_currentToolCallIndex, _AssistantStream_currentToolCall, _AssistantStream_currentEvent, _AssistantStream_currentRunSnapshot, _AssistantStream_currentRunStepSnapshot, _AssistantStream_addEvent, _AssistantStream_endRequest, _AssistantStream_handleMessage, _AssistantStream_handleRunStep, _AssistantStream_handleEvent, _AssistantStream_accumulateRunStep, _AssistantStream_accumulateMessage, _AssistantStream_accumulateContent, _AssistantStream_handleRun;
12569
12568
  class AssistantStream extends EventStream {
12570
12569
  constructor() {
12571
12570
  super(...arguments);
@@ -12640,7 +12639,7 @@ class AssistantStream extends EventStream {
12640
12639
  };
12641
12640
  }
12642
12641
  static fromReadableStream(stream) {
12643
- const runner = new _a$1();
12642
+ const runner = new _a$2();
12644
12643
  runner._run(() => runner._fromReadableStream(stream));
12645
12644
  return runner;
12646
12645
  }
@@ -12666,7 +12665,7 @@ class AssistantStream extends EventStream {
12666
12665
  return stream.toReadableStream();
12667
12666
  }
12668
12667
  static createToolAssistantStream(runId, runs, params, options) {
12669
- const runner = new _a$1();
12668
+ const runner = new _a$2();
12670
12669
  runner._run(() => runner._runToolAssistantStream(runId, runs, params, {
12671
12670
  ...options,
12672
12671
  headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },
@@ -12695,7 +12694,7 @@ class AssistantStream extends EventStream {
12695
12694
  return this._addRun(__classPrivateFieldGet(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
12696
12695
  }
12697
12696
  static createThreadAssistantStream(params, thread, options) {
12698
- const runner = new _a$1();
12697
+ const runner = new _a$2();
12699
12698
  runner._run(() => runner._threadAssistantStream(params, thread, {
12700
12699
  ...options,
12701
12700
  headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },
@@ -12703,7 +12702,7 @@ class AssistantStream extends EventStream {
12703
12702
  return runner;
12704
12703
  }
12705
12704
  static createAssistantStream(threadId, runs, params, options) {
12706
- const runner = new _a$1();
12705
+ const runner = new _a$2();
12707
12706
  runner._run(() => runner._runAssistantStream(threadId, runs, params, {
12708
12707
  ...options,
12709
12708
  headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },
@@ -12845,7 +12844,7 @@ class AssistantStream extends EventStream {
12845
12844
  return await this._createToolAssistantStream(runs, runId, params, options);
12846
12845
  }
12847
12846
  }
12848
- _a$1 = AssistantStream, _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
12847
+ _a$2 = AssistantStream, _AssistantStream_addEvent = function _AssistantStream_addEvent(event) {
12849
12848
  if (this.ended)
12850
12849
  return;
12851
12850
  __classPrivateFieldSet(this, _AssistantStream_currentEvent, event);
@@ -13023,7 +13022,7 @@ _a$1 = AssistantStream, _AssistantStream_addEvent = function _AssistantStream_ad
13023
13022
  }
13024
13023
  let data = event.data;
13025
13024
  if (data.delta) {
13026
- const accumulated = _a$1.accumulateDelta(snapshot, data.delta);
13025
+ const accumulated = _a$2.accumulateDelta(snapshot, data.delta);
13027
13026
  __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = accumulated;
13028
13027
  }
13029
13028
  return __classPrivateFieldGet(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
@@ -13077,7 +13076,7 @@ _a$1 = AssistantStream, _AssistantStream_addEvent = function _AssistantStream_ad
13077
13076
  }
13078
13077
  throw Error('Tried to accumulate a non-message event');
13079
13078
  }, _AssistantStream_accumulateContent = function _AssistantStream_accumulateContent(contentElement, currentContent) {
13080
- return _a$1.accumulateDelta(currentContent, contentElement);
13079
+ return _a$2.accumulateDelta(currentContent, contentElement);
13081
13080
  }, _AssistantStream_handleRun = function _AssistantStream_handleRun(event) {
13082
13081
  __classPrivateFieldSet(this, _AssistantStream_currentRunSnapshot, event.data);
13083
13082
  switch (event.event) {
@@ -15286,7 +15285,7 @@ _Webhooks_instances = new WeakSet(), _Webhooks_validateSecret = function _Webhoo
15286
15285
  };
15287
15286
 
15288
15287
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
15289
- var _OpenAI_instances, _a, _OpenAI_encoder, _OpenAI_baseURLOverridden;
15288
+ var _OpenAI_instances, _a$1, _OpenAI_encoder, _OpenAI_baseURLOverridden;
15290
15289
  /**
15291
15290
  * API Client for interfacing with the OpenAI API.
15292
15291
  */
@@ -15346,7 +15345,7 @@ class OpenAI {
15346
15345
  throw new OpenAIError("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\n\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\n");
15347
15346
  }
15348
15347
  this.baseURL = options.baseURL;
15349
- this.timeout = options.timeout ?? _a.DEFAULT_TIMEOUT /* 10 minutes */;
15348
+ this.timeout = options.timeout ?? _a$1.DEFAULT_TIMEOUT /* 10 minutes */;
15350
15349
  this.logger = options.logger ?? console;
15351
15350
  const defaultLogLevel = 'warn';
15352
15351
  // Set default logLevel early so that we can log a warning in parseLogLevel.
@@ -15761,10 +15760,10 @@ class OpenAI {
15761
15760
  }
15762
15761
  }
15763
15762
  }
15764
- _a = OpenAI, _OpenAI_encoder = new WeakMap(), _OpenAI_instances = new WeakSet(), _OpenAI_baseURLOverridden = function _OpenAI_baseURLOverridden() {
15763
+ _a$1 = OpenAI, _OpenAI_encoder = new WeakMap(), _OpenAI_instances = new WeakSet(), _OpenAI_baseURLOverridden = function _OpenAI_baseURLOverridden() {
15765
15764
  return this.baseURL !== 'https://api.openai.com/v1';
15766
15765
  };
15767
- OpenAI.OpenAI = _a;
15766
+ OpenAI.OpenAI = _a$1;
15768
15767
  OpenAI.DEFAULT_TIMEOUT = 600000; // 10 minutes
15769
15768
  OpenAI.OpenAIError = OpenAIError;
15770
15769
  OpenAI.APIError = APIError;
@@ -16210,9 +16209,9 @@ function getDefaultExportFromCjs (x) {
16210
16209
 
16211
16210
  var main = {exports: {}};
16212
16211
 
16213
- var version$1 = "17.2.3";
16212
+ var version$2 = "17.2.3";
16214
16213
  var require$$4 = {
16215
- version: version$1};
16214
+ version: version$2};
16216
16215
 
16217
16216
  const fs = fs__default;
16218
16217
  const path = path__default;
@@ -16220,7 +16219,7 @@ const os = os__default;
16220
16219
  const crypto$1 = crypto__default;
16221
16220
  const packageJson = require$$4;
16222
16221
 
16223
- const version = packageJson.version;
16222
+ const version$1 = packageJson.version;
16224
16223
 
16225
16224
  // Array of tips to display randomly
16226
16225
  const TIPS = [
@@ -16265,7 +16264,7 @@ function dim (text) {
16265
16264
  const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
16266
16265
 
16267
16266
  // Parse src into an Object
16268
- function parse (src) {
16267
+ function parse$1 (src) {
16269
16268
  const obj = {};
16270
16269
 
16271
16270
  // Convert buffer to string
@@ -16347,15 +16346,15 @@ function _parseVault (options) {
16347
16346
  }
16348
16347
 
16349
16348
  function _warn (message) {
16350
- console.error(`[dotenv@${version}][WARN] ${message}`);
16349
+ console.error(`[dotenv@${version$1}][WARN] ${message}`);
16351
16350
  }
16352
16351
 
16353
16352
  function _debug (message) {
16354
- console.log(`[dotenv@${version}][DEBUG] ${message}`);
16353
+ console.log(`[dotenv@${version$1}][DEBUG] ${message}`);
16355
16354
  }
16356
16355
 
16357
16356
  function _log (message) {
16358
- console.log(`[dotenv@${version}] ${message}`);
16357
+ console.log(`[dotenv@${version$1}] ${message}`);
16359
16358
  }
16360
16359
 
16361
16360
  function _dotenvKey (options) {
@@ -16544,7 +16543,7 @@ function configDotenv (options) {
16544
16543
  }
16545
16544
 
16546
16545
  // Populates process.env from .env file
16547
- function config (options) {
16546
+ function config$1 (options) {
16548
16547
  // fallback to original dotenv if DOTENV_KEY is not set
16549
16548
  if (_dotenvKey(options).length === 0) {
16550
16549
  return DotenvModule.configDotenv(options)
@@ -16633,9 +16632,9 @@ const DotenvModule = {
16633
16632
  configDotenv,
16634
16633
  _configVault,
16635
16634
  _parseVault,
16636
- config,
16635
+ config: config$1,
16637
16636
  decrypt,
16638
- parse,
16637
+ parse: parse$1,
16639
16638
  populate
16640
16639
  };
16641
16640
 
@@ -20193,6 +20192,3918 @@ function createSekuireFastifyPlugin(server) {
20193
20192
  };
20194
20193
  }
20195
20194
 
20195
+ /** A special constant with type `never` */
20196
+ function $constructor(name, initializer, params) {
20197
+ function init(inst, def) {
20198
+ if (!inst._zod) {
20199
+ Object.defineProperty(inst, "_zod", {
20200
+ value: {
20201
+ def,
20202
+ constr: _,
20203
+ traits: new Set(),
20204
+ },
20205
+ enumerable: false,
20206
+ });
20207
+ }
20208
+ if (inst._zod.traits.has(name)) {
20209
+ return;
20210
+ }
20211
+ inst._zod.traits.add(name);
20212
+ initializer(inst, def);
20213
+ // support prototype modifications
20214
+ const proto = _.prototype;
20215
+ const keys = Object.keys(proto);
20216
+ for (let i = 0; i < keys.length; i++) {
20217
+ const k = keys[i];
20218
+ if (!(k in inst)) {
20219
+ inst[k] = proto[k].bind(inst);
20220
+ }
20221
+ }
20222
+ }
20223
+ // doesn't work if Parent has a constructor with arguments
20224
+ const Parent = params?.Parent ?? Object;
20225
+ class Definition extends Parent {
20226
+ }
20227
+ Object.defineProperty(Definition, "name", { value: name });
20228
+ function _(def) {
20229
+ var _a;
20230
+ const inst = params?.Parent ? new Definition() : this;
20231
+ init(inst, def);
20232
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
20233
+ for (const fn of inst._zod.deferred) {
20234
+ fn();
20235
+ }
20236
+ return inst;
20237
+ }
20238
+ Object.defineProperty(_, "init", { value: init });
20239
+ Object.defineProperty(_, Symbol.hasInstance, {
20240
+ value: (inst) => {
20241
+ if (params?.Parent && inst instanceof params.Parent)
20242
+ return true;
20243
+ return inst?._zod?.traits?.has(name);
20244
+ },
20245
+ });
20246
+ Object.defineProperty(_, "name", { value: name });
20247
+ return _;
20248
+ }
20249
+ class $ZodAsyncError extends Error {
20250
+ constructor() {
20251
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
20252
+ }
20253
+ }
20254
+ class $ZodEncodeError extends Error {
20255
+ constructor(name) {
20256
+ super(`Encountered unidirectional transform during encode: ${name}`);
20257
+ this.name = "ZodEncodeError";
20258
+ }
20259
+ }
20260
+ const globalConfig = {};
20261
+ function config(newConfig) {
20262
+ return globalConfig;
20263
+ }
20264
+
20265
+ // functions
20266
+ function getEnumValues(entries) {
20267
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
20268
+ const values = Object.entries(entries)
20269
+ .filter(([k, _]) => numericValues.indexOf(+k) === -1)
20270
+ .map(([_, v]) => v);
20271
+ return values;
20272
+ }
20273
+ function jsonStringifyReplacer(_, value) {
20274
+ if (typeof value === "bigint")
20275
+ return value.toString();
20276
+ return value;
20277
+ }
20278
+ function cached(getter) {
20279
+ return {
20280
+ get value() {
20281
+ {
20282
+ const value = getter();
20283
+ Object.defineProperty(this, "value", { value });
20284
+ return value;
20285
+ }
20286
+ },
20287
+ };
20288
+ }
20289
+ function nullish(input) {
20290
+ return input === null || input === undefined;
20291
+ }
20292
+ function cleanRegex(source) {
20293
+ const start = source.startsWith("^") ? 1 : 0;
20294
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
20295
+ return source.slice(start, end);
20296
+ }
20297
+ const EVALUATING = Symbol("evaluating");
20298
+ function defineLazy(object, key, getter) {
20299
+ let value = undefined;
20300
+ Object.defineProperty(object, key, {
20301
+ get() {
20302
+ if (value === EVALUATING) {
20303
+ // Circular reference detected, return undefined to break the cycle
20304
+ return undefined;
20305
+ }
20306
+ if (value === undefined) {
20307
+ value = EVALUATING;
20308
+ value = getter();
20309
+ }
20310
+ return value;
20311
+ },
20312
+ set(v) {
20313
+ Object.defineProperty(object, key, {
20314
+ value: v,
20315
+ // configurable: true,
20316
+ });
20317
+ // object[key] = v;
20318
+ },
20319
+ configurable: true,
20320
+ });
20321
+ }
20322
+ function assignProp(target, prop, value) {
20323
+ Object.defineProperty(target, prop, {
20324
+ value,
20325
+ writable: true,
20326
+ enumerable: true,
20327
+ configurable: true,
20328
+ });
20329
+ }
20330
+ function mergeDefs(...defs) {
20331
+ const mergedDescriptors = {};
20332
+ for (const def of defs) {
20333
+ const descriptors = Object.getOwnPropertyDescriptors(def);
20334
+ Object.assign(mergedDescriptors, descriptors);
20335
+ }
20336
+ return Object.defineProperties({}, mergedDescriptors);
20337
+ }
20338
+ function esc(str) {
20339
+ return JSON.stringify(str);
20340
+ }
20341
+ function slugify(input) {
20342
+ return input
20343
+ .toLowerCase()
20344
+ .trim()
20345
+ .replace(/[^\w\s-]/g, "")
20346
+ .replace(/[\s_-]+/g, "-")
20347
+ .replace(/^-+|-+$/g, "");
20348
+ }
20349
+ const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
20350
+ function isObject(data) {
20351
+ return typeof data === "object" && data !== null && !Array.isArray(data);
20352
+ }
20353
+ const allowsEval = cached(() => {
20354
+ // @ts-ignore
20355
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
20356
+ return false;
20357
+ }
20358
+ try {
20359
+ const F = Function;
20360
+ new F("");
20361
+ return true;
20362
+ }
20363
+ catch (_) {
20364
+ return false;
20365
+ }
20366
+ });
20367
+ function isPlainObject(o) {
20368
+ if (isObject(o) === false)
20369
+ return false;
20370
+ // modified constructor
20371
+ const ctor = o.constructor;
20372
+ if (ctor === undefined)
20373
+ return true;
20374
+ if (typeof ctor !== "function")
20375
+ return true;
20376
+ // modified prototype
20377
+ const prot = ctor.prototype;
20378
+ if (isObject(prot) === false)
20379
+ return false;
20380
+ // ctor doesn't have static `isPrototypeOf`
20381
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
20382
+ return false;
20383
+ }
20384
+ return true;
20385
+ }
20386
+ function shallowClone(o) {
20387
+ if (isPlainObject(o))
20388
+ return { ...o };
20389
+ if (Array.isArray(o))
20390
+ return [...o];
20391
+ return o;
20392
+ }
20393
+ const propertyKeyTypes = new Set(["string", "number", "symbol"]);
20394
+ function escapeRegex(str) {
20395
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20396
+ }
20397
+ // zod-specific utils
20398
+ function clone(inst, def, params) {
20399
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
20400
+ if (!def || params?.parent)
20401
+ cl._zod.parent = inst;
20402
+ return cl;
20403
+ }
20404
+ function normalizeParams(_params) {
20405
+ const params = _params;
20406
+ if (!params)
20407
+ return {};
20408
+ if (typeof params === "string")
20409
+ return { error: () => params };
20410
+ if (params?.message !== undefined) {
20411
+ if (params?.error !== undefined)
20412
+ throw new Error("Cannot specify both `message` and `error` params");
20413
+ params.error = params.message;
20414
+ }
20415
+ delete params.message;
20416
+ if (typeof params.error === "string")
20417
+ return { ...params, error: () => params.error };
20418
+ return params;
20419
+ }
20420
+ function optionalKeys(shape) {
20421
+ return Object.keys(shape).filter((k) => {
20422
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
20423
+ });
20424
+ }
20425
+ function pick(schema, mask) {
20426
+ const currDef = schema._zod.def;
20427
+ const def = mergeDefs(schema._zod.def, {
20428
+ get shape() {
20429
+ const newShape = {};
20430
+ for (const key in mask) {
20431
+ if (!(key in currDef.shape)) {
20432
+ throw new Error(`Unrecognized key: "${key}"`);
20433
+ }
20434
+ if (!mask[key])
20435
+ continue;
20436
+ newShape[key] = currDef.shape[key];
20437
+ }
20438
+ assignProp(this, "shape", newShape); // self-caching
20439
+ return newShape;
20440
+ },
20441
+ checks: [],
20442
+ });
20443
+ return clone(schema, def);
20444
+ }
20445
+ function omit(schema, mask) {
20446
+ const currDef = schema._zod.def;
20447
+ const def = mergeDefs(schema._zod.def, {
20448
+ get shape() {
20449
+ const newShape = { ...schema._zod.def.shape };
20450
+ for (const key in mask) {
20451
+ if (!(key in currDef.shape)) {
20452
+ throw new Error(`Unrecognized key: "${key}"`);
20453
+ }
20454
+ if (!mask[key])
20455
+ continue;
20456
+ delete newShape[key];
20457
+ }
20458
+ assignProp(this, "shape", newShape); // self-caching
20459
+ return newShape;
20460
+ },
20461
+ checks: [],
20462
+ });
20463
+ return clone(schema, def);
20464
+ }
20465
+ function extend(schema, shape) {
20466
+ if (!isPlainObject(shape)) {
20467
+ throw new Error("Invalid input to extend: expected a plain object");
20468
+ }
20469
+ const checks = schema._zod.def.checks;
20470
+ const hasChecks = checks && checks.length > 0;
20471
+ if (hasChecks) {
20472
+ throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
20473
+ }
20474
+ const def = mergeDefs(schema._zod.def, {
20475
+ get shape() {
20476
+ const _shape = { ...schema._zod.def.shape, ...shape };
20477
+ assignProp(this, "shape", _shape); // self-caching
20478
+ return _shape;
20479
+ },
20480
+ checks: [],
20481
+ });
20482
+ return clone(schema, def);
20483
+ }
20484
+ function safeExtend(schema, shape) {
20485
+ if (!isPlainObject(shape)) {
20486
+ throw new Error("Invalid input to safeExtend: expected a plain object");
20487
+ }
20488
+ const def = {
20489
+ ...schema._zod.def,
20490
+ get shape() {
20491
+ const _shape = { ...schema._zod.def.shape, ...shape };
20492
+ assignProp(this, "shape", _shape); // self-caching
20493
+ return _shape;
20494
+ },
20495
+ checks: schema._zod.def.checks,
20496
+ };
20497
+ return clone(schema, def);
20498
+ }
20499
+ function merge(a, b) {
20500
+ const def = mergeDefs(a._zod.def, {
20501
+ get shape() {
20502
+ const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
20503
+ assignProp(this, "shape", _shape); // self-caching
20504
+ return _shape;
20505
+ },
20506
+ get catchall() {
20507
+ return b._zod.def.catchall;
20508
+ },
20509
+ checks: [], // delete existing checks
20510
+ });
20511
+ return clone(a, def);
20512
+ }
20513
+ function partial(Class, schema, mask) {
20514
+ const def = mergeDefs(schema._zod.def, {
20515
+ get shape() {
20516
+ const oldShape = schema._zod.def.shape;
20517
+ const shape = { ...oldShape };
20518
+ if (mask) {
20519
+ for (const key in mask) {
20520
+ if (!(key in oldShape)) {
20521
+ throw new Error(`Unrecognized key: "${key}"`);
20522
+ }
20523
+ if (!mask[key])
20524
+ continue;
20525
+ // if (oldShape[key]!._zod.optin === "optional") continue;
20526
+ shape[key] = Class
20527
+ ? new Class({
20528
+ type: "optional",
20529
+ innerType: oldShape[key],
20530
+ })
20531
+ : oldShape[key];
20532
+ }
20533
+ }
20534
+ else {
20535
+ for (const key in oldShape) {
20536
+ // if (oldShape[key]!._zod.optin === "optional") continue;
20537
+ shape[key] = Class
20538
+ ? new Class({
20539
+ type: "optional",
20540
+ innerType: oldShape[key],
20541
+ })
20542
+ : oldShape[key];
20543
+ }
20544
+ }
20545
+ assignProp(this, "shape", shape); // self-caching
20546
+ return shape;
20547
+ },
20548
+ checks: [],
20549
+ });
20550
+ return clone(schema, def);
20551
+ }
20552
+ function required(Class, schema, mask) {
20553
+ const def = mergeDefs(schema._zod.def, {
20554
+ get shape() {
20555
+ const oldShape = schema._zod.def.shape;
20556
+ const shape = { ...oldShape };
20557
+ if (mask) {
20558
+ for (const key in mask) {
20559
+ if (!(key in shape)) {
20560
+ throw new Error(`Unrecognized key: "${key}"`);
20561
+ }
20562
+ if (!mask[key])
20563
+ continue;
20564
+ // overwrite with non-optional
20565
+ shape[key] = new Class({
20566
+ type: "nonoptional",
20567
+ innerType: oldShape[key],
20568
+ });
20569
+ }
20570
+ }
20571
+ else {
20572
+ for (const key in oldShape) {
20573
+ // overwrite with non-optional
20574
+ shape[key] = new Class({
20575
+ type: "nonoptional",
20576
+ innerType: oldShape[key],
20577
+ });
20578
+ }
20579
+ }
20580
+ assignProp(this, "shape", shape); // self-caching
20581
+ return shape;
20582
+ },
20583
+ checks: [],
20584
+ });
20585
+ return clone(schema, def);
20586
+ }
20587
+ // invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
20588
+ function aborted(x, startIndex = 0) {
20589
+ if (x.aborted === true)
20590
+ return true;
20591
+ for (let i = startIndex; i < x.issues.length; i++) {
20592
+ if (x.issues[i]?.continue !== true) {
20593
+ return true;
20594
+ }
20595
+ }
20596
+ return false;
20597
+ }
20598
+ function prefixIssues(path, issues) {
20599
+ return issues.map((iss) => {
20600
+ var _a;
20601
+ (_a = iss).path ?? (_a.path = []);
20602
+ iss.path.unshift(path);
20603
+ return iss;
20604
+ });
20605
+ }
20606
+ function unwrapMessage(message) {
20607
+ return typeof message === "string" ? message : message?.message;
20608
+ }
20609
+ function finalizeIssue(iss, ctx, config) {
20610
+ const full = { ...iss, path: iss.path ?? [] };
20611
+ // for backwards compatibility
20612
+ if (!iss.message) {
20613
+ const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
20614
+ unwrapMessage(ctx?.error?.(iss)) ??
20615
+ unwrapMessage(config.customError?.(iss)) ??
20616
+ unwrapMessage(config.localeError?.(iss)) ??
20617
+ "Invalid input";
20618
+ full.message = message;
20619
+ }
20620
+ // delete (full as any).def;
20621
+ delete full.inst;
20622
+ delete full.continue;
20623
+ if (!ctx?.reportInput) {
20624
+ delete full.input;
20625
+ }
20626
+ return full;
20627
+ }
20628
+ function getLengthableOrigin(input) {
20629
+ if (Array.isArray(input))
20630
+ return "array";
20631
+ if (typeof input === "string")
20632
+ return "string";
20633
+ return "unknown";
20634
+ }
20635
+ function issue(...args) {
20636
+ const [iss, input, inst] = args;
20637
+ if (typeof iss === "string") {
20638
+ return {
20639
+ message: iss,
20640
+ code: "custom",
20641
+ input,
20642
+ inst,
20643
+ };
20644
+ }
20645
+ return { ...iss };
20646
+ }
20647
+
20648
+ const initializer$1 = (inst, def) => {
20649
+ inst.name = "$ZodError";
20650
+ Object.defineProperty(inst, "_zod", {
20651
+ value: inst._zod,
20652
+ enumerable: false,
20653
+ });
20654
+ Object.defineProperty(inst, "issues", {
20655
+ value: def,
20656
+ enumerable: false,
20657
+ });
20658
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
20659
+ Object.defineProperty(inst, "toString", {
20660
+ value: () => inst.message,
20661
+ enumerable: false,
20662
+ });
20663
+ };
20664
+ const $ZodError = $constructor("$ZodError", initializer$1);
20665
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
20666
+ function flattenError(error, mapper = (issue) => issue.message) {
20667
+ const fieldErrors = {};
20668
+ const formErrors = [];
20669
+ for (const sub of error.issues) {
20670
+ if (sub.path.length > 0) {
20671
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
20672
+ fieldErrors[sub.path[0]].push(mapper(sub));
20673
+ }
20674
+ else {
20675
+ formErrors.push(mapper(sub));
20676
+ }
20677
+ }
20678
+ return { formErrors, fieldErrors };
20679
+ }
20680
+ function formatError(error, mapper = (issue) => issue.message) {
20681
+ const fieldErrors = { _errors: [] };
20682
+ const processError = (error) => {
20683
+ for (const issue of error.issues) {
20684
+ if (issue.code === "invalid_union" && issue.errors.length) {
20685
+ issue.errors.map((issues) => processError({ issues }));
20686
+ }
20687
+ else if (issue.code === "invalid_key") {
20688
+ processError({ issues: issue.issues });
20689
+ }
20690
+ else if (issue.code === "invalid_element") {
20691
+ processError({ issues: issue.issues });
20692
+ }
20693
+ else if (issue.path.length === 0) {
20694
+ fieldErrors._errors.push(mapper(issue));
20695
+ }
20696
+ else {
20697
+ let curr = fieldErrors;
20698
+ let i = 0;
20699
+ while (i < issue.path.length) {
20700
+ const el = issue.path[i];
20701
+ const terminal = i === issue.path.length - 1;
20702
+ if (!terminal) {
20703
+ curr[el] = curr[el] || { _errors: [] };
20704
+ }
20705
+ else {
20706
+ curr[el] = curr[el] || { _errors: [] };
20707
+ curr[el]._errors.push(mapper(issue));
20708
+ }
20709
+ curr = curr[el];
20710
+ i++;
20711
+ }
20712
+ }
20713
+ }
20714
+ };
20715
+ processError(error);
20716
+ return fieldErrors;
20717
+ }
20718
+
20719
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
20720
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
20721
+ const result = schema._zod.run({ value, issues: [] }, ctx);
20722
+ if (result instanceof Promise) {
20723
+ throw new $ZodAsyncError();
20724
+ }
20725
+ if (result.issues.length) {
20726
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
20727
+ captureStackTrace(e, _params?.callee);
20728
+ throw e;
20729
+ }
20730
+ return result.value;
20731
+ };
20732
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
20733
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
20734
+ let result = schema._zod.run({ value, issues: [] }, ctx);
20735
+ if (result instanceof Promise)
20736
+ result = await result;
20737
+ if (result.issues.length) {
20738
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
20739
+ captureStackTrace(e, params?.callee);
20740
+ throw e;
20741
+ }
20742
+ return result.value;
20743
+ };
20744
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
20745
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
20746
+ const result = schema._zod.run({ value, issues: [] }, ctx);
20747
+ if (result instanceof Promise) {
20748
+ throw new $ZodAsyncError();
20749
+ }
20750
+ return result.issues.length
20751
+ ? {
20752
+ success: false,
20753
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
20754
+ }
20755
+ : { success: true, data: result.value };
20756
+ };
20757
+ const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
20758
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
20759
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
20760
+ let result = schema._zod.run({ value, issues: [] }, ctx);
20761
+ if (result instanceof Promise)
20762
+ result = await result;
20763
+ return result.issues.length
20764
+ ? {
20765
+ success: false,
20766
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
20767
+ }
20768
+ : { success: true, data: result.value };
20769
+ };
20770
+ const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
20771
+ const _encode = (_Err) => (schema, value, _ctx) => {
20772
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
20773
+ return _parse(_Err)(schema, value, ctx);
20774
+ };
20775
+ const _decode = (_Err) => (schema, value, _ctx) => {
20776
+ return _parse(_Err)(schema, value, _ctx);
20777
+ };
20778
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
20779
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
20780
+ return _parseAsync(_Err)(schema, value, ctx);
20781
+ };
20782
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
20783
+ return _parseAsync(_Err)(schema, value, _ctx);
20784
+ };
20785
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
20786
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
20787
+ return _safeParse(_Err)(schema, value, ctx);
20788
+ };
20789
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
20790
+ return _safeParse(_Err)(schema, value, _ctx);
20791
+ };
20792
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
20793
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
20794
+ return _safeParseAsync(_Err)(schema, value, ctx);
20795
+ };
20796
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
20797
+ return _safeParseAsync(_Err)(schema, value, _ctx);
20798
+ };
20799
+
20800
+ const cuid = /^[cC][^\s-]{8,}$/;
20801
+ const cuid2 = /^[0-9a-z]+$/;
20802
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
20803
+ const xid = /^[0-9a-vA-V]{20}$/;
20804
+ const ksuid = /^[A-Za-z0-9]{27}$/;
20805
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
20806
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
20807
+ const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
20808
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
20809
+ const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
20810
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
20811
+ *
20812
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
20813
+ const uuid = (version) => {
20814
+ if (!version)
20815
+ return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
20816
+ return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
20817
+ };
20818
+ /** Practical email validation */
20819
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
20820
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
20821
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
20822
+ function emoji() {
20823
+ return new RegExp(_emoji$1, "u");
20824
+ }
20825
+ const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
20826
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
20827
+ const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
20828
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
20829
+ // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
20830
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
20831
+ const base64url = /^[A-Za-z0-9_-]*$/;
20832
+ // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
20833
+ const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
20834
+ // const dateSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
20835
+ const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
20836
+ const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
20837
+ function timeSource(args) {
20838
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
20839
+ const regex = typeof args.precision === "number"
20840
+ ? args.precision === -1
20841
+ ? `${hhmm}`
20842
+ : args.precision === 0
20843
+ ? `${hhmm}:[0-5]\\d`
20844
+ : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
20845
+ : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
20846
+ return regex;
20847
+ }
20848
+ function time$1(args) {
20849
+ return new RegExp(`^${timeSource(args)}$`);
20850
+ }
20851
+ // Adapted from https://stackoverflow.com/a/3143231
20852
+ function datetime$1(args) {
20853
+ const time = timeSource({ precision: args.precision });
20854
+ const opts = ["Z"];
20855
+ if (args.local)
20856
+ opts.push("");
20857
+ // if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
20858
+ if (args.offset)
20859
+ opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
20860
+ const timeRegex = `${time}(?:${opts.join("|")})`;
20861
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
20862
+ }
20863
+ const string$1 = (params) => {
20864
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
20865
+ return new RegExp(`^${regex}$`);
20866
+ };
20867
+ // regex for string with no uppercase letters
20868
+ const lowercase = /^[^A-Z]*$/;
20869
+ // regex for string with no lowercase letters
20870
+ const uppercase = /^[^a-z]*$/;
20871
+
20872
+ // import { $ZodType } from "./schemas.js";
20873
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
20874
+ var _a;
20875
+ inst._zod ?? (inst._zod = {});
20876
+ inst._zod.def = def;
20877
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
20878
+ });
20879
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
20880
+ var _a;
20881
+ $ZodCheck.init(inst, def);
20882
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
20883
+ const val = payload.value;
20884
+ return !nullish(val) && val.length !== undefined;
20885
+ });
20886
+ inst._zod.onattach.push((inst) => {
20887
+ const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
20888
+ if (def.maximum < curr)
20889
+ inst._zod.bag.maximum = def.maximum;
20890
+ });
20891
+ inst._zod.check = (payload) => {
20892
+ const input = payload.value;
20893
+ const length = input.length;
20894
+ if (length <= def.maximum)
20895
+ return;
20896
+ const origin = getLengthableOrigin(input);
20897
+ payload.issues.push({
20898
+ origin,
20899
+ code: "too_big",
20900
+ maximum: def.maximum,
20901
+ inclusive: true,
20902
+ input,
20903
+ inst,
20904
+ continue: !def.abort,
20905
+ });
20906
+ };
20907
+ });
20908
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
20909
+ var _a;
20910
+ $ZodCheck.init(inst, def);
20911
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
20912
+ const val = payload.value;
20913
+ return !nullish(val) && val.length !== undefined;
20914
+ });
20915
+ inst._zod.onattach.push((inst) => {
20916
+ const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
20917
+ if (def.minimum > curr)
20918
+ inst._zod.bag.minimum = def.minimum;
20919
+ });
20920
+ inst._zod.check = (payload) => {
20921
+ const input = payload.value;
20922
+ const length = input.length;
20923
+ if (length >= def.minimum)
20924
+ return;
20925
+ const origin = getLengthableOrigin(input);
20926
+ payload.issues.push({
20927
+ origin,
20928
+ code: "too_small",
20929
+ minimum: def.minimum,
20930
+ inclusive: true,
20931
+ input,
20932
+ inst,
20933
+ continue: !def.abort,
20934
+ });
20935
+ };
20936
+ });
20937
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
20938
+ var _a;
20939
+ $ZodCheck.init(inst, def);
20940
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
20941
+ const val = payload.value;
20942
+ return !nullish(val) && val.length !== undefined;
20943
+ });
20944
+ inst._zod.onattach.push((inst) => {
20945
+ const bag = inst._zod.bag;
20946
+ bag.minimum = def.length;
20947
+ bag.maximum = def.length;
20948
+ bag.length = def.length;
20949
+ });
20950
+ inst._zod.check = (payload) => {
20951
+ const input = payload.value;
20952
+ const length = input.length;
20953
+ if (length === def.length)
20954
+ return;
20955
+ const origin = getLengthableOrigin(input);
20956
+ const tooBig = length > def.length;
20957
+ payload.issues.push({
20958
+ origin,
20959
+ ...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
20960
+ inclusive: true,
20961
+ exact: true,
20962
+ input: payload.value,
20963
+ inst,
20964
+ continue: !def.abort,
20965
+ });
20966
+ };
20967
+ });
20968
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
20969
+ var _a, _b;
20970
+ $ZodCheck.init(inst, def);
20971
+ inst._zod.onattach.push((inst) => {
20972
+ const bag = inst._zod.bag;
20973
+ bag.format = def.format;
20974
+ if (def.pattern) {
20975
+ bag.patterns ?? (bag.patterns = new Set());
20976
+ bag.patterns.add(def.pattern);
20977
+ }
20978
+ });
20979
+ if (def.pattern)
20980
+ (_a = inst._zod).check ?? (_a.check = (payload) => {
20981
+ def.pattern.lastIndex = 0;
20982
+ if (def.pattern.test(payload.value))
20983
+ return;
20984
+ payload.issues.push({
20985
+ origin: "string",
20986
+ code: "invalid_format",
20987
+ format: def.format,
20988
+ input: payload.value,
20989
+ ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
20990
+ inst,
20991
+ continue: !def.abort,
20992
+ });
20993
+ });
20994
+ else
20995
+ (_b = inst._zod).check ?? (_b.check = () => { });
20996
+ });
20997
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
20998
+ $ZodCheckStringFormat.init(inst, def);
20999
+ inst._zod.check = (payload) => {
21000
+ def.pattern.lastIndex = 0;
21001
+ if (def.pattern.test(payload.value))
21002
+ return;
21003
+ payload.issues.push({
21004
+ origin: "string",
21005
+ code: "invalid_format",
21006
+ format: "regex",
21007
+ input: payload.value,
21008
+ pattern: def.pattern.toString(),
21009
+ inst,
21010
+ continue: !def.abort,
21011
+ });
21012
+ };
21013
+ });
21014
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
21015
+ def.pattern ?? (def.pattern = lowercase);
21016
+ $ZodCheckStringFormat.init(inst, def);
21017
+ });
21018
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
21019
+ def.pattern ?? (def.pattern = uppercase);
21020
+ $ZodCheckStringFormat.init(inst, def);
21021
+ });
21022
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
21023
+ $ZodCheck.init(inst, def);
21024
+ const escapedRegex = escapeRegex(def.includes);
21025
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
21026
+ def.pattern = pattern;
21027
+ inst._zod.onattach.push((inst) => {
21028
+ const bag = inst._zod.bag;
21029
+ bag.patterns ?? (bag.patterns = new Set());
21030
+ bag.patterns.add(pattern);
21031
+ });
21032
+ inst._zod.check = (payload) => {
21033
+ if (payload.value.includes(def.includes, def.position))
21034
+ return;
21035
+ payload.issues.push({
21036
+ origin: "string",
21037
+ code: "invalid_format",
21038
+ format: "includes",
21039
+ includes: def.includes,
21040
+ input: payload.value,
21041
+ inst,
21042
+ continue: !def.abort,
21043
+ });
21044
+ };
21045
+ });
21046
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
21047
+ $ZodCheck.init(inst, def);
21048
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
21049
+ def.pattern ?? (def.pattern = pattern);
21050
+ inst._zod.onattach.push((inst) => {
21051
+ const bag = inst._zod.bag;
21052
+ bag.patterns ?? (bag.patterns = new Set());
21053
+ bag.patterns.add(pattern);
21054
+ });
21055
+ inst._zod.check = (payload) => {
21056
+ if (payload.value.startsWith(def.prefix))
21057
+ return;
21058
+ payload.issues.push({
21059
+ origin: "string",
21060
+ code: "invalid_format",
21061
+ format: "starts_with",
21062
+ prefix: def.prefix,
21063
+ input: payload.value,
21064
+ inst,
21065
+ continue: !def.abort,
21066
+ });
21067
+ };
21068
+ });
21069
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
21070
+ $ZodCheck.init(inst, def);
21071
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
21072
+ def.pattern ?? (def.pattern = pattern);
21073
+ inst._zod.onattach.push((inst) => {
21074
+ const bag = inst._zod.bag;
21075
+ bag.patterns ?? (bag.patterns = new Set());
21076
+ bag.patterns.add(pattern);
21077
+ });
21078
+ inst._zod.check = (payload) => {
21079
+ if (payload.value.endsWith(def.suffix))
21080
+ return;
21081
+ payload.issues.push({
21082
+ origin: "string",
21083
+ code: "invalid_format",
21084
+ format: "ends_with",
21085
+ suffix: def.suffix,
21086
+ input: payload.value,
21087
+ inst,
21088
+ continue: !def.abort,
21089
+ });
21090
+ };
21091
+ });
21092
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
21093
+ $ZodCheck.init(inst, def);
21094
+ inst._zod.check = (payload) => {
21095
+ payload.value = def.tx(payload.value);
21096
+ };
21097
+ });
21098
+
21099
+ class Doc {
21100
+ constructor(args = []) {
21101
+ this.content = [];
21102
+ this.indent = 0;
21103
+ if (this)
21104
+ this.args = args;
21105
+ }
21106
+ indented(fn) {
21107
+ this.indent += 1;
21108
+ fn(this);
21109
+ this.indent -= 1;
21110
+ }
21111
+ write(arg) {
21112
+ if (typeof arg === "function") {
21113
+ arg(this, { execution: "sync" });
21114
+ arg(this, { execution: "async" });
21115
+ return;
21116
+ }
21117
+ const content = arg;
21118
+ const lines = content.split("\n").filter((x) => x);
21119
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
21120
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
21121
+ for (const line of dedented) {
21122
+ this.content.push(line);
21123
+ }
21124
+ }
21125
+ compile() {
21126
+ const F = Function;
21127
+ const args = this?.args;
21128
+ const content = this?.content ?? [``];
21129
+ const lines = [...content.map((x) => ` ${x}`)];
21130
+ // console.log(lines.join("\n"));
21131
+ return new F(...args, lines.join("\n"));
21132
+ }
21133
+ }
21134
+
21135
+ const version = {
21136
+ major: 4,
21137
+ minor: 2,
21138
+ patch: 1,
21139
+ };
21140
+
21141
+ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
21142
+ var _a;
21143
+ inst ?? (inst = {});
21144
+ inst._zod.def = def; // set _def property
21145
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
21146
+ inst._zod.version = version;
21147
+ const checks = [...(inst._zod.def.checks ?? [])];
21148
+ // if inst is itself a checks.$ZodCheck, run it as a check
21149
+ if (inst._zod.traits.has("$ZodCheck")) {
21150
+ checks.unshift(inst);
21151
+ }
21152
+ for (const ch of checks) {
21153
+ for (const fn of ch._zod.onattach) {
21154
+ fn(inst);
21155
+ }
21156
+ }
21157
+ if (checks.length === 0) {
21158
+ // deferred initializer
21159
+ // inst._zod.parse is not yet defined
21160
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
21161
+ inst._zod.deferred?.push(() => {
21162
+ inst._zod.run = inst._zod.parse;
21163
+ });
21164
+ }
21165
+ else {
21166
+ const runChecks = (payload, checks, ctx) => {
21167
+ let isAborted = aborted(payload);
21168
+ let asyncResult;
21169
+ for (const ch of checks) {
21170
+ if (ch._zod.def.when) {
21171
+ const shouldRun = ch._zod.def.when(payload);
21172
+ if (!shouldRun)
21173
+ continue;
21174
+ }
21175
+ else if (isAborted) {
21176
+ continue;
21177
+ }
21178
+ const currLen = payload.issues.length;
21179
+ const _ = ch._zod.check(payload);
21180
+ if (_ instanceof Promise && ctx?.async === false) {
21181
+ throw new $ZodAsyncError();
21182
+ }
21183
+ if (asyncResult || _ instanceof Promise) {
21184
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
21185
+ await _;
21186
+ const nextLen = payload.issues.length;
21187
+ if (nextLen === currLen)
21188
+ return;
21189
+ if (!isAborted)
21190
+ isAborted = aborted(payload, currLen);
21191
+ });
21192
+ }
21193
+ else {
21194
+ const nextLen = payload.issues.length;
21195
+ if (nextLen === currLen)
21196
+ continue;
21197
+ if (!isAborted)
21198
+ isAborted = aborted(payload, currLen);
21199
+ }
21200
+ }
21201
+ if (asyncResult) {
21202
+ return asyncResult.then(() => {
21203
+ return payload;
21204
+ });
21205
+ }
21206
+ return payload;
21207
+ };
21208
+ const handleCanaryResult = (canary, payload, ctx) => {
21209
+ // abort if the canary is aborted
21210
+ if (aborted(canary)) {
21211
+ canary.aborted = true;
21212
+ return canary;
21213
+ }
21214
+ // run checks first, then
21215
+ const checkResult = runChecks(payload, checks, ctx);
21216
+ if (checkResult instanceof Promise) {
21217
+ if (ctx.async === false)
21218
+ throw new $ZodAsyncError();
21219
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
21220
+ }
21221
+ return inst._zod.parse(checkResult, ctx);
21222
+ };
21223
+ inst._zod.run = (payload, ctx) => {
21224
+ if (ctx.skipChecks) {
21225
+ return inst._zod.parse(payload, ctx);
21226
+ }
21227
+ if (ctx.direction === "backward") {
21228
+ // run canary
21229
+ // initial pass (no checks)
21230
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
21231
+ if (canary instanceof Promise) {
21232
+ return canary.then((canary) => {
21233
+ return handleCanaryResult(canary, payload, ctx);
21234
+ });
21235
+ }
21236
+ return handleCanaryResult(canary, payload, ctx);
21237
+ }
21238
+ // forward
21239
+ const result = inst._zod.parse(payload, ctx);
21240
+ if (result instanceof Promise) {
21241
+ if (ctx.async === false)
21242
+ throw new $ZodAsyncError();
21243
+ return result.then((result) => runChecks(result, checks, ctx));
21244
+ }
21245
+ return runChecks(result, checks, ctx);
21246
+ };
21247
+ }
21248
+ inst["~standard"] = {
21249
+ validate: (value) => {
21250
+ try {
21251
+ const r = safeParse$1(inst, value);
21252
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
21253
+ }
21254
+ catch (_) {
21255
+ return safeParseAsync$1(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
21256
+ }
21257
+ },
21258
+ vendor: "zod",
21259
+ version: 1,
21260
+ };
21261
+ });
21262
+ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
21263
+ $ZodType.init(inst, def);
21264
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? string$1(inst._zod.bag);
21265
+ inst._zod.parse = (payload, _) => {
21266
+ if (def.coerce)
21267
+ try {
21268
+ payload.value = String(payload.value);
21269
+ }
21270
+ catch (_) { }
21271
+ if (typeof payload.value === "string")
21272
+ return payload;
21273
+ payload.issues.push({
21274
+ expected: "string",
21275
+ code: "invalid_type",
21276
+ input: payload.value,
21277
+ inst,
21278
+ });
21279
+ return payload;
21280
+ };
21281
+ });
21282
+ const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
21283
+ // check initialization must come first
21284
+ $ZodCheckStringFormat.init(inst, def);
21285
+ $ZodString.init(inst, def);
21286
+ });
21287
+ const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
21288
+ def.pattern ?? (def.pattern = guid);
21289
+ $ZodStringFormat.init(inst, def);
21290
+ });
21291
+ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
21292
+ if (def.version) {
21293
+ const versionMap = {
21294
+ v1: 1,
21295
+ v2: 2,
21296
+ v3: 3,
21297
+ v4: 4,
21298
+ v5: 5,
21299
+ v6: 6,
21300
+ v7: 7,
21301
+ v8: 8,
21302
+ };
21303
+ const v = versionMap[def.version];
21304
+ if (v === undefined)
21305
+ throw new Error(`Invalid UUID version: "${def.version}"`);
21306
+ def.pattern ?? (def.pattern = uuid(v));
21307
+ }
21308
+ else
21309
+ def.pattern ?? (def.pattern = uuid());
21310
+ $ZodStringFormat.init(inst, def);
21311
+ });
21312
+ const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
21313
+ def.pattern ?? (def.pattern = email);
21314
+ $ZodStringFormat.init(inst, def);
21315
+ });
21316
+ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
21317
+ $ZodStringFormat.init(inst, def);
21318
+ inst._zod.check = (payload) => {
21319
+ try {
21320
+ // Trim whitespace from input
21321
+ const trimmed = payload.value.trim();
21322
+ // @ts-ignore
21323
+ const url = new URL(trimmed);
21324
+ if (def.hostname) {
21325
+ def.hostname.lastIndex = 0;
21326
+ if (!def.hostname.test(url.hostname)) {
21327
+ payload.issues.push({
21328
+ code: "invalid_format",
21329
+ format: "url",
21330
+ note: "Invalid hostname",
21331
+ pattern: def.hostname.source,
21332
+ input: payload.value,
21333
+ inst,
21334
+ continue: !def.abort,
21335
+ });
21336
+ }
21337
+ }
21338
+ if (def.protocol) {
21339
+ def.protocol.lastIndex = 0;
21340
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
21341
+ payload.issues.push({
21342
+ code: "invalid_format",
21343
+ format: "url",
21344
+ note: "Invalid protocol",
21345
+ pattern: def.protocol.source,
21346
+ input: payload.value,
21347
+ inst,
21348
+ continue: !def.abort,
21349
+ });
21350
+ }
21351
+ }
21352
+ // Set the output value based on normalize flag
21353
+ if (def.normalize) {
21354
+ // Use normalized URL
21355
+ payload.value = url.href;
21356
+ }
21357
+ else {
21358
+ // Preserve the original input (trimmed)
21359
+ payload.value = trimmed;
21360
+ }
21361
+ return;
21362
+ }
21363
+ catch (_) {
21364
+ payload.issues.push({
21365
+ code: "invalid_format",
21366
+ format: "url",
21367
+ input: payload.value,
21368
+ inst,
21369
+ continue: !def.abort,
21370
+ });
21371
+ }
21372
+ };
21373
+ });
21374
+ const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
21375
+ def.pattern ?? (def.pattern = emoji());
21376
+ $ZodStringFormat.init(inst, def);
21377
+ });
21378
+ const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
21379
+ def.pattern ?? (def.pattern = nanoid);
21380
+ $ZodStringFormat.init(inst, def);
21381
+ });
21382
+ const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
21383
+ def.pattern ?? (def.pattern = cuid);
21384
+ $ZodStringFormat.init(inst, def);
21385
+ });
21386
+ const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
21387
+ def.pattern ?? (def.pattern = cuid2);
21388
+ $ZodStringFormat.init(inst, def);
21389
+ });
21390
+ const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
21391
+ def.pattern ?? (def.pattern = ulid);
21392
+ $ZodStringFormat.init(inst, def);
21393
+ });
21394
+ const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
21395
+ def.pattern ?? (def.pattern = xid);
21396
+ $ZodStringFormat.init(inst, def);
21397
+ });
21398
+ const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
21399
+ def.pattern ?? (def.pattern = ksuid);
21400
+ $ZodStringFormat.init(inst, def);
21401
+ });
21402
+ const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
21403
+ def.pattern ?? (def.pattern = datetime$1(def));
21404
+ $ZodStringFormat.init(inst, def);
21405
+ });
21406
+ const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
21407
+ def.pattern ?? (def.pattern = date$1);
21408
+ $ZodStringFormat.init(inst, def);
21409
+ });
21410
+ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
21411
+ def.pattern ?? (def.pattern = time$1(def));
21412
+ $ZodStringFormat.init(inst, def);
21413
+ });
21414
+ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
21415
+ def.pattern ?? (def.pattern = duration$1);
21416
+ $ZodStringFormat.init(inst, def);
21417
+ });
21418
+ const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
21419
+ def.pattern ?? (def.pattern = ipv4);
21420
+ $ZodStringFormat.init(inst, def);
21421
+ inst._zod.bag.format = `ipv4`;
21422
+ });
21423
+ const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
21424
+ def.pattern ?? (def.pattern = ipv6);
21425
+ $ZodStringFormat.init(inst, def);
21426
+ inst._zod.bag.format = `ipv6`;
21427
+ inst._zod.check = (payload) => {
21428
+ try {
21429
+ // @ts-ignore
21430
+ new URL(`http://[${payload.value}]`);
21431
+ // return;
21432
+ }
21433
+ catch {
21434
+ payload.issues.push({
21435
+ code: "invalid_format",
21436
+ format: "ipv6",
21437
+ input: payload.value,
21438
+ inst,
21439
+ continue: !def.abort,
21440
+ });
21441
+ }
21442
+ };
21443
+ });
21444
+ const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
21445
+ def.pattern ?? (def.pattern = cidrv4);
21446
+ $ZodStringFormat.init(inst, def);
21447
+ });
21448
+ const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
21449
+ def.pattern ?? (def.pattern = cidrv6); // not used for validation
21450
+ $ZodStringFormat.init(inst, def);
21451
+ inst._zod.check = (payload) => {
21452
+ const parts = payload.value.split("/");
21453
+ try {
21454
+ if (parts.length !== 2)
21455
+ throw new Error();
21456
+ const [address, prefix] = parts;
21457
+ if (!prefix)
21458
+ throw new Error();
21459
+ const prefixNum = Number(prefix);
21460
+ if (`${prefixNum}` !== prefix)
21461
+ throw new Error();
21462
+ if (prefixNum < 0 || prefixNum > 128)
21463
+ throw new Error();
21464
+ // @ts-ignore
21465
+ new URL(`http://[${address}]`);
21466
+ }
21467
+ catch {
21468
+ payload.issues.push({
21469
+ code: "invalid_format",
21470
+ format: "cidrv6",
21471
+ input: payload.value,
21472
+ inst,
21473
+ continue: !def.abort,
21474
+ });
21475
+ }
21476
+ };
21477
+ });
21478
+ ////////////////////////////// ZodBase64 //////////////////////////////
21479
+ function isValidBase64(data) {
21480
+ if (data === "")
21481
+ return true;
21482
+ if (data.length % 4 !== 0)
21483
+ return false;
21484
+ try {
21485
+ // @ts-ignore
21486
+ atob(data);
21487
+ return true;
21488
+ }
21489
+ catch {
21490
+ return false;
21491
+ }
21492
+ }
21493
+ const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
21494
+ def.pattern ?? (def.pattern = base64);
21495
+ $ZodStringFormat.init(inst, def);
21496
+ inst._zod.bag.contentEncoding = "base64";
21497
+ inst._zod.check = (payload) => {
21498
+ if (isValidBase64(payload.value))
21499
+ return;
21500
+ payload.issues.push({
21501
+ code: "invalid_format",
21502
+ format: "base64",
21503
+ input: payload.value,
21504
+ inst,
21505
+ continue: !def.abort,
21506
+ });
21507
+ };
21508
+ });
21509
+ ////////////////////////////// ZodBase64 //////////////////////////////
21510
+ function isValidBase64URL(data) {
21511
+ if (!base64url.test(data))
21512
+ return false;
21513
+ const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
21514
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
21515
+ return isValidBase64(padded);
21516
+ }
21517
+ const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
21518
+ def.pattern ?? (def.pattern = base64url);
21519
+ $ZodStringFormat.init(inst, def);
21520
+ inst._zod.bag.contentEncoding = "base64url";
21521
+ inst._zod.check = (payload) => {
21522
+ if (isValidBase64URL(payload.value))
21523
+ return;
21524
+ payload.issues.push({
21525
+ code: "invalid_format",
21526
+ format: "base64url",
21527
+ input: payload.value,
21528
+ inst,
21529
+ continue: !def.abort,
21530
+ });
21531
+ };
21532
+ });
21533
+ const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
21534
+ def.pattern ?? (def.pattern = e164);
21535
+ $ZodStringFormat.init(inst, def);
21536
+ });
21537
+ ////////////////////////////// ZodJWT //////////////////////////////
21538
+ function isValidJWT(token, algorithm = null) {
21539
+ try {
21540
+ const tokensParts = token.split(".");
21541
+ if (tokensParts.length !== 3)
21542
+ return false;
21543
+ const [header] = tokensParts;
21544
+ if (!header)
21545
+ return false;
21546
+ // @ts-ignore
21547
+ const parsedHeader = JSON.parse(atob(header));
21548
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
21549
+ return false;
21550
+ if (!parsedHeader.alg)
21551
+ return false;
21552
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
21553
+ return false;
21554
+ return true;
21555
+ }
21556
+ catch {
21557
+ return false;
21558
+ }
21559
+ }
21560
+ const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
21561
+ $ZodStringFormat.init(inst, def);
21562
+ inst._zod.check = (payload) => {
21563
+ if (isValidJWT(payload.value, def.alg))
21564
+ return;
21565
+ payload.issues.push({
21566
+ code: "invalid_format",
21567
+ format: "jwt",
21568
+ input: payload.value,
21569
+ inst,
21570
+ continue: !def.abort,
21571
+ });
21572
+ };
21573
+ });
21574
+ const $ZodAny = /*@__PURE__*/ $constructor("$ZodAny", (inst, def) => {
21575
+ $ZodType.init(inst, def);
21576
+ inst._zod.parse = (payload) => payload;
21577
+ });
21578
+ const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
21579
+ $ZodType.init(inst, def);
21580
+ inst._zod.parse = (payload) => payload;
21581
+ });
21582
+ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
21583
+ $ZodType.init(inst, def);
21584
+ inst._zod.parse = (payload, _ctx) => {
21585
+ payload.issues.push({
21586
+ expected: "never",
21587
+ code: "invalid_type",
21588
+ input: payload.value,
21589
+ inst,
21590
+ });
21591
+ return payload;
21592
+ };
21593
+ });
21594
+ function handleArrayResult(result, final, index) {
21595
+ if (result.issues.length) {
21596
+ final.issues.push(...prefixIssues(index, result.issues));
21597
+ }
21598
+ final.value[index] = result.value;
21599
+ }
21600
+ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
21601
+ $ZodType.init(inst, def);
21602
+ inst._zod.parse = (payload, ctx) => {
21603
+ const input = payload.value;
21604
+ if (!Array.isArray(input)) {
21605
+ payload.issues.push({
21606
+ expected: "array",
21607
+ code: "invalid_type",
21608
+ input,
21609
+ inst,
21610
+ });
21611
+ return payload;
21612
+ }
21613
+ payload.value = Array(input.length);
21614
+ const proms = [];
21615
+ for (let i = 0; i < input.length; i++) {
21616
+ const item = input[i];
21617
+ const result = def.element._zod.run({
21618
+ value: item,
21619
+ issues: [],
21620
+ }, ctx);
21621
+ if (result instanceof Promise) {
21622
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
21623
+ }
21624
+ else {
21625
+ handleArrayResult(result, payload, i);
21626
+ }
21627
+ }
21628
+ if (proms.length) {
21629
+ return Promise.all(proms).then(() => payload);
21630
+ }
21631
+ return payload; //handleArrayResultsAsync(parseResults, final);
21632
+ };
21633
+ });
21634
+ function handlePropertyResult(result, final, key, input) {
21635
+ if (result.issues.length) {
21636
+ final.issues.push(...prefixIssues(key, result.issues));
21637
+ }
21638
+ if (result.value === undefined) {
21639
+ if (key in input) {
21640
+ final.value[key] = undefined;
21641
+ }
21642
+ }
21643
+ else {
21644
+ final.value[key] = result.value;
21645
+ }
21646
+ }
21647
+ function normalizeDef(def) {
21648
+ const keys = Object.keys(def.shape);
21649
+ for (const k of keys) {
21650
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
21651
+ throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
21652
+ }
21653
+ }
21654
+ const okeys = optionalKeys(def.shape);
21655
+ return {
21656
+ ...def,
21657
+ keys,
21658
+ keySet: new Set(keys),
21659
+ numKeys: keys.length,
21660
+ optionalKeys: new Set(okeys),
21661
+ };
21662
+ }
21663
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
21664
+ const unrecognized = [];
21665
+ // iterate over input keys
21666
+ const keySet = def.keySet;
21667
+ const _catchall = def.catchall._zod;
21668
+ const t = _catchall.def.type;
21669
+ for (const key in input) {
21670
+ if (keySet.has(key))
21671
+ continue;
21672
+ if (t === "never") {
21673
+ unrecognized.push(key);
21674
+ continue;
21675
+ }
21676
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
21677
+ if (r instanceof Promise) {
21678
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
21679
+ }
21680
+ else {
21681
+ handlePropertyResult(r, payload, key, input);
21682
+ }
21683
+ }
21684
+ if (unrecognized.length) {
21685
+ payload.issues.push({
21686
+ code: "unrecognized_keys",
21687
+ keys: unrecognized,
21688
+ input,
21689
+ inst,
21690
+ });
21691
+ }
21692
+ if (!proms.length)
21693
+ return payload;
21694
+ return Promise.all(proms).then(() => {
21695
+ return payload;
21696
+ });
21697
+ }
21698
+ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
21699
+ // requires cast because technically $ZodObject doesn't extend
21700
+ $ZodType.init(inst, def);
21701
+ // const sh = def.shape;
21702
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
21703
+ if (!desc?.get) {
21704
+ const sh = def.shape;
21705
+ Object.defineProperty(def, "shape", {
21706
+ get: () => {
21707
+ const newSh = { ...sh };
21708
+ Object.defineProperty(def, "shape", {
21709
+ value: newSh,
21710
+ });
21711
+ return newSh;
21712
+ },
21713
+ });
21714
+ }
21715
+ const _normalized = cached(() => normalizeDef(def));
21716
+ defineLazy(inst._zod, "propValues", () => {
21717
+ const shape = def.shape;
21718
+ const propValues = {};
21719
+ for (const key in shape) {
21720
+ const field = shape[key]._zod;
21721
+ if (field.values) {
21722
+ propValues[key] ?? (propValues[key] = new Set());
21723
+ for (const v of field.values)
21724
+ propValues[key].add(v);
21725
+ }
21726
+ }
21727
+ return propValues;
21728
+ });
21729
+ const isObject$1 = isObject;
21730
+ const catchall = def.catchall;
21731
+ let value;
21732
+ inst._zod.parse = (payload, ctx) => {
21733
+ value ?? (value = _normalized.value);
21734
+ const input = payload.value;
21735
+ if (!isObject$1(input)) {
21736
+ payload.issues.push({
21737
+ expected: "object",
21738
+ code: "invalid_type",
21739
+ input,
21740
+ inst,
21741
+ });
21742
+ return payload;
21743
+ }
21744
+ payload.value = {};
21745
+ const proms = [];
21746
+ const shape = value.shape;
21747
+ for (const key of value.keys) {
21748
+ const el = shape[key];
21749
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
21750
+ if (r instanceof Promise) {
21751
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
21752
+ }
21753
+ else {
21754
+ handlePropertyResult(r, payload, key, input);
21755
+ }
21756
+ }
21757
+ if (!catchall) {
21758
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
21759
+ }
21760
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
21761
+ };
21762
+ });
21763
+ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) => {
21764
+ // requires cast because technically $ZodObject doesn't extend
21765
+ $ZodObject.init(inst, def);
21766
+ const superParse = inst._zod.parse;
21767
+ const _normalized = cached(() => normalizeDef(def));
21768
+ const generateFastpass = (shape) => {
21769
+ const doc = new Doc(["shape", "payload", "ctx"]);
21770
+ const normalized = _normalized.value;
21771
+ const parseStr = (key) => {
21772
+ const k = esc(key);
21773
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
21774
+ };
21775
+ doc.write(`const input = payload.value;`);
21776
+ const ids = Object.create(null);
21777
+ let counter = 0;
21778
+ for (const key of normalized.keys) {
21779
+ ids[key] = `key_${counter++}`;
21780
+ }
21781
+ // A: preserve key order {
21782
+ doc.write(`const newResult = {};`);
21783
+ for (const key of normalized.keys) {
21784
+ const id = ids[key];
21785
+ const k = esc(key);
21786
+ doc.write(`const ${id} = ${parseStr(key)};`);
21787
+ doc.write(`
21788
+ if (${id}.issues.length) {
21789
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
21790
+ ...iss,
21791
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
21792
+ })));
21793
+ }
21794
+
21795
+
21796
+ if (${id}.value === undefined) {
21797
+ if (${k} in input) {
21798
+ newResult[${k}] = undefined;
21799
+ }
21800
+ } else {
21801
+ newResult[${k}] = ${id}.value;
21802
+ }
21803
+
21804
+ `);
21805
+ }
21806
+ doc.write(`payload.value = newResult;`);
21807
+ doc.write(`return payload;`);
21808
+ const fn = doc.compile();
21809
+ return (payload, ctx) => fn(shape, payload, ctx);
21810
+ };
21811
+ let fastpass;
21812
+ const isObject$1 = isObject;
21813
+ const jit = !globalConfig.jitless;
21814
+ const allowsEval$1 = allowsEval;
21815
+ const fastEnabled = jit && allowsEval$1.value; // && !def.catchall;
21816
+ const catchall = def.catchall;
21817
+ let value;
21818
+ inst._zod.parse = (payload, ctx) => {
21819
+ value ?? (value = _normalized.value);
21820
+ const input = payload.value;
21821
+ if (!isObject$1(input)) {
21822
+ payload.issues.push({
21823
+ expected: "object",
21824
+ code: "invalid_type",
21825
+ input,
21826
+ inst,
21827
+ });
21828
+ return payload;
21829
+ }
21830
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
21831
+ // always synchronous
21832
+ if (!fastpass)
21833
+ fastpass = generateFastpass(def.shape);
21834
+ payload = fastpass(payload, ctx);
21835
+ if (!catchall)
21836
+ return payload;
21837
+ return handleCatchall([], input, payload, ctx, value, inst);
21838
+ }
21839
+ return superParse(payload, ctx);
21840
+ };
21841
+ });
21842
+ function handleUnionResults(results, final, inst, ctx) {
21843
+ for (const result of results) {
21844
+ if (result.issues.length === 0) {
21845
+ final.value = result.value;
21846
+ return final;
21847
+ }
21848
+ }
21849
+ const nonaborted = results.filter((r) => !aborted(r));
21850
+ if (nonaborted.length === 1) {
21851
+ final.value = nonaborted[0].value;
21852
+ return nonaborted[0];
21853
+ }
21854
+ final.issues.push({
21855
+ code: "invalid_union",
21856
+ input: final.value,
21857
+ inst,
21858
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
21859
+ });
21860
+ return final;
21861
+ }
21862
+ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
21863
+ $ZodType.init(inst, def);
21864
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
21865
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
21866
+ defineLazy(inst._zod, "values", () => {
21867
+ if (def.options.every((o) => o._zod.values)) {
21868
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
21869
+ }
21870
+ return undefined;
21871
+ });
21872
+ defineLazy(inst._zod, "pattern", () => {
21873
+ if (def.options.every((o) => o._zod.pattern)) {
21874
+ const patterns = def.options.map((o) => o._zod.pattern);
21875
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
21876
+ }
21877
+ return undefined;
21878
+ });
21879
+ const single = def.options.length === 1;
21880
+ const first = def.options[0]._zod.run;
21881
+ inst._zod.parse = (payload, ctx) => {
21882
+ if (single) {
21883
+ return first(payload, ctx);
21884
+ }
21885
+ let async = false;
21886
+ const results = [];
21887
+ for (const option of def.options) {
21888
+ const result = option._zod.run({
21889
+ value: payload.value,
21890
+ issues: [],
21891
+ }, ctx);
21892
+ if (result instanceof Promise) {
21893
+ results.push(result);
21894
+ async = true;
21895
+ }
21896
+ else {
21897
+ if (result.issues.length === 0)
21898
+ return result;
21899
+ results.push(result);
21900
+ }
21901
+ }
21902
+ if (!async)
21903
+ return handleUnionResults(results, payload, inst, ctx);
21904
+ return Promise.all(results).then((results) => {
21905
+ return handleUnionResults(results, payload, inst, ctx);
21906
+ });
21907
+ };
21908
+ });
21909
+ const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
21910
+ $ZodType.init(inst, def);
21911
+ inst._zod.parse = (payload, ctx) => {
21912
+ const input = payload.value;
21913
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
21914
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
21915
+ const async = left instanceof Promise || right instanceof Promise;
21916
+ if (async) {
21917
+ return Promise.all([left, right]).then(([left, right]) => {
21918
+ return handleIntersectionResults(payload, left, right);
21919
+ });
21920
+ }
21921
+ return handleIntersectionResults(payload, left, right);
21922
+ };
21923
+ });
21924
+ function mergeValues(a, b) {
21925
+ // const aType = parse.t(a);
21926
+ // const bType = parse.t(b);
21927
+ if (a === b) {
21928
+ return { valid: true, data: a };
21929
+ }
21930
+ if (a instanceof Date && b instanceof Date && +a === +b) {
21931
+ return { valid: true, data: a };
21932
+ }
21933
+ if (isPlainObject(a) && isPlainObject(b)) {
21934
+ const bKeys = Object.keys(b);
21935
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
21936
+ const newObj = { ...a, ...b };
21937
+ for (const key of sharedKeys) {
21938
+ const sharedValue = mergeValues(a[key], b[key]);
21939
+ if (!sharedValue.valid) {
21940
+ return {
21941
+ valid: false,
21942
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
21943
+ };
21944
+ }
21945
+ newObj[key] = sharedValue.data;
21946
+ }
21947
+ return { valid: true, data: newObj };
21948
+ }
21949
+ if (Array.isArray(a) && Array.isArray(b)) {
21950
+ if (a.length !== b.length) {
21951
+ return { valid: false, mergeErrorPath: [] };
21952
+ }
21953
+ const newArray = [];
21954
+ for (let index = 0; index < a.length; index++) {
21955
+ const itemA = a[index];
21956
+ const itemB = b[index];
21957
+ const sharedValue = mergeValues(itemA, itemB);
21958
+ if (!sharedValue.valid) {
21959
+ return {
21960
+ valid: false,
21961
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
21962
+ };
21963
+ }
21964
+ newArray.push(sharedValue.data);
21965
+ }
21966
+ return { valid: true, data: newArray };
21967
+ }
21968
+ return { valid: false, mergeErrorPath: [] };
21969
+ }
21970
+ function handleIntersectionResults(result, left, right) {
21971
+ if (left.issues.length) {
21972
+ result.issues.push(...left.issues);
21973
+ }
21974
+ if (right.issues.length) {
21975
+ result.issues.push(...right.issues);
21976
+ }
21977
+ if (aborted(result))
21978
+ return result;
21979
+ const merged = mergeValues(left.value, right.value);
21980
+ if (!merged.valid) {
21981
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
21982
+ }
21983
+ result.value = merged.data;
21984
+ return result;
21985
+ }
21986
+ const $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
21987
+ $ZodType.init(inst, def);
21988
+ inst._zod.parse = (payload, ctx) => {
21989
+ const input = payload.value;
21990
+ if (!isPlainObject(input)) {
21991
+ payload.issues.push({
21992
+ expected: "record",
21993
+ code: "invalid_type",
21994
+ input,
21995
+ inst,
21996
+ });
21997
+ return payload;
21998
+ }
21999
+ const proms = [];
22000
+ const values = def.keyType._zod.values;
22001
+ if (values) {
22002
+ payload.value = {};
22003
+ const recordKeys = new Set();
22004
+ for (const key of values) {
22005
+ if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
22006
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
22007
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
22008
+ if (result instanceof Promise) {
22009
+ proms.push(result.then((result) => {
22010
+ if (result.issues.length) {
22011
+ payload.issues.push(...prefixIssues(key, result.issues));
22012
+ }
22013
+ payload.value[key] = result.value;
22014
+ }));
22015
+ }
22016
+ else {
22017
+ if (result.issues.length) {
22018
+ payload.issues.push(...prefixIssues(key, result.issues));
22019
+ }
22020
+ payload.value[key] = result.value;
22021
+ }
22022
+ }
22023
+ }
22024
+ let unrecognized;
22025
+ for (const key in input) {
22026
+ if (!recordKeys.has(key)) {
22027
+ unrecognized = unrecognized ?? [];
22028
+ unrecognized.push(key);
22029
+ }
22030
+ }
22031
+ if (unrecognized && unrecognized.length > 0) {
22032
+ payload.issues.push({
22033
+ code: "unrecognized_keys",
22034
+ input,
22035
+ inst,
22036
+ keys: unrecognized,
22037
+ });
22038
+ }
22039
+ }
22040
+ else {
22041
+ payload.value = {};
22042
+ for (const key of Reflect.ownKeys(input)) {
22043
+ if (key === "__proto__")
22044
+ continue;
22045
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
22046
+ if (keyResult instanceof Promise) {
22047
+ throw new Error("Async schemas not supported in object keys currently");
22048
+ }
22049
+ if (keyResult.issues.length) {
22050
+ if (def.mode === "loose") {
22051
+ // Pass through unchanged
22052
+ payload.value[key] = input[key];
22053
+ }
22054
+ else {
22055
+ // Default "strict" behavior: error on invalid key
22056
+ payload.issues.push({
22057
+ code: "invalid_key",
22058
+ origin: "record",
22059
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
22060
+ input: key,
22061
+ path: [key],
22062
+ inst,
22063
+ });
22064
+ }
22065
+ continue;
22066
+ }
22067
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
22068
+ if (result instanceof Promise) {
22069
+ proms.push(result.then((result) => {
22070
+ if (result.issues.length) {
22071
+ payload.issues.push(...prefixIssues(key, result.issues));
22072
+ }
22073
+ payload.value[keyResult.value] = result.value;
22074
+ }));
22075
+ }
22076
+ else {
22077
+ if (result.issues.length) {
22078
+ payload.issues.push(...prefixIssues(key, result.issues));
22079
+ }
22080
+ payload.value[keyResult.value] = result.value;
22081
+ }
22082
+ }
22083
+ }
22084
+ if (proms.length) {
22085
+ return Promise.all(proms).then(() => payload);
22086
+ }
22087
+ return payload;
22088
+ };
22089
+ });
22090
+ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
22091
+ $ZodType.init(inst, def);
22092
+ const values = getEnumValues(def.entries);
22093
+ const valuesSet = new Set(values);
22094
+ inst._zod.values = valuesSet;
22095
+ inst._zod.pattern = new RegExp(`^(${values
22096
+ .filter((k) => propertyKeyTypes.has(typeof k))
22097
+ .map((o) => (typeof o === "string" ? escapeRegex(o) : o.toString()))
22098
+ .join("|")})$`);
22099
+ inst._zod.parse = (payload, _ctx) => {
22100
+ const input = payload.value;
22101
+ if (valuesSet.has(input)) {
22102
+ return payload;
22103
+ }
22104
+ payload.issues.push({
22105
+ code: "invalid_value",
22106
+ values,
22107
+ input,
22108
+ inst,
22109
+ });
22110
+ return payload;
22111
+ };
22112
+ });
22113
+ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
22114
+ $ZodType.init(inst, def);
22115
+ inst._zod.parse = (payload, ctx) => {
22116
+ if (ctx.direction === "backward") {
22117
+ throw new $ZodEncodeError(inst.constructor.name);
22118
+ }
22119
+ const _out = def.transform(payload.value, payload);
22120
+ if (ctx.async) {
22121
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
22122
+ return output.then((output) => {
22123
+ payload.value = output;
22124
+ return payload;
22125
+ });
22126
+ }
22127
+ if (_out instanceof Promise) {
22128
+ throw new $ZodAsyncError();
22129
+ }
22130
+ payload.value = _out;
22131
+ return payload;
22132
+ };
22133
+ });
22134
+ function handleOptionalResult(result, input) {
22135
+ if (result.issues.length && input === undefined) {
22136
+ return { issues: [], value: undefined };
22137
+ }
22138
+ return result;
22139
+ }
22140
+ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
22141
+ $ZodType.init(inst, def);
22142
+ inst._zod.optin = "optional";
22143
+ inst._zod.optout = "optional";
22144
+ defineLazy(inst._zod, "values", () => {
22145
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
22146
+ });
22147
+ defineLazy(inst._zod, "pattern", () => {
22148
+ const pattern = def.innerType._zod.pattern;
22149
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : undefined;
22150
+ });
22151
+ inst._zod.parse = (payload, ctx) => {
22152
+ if (def.innerType._zod.optin === "optional") {
22153
+ const result = def.innerType._zod.run(payload, ctx);
22154
+ if (result instanceof Promise)
22155
+ return result.then((r) => handleOptionalResult(r, payload.value));
22156
+ return handleOptionalResult(result, payload.value);
22157
+ }
22158
+ if (payload.value === undefined) {
22159
+ return payload;
22160
+ }
22161
+ return def.innerType._zod.run(payload, ctx);
22162
+ };
22163
+ });
22164
+ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
22165
+ $ZodType.init(inst, def);
22166
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
22167
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
22168
+ defineLazy(inst._zod, "pattern", () => {
22169
+ const pattern = def.innerType._zod.pattern;
22170
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : undefined;
22171
+ });
22172
+ defineLazy(inst._zod, "values", () => {
22173
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
22174
+ });
22175
+ inst._zod.parse = (payload, ctx) => {
22176
+ // Forward direction (decode): allow null to pass through
22177
+ if (payload.value === null)
22178
+ return payload;
22179
+ return def.innerType._zod.run(payload, ctx);
22180
+ };
22181
+ });
22182
+ const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
22183
+ $ZodType.init(inst, def);
22184
+ // inst._zod.qin = "true";
22185
+ inst._zod.optin = "optional";
22186
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
22187
+ inst._zod.parse = (payload, ctx) => {
22188
+ if (ctx.direction === "backward") {
22189
+ return def.innerType._zod.run(payload, ctx);
22190
+ }
22191
+ // Forward direction (decode): apply defaults for undefined input
22192
+ if (payload.value === undefined) {
22193
+ payload.value = def.defaultValue;
22194
+ /**
22195
+ * $ZodDefault returns the default value immediately in forward direction.
22196
+ * 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. */
22197
+ return payload;
22198
+ }
22199
+ // Forward direction: continue with default handling
22200
+ const result = def.innerType._zod.run(payload, ctx);
22201
+ if (result instanceof Promise) {
22202
+ return result.then((result) => handleDefaultResult(result, def));
22203
+ }
22204
+ return handleDefaultResult(result, def);
22205
+ };
22206
+ });
22207
+ function handleDefaultResult(payload, def) {
22208
+ if (payload.value === undefined) {
22209
+ payload.value = def.defaultValue;
22210
+ }
22211
+ return payload;
22212
+ }
22213
+ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
22214
+ $ZodType.init(inst, def);
22215
+ inst._zod.optin = "optional";
22216
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
22217
+ inst._zod.parse = (payload, ctx) => {
22218
+ if (ctx.direction === "backward") {
22219
+ return def.innerType._zod.run(payload, ctx);
22220
+ }
22221
+ // Forward direction (decode): apply prefault for undefined input
22222
+ if (payload.value === undefined) {
22223
+ payload.value = def.defaultValue;
22224
+ }
22225
+ return def.innerType._zod.run(payload, ctx);
22226
+ };
22227
+ });
22228
+ const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
22229
+ $ZodType.init(inst, def);
22230
+ defineLazy(inst._zod, "values", () => {
22231
+ const v = def.innerType._zod.values;
22232
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
22233
+ });
22234
+ inst._zod.parse = (payload, ctx) => {
22235
+ const result = def.innerType._zod.run(payload, ctx);
22236
+ if (result instanceof Promise) {
22237
+ return result.then((result) => handleNonOptionalResult(result, inst));
22238
+ }
22239
+ return handleNonOptionalResult(result, inst);
22240
+ };
22241
+ });
22242
+ function handleNonOptionalResult(payload, inst) {
22243
+ if (!payload.issues.length && payload.value === undefined) {
22244
+ payload.issues.push({
22245
+ code: "invalid_type",
22246
+ expected: "nonoptional",
22247
+ input: payload.value,
22248
+ inst,
22249
+ });
22250
+ }
22251
+ return payload;
22252
+ }
22253
+ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
22254
+ $ZodType.init(inst, def);
22255
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
22256
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
22257
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
22258
+ inst._zod.parse = (payload, ctx) => {
22259
+ if (ctx.direction === "backward") {
22260
+ return def.innerType._zod.run(payload, ctx);
22261
+ }
22262
+ // Forward direction (decode): apply catch logic
22263
+ const result = def.innerType._zod.run(payload, ctx);
22264
+ if (result instanceof Promise) {
22265
+ return result.then((result) => {
22266
+ payload.value = result.value;
22267
+ if (result.issues.length) {
22268
+ payload.value = def.catchValue({
22269
+ ...payload,
22270
+ error: {
22271
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
22272
+ },
22273
+ input: payload.value,
22274
+ });
22275
+ payload.issues = [];
22276
+ }
22277
+ return payload;
22278
+ });
22279
+ }
22280
+ payload.value = result.value;
22281
+ if (result.issues.length) {
22282
+ payload.value = def.catchValue({
22283
+ ...payload,
22284
+ error: {
22285
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
22286
+ },
22287
+ input: payload.value,
22288
+ });
22289
+ payload.issues = [];
22290
+ }
22291
+ return payload;
22292
+ };
22293
+ });
22294
+ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
22295
+ $ZodType.init(inst, def);
22296
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
22297
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
22298
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
22299
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
22300
+ inst._zod.parse = (payload, ctx) => {
22301
+ if (ctx.direction === "backward") {
22302
+ const right = def.out._zod.run(payload, ctx);
22303
+ if (right instanceof Promise) {
22304
+ return right.then((right) => handlePipeResult(right, def.in, ctx));
22305
+ }
22306
+ return handlePipeResult(right, def.in, ctx);
22307
+ }
22308
+ const left = def.in._zod.run(payload, ctx);
22309
+ if (left instanceof Promise) {
22310
+ return left.then((left) => handlePipeResult(left, def.out, ctx));
22311
+ }
22312
+ return handlePipeResult(left, def.out, ctx);
22313
+ };
22314
+ });
22315
+ function handlePipeResult(left, next, ctx) {
22316
+ if (left.issues.length) {
22317
+ // prevent further checks
22318
+ left.aborted = true;
22319
+ return left;
22320
+ }
22321
+ return next._zod.run({ value: left.value, issues: left.issues }, ctx);
22322
+ }
22323
+ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
22324
+ $ZodType.init(inst, def);
22325
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
22326
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
22327
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
22328
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
22329
+ inst._zod.parse = (payload, ctx) => {
22330
+ if (ctx.direction === "backward") {
22331
+ return def.innerType._zod.run(payload, ctx);
22332
+ }
22333
+ const result = def.innerType._zod.run(payload, ctx);
22334
+ if (result instanceof Promise) {
22335
+ return result.then(handleReadonlyResult);
22336
+ }
22337
+ return handleReadonlyResult(result);
22338
+ };
22339
+ });
22340
+ function handleReadonlyResult(payload) {
22341
+ payload.value = Object.freeze(payload.value);
22342
+ return payload;
22343
+ }
22344
+ const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
22345
+ $ZodCheck.init(inst, def);
22346
+ $ZodType.init(inst, def);
22347
+ inst._zod.parse = (payload, _) => {
22348
+ return payload;
22349
+ };
22350
+ inst._zod.check = (payload) => {
22351
+ const input = payload.value;
22352
+ const r = def.fn(input);
22353
+ if (r instanceof Promise) {
22354
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
22355
+ }
22356
+ handleRefineResult(r, payload, input, inst);
22357
+ return;
22358
+ };
22359
+ });
22360
+ function handleRefineResult(result, payload, input, inst) {
22361
+ if (!result) {
22362
+ const _iss = {
22363
+ code: "custom",
22364
+ input,
22365
+ inst, // incorporates params.error into issue reporting
22366
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
22367
+ continue: !inst._zod.def.abort,
22368
+ // params: inst._zod.def.params,
22369
+ };
22370
+ if (inst._zod.def.params)
22371
+ _iss.params = inst._zod.def.params;
22372
+ payload.issues.push(issue(_iss));
22373
+ }
22374
+ }
22375
+
22376
+ var _a;
22377
+ class $ZodRegistry {
22378
+ constructor() {
22379
+ this._map = new WeakMap();
22380
+ this._idmap = new Map();
22381
+ }
22382
+ add(schema, ..._meta) {
22383
+ const meta = _meta[0];
22384
+ this._map.set(schema, meta);
22385
+ if (meta && typeof meta === "object" && "id" in meta) {
22386
+ if (this._idmap.has(meta.id)) {
22387
+ throw new Error(`ID ${meta.id} already exists in the registry`);
22388
+ }
22389
+ this._idmap.set(meta.id, schema);
22390
+ }
22391
+ return this;
22392
+ }
22393
+ clear() {
22394
+ this._map = new WeakMap();
22395
+ this._idmap = new Map();
22396
+ return this;
22397
+ }
22398
+ remove(schema) {
22399
+ const meta = this._map.get(schema);
22400
+ if (meta && typeof meta === "object" && "id" in meta) {
22401
+ this._idmap.delete(meta.id);
22402
+ }
22403
+ this._map.delete(schema);
22404
+ return this;
22405
+ }
22406
+ get(schema) {
22407
+ // return this._map.get(schema) as any;
22408
+ // inherit metadata
22409
+ const p = schema._zod.parent;
22410
+ if (p) {
22411
+ const pm = { ...(this.get(p) ?? {}) };
22412
+ delete pm.id; // do not inherit id
22413
+ const f = { ...pm, ...this._map.get(schema) };
22414
+ return Object.keys(f).length ? f : undefined;
22415
+ }
22416
+ return this._map.get(schema);
22417
+ }
22418
+ has(schema) {
22419
+ return this._map.has(schema);
22420
+ }
22421
+ }
22422
+ // registries
22423
+ function registry() {
22424
+ return new $ZodRegistry();
22425
+ }
22426
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
22427
+ const globalRegistry = globalThis.__zod_globalRegistry;
22428
+
22429
+ function _string(Class, params) {
22430
+ return new Class({
22431
+ type: "string",
22432
+ ...normalizeParams(params),
22433
+ });
22434
+ }
22435
+ function _email(Class, params) {
22436
+ return new Class({
22437
+ type: "string",
22438
+ format: "email",
22439
+ check: "string_format",
22440
+ abort: false,
22441
+ ...normalizeParams(params),
22442
+ });
22443
+ }
22444
+ function _guid(Class, params) {
22445
+ return new Class({
22446
+ type: "string",
22447
+ format: "guid",
22448
+ check: "string_format",
22449
+ abort: false,
22450
+ ...normalizeParams(params),
22451
+ });
22452
+ }
22453
+ function _uuid(Class, params) {
22454
+ return new Class({
22455
+ type: "string",
22456
+ format: "uuid",
22457
+ check: "string_format",
22458
+ abort: false,
22459
+ ...normalizeParams(params),
22460
+ });
22461
+ }
22462
+ function _uuidv4(Class, params) {
22463
+ return new Class({
22464
+ type: "string",
22465
+ format: "uuid",
22466
+ check: "string_format",
22467
+ abort: false,
22468
+ version: "v4",
22469
+ ...normalizeParams(params),
22470
+ });
22471
+ }
22472
+ function _uuidv6(Class, params) {
22473
+ return new Class({
22474
+ type: "string",
22475
+ format: "uuid",
22476
+ check: "string_format",
22477
+ abort: false,
22478
+ version: "v6",
22479
+ ...normalizeParams(params),
22480
+ });
22481
+ }
22482
+ function _uuidv7(Class, params) {
22483
+ return new Class({
22484
+ type: "string",
22485
+ format: "uuid",
22486
+ check: "string_format",
22487
+ abort: false,
22488
+ version: "v7",
22489
+ ...normalizeParams(params),
22490
+ });
22491
+ }
22492
+ function _url(Class, params) {
22493
+ return new Class({
22494
+ type: "string",
22495
+ format: "url",
22496
+ check: "string_format",
22497
+ abort: false,
22498
+ ...normalizeParams(params),
22499
+ });
22500
+ }
22501
+ function _emoji(Class, params) {
22502
+ return new Class({
22503
+ type: "string",
22504
+ format: "emoji",
22505
+ check: "string_format",
22506
+ abort: false,
22507
+ ...normalizeParams(params),
22508
+ });
22509
+ }
22510
+ function _nanoid(Class, params) {
22511
+ return new Class({
22512
+ type: "string",
22513
+ format: "nanoid",
22514
+ check: "string_format",
22515
+ abort: false,
22516
+ ...normalizeParams(params),
22517
+ });
22518
+ }
22519
+ function _cuid(Class, params) {
22520
+ return new Class({
22521
+ type: "string",
22522
+ format: "cuid",
22523
+ check: "string_format",
22524
+ abort: false,
22525
+ ...normalizeParams(params),
22526
+ });
22527
+ }
22528
+ function _cuid2(Class, params) {
22529
+ return new Class({
22530
+ type: "string",
22531
+ format: "cuid2",
22532
+ check: "string_format",
22533
+ abort: false,
22534
+ ...normalizeParams(params),
22535
+ });
22536
+ }
22537
+ function _ulid(Class, params) {
22538
+ return new Class({
22539
+ type: "string",
22540
+ format: "ulid",
22541
+ check: "string_format",
22542
+ abort: false,
22543
+ ...normalizeParams(params),
22544
+ });
22545
+ }
22546
+ function _xid(Class, params) {
22547
+ return new Class({
22548
+ type: "string",
22549
+ format: "xid",
22550
+ check: "string_format",
22551
+ abort: false,
22552
+ ...normalizeParams(params),
22553
+ });
22554
+ }
22555
+ function _ksuid(Class, params) {
22556
+ return new Class({
22557
+ type: "string",
22558
+ format: "ksuid",
22559
+ check: "string_format",
22560
+ abort: false,
22561
+ ...normalizeParams(params),
22562
+ });
22563
+ }
22564
+ function _ipv4(Class, params) {
22565
+ return new Class({
22566
+ type: "string",
22567
+ format: "ipv4",
22568
+ check: "string_format",
22569
+ abort: false,
22570
+ ...normalizeParams(params),
22571
+ });
22572
+ }
22573
+ function _ipv6(Class, params) {
22574
+ return new Class({
22575
+ type: "string",
22576
+ format: "ipv6",
22577
+ check: "string_format",
22578
+ abort: false,
22579
+ ...normalizeParams(params),
22580
+ });
22581
+ }
22582
+ function _cidrv4(Class, params) {
22583
+ return new Class({
22584
+ type: "string",
22585
+ format: "cidrv4",
22586
+ check: "string_format",
22587
+ abort: false,
22588
+ ...normalizeParams(params),
22589
+ });
22590
+ }
22591
+ function _cidrv6(Class, params) {
22592
+ return new Class({
22593
+ type: "string",
22594
+ format: "cidrv6",
22595
+ check: "string_format",
22596
+ abort: false,
22597
+ ...normalizeParams(params),
22598
+ });
22599
+ }
22600
+ function _base64(Class, params) {
22601
+ return new Class({
22602
+ type: "string",
22603
+ format: "base64",
22604
+ check: "string_format",
22605
+ abort: false,
22606
+ ...normalizeParams(params),
22607
+ });
22608
+ }
22609
+ function _base64url(Class, params) {
22610
+ return new Class({
22611
+ type: "string",
22612
+ format: "base64url",
22613
+ check: "string_format",
22614
+ abort: false,
22615
+ ...normalizeParams(params),
22616
+ });
22617
+ }
22618
+ function _e164(Class, params) {
22619
+ return new Class({
22620
+ type: "string",
22621
+ format: "e164",
22622
+ check: "string_format",
22623
+ abort: false,
22624
+ ...normalizeParams(params),
22625
+ });
22626
+ }
22627
+ function _jwt(Class, params) {
22628
+ return new Class({
22629
+ type: "string",
22630
+ format: "jwt",
22631
+ check: "string_format",
22632
+ abort: false,
22633
+ ...normalizeParams(params),
22634
+ });
22635
+ }
22636
+ function _isoDateTime(Class, params) {
22637
+ return new Class({
22638
+ type: "string",
22639
+ format: "datetime",
22640
+ check: "string_format",
22641
+ offset: false,
22642
+ local: false,
22643
+ precision: null,
22644
+ ...normalizeParams(params),
22645
+ });
22646
+ }
22647
+ function _isoDate(Class, params) {
22648
+ return new Class({
22649
+ type: "string",
22650
+ format: "date",
22651
+ check: "string_format",
22652
+ ...normalizeParams(params),
22653
+ });
22654
+ }
22655
+ function _isoTime(Class, params) {
22656
+ return new Class({
22657
+ type: "string",
22658
+ format: "time",
22659
+ check: "string_format",
22660
+ precision: null,
22661
+ ...normalizeParams(params),
22662
+ });
22663
+ }
22664
+ function _isoDuration(Class, params) {
22665
+ return new Class({
22666
+ type: "string",
22667
+ format: "duration",
22668
+ check: "string_format",
22669
+ ...normalizeParams(params),
22670
+ });
22671
+ }
22672
+ function _any(Class) {
22673
+ return new Class({
22674
+ type: "any",
22675
+ });
22676
+ }
22677
+ function _unknown(Class) {
22678
+ return new Class({
22679
+ type: "unknown",
22680
+ });
22681
+ }
22682
+ function _never(Class, params) {
22683
+ return new Class({
22684
+ type: "never",
22685
+ ...normalizeParams(params),
22686
+ });
22687
+ }
22688
+ function _maxLength(maximum, params) {
22689
+ const ch = new $ZodCheckMaxLength({
22690
+ check: "max_length",
22691
+ ...normalizeParams(params),
22692
+ maximum,
22693
+ });
22694
+ return ch;
22695
+ }
22696
+ function _minLength(minimum, params) {
22697
+ return new $ZodCheckMinLength({
22698
+ check: "min_length",
22699
+ ...normalizeParams(params),
22700
+ minimum,
22701
+ });
22702
+ }
22703
+ function _length(length, params) {
22704
+ return new $ZodCheckLengthEquals({
22705
+ check: "length_equals",
22706
+ ...normalizeParams(params),
22707
+ length,
22708
+ });
22709
+ }
22710
+ function _regex(pattern, params) {
22711
+ return new $ZodCheckRegex({
22712
+ check: "string_format",
22713
+ format: "regex",
22714
+ ...normalizeParams(params),
22715
+ pattern,
22716
+ });
22717
+ }
22718
+ function _lowercase(params) {
22719
+ return new $ZodCheckLowerCase({
22720
+ check: "string_format",
22721
+ format: "lowercase",
22722
+ ...normalizeParams(params),
22723
+ });
22724
+ }
22725
+ function _uppercase(params) {
22726
+ return new $ZodCheckUpperCase({
22727
+ check: "string_format",
22728
+ format: "uppercase",
22729
+ ...normalizeParams(params),
22730
+ });
22731
+ }
22732
+ function _includes(includes, params) {
22733
+ return new $ZodCheckIncludes({
22734
+ check: "string_format",
22735
+ format: "includes",
22736
+ ...normalizeParams(params),
22737
+ includes,
22738
+ });
22739
+ }
22740
+ function _startsWith(prefix, params) {
22741
+ return new $ZodCheckStartsWith({
22742
+ check: "string_format",
22743
+ format: "starts_with",
22744
+ ...normalizeParams(params),
22745
+ prefix,
22746
+ });
22747
+ }
22748
+ function _endsWith(suffix, params) {
22749
+ return new $ZodCheckEndsWith({
22750
+ check: "string_format",
22751
+ format: "ends_with",
22752
+ ...normalizeParams(params),
22753
+ suffix,
22754
+ });
22755
+ }
22756
+ function _overwrite(tx) {
22757
+ return new $ZodCheckOverwrite({
22758
+ check: "overwrite",
22759
+ tx,
22760
+ });
22761
+ }
22762
+ // normalize
22763
+ function _normalize(form) {
22764
+ return _overwrite((input) => input.normalize(form));
22765
+ }
22766
+ // trim
22767
+ function _trim() {
22768
+ return _overwrite((input) => input.trim());
22769
+ }
22770
+ // toLowerCase
22771
+ function _toLowerCase() {
22772
+ return _overwrite((input) => input.toLowerCase());
22773
+ }
22774
+ // toUpperCase
22775
+ function _toUpperCase() {
22776
+ return _overwrite((input) => input.toUpperCase());
22777
+ }
22778
+ // slugify
22779
+ function _slugify() {
22780
+ return _overwrite((input) => slugify(input));
22781
+ }
22782
+ function _array(Class, element, params) {
22783
+ return new Class({
22784
+ type: "array",
22785
+ element,
22786
+ // get element() {
22787
+ // return element;
22788
+ // },
22789
+ ...normalizeParams(params),
22790
+ });
22791
+ }
22792
+ // same as _custom but defaults to abort:false
22793
+ function _refine(Class, fn, _params) {
22794
+ const schema = new Class({
22795
+ type: "custom",
22796
+ check: "custom",
22797
+ fn: fn,
22798
+ ...normalizeParams(_params),
22799
+ });
22800
+ return schema;
22801
+ }
22802
+ function _superRefine(fn) {
22803
+ const ch = _check((payload) => {
22804
+ payload.addIssue = (issue$1) => {
22805
+ if (typeof issue$1 === "string") {
22806
+ payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
22807
+ }
22808
+ else {
22809
+ // for Zod 3 backwards compatibility
22810
+ const _issue = issue$1;
22811
+ if (_issue.fatal)
22812
+ _issue.continue = false;
22813
+ _issue.code ?? (_issue.code = "custom");
22814
+ _issue.input ?? (_issue.input = payload.value);
22815
+ _issue.inst ?? (_issue.inst = ch);
22816
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
22817
+ payload.issues.push(issue(_issue));
22818
+ }
22819
+ };
22820
+ return fn(payload.value, payload);
22821
+ });
22822
+ return ch;
22823
+ }
22824
+ function _check(fn, params) {
22825
+ const ch = new $ZodCheck({
22826
+ check: "custom",
22827
+ ...normalizeParams(params),
22828
+ });
22829
+ ch._zod.check = fn;
22830
+ return ch;
22831
+ }
22832
+
22833
+ // function initializeContext<T extends schemas.$ZodType>(inputs: JSONSchemaGeneratorParams<T>): ToJSONSchemaContext<T> {
22834
+ // return {
22835
+ // processor: inputs.processor,
22836
+ // metadataRegistry: inputs.metadata ?? globalRegistry,
22837
+ // target: inputs.target ?? "draft-2020-12",
22838
+ // unrepresentable: inputs.unrepresentable ?? "throw",
22839
+ // };
22840
+ // }
22841
+ function initializeContext(params) {
22842
+ // Normalize target: convert old non-hyphenated versions to hyphenated versions
22843
+ let target = params?.target ?? "draft-2020-12";
22844
+ if (target === "draft-4")
22845
+ target = "draft-04";
22846
+ if (target === "draft-7")
22847
+ target = "draft-07";
22848
+ return {
22849
+ processors: params.processors ?? {},
22850
+ metadataRegistry: params?.metadata ?? globalRegistry,
22851
+ target,
22852
+ unrepresentable: params?.unrepresentable ?? "throw",
22853
+ override: params?.override ?? (() => { }),
22854
+ io: params?.io ?? "output",
22855
+ counter: 0,
22856
+ seen: new Map(),
22857
+ cycles: params?.cycles ?? "ref",
22858
+ reused: params?.reused ?? "inline",
22859
+ external: params?.external ?? undefined,
22860
+ };
22861
+ }
22862
+ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
22863
+ var _a;
22864
+ const def = schema._zod.def;
22865
+ // check for schema in seens
22866
+ const seen = ctx.seen.get(schema);
22867
+ if (seen) {
22868
+ seen.count++;
22869
+ // check if cycle
22870
+ const isCycle = _params.schemaPath.includes(schema);
22871
+ if (isCycle) {
22872
+ seen.cycle = _params.path;
22873
+ }
22874
+ return seen.schema;
22875
+ }
22876
+ // initialize
22877
+ const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
22878
+ ctx.seen.set(schema, result);
22879
+ // custom method overrides default behavior
22880
+ const overrideSchema = schema._zod.toJSONSchema?.();
22881
+ if (overrideSchema) {
22882
+ result.schema = overrideSchema;
22883
+ }
22884
+ else {
22885
+ const params = {
22886
+ ..._params,
22887
+ schemaPath: [..._params.schemaPath, schema],
22888
+ path: _params.path,
22889
+ };
22890
+ const parent = schema._zod.parent;
22891
+ if (parent) {
22892
+ // schema was cloned from another schema
22893
+ result.ref = parent;
22894
+ process$1(parent, ctx, params);
22895
+ ctx.seen.get(parent).isParent = true;
22896
+ }
22897
+ else if (schema._zod.processJSONSchema) {
22898
+ schema._zod.processJSONSchema(ctx, result.schema, params);
22899
+ }
22900
+ else {
22901
+ const _json = result.schema;
22902
+ const processor = ctx.processors[def.type];
22903
+ if (!processor) {
22904
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
22905
+ }
22906
+ processor(schema, ctx, _json, params);
22907
+ }
22908
+ }
22909
+ // metadata
22910
+ const meta = ctx.metadataRegistry.get(schema);
22911
+ if (meta)
22912
+ Object.assign(result.schema, meta);
22913
+ if (ctx.io === "input" && isTransforming(schema)) {
22914
+ // examples/defaults only apply to output type of pipe
22915
+ delete result.schema.examples;
22916
+ delete result.schema.default;
22917
+ }
22918
+ // set prefault as default
22919
+ if (ctx.io === "input" && result.schema._prefault)
22920
+ (_a = result.schema).default ?? (_a.default = result.schema._prefault);
22921
+ delete result.schema._prefault;
22922
+ // pulling fresh from ctx.seen in case it was overwritten
22923
+ const _result = ctx.seen.get(schema);
22924
+ return _result.schema;
22925
+ }
22926
+ function extractDefs(ctx, schema
22927
+ // params: EmitParams
22928
+ ) {
22929
+ // iterate over seen map;
22930
+ const root = ctx.seen.get(schema);
22931
+ if (!root)
22932
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
22933
+ // returns a ref to the schema
22934
+ // defId will be empty if the ref points to an external schema (or #)
22935
+ const makeURI = (entry) => {
22936
+ // comparing the seen objects because sometimes
22937
+ // multiple schemas map to the same seen object.
22938
+ // e.g. lazy
22939
+ // external is configured
22940
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
22941
+ if (ctx.external) {
22942
+ const externalId = ctx.external.registry.get(entry[0])?.id; // ?? "__shared";// `__schema${ctx.counter++}`;
22943
+ // check if schema is in the external registry
22944
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
22945
+ if (externalId) {
22946
+ return { ref: uriGenerator(externalId) };
22947
+ }
22948
+ // otherwise, add to __shared
22949
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
22950
+ entry[1].defId = id; // set defId so it will be reused if needed
22951
+ return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
22952
+ }
22953
+ if (entry[1] === root) {
22954
+ return { ref: "#" };
22955
+ }
22956
+ // self-contained schema
22957
+ const uriPrefix = `#`;
22958
+ const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
22959
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
22960
+ return { defId, ref: defUriPrefix + defId };
22961
+ };
22962
+ // stored cached version in `def` property
22963
+ // remove all properties, set $ref
22964
+ const extractToDef = (entry) => {
22965
+ // if the schema is already a reference, do not extract it
22966
+ if (entry[1].schema.$ref) {
22967
+ return;
22968
+ }
22969
+ const seen = entry[1];
22970
+ const { ref, defId } = makeURI(entry);
22971
+ seen.def = { ...seen.schema };
22972
+ // defId won't be set if the schema is a reference to an external schema
22973
+ // or if the schema is the root schema
22974
+ if (defId)
22975
+ seen.defId = defId;
22976
+ // wipe away all properties except $ref
22977
+ const schema = seen.schema;
22978
+ for (const key in schema) {
22979
+ delete schema[key];
22980
+ }
22981
+ schema.$ref = ref;
22982
+ };
22983
+ // throw on cycles
22984
+ // break cycles
22985
+ if (ctx.cycles === "throw") {
22986
+ for (const entry of ctx.seen.entries()) {
22987
+ const seen = entry[1];
22988
+ if (seen.cycle) {
22989
+ throw new Error("Cycle detected: " +
22990
+ `#/${seen.cycle?.join("/")}/<root>` +
22991
+ '\n\nSet the `cycles` parameter to `"ref"` to resolve cyclical schemas with defs.');
22992
+ }
22993
+ }
22994
+ }
22995
+ // extract schemas into $defs
22996
+ for (const entry of ctx.seen.entries()) {
22997
+ const seen = entry[1];
22998
+ // convert root schema to # $ref
22999
+ if (schema === entry[0]) {
23000
+ extractToDef(entry); // this has special handling for the root schema
23001
+ continue;
23002
+ }
23003
+ // extract schemas that are in the external registry
23004
+ if (ctx.external) {
23005
+ const ext = ctx.external.registry.get(entry[0])?.id;
23006
+ if (schema !== entry[0] && ext) {
23007
+ extractToDef(entry);
23008
+ continue;
23009
+ }
23010
+ }
23011
+ // extract schemas with `id` meta
23012
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
23013
+ if (id) {
23014
+ extractToDef(entry);
23015
+ continue;
23016
+ }
23017
+ // break cycles
23018
+ if (seen.cycle) {
23019
+ // any
23020
+ extractToDef(entry);
23021
+ continue;
23022
+ }
23023
+ // extract reused schemas
23024
+ if (seen.count > 1) {
23025
+ if (ctx.reused === "ref") {
23026
+ extractToDef(entry);
23027
+ // biome-ignore lint:
23028
+ continue;
23029
+ }
23030
+ }
23031
+ }
23032
+ }
23033
+ function finalize(ctx, schema) {
23034
+ //
23035
+ // iterate over seen map;
23036
+ const root = ctx.seen.get(schema);
23037
+ if (!root)
23038
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
23039
+ // flatten _refs
23040
+ const flattenRef = (zodSchema) => {
23041
+ const seen = ctx.seen.get(zodSchema);
23042
+ const schema = seen.def ?? seen.schema;
23043
+ const _cached = { ...schema };
23044
+ // already seen
23045
+ if (seen.ref === null) {
23046
+ return;
23047
+ }
23048
+ // flatten ref if defined
23049
+ const ref = seen.ref;
23050
+ seen.ref = null; // prevent recursion
23051
+ if (ref) {
23052
+ flattenRef(ref);
23053
+ // merge referenced schema into current
23054
+ const refSchema = ctx.seen.get(ref).schema;
23055
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
23056
+ schema.allOf = schema.allOf ?? [];
23057
+ schema.allOf.push(refSchema);
23058
+ }
23059
+ else {
23060
+ Object.assign(schema, refSchema);
23061
+ Object.assign(schema, _cached); // prevent overwriting any fields in the original schema
23062
+ }
23063
+ }
23064
+ // execute overrides
23065
+ if (!seen.isParent)
23066
+ ctx.override({
23067
+ zodSchema: zodSchema,
23068
+ jsonSchema: schema,
23069
+ path: seen.path ?? [],
23070
+ });
23071
+ };
23072
+ for (const entry of [...ctx.seen.entries()].reverse()) {
23073
+ flattenRef(entry[0]);
23074
+ }
23075
+ const result = {};
23076
+ if (ctx.target === "draft-2020-12") {
23077
+ result.$schema = "https://json-schema.org/draft/2020-12/schema";
23078
+ }
23079
+ else if (ctx.target === "draft-07") {
23080
+ result.$schema = "http://json-schema.org/draft-07/schema#";
23081
+ }
23082
+ else if (ctx.target === "draft-04") {
23083
+ result.$schema = "http://json-schema.org/draft-04/schema#";
23084
+ }
23085
+ else if (ctx.target === "openapi-3.0") ;
23086
+ else ;
23087
+ if (ctx.external?.uri) {
23088
+ const id = ctx.external.registry.get(schema)?.id;
23089
+ if (!id)
23090
+ throw new Error("Schema is missing an `id` property");
23091
+ result.$id = ctx.external.uri(id);
23092
+ }
23093
+ Object.assign(result, root.def ?? root.schema);
23094
+ // build defs object
23095
+ const defs = ctx.external?.defs ?? {};
23096
+ for (const entry of ctx.seen.entries()) {
23097
+ const seen = entry[1];
23098
+ if (seen.def && seen.defId) {
23099
+ defs[seen.defId] = seen.def;
23100
+ }
23101
+ }
23102
+ // set definitions in result
23103
+ if (ctx.external) ;
23104
+ else {
23105
+ if (Object.keys(defs).length > 0) {
23106
+ if (ctx.target === "draft-2020-12") {
23107
+ result.$defs = defs;
23108
+ }
23109
+ else {
23110
+ result.definitions = defs;
23111
+ }
23112
+ }
23113
+ }
23114
+ try {
23115
+ // this "finalizes" this schema and ensures all cycles are removed
23116
+ // each call to finalize() is functionally independent
23117
+ // though the seen map is shared
23118
+ const finalized = JSON.parse(JSON.stringify(result));
23119
+ Object.defineProperty(finalized, "~standard", {
23120
+ value: {
23121
+ ...schema["~standard"],
23122
+ jsonSchema: {
23123
+ input: createStandardJSONSchemaMethod(schema, "input"),
23124
+ output: createStandardJSONSchemaMethod(schema, "output"),
23125
+ },
23126
+ },
23127
+ enumerable: false,
23128
+ writable: false,
23129
+ });
23130
+ return finalized;
23131
+ }
23132
+ catch (_err) {
23133
+ throw new Error("Error converting schema to JSON.");
23134
+ }
23135
+ }
23136
+ function isTransforming(_schema, _ctx) {
23137
+ const ctx = _ctx ?? { seen: new Set() };
23138
+ if (ctx.seen.has(_schema))
23139
+ return false;
23140
+ ctx.seen.add(_schema);
23141
+ const def = _schema._zod.def;
23142
+ if (def.type === "transform")
23143
+ return true;
23144
+ if (def.type === "array")
23145
+ return isTransforming(def.element, ctx);
23146
+ if (def.type === "set")
23147
+ return isTransforming(def.valueType, ctx);
23148
+ if (def.type === "lazy")
23149
+ return isTransforming(def.getter(), ctx);
23150
+ if (def.type === "promise" ||
23151
+ def.type === "optional" ||
23152
+ def.type === "nonoptional" ||
23153
+ def.type === "nullable" ||
23154
+ def.type === "readonly" ||
23155
+ def.type === "default" ||
23156
+ def.type === "prefault") {
23157
+ return isTransforming(def.innerType, ctx);
23158
+ }
23159
+ if (def.type === "intersection") {
23160
+ return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
23161
+ }
23162
+ if (def.type === "record" || def.type === "map") {
23163
+ return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
23164
+ }
23165
+ if (def.type === "pipe") {
23166
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
23167
+ }
23168
+ if (def.type === "object") {
23169
+ for (const key in def.shape) {
23170
+ if (isTransforming(def.shape[key], ctx))
23171
+ return true;
23172
+ }
23173
+ return false;
23174
+ }
23175
+ if (def.type === "union") {
23176
+ for (const option of def.options) {
23177
+ if (isTransforming(option, ctx))
23178
+ return true;
23179
+ }
23180
+ return false;
23181
+ }
23182
+ if (def.type === "tuple") {
23183
+ for (const item of def.items) {
23184
+ if (isTransforming(item, ctx))
23185
+ return true;
23186
+ }
23187
+ if (def.rest && isTransforming(def.rest, ctx))
23188
+ return true;
23189
+ return false;
23190
+ }
23191
+ return false;
23192
+ }
23193
+ /**
23194
+ * Creates a toJSONSchema method for a schema instance.
23195
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
23196
+ */
23197
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
23198
+ const ctx = initializeContext({ ...params, processors });
23199
+ process$1(schema, ctx);
23200
+ extractDefs(ctx, schema);
23201
+ return finalize(ctx, schema);
23202
+ };
23203
+ const createStandardJSONSchemaMethod = (schema, io) => (params) => {
23204
+ const { libraryOptions, target } = params ?? {};
23205
+ const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors: {} });
23206
+ process$1(schema, ctx);
23207
+ extractDefs(ctx, schema);
23208
+ return finalize(ctx, schema);
23209
+ };
23210
+
23211
+ const formatMap = {
23212
+ guid: "uuid",
23213
+ url: "uri",
23214
+ datetime: "date-time",
23215
+ json_string: "json-string",
23216
+ regex: "", // do not set
23217
+ };
23218
+ // ==================== SIMPLE TYPE PROCESSORS ====================
23219
+ const stringProcessor = (schema, ctx, _json, _params) => {
23220
+ const json = _json;
23221
+ json.type = "string";
23222
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod
23223
+ .bag;
23224
+ if (typeof minimum === "number")
23225
+ json.minLength = minimum;
23226
+ if (typeof maximum === "number")
23227
+ json.maxLength = maximum;
23228
+ // custom pattern overrides format
23229
+ if (format) {
23230
+ json.format = formatMap[format] ?? format;
23231
+ if (json.format === "")
23232
+ delete json.format; // empty format is not valid
23233
+ }
23234
+ if (contentEncoding)
23235
+ json.contentEncoding = contentEncoding;
23236
+ if (patterns && patterns.size > 0) {
23237
+ const regexes = [...patterns];
23238
+ if (regexes.length === 1)
23239
+ json.pattern = regexes[0].source;
23240
+ else if (regexes.length > 1) {
23241
+ json.allOf = [
23242
+ ...regexes.map((regex) => ({
23243
+ ...(ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0"
23244
+ ? { type: "string" }
23245
+ : {}),
23246
+ pattern: regex.source,
23247
+ })),
23248
+ ];
23249
+ }
23250
+ }
23251
+ };
23252
+ const neverProcessor = (_schema, _ctx, json, _params) => {
23253
+ json.not = {};
23254
+ };
23255
+ const anyProcessor = (_schema, _ctx, _json, _params) => {
23256
+ // empty schema accepts anything
23257
+ };
23258
+ const unknownProcessor = (_schema, _ctx, _json, _params) => {
23259
+ // empty schema accepts anything
23260
+ };
23261
+ const enumProcessor = (schema, _ctx, json, _params) => {
23262
+ const def = schema._zod.def;
23263
+ const values = getEnumValues(def.entries);
23264
+ // Number enums can have both string and number values
23265
+ if (values.every((v) => typeof v === "number"))
23266
+ json.type = "number";
23267
+ if (values.every((v) => typeof v === "string"))
23268
+ json.type = "string";
23269
+ json.enum = values;
23270
+ };
23271
+ const customProcessor = (_schema, ctx, _json, _params) => {
23272
+ if (ctx.unrepresentable === "throw") {
23273
+ throw new Error("Custom types cannot be represented in JSON Schema");
23274
+ }
23275
+ };
23276
+ const transformProcessor = (_schema, ctx, _json, _params) => {
23277
+ if (ctx.unrepresentable === "throw") {
23278
+ throw new Error("Transforms cannot be represented in JSON Schema");
23279
+ }
23280
+ };
23281
+ // ==================== COMPOSITE TYPE PROCESSORS ====================
23282
+ const arrayProcessor = (schema, ctx, _json, params) => {
23283
+ const json = _json;
23284
+ const def = schema._zod.def;
23285
+ const { minimum, maximum } = schema._zod.bag;
23286
+ if (typeof minimum === "number")
23287
+ json.minItems = minimum;
23288
+ if (typeof maximum === "number")
23289
+ json.maxItems = maximum;
23290
+ json.type = "array";
23291
+ json.items = process$1(def.element, ctx, { ...params, path: [...params.path, "items"] });
23292
+ };
23293
+ const objectProcessor = (schema, ctx, _json, params) => {
23294
+ const json = _json;
23295
+ const def = schema._zod.def;
23296
+ json.type = "object";
23297
+ json.properties = {};
23298
+ const shape = def.shape;
23299
+ for (const key in shape) {
23300
+ json.properties[key] = process$1(shape[key], ctx, {
23301
+ ...params,
23302
+ path: [...params.path, "properties", key],
23303
+ });
23304
+ }
23305
+ // required keys
23306
+ const allKeys = new Set(Object.keys(shape));
23307
+ const requiredKeys = new Set([...allKeys].filter((key) => {
23308
+ const v = def.shape[key]._zod;
23309
+ if (ctx.io === "input") {
23310
+ return v.optin === undefined;
23311
+ }
23312
+ else {
23313
+ return v.optout === undefined;
23314
+ }
23315
+ }));
23316
+ if (requiredKeys.size > 0) {
23317
+ json.required = Array.from(requiredKeys);
23318
+ }
23319
+ // catchall
23320
+ if (def.catchall?._zod.def.type === "never") {
23321
+ // strict
23322
+ json.additionalProperties = false;
23323
+ }
23324
+ else if (!def.catchall) {
23325
+ // regular
23326
+ if (ctx.io === "output")
23327
+ json.additionalProperties = false;
23328
+ }
23329
+ else if (def.catchall) {
23330
+ json.additionalProperties = process$1(def.catchall, ctx, {
23331
+ ...params,
23332
+ path: [...params.path, "additionalProperties"],
23333
+ });
23334
+ }
23335
+ };
23336
+ const unionProcessor = (schema, ctx, json, params) => {
23337
+ const def = schema._zod.def;
23338
+ // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
23339
+ // This includes both z.xor() and discriminated unions
23340
+ const isExclusive = def.inclusive === false;
23341
+ const options = def.options.map((x, i) => process$1(x, ctx, {
23342
+ ...params,
23343
+ path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
23344
+ }));
23345
+ if (isExclusive) {
23346
+ json.oneOf = options;
23347
+ }
23348
+ else {
23349
+ json.anyOf = options;
23350
+ }
23351
+ };
23352
+ const intersectionProcessor = (schema, ctx, json, params) => {
23353
+ const def = schema._zod.def;
23354
+ const a = process$1(def.left, ctx, {
23355
+ ...params,
23356
+ path: [...params.path, "allOf", 0],
23357
+ });
23358
+ const b = process$1(def.right, ctx, {
23359
+ ...params,
23360
+ path: [...params.path, "allOf", 1],
23361
+ });
23362
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
23363
+ const allOf = [
23364
+ ...(isSimpleIntersection(a) ? a.allOf : [a]),
23365
+ ...(isSimpleIntersection(b) ? b.allOf : [b]),
23366
+ ];
23367
+ json.allOf = allOf;
23368
+ };
23369
+ const recordProcessor = (schema, ctx, _json, params) => {
23370
+ const json = _json;
23371
+ const def = schema._zod.def;
23372
+ json.type = "object";
23373
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
23374
+ json.propertyNames = process$1(def.keyType, ctx, {
23375
+ ...params,
23376
+ path: [...params.path, "propertyNames"],
23377
+ });
23378
+ }
23379
+ json.additionalProperties = process$1(def.valueType, ctx, {
23380
+ ...params,
23381
+ path: [...params.path, "additionalProperties"],
23382
+ });
23383
+ };
23384
+ const nullableProcessor = (schema, ctx, json, params) => {
23385
+ const def = schema._zod.def;
23386
+ const inner = process$1(def.innerType, ctx, params);
23387
+ const seen = ctx.seen.get(schema);
23388
+ if (ctx.target === "openapi-3.0") {
23389
+ seen.ref = def.innerType;
23390
+ json.nullable = true;
23391
+ }
23392
+ else {
23393
+ json.anyOf = [inner, { type: "null" }];
23394
+ }
23395
+ };
23396
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
23397
+ const def = schema._zod.def;
23398
+ process$1(def.innerType, ctx, params);
23399
+ const seen = ctx.seen.get(schema);
23400
+ seen.ref = def.innerType;
23401
+ };
23402
+ const defaultProcessor = (schema, ctx, json, params) => {
23403
+ const def = schema._zod.def;
23404
+ process$1(def.innerType, ctx, params);
23405
+ const seen = ctx.seen.get(schema);
23406
+ seen.ref = def.innerType;
23407
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
23408
+ };
23409
+ const prefaultProcessor = (schema, ctx, json, params) => {
23410
+ const def = schema._zod.def;
23411
+ process$1(def.innerType, ctx, params);
23412
+ const seen = ctx.seen.get(schema);
23413
+ seen.ref = def.innerType;
23414
+ if (ctx.io === "input")
23415
+ json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
23416
+ };
23417
+ const catchProcessor = (schema, ctx, json, params) => {
23418
+ const def = schema._zod.def;
23419
+ process$1(def.innerType, ctx, params);
23420
+ const seen = ctx.seen.get(schema);
23421
+ seen.ref = def.innerType;
23422
+ let catchValue;
23423
+ try {
23424
+ catchValue = def.catchValue(undefined);
23425
+ }
23426
+ catch {
23427
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
23428
+ }
23429
+ json.default = catchValue;
23430
+ };
23431
+ const pipeProcessor = (schema, ctx, _json, params) => {
23432
+ const def = schema._zod.def;
23433
+ const innerType = ctx.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
23434
+ process$1(innerType, ctx, params);
23435
+ const seen = ctx.seen.get(schema);
23436
+ seen.ref = innerType;
23437
+ };
23438
+ const readonlyProcessor = (schema, ctx, json, params) => {
23439
+ const def = schema._zod.def;
23440
+ process$1(def.innerType, ctx, params);
23441
+ const seen = ctx.seen.get(schema);
23442
+ seen.ref = def.innerType;
23443
+ json.readOnly = true;
23444
+ };
23445
+ const optionalProcessor = (schema, ctx, _json, params) => {
23446
+ const def = schema._zod.def;
23447
+ process$1(def.innerType, ctx, params);
23448
+ const seen = ctx.seen.get(schema);
23449
+ seen.ref = def.innerType;
23450
+ };
23451
+
23452
+ const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
23453
+ $ZodISODateTime.init(inst, def);
23454
+ ZodStringFormat.init(inst, def);
23455
+ });
23456
+ function datetime(params) {
23457
+ return _isoDateTime(ZodISODateTime, params);
23458
+ }
23459
+ const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
23460
+ $ZodISODate.init(inst, def);
23461
+ ZodStringFormat.init(inst, def);
23462
+ });
23463
+ function date(params) {
23464
+ return _isoDate(ZodISODate, params);
23465
+ }
23466
+ const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
23467
+ $ZodISOTime.init(inst, def);
23468
+ ZodStringFormat.init(inst, def);
23469
+ });
23470
+ function time(params) {
23471
+ return _isoTime(ZodISOTime, params);
23472
+ }
23473
+ const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
23474
+ $ZodISODuration.init(inst, def);
23475
+ ZodStringFormat.init(inst, def);
23476
+ });
23477
+ function duration(params) {
23478
+ return _isoDuration(ZodISODuration, params);
23479
+ }
23480
+
23481
+ const initializer = (inst, issues) => {
23482
+ $ZodError.init(inst, issues);
23483
+ inst.name = "ZodError";
23484
+ Object.defineProperties(inst, {
23485
+ format: {
23486
+ value: (mapper) => formatError(inst, mapper),
23487
+ // enumerable: false,
23488
+ },
23489
+ flatten: {
23490
+ value: (mapper) => flattenError(inst, mapper),
23491
+ // enumerable: false,
23492
+ },
23493
+ addIssue: {
23494
+ value: (issue) => {
23495
+ inst.issues.push(issue);
23496
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
23497
+ },
23498
+ // enumerable: false,
23499
+ },
23500
+ addIssues: {
23501
+ value: (issues) => {
23502
+ inst.issues.push(...issues);
23503
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
23504
+ },
23505
+ // enumerable: false,
23506
+ },
23507
+ isEmpty: {
23508
+ get() {
23509
+ return inst.issues.length === 0;
23510
+ },
23511
+ // enumerable: false,
23512
+ },
23513
+ });
23514
+ // Object.defineProperty(inst, "isEmpty", {
23515
+ // get() {
23516
+ // return inst.issues.length === 0;
23517
+ // },
23518
+ // });
23519
+ };
23520
+ const ZodRealError = $constructor("ZodError", initializer, {
23521
+ Parent: Error,
23522
+ });
23523
+ // /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
23524
+ // export type ErrorMapCtx = core.$ZodErrorMapCtx;
23525
+
23526
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
23527
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
23528
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
23529
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
23530
+ // Codec functions
23531
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
23532
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
23533
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
23534
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
23535
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
23536
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
23537
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
23538
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
23539
+
23540
+ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
23541
+ $ZodType.init(inst, def);
23542
+ Object.assign(inst["~standard"], {
23543
+ jsonSchema: {
23544
+ input: createStandardJSONSchemaMethod(inst, "input"),
23545
+ output: createStandardJSONSchemaMethod(inst, "output"),
23546
+ },
23547
+ });
23548
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
23549
+ inst.def = def;
23550
+ inst.type = def.type;
23551
+ Object.defineProperty(inst, "_def", { value: def });
23552
+ // base methods
23553
+ inst.check = (...checks) => {
23554
+ return inst.clone(mergeDefs(def, {
23555
+ checks: [
23556
+ ...(def.checks ?? []),
23557
+ ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
23558
+ ],
23559
+ }));
23560
+ };
23561
+ inst.clone = (def, params) => clone(inst, def, params);
23562
+ inst.brand = () => inst;
23563
+ inst.register = ((reg, meta) => {
23564
+ reg.add(inst, meta);
23565
+ return inst;
23566
+ });
23567
+ // parsing
23568
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
23569
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
23570
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
23571
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
23572
+ inst.spa = inst.safeParseAsync;
23573
+ // encoding/decoding
23574
+ inst.encode = (data, params) => encode(inst, data, params);
23575
+ inst.decode = (data, params) => decode(inst, data, params);
23576
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
23577
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
23578
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
23579
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
23580
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
23581
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
23582
+ // refinements
23583
+ inst.refine = (check, params) => inst.check(refine(check, params));
23584
+ inst.superRefine = (refinement) => inst.check(superRefine(refinement));
23585
+ inst.overwrite = (fn) => inst.check(_overwrite(fn));
23586
+ // wrappers
23587
+ inst.optional = () => optional(inst);
23588
+ inst.nullable = () => nullable(inst);
23589
+ inst.nullish = () => optional(nullable(inst));
23590
+ inst.nonoptional = (params) => nonoptional(inst, params);
23591
+ inst.array = () => array(inst);
23592
+ inst.or = (arg) => union([inst, arg]);
23593
+ inst.and = (arg) => intersection(inst, arg);
23594
+ inst.transform = (tx) => pipe(inst, transform(tx));
23595
+ inst.default = (def) => _default(inst, def);
23596
+ inst.prefault = (def) => prefault(inst, def);
23597
+ // inst.coalesce = (def, params) => coalesce(inst, def, params);
23598
+ inst.catch = (params) => _catch(inst, params);
23599
+ inst.pipe = (target) => pipe(inst, target);
23600
+ inst.readonly = () => readonly(inst);
23601
+ // meta
23602
+ inst.describe = (description) => {
23603
+ const cl = inst.clone();
23604
+ globalRegistry.add(cl, { description });
23605
+ return cl;
23606
+ };
23607
+ Object.defineProperty(inst, "description", {
23608
+ get() {
23609
+ return globalRegistry.get(inst)?.description;
23610
+ },
23611
+ configurable: true,
23612
+ });
23613
+ inst.meta = (...args) => {
23614
+ if (args.length === 0) {
23615
+ return globalRegistry.get(inst);
23616
+ }
23617
+ const cl = inst.clone();
23618
+ globalRegistry.add(cl, args[0]);
23619
+ return cl;
23620
+ };
23621
+ // helpers
23622
+ inst.isOptional = () => inst.safeParse(undefined).success;
23623
+ inst.isNullable = () => inst.safeParse(null).success;
23624
+ return inst;
23625
+ });
23626
+ /** @internal */
23627
+ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
23628
+ $ZodString.init(inst, def);
23629
+ ZodType.init(inst, def);
23630
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
23631
+ const bag = inst._zod.bag;
23632
+ inst.format = bag.format ?? null;
23633
+ inst.minLength = bag.minimum ?? null;
23634
+ inst.maxLength = bag.maximum ?? null;
23635
+ // validations
23636
+ inst.regex = (...args) => inst.check(_regex(...args));
23637
+ inst.includes = (...args) => inst.check(_includes(...args));
23638
+ inst.startsWith = (...args) => inst.check(_startsWith(...args));
23639
+ inst.endsWith = (...args) => inst.check(_endsWith(...args));
23640
+ inst.min = (...args) => inst.check(_minLength(...args));
23641
+ inst.max = (...args) => inst.check(_maxLength(...args));
23642
+ inst.length = (...args) => inst.check(_length(...args));
23643
+ inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
23644
+ inst.lowercase = (params) => inst.check(_lowercase(params));
23645
+ inst.uppercase = (params) => inst.check(_uppercase(params));
23646
+ // transforms
23647
+ inst.trim = () => inst.check(_trim());
23648
+ inst.normalize = (...args) => inst.check(_normalize(...args));
23649
+ inst.toLowerCase = () => inst.check(_toLowerCase());
23650
+ inst.toUpperCase = () => inst.check(_toUpperCase());
23651
+ inst.slugify = () => inst.check(_slugify());
23652
+ });
23653
+ const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
23654
+ $ZodString.init(inst, def);
23655
+ _ZodString.init(inst, def);
23656
+ inst.email = (params) => inst.check(_email(ZodEmail, params));
23657
+ inst.url = (params) => inst.check(_url(ZodURL, params));
23658
+ inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
23659
+ inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
23660
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
23661
+ inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
23662
+ inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
23663
+ inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
23664
+ inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
23665
+ inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
23666
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
23667
+ inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
23668
+ inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
23669
+ inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
23670
+ inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
23671
+ inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
23672
+ inst.xid = (params) => inst.check(_xid(ZodXID, params));
23673
+ inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
23674
+ inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
23675
+ inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
23676
+ inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
23677
+ inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
23678
+ inst.e164 = (params) => inst.check(_e164(ZodE164, params));
23679
+ // iso
23680
+ inst.datetime = (params) => inst.check(datetime(params));
23681
+ inst.date = (params) => inst.check(date(params));
23682
+ inst.time = (params) => inst.check(time(params));
23683
+ inst.duration = (params) => inst.check(duration(params));
23684
+ });
23685
+ function string(params) {
23686
+ return _string(ZodString, params);
23687
+ }
23688
+ const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
23689
+ $ZodStringFormat.init(inst, def);
23690
+ _ZodString.init(inst, def);
23691
+ });
23692
+ const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
23693
+ // ZodStringFormat.init(inst, def);
23694
+ $ZodEmail.init(inst, def);
23695
+ ZodStringFormat.init(inst, def);
23696
+ });
23697
+ const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
23698
+ // ZodStringFormat.init(inst, def);
23699
+ $ZodGUID.init(inst, def);
23700
+ ZodStringFormat.init(inst, def);
23701
+ });
23702
+ const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
23703
+ // ZodStringFormat.init(inst, def);
23704
+ $ZodUUID.init(inst, def);
23705
+ ZodStringFormat.init(inst, def);
23706
+ });
23707
+ const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
23708
+ // ZodStringFormat.init(inst, def);
23709
+ $ZodURL.init(inst, def);
23710
+ ZodStringFormat.init(inst, def);
23711
+ });
23712
+ const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
23713
+ // ZodStringFormat.init(inst, def);
23714
+ $ZodEmoji.init(inst, def);
23715
+ ZodStringFormat.init(inst, def);
23716
+ });
23717
+ const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
23718
+ // ZodStringFormat.init(inst, def);
23719
+ $ZodNanoID.init(inst, def);
23720
+ ZodStringFormat.init(inst, def);
23721
+ });
23722
+ const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
23723
+ // ZodStringFormat.init(inst, def);
23724
+ $ZodCUID.init(inst, def);
23725
+ ZodStringFormat.init(inst, def);
23726
+ });
23727
+ const ZodCUID2 = /*@__PURE__*/ $constructor("ZodCUID2", (inst, def) => {
23728
+ // ZodStringFormat.init(inst, def);
23729
+ $ZodCUID2.init(inst, def);
23730
+ ZodStringFormat.init(inst, def);
23731
+ });
23732
+ const ZodULID = /*@__PURE__*/ $constructor("ZodULID", (inst, def) => {
23733
+ // ZodStringFormat.init(inst, def);
23734
+ $ZodULID.init(inst, def);
23735
+ ZodStringFormat.init(inst, def);
23736
+ });
23737
+ const ZodXID = /*@__PURE__*/ $constructor("ZodXID", (inst, def) => {
23738
+ // ZodStringFormat.init(inst, def);
23739
+ $ZodXID.init(inst, def);
23740
+ ZodStringFormat.init(inst, def);
23741
+ });
23742
+ const ZodKSUID = /*@__PURE__*/ $constructor("ZodKSUID", (inst, def) => {
23743
+ // ZodStringFormat.init(inst, def);
23744
+ $ZodKSUID.init(inst, def);
23745
+ ZodStringFormat.init(inst, def);
23746
+ });
23747
+ const ZodIPv4 = /*@__PURE__*/ $constructor("ZodIPv4", (inst, def) => {
23748
+ // ZodStringFormat.init(inst, def);
23749
+ $ZodIPv4.init(inst, def);
23750
+ ZodStringFormat.init(inst, def);
23751
+ });
23752
+ const ZodIPv6 = /*@__PURE__*/ $constructor("ZodIPv6", (inst, def) => {
23753
+ // ZodStringFormat.init(inst, def);
23754
+ $ZodIPv6.init(inst, def);
23755
+ ZodStringFormat.init(inst, def);
23756
+ });
23757
+ const ZodCIDRv4 = /*@__PURE__*/ $constructor("ZodCIDRv4", (inst, def) => {
23758
+ $ZodCIDRv4.init(inst, def);
23759
+ ZodStringFormat.init(inst, def);
23760
+ });
23761
+ const ZodCIDRv6 = /*@__PURE__*/ $constructor("ZodCIDRv6", (inst, def) => {
23762
+ $ZodCIDRv6.init(inst, def);
23763
+ ZodStringFormat.init(inst, def);
23764
+ });
23765
+ const ZodBase64 = /*@__PURE__*/ $constructor("ZodBase64", (inst, def) => {
23766
+ // ZodStringFormat.init(inst, def);
23767
+ $ZodBase64.init(inst, def);
23768
+ ZodStringFormat.init(inst, def);
23769
+ });
23770
+ const ZodBase64URL = /*@__PURE__*/ $constructor("ZodBase64URL", (inst, def) => {
23771
+ // ZodStringFormat.init(inst, def);
23772
+ $ZodBase64URL.init(inst, def);
23773
+ ZodStringFormat.init(inst, def);
23774
+ });
23775
+ const ZodE164 = /*@__PURE__*/ $constructor("ZodE164", (inst, def) => {
23776
+ // ZodStringFormat.init(inst, def);
23777
+ $ZodE164.init(inst, def);
23778
+ ZodStringFormat.init(inst, def);
23779
+ });
23780
+ const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
23781
+ // ZodStringFormat.init(inst, def);
23782
+ $ZodJWT.init(inst, def);
23783
+ ZodStringFormat.init(inst, def);
23784
+ });
23785
+ const ZodAny = /*@__PURE__*/ $constructor("ZodAny", (inst, def) => {
23786
+ $ZodAny.init(inst, def);
23787
+ ZodType.init(inst, def);
23788
+ inst._zod.processJSONSchema = (ctx, json, params) => anyProcessor();
23789
+ });
23790
+ function any() {
23791
+ return _any(ZodAny);
23792
+ }
23793
+ const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
23794
+ $ZodUnknown.init(inst, def);
23795
+ ZodType.init(inst, def);
23796
+ inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
23797
+ });
23798
+ function unknown() {
23799
+ return _unknown(ZodUnknown);
23800
+ }
23801
+ const ZodNever = /*@__PURE__*/ $constructor("ZodNever", (inst, def) => {
23802
+ $ZodNever.init(inst, def);
23803
+ ZodType.init(inst, def);
23804
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
23805
+ });
23806
+ function never(params) {
23807
+ return _never(ZodNever, params);
23808
+ }
23809
+ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
23810
+ $ZodArray.init(inst, def);
23811
+ ZodType.init(inst, def);
23812
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
23813
+ inst.element = def.element;
23814
+ inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
23815
+ inst.nonempty = (params) => inst.check(_minLength(1, params));
23816
+ inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
23817
+ inst.length = (len, params) => inst.check(_length(len, params));
23818
+ inst.unwrap = () => inst.element;
23819
+ });
23820
+ function array(element, params) {
23821
+ return _array(ZodArray, element, params);
23822
+ }
23823
+ const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
23824
+ $ZodObjectJIT.init(inst, def);
23825
+ ZodType.init(inst, def);
23826
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
23827
+ defineLazy(inst, "shape", () => {
23828
+ return def.shape;
23829
+ });
23830
+ inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
23831
+ inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall });
23832
+ inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
23833
+ inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
23834
+ inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
23835
+ inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
23836
+ inst.extend = (incoming) => {
23837
+ return extend(inst, incoming);
23838
+ };
23839
+ inst.safeExtend = (incoming) => {
23840
+ return safeExtend(inst, incoming);
23841
+ };
23842
+ inst.merge = (other) => merge(inst, other);
23843
+ inst.pick = (mask) => pick(inst, mask);
23844
+ inst.omit = (mask) => omit(inst, mask);
23845
+ inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
23846
+ inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
23847
+ });
23848
+ function object(shape, params) {
23849
+ const def = {
23850
+ type: "object",
23851
+ shape: shape ?? {},
23852
+ ...normalizeParams(params),
23853
+ };
23854
+ return new ZodObject(def);
23855
+ }
23856
+ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
23857
+ $ZodUnion.init(inst, def);
23858
+ ZodType.init(inst, def);
23859
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
23860
+ inst.options = def.options;
23861
+ });
23862
+ function union(options, params) {
23863
+ return new ZodUnion({
23864
+ type: "union",
23865
+ options: options,
23866
+ ...normalizeParams(params),
23867
+ });
23868
+ }
23869
+ const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
23870
+ $ZodIntersection.init(inst, def);
23871
+ ZodType.init(inst, def);
23872
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
23873
+ });
23874
+ function intersection(left, right) {
23875
+ return new ZodIntersection({
23876
+ type: "intersection",
23877
+ left: left,
23878
+ right: right,
23879
+ });
23880
+ }
23881
+ const ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
23882
+ $ZodRecord.init(inst, def);
23883
+ ZodType.init(inst, def);
23884
+ inst._zod.processJSONSchema = (ctx, json, params) => recordProcessor(inst, ctx, json, params);
23885
+ inst.keyType = def.keyType;
23886
+ inst.valueType = def.valueType;
23887
+ });
23888
+ function record(keyType, valueType, params) {
23889
+ return new ZodRecord({
23890
+ type: "record",
23891
+ keyType,
23892
+ valueType: valueType,
23893
+ ...normalizeParams(params),
23894
+ });
23895
+ }
23896
+ const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
23897
+ $ZodEnum.init(inst, def);
23898
+ ZodType.init(inst, def);
23899
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
23900
+ inst.enum = def.entries;
23901
+ inst.options = Object.values(def.entries);
23902
+ const keys = new Set(Object.keys(def.entries));
23903
+ inst.extract = (values, params) => {
23904
+ const newEntries = {};
23905
+ for (const value of values) {
23906
+ if (keys.has(value)) {
23907
+ newEntries[value] = def.entries[value];
23908
+ }
23909
+ else
23910
+ throw new Error(`Key ${value} not found in enum`);
23911
+ }
23912
+ return new ZodEnum({
23913
+ ...def,
23914
+ checks: [],
23915
+ ...normalizeParams(params),
23916
+ entries: newEntries,
23917
+ });
23918
+ };
23919
+ inst.exclude = (values, params) => {
23920
+ const newEntries = { ...def.entries };
23921
+ for (const value of values) {
23922
+ if (keys.has(value)) {
23923
+ delete newEntries[value];
23924
+ }
23925
+ else
23926
+ throw new Error(`Key ${value} not found in enum`);
23927
+ }
23928
+ return new ZodEnum({
23929
+ ...def,
23930
+ checks: [],
23931
+ ...normalizeParams(params),
23932
+ entries: newEntries,
23933
+ });
23934
+ };
23935
+ });
23936
+ function _enum(values, params) {
23937
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
23938
+ return new ZodEnum({
23939
+ type: "enum",
23940
+ entries,
23941
+ ...normalizeParams(params),
23942
+ });
23943
+ }
23944
+ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
23945
+ $ZodTransform.init(inst, def);
23946
+ ZodType.init(inst, def);
23947
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
23948
+ inst._zod.parse = (payload, _ctx) => {
23949
+ if (_ctx.direction === "backward") {
23950
+ throw new $ZodEncodeError(inst.constructor.name);
23951
+ }
23952
+ payload.addIssue = (issue$1) => {
23953
+ if (typeof issue$1 === "string") {
23954
+ payload.issues.push(issue(issue$1, payload.value, def));
23955
+ }
23956
+ else {
23957
+ // for Zod 3 backwards compatibility
23958
+ const _issue = issue$1;
23959
+ if (_issue.fatal)
23960
+ _issue.continue = false;
23961
+ _issue.code ?? (_issue.code = "custom");
23962
+ _issue.input ?? (_issue.input = payload.value);
23963
+ _issue.inst ?? (_issue.inst = inst);
23964
+ // _issue.continue ??= true;
23965
+ payload.issues.push(issue(_issue));
23966
+ }
23967
+ };
23968
+ const output = def.transform(payload.value, payload);
23969
+ if (output instanceof Promise) {
23970
+ return output.then((output) => {
23971
+ payload.value = output;
23972
+ return payload;
23973
+ });
23974
+ }
23975
+ payload.value = output;
23976
+ return payload;
23977
+ };
23978
+ });
23979
+ function transform(fn) {
23980
+ return new ZodTransform({
23981
+ type: "transform",
23982
+ transform: fn,
23983
+ });
23984
+ }
23985
+ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
23986
+ $ZodOptional.init(inst, def);
23987
+ ZodType.init(inst, def);
23988
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
23989
+ inst.unwrap = () => inst._zod.def.innerType;
23990
+ });
23991
+ function optional(innerType) {
23992
+ return new ZodOptional({
23993
+ type: "optional",
23994
+ innerType: innerType,
23995
+ });
23996
+ }
23997
+ const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
23998
+ $ZodNullable.init(inst, def);
23999
+ ZodType.init(inst, def);
24000
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
24001
+ inst.unwrap = () => inst._zod.def.innerType;
24002
+ });
24003
+ function nullable(innerType) {
24004
+ return new ZodNullable({
24005
+ type: "nullable",
24006
+ innerType: innerType,
24007
+ });
24008
+ }
24009
+ const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
24010
+ $ZodDefault.init(inst, def);
24011
+ ZodType.init(inst, def);
24012
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
24013
+ inst.unwrap = () => inst._zod.def.innerType;
24014
+ inst.removeDefault = inst.unwrap;
24015
+ });
24016
+ function _default(innerType, defaultValue) {
24017
+ return new ZodDefault({
24018
+ type: "default",
24019
+ innerType: innerType,
24020
+ get defaultValue() {
24021
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
24022
+ },
24023
+ });
24024
+ }
24025
+ const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
24026
+ $ZodPrefault.init(inst, def);
24027
+ ZodType.init(inst, def);
24028
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
24029
+ inst.unwrap = () => inst._zod.def.innerType;
24030
+ });
24031
+ function prefault(innerType, defaultValue) {
24032
+ return new ZodPrefault({
24033
+ type: "prefault",
24034
+ innerType: innerType,
24035
+ get defaultValue() {
24036
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
24037
+ },
24038
+ });
24039
+ }
24040
+ const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
24041
+ $ZodNonOptional.init(inst, def);
24042
+ ZodType.init(inst, def);
24043
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
24044
+ inst.unwrap = () => inst._zod.def.innerType;
24045
+ });
24046
+ function nonoptional(innerType, params) {
24047
+ return new ZodNonOptional({
24048
+ type: "nonoptional",
24049
+ innerType: innerType,
24050
+ ...normalizeParams(params),
24051
+ });
24052
+ }
24053
+ const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
24054
+ $ZodCatch.init(inst, def);
24055
+ ZodType.init(inst, def);
24056
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
24057
+ inst.unwrap = () => inst._zod.def.innerType;
24058
+ inst.removeCatch = inst.unwrap;
24059
+ });
24060
+ function _catch(innerType, catchValue) {
24061
+ return new ZodCatch({
24062
+ type: "catch",
24063
+ innerType: innerType,
24064
+ catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
24065
+ });
24066
+ }
24067
+ const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
24068
+ $ZodPipe.init(inst, def);
24069
+ ZodType.init(inst, def);
24070
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
24071
+ inst.in = def.in;
24072
+ inst.out = def.out;
24073
+ });
24074
+ function pipe(in_, out) {
24075
+ return new ZodPipe({
24076
+ type: "pipe",
24077
+ in: in_,
24078
+ out: out,
24079
+ // ...util.normalizeParams(params),
24080
+ });
24081
+ }
24082
+ const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
24083
+ $ZodReadonly.init(inst, def);
24084
+ ZodType.init(inst, def);
24085
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
24086
+ inst.unwrap = () => inst._zod.def.innerType;
24087
+ });
24088
+ function readonly(innerType) {
24089
+ return new ZodReadonly({
24090
+ type: "readonly",
24091
+ innerType: innerType,
24092
+ });
24093
+ }
24094
+ const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
24095
+ $ZodCustom.init(inst, def);
24096
+ ZodType.init(inst, def);
24097
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
24098
+ });
24099
+ function refine(fn, _params = {}) {
24100
+ return _refine(ZodCustom, fn, _params);
24101
+ }
24102
+ // superRefine
24103
+ function superRefine(fn) {
24104
+ return _superRefine(fn);
24105
+ }
24106
+
20196
24107
  /**
20197
24108
  * Create a tool for discovering other agents in the Sekuire network
20198
24109
  */
@@ -20200,8 +24111,8 @@ function createDiscoveryTool(client) {
20200
24111
  return {
20201
24112
  name: 'discover_agents',
20202
24113
  description: "Search for other AI agents in the Sekuire network by capability or name. Use this to find agents that can help with specific tasks (e.g., 'jira', 'google drive').",
20203
- schema: z.object({
20204
- query: z.string().describe("The search query (e.g., 'jira', 'drive', 'github')"),
24114
+ schema: object({
24115
+ query: string().describe("The search query (e.g., 'jira', 'drive', 'github')"),
20205
24116
  }),
20206
24117
  execute: async ({ query }) => {
20207
24118
  try {
@@ -20229,10 +24140,10 @@ function createDelegationTool(client) {
20229
24140
  return {
20230
24141
  name: 'delegate_task',
20231
24142
  description: "Delegate a task to another agent. Requires the target agent's Sekuire ID (found via discover_agents).",
20232
- schema: z.object({
20233
- agent_id: z.string().describe('The Sekuire ID of the target agent'),
20234
- task: z.string().describe('The task description or message to send to the agent'),
20235
- context: z.record(z.any()).optional().describe('Optional context data to pass'),
24143
+ schema: object({
24144
+ agent_id: string().describe('The Sekuire ID of the target agent'),
24145
+ task: string().describe('The task description or message to send to the agent'),
24146
+ context: record(any()).optional().describe('Optional context data to pass'),
20236
24147
  }),
20237
24148
  execute: async ({ agent_id, task, context }) => {
20238
24149
  try {