@temporary-name/server 1.9.3-alpha.03e17aa3340f4b261a549bf9e3fe948b084e2309 → 1.9.3-alpha.121f1a14eceb7f2aa23c6993c2adce0ccca377db
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/adapters/aws-lambda/index.mjs +2 -5
- package/dist/adapters/fetch/index.mjs +2 -5
- package/dist/adapters/node/index.mjs +2 -5
- package/dist/adapters/standard/index.mjs +2 -5
- package/dist/index.d.mts +938 -217
- package/dist/index.d.ts +938 -217
- package/dist/index.mjs +1675 -94
- package/dist/shared/{server.BKh8I1Ny.mjs → server.BZtKt8i8.mjs} +7 -45
- package/dist/shared/{server.DLsti1Pv.mjs → server.CMTfy2UB.mjs} +1 -1
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
|
-
import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, getContractRouter } from '@temporary-name/contract';
|
|
2
|
-
export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
|
|
3
1
|
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
4
2
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
|
-
import {
|
|
6
|
-
export {
|
|
3
|
+
import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, ContractProcedure, getContractRouter } from '@temporary-name/contract';
|
|
4
|
+
export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
|
|
5
|
+
import { c as createProcedureClient, i as isLazy, g as getLazyMeta, l as lazy$1, u as unlazy } from './shared/server.BZtKt8i8.mjs';
|
|
6
|
+
export { L as LAZY_SYMBOL, a as createORPCErrorConstructorMap, m as mergeCurrentContext, b as middlewareOutputFn } from './shared/server.BZtKt8i8.mjs';
|
|
7
|
+
import * as core from 'zod/v4/core';
|
|
8
|
+
import { $ZodError, util, _overwrite, _regex, _includes, _startsWith, _endsWith, _minLength, _maxLength, _length, _lowercase, _uppercase, _trim, _normalize, _toLowerCase, _toUpperCase, _gt, _gte, _lt, _lte, _multipleOf } from 'zod/v4/core';
|
|
9
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
7
10
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
function isStartWithMiddlewares(middlewares, compare) {
|
|
13
|
+
if (compare.length > middlewares.length) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
17
|
+
if (compare[i] === void 0) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (middlewares[i] !== compare[i]) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
function mergeMiddlewares(first, second, options) {
|
|
27
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
28
|
+
return second;
|
|
29
|
+
}
|
|
30
|
+
return [...first, ...second];
|
|
31
|
+
}
|
|
32
|
+
function addMiddleware(middlewares, addition) {
|
|
33
|
+
return [...middlewares, addition];
|
|
34
|
+
}
|
|
11
35
|
|
|
12
36
|
function decorateMiddleware(middleware) {
|
|
13
37
|
const decorated = ((...args) => middleware(...args));
|
|
@@ -45,30 +69,6 @@ function decorateMiddleware(middleware) {
|
|
|
45
69
|
return decorated;
|
|
46
70
|
}
|
|
47
71
|
|
|
48
|
-
function isStartWithMiddlewares(middlewares, compare) {
|
|
49
|
-
if (compare.length > middlewares.length) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
53
|
-
if (compare[i] === void 0) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
if (middlewares[i] !== compare[i]) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
function mergeMiddlewares(first, second, options) {
|
|
63
|
-
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
64
|
-
return second;
|
|
65
|
-
}
|
|
66
|
-
return [...first, ...second];
|
|
67
|
-
}
|
|
68
|
-
function addMiddleware(middlewares, addition) {
|
|
69
|
-
return [...middlewares, addition];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
72
|
class Procedure {
|
|
73
73
|
/**
|
|
74
74
|
* This property holds the defined options.
|
|
@@ -180,7 +180,7 @@ function getRouter(router, path) {
|
|
|
180
180
|
}
|
|
181
181
|
const lazied = current;
|
|
182
182
|
const rest = path.slice(i);
|
|
183
|
-
return lazy(async () => {
|
|
183
|
+
return lazy$1(async () => {
|
|
184
184
|
const unwrapped = await unlazy(lazied);
|
|
185
185
|
const next = getRouter(unwrapped.default, rest);
|
|
186
186
|
return unlazy(next);
|
|
@@ -204,7 +204,7 @@ function enhanceRouter(router, options) {
|
|
|
204
204
|
if (isLazy(router)) {
|
|
205
205
|
const laziedMeta = getLazyMeta(router);
|
|
206
206
|
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
|
207
|
-
const enhanced2 = lazy(
|
|
207
|
+
const enhanced2 = lazy$1(
|
|
208
208
|
async () => {
|
|
209
209
|
const { default: unlaziedRouter } = await unlazy(router);
|
|
210
210
|
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
|
@@ -295,85 +295,1606 @@ async function unlazyRouter(router) {
|
|
|
295
295
|
return unlazied;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
this["~orpc"] = def;
|
|
298
|
+
const ZodISODateTime = /* @__PURE__ */ core.$constructor(
|
|
299
|
+
"ZodISODateTime",
|
|
300
|
+
(inst, def) => {
|
|
301
|
+
const coreInit = core.$ZodISODateTime.init;
|
|
302
|
+
coreInit(inst, def);
|
|
303
|
+
ZodStringFormat.init(inst, def);
|
|
305
304
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
305
|
+
);
|
|
306
|
+
function datetime(params) {
|
|
307
|
+
return core._isoDateTime(ZodISODateTime, params);
|
|
308
|
+
}
|
|
309
|
+
const ZodISODate = /* @__PURE__ */ core.$constructor(
|
|
310
|
+
"ZodISODate",
|
|
311
|
+
(inst, def) => {
|
|
312
|
+
const coreInit = core.$ZodISODate.init;
|
|
313
|
+
coreInit(inst, def);
|
|
314
|
+
ZodStringFormat.init(inst, def);
|
|
313
315
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
316
|
+
);
|
|
317
|
+
function date$1(params) {
|
|
318
|
+
return core._isoDate(ZodISODate, params);
|
|
319
|
+
}
|
|
320
|
+
const ZodISOTime = /* @__PURE__ */ core.$constructor(
|
|
321
|
+
"ZodISOTime",
|
|
322
|
+
(inst, def) => {
|
|
323
|
+
const coreInit = core.$ZodISOTime.init;
|
|
324
|
+
coreInit(inst, def);
|
|
325
|
+
ZodStringFormat.init(inst, def);
|
|
326
|
+
}
|
|
327
|
+
);
|
|
328
|
+
function time(params) {
|
|
329
|
+
return core._isoTime(ZodISOTime, params);
|
|
330
|
+
}
|
|
331
|
+
const ZodISODuration = /* @__PURE__ */ core.$constructor(
|
|
332
|
+
"ZodISODuration",
|
|
333
|
+
(inst, def) => {
|
|
334
|
+
const coreInit = core.$ZodISODuration.init;
|
|
335
|
+
coreInit(inst, def);
|
|
336
|
+
ZodStringFormat.init(inst, def);
|
|
337
|
+
}
|
|
338
|
+
);
|
|
339
|
+
function duration(params) {
|
|
340
|
+
return core._isoDuration(ZodISODuration, params);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const initializer = (inst, issues) => {
|
|
344
|
+
$ZodError.init(inst, issues);
|
|
345
|
+
inst.name = "ZodError";
|
|
346
|
+
Object.defineProperties(inst, {
|
|
347
|
+
format: {
|
|
348
|
+
value: (mapper) => core.formatError(inst, mapper)
|
|
349
|
+
// enumerable: false,
|
|
350
|
+
},
|
|
351
|
+
flatten: {
|
|
352
|
+
value: (mapper) => core.flattenError(inst, mapper)
|
|
353
|
+
// enumerable: false,
|
|
354
|
+
},
|
|
355
|
+
addIssue: {
|
|
356
|
+
value: (issue) => {
|
|
357
|
+
inst.issues.push(issue);
|
|
358
|
+
inst.message = JSON.stringify(inst.issues, core.util.jsonStringifyReplacer, 2);
|
|
359
|
+
}
|
|
360
|
+
// enumerable: false,
|
|
361
|
+
},
|
|
362
|
+
addIssues: {
|
|
363
|
+
value: (issues2) => {
|
|
364
|
+
inst.issues.push(...issues2);
|
|
365
|
+
inst.message = JSON.stringify(inst.issues, core.util.jsonStringifyReplacer, 2);
|
|
366
|
+
}
|
|
367
|
+
// enumerable: false,
|
|
368
|
+
},
|
|
369
|
+
isEmpty: {
|
|
370
|
+
get() {
|
|
371
|
+
return inst.issues.length === 0;
|
|
372
|
+
}
|
|
373
|
+
// enumerable: false,
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
core.$constructor("ZodError", initializer);
|
|
378
|
+
const ZodRealError = core.$constructor("ZodError", initializer, {
|
|
379
|
+
Parent: Error
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
const parse = /* @__PURE__ */ core._parse(ZodRealError);
|
|
383
|
+
const parseAsync = /* @__PURE__ */ core._parseAsync(ZodRealError);
|
|
384
|
+
const safeParse = /* @__PURE__ */ core._safeParse(ZodRealError);
|
|
385
|
+
const safeParseAsync = /* @__PURE__ */ core._safeParseAsync(ZodRealError);
|
|
386
|
+
const encode = /* @__PURE__ */ core._encode(ZodRealError);
|
|
387
|
+
const decode = /* @__PURE__ */ core._decode(ZodRealError);
|
|
388
|
+
const encodeAsync = /* @__PURE__ */ core._encodeAsync(ZodRealError);
|
|
389
|
+
const decodeAsync = /* @__PURE__ */ core._decodeAsync(ZodRealError);
|
|
390
|
+
const safeEncode = /* @__PURE__ */ core._safeEncode(ZodRealError);
|
|
391
|
+
const safeDecode = /* @__PURE__ */ core._safeDecode(ZodRealError);
|
|
392
|
+
const safeEncodeAsync = /* @__PURE__ */ core._safeEncodeAsync(ZodRealError);
|
|
393
|
+
const safeDecodeAsync = /* @__PURE__ */ core._safeDecodeAsync(ZodRealError);
|
|
394
|
+
|
|
395
|
+
const gatingContext = new AsyncLocalStorage();
|
|
396
|
+
function isGateIssueRaw(issue) {
|
|
397
|
+
return issue.code === "invalid_type" && issue.expected === "never" && issue.inst instanceof ZodGate;
|
|
398
|
+
}
|
|
399
|
+
function isGateIssue(issue) {
|
|
400
|
+
return issue.code === "invalid_type" && issue.expected === "never" && issue.path?.length === 0;
|
|
401
|
+
}
|
|
402
|
+
const ZodGate = /* @__PURE__ */ core.$constructor("ZodGate", (inst, def) => {
|
|
403
|
+
const coreInit = core.$ZodOptional.init;
|
|
404
|
+
coreInit(inst, def);
|
|
405
|
+
KrustyType.init(inst, def);
|
|
406
|
+
inst._zod.parse = (payload, ctx) => {
|
|
407
|
+
const gateEnabled = gatingContext.getStore()?.(def.gateName);
|
|
408
|
+
if (gateEnabled) {
|
|
409
|
+
return def.innerType._zod.run(payload, ctx);
|
|
410
|
+
} else if (payload.value !== void 0) {
|
|
411
|
+
payload.issues.push({
|
|
412
|
+
expected: "never",
|
|
413
|
+
code: "invalid_type",
|
|
414
|
+
input: payload.value,
|
|
415
|
+
inst
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
return payload;
|
|
419
|
+
};
|
|
420
|
+
});
|
|
421
|
+
function gate(innerType, gateName) {
|
|
422
|
+
return new ZodGate({
|
|
423
|
+
type: "optional",
|
|
424
|
+
innerType,
|
|
425
|
+
gateName
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function handleGating(payload) {
|
|
430
|
+
for (let i = 0; i < payload.issues.length; i++) {
|
|
431
|
+
const issue = payload.issues[i];
|
|
432
|
+
if (issue?.code === "invalid_union") {
|
|
433
|
+
const newErrors = issue.errors.filter((innerIssues) => !innerIssues.some(isGateIssue));
|
|
434
|
+
issue.errors.splice(0, Infinity, ...newErrors);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return payload;
|
|
438
|
+
}
|
|
439
|
+
const ZodUnion = /* @__PURE__ */ core.$constructor(
|
|
440
|
+
"ZodUnion",
|
|
441
|
+
(inst, def) => {
|
|
442
|
+
const coreInit = core.$ZodUnion.init;
|
|
443
|
+
coreInit(inst, def);
|
|
444
|
+
KrustyType.init(inst, def);
|
|
445
|
+
inst.options = def.options;
|
|
446
|
+
const origParse = inst._zod.parse;
|
|
447
|
+
inst._zod.parse = (payload, ctx) => {
|
|
448
|
+
const res = origParse(payload, ctx);
|
|
449
|
+
if (res instanceof Promise) {
|
|
450
|
+
return res.then((r) => handleGating(r));
|
|
451
|
+
} else {
|
|
452
|
+
return handleGating(res);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
);
|
|
457
|
+
function union(options, params) {
|
|
458
|
+
return new ZodUnion({
|
|
459
|
+
type: "union",
|
|
460
|
+
options,
|
|
461
|
+
...util.normalizeParams(params)
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const ZodDiscriminatedUnion = /* @__PURE__ */ core.$constructor("ZodDiscriminatedUnion", (inst, def) => {
|
|
465
|
+
ZodUnion.init(inst, def);
|
|
466
|
+
const coreInit = core.$ZodDiscriminatedUnion.init;
|
|
467
|
+
coreInit(inst, def);
|
|
468
|
+
});
|
|
469
|
+
function discriminatedUnion(discriminator, options, params) {
|
|
470
|
+
return new ZodDiscriminatedUnion({
|
|
471
|
+
type: "union",
|
|
472
|
+
options,
|
|
473
|
+
discriminator,
|
|
474
|
+
...util.normalizeParams(params)
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function handlePropertyResult(result, final, key, input) {
|
|
479
|
+
if (result.issues.length) {
|
|
480
|
+
final.issues.push(...util.prefixIssues(key, result.issues));
|
|
481
|
+
}
|
|
482
|
+
if (result.value === void 0) {
|
|
483
|
+
if (key in input) {
|
|
484
|
+
final.value[key] = void 0;
|
|
485
|
+
}
|
|
486
|
+
} else {
|
|
487
|
+
final.value[key] = result.value;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const ZodObject = /* @__PURE__ */ core.$constructor(
|
|
491
|
+
"ZodObject",
|
|
492
|
+
(inst, def) => {
|
|
493
|
+
const coreInit = core.$ZodObjectJIT.init;
|
|
494
|
+
coreInit(inst, def);
|
|
495
|
+
KrustyType.init(inst, def);
|
|
496
|
+
util.defineLazy(inst, "shape", () => {
|
|
497
|
+
return def.shape;
|
|
498
|
+
});
|
|
499
|
+
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
500
|
+
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
|
|
501
|
+
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
502
|
+
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
503
|
+
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
|
|
504
|
+
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: void 0 });
|
|
505
|
+
inst.extend = (incoming) => {
|
|
506
|
+
return util.extend(inst, incoming);
|
|
507
|
+
};
|
|
508
|
+
inst.safeExtend = (incoming) => {
|
|
509
|
+
return util.safeExtend(inst, incoming);
|
|
510
|
+
};
|
|
511
|
+
inst.merge = (other) => util.merge(inst, other);
|
|
512
|
+
inst.pick = (mask) => util.pick(inst, mask);
|
|
513
|
+
inst.omit = (mask) => util.omit(inst, mask);
|
|
514
|
+
inst.partial = (...args) => util.partial(ZodOptional, inst, args[0]);
|
|
515
|
+
inst.required = (...args) => util.required(ZodNonOptional, inst, args[0]);
|
|
516
|
+
function handleGating(input, payload, ctx) {
|
|
517
|
+
const _catchall = def.catchall?._zod;
|
|
518
|
+
const t = _catchall?.def.type;
|
|
519
|
+
let newIssues = null;
|
|
520
|
+
const proms = [];
|
|
521
|
+
const newUnrecognizedKeys = [];
|
|
522
|
+
for (let i = 0; i < payload.issues.length; i++) {
|
|
523
|
+
const issue = payload.issues[i];
|
|
524
|
+
if (!isGateIssueRaw(issue)) {
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
newIssues ??= [...payload.issues];
|
|
528
|
+
newIssues[i] = null;
|
|
529
|
+
const key = issue.path[0];
|
|
530
|
+
if (!_catchall) {
|
|
531
|
+
delete payload.value[key];
|
|
532
|
+
} else if (t === "never") {
|
|
533
|
+
newUnrecognizedKeys.push(key);
|
|
534
|
+
} else {
|
|
535
|
+
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
|
536
|
+
if (r instanceof Promise) {
|
|
537
|
+
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input)));
|
|
538
|
+
} else {
|
|
539
|
+
handlePropertyResult(r, payload, key, input);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (newIssues) {
|
|
544
|
+
payload.issues = newIssues.filter(Boolean);
|
|
545
|
+
}
|
|
546
|
+
if (newUnrecognizedKeys.length > 0) {
|
|
547
|
+
const missingKeyIssue = payload.issues.find(
|
|
548
|
+
(issue) => issue.code === "unrecognized_keys" && !issue.path
|
|
549
|
+
);
|
|
550
|
+
if (missingKeyIssue) {
|
|
551
|
+
missingKeyIssue.keys.push(...newUnrecognizedKeys);
|
|
552
|
+
} else {
|
|
553
|
+
payload.issues.push({
|
|
554
|
+
code: "unrecognized_keys",
|
|
555
|
+
keys: newUnrecognizedKeys,
|
|
556
|
+
input,
|
|
557
|
+
inst
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (proms.length > 0) {
|
|
562
|
+
return Promise.all(proms).then(() => payload);
|
|
563
|
+
} else {
|
|
564
|
+
return payload;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
const origParse = inst._zod.parse;
|
|
568
|
+
inst._zod.parse = (payload, ctx) => {
|
|
569
|
+
const input = payload.value;
|
|
570
|
+
const res = origParse(payload, ctx);
|
|
571
|
+
if (res instanceof Promise) {
|
|
572
|
+
return res.then((r) => handleGating(input, r, ctx));
|
|
573
|
+
} else {
|
|
574
|
+
return handleGating(input, res, ctx);
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
);
|
|
579
|
+
function object(shape, params) {
|
|
580
|
+
const def = {
|
|
581
|
+
type: "object",
|
|
582
|
+
shape: shape ?? {},
|
|
583
|
+
...util.normalizeParams(params)
|
|
584
|
+
};
|
|
585
|
+
return new ZodObject(def);
|
|
586
|
+
}
|
|
587
|
+
function strictObject(shape, params) {
|
|
588
|
+
return new ZodObject({
|
|
589
|
+
type: "object",
|
|
590
|
+
shape,
|
|
591
|
+
catchall: never(),
|
|
592
|
+
...util.normalizeParams(params)
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
function looseObject(shape, params) {
|
|
596
|
+
return new ZodObject({
|
|
597
|
+
type: "object",
|
|
598
|
+
shape,
|
|
599
|
+
catchall: unknown(),
|
|
600
|
+
...util.normalizeParams(params)
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const KrustyType = /* @__PURE__ */ core.$constructor(
|
|
605
|
+
"KrustyType",
|
|
606
|
+
(inst, def) => {
|
|
607
|
+
const coreInit = core.$ZodType.init;
|
|
608
|
+
coreInit(inst, def);
|
|
609
|
+
inst.def = def;
|
|
610
|
+
inst.type = def.type;
|
|
611
|
+
Object.defineProperty(inst, "_def", { value: def });
|
|
612
|
+
inst.check = (...checks2) => {
|
|
613
|
+
return inst.clone(
|
|
614
|
+
util.mergeDefs(def, {
|
|
615
|
+
checks: [
|
|
616
|
+
...def.checks ?? [],
|
|
617
|
+
...checks2.map(
|
|
618
|
+
(ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
|
|
619
|
+
)
|
|
620
|
+
]
|
|
621
|
+
})
|
|
622
|
+
);
|
|
623
|
+
};
|
|
624
|
+
inst.clone = (def2, params) => core.clone(inst, def2, params);
|
|
625
|
+
inst.brand = () => inst;
|
|
626
|
+
inst.register = ((reg, meta) => {
|
|
627
|
+
reg.add(inst, meta);
|
|
628
|
+
return inst;
|
|
629
|
+
});
|
|
630
|
+
inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
|
|
631
|
+
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
632
|
+
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
633
|
+
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
634
|
+
inst.spa = inst.safeParseAsync;
|
|
635
|
+
inst.encode = (data, params) => encode(inst, data, params);
|
|
636
|
+
inst.decode = (data, params) => decode(inst, data, params);
|
|
637
|
+
inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
|
|
638
|
+
inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
|
|
639
|
+
inst.safeEncode = (data, params) => safeEncode(inst, data, params);
|
|
640
|
+
inst.safeDecode = (data, params) => safeDecode(inst, data, params);
|
|
641
|
+
inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
|
|
642
|
+
inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
|
|
643
|
+
inst.refine = (check2, params) => inst.check(refine(check2, params));
|
|
644
|
+
inst.superRefine = (refinement) => inst.check(superRefine(refinement));
|
|
645
|
+
inst.overwrite = (fn) => inst.check(_overwrite(fn));
|
|
646
|
+
inst.gate = (gateName) => gate(inst, gateName);
|
|
647
|
+
inst.optional = () => optional(inst);
|
|
648
|
+
inst.nullable = () => nullable(inst);
|
|
649
|
+
inst.nullish = () => optional(nullable(inst));
|
|
650
|
+
inst.nonoptional = (params) => nonoptional(inst, params);
|
|
651
|
+
inst.array = () => array(inst);
|
|
652
|
+
inst.or = (arg) => union([inst, arg]);
|
|
653
|
+
inst.and = (arg) => intersection(inst, arg);
|
|
654
|
+
inst.transform = (tx) => pipe(inst, transform(tx));
|
|
655
|
+
inst.default = (def2) => _default(inst, def2);
|
|
656
|
+
inst.prefault = (def2) => prefault(inst, def2);
|
|
657
|
+
inst.catch = (params) => _catch(inst, params);
|
|
658
|
+
inst.pipe = (target) => pipe(inst, target);
|
|
659
|
+
inst.readonly = () => readonly(inst);
|
|
660
|
+
inst.describe = (description) => {
|
|
661
|
+
const cl = inst.clone();
|
|
662
|
+
core.globalRegistry.add(cl, { description });
|
|
663
|
+
return cl;
|
|
664
|
+
};
|
|
665
|
+
Object.defineProperty(inst, "description", {
|
|
666
|
+
get() {
|
|
667
|
+
return core.globalRegistry.get(inst)?.description;
|
|
668
|
+
},
|
|
669
|
+
configurable: true
|
|
670
|
+
});
|
|
671
|
+
inst.meta = (...args) => {
|
|
672
|
+
if (args.length === 0) {
|
|
673
|
+
return core.globalRegistry.get(inst);
|
|
674
|
+
}
|
|
675
|
+
const cl = inst.clone();
|
|
676
|
+
core.globalRegistry.add(cl, args[0]);
|
|
677
|
+
return cl;
|
|
678
|
+
};
|
|
679
|
+
return inst;
|
|
680
|
+
}
|
|
681
|
+
);
|
|
682
|
+
const _ZodString = /* @__PURE__ */ core.$constructor(
|
|
683
|
+
"_ZodString",
|
|
684
|
+
(inst, def) => {
|
|
685
|
+
const coreInit = core.$ZodString.init;
|
|
686
|
+
coreInit(inst, def);
|
|
687
|
+
KrustyType.init(inst, def);
|
|
688
|
+
const bag = inst._zod.bag;
|
|
689
|
+
inst.format = bag.format ?? null;
|
|
690
|
+
inst.minLength = bag.minimum ?? null;
|
|
691
|
+
inst.maxLength = bag.maximum ?? null;
|
|
692
|
+
inst.regex = (...args) => inst.check(_regex(...args));
|
|
693
|
+
inst.includes = (...args) => inst.check(_includes(...args));
|
|
694
|
+
inst.startsWith = (...args) => inst.check(_startsWith(...args));
|
|
695
|
+
inst.endsWith = (...args) => inst.check(_endsWith(...args));
|
|
696
|
+
inst.min = (...args) => inst.check(_minLength(...args));
|
|
697
|
+
inst.max = (...args) => inst.check(_maxLength(...args));
|
|
698
|
+
inst.length = (...args) => inst.check(_length(...args));
|
|
699
|
+
inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
|
|
700
|
+
inst.lowercase = (params) => inst.check(_lowercase(params));
|
|
701
|
+
inst.uppercase = (params) => inst.check(_uppercase(params));
|
|
702
|
+
inst.trim = () => inst.check(_trim());
|
|
703
|
+
inst.normalize = (...args) => inst.check(_normalize(...args));
|
|
704
|
+
inst.toLowerCase = () => inst.check(_toLowerCase());
|
|
705
|
+
inst.toUpperCase = () => inst.check(_toUpperCase());
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
const ZodString = /* @__PURE__ */ core.$constructor(
|
|
709
|
+
"ZodString",
|
|
710
|
+
(inst, def) => {
|
|
711
|
+
const coreInit = core.$ZodString.init;
|
|
712
|
+
coreInit(inst, def);
|
|
713
|
+
_ZodString.init(inst, def);
|
|
714
|
+
inst.email = (params) => inst.check(core._email(ZodEmail, params));
|
|
715
|
+
inst.url = (params) => inst.check(core._url(ZodURL, params));
|
|
716
|
+
inst.jwt = (params) => inst.check(core._jwt(ZodJWT, params));
|
|
717
|
+
inst.emoji = (params) => inst.check(core._emoji(ZodEmoji, params));
|
|
718
|
+
inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
|
|
719
|
+
inst.uuid = (params) => inst.check(core._uuid(ZodUUID, params));
|
|
720
|
+
inst.uuidv4 = (params) => inst.check(core._uuidv4(ZodUUID, params));
|
|
721
|
+
inst.uuidv6 = (params) => inst.check(core._uuidv6(ZodUUID, params));
|
|
722
|
+
inst.uuidv7 = (params) => inst.check(core._uuidv7(ZodUUID, params));
|
|
723
|
+
inst.nanoid = (params) => inst.check(core._nanoid(ZodNanoID, params));
|
|
724
|
+
inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
|
|
725
|
+
inst.cuid = (params) => inst.check(core._cuid(ZodCUID, params));
|
|
726
|
+
inst.cuid2 = (params) => inst.check(core._cuid2(ZodCUID2, params));
|
|
727
|
+
inst.ulid = (params) => inst.check(core._ulid(ZodULID, params));
|
|
728
|
+
inst.base64 = (params) => inst.check(core._base64(ZodBase64, params));
|
|
729
|
+
inst.base64url = (params) => inst.check(core._base64url(ZodBase64URL, params));
|
|
730
|
+
inst.xid = (params) => inst.check(core._xid(ZodXID, params));
|
|
731
|
+
inst.ksuid = (params) => inst.check(core._ksuid(ZodKSUID, params));
|
|
732
|
+
inst.ipv4 = (params) => inst.check(core._ipv4(ZodIPv4, params));
|
|
733
|
+
inst.ipv6 = (params) => inst.check(core._ipv6(ZodIPv6, params));
|
|
734
|
+
inst.cidrv4 = (params) => inst.check(core._cidrv4(ZodCIDRv4, params));
|
|
735
|
+
inst.cidrv6 = (params) => inst.check(core._cidrv6(ZodCIDRv6, params));
|
|
736
|
+
inst.e164 = (params) => inst.check(core._e164(ZodE164, params));
|
|
737
|
+
inst.datetime = (params) => inst.check(datetime(params));
|
|
738
|
+
inst.date = (params) => inst.check(date$1(params));
|
|
739
|
+
inst.time = (params) => inst.check(time(params));
|
|
740
|
+
inst.duration = (params) => inst.check(duration(params));
|
|
741
|
+
}
|
|
742
|
+
);
|
|
743
|
+
function string(params) {
|
|
744
|
+
return core._string(ZodString, params);
|
|
745
|
+
}
|
|
746
|
+
const ZodStringFormat = /* @__PURE__ */ core.$constructor(
|
|
747
|
+
"ZodStringFormat",
|
|
748
|
+
(inst, def) => {
|
|
749
|
+
const coreInit = core.$ZodStringFormat.init;
|
|
750
|
+
coreInit(inst, def);
|
|
751
|
+
_ZodString.init(inst, def);
|
|
752
|
+
}
|
|
753
|
+
);
|
|
754
|
+
const ZodEmail = /* @__PURE__ */ core.$constructor(
|
|
755
|
+
"ZodEmail",
|
|
756
|
+
(inst, def) => {
|
|
757
|
+
const coreInit = core.$ZodEmail.init;
|
|
758
|
+
coreInit(inst, def);
|
|
759
|
+
ZodStringFormat.init(inst, def);
|
|
760
|
+
}
|
|
761
|
+
);
|
|
762
|
+
function email(params) {
|
|
763
|
+
return core._email(ZodEmail, params);
|
|
764
|
+
}
|
|
765
|
+
const ZodGUID = /* @__PURE__ */ core.$constructor("ZodGUID", (inst, def) => {
|
|
766
|
+
const coreInit = core.$ZodGUID.init;
|
|
767
|
+
coreInit(inst, def);
|
|
768
|
+
ZodStringFormat.init(inst, def);
|
|
769
|
+
});
|
|
770
|
+
function guid(params) {
|
|
771
|
+
return core._guid(ZodGUID, params);
|
|
772
|
+
}
|
|
773
|
+
const ZodUUID = /* @__PURE__ */ core.$constructor("ZodUUID", (inst, def) => {
|
|
774
|
+
const coreInit = core.$ZodUUID.init;
|
|
775
|
+
coreInit(inst, def);
|
|
776
|
+
ZodStringFormat.init(inst, def);
|
|
777
|
+
});
|
|
778
|
+
function uuid(params) {
|
|
779
|
+
return core._uuid(ZodUUID, params);
|
|
780
|
+
}
|
|
781
|
+
function uuidv4(params) {
|
|
782
|
+
return core._uuidv4(ZodUUID, params);
|
|
783
|
+
}
|
|
784
|
+
function uuidv6(params) {
|
|
785
|
+
return core._uuidv6(ZodUUID, params);
|
|
786
|
+
}
|
|
787
|
+
function uuidv7(params) {
|
|
788
|
+
return core._uuidv7(ZodUUID, params);
|
|
789
|
+
}
|
|
790
|
+
const ZodURL = /* @__PURE__ */ core.$constructor("ZodURL", (inst, def) => {
|
|
791
|
+
const coreInit = core.$ZodURL.init;
|
|
792
|
+
coreInit(inst, def);
|
|
793
|
+
ZodStringFormat.init(inst, def);
|
|
794
|
+
});
|
|
795
|
+
function url(params) {
|
|
796
|
+
return core._url(ZodURL, params);
|
|
797
|
+
}
|
|
798
|
+
function httpUrl(params) {
|
|
799
|
+
return core._url(ZodURL, {
|
|
800
|
+
protocol: /^https?$/,
|
|
801
|
+
hostname: core.regexes.domain,
|
|
802
|
+
...util.normalizeParams(params)
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
const ZodEmoji = /* @__PURE__ */ core.$constructor(
|
|
806
|
+
"ZodEmoji",
|
|
807
|
+
(inst, def) => {
|
|
808
|
+
const coreInit = core.$ZodEmoji.init;
|
|
809
|
+
coreInit(inst, def);
|
|
810
|
+
ZodStringFormat.init(inst, def);
|
|
811
|
+
}
|
|
812
|
+
);
|
|
813
|
+
function emoji(params) {
|
|
814
|
+
return core._emoji(ZodEmoji, params);
|
|
815
|
+
}
|
|
816
|
+
const ZodNanoID = /* @__PURE__ */ core.$constructor(
|
|
817
|
+
"ZodNanoID",
|
|
818
|
+
(inst, def) => {
|
|
819
|
+
const coreInit = core.$ZodNanoID.init;
|
|
820
|
+
coreInit(inst, def);
|
|
821
|
+
ZodStringFormat.init(inst, def);
|
|
822
|
+
}
|
|
823
|
+
);
|
|
824
|
+
function nanoid(params) {
|
|
825
|
+
return core._nanoid(ZodNanoID, params);
|
|
826
|
+
}
|
|
827
|
+
const ZodCUID = /* @__PURE__ */ core.$constructor("ZodCUID", (inst, def) => {
|
|
828
|
+
const coreInit = core.$ZodCUID.init;
|
|
829
|
+
coreInit(inst, def);
|
|
830
|
+
ZodStringFormat.init(inst, def);
|
|
831
|
+
});
|
|
832
|
+
function cuid(params) {
|
|
833
|
+
return core._cuid(ZodCUID, params);
|
|
834
|
+
}
|
|
835
|
+
const ZodCUID2 = /* @__PURE__ */ core.$constructor(
|
|
836
|
+
"ZodCUID2",
|
|
837
|
+
(inst, def) => {
|
|
838
|
+
const coreInit = core.$ZodCUID2.init;
|
|
839
|
+
coreInit(inst, def);
|
|
840
|
+
ZodStringFormat.init(inst, def);
|
|
841
|
+
}
|
|
842
|
+
);
|
|
843
|
+
function cuid2(params) {
|
|
844
|
+
return core._cuid2(ZodCUID2, params);
|
|
845
|
+
}
|
|
846
|
+
const ZodULID = /* @__PURE__ */ core.$constructor("ZodULID", (inst, def) => {
|
|
847
|
+
const coreInit = core.$ZodULID.init;
|
|
848
|
+
coreInit(inst, def);
|
|
849
|
+
ZodStringFormat.init(inst, def);
|
|
850
|
+
});
|
|
851
|
+
function ulid(params) {
|
|
852
|
+
return core._ulid(ZodULID, params);
|
|
853
|
+
}
|
|
854
|
+
const ZodXID = /* @__PURE__ */ core.$constructor("ZodXID", (inst, def) => {
|
|
855
|
+
const coreInit = core.$ZodXID.init;
|
|
856
|
+
coreInit(inst, def);
|
|
857
|
+
ZodStringFormat.init(inst, def);
|
|
858
|
+
});
|
|
859
|
+
function xid(params) {
|
|
860
|
+
return core._xid(ZodXID, params);
|
|
861
|
+
}
|
|
862
|
+
const ZodKSUID = /* @__PURE__ */ core.$constructor(
|
|
863
|
+
"ZodKSUID",
|
|
864
|
+
(inst, def) => {
|
|
865
|
+
const coreInit = core.$ZodKSUID.init;
|
|
866
|
+
coreInit(inst, def);
|
|
867
|
+
ZodStringFormat.init(inst, def);
|
|
868
|
+
}
|
|
869
|
+
);
|
|
870
|
+
function ksuid(params) {
|
|
871
|
+
return core._ksuid(ZodKSUID, params);
|
|
872
|
+
}
|
|
873
|
+
const ZodIPv4 = /* @__PURE__ */ core.$constructor("ZodIPv4", (inst, def) => {
|
|
874
|
+
const coreInit = core.$ZodIPv4.init;
|
|
875
|
+
coreInit(inst, def);
|
|
876
|
+
ZodStringFormat.init(inst, def);
|
|
877
|
+
});
|
|
878
|
+
function ipv4(params) {
|
|
879
|
+
return core._ipv4(ZodIPv4, params);
|
|
880
|
+
}
|
|
881
|
+
const ZodIPv6 = /* @__PURE__ */ core.$constructor("ZodIPv6", (inst, def) => {
|
|
882
|
+
const coreInit = core.$ZodIPv6.init;
|
|
883
|
+
coreInit(inst, def);
|
|
884
|
+
ZodStringFormat.init(inst, def);
|
|
885
|
+
});
|
|
886
|
+
function ipv6(params) {
|
|
887
|
+
return core._ipv6(ZodIPv6, params);
|
|
888
|
+
}
|
|
889
|
+
const ZodCIDRv4 = /* @__PURE__ */ core.$constructor(
|
|
890
|
+
"ZodCIDRv4",
|
|
891
|
+
(inst, def) => {
|
|
892
|
+
const coreInit = core.$ZodCIDRv4.init;
|
|
893
|
+
coreInit(inst, def);
|
|
894
|
+
ZodStringFormat.init(inst, def);
|
|
895
|
+
}
|
|
896
|
+
);
|
|
897
|
+
function cidrv4(params) {
|
|
898
|
+
return core._cidrv4(ZodCIDRv4, params);
|
|
899
|
+
}
|
|
900
|
+
const ZodCIDRv6 = /* @__PURE__ */ core.$constructor(
|
|
901
|
+
"ZodCIDRv6",
|
|
902
|
+
(inst, def) => {
|
|
903
|
+
const coreInit = core.$ZodCIDRv6.init;
|
|
904
|
+
coreInit(inst, def);
|
|
905
|
+
ZodStringFormat.init(inst, def);
|
|
906
|
+
}
|
|
907
|
+
);
|
|
908
|
+
function cidrv6(params) {
|
|
909
|
+
return core._cidrv6(ZodCIDRv6, params);
|
|
910
|
+
}
|
|
911
|
+
const ZodBase64 = /* @__PURE__ */ core.$constructor(
|
|
912
|
+
"ZodBase64",
|
|
913
|
+
(inst, def) => {
|
|
914
|
+
const coreInit = core.$ZodBase64.init;
|
|
915
|
+
coreInit(inst, def);
|
|
916
|
+
ZodStringFormat.init(inst, def);
|
|
917
|
+
}
|
|
918
|
+
);
|
|
919
|
+
function base64(params) {
|
|
920
|
+
return core._base64(ZodBase64, params);
|
|
921
|
+
}
|
|
922
|
+
const ZodBase64URL = /* @__PURE__ */ core.$constructor(
|
|
923
|
+
"ZodBase64URL",
|
|
924
|
+
(inst, def) => {
|
|
925
|
+
const coreInit = core.$ZodBase64URL.init;
|
|
926
|
+
coreInit(inst, def);
|
|
927
|
+
ZodStringFormat.init(inst, def);
|
|
928
|
+
}
|
|
929
|
+
);
|
|
930
|
+
function base64url(params) {
|
|
931
|
+
return core._base64url(ZodBase64URL, params);
|
|
932
|
+
}
|
|
933
|
+
const ZodE164 = /* @__PURE__ */ core.$constructor("ZodE164", (inst, def) => {
|
|
934
|
+
const coreInit = core.$ZodE164.init;
|
|
935
|
+
coreInit(inst, def);
|
|
936
|
+
ZodStringFormat.init(inst, def);
|
|
937
|
+
});
|
|
938
|
+
function e164(params) {
|
|
939
|
+
return core._e164(ZodE164, params);
|
|
940
|
+
}
|
|
941
|
+
const ZodJWT = /* @__PURE__ */ core.$constructor("ZodJWT", (inst, def) => {
|
|
942
|
+
const coreInit = core.$ZodJWT.init;
|
|
943
|
+
coreInit(inst, def);
|
|
944
|
+
ZodStringFormat.init(inst, def);
|
|
945
|
+
});
|
|
946
|
+
function jwt(params) {
|
|
947
|
+
return core._jwt(ZodJWT, params);
|
|
948
|
+
}
|
|
949
|
+
const ZodCustomStringFormat = /* @__PURE__ */ core.$constructor("ZodCustomStringFormat", (inst, def) => {
|
|
950
|
+
const coreInit = core.$ZodCustomStringFormat.init;
|
|
951
|
+
coreInit(inst, def);
|
|
952
|
+
ZodStringFormat.init(inst, def);
|
|
953
|
+
});
|
|
954
|
+
function stringFormat(format, fnOrRegex, _params = {}) {
|
|
955
|
+
return core._stringFormat(ZodCustomStringFormat, format, fnOrRegex, _params);
|
|
956
|
+
}
|
|
957
|
+
function hostname(_params) {
|
|
958
|
+
return core._stringFormat(ZodCustomStringFormat, "hostname", core.regexes.hostname, _params);
|
|
959
|
+
}
|
|
960
|
+
function hex(_params) {
|
|
961
|
+
return core._stringFormat(ZodCustomStringFormat, "hex", core.regexes.hex, _params);
|
|
962
|
+
}
|
|
963
|
+
function hash(alg, params) {
|
|
964
|
+
const enc = params?.enc ?? "hex";
|
|
965
|
+
const format = `${alg}_${enc}`;
|
|
966
|
+
const regex = core.regexes[format];
|
|
967
|
+
if (!regex) throw new Error(`Unrecognized hash format: ${format}`);
|
|
968
|
+
return core._stringFormat(ZodCustomStringFormat, format, regex, params);
|
|
969
|
+
}
|
|
970
|
+
const ZodNumber = /* @__PURE__ */ core.$constructor(
|
|
971
|
+
"ZodNumber",
|
|
972
|
+
(inst, def) => {
|
|
973
|
+
const coreInit = core.$ZodNumber.init;
|
|
974
|
+
coreInit(inst, def);
|
|
975
|
+
KrustyType.init(inst, def);
|
|
976
|
+
inst.gt = (value, params) => inst.check(_gt(value, params));
|
|
977
|
+
inst.gte = (value, params) => inst.check(_gte(value, params));
|
|
978
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
979
|
+
inst.lt = (value, params) => inst.check(_lt(value, params));
|
|
980
|
+
inst.lte = (value, params) => inst.check(_lte(value, params));
|
|
981
|
+
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
982
|
+
inst.int = (params) => inst.check(int(params));
|
|
983
|
+
inst.safe = (params) => inst.check(int(params));
|
|
984
|
+
inst.positive = (params) => inst.check(_gt(0, params));
|
|
985
|
+
inst.nonnegative = (params) => inst.check(_gte(0, params));
|
|
986
|
+
inst.negative = (params) => inst.check(_lt(0, params));
|
|
987
|
+
inst.nonpositive = (params) => inst.check(_lte(0, params));
|
|
988
|
+
inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
|
|
989
|
+
inst.step = (value, params) => inst.check(_multipleOf(value, params));
|
|
990
|
+
inst.finite = () => inst;
|
|
991
|
+
const bag = inst._zod.bag;
|
|
992
|
+
inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
|
|
993
|
+
inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
|
|
994
|
+
inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
|
|
995
|
+
inst.isFinite = true;
|
|
996
|
+
inst.format = bag.format ?? null;
|
|
997
|
+
}
|
|
998
|
+
);
|
|
999
|
+
function number(params) {
|
|
1000
|
+
return core._number(ZodNumber, params);
|
|
1001
|
+
}
|
|
1002
|
+
const ZodNumberFormat = /* @__PURE__ */ core.$constructor(
|
|
1003
|
+
"ZodNumberFormat",
|
|
1004
|
+
(inst, def) => {
|
|
1005
|
+
const coreInit = core.$ZodNumberFormat.init;
|
|
1006
|
+
coreInit(inst, def);
|
|
1007
|
+
ZodNumber.init(inst, def);
|
|
1008
|
+
}
|
|
1009
|
+
);
|
|
1010
|
+
function int(params) {
|
|
1011
|
+
return core._int(ZodNumberFormat, params);
|
|
1012
|
+
}
|
|
1013
|
+
function float32(params) {
|
|
1014
|
+
return core._float32(ZodNumberFormat, params);
|
|
1015
|
+
}
|
|
1016
|
+
function float64(params) {
|
|
1017
|
+
return core._float64(ZodNumberFormat, params);
|
|
1018
|
+
}
|
|
1019
|
+
function int32(params) {
|
|
1020
|
+
return core._int32(ZodNumberFormat, params);
|
|
1021
|
+
}
|
|
1022
|
+
function uint32(params) {
|
|
1023
|
+
return core._uint32(ZodNumberFormat, params);
|
|
1024
|
+
}
|
|
1025
|
+
const ZodBoolean = /* @__PURE__ */ core.$constructor(
|
|
1026
|
+
"ZodBoolean",
|
|
1027
|
+
(inst, def) => {
|
|
1028
|
+
const coreInit = core.$ZodBoolean.init;
|
|
1029
|
+
coreInit(inst, def);
|
|
1030
|
+
KrustyType.init(inst, def);
|
|
1031
|
+
}
|
|
1032
|
+
);
|
|
1033
|
+
function boolean(params) {
|
|
1034
|
+
return core._boolean(ZodBoolean, params);
|
|
1035
|
+
}
|
|
1036
|
+
const ZodBigInt = /* @__PURE__ */ core.$constructor(
|
|
1037
|
+
"ZodBigInt",
|
|
1038
|
+
(inst, def) => {
|
|
1039
|
+
const coreInit = core.$ZodBigInt.init;
|
|
1040
|
+
coreInit(inst, def);
|
|
1041
|
+
KrustyType.init(inst, def);
|
|
1042
|
+
inst.gte = (value, params) => inst.check(_gte(value, params));
|
|
1043
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
1044
|
+
inst.gt = (value, params) => inst.check(_gt(value, params));
|
|
1045
|
+
inst.gte = (value, params) => inst.check(_gte(value, params));
|
|
1046
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
1047
|
+
inst.lt = (value, params) => inst.check(_lt(value, params));
|
|
1048
|
+
inst.lte = (value, params) => inst.check(_lte(value, params));
|
|
1049
|
+
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
1050
|
+
inst.positive = (params) => inst.check(_gt(BigInt(0), params));
|
|
1051
|
+
inst.negative = (params) => inst.check(_lt(BigInt(0), params));
|
|
1052
|
+
inst.nonpositive = (params) => inst.check(_lte(BigInt(0), params));
|
|
1053
|
+
inst.nonnegative = (params) => inst.check(_gte(BigInt(0), params));
|
|
1054
|
+
inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
|
|
1055
|
+
const bag = inst._zod.bag;
|
|
1056
|
+
inst.minValue = bag.minimum ?? null;
|
|
1057
|
+
inst.maxValue = bag.maximum ?? null;
|
|
1058
|
+
inst.format = bag.format ?? null;
|
|
1059
|
+
}
|
|
1060
|
+
);
|
|
1061
|
+
function bigint(params) {
|
|
1062
|
+
return core._bigint(ZodBigInt, params);
|
|
1063
|
+
}
|
|
1064
|
+
const ZodBigIntFormat = /* @__PURE__ */ core.$constructor(
|
|
1065
|
+
"ZodBigIntFormat",
|
|
1066
|
+
(inst, def) => {
|
|
1067
|
+
const coreInit = core.$ZodBigIntFormat.init;
|
|
1068
|
+
coreInit(inst, def);
|
|
1069
|
+
ZodBigInt.init(inst, def);
|
|
1070
|
+
}
|
|
1071
|
+
);
|
|
1072
|
+
function int64(params) {
|
|
1073
|
+
return core._int64(ZodBigIntFormat, params);
|
|
1074
|
+
}
|
|
1075
|
+
function uint64(params) {
|
|
1076
|
+
return core._uint64(ZodBigIntFormat, params);
|
|
1077
|
+
}
|
|
1078
|
+
const ZodSymbol = /* @__PURE__ */ core.$constructor(
|
|
1079
|
+
"ZodSymbol",
|
|
1080
|
+
(inst, def) => {
|
|
1081
|
+
const coreInit = core.$ZodSymbol.init;
|
|
1082
|
+
coreInit(inst, def);
|
|
1083
|
+
KrustyType.init(inst, def);
|
|
1084
|
+
}
|
|
1085
|
+
);
|
|
1086
|
+
function symbol(params) {
|
|
1087
|
+
return core._symbol(ZodSymbol, params);
|
|
1088
|
+
}
|
|
1089
|
+
const ZodUndefined = /* @__PURE__ */ core.$constructor(
|
|
1090
|
+
"ZodUndefined",
|
|
1091
|
+
(inst, def) => {
|
|
1092
|
+
const coreInit = core.$ZodUndefined.init;
|
|
1093
|
+
coreInit(inst, def);
|
|
1094
|
+
KrustyType.init(inst, def);
|
|
1095
|
+
}
|
|
1096
|
+
);
|
|
1097
|
+
function _undefined(params) {
|
|
1098
|
+
return core._undefined(ZodUndefined, params);
|
|
1099
|
+
}
|
|
1100
|
+
const ZodNull = /* @__PURE__ */ core.$constructor("ZodNull", (inst, def) => {
|
|
1101
|
+
const coreInit = core.$ZodNull.init;
|
|
1102
|
+
coreInit(inst, def);
|
|
1103
|
+
KrustyType.init(inst, def);
|
|
1104
|
+
});
|
|
1105
|
+
function _null(params) {
|
|
1106
|
+
return core._null(ZodNull, params);
|
|
1107
|
+
}
|
|
1108
|
+
const ZodAny = /* @__PURE__ */ core.$constructor("ZodAny", (inst, def) => {
|
|
1109
|
+
const coreInit = core.$ZodAny.init;
|
|
1110
|
+
coreInit(inst, def);
|
|
1111
|
+
KrustyType.init(inst, def);
|
|
1112
|
+
});
|
|
1113
|
+
function any() {
|
|
1114
|
+
return core._any(ZodAny);
|
|
1115
|
+
}
|
|
1116
|
+
const ZodUnknown = /* @__PURE__ */ core.$constructor(
|
|
1117
|
+
"ZodUnknown",
|
|
1118
|
+
(inst, def) => {
|
|
1119
|
+
const coreInit = core.$ZodUnknown.init;
|
|
1120
|
+
coreInit(inst, def);
|
|
1121
|
+
KrustyType.init(inst, def);
|
|
1122
|
+
}
|
|
1123
|
+
);
|
|
1124
|
+
function unknown() {
|
|
1125
|
+
return core._unknown(ZodUnknown);
|
|
1126
|
+
}
|
|
1127
|
+
const ZodNever = /* @__PURE__ */ core.$constructor(
|
|
1128
|
+
"ZodNever",
|
|
1129
|
+
(inst, def) => {
|
|
1130
|
+
const coreInit = core.$ZodNever.init;
|
|
1131
|
+
coreInit(inst, def);
|
|
1132
|
+
KrustyType.init(inst, def);
|
|
1133
|
+
}
|
|
1134
|
+
);
|
|
1135
|
+
function never(params) {
|
|
1136
|
+
return core._never(ZodNever, params);
|
|
1137
|
+
}
|
|
1138
|
+
const ZodVoid = /* @__PURE__ */ core.$constructor("ZodVoid", (inst, def) => {
|
|
1139
|
+
const coreInit = core.$ZodVoid.init;
|
|
1140
|
+
coreInit(inst, def);
|
|
1141
|
+
KrustyType.init(inst, def);
|
|
1142
|
+
});
|
|
1143
|
+
function _void(params) {
|
|
1144
|
+
return core._void(ZodVoid, params);
|
|
1145
|
+
}
|
|
1146
|
+
const ZodDate = /* @__PURE__ */ core.$constructor("ZodDate", (inst, def) => {
|
|
1147
|
+
const coreInit = core.$ZodDate.init;
|
|
1148
|
+
coreInit(inst, def);
|
|
1149
|
+
KrustyType.init(inst, def);
|
|
1150
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
1151
|
+
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
1152
|
+
const c = inst._zod.bag;
|
|
1153
|
+
inst.minDate = c.minimum ? new Date(c.minimum) : null;
|
|
1154
|
+
inst.maxDate = c.maximum ? new Date(c.maximum) : null;
|
|
1155
|
+
});
|
|
1156
|
+
function date(params) {
|
|
1157
|
+
return core._date(ZodDate, params);
|
|
1158
|
+
}
|
|
1159
|
+
const ZodArray = /* @__PURE__ */ core.$constructor(
|
|
1160
|
+
"ZodArray",
|
|
1161
|
+
(inst, def) => {
|
|
1162
|
+
const coreInit = core.$ZodArray.init;
|
|
1163
|
+
coreInit(inst, def);
|
|
1164
|
+
KrustyType.init(inst, def);
|
|
1165
|
+
inst.element = def.element;
|
|
1166
|
+
inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
|
|
1167
|
+
inst.nonempty = (params) => inst.check(_minLength(1, params));
|
|
1168
|
+
inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
|
|
1169
|
+
inst.length = (len, params) => inst.check(_length(len, params));
|
|
1170
|
+
inst.unwrap = () => inst.element;
|
|
1171
|
+
}
|
|
1172
|
+
);
|
|
1173
|
+
function array(element, params) {
|
|
1174
|
+
return core._array(ZodArray, element, params);
|
|
1175
|
+
}
|
|
1176
|
+
function keyof(schema) {
|
|
1177
|
+
const shape = schema._zod.def.shape;
|
|
1178
|
+
return _enum(Object.keys(shape));
|
|
1179
|
+
}
|
|
1180
|
+
const ZodIntersection = /* @__PURE__ */ core.$constructor(
|
|
1181
|
+
"ZodIntersection",
|
|
1182
|
+
(inst, def) => {
|
|
1183
|
+
const coreInit = core.$ZodIntersection.init;
|
|
1184
|
+
coreInit(inst, def);
|
|
1185
|
+
KrustyType.init(inst, def);
|
|
1186
|
+
}
|
|
1187
|
+
);
|
|
1188
|
+
function intersection(left, right) {
|
|
1189
|
+
return new ZodIntersection({
|
|
1190
|
+
type: "intersection",
|
|
1191
|
+
left,
|
|
1192
|
+
right
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
const ZodTuple = /* @__PURE__ */ core.$constructor(
|
|
1196
|
+
"ZodTuple",
|
|
1197
|
+
(inst, def) => {
|
|
1198
|
+
const coreInit = core.$ZodTuple.init;
|
|
1199
|
+
coreInit(inst, def);
|
|
1200
|
+
KrustyType.init(inst, def);
|
|
1201
|
+
inst.rest = (rest) => inst.clone({
|
|
1202
|
+
...inst._zod.def,
|
|
1203
|
+
rest
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
);
|
|
1207
|
+
function tuple(items, _paramsOrRest, _params) {
|
|
1208
|
+
const hasRest = _paramsOrRest instanceof core.$ZodType;
|
|
1209
|
+
const params = hasRest ? _params : _paramsOrRest;
|
|
1210
|
+
const rest = hasRest ? _paramsOrRest : null;
|
|
1211
|
+
return new ZodTuple({
|
|
1212
|
+
type: "tuple",
|
|
1213
|
+
items,
|
|
1214
|
+
rest,
|
|
1215
|
+
...util.normalizeParams(params)
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
const ZodRecord = /* @__PURE__ */ core.$constructor(
|
|
1219
|
+
"ZodRecord",
|
|
1220
|
+
(inst, def) => {
|
|
1221
|
+
const coreInit = core.$ZodRecord.init;
|
|
1222
|
+
coreInit(inst, def);
|
|
1223
|
+
KrustyType.init(inst, def);
|
|
1224
|
+
inst.keyType = def.keyType;
|
|
1225
|
+
inst.valueType = def.valueType;
|
|
1226
|
+
}
|
|
1227
|
+
);
|
|
1228
|
+
function record(keyType, valueType, params) {
|
|
1229
|
+
return new ZodRecord({
|
|
1230
|
+
type: "record",
|
|
1231
|
+
keyType,
|
|
1232
|
+
valueType,
|
|
1233
|
+
...util.normalizeParams(params)
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
function partialRecord(keyType, valueType, params) {
|
|
1237
|
+
const k = core.clone(keyType);
|
|
1238
|
+
k._zod.values = void 0;
|
|
1239
|
+
return new ZodRecord({
|
|
1240
|
+
type: "record",
|
|
1241
|
+
keyType: k,
|
|
1242
|
+
valueType,
|
|
1243
|
+
...util.normalizeParams(params)
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
const ZodMap = /* @__PURE__ */ core.$constructor("ZodMap", (inst, def) => {
|
|
1247
|
+
const coreInit = core.$ZodMap.init;
|
|
1248
|
+
coreInit(inst, def);
|
|
1249
|
+
KrustyType.init(inst, def);
|
|
1250
|
+
inst.keyType = def.keyType;
|
|
1251
|
+
inst.valueType = def.valueType;
|
|
1252
|
+
});
|
|
1253
|
+
function map(keyType, valueType, params) {
|
|
1254
|
+
return new ZodMap({
|
|
1255
|
+
type: "map",
|
|
1256
|
+
keyType,
|
|
1257
|
+
valueType,
|
|
1258
|
+
...util.normalizeParams(params)
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
const ZodSet = /* @__PURE__ */ core.$constructor("ZodSet", (inst, def) => {
|
|
1262
|
+
const coreInit = core.$ZodSet.init;
|
|
1263
|
+
coreInit(inst, def);
|
|
1264
|
+
KrustyType.init(inst, def);
|
|
1265
|
+
inst.min = (...args) => inst.check(core._minSize(...args));
|
|
1266
|
+
inst.nonempty = (params) => inst.check(core._minSize(1, params));
|
|
1267
|
+
inst.max = (...args) => inst.check(core._maxSize(...args));
|
|
1268
|
+
inst.size = (...args) => inst.check(core._size(...args));
|
|
1269
|
+
});
|
|
1270
|
+
function set(valueType, params) {
|
|
1271
|
+
return new ZodSet({
|
|
1272
|
+
type: "set",
|
|
1273
|
+
valueType,
|
|
1274
|
+
...util.normalizeParams(params)
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
const ZodEnum = /* @__PURE__ */ core.$constructor("ZodEnum", (inst, def) => {
|
|
1278
|
+
const coreInit = core.$ZodEnum.init;
|
|
1279
|
+
coreInit(inst, def);
|
|
1280
|
+
KrustyType.init(inst, def);
|
|
1281
|
+
inst.enum = def.entries;
|
|
1282
|
+
inst.options = Object.values(def.entries);
|
|
1283
|
+
const keys = new Set(Object.keys(def.entries));
|
|
1284
|
+
inst.extract = (values, params) => {
|
|
1285
|
+
const newEntries = {};
|
|
1286
|
+
for (const value of values) {
|
|
1287
|
+
if (keys.has(value)) {
|
|
1288
|
+
newEntries[value] = def.entries[value];
|
|
1289
|
+
} else throw new Error(`Key ${value} not found in enum`);
|
|
1290
|
+
}
|
|
1291
|
+
return new ZodEnum({
|
|
1292
|
+
...def,
|
|
1293
|
+
checks: [],
|
|
1294
|
+
...util.normalizeParams(params),
|
|
1295
|
+
entries: newEntries
|
|
1296
|
+
});
|
|
1297
|
+
};
|
|
1298
|
+
inst.exclude = (values, params) => {
|
|
1299
|
+
const newEntries = { ...def.entries };
|
|
1300
|
+
for (const value of values) {
|
|
1301
|
+
if (keys.has(value)) {
|
|
1302
|
+
delete newEntries[value];
|
|
1303
|
+
} else throw new Error(`Key ${value} not found in enum`);
|
|
1304
|
+
}
|
|
1305
|
+
return new ZodEnum({
|
|
1306
|
+
...def,
|
|
1307
|
+
checks: [],
|
|
1308
|
+
...util.normalizeParams(params),
|
|
1309
|
+
entries: newEntries
|
|
1310
|
+
});
|
|
1311
|
+
};
|
|
1312
|
+
});
|
|
1313
|
+
function _enum(values, params) {
|
|
1314
|
+
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
|
|
1315
|
+
return new ZodEnum({
|
|
1316
|
+
type: "enum",
|
|
1317
|
+
entries,
|
|
1318
|
+
...util.normalizeParams(params)
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
function nativeEnum(entries, params) {
|
|
1322
|
+
return new ZodEnum({
|
|
1323
|
+
type: "enum",
|
|
1324
|
+
entries,
|
|
1325
|
+
...util.normalizeParams(params)
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
const ZodLiteral = /* @__PURE__ */ core.$constructor(
|
|
1329
|
+
"ZodLiteral",
|
|
1330
|
+
(inst, def) => {
|
|
1331
|
+
const coreInit = core.$ZodLiteral.init;
|
|
1332
|
+
coreInit(inst, def);
|
|
1333
|
+
KrustyType.init(inst, def);
|
|
1334
|
+
inst.values = new Set(def.values);
|
|
1335
|
+
Object.defineProperty(inst, "value", {
|
|
1336
|
+
get() {
|
|
1337
|
+
if (def.values.length > 1) {
|
|
1338
|
+
throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
|
|
1339
|
+
}
|
|
1340
|
+
return def.values[0];
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
);
|
|
1345
|
+
function literal(value, params) {
|
|
1346
|
+
return new ZodLiteral({
|
|
1347
|
+
type: "literal",
|
|
1348
|
+
values: Array.isArray(value) ? value : [value],
|
|
1349
|
+
...util.normalizeParams(params)
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
const ZodFile = /* @__PURE__ */ core.$constructor("ZodFile", (inst, def) => {
|
|
1353
|
+
const coreInit = core.$ZodFile.init;
|
|
1354
|
+
coreInit(inst, def);
|
|
1355
|
+
KrustyType.init(inst, def);
|
|
1356
|
+
inst.min = (size, params) => inst.check(core._minSize(size, params));
|
|
1357
|
+
inst.max = (size, params) => inst.check(core._maxSize(size, params));
|
|
1358
|
+
inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params));
|
|
1359
|
+
});
|
|
1360
|
+
function file(params) {
|
|
1361
|
+
return core._file(ZodFile, params);
|
|
1362
|
+
}
|
|
1363
|
+
const ZodTransform = /* @__PURE__ */ core.$constructor(
|
|
1364
|
+
"ZodTransform",
|
|
1365
|
+
(inst, def) => {
|
|
1366
|
+
const coreInit = core.$ZodTransform.init;
|
|
1367
|
+
coreInit(inst, def);
|
|
1368
|
+
KrustyType.init(inst, def);
|
|
1369
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1370
|
+
if (_ctx.direction === "backward") {
|
|
1371
|
+
throw new core.$ZodEncodeError(inst.constructor.name);
|
|
1372
|
+
}
|
|
1373
|
+
payload.addIssue = (issue) => {
|
|
1374
|
+
if (typeof issue === "string") {
|
|
1375
|
+
payload.issues.push(util.issue(issue, payload.value, def));
|
|
1376
|
+
} else {
|
|
1377
|
+
const _issue = issue;
|
|
1378
|
+
if (_issue.fatal) _issue.continue = false;
|
|
1379
|
+
_issue.code ??= "custom";
|
|
1380
|
+
_issue.input ??= payload.value;
|
|
1381
|
+
_issue.inst ??= inst;
|
|
1382
|
+
payload.issues.push(util.issue(_issue));
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
const output = def.transform(payload.value, payload);
|
|
1386
|
+
if (output instanceof Promise) {
|
|
1387
|
+
return output.then((output2) => {
|
|
1388
|
+
payload.value = output2;
|
|
1389
|
+
return payload;
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
payload.value = output;
|
|
1393
|
+
return payload;
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
);
|
|
1397
|
+
function transform(fn) {
|
|
1398
|
+
return new ZodTransform({
|
|
1399
|
+
type: "transform",
|
|
1400
|
+
transform: fn
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
const ZodOptional = /* @__PURE__ */ core.$constructor(
|
|
1404
|
+
"ZodOptional",
|
|
1405
|
+
(inst, def) => {
|
|
1406
|
+
const coreInit = core.$ZodOptional.init;
|
|
1407
|
+
coreInit(inst, def);
|
|
1408
|
+
KrustyType.init(inst, def);
|
|
1409
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1410
|
+
}
|
|
1411
|
+
);
|
|
1412
|
+
function optional(innerType) {
|
|
1413
|
+
return new ZodOptional({
|
|
1414
|
+
type: "optional",
|
|
1415
|
+
innerType
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
const ZodNullable = /* @__PURE__ */ core.$constructor(
|
|
1419
|
+
"ZodNullable",
|
|
1420
|
+
(inst, def) => {
|
|
1421
|
+
const coreInit = core.$ZodNullable.init;
|
|
1422
|
+
coreInit(inst, def);
|
|
1423
|
+
KrustyType.init(inst, def);
|
|
1424
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1425
|
+
}
|
|
1426
|
+
);
|
|
1427
|
+
function nullable(innerType) {
|
|
1428
|
+
return new ZodNullable({
|
|
1429
|
+
type: "nullable",
|
|
1430
|
+
innerType
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
function nullish(innerType) {
|
|
1434
|
+
return optional(nullable(innerType));
|
|
1435
|
+
}
|
|
1436
|
+
const ZodDefault = /* @__PURE__ */ core.$constructor(
|
|
1437
|
+
"ZodDefault",
|
|
1438
|
+
(inst, def) => {
|
|
1439
|
+
const coreInit = core.$ZodDefault.init;
|
|
1440
|
+
coreInit(inst, def);
|
|
1441
|
+
KrustyType.init(inst, def);
|
|
1442
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1443
|
+
inst.removeDefault = inst.unwrap;
|
|
1444
|
+
}
|
|
1445
|
+
);
|
|
1446
|
+
function _default(innerType, defaultValue) {
|
|
1447
|
+
return new ZodDefault({
|
|
1448
|
+
type: "default",
|
|
1449
|
+
innerType,
|
|
1450
|
+
get defaultValue() {
|
|
1451
|
+
return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
const ZodPrefault = /* @__PURE__ */ core.$constructor(
|
|
1456
|
+
"ZodPrefault",
|
|
1457
|
+
(inst, def) => {
|
|
1458
|
+
const coreInit = core.$ZodPrefault.init;
|
|
1459
|
+
coreInit(inst, def);
|
|
1460
|
+
KrustyType.init(inst, def);
|
|
1461
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1462
|
+
}
|
|
1463
|
+
);
|
|
1464
|
+
function prefault(innerType, defaultValue) {
|
|
1465
|
+
return new ZodPrefault({
|
|
1466
|
+
type: "prefault",
|
|
1467
|
+
innerType,
|
|
1468
|
+
get defaultValue() {
|
|
1469
|
+
return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
|
|
1470
|
+
}
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
const ZodNonOptional = /* @__PURE__ */ core.$constructor(
|
|
1474
|
+
"ZodNonOptional",
|
|
1475
|
+
(inst, def) => {
|
|
1476
|
+
const coreInit = core.$ZodNonOptional.init;
|
|
1477
|
+
coreInit(inst, def);
|
|
1478
|
+
KrustyType.init(inst, def);
|
|
1479
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1480
|
+
}
|
|
1481
|
+
);
|
|
1482
|
+
function nonoptional(innerType, params) {
|
|
1483
|
+
return new ZodNonOptional({
|
|
1484
|
+
type: "nonoptional",
|
|
1485
|
+
innerType,
|
|
1486
|
+
...util.normalizeParams(params)
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
const ZodSuccess = /* @__PURE__ */ core.$constructor(
|
|
1490
|
+
"ZodSuccess",
|
|
1491
|
+
(inst, def) => {
|
|
1492
|
+
const coreInit = core.$ZodSuccess.init;
|
|
1493
|
+
coreInit(inst, def);
|
|
1494
|
+
KrustyType.init(inst, def);
|
|
1495
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1496
|
+
}
|
|
1497
|
+
);
|
|
1498
|
+
function success(innerType) {
|
|
1499
|
+
return new ZodSuccess({
|
|
1500
|
+
type: "success",
|
|
1501
|
+
innerType
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
const ZodCatch = /* @__PURE__ */ core.$constructor(
|
|
1505
|
+
"ZodCatch",
|
|
1506
|
+
(inst, def) => {
|
|
1507
|
+
const coreInit = core.$ZodCatch.init;
|
|
1508
|
+
coreInit(inst, def);
|
|
1509
|
+
KrustyType.init(inst, def);
|
|
1510
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1511
|
+
inst.removeCatch = inst.unwrap;
|
|
1512
|
+
}
|
|
1513
|
+
);
|
|
1514
|
+
function _catch(innerType, catchValue) {
|
|
1515
|
+
return new ZodCatch({
|
|
1516
|
+
type: "catch",
|
|
1517
|
+
innerType,
|
|
1518
|
+
catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
const ZodNaN = /* @__PURE__ */ core.$constructor("ZodNaN", (inst, def) => {
|
|
1522
|
+
const coreInit = core.$ZodNaN.init;
|
|
1523
|
+
coreInit(inst, def);
|
|
1524
|
+
KrustyType.init(inst, def);
|
|
1525
|
+
});
|
|
1526
|
+
function nan(params) {
|
|
1527
|
+
return core._nan(ZodNaN, params);
|
|
1528
|
+
}
|
|
1529
|
+
const ZodPipe = /* @__PURE__ */ core.$constructor("ZodPipe", (inst, def) => {
|
|
1530
|
+
const coreInit = core.$ZodPipe.init;
|
|
1531
|
+
coreInit(inst, def);
|
|
1532
|
+
KrustyType.init(inst, def);
|
|
1533
|
+
inst.in = def.in;
|
|
1534
|
+
inst.out = def.out;
|
|
1535
|
+
});
|
|
1536
|
+
function pipe(in_, out) {
|
|
1537
|
+
return new ZodPipe({
|
|
1538
|
+
type: "pipe",
|
|
1539
|
+
in: in_,
|
|
1540
|
+
out
|
|
1541
|
+
// ...util.normalizeParams(params),
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
const ZodCodec = /* @__PURE__ */ core.$constructor(
|
|
1545
|
+
"ZodCodec",
|
|
1546
|
+
(inst, def) => {
|
|
1547
|
+
ZodPipe.init(inst, def);
|
|
1548
|
+
const coreInit = core.$ZodCodec.init;
|
|
1549
|
+
coreInit(inst, def);
|
|
1550
|
+
}
|
|
1551
|
+
);
|
|
1552
|
+
function codec(in_, out, params) {
|
|
1553
|
+
return new ZodCodec({
|
|
1554
|
+
type: "pipe",
|
|
1555
|
+
in: in_,
|
|
1556
|
+
out,
|
|
1557
|
+
transform: params.decode,
|
|
1558
|
+
reverseTransform: params.encode
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
const ZodReadonly = /* @__PURE__ */ core.$constructor(
|
|
1562
|
+
"ZodReadonly",
|
|
1563
|
+
(inst, def) => {
|
|
1564
|
+
const coreInit = core.$ZodReadonly.init;
|
|
1565
|
+
coreInit(inst, def);
|
|
1566
|
+
KrustyType.init(inst, def);
|
|
1567
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1568
|
+
}
|
|
1569
|
+
);
|
|
1570
|
+
function readonly(innerType) {
|
|
1571
|
+
return new ZodReadonly({
|
|
1572
|
+
type: "readonly",
|
|
1573
|
+
innerType
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
const ZodTemplateLiteral = /* @__PURE__ */ core.$constructor(
|
|
1577
|
+
"ZodTemplateLiteral",
|
|
1578
|
+
(inst, def) => {
|
|
1579
|
+
const coreInit = core.$ZodTemplateLiteral.init;
|
|
1580
|
+
coreInit(inst, def);
|
|
1581
|
+
KrustyType.init(inst, def);
|
|
1582
|
+
}
|
|
1583
|
+
);
|
|
1584
|
+
function templateLiteral(parts, params) {
|
|
1585
|
+
return new ZodTemplateLiteral({
|
|
1586
|
+
type: "template_literal",
|
|
1587
|
+
parts,
|
|
1588
|
+
...util.normalizeParams(params)
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
const ZodLazy = /* @__PURE__ */ core.$constructor("ZodLazy", (inst, def) => {
|
|
1592
|
+
const coreInit = core.$ZodLazy.init;
|
|
1593
|
+
coreInit(inst, def);
|
|
1594
|
+
KrustyType.init(inst, def);
|
|
1595
|
+
inst.unwrap = () => inst._zod.def.getter();
|
|
1596
|
+
});
|
|
1597
|
+
function lazy(getter) {
|
|
1598
|
+
return new ZodLazy({
|
|
1599
|
+
type: "lazy",
|
|
1600
|
+
getter
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
const ZodPromise = /* @__PURE__ */ core.$constructor(
|
|
1604
|
+
"ZodPromise",
|
|
1605
|
+
(inst, def) => {
|
|
1606
|
+
const coreInit = core.$ZodPromise.init;
|
|
1607
|
+
coreInit(inst, def);
|
|
1608
|
+
KrustyType.init(inst, def);
|
|
1609
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1610
|
+
}
|
|
1611
|
+
);
|
|
1612
|
+
function promise(innerType) {
|
|
1613
|
+
return new ZodPromise({
|
|
1614
|
+
type: "promise",
|
|
1615
|
+
innerType
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
const ZodFunction = /* @__PURE__ */ core.$constructor(
|
|
1619
|
+
"ZodFunction",
|
|
1620
|
+
(inst, def) => {
|
|
1621
|
+
const coreInit = core.$ZodFunction.init;
|
|
1622
|
+
coreInit(inst, def);
|
|
1623
|
+
KrustyType.init(inst, def);
|
|
1624
|
+
}
|
|
1625
|
+
);
|
|
1626
|
+
function _function(params) {
|
|
1627
|
+
return new ZodFunction({
|
|
1628
|
+
type: "function",
|
|
1629
|
+
input: Array.isArray(params?.input) ? tuple(params?.input) : params?.input ?? array(unknown()),
|
|
1630
|
+
output: params?.output ?? unknown()
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
const ZodCustom = /* @__PURE__ */ core.$constructor(
|
|
1634
|
+
"ZodCustom",
|
|
1635
|
+
(inst, def) => {
|
|
1636
|
+
const coreInit = core.$ZodCustom.init;
|
|
1637
|
+
coreInit(inst, def);
|
|
1638
|
+
KrustyType.init(inst, def);
|
|
1639
|
+
}
|
|
1640
|
+
);
|
|
1641
|
+
function check(fn) {
|
|
1642
|
+
const ch = new core.$ZodCheck({
|
|
1643
|
+
check: "custom"
|
|
1644
|
+
// ...util.normalizeParams(params),
|
|
1645
|
+
});
|
|
1646
|
+
ch._zod.check = fn;
|
|
1647
|
+
return ch;
|
|
1648
|
+
}
|
|
1649
|
+
function custom(fn, _params) {
|
|
1650
|
+
return core._custom(ZodCustom, fn ?? (() => true), _params);
|
|
1651
|
+
}
|
|
1652
|
+
function refine(fn, _params = {}) {
|
|
1653
|
+
return core._refine(ZodCustom, fn, _params);
|
|
1654
|
+
}
|
|
1655
|
+
function superRefine(fn) {
|
|
1656
|
+
return core._superRefine(fn);
|
|
1657
|
+
}
|
|
1658
|
+
function _instanceof(cls, params = {
|
|
1659
|
+
error: `Input not instance of ${cls.name}`
|
|
1660
|
+
}) {
|
|
1661
|
+
const inst = new ZodCustom({
|
|
1662
|
+
type: "custom",
|
|
1663
|
+
check: "custom",
|
|
1664
|
+
fn: (data) => data instanceof cls,
|
|
1665
|
+
abort: true,
|
|
1666
|
+
...util.normalizeParams(params)
|
|
1667
|
+
});
|
|
1668
|
+
inst._zod.bag.Class = cls;
|
|
1669
|
+
return inst;
|
|
1670
|
+
}
|
|
1671
|
+
const stringbool = (...args) => core._stringbool(
|
|
1672
|
+
{
|
|
1673
|
+
Codec: ZodCodec,
|
|
1674
|
+
Boolean: ZodBoolean,
|
|
1675
|
+
String: ZodString
|
|
1676
|
+
},
|
|
1677
|
+
...args
|
|
1678
|
+
);
|
|
1679
|
+
function json(params) {
|
|
1680
|
+
const jsonSchema = lazy(() => {
|
|
1681
|
+
return union([
|
|
1682
|
+
string(params),
|
|
1683
|
+
number(),
|
|
1684
|
+
boolean(),
|
|
1685
|
+
_null(),
|
|
1686
|
+
array(jsonSchema),
|
|
1687
|
+
record(string(), jsonSchema)
|
|
1688
|
+
]);
|
|
1689
|
+
});
|
|
1690
|
+
return jsonSchema;
|
|
1691
|
+
}
|
|
1692
|
+
function preprocess(fn, schema) {
|
|
1693
|
+
return pipe(transform(fn), schema);
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
const fullSchema_ = {
|
|
1697
|
+
__proto__: null,
|
|
1698
|
+
KrustyType: KrustyType,
|
|
1699
|
+
ZodAny: ZodAny,
|
|
1700
|
+
ZodArray: ZodArray,
|
|
1701
|
+
ZodBase64: ZodBase64,
|
|
1702
|
+
ZodBase64URL: ZodBase64URL,
|
|
1703
|
+
ZodBigInt: ZodBigInt,
|
|
1704
|
+
ZodBigIntFormat: ZodBigIntFormat,
|
|
1705
|
+
ZodBoolean: ZodBoolean,
|
|
1706
|
+
ZodCIDRv4: ZodCIDRv4,
|
|
1707
|
+
ZodCIDRv6: ZodCIDRv6,
|
|
1708
|
+
ZodCUID: ZodCUID,
|
|
1709
|
+
ZodCUID2: ZodCUID2,
|
|
1710
|
+
ZodCatch: ZodCatch,
|
|
1711
|
+
ZodCodec: ZodCodec,
|
|
1712
|
+
ZodCustom: ZodCustom,
|
|
1713
|
+
ZodCustomStringFormat: ZodCustomStringFormat,
|
|
1714
|
+
ZodDate: ZodDate,
|
|
1715
|
+
ZodDefault: ZodDefault,
|
|
1716
|
+
ZodDiscriminatedUnion: ZodDiscriminatedUnion,
|
|
1717
|
+
ZodE164: ZodE164,
|
|
1718
|
+
ZodEmail: ZodEmail,
|
|
1719
|
+
ZodEmoji: ZodEmoji,
|
|
1720
|
+
ZodEnum: ZodEnum,
|
|
1721
|
+
ZodFile: ZodFile,
|
|
1722
|
+
ZodFunction: ZodFunction,
|
|
1723
|
+
ZodGUID: ZodGUID,
|
|
1724
|
+
ZodGate: ZodGate,
|
|
1725
|
+
ZodIPv4: ZodIPv4,
|
|
1726
|
+
ZodIPv6: ZodIPv6,
|
|
1727
|
+
ZodIntersection: ZodIntersection,
|
|
1728
|
+
ZodJWT: ZodJWT,
|
|
1729
|
+
ZodKSUID: ZodKSUID,
|
|
1730
|
+
ZodLazy: ZodLazy,
|
|
1731
|
+
ZodLiteral: ZodLiteral,
|
|
1732
|
+
ZodMap: ZodMap,
|
|
1733
|
+
ZodNaN: ZodNaN,
|
|
1734
|
+
ZodNanoID: ZodNanoID,
|
|
1735
|
+
ZodNever: ZodNever,
|
|
1736
|
+
ZodNonOptional: ZodNonOptional,
|
|
1737
|
+
ZodNull: ZodNull,
|
|
1738
|
+
ZodNullable: ZodNullable,
|
|
1739
|
+
ZodNumber: ZodNumber,
|
|
1740
|
+
ZodNumberFormat: ZodNumberFormat,
|
|
1741
|
+
ZodObject: ZodObject,
|
|
1742
|
+
ZodOptional: ZodOptional,
|
|
1743
|
+
ZodPipe: ZodPipe,
|
|
1744
|
+
ZodPrefault: ZodPrefault,
|
|
1745
|
+
ZodPromise: ZodPromise,
|
|
1746
|
+
ZodReadonly: ZodReadonly,
|
|
1747
|
+
ZodRecord: ZodRecord,
|
|
1748
|
+
ZodSet: ZodSet,
|
|
1749
|
+
ZodString: ZodString,
|
|
1750
|
+
ZodStringFormat: ZodStringFormat,
|
|
1751
|
+
ZodSuccess: ZodSuccess,
|
|
1752
|
+
ZodSymbol: ZodSymbol,
|
|
1753
|
+
ZodTemplateLiteral: ZodTemplateLiteral,
|
|
1754
|
+
ZodTransform: ZodTransform,
|
|
1755
|
+
ZodTuple: ZodTuple,
|
|
1756
|
+
ZodULID: ZodULID,
|
|
1757
|
+
ZodURL: ZodURL,
|
|
1758
|
+
ZodUUID: ZodUUID,
|
|
1759
|
+
ZodUndefined: ZodUndefined,
|
|
1760
|
+
ZodUnion: ZodUnion,
|
|
1761
|
+
ZodUnknown: ZodUnknown,
|
|
1762
|
+
ZodVoid: ZodVoid,
|
|
1763
|
+
ZodXID: ZodXID,
|
|
1764
|
+
_ZodString: _ZodString,
|
|
1765
|
+
_default: _default,
|
|
1766
|
+
_function: _function,
|
|
1767
|
+
any: any,
|
|
1768
|
+
array: array,
|
|
1769
|
+
base64: base64,
|
|
1770
|
+
base64url: base64url,
|
|
1771
|
+
bigint: bigint,
|
|
1772
|
+
boolean: boolean,
|
|
1773
|
+
catch: _catch,
|
|
1774
|
+
check: check,
|
|
1775
|
+
cidrv4: cidrv4,
|
|
1776
|
+
cidrv6: cidrv6,
|
|
1777
|
+
codec: codec,
|
|
1778
|
+
cuid: cuid,
|
|
1779
|
+
cuid2: cuid2,
|
|
1780
|
+
custom: custom,
|
|
1781
|
+
date: date,
|
|
1782
|
+
discriminatedUnion: discriminatedUnion,
|
|
1783
|
+
e164: e164,
|
|
1784
|
+
email: email,
|
|
1785
|
+
emoji: emoji,
|
|
1786
|
+
enum: _enum,
|
|
1787
|
+
file: file,
|
|
1788
|
+
float32: float32,
|
|
1789
|
+
float64: float64,
|
|
1790
|
+
function: _function,
|
|
1791
|
+
gate: gate,
|
|
1792
|
+
gatingContext: gatingContext,
|
|
1793
|
+
guid: guid,
|
|
1794
|
+
hash: hash,
|
|
1795
|
+
hex: hex,
|
|
1796
|
+
hostname: hostname,
|
|
1797
|
+
httpUrl: httpUrl,
|
|
1798
|
+
instanceof: _instanceof,
|
|
1799
|
+
int: int,
|
|
1800
|
+
int32: int32,
|
|
1801
|
+
int64: int64,
|
|
1802
|
+
intersection: intersection,
|
|
1803
|
+
ipv4: ipv4,
|
|
1804
|
+
ipv6: ipv6,
|
|
1805
|
+
isGateIssue: isGateIssue,
|
|
1806
|
+
isGateIssueRaw: isGateIssueRaw,
|
|
1807
|
+
json: json,
|
|
1808
|
+
jwt: jwt,
|
|
1809
|
+
keyof: keyof,
|
|
1810
|
+
ksuid: ksuid,
|
|
1811
|
+
lazy: lazy,
|
|
1812
|
+
literal: literal,
|
|
1813
|
+
looseObject: looseObject,
|
|
1814
|
+
map: map,
|
|
1815
|
+
nan: nan,
|
|
1816
|
+
nanoid: nanoid,
|
|
1817
|
+
nativeEnum: nativeEnum,
|
|
1818
|
+
never: never,
|
|
1819
|
+
nonoptional: nonoptional,
|
|
1820
|
+
null: _null,
|
|
1821
|
+
nullable: nullable,
|
|
1822
|
+
nullish: nullish,
|
|
1823
|
+
number: number,
|
|
1824
|
+
object: object,
|
|
1825
|
+
optional: optional,
|
|
1826
|
+
partialRecord: partialRecord,
|
|
1827
|
+
pipe: pipe,
|
|
1828
|
+
prefault: prefault,
|
|
1829
|
+
preprocess: preprocess,
|
|
1830
|
+
promise: promise,
|
|
1831
|
+
readonly: readonly,
|
|
1832
|
+
record: record,
|
|
1833
|
+
refine: refine,
|
|
1834
|
+
set: set,
|
|
1835
|
+
strictObject: strictObject,
|
|
1836
|
+
string: string,
|
|
1837
|
+
stringFormat: stringFormat,
|
|
1838
|
+
stringbool: stringbool,
|
|
1839
|
+
success: success,
|
|
1840
|
+
superRefine: superRefine,
|
|
1841
|
+
symbol: symbol,
|
|
1842
|
+
templateLiteral: templateLiteral,
|
|
1843
|
+
transform: transform,
|
|
1844
|
+
tuple: tuple,
|
|
1845
|
+
uint32: uint32,
|
|
1846
|
+
uint64: uint64,
|
|
1847
|
+
ulid: ulid,
|
|
1848
|
+
undefined: _undefined,
|
|
1849
|
+
union: union,
|
|
1850
|
+
unknown: unknown,
|
|
1851
|
+
url: url,
|
|
1852
|
+
uuid: uuid,
|
|
1853
|
+
uuidv4: uuidv4,
|
|
1854
|
+
uuidv6: uuidv6,
|
|
1855
|
+
uuidv7: uuidv7,
|
|
1856
|
+
void: _void,
|
|
1857
|
+
xid: xid
|
|
1858
|
+
};
|
|
1859
|
+
|
|
1860
|
+
class ProcedureBuilder extends ContractProcedure {
|
|
1861
|
+
constructor(def) {
|
|
1862
|
+
super(def);
|
|
321
1863
|
}
|
|
322
1864
|
/**
|
|
323
|
-
* Adds type-safe custom errors.
|
|
324
|
-
* The provided errors are spared-merged with any existing errors.
|
|
1865
|
+
* Adds type-safe custom errors to the contract.
|
|
1866
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
325
1867
|
*
|
|
326
1868
|
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
327
1869
|
*/
|
|
328
1870
|
errors(errors) {
|
|
329
|
-
return new
|
|
1871
|
+
return new ProcedureBuilder({
|
|
330
1872
|
...this["~orpc"],
|
|
331
1873
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
332
1874
|
});
|
|
333
1875
|
}
|
|
334
1876
|
/**
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
338
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
339
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
340
|
-
*/
|
|
341
|
-
use(middleware) {
|
|
342
|
-
return new Builder({
|
|
343
|
-
...this["~orpc"],
|
|
344
|
-
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
useGating(gates, isGateEnabled) {
|
|
348
|
-
return this.use(({ next, context }) => {
|
|
349
|
-
return gatingContext.run(
|
|
350
|
-
(gate) => isGateEnabled(gate, context),
|
|
351
|
-
() => next({ context: { isGateEnabled } })
|
|
352
|
-
);
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Sets or updates the metadata.
|
|
357
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
1877
|
+
* Sets or updates the metadata for the contract.
|
|
1878
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
358
1879
|
*
|
|
359
1880
|
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
360
1881
|
*/
|
|
361
1882
|
meta(meta) {
|
|
362
|
-
return new
|
|
1883
|
+
return new ProcedureBuilder({
|
|
363
1884
|
...this["~orpc"],
|
|
364
1885
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
365
1886
|
});
|
|
366
1887
|
}
|
|
367
1888
|
/**
|
|
368
|
-
* Sets or updates the route definition.
|
|
369
|
-
* The provided route is spared-merged with any existing route.
|
|
1889
|
+
* Sets or updates the route definition for the contract.
|
|
1890
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
370
1891
|
* This option is typically relevant when integrating with OpenAPI.
|
|
371
1892
|
*
|
|
372
1893
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
373
1894
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
374
1895
|
*/
|
|
375
1896
|
route(route) {
|
|
376
|
-
return new
|
|
1897
|
+
return new ProcedureBuilder({
|
|
377
1898
|
...this["~orpc"],
|
|
378
1899
|
route: mergeRoute(this["~orpc"].route, route)
|
|
379
1900
|
});
|
|
@@ -384,7 +1905,7 @@ class Builder {
|
|
|
384
1905
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
385
1906
|
*/
|
|
386
1907
|
input(schema) {
|
|
387
|
-
return new
|
|
1908
|
+
return new ProcedureBuilder({
|
|
388
1909
|
...this["~orpc"],
|
|
389
1910
|
inputSchema: schema,
|
|
390
1911
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
@@ -396,12 +1917,33 @@ class Builder {
|
|
|
396
1917
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
397
1918
|
*/
|
|
398
1919
|
output(schema) {
|
|
399
|
-
return new
|
|
1920
|
+
return new ProcedureBuilder({
|
|
400
1921
|
...this["~orpc"],
|
|
401
1922
|
outputSchema: schema,
|
|
402
1923
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
403
1924
|
});
|
|
404
1925
|
}
|
|
1926
|
+
/**
|
|
1927
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
1928
|
+
*
|
|
1929
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
1930
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
1931
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
1932
|
+
*/
|
|
1933
|
+
use(middleware) {
|
|
1934
|
+
return new this.constructor({
|
|
1935
|
+
...this["~orpc"],
|
|
1936
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
1937
|
+
});
|
|
1938
|
+
}
|
|
1939
|
+
useGating(gates, isGateEnabled) {
|
|
1940
|
+
return this.use(({ next, context }) => {
|
|
1941
|
+
return gatingContext.run(
|
|
1942
|
+
(gate) => isGateEnabled(gate, context),
|
|
1943
|
+
() => next({ context: { isGateEnabled } })
|
|
1944
|
+
);
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
405
1947
|
/**
|
|
406
1948
|
* Defines the handler of the procedure.
|
|
407
1949
|
*
|
|
@@ -413,6 +1955,8 @@ class Builder {
|
|
|
413
1955
|
handler
|
|
414
1956
|
});
|
|
415
1957
|
}
|
|
1958
|
+
}
|
|
1959
|
+
class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
416
1960
|
/**
|
|
417
1961
|
* Prefixes all procedures in the router.
|
|
418
1962
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -422,7 +1966,7 @@ class Builder {
|
|
|
422
1966
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
423
1967
|
*/
|
|
424
1968
|
prefix(prefix) {
|
|
425
|
-
return new
|
|
1969
|
+
return new this.constructor({
|
|
426
1970
|
...this["~orpc"],
|
|
427
1971
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
428
1972
|
});
|
|
@@ -434,7 +1978,7 @@ class Builder {
|
|
|
434
1978
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
435
1979
|
*/
|
|
436
1980
|
tag(...tags) {
|
|
437
|
-
return new
|
|
1981
|
+
return new this.constructor({
|
|
438
1982
|
...this["~orpc"],
|
|
439
1983
|
tags: mergeTags(this["~orpc"].tags, tags)
|
|
440
1984
|
});
|
|
@@ -454,7 +1998,44 @@ class Builder {
|
|
|
454
1998
|
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
455
1999
|
*/
|
|
456
2000
|
lazyRoute(loader) {
|
|
457
|
-
return enhanceRouter(lazy(loader), this["~orpc"]);
|
|
2001
|
+
return enhanceRouter(lazy$1(loader), this["~orpc"]);
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
const fullSchema = fullSchema_;
|
|
2006
|
+
const miniSchema = {
|
|
2007
|
+
array: fullSchema.array,
|
|
2008
|
+
boolean: fullSchema.boolean,
|
|
2009
|
+
date: fullSchema.date,
|
|
2010
|
+
number: fullSchema.number,
|
|
2011
|
+
int: fullSchema.int,
|
|
2012
|
+
string: fullSchema.string,
|
|
2013
|
+
literal: fullSchema.literal,
|
|
2014
|
+
enum: fullSchema.enum,
|
|
2015
|
+
union: fullSchema.union,
|
|
2016
|
+
discriminatedUnion: fullSchema.discriminatedUnion,
|
|
2017
|
+
null: fullSchema.null,
|
|
2018
|
+
record: fullSchema.record,
|
|
2019
|
+
file: fullSchema.file,
|
|
2020
|
+
object: fullSchema.object
|
|
2021
|
+
};
|
|
2022
|
+
|
|
2023
|
+
class Builder extends BuilderWithMiddlewares {
|
|
2024
|
+
/**
|
|
2025
|
+
* Set or override the initial context.
|
|
2026
|
+
*
|
|
2027
|
+
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
2028
|
+
*/
|
|
2029
|
+
$context() {
|
|
2030
|
+
return this;
|
|
2031
|
+
}
|
|
2032
|
+
/**
|
|
2033
|
+
* Creates a middleware.
|
|
2034
|
+
*
|
|
2035
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
2036
|
+
*/
|
|
2037
|
+
middleware(middleware) {
|
|
2038
|
+
return decorateMiddleware(middleware);
|
|
458
2039
|
}
|
|
459
2040
|
}
|
|
460
2041
|
function createApiBuilder(opts = {}) {
|
|
@@ -465,7 +2046,7 @@ function createApiBuilder(opts = {}) {
|
|
|
465
2046
|
inputValidationIndex: 0,
|
|
466
2047
|
outputValidationIndex: 0,
|
|
467
2048
|
middlewares: [
|
|
468
|
-
onError((error,
|
|
2049
|
+
onError((error, _options) => {
|
|
469
2050
|
console.dir(error, { depth: null });
|
|
470
2051
|
})
|
|
471
2052
|
],
|
|
@@ -473,7 +2054,7 @@ function createApiBuilder(opts = {}) {
|
|
|
473
2054
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
474
2055
|
dedupeLeadingMiddlewares: true
|
|
475
2056
|
});
|
|
476
|
-
return base;
|
|
2057
|
+
return Object.assign(base, miniSchema, { z: fullSchema });
|
|
477
2058
|
}
|
|
478
2059
|
const os = createApiBuilder();
|
|
479
2060
|
|
|
@@ -513,7 +2094,7 @@ function implementerInternal(contract, middlewares) {
|
|
|
513
2094
|
};
|
|
514
2095
|
} else if (key === "lazyRoute") {
|
|
515
2096
|
method = (loader) => {
|
|
516
|
-
const adapted = enhanceRouter(lazy(loader), {
|
|
2097
|
+
const adapted = enhanceRouter(lazy$1(loader), {
|
|
517
2098
|
middlewares,
|
|
518
2099
|
errorMap: {},
|
|
519
2100
|
prefix: void 0,
|
|
@@ -563,7 +2144,7 @@ function implement(contract) {
|
|
|
563
2144
|
}
|
|
564
2145
|
|
|
565
2146
|
function createAssertedLazyProcedure(lazied) {
|
|
566
|
-
const lazyProcedure = lazy(async () => {
|
|
2147
|
+
const lazyProcedure = lazy$1(async () => {
|
|
567
2148
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
568
2149
|
if (!isProcedure(maybeProcedure)) {
|
|
569
2150
|
throw new Error(`
|
|
@@ -614,4 +2195,4 @@ function createRouterClient(router, ...rest) {
|
|
|
614
2195
|
return recursive;
|
|
615
2196
|
}
|
|
616
2197
|
|
|
617
|
-
export { Builder, DecoratedProcedure, Procedure, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
|
|
2198
|
+
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy$1 as lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
|