@finatic/client 0.9.5 → 0.9.6
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.d.ts +5 -630
- package/dist/index.js +3281 -381
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3278 -347
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import pRetry, { AbortError } from 'p-retry';
|
|
2
|
-
import * as z from 'zod';
|
|
3
1
|
import globalAxios from 'axios';
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -23,6 +21,264 @@ function generateRequestId() {
|
|
|
23
21
|
});
|
|
24
22
|
}
|
|
25
23
|
|
|
24
|
+
const objectToString = Object.prototype.toString;
|
|
25
|
+
|
|
26
|
+
const isError = value => objectToString.call(value) === '[object Error]';
|
|
27
|
+
|
|
28
|
+
const errorMessages = new Set([
|
|
29
|
+
'network error', // Chrome
|
|
30
|
+
'Failed to fetch', // Chrome
|
|
31
|
+
'NetworkError when attempting to fetch resource.', // Firefox
|
|
32
|
+
'The Internet connection appears to be offline.', // Safari 16
|
|
33
|
+
'Network request failed', // `cross-fetch`
|
|
34
|
+
'fetch failed', // Undici (Node.js)
|
|
35
|
+
'terminated', // Undici (Node.js)
|
|
36
|
+
' A network error occurred.', // Bun (WebKit)
|
|
37
|
+
'Network connection lost', // Cloudflare Workers (fetch)
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
function isNetworkError(error) {
|
|
41
|
+
const isValid = error
|
|
42
|
+
&& isError(error)
|
|
43
|
+
&& error.name === 'TypeError'
|
|
44
|
+
&& typeof error.message === 'string';
|
|
45
|
+
|
|
46
|
+
if (!isValid) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const {message, stack} = error;
|
|
51
|
+
|
|
52
|
+
// Safari 17+ has generic message but no stack for network errors
|
|
53
|
+
if (message === 'Load failed') {
|
|
54
|
+
return stack === undefined
|
|
55
|
+
// Sentry adds its own stack trace to the fetch error, so also check for that
|
|
56
|
+
|| '__sentry_captured__' in error;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Deno network errors start with specific text
|
|
60
|
+
if (message.startsWith('error sending request for url')) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Standard network error messages
|
|
65
|
+
return errorMessages.has(message);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function validateRetries(retries) {
|
|
69
|
+
if (typeof retries === 'number') {
|
|
70
|
+
if (retries < 0) {
|
|
71
|
+
throw new TypeError('Expected `retries` to be a non-negative number.');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (Number.isNaN(retries)) {
|
|
75
|
+
throw new TypeError('Expected `retries` to be a valid number or Infinity, got NaN.');
|
|
76
|
+
}
|
|
77
|
+
} else if (retries !== undefined) {
|
|
78
|
+
throw new TypeError('Expected `retries` to be a number or Infinity.');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function validateNumberOption(name, value, {min = 0, allowInfinity = false} = {}) {
|
|
83
|
+
if (value === undefined) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (typeof value !== 'number' || Number.isNaN(value)) {
|
|
88
|
+
throw new TypeError(`Expected \`${name}\` to be a number${allowInfinity ? ' or Infinity' : ''}.`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!allowInfinity && !Number.isFinite(value)) {
|
|
92
|
+
throw new TypeError(`Expected \`${name}\` to be a finite number.`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (value < min) {
|
|
96
|
+
throw new TypeError(`Expected \`${name}\` to be \u2265 ${min}.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class AbortError extends Error {
|
|
101
|
+
constructor(message) {
|
|
102
|
+
super();
|
|
103
|
+
|
|
104
|
+
if (message instanceof Error) {
|
|
105
|
+
this.originalError = message;
|
|
106
|
+
({message} = message);
|
|
107
|
+
} else {
|
|
108
|
+
this.originalError = new Error(message);
|
|
109
|
+
this.originalError.stack = this.stack;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this.name = 'AbortError';
|
|
113
|
+
this.message = message;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function calculateDelay(retriesConsumed, options) {
|
|
118
|
+
const attempt = Math.max(1, retriesConsumed + 1);
|
|
119
|
+
const random = options.randomize ? (Math.random() + 1) : 1;
|
|
120
|
+
|
|
121
|
+
let timeout = Math.round(random * options.minTimeout * (options.factor ** (attempt - 1)));
|
|
122
|
+
timeout = Math.min(timeout, options.maxTimeout);
|
|
123
|
+
|
|
124
|
+
return timeout;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function calculateRemainingTime(start, max) {
|
|
128
|
+
if (!Number.isFinite(max)) {
|
|
129
|
+
return max;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return max - (performance.now() - start);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function onAttemptFailure({error, attemptNumber, retriesConsumed, startTime, options}) {
|
|
136
|
+
const normalizedError = error instanceof Error
|
|
137
|
+
? error
|
|
138
|
+
: new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
|
|
139
|
+
|
|
140
|
+
if (normalizedError instanceof AbortError) {
|
|
141
|
+
throw normalizedError.originalError;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const retriesLeft = Number.isFinite(options.retries)
|
|
145
|
+
? Math.max(0, options.retries - retriesConsumed)
|
|
146
|
+
: options.retries;
|
|
147
|
+
|
|
148
|
+
const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
|
|
149
|
+
|
|
150
|
+
const context = Object.freeze({
|
|
151
|
+
error: normalizedError,
|
|
152
|
+
attemptNumber,
|
|
153
|
+
retriesLeft,
|
|
154
|
+
retriesConsumed,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
await options.onFailedAttempt(context);
|
|
158
|
+
|
|
159
|
+
if (calculateRemainingTime(startTime, maxRetryTime) <= 0) {
|
|
160
|
+
throw normalizedError;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const consumeRetry = await options.shouldConsumeRetry(context);
|
|
164
|
+
|
|
165
|
+
const remainingTime = calculateRemainingTime(startTime, maxRetryTime);
|
|
166
|
+
|
|
167
|
+
if (remainingTime <= 0 || retriesLeft <= 0) {
|
|
168
|
+
throw normalizedError;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (normalizedError instanceof TypeError && !isNetworkError(normalizedError)) {
|
|
172
|
+
if (consumeRetry) {
|
|
173
|
+
throw normalizedError;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
options.signal?.throwIfAborted();
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (!await options.shouldRetry(context)) {
|
|
181
|
+
throw normalizedError;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!consumeRetry) {
|
|
185
|
+
options.signal?.throwIfAborted();
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const delayTime = calculateDelay(retriesConsumed, options);
|
|
190
|
+
const finalDelay = Math.min(delayTime, remainingTime);
|
|
191
|
+
|
|
192
|
+
if (finalDelay > 0) {
|
|
193
|
+
await new Promise((resolve, reject) => {
|
|
194
|
+
const onAbort = () => {
|
|
195
|
+
clearTimeout(timeoutToken);
|
|
196
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
197
|
+
reject(options.signal.reason);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const timeoutToken = setTimeout(() => {
|
|
201
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
202
|
+
resolve();
|
|
203
|
+
}, finalDelay);
|
|
204
|
+
|
|
205
|
+
if (options.unref) {
|
|
206
|
+
timeoutToken.unref?.();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
options.signal?.addEventListener('abort', onAbort, {once: true});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
options.signal?.throwIfAborted();
|
|
214
|
+
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function pRetry(input, options = {}) {
|
|
219
|
+
options = {...options};
|
|
220
|
+
|
|
221
|
+
validateRetries(options.retries);
|
|
222
|
+
|
|
223
|
+
if (Object.hasOwn(options, 'forever')) {
|
|
224
|
+
throw new Error('The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
options.retries ??= 10;
|
|
228
|
+
options.factor ??= 2;
|
|
229
|
+
options.minTimeout ??= 1000;
|
|
230
|
+
options.maxTimeout ??= Number.POSITIVE_INFINITY;
|
|
231
|
+
options.maxRetryTime ??= Number.POSITIVE_INFINITY;
|
|
232
|
+
options.randomize ??= false;
|
|
233
|
+
options.onFailedAttempt ??= () => {};
|
|
234
|
+
options.shouldRetry ??= () => true;
|
|
235
|
+
options.shouldConsumeRetry ??= () => true;
|
|
236
|
+
|
|
237
|
+
// Validate numeric options and normalize edge cases
|
|
238
|
+
validateNumberOption('factor', options.factor, {min: 0, allowInfinity: false});
|
|
239
|
+
validateNumberOption('minTimeout', options.minTimeout, {min: 0, allowInfinity: false});
|
|
240
|
+
validateNumberOption('maxTimeout', options.maxTimeout, {min: 0, allowInfinity: true});
|
|
241
|
+
validateNumberOption('maxRetryTime', options.maxRetryTime, {min: 0, allowInfinity: true});
|
|
242
|
+
|
|
243
|
+
// Treat non-positive factor as 1 to avoid zero backoff or negative behavior
|
|
244
|
+
if (!(options.factor > 0)) {
|
|
245
|
+
options.factor = 1;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
options.signal?.throwIfAborted();
|
|
249
|
+
|
|
250
|
+
let attemptNumber = 0;
|
|
251
|
+
let retriesConsumed = 0;
|
|
252
|
+
const startTime = performance.now();
|
|
253
|
+
|
|
254
|
+
while (Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true) {
|
|
255
|
+
attemptNumber++;
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
options.signal?.throwIfAborted();
|
|
259
|
+
|
|
260
|
+
const result = await input(attemptNumber);
|
|
261
|
+
|
|
262
|
+
options.signal?.throwIfAborted();
|
|
263
|
+
|
|
264
|
+
return result;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (await onAttemptFailure({
|
|
267
|
+
error,
|
|
268
|
+
attemptNumber,
|
|
269
|
+
retriesConsumed,
|
|
270
|
+
startTime,
|
|
271
|
+
options,
|
|
272
|
+
})) {
|
|
273
|
+
retriesConsumed++;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Should not reach here, but in case it does, throw an error
|
|
279
|
+
throw new Error('Retry attempts exhausted without throwing an error.');
|
|
280
|
+
}
|
|
281
|
+
|
|
26
282
|
/**
|
|
27
283
|
* Retry utility with p-retry package (Phase 2B).
|
|
28
284
|
*
|
|
@@ -4508,166 +4764,3043 @@ class SessionWrapper {
|
|
|
4508
4764
|
}
|
|
4509
4765
|
}
|
|
4510
4766
|
|
|
4511
|
-
/**
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
try {
|
|
4524
|
-
return schema.parse(params);
|
|
4525
|
-
}
|
|
4526
|
-
catch (error) {
|
|
4527
|
-
if (error instanceof z.ZodError) {
|
|
4528
|
-
const message = `Validation failed: ${error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ')}`;
|
|
4529
|
-
if (config?.validationStrict) {
|
|
4530
|
-
throw new ValidationError(message);
|
|
4531
|
-
}
|
|
4532
|
-
else {
|
|
4533
|
-
console.warn(`[Validation Warning] ${message}`);
|
|
4534
|
-
return params;
|
|
4535
|
-
}
|
|
4767
|
+
/** A special constant with type `never` */
|
|
4768
|
+
function $constructor(name, initializer, params) {
|
|
4769
|
+
function init(inst, def) {
|
|
4770
|
+
if (!inst._zod) {
|
|
4771
|
+
Object.defineProperty(inst, "_zod", {
|
|
4772
|
+
value: {
|
|
4773
|
+
def,
|
|
4774
|
+
constr: _,
|
|
4775
|
+
traits: new Set(),
|
|
4776
|
+
},
|
|
4777
|
+
enumerable: false,
|
|
4778
|
+
});
|
|
4536
4779
|
}
|
|
4537
|
-
|
|
4538
|
-
|
|
4780
|
+
if (inst._zod.traits.has(name)) {
|
|
4781
|
+
return;
|
|
4782
|
+
}
|
|
4783
|
+
inst._zod.traits.add(name);
|
|
4784
|
+
initializer(inst, def);
|
|
4785
|
+
// support prototype modifications
|
|
4786
|
+
const proto = _.prototype;
|
|
4787
|
+
const keys = Object.keys(proto);
|
|
4788
|
+
for (let i = 0; i < keys.length; i++) {
|
|
4789
|
+
const k = keys[i];
|
|
4790
|
+
if (!(k in inst)) {
|
|
4791
|
+
inst[k] = proto[k].bind(inst);
|
|
4792
|
+
}
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4795
|
+
// doesn't work if Parent has a constructor with arguments
|
|
4796
|
+
const Parent = params?.Parent ?? Object;
|
|
4797
|
+
class Definition extends Parent {
|
|
4798
|
+
}
|
|
4799
|
+
Object.defineProperty(Definition, "name", { value: name });
|
|
4800
|
+
function _(def) {
|
|
4801
|
+
var _a;
|
|
4802
|
+
const inst = params?.Parent ? new Definition() : this;
|
|
4803
|
+
init(inst, def);
|
|
4804
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
4805
|
+
for (const fn of inst._zod.deferred) {
|
|
4806
|
+
fn();
|
|
4807
|
+
}
|
|
4808
|
+
return inst;
|
|
4809
|
+
}
|
|
4810
|
+
Object.defineProperty(_, "init", { value: init });
|
|
4811
|
+
Object.defineProperty(_, Symbol.hasInstance, {
|
|
4812
|
+
value: (inst) => {
|
|
4813
|
+
if (params?.Parent && inst instanceof params.Parent)
|
|
4814
|
+
return true;
|
|
4815
|
+
return inst?._zod?.traits?.has(name);
|
|
4816
|
+
},
|
|
4817
|
+
});
|
|
4818
|
+
Object.defineProperty(_, "name", { value: name });
|
|
4819
|
+
return _;
|
|
4539
4820
|
}
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
function numberSchema(min, max, defaultVal) {
|
|
4544
|
-
let schema = z.number();
|
|
4545
|
-
if (min !== undefined)
|
|
4546
|
-
schema = schema.min(min);
|
|
4547
|
-
if (max !== undefined)
|
|
4548
|
-
schema = schema.max(max);
|
|
4549
|
-
if (defaultVal !== undefined) {
|
|
4550
|
-
// Use .default() which automatically makes the field optional
|
|
4551
|
-
// This avoids the ZodUnion issue with .optional().default()
|
|
4552
|
-
schema = schema.default(defaultVal);
|
|
4821
|
+
class $ZodAsyncError extends Error {
|
|
4822
|
+
constructor() {
|
|
4823
|
+
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
4553
4824
|
}
|
|
4554
|
-
return schema;
|
|
4555
4825
|
}
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
let schema = z.string();
|
|
4561
|
-
if (min !== undefined)
|
|
4562
|
-
schema = schema.min(min);
|
|
4563
|
-
if (max !== undefined)
|
|
4564
|
-
schema = schema.max(max);
|
|
4565
|
-
if (defaultVal !== undefined) {
|
|
4566
|
-
// Use .default() which automatically makes the field optional
|
|
4567
|
-
// This avoids the ZodUnion issue with .optional().default()
|
|
4568
|
-
schema = schema.default(defaultVal);
|
|
4826
|
+
class $ZodEncodeError extends Error {
|
|
4827
|
+
constructor(name) {
|
|
4828
|
+
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
4829
|
+
this.name = "ZodEncodeError";
|
|
4569
4830
|
}
|
|
4570
|
-
|
|
4831
|
+
}
|
|
4832
|
+
const globalConfig = {};
|
|
4833
|
+
function config(newConfig) {
|
|
4834
|
+
return globalConfig;
|
|
4571
4835
|
}
|
|
4572
4836
|
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4837
|
+
// functions
|
|
4838
|
+
function jsonStringifyReplacer(_, value) {
|
|
4839
|
+
if (typeof value === "bigint")
|
|
4840
|
+
return value.toString();
|
|
4841
|
+
return value;
|
|
4842
|
+
}
|
|
4843
|
+
function nullish(input) {
|
|
4844
|
+
return input === null || input === undefined;
|
|
4845
|
+
}
|
|
4846
|
+
function cleanRegex(source) {
|
|
4847
|
+
const start = source.startsWith("^") ? 1 : 0;
|
|
4848
|
+
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
4849
|
+
return source.slice(start, end);
|
|
4850
|
+
}
|
|
4851
|
+
function floatSafeRemainder(val, step) {
|
|
4852
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
4853
|
+
const stepString = step.toString();
|
|
4854
|
+
let stepDecCount = (stepString.split(".")[1] || "").length;
|
|
4855
|
+
if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
|
|
4856
|
+
const match = stepString.match(/\d?e-(\d?)/);
|
|
4857
|
+
if (match?.[1]) {
|
|
4858
|
+
stepDecCount = Number.parseInt(match[1]);
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
4862
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
4863
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
4864
|
+
return (valInt % stepInt) / 10 ** decCount;
|
|
4865
|
+
}
|
|
4866
|
+
const EVALUATING = Symbol("evaluating");
|
|
4867
|
+
function defineLazy(object, key, getter) {
|
|
4868
|
+
let value = undefined;
|
|
4869
|
+
Object.defineProperty(object, key, {
|
|
4870
|
+
get() {
|
|
4871
|
+
if (value === EVALUATING) {
|
|
4872
|
+
// Circular reference detected, return undefined to break the cycle
|
|
4873
|
+
return undefined;
|
|
4874
|
+
}
|
|
4875
|
+
if (value === undefined) {
|
|
4876
|
+
value = EVALUATING;
|
|
4877
|
+
value = getter();
|
|
4878
|
+
}
|
|
4879
|
+
return value;
|
|
4880
|
+
},
|
|
4881
|
+
set(v) {
|
|
4882
|
+
Object.defineProperty(object, key, {
|
|
4883
|
+
value: v,
|
|
4884
|
+
// configurable: true,
|
|
4885
|
+
});
|
|
4886
|
+
// object[key] = v;
|
|
4887
|
+
},
|
|
4888
|
+
configurable: true,
|
|
4889
|
+
});
|
|
4890
|
+
}
|
|
4891
|
+
function mergeDefs(...defs) {
|
|
4892
|
+
const mergedDescriptors = {};
|
|
4893
|
+
for (const def of defs) {
|
|
4894
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
4895
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
4587
4896
|
}
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4897
|
+
return Object.defineProperties({}, mergedDescriptors);
|
|
4898
|
+
}
|
|
4899
|
+
function slugify(input) {
|
|
4900
|
+
return input
|
|
4901
|
+
.toLowerCase()
|
|
4902
|
+
.trim()
|
|
4903
|
+
.replace(/[^\w\s-]/g, "")
|
|
4904
|
+
.replace(/[\s_-]+/g, "-")
|
|
4905
|
+
.replace(/^-+|-+$/g, "");
|
|
4906
|
+
}
|
|
4907
|
+
const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
|
|
4908
|
+
function isObject(data) {
|
|
4909
|
+
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
4910
|
+
}
|
|
4911
|
+
function isPlainObject(o) {
|
|
4912
|
+
if (isObject(o) === false)
|
|
4913
|
+
return false;
|
|
4914
|
+
// modified constructor
|
|
4915
|
+
const ctor = o.constructor;
|
|
4916
|
+
if (ctor === undefined)
|
|
4917
|
+
return true;
|
|
4918
|
+
if (typeof ctor !== "function")
|
|
4919
|
+
return true;
|
|
4920
|
+
// modified prototype
|
|
4921
|
+
const prot = ctor.prototype;
|
|
4922
|
+
if (isObject(prot) === false)
|
|
4923
|
+
return false;
|
|
4924
|
+
// ctor doesn't have static `isPrototypeOf`
|
|
4925
|
+
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
|
|
4926
|
+
return false;
|
|
4927
|
+
}
|
|
4928
|
+
return true;
|
|
4929
|
+
}
|
|
4930
|
+
function shallowClone(o) {
|
|
4931
|
+
if (isPlainObject(o))
|
|
4932
|
+
return { ...o };
|
|
4933
|
+
if (Array.isArray(o))
|
|
4934
|
+
return [...o];
|
|
4935
|
+
return o;
|
|
4936
|
+
}
|
|
4937
|
+
function escapeRegex(str) {
|
|
4938
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4939
|
+
}
|
|
4940
|
+
// zod-specific utils
|
|
4941
|
+
function clone(inst, def, params) {
|
|
4942
|
+
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
4943
|
+
if (!def || params?.parent)
|
|
4944
|
+
cl._zod.parent = inst;
|
|
4945
|
+
return cl;
|
|
4946
|
+
}
|
|
4947
|
+
function normalizeParams(_params) {
|
|
4948
|
+
const params = _params;
|
|
4949
|
+
if (!params)
|
|
4950
|
+
return {};
|
|
4951
|
+
if (typeof params === "string")
|
|
4952
|
+
return { error: () => params };
|
|
4953
|
+
if (params?.message !== undefined) {
|
|
4954
|
+
if (params?.error !== undefined)
|
|
4955
|
+
throw new Error("Cannot specify both `message` and `error` params");
|
|
4956
|
+
params.error = params.message;
|
|
4957
|
+
}
|
|
4958
|
+
delete params.message;
|
|
4959
|
+
if (typeof params.error === "string")
|
|
4960
|
+
return { ...params, error: () => params.error };
|
|
4961
|
+
return params;
|
|
4962
|
+
}
|
|
4963
|
+
const NUMBER_FORMAT_RANGES = {
|
|
4964
|
+
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
4965
|
+
int32: [-2147483648, 2147483647],
|
|
4966
|
+
uint32: [0, 4294967295],
|
|
4967
|
+
float32: [-34028234663852886e22, 3.4028234663852886e38],
|
|
4968
|
+
float64: [-Number.MAX_VALUE, Number.MAX_VALUE],
|
|
4969
|
+
};
|
|
4970
|
+
// invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
|
|
4971
|
+
function aborted(x, startIndex = 0) {
|
|
4972
|
+
if (x.aborted === true)
|
|
4973
|
+
return true;
|
|
4974
|
+
for (let i = startIndex; i < x.issues.length; i++) {
|
|
4975
|
+
if (x.issues[i]?.continue !== true) {
|
|
4976
|
+
return true;
|
|
4603
4977
|
}
|
|
4604
|
-
return url.toString();
|
|
4605
|
-
}
|
|
4606
|
-
catch (error) {
|
|
4607
|
-
// If URL parsing fails, return original URL
|
|
4608
|
-
return baseUrl;
|
|
4609
4978
|
}
|
|
4979
|
+
return false;
|
|
4610
4980
|
}
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4981
|
+
function prefixIssues(path, issues) {
|
|
4982
|
+
return issues.map((iss) => {
|
|
4983
|
+
var _a;
|
|
4984
|
+
(_a = iss).path ?? (_a.path = []);
|
|
4985
|
+
iss.path.unshift(path);
|
|
4986
|
+
return iss;
|
|
4987
|
+
});
|
|
4988
|
+
}
|
|
4989
|
+
function unwrapMessage(message) {
|
|
4990
|
+
return typeof message === "string" ? message : message?.message;
|
|
4991
|
+
}
|
|
4992
|
+
function finalizeIssue(iss, ctx, config) {
|
|
4993
|
+
const full = { ...iss, path: iss.path ?? [] };
|
|
4994
|
+
// for backwards compatibility
|
|
4995
|
+
if (!iss.message) {
|
|
4996
|
+
const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
|
|
4997
|
+
unwrapMessage(ctx?.error?.(iss)) ??
|
|
4998
|
+
unwrapMessage(config.customError?.(iss)) ??
|
|
4999
|
+
unwrapMessage(config.localeError?.(iss)) ??
|
|
5000
|
+
"Invalid input";
|
|
5001
|
+
full.message = message;
|
|
5002
|
+
}
|
|
5003
|
+
// delete (full as any).def;
|
|
5004
|
+
delete full.inst;
|
|
5005
|
+
delete full.continue;
|
|
5006
|
+
if (!ctx?.reportInput) {
|
|
5007
|
+
delete full.input;
|
|
5008
|
+
}
|
|
5009
|
+
return full;
|
|
5010
|
+
}
|
|
5011
|
+
function getLengthableOrigin(input) {
|
|
5012
|
+
if (Array.isArray(input))
|
|
5013
|
+
return "array";
|
|
5014
|
+
if (typeof input === "string")
|
|
5015
|
+
return "string";
|
|
5016
|
+
return "unknown";
|
|
5017
|
+
}
|
|
5018
|
+
function issue(...args) {
|
|
5019
|
+
const [iss, input, inst] = args;
|
|
5020
|
+
if (typeof iss === "string") {
|
|
5021
|
+
return {
|
|
5022
|
+
message: iss,
|
|
5023
|
+
code: "custom",
|
|
5024
|
+
input,
|
|
5025
|
+
inst,
|
|
5026
|
+
};
|
|
4630
5027
|
}
|
|
5028
|
+
return { ...iss };
|
|
4631
5029
|
}
|
|
4632
5030
|
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
5031
|
+
const initializer$1 = (inst, def) => {
|
|
5032
|
+
inst.name = "$ZodError";
|
|
5033
|
+
Object.defineProperty(inst, "_zod", {
|
|
5034
|
+
value: inst._zod,
|
|
5035
|
+
enumerable: false,
|
|
5036
|
+
});
|
|
5037
|
+
Object.defineProperty(inst, "issues", {
|
|
5038
|
+
value: def,
|
|
5039
|
+
enumerable: false,
|
|
5040
|
+
});
|
|
5041
|
+
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
5042
|
+
Object.defineProperty(inst, "toString", {
|
|
5043
|
+
value: () => inst.message,
|
|
5044
|
+
enumerable: false,
|
|
5045
|
+
});
|
|
5046
|
+
};
|
|
5047
|
+
const $ZodError = $constructor("$ZodError", initializer$1);
|
|
5048
|
+
const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
|
|
5049
|
+
function flattenError(error, mapper = (issue) => issue.message) {
|
|
5050
|
+
const fieldErrors = {};
|
|
5051
|
+
const formErrors = [];
|
|
5052
|
+
for (const sub of error.issues) {
|
|
5053
|
+
if (sub.path.length > 0) {
|
|
5054
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
5055
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
4645
5056
|
}
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
off(event, callback) {
|
|
4649
|
-
if (this.events.has(event)) {
|
|
4650
|
-
this.events.get(event).delete(callback);
|
|
5057
|
+
else {
|
|
5058
|
+
formErrors.push(mapper(sub));
|
|
4651
5059
|
}
|
|
4652
5060
|
}
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
5061
|
+
return { formErrors, fieldErrors };
|
|
5062
|
+
}
|
|
5063
|
+
function formatError(error, mapper = (issue) => issue.message) {
|
|
5064
|
+
const fieldErrors = { _errors: [] };
|
|
5065
|
+
const processError = (error) => {
|
|
5066
|
+
for (const issue of error.issues) {
|
|
5067
|
+
if (issue.code === "invalid_union" && issue.errors.length) {
|
|
5068
|
+
issue.errors.map((issues) => processError({ issues }));
|
|
5069
|
+
}
|
|
5070
|
+
else if (issue.code === "invalid_key") {
|
|
5071
|
+
processError({ issues: issue.issues });
|
|
5072
|
+
}
|
|
5073
|
+
else if (issue.code === "invalid_element") {
|
|
5074
|
+
processError({ issues: issue.issues });
|
|
5075
|
+
}
|
|
5076
|
+
else if (issue.path.length === 0) {
|
|
5077
|
+
fieldErrors._errors.push(mapper(issue));
|
|
5078
|
+
}
|
|
5079
|
+
else {
|
|
5080
|
+
let curr = fieldErrors;
|
|
5081
|
+
let i = 0;
|
|
5082
|
+
while (i < issue.path.length) {
|
|
5083
|
+
const el = issue.path[i];
|
|
5084
|
+
const terminal = i === issue.path.length - 1;
|
|
5085
|
+
if (!terminal) {
|
|
5086
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
5087
|
+
}
|
|
5088
|
+
else {
|
|
5089
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
5090
|
+
curr[el]._errors.push(mapper(issue));
|
|
5091
|
+
}
|
|
5092
|
+
curr = curr[el];
|
|
5093
|
+
i++;
|
|
4669
5094
|
}
|
|
4670
|
-
}
|
|
5095
|
+
}
|
|
5096
|
+
}
|
|
5097
|
+
};
|
|
5098
|
+
processError(error);
|
|
5099
|
+
return fieldErrors;
|
|
5100
|
+
}
|
|
5101
|
+
|
|
5102
|
+
const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
5103
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
5104
|
+
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
5105
|
+
if (result instanceof Promise) {
|
|
5106
|
+
throw new $ZodAsyncError();
|
|
5107
|
+
}
|
|
5108
|
+
if (result.issues.length) {
|
|
5109
|
+
const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
5110
|
+
captureStackTrace(e, _params?.callee);
|
|
5111
|
+
throw e;
|
|
5112
|
+
}
|
|
5113
|
+
return result.value;
|
|
5114
|
+
};
|
|
5115
|
+
const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
5116
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
5117
|
+
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
5118
|
+
if (result instanceof Promise)
|
|
5119
|
+
result = await result;
|
|
5120
|
+
if (result.issues.length) {
|
|
5121
|
+
const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
5122
|
+
captureStackTrace(e, params?.callee);
|
|
5123
|
+
throw e;
|
|
5124
|
+
}
|
|
5125
|
+
return result.value;
|
|
5126
|
+
};
|
|
5127
|
+
const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
5128
|
+
const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
|
|
5129
|
+
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
5130
|
+
if (result instanceof Promise) {
|
|
5131
|
+
throw new $ZodAsyncError();
|
|
5132
|
+
}
|
|
5133
|
+
return result.issues.length
|
|
5134
|
+
? {
|
|
5135
|
+
success: false,
|
|
5136
|
+
error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
|
|
5137
|
+
}
|
|
5138
|
+
: { success: true, data: result.value };
|
|
5139
|
+
};
|
|
5140
|
+
const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
|
|
5141
|
+
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
5142
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
5143
|
+
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
5144
|
+
if (result instanceof Promise)
|
|
5145
|
+
result = await result;
|
|
5146
|
+
return result.issues.length
|
|
5147
|
+
? {
|
|
5148
|
+
success: false,
|
|
5149
|
+
error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
|
|
5150
|
+
}
|
|
5151
|
+
: { success: true, data: result.value };
|
|
5152
|
+
};
|
|
5153
|
+
const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
|
|
5154
|
+
const _encode = (_Err) => (schema, value, _ctx) => {
|
|
5155
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
5156
|
+
return _parse(_Err)(schema, value, ctx);
|
|
5157
|
+
};
|
|
5158
|
+
const _decode = (_Err) => (schema, value, _ctx) => {
|
|
5159
|
+
return _parse(_Err)(schema, value, _ctx);
|
|
5160
|
+
};
|
|
5161
|
+
const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
5162
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
5163
|
+
return _parseAsync(_Err)(schema, value, ctx);
|
|
5164
|
+
};
|
|
5165
|
+
const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
5166
|
+
return _parseAsync(_Err)(schema, value, _ctx);
|
|
5167
|
+
};
|
|
5168
|
+
const _safeEncode = (_Err) => (schema, value, _ctx) => {
|
|
5169
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
5170
|
+
return _safeParse(_Err)(schema, value, ctx);
|
|
5171
|
+
};
|
|
5172
|
+
const _safeDecode = (_Err) => (schema, value, _ctx) => {
|
|
5173
|
+
return _safeParse(_Err)(schema, value, _ctx);
|
|
5174
|
+
};
|
|
5175
|
+
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
5176
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
5177
|
+
return _safeParseAsync(_Err)(schema, value, ctx);
|
|
5178
|
+
};
|
|
5179
|
+
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
5180
|
+
return _safeParseAsync(_Err)(schema, value, _ctx);
|
|
5181
|
+
};
|
|
5182
|
+
|
|
5183
|
+
const cuid = /^[cC][^\s-]{8,}$/;
|
|
5184
|
+
const cuid2 = /^[0-9a-z]+$/;
|
|
5185
|
+
const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
|
5186
|
+
const xid = /^[0-9a-vA-V]{20}$/;
|
|
5187
|
+
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
5188
|
+
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
5189
|
+
/** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
|
|
5190
|
+
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)?)?)$/;
|
|
5191
|
+
/** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
|
|
5192
|
+
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})$/;
|
|
5193
|
+
/** Returns a regex for validating an RFC 9562/4122 UUID.
|
|
5194
|
+
*
|
|
5195
|
+
* @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
|
|
5196
|
+
const uuid = (version) => {
|
|
5197
|
+
if (!version)
|
|
5198
|
+
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)$/;
|
|
5199
|
+
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})$`);
|
|
5200
|
+
};
|
|
5201
|
+
/** Practical email validation */
|
|
5202
|
+
const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
5203
|
+
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
5204
|
+
const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
5205
|
+
function emoji() {
|
|
5206
|
+
return new RegExp(_emoji$1, "u");
|
|
5207
|
+
}
|
|
5208
|
+
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])$/;
|
|
5209
|
+
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}|:))$/;
|
|
5210
|
+
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])$/;
|
|
5211
|
+
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])$/;
|
|
5212
|
+
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
5213
|
+
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
5214
|
+
const base64url = /^[A-Za-z0-9_-]*$/;
|
|
5215
|
+
// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
|
|
5216
|
+
const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
|
|
5217
|
+
// 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])))`;
|
|
5218
|
+
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])))`;
|
|
5219
|
+
const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
|
|
5220
|
+
function timeSource(args) {
|
|
5221
|
+
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
|
|
5222
|
+
const regex = typeof args.precision === "number"
|
|
5223
|
+
? args.precision === -1
|
|
5224
|
+
? `${hhmm}`
|
|
5225
|
+
: args.precision === 0
|
|
5226
|
+
? `${hhmm}:[0-5]\\d`
|
|
5227
|
+
: `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
|
|
5228
|
+
: `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
|
5229
|
+
return regex;
|
|
5230
|
+
}
|
|
5231
|
+
function time$1(args) {
|
|
5232
|
+
return new RegExp(`^${timeSource(args)}$`);
|
|
5233
|
+
}
|
|
5234
|
+
// Adapted from https://stackoverflow.com/a/3143231
|
|
5235
|
+
function datetime$1(args) {
|
|
5236
|
+
const time = timeSource({ precision: args.precision });
|
|
5237
|
+
const opts = ["Z"];
|
|
5238
|
+
if (args.local)
|
|
5239
|
+
opts.push("");
|
|
5240
|
+
// if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
|
|
5241
|
+
if (args.offset)
|
|
5242
|
+
opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
|
|
5243
|
+
const timeRegex = `${time}(?:${opts.join("|")})`;
|
|
5244
|
+
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
5245
|
+
}
|
|
5246
|
+
const string$1 = (params) => {
|
|
5247
|
+
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
5248
|
+
return new RegExp(`^${regex}$`);
|
|
5249
|
+
};
|
|
5250
|
+
const integer = /^-?\d+$/;
|
|
5251
|
+
const number$1 = /^-?\d+(?:\.\d+)?/;
|
|
5252
|
+
// regex for string with no uppercase letters
|
|
5253
|
+
const lowercase = /^[^A-Z]*$/;
|
|
5254
|
+
// regex for string with no lowercase letters
|
|
5255
|
+
const uppercase = /^[^a-z]*$/;
|
|
5256
|
+
|
|
5257
|
+
// import { $ZodType } from "./schemas.js";
|
|
5258
|
+
const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
|
|
5259
|
+
var _a;
|
|
5260
|
+
inst._zod ?? (inst._zod = {});
|
|
5261
|
+
inst._zod.def = def;
|
|
5262
|
+
(_a = inst._zod).onattach ?? (_a.onattach = []);
|
|
5263
|
+
});
|
|
5264
|
+
const numericOriginMap = {
|
|
5265
|
+
number: "number",
|
|
5266
|
+
bigint: "bigint",
|
|
5267
|
+
object: "date",
|
|
5268
|
+
};
|
|
5269
|
+
const $ZodCheckLessThan = /*@__PURE__*/ $constructor("$ZodCheckLessThan", (inst, def) => {
|
|
5270
|
+
$ZodCheck.init(inst, def);
|
|
5271
|
+
const origin = numericOriginMap[typeof def.value];
|
|
5272
|
+
inst._zod.onattach.push((inst) => {
|
|
5273
|
+
const bag = inst._zod.bag;
|
|
5274
|
+
const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
|
|
5275
|
+
if (def.value < curr) {
|
|
5276
|
+
if (def.inclusive)
|
|
5277
|
+
bag.maximum = def.value;
|
|
5278
|
+
else
|
|
5279
|
+
bag.exclusiveMaximum = def.value;
|
|
5280
|
+
}
|
|
5281
|
+
});
|
|
5282
|
+
inst._zod.check = (payload) => {
|
|
5283
|
+
if (def.inclusive ? payload.value <= def.value : payload.value < def.value) {
|
|
5284
|
+
return;
|
|
5285
|
+
}
|
|
5286
|
+
payload.issues.push({
|
|
5287
|
+
origin,
|
|
5288
|
+
code: "too_big",
|
|
5289
|
+
maximum: def.value,
|
|
5290
|
+
input: payload.value,
|
|
5291
|
+
inclusive: def.inclusive,
|
|
5292
|
+
inst,
|
|
5293
|
+
continue: !def.abort,
|
|
5294
|
+
});
|
|
5295
|
+
};
|
|
5296
|
+
});
|
|
5297
|
+
const $ZodCheckGreaterThan = /*@__PURE__*/ $constructor("$ZodCheckGreaterThan", (inst, def) => {
|
|
5298
|
+
$ZodCheck.init(inst, def);
|
|
5299
|
+
const origin = numericOriginMap[typeof def.value];
|
|
5300
|
+
inst._zod.onattach.push((inst) => {
|
|
5301
|
+
const bag = inst._zod.bag;
|
|
5302
|
+
const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
|
|
5303
|
+
if (def.value > curr) {
|
|
5304
|
+
if (def.inclusive)
|
|
5305
|
+
bag.minimum = def.value;
|
|
5306
|
+
else
|
|
5307
|
+
bag.exclusiveMinimum = def.value;
|
|
5308
|
+
}
|
|
5309
|
+
});
|
|
5310
|
+
inst._zod.check = (payload) => {
|
|
5311
|
+
if (def.inclusive ? payload.value >= def.value : payload.value > def.value) {
|
|
5312
|
+
return;
|
|
5313
|
+
}
|
|
5314
|
+
payload.issues.push({
|
|
5315
|
+
origin,
|
|
5316
|
+
code: "too_small",
|
|
5317
|
+
minimum: def.value,
|
|
5318
|
+
input: payload.value,
|
|
5319
|
+
inclusive: def.inclusive,
|
|
5320
|
+
inst,
|
|
5321
|
+
continue: !def.abort,
|
|
5322
|
+
});
|
|
5323
|
+
};
|
|
5324
|
+
});
|
|
5325
|
+
const $ZodCheckMultipleOf =
|
|
5326
|
+
/*@__PURE__*/ $constructor("$ZodCheckMultipleOf", (inst, def) => {
|
|
5327
|
+
$ZodCheck.init(inst, def);
|
|
5328
|
+
inst._zod.onattach.push((inst) => {
|
|
5329
|
+
var _a;
|
|
5330
|
+
(_a = inst._zod.bag).multipleOf ?? (_a.multipleOf = def.value);
|
|
5331
|
+
});
|
|
5332
|
+
inst._zod.check = (payload) => {
|
|
5333
|
+
if (typeof payload.value !== typeof def.value)
|
|
5334
|
+
throw new Error("Cannot mix number and bigint in multiple_of check.");
|
|
5335
|
+
const isMultiple = typeof payload.value === "bigint"
|
|
5336
|
+
? payload.value % def.value === BigInt(0)
|
|
5337
|
+
: floatSafeRemainder(payload.value, def.value) === 0;
|
|
5338
|
+
if (isMultiple)
|
|
5339
|
+
return;
|
|
5340
|
+
payload.issues.push({
|
|
5341
|
+
origin: typeof payload.value,
|
|
5342
|
+
code: "not_multiple_of",
|
|
5343
|
+
divisor: def.value,
|
|
5344
|
+
input: payload.value,
|
|
5345
|
+
inst,
|
|
5346
|
+
continue: !def.abort,
|
|
5347
|
+
});
|
|
5348
|
+
};
|
|
5349
|
+
});
|
|
5350
|
+
const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat", (inst, def) => {
|
|
5351
|
+
$ZodCheck.init(inst, def); // no format checks
|
|
5352
|
+
def.format = def.format || "float64";
|
|
5353
|
+
const isInt = def.format?.includes("int");
|
|
5354
|
+
const origin = isInt ? "int" : "number";
|
|
5355
|
+
const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
|
|
5356
|
+
inst._zod.onattach.push((inst) => {
|
|
5357
|
+
const bag = inst._zod.bag;
|
|
5358
|
+
bag.format = def.format;
|
|
5359
|
+
bag.minimum = minimum;
|
|
5360
|
+
bag.maximum = maximum;
|
|
5361
|
+
if (isInt)
|
|
5362
|
+
bag.pattern = integer;
|
|
5363
|
+
});
|
|
5364
|
+
inst._zod.check = (payload) => {
|
|
5365
|
+
const input = payload.value;
|
|
5366
|
+
if (isInt) {
|
|
5367
|
+
if (!Number.isInteger(input)) {
|
|
5368
|
+
// invalid_format issue
|
|
5369
|
+
// payload.issues.push({
|
|
5370
|
+
// expected: def.format,
|
|
5371
|
+
// format: def.format,
|
|
5372
|
+
// code: "invalid_format",
|
|
5373
|
+
// input,
|
|
5374
|
+
// inst,
|
|
5375
|
+
// });
|
|
5376
|
+
// invalid_type issue
|
|
5377
|
+
payload.issues.push({
|
|
5378
|
+
expected: origin,
|
|
5379
|
+
format: def.format,
|
|
5380
|
+
code: "invalid_type",
|
|
5381
|
+
continue: false,
|
|
5382
|
+
input,
|
|
5383
|
+
inst,
|
|
5384
|
+
});
|
|
5385
|
+
return;
|
|
5386
|
+
// not_multiple_of issue
|
|
5387
|
+
// payload.issues.push({
|
|
5388
|
+
// code: "not_multiple_of",
|
|
5389
|
+
// origin: "number",
|
|
5390
|
+
// input,
|
|
5391
|
+
// inst,
|
|
5392
|
+
// divisor: 1,
|
|
5393
|
+
// });
|
|
5394
|
+
}
|
|
5395
|
+
if (!Number.isSafeInteger(input)) {
|
|
5396
|
+
if (input > 0) {
|
|
5397
|
+
// too_big
|
|
5398
|
+
payload.issues.push({
|
|
5399
|
+
input,
|
|
5400
|
+
code: "too_big",
|
|
5401
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
5402
|
+
note: "Integers must be within the safe integer range.",
|
|
5403
|
+
inst,
|
|
5404
|
+
origin,
|
|
5405
|
+
continue: !def.abort,
|
|
5406
|
+
});
|
|
5407
|
+
}
|
|
5408
|
+
else {
|
|
5409
|
+
// too_small
|
|
5410
|
+
payload.issues.push({
|
|
5411
|
+
input,
|
|
5412
|
+
code: "too_small",
|
|
5413
|
+
minimum: Number.MIN_SAFE_INTEGER,
|
|
5414
|
+
note: "Integers must be within the safe integer range.",
|
|
5415
|
+
inst,
|
|
5416
|
+
origin,
|
|
5417
|
+
continue: !def.abort,
|
|
5418
|
+
});
|
|
5419
|
+
}
|
|
5420
|
+
return;
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
if (input < minimum) {
|
|
5424
|
+
payload.issues.push({
|
|
5425
|
+
origin: "number",
|
|
5426
|
+
input,
|
|
5427
|
+
code: "too_small",
|
|
5428
|
+
minimum,
|
|
5429
|
+
inclusive: true,
|
|
5430
|
+
inst,
|
|
5431
|
+
continue: !def.abort,
|
|
5432
|
+
});
|
|
5433
|
+
}
|
|
5434
|
+
if (input > maximum) {
|
|
5435
|
+
payload.issues.push({
|
|
5436
|
+
origin: "number",
|
|
5437
|
+
input,
|
|
5438
|
+
code: "too_big",
|
|
5439
|
+
maximum,
|
|
5440
|
+
inst,
|
|
5441
|
+
});
|
|
5442
|
+
}
|
|
5443
|
+
};
|
|
5444
|
+
});
|
|
5445
|
+
const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
|
|
5446
|
+
var _a;
|
|
5447
|
+
$ZodCheck.init(inst, def);
|
|
5448
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
5449
|
+
const val = payload.value;
|
|
5450
|
+
return !nullish(val) && val.length !== undefined;
|
|
5451
|
+
});
|
|
5452
|
+
inst._zod.onattach.push((inst) => {
|
|
5453
|
+
const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
|
|
5454
|
+
if (def.maximum < curr)
|
|
5455
|
+
inst._zod.bag.maximum = def.maximum;
|
|
5456
|
+
});
|
|
5457
|
+
inst._zod.check = (payload) => {
|
|
5458
|
+
const input = payload.value;
|
|
5459
|
+
const length = input.length;
|
|
5460
|
+
if (length <= def.maximum)
|
|
5461
|
+
return;
|
|
5462
|
+
const origin = getLengthableOrigin(input);
|
|
5463
|
+
payload.issues.push({
|
|
5464
|
+
origin,
|
|
5465
|
+
code: "too_big",
|
|
5466
|
+
maximum: def.maximum,
|
|
5467
|
+
inclusive: true,
|
|
5468
|
+
input,
|
|
5469
|
+
inst,
|
|
5470
|
+
continue: !def.abort,
|
|
5471
|
+
});
|
|
5472
|
+
};
|
|
5473
|
+
});
|
|
5474
|
+
const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
|
|
5475
|
+
var _a;
|
|
5476
|
+
$ZodCheck.init(inst, def);
|
|
5477
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
5478
|
+
const val = payload.value;
|
|
5479
|
+
return !nullish(val) && val.length !== undefined;
|
|
5480
|
+
});
|
|
5481
|
+
inst._zod.onattach.push((inst) => {
|
|
5482
|
+
const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
|
|
5483
|
+
if (def.minimum > curr)
|
|
5484
|
+
inst._zod.bag.minimum = def.minimum;
|
|
5485
|
+
});
|
|
5486
|
+
inst._zod.check = (payload) => {
|
|
5487
|
+
const input = payload.value;
|
|
5488
|
+
const length = input.length;
|
|
5489
|
+
if (length >= def.minimum)
|
|
5490
|
+
return;
|
|
5491
|
+
const origin = getLengthableOrigin(input);
|
|
5492
|
+
payload.issues.push({
|
|
5493
|
+
origin,
|
|
5494
|
+
code: "too_small",
|
|
5495
|
+
minimum: def.minimum,
|
|
5496
|
+
inclusive: true,
|
|
5497
|
+
input,
|
|
5498
|
+
inst,
|
|
5499
|
+
continue: !def.abort,
|
|
5500
|
+
});
|
|
5501
|
+
};
|
|
5502
|
+
});
|
|
5503
|
+
const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
|
|
5504
|
+
var _a;
|
|
5505
|
+
$ZodCheck.init(inst, def);
|
|
5506
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
5507
|
+
const val = payload.value;
|
|
5508
|
+
return !nullish(val) && val.length !== undefined;
|
|
5509
|
+
});
|
|
5510
|
+
inst._zod.onattach.push((inst) => {
|
|
5511
|
+
const bag = inst._zod.bag;
|
|
5512
|
+
bag.minimum = def.length;
|
|
5513
|
+
bag.maximum = def.length;
|
|
5514
|
+
bag.length = def.length;
|
|
5515
|
+
});
|
|
5516
|
+
inst._zod.check = (payload) => {
|
|
5517
|
+
const input = payload.value;
|
|
5518
|
+
const length = input.length;
|
|
5519
|
+
if (length === def.length)
|
|
5520
|
+
return;
|
|
5521
|
+
const origin = getLengthableOrigin(input);
|
|
5522
|
+
const tooBig = length > def.length;
|
|
5523
|
+
payload.issues.push({
|
|
5524
|
+
origin,
|
|
5525
|
+
...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
|
|
5526
|
+
inclusive: true,
|
|
5527
|
+
exact: true,
|
|
5528
|
+
input: payload.value,
|
|
5529
|
+
inst,
|
|
5530
|
+
continue: !def.abort,
|
|
5531
|
+
});
|
|
5532
|
+
};
|
|
5533
|
+
});
|
|
5534
|
+
const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
|
|
5535
|
+
var _a, _b;
|
|
5536
|
+
$ZodCheck.init(inst, def);
|
|
5537
|
+
inst._zod.onattach.push((inst) => {
|
|
5538
|
+
const bag = inst._zod.bag;
|
|
5539
|
+
bag.format = def.format;
|
|
5540
|
+
if (def.pattern) {
|
|
5541
|
+
bag.patterns ?? (bag.patterns = new Set());
|
|
5542
|
+
bag.patterns.add(def.pattern);
|
|
5543
|
+
}
|
|
5544
|
+
});
|
|
5545
|
+
if (def.pattern)
|
|
5546
|
+
(_a = inst._zod).check ?? (_a.check = (payload) => {
|
|
5547
|
+
def.pattern.lastIndex = 0;
|
|
5548
|
+
if (def.pattern.test(payload.value))
|
|
5549
|
+
return;
|
|
5550
|
+
payload.issues.push({
|
|
5551
|
+
origin: "string",
|
|
5552
|
+
code: "invalid_format",
|
|
5553
|
+
format: def.format,
|
|
5554
|
+
input: payload.value,
|
|
5555
|
+
...(def.pattern ? { pattern: def.pattern.toString() } : {}),
|
|
5556
|
+
inst,
|
|
5557
|
+
continue: !def.abort,
|
|
5558
|
+
});
|
|
5559
|
+
});
|
|
5560
|
+
else
|
|
5561
|
+
(_b = inst._zod).check ?? (_b.check = () => { });
|
|
5562
|
+
});
|
|
5563
|
+
const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
|
|
5564
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
5565
|
+
inst._zod.check = (payload) => {
|
|
5566
|
+
def.pattern.lastIndex = 0;
|
|
5567
|
+
if (def.pattern.test(payload.value))
|
|
5568
|
+
return;
|
|
5569
|
+
payload.issues.push({
|
|
5570
|
+
origin: "string",
|
|
5571
|
+
code: "invalid_format",
|
|
5572
|
+
format: "regex",
|
|
5573
|
+
input: payload.value,
|
|
5574
|
+
pattern: def.pattern.toString(),
|
|
5575
|
+
inst,
|
|
5576
|
+
continue: !def.abort,
|
|
5577
|
+
});
|
|
5578
|
+
};
|
|
5579
|
+
});
|
|
5580
|
+
const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
|
|
5581
|
+
def.pattern ?? (def.pattern = lowercase);
|
|
5582
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
5583
|
+
});
|
|
5584
|
+
const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
|
|
5585
|
+
def.pattern ?? (def.pattern = uppercase);
|
|
5586
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
5587
|
+
});
|
|
5588
|
+
const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
|
|
5589
|
+
$ZodCheck.init(inst, def);
|
|
5590
|
+
const escapedRegex = escapeRegex(def.includes);
|
|
5591
|
+
const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
|
|
5592
|
+
def.pattern = pattern;
|
|
5593
|
+
inst._zod.onattach.push((inst) => {
|
|
5594
|
+
const bag = inst._zod.bag;
|
|
5595
|
+
bag.patterns ?? (bag.patterns = new Set());
|
|
5596
|
+
bag.patterns.add(pattern);
|
|
5597
|
+
});
|
|
5598
|
+
inst._zod.check = (payload) => {
|
|
5599
|
+
if (payload.value.includes(def.includes, def.position))
|
|
5600
|
+
return;
|
|
5601
|
+
payload.issues.push({
|
|
5602
|
+
origin: "string",
|
|
5603
|
+
code: "invalid_format",
|
|
5604
|
+
format: "includes",
|
|
5605
|
+
includes: def.includes,
|
|
5606
|
+
input: payload.value,
|
|
5607
|
+
inst,
|
|
5608
|
+
continue: !def.abort,
|
|
5609
|
+
});
|
|
5610
|
+
};
|
|
5611
|
+
});
|
|
5612
|
+
const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
|
|
5613
|
+
$ZodCheck.init(inst, def);
|
|
5614
|
+
const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
|
|
5615
|
+
def.pattern ?? (def.pattern = pattern);
|
|
5616
|
+
inst._zod.onattach.push((inst) => {
|
|
5617
|
+
const bag = inst._zod.bag;
|
|
5618
|
+
bag.patterns ?? (bag.patterns = new Set());
|
|
5619
|
+
bag.patterns.add(pattern);
|
|
5620
|
+
});
|
|
5621
|
+
inst._zod.check = (payload) => {
|
|
5622
|
+
if (payload.value.startsWith(def.prefix))
|
|
5623
|
+
return;
|
|
5624
|
+
payload.issues.push({
|
|
5625
|
+
origin: "string",
|
|
5626
|
+
code: "invalid_format",
|
|
5627
|
+
format: "starts_with",
|
|
5628
|
+
prefix: def.prefix,
|
|
5629
|
+
input: payload.value,
|
|
5630
|
+
inst,
|
|
5631
|
+
continue: !def.abort,
|
|
5632
|
+
});
|
|
5633
|
+
};
|
|
5634
|
+
});
|
|
5635
|
+
const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
|
|
5636
|
+
$ZodCheck.init(inst, def);
|
|
5637
|
+
const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
|
|
5638
|
+
def.pattern ?? (def.pattern = pattern);
|
|
5639
|
+
inst._zod.onattach.push((inst) => {
|
|
5640
|
+
const bag = inst._zod.bag;
|
|
5641
|
+
bag.patterns ?? (bag.patterns = new Set());
|
|
5642
|
+
bag.patterns.add(pattern);
|
|
5643
|
+
});
|
|
5644
|
+
inst._zod.check = (payload) => {
|
|
5645
|
+
if (payload.value.endsWith(def.suffix))
|
|
5646
|
+
return;
|
|
5647
|
+
payload.issues.push({
|
|
5648
|
+
origin: "string",
|
|
5649
|
+
code: "invalid_format",
|
|
5650
|
+
format: "ends_with",
|
|
5651
|
+
suffix: def.suffix,
|
|
5652
|
+
input: payload.value,
|
|
5653
|
+
inst,
|
|
5654
|
+
continue: !def.abort,
|
|
5655
|
+
});
|
|
5656
|
+
};
|
|
5657
|
+
});
|
|
5658
|
+
const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
|
|
5659
|
+
$ZodCheck.init(inst, def);
|
|
5660
|
+
inst._zod.check = (payload) => {
|
|
5661
|
+
payload.value = def.tx(payload.value);
|
|
5662
|
+
};
|
|
5663
|
+
});
|
|
5664
|
+
|
|
5665
|
+
const version = {
|
|
5666
|
+
major: 4,
|
|
5667
|
+
minor: 1,
|
|
5668
|
+
patch: 13,
|
|
5669
|
+
};
|
|
5670
|
+
|
|
5671
|
+
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
5672
|
+
var _a;
|
|
5673
|
+
inst ?? (inst = {});
|
|
5674
|
+
inst._zod.def = def; // set _def property
|
|
5675
|
+
inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
|
|
5676
|
+
inst._zod.version = version;
|
|
5677
|
+
const checks = [...(inst._zod.def.checks ?? [])];
|
|
5678
|
+
// if inst is itself a checks.$ZodCheck, run it as a check
|
|
5679
|
+
if (inst._zod.traits.has("$ZodCheck")) {
|
|
5680
|
+
checks.unshift(inst);
|
|
5681
|
+
}
|
|
5682
|
+
for (const ch of checks) {
|
|
5683
|
+
for (const fn of ch._zod.onattach) {
|
|
5684
|
+
fn(inst);
|
|
5685
|
+
}
|
|
5686
|
+
}
|
|
5687
|
+
if (checks.length === 0) {
|
|
5688
|
+
// deferred initializer
|
|
5689
|
+
// inst._zod.parse is not yet defined
|
|
5690
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
5691
|
+
inst._zod.deferred?.push(() => {
|
|
5692
|
+
inst._zod.run = inst._zod.parse;
|
|
5693
|
+
});
|
|
5694
|
+
}
|
|
5695
|
+
else {
|
|
5696
|
+
const runChecks = (payload, checks, ctx) => {
|
|
5697
|
+
let isAborted = aborted(payload);
|
|
5698
|
+
let asyncResult;
|
|
5699
|
+
for (const ch of checks) {
|
|
5700
|
+
if (ch._zod.def.when) {
|
|
5701
|
+
const shouldRun = ch._zod.def.when(payload);
|
|
5702
|
+
if (!shouldRun)
|
|
5703
|
+
continue;
|
|
5704
|
+
}
|
|
5705
|
+
else if (isAborted) {
|
|
5706
|
+
continue;
|
|
5707
|
+
}
|
|
5708
|
+
const currLen = payload.issues.length;
|
|
5709
|
+
const _ = ch._zod.check(payload);
|
|
5710
|
+
if (_ instanceof Promise && ctx?.async === false) {
|
|
5711
|
+
throw new $ZodAsyncError();
|
|
5712
|
+
}
|
|
5713
|
+
if (asyncResult || _ instanceof Promise) {
|
|
5714
|
+
asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
5715
|
+
await _;
|
|
5716
|
+
const nextLen = payload.issues.length;
|
|
5717
|
+
if (nextLen === currLen)
|
|
5718
|
+
return;
|
|
5719
|
+
if (!isAborted)
|
|
5720
|
+
isAborted = aborted(payload, currLen);
|
|
5721
|
+
});
|
|
5722
|
+
}
|
|
5723
|
+
else {
|
|
5724
|
+
const nextLen = payload.issues.length;
|
|
5725
|
+
if (nextLen === currLen)
|
|
5726
|
+
continue;
|
|
5727
|
+
if (!isAborted)
|
|
5728
|
+
isAborted = aborted(payload, currLen);
|
|
5729
|
+
}
|
|
5730
|
+
}
|
|
5731
|
+
if (asyncResult) {
|
|
5732
|
+
return asyncResult.then(() => {
|
|
5733
|
+
return payload;
|
|
5734
|
+
});
|
|
5735
|
+
}
|
|
5736
|
+
return payload;
|
|
5737
|
+
};
|
|
5738
|
+
// const handleChecksResult = (
|
|
5739
|
+
// checkResult: ParsePayload,
|
|
5740
|
+
// originalResult: ParsePayload,
|
|
5741
|
+
// ctx: ParseContextInternal
|
|
5742
|
+
// ): util.MaybeAsync<ParsePayload> => {
|
|
5743
|
+
// // if the checks mutated the value && there are no issues, re-parse the result
|
|
5744
|
+
// if (checkResult.value !== originalResult.value && !checkResult.issues.length)
|
|
5745
|
+
// return inst._zod.parse(checkResult, ctx);
|
|
5746
|
+
// return originalResult;
|
|
5747
|
+
// };
|
|
5748
|
+
const handleCanaryResult = (canary, payload, ctx) => {
|
|
5749
|
+
// abort if the canary is aborted
|
|
5750
|
+
if (aborted(canary)) {
|
|
5751
|
+
canary.aborted = true;
|
|
5752
|
+
return canary;
|
|
5753
|
+
}
|
|
5754
|
+
// run checks first, then
|
|
5755
|
+
const checkResult = runChecks(payload, checks, ctx);
|
|
5756
|
+
if (checkResult instanceof Promise) {
|
|
5757
|
+
if (ctx.async === false)
|
|
5758
|
+
throw new $ZodAsyncError();
|
|
5759
|
+
return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
|
|
5760
|
+
}
|
|
5761
|
+
return inst._zod.parse(checkResult, ctx);
|
|
5762
|
+
};
|
|
5763
|
+
inst._zod.run = (payload, ctx) => {
|
|
5764
|
+
if (ctx.skipChecks) {
|
|
5765
|
+
return inst._zod.parse(payload, ctx);
|
|
5766
|
+
}
|
|
5767
|
+
if (ctx.direction === "backward") {
|
|
5768
|
+
// run canary
|
|
5769
|
+
// initial pass (no checks)
|
|
5770
|
+
const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
|
|
5771
|
+
if (canary instanceof Promise) {
|
|
5772
|
+
return canary.then((canary) => {
|
|
5773
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
5774
|
+
});
|
|
5775
|
+
}
|
|
5776
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
5777
|
+
}
|
|
5778
|
+
// forward
|
|
5779
|
+
const result = inst._zod.parse(payload, ctx);
|
|
5780
|
+
if (result instanceof Promise) {
|
|
5781
|
+
if (ctx.async === false)
|
|
5782
|
+
throw new $ZodAsyncError();
|
|
5783
|
+
return result.then((result) => runChecks(result, checks, ctx));
|
|
5784
|
+
}
|
|
5785
|
+
return runChecks(result, checks, ctx);
|
|
5786
|
+
};
|
|
5787
|
+
}
|
|
5788
|
+
inst["~standard"] = {
|
|
5789
|
+
validate: (value) => {
|
|
5790
|
+
try {
|
|
5791
|
+
const r = safeParse$1(inst, value);
|
|
5792
|
+
return r.success ? { value: r.data } : { issues: r.error?.issues };
|
|
5793
|
+
}
|
|
5794
|
+
catch (_) {
|
|
5795
|
+
return safeParseAsync$1(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
|
|
5796
|
+
}
|
|
5797
|
+
},
|
|
5798
|
+
vendor: "zod",
|
|
5799
|
+
version: 1,
|
|
5800
|
+
};
|
|
5801
|
+
});
|
|
5802
|
+
const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
|
|
5803
|
+
$ZodType.init(inst, def);
|
|
5804
|
+
inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? string$1(inst._zod.bag);
|
|
5805
|
+
inst._zod.parse = (payload, _) => {
|
|
5806
|
+
if (def.coerce)
|
|
5807
|
+
try {
|
|
5808
|
+
payload.value = String(payload.value);
|
|
5809
|
+
}
|
|
5810
|
+
catch (_) { }
|
|
5811
|
+
if (typeof payload.value === "string")
|
|
5812
|
+
return payload;
|
|
5813
|
+
payload.issues.push({
|
|
5814
|
+
expected: "string",
|
|
5815
|
+
code: "invalid_type",
|
|
5816
|
+
input: payload.value,
|
|
5817
|
+
inst,
|
|
5818
|
+
});
|
|
5819
|
+
return payload;
|
|
5820
|
+
};
|
|
5821
|
+
});
|
|
5822
|
+
const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
|
|
5823
|
+
// check initialization must come first
|
|
5824
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
5825
|
+
$ZodString.init(inst, def);
|
|
5826
|
+
});
|
|
5827
|
+
const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
|
|
5828
|
+
def.pattern ?? (def.pattern = guid);
|
|
5829
|
+
$ZodStringFormat.init(inst, def);
|
|
5830
|
+
});
|
|
5831
|
+
const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
|
|
5832
|
+
if (def.version) {
|
|
5833
|
+
const versionMap = {
|
|
5834
|
+
v1: 1,
|
|
5835
|
+
v2: 2,
|
|
5836
|
+
v3: 3,
|
|
5837
|
+
v4: 4,
|
|
5838
|
+
v5: 5,
|
|
5839
|
+
v6: 6,
|
|
5840
|
+
v7: 7,
|
|
5841
|
+
v8: 8,
|
|
5842
|
+
};
|
|
5843
|
+
const v = versionMap[def.version];
|
|
5844
|
+
if (v === undefined)
|
|
5845
|
+
throw new Error(`Invalid UUID version: "${def.version}"`);
|
|
5846
|
+
def.pattern ?? (def.pattern = uuid(v));
|
|
5847
|
+
}
|
|
5848
|
+
else
|
|
5849
|
+
def.pattern ?? (def.pattern = uuid());
|
|
5850
|
+
$ZodStringFormat.init(inst, def);
|
|
5851
|
+
});
|
|
5852
|
+
const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
|
|
5853
|
+
def.pattern ?? (def.pattern = email);
|
|
5854
|
+
$ZodStringFormat.init(inst, def);
|
|
5855
|
+
});
|
|
5856
|
+
const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
|
|
5857
|
+
$ZodStringFormat.init(inst, def);
|
|
5858
|
+
inst._zod.check = (payload) => {
|
|
5859
|
+
try {
|
|
5860
|
+
// Trim whitespace from input
|
|
5861
|
+
const trimmed = payload.value.trim();
|
|
5862
|
+
// @ts-ignore
|
|
5863
|
+
const url = new URL(trimmed);
|
|
5864
|
+
if (def.hostname) {
|
|
5865
|
+
def.hostname.lastIndex = 0;
|
|
5866
|
+
if (!def.hostname.test(url.hostname)) {
|
|
5867
|
+
payload.issues.push({
|
|
5868
|
+
code: "invalid_format",
|
|
5869
|
+
format: "url",
|
|
5870
|
+
note: "Invalid hostname",
|
|
5871
|
+
pattern: def.hostname.source,
|
|
5872
|
+
input: payload.value,
|
|
5873
|
+
inst,
|
|
5874
|
+
continue: !def.abort,
|
|
5875
|
+
});
|
|
5876
|
+
}
|
|
5877
|
+
}
|
|
5878
|
+
if (def.protocol) {
|
|
5879
|
+
def.protocol.lastIndex = 0;
|
|
5880
|
+
if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
|
|
5881
|
+
payload.issues.push({
|
|
5882
|
+
code: "invalid_format",
|
|
5883
|
+
format: "url",
|
|
5884
|
+
note: "Invalid protocol",
|
|
5885
|
+
pattern: def.protocol.source,
|
|
5886
|
+
input: payload.value,
|
|
5887
|
+
inst,
|
|
5888
|
+
continue: !def.abort,
|
|
5889
|
+
});
|
|
5890
|
+
}
|
|
5891
|
+
}
|
|
5892
|
+
// Set the output value based on normalize flag
|
|
5893
|
+
if (def.normalize) {
|
|
5894
|
+
// Use normalized URL
|
|
5895
|
+
payload.value = url.href;
|
|
5896
|
+
}
|
|
5897
|
+
else {
|
|
5898
|
+
// Preserve the original input (trimmed)
|
|
5899
|
+
payload.value = trimmed;
|
|
5900
|
+
}
|
|
5901
|
+
return;
|
|
5902
|
+
}
|
|
5903
|
+
catch (_) {
|
|
5904
|
+
payload.issues.push({
|
|
5905
|
+
code: "invalid_format",
|
|
5906
|
+
format: "url",
|
|
5907
|
+
input: payload.value,
|
|
5908
|
+
inst,
|
|
5909
|
+
continue: !def.abort,
|
|
5910
|
+
});
|
|
5911
|
+
}
|
|
5912
|
+
};
|
|
5913
|
+
});
|
|
5914
|
+
const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
|
|
5915
|
+
def.pattern ?? (def.pattern = emoji());
|
|
5916
|
+
$ZodStringFormat.init(inst, def);
|
|
5917
|
+
});
|
|
5918
|
+
const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
|
|
5919
|
+
def.pattern ?? (def.pattern = nanoid);
|
|
5920
|
+
$ZodStringFormat.init(inst, def);
|
|
5921
|
+
});
|
|
5922
|
+
const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
|
|
5923
|
+
def.pattern ?? (def.pattern = cuid);
|
|
5924
|
+
$ZodStringFormat.init(inst, def);
|
|
5925
|
+
});
|
|
5926
|
+
const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
|
|
5927
|
+
def.pattern ?? (def.pattern = cuid2);
|
|
5928
|
+
$ZodStringFormat.init(inst, def);
|
|
5929
|
+
});
|
|
5930
|
+
const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
|
|
5931
|
+
def.pattern ?? (def.pattern = ulid);
|
|
5932
|
+
$ZodStringFormat.init(inst, def);
|
|
5933
|
+
});
|
|
5934
|
+
const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
|
|
5935
|
+
def.pattern ?? (def.pattern = xid);
|
|
5936
|
+
$ZodStringFormat.init(inst, def);
|
|
5937
|
+
});
|
|
5938
|
+
const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
|
|
5939
|
+
def.pattern ?? (def.pattern = ksuid);
|
|
5940
|
+
$ZodStringFormat.init(inst, def);
|
|
5941
|
+
});
|
|
5942
|
+
const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
|
|
5943
|
+
def.pattern ?? (def.pattern = datetime$1(def));
|
|
5944
|
+
$ZodStringFormat.init(inst, def);
|
|
5945
|
+
});
|
|
5946
|
+
const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
|
|
5947
|
+
def.pattern ?? (def.pattern = date$1);
|
|
5948
|
+
$ZodStringFormat.init(inst, def);
|
|
5949
|
+
});
|
|
5950
|
+
const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
|
|
5951
|
+
def.pattern ?? (def.pattern = time$1(def));
|
|
5952
|
+
$ZodStringFormat.init(inst, def);
|
|
5953
|
+
});
|
|
5954
|
+
const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
|
|
5955
|
+
def.pattern ?? (def.pattern = duration$1);
|
|
5956
|
+
$ZodStringFormat.init(inst, def);
|
|
5957
|
+
});
|
|
5958
|
+
const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
|
|
5959
|
+
def.pattern ?? (def.pattern = ipv4);
|
|
5960
|
+
$ZodStringFormat.init(inst, def);
|
|
5961
|
+
inst._zod.bag.format = `ipv4`;
|
|
5962
|
+
});
|
|
5963
|
+
const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
|
|
5964
|
+
def.pattern ?? (def.pattern = ipv6);
|
|
5965
|
+
$ZodStringFormat.init(inst, def);
|
|
5966
|
+
inst._zod.bag.format = `ipv6`;
|
|
5967
|
+
inst._zod.check = (payload) => {
|
|
5968
|
+
try {
|
|
5969
|
+
// @ts-ignore
|
|
5970
|
+
new URL(`http://[${payload.value}]`);
|
|
5971
|
+
// return;
|
|
5972
|
+
}
|
|
5973
|
+
catch {
|
|
5974
|
+
payload.issues.push({
|
|
5975
|
+
code: "invalid_format",
|
|
5976
|
+
format: "ipv6",
|
|
5977
|
+
input: payload.value,
|
|
5978
|
+
inst,
|
|
5979
|
+
continue: !def.abort,
|
|
5980
|
+
});
|
|
5981
|
+
}
|
|
5982
|
+
};
|
|
5983
|
+
});
|
|
5984
|
+
const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
|
|
5985
|
+
def.pattern ?? (def.pattern = cidrv4);
|
|
5986
|
+
$ZodStringFormat.init(inst, def);
|
|
5987
|
+
});
|
|
5988
|
+
const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
|
|
5989
|
+
def.pattern ?? (def.pattern = cidrv6); // not used for validation
|
|
5990
|
+
$ZodStringFormat.init(inst, def);
|
|
5991
|
+
inst._zod.check = (payload) => {
|
|
5992
|
+
const parts = payload.value.split("/");
|
|
5993
|
+
try {
|
|
5994
|
+
if (parts.length !== 2)
|
|
5995
|
+
throw new Error();
|
|
5996
|
+
const [address, prefix] = parts;
|
|
5997
|
+
if (!prefix)
|
|
5998
|
+
throw new Error();
|
|
5999
|
+
const prefixNum = Number(prefix);
|
|
6000
|
+
if (`${prefixNum}` !== prefix)
|
|
6001
|
+
throw new Error();
|
|
6002
|
+
if (prefixNum < 0 || prefixNum > 128)
|
|
6003
|
+
throw new Error();
|
|
6004
|
+
// @ts-ignore
|
|
6005
|
+
new URL(`http://[${address}]`);
|
|
6006
|
+
}
|
|
6007
|
+
catch {
|
|
6008
|
+
payload.issues.push({
|
|
6009
|
+
code: "invalid_format",
|
|
6010
|
+
format: "cidrv6",
|
|
6011
|
+
input: payload.value,
|
|
6012
|
+
inst,
|
|
6013
|
+
continue: !def.abort,
|
|
6014
|
+
});
|
|
6015
|
+
}
|
|
6016
|
+
};
|
|
6017
|
+
});
|
|
6018
|
+
////////////////////////////// ZodBase64 //////////////////////////////
|
|
6019
|
+
function isValidBase64(data) {
|
|
6020
|
+
if (data === "")
|
|
6021
|
+
return true;
|
|
6022
|
+
if (data.length % 4 !== 0)
|
|
6023
|
+
return false;
|
|
6024
|
+
try {
|
|
6025
|
+
// @ts-ignore
|
|
6026
|
+
atob(data);
|
|
6027
|
+
return true;
|
|
6028
|
+
}
|
|
6029
|
+
catch {
|
|
6030
|
+
return false;
|
|
6031
|
+
}
|
|
6032
|
+
}
|
|
6033
|
+
const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
|
|
6034
|
+
def.pattern ?? (def.pattern = base64);
|
|
6035
|
+
$ZodStringFormat.init(inst, def);
|
|
6036
|
+
inst._zod.bag.contentEncoding = "base64";
|
|
6037
|
+
inst._zod.check = (payload) => {
|
|
6038
|
+
if (isValidBase64(payload.value))
|
|
6039
|
+
return;
|
|
6040
|
+
payload.issues.push({
|
|
6041
|
+
code: "invalid_format",
|
|
6042
|
+
format: "base64",
|
|
6043
|
+
input: payload.value,
|
|
6044
|
+
inst,
|
|
6045
|
+
continue: !def.abort,
|
|
6046
|
+
});
|
|
6047
|
+
};
|
|
6048
|
+
});
|
|
6049
|
+
////////////////////////////// ZodBase64 //////////////////////////////
|
|
6050
|
+
function isValidBase64URL(data) {
|
|
6051
|
+
if (!base64url.test(data))
|
|
6052
|
+
return false;
|
|
6053
|
+
const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
|
|
6054
|
+
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
|
|
6055
|
+
return isValidBase64(padded);
|
|
6056
|
+
}
|
|
6057
|
+
const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
|
|
6058
|
+
def.pattern ?? (def.pattern = base64url);
|
|
6059
|
+
$ZodStringFormat.init(inst, def);
|
|
6060
|
+
inst._zod.bag.contentEncoding = "base64url";
|
|
6061
|
+
inst._zod.check = (payload) => {
|
|
6062
|
+
if (isValidBase64URL(payload.value))
|
|
6063
|
+
return;
|
|
6064
|
+
payload.issues.push({
|
|
6065
|
+
code: "invalid_format",
|
|
6066
|
+
format: "base64url",
|
|
6067
|
+
input: payload.value,
|
|
6068
|
+
inst,
|
|
6069
|
+
continue: !def.abort,
|
|
6070
|
+
});
|
|
6071
|
+
};
|
|
6072
|
+
});
|
|
6073
|
+
const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
|
|
6074
|
+
def.pattern ?? (def.pattern = e164);
|
|
6075
|
+
$ZodStringFormat.init(inst, def);
|
|
6076
|
+
});
|
|
6077
|
+
////////////////////////////// ZodJWT //////////////////////////////
|
|
6078
|
+
function isValidJWT(token, algorithm = null) {
|
|
6079
|
+
try {
|
|
6080
|
+
const tokensParts = token.split(".");
|
|
6081
|
+
if (tokensParts.length !== 3)
|
|
6082
|
+
return false;
|
|
6083
|
+
const [header] = tokensParts;
|
|
6084
|
+
if (!header)
|
|
6085
|
+
return false;
|
|
6086
|
+
// @ts-ignore
|
|
6087
|
+
const parsedHeader = JSON.parse(atob(header));
|
|
6088
|
+
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
|
|
6089
|
+
return false;
|
|
6090
|
+
if (!parsedHeader.alg)
|
|
6091
|
+
return false;
|
|
6092
|
+
if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
|
|
6093
|
+
return false;
|
|
6094
|
+
return true;
|
|
6095
|
+
}
|
|
6096
|
+
catch {
|
|
6097
|
+
return false;
|
|
6098
|
+
}
|
|
6099
|
+
}
|
|
6100
|
+
const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
|
|
6101
|
+
$ZodStringFormat.init(inst, def);
|
|
6102
|
+
inst._zod.check = (payload) => {
|
|
6103
|
+
if (isValidJWT(payload.value, def.alg))
|
|
6104
|
+
return;
|
|
6105
|
+
payload.issues.push({
|
|
6106
|
+
code: "invalid_format",
|
|
6107
|
+
format: "jwt",
|
|
6108
|
+
input: payload.value,
|
|
6109
|
+
inst,
|
|
6110
|
+
continue: !def.abort,
|
|
6111
|
+
});
|
|
6112
|
+
};
|
|
6113
|
+
});
|
|
6114
|
+
const $ZodNumber = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) => {
|
|
6115
|
+
$ZodType.init(inst, def);
|
|
6116
|
+
inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
|
|
6117
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
6118
|
+
if (def.coerce)
|
|
6119
|
+
try {
|
|
6120
|
+
payload.value = Number(payload.value);
|
|
6121
|
+
}
|
|
6122
|
+
catch (_) { }
|
|
6123
|
+
const input = payload.value;
|
|
6124
|
+
if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
|
|
6125
|
+
return payload;
|
|
6126
|
+
}
|
|
6127
|
+
const received = typeof input === "number"
|
|
6128
|
+
? Number.isNaN(input)
|
|
6129
|
+
? "NaN"
|
|
6130
|
+
: !Number.isFinite(input)
|
|
6131
|
+
? "Infinity"
|
|
6132
|
+
: undefined
|
|
6133
|
+
: undefined;
|
|
6134
|
+
payload.issues.push({
|
|
6135
|
+
expected: "number",
|
|
6136
|
+
code: "invalid_type",
|
|
6137
|
+
input,
|
|
6138
|
+
inst,
|
|
6139
|
+
...(received ? { received } : {}),
|
|
6140
|
+
});
|
|
6141
|
+
return payload;
|
|
6142
|
+
};
|
|
6143
|
+
});
|
|
6144
|
+
const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, def) => {
|
|
6145
|
+
$ZodCheckNumberFormat.init(inst, def);
|
|
6146
|
+
$ZodNumber.init(inst, def); // no format checks
|
|
6147
|
+
});
|
|
6148
|
+
function handleArrayResult(result, final, index) {
|
|
6149
|
+
if (result.issues.length) {
|
|
6150
|
+
final.issues.push(...prefixIssues(index, result.issues));
|
|
6151
|
+
}
|
|
6152
|
+
final.value[index] = result.value;
|
|
6153
|
+
}
|
|
6154
|
+
const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
|
|
6155
|
+
$ZodType.init(inst, def);
|
|
6156
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6157
|
+
const input = payload.value;
|
|
6158
|
+
if (!Array.isArray(input)) {
|
|
6159
|
+
payload.issues.push({
|
|
6160
|
+
expected: "array",
|
|
6161
|
+
code: "invalid_type",
|
|
6162
|
+
input,
|
|
6163
|
+
inst,
|
|
6164
|
+
});
|
|
6165
|
+
return payload;
|
|
6166
|
+
}
|
|
6167
|
+
payload.value = Array(input.length);
|
|
6168
|
+
const proms = [];
|
|
6169
|
+
for (let i = 0; i < input.length; i++) {
|
|
6170
|
+
const item = input[i];
|
|
6171
|
+
const result = def.element._zod.run({
|
|
6172
|
+
value: item,
|
|
6173
|
+
issues: [],
|
|
6174
|
+
}, ctx);
|
|
6175
|
+
if (result instanceof Promise) {
|
|
6176
|
+
proms.push(result.then((result) => handleArrayResult(result, payload, i)));
|
|
6177
|
+
}
|
|
6178
|
+
else {
|
|
6179
|
+
handleArrayResult(result, payload, i);
|
|
6180
|
+
}
|
|
6181
|
+
}
|
|
6182
|
+
if (proms.length) {
|
|
6183
|
+
return Promise.all(proms).then(() => payload);
|
|
6184
|
+
}
|
|
6185
|
+
return payload; //handleArrayResultsAsync(parseResults, final);
|
|
6186
|
+
};
|
|
6187
|
+
});
|
|
6188
|
+
function handleUnionResults(results, final, inst, ctx) {
|
|
6189
|
+
for (const result of results) {
|
|
6190
|
+
if (result.issues.length === 0) {
|
|
6191
|
+
final.value = result.value;
|
|
6192
|
+
return final;
|
|
6193
|
+
}
|
|
6194
|
+
}
|
|
6195
|
+
const nonaborted = results.filter((r) => !aborted(r));
|
|
6196
|
+
if (nonaborted.length === 1) {
|
|
6197
|
+
final.value = nonaborted[0].value;
|
|
6198
|
+
return nonaborted[0];
|
|
6199
|
+
}
|
|
6200
|
+
final.issues.push({
|
|
6201
|
+
code: "invalid_union",
|
|
6202
|
+
input: final.value,
|
|
6203
|
+
inst,
|
|
6204
|
+
errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
|
|
6205
|
+
});
|
|
6206
|
+
return final;
|
|
6207
|
+
}
|
|
6208
|
+
const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
|
|
6209
|
+
$ZodType.init(inst, def);
|
|
6210
|
+
defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
|
|
6211
|
+
defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
|
|
6212
|
+
defineLazy(inst._zod, "values", () => {
|
|
6213
|
+
if (def.options.every((o) => o._zod.values)) {
|
|
6214
|
+
return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
6215
|
+
}
|
|
6216
|
+
return undefined;
|
|
6217
|
+
});
|
|
6218
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
6219
|
+
if (def.options.every((o) => o._zod.pattern)) {
|
|
6220
|
+
const patterns = def.options.map((o) => o._zod.pattern);
|
|
6221
|
+
return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
|
|
6222
|
+
}
|
|
6223
|
+
return undefined;
|
|
6224
|
+
});
|
|
6225
|
+
const single = def.options.length === 1;
|
|
6226
|
+
const first = def.options[0]._zod.run;
|
|
6227
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6228
|
+
if (single) {
|
|
6229
|
+
return first(payload, ctx);
|
|
6230
|
+
}
|
|
6231
|
+
let async = false;
|
|
6232
|
+
const results = [];
|
|
6233
|
+
for (const option of def.options) {
|
|
6234
|
+
const result = option._zod.run({
|
|
6235
|
+
value: payload.value,
|
|
6236
|
+
issues: [],
|
|
6237
|
+
}, ctx);
|
|
6238
|
+
if (result instanceof Promise) {
|
|
6239
|
+
results.push(result);
|
|
6240
|
+
async = true;
|
|
6241
|
+
}
|
|
6242
|
+
else {
|
|
6243
|
+
if (result.issues.length === 0)
|
|
6244
|
+
return result;
|
|
6245
|
+
results.push(result);
|
|
6246
|
+
}
|
|
6247
|
+
}
|
|
6248
|
+
if (!async)
|
|
6249
|
+
return handleUnionResults(results, payload, inst, ctx);
|
|
6250
|
+
return Promise.all(results).then((results) => {
|
|
6251
|
+
return handleUnionResults(results, payload, inst, ctx);
|
|
6252
|
+
});
|
|
6253
|
+
};
|
|
6254
|
+
});
|
|
6255
|
+
const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
|
|
6256
|
+
$ZodType.init(inst, def);
|
|
6257
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6258
|
+
const input = payload.value;
|
|
6259
|
+
const left = def.left._zod.run({ value: input, issues: [] }, ctx);
|
|
6260
|
+
const right = def.right._zod.run({ value: input, issues: [] }, ctx);
|
|
6261
|
+
const async = left instanceof Promise || right instanceof Promise;
|
|
6262
|
+
if (async) {
|
|
6263
|
+
return Promise.all([left, right]).then(([left, right]) => {
|
|
6264
|
+
return handleIntersectionResults(payload, left, right);
|
|
6265
|
+
});
|
|
6266
|
+
}
|
|
6267
|
+
return handleIntersectionResults(payload, left, right);
|
|
6268
|
+
};
|
|
6269
|
+
});
|
|
6270
|
+
function mergeValues(a, b) {
|
|
6271
|
+
// const aType = parse.t(a);
|
|
6272
|
+
// const bType = parse.t(b);
|
|
6273
|
+
if (a === b) {
|
|
6274
|
+
return { valid: true, data: a };
|
|
6275
|
+
}
|
|
6276
|
+
if (a instanceof Date && b instanceof Date && +a === +b) {
|
|
6277
|
+
return { valid: true, data: a };
|
|
6278
|
+
}
|
|
6279
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
6280
|
+
const bKeys = Object.keys(b);
|
|
6281
|
+
const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
6282
|
+
const newObj = { ...a, ...b };
|
|
6283
|
+
for (const key of sharedKeys) {
|
|
6284
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
6285
|
+
if (!sharedValue.valid) {
|
|
6286
|
+
return {
|
|
6287
|
+
valid: false,
|
|
6288
|
+
mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
|
|
6289
|
+
};
|
|
6290
|
+
}
|
|
6291
|
+
newObj[key] = sharedValue.data;
|
|
6292
|
+
}
|
|
6293
|
+
return { valid: true, data: newObj };
|
|
6294
|
+
}
|
|
6295
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
6296
|
+
if (a.length !== b.length) {
|
|
6297
|
+
return { valid: false, mergeErrorPath: [] };
|
|
6298
|
+
}
|
|
6299
|
+
const newArray = [];
|
|
6300
|
+
for (let index = 0; index < a.length; index++) {
|
|
6301
|
+
const itemA = a[index];
|
|
6302
|
+
const itemB = b[index];
|
|
6303
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
6304
|
+
if (!sharedValue.valid) {
|
|
6305
|
+
return {
|
|
6306
|
+
valid: false,
|
|
6307
|
+
mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
|
|
6308
|
+
};
|
|
6309
|
+
}
|
|
6310
|
+
newArray.push(sharedValue.data);
|
|
6311
|
+
}
|
|
6312
|
+
return { valid: true, data: newArray };
|
|
6313
|
+
}
|
|
6314
|
+
return { valid: false, mergeErrorPath: [] };
|
|
6315
|
+
}
|
|
6316
|
+
function handleIntersectionResults(result, left, right) {
|
|
6317
|
+
if (left.issues.length) {
|
|
6318
|
+
result.issues.push(...left.issues);
|
|
6319
|
+
}
|
|
6320
|
+
if (right.issues.length) {
|
|
6321
|
+
result.issues.push(...right.issues);
|
|
6322
|
+
}
|
|
6323
|
+
if (aborted(result))
|
|
6324
|
+
return result;
|
|
6325
|
+
const merged = mergeValues(left.value, right.value);
|
|
6326
|
+
if (!merged.valid) {
|
|
6327
|
+
throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
|
|
6328
|
+
}
|
|
6329
|
+
result.value = merged.data;
|
|
6330
|
+
return result;
|
|
6331
|
+
}
|
|
6332
|
+
const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
|
|
6333
|
+
$ZodType.init(inst, def);
|
|
6334
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6335
|
+
if (ctx.direction === "backward") {
|
|
6336
|
+
throw new $ZodEncodeError(inst.constructor.name);
|
|
6337
|
+
}
|
|
6338
|
+
const _out = def.transform(payload.value, payload);
|
|
6339
|
+
if (ctx.async) {
|
|
6340
|
+
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
|
6341
|
+
return output.then((output) => {
|
|
6342
|
+
payload.value = output;
|
|
6343
|
+
return payload;
|
|
6344
|
+
});
|
|
6345
|
+
}
|
|
6346
|
+
if (_out instanceof Promise) {
|
|
6347
|
+
throw new $ZodAsyncError();
|
|
6348
|
+
}
|
|
6349
|
+
payload.value = _out;
|
|
6350
|
+
return payload;
|
|
6351
|
+
};
|
|
6352
|
+
});
|
|
6353
|
+
function handleOptionalResult(result, input) {
|
|
6354
|
+
if (result.issues.length && input === undefined) {
|
|
6355
|
+
return { issues: [], value: undefined };
|
|
6356
|
+
}
|
|
6357
|
+
return result;
|
|
6358
|
+
}
|
|
6359
|
+
const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
|
|
6360
|
+
$ZodType.init(inst, def);
|
|
6361
|
+
inst._zod.optin = "optional";
|
|
6362
|
+
inst._zod.optout = "optional";
|
|
6363
|
+
defineLazy(inst._zod, "values", () => {
|
|
6364
|
+
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
|
|
6365
|
+
});
|
|
6366
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
6367
|
+
const pattern = def.innerType._zod.pattern;
|
|
6368
|
+
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : undefined;
|
|
6369
|
+
});
|
|
6370
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6371
|
+
if (def.innerType._zod.optin === "optional") {
|
|
6372
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
6373
|
+
if (result instanceof Promise)
|
|
6374
|
+
return result.then((r) => handleOptionalResult(r, payload.value));
|
|
6375
|
+
return handleOptionalResult(result, payload.value);
|
|
6376
|
+
}
|
|
6377
|
+
if (payload.value === undefined) {
|
|
6378
|
+
return payload;
|
|
6379
|
+
}
|
|
6380
|
+
return def.innerType._zod.run(payload, ctx);
|
|
6381
|
+
};
|
|
6382
|
+
});
|
|
6383
|
+
const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
|
|
6384
|
+
$ZodType.init(inst, def);
|
|
6385
|
+
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
6386
|
+
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
6387
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
6388
|
+
const pattern = def.innerType._zod.pattern;
|
|
6389
|
+
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : undefined;
|
|
6390
|
+
});
|
|
6391
|
+
defineLazy(inst._zod, "values", () => {
|
|
6392
|
+
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
|
|
6393
|
+
});
|
|
6394
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6395
|
+
// Forward direction (decode): allow null to pass through
|
|
6396
|
+
if (payload.value === null)
|
|
6397
|
+
return payload;
|
|
6398
|
+
return def.innerType._zod.run(payload, ctx);
|
|
6399
|
+
};
|
|
6400
|
+
});
|
|
6401
|
+
const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
|
|
6402
|
+
$ZodType.init(inst, def);
|
|
6403
|
+
// inst._zod.qin = "true";
|
|
6404
|
+
inst._zod.optin = "optional";
|
|
6405
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
6406
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6407
|
+
if (ctx.direction === "backward") {
|
|
6408
|
+
return def.innerType._zod.run(payload, ctx);
|
|
6409
|
+
}
|
|
6410
|
+
// Forward direction (decode): apply defaults for undefined input
|
|
6411
|
+
if (payload.value === undefined) {
|
|
6412
|
+
payload.value = def.defaultValue;
|
|
6413
|
+
/**
|
|
6414
|
+
* $ZodDefault returns the default value immediately in forward direction.
|
|
6415
|
+
* 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. */
|
|
6416
|
+
return payload;
|
|
6417
|
+
}
|
|
6418
|
+
// Forward direction: continue with default handling
|
|
6419
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
6420
|
+
if (result instanceof Promise) {
|
|
6421
|
+
return result.then((result) => handleDefaultResult(result, def));
|
|
6422
|
+
}
|
|
6423
|
+
return handleDefaultResult(result, def);
|
|
6424
|
+
};
|
|
6425
|
+
});
|
|
6426
|
+
function handleDefaultResult(payload, def) {
|
|
6427
|
+
if (payload.value === undefined) {
|
|
6428
|
+
payload.value = def.defaultValue;
|
|
6429
|
+
}
|
|
6430
|
+
return payload;
|
|
6431
|
+
}
|
|
6432
|
+
const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
|
|
6433
|
+
$ZodType.init(inst, def);
|
|
6434
|
+
inst._zod.optin = "optional";
|
|
6435
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
6436
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6437
|
+
if (ctx.direction === "backward") {
|
|
6438
|
+
return def.innerType._zod.run(payload, ctx);
|
|
6439
|
+
}
|
|
6440
|
+
// Forward direction (decode): apply prefault for undefined input
|
|
6441
|
+
if (payload.value === undefined) {
|
|
6442
|
+
payload.value = def.defaultValue;
|
|
6443
|
+
}
|
|
6444
|
+
return def.innerType._zod.run(payload, ctx);
|
|
6445
|
+
};
|
|
6446
|
+
});
|
|
6447
|
+
const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
|
|
6448
|
+
$ZodType.init(inst, def);
|
|
6449
|
+
defineLazy(inst._zod, "values", () => {
|
|
6450
|
+
const v = def.innerType._zod.values;
|
|
6451
|
+
return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
|
|
6452
|
+
});
|
|
6453
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6454
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
6455
|
+
if (result instanceof Promise) {
|
|
6456
|
+
return result.then((result) => handleNonOptionalResult(result, inst));
|
|
6457
|
+
}
|
|
6458
|
+
return handleNonOptionalResult(result, inst);
|
|
6459
|
+
};
|
|
6460
|
+
});
|
|
6461
|
+
function handleNonOptionalResult(payload, inst) {
|
|
6462
|
+
if (!payload.issues.length && payload.value === undefined) {
|
|
6463
|
+
payload.issues.push({
|
|
6464
|
+
code: "invalid_type",
|
|
6465
|
+
expected: "nonoptional",
|
|
6466
|
+
input: payload.value,
|
|
6467
|
+
inst,
|
|
6468
|
+
});
|
|
6469
|
+
}
|
|
6470
|
+
return payload;
|
|
6471
|
+
}
|
|
6472
|
+
const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
|
|
6473
|
+
$ZodType.init(inst, def);
|
|
6474
|
+
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
6475
|
+
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
6476
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
6477
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6478
|
+
if (ctx.direction === "backward") {
|
|
6479
|
+
return def.innerType._zod.run(payload, ctx);
|
|
6480
|
+
}
|
|
6481
|
+
// Forward direction (decode): apply catch logic
|
|
6482
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
6483
|
+
if (result instanceof Promise) {
|
|
6484
|
+
return result.then((result) => {
|
|
6485
|
+
payload.value = result.value;
|
|
6486
|
+
if (result.issues.length) {
|
|
6487
|
+
payload.value = def.catchValue({
|
|
6488
|
+
...payload,
|
|
6489
|
+
error: {
|
|
6490
|
+
issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
|
|
6491
|
+
},
|
|
6492
|
+
input: payload.value,
|
|
6493
|
+
});
|
|
6494
|
+
payload.issues = [];
|
|
6495
|
+
}
|
|
6496
|
+
return payload;
|
|
6497
|
+
});
|
|
6498
|
+
}
|
|
6499
|
+
payload.value = result.value;
|
|
6500
|
+
if (result.issues.length) {
|
|
6501
|
+
payload.value = def.catchValue({
|
|
6502
|
+
...payload,
|
|
6503
|
+
error: {
|
|
6504
|
+
issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
|
|
6505
|
+
},
|
|
6506
|
+
input: payload.value,
|
|
6507
|
+
});
|
|
6508
|
+
payload.issues = [];
|
|
6509
|
+
}
|
|
6510
|
+
return payload;
|
|
6511
|
+
};
|
|
6512
|
+
});
|
|
6513
|
+
const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
|
|
6514
|
+
$ZodType.init(inst, def);
|
|
6515
|
+
defineLazy(inst._zod, "values", () => def.in._zod.values);
|
|
6516
|
+
defineLazy(inst._zod, "optin", () => def.in._zod.optin);
|
|
6517
|
+
defineLazy(inst._zod, "optout", () => def.out._zod.optout);
|
|
6518
|
+
defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
|
|
6519
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6520
|
+
if (ctx.direction === "backward") {
|
|
6521
|
+
const right = def.out._zod.run(payload, ctx);
|
|
6522
|
+
if (right instanceof Promise) {
|
|
6523
|
+
return right.then((right) => handlePipeResult(right, def.in, ctx));
|
|
6524
|
+
}
|
|
6525
|
+
return handlePipeResult(right, def.in, ctx);
|
|
6526
|
+
}
|
|
6527
|
+
const left = def.in._zod.run(payload, ctx);
|
|
6528
|
+
if (left instanceof Promise) {
|
|
6529
|
+
return left.then((left) => handlePipeResult(left, def.out, ctx));
|
|
6530
|
+
}
|
|
6531
|
+
return handlePipeResult(left, def.out, ctx);
|
|
6532
|
+
};
|
|
6533
|
+
});
|
|
6534
|
+
function handlePipeResult(left, next, ctx) {
|
|
6535
|
+
if (left.issues.length) {
|
|
6536
|
+
// prevent further checks
|
|
6537
|
+
left.aborted = true;
|
|
6538
|
+
return left;
|
|
6539
|
+
}
|
|
6540
|
+
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
|
|
6541
|
+
}
|
|
6542
|
+
const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
|
|
6543
|
+
$ZodType.init(inst, def);
|
|
6544
|
+
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
6545
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
6546
|
+
defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
|
|
6547
|
+
defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
|
|
6548
|
+
inst._zod.parse = (payload, ctx) => {
|
|
6549
|
+
if (ctx.direction === "backward") {
|
|
6550
|
+
return def.innerType._zod.run(payload, ctx);
|
|
6551
|
+
}
|
|
6552
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
6553
|
+
if (result instanceof Promise) {
|
|
6554
|
+
return result.then(handleReadonlyResult);
|
|
6555
|
+
}
|
|
6556
|
+
return handleReadonlyResult(result);
|
|
6557
|
+
};
|
|
6558
|
+
});
|
|
6559
|
+
function handleReadonlyResult(payload) {
|
|
6560
|
+
payload.value = Object.freeze(payload.value);
|
|
6561
|
+
return payload;
|
|
6562
|
+
}
|
|
6563
|
+
const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
|
|
6564
|
+
$ZodCheck.init(inst, def);
|
|
6565
|
+
$ZodType.init(inst, def);
|
|
6566
|
+
inst._zod.parse = (payload, _) => {
|
|
6567
|
+
return payload;
|
|
6568
|
+
};
|
|
6569
|
+
inst._zod.check = (payload) => {
|
|
6570
|
+
const input = payload.value;
|
|
6571
|
+
const r = def.fn(input);
|
|
6572
|
+
if (r instanceof Promise) {
|
|
6573
|
+
return r.then((r) => handleRefineResult(r, payload, input, inst));
|
|
6574
|
+
}
|
|
6575
|
+
handleRefineResult(r, payload, input, inst);
|
|
6576
|
+
return;
|
|
6577
|
+
};
|
|
6578
|
+
});
|
|
6579
|
+
function handleRefineResult(result, payload, input, inst) {
|
|
6580
|
+
if (!result) {
|
|
6581
|
+
const _iss = {
|
|
6582
|
+
code: "custom",
|
|
6583
|
+
input,
|
|
6584
|
+
inst, // incorporates params.error into issue reporting
|
|
6585
|
+
path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
|
|
6586
|
+
continue: !inst._zod.def.abort,
|
|
6587
|
+
// params: inst._zod.def.params,
|
|
6588
|
+
};
|
|
6589
|
+
if (inst._zod.def.params)
|
|
6590
|
+
_iss.params = inst._zod.def.params;
|
|
6591
|
+
payload.issues.push(issue(_iss));
|
|
6592
|
+
}
|
|
6593
|
+
}
|
|
6594
|
+
|
|
6595
|
+
var _a;
|
|
6596
|
+
class $ZodRegistry {
|
|
6597
|
+
constructor() {
|
|
6598
|
+
this._map = new WeakMap();
|
|
6599
|
+
this._idmap = new Map();
|
|
6600
|
+
}
|
|
6601
|
+
add(schema, ..._meta) {
|
|
6602
|
+
const meta = _meta[0];
|
|
6603
|
+
this._map.set(schema, meta);
|
|
6604
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
6605
|
+
if (this._idmap.has(meta.id)) {
|
|
6606
|
+
throw new Error(`ID ${meta.id} already exists in the registry`);
|
|
6607
|
+
}
|
|
6608
|
+
this._idmap.set(meta.id, schema);
|
|
6609
|
+
}
|
|
6610
|
+
return this;
|
|
6611
|
+
}
|
|
6612
|
+
clear() {
|
|
6613
|
+
this._map = new WeakMap();
|
|
6614
|
+
this._idmap = new Map();
|
|
6615
|
+
return this;
|
|
6616
|
+
}
|
|
6617
|
+
remove(schema) {
|
|
6618
|
+
const meta = this._map.get(schema);
|
|
6619
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
6620
|
+
this._idmap.delete(meta.id);
|
|
6621
|
+
}
|
|
6622
|
+
this._map.delete(schema);
|
|
6623
|
+
return this;
|
|
6624
|
+
}
|
|
6625
|
+
get(schema) {
|
|
6626
|
+
// return this._map.get(schema) as any;
|
|
6627
|
+
// inherit metadata
|
|
6628
|
+
const p = schema._zod.parent;
|
|
6629
|
+
if (p) {
|
|
6630
|
+
const pm = { ...(this.get(p) ?? {}) };
|
|
6631
|
+
delete pm.id; // do not inherit id
|
|
6632
|
+
const f = { ...pm, ...this._map.get(schema) };
|
|
6633
|
+
return Object.keys(f).length ? f : undefined;
|
|
6634
|
+
}
|
|
6635
|
+
return this._map.get(schema);
|
|
6636
|
+
}
|
|
6637
|
+
has(schema) {
|
|
6638
|
+
return this._map.has(schema);
|
|
6639
|
+
}
|
|
6640
|
+
}
|
|
6641
|
+
// registries
|
|
6642
|
+
function registry() {
|
|
6643
|
+
return new $ZodRegistry();
|
|
6644
|
+
}
|
|
6645
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
6646
|
+
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
6647
|
+
|
|
6648
|
+
function _string(Class, params) {
|
|
6649
|
+
return new Class({
|
|
6650
|
+
type: "string",
|
|
6651
|
+
...normalizeParams(params),
|
|
6652
|
+
});
|
|
6653
|
+
}
|
|
6654
|
+
function _email(Class, params) {
|
|
6655
|
+
return new Class({
|
|
6656
|
+
type: "string",
|
|
6657
|
+
format: "email",
|
|
6658
|
+
check: "string_format",
|
|
6659
|
+
abort: false,
|
|
6660
|
+
...normalizeParams(params),
|
|
6661
|
+
});
|
|
6662
|
+
}
|
|
6663
|
+
function _guid(Class, params) {
|
|
6664
|
+
return new Class({
|
|
6665
|
+
type: "string",
|
|
6666
|
+
format: "guid",
|
|
6667
|
+
check: "string_format",
|
|
6668
|
+
abort: false,
|
|
6669
|
+
...normalizeParams(params),
|
|
6670
|
+
});
|
|
6671
|
+
}
|
|
6672
|
+
function _uuid(Class, params) {
|
|
6673
|
+
return new Class({
|
|
6674
|
+
type: "string",
|
|
6675
|
+
format: "uuid",
|
|
6676
|
+
check: "string_format",
|
|
6677
|
+
abort: false,
|
|
6678
|
+
...normalizeParams(params),
|
|
6679
|
+
});
|
|
6680
|
+
}
|
|
6681
|
+
function _uuidv4(Class, params) {
|
|
6682
|
+
return new Class({
|
|
6683
|
+
type: "string",
|
|
6684
|
+
format: "uuid",
|
|
6685
|
+
check: "string_format",
|
|
6686
|
+
abort: false,
|
|
6687
|
+
version: "v4",
|
|
6688
|
+
...normalizeParams(params),
|
|
6689
|
+
});
|
|
6690
|
+
}
|
|
6691
|
+
function _uuidv6(Class, params) {
|
|
6692
|
+
return new Class({
|
|
6693
|
+
type: "string",
|
|
6694
|
+
format: "uuid",
|
|
6695
|
+
check: "string_format",
|
|
6696
|
+
abort: false,
|
|
6697
|
+
version: "v6",
|
|
6698
|
+
...normalizeParams(params),
|
|
6699
|
+
});
|
|
6700
|
+
}
|
|
6701
|
+
function _uuidv7(Class, params) {
|
|
6702
|
+
return new Class({
|
|
6703
|
+
type: "string",
|
|
6704
|
+
format: "uuid",
|
|
6705
|
+
check: "string_format",
|
|
6706
|
+
abort: false,
|
|
6707
|
+
version: "v7",
|
|
6708
|
+
...normalizeParams(params),
|
|
6709
|
+
});
|
|
6710
|
+
}
|
|
6711
|
+
function _url(Class, params) {
|
|
6712
|
+
return new Class({
|
|
6713
|
+
type: "string",
|
|
6714
|
+
format: "url",
|
|
6715
|
+
check: "string_format",
|
|
6716
|
+
abort: false,
|
|
6717
|
+
...normalizeParams(params),
|
|
6718
|
+
});
|
|
6719
|
+
}
|
|
6720
|
+
function _emoji(Class, params) {
|
|
6721
|
+
return new Class({
|
|
6722
|
+
type: "string",
|
|
6723
|
+
format: "emoji",
|
|
6724
|
+
check: "string_format",
|
|
6725
|
+
abort: false,
|
|
6726
|
+
...normalizeParams(params),
|
|
6727
|
+
});
|
|
6728
|
+
}
|
|
6729
|
+
function _nanoid(Class, params) {
|
|
6730
|
+
return new Class({
|
|
6731
|
+
type: "string",
|
|
6732
|
+
format: "nanoid",
|
|
6733
|
+
check: "string_format",
|
|
6734
|
+
abort: false,
|
|
6735
|
+
...normalizeParams(params),
|
|
6736
|
+
});
|
|
6737
|
+
}
|
|
6738
|
+
function _cuid(Class, params) {
|
|
6739
|
+
return new Class({
|
|
6740
|
+
type: "string",
|
|
6741
|
+
format: "cuid",
|
|
6742
|
+
check: "string_format",
|
|
6743
|
+
abort: false,
|
|
6744
|
+
...normalizeParams(params),
|
|
6745
|
+
});
|
|
6746
|
+
}
|
|
6747
|
+
function _cuid2(Class, params) {
|
|
6748
|
+
return new Class({
|
|
6749
|
+
type: "string",
|
|
6750
|
+
format: "cuid2",
|
|
6751
|
+
check: "string_format",
|
|
6752
|
+
abort: false,
|
|
6753
|
+
...normalizeParams(params),
|
|
6754
|
+
});
|
|
6755
|
+
}
|
|
6756
|
+
function _ulid(Class, params) {
|
|
6757
|
+
return new Class({
|
|
6758
|
+
type: "string",
|
|
6759
|
+
format: "ulid",
|
|
6760
|
+
check: "string_format",
|
|
6761
|
+
abort: false,
|
|
6762
|
+
...normalizeParams(params),
|
|
6763
|
+
});
|
|
6764
|
+
}
|
|
6765
|
+
function _xid(Class, params) {
|
|
6766
|
+
return new Class({
|
|
6767
|
+
type: "string",
|
|
6768
|
+
format: "xid",
|
|
6769
|
+
check: "string_format",
|
|
6770
|
+
abort: false,
|
|
6771
|
+
...normalizeParams(params),
|
|
6772
|
+
});
|
|
6773
|
+
}
|
|
6774
|
+
function _ksuid(Class, params) {
|
|
6775
|
+
return new Class({
|
|
6776
|
+
type: "string",
|
|
6777
|
+
format: "ksuid",
|
|
6778
|
+
check: "string_format",
|
|
6779
|
+
abort: false,
|
|
6780
|
+
...normalizeParams(params),
|
|
6781
|
+
});
|
|
6782
|
+
}
|
|
6783
|
+
function _ipv4(Class, params) {
|
|
6784
|
+
return new Class({
|
|
6785
|
+
type: "string",
|
|
6786
|
+
format: "ipv4",
|
|
6787
|
+
check: "string_format",
|
|
6788
|
+
abort: false,
|
|
6789
|
+
...normalizeParams(params),
|
|
6790
|
+
});
|
|
6791
|
+
}
|
|
6792
|
+
function _ipv6(Class, params) {
|
|
6793
|
+
return new Class({
|
|
6794
|
+
type: "string",
|
|
6795
|
+
format: "ipv6",
|
|
6796
|
+
check: "string_format",
|
|
6797
|
+
abort: false,
|
|
6798
|
+
...normalizeParams(params),
|
|
6799
|
+
});
|
|
6800
|
+
}
|
|
6801
|
+
function _cidrv4(Class, params) {
|
|
6802
|
+
return new Class({
|
|
6803
|
+
type: "string",
|
|
6804
|
+
format: "cidrv4",
|
|
6805
|
+
check: "string_format",
|
|
6806
|
+
abort: false,
|
|
6807
|
+
...normalizeParams(params),
|
|
6808
|
+
});
|
|
6809
|
+
}
|
|
6810
|
+
function _cidrv6(Class, params) {
|
|
6811
|
+
return new Class({
|
|
6812
|
+
type: "string",
|
|
6813
|
+
format: "cidrv6",
|
|
6814
|
+
check: "string_format",
|
|
6815
|
+
abort: false,
|
|
6816
|
+
...normalizeParams(params),
|
|
6817
|
+
});
|
|
6818
|
+
}
|
|
6819
|
+
function _base64(Class, params) {
|
|
6820
|
+
return new Class({
|
|
6821
|
+
type: "string",
|
|
6822
|
+
format: "base64",
|
|
6823
|
+
check: "string_format",
|
|
6824
|
+
abort: false,
|
|
6825
|
+
...normalizeParams(params),
|
|
6826
|
+
});
|
|
6827
|
+
}
|
|
6828
|
+
function _base64url(Class, params) {
|
|
6829
|
+
return new Class({
|
|
6830
|
+
type: "string",
|
|
6831
|
+
format: "base64url",
|
|
6832
|
+
check: "string_format",
|
|
6833
|
+
abort: false,
|
|
6834
|
+
...normalizeParams(params),
|
|
6835
|
+
});
|
|
6836
|
+
}
|
|
6837
|
+
function _e164(Class, params) {
|
|
6838
|
+
return new Class({
|
|
6839
|
+
type: "string",
|
|
6840
|
+
format: "e164",
|
|
6841
|
+
check: "string_format",
|
|
6842
|
+
abort: false,
|
|
6843
|
+
...normalizeParams(params),
|
|
6844
|
+
});
|
|
6845
|
+
}
|
|
6846
|
+
function _jwt(Class, params) {
|
|
6847
|
+
return new Class({
|
|
6848
|
+
type: "string",
|
|
6849
|
+
format: "jwt",
|
|
6850
|
+
check: "string_format",
|
|
6851
|
+
abort: false,
|
|
6852
|
+
...normalizeParams(params),
|
|
6853
|
+
});
|
|
6854
|
+
}
|
|
6855
|
+
function _isoDateTime(Class, params) {
|
|
6856
|
+
return new Class({
|
|
6857
|
+
type: "string",
|
|
6858
|
+
format: "datetime",
|
|
6859
|
+
check: "string_format",
|
|
6860
|
+
offset: false,
|
|
6861
|
+
local: false,
|
|
6862
|
+
precision: null,
|
|
6863
|
+
...normalizeParams(params),
|
|
6864
|
+
});
|
|
6865
|
+
}
|
|
6866
|
+
function _isoDate(Class, params) {
|
|
6867
|
+
return new Class({
|
|
6868
|
+
type: "string",
|
|
6869
|
+
format: "date",
|
|
6870
|
+
check: "string_format",
|
|
6871
|
+
...normalizeParams(params),
|
|
6872
|
+
});
|
|
6873
|
+
}
|
|
6874
|
+
function _isoTime(Class, params) {
|
|
6875
|
+
return new Class({
|
|
6876
|
+
type: "string",
|
|
6877
|
+
format: "time",
|
|
6878
|
+
check: "string_format",
|
|
6879
|
+
precision: null,
|
|
6880
|
+
...normalizeParams(params),
|
|
6881
|
+
});
|
|
6882
|
+
}
|
|
6883
|
+
function _isoDuration(Class, params) {
|
|
6884
|
+
return new Class({
|
|
6885
|
+
type: "string",
|
|
6886
|
+
format: "duration",
|
|
6887
|
+
check: "string_format",
|
|
6888
|
+
...normalizeParams(params),
|
|
6889
|
+
});
|
|
6890
|
+
}
|
|
6891
|
+
function _number(Class, params) {
|
|
6892
|
+
return new Class({
|
|
6893
|
+
type: "number",
|
|
6894
|
+
checks: [],
|
|
6895
|
+
...normalizeParams(params),
|
|
6896
|
+
});
|
|
6897
|
+
}
|
|
6898
|
+
function _int(Class, params) {
|
|
6899
|
+
return new Class({
|
|
6900
|
+
type: "number",
|
|
6901
|
+
check: "number_format",
|
|
6902
|
+
abort: false,
|
|
6903
|
+
format: "safeint",
|
|
6904
|
+
...normalizeParams(params),
|
|
6905
|
+
});
|
|
6906
|
+
}
|
|
6907
|
+
function _lt(value, params) {
|
|
6908
|
+
return new $ZodCheckLessThan({
|
|
6909
|
+
check: "less_than",
|
|
6910
|
+
...normalizeParams(params),
|
|
6911
|
+
value,
|
|
6912
|
+
inclusive: false,
|
|
6913
|
+
});
|
|
6914
|
+
}
|
|
6915
|
+
function _lte(value, params) {
|
|
6916
|
+
return new $ZodCheckLessThan({
|
|
6917
|
+
check: "less_than",
|
|
6918
|
+
...normalizeParams(params),
|
|
6919
|
+
value,
|
|
6920
|
+
inclusive: true,
|
|
6921
|
+
});
|
|
6922
|
+
}
|
|
6923
|
+
function _gt(value, params) {
|
|
6924
|
+
return new $ZodCheckGreaterThan({
|
|
6925
|
+
check: "greater_than",
|
|
6926
|
+
...normalizeParams(params),
|
|
6927
|
+
value,
|
|
6928
|
+
inclusive: false,
|
|
6929
|
+
});
|
|
6930
|
+
}
|
|
6931
|
+
function _gte(value, params) {
|
|
6932
|
+
return new $ZodCheckGreaterThan({
|
|
6933
|
+
check: "greater_than",
|
|
6934
|
+
...normalizeParams(params),
|
|
6935
|
+
value,
|
|
6936
|
+
inclusive: true,
|
|
6937
|
+
});
|
|
6938
|
+
}
|
|
6939
|
+
function _multipleOf(value, params) {
|
|
6940
|
+
return new $ZodCheckMultipleOf({
|
|
6941
|
+
check: "multiple_of",
|
|
6942
|
+
...normalizeParams(params),
|
|
6943
|
+
value,
|
|
6944
|
+
});
|
|
6945
|
+
}
|
|
6946
|
+
function _maxLength(maximum, params) {
|
|
6947
|
+
const ch = new $ZodCheckMaxLength({
|
|
6948
|
+
check: "max_length",
|
|
6949
|
+
...normalizeParams(params),
|
|
6950
|
+
maximum,
|
|
6951
|
+
});
|
|
6952
|
+
return ch;
|
|
6953
|
+
}
|
|
6954
|
+
function _minLength(minimum, params) {
|
|
6955
|
+
return new $ZodCheckMinLength({
|
|
6956
|
+
check: "min_length",
|
|
6957
|
+
...normalizeParams(params),
|
|
6958
|
+
minimum,
|
|
6959
|
+
});
|
|
6960
|
+
}
|
|
6961
|
+
function _length(length, params) {
|
|
6962
|
+
return new $ZodCheckLengthEquals({
|
|
6963
|
+
check: "length_equals",
|
|
6964
|
+
...normalizeParams(params),
|
|
6965
|
+
length,
|
|
6966
|
+
});
|
|
6967
|
+
}
|
|
6968
|
+
function _regex(pattern, params) {
|
|
6969
|
+
return new $ZodCheckRegex({
|
|
6970
|
+
check: "string_format",
|
|
6971
|
+
format: "regex",
|
|
6972
|
+
...normalizeParams(params),
|
|
6973
|
+
pattern,
|
|
6974
|
+
});
|
|
6975
|
+
}
|
|
6976
|
+
function _lowercase(params) {
|
|
6977
|
+
return new $ZodCheckLowerCase({
|
|
6978
|
+
check: "string_format",
|
|
6979
|
+
format: "lowercase",
|
|
6980
|
+
...normalizeParams(params),
|
|
6981
|
+
});
|
|
6982
|
+
}
|
|
6983
|
+
function _uppercase(params) {
|
|
6984
|
+
return new $ZodCheckUpperCase({
|
|
6985
|
+
check: "string_format",
|
|
6986
|
+
format: "uppercase",
|
|
6987
|
+
...normalizeParams(params),
|
|
6988
|
+
});
|
|
6989
|
+
}
|
|
6990
|
+
function _includes(includes, params) {
|
|
6991
|
+
return new $ZodCheckIncludes({
|
|
6992
|
+
check: "string_format",
|
|
6993
|
+
format: "includes",
|
|
6994
|
+
...normalizeParams(params),
|
|
6995
|
+
includes,
|
|
6996
|
+
});
|
|
6997
|
+
}
|
|
6998
|
+
function _startsWith(prefix, params) {
|
|
6999
|
+
return new $ZodCheckStartsWith({
|
|
7000
|
+
check: "string_format",
|
|
7001
|
+
format: "starts_with",
|
|
7002
|
+
...normalizeParams(params),
|
|
7003
|
+
prefix,
|
|
7004
|
+
});
|
|
7005
|
+
}
|
|
7006
|
+
function _endsWith(suffix, params) {
|
|
7007
|
+
return new $ZodCheckEndsWith({
|
|
7008
|
+
check: "string_format",
|
|
7009
|
+
format: "ends_with",
|
|
7010
|
+
...normalizeParams(params),
|
|
7011
|
+
suffix,
|
|
7012
|
+
});
|
|
7013
|
+
}
|
|
7014
|
+
function _overwrite(tx) {
|
|
7015
|
+
return new $ZodCheckOverwrite({
|
|
7016
|
+
check: "overwrite",
|
|
7017
|
+
tx,
|
|
7018
|
+
});
|
|
7019
|
+
}
|
|
7020
|
+
// normalize
|
|
7021
|
+
function _normalize(form) {
|
|
7022
|
+
return _overwrite((input) => input.normalize(form));
|
|
7023
|
+
}
|
|
7024
|
+
// trim
|
|
7025
|
+
function _trim() {
|
|
7026
|
+
return _overwrite((input) => input.trim());
|
|
7027
|
+
}
|
|
7028
|
+
// toLowerCase
|
|
7029
|
+
function _toLowerCase() {
|
|
7030
|
+
return _overwrite((input) => input.toLowerCase());
|
|
7031
|
+
}
|
|
7032
|
+
// toUpperCase
|
|
7033
|
+
function _toUpperCase() {
|
|
7034
|
+
return _overwrite((input) => input.toUpperCase());
|
|
7035
|
+
}
|
|
7036
|
+
// slugify
|
|
7037
|
+
function _slugify() {
|
|
7038
|
+
return _overwrite((input) => slugify(input));
|
|
7039
|
+
}
|
|
7040
|
+
function _array(Class, element, params) {
|
|
7041
|
+
return new Class({
|
|
7042
|
+
type: "array",
|
|
7043
|
+
element,
|
|
7044
|
+
// get element() {
|
|
7045
|
+
// return element;
|
|
7046
|
+
// },
|
|
7047
|
+
...normalizeParams(params),
|
|
7048
|
+
});
|
|
7049
|
+
}
|
|
7050
|
+
// same as _custom but defaults to abort:false
|
|
7051
|
+
function _refine(Class, fn, _params) {
|
|
7052
|
+
const schema = new Class({
|
|
7053
|
+
type: "custom",
|
|
7054
|
+
check: "custom",
|
|
7055
|
+
fn: fn,
|
|
7056
|
+
...normalizeParams(_params),
|
|
7057
|
+
});
|
|
7058
|
+
return schema;
|
|
7059
|
+
}
|
|
7060
|
+
function _superRefine(fn) {
|
|
7061
|
+
const ch = _check((payload) => {
|
|
7062
|
+
payload.addIssue = (issue$1) => {
|
|
7063
|
+
if (typeof issue$1 === "string") {
|
|
7064
|
+
payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
|
|
7065
|
+
}
|
|
7066
|
+
else {
|
|
7067
|
+
// for Zod 3 backwards compatibility
|
|
7068
|
+
const _issue = issue$1;
|
|
7069
|
+
if (_issue.fatal)
|
|
7070
|
+
_issue.continue = false;
|
|
7071
|
+
_issue.code ?? (_issue.code = "custom");
|
|
7072
|
+
_issue.input ?? (_issue.input = payload.value);
|
|
7073
|
+
_issue.inst ?? (_issue.inst = ch);
|
|
7074
|
+
_issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
|
|
7075
|
+
payload.issues.push(issue(_issue));
|
|
7076
|
+
}
|
|
7077
|
+
};
|
|
7078
|
+
return fn(payload.value, payload);
|
|
7079
|
+
});
|
|
7080
|
+
return ch;
|
|
7081
|
+
}
|
|
7082
|
+
function _check(fn, params) {
|
|
7083
|
+
const ch = new $ZodCheck({
|
|
7084
|
+
check: "custom",
|
|
7085
|
+
...normalizeParams(params),
|
|
7086
|
+
});
|
|
7087
|
+
ch._zod.check = fn;
|
|
7088
|
+
return ch;
|
|
7089
|
+
}
|
|
7090
|
+
|
|
7091
|
+
const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
|
|
7092
|
+
$ZodISODateTime.init(inst, def);
|
|
7093
|
+
ZodStringFormat.init(inst, def);
|
|
7094
|
+
});
|
|
7095
|
+
function datetime(params) {
|
|
7096
|
+
return _isoDateTime(ZodISODateTime, params);
|
|
7097
|
+
}
|
|
7098
|
+
const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
|
|
7099
|
+
$ZodISODate.init(inst, def);
|
|
7100
|
+
ZodStringFormat.init(inst, def);
|
|
7101
|
+
});
|
|
7102
|
+
function date(params) {
|
|
7103
|
+
return _isoDate(ZodISODate, params);
|
|
7104
|
+
}
|
|
7105
|
+
const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
|
|
7106
|
+
$ZodISOTime.init(inst, def);
|
|
7107
|
+
ZodStringFormat.init(inst, def);
|
|
7108
|
+
});
|
|
7109
|
+
function time(params) {
|
|
7110
|
+
return _isoTime(ZodISOTime, params);
|
|
7111
|
+
}
|
|
7112
|
+
const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
|
|
7113
|
+
$ZodISODuration.init(inst, def);
|
|
7114
|
+
ZodStringFormat.init(inst, def);
|
|
7115
|
+
});
|
|
7116
|
+
function duration(params) {
|
|
7117
|
+
return _isoDuration(ZodISODuration, params);
|
|
7118
|
+
}
|
|
7119
|
+
|
|
7120
|
+
const initializer = (inst, issues) => {
|
|
7121
|
+
$ZodError.init(inst, issues);
|
|
7122
|
+
inst.name = "ZodError";
|
|
7123
|
+
Object.defineProperties(inst, {
|
|
7124
|
+
format: {
|
|
7125
|
+
value: (mapper) => formatError(inst, mapper),
|
|
7126
|
+
// enumerable: false,
|
|
7127
|
+
},
|
|
7128
|
+
flatten: {
|
|
7129
|
+
value: (mapper) => flattenError(inst, mapper),
|
|
7130
|
+
// enumerable: false,
|
|
7131
|
+
},
|
|
7132
|
+
addIssue: {
|
|
7133
|
+
value: (issue) => {
|
|
7134
|
+
inst.issues.push(issue);
|
|
7135
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
7136
|
+
},
|
|
7137
|
+
// enumerable: false,
|
|
7138
|
+
},
|
|
7139
|
+
addIssues: {
|
|
7140
|
+
value: (issues) => {
|
|
7141
|
+
inst.issues.push(...issues);
|
|
7142
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
7143
|
+
},
|
|
7144
|
+
// enumerable: false,
|
|
7145
|
+
},
|
|
7146
|
+
isEmpty: {
|
|
7147
|
+
get() {
|
|
7148
|
+
return inst.issues.length === 0;
|
|
7149
|
+
},
|
|
7150
|
+
// enumerable: false,
|
|
7151
|
+
},
|
|
7152
|
+
});
|
|
7153
|
+
// Object.defineProperty(inst, "isEmpty", {
|
|
7154
|
+
// get() {
|
|
7155
|
+
// return inst.issues.length === 0;
|
|
7156
|
+
// },
|
|
7157
|
+
// });
|
|
7158
|
+
};
|
|
7159
|
+
const ZodError = $constructor("ZodError", initializer);
|
|
7160
|
+
const ZodRealError = $constructor("ZodError", initializer, {
|
|
7161
|
+
Parent: Error,
|
|
7162
|
+
});
|
|
7163
|
+
// /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
|
|
7164
|
+
// export type ErrorMapCtx = core.$ZodErrorMapCtx;
|
|
7165
|
+
|
|
7166
|
+
const parse = /* @__PURE__ */ _parse(ZodRealError);
|
|
7167
|
+
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
7168
|
+
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
7169
|
+
const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
7170
|
+
// Codec functions
|
|
7171
|
+
const encode = /* @__PURE__ */ _encode(ZodRealError);
|
|
7172
|
+
const decode = /* @__PURE__ */ _decode(ZodRealError);
|
|
7173
|
+
const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
|
|
7174
|
+
const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
|
|
7175
|
+
const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
7176
|
+
const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
7177
|
+
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
7178
|
+
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
7179
|
+
|
|
7180
|
+
const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
7181
|
+
$ZodType.init(inst, def);
|
|
7182
|
+
inst.def = def;
|
|
7183
|
+
inst.type = def.type;
|
|
7184
|
+
Object.defineProperty(inst, "_def", { value: def });
|
|
7185
|
+
// base methods
|
|
7186
|
+
inst.check = (...checks) => {
|
|
7187
|
+
return inst.clone(mergeDefs(def, {
|
|
7188
|
+
checks: [
|
|
7189
|
+
...(def.checks ?? []),
|
|
7190
|
+
...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
|
|
7191
|
+
],
|
|
7192
|
+
}));
|
|
7193
|
+
};
|
|
7194
|
+
inst.clone = (def, params) => clone(inst, def, params);
|
|
7195
|
+
inst.brand = () => inst;
|
|
7196
|
+
inst.register = ((reg, meta) => {
|
|
7197
|
+
reg.add(inst, meta);
|
|
7198
|
+
return inst;
|
|
7199
|
+
});
|
|
7200
|
+
// parsing
|
|
7201
|
+
inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
|
|
7202
|
+
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
7203
|
+
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
7204
|
+
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
7205
|
+
inst.spa = inst.safeParseAsync;
|
|
7206
|
+
// encoding/decoding
|
|
7207
|
+
inst.encode = (data, params) => encode(inst, data, params);
|
|
7208
|
+
inst.decode = (data, params) => decode(inst, data, params);
|
|
7209
|
+
inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
|
|
7210
|
+
inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
|
|
7211
|
+
inst.safeEncode = (data, params) => safeEncode(inst, data, params);
|
|
7212
|
+
inst.safeDecode = (data, params) => safeDecode(inst, data, params);
|
|
7213
|
+
inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
|
|
7214
|
+
inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
|
|
7215
|
+
// refinements
|
|
7216
|
+
inst.refine = (check, params) => inst.check(refine(check, params));
|
|
7217
|
+
inst.superRefine = (refinement) => inst.check(superRefine(refinement));
|
|
7218
|
+
inst.overwrite = (fn) => inst.check(_overwrite(fn));
|
|
7219
|
+
// wrappers
|
|
7220
|
+
inst.optional = () => optional(inst);
|
|
7221
|
+
inst.nullable = () => nullable(inst);
|
|
7222
|
+
inst.nullish = () => optional(nullable(inst));
|
|
7223
|
+
inst.nonoptional = (params) => nonoptional(inst, params);
|
|
7224
|
+
inst.array = () => array(inst);
|
|
7225
|
+
inst.or = (arg) => union([inst, arg]);
|
|
7226
|
+
inst.and = (arg) => intersection(inst, arg);
|
|
7227
|
+
inst.transform = (tx) => pipe(inst, transform(tx));
|
|
7228
|
+
inst.default = (def) => _default(inst, def);
|
|
7229
|
+
inst.prefault = (def) => prefault(inst, def);
|
|
7230
|
+
// inst.coalesce = (def, params) => coalesce(inst, def, params);
|
|
7231
|
+
inst.catch = (params) => _catch(inst, params);
|
|
7232
|
+
inst.pipe = (target) => pipe(inst, target);
|
|
7233
|
+
inst.readonly = () => readonly(inst);
|
|
7234
|
+
// meta
|
|
7235
|
+
inst.describe = (description) => {
|
|
7236
|
+
const cl = inst.clone();
|
|
7237
|
+
globalRegistry.add(cl, { description });
|
|
7238
|
+
return cl;
|
|
7239
|
+
};
|
|
7240
|
+
Object.defineProperty(inst, "description", {
|
|
7241
|
+
get() {
|
|
7242
|
+
return globalRegistry.get(inst)?.description;
|
|
7243
|
+
},
|
|
7244
|
+
configurable: true,
|
|
7245
|
+
});
|
|
7246
|
+
inst.meta = (...args) => {
|
|
7247
|
+
if (args.length === 0) {
|
|
7248
|
+
return globalRegistry.get(inst);
|
|
7249
|
+
}
|
|
7250
|
+
const cl = inst.clone();
|
|
7251
|
+
globalRegistry.add(cl, args[0]);
|
|
7252
|
+
return cl;
|
|
7253
|
+
};
|
|
7254
|
+
// helpers
|
|
7255
|
+
inst.isOptional = () => inst.safeParse(undefined).success;
|
|
7256
|
+
inst.isNullable = () => inst.safeParse(null).success;
|
|
7257
|
+
return inst;
|
|
7258
|
+
});
|
|
7259
|
+
/** @internal */
|
|
7260
|
+
const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
|
|
7261
|
+
$ZodString.init(inst, def);
|
|
7262
|
+
ZodType.init(inst, def);
|
|
7263
|
+
const bag = inst._zod.bag;
|
|
7264
|
+
inst.format = bag.format ?? null;
|
|
7265
|
+
inst.minLength = bag.minimum ?? null;
|
|
7266
|
+
inst.maxLength = bag.maximum ?? null;
|
|
7267
|
+
// validations
|
|
7268
|
+
inst.regex = (...args) => inst.check(_regex(...args));
|
|
7269
|
+
inst.includes = (...args) => inst.check(_includes(...args));
|
|
7270
|
+
inst.startsWith = (...args) => inst.check(_startsWith(...args));
|
|
7271
|
+
inst.endsWith = (...args) => inst.check(_endsWith(...args));
|
|
7272
|
+
inst.min = (...args) => inst.check(_minLength(...args));
|
|
7273
|
+
inst.max = (...args) => inst.check(_maxLength(...args));
|
|
7274
|
+
inst.length = (...args) => inst.check(_length(...args));
|
|
7275
|
+
inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
|
|
7276
|
+
inst.lowercase = (params) => inst.check(_lowercase(params));
|
|
7277
|
+
inst.uppercase = (params) => inst.check(_uppercase(params));
|
|
7278
|
+
// transforms
|
|
7279
|
+
inst.trim = () => inst.check(_trim());
|
|
7280
|
+
inst.normalize = (...args) => inst.check(_normalize(...args));
|
|
7281
|
+
inst.toLowerCase = () => inst.check(_toLowerCase());
|
|
7282
|
+
inst.toUpperCase = () => inst.check(_toUpperCase());
|
|
7283
|
+
inst.slugify = () => inst.check(_slugify());
|
|
7284
|
+
});
|
|
7285
|
+
const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
|
|
7286
|
+
$ZodString.init(inst, def);
|
|
7287
|
+
_ZodString.init(inst, def);
|
|
7288
|
+
inst.email = (params) => inst.check(_email(ZodEmail, params));
|
|
7289
|
+
inst.url = (params) => inst.check(_url(ZodURL, params));
|
|
7290
|
+
inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
|
|
7291
|
+
inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
|
|
7292
|
+
inst.guid = (params) => inst.check(_guid(ZodGUID, params));
|
|
7293
|
+
inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
|
|
7294
|
+
inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
|
|
7295
|
+
inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
|
|
7296
|
+
inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
|
|
7297
|
+
inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
|
|
7298
|
+
inst.guid = (params) => inst.check(_guid(ZodGUID, params));
|
|
7299
|
+
inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
|
|
7300
|
+
inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
|
|
7301
|
+
inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
|
|
7302
|
+
inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
|
|
7303
|
+
inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
|
|
7304
|
+
inst.xid = (params) => inst.check(_xid(ZodXID, params));
|
|
7305
|
+
inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
|
|
7306
|
+
inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
|
|
7307
|
+
inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
|
|
7308
|
+
inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
|
|
7309
|
+
inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
|
|
7310
|
+
inst.e164 = (params) => inst.check(_e164(ZodE164, params));
|
|
7311
|
+
// iso
|
|
7312
|
+
inst.datetime = (params) => inst.check(datetime(params));
|
|
7313
|
+
inst.date = (params) => inst.check(date(params));
|
|
7314
|
+
inst.time = (params) => inst.check(time(params));
|
|
7315
|
+
inst.duration = (params) => inst.check(duration(params));
|
|
7316
|
+
});
|
|
7317
|
+
function string(params) {
|
|
7318
|
+
return _string(ZodString, params);
|
|
7319
|
+
}
|
|
7320
|
+
const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
|
|
7321
|
+
$ZodStringFormat.init(inst, def);
|
|
7322
|
+
_ZodString.init(inst, def);
|
|
7323
|
+
});
|
|
7324
|
+
const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
|
|
7325
|
+
// ZodStringFormat.init(inst, def);
|
|
7326
|
+
$ZodEmail.init(inst, def);
|
|
7327
|
+
ZodStringFormat.init(inst, def);
|
|
7328
|
+
});
|
|
7329
|
+
const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
|
|
7330
|
+
// ZodStringFormat.init(inst, def);
|
|
7331
|
+
$ZodGUID.init(inst, def);
|
|
7332
|
+
ZodStringFormat.init(inst, def);
|
|
7333
|
+
});
|
|
7334
|
+
const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
|
|
7335
|
+
// ZodStringFormat.init(inst, def);
|
|
7336
|
+
$ZodUUID.init(inst, def);
|
|
7337
|
+
ZodStringFormat.init(inst, def);
|
|
7338
|
+
});
|
|
7339
|
+
const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
|
|
7340
|
+
// ZodStringFormat.init(inst, def);
|
|
7341
|
+
$ZodURL.init(inst, def);
|
|
7342
|
+
ZodStringFormat.init(inst, def);
|
|
7343
|
+
});
|
|
7344
|
+
const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
|
|
7345
|
+
// ZodStringFormat.init(inst, def);
|
|
7346
|
+
$ZodEmoji.init(inst, def);
|
|
7347
|
+
ZodStringFormat.init(inst, def);
|
|
7348
|
+
});
|
|
7349
|
+
const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
|
|
7350
|
+
// ZodStringFormat.init(inst, def);
|
|
7351
|
+
$ZodNanoID.init(inst, def);
|
|
7352
|
+
ZodStringFormat.init(inst, def);
|
|
7353
|
+
});
|
|
7354
|
+
const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
|
|
7355
|
+
// ZodStringFormat.init(inst, def);
|
|
7356
|
+
$ZodCUID.init(inst, def);
|
|
7357
|
+
ZodStringFormat.init(inst, def);
|
|
7358
|
+
});
|
|
7359
|
+
const ZodCUID2 = /*@__PURE__*/ $constructor("ZodCUID2", (inst, def) => {
|
|
7360
|
+
// ZodStringFormat.init(inst, def);
|
|
7361
|
+
$ZodCUID2.init(inst, def);
|
|
7362
|
+
ZodStringFormat.init(inst, def);
|
|
7363
|
+
});
|
|
7364
|
+
const ZodULID = /*@__PURE__*/ $constructor("ZodULID", (inst, def) => {
|
|
7365
|
+
// ZodStringFormat.init(inst, def);
|
|
7366
|
+
$ZodULID.init(inst, def);
|
|
7367
|
+
ZodStringFormat.init(inst, def);
|
|
7368
|
+
});
|
|
7369
|
+
const ZodXID = /*@__PURE__*/ $constructor("ZodXID", (inst, def) => {
|
|
7370
|
+
// ZodStringFormat.init(inst, def);
|
|
7371
|
+
$ZodXID.init(inst, def);
|
|
7372
|
+
ZodStringFormat.init(inst, def);
|
|
7373
|
+
});
|
|
7374
|
+
const ZodKSUID = /*@__PURE__*/ $constructor("ZodKSUID", (inst, def) => {
|
|
7375
|
+
// ZodStringFormat.init(inst, def);
|
|
7376
|
+
$ZodKSUID.init(inst, def);
|
|
7377
|
+
ZodStringFormat.init(inst, def);
|
|
7378
|
+
});
|
|
7379
|
+
const ZodIPv4 = /*@__PURE__*/ $constructor("ZodIPv4", (inst, def) => {
|
|
7380
|
+
// ZodStringFormat.init(inst, def);
|
|
7381
|
+
$ZodIPv4.init(inst, def);
|
|
7382
|
+
ZodStringFormat.init(inst, def);
|
|
7383
|
+
});
|
|
7384
|
+
const ZodIPv6 = /*@__PURE__*/ $constructor("ZodIPv6", (inst, def) => {
|
|
7385
|
+
// ZodStringFormat.init(inst, def);
|
|
7386
|
+
$ZodIPv6.init(inst, def);
|
|
7387
|
+
ZodStringFormat.init(inst, def);
|
|
7388
|
+
});
|
|
7389
|
+
const ZodCIDRv4 = /*@__PURE__*/ $constructor("ZodCIDRv4", (inst, def) => {
|
|
7390
|
+
$ZodCIDRv4.init(inst, def);
|
|
7391
|
+
ZodStringFormat.init(inst, def);
|
|
7392
|
+
});
|
|
7393
|
+
const ZodCIDRv6 = /*@__PURE__*/ $constructor("ZodCIDRv6", (inst, def) => {
|
|
7394
|
+
$ZodCIDRv6.init(inst, def);
|
|
7395
|
+
ZodStringFormat.init(inst, def);
|
|
7396
|
+
});
|
|
7397
|
+
const ZodBase64 = /*@__PURE__*/ $constructor("ZodBase64", (inst, def) => {
|
|
7398
|
+
// ZodStringFormat.init(inst, def);
|
|
7399
|
+
$ZodBase64.init(inst, def);
|
|
7400
|
+
ZodStringFormat.init(inst, def);
|
|
7401
|
+
});
|
|
7402
|
+
const ZodBase64URL = /*@__PURE__*/ $constructor("ZodBase64URL", (inst, def) => {
|
|
7403
|
+
// ZodStringFormat.init(inst, def);
|
|
7404
|
+
$ZodBase64URL.init(inst, def);
|
|
7405
|
+
ZodStringFormat.init(inst, def);
|
|
7406
|
+
});
|
|
7407
|
+
const ZodE164 = /*@__PURE__*/ $constructor("ZodE164", (inst, def) => {
|
|
7408
|
+
// ZodStringFormat.init(inst, def);
|
|
7409
|
+
$ZodE164.init(inst, def);
|
|
7410
|
+
ZodStringFormat.init(inst, def);
|
|
7411
|
+
});
|
|
7412
|
+
const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
|
|
7413
|
+
// ZodStringFormat.init(inst, def);
|
|
7414
|
+
$ZodJWT.init(inst, def);
|
|
7415
|
+
ZodStringFormat.init(inst, def);
|
|
7416
|
+
});
|
|
7417
|
+
const ZodNumber = /*@__PURE__*/ $constructor("ZodNumber", (inst, def) => {
|
|
7418
|
+
$ZodNumber.init(inst, def);
|
|
7419
|
+
ZodType.init(inst, def);
|
|
7420
|
+
inst.gt = (value, params) => inst.check(_gt(value, params));
|
|
7421
|
+
inst.gte = (value, params) => inst.check(_gte(value, params));
|
|
7422
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
7423
|
+
inst.lt = (value, params) => inst.check(_lt(value, params));
|
|
7424
|
+
inst.lte = (value, params) => inst.check(_lte(value, params));
|
|
7425
|
+
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
7426
|
+
inst.int = (params) => inst.check(int(params));
|
|
7427
|
+
inst.safe = (params) => inst.check(int(params));
|
|
7428
|
+
inst.positive = (params) => inst.check(_gt(0, params));
|
|
7429
|
+
inst.nonnegative = (params) => inst.check(_gte(0, params));
|
|
7430
|
+
inst.negative = (params) => inst.check(_lt(0, params));
|
|
7431
|
+
inst.nonpositive = (params) => inst.check(_lte(0, params));
|
|
7432
|
+
inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
|
|
7433
|
+
inst.step = (value, params) => inst.check(_multipleOf(value, params));
|
|
7434
|
+
// inst.finite = (params) => inst.check(core.finite(params));
|
|
7435
|
+
inst.finite = () => inst;
|
|
7436
|
+
const bag = inst._zod.bag;
|
|
7437
|
+
inst.minValue =
|
|
7438
|
+
Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
|
|
7439
|
+
inst.maxValue =
|
|
7440
|
+
Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
|
|
7441
|
+
inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
|
|
7442
|
+
inst.isFinite = true;
|
|
7443
|
+
inst.format = bag.format ?? null;
|
|
7444
|
+
});
|
|
7445
|
+
function number(params) {
|
|
7446
|
+
return _number(ZodNumber, params);
|
|
7447
|
+
}
|
|
7448
|
+
const ZodNumberFormat = /*@__PURE__*/ $constructor("ZodNumberFormat", (inst, def) => {
|
|
7449
|
+
$ZodNumberFormat.init(inst, def);
|
|
7450
|
+
ZodNumber.init(inst, def);
|
|
7451
|
+
});
|
|
7452
|
+
function int(params) {
|
|
7453
|
+
return _int(ZodNumberFormat, params);
|
|
7454
|
+
}
|
|
7455
|
+
const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
|
|
7456
|
+
$ZodArray.init(inst, def);
|
|
7457
|
+
ZodType.init(inst, def);
|
|
7458
|
+
inst.element = def.element;
|
|
7459
|
+
inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
|
|
7460
|
+
inst.nonempty = (params) => inst.check(_minLength(1, params));
|
|
7461
|
+
inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
|
|
7462
|
+
inst.length = (len, params) => inst.check(_length(len, params));
|
|
7463
|
+
inst.unwrap = () => inst.element;
|
|
7464
|
+
});
|
|
7465
|
+
function array(element, params) {
|
|
7466
|
+
return _array(ZodArray, element, params);
|
|
7467
|
+
}
|
|
7468
|
+
const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
|
|
7469
|
+
$ZodUnion.init(inst, def);
|
|
7470
|
+
ZodType.init(inst, def);
|
|
7471
|
+
inst.options = def.options;
|
|
7472
|
+
});
|
|
7473
|
+
function union(options, params) {
|
|
7474
|
+
return new ZodUnion({
|
|
7475
|
+
type: "union",
|
|
7476
|
+
options: options,
|
|
7477
|
+
...normalizeParams(params),
|
|
7478
|
+
});
|
|
7479
|
+
}
|
|
7480
|
+
const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
|
|
7481
|
+
$ZodIntersection.init(inst, def);
|
|
7482
|
+
ZodType.init(inst, def);
|
|
7483
|
+
});
|
|
7484
|
+
function intersection(left, right) {
|
|
7485
|
+
return new ZodIntersection({
|
|
7486
|
+
type: "intersection",
|
|
7487
|
+
left: left,
|
|
7488
|
+
right: right,
|
|
7489
|
+
});
|
|
7490
|
+
}
|
|
7491
|
+
const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
|
|
7492
|
+
$ZodTransform.init(inst, def);
|
|
7493
|
+
ZodType.init(inst, def);
|
|
7494
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
7495
|
+
if (_ctx.direction === "backward") {
|
|
7496
|
+
throw new $ZodEncodeError(inst.constructor.name);
|
|
7497
|
+
}
|
|
7498
|
+
payload.addIssue = (issue$1) => {
|
|
7499
|
+
if (typeof issue$1 === "string") {
|
|
7500
|
+
payload.issues.push(issue(issue$1, payload.value, def));
|
|
7501
|
+
}
|
|
7502
|
+
else {
|
|
7503
|
+
// for Zod 3 backwards compatibility
|
|
7504
|
+
const _issue = issue$1;
|
|
7505
|
+
if (_issue.fatal)
|
|
7506
|
+
_issue.continue = false;
|
|
7507
|
+
_issue.code ?? (_issue.code = "custom");
|
|
7508
|
+
_issue.input ?? (_issue.input = payload.value);
|
|
7509
|
+
_issue.inst ?? (_issue.inst = inst);
|
|
7510
|
+
// _issue.continue ??= true;
|
|
7511
|
+
payload.issues.push(issue(_issue));
|
|
7512
|
+
}
|
|
7513
|
+
};
|
|
7514
|
+
const output = def.transform(payload.value, payload);
|
|
7515
|
+
if (output instanceof Promise) {
|
|
7516
|
+
return output.then((output) => {
|
|
7517
|
+
payload.value = output;
|
|
7518
|
+
return payload;
|
|
7519
|
+
});
|
|
7520
|
+
}
|
|
7521
|
+
payload.value = output;
|
|
7522
|
+
return payload;
|
|
7523
|
+
};
|
|
7524
|
+
});
|
|
7525
|
+
function transform(fn) {
|
|
7526
|
+
return new ZodTransform({
|
|
7527
|
+
type: "transform",
|
|
7528
|
+
transform: fn,
|
|
7529
|
+
});
|
|
7530
|
+
}
|
|
7531
|
+
const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
|
|
7532
|
+
$ZodOptional.init(inst, def);
|
|
7533
|
+
ZodType.init(inst, def);
|
|
7534
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
7535
|
+
});
|
|
7536
|
+
function optional(innerType) {
|
|
7537
|
+
return new ZodOptional({
|
|
7538
|
+
type: "optional",
|
|
7539
|
+
innerType: innerType,
|
|
7540
|
+
});
|
|
7541
|
+
}
|
|
7542
|
+
const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
|
|
7543
|
+
$ZodNullable.init(inst, def);
|
|
7544
|
+
ZodType.init(inst, def);
|
|
7545
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
7546
|
+
});
|
|
7547
|
+
function nullable(innerType) {
|
|
7548
|
+
return new ZodNullable({
|
|
7549
|
+
type: "nullable",
|
|
7550
|
+
innerType: innerType,
|
|
7551
|
+
});
|
|
7552
|
+
}
|
|
7553
|
+
const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
|
|
7554
|
+
$ZodDefault.init(inst, def);
|
|
7555
|
+
ZodType.init(inst, def);
|
|
7556
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
7557
|
+
inst.removeDefault = inst.unwrap;
|
|
7558
|
+
});
|
|
7559
|
+
function _default(innerType, defaultValue) {
|
|
7560
|
+
return new ZodDefault({
|
|
7561
|
+
type: "default",
|
|
7562
|
+
innerType: innerType,
|
|
7563
|
+
get defaultValue() {
|
|
7564
|
+
return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
|
|
7565
|
+
},
|
|
7566
|
+
});
|
|
7567
|
+
}
|
|
7568
|
+
const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
|
|
7569
|
+
$ZodPrefault.init(inst, def);
|
|
7570
|
+
ZodType.init(inst, def);
|
|
7571
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
7572
|
+
});
|
|
7573
|
+
function prefault(innerType, defaultValue) {
|
|
7574
|
+
return new ZodPrefault({
|
|
7575
|
+
type: "prefault",
|
|
7576
|
+
innerType: innerType,
|
|
7577
|
+
get defaultValue() {
|
|
7578
|
+
return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
|
|
7579
|
+
},
|
|
7580
|
+
});
|
|
7581
|
+
}
|
|
7582
|
+
const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
|
|
7583
|
+
$ZodNonOptional.init(inst, def);
|
|
7584
|
+
ZodType.init(inst, def);
|
|
7585
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
7586
|
+
});
|
|
7587
|
+
function nonoptional(innerType, params) {
|
|
7588
|
+
return new ZodNonOptional({
|
|
7589
|
+
type: "nonoptional",
|
|
7590
|
+
innerType: innerType,
|
|
7591
|
+
...normalizeParams(params),
|
|
7592
|
+
});
|
|
7593
|
+
}
|
|
7594
|
+
const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
|
|
7595
|
+
$ZodCatch.init(inst, def);
|
|
7596
|
+
ZodType.init(inst, def);
|
|
7597
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
7598
|
+
inst.removeCatch = inst.unwrap;
|
|
7599
|
+
});
|
|
7600
|
+
function _catch(innerType, catchValue) {
|
|
7601
|
+
return new ZodCatch({
|
|
7602
|
+
type: "catch",
|
|
7603
|
+
innerType: innerType,
|
|
7604
|
+
catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
|
|
7605
|
+
});
|
|
7606
|
+
}
|
|
7607
|
+
const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
|
|
7608
|
+
$ZodPipe.init(inst, def);
|
|
7609
|
+
ZodType.init(inst, def);
|
|
7610
|
+
inst.in = def.in;
|
|
7611
|
+
inst.out = def.out;
|
|
7612
|
+
});
|
|
7613
|
+
function pipe(in_, out) {
|
|
7614
|
+
return new ZodPipe({
|
|
7615
|
+
type: "pipe",
|
|
7616
|
+
in: in_,
|
|
7617
|
+
out: out,
|
|
7618
|
+
// ...util.normalizeParams(params),
|
|
7619
|
+
});
|
|
7620
|
+
}
|
|
7621
|
+
const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
|
|
7622
|
+
$ZodReadonly.init(inst, def);
|
|
7623
|
+
ZodType.init(inst, def);
|
|
7624
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
7625
|
+
});
|
|
7626
|
+
function readonly(innerType) {
|
|
7627
|
+
return new ZodReadonly({
|
|
7628
|
+
type: "readonly",
|
|
7629
|
+
innerType: innerType,
|
|
7630
|
+
});
|
|
7631
|
+
}
|
|
7632
|
+
const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
|
|
7633
|
+
$ZodCustom.init(inst, def);
|
|
7634
|
+
ZodType.init(inst, def);
|
|
7635
|
+
});
|
|
7636
|
+
function refine(fn, _params = {}) {
|
|
7637
|
+
return _refine(ZodCustom, fn, _params);
|
|
7638
|
+
}
|
|
7639
|
+
// superRefine
|
|
7640
|
+
function superRefine(fn) {
|
|
7641
|
+
return _superRefine(fn);
|
|
7642
|
+
}
|
|
7643
|
+
|
|
7644
|
+
/**
|
|
7645
|
+
* Input validation utility with zod package (Phase 2B).
|
|
7646
|
+
*
|
|
7647
|
+
* Generated - do not edit directly.
|
|
7648
|
+
*/
|
|
7649
|
+
/**
|
|
7650
|
+
* Validate parameters using zod schema.
|
|
7651
|
+
*/
|
|
7652
|
+
function validateParams(schema, params, config) {
|
|
7653
|
+
if (!config?.validationEnabled) {
|
|
7654
|
+
return params;
|
|
7655
|
+
}
|
|
7656
|
+
try {
|
|
7657
|
+
return schema.parse(params);
|
|
7658
|
+
}
|
|
7659
|
+
catch (error) {
|
|
7660
|
+
if (error instanceof ZodError) {
|
|
7661
|
+
const message = `Validation failed: ${error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ')}`;
|
|
7662
|
+
if (config?.validationStrict) {
|
|
7663
|
+
throw new ValidationError(message);
|
|
7664
|
+
}
|
|
7665
|
+
else {
|
|
7666
|
+
console.warn(`[Validation Warning] ${message}`);
|
|
7667
|
+
return params;
|
|
7668
|
+
}
|
|
7669
|
+
}
|
|
7670
|
+
throw error;
|
|
7671
|
+
}
|
|
7672
|
+
}
|
|
7673
|
+
/**
|
|
7674
|
+
* Create a number schema with min/max constraints.
|
|
7675
|
+
*/
|
|
7676
|
+
function numberSchema(min, max, defaultVal) {
|
|
7677
|
+
let schema = number();
|
|
7678
|
+
if (min !== undefined)
|
|
7679
|
+
schema = schema.min(min);
|
|
7680
|
+
if (max !== undefined)
|
|
7681
|
+
schema = schema.max(max);
|
|
7682
|
+
if (defaultVal !== undefined) {
|
|
7683
|
+
// Use .default() which automatically makes the field optional
|
|
7684
|
+
// This avoids the ZodUnion issue with .optional().default()
|
|
7685
|
+
schema = schema.default(defaultVal);
|
|
7686
|
+
}
|
|
7687
|
+
return schema;
|
|
7688
|
+
}
|
|
7689
|
+
/**
|
|
7690
|
+
* Create a string schema with length constraints.
|
|
7691
|
+
*/
|
|
7692
|
+
function stringSchema(min, max, defaultVal) {
|
|
7693
|
+
let schema = string();
|
|
7694
|
+
if (min !== undefined)
|
|
7695
|
+
schema = schema.min(min);
|
|
7696
|
+
if (max !== undefined)
|
|
7697
|
+
schema = schema.max(max);
|
|
7698
|
+
if (defaultVal !== undefined) {
|
|
7699
|
+
// Use .default() which automatically makes the field optional
|
|
7700
|
+
// This avoids the ZodUnion issue with .optional().default()
|
|
7701
|
+
schema = schema.default(defaultVal);
|
|
7702
|
+
}
|
|
7703
|
+
return schema;
|
|
7704
|
+
}
|
|
7705
|
+
|
|
7706
|
+
/**
|
|
7707
|
+
* URL utility functions for portal URL manipulation.
|
|
7708
|
+
*
|
|
7709
|
+
* Generated - do not edit directly.
|
|
7710
|
+
*/
|
|
7711
|
+
/**
|
|
7712
|
+
* Append theme parameters to a portal URL.
|
|
7713
|
+
* @param baseUrl The base portal URL (may already have query parameters)
|
|
7714
|
+
* @param theme The theme configuration (preset string or custom object)
|
|
7715
|
+
* @returns The portal URL with theme parameters appended
|
|
7716
|
+
*/
|
|
7717
|
+
function appendThemeToURL(baseUrl, theme) {
|
|
7718
|
+
if (!theme) {
|
|
7719
|
+
return baseUrl;
|
|
7720
|
+
}
|
|
7721
|
+
try {
|
|
7722
|
+
const url = new URL(baseUrl);
|
|
7723
|
+
if (typeof theme === 'string') {
|
|
7724
|
+
// Preset theme
|
|
7725
|
+
url.searchParams.set('theme', theme);
|
|
7726
|
+
}
|
|
7727
|
+
else if (theme.preset) {
|
|
7728
|
+
// Preset theme from object
|
|
7729
|
+
url.searchParams.set('theme', theme.preset);
|
|
7730
|
+
}
|
|
7731
|
+
else if (theme.custom) {
|
|
7732
|
+
// Custom theme
|
|
7733
|
+
const encodedTheme = btoa(JSON.stringify(theme.custom));
|
|
7734
|
+
url.searchParams.set('theme', 'custom');
|
|
7735
|
+
url.searchParams.set('themeObject', encodedTheme);
|
|
7736
|
+
}
|
|
7737
|
+
return url.toString();
|
|
7738
|
+
}
|
|
7739
|
+
catch (error) {
|
|
7740
|
+
// If URL parsing fails, return original URL
|
|
7741
|
+
return baseUrl;
|
|
7742
|
+
}
|
|
7743
|
+
}
|
|
7744
|
+
/**
|
|
7745
|
+
* Append broker filter parameters to a portal URL.
|
|
7746
|
+
* @param baseUrl The base portal URL (may already have query parameters)
|
|
7747
|
+
* @param brokerNames Array of broker names/IDs to filter by
|
|
7748
|
+
* @returns The portal URL with broker filter parameters appended
|
|
7749
|
+
*/
|
|
7750
|
+
function appendBrokerFilterToURL(baseUrl, brokerNames) {
|
|
7751
|
+
if (!brokerNames || brokerNames.length === 0) {
|
|
7752
|
+
return baseUrl;
|
|
7753
|
+
}
|
|
7754
|
+
try {
|
|
7755
|
+
const url = new URL(baseUrl);
|
|
7756
|
+
const encodedBrokers = btoa(JSON.stringify(brokerNames));
|
|
7757
|
+
url.searchParams.set('brokers', encodedBrokers);
|
|
7758
|
+
return url.toString();
|
|
7759
|
+
}
|
|
7760
|
+
catch (error) {
|
|
7761
|
+
// If URL parsing fails, return original URL
|
|
7762
|
+
return baseUrl;
|
|
7763
|
+
}
|
|
7764
|
+
}
|
|
7765
|
+
|
|
7766
|
+
/**
|
|
7767
|
+
* EventEmitter utility for Client SDK.
|
|
7768
|
+
*
|
|
7769
|
+
* Generated - do not edit directly.
|
|
7770
|
+
*/
|
|
7771
|
+
class EventEmitter {
|
|
7772
|
+
constructor() {
|
|
7773
|
+
this.events = new Map();
|
|
7774
|
+
}
|
|
7775
|
+
on(event, callback) {
|
|
7776
|
+
if (!this.events.has(event)) {
|
|
7777
|
+
this.events.set(event, new Set());
|
|
7778
|
+
}
|
|
7779
|
+
this.events.get(event).add(callback);
|
|
7780
|
+
}
|
|
7781
|
+
off(event, callback) {
|
|
7782
|
+
if (this.events.has(event)) {
|
|
7783
|
+
this.events.get(event).delete(callback);
|
|
7784
|
+
}
|
|
7785
|
+
}
|
|
7786
|
+
once(event, callback) {
|
|
7787
|
+
const onceCallback = (...args) => {
|
|
7788
|
+
callback(...args);
|
|
7789
|
+
this.off(event, onceCallback);
|
|
7790
|
+
};
|
|
7791
|
+
this.on(event, onceCallback);
|
|
7792
|
+
}
|
|
7793
|
+
emit(event, ...args) {
|
|
7794
|
+
if (this.events.has(event)) {
|
|
7795
|
+
this.events.get(event).forEach(callback => {
|
|
7796
|
+
try {
|
|
7797
|
+
callback(...args);
|
|
7798
|
+
}
|
|
7799
|
+
catch (error) {
|
|
7800
|
+
// Silently handle errors in event handlers
|
|
7801
|
+
console.error(`Error in event handler for ${event}:`, error);
|
|
7802
|
+
}
|
|
7803
|
+
});
|
|
4671
7804
|
}
|
|
4672
7805
|
}
|
|
4673
7806
|
removeAllListeners(event) {
|
|
@@ -5282,54 +8415,6 @@ const SessionApiFp = function (configuration) {
|
|
|
5282
8415
|
},
|
|
5283
8416
|
};
|
|
5284
8417
|
};
|
|
5285
|
-
/**
|
|
5286
|
-
* SessionApi - factory interface
|
|
5287
|
-
*/
|
|
5288
|
-
const SessionApiFactory = function (configuration, basePath, axios) {
|
|
5289
|
-
const localVarFp = SessionApiFp(configuration);
|
|
5290
|
-
return {
|
|
5291
|
-
/**
|
|
5292
|
-
* Get a portal URL with token for a session. The session must be in ACTIVE or AUTHENTICATING state and the request must come from the same device that initiated the session. Device info is automatically validated from the request.
|
|
5293
|
-
* @summary Get Portal Url
|
|
5294
|
-
* @param {SessionApiGetPortalUrlApiV1SessionPortalGetRequest} requestParameters Request parameters.
|
|
5295
|
-
* @param {*} [options] Override http request option.
|
|
5296
|
-
* @throws {RequiredError}
|
|
5297
|
-
*/
|
|
5298
|
-
getPortalUrlApiV1SessionPortalGet(requestParameters, options) {
|
|
5299
|
-
return localVarFp.getPortalUrlApiV1SessionPortalGet(requestParameters.sessionId, options).then((request) => request(axios, basePath));
|
|
5300
|
-
},
|
|
5301
|
-
/**
|
|
5302
|
-
* Get user information and fresh tokens for a completed session. This endpoint is designed for server SDKs to retrieve user information and authentication tokens after successful OTP verification. Security: - Requires valid session in ACTIVE state - Validates device fingerprint binding - Generates fresh tokens (not returning stored ones) - Only accessible to authenticated sessions with user_id - Validates that header session_id matches path session_id
|
|
5303
|
-
* @summary Get Session User
|
|
5304
|
-
* @param {SessionApiGetSessionUserApiV1SessionSessionIdUserGetRequest} requestParameters Request parameters.
|
|
5305
|
-
* @param {*} [options] Override http request option.
|
|
5306
|
-
* @throws {RequiredError}
|
|
5307
|
-
*/
|
|
5308
|
-
getSessionUserApiV1SessionSessionIdUserGet(requestParameters, options) {
|
|
5309
|
-
return localVarFp.getSessionUserApiV1SessionSessionIdUserGet(requestParameters.sessionId, requestParameters.xSessionId, options).then((request) => request(axios, basePath));
|
|
5310
|
-
},
|
|
5311
|
-
/**
|
|
5312
|
-
* Initialize a new session with company API key.
|
|
5313
|
-
* @summary Init Session
|
|
5314
|
-
* @param {SessionApiInitSessionApiV1SessionInitPostRequest} requestParameters Request parameters.
|
|
5315
|
-
* @param {*} [options] Override http request option.
|
|
5316
|
-
* @throws {RequiredError}
|
|
5317
|
-
*/
|
|
5318
|
-
initSessionApiV1SessionInitPost(requestParameters, options) {
|
|
5319
|
-
return localVarFp.initSessionApiV1SessionInitPost(requestParameters.xApiKey, options).then((request) => request(axios, basePath));
|
|
5320
|
-
},
|
|
5321
|
-
/**
|
|
5322
|
-
* Start a session with a one-time token.
|
|
5323
|
-
* @summary Start Session
|
|
5324
|
-
* @param {SessionApiStartSessionApiV1SessionStartPostRequest} requestParameters Request parameters.
|
|
5325
|
-
* @param {*} [options] Override http request option.
|
|
5326
|
-
* @throws {RequiredError}
|
|
5327
|
-
*/
|
|
5328
|
-
startSessionApiV1SessionStartPost(requestParameters, options) {
|
|
5329
|
-
return localVarFp.startSessionApiV1SessionStartPost(requestParameters.oneTimeToken, requestParameters.sessionStartRequest, options).then((request) => request(axios, basePath));
|
|
5330
|
-
},
|
|
5331
|
-
};
|
|
5332
|
-
};
|
|
5333
8418
|
/**
|
|
5334
8419
|
* SessionApi - object-oriented interface
|
|
5335
8420
|
*/
|
|
@@ -6214,132 +9299,6 @@ const BrokersApiFp = function (configuration) {
|
|
|
6214
9299
|
},
|
|
6215
9300
|
};
|
|
6216
9301
|
};
|
|
6217
|
-
/**
|
|
6218
|
-
* BrokersApi - factory interface
|
|
6219
|
-
*/
|
|
6220
|
-
const BrokersApiFactory = function (configuration, basePath, axios) {
|
|
6221
|
-
const localVarFp = BrokersApiFp(configuration);
|
|
6222
|
-
return {
|
|
6223
|
-
/**
|
|
6224
|
-
* Remove a company\'s access to a broker connection. If the company is the only one with access, the entire connection is deleted. If other companies have access, only the company\'s access is removed.
|
|
6225
|
-
* @summary Disconnect Company From Broker
|
|
6226
|
-
* @param {BrokersApiDisconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDeleteRequest} requestParameters Request parameters.
|
|
6227
|
-
* @param {*} [options] Override http request option.
|
|
6228
|
-
* @throws {RequiredError}
|
|
6229
|
-
*/
|
|
6230
|
-
disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete(requestParameters, options) {
|
|
6231
|
-
return localVarFp.disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete(requestParameters.connectionId, options).then((request) => request(axios, basePath));
|
|
6232
|
-
},
|
|
6233
|
-
/**
|
|
6234
|
-
* Get accounts for all authorized broker connections. This endpoint is accessible from the portal and uses session-only authentication. Returns accounts from connections the company has read access to.
|
|
6235
|
-
* @summary Get Accounts
|
|
6236
|
-
* @param {BrokersApiGetAccountsApiV1BrokersDataAccountsGetRequest} requestParameters Request parameters.
|
|
6237
|
-
* @param {*} [options] Override http request option.
|
|
6238
|
-
* @throws {RequiredError}
|
|
6239
|
-
*/
|
|
6240
|
-
getAccountsApiV1BrokersDataAccountsGet(requestParameters = {}, options) {
|
|
6241
|
-
return localVarFp.getAccountsApiV1BrokersDataAccountsGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountType, requestParameters.status, requestParameters.currency, requestParameters.limit, requestParameters.offset, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
|
|
6242
|
-
},
|
|
6243
|
-
/**
|
|
6244
|
-
* Get balances for all authorized broker connections. This endpoint is accessible from the portal and uses session-only authentication. Returns balances from connections the company has read access to.
|
|
6245
|
-
* @summary Get Balances
|
|
6246
|
-
* @param {BrokersApiGetBalancesApiV1BrokersDataBalancesGetRequest} requestParameters Request parameters.
|
|
6247
|
-
* @param {*} [options] Override http request option.
|
|
6248
|
-
* @throws {RequiredError}
|
|
6249
|
-
*/
|
|
6250
|
-
getBalancesApiV1BrokersDataBalancesGet(requestParameters = {}, options) {
|
|
6251
|
-
return localVarFp.getBalancesApiV1BrokersDataBalancesGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountId, requestParameters.isEndOfDaySnapshot, requestParameters.limit, requestParameters.offset, requestParameters.balanceCreatedAfter, requestParameters.balanceCreatedBefore, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
|
|
6252
|
-
},
|
|
6253
|
-
/**
|
|
6254
|
-
* Get all available brokers. This is a fast operation that returns a cached list of available brokers. The list is loaded once at startup and never changes during runtime. Returns ------- FinaticResponse[list[BrokerInfo]] list of available brokers with their metadata.
|
|
6255
|
-
* @summary Get Brokers
|
|
6256
|
-
* @param {*} [options] Override http request option.
|
|
6257
|
-
* @throws {RequiredError}
|
|
6258
|
-
*/
|
|
6259
|
-
getBrokersApiV1BrokersGet(options) {
|
|
6260
|
-
return localVarFp.getBrokersApiV1BrokersGet(options).then((request) => request(axios, basePath));
|
|
6261
|
-
},
|
|
6262
|
-
/**
|
|
6263
|
-
* Get order events for a specific order. This endpoint returns all lifecycle events for the specified order.
|
|
6264
|
-
* @summary Get Order Events
|
|
6265
|
-
* @param {BrokersApiGetOrderEventsApiV1BrokersDataOrdersOrderIdEventsGetRequest} requestParameters Request parameters.
|
|
6266
|
-
* @param {*} [options] Override http request option.
|
|
6267
|
-
* @throws {RequiredError}
|
|
6268
|
-
*/
|
|
6269
|
-
getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet(requestParameters, options) {
|
|
6270
|
-
return localVarFp.getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet(requestParameters.orderId, requestParameters.connectionId, requestParameters.limit, requestParameters.offset, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
|
|
6271
|
-
},
|
|
6272
|
-
/**
|
|
6273
|
-
* Get order fills for a specific order. This endpoint returns all execution fills for the specified order.
|
|
6274
|
-
* @summary Get Order Fills
|
|
6275
|
-
* @param {BrokersApiGetOrderFillsApiV1BrokersDataOrdersOrderIdFillsGetRequest} requestParameters Request parameters.
|
|
6276
|
-
* @param {*} [options] Override http request option.
|
|
6277
|
-
* @throws {RequiredError}
|
|
6278
|
-
*/
|
|
6279
|
-
getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet(requestParameters, options) {
|
|
6280
|
-
return localVarFp.getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet(requestParameters.orderId, requestParameters.connectionId, requestParameters.limit, requestParameters.offset, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
|
|
6281
|
-
},
|
|
6282
|
-
/**
|
|
6283
|
-
* Get order groups. This endpoint returns order groups that contain multiple orders.
|
|
6284
|
-
* @summary Get Order Groups
|
|
6285
|
-
* @param {BrokersApiGetOrderGroupsApiV1BrokersDataOrdersGroupsGetRequest} requestParameters Request parameters.
|
|
6286
|
-
* @param {*} [options] Override http request option.
|
|
6287
|
-
* @throws {RequiredError}
|
|
6288
|
-
*/
|
|
6289
|
-
getOrderGroupsApiV1BrokersDataOrdersGroupsGet(requestParameters = {}, options) {
|
|
6290
|
-
return localVarFp.getOrderGroupsApiV1BrokersDataOrdersGroupsGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.limit, requestParameters.offset, requestParameters.createdAfter, requestParameters.createdBefore, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
|
|
6291
|
-
},
|
|
6292
|
-
/**
|
|
6293
|
-
* Get orders for all authorized broker connections. This endpoint is accessible from the portal and uses session-only authentication. Returns orders from connections the company has read access to.
|
|
6294
|
-
* @summary Get Orders
|
|
6295
|
-
* @param {BrokersApiGetOrdersApiV1BrokersDataOrdersGetRequest} requestParameters Request parameters.
|
|
6296
|
-
* @param {*} [options] Override http request option.
|
|
6297
|
-
* @throws {RequiredError}
|
|
6298
|
-
*/
|
|
6299
|
-
getOrdersApiV1BrokersDataOrdersGet(requestParameters = {}, options) {
|
|
6300
|
-
return localVarFp.getOrdersApiV1BrokersDataOrdersGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountId, requestParameters.symbol, requestParameters.orderStatus, requestParameters.side, requestParameters.assetType, requestParameters.limit, requestParameters.offset, requestParameters.createdAfter, requestParameters.createdBefore, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
|
|
6301
|
-
},
|
|
6302
|
-
/**
|
|
6303
|
-
* Get position lot fills for a specific lot. This endpoint returns all fills associated with a specific position lot.
|
|
6304
|
-
* @summary Get Position Lot Fills
|
|
6305
|
-
* @param {BrokersApiGetPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGetRequest} requestParameters Request parameters.
|
|
6306
|
-
* @param {*} [options] Override http request option.
|
|
6307
|
-
* @throws {RequiredError}
|
|
6308
|
-
*/
|
|
6309
|
-
getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet(requestParameters, options) {
|
|
6310
|
-
return localVarFp.getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet(requestParameters.lotId, requestParameters.connectionId, requestParameters.limit, requestParameters.offset, options).then((request) => request(axios, basePath));
|
|
6311
|
-
},
|
|
6312
|
-
/**
|
|
6313
|
-
* Get position lots (tax lots for positions). This endpoint returns tax lots for positions, which are used for tax reporting. Each lot tracks when a position was opened/closed and at what prices.
|
|
6314
|
-
* @summary Get Position Lots
|
|
6315
|
-
* @param {BrokersApiGetPositionLotsApiV1BrokersDataPositionsLotsGetRequest} requestParameters Request parameters.
|
|
6316
|
-
* @param {*} [options] Override http request option.
|
|
6317
|
-
* @throws {RequiredError}
|
|
6318
|
-
*/
|
|
6319
|
-
getPositionLotsApiV1BrokersDataPositionsLotsGet(requestParameters = {}, options) {
|
|
6320
|
-
return localVarFp.getPositionLotsApiV1BrokersDataPositionsLotsGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountId, requestParameters.symbol, requestParameters.positionId, requestParameters.limit, requestParameters.offset, options).then((request) => request(axios, basePath));
|
|
6321
|
-
},
|
|
6322
|
-
/**
|
|
6323
|
-
* Get positions for all authorized broker connections. This endpoint is accessible from the portal and uses session-only authentication. Returns positions from connections the company has read access to.
|
|
6324
|
-
* @summary Get Positions
|
|
6325
|
-
* @param {BrokersApiGetPositionsApiV1BrokersDataPositionsGetRequest} requestParameters Request parameters.
|
|
6326
|
-
* @param {*} [options] Override http request option.
|
|
6327
|
-
* @throws {RequiredError}
|
|
6328
|
-
*/
|
|
6329
|
-
getPositionsApiV1BrokersDataPositionsGet(requestParameters = {}, options) {
|
|
6330
|
-
return localVarFp.getPositionsApiV1BrokersDataPositionsGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountId, requestParameters.symbol, requestParameters.side, requestParameters.assetType, requestParameters.positionStatus, requestParameters.limit, requestParameters.offset, requestParameters.updatedAfter, requestParameters.updatedBefore, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
|
|
6331
|
-
},
|
|
6332
|
-
/**
|
|
6333
|
-
* List all broker connections for the current user with permissions. This endpoint is accessible from the portal and uses session-only authentication. Returns connections that the user has any permissions for, including the current company\'s permissions (read/write) for each connection.
|
|
6334
|
-
* @summary List Broker Connections
|
|
6335
|
-
* @param {*} [options] Override http request option.
|
|
6336
|
-
* @throws {RequiredError}
|
|
6337
|
-
*/
|
|
6338
|
-
listBrokerConnectionsApiV1BrokersConnectionsGet(options) {
|
|
6339
|
-
return localVarFp.listBrokerConnectionsApiV1BrokersConnectionsGet(options).then((request) => request(axios, basePath));
|
|
6340
|
-
},
|
|
6341
|
-
};
|
|
6342
|
-
};
|
|
6343
9302
|
/**
|
|
6344
9303
|
* BrokersApi - object-oriented interface
|
|
6345
9304
|
*/
|
|
@@ -6576,34 +9535,6 @@ const CompanyApiFp = function (configuration) {
|
|
|
6576
9535
|
},
|
|
6577
9536
|
};
|
|
6578
9537
|
};
|
|
6579
|
-
/**
|
|
6580
|
-
* CompanyApi - factory interface
|
|
6581
|
-
*/
|
|
6582
|
-
const CompanyApiFactory = function (configuration, basePath, axios) {
|
|
6583
|
-
const localVarFp = CompanyApiFp(configuration);
|
|
6584
|
-
return {
|
|
6585
|
-
/**
|
|
6586
|
-
* Get public company details by ID (no user check, no sensitive data).
|
|
6587
|
-
* @summary Get Company
|
|
6588
|
-
* @param {CompanyApiGetCompanyApiV1CompanyCompanyIdGetRequest} requestParameters Request parameters.
|
|
6589
|
-
* @param {*} [options] Override http request option.
|
|
6590
|
-
* @throws {RequiredError}
|
|
6591
|
-
*/
|
|
6592
|
-
getCompanyApiV1CompanyCompanyIdGet(requestParameters, options) {
|
|
6593
|
-
return localVarFp.getCompanyApiV1CompanyCompanyIdGet(requestParameters.companyId, options).then((request) => request(axios, basePath));
|
|
6594
|
-
},
|
|
6595
|
-
/**
|
|
6596
|
-
* Get public company details by ID (no user check, no sensitive data).
|
|
6597
|
-
* @summary Get Company
|
|
6598
|
-
* @param {CompanyApiGetCompanyApiV1CompanyCompanyIdGet0Request} requestParameters Request parameters.
|
|
6599
|
-
* @param {*} [options] Override http request option.
|
|
6600
|
-
* @throws {RequiredError}
|
|
6601
|
-
*/
|
|
6602
|
-
getCompanyApiV1CompanyCompanyIdGet_1(requestParameters, options) {
|
|
6603
|
-
return localVarFp.getCompanyApiV1CompanyCompanyIdGet_1(requestParameters.companyId, options).then((request) => request(axios, basePath));
|
|
6604
|
-
},
|
|
6605
|
-
};
|
|
6606
|
-
};
|
|
6607
9538
|
/**
|
|
6608
9539
|
* CompanyApi - object-oriented interface
|
|
6609
9540
|
*/
|
|
@@ -9083,5 +12014,5 @@ class FinaticConnect extends FinaticConnect$1 {
|
|
|
9083
12014
|
// Marker to verify custom class is being used
|
|
9084
12015
|
FinaticConnect.__CUSTOM_CLASS__ = true;
|
|
9085
12016
|
|
|
9086
|
-
export { AccountStatus, ApiError, BrokerDataAccountTypeEnum, BrokerDataAssetTypeEnum, BrokerDataOrderSideEnum, BrokerDataPositionStatusEnum,
|
|
12017
|
+
export { AccountStatus, ApiError, BrokerDataAccountTypeEnum, BrokerDataAssetTypeEnum, BrokerDataOrderSideEnum, BrokerDataPositionStatusEnum, BrokersWrapper, CompanyWrapper, Configuration, EventEmitter, FDXAccountStatus, FDXAccountType, FDXAssetType, FDXBalanceType, FDXOrderClass, FDXOrderEventType, FDXOrderGroupType, FDXOrderSide, FDXOrderStatus, FDXOrderType, FDXPositionSide, FDXPositionStatus, FDXSecurityIdType, FDXTimeInForce, FinaticConnect, FinaticError, PaginatedData, SessionStatus, SessionWrapper, ValidationError, addErrorInterceptor, addRequestInterceptor, addResponseInterceptor, appendBrokerFilterToURL, appendThemeToURL, applyErrorInterceptors, applyRequestInterceptors, applyResponseInterceptors, coerceEnumValue, convertToPlainObject, defaultConfig, generateCacheKey, generateRequestId, getCache, getConfig, getLogger, handleError, numberSchema, retryApiCall, stringSchema, unwrapAxiosResponse, validateParams };
|
|
9087
12018
|
//# sourceMappingURL=index.mjs.map
|