@uipath/uipath-typescript 1.0.0-beta.16 → 1.0.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,17 +1,3774 @@
1
1
  'use strict';
2
2
 
3
- var zod = require('zod');
4
3
  var sdkLogs = require('@opentelemetry/sdk-logs');
5
4
  var axios = require('axios');
6
5
 
7
- zod.z.object({
8
- baseUrl: zod.z.string().url().default('https://cloud.uipath.com'),
9
- orgName: zod.z.string().min(1),
10
- tenantName: zod.z.string().min(1),
11
- secret: zod.z.string().optional(),
12
- clientId: zod.z.string().optional(),
13
- redirectUri: zod.z.string().url().optional(),
14
- scope: zod.z.string().optional()
6
+ /** A special constant with type `never` */
7
+ function $constructor(name, initializer, params) {
8
+ function init(inst, def) {
9
+ if (!inst._zod) {
10
+ Object.defineProperty(inst, "_zod", {
11
+ value: {
12
+ def,
13
+ constr: _,
14
+ traits: new Set(),
15
+ },
16
+ enumerable: false,
17
+ });
18
+ }
19
+ if (inst._zod.traits.has(name)) {
20
+ return;
21
+ }
22
+ inst._zod.traits.add(name);
23
+ initializer(inst, def);
24
+ // support prototype modifications
25
+ const proto = _.prototype;
26
+ const keys = Object.keys(proto);
27
+ for (let i = 0; i < keys.length; i++) {
28
+ const k = keys[i];
29
+ if (!(k in inst)) {
30
+ inst[k] = proto[k].bind(inst);
31
+ }
32
+ }
33
+ }
34
+ // doesn't work if Parent has a constructor with arguments
35
+ const Parent = params?.Parent ?? Object;
36
+ class Definition extends Parent {
37
+ }
38
+ Object.defineProperty(Definition, "name", { value: name });
39
+ function _(def) {
40
+ var _a;
41
+ const inst = params?.Parent ? new Definition() : this;
42
+ init(inst, def);
43
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
44
+ for (const fn of inst._zod.deferred) {
45
+ fn();
46
+ }
47
+ return inst;
48
+ }
49
+ Object.defineProperty(_, "init", { value: init });
50
+ Object.defineProperty(_, Symbol.hasInstance, {
51
+ value: (inst) => {
52
+ if (params?.Parent && inst instanceof params.Parent)
53
+ return true;
54
+ return inst?._zod?.traits?.has(name);
55
+ },
56
+ });
57
+ Object.defineProperty(_, "name", { value: name });
58
+ return _;
59
+ }
60
+ class $ZodAsyncError extends Error {
61
+ constructor() {
62
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
63
+ }
64
+ }
65
+ class $ZodEncodeError extends Error {
66
+ constructor(name) {
67
+ super(`Encountered unidirectional transform during encode: ${name}`);
68
+ this.name = "ZodEncodeError";
69
+ }
70
+ }
71
+ const globalConfig = {};
72
+ function config(newConfig) {
73
+ return globalConfig;
74
+ }
75
+
76
+ // functions
77
+ function getEnumValues(entries) {
78
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
79
+ const values = Object.entries(entries)
80
+ .filter(([k, _]) => numericValues.indexOf(+k) === -1)
81
+ .map(([_, v]) => v);
82
+ return values;
83
+ }
84
+ function jsonStringifyReplacer(_, value) {
85
+ if (typeof value === "bigint")
86
+ return value.toString();
87
+ return value;
88
+ }
89
+ function cached(getter) {
90
+ return {
91
+ get value() {
92
+ {
93
+ const value = getter();
94
+ Object.defineProperty(this, "value", { value });
95
+ return value;
96
+ }
97
+ },
98
+ };
99
+ }
100
+ function nullish(input) {
101
+ return input === null || input === undefined;
102
+ }
103
+ function cleanRegex(source) {
104
+ const start = source.startsWith("^") ? 1 : 0;
105
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
106
+ return source.slice(start, end);
107
+ }
108
+ const EVALUATING = Symbol("evaluating");
109
+ function defineLazy(object, key, getter) {
110
+ let value = undefined;
111
+ Object.defineProperty(object, key, {
112
+ get() {
113
+ if (value === EVALUATING) {
114
+ // Circular reference detected, return undefined to break the cycle
115
+ return undefined;
116
+ }
117
+ if (value === undefined) {
118
+ value = EVALUATING;
119
+ value = getter();
120
+ }
121
+ return value;
122
+ },
123
+ set(v) {
124
+ Object.defineProperty(object, key, {
125
+ value: v,
126
+ // configurable: true,
127
+ });
128
+ // object[key] = v;
129
+ },
130
+ configurable: true,
131
+ });
132
+ }
133
+ function assignProp(target, prop, value) {
134
+ Object.defineProperty(target, prop, {
135
+ value,
136
+ writable: true,
137
+ enumerable: true,
138
+ configurable: true,
139
+ });
140
+ }
141
+ function mergeDefs(...defs) {
142
+ const mergedDescriptors = {};
143
+ for (const def of defs) {
144
+ const descriptors = Object.getOwnPropertyDescriptors(def);
145
+ Object.assign(mergedDescriptors, descriptors);
146
+ }
147
+ return Object.defineProperties({}, mergedDescriptors);
148
+ }
149
+ function esc(str) {
150
+ return JSON.stringify(str);
151
+ }
152
+ function slugify(input) {
153
+ return input
154
+ .toLowerCase()
155
+ .trim()
156
+ .replace(/[^\w\s-]/g, "")
157
+ .replace(/[\s_-]+/g, "-")
158
+ .replace(/^-+|-+$/g, "");
159
+ }
160
+ const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
161
+ function isObject(data) {
162
+ return typeof data === "object" && data !== null && !Array.isArray(data);
163
+ }
164
+ const allowsEval = cached(() => {
165
+ // @ts-ignore
166
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
167
+ return false;
168
+ }
169
+ try {
170
+ const F = Function;
171
+ new F("");
172
+ return true;
173
+ }
174
+ catch (_) {
175
+ return false;
176
+ }
177
+ });
178
+ function isPlainObject(o) {
179
+ if (isObject(o) === false)
180
+ return false;
181
+ // modified constructor
182
+ const ctor = o.constructor;
183
+ if (ctor === undefined)
184
+ return true;
185
+ if (typeof ctor !== "function")
186
+ return true;
187
+ // modified prototype
188
+ const prot = ctor.prototype;
189
+ if (isObject(prot) === false)
190
+ return false;
191
+ // ctor doesn't have static `isPrototypeOf`
192
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
193
+ return false;
194
+ }
195
+ return true;
196
+ }
197
+ function shallowClone(o) {
198
+ if (isPlainObject(o))
199
+ return { ...o };
200
+ if (Array.isArray(o))
201
+ return [...o];
202
+ return o;
203
+ }
204
+ const propertyKeyTypes = new Set(["string", "number", "symbol"]);
205
+ function escapeRegex(str) {
206
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
207
+ }
208
+ // zod-specific utils
209
+ function clone(inst, def, params) {
210
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
211
+ if (!def || params?.parent)
212
+ cl._zod.parent = inst;
213
+ return cl;
214
+ }
215
+ function normalizeParams(_params) {
216
+ const params = _params;
217
+ if (!params)
218
+ return {};
219
+ if (typeof params === "string")
220
+ return { error: () => params };
221
+ if (params?.message !== undefined) {
222
+ if (params?.error !== undefined)
223
+ throw new Error("Cannot specify both `message` and `error` params");
224
+ params.error = params.message;
225
+ }
226
+ delete params.message;
227
+ if (typeof params.error === "string")
228
+ return { ...params, error: () => params.error };
229
+ return params;
230
+ }
231
+ function optionalKeys(shape) {
232
+ return Object.keys(shape).filter((k) => {
233
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
234
+ });
235
+ }
236
+ function pick(schema, mask) {
237
+ const currDef = schema._zod.def;
238
+ const def = mergeDefs(schema._zod.def, {
239
+ get shape() {
240
+ const newShape = {};
241
+ for (const key in mask) {
242
+ if (!(key in currDef.shape)) {
243
+ throw new Error(`Unrecognized key: "${key}"`);
244
+ }
245
+ if (!mask[key])
246
+ continue;
247
+ newShape[key] = currDef.shape[key];
248
+ }
249
+ assignProp(this, "shape", newShape); // self-caching
250
+ return newShape;
251
+ },
252
+ checks: [],
253
+ });
254
+ return clone(schema, def);
255
+ }
256
+ function omit(schema, mask) {
257
+ const currDef = schema._zod.def;
258
+ const def = mergeDefs(schema._zod.def, {
259
+ get shape() {
260
+ const newShape = { ...schema._zod.def.shape };
261
+ for (const key in mask) {
262
+ if (!(key in currDef.shape)) {
263
+ throw new Error(`Unrecognized key: "${key}"`);
264
+ }
265
+ if (!mask[key])
266
+ continue;
267
+ delete newShape[key];
268
+ }
269
+ assignProp(this, "shape", newShape); // self-caching
270
+ return newShape;
271
+ },
272
+ checks: [],
273
+ });
274
+ return clone(schema, def);
275
+ }
276
+ function extend(schema, shape) {
277
+ if (!isPlainObject(shape)) {
278
+ throw new Error("Invalid input to extend: expected a plain object");
279
+ }
280
+ const checks = schema._zod.def.checks;
281
+ const hasChecks = checks && checks.length > 0;
282
+ if (hasChecks) {
283
+ throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
284
+ }
285
+ const def = mergeDefs(schema._zod.def, {
286
+ get shape() {
287
+ const _shape = { ...schema._zod.def.shape, ...shape };
288
+ assignProp(this, "shape", _shape); // self-caching
289
+ return _shape;
290
+ },
291
+ checks: [],
292
+ });
293
+ return clone(schema, def);
294
+ }
295
+ function safeExtend(schema, shape) {
296
+ if (!isPlainObject(shape)) {
297
+ throw new Error("Invalid input to safeExtend: expected a plain object");
298
+ }
299
+ const def = {
300
+ ...schema._zod.def,
301
+ get shape() {
302
+ const _shape = { ...schema._zod.def.shape, ...shape };
303
+ assignProp(this, "shape", _shape); // self-caching
304
+ return _shape;
305
+ },
306
+ checks: schema._zod.def.checks,
307
+ };
308
+ return clone(schema, def);
309
+ }
310
+ function merge(a, b) {
311
+ const def = mergeDefs(a._zod.def, {
312
+ get shape() {
313
+ const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
314
+ assignProp(this, "shape", _shape); // self-caching
315
+ return _shape;
316
+ },
317
+ get catchall() {
318
+ return b._zod.def.catchall;
319
+ },
320
+ checks: [], // delete existing checks
321
+ });
322
+ return clone(a, def);
323
+ }
324
+ function partial(Class, schema, mask) {
325
+ const def = mergeDefs(schema._zod.def, {
326
+ get shape() {
327
+ const oldShape = schema._zod.def.shape;
328
+ const shape = { ...oldShape };
329
+ if (mask) {
330
+ for (const key in mask) {
331
+ if (!(key in oldShape)) {
332
+ throw new Error(`Unrecognized key: "${key}"`);
333
+ }
334
+ if (!mask[key])
335
+ continue;
336
+ // if (oldShape[key]!._zod.optin === "optional") continue;
337
+ shape[key] = Class
338
+ ? new Class({
339
+ type: "optional",
340
+ innerType: oldShape[key],
341
+ })
342
+ : oldShape[key];
343
+ }
344
+ }
345
+ else {
346
+ for (const key in oldShape) {
347
+ // if (oldShape[key]!._zod.optin === "optional") continue;
348
+ shape[key] = Class
349
+ ? new Class({
350
+ type: "optional",
351
+ innerType: oldShape[key],
352
+ })
353
+ : oldShape[key];
354
+ }
355
+ }
356
+ assignProp(this, "shape", shape); // self-caching
357
+ return shape;
358
+ },
359
+ checks: [],
360
+ });
361
+ return clone(schema, def);
362
+ }
363
+ function required(Class, schema, mask) {
364
+ const def = mergeDefs(schema._zod.def, {
365
+ get shape() {
366
+ const oldShape = schema._zod.def.shape;
367
+ const shape = { ...oldShape };
368
+ if (mask) {
369
+ for (const key in mask) {
370
+ if (!(key in shape)) {
371
+ throw new Error(`Unrecognized key: "${key}"`);
372
+ }
373
+ if (!mask[key])
374
+ continue;
375
+ // overwrite with non-optional
376
+ shape[key] = new Class({
377
+ type: "nonoptional",
378
+ innerType: oldShape[key],
379
+ });
380
+ }
381
+ }
382
+ else {
383
+ for (const key in oldShape) {
384
+ // overwrite with non-optional
385
+ shape[key] = new Class({
386
+ type: "nonoptional",
387
+ innerType: oldShape[key],
388
+ });
389
+ }
390
+ }
391
+ assignProp(this, "shape", shape); // self-caching
392
+ return shape;
393
+ },
394
+ checks: [],
395
+ });
396
+ return clone(schema, def);
397
+ }
398
+ // invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
399
+ function aborted(x, startIndex = 0) {
400
+ if (x.aborted === true)
401
+ return true;
402
+ for (let i = startIndex; i < x.issues.length; i++) {
403
+ if (x.issues[i]?.continue !== true) {
404
+ return true;
405
+ }
406
+ }
407
+ return false;
408
+ }
409
+ function prefixIssues(path, issues) {
410
+ return issues.map((iss) => {
411
+ var _a;
412
+ (_a = iss).path ?? (_a.path = []);
413
+ iss.path.unshift(path);
414
+ return iss;
415
+ });
416
+ }
417
+ function unwrapMessage(message) {
418
+ return typeof message === "string" ? message : message?.message;
419
+ }
420
+ function finalizeIssue(iss, ctx, config) {
421
+ const full = { ...iss, path: iss.path ?? [] };
422
+ // for backwards compatibility
423
+ if (!iss.message) {
424
+ const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
425
+ unwrapMessage(ctx?.error?.(iss)) ??
426
+ unwrapMessage(config.customError?.(iss)) ??
427
+ unwrapMessage(config.localeError?.(iss)) ??
428
+ "Invalid input";
429
+ full.message = message;
430
+ }
431
+ // delete (full as any).def;
432
+ delete full.inst;
433
+ delete full.continue;
434
+ if (!ctx?.reportInput) {
435
+ delete full.input;
436
+ }
437
+ return full;
438
+ }
439
+ function getLengthableOrigin(input) {
440
+ if (Array.isArray(input))
441
+ return "array";
442
+ if (typeof input === "string")
443
+ return "string";
444
+ return "unknown";
445
+ }
446
+ function issue(...args) {
447
+ const [iss, input, inst] = args;
448
+ if (typeof iss === "string") {
449
+ return {
450
+ message: iss,
451
+ code: "custom",
452
+ input,
453
+ inst,
454
+ };
455
+ }
456
+ return { ...iss };
457
+ }
458
+
459
+ const initializer$1 = (inst, def) => {
460
+ inst.name = "$ZodError";
461
+ Object.defineProperty(inst, "_zod", {
462
+ value: inst._zod,
463
+ enumerable: false,
464
+ });
465
+ Object.defineProperty(inst, "issues", {
466
+ value: def,
467
+ enumerable: false,
468
+ });
469
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
470
+ Object.defineProperty(inst, "toString", {
471
+ value: () => inst.message,
472
+ enumerable: false,
473
+ });
474
+ };
475
+ const $ZodError = $constructor("$ZodError", initializer$1);
476
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
477
+ function flattenError(error, mapper = (issue) => issue.message) {
478
+ const fieldErrors = {};
479
+ const formErrors = [];
480
+ for (const sub of error.issues) {
481
+ if (sub.path.length > 0) {
482
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
483
+ fieldErrors[sub.path[0]].push(mapper(sub));
484
+ }
485
+ else {
486
+ formErrors.push(mapper(sub));
487
+ }
488
+ }
489
+ return { formErrors, fieldErrors };
490
+ }
491
+ function formatError(error, mapper = (issue) => issue.message) {
492
+ const fieldErrors = { _errors: [] };
493
+ const processError = (error) => {
494
+ for (const issue of error.issues) {
495
+ if (issue.code === "invalid_union" && issue.errors.length) {
496
+ issue.errors.map((issues) => processError({ issues }));
497
+ }
498
+ else if (issue.code === "invalid_key") {
499
+ processError({ issues: issue.issues });
500
+ }
501
+ else if (issue.code === "invalid_element") {
502
+ processError({ issues: issue.issues });
503
+ }
504
+ else if (issue.path.length === 0) {
505
+ fieldErrors._errors.push(mapper(issue));
506
+ }
507
+ else {
508
+ let curr = fieldErrors;
509
+ let i = 0;
510
+ while (i < issue.path.length) {
511
+ const el = issue.path[i];
512
+ const terminal = i === issue.path.length - 1;
513
+ if (!terminal) {
514
+ curr[el] = curr[el] || { _errors: [] };
515
+ }
516
+ else {
517
+ curr[el] = curr[el] || { _errors: [] };
518
+ curr[el]._errors.push(mapper(issue));
519
+ }
520
+ curr = curr[el];
521
+ i++;
522
+ }
523
+ }
524
+ }
525
+ };
526
+ processError(error);
527
+ return fieldErrors;
528
+ }
529
+
530
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
531
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
532
+ const result = schema._zod.run({ value, issues: [] }, ctx);
533
+ if (result instanceof Promise) {
534
+ throw new $ZodAsyncError();
535
+ }
536
+ if (result.issues.length) {
537
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
538
+ captureStackTrace(e, _params?.callee);
539
+ throw e;
540
+ }
541
+ return result.value;
542
+ };
543
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
544
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
545
+ let result = schema._zod.run({ value, issues: [] }, ctx);
546
+ if (result instanceof Promise)
547
+ result = await result;
548
+ if (result.issues.length) {
549
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
550
+ captureStackTrace(e, params?.callee);
551
+ throw e;
552
+ }
553
+ return result.value;
554
+ };
555
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
556
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
557
+ const result = schema._zod.run({ value, issues: [] }, ctx);
558
+ if (result instanceof Promise) {
559
+ throw new $ZodAsyncError();
560
+ }
561
+ return result.issues.length
562
+ ? {
563
+ success: false,
564
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
565
+ }
566
+ : { success: true, data: result.value };
567
+ };
568
+ const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
569
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
570
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
571
+ let result = schema._zod.run({ value, issues: [] }, ctx);
572
+ if (result instanceof Promise)
573
+ result = await result;
574
+ return result.issues.length
575
+ ? {
576
+ success: false,
577
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
578
+ }
579
+ : { success: true, data: result.value };
580
+ };
581
+ const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
582
+ const _encode = (_Err) => (schema, value, _ctx) => {
583
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
584
+ return _parse(_Err)(schema, value, ctx);
585
+ };
586
+ const _decode = (_Err) => (schema, value, _ctx) => {
587
+ return _parse(_Err)(schema, value, _ctx);
588
+ };
589
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
590
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
591
+ return _parseAsync(_Err)(schema, value, ctx);
592
+ };
593
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
594
+ return _parseAsync(_Err)(schema, value, _ctx);
595
+ };
596
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
597
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
598
+ return _safeParse(_Err)(schema, value, ctx);
599
+ };
600
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
601
+ return _safeParse(_Err)(schema, value, _ctx);
602
+ };
603
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
604
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
605
+ return _safeParseAsync(_Err)(schema, value, ctx);
606
+ };
607
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
608
+ return _safeParseAsync(_Err)(schema, value, _ctx);
609
+ };
610
+
611
+ const cuid = /^[cC][^\s-]{8,}$/;
612
+ const cuid2 = /^[0-9a-z]+$/;
613
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
614
+ const xid = /^[0-9a-vA-V]{20}$/;
615
+ const ksuid = /^[A-Za-z0-9]{27}$/;
616
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
617
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
618
+ 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)?)?)$/;
619
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
620
+ 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})$/;
621
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
622
+ *
623
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
624
+ const uuid = (version) => {
625
+ if (!version)
626
+ 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)$/;
627
+ 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})$`);
628
+ };
629
+ /** Practical email validation */
630
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
631
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
632
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
633
+ function emoji() {
634
+ return new RegExp(_emoji$1, "u");
635
+ }
636
+ 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])$/;
637
+ 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}|:))$/;
638
+ 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])$/;
639
+ 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])$/;
640
+ // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
641
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
642
+ const base64url = /^[A-Za-z0-9_-]*$/;
643
+ // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
644
+ const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
645
+ // 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])))`;
646
+ 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])))`;
647
+ const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
648
+ function timeSource(args) {
649
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
650
+ const regex = typeof args.precision === "number"
651
+ ? args.precision === -1
652
+ ? `${hhmm}`
653
+ : args.precision === 0
654
+ ? `${hhmm}:[0-5]\\d`
655
+ : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
656
+ : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
657
+ return regex;
658
+ }
659
+ function time$1(args) {
660
+ return new RegExp(`^${timeSource(args)}$`);
661
+ }
662
+ // Adapted from https://stackoverflow.com/a/3143231
663
+ function datetime$1(args) {
664
+ const time = timeSource({ precision: args.precision });
665
+ const opts = ["Z"];
666
+ if (args.local)
667
+ opts.push("");
668
+ // if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
669
+ if (args.offset)
670
+ opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
671
+ const timeRegex = `${time}(?:${opts.join("|")})`;
672
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
673
+ }
674
+ const string$1 = (params) => {
675
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
676
+ return new RegExp(`^${regex}$`);
677
+ };
678
+ // regex for string with no uppercase letters
679
+ const lowercase = /^[^A-Z]*$/;
680
+ // regex for string with no lowercase letters
681
+ const uppercase = /^[^a-z]*$/;
682
+
683
+ // import { $ZodType } from "./schemas.js";
684
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
685
+ var _a;
686
+ inst._zod ?? (inst._zod = {});
687
+ inst._zod.def = def;
688
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
689
+ });
690
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
691
+ var _a;
692
+ $ZodCheck.init(inst, def);
693
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
694
+ const val = payload.value;
695
+ return !nullish(val) && val.length !== undefined;
696
+ });
697
+ inst._zod.onattach.push((inst) => {
698
+ const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
699
+ if (def.maximum < curr)
700
+ inst._zod.bag.maximum = def.maximum;
701
+ });
702
+ inst._zod.check = (payload) => {
703
+ const input = payload.value;
704
+ const length = input.length;
705
+ if (length <= def.maximum)
706
+ return;
707
+ const origin = getLengthableOrigin(input);
708
+ payload.issues.push({
709
+ origin,
710
+ code: "too_big",
711
+ maximum: def.maximum,
712
+ inclusive: true,
713
+ input,
714
+ inst,
715
+ continue: !def.abort,
716
+ });
717
+ };
718
+ });
719
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
720
+ var _a;
721
+ $ZodCheck.init(inst, def);
722
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
723
+ const val = payload.value;
724
+ return !nullish(val) && val.length !== undefined;
725
+ });
726
+ inst._zod.onattach.push((inst) => {
727
+ const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
728
+ if (def.minimum > curr)
729
+ inst._zod.bag.minimum = def.minimum;
730
+ });
731
+ inst._zod.check = (payload) => {
732
+ const input = payload.value;
733
+ const length = input.length;
734
+ if (length >= def.minimum)
735
+ return;
736
+ const origin = getLengthableOrigin(input);
737
+ payload.issues.push({
738
+ origin,
739
+ code: "too_small",
740
+ minimum: def.minimum,
741
+ inclusive: true,
742
+ input,
743
+ inst,
744
+ continue: !def.abort,
745
+ });
746
+ };
747
+ });
748
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
749
+ var _a;
750
+ $ZodCheck.init(inst, def);
751
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
752
+ const val = payload.value;
753
+ return !nullish(val) && val.length !== undefined;
754
+ });
755
+ inst._zod.onattach.push((inst) => {
756
+ const bag = inst._zod.bag;
757
+ bag.minimum = def.length;
758
+ bag.maximum = def.length;
759
+ bag.length = def.length;
760
+ });
761
+ inst._zod.check = (payload) => {
762
+ const input = payload.value;
763
+ const length = input.length;
764
+ if (length === def.length)
765
+ return;
766
+ const origin = getLengthableOrigin(input);
767
+ const tooBig = length > def.length;
768
+ payload.issues.push({
769
+ origin,
770
+ ...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
771
+ inclusive: true,
772
+ exact: true,
773
+ input: payload.value,
774
+ inst,
775
+ continue: !def.abort,
776
+ });
777
+ };
778
+ });
779
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
780
+ var _a, _b;
781
+ $ZodCheck.init(inst, def);
782
+ inst._zod.onattach.push((inst) => {
783
+ const bag = inst._zod.bag;
784
+ bag.format = def.format;
785
+ if (def.pattern) {
786
+ bag.patterns ?? (bag.patterns = new Set());
787
+ bag.patterns.add(def.pattern);
788
+ }
789
+ });
790
+ if (def.pattern)
791
+ (_a = inst._zod).check ?? (_a.check = (payload) => {
792
+ def.pattern.lastIndex = 0;
793
+ if (def.pattern.test(payload.value))
794
+ return;
795
+ payload.issues.push({
796
+ origin: "string",
797
+ code: "invalid_format",
798
+ format: def.format,
799
+ input: payload.value,
800
+ ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
801
+ inst,
802
+ continue: !def.abort,
803
+ });
804
+ });
805
+ else
806
+ (_b = inst._zod).check ?? (_b.check = () => { });
807
+ });
808
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
809
+ $ZodCheckStringFormat.init(inst, def);
810
+ inst._zod.check = (payload) => {
811
+ def.pattern.lastIndex = 0;
812
+ if (def.pattern.test(payload.value))
813
+ return;
814
+ payload.issues.push({
815
+ origin: "string",
816
+ code: "invalid_format",
817
+ format: "regex",
818
+ input: payload.value,
819
+ pattern: def.pattern.toString(),
820
+ inst,
821
+ continue: !def.abort,
822
+ });
823
+ };
824
+ });
825
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
826
+ def.pattern ?? (def.pattern = lowercase);
827
+ $ZodCheckStringFormat.init(inst, def);
828
+ });
829
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
830
+ def.pattern ?? (def.pattern = uppercase);
831
+ $ZodCheckStringFormat.init(inst, def);
832
+ });
833
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
834
+ $ZodCheck.init(inst, def);
835
+ const escapedRegex = escapeRegex(def.includes);
836
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
837
+ def.pattern = pattern;
838
+ inst._zod.onattach.push((inst) => {
839
+ const bag = inst._zod.bag;
840
+ bag.patterns ?? (bag.patterns = new Set());
841
+ bag.patterns.add(pattern);
842
+ });
843
+ inst._zod.check = (payload) => {
844
+ if (payload.value.includes(def.includes, def.position))
845
+ return;
846
+ payload.issues.push({
847
+ origin: "string",
848
+ code: "invalid_format",
849
+ format: "includes",
850
+ includes: def.includes,
851
+ input: payload.value,
852
+ inst,
853
+ continue: !def.abort,
854
+ });
855
+ };
856
+ });
857
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
858
+ $ZodCheck.init(inst, def);
859
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
860
+ def.pattern ?? (def.pattern = pattern);
861
+ inst._zod.onattach.push((inst) => {
862
+ const bag = inst._zod.bag;
863
+ bag.patterns ?? (bag.patterns = new Set());
864
+ bag.patterns.add(pattern);
865
+ });
866
+ inst._zod.check = (payload) => {
867
+ if (payload.value.startsWith(def.prefix))
868
+ return;
869
+ payload.issues.push({
870
+ origin: "string",
871
+ code: "invalid_format",
872
+ format: "starts_with",
873
+ prefix: def.prefix,
874
+ input: payload.value,
875
+ inst,
876
+ continue: !def.abort,
877
+ });
878
+ };
879
+ });
880
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
881
+ $ZodCheck.init(inst, def);
882
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
883
+ def.pattern ?? (def.pattern = pattern);
884
+ inst._zod.onattach.push((inst) => {
885
+ const bag = inst._zod.bag;
886
+ bag.patterns ?? (bag.patterns = new Set());
887
+ bag.patterns.add(pattern);
888
+ });
889
+ inst._zod.check = (payload) => {
890
+ if (payload.value.endsWith(def.suffix))
891
+ return;
892
+ payload.issues.push({
893
+ origin: "string",
894
+ code: "invalid_format",
895
+ format: "ends_with",
896
+ suffix: def.suffix,
897
+ input: payload.value,
898
+ inst,
899
+ continue: !def.abort,
900
+ });
901
+ };
902
+ });
903
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
904
+ $ZodCheck.init(inst, def);
905
+ inst._zod.check = (payload) => {
906
+ payload.value = def.tx(payload.value);
907
+ };
908
+ });
909
+
910
+ class Doc {
911
+ constructor(args = []) {
912
+ this.content = [];
913
+ this.indent = 0;
914
+ if (this)
915
+ this.args = args;
916
+ }
917
+ indented(fn) {
918
+ this.indent += 1;
919
+ fn(this);
920
+ this.indent -= 1;
921
+ }
922
+ write(arg) {
923
+ if (typeof arg === "function") {
924
+ arg(this, { execution: "sync" });
925
+ arg(this, { execution: "async" });
926
+ return;
927
+ }
928
+ const content = arg;
929
+ const lines = content.split("\n").filter((x) => x);
930
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
931
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
932
+ for (const line of dedented) {
933
+ this.content.push(line);
934
+ }
935
+ }
936
+ compile() {
937
+ const F = Function;
938
+ const args = this?.args;
939
+ const content = this?.content ?? [``];
940
+ const lines = [...content.map((x) => ` ${x}`)];
941
+ // console.log(lines.join("\n"));
942
+ return new F(...args, lines.join("\n"));
943
+ }
944
+ }
945
+
946
+ const version = {
947
+ major: 4,
948
+ minor: 2,
949
+ patch: 1,
950
+ };
951
+
952
+ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
953
+ var _a;
954
+ inst ?? (inst = {});
955
+ inst._zod.def = def; // set _def property
956
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
957
+ inst._zod.version = version;
958
+ const checks = [...(inst._zod.def.checks ?? [])];
959
+ // if inst is itself a checks.$ZodCheck, run it as a check
960
+ if (inst._zod.traits.has("$ZodCheck")) {
961
+ checks.unshift(inst);
962
+ }
963
+ for (const ch of checks) {
964
+ for (const fn of ch._zod.onattach) {
965
+ fn(inst);
966
+ }
967
+ }
968
+ if (checks.length === 0) {
969
+ // deferred initializer
970
+ // inst._zod.parse is not yet defined
971
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
972
+ inst._zod.deferred?.push(() => {
973
+ inst._zod.run = inst._zod.parse;
974
+ });
975
+ }
976
+ else {
977
+ const runChecks = (payload, checks, ctx) => {
978
+ let isAborted = aborted(payload);
979
+ let asyncResult;
980
+ for (const ch of checks) {
981
+ if (ch._zod.def.when) {
982
+ const shouldRun = ch._zod.def.when(payload);
983
+ if (!shouldRun)
984
+ continue;
985
+ }
986
+ else if (isAborted) {
987
+ continue;
988
+ }
989
+ const currLen = payload.issues.length;
990
+ const _ = ch._zod.check(payload);
991
+ if (_ instanceof Promise && ctx?.async === false) {
992
+ throw new $ZodAsyncError();
993
+ }
994
+ if (asyncResult || _ instanceof Promise) {
995
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
996
+ await _;
997
+ const nextLen = payload.issues.length;
998
+ if (nextLen === currLen)
999
+ return;
1000
+ if (!isAborted)
1001
+ isAborted = aborted(payload, currLen);
1002
+ });
1003
+ }
1004
+ else {
1005
+ const nextLen = payload.issues.length;
1006
+ if (nextLen === currLen)
1007
+ continue;
1008
+ if (!isAborted)
1009
+ isAborted = aborted(payload, currLen);
1010
+ }
1011
+ }
1012
+ if (asyncResult) {
1013
+ return asyncResult.then(() => {
1014
+ return payload;
1015
+ });
1016
+ }
1017
+ return payload;
1018
+ };
1019
+ const handleCanaryResult = (canary, payload, ctx) => {
1020
+ // abort if the canary is aborted
1021
+ if (aborted(canary)) {
1022
+ canary.aborted = true;
1023
+ return canary;
1024
+ }
1025
+ // run checks first, then
1026
+ const checkResult = runChecks(payload, checks, ctx);
1027
+ if (checkResult instanceof Promise) {
1028
+ if (ctx.async === false)
1029
+ throw new $ZodAsyncError();
1030
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
1031
+ }
1032
+ return inst._zod.parse(checkResult, ctx);
1033
+ };
1034
+ inst._zod.run = (payload, ctx) => {
1035
+ if (ctx.skipChecks) {
1036
+ return inst._zod.parse(payload, ctx);
1037
+ }
1038
+ if (ctx.direction === "backward") {
1039
+ // run canary
1040
+ // initial pass (no checks)
1041
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
1042
+ if (canary instanceof Promise) {
1043
+ return canary.then((canary) => {
1044
+ return handleCanaryResult(canary, payload, ctx);
1045
+ });
1046
+ }
1047
+ return handleCanaryResult(canary, payload, ctx);
1048
+ }
1049
+ // forward
1050
+ const result = inst._zod.parse(payload, ctx);
1051
+ if (result instanceof Promise) {
1052
+ if (ctx.async === false)
1053
+ throw new $ZodAsyncError();
1054
+ return result.then((result) => runChecks(result, checks, ctx));
1055
+ }
1056
+ return runChecks(result, checks, ctx);
1057
+ };
1058
+ }
1059
+ inst["~standard"] = {
1060
+ validate: (value) => {
1061
+ try {
1062
+ const r = safeParse$1(inst, value);
1063
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
1064
+ }
1065
+ catch (_) {
1066
+ return safeParseAsync$1(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
1067
+ }
1068
+ },
1069
+ vendor: "zod",
1070
+ version: 1,
1071
+ };
1072
+ });
1073
+ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
1074
+ $ZodType.init(inst, def);
1075
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? string$1(inst._zod.bag);
1076
+ inst._zod.parse = (payload, _) => {
1077
+ if (def.coerce)
1078
+ try {
1079
+ payload.value = String(payload.value);
1080
+ }
1081
+ catch (_) { }
1082
+ if (typeof payload.value === "string")
1083
+ return payload;
1084
+ payload.issues.push({
1085
+ expected: "string",
1086
+ code: "invalid_type",
1087
+ input: payload.value,
1088
+ inst,
1089
+ });
1090
+ return payload;
1091
+ };
1092
+ });
1093
+ const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
1094
+ // check initialization must come first
1095
+ $ZodCheckStringFormat.init(inst, def);
1096
+ $ZodString.init(inst, def);
1097
+ });
1098
+ const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
1099
+ def.pattern ?? (def.pattern = guid);
1100
+ $ZodStringFormat.init(inst, def);
1101
+ });
1102
+ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
1103
+ if (def.version) {
1104
+ const versionMap = {
1105
+ v1: 1,
1106
+ v2: 2,
1107
+ v3: 3,
1108
+ v4: 4,
1109
+ v5: 5,
1110
+ v6: 6,
1111
+ v7: 7,
1112
+ v8: 8,
1113
+ };
1114
+ const v = versionMap[def.version];
1115
+ if (v === undefined)
1116
+ throw new Error(`Invalid UUID version: "${def.version}"`);
1117
+ def.pattern ?? (def.pattern = uuid(v));
1118
+ }
1119
+ else
1120
+ def.pattern ?? (def.pattern = uuid());
1121
+ $ZodStringFormat.init(inst, def);
1122
+ });
1123
+ const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
1124
+ def.pattern ?? (def.pattern = email);
1125
+ $ZodStringFormat.init(inst, def);
1126
+ });
1127
+ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
1128
+ $ZodStringFormat.init(inst, def);
1129
+ inst._zod.check = (payload) => {
1130
+ try {
1131
+ // Trim whitespace from input
1132
+ const trimmed = payload.value.trim();
1133
+ // @ts-ignore
1134
+ const url = new URL(trimmed);
1135
+ if (def.hostname) {
1136
+ def.hostname.lastIndex = 0;
1137
+ if (!def.hostname.test(url.hostname)) {
1138
+ payload.issues.push({
1139
+ code: "invalid_format",
1140
+ format: "url",
1141
+ note: "Invalid hostname",
1142
+ pattern: def.hostname.source,
1143
+ input: payload.value,
1144
+ inst,
1145
+ continue: !def.abort,
1146
+ });
1147
+ }
1148
+ }
1149
+ if (def.protocol) {
1150
+ def.protocol.lastIndex = 0;
1151
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
1152
+ payload.issues.push({
1153
+ code: "invalid_format",
1154
+ format: "url",
1155
+ note: "Invalid protocol",
1156
+ pattern: def.protocol.source,
1157
+ input: payload.value,
1158
+ inst,
1159
+ continue: !def.abort,
1160
+ });
1161
+ }
1162
+ }
1163
+ // Set the output value based on normalize flag
1164
+ if (def.normalize) {
1165
+ // Use normalized URL
1166
+ payload.value = url.href;
1167
+ }
1168
+ else {
1169
+ // Preserve the original input (trimmed)
1170
+ payload.value = trimmed;
1171
+ }
1172
+ return;
1173
+ }
1174
+ catch (_) {
1175
+ payload.issues.push({
1176
+ code: "invalid_format",
1177
+ format: "url",
1178
+ input: payload.value,
1179
+ inst,
1180
+ continue: !def.abort,
1181
+ });
1182
+ }
1183
+ };
1184
+ });
1185
+ const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
1186
+ def.pattern ?? (def.pattern = emoji());
1187
+ $ZodStringFormat.init(inst, def);
1188
+ });
1189
+ const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
1190
+ def.pattern ?? (def.pattern = nanoid);
1191
+ $ZodStringFormat.init(inst, def);
1192
+ });
1193
+ const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
1194
+ def.pattern ?? (def.pattern = cuid);
1195
+ $ZodStringFormat.init(inst, def);
1196
+ });
1197
+ const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
1198
+ def.pattern ?? (def.pattern = cuid2);
1199
+ $ZodStringFormat.init(inst, def);
1200
+ });
1201
+ const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
1202
+ def.pattern ?? (def.pattern = ulid);
1203
+ $ZodStringFormat.init(inst, def);
1204
+ });
1205
+ const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
1206
+ def.pattern ?? (def.pattern = xid);
1207
+ $ZodStringFormat.init(inst, def);
1208
+ });
1209
+ const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
1210
+ def.pattern ?? (def.pattern = ksuid);
1211
+ $ZodStringFormat.init(inst, def);
1212
+ });
1213
+ const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
1214
+ def.pattern ?? (def.pattern = datetime$1(def));
1215
+ $ZodStringFormat.init(inst, def);
1216
+ });
1217
+ const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
1218
+ def.pattern ?? (def.pattern = date$1);
1219
+ $ZodStringFormat.init(inst, def);
1220
+ });
1221
+ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
1222
+ def.pattern ?? (def.pattern = time$1(def));
1223
+ $ZodStringFormat.init(inst, def);
1224
+ });
1225
+ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
1226
+ def.pattern ?? (def.pattern = duration$1);
1227
+ $ZodStringFormat.init(inst, def);
1228
+ });
1229
+ const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
1230
+ def.pattern ?? (def.pattern = ipv4);
1231
+ $ZodStringFormat.init(inst, def);
1232
+ inst._zod.bag.format = `ipv4`;
1233
+ });
1234
+ const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
1235
+ def.pattern ?? (def.pattern = ipv6);
1236
+ $ZodStringFormat.init(inst, def);
1237
+ inst._zod.bag.format = `ipv6`;
1238
+ inst._zod.check = (payload) => {
1239
+ try {
1240
+ // @ts-ignore
1241
+ new URL(`http://[${payload.value}]`);
1242
+ // return;
1243
+ }
1244
+ catch {
1245
+ payload.issues.push({
1246
+ code: "invalid_format",
1247
+ format: "ipv6",
1248
+ input: payload.value,
1249
+ inst,
1250
+ continue: !def.abort,
1251
+ });
1252
+ }
1253
+ };
1254
+ });
1255
+ const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
1256
+ def.pattern ?? (def.pattern = cidrv4);
1257
+ $ZodStringFormat.init(inst, def);
1258
+ });
1259
+ const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
1260
+ def.pattern ?? (def.pattern = cidrv6); // not used for validation
1261
+ $ZodStringFormat.init(inst, def);
1262
+ inst._zod.check = (payload) => {
1263
+ const parts = payload.value.split("/");
1264
+ try {
1265
+ if (parts.length !== 2)
1266
+ throw new Error();
1267
+ const [address, prefix] = parts;
1268
+ if (!prefix)
1269
+ throw new Error();
1270
+ const prefixNum = Number(prefix);
1271
+ if (`${prefixNum}` !== prefix)
1272
+ throw new Error();
1273
+ if (prefixNum < 0 || prefixNum > 128)
1274
+ throw new Error();
1275
+ // @ts-ignore
1276
+ new URL(`http://[${address}]`);
1277
+ }
1278
+ catch {
1279
+ payload.issues.push({
1280
+ code: "invalid_format",
1281
+ format: "cidrv6",
1282
+ input: payload.value,
1283
+ inst,
1284
+ continue: !def.abort,
1285
+ });
1286
+ }
1287
+ };
1288
+ });
1289
+ ////////////////////////////// ZodBase64 //////////////////////////////
1290
+ function isValidBase64(data) {
1291
+ if (data === "")
1292
+ return true;
1293
+ if (data.length % 4 !== 0)
1294
+ return false;
1295
+ try {
1296
+ // @ts-ignore
1297
+ atob(data);
1298
+ return true;
1299
+ }
1300
+ catch {
1301
+ return false;
1302
+ }
1303
+ }
1304
+ const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
1305
+ def.pattern ?? (def.pattern = base64);
1306
+ $ZodStringFormat.init(inst, def);
1307
+ inst._zod.bag.contentEncoding = "base64";
1308
+ inst._zod.check = (payload) => {
1309
+ if (isValidBase64(payload.value))
1310
+ return;
1311
+ payload.issues.push({
1312
+ code: "invalid_format",
1313
+ format: "base64",
1314
+ input: payload.value,
1315
+ inst,
1316
+ continue: !def.abort,
1317
+ });
1318
+ };
1319
+ });
1320
+ ////////////////////////////// ZodBase64 //////////////////////////////
1321
+ function isValidBase64URL(data) {
1322
+ if (!base64url.test(data))
1323
+ return false;
1324
+ const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
1325
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
1326
+ return isValidBase64(padded);
1327
+ }
1328
+ const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
1329
+ def.pattern ?? (def.pattern = base64url);
1330
+ $ZodStringFormat.init(inst, def);
1331
+ inst._zod.bag.contentEncoding = "base64url";
1332
+ inst._zod.check = (payload) => {
1333
+ if (isValidBase64URL(payload.value))
1334
+ return;
1335
+ payload.issues.push({
1336
+ code: "invalid_format",
1337
+ format: "base64url",
1338
+ input: payload.value,
1339
+ inst,
1340
+ continue: !def.abort,
1341
+ });
1342
+ };
1343
+ });
1344
+ const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
1345
+ def.pattern ?? (def.pattern = e164);
1346
+ $ZodStringFormat.init(inst, def);
1347
+ });
1348
+ ////////////////////////////// ZodJWT //////////////////////////////
1349
+ function isValidJWT(token, algorithm = null) {
1350
+ try {
1351
+ const tokensParts = token.split(".");
1352
+ if (tokensParts.length !== 3)
1353
+ return false;
1354
+ const [header] = tokensParts;
1355
+ if (!header)
1356
+ return false;
1357
+ // @ts-ignore
1358
+ const parsedHeader = JSON.parse(atob(header));
1359
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
1360
+ return false;
1361
+ if (!parsedHeader.alg)
1362
+ return false;
1363
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
1364
+ return false;
1365
+ return true;
1366
+ }
1367
+ catch {
1368
+ return false;
1369
+ }
1370
+ }
1371
+ const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
1372
+ $ZodStringFormat.init(inst, def);
1373
+ inst._zod.check = (payload) => {
1374
+ if (isValidJWT(payload.value, def.alg))
1375
+ return;
1376
+ payload.issues.push({
1377
+ code: "invalid_format",
1378
+ format: "jwt",
1379
+ input: payload.value,
1380
+ inst,
1381
+ continue: !def.abort,
1382
+ });
1383
+ };
1384
+ });
1385
+ const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
1386
+ $ZodType.init(inst, def);
1387
+ inst._zod.parse = (payload) => payload;
1388
+ });
1389
+ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
1390
+ $ZodType.init(inst, def);
1391
+ inst._zod.parse = (payload, _ctx) => {
1392
+ payload.issues.push({
1393
+ expected: "never",
1394
+ code: "invalid_type",
1395
+ input: payload.value,
1396
+ inst,
1397
+ });
1398
+ return payload;
1399
+ };
1400
+ });
1401
+ function handleArrayResult(result, final, index) {
1402
+ if (result.issues.length) {
1403
+ final.issues.push(...prefixIssues(index, result.issues));
1404
+ }
1405
+ final.value[index] = result.value;
1406
+ }
1407
+ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
1408
+ $ZodType.init(inst, def);
1409
+ inst._zod.parse = (payload, ctx) => {
1410
+ const input = payload.value;
1411
+ if (!Array.isArray(input)) {
1412
+ payload.issues.push({
1413
+ expected: "array",
1414
+ code: "invalid_type",
1415
+ input,
1416
+ inst,
1417
+ });
1418
+ return payload;
1419
+ }
1420
+ payload.value = Array(input.length);
1421
+ const proms = [];
1422
+ for (let i = 0; i < input.length; i++) {
1423
+ const item = input[i];
1424
+ const result = def.element._zod.run({
1425
+ value: item,
1426
+ issues: [],
1427
+ }, ctx);
1428
+ if (result instanceof Promise) {
1429
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
1430
+ }
1431
+ else {
1432
+ handleArrayResult(result, payload, i);
1433
+ }
1434
+ }
1435
+ if (proms.length) {
1436
+ return Promise.all(proms).then(() => payload);
1437
+ }
1438
+ return payload; //handleArrayResultsAsync(parseResults, final);
1439
+ };
1440
+ });
1441
+ function handlePropertyResult(result, final, key, input) {
1442
+ if (result.issues.length) {
1443
+ final.issues.push(...prefixIssues(key, result.issues));
1444
+ }
1445
+ if (result.value === undefined) {
1446
+ if (key in input) {
1447
+ final.value[key] = undefined;
1448
+ }
1449
+ }
1450
+ else {
1451
+ final.value[key] = result.value;
1452
+ }
1453
+ }
1454
+ function normalizeDef(def) {
1455
+ const keys = Object.keys(def.shape);
1456
+ for (const k of keys) {
1457
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
1458
+ throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1459
+ }
1460
+ }
1461
+ const okeys = optionalKeys(def.shape);
1462
+ return {
1463
+ ...def,
1464
+ keys,
1465
+ keySet: new Set(keys),
1466
+ numKeys: keys.length,
1467
+ optionalKeys: new Set(okeys),
1468
+ };
1469
+ }
1470
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
1471
+ const unrecognized = [];
1472
+ // iterate over input keys
1473
+ const keySet = def.keySet;
1474
+ const _catchall = def.catchall._zod;
1475
+ const t = _catchall.def.type;
1476
+ for (const key in input) {
1477
+ if (keySet.has(key))
1478
+ continue;
1479
+ if (t === "never") {
1480
+ unrecognized.push(key);
1481
+ continue;
1482
+ }
1483
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
1484
+ if (r instanceof Promise) {
1485
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
1486
+ }
1487
+ else {
1488
+ handlePropertyResult(r, payload, key, input);
1489
+ }
1490
+ }
1491
+ if (unrecognized.length) {
1492
+ payload.issues.push({
1493
+ code: "unrecognized_keys",
1494
+ keys: unrecognized,
1495
+ input,
1496
+ inst,
1497
+ });
1498
+ }
1499
+ if (!proms.length)
1500
+ return payload;
1501
+ return Promise.all(proms).then(() => {
1502
+ return payload;
1503
+ });
1504
+ }
1505
+ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
1506
+ // requires cast because technically $ZodObject doesn't extend
1507
+ $ZodType.init(inst, def);
1508
+ // const sh = def.shape;
1509
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
1510
+ if (!desc?.get) {
1511
+ const sh = def.shape;
1512
+ Object.defineProperty(def, "shape", {
1513
+ get: () => {
1514
+ const newSh = { ...sh };
1515
+ Object.defineProperty(def, "shape", {
1516
+ value: newSh,
1517
+ });
1518
+ return newSh;
1519
+ },
1520
+ });
1521
+ }
1522
+ const _normalized = cached(() => normalizeDef(def));
1523
+ defineLazy(inst._zod, "propValues", () => {
1524
+ const shape = def.shape;
1525
+ const propValues = {};
1526
+ for (const key in shape) {
1527
+ const field = shape[key]._zod;
1528
+ if (field.values) {
1529
+ propValues[key] ?? (propValues[key] = new Set());
1530
+ for (const v of field.values)
1531
+ propValues[key].add(v);
1532
+ }
1533
+ }
1534
+ return propValues;
1535
+ });
1536
+ const isObject$1 = isObject;
1537
+ const catchall = def.catchall;
1538
+ let value;
1539
+ inst._zod.parse = (payload, ctx) => {
1540
+ value ?? (value = _normalized.value);
1541
+ const input = payload.value;
1542
+ if (!isObject$1(input)) {
1543
+ payload.issues.push({
1544
+ expected: "object",
1545
+ code: "invalid_type",
1546
+ input,
1547
+ inst,
1548
+ });
1549
+ return payload;
1550
+ }
1551
+ payload.value = {};
1552
+ const proms = [];
1553
+ const shape = value.shape;
1554
+ for (const key of value.keys) {
1555
+ const el = shape[key];
1556
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
1557
+ if (r instanceof Promise) {
1558
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
1559
+ }
1560
+ else {
1561
+ handlePropertyResult(r, payload, key, input);
1562
+ }
1563
+ }
1564
+ if (!catchall) {
1565
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
1566
+ }
1567
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
1568
+ };
1569
+ });
1570
+ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) => {
1571
+ // requires cast because technically $ZodObject doesn't extend
1572
+ $ZodObject.init(inst, def);
1573
+ const superParse = inst._zod.parse;
1574
+ const _normalized = cached(() => normalizeDef(def));
1575
+ const generateFastpass = (shape) => {
1576
+ const doc = new Doc(["shape", "payload", "ctx"]);
1577
+ const normalized = _normalized.value;
1578
+ const parseStr = (key) => {
1579
+ const k = esc(key);
1580
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1581
+ };
1582
+ doc.write(`const input = payload.value;`);
1583
+ const ids = Object.create(null);
1584
+ let counter = 0;
1585
+ for (const key of normalized.keys) {
1586
+ ids[key] = `key_${counter++}`;
1587
+ }
1588
+ // A: preserve key order {
1589
+ doc.write(`const newResult = {};`);
1590
+ for (const key of normalized.keys) {
1591
+ const id = ids[key];
1592
+ const k = esc(key);
1593
+ doc.write(`const ${id} = ${parseStr(key)};`);
1594
+ doc.write(`
1595
+ if (${id}.issues.length) {
1596
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1597
+ ...iss,
1598
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1599
+ })));
1600
+ }
1601
+
1602
+
1603
+ if (${id}.value === undefined) {
1604
+ if (${k} in input) {
1605
+ newResult[${k}] = undefined;
1606
+ }
1607
+ } else {
1608
+ newResult[${k}] = ${id}.value;
1609
+ }
1610
+
1611
+ `);
1612
+ }
1613
+ doc.write(`payload.value = newResult;`);
1614
+ doc.write(`return payload;`);
1615
+ const fn = doc.compile();
1616
+ return (payload, ctx) => fn(shape, payload, ctx);
1617
+ };
1618
+ let fastpass;
1619
+ const isObject$1 = isObject;
1620
+ const jit = !globalConfig.jitless;
1621
+ const allowsEval$1 = allowsEval;
1622
+ const fastEnabled = jit && allowsEval$1.value; // && !def.catchall;
1623
+ const catchall = def.catchall;
1624
+ let value;
1625
+ inst._zod.parse = (payload, ctx) => {
1626
+ value ?? (value = _normalized.value);
1627
+ const input = payload.value;
1628
+ if (!isObject$1(input)) {
1629
+ payload.issues.push({
1630
+ expected: "object",
1631
+ code: "invalid_type",
1632
+ input,
1633
+ inst,
1634
+ });
1635
+ return payload;
1636
+ }
1637
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
1638
+ // always synchronous
1639
+ if (!fastpass)
1640
+ fastpass = generateFastpass(def.shape);
1641
+ payload = fastpass(payload, ctx);
1642
+ if (!catchall)
1643
+ return payload;
1644
+ return handleCatchall([], input, payload, ctx, value, inst);
1645
+ }
1646
+ return superParse(payload, ctx);
1647
+ };
1648
+ });
1649
+ function handleUnionResults(results, final, inst, ctx) {
1650
+ for (const result of results) {
1651
+ if (result.issues.length === 0) {
1652
+ final.value = result.value;
1653
+ return final;
1654
+ }
1655
+ }
1656
+ const nonaborted = results.filter((r) => !aborted(r));
1657
+ if (nonaborted.length === 1) {
1658
+ final.value = nonaborted[0].value;
1659
+ return nonaborted[0];
1660
+ }
1661
+ final.issues.push({
1662
+ code: "invalid_union",
1663
+ input: final.value,
1664
+ inst,
1665
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
1666
+ });
1667
+ return final;
1668
+ }
1669
+ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
1670
+ $ZodType.init(inst, def);
1671
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
1672
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
1673
+ defineLazy(inst._zod, "values", () => {
1674
+ if (def.options.every((o) => o._zod.values)) {
1675
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1676
+ }
1677
+ return undefined;
1678
+ });
1679
+ defineLazy(inst._zod, "pattern", () => {
1680
+ if (def.options.every((o) => o._zod.pattern)) {
1681
+ const patterns = def.options.map((o) => o._zod.pattern);
1682
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
1683
+ }
1684
+ return undefined;
1685
+ });
1686
+ const single = def.options.length === 1;
1687
+ const first = def.options[0]._zod.run;
1688
+ inst._zod.parse = (payload, ctx) => {
1689
+ if (single) {
1690
+ return first(payload, ctx);
1691
+ }
1692
+ let async = false;
1693
+ const results = [];
1694
+ for (const option of def.options) {
1695
+ const result = option._zod.run({
1696
+ value: payload.value,
1697
+ issues: [],
1698
+ }, ctx);
1699
+ if (result instanceof Promise) {
1700
+ results.push(result);
1701
+ async = true;
1702
+ }
1703
+ else {
1704
+ if (result.issues.length === 0)
1705
+ return result;
1706
+ results.push(result);
1707
+ }
1708
+ }
1709
+ if (!async)
1710
+ return handleUnionResults(results, payload, inst, ctx);
1711
+ return Promise.all(results).then((results) => {
1712
+ return handleUnionResults(results, payload, inst, ctx);
1713
+ });
1714
+ };
1715
+ });
1716
+ const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
1717
+ $ZodType.init(inst, def);
1718
+ inst._zod.parse = (payload, ctx) => {
1719
+ const input = payload.value;
1720
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
1721
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
1722
+ const async = left instanceof Promise || right instanceof Promise;
1723
+ if (async) {
1724
+ return Promise.all([left, right]).then(([left, right]) => {
1725
+ return handleIntersectionResults(payload, left, right);
1726
+ });
1727
+ }
1728
+ return handleIntersectionResults(payload, left, right);
1729
+ };
1730
+ });
1731
+ function mergeValues(a, b) {
1732
+ // const aType = parse.t(a);
1733
+ // const bType = parse.t(b);
1734
+ if (a === b) {
1735
+ return { valid: true, data: a };
1736
+ }
1737
+ if (a instanceof Date && b instanceof Date && +a === +b) {
1738
+ return { valid: true, data: a };
1739
+ }
1740
+ if (isPlainObject(a) && isPlainObject(b)) {
1741
+ const bKeys = Object.keys(b);
1742
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1743
+ const newObj = { ...a, ...b };
1744
+ for (const key of sharedKeys) {
1745
+ const sharedValue = mergeValues(a[key], b[key]);
1746
+ if (!sharedValue.valid) {
1747
+ return {
1748
+ valid: false,
1749
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
1750
+ };
1751
+ }
1752
+ newObj[key] = sharedValue.data;
1753
+ }
1754
+ return { valid: true, data: newObj };
1755
+ }
1756
+ if (Array.isArray(a) && Array.isArray(b)) {
1757
+ if (a.length !== b.length) {
1758
+ return { valid: false, mergeErrorPath: [] };
1759
+ }
1760
+ const newArray = [];
1761
+ for (let index = 0; index < a.length; index++) {
1762
+ const itemA = a[index];
1763
+ const itemB = b[index];
1764
+ const sharedValue = mergeValues(itemA, itemB);
1765
+ if (!sharedValue.valid) {
1766
+ return {
1767
+ valid: false,
1768
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
1769
+ };
1770
+ }
1771
+ newArray.push(sharedValue.data);
1772
+ }
1773
+ return { valid: true, data: newArray };
1774
+ }
1775
+ return { valid: false, mergeErrorPath: [] };
1776
+ }
1777
+ function handleIntersectionResults(result, left, right) {
1778
+ if (left.issues.length) {
1779
+ result.issues.push(...left.issues);
1780
+ }
1781
+ if (right.issues.length) {
1782
+ result.issues.push(...right.issues);
1783
+ }
1784
+ if (aborted(result))
1785
+ return result;
1786
+ const merged = mergeValues(left.value, right.value);
1787
+ if (!merged.valid) {
1788
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
1789
+ }
1790
+ result.value = merged.data;
1791
+ return result;
1792
+ }
1793
+ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
1794
+ $ZodType.init(inst, def);
1795
+ const values = getEnumValues(def.entries);
1796
+ const valuesSet = new Set(values);
1797
+ inst._zod.values = valuesSet;
1798
+ inst._zod.pattern = new RegExp(`^(${values
1799
+ .filter((k) => propertyKeyTypes.has(typeof k))
1800
+ .map((o) => (typeof o === "string" ? escapeRegex(o) : o.toString()))
1801
+ .join("|")})$`);
1802
+ inst._zod.parse = (payload, _ctx) => {
1803
+ const input = payload.value;
1804
+ if (valuesSet.has(input)) {
1805
+ return payload;
1806
+ }
1807
+ payload.issues.push({
1808
+ code: "invalid_value",
1809
+ values,
1810
+ input,
1811
+ inst,
1812
+ });
1813
+ return payload;
1814
+ };
1815
+ });
1816
+ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
1817
+ $ZodType.init(inst, def);
1818
+ inst._zod.parse = (payload, ctx) => {
1819
+ if (ctx.direction === "backward") {
1820
+ throw new $ZodEncodeError(inst.constructor.name);
1821
+ }
1822
+ const _out = def.transform(payload.value, payload);
1823
+ if (ctx.async) {
1824
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
1825
+ return output.then((output) => {
1826
+ payload.value = output;
1827
+ return payload;
1828
+ });
1829
+ }
1830
+ if (_out instanceof Promise) {
1831
+ throw new $ZodAsyncError();
1832
+ }
1833
+ payload.value = _out;
1834
+ return payload;
1835
+ };
1836
+ });
1837
+ function handleOptionalResult(result, input) {
1838
+ if (result.issues.length && input === undefined) {
1839
+ return { issues: [], value: undefined };
1840
+ }
1841
+ return result;
1842
+ }
1843
+ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
1844
+ $ZodType.init(inst, def);
1845
+ inst._zod.optin = "optional";
1846
+ inst._zod.optout = "optional";
1847
+ defineLazy(inst._zod, "values", () => {
1848
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
1849
+ });
1850
+ defineLazy(inst._zod, "pattern", () => {
1851
+ const pattern = def.innerType._zod.pattern;
1852
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : undefined;
1853
+ });
1854
+ inst._zod.parse = (payload, ctx) => {
1855
+ if (def.innerType._zod.optin === "optional") {
1856
+ const result = def.innerType._zod.run(payload, ctx);
1857
+ if (result instanceof Promise)
1858
+ return result.then((r) => handleOptionalResult(r, payload.value));
1859
+ return handleOptionalResult(result, payload.value);
1860
+ }
1861
+ if (payload.value === undefined) {
1862
+ return payload;
1863
+ }
1864
+ return def.innerType._zod.run(payload, ctx);
1865
+ };
1866
+ });
1867
+ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
1868
+ $ZodType.init(inst, def);
1869
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1870
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1871
+ defineLazy(inst._zod, "pattern", () => {
1872
+ const pattern = def.innerType._zod.pattern;
1873
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : undefined;
1874
+ });
1875
+ defineLazy(inst._zod, "values", () => {
1876
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
1877
+ });
1878
+ inst._zod.parse = (payload, ctx) => {
1879
+ // Forward direction (decode): allow null to pass through
1880
+ if (payload.value === null)
1881
+ return payload;
1882
+ return def.innerType._zod.run(payload, ctx);
1883
+ };
1884
+ });
1885
+ const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
1886
+ $ZodType.init(inst, def);
1887
+ // inst._zod.qin = "true";
1888
+ inst._zod.optin = "optional";
1889
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1890
+ inst._zod.parse = (payload, ctx) => {
1891
+ if (ctx.direction === "backward") {
1892
+ return def.innerType._zod.run(payload, ctx);
1893
+ }
1894
+ // Forward direction (decode): apply defaults for undefined input
1895
+ if (payload.value === undefined) {
1896
+ payload.value = def.defaultValue;
1897
+ /**
1898
+ * $ZodDefault returns the default value immediately in forward direction.
1899
+ * 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. */
1900
+ return payload;
1901
+ }
1902
+ // Forward direction: continue with default handling
1903
+ const result = def.innerType._zod.run(payload, ctx);
1904
+ if (result instanceof Promise) {
1905
+ return result.then((result) => handleDefaultResult(result, def));
1906
+ }
1907
+ return handleDefaultResult(result, def);
1908
+ };
1909
+ });
1910
+ function handleDefaultResult(payload, def) {
1911
+ if (payload.value === undefined) {
1912
+ payload.value = def.defaultValue;
1913
+ }
1914
+ return payload;
1915
+ }
1916
+ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
1917
+ $ZodType.init(inst, def);
1918
+ inst._zod.optin = "optional";
1919
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1920
+ inst._zod.parse = (payload, ctx) => {
1921
+ if (ctx.direction === "backward") {
1922
+ return def.innerType._zod.run(payload, ctx);
1923
+ }
1924
+ // Forward direction (decode): apply prefault for undefined input
1925
+ if (payload.value === undefined) {
1926
+ payload.value = def.defaultValue;
1927
+ }
1928
+ return def.innerType._zod.run(payload, ctx);
1929
+ };
1930
+ });
1931
+ const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
1932
+ $ZodType.init(inst, def);
1933
+ defineLazy(inst._zod, "values", () => {
1934
+ const v = def.innerType._zod.values;
1935
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
1936
+ });
1937
+ inst._zod.parse = (payload, ctx) => {
1938
+ const result = def.innerType._zod.run(payload, ctx);
1939
+ if (result instanceof Promise) {
1940
+ return result.then((result) => handleNonOptionalResult(result, inst));
1941
+ }
1942
+ return handleNonOptionalResult(result, inst);
1943
+ };
1944
+ });
1945
+ function handleNonOptionalResult(payload, inst) {
1946
+ if (!payload.issues.length && payload.value === undefined) {
1947
+ payload.issues.push({
1948
+ code: "invalid_type",
1949
+ expected: "nonoptional",
1950
+ input: payload.value,
1951
+ inst,
1952
+ });
1953
+ }
1954
+ return payload;
1955
+ }
1956
+ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
1957
+ $ZodType.init(inst, def);
1958
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1959
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1960
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1961
+ inst._zod.parse = (payload, ctx) => {
1962
+ if (ctx.direction === "backward") {
1963
+ return def.innerType._zod.run(payload, ctx);
1964
+ }
1965
+ // Forward direction (decode): apply catch logic
1966
+ const result = def.innerType._zod.run(payload, ctx);
1967
+ if (result instanceof Promise) {
1968
+ return result.then((result) => {
1969
+ payload.value = result.value;
1970
+ if (result.issues.length) {
1971
+ payload.value = def.catchValue({
1972
+ ...payload,
1973
+ error: {
1974
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
1975
+ },
1976
+ input: payload.value,
1977
+ });
1978
+ payload.issues = [];
1979
+ }
1980
+ return payload;
1981
+ });
1982
+ }
1983
+ payload.value = result.value;
1984
+ if (result.issues.length) {
1985
+ payload.value = def.catchValue({
1986
+ ...payload,
1987
+ error: {
1988
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
1989
+ },
1990
+ input: payload.value,
1991
+ });
1992
+ payload.issues = [];
1993
+ }
1994
+ return payload;
1995
+ };
1996
+ });
1997
+ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
1998
+ $ZodType.init(inst, def);
1999
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
2000
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
2001
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2002
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2003
+ inst._zod.parse = (payload, ctx) => {
2004
+ if (ctx.direction === "backward") {
2005
+ const right = def.out._zod.run(payload, ctx);
2006
+ if (right instanceof Promise) {
2007
+ return right.then((right) => handlePipeResult(right, def.in, ctx));
2008
+ }
2009
+ return handlePipeResult(right, def.in, ctx);
2010
+ }
2011
+ const left = def.in._zod.run(payload, ctx);
2012
+ if (left instanceof Promise) {
2013
+ return left.then((left) => handlePipeResult(left, def.out, ctx));
2014
+ }
2015
+ return handlePipeResult(left, def.out, ctx);
2016
+ };
2017
+ });
2018
+ function handlePipeResult(left, next, ctx) {
2019
+ if (left.issues.length) {
2020
+ // prevent further checks
2021
+ left.aborted = true;
2022
+ return left;
2023
+ }
2024
+ return next._zod.run({ value: left.value, issues: left.issues }, ctx);
2025
+ }
2026
+ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
2027
+ $ZodType.init(inst, def);
2028
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2029
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2030
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
2031
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
2032
+ inst._zod.parse = (payload, ctx) => {
2033
+ if (ctx.direction === "backward") {
2034
+ return def.innerType._zod.run(payload, ctx);
2035
+ }
2036
+ const result = def.innerType._zod.run(payload, ctx);
2037
+ if (result instanceof Promise) {
2038
+ return result.then(handleReadonlyResult);
2039
+ }
2040
+ return handleReadonlyResult(result);
2041
+ };
2042
+ });
2043
+ function handleReadonlyResult(payload) {
2044
+ payload.value = Object.freeze(payload.value);
2045
+ return payload;
2046
+ }
2047
+ const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
2048
+ $ZodCheck.init(inst, def);
2049
+ $ZodType.init(inst, def);
2050
+ inst._zod.parse = (payload, _) => {
2051
+ return payload;
2052
+ };
2053
+ inst._zod.check = (payload) => {
2054
+ const input = payload.value;
2055
+ const r = def.fn(input);
2056
+ if (r instanceof Promise) {
2057
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
2058
+ }
2059
+ handleRefineResult(r, payload, input, inst);
2060
+ return;
2061
+ };
2062
+ });
2063
+ function handleRefineResult(result, payload, input, inst) {
2064
+ if (!result) {
2065
+ const _iss = {
2066
+ code: "custom",
2067
+ input,
2068
+ inst, // incorporates params.error into issue reporting
2069
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
2070
+ continue: !inst._zod.def.abort,
2071
+ // params: inst._zod.def.params,
2072
+ };
2073
+ if (inst._zod.def.params)
2074
+ _iss.params = inst._zod.def.params;
2075
+ payload.issues.push(issue(_iss));
2076
+ }
2077
+ }
2078
+
2079
+ var _a;
2080
+ class $ZodRegistry {
2081
+ constructor() {
2082
+ this._map = new WeakMap();
2083
+ this._idmap = new Map();
2084
+ }
2085
+ add(schema, ..._meta) {
2086
+ const meta = _meta[0];
2087
+ this._map.set(schema, meta);
2088
+ if (meta && typeof meta === "object" && "id" in meta) {
2089
+ if (this._idmap.has(meta.id)) {
2090
+ throw new Error(`ID ${meta.id} already exists in the registry`);
2091
+ }
2092
+ this._idmap.set(meta.id, schema);
2093
+ }
2094
+ return this;
2095
+ }
2096
+ clear() {
2097
+ this._map = new WeakMap();
2098
+ this._idmap = new Map();
2099
+ return this;
2100
+ }
2101
+ remove(schema) {
2102
+ const meta = this._map.get(schema);
2103
+ if (meta && typeof meta === "object" && "id" in meta) {
2104
+ this._idmap.delete(meta.id);
2105
+ }
2106
+ this._map.delete(schema);
2107
+ return this;
2108
+ }
2109
+ get(schema) {
2110
+ // return this._map.get(schema) as any;
2111
+ // inherit metadata
2112
+ const p = schema._zod.parent;
2113
+ if (p) {
2114
+ const pm = { ...(this.get(p) ?? {}) };
2115
+ delete pm.id; // do not inherit id
2116
+ const f = { ...pm, ...this._map.get(schema) };
2117
+ return Object.keys(f).length ? f : undefined;
2118
+ }
2119
+ return this._map.get(schema);
2120
+ }
2121
+ has(schema) {
2122
+ return this._map.has(schema);
2123
+ }
2124
+ }
2125
+ // registries
2126
+ function registry() {
2127
+ return new $ZodRegistry();
2128
+ }
2129
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2130
+ const globalRegistry = globalThis.__zod_globalRegistry;
2131
+
2132
+ function _string(Class, params) {
2133
+ return new Class({
2134
+ type: "string",
2135
+ ...normalizeParams(params),
2136
+ });
2137
+ }
2138
+ function _email(Class, params) {
2139
+ return new Class({
2140
+ type: "string",
2141
+ format: "email",
2142
+ check: "string_format",
2143
+ abort: false,
2144
+ ...normalizeParams(params),
2145
+ });
2146
+ }
2147
+ function _guid(Class, params) {
2148
+ return new Class({
2149
+ type: "string",
2150
+ format: "guid",
2151
+ check: "string_format",
2152
+ abort: false,
2153
+ ...normalizeParams(params),
2154
+ });
2155
+ }
2156
+ function _uuid(Class, params) {
2157
+ return new Class({
2158
+ type: "string",
2159
+ format: "uuid",
2160
+ check: "string_format",
2161
+ abort: false,
2162
+ ...normalizeParams(params),
2163
+ });
2164
+ }
2165
+ function _uuidv4(Class, params) {
2166
+ return new Class({
2167
+ type: "string",
2168
+ format: "uuid",
2169
+ check: "string_format",
2170
+ abort: false,
2171
+ version: "v4",
2172
+ ...normalizeParams(params),
2173
+ });
2174
+ }
2175
+ function _uuidv6(Class, params) {
2176
+ return new Class({
2177
+ type: "string",
2178
+ format: "uuid",
2179
+ check: "string_format",
2180
+ abort: false,
2181
+ version: "v6",
2182
+ ...normalizeParams(params),
2183
+ });
2184
+ }
2185
+ function _uuidv7(Class, params) {
2186
+ return new Class({
2187
+ type: "string",
2188
+ format: "uuid",
2189
+ check: "string_format",
2190
+ abort: false,
2191
+ version: "v7",
2192
+ ...normalizeParams(params),
2193
+ });
2194
+ }
2195
+ function _url(Class, params) {
2196
+ return new Class({
2197
+ type: "string",
2198
+ format: "url",
2199
+ check: "string_format",
2200
+ abort: false,
2201
+ ...normalizeParams(params),
2202
+ });
2203
+ }
2204
+ function _emoji(Class, params) {
2205
+ return new Class({
2206
+ type: "string",
2207
+ format: "emoji",
2208
+ check: "string_format",
2209
+ abort: false,
2210
+ ...normalizeParams(params),
2211
+ });
2212
+ }
2213
+ function _nanoid(Class, params) {
2214
+ return new Class({
2215
+ type: "string",
2216
+ format: "nanoid",
2217
+ check: "string_format",
2218
+ abort: false,
2219
+ ...normalizeParams(params),
2220
+ });
2221
+ }
2222
+ function _cuid(Class, params) {
2223
+ return new Class({
2224
+ type: "string",
2225
+ format: "cuid",
2226
+ check: "string_format",
2227
+ abort: false,
2228
+ ...normalizeParams(params),
2229
+ });
2230
+ }
2231
+ function _cuid2(Class, params) {
2232
+ return new Class({
2233
+ type: "string",
2234
+ format: "cuid2",
2235
+ check: "string_format",
2236
+ abort: false,
2237
+ ...normalizeParams(params),
2238
+ });
2239
+ }
2240
+ function _ulid(Class, params) {
2241
+ return new Class({
2242
+ type: "string",
2243
+ format: "ulid",
2244
+ check: "string_format",
2245
+ abort: false,
2246
+ ...normalizeParams(params),
2247
+ });
2248
+ }
2249
+ function _xid(Class, params) {
2250
+ return new Class({
2251
+ type: "string",
2252
+ format: "xid",
2253
+ check: "string_format",
2254
+ abort: false,
2255
+ ...normalizeParams(params),
2256
+ });
2257
+ }
2258
+ function _ksuid(Class, params) {
2259
+ return new Class({
2260
+ type: "string",
2261
+ format: "ksuid",
2262
+ check: "string_format",
2263
+ abort: false,
2264
+ ...normalizeParams(params),
2265
+ });
2266
+ }
2267
+ function _ipv4(Class, params) {
2268
+ return new Class({
2269
+ type: "string",
2270
+ format: "ipv4",
2271
+ check: "string_format",
2272
+ abort: false,
2273
+ ...normalizeParams(params),
2274
+ });
2275
+ }
2276
+ function _ipv6(Class, params) {
2277
+ return new Class({
2278
+ type: "string",
2279
+ format: "ipv6",
2280
+ check: "string_format",
2281
+ abort: false,
2282
+ ...normalizeParams(params),
2283
+ });
2284
+ }
2285
+ function _cidrv4(Class, params) {
2286
+ return new Class({
2287
+ type: "string",
2288
+ format: "cidrv4",
2289
+ check: "string_format",
2290
+ abort: false,
2291
+ ...normalizeParams(params),
2292
+ });
2293
+ }
2294
+ function _cidrv6(Class, params) {
2295
+ return new Class({
2296
+ type: "string",
2297
+ format: "cidrv6",
2298
+ check: "string_format",
2299
+ abort: false,
2300
+ ...normalizeParams(params),
2301
+ });
2302
+ }
2303
+ function _base64(Class, params) {
2304
+ return new Class({
2305
+ type: "string",
2306
+ format: "base64",
2307
+ check: "string_format",
2308
+ abort: false,
2309
+ ...normalizeParams(params),
2310
+ });
2311
+ }
2312
+ function _base64url(Class, params) {
2313
+ return new Class({
2314
+ type: "string",
2315
+ format: "base64url",
2316
+ check: "string_format",
2317
+ abort: false,
2318
+ ...normalizeParams(params),
2319
+ });
2320
+ }
2321
+ function _e164(Class, params) {
2322
+ return new Class({
2323
+ type: "string",
2324
+ format: "e164",
2325
+ check: "string_format",
2326
+ abort: false,
2327
+ ...normalizeParams(params),
2328
+ });
2329
+ }
2330
+ function _jwt(Class, params) {
2331
+ return new Class({
2332
+ type: "string",
2333
+ format: "jwt",
2334
+ check: "string_format",
2335
+ abort: false,
2336
+ ...normalizeParams(params),
2337
+ });
2338
+ }
2339
+ function _isoDateTime(Class, params) {
2340
+ return new Class({
2341
+ type: "string",
2342
+ format: "datetime",
2343
+ check: "string_format",
2344
+ offset: false,
2345
+ local: false,
2346
+ precision: null,
2347
+ ...normalizeParams(params),
2348
+ });
2349
+ }
2350
+ function _isoDate(Class, params) {
2351
+ return new Class({
2352
+ type: "string",
2353
+ format: "date",
2354
+ check: "string_format",
2355
+ ...normalizeParams(params),
2356
+ });
2357
+ }
2358
+ function _isoTime(Class, params) {
2359
+ return new Class({
2360
+ type: "string",
2361
+ format: "time",
2362
+ check: "string_format",
2363
+ precision: null,
2364
+ ...normalizeParams(params),
2365
+ });
2366
+ }
2367
+ function _isoDuration(Class, params) {
2368
+ return new Class({
2369
+ type: "string",
2370
+ format: "duration",
2371
+ check: "string_format",
2372
+ ...normalizeParams(params),
2373
+ });
2374
+ }
2375
+ function _unknown(Class) {
2376
+ return new Class({
2377
+ type: "unknown",
2378
+ });
2379
+ }
2380
+ function _never(Class, params) {
2381
+ return new Class({
2382
+ type: "never",
2383
+ ...normalizeParams(params),
2384
+ });
2385
+ }
2386
+ function _maxLength(maximum, params) {
2387
+ const ch = new $ZodCheckMaxLength({
2388
+ check: "max_length",
2389
+ ...normalizeParams(params),
2390
+ maximum,
2391
+ });
2392
+ return ch;
2393
+ }
2394
+ function _minLength(minimum, params) {
2395
+ return new $ZodCheckMinLength({
2396
+ check: "min_length",
2397
+ ...normalizeParams(params),
2398
+ minimum,
2399
+ });
2400
+ }
2401
+ function _length(length, params) {
2402
+ return new $ZodCheckLengthEquals({
2403
+ check: "length_equals",
2404
+ ...normalizeParams(params),
2405
+ length,
2406
+ });
2407
+ }
2408
+ function _regex(pattern, params) {
2409
+ return new $ZodCheckRegex({
2410
+ check: "string_format",
2411
+ format: "regex",
2412
+ ...normalizeParams(params),
2413
+ pattern,
2414
+ });
2415
+ }
2416
+ function _lowercase(params) {
2417
+ return new $ZodCheckLowerCase({
2418
+ check: "string_format",
2419
+ format: "lowercase",
2420
+ ...normalizeParams(params),
2421
+ });
2422
+ }
2423
+ function _uppercase(params) {
2424
+ return new $ZodCheckUpperCase({
2425
+ check: "string_format",
2426
+ format: "uppercase",
2427
+ ...normalizeParams(params),
2428
+ });
2429
+ }
2430
+ function _includes(includes, params) {
2431
+ return new $ZodCheckIncludes({
2432
+ check: "string_format",
2433
+ format: "includes",
2434
+ ...normalizeParams(params),
2435
+ includes,
2436
+ });
2437
+ }
2438
+ function _startsWith(prefix, params) {
2439
+ return new $ZodCheckStartsWith({
2440
+ check: "string_format",
2441
+ format: "starts_with",
2442
+ ...normalizeParams(params),
2443
+ prefix,
2444
+ });
2445
+ }
2446
+ function _endsWith(suffix, params) {
2447
+ return new $ZodCheckEndsWith({
2448
+ check: "string_format",
2449
+ format: "ends_with",
2450
+ ...normalizeParams(params),
2451
+ suffix,
2452
+ });
2453
+ }
2454
+ function _overwrite(tx) {
2455
+ return new $ZodCheckOverwrite({
2456
+ check: "overwrite",
2457
+ tx,
2458
+ });
2459
+ }
2460
+ // normalize
2461
+ function _normalize(form) {
2462
+ return _overwrite((input) => input.normalize(form));
2463
+ }
2464
+ // trim
2465
+ function _trim() {
2466
+ return _overwrite((input) => input.trim());
2467
+ }
2468
+ // toLowerCase
2469
+ function _toLowerCase() {
2470
+ return _overwrite((input) => input.toLowerCase());
2471
+ }
2472
+ // toUpperCase
2473
+ function _toUpperCase() {
2474
+ return _overwrite((input) => input.toUpperCase());
2475
+ }
2476
+ // slugify
2477
+ function _slugify() {
2478
+ return _overwrite((input) => slugify(input));
2479
+ }
2480
+ function _array(Class, element, params) {
2481
+ return new Class({
2482
+ type: "array",
2483
+ element,
2484
+ // get element() {
2485
+ // return element;
2486
+ // },
2487
+ ...normalizeParams(params),
2488
+ });
2489
+ }
2490
+ // same as _custom but defaults to abort:false
2491
+ function _refine(Class, fn, _params) {
2492
+ const schema = new Class({
2493
+ type: "custom",
2494
+ check: "custom",
2495
+ fn: fn,
2496
+ ...normalizeParams(_params),
2497
+ });
2498
+ return schema;
2499
+ }
2500
+ function _superRefine(fn) {
2501
+ const ch = _check((payload) => {
2502
+ payload.addIssue = (issue$1) => {
2503
+ if (typeof issue$1 === "string") {
2504
+ payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
2505
+ }
2506
+ else {
2507
+ // for Zod 3 backwards compatibility
2508
+ const _issue = issue$1;
2509
+ if (_issue.fatal)
2510
+ _issue.continue = false;
2511
+ _issue.code ?? (_issue.code = "custom");
2512
+ _issue.input ?? (_issue.input = payload.value);
2513
+ _issue.inst ?? (_issue.inst = ch);
2514
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
2515
+ payload.issues.push(issue(_issue));
2516
+ }
2517
+ };
2518
+ return fn(payload.value, payload);
2519
+ });
2520
+ return ch;
2521
+ }
2522
+ function _check(fn, params) {
2523
+ const ch = new $ZodCheck({
2524
+ check: "custom",
2525
+ ...normalizeParams(params),
2526
+ });
2527
+ ch._zod.check = fn;
2528
+ return ch;
2529
+ }
2530
+
2531
+ // function initializeContext<T extends schemas.$ZodType>(inputs: JSONSchemaGeneratorParams<T>): ToJSONSchemaContext<T> {
2532
+ // return {
2533
+ // processor: inputs.processor,
2534
+ // metadataRegistry: inputs.metadata ?? globalRegistry,
2535
+ // target: inputs.target ?? "draft-2020-12",
2536
+ // unrepresentable: inputs.unrepresentable ?? "throw",
2537
+ // };
2538
+ // }
2539
+ function initializeContext(params) {
2540
+ // Normalize target: convert old non-hyphenated versions to hyphenated versions
2541
+ let target = params?.target ?? "draft-2020-12";
2542
+ if (target === "draft-4")
2543
+ target = "draft-04";
2544
+ if (target === "draft-7")
2545
+ target = "draft-07";
2546
+ return {
2547
+ processors: params.processors ?? {},
2548
+ metadataRegistry: params?.metadata ?? globalRegistry,
2549
+ target,
2550
+ unrepresentable: params?.unrepresentable ?? "throw",
2551
+ override: params?.override ?? (() => { }),
2552
+ io: params?.io ?? "output",
2553
+ counter: 0,
2554
+ seen: new Map(),
2555
+ cycles: params?.cycles ?? "ref",
2556
+ reused: params?.reused ?? "inline",
2557
+ external: params?.external ?? undefined,
2558
+ };
2559
+ }
2560
+ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
2561
+ var _a;
2562
+ const def = schema._zod.def;
2563
+ // check for schema in seens
2564
+ const seen = ctx.seen.get(schema);
2565
+ if (seen) {
2566
+ seen.count++;
2567
+ // check if cycle
2568
+ const isCycle = _params.schemaPath.includes(schema);
2569
+ if (isCycle) {
2570
+ seen.cycle = _params.path;
2571
+ }
2572
+ return seen.schema;
2573
+ }
2574
+ // initialize
2575
+ const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
2576
+ ctx.seen.set(schema, result);
2577
+ // custom method overrides default behavior
2578
+ const overrideSchema = schema._zod.toJSONSchema?.();
2579
+ if (overrideSchema) {
2580
+ result.schema = overrideSchema;
2581
+ }
2582
+ else {
2583
+ const params = {
2584
+ ..._params,
2585
+ schemaPath: [..._params.schemaPath, schema],
2586
+ path: _params.path,
2587
+ };
2588
+ const parent = schema._zod.parent;
2589
+ if (parent) {
2590
+ // schema was cloned from another schema
2591
+ result.ref = parent;
2592
+ process(parent, ctx, params);
2593
+ ctx.seen.get(parent).isParent = true;
2594
+ }
2595
+ else if (schema._zod.processJSONSchema) {
2596
+ schema._zod.processJSONSchema(ctx, result.schema, params);
2597
+ }
2598
+ else {
2599
+ const _json = result.schema;
2600
+ const processor = ctx.processors[def.type];
2601
+ if (!processor) {
2602
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
2603
+ }
2604
+ processor(schema, ctx, _json, params);
2605
+ }
2606
+ }
2607
+ // metadata
2608
+ const meta = ctx.metadataRegistry.get(schema);
2609
+ if (meta)
2610
+ Object.assign(result.schema, meta);
2611
+ if (ctx.io === "input" && isTransforming(schema)) {
2612
+ // examples/defaults only apply to output type of pipe
2613
+ delete result.schema.examples;
2614
+ delete result.schema.default;
2615
+ }
2616
+ // set prefault as default
2617
+ if (ctx.io === "input" && result.schema._prefault)
2618
+ (_a = result.schema).default ?? (_a.default = result.schema._prefault);
2619
+ delete result.schema._prefault;
2620
+ // pulling fresh from ctx.seen in case it was overwritten
2621
+ const _result = ctx.seen.get(schema);
2622
+ return _result.schema;
2623
+ }
2624
+ function extractDefs(ctx, schema
2625
+ // params: EmitParams
2626
+ ) {
2627
+ // iterate over seen map;
2628
+ const root = ctx.seen.get(schema);
2629
+ if (!root)
2630
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
2631
+ // returns a ref to the schema
2632
+ // defId will be empty if the ref points to an external schema (or #)
2633
+ const makeURI = (entry) => {
2634
+ // comparing the seen objects because sometimes
2635
+ // multiple schemas map to the same seen object.
2636
+ // e.g. lazy
2637
+ // external is configured
2638
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
2639
+ if (ctx.external) {
2640
+ const externalId = ctx.external.registry.get(entry[0])?.id; // ?? "__shared";// `__schema${ctx.counter++}`;
2641
+ // check if schema is in the external registry
2642
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
2643
+ if (externalId) {
2644
+ return { ref: uriGenerator(externalId) };
2645
+ }
2646
+ // otherwise, add to __shared
2647
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
2648
+ entry[1].defId = id; // set defId so it will be reused if needed
2649
+ return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
2650
+ }
2651
+ if (entry[1] === root) {
2652
+ return { ref: "#" };
2653
+ }
2654
+ // self-contained schema
2655
+ const uriPrefix = `#`;
2656
+ const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
2657
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
2658
+ return { defId, ref: defUriPrefix + defId };
2659
+ };
2660
+ // stored cached version in `def` property
2661
+ // remove all properties, set $ref
2662
+ const extractToDef = (entry) => {
2663
+ // if the schema is already a reference, do not extract it
2664
+ if (entry[1].schema.$ref) {
2665
+ return;
2666
+ }
2667
+ const seen = entry[1];
2668
+ const { ref, defId } = makeURI(entry);
2669
+ seen.def = { ...seen.schema };
2670
+ // defId won't be set if the schema is a reference to an external schema
2671
+ // or if the schema is the root schema
2672
+ if (defId)
2673
+ seen.defId = defId;
2674
+ // wipe away all properties except $ref
2675
+ const schema = seen.schema;
2676
+ for (const key in schema) {
2677
+ delete schema[key];
2678
+ }
2679
+ schema.$ref = ref;
2680
+ };
2681
+ // throw on cycles
2682
+ // break cycles
2683
+ if (ctx.cycles === "throw") {
2684
+ for (const entry of ctx.seen.entries()) {
2685
+ const seen = entry[1];
2686
+ if (seen.cycle) {
2687
+ throw new Error("Cycle detected: " +
2688
+ `#/${seen.cycle?.join("/")}/<root>` +
2689
+ '\n\nSet the `cycles` parameter to `"ref"` to resolve cyclical schemas with defs.');
2690
+ }
2691
+ }
2692
+ }
2693
+ // extract schemas into $defs
2694
+ for (const entry of ctx.seen.entries()) {
2695
+ const seen = entry[1];
2696
+ // convert root schema to # $ref
2697
+ if (schema === entry[0]) {
2698
+ extractToDef(entry); // this has special handling for the root schema
2699
+ continue;
2700
+ }
2701
+ // extract schemas that are in the external registry
2702
+ if (ctx.external) {
2703
+ const ext = ctx.external.registry.get(entry[0])?.id;
2704
+ if (schema !== entry[0] && ext) {
2705
+ extractToDef(entry);
2706
+ continue;
2707
+ }
2708
+ }
2709
+ // extract schemas with `id` meta
2710
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
2711
+ if (id) {
2712
+ extractToDef(entry);
2713
+ continue;
2714
+ }
2715
+ // break cycles
2716
+ if (seen.cycle) {
2717
+ // any
2718
+ extractToDef(entry);
2719
+ continue;
2720
+ }
2721
+ // extract reused schemas
2722
+ if (seen.count > 1) {
2723
+ if (ctx.reused === "ref") {
2724
+ extractToDef(entry);
2725
+ // biome-ignore lint:
2726
+ continue;
2727
+ }
2728
+ }
2729
+ }
2730
+ }
2731
+ function finalize(ctx, schema) {
2732
+ //
2733
+ // iterate over seen map;
2734
+ const root = ctx.seen.get(schema);
2735
+ if (!root)
2736
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
2737
+ // flatten _refs
2738
+ const flattenRef = (zodSchema) => {
2739
+ const seen = ctx.seen.get(zodSchema);
2740
+ const schema = seen.def ?? seen.schema;
2741
+ const _cached = { ...schema };
2742
+ // already seen
2743
+ if (seen.ref === null) {
2744
+ return;
2745
+ }
2746
+ // flatten ref if defined
2747
+ const ref = seen.ref;
2748
+ seen.ref = null; // prevent recursion
2749
+ if (ref) {
2750
+ flattenRef(ref);
2751
+ // merge referenced schema into current
2752
+ const refSchema = ctx.seen.get(ref).schema;
2753
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
2754
+ schema.allOf = schema.allOf ?? [];
2755
+ schema.allOf.push(refSchema);
2756
+ }
2757
+ else {
2758
+ Object.assign(schema, refSchema);
2759
+ Object.assign(schema, _cached); // prevent overwriting any fields in the original schema
2760
+ }
2761
+ }
2762
+ // execute overrides
2763
+ if (!seen.isParent)
2764
+ ctx.override({
2765
+ zodSchema: zodSchema,
2766
+ jsonSchema: schema,
2767
+ path: seen.path ?? [],
2768
+ });
2769
+ };
2770
+ for (const entry of [...ctx.seen.entries()].reverse()) {
2771
+ flattenRef(entry[0]);
2772
+ }
2773
+ const result = {};
2774
+ if (ctx.target === "draft-2020-12") {
2775
+ result.$schema = "https://json-schema.org/draft/2020-12/schema";
2776
+ }
2777
+ else if (ctx.target === "draft-07") {
2778
+ result.$schema = "http://json-schema.org/draft-07/schema#";
2779
+ }
2780
+ else if (ctx.target === "draft-04") {
2781
+ result.$schema = "http://json-schema.org/draft-04/schema#";
2782
+ }
2783
+ else if (ctx.target === "openapi-3.0") ;
2784
+ else ;
2785
+ if (ctx.external?.uri) {
2786
+ const id = ctx.external.registry.get(schema)?.id;
2787
+ if (!id)
2788
+ throw new Error("Schema is missing an `id` property");
2789
+ result.$id = ctx.external.uri(id);
2790
+ }
2791
+ Object.assign(result, root.def ?? root.schema);
2792
+ // build defs object
2793
+ const defs = ctx.external?.defs ?? {};
2794
+ for (const entry of ctx.seen.entries()) {
2795
+ const seen = entry[1];
2796
+ if (seen.def && seen.defId) {
2797
+ defs[seen.defId] = seen.def;
2798
+ }
2799
+ }
2800
+ // set definitions in result
2801
+ if (ctx.external) ;
2802
+ else {
2803
+ if (Object.keys(defs).length > 0) {
2804
+ if (ctx.target === "draft-2020-12") {
2805
+ result.$defs = defs;
2806
+ }
2807
+ else {
2808
+ result.definitions = defs;
2809
+ }
2810
+ }
2811
+ }
2812
+ try {
2813
+ // this "finalizes" this schema and ensures all cycles are removed
2814
+ // each call to finalize() is functionally independent
2815
+ // though the seen map is shared
2816
+ const finalized = JSON.parse(JSON.stringify(result));
2817
+ Object.defineProperty(finalized, "~standard", {
2818
+ value: {
2819
+ ...schema["~standard"],
2820
+ jsonSchema: {
2821
+ input: createStandardJSONSchemaMethod(schema, "input"),
2822
+ output: createStandardJSONSchemaMethod(schema, "output"),
2823
+ },
2824
+ },
2825
+ enumerable: false,
2826
+ writable: false,
2827
+ });
2828
+ return finalized;
2829
+ }
2830
+ catch (_err) {
2831
+ throw new Error("Error converting schema to JSON.");
2832
+ }
2833
+ }
2834
+ function isTransforming(_schema, _ctx) {
2835
+ const ctx = _ctx ?? { seen: new Set() };
2836
+ if (ctx.seen.has(_schema))
2837
+ return false;
2838
+ ctx.seen.add(_schema);
2839
+ const def = _schema._zod.def;
2840
+ if (def.type === "transform")
2841
+ return true;
2842
+ if (def.type === "array")
2843
+ return isTransforming(def.element, ctx);
2844
+ if (def.type === "set")
2845
+ return isTransforming(def.valueType, ctx);
2846
+ if (def.type === "lazy")
2847
+ return isTransforming(def.getter(), ctx);
2848
+ if (def.type === "promise" ||
2849
+ def.type === "optional" ||
2850
+ def.type === "nonoptional" ||
2851
+ def.type === "nullable" ||
2852
+ def.type === "readonly" ||
2853
+ def.type === "default" ||
2854
+ def.type === "prefault") {
2855
+ return isTransforming(def.innerType, ctx);
2856
+ }
2857
+ if (def.type === "intersection") {
2858
+ return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
2859
+ }
2860
+ if (def.type === "record" || def.type === "map") {
2861
+ return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
2862
+ }
2863
+ if (def.type === "pipe") {
2864
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
2865
+ }
2866
+ if (def.type === "object") {
2867
+ for (const key in def.shape) {
2868
+ if (isTransforming(def.shape[key], ctx))
2869
+ return true;
2870
+ }
2871
+ return false;
2872
+ }
2873
+ if (def.type === "union") {
2874
+ for (const option of def.options) {
2875
+ if (isTransforming(option, ctx))
2876
+ return true;
2877
+ }
2878
+ return false;
2879
+ }
2880
+ if (def.type === "tuple") {
2881
+ for (const item of def.items) {
2882
+ if (isTransforming(item, ctx))
2883
+ return true;
2884
+ }
2885
+ if (def.rest && isTransforming(def.rest, ctx))
2886
+ return true;
2887
+ return false;
2888
+ }
2889
+ return false;
2890
+ }
2891
+ /**
2892
+ * Creates a toJSONSchema method for a schema instance.
2893
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
2894
+ */
2895
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
2896
+ const ctx = initializeContext({ ...params, processors });
2897
+ process(schema, ctx);
2898
+ extractDefs(ctx, schema);
2899
+ return finalize(ctx, schema);
2900
+ };
2901
+ const createStandardJSONSchemaMethod = (schema, io) => (params) => {
2902
+ const { libraryOptions, target } = params ?? {};
2903
+ const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors: {} });
2904
+ process(schema, ctx);
2905
+ extractDefs(ctx, schema);
2906
+ return finalize(ctx, schema);
2907
+ };
2908
+
2909
+ const formatMap = {
2910
+ guid: "uuid",
2911
+ url: "uri",
2912
+ datetime: "date-time",
2913
+ json_string: "json-string",
2914
+ regex: "", // do not set
2915
+ };
2916
+ // ==================== SIMPLE TYPE PROCESSORS ====================
2917
+ const stringProcessor = (schema, ctx, _json, _params) => {
2918
+ const json = _json;
2919
+ json.type = "string";
2920
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod
2921
+ .bag;
2922
+ if (typeof minimum === "number")
2923
+ json.minLength = minimum;
2924
+ if (typeof maximum === "number")
2925
+ json.maxLength = maximum;
2926
+ // custom pattern overrides format
2927
+ if (format) {
2928
+ json.format = formatMap[format] ?? format;
2929
+ if (json.format === "")
2930
+ delete json.format; // empty format is not valid
2931
+ }
2932
+ if (contentEncoding)
2933
+ json.contentEncoding = contentEncoding;
2934
+ if (patterns && patterns.size > 0) {
2935
+ const regexes = [...patterns];
2936
+ if (regexes.length === 1)
2937
+ json.pattern = regexes[0].source;
2938
+ else if (regexes.length > 1) {
2939
+ json.allOf = [
2940
+ ...regexes.map((regex) => ({
2941
+ ...(ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0"
2942
+ ? { type: "string" }
2943
+ : {}),
2944
+ pattern: regex.source,
2945
+ })),
2946
+ ];
2947
+ }
2948
+ }
2949
+ };
2950
+ const neverProcessor = (_schema, _ctx, json, _params) => {
2951
+ json.not = {};
2952
+ };
2953
+ const unknownProcessor = (_schema, _ctx, _json, _params) => {
2954
+ // empty schema accepts anything
2955
+ };
2956
+ const enumProcessor = (schema, _ctx, json, _params) => {
2957
+ const def = schema._zod.def;
2958
+ const values = getEnumValues(def.entries);
2959
+ // Number enums can have both string and number values
2960
+ if (values.every((v) => typeof v === "number"))
2961
+ json.type = "number";
2962
+ if (values.every((v) => typeof v === "string"))
2963
+ json.type = "string";
2964
+ json.enum = values;
2965
+ };
2966
+ const customProcessor = (_schema, ctx, _json, _params) => {
2967
+ if (ctx.unrepresentable === "throw") {
2968
+ throw new Error("Custom types cannot be represented in JSON Schema");
2969
+ }
2970
+ };
2971
+ const transformProcessor = (_schema, ctx, _json, _params) => {
2972
+ if (ctx.unrepresentable === "throw") {
2973
+ throw new Error("Transforms cannot be represented in JSON Schema");
2974
+ }
2975
+ };
2976
+ // ==================== COMPOSITE TYPE PROCESSORS ====================
2977
+ const arrayProcessor = (schema, ctx, _json, params) => {
2978
+ const json = _json;
2979
+ const def = schema._zod.def;
2980
+ const { minimum, maximum } = schema._zod.bag;
2981
+ if (typeof minimum === "number")
2982
+ json.minItems = minimum;
2983
+ if (typeof maximum === "number")
2984
+ json.maxItems = maximum;
2985
+ json.type = "array";
2986
+ json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
2987
+ };
2988
+ const objectProcessor = (schema, ctx, _json, params) => {
2989
+ const json = _json;
2990
+ const def = schema._zod.def;
2991
+ json.type = "object";
2992
+ json.properties = {};
2993
+ const shape = def.shape;
2994
+ for (const key in shape) {
2995
+ json.properties[key] = process(shape[key], ctx, {
2996
+ ...params,
2997
+ path: [...params.path, "properties", key],
2998
+ });
2999
+ }
3000
+ // required keys
3001
+ const allKeys = new Set(Object.keys(shape));
3002
+ const requiredKeys = new Set([...allKeys].filter((key) => {
3003
+ const v = def.shape[key]._zod;
3004
+ if (ctx.io === "input") {
3005
+ return v.optin === undefined;
3006
+ }
3007
+ else {
3008
+ return v.optout === undefined;
3009
+ }
3010
+ }));
3011
+ if (requiredKeys.size > 0) {
3012
+ json.required = Array.from(requiredKeys);
3013
+ }
3014
+ // catchall
3015
+ if (def.catchall?._zod.def.type === "never") {
3016
+ // strict
3017
+ json.additionalProperties = false;
3018
+ }
3019
+ else if (!def.catchall) {
3020
+ // regular
3021
+ if (ctx.io === "output")
3022
+ json.additionalProperties = false;
3023
+ }
3024
+ else if (def.catchall) {
3025
+ json.additionalProperties = process(def.catchall, ctx, {
3026
+ ...params,
3027
+ path: [...params.path, "additionalProperties"],
3028
+ });
3029
+ }
3030
+ };
3031
+ const unionProcessor = (schema, ctx, json, params) => {
3032
+ const def = schema._zod.def;
3033
+ // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
3034
+ // This includes both z.xor() and discriminated unions
3035
+ const isExclusive = def.inclusive === false;
3036
+ const options = def.options.map((x, i) => process(x, ctx, {
3037
+ ...params,
3038
+ path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
3039
+ }));
3040
+ if (isExclusive) {
3041
+ json.oneOf = options;
3042
+ }
3043
+ else {
3044
+ json.anyOf = options;
3045
+ }
3046
+ };
3047
+ const intersectionProcessor = (schema, ctx, json, params) => {
3048
+ const def = schema._zod.def;
3049
+ const a = process(def.left, ctx, {
3050
+ ...params,
3051
+ path: [...params.path, "allOf", 0],
3052
+ });
3053
+ const b = process(def.right, ctx, {
3054
+ ...params,
3055
+ path: [...params.path, "allOf", 1],
3056
+ });
3057
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
3058
+ const allOf = [
3059
+ ...(isSimpleIntersection(a) ? a.allOf : [a]),
3060
+ ...(isSimpleIntersection(b) ? b.allOf : [b]),
3061
+ ];
3062
+ json.allOf = allOf;
3063
+ };
3064
+ const nullableProcessor = (schema, ctx, json, params) => {
3065
+ const def = schema._zod.def;
3066
+ const inner = process(def.innerType, ctx, params);
3067
+ const seen = ctx.seen.get(schema);
3068
+ if (ctx.target === "openapi-3.0") {
3069
+ seen.ref = def.innerType;
3070
+ json.nullable = true;
3071
+ }
3072
+ else {
3073
+ json.anyOf = [inner, { type: "null" }];
3074
+ }
3075
+ };
3076
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
3077
+ const def = schema._zod.def;
3078
+ process(def.innerType, ctx, params);
3079
+ const seen = ctx.seen.get(schema);
3080
+ seen.ref = def.innerType;
3081
+ };
3082
+ const defaultProcessor = (schema, ctx, json, params) => {
3083
+ const def = schema._zod.def;
3084
+ process(def.innerType, ctx, params);
3085
+ const seen = ctx.seen.get(schema);
3086
+ seen.ref = def.innerType;
3087
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
3088
+ };
3089
+ const prefaultProcessor = (schema, ctx, json, params) => {
3090
+ const def = schema._zod.def;
3091
+ process(def.innerType, ctx, params);
3092
+ const seen = ctx.seen.get(schema);
3093
+ seen.ref = def.innerType;
3094
+ if (ctx.io === "input")
3095
+ json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
3096
+ };
3097
+ const catchProcessor = (schema, ctx, json, params) => {
3098
+ const def = schema._zod.def;
3099
+ process(def.innerType, ctx, params);
3100
+ const seen = ctx.seen.get(schema);
3101
+ seen.ref = def.innerType;
3102
+ let catchValue;
3103
+ try {
3104
+ catchValue = def.catchValue(undefined);
3105
+ }
3106
+ catch {
3107
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
3108
+ }
3109
+ json.default = catchValue;
3110
+ };
3111
+ const pipeProcessor = (schema, ctx, _json, params) => {
3112
+ const def = schema._zod.def;
3113
+ const innerType = ctx.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
3114
+ process(innerType, ctx, params);
3115
+ const seen = ctx.seen.get(schema);
3116
+ seen.ref = innerType;
3117
+ };
3118
+ const readonlyProcessor = (schema, ctx, json, params) => {
3119
+ const def = schema._zod.def;
3120
+ process(def.innerType, ctx, params);
3121
+ const seen = ctx.seen.get(schema);
3122
+ seen.ref = def.innerType;
3123
+ json.readOnly = true;
3124
+ };
3125
+ const optionalProcessor = (schema, ctx, _json, params) => {
3126
+ const def = schema._zod.def;
3127
+ process(def.innerType, ctx, params);
3128
+ const seen = ctx.seen.get(schema);
3129
+ seen.ref = def.innerType;
3130
+ };
3131
+
3132
+ const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
3133
+ $ZodISODateTime.init(inst, def);
3134
+ ZodStringFormat.init(inst, def);
3135
+ });
3136
+ function datetime(params) {
3137
+ return _isoDateTime(ZodISODateTime, params);
3138
+ }
3139
+ const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
3140
+ $ZodISODate.init(inst, def);
3141
+ ZodStringFormat.init(inst, def);
3142
+ });
3143
+ function date(params) {
3144
+ return _isoDate(ZodISODate, params);
3145
+ }
3146
+ const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
3147
+ $ZodISOTime.init(inst, def);
3148
+ ZodStringFormat.init(inst, def);
3149
+ });
3150
+ function time(params) {
3151
+ return _isoTime(ZodISOTime, params);
3152
+ }
3153
+ const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
3154
+ $ZodISODuration.init(inst, def);
3155
+ ZodStringFormat.init(inst, def);
3156
+ });
3157
+ function duration(params) {
3158
+ return _isoDuration(ZodISODuration, params);
3159
+ }
3160
+
3161
+ const initializer = (inst, issues) => {
3162
+ $ZodError.init(inst, issues);
3163
+ inst.name = "ZodError";
3164
+ Object.defineProperties(inst, {
3165
+ format: {
3166
+ value: (mapper) => formatError(inst, mapper),
3167
+ // enumerable: false,
3168
+ },
3169
+ flatten: {
3170
+ value: (mapper) => flattenError(inst, mapper),
3171
+ // enumerable: false,
3172
+ },
3173
+ addIssue: {
3174
+ value: (issue) => {
3175
+ inst.issues.push(issue);
3176
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3177
+ },
3178
+ // enumerable: false,
3179
+ },
3180
+ addIssues: {
3181
+ value: (issues) => {
3182
+ inst.issues.push(...issues);
3183
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3184
+ },
3185
+ // enumerable: false,
3186
+ },
3187
+ isEmpty: {
3188
+ get() {
3189
+ return inst.issues.length === 0;
3190
+ },
3191
+ // enumerable: false,
3192
+ },
3193
+ });
3194
+ // Object.defineProperty(inst, "isEmpty", {
3195
+ // get() {
3196
+ // return inst.issues.length === 0;
3197
+ // },
3198
+ // });
3199
+ };
3200
+ const ZodRealError = $constructor("ZodError", initializer, {
3201
+ Parent: Error,
3202
+ });
3203
+ // /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
3204
+ // export type ErrorMapCtx = core.$ZodErrorMapCtx;
3205
+
3206
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
3207
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
3208
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
3209
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
3210
+ // Codec functions
3211
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
3212
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
3213
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
3214
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
3215
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
3216
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
3217
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
3218
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
3219
+
3220
+ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
3221
+ $ZodType.init(inst, def);
3222
+ Object.assign(inst["~standard"], {
3223
+ jsonSchema: {
3224
+ input: createStandardJSONSchemaMethod(inst, "input"),
3225
+ output: createStandardJSONSchemaMethod(inst, "output"),
3226
+ },
3227
+ });
3228
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
3229
+ inst.def = def;
3230
+ inst.type = def.type;
3231
+ Object.defineProperty(inst, "_def", { value: def });
3232
+ // base methods
3233
+ inst.check = (...checks) => {
3234
+ return inst.clone(mergeDefs(def, {
3235
+ checks: [
3236
+ ...(def.checks ?? []),
3237
+ ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
3238
+ ],
3239
+ }));
3240
+ };
3241
+ inst.clone = (def, params) => clone(inst, def, params);
3242
+ inst.brand = () => inst;
3243
+ inst.register = ((reg, meta) => {
3244
+ reg.add(inst, meta);
3245
+ return inst;
3246
+ });
3247
+ // parsing
3248
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
3249
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
3250
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
3251
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
3252
+ inst.spa = inst.safeParseAsync;
3253
+ // encoding/decoding
3254
+ inst.encode = (data, params) => encode(inst, data, params);
3255
+ inst.decode = (data, params) => decode(inst, data, params);
3256
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
3257
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
3258
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
3259
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
3260
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
3261
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
3262
+ // refinements
3263
+ inst.refine = (check, params) => inst.check(refine(check, params));
3264
+ inst.superRefine = (refinement) => inst.check(superRefine(refinement));
3265
+ inst.overwrite = (fn) => inst.check(_overwrite(fn));
3266
+ // wrappers
3267
+ inst.optional = () => optional(inst);
3268
+ inst.nullable = () => nullable(inst);
3269
+ inst.nullish = () => optional(nullable(inst));
3270
+ inst.nonoptional = (params) => nonoptional(inst, params);
3271
+ inst.array = () => array(inst);
3272
+ inst.or = (arg) => union([inst, arg]);
3273
+ inst.and = (arg) => intersection(inst, arg);
3274
+ inst.transform = (tx) => pipe(inst, transform(tx));
3275
+ inst.default = (def) => _default(inst, def);
3276
+ inst.prefault = (def) => prefault(inst, def);
3277
+ // inst.coalesce = (def, params) => coalesce(inst, def, params);
3278
+ inst.catch = (params) => _catch(inst, params);
3279
+ inst.pipe = (target) => pipe(inst, target);
3280
+ inst.readonly = () => readonly(inst);
3281
+ // meta
3282
+ inst.describe = (description) => {
3283
+ const cl = inst.clone();
3284
+ globalRegistry.add(cl, { description });
3285
+ return cl;
3286
+ };
3287
+ Object.defineProperty(inst, "description", {
3288
+ get() {
3289
+ return globalRegistry.get(inst)?.description;
3290
+ },
3291
+ configurable: true,
3292
+ });
3293
+ inst.meta = (...args) => {
3294
+ if (args.length === 0) {
3295
+ return globalRegistry.get(inst);
3296
+ }
3297
+ const cl = inst.clone();
3298
+ globalRegistry.add(cl, args[0]);
3299
+ return cl;
3300
+ };
3301
+ // helpers
3302
+ inst.isOptional = () => inst.safeParse(undefined).success;
3303
+ inst.isNullable = () => inst.safeParse(null).success;
3304
+ return inst;
3305
+ });
3306
+ /** @internal */
3307
+ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
3308
+ $ZodString.init(inst, def);
3309
+ ZodType.init(inst, def);
3310
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
3311
+ const bag = inst._zod.bag;
3312
+ inst.format = bag.format ?? null;
3313
+ inst.minLength = bag.minimum ?? null;
3314
+ inst.maxLength = bag.maximum ?? null;
3315
+ // validations
3316
+ inst.regex = (...args) => inst.check(_regex(...args));
3317
+ inst.includes = (...args) => inst.check(_includes(...args));
3318
+ inst.startsWith = (...args) => inst.check(_startsWith(...args));
3319
+ inst.endsWith = (...args) => inst.check(_endsWith(...args));
3320
+ inst.min = (...args) => inst.check(_minLength(...args));
3321
+ inst.max = (...args) => inst.check(_maxLength(...args));
3322
+ inst.length = (...args) => inst.check(_length(...args));
3323
+ inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
3324
+ inst.lowercase = (params) => inst.check(_lowercase(params));
3325
+ inst.uppercase = (params) => inst.check(_uppercase(params));
3326
+ // transforms
3327
+ inst.trim = () => inst.check(_trim());
3328
+ inst.normalize = (...args) => inst.check(_normalize(...args));
3329
+ inst.toLowerCase = () => inst.check(_toLowerCase());
3330
+ inst.toUpperCase = () => inst.check(_toUpperCase());
3331
+ inst.slugify = () => inst.check(_slugify());
3332
+ });
3333
+ const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
3334
+ $ZodString.init(inst, def);
3335
+ _ZodString.init(inst, def);
3336
+ inst.email = (params) => inst.check(_email(ZodEmail, params));
3337
+ inst.url = (params) => inst.check(_url(ZodURL, params));
3338
+ inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
3339
+ inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
3340
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
3341
+ inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
3342
+ inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
3343
+ inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
3344
+ inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
3345
+ inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
3346
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
3347
+ inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
3348
+ inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
3349
+ inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
3350
+ inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
3351
+ inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
3352
+ inst.xid = (params) => inst.check(_xid(ZodXID, params));
3353
+ inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
3354
+ inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
3355
+ inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
3356
+ inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
3357
+ inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
3358
+ inst.e164 = (params) => inst.check(_e164(ZodE164, params));
3359
+ // iso
3360
+ inst.datetime = (params) => inst.check(datetime(params));
3361
+ inst.date = (params) => inst.check(date(params));
3362
+ inst.time = (params) => inst.check(time(params));
3363
+ inst.duration = (params) => inst.check(duration(params));
3364
+ });
3365
+ function string(params) {
3366
+ return _string(ZodString, params);
3367
+ }
3368
+ const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
3369
+ $ZodStringFormat.init(inst, def);
3370
+ _ZodString.init(inst, def);
3371
+ });
3372
+ const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
3373
+ // ZodStringFormat.init(inst, def);
3374
+ $ZodEmail.init(inst, def);
3375
+ ZodStringFormat.init(inst, def);
3376
+ });
3377
+ const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
3378
+ // ZodStringFormat.init(inst, def);
3379
+ $ZodGUID.init(inst, def);
3380
+ ZodStringFormat.init(inst, def);
3381
+ });
3382
+ const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
3383
+ // ZodStringFormat.init(inst, def);
3384
+ $ZodUUID.init(inst, def);
3385
+ ZodStringFormat.init(inst, def);
3386
+ });
3387
+ const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
3388
+ // ZodStringFormat.init(inst, def);
3389
+ $ZodURL.init(inst, def);
3390
+ ZodStringFormat.init(inst, def);
3391
+ });
3392
+ const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
3393
+ // ZodStringFormat.init(inst, def);
3394
+ $ZodEmoji.init(inst, def);
3395
+ ZodStringFormat.init(inst, def);
3396
+ });
3397
+ const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
3398
+ // ZodStringFormat.init(inst, def);
3399
+ $ZodNanoID.init(inst, def);
3400
+ ZodStringFormat.init(inst, def);
3401
+ });
3402
+ const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
3403
+ // ZodStringFormat.init(inst, def);
3404
+ $ZodCUID.init(inst, def);
3405
+ ZodStringFormat.init(inst, def);
3406
+ });
3407
+ const ZodCUID2 = /*@__PURE__*/ $constructor("ZodCUID2", (inst, def) => {
3408
+ // ZodStringFormat.init(inst, def);
3409
+ $ZodCUID2.init(inst, def);
3410
+ ZodStringFormat.init(inst, def);
3411
+ });
3412
+ const ZodULID = /*@__PURE__*/ $constructor("ZodULID", (inst, def) => {
3413
+ // ZodStringFormat.init(inst, def);
3414
+ $ZodULID.init(inst, def);
3415
+ ZodStringFormat.init(inst, def);
3416
+ });
3417
+ const ZodXID = /*@__PURE__*/ $constructor("ZodXID", (inst, def) => {
3418
+ // ZodStringFormat.init(inst, def);
3419
+ $ZodXID.init(inst, def);
3420
+ ZodStringFormat.init(inst, def);
3421
+ });
3422
+ const ZodKSUID = /*@__PURE__*/ $constructor("ZodKSUID", (inst, def) => {
3423
+ // ZodStringFormat.init(inst, def);
3424
+ $ZodKSUID.init(inst, def);
3425
+ ZodStringFormat.init(inst, def);
3426
+ });
3427
+ const ZodIPv4 = /*@__PURE__*/ $constructor("ZodIPv4", (inst, def) => {
3428
+ // ZodStringFormat.init(inst, def);
3429
+ $ZodIPv4.init(inst, def);
3430
+ ZodStringFormat.init(inst, def);
3431
+ });
3432
+ const ZodIPv6 = /*@__PURE__*/ $constructor("ZodIPv6", (inst, def) => {
3433
+ // ZodStringFormat.init(inst, def);
3434
+ $ZodIPv6.init(inst, def);
3435
+ ZodStringFormat.init(inst, def);
3436
+ });
3437
+ const ZodCIDRv4 = /*@__PURE__*/ $constructor("ZodCIDRv4", (inst, def) => {
3438
+ $ZodCIDRv4.init(inst, def);
3439
+ ZodStringFormat.init(inst, def);
3440
+ });
3441
+ const ZodCIDRv6 = /*@__PURE__*/ $constructor("ZodCIDRv6", (inst, def) => {
3442
+ $ZodCIDRv6.init(inst, def);
3443
+ ZodStringFormat.init(inst, def);
3444
+ });
3445
+ const ZodBase64 = /*@__PURE__*/ $constructor("ZodBase64", (inst, def) => {
3446
+ // ZodStringFormat.init(inst, def);
3447
+ $ZodBase64.init(inst, def);
3448
+ ZodStringFormat.init(inst, def);
3449
+ });
3450
+ const ZodBase64URL = /*@__PURE__*/ $constructor("ZodBase64URL", (inst, def) => {
3451
+ // ZodStringFormat.init(inst, def);
3452
+ $ZodBase64URL.init(inst, def);
3453
+ ZodStringFormat.init(inst, def);
3454
+ });
3455
+ const ZodE164 = /*@__PURE__*/ $constructor("ZodE164", (inst, def) => {
3456
+ // ZodStringFormat.init(inst, def);
3457
+ $ZodE164.init(inst, def);
3458
+ ZodStringFormat.init(inst, def);
3459
+ });
3460
+ const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
3461
+ // ZodStringFormat.init(inst, def);
3462
+ $ZodJWT.init(inst, def);
3463
+ ZodStringFormat.init(inst, def);
3464
+ });
3465
+ const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
3466
+ $ZodUnknown.init(inst, def);
3467
+ ZodType.init(inst, def);
3468
+ inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
3469
+ });
3470
+ function unknown() {
3471
+ return _unknown(ZodUnknown);
3472
+ }
3473
+ const ZodNever = /*@__PURE__*/ $constructor("ZodNever", (inst, def) => {
3474
+ $ZodNever.init(inst, def);
3475
+ ZodType.init(inst, def);
3476
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
3477
+ });
3478
+ function never(params) {
3479
+ return _never(ZodNever, params);
3480
+ }
3481
+ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
3482
+ $ZodArray.init(inst, def);
3483
+ ZodType.init(inst, def);
3484
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
3485
+ inst.element = def.element;
3486
+ inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
3487
+ inst.nonempty = (params) => inst.check(_minLength(1, params));
3488
+ inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
3489
+ inst.length = (len, params) => inst.check(_length(len, params));
3490
+ inst.unwrap = () => inst.element;
3491
+ });
3492
+ function array(element, params) {
3493
+ return _array(ZodArray, element, params);
3494
+ }
3495
+ const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
3496
+ $ZodObjectJIT.init(inst, def);
3497
+ ZodType.init(inst, def);
3498
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
3499
+ defineLazy(inst, "shape", () => {
3500
+ return def.shape;
3501
+ });
3502
+ inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
3503
+ inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall });
3504
+ inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
3505
+ inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
3506
+ inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
3507
+ inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
3508
+ inst.extend = (incoming) => {
3509
+ return extend(inst, incoming);
3510
+ };
3511
+ inst.safeExtend = (incoming) => {
3512
+ return safeExtend(inst, incoming);
3513
+ };
3514
+ inst.merge = (other) => merge(inst, other);
3515
+ inst.pick = (mask) => pick(inst, mask);
3516
+ inst.omit = (mask) => omit(inst, mask);
3517
+ inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
3518
+ inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
3519
+ });
3520
+ function object(shape, params) {
3521
+ const def = {
3522
+ type: "object",
3523
+ shape: shape ?? {},
3524
+ ...normalizeParams(params),
3525
+ };
3526
+ return new ZodObject(def);
3527
+ }
3528
+ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
3529
+ $ZodUnion.init(inst, def);
3530
+ ZodType.init(inst, def);
3531
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
3532
+ inst.options = def.options;
3533
+ });
3534
+ function union(options, params) {
3535
+ return new ZodUnion({
3536
+ type: "union",
3537
+ options: options,
3538
+ ...normalizeParams(params),
3539
+ });
3540
+ }
3541
+ const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
3542
+ $ZodIntersection.init(inst, def);
3543
+ ZodType.init(inst, def);
3544
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
3545
+ });
3546
+ function intersection(left, right) {
3547
+ return new ZodIntersection({
3548
+ type: "intersection",
3549
+ left: left,
3550
+ right: right,
3551
+ });
3552
+ }
3553
+ const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
3554
+ $ZodEnum.init(inst, def);
3555
+ ZodType.init(inst, def);
3556
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
3557
+ inst.enum = def.entries;
3558
+ inst.options = Object.values(def.entries);
3559
+ const keys = new Set(Object.keys(def.entries));
3560
+ inst.extract = (values, params) => {
3561
+ const newEntries = {};
3562
+ for (const value of values) {
3563
+ if (keys.has(value)) {
3564
+ newEntries[value] = def.entries[value];
3565
+ }
3566
+ else
3567
+ throw new Error(`Key ${value} not found in enum`);
3568
+ }
3569
+ return new ZodEnum({
3570
+ ...def,
3571
+ checks: [],
3572
+ ...normalizeParams(params),
3573
+ entries: newEntries,
3574
+ });
3575
+ };
3576
+ inst.exclude = (values, params) => {
3577
+ const newEntries = { ...def.entries };
3578
+ for (const value of values) {
3579
+ if (keys.has(value)) {
3580
+ delete newEntries[value];
3581
+ }
3582
+ else
3583
+ throw new Error(`Key ${value} not found in enum`);
3584
+ }
3585
+ return new ZodEnum({
3586
+ ...def,
3587
+ checks: [],
3588
+ ...normalizeParams(params),
3589
+ entries: newEntries,
3590
+ });
3591
+ };
3592
+ });
3593
+ function _enum(values, params) {
3594
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
3595
+ return new ZodEnum({
3596
+ type: "enum",
3597
+ entries,
3598
+ ...normalizeParams(params),
3599
+ });
3600
+ }
3601
+ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
3602
+ $ZodTransform.init(inst, def);
3603
+ ZodType.init(inst, def);
3604
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
3605
+ inst._zod.parse = (payload, _ctx) => {
3606
+ if (_ctx.direction === "backward") {
3607
+ throw new $ZodEncodeError(inst.constructor.name);
3608
+ }
3609
+ payload.addIssue = (issue$1) => {
3610
+ if (typeof issue$1 === "string") {
3611
+ payload.issues.push(issue(issue$1, payload.value, def));
3612
+ }
3613
+ else {
3614
+ // for Zod 3 backwards compatibility
3615
+ const _issue = issue$1;
3616
+ if (_issue.fatal)
3617
+ _issue.continue = false;
3618
+ _issue.code ?? (_issue.code = "custom");
3619
+ _issue.input ?? (_issue.input = payload.value);
3620
+ _issue.inst ?? (_issue.inst = inst);
3621
+ // _issue.continue ??= true;
3622
+ payload.issues.push(issue(_issue));
3623
+ }
3624
+ };
3625
+ const output = def.transform(payload.value, payload);
3626
+ if (output instanceof Promise) {
3627
+ return output.then((output) => {
3628
+ payload.value = output;
3629
+ return payload;
3630
+ });
3631
+ }
3632
+ payload.value = output;
3633
+ return payload;
3634
+ };
3635
+ });
3636
+ function transform(fn) {
3637
+ return new ZodTransform({
3638
+ type: "transform",
3639
+ transform: fn,
3640
+ });
3641
+ }
3642
+ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
3643
+ $ZodOptional.init(inst, def);
3644
+ ZodType.init(inst, def);
3645
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
3646
+ inst.unwrap = () => inst._zod.def.innerType;
3647
+ });
3648
+ function optional(innerType) {
3649
+ return new ZodOptional({
3650
+ type: "optional",
3651
+ innerType: innerType,
3652
+ });
3653
+ }
3654
+ const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
3655
+ $ZodNullable.init(inst, def);
3656
+ ZodType.init(inst, def);
3657
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
3658
+ inst.unwrap = () => inst._zod.def.innerType;
3659
+ });
3660
+ function nullable(innerType) {
3661
+ return new ZodNullable({
3662
+ type: "nullable",
3663
+ innerType: innerType,
3664
+ });
3665
+ }
3666
+ const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
3667
+ $ZodDefault.init(inst, def);
3668
+ ZodType.init(inst, def);
3669
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
3670
+ inst.unwrap = () => inst._zod.def.innerType;
3671
+ inst.removeDefault = inst.unwrap;
3672
+ });
3673
+ function _default(innerType, defaultValue) {
3674
+ return new ZodDefault({
3675
+ type: "default",
3676
+ innerType: innerType,
3677
+ get defaultValue() {
3678
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3679
+ },
3680
+ });
3681
+ }
3682
+ const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
3683
+ $ZodPrefault.init(inst, def);
3684
+ ZodType.init(inst, def);
3685
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
3686
+ inst.unwrap = () => inst._zod.def.innerType;
3687
+ });
3688
+ function prefault(innerType, defaultValue) {
3689
+ return new ZodPrefault({
3690
+ type: "prefault",
3691
+ innerType: innerType,
3692
+ get defaultValue() {
3693
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3694
+ },
3695
+ });
3696
+ }
3697
+ const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
3698
+ $ZodNonOptional.init(inst, def);
3699
+ ZodType.init(inst, def);
3700
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
3701
+ inst.unwrap = () => inst._zod.def.innerType;
3702
+ });
3703
+ function nonoptional(innerType, params) {
3704
+ return new ZodNonOptional({
3705
+ type: "nonoptional",
3706
+ innerType: innerType,
3707
+ ...normalizeParams(params),
3708
+ });
3709
+ }
3710
+ const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
3711
+ $ZodCatch.init(inst, def);
3712
+ ZodType.init(inst, def);
3713
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
3714
+ inst.unwrap = () => inst._zod.def.innerType;
3715
+ inst.removeCatch = inst.unwrap;
3716
+ });
3717
+ function _catch(innerType, catchValue) {
3718
+ return new ZodCatch({
3719
+ type: "catch",
3720
+ innerType: innerType,
3721
+ catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
3722
+ });
3723
+ }
3724
+ const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
3725
+ $ZodPipe.init(inst, def);
3726
+ ZodType.init(inst, def);
3727
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
3728
+ inst.in = def.in;
3729
+ inst.out = def.out;
3730
+ });
3731
+ function pipe(in_, out) {
3732
+ return new ZodPipe({
3733
+ type: "pipe",
3734
+ in: in_,
3735
+ out: out,
3736
+ // ...util.normalizeParams(params),
3737
+ });
3738
+ }
3739
+ const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
3740
+ $ZodReadonly.init(inst, def);
3741
+ ZodType.init(inst, def);
3742
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
3743
+ inst.unwrap = () => inst._zod.def.innerType;
3744
+ });
3745
+ function readonly(innerType) {
3746
+ return new ZodReadonly({
3747
+ type: "readonly",
3748
+ innerType: innerType,
3749
+ });
3750
+ }
3751
+ const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
3752
+ $ZodCustom.init(inst, def);
3753
+ ZodType.init(inst, def);
3754
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
3755
+ });
3756
+ function refine(fn, _params = {}) {
3757
+ return _refine(ZodCustom, fn, _params);
3758
+ }
3759
+ // superRefine
3760
+ function superRefine(fn) {
3761
+ return _superRefine(fn);
3762
+ }
3763
+
3764
+ object({
3765
+ baseUrl: string().url().default('https://cloud.uipath.com'),
3766
+ orgName: string().min(1),
3767
+ tenantName: string().min(1),
3768
+ secret: string().optional(),
3769
+ clientId: string().optional(),
3770
+ redirectUri: string().url().optional(),
3771
+ scope: string().optional()
15
3772
  });
16
3773
  class UiPathConfig {
17
3774
  constructor(options) {
@@ -617,6 +4374,15 @@ const CONTENT_TYPES = {
617
4374
  XML: 'application/xml',
618
4375
  OCTET_STREAM: 'application/octet-stream'
619
4376
  };
4377
+ /**
4378
+ * Response type constants for HTTP requests
4379
+ */
4380
+ const RESPONSE_TYPES = {
4381
+ JSON: 'json',
4382
+ TEXT: 'text',
4383
+ BLOB: 'blob',
4384
+ ARRAYBUFFER: 'arraybuffer'
4385
+ };
620
4386
 
621
4387
  class ApiClient {
622
4388
  constructor(config, executionContext, tokenManager, clientConfig = {}) {
@@ -711,6 +4477,11 @@ class ApiClient {
711
4477
  if (response.status === 204) {
712
4478
  return undefined;
713
4479
  }
4480
+ // Handle blob response type for binary data (e.g., file downloads)
4481
+ if (options.responseType === RESPONSE_TYPES.BLOB) {
4482
+ const blob = await response.blob();
4483
+ return blob;
4484
+ }
714
4485
  // Check if we're expecting XML
715
4486
  const acceptHeader = headers['Accept'] || headers['accept'];
716
4487
  if (acceptHeader === CONTENT_TYPES.XML) {
@@ -981,6 +4752,12 @@ function createHeaders(headersObj) {
981
4752
  const ODATA_PREFIX = '$';
982
4753
  const UNKNOWN$1 = 'Unknown';
983
4754
  const NO_INSTANCE = 'no-instance';
4755
+ /**
4756
+ * HTTP methods
4757
+ */
4758
+ const HTTP_METHODS = {
4759
+ GET: 'GET',
4760
+ POST: 'POST'};
984
4761
  /**
985
4762
  * OData pagination constants
986
4763
  */
@@ -999,6 +4776,16 @@ const ENTITY_PAGINATION = {
999
4776
  /** Field name for total count in entity response */
1000
4777
  TOTAL_COUNT_FIELD: 'totalRecordCount'
1001
4778
  };
4779
+ /**
4780
+ * Choice Set values endpoint pagination constants
4781
+ * Note: The API returns items as a JSON string in 'jsonValue' field
4782
+ */
4783
+ const CHOICESET_VALUES_PAGINATION = {
4784
+ /** Field name for items in choice set values response (contains JSON string) */
4785
+ ITEMS_FIELD: 'jsonValue',
4786
+ /** Field name for total count in choice set values response */
4787
+ TOTAL_COUNT_FIELD: 'totalRecordCount'
4788
+ };
1002
4789
  /**
1003
4790
  * Bucket pagination constants for token-based pagination
1004
4791
  */
@@ -1518,10 +5305,10 @@ class PaginationHelpers {
1518
5305
  * @returns Promise resolving to a paginated result
1519
5306
  */
1520
5307
  static async getAllPaginated(params) {
1521
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, options = {} } = params;
5308
+ const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1522
5309
  const endpoint = getEndpoint(folderId);
1523
5310
  const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1524
- const paginatedResponse = await serviceAccess.requestWithPagination('GET', endpoint, paginationParams, {
5311
+ const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1525
5312
  headers,
1526
5313
  params: additionalParams,
1527
5314
  pagination: {
@@ -1532,10 +5319,10 @@ class PaginationHelpers {
1532
5319
  paginationParams: options.paginationParams
1533
5320
  }
1534
5321
  });
1535
- // Transform items only if a transform function is provided
1536
- const transformedItems = transformFn
1537
- ? paginatedResponse.items.map(transformFn)
1538
- : paginatedResponse.items;
5322
+ // Parse items - automatically handle JSON string responses
5323
+ const rawItems = paginatedResponse.items;
5324
+ const parsedItems = typeof rawItems === 'string' ? JSON.parse(rawItems) : (rawItems || []);
5325
+ const transformedItems = transformFn ? parsedItems.map(transformFn) : parsedItems;
1539
5326
  return {
1540
5327
  ...paginatedResponse,
1541
5328
  items: transformedItems
@@ -1548,27 +5335,32 @@ class PaginationHelpers {
1548
5335
  * @returns Promise resolving to an object with data and totalCount
1549
5336
  */
1550
5337
  static async getAllNonPaginated(params) {
1551
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, options = {} } = params;
5338
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1552
5339
  // Set default field names
1553
5340
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1554
5341
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1555
5342
  // Determine endpoint and headers based on folderId
1556
5343
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1557
5344
  const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1558
- // Make the API call
1559
- const response = await serviceAccess.get(endpoint, {
1560
- params: additionalParams,
1561
- headers
1562
- });
1563
- // Extract data
1564
- const items = response.data?.[itemsField] || [];
1565
- // Transform items if a transform function is provided
1566
- const data = transformFn
1567
- ? items.map(transformFn)
1568
- : items;
5345
+ // Make the API call based on method
5346
+ let response;
5347
+ if (method === HTTP_METHODS.POST) {
5348
+ response = await serviceAccess.post(endpoint, additionalParams, { headers });
5349
+ }
5350
+ else {
5351
+ response = await serviceAccess.get(endpoint, {
5352
+ params: additionalParams,
5353
+ headers
5354
+ });
5355
+ }
5356
+ // Extract and transform items from response
5357
+ const rawItems = response.data?.[itemsField];
1569
5358
  const totalCount = response.data?.[totalCountField];
5359
+ // Parse items - automatically handle JSON string responses
5360
+ const parsedItems = typeof rawItems === 'string' ? JSON.parse(rawItems) : (rawItems || []);
5361
+ const items = transformFn ? parsedItems.map(transformFn) : parsedItems;
1570
5362
  return {
1571
- items: data,
5363
+ items,
1572
5364
  totalCount
1573
5365
  };
1574
5366
  }
@@ -1612,6 +5404,7 @@ class PaginationHelpers {
1612
5404
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1613
5405
  additionalParams: prefixedOptions,
1614
5406
  transformFn: config.transformFn,
5407
+ method: config.method,
1615
5408
  options: {
1616
5409
  ...paginationOptions,
1617
5410
  paginationParams: config.pagination?.paginationParams
@@ -1627,6 +5420,7 @@ class PaginationHelpers {
1627
5420
  folderId,
1628
5421
  additionalParams: prefixedOptions,
1629
5422
  transformFn: config.transformFn,
5423
+ method: config.method,
1630
5424
  options: {
1631
5425
  itemsField: paginationOptions.itemsField,
1632
5426
  totalCountField: paginationOptions.totalCountField
@@ -1648,6 +5442,7 @@ class BaseService {
1648
5442
  createPaginationServiceAccess() {
1649
5443
  return {
1650
5444
  get: (path, options) => this.get(path, options || {}),
5445
+ post: (path, body, options) => this.post(path, body, options || {}),
1651
5446
  requestWithPagination: (method, path, paginationOptions, options) => this.requestWithPagination(method, path, paginationOptions, options)
1652
5447
  };
1653
5448
  }
@@ -1702,11 +5497,22 @@ class BaseService {
1702
5497
  const params = this.validateAndPreparePaginationParams(paginationType, paginationOptions);
1703
5498
  // Prepare request parameters based on pagination type
1704
5499
  const requestParams = this.preparePaginationRequestParams(paginationType, params, options.pagination);
1705
- // Merge pagination parameters with existing parameters
1706
- options.params = {
1707
- ...options.params,
1708
- ...requestParams
1709
- };
5500
+ // For POST requests, merge pagination params into body; for GET, use query params
5501
+ if (method.toUpperCase() === 'POST') {
5502
+ const existingBody = (options.body && typeof options.body === 'object') ? options.body : {};
5503
+ options.body = {
5504
+ ...existingBody,
5505
+ ...options.params,
5506
+ ...requestParams
5507
+ };
5508
+ }
5509
+ else {
5510
+ // Merge pagination parameters with existing parameters
5511
+ options.params = {
5512
+ ...options.params,
5513
+ ...requestParams
5514
+ };
5515
+ }
1710
5516
  // Make the request
1711
5517
  const response = await this.request(method, path, options);
1712
5518
  // Extract data from the response and create page result
@@ -2071,105 +5877,118 @@ class TokenManager {
2071
5877
  * API Endpoint Constants
2072
5878
  * Centralized location for all API endpoints used throughout the SDK
2073
5879
  */
5880
+ /**
5881
+ * Base path constants for different services
5882
+ */
5883
+ const ORCHESTRATOR_BASE = 'orchestrator_';
5884
+ const PIMS_BASE = 'pims_';
5885
+ const DATAFABRIC_BASE = 'datafabric_';
5886
+ const IDENTITY_BASE = 'identity_';
2074
5887
  /**
2075
5888
  * Maestro Process Service Endpoints
2076
5889
  */
2077
5890
  const MAESTRO_ENDPOINTS = {
2078
- BASE_PATH: 'pims_/api/v1',
2079
5891
  PROCESSES: {
2080
- GET_ALL: 'pims_/api/v1/processes/summary',
2081
- GET_SETTINGS: (processKey) => `pims_/api/v1/processes/${processKey}/settings`,
5892
+ GET_ALL: `${PIMS_BASE}/api/v1/processes/summary`,
5893
+ GET_SETTINGS: (processKey) => `${PIMS_BASE}/api/v1/processes/${processKey}/settings`,
2082
5894
  },
2083
5895
  INSTANCES: {
2084
- GET_ALL: 'pims_/api/v1/instances',
2085
- GET_BY_ID: (instanceId) => `pims_/api/v1/instances/${instanceId}`,
2086
- GET_EXECUTION_HISTORY: (instanceId) => `pims_/api/v1/spans/${instanceId}`,
2087
- GET_BPMN: (instanceId) => `pims_/api/v1/instances/${instanceId}/bpmn`,
2088
- GET_VARIABLES: (instanceId) => `pims_/api/v1/instances/${instanceId}/variables`,
2089
- CANCEL: (instanceId) => `pims_/api/v1/instances/${instanceId}/cancel`,
2090
- PAUSE: (instanceId) => `pims_/api/v1/instances/${instanceId}/pause`,
2091
- RESUME: (instanceId) => `pims_/api/v1/instances/${instanceId}/resume`,
5896
+ GET_ALL: `${PIMS_BASE}/api/v1/instances`,
5897
+ GET_BY_ID: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}`,
5898
+ GET_EXECUTION_HISTORY: (instanceId) => `${PIMS_BASE}/api/v1/spans/${instanceId}`,
5899
+ GET_BPMN: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/bpmn`,
5900
+ GET_VARIABLES: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/variables`,
5901
+ CANCEL: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/cancel`,
5902
+ PAUSE: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/pause`,
5903
+ RESUME: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/resume`,
2092
5904
  },
2093
5905
  INCIDENTS: {
2094
- GET_ALL: 'pims_/api/v1/incidents/summary',
2095
- GET_BY_PROCESS: (processKey) => `pims_/api/v1/incidents/process/${processKey}`,
2096
- GET_BY_INSTANCE: (instanceId) => `pims_/api/v1/instances/${instanceId}/incidents`,
5906
+ GET_ALL: `${PIMS_BASE}/api/v1/incidents/summary`,
5907
+ GET_BY_PROCESS: (processKey) => `${PIMS_BASE}/api/v1/incidents/process/${processKey}`,
5908
+ GET_BY_INSTANCE: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/incidents`,
2097
5909
  },
2098
5910
  CASES: {
2099
- GET_CASE_JSON: (instanceId) => `pims_/api/v1/cases/${instanceId}/case-json`,
2100
- GET_ELEMENT_EXECUTIONS: (instanceId) => `pims_/api/v1alpha1/element-executions/case-instances/${instanceId}`,
5911
+ GET_CASE_JSON: (instanceId) => `${PIMS_BASE}/api/v1/cases/${instanceId}/case-json`,
5912
+ GET_ELEMENT_EXECUTIONS: (instanceId) => `${PIMS_BASE}/api/v1alpha1/element-executions/case-instances/${instanceId}`,
2101
5913
  },
2102
5914
  };
2103
5915
  /**
2104
5916
  * Task Service (Action Center) Endpoints
2105
5917
  */
2106
5918
  const TASK_ENDPOINTS = {
2107
- CREATE_GENERIC_TASK: '/tasks/GenericTasks/CreateTask',
2108
- GET_TASK_USERS: (folderId) => `/odata/Tasks/UiPath.Server.Configuration.OData.GetTaskUsers(organizationUnitId=${folderId})`,
2109
- GET_TASKS_ACROSS_FOLDERS: '/odata/Tasks/UiPath.Server.Configuration.OData.GetTasksAcrossFoldersForAdmin',
2110
- GET_BY_ID: (id) => `/odata/Tasks(${id})`,
2111
- ASSIGN_TASKS: '/odata/Tasks/UiPath.Server.Configuration.OData.AssignTasks',
2112
- REASSIGN_TASKS: '/odata/Tasks/UiPath.Server.Configuration.OData.ReassignTasks',
2113
- UNASSIGN_TASKS: '/odata/Tasks/UiPath.Server.Configuration.OData.UnassignTasks',
2114
- COMPLETE_FORM_TASK: '/forms/TaskForms/CompleteTask',
2115
- COMPLETE_APP_TASK: '/tasks/AppTasks/CompleteAppTask',
2116
- COMPLETE_GENERIC_TASK: '/tasks/GenericTasks/CompleteTask',
2117
- GET_TASK_FORM_BY_ID: '/forms/TaskForms/GetTaskFormById',
5919
+ CREATE_GENERIC_TASK: `${ORCHESTRATOR_BASE}/tasks/GenericTasks/CreateTask`,
5920
+ GET_TASK_USERS: (folderId) => `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.GetTaskUsers(organizationUnitId=${folderId})`,
5921
+ GET_TASKS_ACROSS_FOLDERS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.GetTasksAcrossFolders`,
5922
+ GET_TASKS_ACROSS_FOLDERS_ADMIN: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.GetTasksAcrossFoldersForAdmin`,
5923
+ GET_BY_ID: (id) => `${ORCHESTRATOR_BASE}/odata/Tasks(${id})`,
5924
+ ASSIGN_TASKS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.AssignTasks`,
5925
+ REASSIGN_TASKS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.ReassignTasks`,
5926
+ UNASSIGN_TASKS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.UnassignTasks`,
5927
+ COMPLETE_FORM_TASK: `${ORCHESTRATOR_BASE}/forms/TaskForms/CompleteTask`,
5928
+ COMPLETE_APP_TASK: `${ORCHESTRATOR_BASE}/tasks/AppTasks/CompleteAppTask`,
5929
+ COMPLETE_GENERIC_TASK: `${ORCHESTRATOR_BASE}/tasks/GenericTasks/CompleteTask`,
5930
+ GET_TASK_FORM_BY_ID: `${ORCHESTRATOR_BASE}/forms/TaskForms/GetTaskFormById`,
2118
5931
  };
2119
5932
  /**
2120
5933
  * Data Fabric Service Endpoints
2121
5934
  */
2122
5935
  const DATA_FABRIC_ENDPOINTS = {
2123
5936
  ENTITY: {
2124
- GET_ALL: 'datafabric_/api/Entity',
2125
- GET_ENTITY_RECORDS: (entityId) => `datafabric_/api/EntityService/entity/${entityId}/read`,
2126
- GET_BY_ID: (entityId) => `datafabric_/api/Entity/${entityId}`,
2127
- INSERT_BY_ID: (entityId) => `datafabric_/api/EntityService/entity/${entityId}/insert-batch`,
2128
- UPDATE_BY_ID: (entityId) => `datafabric_/api/EntityService/entity/${entityId}/update-batch`,
2129
- DELETE_BY_ID: (entityId) => `datafabric_/api/EntityService/entity/${entityId}/delete-batch`,
5937
+ GET_ALL: `${DATAFABRIC_BASE}/api/Entity`,
5938
+ GET_ENTITY_RECORDS: (entityId) => `${DATAFABRIC_BASE}/api/EntityService/entity/${entityId}/read`,
5939
+ GET_BY_ID: (entityId) => `${DATAFABRIC_BASE}/api/Entity/${entityId}`,
5940
+ INSERT_BY_ID: (entityId) => `${DATAFABRIC_BASE}/api/EntityService/entity/${entityId}/insert`,
5941
+ BATCH_INSERT_BY_ID: (entityId) => `${DATAFABRIC_BASE}/api/EntityService/entity/${entityId}/insert-batch`,
5942
+ UPDATE_BY_ID: (entityId) => `${DATAFABRIC_BASE}/api/EntityService/entity/${entityId}/update-batch`,
5943
+ DELETE_BY_ID: (entityId) => `${DATAFABRIC_BASE}/api/EntityService/entity/${entityId}/delete-batch`,
5944
+ DOWNLOAD_ATTACHMENT: (entityName, recordId, fieldName) => `${DATAFABRIC_BASE}/api/Attachment/${entityName}/${recordId}/${fieldName}`,
5945
+ },
5946
+ CHOICESETS: {
5947
+ GET_ALL: `${DATAFABRIC_BASE}/api/Entity/choiceset`,
5948
+ GET_BY_ID: (choiceSetId) => `${DATAFABRIC_BASE}/api/EntityService/entity/${choiceSetId}/query_expansion`,
2130
5949
  },
2131
5950
  };
2132
5951
  /**
2133
5952
  * Orchestrator Bucket Endpoints
2134
5953
  */
2135
5954
  const BUCKET_ENDPOINTS = {
2136
- GET_BY_FOLDER: '/odata/Buckets',
2137
- GET_ALL: '/odata/Buckets/UiPath.Server.Configuration.OData.GetBucketsAcrossFolders',
2138
- GET_BY_ID: (id) => `/odata/Buckets(${id})`,
2139
- GET_FILE_META_DATA: (id) => `/api/Buckets/${id}/ListFiles`,
2140
- GET_READ_URI: (id) => `/odata/Buckets(${id})/UiPath.Server.Configuration.OData.GetReadUri`,
2141
- GET_WRITE_URI: (id) => `/odata/Buckets(${id})/UiPath.Server.Configuration.OData.GetWriteUri`,
5955
+ GET_BY_FOLDER: `${ORCHESTRATOR_BASE}/odata/Buckets`,
5956
+ GET_ALL: `${ORCHESTRATOR_BASE}/odata/Buckets/UiPath.Server.Configuration.OData.GetBucketsAcrossFolders`,
5957
+ GET_BY_ID: (id) => `${ORCHESTRATOR_BASE}/odata/Buckets(${id})`,
5958
+ GET_FILE_META_DATA: (id) => `${ORCHESTRATOR_BASE}/api/Buckets/${id}/ListFiles`,
5959
+ GET_READ_URI: (id) => `${ORCHESTRATOR_BASE}/odata/Buckets(${id})/UiPath.Server.Configuration.OData.GetReadUri`,
5960
+ GET_WRITE_URI: (id) => `${ORCHESTRATOR_BASE}/odata/Buckets(${id})/UiPath.Server.Configuration.OData.GetWriteUri`,
2142
5961
  };
2143
5962
  /**
2144
5963
  * Identity/Authentication Endpoints
2145
5964
  */
2146
5965
  const IDENTITY_ENDPOINTS = {
2147
- TOKEN: 'identity_/connect/token',
2148
- AUTHORIZE: 'identity_/connect/authorize',
5966
+ TOKEN: `${IDENTITY_BASE}/connect/token`,
5967
+ AUTHORIZE: `${IDENTITY_BASE}/connect/authorize`,
2149
5968
  };
2150
5969
  /**
2151
5970
  * Orchestrator Process Service Endpoints
2152
5971
  */
2153
5972
  const PROCESS_ENDPOINTS = {
2154
- GET_ALL: '/odata/Releases',
2155
- START_PROCESS: '/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs',
2156
- GET_BY_ID: (id) => `/odata/Releases(${id})`,
5973
+ GET_ALL: `${ORCHESTRATOR_BASE}/odata/Releases`,
5974
+ START_PROCESS: `${ORCHESTRATOR_BASE}/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs`,
5975
+ GET_BY_ID: (id) => `${ORCHESTRATOR_BASE}/odata/Releases(${id})`,
2157
5976
  };
2158
5977
  /**
2159
5978
  * Orchestrator Queue Service Endpoints
2160
5979
  */
2161
5980
  const QUEUE_ENDPOINTS = {
2162
- GET_BY_FOLDER: '/odata/QueueDefinitions',
2163
- GET_ALL: '/odata/QueueDefinitions/UiPath.Server.Configuration.OData.GetQueuesAcrossFolders',
2164
- GET_BY_ID: (id) => `/odata/QueueDefinitions(${id})`,
5981
+ GET_BY_FOLDER: `${ORCHESTRATOR_BASE}/odata/QueueDefinitions`,
5982
+ GET_ALL: `${ORCHESTRATOR_BASE}/odata/QueueDefinitions/UiPath.Server.Configuration.OData.GetQueuesAcrossFolders`,
5983
+ GET_BY_ID: (id) => `${ORCHESTRATOR_BASE}/odata/QueueDefinitions(${id})`,
2165
5984
  };
2166
5985
  /**
2167
5986
  * Orchestrator Asset Service Endpoints
2168
5987
  */
2169
5988
  const ASSET_ENDPOINTS = {
2170
- GET_BY_FOLDER: '/odata/Assets/UiPath.Server.Configuration.OData.GetFiltered',
2171
- GET_ALL: '/odata/Assets/UiPath.Server.Configuration.OData.GetAssetsAcrossFolders',
2172
- GET_BY_ID: (id) => `/odata/Assets(${id})`,
5989
+ GET_BY_FOLDER: `${ORCHESTRATOR_BASE}/odata/Assets/UiPath.Server.Configuration.OData.GetFiltered`,
5990
+ GET_ALL: `${ORCHESTRATOR_BASE}/odata/Assets/UiPath.Server.Configuration.OData.GetAssetsAcrossFolders`,
5991
+ GET_BY_ID: (id) => `${ORCHESTRATOR_BASE}/odata/Assets(${id})`,
2173
5992
  };
2174
5993
 
2175
5994
  class AuthService extends BaseService {
@@ -2181,6 +6000,9 @@ class AuthService extends BaseService {
2181
6000
  const tokenManager = new TokenManager(executionContext, effectiveConfig, isOAuth);
2182
6001
  super(effectiveConfig, executionContext, tokenManager);
2183
6002
  this.tokenManager = tokenManager;
6003
+ // Auto-load token from storage on initialization
6004
+ // This ensures isAuthenticated() returns true after page refresh if a valid token exists
6005
+ this.tokenManager.loadFromStorage();
2184
6006
  }
2185
6007
  /**
2186
6008
  * Check if we're in an OAuth callback state
@@ -2553,6 +6375,11 @@ function createEntityMethods(entityData, service) {
2553
6375
  throw new Error('Entity ID is undefined');
2554
6376
  return service.insertById(entityData.id, data, options);
2555
6377
  },
6378
+ async batchInsert(data, options) {
6379
+ if (!entityData.id)
6380
+ throw new Error('Entity ID is undefined');
6381
+ return service.batchInsertById(entityData.id, data, options);
6382
+ },
2556
6383
  async update(data, options) {
2557
6384
  if (!entityData.id)
2558
6385
  throw new Error('Entity ID is undefined');
@@ -2567,6 +6394,15 @@ function createEntityMethods(entityData, service) {
2567
6394
  if (!entityData.id)
2568
6395
  throw new Error('Entity ID is undefined');
2569
6396
  return service.getRecordsById(entityData.id, options);
6397
+ },
6398
+ async downloadAttachment(recordId, fieldName) {
6399
+ if (!entityData.name)
6400
+ throw new Error('Entity name is undefined');
6401
+ return service.downloadAttachment({
6402
+ entityName: entityData.name,
6403
+ recordId,
6404
+ fieldName
6405
+ });
2570
6406
  }
2571
6407
  };
2572
6408
  }
@@ -2731,7 +6567,7 @@ const EntityFieldTypeMap = {
2731
6567
  // Connection string placeholder that will be replaced during build
2732
6568
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
2733
6569
  // SDK Version placeholder
2734
- const SDK_VERSION = "1.0.0-beta.16";
6570
+ const SDK_VERSION = "1.0.0-beta.18";
2735
6571
  const VERSION = "Version";
2736
6572
  const SERVICE = "Service";
2737
6573
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -3029,8 +6865,13 @@ class EntityService extends BaseService {
3029
6865
  * // Call operations directly on the entity
3030
6866
  * const records = await entity.getRecords();
3031
6867
  *
3032
- * const insertResult = await entity.insert([
3033
- * { name: "John", age: 30 }
6868
+ * // Insert a single record
6869
+ * const insertResult = await entity.insert({ name: "John", age: 30 });
6870
+ *
6871
+ * // Or batch insert multiple records
6872
+ * const batchResult = await entity.batchInsert([
6873
+ * { name: "Jane", age: 25 },
6874
+ * { name: "Bob", age: 35 }
3034
6875
  * ]);
3035
6876
  * ```
3036
6877
  */
@@ -3092,7 +6933,38 @@ class EntityService extends BaseService {
3092
6933
  }, options);
3093
6934
  }
3094
6935
  /**
3095
- * Inserts data into an entity by entity ID
6936
+ * Inserts a single record into an entity by entity ID
6937
+ *
6938
+ * @param entityId - UUID of the entity
6939
+ * @param data - Record to insert
6940
+ * @param options - Insert options
6941
+ * @returns Promise resolving to the inserted record with generated record ID
6942
+ *
6943
+ * @example
6944
+ * ```typescript
6945
+ * // Basic usage
6946
+ * const result = await sdk.entities.insertById(<entityId>, { name: "John", age: 30 });
6947
+ *
6948
+ * // With options
6949
+ * const result = await sdk.entities.insertById(<entityId>, { name: "John", age: 30 }, {
6950
+ * expansionLevel: 1
6951
+ * });
6952
+ * ```
6953
+ */
6954
+ async insertById(id, data, options = {}) {
6955
+ const params = createParams({
6956
+ expansionLevel: options.expansionLevel
6957
+ });
6958
+ const response = await this.post(DATA_FABRIC_ENDPOINTS.ENTITY.INSERT_BY_ID(id), data, {
6959
+ params,
6960
+ ...options
6961
+ });
6962
+ // Convert PascalCase response to camelCase
6963
+ const camelResponse = pascalToCamelCaseKeys(response.data);
6964
+ return camelResponse;
6965
+ }
6966
+ /**
6967
+ * Inserts data into an entity by entity ID using batch insert
3096
6968
  *
3097
6969
  * @param entityId - UUID of the entity
3098
6970
  * @param data - Array of records to insert
@@ -3102,13 +6974,13 @@ class EntityService extends BaseService {
3102
6974
  * @example
3103
6975
  * ```typescript
3104
6976
  * // Basic usage
3105
- * const result = await sdk.entities.insertById(<entityId>, [
6977
+ * const result = await sdk.entities.batchInsertById(<entityId>, [
3106
6978
  * { name: "John", age: 30 },
3107
6979
  * { name: "Jane", age: 25 }
3108
6980
  * ]);
3109
6981
  *
3110
6982
  * // With options
3111
- * const result = await sdk.entities.insertById(<entityId>, [
6983
+ * const result = await sdk.entities.batchInsertById(<entityId>, [
3112
6984
  * { name: "John", age: 30 },
3113
6985
  * { name: "Jane", age: 25 }
3114
6986
  * ], {
@@ -3117,12 +6989,12 @@ class EntityService extends BaseService {
3117
6989
  * });
3118
6990
  * ```
3119
6991
  */
3120
- async insertById(id, data, options = {}) {
6992
+ async batchInsertById(id, data, options = {}) {
3121
6993
  const params = createParams({
3122
6994
  expansionLevel: options.expansionLevel,
3123
6995
  failOnFirst: options.failOnFirst
3124
6996
  });
3125
- const response = await this.post(DATA_FABRIC_ENDPOINTS.ENTITY.INSERT_BY_ID(id), data, {
6997
+ const response = await this.post(DATA_FABRIC_ENDPOINTS.ENTITY.BATCH_INSERT_BY_ID(id), data, {
3126
6998
  params,
3127
6999
  ...options
3128
7000
  });
@@ -3224,6 +7096,28 @@ class EntityService extends BaseService {
3224
7096
  });
3225
7097
  return entities;
3226
7098
  }
7099
+ /**
7100
+ * Downloads an attachment from an entity record field
7101
+ *
7102
+ * @param options - Options containing entityName, recordId, and fieldName
7103
+ * @returns Promise resolving to Blob containing the file content
7104
+ *
7105
+ * @example
7106
+ * ```typescript
7107
+ * // Download attachment for a specific record and field
7108
+ * const blob = await sdk.entities.downloadAttachment({
7109
+ * entityName: 'Invoice',
7110
+ * recordId: '<record-uuid>',
7111
+ * fieldName: 'Documents'
7112
+ * });
7113
+ */
7114
+ async downloadAttachment(options) {
7115
+ const { entityName, recordId, fieldName } = options;
7116
+ const response = await this.get(DATA_FABRIC_ENDPOINTS.ENTITY.DOWNLOAD_ATTACHMENT(entityName, recordId, fieldName), {
7117
+ responseType: RESPONSE_TYPES.BLOB
7118
+ });
7119
+ return response.data;
7120
+ }
3227
7121
  /**
3228
7122
  * Orchestrates all field mapping transformations
3229
7123
  *
@@ -3304,6 +7198,9 @@ __decorate([
3304
7198
  __decorate([
3305
7199
  track('Entities.InsertById')
3306
7200
  ], EntityService.prototype, "insertById", null);
7201
+ __decorate([
7202
+ track('Entities.BatchInsertById')
7203
+ ], EntityService.prototype, "batchInsertById", null);
3307
7204
  __decorate([
3308
7205
  track('Entities.UpdateById')
3309
7206
  ], EntityService.prototype, "updateById", null);
@@ -3313,6 +7210,105 @@ __decorate([
3313
7210
  __decorate([
3314
7211
  track('Entities.GetAll')
3315
7212
  ], EntityService.prototype, "getAll", null);
7213
+ __decorate([
7214
+ track('Entities.DownloadAttachment')
7215
+ ], EntityService.prototype, "downloadAttachment", null);
7216
+
7217
+ class ChoiceSetService extends BaseService {
7218
+ /**
7219
+ * @hideconstructor
7220
+ */
7221
+ constructor(config, executionContext, tokenManager) {
7222
+ super(config, executionContext, tokenManager);
7223
+ }
7224
+ /**
7225
+ * Gets all choice sets in the system
7226
+ *
7227
+ * @returns Promise resolving to an array of choice set metadata
7228
+ *
7229
+ * @example
7230
+ * ```typescript
7231
+ * // Get all choice sets
7232
+ * const choiceSets = await sdk.entities.choicesets.getAll();
7233
+ *
7234
+ * // Iterate through choice sets
7235
+ * choiceSets.forEach(choiceSet => {
7236
+ * console.log(`ChoiceSet: ${choiceSet.displayName} (${choiceSet.name})`);
7237
+ * console.log(`Description: ${choiceSet.description}`);
7238
+ * });
7239
+ * ```
7240
+ */
7241
+ async getAll() {
7242
+ const rawResponse = await this.get(DATA_FABRIC_ENDPOINTS.CHOICESETS.GET_ALL);
7243
+ // Transform field names
7244
+ const data = rawResponse.data || [];
7245
+ return data.map(choiceSet => transformData(choiceSet, EntityMap));
7246
+ }
7247
+ /**
7248
+ * Gets choice set values by choice set ID with optional pagination
7249
+ *
7250
+ * The method returns either:
7251
+ * - A NonPaginatedResponse with items array (when no pagination parameters are provided)
7252
+ * - A PaginatedResponse with navigation cursors (when any pagination parameter is provided)
7253
+ *
7254
+ * @param choiceSetId - UUID of the choice set
7255
+ * @param options - Pagination options
7256
+ * @returns Promise resolving to choice set values or paginated result
7257
+ *
7258
+ * @example
7259
+ * ```typescript
7260
+ * // First, get the choice set ID using getAll()
7261
+ * const choiceSets = await sdk.entities.choicesets.getAll();
7262
+ * const expenseTypes = choiceSets.find(cs => cs.name === 'ExpenseTypes');
7263
+ * const choiceSetId = expenseTypes.id;
7264
+ *
7265
+ * // Get all values (non-paginated)
7266
+ * const values = await sdk.entities.choicesets.getById(choiceSetId);
7267
+ *
7268
+ * // Iterate through choice set values
7269
+ * for (const value of values.items) {
7270
+ * console.log(`Value: ${value.displayName} (${value.name})`);
7271
+ * }
7272
+ *
7273
+ * // First page with pagination
7274
+ * const page1 = await sdk.entities.choicesets.getById(choiceSetId, { pageSize: 10 });
7275
+ *
7276
+ * // Navigate using cursor
7277
+ * if (page1.hasNextPage) {
7278
+ * const page2 = await sdk.entities.choicesets.getById(choiceSetId, { cursor: page1.nextCursor });
7279
+ * }
7280
+ * ```
7281
+ */
7282
+ async getById(choiceSetId, options) {
7283
+ // Transform a single item from PascalCase to camelCase
7284
+ const transformFn = (item) => {
7285
+ const camelCased = pascalToCamelCaseKeys(item);
7286
+ return transformData(camelCased, EntityMap);
7287
+ };
7288
+ return PaginationHelpers.getAll({
7289
+ serviceAccess: this.createPaginationServiceAccess(),
7290
+ getEndpoint: () => DATA_FABRIC_ENDPOINTS.CHOICESETS.GET_BY_ID(choiceSetId),
7291
+ transformFn,
7292
+ method: HTTP_METHODS.POST,
7293
+ pagination: {
7294
+ paginationType: PaginationType.OFFSET,
7295
+ itemsField: CHOICESET_VALUES_PAGINATION.ITEMS_FIELD,
7296
+ totalCountField: CHOICESET_VALUES_PAGINATION.TOTAL_COUNT_FIELD,
7297
+ paginationParams: {
7298
+ pageSizeParam: ENTITY_OFFSET_PARAMS.PAGE_SIZE_PARAM,
7299
+ offsetParam: ENTITY_OFFSET_PARAMS.OFFSET_PARAM,
7300
+ countParam: ENTITY_OFFSET_PARAMS.COUNT_PARAM
7301
+ }
7302
+ }
7303
+ }, options);
7304
+ }
7305
+ }
7306
+ __decorate([
7307
+ track('Choicesets.GetAll')
7308
+ ], ChoiceSetService.prototype, "getAll", null);
7309
+ __decorate([
7310
+ track('Choicesets.GetById')
7311
+ ], ChoiceSetService.prototype, "getById", null);
3316
7312
 
3317
7313
  /**
3318
7314
  * Maestro Process Models
@@ -4490,7 +8486,7 @@ class TaskService extends BaseService {
4490
8486
  * - An array of tasks (when no pagination parameters are provided)
4491
8487
  * - A paginated result with navigation cursors (when any pagination parameter is provided)
4492
8488
  *
4493
- * @param options - Query options including optional folderId and pagination options
8489
+ * @param options - Query options including optional folderId, asTaskAdmin flag and pagination options
4494
8490
  * @returns Promise resolving to an array of tasks or paginated result
4495
8491
  *
4496
8492
  * @example
@@ -4503,6 +8499,11 @@ class TaskService extends BaseService {
4503
8499
  * folderId: 123
4504
8500
  * });
4505
8501
  *
8502
+ * // Get tasks with admin permissions
8503
+ * const tasks = await sdk.tasks.getAll({
8504
+ * asTaskAdmin: true
8505
+ * });
8506
+ *
4506
8507
  * // First page with pagination
4507
8508
  * const page1 = await sdk.tasks.getAll({ pageSize: 10 });
4508
8509
  *
@@ -4519,6 +8520,10 @@ class TaskService extends BaseService {
4519
8520
  * ```
4520
8521
  */
4521
8522
  async getAll(options) {
8523
+ // Determine which endpoint to use based on asTaskAdmin flag
8524
+ const endpoint = options?.asTaskAdmin
8525
+ ? TASK_ENDPOINTS.GET_TASKS_ACROSS_FOLDERS_ADMIN
8526
+ : TASK_ENDPOINTS.GET_TASKS_ACROSS_FOLDERS;
4522
8527
  // Transformation function for tasks
4523
8528
  const transformTaskResponse = (task) => {
4524
8529
  const transformedTask = transformData(pascalToCamelCaseKeys(task), TaskMap);
@@ -4526,7 +8531,7 @@ class TaskService extends BaseService {
4526
8531
  };
4527
8532
  return PaginationHelpers.getAll({
4528
8533
  serviceAccess: this.createPaginationServiceAccess(),
4529
- getEndpoint: () => TASK_ENDPOINTS.GET_TASKS_ACROSS_FOLDERS,
8534
+ getEndpoint: () => endpoint,
4530
8535
  transformFn: transformTaskResponse,
4531
8536
  processParametersFn: this.processTaskParameters,
4532
8537
  excludeFromPrefix: ['event'], // Exclude 'event' key from ODATA prefix transformation
@@ -6169,7 +10174,12 @@ class UiPath {
6169
10174
  * Access to Entity service
6170
10175
  */
6171
10176
  get entities() {
6172
- return this.getService(EntityService);
10177
+ return Object.assign(this.getService(EntityService), {
10178
+ /**
10179
+ * Access to ChoiceSet service for managing choice sets
10180
+ */
10181
+ choicesets: this.getService(ChoiceSetService)
10182
+ });
6173
10183
  }
6174
10184
  /**
6175
10185
  * Access to Tasks service