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