@temporary-name/server 1.9.3-alpha.a252b3ff8cb6bf7deaa6d41dc9ac8a8d50edd80e → 1.9.3-alpha.a253b67a3639148c12f13a47295e1922182adecd
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 +4 -5
- package/dist/adapters/aws-lambda/index.d.ts +4 -5
- package/dist/adapters/aws-lambda/index.mjs +4 -3
- package/dist/adapters/fetch/index.d.mts +4 -5
- package/dist/adapters/fetch/index.d.ts +4 -5
- package/dist/adapters/fetch/index.mjs +4 -3
- package/dist/adapters/node/index.d.mts +4 -5
- package/dist/adapters/node/index.d.ts +4 -5
- package/dist/adapters/node/index.mjs +4 -3
- package/dist/adapters/standard/index.d.mts +20 -32
- package/dist/adapters/standard/index.d.ts +20 -32
- package/dist/adapters/standard/index.mjs +5 -4
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +54 -1194
- package/dist/index.d.ts +54 -1194
- package/dist/index.mjs +168 -1983
- package/dist/openapi/index.d.mts +9 -9
- package/dist/openapi/index.d.ts +9 -9
- package/dist/openapi/index.mjs +64 -133
- package/dist/plugins/index.d.mts +5 -83
- package/dist/plugins/index.d.ts +5 -83
- package/dist/plugins/index.mjs +17 -189
- package/dist/shared/{server.SLLuK6_v.d.ts → server.BR0GBxlv.d.ts} +2 -2
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/{server.BeuTpcmO.d.mts → server.C7HccVwN.d.mts} +2 -2
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.CPThlZ_E.d.ts} +6 -8
- package/dist/shared/server.D-DR5Z00.mjs +362 -0
- package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
- package/dist/shared/server.oy0285uM.d.mts +252 -0
- package/dist/shared/server.oy0285uM.d.ts +252 -0
- package/dist/shared/{server.CMTfy2UB.mjs → server.rZDPWnA8.mjs} +65 -124
- package/dist/shared/{server.C1fnTLq0.d.mts → server.y97Td78c.d.mts} +6 -8
- package/package.json +10 -21
- package/dist/shared/server.BKSOrA6h.d.mts +0 -192
- package/dist/shared/server.BKSOrA6h.d.ts +0 -192
- package/dist/shared/server.BZtKt8i8.mjs +0 -201
package/dist/index.mjs
CHANGED
|
@@ -1,136 +1,66 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
1
|
+
import { mergePrefix, mergeTags, mergeMeta, parseEndpointDefinition, mergeRoute, prefixRoute, initialSchemas } from '@temporary-name/contract';
|
|
2
|
+
export { ValidationError, eventIterator } from '@temporary-name/contract';
|
|
3
|
+
import { assertNever, splitFirst, ORPCError, onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
4
|
+
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
|
+
import { SchemaClass, object, core, gatingContext } from '@temporary-name/zod';
|
|
6
|
+
import { g as getCookie } from './shared/server.C1RJffw4.mjs';
|
|
7
|
+
import { P as Procedure, c as createProcedureClient, e as enhanceRouter, C as Contract, a as addMiddleware, l as lazyInternal, g as getLazyMeta, u as unlazy, i as isProcedure, b as isLazy, d as getRouter } from './shared/server.D-DR5Z00.mjs';
|
|
8
|
+
export { L as LAZY_SYMBOL, n as createAccessibleLazyRouter, j as isStartWithMiddlewares, f as lazy, m as mergeCurrentContext, k as mergeMiddlewares, h as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, o as unlazyRouter } from './shared/server.D-DR5Z00.mjs';
|
|
10
9
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
10
|
+
import 'cookie';
|
|
11
11
|
|
|
12
|
-
function
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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"];
|
|
12
|
+
function validateTokenPrefix(prefix, token) {
|
|
13
|
+
if (prefix && !token.startsWith(prefix)) {
|
|
14
|
+
throw new ORPCError("UNAUTHORIZED", { message: `Invalid auth token. It must start with "${prefix}"` });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function validateTokenAuth(config, token, options) {
|
|
18
|
+
const { tokenPrefix, validate } = config;
|
|
19
|
+
validateTokenPrefix(tokenPrefix, token);
|
|
20
|
+
return validate(token, options);
|
|
21
|
+
}
|
|
22
|
+
function authByQuery(config, options) {
|
|
23
|
+
const { name, tokenPrefix, validate } = config;
|
|
24
|
+
const query = options.request.url.searchParams;
|
|
25
|
+
const token = query.get(name);
|
|
26
|
+
if (!token) return void 0;
|
|
27
|
+
validateTokenPrefix(tokenPrefix, token);
|
|
28
|
+
return validate(token, options);
|
|
29
|
+
}
|
|
30
|
+
function authByHeader(config, options) {
|
|
31
|
+
const authHeader = options.request.headers.get(config.name);
|
|
32
|
+
return authHeader ? validateTokenAuth(config, authHeader, options) : void 0;
|
|
33
|
+
}
|
|
34
|
+
function authByCookie(config, options) {
|
|
35
|
+
const cookie = getCookie(options.request.headers, config.name);
|
|
36
|
+
return cookie ? validateTokenAuth(config, cookie, options) : void 0;
|
|
37
|
+
}
|
|
38
|
+
function authByBearer(config, options) {
|
|
39
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
40
|
+
if (!authHeader) return void 0;
|
|
41
|
+
const [authType, bearer] = splitFirst(authHeader, " ");
|
|
42
|
+
return authType === "Bearer" ? validateTokenAuth(config, bearer, options) : void 0;
|
|
43
|
+
}
|
|
44
|
+
function authByBasic(config, options) {
|
|
45
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
46
|
+
if (!authHeader) return void 0;
|
|
47
|
+
const [authType, encoded] = splitFirst(authHeader, " ");
|
|
48
|
+
if (authType !== "Basic") return void 0;
|
|
49
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf-8");
|
|
50
|
+
const [username, password] = splitFirst(decoded, ":");
|
|
51
|
+
validateTokenPrefix(config.tokenPrefix, password);
|
|
52
|
+
return config.validate(username, password, options);
|
|
53
|
+
}
|
|
54
|
+
function authByType(config, options) {
|
|
55
|
+
const { type } = config;
|
|
56
|
+
return type === "header" ? authByHeader(config, options) : type === "query" ? authByQuery(config, options) : type === "cookie" ? authByCookie(config, options) : type === "bearer" ? authByBearer(config, options) : type === "basic" ? authByBasic(config, options) : type === "none" ? false : assertNever(type);
|
|
57
|
+
}
|
|
58
|
+
function authDescription(config) {
|
|
59
|
+
const { type } = config;
|
|
60
|
+
return type === "basic" ? "a Basic Authentication header" : type === "bearer" ? "a Bearer Authentication header" : type === "header" ? `a header named "${config.name}"` : type === "query" ? `a query parameter named "${config.name}"` : type === "cookie" ? `a cookie named "${config.name}"` : type === "none" ? "no authentication" : assertNever(type);
|
|
86
61
|
}
|
|
87
62
|
|
|
88
63
|
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
64
|
/**
|
|
135
65
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
136
66
|
*
|
|
@@ -149,1729 +79,11 @@ class DecoratedProcedure extends Procedure {
|
|
|
149
79
|
}
|
|
150
80
|
}
|
|
151
81
|
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
class ProcedureBuilder extends ContractProcedure {
|
|
82
|
+
class ProcedureBuilder extends Contract {
|
|
83
|
+
z;
|
|
1861
84
|
constructor(def) {
|
|
1862
85
|
super(def);
|
|
1863
|
-
|
|
1864
|
-
/**
|
|
1865
|
-
* Adds type-safe custom errors to the contract.
|
|
1866
|
-
* The provided errors are spared-merged with any existing errors in the contract.
|
|
1867
|
-
*
|
|
1868
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
1869
|
-
*/
|
|
1870
|
-
errors(errors) {
|
|
1871
|
-
return new ProcedureBuilder({
|
|
1872
|
-
...this["~orpc"],
|
|
1873
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
1874
|
-
});
|
|
86
|
+
this.z = new SchemaClass();
|
|
1875
87
|
}
|
|
1876
88
|
/**
|
|
1877
89
|
* Sets or updates the metadata for the contract.
|
|
@@ -1885,6 +97,19 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
1885
97
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
1886
98
|
});
|
|
1887
99
|
}
|
|
100
|
+
endpoint(stringsOrEndpoint, ...values) {
|
|
101
|
+
const { method, path, pathSchema } = parseEndpointDefinition(stringsOrEndpoint, values);
|
|
102
|
+
const { prefix } = this["~orpc"];
|
|
103
|
+
const route = { method, path };
|
|
104
|
+
return new ProcedureBuilder({
|
|
105
|
+
...this["~orpc"],
|
|
106
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route),
|
|
107
|
+
schemas: {
|
|
108
|
+
...this["~orpc"].schemas,
|
|
109
|
+
pathSchema
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
1888
113
|
/**
|
|
1889
114
|
* Sets or updates the route definition for the contract.
|
|
1890
115
|
* The provided route is spared-merged with any existing route in the contract.
|
|
@@ -1893,22 +118,30 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
1893
118
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
1894
119
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
1895
120
|
*/
|
|
1896
|
-
|
|
121
|
+
endpointOpts(route) {
|
|
1897
122
|
const { prefix } = this["~orpc"];
|
|
1898
123
|
return new ProcedureBuilder({
|
|
1899
124
|
...this["~orpc"],
|
|
1900
125
|
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
1901
126
|
});
|
|
1902
127
|
}
|
|
1903
|
-
|
|
1904
|
-
* Defines the input validation schema.
|
|
1905
|
-
*
|
|
1906
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
1907
|
-
*/
|
|
1908
|
-
input(schema) {
|
|
128
|
+
query(schema) {
|
|
1909
129
|
return new ProcedureBuilder({
|
|
1910
130
|
...this["~orpc"],
|
|
1911
|
-
|
|
131
|
+
schemas: {
|
|
132
|
+
...this["~orpc"].schemas,
|
|
133
|
+
querySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
134
|
+
},
|
|
135
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
body(schema) {
|
|
139
|
+
return new ProcedureBuilder({
|
|
140
|
+
...this["~orpc"],
|
|
141
|
+
schemas: {
|
|
142
|
+
...this["~orpc"].schemas,
|
|
143
|
+
bodySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
144
|
+
},
|
|
1912
145
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
1913
146
|
});
|
|
1914
147
|
}
|
|
@@ -1920,7 +153,10 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
1920
153
|
output(schema) {
|
|
1921
154
|
return new ProcedureBuilder({
|
|
1922
155
|
...this["~orpc"],
|
|
1923
|
-
|
|
156
|
+
schemas: {
|
|
157
|
+
...this["~orpc"].schemas,
|
|
158
|
+
outputSchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
159
|
+
},
|
|
1924
160
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
1925
161
|
});
|
|
1926
162
|
}
|
|
@@ -1937,6 +173,36 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
1937
173
|
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
1938
174
|
});
|
|
1939
175
|
}
|
|
176
|
+
// `& {}` is so AuthType will be expanded in parameter info tooltips.
|
|
177
|
+
// The default of false for ValidatedAuthContext is used when you pass in the type 'none'. We use false
|
|
178
|
+
// because we can't use null or undefined (see ValidatedAuthContext) but we still want it to be falsy.
|
|
179
|
+
useAuth(type, ...rest) {
|
|
180
|
+
const config = { type, ...rest[0] };
|
|
181
|
+
const middleware = os.$context().middleware(async (options) => {
|
|
182
|
+
const { next, context } = options;
|
|
183
|
+
if (context.auth) return next();
|
|
184
|
+
const auth = await authByType(config, options);
|
|
185
|
+
if (auth === void 0) {
|
|
186
|
+
const { authConfigs } = options.procedure["~orpc"];
|
|
187
|
+
if (context.auth !== false && config === authConfigs.at(-1)) {
|
|
188
|
+
let authDescriptions = authConfigs.map(authDescription).join(", ");
|
|
189
|
+
if (authConfigs.length > 1) {
|
|
190
|
+
authDescriptions = `one of: ${authDescriptions}`;
|
|
191
|
+
}
|
|
192
|
+
throw new ORPCError("UNAUTHORIZED", {
|
|
193
|
+
message: `Authentication required. You must provide ${authDescriptions}`
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return next();
|
|
197
|
+
}
|
|
198
|
+
return next({ context: { auth } });
|
|
199
|
+
});
|
|
200
|
+
return new this.constructor({
|
|
201
|
+
...this["~orpc"],
|
|
202
|
+
authConfigs: [...this["~orpc"].authConfigs, config],
|
|
203
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
204
|
+
});
|
|
205
|
+
}
|
|
1940
206
|
useGating(gates, isGateEnabled) {
|
|
1941
207
|
return this.use(({ next, context }) => {
|
|
1942
208
|
return gatingContext.run(
|
|
@@ -1951,6 +217,9 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
1951
217
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
1952
218
|
*/
|
|
1953
219
|
handler(handler) {
|
|
220
|
+
if (this["~orpc"].schemas.outputSchema === initialSchemas.outputSchema) {
|
|
221
|
+
throw new Error("You must call .output() before calling .handler()");
|
|
222
|
+
}
|
|
1954
223
|
return new DecoratedProcedure({
|
|
1955
224
|
...this["~orpc"],
|
|
1956
225
|
handler
|
|
@@ -1992,34 +261,43 @@ class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
|
1992
261
|
router(router) {
|
|
1993
262
|
return enhanceRouter(router, this["~orpc"]);
|
|
1994
263
|
}
|
|
1995
|
-
/**
|
|
1996
|
-
* Create a lazy router
|
|
1997
|
-
* And applies all of the previously defined options to the specified router.
|
|
1998
|
-
*
|
|
1999
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
2000
|
-
*/
|
|
2001
|
-
lazyRoute(loader) {
|
|
2002
|
-
return enhanceRouter(lazy$1(loader), this["~orpc"]);
|
|
2003
|
-
}
|
|
2004
264
|
}
|
|
2005
265
|
|
|
2006
|
-
|
|
2007
|
-
const
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
266
|
+
function decorateMiddleware(middleware) {
|
|
267
|
+
const decorated = ((...args) => middleware(...args));
|
|
268
|
+
decorated.mapInput = (mapInput) => {
|
|
269
|
+
const mapped = decorateMiddleware(
|
|
270
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
|
271
|
+
);
|
|
272
|
+
return mapped;
|
|
273
|
+
};
|
|
274
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
|
275
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
|
276
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
|
277
|
+
const merged = middleware(
|
|
278
|
+
{
|
|
279
|
+
...options,
|
|
280
|
+
next: (...[nextOptions1]) => mapped(
|
|
281
|
+
{
|
|
282
|
+
...options,
|
|
283
|
+
context: { ...options.context, ...nextOptions1?.context },
|
|
284
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
|
285
|
+
},
|
|
286
|
+
input,
|
|
287
|
+
output,
|
|
288
|
+
...rest
|
|
289
|
+
)
|
|
290
|
+
},
|
|
291
|
+
input,
|
|
292
|
+
output,
|
|
293
|
+
...rest
|
|
294
|
+
);
|
|
295
|
+
return merged;
|
|
296
|
+
});
|
|
297
|
+
return concatted;
|
|
298
|
+
};
|
|
299
|
+
return decorated;
|
|
300
|
+
}
|
|
2023
301
|
|
|
2024
302
|
class Builder extends BuilderWithMiddlewares {
|
|
2025
303
|
/**
|
|
@@ -2040,10 +318,9 @@ class Builder extends BuilderWithMiddlewares {
|
|
|
2040
318
|
}
|
|
2041
319
|
}
|
|
2042
320
|
function createApiBuilder(opts = {}) {
|
|
2043
|
-
|
|
321
|
+
return new Builder({
|
|
2044
322
|
route: {},
|
|
2045
323
|
meta: opts.meta ?? {},
|
|
2046
|
-
errorMap: {},
|
|
2047
324
|
inputValidationIndex: 0,
|
|
2048
325
|
outputValidationIndex: 0,
|
|
2049
326
|
middlewares: [
|
|
@@ -2051,101 +328,17 @@ function createApiBuilder(opts = {}) {
|
|
|
2051
328
|
console.dir(error, { depth: null });
|
|
2052
329
|
})
|
|
2053
330
|
],
|
|
331
|
+
schemas: initialSchemas,
|
|
2054
332
|
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
2055
333
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
2056
|
-
dedupeLeadingMiddlewares: true
|
|
334
|
+
dedupeLeadingMiddlewares: true,
|
|
335
|
+
authConfigs: []
|
|
2057
336
|
});
|
|
2058
|
-
return Object.assign(base, miniSchema, { z: fullSchema });
|
|
2059
337
|
}
|
|
2060
338
|
const os = createApiBuilder();
|
|
2061
339
|
|
|
2062
|
-
function implementerInternal(contract, middlewares) {
|
|
2063
|
-
if (isContractProcedure(contract)) {
|
|
2064
|
-
const impl2 = new Builder({
|
|
2065
|
-
...contract["~orpc"],
|
|
2066
|
-
middlewares,
|
|
2067
|
-
inputValidationIndex: middlewares.length,
|
|
2068
|
-
outputValidationIndex: middlewares.length,
|
|
2069
|
-
dedupeLeadingMiddlewares: true
|
|
2070
|
-
});
|
|
2071
|
-
return impl2;
|
|
2072
|
-
}
|
|
2073
|
-
const impl = new Proxy(contract, {
|
|
2074
|
-
get: (target, key) => {
|
|
2075
|
-
if (typeof key !== "string") {
|
|
2076
|
-
return Reflect.get(target, key);
|
|
2077
|
-
}
|
|
2078
|
-
let method;
|
|
2079
|
-
if (key === "middleware") {
|
|
2080
|
-
method = (mid) => decorateMiddleware(mid);
|
|
2081
|
-
} else if (key === "use") {
|
|
2082
|
-
method = (mid) => {
|
|
2083
|
-
return implementerInternal(contract, addMiddleware(middlewares, mid));
|
|
2084
|
-
};
|
|
2085
|
-
} else if (key === "router") {
|
|
2086
|
-
method = (router) => {
|
|
2087
|
-
const adapted = enhanceRouter(router, {
|
|
2088
|
-
middlewares,
|
|
2089
|
-
errorMap: {},
|
|
2090
|
-
prefix: void 0,
|
|
2091
|
-
tags: void 0,
|
|
2092
|
-
dedupeLeadingMiddlewares: true
|
|
2093
|
-
});
|
|
2094
|
-
return setHiddenRouterContract(adapted, contract);
|
|
2095
|
-
};
|
|
2096
|
-
} else if (key === "lazyRoute") {
|
|
2097
|
-
method = (loader) => {
|
|
2098
|
-
const adapted = enhanceRouter(lazy$1(loader), {
|
|
2099
|
-
middlewares,
|
|
2100
|
-
errorMap: {},
|
|
2101
|
-
prefix: void 0,
|
|
2102
|
-
tags: void 0,
|
|
2103
|
-
dedupeLeadingMiddlewares: true
|
|
2104
|
-
});
|
|
2105
|
-
return setHiddenRouterContract(adapted, contract);
|
|
2106
|
-
};
|
|
2107
|
-
}
|
|
2108
|
-
const next = getContractRouter(target, [key]);
|
|
2109
|
-
if (!next) {
|
|
2110
|
-
return method ?? next;
|
|
2111
|
-
}
|
|
2112
|
-
const nextImpl = implementerInternal(next, middlewares);
|
|
2113
|
-
if (method) {
|
|
2114
|
-
return new Proxy(method, {
|
|
2115
|
-
get(_, key2) {
|
|
2116
|
-
return Reflect.get(nextImpl, key2);
|
|
2117
|
-
}
|
|
2118
|
-
});
|
|
2119
|
-
}
|
|
2120
|
-
return nextImpl;
|
|
2121
|
-
}
|
|
2122
|
-
});
|
|
2123
|
-
return impl;
|
|
2124
|
-
}
|
|
2125
|
-
function implement(contract) {
|
|
2126
|
-
const implInternal = implementerInternal(contract, []);
|
|
2127
|
-
const impl = new Proxy(implInternal, {
|
|
2128
|
-
get: (target, key) => {
|
|
2129
|
-
let method;
|
|
2130
|
-
if (key === "$context") {
|
|
2131
|
-
method = () => impl;
|
|
2132
|
-
}
|
|
2133
|
-
const next = Reflect.get(target, key);
|
|
2134
|
-
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
|
2135
|
-
return method || next;
|
|
2136
|
-
}
|
|
2137
|
-
return new Proxy(method, {
|
|
2138
|
-
get(_, key2) {
|
|
2139
|
-
return Reflect.get(next, key2);
|
|
2140
|
-
}
|
|
2141
|
-
});
|
|
2142
|
-
}
|
|
2143
|
-
});
|
|
2144
|
-
return impl;
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
340
|
function createAssertedLazyProcedure(lazied) {
|
|
2148
|
-
const lazyProcedure =
|
|
341
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
2149
342
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
2150
343
|
if (!isProcedure(maybeProcedure)) {
|
|
2151
344
|
throw new Error(`
|
|
@@ -2158,14 +351,6 @@ function createAssertedLazyProcedure(lazied) {
|
|
|
2158
351
|
}, getLazyMeta(lazied));
|
|
2159
352
|
return lazyProcedure;
|
|
2160
353
|
}
|
|
2161
|
-
function createContractedProcedure(procedure, contract) {
|
|
2162
|
-
return new Procedure({
|
|
2163
|
-
...procedure["~orpc"],
|
|
2164
|
-
errorMap: contract["~orpc"].errorMap,
|
|
2165
|
-
route: contract["~orpc"].route,
|
|
2166
|
-
meta: contract["~orpc"].meta
|
|
2167
|
-
});
|
|
2168
|
-
}
|
|
2169
354
|
function call(procedure, input, ...rest) {
|
|
2170
355
|
const options = resolveMaybeOptionalOptions(rest);
|
|
2171
356
|
return createProcedureClient(procedure, options)(input, options);
|
|
@@ -2196,4 +381,4 @@ function createRouterClient(router, ...rest) {
|
|
|
2196
381
|
return recursive;
|
|
2197
382
|
}
|
|
2198
383
|
|
|
2199
|
-
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call,
|
|
384
|
+
export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, isLazy, isProcedure, lazyInternal, os, unlazy };
|