@temporary-name/server 1.9.3-alpha.121f1a14eceb7f2aa23c6993c2adce0ccca377db → 1.9.3-alpha.1a5ff4923d25c9d83e80d717687ebc859f5312f2
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.d.mts +3 -3
- package/dist/adapters/aws-lambda/index.d.ts +3 -3
- package/dist/adapters/aws-lambda/index.mjs +4 -3
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +4 -3
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +4 -3
- package/dist/adapters/standard/index.d.mts +20 -31
- package/dist/adapters/standard/index.d.ts +20 -31
- package/dist/adapters/standard/index.mjs +4 -3
- package/dist/index.d.mts +53 -1047
- package/dist/index.d.ts +53 -1047
- package/dist/index.mjs +77 -1886
- package/dist/openapi/index.d.mts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.mjs +59 -76
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.CMTfy2UB.mjs → server.B--sAUhn.mjs} +55 -94
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.BCcLYvdF.d.mts} +1 -2
- package/dist/shared/server.CHV9AQHl.mjs +412 -0
- package/dist/shared/{server.C1fnTLq0.d.mts → server.CdeqmULw.d.ts} +1 -2
- package/dist/shared/{server.BeuTpcmO.d.mts → server.DHezmW6C.d.mts} +2 -2
- package/dist/shared/{server.SLLuK6_v.d.ts → server.Da-qLzdU.d.ts} +2 -2
- package/dist/shared/{server.BKSOrA6h.d.mts → server.DecvGKtb.d.mts} +125 -75
- package/dist/shared/{server.BKSOrA6h.d.ts → server.DecvGKtb.d.ts} +125 -75
- package/dist/shared/{server.BEHw7Eyx.mjs → server.Kxw442A9.mjs} +1 -1
- package/package.json +10 -9
- package/dist/shared/server.BZtKt8i8.mjs +0 -201
package/dist/index.mjs
CHANGED
|
@@ -1,136 +1,13 @@
|
|
|
1
|
+
import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, prefixRoute, initialSchemas, isContractProcedure, getContractRouter } from '@temporary-name/contract';
|
|
2
|
+
export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
1
3
|
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
4
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
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';
|
|
5
|
+
import { SchemaClass, gatingContext } from '@temporary-name/zod';
|
|
6
|
+
import { P as Procedure, c as createProcedureClient, e as enhanceRouter, a as addMiddleware, s as setHiddenRouterContract, l as lazyInternal, g as getLazyMeta, u as unlazy, i as isProcedure, b as isLazy, d as getRouter } from './shared/server.CHV9AQHl.mjs';
|
|
7
|
+
export { L as LAZY_SYMBOL, p as createAccessibleLazyRouter, f as createORPCErrorConstructorMap, o as getHiddenRouterContract, k as isStartWithMiddlewares, h as lazy, m as mergeCurrentContext, n as mergeMiddlewares, j as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, q as unlazyRouter } from './shared/server.CHV9AQHl.mjs';
|
|
10
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
11
9
|
|
|
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
|
-
}
|
|
35
|
-
|
|
36
|
-
function decorateMiddleware(middleware) {
|
|
37
|
-
const decorated = ((...args) => middleware(...args));
|
|
38
|
-
decorated.mapInput = (mapInput) => {
|
|
39
|
-
const mapped = decorateMiddleware(
|
|
40
|
-
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
|
41
|
-
);
|
|
42
|
-
return mapped;
|
|
43
|
-
};
|
|
44
|
-
decorated.concat = (concatMiddleware, mapInput) => {
|
|
45
|
-
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
|
46
|
-
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
|
47
|
-
const merged = middleware(
|
|
48
|
-
{
|
|
49
|
-
...options,
|
|
50
|
-
next: (...[nextOptions1]) => mapped(
|
|
51
|
-
{
|
|
52
|
-
...options,
|
|
53
|
-
context: { ...options.context, ...nextOptions1?.context },
|
|
54
|
-
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
|
55
|
-
},
|
|
56
|
-
input,
|
|
57
|
-
output,
|
|
58
|
-
...rest
|
|
59
|
-
)
|
|
60
|
-
},
|
|
61
|
-
input,
|
|
62
|
-
output,
|
|
63
|
-
...rest
|
|
64
|
-
);
|
|
65
|
-
return merged;
|
|
66
|
-
});
|
|
67
|
-
return concatted;
|
|
68
|
-
};
|
|
69
|
-
return decorated;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
class Procedure {
|
|
73
|
-
/**
|
|
74
|
-
* This property holds the defined options.
|
|
75
|
-
*/
|
|
76
|
-
"~orpc";
|
|
77
|
-
constructor(def) {
|
|
78
|
-
this["~orpc"] = def;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function isProcedure(item) {
|
|
82
|
-
if (item instanceof Procedure) {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
10
|
class DecoratedProcedure extends Procedure {
|
|
89
|
-
/**
|
|
90
|
-
* Adds type-safe custom errors.
|
|
91
|
-
* The provided errors are spared-merged with any existing errors.
|
|
92
|
-
*
|
|
93
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
94
|
-
*/
|
|
95
|
-
errors(errors) {
|
|
96
|
-
return new DecoratedProcedure({
|
|
97
|
-
...this["~orpc"],
|
|
98
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Sets or updates the metadata.
|
|
103
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
104
|
-
*
|
|
105
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
106
|
-
*/
|
|
107
|
-
meta(meta) {
|
|
108
|
-
return new DecoratedProcedure({
|
|
109
|
-
...this["~orpc"],
|
|
110
|
-
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Sets or updates the route definition.
|
|
115
|
-
* The provided route is spared-merged with any existing route.
|
|
116
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
117
|
-
*
|
|
118
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
119
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
120
|
-
*/
|
|
121
|
-
route(route) {
|
|
122
|
-
return new DecoratedProcedure({
|
|
123
|
-
...this["~orpc"],
|
|
124
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
use(middleware, mapInput) {
|
|
128
|
-
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
|
129
|
-
return new DecoratedProcedure({
|
|
130
|
-
...this["~orpc"],
|
|
131
|
-
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
11
|
/**
|
|
135
12
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
136
13
|
*
|
|
@@ -149,1717 +26,11 @@ class DecoratedProcedure extends Procedure {
|
|
|
149
26
|
}
|
|
150
27
|
}
|
|
151
28
|
|
|
152
|
-
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
|
153
|
-
function setHiddenRouterContract(router, contract) {
|
|
154
|
-
return new Proxy(router, {
|
|
155
|
-
get(target, key) {
|
|
156
|
-
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
|
157
|
-
return contract;
|
|
158
|
-
}
|
|
159
|
-
return Reflect.get(target, key);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function getHiddenRouterContract(router) {
|
|
164
|
-
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function getRouter(router, path) {
|
|
168
|
-
let current = router;
|
|
169
|
-
for (let i = 0; i < path.length; i++) {
|
|
170
|
-
const segment = path[i];
|
|
171
|
-
if (!current) {
|
|
172
|
-
return void 0;
|
|
173
|
-
}
|
|
174
|
-
if (isProcedure(current)) {
|
|
175
|
-
return void 0;
|
|
176
|
-
}
|
|
177
|
-
if (!isLazy(current)) {
|
|
178
|
-
current = current[segment];
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
const lazied = current;
|
|
182
|
-
const rest = path.slice(i);
|
|
183
|
-
return lazy$1(async () => {
|
|
184
|
-
const unwrapped = await unlazy(lazied);
|
|
185
|
-
const next = getRouter(unwrapped.default, rest);
|
|
186
|
-
return unlazy(next);
|
|
187
|
-
}, getLazyMeta(lazied));
|
|
188
|
-
}
|
|
189
|
-
return current;
|
|
190
|
-
}
|
|
191
|
-
function createAccessibleLazyRouter(lazied) {
|
|
192
|
-
const recursive = new Proxy(lazied, {
|
|
193
|
-
get(target, key) {
|
|
194
|
-
if (typeof key !== "string") {
|
|
195
|
-
return Reflect.get(target, key);
|
|
196
|
-
}
|
|
197
|
-
const next = getRouter(lazied, [key]);
|
|
198
|
-
return createAccessibleLazyRouter(next);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
return recursive;
|
|
202
|
-
}
|
|
203
|
-
function enhanceRouter(router, options) {
|
|
204
|
-
if (isLazy(router)) {
|
|
205
|
-
const laziedMeta = getLazyMeta(router);
|
|
206
|
-
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
|
207
|
-
const enhanced2 = lazy$1(
|
|
208
|
-
async () => {
|
|
209
|
-
const { default: unlaziedRouter } = await unlazy(router);
|
|
210
|
-
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
|
211
|
-
return unlazy(enhanced3);
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
...laziedMeta,
|
|
215
|
-
prefix: enhancedPrefix
|
|
216
|
-
}
|
|
217
|
-
);
|
|
218
|
-
const accessible = createAccessibleLazyRouter(enhanced2);
|
|
219
|
-
return accessible;
|
|
220
|
-
}
|
|
221
|
-
if (isProcedure(router)) {
|
|
222
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, {
|
|
223
|
-
dedupeLeading: options.dedupeLeadingMiddlewares
|
|
224
|
-
});
|
|
225
|
-
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
|
226
|
-
const enhanced2 = new Procedure({
|
|
227
|
-
...router["~orpc"],
|
|
228
|
-
route: enhanceRoute(router["~orpc"].route, options),
|
|
229
|
-
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
230
|
-
middlewares: newMiddlewares,
|
|
231
|
-
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
232
|
-
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
|
233
|
-
});
|
|
234
|
-
return enhanced2;
|
|
235
|
-
}
|
|
236
|
-
const enhanced = {};
|
|
237
|
-
for (const key in router) {
|
|
238
|
-
enhanced[key] = enhanceRouter(router[key], options);
|
|
239
|
-
}
|
|
240
|
-
return enhanced;
|
|
241
|
-
}
|
|
242
|
-
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
|
243
|
-
let currentRouter = options.router;
|
|
244
|
-
const hiddenContract = getHiddenRouterContract(options.router);
|
|
245
|
-
if (hiddenContract !== void 0) {
|
|
246
|
-
currentRouter = hiddenContract;
|
|
247
|
-
}
|
|
248
|
-
if (isLazy(currentRouter)) {
|
|
249
|
-
lazyOptions.push({
|
|
250
|
-
router: currentRouter,
|
|
251
|
-
path: options.path
|
|
252
|
-
});
|
|
253
|
-
} else if (isContractProcedure(currentRouter)) {
|
|
254
|
-
callback({
|
|
255
|
-
contract: currentRouter,
|
|
256
|
-
path: options.path
|
|
257
|
-
});
|
|
258
|
-
} else {
|
|
259
|
-
for (const key in currentRouter) {
|
|
260
|
-
traverseContractProcedures(
|
|
261
|
-
{
|
|
262
|
-
router: currentRouter[key],
|
|
263
|
-
path: [...options.path, key]
|
|
264
|
-
},
|
|
265
|
-
callback,
|
|
266
|
-
lazyOptions
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return lazyOptions;
|
|
271
|
-
}
|
|
272
|
-
async function resolveContractProcedures(options, callback) {
|
|
273
|
-
const pending = [options];
|
|
274
|
-
for (const options2 of pending) {
|
|
275
|
-
const lazyOptions = traverseContractProcedures(options2, callback);
|
|
276
|
-
for (const options3 of lazyOptions) {
|
|
277
|
-
const { default: router } = await unlazy(options3.router);
|
|
278
|
-
pending.push({
|
|
279
|
-
router,
|
|
280
|
-
path: options3.path
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
async function unlazyRouter(router) {
|
|
286
|
-
if (isProcedure(router)) {
|
|
287
|
-
return router;
|
|
288
|
-
}
|
|
289
|
-
const unlazied = {};
|
|
290
|
-
for (const key in router) {
|
|
291
|
-
const item = router[key];
|
|
292
|
-
const { default: unlaziedRouter } = await unlazy(item);
|
|
293
|
-
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
|
294
|
-
}
|
|
295
|
-
return unlazied;
|
|
296
|
-
}
|
|
297
|
-
|
|
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);
|
|
304
|
-
}
|
|
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);
|
|
315
|
-
}
|
|
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
29
|
class ProcedureBuilder extends ContractProcedure {
|
|
30
|
+
z;
|
|
1861
31
|
constructor(def) {
|
|
1862
32
|
super(def);
|
|
33
|
+
this.z = new SchemaClass();
|
|
1863
34
|
}
|
|
1864
35
|
/**
|
|
1865
36
|
* Adds type-safe custom errors to the contract.
|
|
@@ -1894,20 +65,39 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
1894
65
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
1895
66
|
*/
|
|
1896
67
|
route(route) {
|
|
68
|
+
const { prefix } = this["~orpc"];
|
|
1897
69
|
return new ProcedureBuilder({
|
|
1898
70
|
...this["~orpc"],
|
|
1899
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
71
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
1900
72
|
});
|
|
1901
73
|
}
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
74
|
+
path(schema) {
|
|
75
|
+
return new ProcedureBuilder({
|
|
76
|
+
...this["~orpc"],
|
|
77
|
+
schemas: {
|
|
78
|
+
...this["~orpc"].schemas,
|
|
79
|
+
pathSchema: schema
|
|
80
|
+
},
|
|
81
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
query(schema) {
|
|
85
|
+
return new ProcedureBuilder({
|
|
86
|
+
...this["~orpc"],
|
|
87
|
+
schemas: {
|
|
88
|
+
...this["~orpc"].schemas,
|
|
89
|
+
querySchema: schema
|
|
90
|
+
},
|
|
91
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
body(schema) {
|
|
1908
95
|
return new ProcedureBuilder({
|
|
1909
96
|
...this["~orpc"],
|
|
1910
|
-
|
|
97
|
+
schemas: {
|
|
98
|
+
...this["~orpc"].schemas,
|
|
99
|
+
bodySchema: schema
|
|
100
|
+
},
|
|
1911
101
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
1912
102
|
});
|
|
1913
103
|
}
|
|
@@ -1919,7 +109,10 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
1919
109
|
output(schema) {
|
|
1920
110
|
return new ProcedureBuilder({
|
|
1921
111
|
...this["~orpc"],
|
|
1922
|
-
|
|
112
|
+
schemas: {
|
|
113
|
+
...this["~orpc"].schemas,
|
|
114
|
+
outputSchema: schema
|
|
115
|
+
},
|
|
1923
116
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
1924
117
|
});
|
|
1925
118
|
}
|
|
@@ -1991,34 +184,43 @@ class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
|
1991
184
|
router(router) {
|
|
1992
185
|
return enhanceRouter(router, this["~orpc"]);
|
|
1993
186
|
}
|
|
1994
|
-
/**
|
|
1995
|
-
* Create a lazy router
|
|
1996
|
-
* And applies all of the previously defined options to the specified router.
|
|
1997
|
-
*
|
|
1998
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
1999
|
-
*/
|
|
2000
|
-
lazyRoute(loader) {
|
|
2001
|
-
return enhanceRouter(lazy$1(loader), this["~orpc"]);
|
|
2002
|
-
}
|
|
2003
187
|
}
|
|
2004
188
|
|
|
2005
|
-
|
|
2006
|
-
const
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
189
|
+
function decorateMiddleware(middleware) {
|
|
190
|
+
const decorated = ((...args) => middleware(...args));
|
|
191
|
+
decorated.mapInput = (mapInput) => {
|
|
192
|
+
const mapped = decorateMiddleware(
|
|
193
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
|
194
|
+
);
|
|
195
|
+
return mapped;
|
|
196
|
+
};
|
|
197
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
|
198
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
|
199
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
|
200
|
+
const merged = middleware(
|
|
201
|
+
{
|
|
202
|
+
...options,
|
|
203
|
+
next: (...[nextOptions1]) => mapped(
|
|
204
|
+
{
|
|
205
|
+
...options,
|
|
206
|
+
context: { ...options.context, ...nextOptions1?.context },
|
|
207
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
|
208
|
+
},
|
|
209
|
+
input,
|
|
210
|
+
output,
|
|
211
|
+
...rest
|
|
212
|
+
)
|
|
213
|
+
},
|
|
214
|
+
input,
|
|
215
|
+
output,
|
|
216
|
+
...rest
|
|
217
|
+
);
|
|
218
|
+
return merged;
|
|
219
|
+
});
|
|
220
|
+
return concatted;
|
|
221
|
+
};
|
|
222
|
+
return decorated;
|
|
223
|
+
}
|
|
2022
224
|
|
|
2023
225
|
class Builder extends BuilderWithMiddlewares {
|
|
2024
226
|
/**
|
|
@@ -2039,7 +241,7 @@ class Builder extends BuilderWithMiddlewares {
|
|
|
2039
241
|
}
|
|
2040
242
|
}
|
|
2041
243
|
function createApiBuilder(opts = {}) {
|
|
2042
|
-
|
|
244
|
+
return new Builder({
|
|
2043
245
|
route: {},
|
|
2044
246
|
meta: opts.meta ?? {},
|
|
2045
247
|
errorMap: {},
|
|
@@ -2050,11 +252,11 @@ function createApiBuilder(opts = {}) {
|
|
|
2050
252
|
console.dir(error, { depth: null });
|
|
2051
253
|
})
|
|
2052
254
|
],
|
|
255
|
+
schemas: initialSchemas,
|
|
2053
256
|
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
2054
257
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
2055
258
|
dedupeLeadingMiddlewares: true
|
|
2056
259
|
});
|
|
2057
|
-
return Object.assign(base, miniSchema, { z: fullSchema });
|
|
2058
260
|
}
|
|
2059
261
|
const os = createApiBuilder();
|
|
2060
262
|
|
|
@@ -2092,17 +294,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
2092
294
|
});
|
|
2093
295
|
return setHiddenRouterContract(adapted, contract);
|
|
2094
296
|
};
|
|
2095
|
-
} else if (key === "lazyRoute") {
|
|
2096
|
-
method = (loader) => {
|
|
2097
|
-
const adapted = enhanceRouter(lazy$1(loader), {
|
|
2098
|
-
middlewares,
|
|
2099
|
-
errorMap: {},
|
|
2100
|
-
prefix: void 0,
|
|
2101
|
-
tags: void 0,
|
|
2102
|
-
dedupeLeadingMiddlewares: true
|
|
2103
|
-
});
|
|
2104
|
-
return setHiddenRouterContract(adapted, contract);
|
|
2105
|
-
};
|
|
2106
297
|
}
|
|
2107
298
|
const next = getContractRouter(target, [key]);
|
|
2108
299
|
if (!next) {
|
|
@@ -2144,7 +335,7 @@ function implement(contract) {
|
|
|
2144
335
|
}
|
|
2145
336
|
|
|
2146
337
|
function createAssertedLazyProcedure(lazied) {
|
|
2147
|
-
const lazyProcedure =
|
|
338
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
2148
339
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
2149
340
|
if (!isProcedure(maybeProcedure)) {
|
|
2150
341
|
throw new Error(`
|
|
@@ -2195,4 +386,4 @@ function createRouterClient(router, ...rest) {
|
|
|
2195
386
|
return recursive;
|
|
2196
387
|
}
|
|
2197
388
|
|
|
2198
|
-
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call,
|
|
389
|
+
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, lazyInternal, os, setHiddenRouterContract, unlazy };
|