authhero 0.0.1 → 1.0.0
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.github/workflows/release.yml +34 -0
- package/.prettierignore +3 -0
- package/.prettierrc.json +1 -0
- package/README.md +9 -4
- package/apps/react-admin/.eslintrc.js +21 -0
- package/apps/react-admin/README.md +50 -0
- package/apps/react-admin/index.html +125 -0
- package/apps/react-admin/package.json +45 -0
- package/apps/react-admin/prettier.config.js +1 -0
- package/apps/react-admin/public/favicon.ico +0 -0
- package/apps/react-admin/public/manifest.json +15 -0
- package/apps/react-admin/src/App.spec.tsx +39 -0
- package/apps/react-admin/src/App.tsx +75 -0
- package/apps/react-admin/src/Layout.tsx +12 -0
- package/apps/react-admin/src/TenantsApp.tsx +21 -0
- package/apps/react-admin/src/auth0DataProvider.ts +220 -0
- package/apps/react-admin/src/authProvider.ts +42 -0
- package/apps/react-admin/src/components/TenantAppBar.tsx +46 -0
- package/apps/react-admin/src/components/TenantLayout.tsx +17 -0
- package/apps/react-admin/src/components/applications/create.tsx +29 -0
- package/apps/react-admin/src/components/applications/edit.tsx +40 -0
- package/apps/react-admin/src/components/applications/index.ts +3 -0
- package/apps/react-admin/src/components/applications/list.tsx +37 -0
- package/apps/react-admin/src/components/common/DateAgo.tsx +6 -0
- package/apps/react-admin/src/components/common/JsonOutput.tsx +3 -0
- package/apps/react-admin/src/components/common/index.ts +1 -0
- package/apps/react-admin/src/components/connections/create.tsx +11 -0
- package/apps/react-admin/src/components/connections/edit.tsx +66 -0
- package/apps/react-admin/src/components/connections/index.ts +3 -0
- package/apps/react-admin/src/components/connections/list.tsx +15 -0
- package/apps/react-admin/src/components/domains/create.tsx +11 -0
- package/apps/react-admin/src/components/domains/edit.tsx +49 -0
- package/apps/react-admin/src/components/domains/index.ts +3 -0
- package/apps/react-admin/src/components/domains/list.tsx +15 -0
- package/apps/react-admin/src/components/listActions/PostListActions.tsx +10 -0
- package/apps/react-admin/src/components/tenants/create.tsx +15 -0
- package/apps/react-admin/src/components/tenants/edit.tsx +51 -0
- package/apps/react-admin/src/components/tenants/index.ts +2 -0
- package/apps/react-admin/src/components/tenants/list.tsx +48 -0
- package/apps/react-admin/src/components/users/create.tsx +15 -0
- package/apps/react-admin/src/components/users/edit.tsx +108 -0
- package/apps/react-admin/src/components/users/index.ts +3 -0
- package/apps/react-admin/src/components/users/list.tsx +30 -0
- package/apps/react-admin/src/data.json +121 -0
- package/apps/react-admin/src/dataProvider.ts +48 -0
- package/apps/react-admin/src/index.tsx +30 -0
- package/apps/react-admin/src/lib/logs.ts +19 -0
- package/apps/react-admin/tsconfig.json +9 -0
- package/apps/react-admin/tsconfig.node.json +4 -0
- package/apps/react-admin/vercel.json +20 -0
- package/apps/react-admin/vite.config.ts +19 -0
- package/eslint.config.mjs +25 -0
- package/package.json +22 -16
- package/packages/authhero/CHANGELOG.md +7 -0
- package/packages/authhero/README.md +9 -0
- package/packages/authhero/package.json +25 -0
- package/packages/authhero/src/bun.ts +16 -0
- package/packages/authhero/src/index.ts +34 -0
- package/packages/authhero/src/routes/oauth2/index.ts +1 -0
- package/packages/authhero/src/routes/oauth2/well-known.ts +179 -0
- package/{src → packages/authhero/src}/types/Bindings.ts +3 -0
- package/packages/authhero/src/types/JWKS.ts +37 -0
- package/packages/authhero/src/types/Variables.ts +1 -0
- package/packages/authhero/src/types/index.ts +3 -0
- package/packages/authhero/src/vite-env.d.ts +1 -0
- package/packages/authhero/tsconfig.json +11 -0
- package/packages/authhero/tsconfig.node.json +4 -0
- package/packages/create-authhero/package.json +22 -0
- package/packages/create-authhero/src/index.ts +72 -0
- package/packages/create-authhero/src/vite-env.d.ts +1 -0
- package/packages/create-authhero/templates/sqlite/package.json +17 -0
- package/packages/create-authhero/templates/sqlite/src/index.ts +19 -0
- package/packages/create-authhero/templates/sqlite/yarn.lock +48 -0
- package/packages/create-authhero/tsconfig.json +9 -0
- package/packages/create-authhero/tsconfig.node.json +4 -0
- package/packages/create-authhero/vite.config.ts +14 -0
- package/pnpm-workspace.yaml +3 -0
- package/tsconfig.json +28 -8
- package/tsconfig.node.json +7 -2
- package/dist/authhero.js +0 -4912
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/types/Bindings.d.ts +0 -5
- package/dist/types/Bindings.d.ts.map +0 -1
- package/src/index.ts +0 -13
- /package/{src → apps/react-admin/src}/vite-env.d.ts +0 -0
- /package/{vite.config.ts → packages/authhero/vite.config.ts} +0 -0
package/dist/authhero.js
DELETED
|
@@ -1,4912 +0,0 @@
|
|
|
1
|
-
var yr = Object.defineProperty;
|
|
2
|
-
var Mt = (r) => {
|
|
3
|
-
throw TypeError(r);
|
|
4
|
-
};
|
|
5
|
-
var _r = (r, e, t) => e in r ? yr(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
6
|
-
var p = (r, e, t) => _r(r, typeof e != "symbol" ? e + "" : e, t), $t = (r, e, t) => e.has(r) || Mt("Cannot " + t);
|
|
7
|
-
var h = (r, e, t) => ($t(r, e, "read from private field"), t ? t.call(r) : e.get(r)), N = (r, e, t) => e.has(r) ? Mt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), T = (r, e, t, n) => ($t(r, e, "write to private field"), n ? n.call(r, t) : e.set(r, t), t);
|
|
8
|
-
function Se(r, e) {
|
|
9
|
-
var t = {};
|
|
10
|
-
for (var n in r) Object.prototype.hasOwnProperty.call(r, n) && e.indexOf(n) < 0 && (t[n] = r[n]);
|
|
11
|
-
if (r != null && typeof Object.getOwnPropertySymbols == "function")
|
|
12
|
-
for (var s = 0, n = Object.getOwnPropertySymbols(r); s < n.length; s++)
|
|
13
|
-
e.indexOf(n[s]) < 0 && Object.prototype.propertyIsEnumerable.call(r, n[s]) && (t[n[s]] = r[n[s]]);
|
|
14
|
-
return t;
|
|
15
|
-
}
|
|
16
|
-
function x(r, e) {
|
|
17
|
-
var t;
|
|
18
|
-
return ((t = r == null ? void 0 : r._def) === null || t === void 0 ? void 0 : t.typeName) === e;
|
|
19
|
-
}
|
|
20
|
-
function br(r) {
|
|
21
|
-
return "_def" in r;
|
|
22
|
-
}
|
|
23
|
-
function Pe(r, e) {
|
|
24
|
-
const t = r.ZodType.prototype[e];
|
|
25
|
-
r.ZodType.prototype[e] = function(...n) {
|
|
26
|
-
const s = t.apply(this, n);
|
|
27
|
-
return s._def.openapi = this._def.openapi, s;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function wr(r) {
|
|
31
|
-
if (typeof r.ZodType.prototype.openapi < "u")
|
|
32
|
-
return;
|
|
33
|
-
r.ZodType.prototype.openapi = function(s, a) {
|
|
34
|
-
var i, o, c, u, d, f;
|
|
35
|
-
const k = typeof s == "string" ? a : s, E = k ?? {}, { param: R } = E, b = Se(E, ["param"]), S = Object.assign(Object.assign({}, (i = this._def.openapi) === null || i === void 0 ? void 0 : i._internal), typeof s == "string" ? { refId: s } : void 0), D = Object.assign(Object.assign(Object.assign({}, (o = this._def.openapi) === null || o === void 0 ? void 0 : o.metadata), b), !((u = (c = this._def.openapi) === null || c === void 0 ? void 0 : c.metadata) === null || u === void 0) && u.param || R ? {
|
|
36
|
-
param: Object.assign(Object.assign({}, (f = (d = this._def.openapi) === null || d === void 0 ? void 0 : d.metadata) === null || f === void 0 ? void 0 : f.param), R)
|
|
37
|
-
} : void 0), G = new this.constructor(Object.assign(Object.assign({}, this._def), { openapi: Object.assign(Object.assign({}, Object.keys(S).length > 0 ? { _internal: S } : void 0), Object.keys(D).length > 0 ? { metadata: D } : void 0) }));
|
|
38
|
-
if (x(this, "ZodObject")) {
|
|
39
|
-
const V = this.extend;
|
|
40
|
-
G.extend = function(...ge) {
|
|
41
|
-
var ne, Q, K, ve, de, Ot;
|
|
42
|
-
const kt = V.apply(this, ge);
|
|
43
|
-
return kt._def.openapi = {
|
|
44
|
-
_internal: {
|
|
45
|
-
extendedFrom: !((Q = (ne = this._def.openapi) === null || ne === void 0 ? void 0 : ne._internal) === null || Q === void 0) && Q.refId ? { refId: (ve = (K = this._def.openapi) === null || K === void 0 ? void 0 : K._internal) === null || ve === void 0 ? void 0 : ve.refId, schema: this } : (de = this._def.openapi) === null || de === void 0 ? void 0 : de._internal.extendedFrom
|
|
46
|
-
},
|
|
47
|
-
metadata: (Ot = kt._def.openapi) === null || Ot === void 0 ? void 0 : Ot.metadata
|
|
48
|
-
}, kt;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return G;
|
|
52
|
-
}, Pe(r, "optional"), Pe(r, "nullable"), Pe(r, "default"), Pe(r, "transform"), Pe(r, "refine");
|
|
53
|
-
const e = r.ZodObject.prototype.deepPartial;
|
|
54
|
-
r.ZodObject.prototype.deepPartial = function() {
|
|
55
|
-
const s = this._def.shape(), a = e.apply(this), i = a._def.shape();
|
|
56
|
-
return Object.entries(i).forEach(([o, c]) => {
|
|
57
|
-
var u, d;
|
|
58
|
-
c._def.openapi = (d = (u = s[o]) === null || u === void 0 ? void 0 : u._def) === null || d === void 0 ? void 0 : d.openapi;
|
|
59
|
-
}), a._def.openapi = void 0, a;
|
|
60
|
-
};
|
|
61
|
-
const t = r.ZodObject.prototype.pick;
|
|
62
|
-
r.ZodObject.prototype.pick = function(...s) {
|
|
63
|
-
const a = t.apply(this, s);
|
|
64
|
-
return a._def.openapi = void 0, a;
|
|
65
|
-
};
|
|
66
|
-
const n = r.ZodObject.prototype.omit;
|
|
67
|
-
r.ZodObject.prototype.omit = function(...s) {
|
|
68
|
-
const a = n.apply(this, s);
|
|
69
|
-
return a._def.openapi = void 0, a;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function dt(r, e) {
|
|
73
|
-
if (r == null || e === null || e === void 0)
|
|
74
|
-
return r === e;
|
|
75
|
-
if (r === e || r.valueOf() === e.valueOf())
|
|
76
|
-
return !0;
|
|
77
|
-
if (Array.isArray(r) && (!Array.isArray(e) || r.length !== e.length) || !(r instanceof Object) || !(e instanceof Object))
|
|
78
|
-
return !1;
|
|
79
|
-
const t = Object.keys(r);
|
|
80
|
-
return Object.keys(e).every((n) => t.indexOf(n) !== -1) && t.every((n) => dt(r[n], e[n]));
|
|
81
|
-
}
|
|
82
|
-
class xr {
|
|
83
|
-
constructor() {
|
|
84
|
-
this.buckets = /* @__PURE__ */ new Map();
|
|
85
|
-
}
|
|
86
|
-
put(e) {
|
|
87
|
-
const t = this.hashCodeOf(e), n = this.buckets.get(t);
|
|
88
|
-
if (!n) {
|
|
89
|
-
this.buckets.set(t, [e]);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
n.some((a) => dt(a, e)) || n.push(e);
|
|
93
|
-
}
|
|
94
|
-
contains(e) {
|
|
95
|
-
const t = this.hashCodeOf(e), n = this.buckets.get(t);
|
|
96
|
-
return n ? n.some((s) => dt(s, e)) : !1;
|
|
97
|
-
}
|
|
98
|
-
values() {
|
|
99
|
-
return [...this.buckets.values()].flat();
|
|
100
|
-
}
|
|
101
|
-
stats() {
|
|
102
|
-
let e = 0, t = 0, n = 0;
|
|
103
|
-
for (const a of this.buckets.values())
|
|
104
|
-
e += 1, t += a.length, a.length > 1 && (n += 1);
|
|
105
|
-
const s = e / t;
|
|
106
|
-
return { totalBuckets: e, collisions: n, totalValues: t, hashEffectiveness: s };
|
|
107
|
-
}
|
|
108
|
-
hashCodeOf(e) {
|
|
109
|
-
let t = 0;
|
|
110
|
-
if (Array.isArray(e)) {
|
|
111
|
-
for (let n = 0; n < e.length; n++)
|
|
112
|
-
t ^= this.hashCodeOf(e[n]) * n;
|
|
113
|
-
return t;
|
|
114
|
-
}
|
|
115
|
-
if (typeof e == "string") {
|
|
116
|
-
for (let n = 0; n < e.length; n++)
|
|
117
|
-
t ^= e.charCodeAt(n) * n;
|
|
118
|
-
return t;
|
|
119
|
-
}
|
|
120
|
-
if (typeof e == "number")
|
|
121
|
-
return e;
|
|
122
|
-
if (typeof e == "object")
|
|
123
|
-
for (const [n, s] of Object.entries(e))
|
|
124
|
-
t ^= this.hashCodeOf(n) + this.hashCodeOf(s ?? "");
|
|
125
|
-
return t;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function Me(r) {
|
|
129
|
-
return r == null;
|
|
130
|
-
}
|
|
131
|
-
function $e(r, e) {
|
|
132
|
-
const t = {};
|
|
133
|
-
return Object.entries(r).forEach(([n, s]) => {
|
|
134
|
-
t[n] = e(s);
|
|
135
|
-
}), t;
|
|
136
|
-
}
|
|
137
|
-
function Or(r, e) {
|
|
138
|
-
const t = {};
|
|
139
|
-
return Object.entries(r).forEach(([n, s]) => {
|
|
140
|
-
e.some((a) => a === n) || (t[n] = s);
|
|
141
|
-
}), t;
|
|
142
|
-
}
|
|
143
|
-
function xe(r, e) {
|
|
144
|
-
const t = {};
|
|
145
|
-
return Object.entries(r).forEach(([n, s]) => {
|
|
146
|
-
e(s, n) || (t[n] = s);
|
|
147
|
-
}), t;
|
|
148
|
-
}
|
|
149
|
-
function Lt(r) {
|
|
150
|
-
return r.filter((e) => !Me(e));
|
|
151
|
-
}
|
|
152
|
-
const It = dt;
|
|
153
|
-
function kr(r) {
|
|
154
|
-
const e = new xr();
|
|
155
|
-
return r.forEach((t) => e.put(t)), [...e.values()];
|
|
156
|
-
}
|
|
157
|
-
function Kt(r) {
|
|
158
|
-
return typeof r == "string";
|
|
159
|
-
}
|
|
160
|
-
class Tr {
|
|
161
|
-
constructor(e) {
|
|
162
|
-
this.parents = e, this._definitions = [];
|
|
163
|
-
}
|
|
164
|
-
get definitions() {
|
|
165
|
-
var e, t;
|
|
166
|
-
return [...(t = (e = this.parents) === null || e === void 0 ? void 0 : e.flatMap((s) => s.definitions)) !== null && t !== void 0 ? t : [], ...this._definitions];
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Registers a new component schema under /components/schemas/${name}
|
|
170
|
-
*/
|
|
171
|
-
register(e, t) {
|
|
172
|
-
const n = this.schemaWithRefId(e, t);
|
|
173
|
-
return this._definitions.push({ type: "schema", schema: n }), n;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Registers a new parameter schema under /components/parameters/${name}
|
|
177
|
-
*/
|
|
178
|
-
registerParameter(e, t) {
|
|
179
|
-
var n, s, a;
|
|
180
|
-
const i = this.schemaWithRefId(e, t), o = (n = i._def.openapi) === null || n === void 0 ? void 0 : n.metadata, c = i.openapi(Object.assign(Object.assign({}, o), { param: Object.assign(Object.assign({}, o == null ? void 0 : o.param), { name: (a = (s = o == null ? void 0 : o.param) === null || s === void 0 ? void 0 : s.name) !== null && a !== void 0 ? a : e }) }));
|
|
181
|
-
return this._definitions.push({
|
|
182
|
-
type: "parameter",
|
|
183
|
-
schema: c
|
|
184
|
-
}), c;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Registers a new path that would be generated under paths:
|
|
188
|
-
*/
|
|
189
|
-
registerPath(e) {
|
|
190
|
-
this._definitions.push({
|
|
191
|
-
type: "route",
|
|
192
|
-
route: e
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Registers a new webhook that would be generated under webhooks:
|
|
197
|
-
*/
|
|
198
|
-
registerWebhook(e) {
|
|
199
|
-
this._definitions.push({
|
|
200
|
-
type: "webhook",
|
|
201
|
-
webhook: e
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Registers a raw OpenAPI component. Use this if you have a simple object instead of a Zod schema.
|
|
206
|
-
*
|
|
207
|
-
* @param type The component type, e.g. `schemas`, `responses`, `securitySchemes`, etc.
|
|
208
|
-
* @param name The name of the object, it is the key under the component
|
|
209
|
-
* type in the resulting OpenAPI document
|
|
210
|
-
* @param component The actual object to put there
|
|
211
|
-
*/
|
|
212
|
-
registerComponent(e, t, n) {
|
|
213
|
-
return this._definitions.push({
|
|
214
|
-
type: "component",
|
|
215
|
-
componentType: e,
|
|
216
|
-
name: t,
|
|
217
|
-
component: n
|
|
218
|
-
}), {
|
|
219
|
-
name: t,
|
|
220
|
-
ref: { $ref: `#/components/${e}/${t}` }
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
schemaWithRefId(e, t) {
|
|
224
|
-
return t.openapi(e);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
class wt {
|
|
228
|
-
constructor(e) {
|
|
229
|
-
this.message = e;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
class Ce extends wt {
|
|
233
|
-
constructor(e, t) {
|
|
234
|
-
super(e), this.data = t;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
class lt extends wt {
|
|
238
|
-
constructor(e) {
|
|
239
|
-
super(`Missing parameter data, please specify \`${e.missingField}\` and other OpenAPI parameter props using the \`param\` field of \`ZodSchema.openapi\``), this.data = e;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function Ze(r, e) {
|
|
243
|
-
try {
|
|
244
|
-
return r();
|
|
245
|
-
} catch (t) {
|
|
246
|
-
throw t instanceof lt ? new lt(Object.assign(Object.assign({}, t.data), e)) : t;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
class jr extends wt {
|
|
250
|
-
constructor(e) {
|
|
251
|
-
super("Unknown zod object type, please specify `type` and other OpenAPI props using `ZodSchema.openapi`."), this.data = e;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
class I {
|
|
255
|
-
static getMetadata(e) {
|
|
256
|
-
var t;
|
|
257
|
-
const n = this.unwrapChained(e), s = e._def.openapi ? e._def.openapi : n._def.openapi, a = (t = e.description) !== null && t !== void 0 ? t : n.description;
|
|
258
|
-
return {
|
|
259
|
-
_internal: s == null ? void 0 : s._internal,
|
|
260
|
-
metadata: Object.assign({ description: a }, s == null ? void 0 : s.metadata)
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
static getInternalMetadata(e) {
|
|
264
|
-
const t = this.unwrapChained(e), n = e._def.openapi ? e._def.openapi : t._def.openapi;
|
|
265
|
-
return n == null ? void 0 : n._internal;
|
|
266
|
-
}
|
|
267
|
-
static getParamMetadata(e) {
|
|
268
|
-
var t, n;
|
|
269
|
-
const s = this.unwrapChained(e), a = e._def.openapi ? e._def.openapi : s._def.openapi, i = (t = e.description) !== null && t !== void 0 ? t : s.description;
|
|
270
|
-
return {
|
|
271
|
-
_internal: a == null ? void 0 : a._internal,
|
|
272
|
-
metadata: Object.assign(Object.assign({}, a == null ? void 0 : a.metadata), {
|
|
273
|
-
// A description provided from .openapi() should be taken with higher precedence
|
|
274
|
-
param: Object.assign({ description: i }, (n = a == null ? void 0 : a.metadata) === null || n === void 0 ? void 0 : n.param)
|
|
275
|
-
})
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* A method that omits all custom keys added to the regular OpenAPI
|
|
280
|
-
* metadata properties
|
|
281
|
-
*/
|
|
282
|
-
static buildSchemaMetadata(e) {
|
|
283
|
-
return xe(Or(e, ["param"]), Me);
|
|
284
|
-
}
|
|
285
|
-
static buildParameterMetadata(e) {
|
|
286
|
-
return xe(e, Me);
|
|
287
|
-
}
|
|
288
|
-
static applySchemaMetadata(e, t) {
|
|
289
|
-
return xe(Object.assign(Object.assign({}, e), this.buildSchemaMetadata(t)), Me);
|
|
290
|
-
}
|
|
291
|
-
static getRefId(e) {
|
|
292
|
-
var t;
|
|
293
|
-
return (t = this.getInternalMetadata(e)) === null || t === void 0 ? void 0 : t.refId;
|
|
294
|
-
}
|
|
295
|
-
static unwrapChained(e) {
|
|
296
|
-
return this.unwrapUntil(e);
|
|
297
|
-
}
|
|
298
|
-
static getDefaultValue(e) {
|
|
299
|
-
const t = this.unwrapUntil(e, "ZodDefault");
|
|
300
|
-
return t == null ? void 0 : t._def.defaultValue();
|
|
301
|
-
}
|
|
302
|
-
static unwrapUntil(e, t) {
|
|
303
|
-
return t && x(e, t) ? e : x(e, "ZodOptional") || x(e, "ZodNullable") || x(e, "ZodBranded") ? this.unwrapUntil(e.unwrap(), t) : x(e, "ZodDefault") || x(e, "ZodReadonly") ? this.unwrapUntil(e._def.innerType, t) : x(e, "ZodEffects") ? this.unwrapUntil(e._def.schema, t) : x(e, "ZodPipeline") ? this.unwrapUntil(e._def.in, t) : t ? void 0 : e;
|
|
304
|
-
}
|
|
305
|
-
static isOptionalSchema(e) {
|
|
306
|
-
return x(e, "ZodEffects") ? this.isOptionalSchema(e._def.schema) : e.isOptional();
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
class Rr {
|
|
310
|
-
transform(e, t, n) {
|
|
311
|
-
var s, a;
|
|
312
|
-
const i = e._def.type;
|
|
313
|
-
return Object.assign(Object.assign({}, t("array")), { items: n(i), minItems: (s = e._def.minLength) === null || s === void 0 ? void 0 : s.value, maxItems: (a = e._def.maxLength) === null || a === void 0 ? void 0 : a.value });
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
class Er {
|
|
317
|
-
transform(e) {
|
|
318
|
-
return Object.assign(Object.assign({}, e("string")), { pattern: "^d+$" });
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
class Ir {
|
|
322
|
-
transform(e, t, n, s, a) {
|
|
323
|
-
const i = [...e.options.values()], o = i.map(s);
|
|
324
|
-
return t ? {
|
|
325
|
-
oneOf: n(o, t)
|
|
326
|
-
} : {
|
|
327
|
-
oneOf: o,
|
|
328
|
-
discriminator: this.mapDiscriminator(i, e.discriminator, a)
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
mapDiscriminator(e, t, n) {
|
|
332
|
-
if (e.some((a) => I.getRefId(a) === void 0))
|
|
333
|
-
return;
|
|
334
|
-
const s = {};
|
|
335
|
-
return e.forEach((a) => {
|
|
336
|
-
var i;
|
|
337
|
-
const o = I.getRefId(a), c = (i = a.shape) === null || i === void 0 ? void 0 : i[t];
|
|
338
|
-
if (x(c, "ZodEnum") || x(c, "ZodNativeEnum")) {
|
|
339
|
-
Object.values(c.enum).filter(Kt).forEach((f) => {
|
|
340
|
-
s[f] = n(o);
|
|
341
|
-
});
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
const u = c == null ? void 0 : c._def.value;
|
|
345
|
-
if (typeof u != "string")
|
|
346
|
-
throw new Error(`Discriminator ${t} could not be found in one of the values of a discriminated union`);
|
|
347
|
-
s[u] = n(o);
|
|
348
|
-
}), {
|
|
349
|
-
propertyName: t,
|
|
350
|
-
mapping: s
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
class Pr {
|
|
355
|
-
transform(e, t) {
|
|
356
|
-
return Object.assign(Object.assign({}, t("string")), { enum: e._def.values });
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
class Cr {
|
|
360
|
-
transform(e, t, n, s) {
|
|
361
|
-
const i = {
|
|
362
|
-
allOf: this.flattenIntersectionTypes(e).map(s)
|
|
363
|
-
};
|
|
364
|
-
return t ? {
|
|
365
|
-
anyOf: n([i], t)
|
|
366
|
-
} : i;
|
|
367
|
-
}
|
|
368
|
-
flattenIntersectionTypes(e) {
|
|
369
|
-
if (!x(e, "ZodIntersection"))
|
|
370
|
-
return [e];
|
|
371
|
-
const t = this.flattenIntersectionTypes(e._def.left), n = this.flattenIntersectionTypes(e._def.right);
|
|
372
|
-
return [...t, ...n];
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
class Zr {
|
|
376
|
-
transform(e, t) {
|
|
377
|
-
return Object.assign(Object.assign({}, t(typeof e._def.value)), { enum: [e._def.value] });
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
function Sr(r) {
|
|
381
|
-
const t = Object.keys(r).filter((a) => typeof r[r[a]] != "number").map((a) => r[a]), n = t.filter((a) => typeof a == "number").length, s = n === 0 ? "string" : n === t.length ? "numeric" : "mixed";
|
|
382
|
-
return { values: t, type: s };
|
|
383
|
-
}
|
|
384
|
-
class Ar {
|
|
385
|
-
transform(e, t) {
|
|
386
|
-
const { type: n, values: s } = Sr(e._def.values);
|
|
387
|
-
if (n === "mixed")
|
|
388
|
-
throw new wt("Enum has mixed string and number values, please specify the OpenAPI type manually");
|
|
389
|
-
return Object.assign(Object.assign({}, t(n === "numeric" ? "integer" : "string")), { enum: s });
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
class Nr {
|
|
393
|
-
transform(e, t, n) {
|
|
394
|
-
return Object.assign(Object.assign({}, t(e.isInt ? "integer" : "number")), n(e._def.checks));
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
class Dr {
|
|
398
|
-
transform(e, t, n, s) {
|
|
399
|
-
var a;
|
|
400
|
-
const i = (a = I.getInternalMetadata(e)) === null || a === void 0 ? void 0 : a.extendedFrom, o = this.requiredKeysOf(e), c = $e(e._def.shape(), s);
|
|
401
|
-
if (!i)
|
|
402
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, n("object")), { properties: c, default: t }), o.length > 0 ? { required: o } : {}), this.generateAdditionalProperties(e, s));
|
|
403
|
-
const u = i.schema;
|
|
404
|
-
s(u);
|
|
405
|
-
const d = this.requiredKeysOf(u), f = $e(u == null ? void 0 : u._def.shape(), s), k = Object.fromEntries(Object.entries(c).filter(([b, S]) => !It(f[b], S))), E = o.filter((b) => !d.includes(b)), R = Object.assign(Object.assign(Object.assign(Object.assign({}, n("object")), { default: t, properties: k }), E.length > 0 ? { required: E } : {}), this.generateAdditionalProperties(e, s));
|
|
406
|
-
return {
|
|
407
|
-
allOf: [
|
|
408
|
-
{ $ref: `#/components/schemas/${i.refId}` },
|
|
409
|
-
R
|
|
410
|
-
]
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
generateAdditionalProperties(e, t) {
|
|
414
|
-
const n = e._def.unknownKeys, s = e._def.catchall;
|
|
415
|
-
return x(s, "ZodNever") ? n === "strict" ? { additionalProperties: !1 } : {} : { additionalProperties: t(s) };
|
|
416
|
-
}
|
|
417
|
-
requiredKeysOf(e) {
|
|
418
|
-
return Object.entries(e._def.shape()).filter(([t, n]) => !I.isOptionalSchema(n)).map(([t, n]) => t);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
class Mr {
|
|
422
|
-
transform(e, t, n) {
|
|
423
|
-
const s = e._def.valueType, a = e._def.keyType, i = n(s);
|
|
424
|
-
if (x(a, "ZodEnum") || x(a, "ZodNativeEnum")) {
|
|
425
|
-
const c = Object.values(a.enum).filter(Kt).reduce((u, d) => Object.assign(Object.assign({}, u), { [d]: i }), {});
|
|
426
|
-
return Object.assign(Object.assign({}, t("object")), { properties: c });
|
|
427
|
-
}
|
|
428
|
-
return Object.assign(Object.assign({}, t("object")), { additionalProperties: i });
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
class $r {
|
|
432
|
-
transform(e, t) {
|
|
433
|
-
var n, s, a;
|
|
434
|
-
const i = this.getZodStringCheck(e, "regex"), o = (n = this.getZodStringCheck(e, "length")) === null || n === void 0 ? void 0 : n.value, c = Number.isFinite(e.minLength) && (s = e.minLength) !== null && s !== void 0 ? s : void 0, u = Number.isFinite(e.maxLength) && (a = e.maxLength) !== null && a !== void 0 ? a : void 0;
|
|
435
|
-
return Object.assign(Object.assign({}, t("string")), {
|
|
436
|
-
// FIXME: https://github.com/colinhacks/zod/commit/d78047e9f44596a96d637abb0ce209cd2732d88c
|
|
437
|
-
minLength: o ?? c,
|
|
438
|
-
maxLength: o ?? u,
|
|
439
|
-
format: this.mapStringFormat(e),
|
|
440
|
-
pattern: i == null ? void 0 : i.regex.source
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Attempts to map Zod strings to known formats
|
|
445
|
-
* https://json-schema.org/understanding-json-schema/reference/string.html#built-in-formats
|
|
446
|
-
*/
|
|
447
|
-
mapStringFormat(e) {
|
|
448
|
-
if (e.isUUID)
|
|
449
|
-
return "uuid";
|
|
450
|
-
if (e.isEmail)
|
|
451
|
-
return "email";
|
|
452
|
-
if (e.isURL)
|
|
453
|
-
return "uri";
|
|
454
|
-
if (e.isDatetime)
|
|
455
|
-
return "date-time";
|
|
456
|
-
}
|
|
457
|
-
getZodStringCheck(e, t) {
|
|
458
|
-
return e._def.checks.find((n) => n.kind === t);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
class Lr {
|
|
462
|
-
constructor(e) {
|
|
463
|
-
this.versionSpecifics = e;
|
|
464
|
-
}
|
|
465
|
-
transform(e, t, n) {
|
|
466
|
-
const { items: s } = e._def, a = s.map(n);
|
|
467
|
-
return Object.assign(Object.assign({}, t("array")), this.versionSpecifics.mapTupleItems(a));
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
class Vr {
|
|
471
|
-
transform(e, t, n) {
|
|
472
|
-
const a = this.flattenUnionTypes(e).map((i) => {
|
|
473
|
-
const o = this.unwrapNullable(i);
|
|
474
|
-
return n(o);
|
|
475
|
-
});
|
|
476
|
-
return {
|
|
477
|
-
anyOf: t(a)
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
flattenUnionTypes(e) {
|
|
481
|
-
return x(e, "ZodUnion") ? e._def.options.flatMap((n) => this.flattenUnionTypes(n)) : [e];
|
|
482
|
-
}
|
|
483
|
-
unwrapNullable(e) {
|
|
484
|
-
return x(e, "ZodNullable") ? this.unwrapNullable(e.unwrap()) : e;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
class Ur {
|
|
488
|
-
constructor(e) {
|
|
489
|
-
this.versionSpecifics = e, this.objectTransformer = new Dr(), this.stringTransformer = new $r(), this.numberTransformer = new Nr(), this.bigIntTransformer = new Er(), this.literalTransformer = new Zr(), this.enumTransformer = new Pr(), this.nativeEnumTransformer = new Ar(), this.arrayTransformer = new Rr(), this.unionTransformer = new Vr(), this.discriminatedUnionTransformer = new Ir(), this.intersectionTransformer = new Cr(), this.recordTransformer = new Mr(), this.tupleTransformer = new Lr(e);
|
|
490
|
-
}
|
|
491
|
-
transform(e, t, n, s, a) {
|
|
492
|
-
if (x(e, "ZodNull"))
|
|
493
|
-
return this.versionSpecifics.nullType;
|
|
494
|
-
if (x(e, "ZodUnknown") || x(e, "ZodAny"))
|
|
495
|
-
return this.versionSpecifics.mapNullableType(void 0, t);
|
|
496
|
-
if (x(e, "ZodObject"))
|
|
497
|
-
return this.objectTransformer.transform(
|
|
498
|
-
e,
|
|
499
|
-
a,
|
|
500
|
-
// verified on TS level from input
|
|
501
|
-
// verified on TS level from input
|
|
502
|
-
(o) => this.versionSpecifics.mapNullableType(o, t),
|
|
503
|
-
n
|
|
504
|
-
);
|
|
505
|
-
const i = this.transformSchemaWithoutDefault(e, t, n, s);
|
|
506
|
-
return Object.assign(Object.assign({}, i), { default: a });
|
|
507
|
-
}
|
|
508
|
-
transformSchemaWithoutDefault(e, t, n, s) {
|
|
509
|
-
if (x(e, "ZodUnknown") || x(e, "ZodAny"))
|
|
510
|
-
return this.versionSpecifics.mapNullableType(void 0, t);
|
|
511
|
-
if (x(e, "ZodString"))
|
|
512
|
-
return this.stringTransformer.transform(e, (i) => this.versionSpecifics.mapNullableType(i, t));
|
|
513
|
-
if (x(e, "ZodNumber"))
|
|
514
|
-
return this.numberTransformer.transform(e, (i) => this.versionSpecifics.mapNullableType(i, t), (i) => this.versionSpecifics.getNumberChecks(i));
|
|
515
|
-
if (x(e, "ZodBigInt"))
|
|
516
|
-
return this.bigIntTransformer.transform((i) => this.versionSpecifics.mapNullableType(i, t));
|
|
517
|
-
if (x(e, "ZodBoolean"))
|
|
518
|
-
return this.versionSpecifics.mapNullableType("boolean", t);
|
|
519
|
-
if (x(e, "ZodLiteral"))
|
|
520
|
-
return this.literalTransformer.transform(e, (i) => this.versionSpecifics.mapNullableType(i, t));
|
|
521
|
-
if (x(e, "ZodEnum"))
|
|
522
|
-
return this.enumTransformer.transform(e, (i) => this.versionSpecifics.mapNullableType(i, t));
|
|
523
|
-
if (x(e, "ZodNativeEnum"))
|
|
524
|
-
return this.nativeEnumTransformer.transform(e, (i) => this.versionSpecifics.mapNullableType(i, t));
|
|
525
|
-
if (x(e, "ZodArray"))
|
|
526
|
-
return this.arrayTransformer.transform(e, (i) => this.versionSpecifics.mapNullableType(i, t), n);
|
|
527
|
-
if (x(e, "ZodTuple"))
|
|
528
|
-
return this.tupleTransformer.transform(e, (i) => this.versionSpecifics.mapNullableType(i, t), n);
|
|
529
|
-
if (x(e, "ZodUnion"))
|
|
530
|
-
return this.unionTransformer.transform(e, (i) => this.versionSpecifics.mapNullableOfArray(i, t), n);
|
|
531
|
-
if (x(e, "ZodDiscriminatedUnion"))
|
|
532
|
-
return this.discriminatedUnionTransformer.transform(e, t, (i) => this.versionSpecifics.mapNullableOfArray(i, t), n, s);
|
|
533
|
-
if (x(e, "ZodIntersection"))
|
|
534
|
-
return this.intersectionTransformer.transform(e, t, (i) => this.versionSpecifics.mapNullableOfArray(i, t), n);
|
|
535
|
-
if (x(e, "ZodRecord"))
|
|
536
|
-
return this.recordTransformer.transform(e, (i) => this.versionSpecifics.mapNullableType(i, t), n);
|
|
537
|
-
if (x(e, "ZodDate"))
|
|
538
|
-
return this.versionSpecifics.mapNullableType("string", t);
|
|
539
|
-
const a = I.getRefId(e);
|
|
540
|
-
throw new jr({
|
|
541
|
-
currentSchema: e._def,
|
|
542
|
-
schemaName: a
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
class Jt {
|
|
547
|
-
constructor(e, t) {
|
|
548
|
-
this.definitions = e, this.versionSpecifics = t, this.schemaRefs = {}, this.paramRefs = {}, this.pathRefs = {}, this.rawComponents = [], this.openApiTransformer = new Ur(t), this.sortDefinitions();
|
|
549
|
-
}
|
|
550
|
-
generateDocumentData() {
|
|
551
|
-
return this.definitions.forEach((e) => this.generateSingle(e)), {
|
|
552
|
-
components: this.buildComponents(),
|
|
553
|
-
paths: this.pathRefs
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
generateComponents() {
|
|
557
|
-
return this.definitions.forEach((e) => this.generateSingle(e)), {
|
|
558
|
-
components: this.buildComponents()
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
buildComponents() {
|
|
562
|
-
var e, t;
|
|
563
|
-
const n = {};
|
|
564
|
-
return this.rawComponents.forEach(({ componentType: s, name: a, component: i }) => {
|
|
565
|
-
var o;
|
|
566
|
-
(o = n[s]) !== null && o !== void 0 || (n[s] = {}), n[s][a] = i;
|
|
567
|
-
}), Object.assign(Object.assign({}, n), { schemas: Object.assign(Object.assign({}, (e = n.schemas) !== null && e !== void 0 ? e : {}), this.schemaRefs), parameters: Object.assign(Object.assign({}, (t = n.parameters) !== null && t !== void 0 ? t : {}), this.paramRefs) });
|
|
568
|
-
}
|
|
569
|
-
sortDefinitions() {
|
|
570
|
-
const e = [
|
|
571
|
-
"schema",
|
|
572
|
-
"parameter",
|
|
573
|
-
"component",
|
|
574
|
-
"route"
|
|
575
|
-
];
|
|
576
|
-
this.definitions.sort((t, n) => {
|
|
577
|
-
if (!("type" in t))
|
|
578
|
-
return "type" in n ? -1 : 0;
|
|
579
|
-
if (!("type" in n))
|
|
580
|
-
return 1;
|
|
581
|
-
const s = e.findIndex((i) => i === t.type), a = e.findIndex((i) => i === n.type);
|
|
582
|
-
return s - a;
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
generateSingle(e) {
|
|
586
|
-
if (!("type" in e)) {
|
|
587
|
-
this.generateSchemaWithRef(e);
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
switch (e.type) {
|
|
591
|
-
case "parameter":
|
|
592
|
-
this.generateParameterDefinition(e.schema);
|
|
593
|
-
return;
|
|
594
|
-
case "schema":
|
|
595
|
-
this.generateSchemaWithRef(e.schema);
|
|
596
|
-
return;
|
|
597
|
-
case "route":
|
|
598
|
-
this.generateSingleRoute(e.route);
|
|
599
|
-
return;
|
|
600
|
-
case "component":
|
|
601
|
-
this.rawComponents.push(e);
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
generateParameterDefinition(e) {
|
|
606
|
-
const t = I.getRefId(e), n = this.generateParameter(e);
|
|
607
|
-
return t && (this.paramRefs[t] = n), n;
|
|
608
|
-
}
|
|
609
|
-
getParameterRef(e, t) {
|
|
610
|
-
var n, s, a, i, o;
|
|
611
|
-
const c = (n = e == null ? void 0 : e.metadata) === null || n === void 0 ? void 0 : n.param, u = !((s = e == null ? void 0 : e._internal) === null || s === void 0) && s.refId ? this.paramRefs[(a = e._internal) === null || a === void 0 ? void 0 : a.refId] : void 0;
|
|
612
|
-
if (!(!(!((i = e == null ? void 0 : e._internal) === null || i === void 0) && i.refId) || !u)) {
|
|
613
|
-
if (c && u.in !== c.in || t != null && t.in && u.in !== t.in)
|
|
614
|
-
throw new Ce(`Conflicting location for parameter ${u.name}`, {
|
|
615
|
-
key: "in",
|
|
616
|
-
values: Lt([
|
|
617
|
-
u.in,
|
|
618
|
-
t == null ? void 0 : t.in,
|
|
619
|
-
c == null ? void 0 : c.in
|
|
620
|
-
])
|
|
621
|
-
});
|
|
622
|
-
if (c && u.name !== c.name || t != null && t.name && u.name !== (t == null ? void 0 : t.name))
|
|
623
|
-
throw new Ce("Conflicting names for parameter", {
|
|
624
|
-
key: "name",
|
|
625
|
-
values: Lt([
|
|
626
|
-
u.name,
|
|
627
|
-
t == null ? void 0 : t.name,
|
|
628
|
-
c == null ? void 0 : c.name
|
|
629
|
-
])
|
|
630
|
-
});
|
|
631
|
-
return {
|
|
632
|
-
$ref: `#/components/parameters/${(o = e._internal) === null || o === void 0 ? void 0 : o.refId}`
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
generateInlineParameters(e, t) {
|
|
637
|
-
var n;
|
|
638
|
-
const s = I.getMetadata(e), a = (n = s == null ? void 0 : s.metadata) === null || n === void 0 ? void 0 : n.param, i = this.getParameterRef(s, { in: t });
|
|
639
|
-
if (i)
|
|
640
|
-
return [i];
|
|
641
|
-
if (x(e, "ZodObject")) {
|
|
642
|
-
const o = e._def.shape();
|
|
643
|
-
return Object.entries(o).map(([u, d]) => {
|
|
644
|
-
var f, k;
|
|
645
|
-
const E = I.getMetadata(d), R = this.getParameterRef(E, {
|
|
646
|
-
in: t,
|
|
647
|
-
name: u
|
|
648
|
-
});
|
|
649
|
-
if (R)
|
|
650
|
-
return R;
|
|
651
|
-
const b = (f = E == null ? void 0 : E.metadata) === null || f === void 0 ? void 0 : f.param;
|
|
652
|
-
if (b != null && b.name && b.name !== u)
|
|
653
|
-
throw new Ce("Conflicting names for parameter", {
|
|
654
|
-
key: "name",
|
|
655
|
-
values: [u, b.name]
|
|
656
|
-
});
|
|
657
|
-
if (b != null && b.in && b.in !== t)
|
|
658
|
-
throw new Ce(`Conflicting location for parameter ${(k = b.name) !== null && k !== void 0 ? k : u}`, {
|
|
659
|
-
key: "in",
|
|
660
|
-
values: [t, b.in]
|
|
661
|
-
});
|
|
662
|
-
return this.generateParameter(d.openapi({ param: { name: u, in: t } }));
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
if (a != null && a.in && a.in !== t)
|
|
666
|
-
throw new Ce(`Conflicting location for parameter ${a.name}`, {
|
|
667
|
-
key: "in",
|
|
668
|
-
values: [t, a.in]
|
|
669
|
-
});
|
|
670
|
-
return [
|
|
671
|
-
this.generateParameter(e.openapi({ param: { in: t } }))
|
|
672
|
-
];
|
|
673
|
-
}
|
|
674
|
-
generateSimpleParameter(e) {
|
|
675
|
-
var t;
|
|
676
|
-
const n = I.getParamMetadata(e), s = (t = n == null ? void 0 : n.metadata) === null || t === void 0 ? void 0 : t.param, a = !I.isOptionalSchema(e) && !e.isNullable(), i = this.generateSchemaWithRef(e);
|
|
677
|
-
return Object.assign({
|
|
678
|
-
schema: i,
|
|
679
|
-
required: a
|
|
680
|
-
}, s ? I.buildParameterMetadata(s) : {});
|
|
681
|
-
}
|
|
682
|
-
generateParameter(e) {
|
|
683
|
-
var t;
|
|
684
|
-
const n = I.getMetadata(e), s = (t = n == null ? void 0 : n.metadata) === null || t === void 0 ? void 0 : t.param, a = s == null ? void 0 : s.name, i = s == null ? void 0 : s.in;
|
|
685
|
-
if (!a)
|
|
686
|
-
throw new lt({ missingField: "name" });
|
|
687
|
-
if (!i)
|
|
688
|
-
throw new lt({
|
|
689
|
-
missingField: "in",
|
|
690
|
-
paramName: a
|
|
691
|
-
});
|
|
692
|
-
const o = this.generateSimpleParameter(e);
|
|
693
|
-
return Object.assign(Object.assign({}, o), { in: i, name: a });
|
|
694
|
-
}
|
|
695
|
-
generateSchemaWithMetadata(e) {
|
|
696
|
-
var t;
|
|
697
|
-
const n = I.unwrapChained(e), s = I.getMetadata(e), a = I.getDefaultValue(e), i = !((t = s == null ? void 0 : s.metadata) === null || t === void 0) && t.type ? { type: s == null ? void 0 : s.metadata.type } : this.toOpenAPISchema(n, e.isNullable(), a);
|
|
698
|
-
return s != null && s.metadata ? I.applySchemaMetadata(i, s.metadata) : xe(i, Me);
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* Same as above but applies nullable
|
|
702
|
-
*/
|
|
703
|
-
constructReferencedOpenAPISchema(e) {
|
|
704
|
-
var t;
|
|
705
|
-
const n = I.getMetadata(e), s = I.unwrapChained(e), a = I.getDefaultValue(e), i = e.isNullable();
|
|
706
|
-
return !((t = n == null ? void 0 : n.metadata) === null || t === void 0) && t.type ? this.versionSpecifics.mapNullableType(n.metadata.type, i) : this.toOpenAPISchema(s, i, a);
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* Generates an OpenAPI SchemaObject or a ReferenceObject with all the provided metadata applied
|
|
710
|
-
*/
|
|
711
|
-
generateSimpleSchema(e) {
|
|
712
|
-
var t;
|
|
713
|
-
const n = I.getMetadata(e), s = I.getRefId(e);
|
|
714
|
-
if (!s || !this.schemaRefs[s])
|
|
715
|
-
return this.generateSchemaWithMetadata(e);
|
|
716
|
-
const a = this.schemaRefs[s], i = {
|
|
717
|
-
$ref: this.generateSchemaRef(s)
|
|
718
|
-
}, o = xe(I.buildSchemaMetadata((t = n == null ? void 0 : n.metadata) !== null && t !== void 0 ? t : {}), (d, f) => d === void 0 || It(d, a[f]));
|
|
719
|
-
if (o.type)
|
|
720
|
-
return {
|
|
721
|
-
allOf: [i, o]
|
|
722
|
-
};
|
|
723
|
-
const c = xe(this.constructReferencedOpenAPISchema(e), (d, f) => d === void 0 || It(d, a[f])), u = I.applySchemaMetadata(c, o);
|
|
724
|
-
return Object.keys(u).length > 0 ? {
|
|
725
|
-
allOf: [i, u]
|
|
726
|
-
} : i;
|
|
727
|
-
}
|
|
728
|
-
/**
|
|
729
|
-
* Same as `generateSchema` but if the new schema is added into the
|
|
730
|
-
* referenced schemas, it would return a ReferenceObject and not the
|
|
731
|
-
* whole result.
|
|
732
|
-
*
|
|
733
|
-
* Should be used for nested objects, arrays, etc.
|
|
734
|
-
*/
|
|
735
|
-
generateSchemaWithRef(e) {
|
|
736
|
-
const t = I.getRefId(e), n = this.generateSimpleSchema(e);
|
|
737
|
-
return t && this.schemaRefs[t] === void 0 ? (this.schemaRefs[t] = n, { $ref: this.generateSchemaRef(t) }) : n;
|
|
738
|
-
}
|
|
739
|
-
generateSchemaRef(e) {
|
|
740
|
-
return `#/components/schemas/${e}`;
|
|
741
|
-
}
|
|
742
|
-
getRequestBody(e) {
|
|
743
|
-
if (!e)
|
|
744
|
-
return;
|
|
745
|
-
const { content: t } = e, n = Se(e, ["content"]), s = this.getBodyContent(t);
|
|
746
|
-
return Object.assign(Object.assign({}, n), { content: s });
|
|
747
|
-
}
|
|
748
|
-
getParameters(e) {
|
|
749
|
-
if (!e)
|
|
750
|
-
return [];
|
|
751
|
-
const { headers: t } = e, n = this.cleanParameter(e.query), s = this.cleanParameter(e.params), a = this.cleanParameter(e.cookies), i = Ze(() => n ? this.generateInlineParameters(n, "query") : [], { location: "query" }), o = Ze(() => s ? this.generateInlineParameters(s, "path") : [], { location: "path" }), c = Ze(() => a ? this.generateInlineParameters(a, "cookie") : [], { location: "cookie" }), u = Ze(() => {
|
|
752
|
-
if (Array.isArray(t))
|
|
753
|
-
return t.flatMap((f) => this.generateInlineParameters(f, "header"));
|
|
754
|
-
const d = this.cleanParameter(t);
|
|
755
|
-
return d ? this.generateInlineParameters(d, "header") : [];
|
|
756
|
-
}, { location: "header" });
|
|
757
|
-
return [
|
|
758
|
-
...o,
|
|
759
|
-
...i,
|
|
760
|
-
...u,
|
|
761
|
-
...c
|
|
762
|
-
];
|
|
763
|
-
}
|
|
764
|
-
cleanParameter(e) {
|
|
765
|
-
if (e)
|
|
766
|
-
return x(e, "ZodEffects") ? this.cleanParameter(e._def.schema) : e;
|
|
767
|
-
}
|
|
768
|
-
generatePath(e) {
|
|
769
|
-
const { method: t, path: n, request: s, responses: a } = e, i = Se(e, ["method", "path", "request", "responses"]), o = $e(a, (f) => this.getResponse(f)), c = Ze(() => this.getParameters(s), { route: `${t} ${n}` }), u = this.getRequestBody(s == null ? void 0 : s.body);
|
|
770
|
-
return {
|
|
771
|
-
[t]: Object.assign(Object.assign(Object.assign(Object.assign({}, i), c.length > 0 ? {
|
|
772
|
-
parameters: [...i.parameters || [], ...c]
|
|
773
|
-
} : {}), u ? { requestBody: u } : {}), { responses: o })
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
generateSingleRoute(e) {
|
|
777
|
-
const t = this.generatePath(e);
|
|
778
|
-
return this.pathRefs[e.path] = Object.assign(Object.assign({}, this.pathRefs[e.path]), t), t;
|
|
779
|
-
}
|
|
780
|
-
getResponse(e) {
|
|
781
|
-
var { content: t, headers: n } = e, s = Se(e, ["content", "headers"]);
|
|
782
|
-
const a = t ? { content: this.getBodyContent(t) } : {};
|
|
783
|
-
if (!n)
|
|
784
|
-
return Object.assign(Object.assign({}, s), a);
|
|
785
|
-
const i = x(n, "ZodObject") ? this.getResponseHeaders(n) : (
|
|
786
|
-
// This is input data so it is okay to cast in the common generator
|
|
787
|
-
// since this is the user's responsibility to keep it correct
|
|
788
|
-
n
|
|
789
|
-
);
|
|
790
|
-
return Object.assign(Object.assign(Object.assign({}, s), { headers: i }), a);
|
|
791
|
-
}
|
|
792
|
-
getResponseHeaders(e) {
|
|
793
|
-
const t = e._def.shape();
|
|
794
|
-
return $e(t, (s) => this.generateSimpleParameter(s));
|
|
795
|
-
}
|
|
796
|
-
getBodyContent(e) {
|
|
797
|
-
return $e(e, (t) => {
|
|
798
|
-
if (!t || !br(t.schema))
|
|
799
|
-
return t;
|
|
800
|
-
const { schema: n } = t, s = Se(t, ["schema"]), a = this.generateSchemaWithRef(n);
|
|
801
|
-
return Object.assign({ schema: a }, s);
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
|
-
toOpenAPISchema(e, t, n) {
|
|
805
|
-
return this.openApiTransformer.transform(e, t, (s) => this.generateSchemaWithRef(s), (s) => this.generateSchemaRef(s), n);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
class Hr {
|
|
809
|
-
get nullType() {
|
|
810
|
-
return { nullable: !0 };
|
|
811
|
-
}
|
|
812
|
-
mapNullableOfArray(e, t) {
|
|
813
|
-
return t ? [...e, this.nullType] : e;
|
|
814
|
-
}
|
|
815
|
-
mapNullableType(e, t) {
|
|
816
|
-
return Object.assign(Object.assign({}, e ? { type: e } : void 0), t ? this.nullType : void 0);
|
|
817
|
-
}
|
|
818
|
-
mapTupleItems(e) {
|
|
819
|
-
const t = kr(e);
|
|
820
|
-
return {
|
|
821
|
-
items: t.length === 1 ? t[0] : { anyOf: t },
|
|
822
|
-
minItems: e.length,
|
|
823
|
-
maxItems: e.length
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
getNumberChecks(e) {
|
|
827
|
-
return Object.assign({}, ...e.map((t) => {
|
|
828
|
-
switch (t.kind) {
|
|
829
|
-
case "min":
|
|
830
|
-
return t.inclusive ? { minimum: Number(t.value) } : { minimum: Number(t.value), exclusiveMinimum: !0 };
|
|
831
|
-
case "max":
|
|
832
|
-
return t.inclusive ? { maximum: Number(t.value) } : { maximum: Number(t.value), exclusiveMaximum: !0 };
|
|
833
|
-
default:
|
|
834
|
-
return {};
|
|
835
|
-
}
|
|
836
|
-
}));
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
class qr {
|
|
840
|
-
constructor(e) {
|
|
841
|
-
const t = new Hr();
|
|
842
|
-
this.generator = new Jt(e, t);
|
|
843
|
-
}
|
|
844
|
-
generateDocument(e) {
|
|
845
|
-
const t = this.generator.generateDocumentData();
|
|
846
|
-
return Object.assign(Object.assign({}, e), t);
|
|
847
|
-
}
|
|
848
|
-
generateComponents() {
|
|
849
|
-
return this.generator.generateComponents();
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
class Br {
|
|
853
|
-
get nullType() {
|
|
854
|
-
return { type: "null" };
|
|
855
|
-
}
|
|
856
|
-
mapNullableOfArray(e, t) {
|
|
857
|
-
return t ? [...e, this.nullType] : e;
|
|
858
|
-
}
|
|
859
|
-
mapNullableType(e, t) {
|
|
860
|
-
return e ? t ? {
|
|
861
|
-
type: Array.isArray(e) ? [...e, "null"] : [e, "null"]
|
|
862
|
-
} : {
|
|
863
|
-
type: e
|
|
864
|
-
} : {};
|
|
865
|
-
}
|
|
866
|
-
mapTupleItems(e) {
|
|
867
|
-
return {
|
|
868
|
-
prefixItems: e
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
getNumberChecks(e) {
|
|
872
|
-
return Object.assign({}, ...e.map((t) => {
|
|
873
|
-
switch (t.kind) {
|
|
874
|
-
case "min":
|
|
875
|
-
return t.inclusive ? { minimum: Number(t.value) } : { exclusiveMinimum: Number(t.value) };
|
|
876
|
-
case "max":
|
|
877
|
-
return t.inclusive ? { maximum: Number(t.value) } : { exclusiveMaximum: Number(t.value) };
|
|
878
|
-
default:
|
|
879
|
-
return {};
|
|
880
|
-
}
|
|
881
|
-
}));
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
function Wr(r) {
|
|
885
|
-
return "type" in r && r.type === "webhook";
|
|
886
|
-
}
|
|
887
|
-
class Fr {
|
|
888
|
-
constructor(e) {
|
|
889
|
-
this.definitions = e, this.webhookRefs = {};
|
|
890
|
-
const t = new Br();
|
|
891
|
-
this.generator = new Jt(this.definitions, t);
|
|
892
|
-
}
|
|
893
|
-
generateDocument(e) {
|
|
894
|
-
const t = this.generator.generateDocumentData();
|
|
895
|
-
return this.definitions.filter(Wr).forEach((n) => this.generateSingleWebhook(n.webhook)), Object.assign(Object.assign(Object.assign({}, e), t), { webhooks: this.webhookRefs });
|
|
896
|
-
}
|
|
897
|
-
generateComponents() {
|
|
898
|
-
return this.generator.generateComponents();
|
|
899
|
-
}
|
|
900
|
-
generateSingleWebhook(e) {
|
|
901
|
-
const t = this.generator.generatePath(e);
|
|
902
|
-
return this.webhookRefs[e.path] = Object.assign(Object.assign({}, this.webhookRefs[e.path]), t), t;
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
var Yt = (r) => {
|
|
906
|
-
const e = r.split("/");
|
|
907
|
-
return e[0] === "" && e.shift(), e;
|
|
908
|
-
}, Gr = (r) => {
|
|
909
|
-
const { groups: e, path: t } = Kr(r), n = Yt(t);
|
|
910
|
-
return Jr(n, e);
|
|
911
|
-
}, Kr = (r) => {
|
|
912
|
-
const e = [];
|
|
913
|
-
return r = r.replace(/\{[^}]+\}/g, (t, n) => {
|
|
914
|
-
const s = `@${n}`;
|
|
915
|
-
return e.push([s, t]), s;
|
|
916
|
-
}), { groups: e, path: r };
|
|
917
|
-
}, Jr = (r, e) => {
|
|
918
|
-
for (let t = e.length - 1; t >= 0; t--) {
|
|
919
|
-
const [n] = e[t];
|
|
920
|
-
for (let s = r.length - 1; s >= 0; s--)
|
|
921
|
-
if (r[s].includes(n)) {
|
|
922
|
-
r[s] = r[s].replace(n, e[t][1]);
|
|
923
|
-
break;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
return r;
|
|
927
|
-
}, ot = {}, Vt = (r) => {
|
|
928
|
-
if (r === "*")
|
|
929
|
-
return "*";
|
|
930
|
-
const e = r.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
931
|
-
return e ? (ot[r] || (e[2] ? ot[r] = [r, e[1], new RegExp("^" + e[2] + "$")] : ot[r] = [r, e[1], !0]), ot[r]) : null;
|
|
932
|
-
}, Yr = (r) => {
|
|
933
|
-
try {
|
|
934
|
-
return decodeURI(r);
|
|
935
|
-
} catch {
|
|
936
|
-
return r.replace(/(?:%[0-9A-Fa-f]{2})+/g, (e) => {
|
|
937
|
-
try {
|
|
938
|
-
return decodeURI(e);
|
|
939
|
-
} catch {
|
|
940
|
-
return e;
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
}, Xt = (r) => {
|
|
945
|
-
const e = r.url, t = e.indexOf("/", 8);
|
|
946
|
-
let n = t;
|
|
947
|
-
for (; n < e.length; n++) {
|
|
948
|
-
const s = e.charCodeAt(n);
|
|
949
|
-
if (s === 37) {
|
|
950
|
-
const a = e.indexOf("?", n), i = e.slice(t, a === -1 ? void 0 : a);
|
|
951
|
-
return Yr(i.includes("%25") ? i.replace(/%25/g, "%2525") : i);
|
|
952
|
-
} else if (s === 63)
|
|
953
|
-
break;
|
|
954
|
-
}
|
|
955
|
-
return e.slice(t, n);
|
|
956
|
-
}, Xr = (r) => {
|
|
957
|
-
const e = Xt(r);
|
|
958
|
-
return e.length > 1 && e[e.length - 1] === "/" ? e.slice(0, -1) : e;
|
|
959
|
-
}, le = (...r) => {
|
|
960
|
-
let e = "", t = !1;
|
|
961
|
-
for (let n of r)
|
|
962
|
-
e[e.length - 1] === "/" && (e = e.slice(0, -1), t = !0), n[0] !== "/" && (n = `/${n}`), n === "/" && t ? e = `${e}/` : n !== "/" && (e = `${e}${n}`), n === "/" && e === "" && (e = "/");
|
|
963
|
-
return e;
|
|
964
|
-
}, Qt = (r) => {
|
|
965
|
-
if (!r.match(/\:.+\?$/))
|
|
966
|
-
return null;
|
|
967
|
-
const e = r.split("/"), t = [];
|
|
968
|
-
let n = "";
|
|
969
|
-
return e.forEach((s) => {
|
|
970
|
-
if (s !== "" && !/\:/.test(s))
|
|
971
|
-
n += "/" + s;
|
|
972
|
-
else if (/\:/.test(s))
|
|
973
|
-
if (/\?/.test(s)) {
|
|
974
|
-
t.length === 0 && n === "" ? t.push("/") : t.push(n);
|
|
975
|
-
const a = s.replace("?", "");
|
|
976
|
-
n += "/" + a, t.push(n);
|
|
977
|
-
} else
|
|
978
|
-
n += "/" + s;
|
|
979
|
-
}), t.filter((s, a, i) => i.indexOf(s) === a);
|
|
980
|
-
}, Tt = (r) => /[%+]/.test(r) ? (r.indexOf("+") !== -1 && (r = r.replace(/\+/g, " ")), /%/.test(r) ? ft(r) : r) : r, zt = (r, e, t) => {
|
|
981
|
-
let n;
|
|
982
|
-
if (!t && e && !/[%+]/.test(e)) {
|
|
983
|
-
let i = r.indexOf(`?${e}`, 8);
|
|
984
|
-
for (i === -1 && (i = r.indexOf(`&${e}`, 8)); i !== -1; ) {
|
|
985
|
-
const o = r.charCodeAt(i + e.length + 1);
|
|
986
|
-
if (o === 61) {
|
|
987
|
-
const c = i + e.length + 2, u = r.indexOf("&", c);
|
|
988
|
-
return Tt(r.slice(c, u === -1 ? void 0 : u));
|
|
989
|
-
} else if (o == 38 || isNaN(o))
|
|
990
|
-
return "";
|
|
991
|
-
i = r.indexOf(`&${e}`, i + 1);
|
|
992
|
-
}
|
|
993
|
-
if (n = /[%+]/.test(r), !n)
|
|
994
|
-
return;
|
|
995
|
-
}
|
|
996
|
-
const s = {};
|
|
997
|
-
n ?? (n = /[%+]/.test(r));
|
|
998
|
-
let a = r.indexOf("?", 8);
|
|
999
|
-
for (; a !== -1; ) {
|
|
1000
|
-
const i = r.indexOf("&", a + 1);
|
|
1001
|
-
let o = r.indexOf("=", a);
|
|
1002
|
-
o > i && i !== -1 && (o = -1);
|
|
1003
|
-
let c = r.slice(
|
|
1004
|
-
a + 1,
|
|
1005
|
-
o === -1 ? i === -1 ? void 0 : i : o
|
|
1006
|
-
);
|
|
1007
|
-
if (n && (c = Tt(c)), a = i, c === "")
|
|
1008
|
-
continue;
|
|
1009
|
-
let u;
|
|
1010
|
-
o === -1 ? u = "" : (u = r.slice(o + 1, i === -1 ? void 0 : i), n && (u = Tt(u))), t ? (s[c] && Array.isArray(s[c]) || (s[c] = []), s[c].push(u)) : s[c] ?? (s[c] = u);
|
|
1011
|
-
}
|
|
1012
|
-
return e ? s[e] : s;
|
|
1013
|
-
}, Qr = zt, zr = (r, e) => zt(r, e, !0), ft = decodeURIComponent, en = /^[\w!#$%&'*.^`|~+-]+$/, tn = /^[ !#-:<-[\]-~]*$/, rn = (r, e) => r.trim().split(";").reduce((n, s) => {
|
|
1014
|
-
s = s.trim();
|
|
1015
|
-
const a = s.indexOf("=");
|
|
1016
|
-
if (a === -1)
|
|
1017
|
-
return n;
|
|
1018
|
-
const i = s.substring(0, a).trim();
|
|
1019
|
-
if (!en.test(i))
|
|
1020
|
-
return n;
|
|
1021
|
-
let o = s.substring(a + 1).trim();
|
|
1022
|
-
return o.startsWith('"') && o.endsWith('"') && (o = o.slice(1, -1)), tn.test(o) && (n[i] = ft(o)), n;
|
|
1023
|
-
}, {}), nn = (r, e, t) => {
|
|
1024
|
-
const n = r.req.raw.headers.get("Cookie");
|
|
1025
|
-
return n ? rn(n) : {};
|
|
1026
|
-
}, jt = class extends Error {
|
|
1027
|
-
constructor(e = 500, t) {
|
|
1028
|
-
super(t == null ? void 0 : t.message, { cause: t == null ? void 0 : t.cause });
|
|
1029
|
-
p(this, "res");
|
|
1030
|
-
p(this, "status");
|
|
1031
|
-
this.res = t == null ? void 0 : t.res, this.status = e;
|
|
1032
|
-
}
|
|
1033
|
-
getResponse() {
|
|
1034
|
-
return this.res ? new Response(this.res.body, {
|
|
1035
|
-
status: this.status,
|
|
1036
|
-
headers: this.res.headers
|
|
1037
|
-
}) : new Response(this.message, {
|
|
1038
|
-
status: this.status
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
}, sn = (r, e) => new Response(r, {
|
|
1042
|
-
headers: {
|
|
1043
|
-
"Content-Type": e
|
|
1044
|
-
}
|
|
1045
|
-
}).formData(), an = (r, e) => async (t, n) => {
|
|
1046
|
-
let s = {};
|
|
1047
|
-
const a = t.req.header("Content-Type");
|
|
1048
|
-
switch (r) {
|
|
1049
|
-
case "json":
|
|
1050
|
-
if (!a || !/^application\/([a-z-\.]+\+)?json/.test(a)) {
|
|
1051
|
-
const o = `Invalid HTTP header: Content-Type=${a}`;
|
|
1052
|
-
throw new jt(400, { message: o });
|
|
1053
|
-
}
|
|
1054
|
-
try {
|
|
1055
|
-
s = await t.req.json();
|
|
1056
|
-
} catch {
|
|
1057
|
-
const o = "Malformed JSON in request body";
|
|
1058
|
-
throw new jt(400, { message: o });
|
|
1059
|
-
}
|
|
1060
|
-
break;
|
|
1061
|
-
case "form": {
|
|
1062
|
-
if (!a)
|
|
1063
|
-
break;
|
|
1064
|
-
if (t.req.bodyCache.formData) {
|
|
1065
|
-
s = await t.req.bodyCache.formData;
|
|
1066
|
-
break;
|
|
1067
|
-
}
|
|
1068
|
-
try {
|
|
1069
|
-
const o = await t.req.arrayBuffer(), c = await sn(o, a), u = {};
|
|
1070
|
-
c.forEach((d, f) => {
|
|
1071
|
-
f.endsWith("[]") ? u[f] === void 0 ? u[f] = [d] : Array.isArray(u[f]) && u[f].push(d) : u[f] = d;
|
|
1072
|
-
}), s = u, t.req.bodyCache.formData = c;
|
|
1073
|
-
} catch (o) {
|
|
1074
|
-
let c = "Malformed FormData request.";
|
|
1075
|
-
throw c += o instanceof Error ? ` ${o.message}` : ` ${String(o)}`, new jt(400, { message: c });
|
|
1076
|
-
}
|
|
1077
|
-
break;
|
|
1078
|
-
}
|
|
1079
|
-
case "query":
|
|
1080
|
-
s = Object.fromEntries(
|
|
1081
|
-
Object.entries(t.req.queries()).map(([o, c]) => c.length === 1 ? [o, c[0]] : [o, c])
|
|
1082
|
-
);
|
|
1083
|
-
break;
|
|
1084
|
-
case "param":
|
|
1085
|
-
s = t.req.param();
|
|
1086
|
-
break;
|
|
1087
|
-
case "header":
|
|
1088
|
-
s = t.req.header();
|
|
1089
|
-
break;
|
|
1090
|
-
case "cookie":
|
|
1091
|
-
s = nn(t);
|
|
1092
|
-
break;
|
|
1093
|
-
}
|
|
1094
|
-
const i = await e(s, t);
|
|
1095
|
-
if (i instanceof Response)
|
|
1096
|
-
return i;
|
|
1097
|
-
t.req.addValidatedData(r, i), await n();
|
|
1098
|
-
};
|
|
1099
|
-
const ye = (r, e, t) => (
|
|
1100
|
-
// @ts-expect-error not typed well
|
|
1101
|
-
an(r, async (n, s) => {
|
|
1102
|
-
const a = await e.safeParseAsync(n);
|
|
1103
|
-
if (t) {
|
|
1104
|
-
const i = await t({ data: n, ...a }, s);
|
|
1105
|
-
if (i) {
|
|
1106
|
-
if (i instanceof Response)
|
|
1107
|
-
return i;
|
|
1108
|
-
if ("response" in i)
|
|
1109
|
-
return i.response;
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
return a.success ? a.data : s.json(a, 400);
|
|
1113
|
-
})
|
|
1114
|
-
);
|
|
1115
|
-
var on = async (r, e = /* @__PURE__ */ Object.create(null)) => {
|
|
1116
|
-
const { all: t = !1, dot: n = !1 } = e, a = (r instanceof er ? r.raw.headers : r.headers).get("Content-Type");
|
|
1117
|
-
return a !== null && a.startsWith("multipart/form-data") || a !== null && a.startsWith("application/x-www-form-urlencoded") ? cn(r, { all: t, dot: n }) : {};
|
|
1118
|
-
};
|
|
1119
|
-
async function cn(r, e) {
|
|
1120
|
-
const t = await r.formData();
|
|
1121
|
-
return t ? un(t, e) : {};
|
|
1122
|
-
}
|
|
1123
|
-
function un(r, e) {
|
|
1124
|
-
const t = /* @__PURE__ */ Object.create(null);
|
|
1125
|
-
return r.forEach((n, s) => {
|
|
1126
|
-
e.all || s.endsWith("[]") ? dn(t, s, n) : t[s] = n;
|
|
1127
|
-
}), e.dot && Object.entries(t).forEach(([n, s]) => {
|
|
1128
|
-
n.includes(".") && (ln(t, n, s), delete t[n]);
|
|
1129
|
-
}), t;
|
|
1130
|
-
}
|
|
1131
|
-
var dn = (r, e, t) => {
|
|
1132
|
-
r[e] !== void 0 ? Array.isArray(r[e]) ? r[e].push(t) : r[e] = [r[e], t] : r[e] = t;
|
|
1133
|
-
}, ln = (r, e, t) => {
|
|
1134
|
-
let n = r;
|
|
1135
|
-
const s = e.split(".");
|
|
1136
|
-
s.forEach((a, i) => {
|
|
1137
|
-
i === s.length - 1 ? n[a] = t : ((!n[a] || typeof n[a] != "object" || Array.isArray(n[a]) || n[a] instanceof File) && (n[a] = /* @__PURE__ */ Object.create(null)), n = n[a]);
|
|
1138
|
-
});
|
|
1139
|
-
}, ke, U, Wt, er = (Wt = class {
|
|
1140
|
-
constructor(r, e = "/", t = [[]]) {
|
|
1141
|
-
p(this, "raw");
|
|
1142
|
-
N(this, ke);
|
|
1143
|
-
N(this, U);
|
|
1144
|
-
p(this, "routeIndex", 0);
|
|
1145
|
-
p(this, "path");
|
|
1146
|
-
p(this, "bodyCache", {});
|
|
1147
|
-
p(this, "cachedBody", (r) => {
|
|
1148
|
-
const { bodyCache: e, raw: t } = this, n = e[r];
|
|
1149
|
-
if (n)
|
|
1150
|
-
return n;
|
|
1151
|
-
const s = Object.keys(e)[0];
|
|
1152
|
-
return s ? e[s].then((a) => (s === "json" && (a = JSON.stringify(a)), new Response(a)[r]())) : e[r] = t[r]();
|
|
1153
|
-
});
|
|
1154
|
-
this.raw = r, this.path = e, T(this, U, t), T(this, ke, {});
|
|
1155
|
-
}
|
|
1156
|
-
param(r) {
|
|
1157
|
-
return r ? this.getDecodedParam(r) : this.getAllDecodedParams();
|
|
1158
|
-
}
|
|
1159
|
-
getDecodedParam(r) {
|
|
1160
|
-
const e = h(this, U)[0][this.routeIndex][1][r], t = this.getParamValue(e);
|
|
1161
|
-
return t ? /\%/.test(t) ? ft(t) : t : void 0;
|
|
1162
|
-
}
|
|
1163
|
-
getAllDecodedParams() {
|
|
1164
|
-
const r = {}, e = Object.keys(h(this, U)[0][this.routeIndex][1]);
|
|
1165
|
-
for (const t of e) {
|
|
1166
|
-
const n = this.getParamValue(h(this, U)[0][this.routeIndex][1][t]);
|
|
1167
|
-
n && typeof n == "string" && (r[t] = /\%/.test(n) ? ft(n) : n);
|
|
1168
|
-
}
|
|
1169
|
-
return r;
|
|
1170
|
-
}
|
|
1171
|
-
getParamValue(r) {
|
|
1172
|
-
return h(this, U)[1] ? h(this, U)[1][r] : r;
|
|
1173
|
-
}
|
|
1174
|
-
query(r) {
|
|
1175
|
-
return Qr(this.url, r);
|
|
1176
|
-
}
|
|
1177
|
-
queries(r) {
|
|
1178
|
-
return zr(this.url, r);
|
|
1179
|
-
}
|
|
1180
|
-
header(r) {
|
|
1181
|
-
if (r)
|
|
1182
|
-
return this.raw.headers.get(r.toLowerCase()) ?? void 0;
|
|
1183
|
-
const e = {};
|
|
1184
|
-
return this.raw.headers.forEach((t, n) => {
|
|
1185
|
-
e[n] = t;
|
|
1186
|
-
}), e;
|
|
1187
|
-
}
|
|
1188
|
-
async parseBody(r) {
|
|
1189
|
-
var e;
|
|
1190
|
-
return (e = this.bodyCache).parsedBody ?? (e.parsedBody = await on(this, r));
|
|
1191
|
-
}
|
|
1192
|
-
json() {
|
|
1193
|
-
return this.cachedBody("json");
|
|
1194
|
-
}
|
|
1195
|
-
text() {
|
|
1196
|
-
return this.cachedBody("text");
|
|
1197
|
-
}
|
|
1198
|
-
arrayBuffer() {
|
|
1199
|
-
return this.cachedBody("arrayBuffer");
|
|
1200
|
-
}
|
|
1201
|
-
blob() {
|
|
1202
|
-
return this.cachedBody("blob");
|
|
1203
|
-
}
|
|
1204
|
-
formData() {
|
|
1205
|
-
return this.cachedBody("formData");
|
|
1206
|
-
}
|
|
1207
|
-
addValidatedData(r, e) {
|
|
1208
|
-
h(this, ke)[r] = e;
|
|
1209
|
-
}
|
|
1210
|
-
valid(r) {
|
|
1211
|
-
return h(this, ke)[r];
|
|
1212
|
-
}
|
|
1213
|
-
get url() {
|
|
1214
|
-
return this.raw.url;
|
|
1215
|
-
}
|
|
1216
|
-
get method() {
|
|
1217
|
-
return this.raw.method;
|
|
1218
|
-
}
|
|
1219
|
-
get matchedRoutes() {
|
|
1220
|
-
return h(this, U)[0].map(([[, r]]) => r);
|
|
1221
|
-
}
|
|
1222
|
-
get routePath() {
|
|
1223
|
-
return h(this, U)[0].map(([[, r]]) => r)[this.routeIndex].path;
|
|
1224
|
-
}
|
|
1225
|
-
}, ke = new WeakMap(), U = new WeakMap(), Wt), fn = {
|
|
1226
|
-
Stringify: 1,
|
|
1227
|
-
BeforeStream: 2,
|
|
1228
|
-
Stream: 3
|
|
1229
|
-
}, tr = async (r, e, t, n, s) => {
|
|
1230
|
-
const a = r.callbacks;
|
|
1231
|
-
return a != null && a.length ? (s ? s[0] += r : s = [r], Promise.all(a.map((o) => o({ phase: e, buffer: s, context: n }))).then(
|
|
1232
|
-
(o) => Promise.all(
|
|
1233
|
-
o.filter(Boolean).map((c) => tr(c, e, !1, n, s))
|
|
1234
|
-
).then(() => s[0])
|
|
1235
|
-
)) : Promise.resolve(r);
|
|
1236
|
-
}, hn = "text/plain; charset=UTF-8", Rt = (r, e = {}) => (Object.entries(e).forEach(([t, n]) => r.set(t, n)), r), tt, rt, ae, fe, ee, P, Z, H, te, nt, Te, je, st, at, Ft, ct = (Ft = class {
|
|
1237
|
-
constructor(r, e) {
|
|
1238
|
-
N(this, tt);
|
|
1239
|
-
N(this, rt);
|
|
1240
|
-
p(this, "env", {});
|
|
1241
|
-
N(this, ae);
|
|
1242
|
-
p(this, "finalized", !1);
|
|
1243
|
-
p(this, "error");
|
|
1244
|
-
N(this, fe, 200);
|
|
1245
|
-
N(this, ee);
|
|
1246
|
-
N(this, P);
|
|
1247
|
-
N(this, Z);
|
|
1248
|
-
N(this, H);
|
|
1249
|
-
N(this, te, !0);
|
|
1250
|
-
N(this, nt);
|
|
1251
|
-
N(this, Te);
|
|
1252
|
-
N(this, je);
|
|
1253
|
-
N(this, st);
|
|
1254
|
-
N(this, at);
|
|
1255
|
-
p(this, "render", (...r) => (h(this, Te) ?? T(this, Te, (e) => this.html(e)), h(this, Te).call(this, ...r)));
|
|
1256
|
-
p(this, "setLayout", (r) => T(this, nt, r));
|
|
1257
|
-
p(this, "getLayout", () => h(this, nt));
|
|
1258
|
-
p(this, "setRenderer", (r) => {
|
|
1259
|
-
T(this, Te, r);
|
|
1260
|
-
});
|
|
1261
|
-
p(this, "header", (r, e, t) => {
|
|
1262
|
-
if (e === void 0) {
|
|
1263
|
-
h(this, P) ? h(this, P).delete(r) : h(this, Z) && delete h(this, Z)[r.toLocaleLowerCase()], this.finalized && this.res.headers.delete(r);
|
|
1264
|
-
return;
|
|
1265
|
-
}
|
|
1266
|
-
t != null && t.append ? (h(this, P) || (T(this, te, !1), T(this, P, new Headers(h(this, Z))), T(this, Z, {})), h(this, P).append(r, e)) : h(this, P) ? h(this, P).set(r, e) : (h(this, Z) ?? T(this, Z, {}), h(this, Z)[r.toLowerCase()] = e), this.finalized && (t != null && t.append ? this.res.headers.append(r, e) : this.res.headers.set(r, e));
|
|
1267
|
-
});
|
|
1268
|
-
p(this, "status", (r) => {
|
|
1269
|
-
T(this, te, !1), T(this, fe, r);
|
|
1270
|
-
});
|
|
1271
|
-
p(this, "set", (r, e) => {
|
|
1272
|
-
h(this, ae) ?? T(this, ae, {}), h(this, ae)[r] = e;
|
|
1273
|
-
});
|
|
1274
|
-
p(this, "get", (r) => h(this, ae) ? h(this, ae)[r] : void 0);
|
|
1275
|
-
p(this, "newResponse", (r, e, t) => {
|
|
1276
|
-
if (h(this, te) && !t && !e && h(this, fe) === 200)
|
|
1277
|
-
return new Response(r, {
|
|
1278
|
-
headers: h(this, Z)
|
|
1279
|
-
});
|
|
1280
|
-
if (e && typeof e != "number") {
|
|
1281
|
-
const s = new Headers(e.headers);
|
|
1282
|
-
h(this, P) && h(this, P).forEach((i, o) => {
|
|
1283
|
-
o === "set-cookie" ? s.append(o, i) : s.set(o, i);
|
|
1284
|
-
});
|
|
1285
|
-
const a = Rt(s, h(this, Z));
|
|
1286
|
-
return new Response(r, {
|
|
1287
|
-
headers: a,
|
|
1288
|
-
status: e.status ?? h(this, fe)
|
|
1289
|
-
});
|
|
1290
|
-
}
|
|
1291
|
-
const n = typeof e == "number" ? e : h(this, fe);
|
|
1292
|
-
h(this, Z) ?? T(this, Z, {}), h(this, P) ?? T(this, P, new Headers()), Rt(h(this, P), h(this, Z)), h(this, H) && (h(this, H).headers.forEach((s, a) => {
|
|
1293
|
-
var i, o;
|
|
1294
|
-
a === "set-cookie" ? (i = h(this, P)) == null || i.append(a, s) : (o = h(this, P)) == null || o.set(a, s);
|
|
1295
|
-
}), Rt(h(this, P), h(this, Z))), t ?? (t = {});
|
|
1296
|
-
for (const [s, a] of Object.entries(t))
|
|
1297
|
-
if (typeof a == "string")
|
|
1298
|
-
h(this, P).set(s, a);
|
|
1299
|
-
else {
|
|
1300
|
-
h(this, P).delete(s);
|
|
1301
|
-
for (const i of a)
|
|
1302
|
-
h(this, P).append(s, i);
|
|
1303
|
-
}
|
|
1304
|
-
return new Response(r, {
|
|
1305
|
-
status: n,
|
|
1306
|
-
headers: h(this, P)
|
|
1307
|
-
});
|
|
1308
|
-
});
|
|
1309
|
-
p(this, "body", (r, e, t) => typeof e == "number" ? this.newResponse(r, e, t) : this.newResponse(r, e));
|
|
1310
|
-
p(this, "text", (r, e, t) => {
|
|
1311
|
-
if (!h(this, Z)) {
|
|
1312
|
-
if (h(this, te) && !t && !e)
|
|
1313
|
-
return new Response(r);
|
|
1314
|
-
T(this, Z, {});
|
|
1315
|
-
}
|
|
1316
|
-
return h(this, Z)["content-type"] = hn, typeof e == "number" ? this.newResponse(r, e, t) : this.newResponse(r, e);
|
|
1317
|
-
});
|
|
1318
|
-
p(this, "json", (r, e, t) => {
|
|
1319
|
-
const n = JSON.stringify(r);
|
|
1320
|
-
return h(this, Z) ?? T(this, Z, {}), h(this, Z)["content-type"] = "application/json; charset=UTF-8", typeof e == "number" ? this.newResponse(n, e, t) : this.newResponse(n, e);
|
|
1321
|
-
});
|
|
1322
|
-
p(this, "html", (r, e, t) => (h(this, Z) ?? T(this, Z, {}), h(this, Z)["content-type"] = "text/html; charset=UTF-8", typeof r == "object" && (r instanceof Promise || (r = r.toString()), r instanceof Promise) ? r.then((n) => tr(n, fn.Stringify, !1, {})).then((n) => typeof e == "number" ? this.newResponse(n, e, t) : this.newResponse(n, e)) : typeof e == "number" ? this.newResponse(r, e, t) : this.newResponse(r, e)));
|
|
1323
|
-
p(this, "redirect", (r, e) => (h(this, P) ?? T(this, P, new Headers()), h(this, P).set("Location", r), this.newResponse(null, e ?? 302)));
|
|
1324
|
-
p(this, "notFound", () => (h(this, je) ?? T(this, je, () => new Response()), h(this, je).call(this, this)));
|
|
1325
|
-
T(this, tt, r), e && (T(this, ee, e.executionCtx), this.env = e.env, T(this, je, e.notFoundHandler), T(this, at, e.path), T(this, st, e.matchResult));
|
|
1326
|
-
}
|
|
1327
|
-
get req() {
|
|
1328
|
-
return h(this, rt) ?? T(this, rt, new er(h(this, tt), h(this, at), h(this, st))), h(this, rt);
|
|
1329
|
-
}
|
|
1330
|
-
get event() {
|
|
1331
|
-
if (h(this, ee) && "respondWith" in h(this, ee))
|
|
1332
|
-
return h(this, ee);
|
|
1333
|
-
throw Error("This context has no FetchEvent");
|
|
1334
|
-
}
|
|
1335
|
-
get executionCtx() {
|
|
1336
|
-
if (h(this, ee))
|
|
1337
|
-
return h(this, ee);
|
|
1338
|
-
throw Error("This context has no ExecutionContext");
|
|
1339
|
-
}
|
|
1340
|
-
get res() {
|
|
1341
|
-
return T(this, te, !1), h(this, H) || T(this, H, new Response("404 Not Found", { status: 404 }));
|
|
1342
|
-
}
|
|
1343
|
-
set res(r) {
|
|
1344
|
-
if (T(this, te, !1), h(this, H) && r) {
|
|
1345
|
-
h(this, H).headers.delete("content-type");
|
|
1346
|
-
for (const [e, t] of h(this, H).headers.entries())
|
|
1347
|
-
if (e === "set-cookie") {
|
|
1348
|
-
const n = h(this, H).headers.getSetCookie();
|
|
1349
|
-
r.headers.delete("set-cookie");
|
|
1350
|
-
for (const s of n)
|
|
1351
|
-
r.headers.append("set-cookie", s);
|
|
1352
|
-
} else
|
|
1353
|
-
r.headers.set(e, t);
|
|
1354
|
-
}
|
|
1355
|
-
T(this, H, r), this.finalized = !0;
|
|
1356
|
-
}
|
|
1357
|
-
get var() {
|
|
1358
|
-
return { ...h(this, ae) };
|
|
1359
|
-
}
|
|
1360
|
-
}, tt = new WeakMap(), rt = new WeakMap(), ae = new WeakMap(), fe = new WeakMap(), ee = new WeakMap(), P = new WeakMap(), Z = new WeakMap(), H = new WeakMap(), te = new WeakMap(), nt = new WeakMap(), Te = new WeakMap(), je = new WeakMap(), st = new WeakMap(), at = new WeakMap(), Ft), Ut = (r, e, t) => (n, s) => {
|
|
1361
|
-
let a = -1;
|
|
1362
|
-
return i(0);
|
|
1363
|
-
async function i(o) {
|
|
1364
|
-
if (o <= a)
|
|
1365
|
-
throw new Error("next() called multiple times");
|
|
1366
|
-
a = o;
|
|
1367
|
-
let c, u = !1, d;
|
|
1368
|
-
if (r[o] ? (d = r[o][0][0], n instanceof ct && (n.req.routeIndex = o)) : d = o === r.length && s || void 0, !d)
|
|
1369
|
-
n instanceof ct && n.finalized === !1 && t && (c = await t(n));
|
|
1370
|
-
else
|
|
1371
|
-
try {
|
|
1372
|
-
c = await d(n, () => i(o + 1));
|
|
1373
|
-
} catch (f) {
|
|
1374
|
-
if (f instanceof Error && n instanceof ct && e)
|
|
1375
|
-
n.error = f, c = await e(f, n), u = !0;
|
|
1376
|
-
else
|
|
1377
|
-
throw f;
|
|
1378
|
-
}
|
|
1379
|
-
return c && (n.finalized === !1 || u) && (n.res = c), n;
|
|
1380
|
-
}
|
|
1381
|
-
}, A = "ALL", pn = "all", mn = ["get", "post", "put", "delete", "options", "patch"], rr = "Can not add a route since the matcher is already built.", nr = class extends Error {
|
|
1382
|
-
}, gn = Symbol("composedHandler"), vn = (r) => r.text("404 Not Found", 404), Ht = (r, e) => "getResponse" in r ? r.getResponse() : (console.error(r), e.text("Internal Server Error", 500)), q, Gt, sr = (Gt = class {
|
|
1383
|
-
constructor(e = {}) {
|
|
1384
|
-
p(this, "get");
|
|
1385
|
-
p(this, "post");
|
|
1386
|
-
p(this, "put");
|
|
1387
|
-
p(this, "delete");
|
|
1388
|
-
p(this, "options");
|
|
1389
|
-
p(this, "patch");
|
|
1390
|
-
p(this, "all");
|
|
1391
|
-
p(this, "on");
|
|
1392
|
-
p(this, "use");
|
|
1393
|
-
p(this, "router");
|
|
1394
|
-
p(this, "getPath");
|
|
1395
|
-
p(this, "_basePath", "/");
|
|
1396
|
-
N(this, q, "/");
|
|
1397
|
-
p(this, "routes", []);
|
|
1398
|
-
p(this, "notFoundHandler", vn);
|
|
1399
|
-
p(this, "errorHandler", Ht);
|
|
1400
|
-
p(this, "onError", (e) => (this.errorHandler = e, this));
|
|
1401
|
-
p(this, "notFound", (e) => (this.notFoundHandler = e, this));
|
|
1402
|
-
p(this, "fetch", (e, ...t) => this.dispatch(e, t[1], t[0], e.method));
|
|
1403
|
-
p(this, "request", (e, t, n, s) => {
|
|
1404
|
-
if (e instanceof Request)
|
|
1405
|
-
return t !== void 0 && (e = new Request(e, t)), this.fetch(e, n, s);
|
|
1406
|
-
e = e.toString();
|
|
1407
|
-
const a = /^https?:\/\//.test(e) ? e : `http://localhost${le("/", e)}`, i = new Request(a, t);
|
|
1408
|
-
return this.fetch(i, n, s);
|
|
1409
|
-
});
|
|
1410
|
-
p(this, "fire", () => {
|
|
1411
|
-
addEventListener("fetch", (e) => {
|
|
1412
|
-
e.respondWith(this.dispatch(e.request, e, void 0, e.request.method));
|
|
1413
|
-
});
|
|
1414
|
-
});
|
|
1415
|
-
[...mn, pn].forEach((s) => {
|
|
1416
|
-
this[s] = (a, ...i) => (typeof a == "string" ? T(this, q, a) : this.addRoute(s, h(this, q), a), i.forEach((o) => {
|
|
1417
|
-
typeof o != "string" && this.addRoute(s, h(this, q), o);
|
|
1418
|
-
}), this);
|
|
1419
|
-
}), this.on = (s, a, ...i) => {
|
|
1420
|
-
for (const o of [a].flat()) {
|
|
1421
|
-
T(this, q, o);
|
|
1422
|
-
for (const c of [s].flat())
|
|
1423
|
-
i.map((u) => {
|
|
1424
|
-
this.addRoute(c.toUpperCase(), h(this, q), u);
|
|
1425
|
-
});
|
|
1426
|
-
}
|
|
1427
|
-
return this;
|
|
1428
|
-
}, this.use = (s, ...a) => (typeof s == "string" ? T(this, q, s) : (T(this, q, "*"), a.unshift(s)), a.forEach((i) => {
|
|
1429
|
-
this.addRoute(A, h(this, q), i);
|
|
1430
|
-
}), this);
|
|
1431
|
-
const n = e.strict ?? !0;
|
|
1432
|
-
delete e.strict, Object.assign(this, e), this.getPath = n ? e.getPath ?? Xt : Xr;
|
|
1433
|
-
}
|
|
1434
|
-
clone() {
|
|
1435
|
-
const e = new sr({
|
|
1436
|
-
router: this.router,
|
|
1437
|
-
getPath: this.getPath
|
|
1438
|
-
});
|
|
1439
|
-
return e.routes = this.routes, e;
|
|
1440
|
-
}
|
|
1441
|
-
route(e, t) {
|
|
1442
|
-
const n = this.basePath(e);
|
|
1443
|
-
return t.routes.map((s) => {
|
|
1444
|
-
let a;
|
|
1445
|
-
t.errorHandler === Ht ? a = s.handler : (a = async (i, o) => (await Ut([], t.errorHandler)(i, () => s.handler(i, o))).res, a[gn] = s.handler), n.addRoute(s.method, s.path, a);
|
|
1446
|
-
}), this;
|
|
1447
|
-
}
|
|
1448
|
-
basePath(e) {
|
|
1449
|
-
const t = this.clone();
|
|
1450
|
-
return t._basePath = le(this._basePath, e), t;
|
|
1451
|
-
}
|
|
1452
|
-
mount(e, t, n) {
|
|
1453
|
-
let s, a;
|
|
1454
|
-
n && (typeof n == "function" ? a = n : (a = n.optionHandler, s = n.replaceRequest));
|
|
1455
|
-
const i = a ? (c) => {
|
|
1456
|
-
const u = a(c);
|
|
1457
|
-
return Array.isArray(u) ? u : [u];
|
|
1458
|
-
} : (c) => {
|
|
1459
|
-
let u;
|
|
1460
|
-
try {
|
|
1461
|
-
u = c.executionCtx;
|
|
1462
|
-
} catch {
|
|
1463
|
-
}
|
|
1464
|
-
return [c.env, u];
|
|
1465
|
-
};
|
|
1466
|
-
s || (s = (() => {
|
|
1467
|
-
const c = le(this._basePath, e), u = c === "/" ? 0 : c.length;
|
|
1468
|
-
return (d) => {
|
|
1469
|
-
const f = new URL(d.url);
|
|
1470
|
-
return f.pathname = f.pathname.slice(u) || "/", new Request(f, d);
|
|
1471
|
-
};
|
|
1472
|
-
})());
|
|
1473
|
-
const o = async (c, u) => {
|
|
1474
|
-
const d = await t(s(c.req.raw), ...i(c));
|
|
1475
|
-
if (d)
|
|
1476
|
-
return d;
|
|
1477
|
-
await u();
|
|
1478
|
-
};
|
|
1479
|
-
return this.addRoute(A, le(e, "*"), o), this;
|
|
1480
|
-
}
|
|
1481
|
-
addRoute(e, t, n) {
|
|
1482
|
-
e = e.toUpperCase(), t = le(this._basePath, t);
|
|
1483
|
-
const s = { path: t, method: e, handler: n };
|
|
1484
|
-
this.router.add(e, t, [n, s]), this.routes.push(s);
|
|
1485
|
-
}
|
|
1486
|
-
matchRoute(e, t) {
|
|
1487
|
-
return this.router.match(e, t);
|
|
1488
|
-
}
|
|
1489
|
-
handleError(e, t) {
|
|
1490
|
-
if (e instanceof Error)
|
|
1491
|
-
return this.errorHandler(e, t);
|
|
1492
|
-
throw e;
|
|
1493
|
-
}
|
|
1494
|
-
dispatch(e, t, n, s) {
|
|
1495
|
-
if (s === "HEAD")
|
|
1496
|
-
return (async () => new Response(null, await this.dispatch(e, t, n, "GET")))();
|
|
1497
|
-
const a = this.getPath(e, { env: n }), i = this.matchRoute(s, a), o = new ct(e, {
|
|
1498
|
-
path: a,
|
|
1499
|
-
matchResult: i,
|
|
1500
|
-
env: n,
|
|
1501
|
-
executionCtx: t,
|
|
1502
|
-
notFoundHandler: this.notFoundHandler
|
|
1503
|
-
});
|
|
1504
|
-
if (i[0].length === 1) {
|
|
1505
|
-
let u;
|
|
1506
|
-
try {
|
|
1507
|
-
u = i[0][0][0][0](o, async () => {
|
|
1508
|
-
o.res = await this.notFoundHandler(o);
|
|
1509
|
-
});
|
|
1510
|
-
} catch (d) {
|
|
1511
|
-
return this.handleError(d, o);
|
|
1512
|
-
}
|
|
1513
|
-
return u instanceof Promise ? u.then(
|
|
1514
|
-
(d) => d || (o.finalized ? o.res : this.notFoundHandler(o))
|
|
1515
|
-
).catch((d) => this.handleError(d, o)) : u ?? this.notFoundHandler(o);
|
|
1516
|
-
}
|
|
1517
|
-
const c = Ut(i[0], this.errorHandler, this.notFoundHandler);
|
|
1518
|
-
return (async () => {
|
|
1519
|
-
try {
|
|
1520
|
-
const u = await c(o);
|
|
1521
|
-
if (!u.finalized)
|
|
1522
|
-
throw new Error(
|
|
1523
|
-
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
1524
|
-
);
|
|
1525
|
-
return u.res;
|
|
1526
|
-
} catch (u) {
|
|
1527
|
-
return this.handleError(u, o);
|
|
1528
|
-
}
|
|
1529
|
-
})();
|
|
1530
|
-
}
|
|
1531
|
-
}, q = new WeakMap(), Gt), ht = "[^/]+", Le = ".*", Ve = "(?:|/.*)", Ae = Symbol(), yn = new Set(".\\+*[^]$()");
|
|
1532
|
-
function _n(r, e) {
|
|
1533
|
-
return r.length === 1 ? e.length === 1 ? r < e ? -1 : 1 : -1 : e.length === 1 || r === Le || r === Ve ? 1 : e === Le || e === Ve ? -1 : r === ht ? 1 : e === ht ? -1 : r.length === e.length ? r < e ? -1 : 1 : e.length - r.length;
|
|
1534
|
-
}
|
|
1535
|
-
var Pt = class {
|
|
1536
|
-
constructor() {
|
|
1537
|
-
p(this, "index");
|
|
1538
|
-
p(this, "varIndex");
|
|
1539
|
-
p(this, "children", /* @__PURE__ */ Object.create(null));
|
|
1540
|
-
}
|
|
1541
|
-
insert(e, t, n, s, a) {
|
|
1542
|
-
if (e.length === 0) {
|
|
1543
|
-
if (this.index !== void 0)
|
|
1544
|
-
throw Ae;
|
|
1545
|
-
if (a)
|
|
1546
|
-
return;
|
|
1547
|
-
this.index = t;
|
|
1548
|
-
return;
|
|
1549
|
-
}
|
|
1550
|
-
const [i, ...o] = e, c = i === "*" ? o.length === 0 ? ["", "", Le] : ["", "", ht] : i === "/*" ? ["", "", Ve] : i.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1551
|
-
let u;
|
|
1552
|
-
if (c) {
|
|
1553
|
-
const d = c[1];
|
|
1554
|
-
let f = c[2] || ht;
|
|
1555
|
-
if (d && c[2] && (f = f.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(f)))
|
|
1556
|
-
throw Ae;
|
|
1557
|
-
if (u = this.children[f], !u) {
|
|
1558
|
-
if (Object.keys(this.children).some(
|
|
1559
|
-
(k) => k !== Le && k !== Ve
|
|
1560
|
-
))
|
|
1561
|
-
throw Ae;
|
|
1562
|
-
if (a)
|
|
1563
|
-
return;
|
|
1564
|
-
u = this.children[f] = new Pt(), d !== "" && (u.varIndex = s.varIndex++);
|
|
1565
|
-
}
|
|
1566
|
-
!a && d !== "" && n.push([d, u.varIndex]);
|
|
1567
|
-
} else if (u = this.children[i], !u) {
|
|
1568
|
-
if (Object.keys(this.children).some(
|
|
1569
|
-
(d) => d.length > 1 && d !== Le && d !== Ve
|
|
1570
|
-
))
|
|
1571
|
-
throw Ae;
|
|
1572
|
-
if (a)
|
|
1573
|
-
return;
|
|
1574
|
-
u = this.children[i] = new Pt();
|
|
1575
|
-
}
|
|
1576
|
-
u.insert(o, t, n, s, a);
|
|
1577
|
-
}
|
|
1578
|
-
buildRegExpStr() {
|
|
1579
|
-
const t = Object.keys(this.children).sort(_n).map((n) => {
|
|
1580
|
-
const s = this.children[n];
|
|
1581
|
-
return (typeof s.varIndex == "number" ? `(${n})@${s.varIndex}` : yn.has(n) ? `\\${n}` : n) + s.buildRegExpStr();
|
|
1582
|
-
});
|
|
1583
|
-
return typeof this.index == "number" && t.unshift(`#${this.index}`), t.length === 0 ? "" : t.length === 1 ? t[0] : "(?:" + t.join("|") + ")";
|
|
1584
|
-
}
|
|
1585
|
-
}, bn = class {
|
|
1586
|
-
constructor() {
|
|
1587
|
-
p(this, "context", { varIndex: 0 });
|
|
1588
|
-
p(this, "root", new Pt());
|
|
1589
|
-
}
|
|
1590
|
-
insert(r, e, t) {
|
|
1591
|
-
const n = [], s = [];
|
|
1592
|
-
for (let i = 0; ; ) {
|
|
1593
|
-
let o = !1;
|
|
1594
|
-
if (r = r.replace(/\{[^}]+\}/g, (c) => {
|
|
1595
|
-
const u = `@\\${i}`;
|
|
1596
|
-
return s[i] = [u, c], i++, o = !0, u;
|
|
1597
|
-
}), !o)
|
|
1598
|
-
break;
|
|
1599
|
-
}
|
|
1600
|
-
const a = r.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
1601
|
-
for (let i = s.length - 1; i >= 0; i--) {
|
|
1602
|
-
const [o] = s[i];
|
|
1603
|
-
for (let c = a.length - 1; c >= 0; c--)
|
|
1604
|
-
if (a[c].indexOf(o) !== -1) {
|
|
1605
|
-
a[c] = a[c].replace(o, s[i][1]);
|
|
1606
|
-
break;
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
return this.root.insert(a, e, n, this.context, t), n;
|
|
1610
|
-
}
|
|
1611
|
-
buildRegExp() {
|
|
1612
|
-
let r = this.root.buildRegExpStr();
|
|
1613
|
-
if (r === "")
|
|
1614
|
-
return [/^$/, [], []];
|
|
1615
|
-
let e = 0;
|
|
1616
|
-
const t = [], n = [];
|
|
1617
|
-
return r = r.replace(/#(\d+)|@(\d+)|\.\*\$/g, (s, a, i) => typeof a < "u" ? (t[++e] = Number(a), "$()") : (typeof i < "u" && (n[Number(i)] = ++e), "")), [new RegExp(`^${r}`), t, n];
|
|
1618
|
-
}
|
|
1619
|
-
}, ar = [], wn = [/^$/, [], /* @__PURE__ */ Object.create(null)], ut = /* @__PURE__ */ Object.create(null);
|
|
1620
|
-
function ir(r) {
|
|
1621
|
-
return ut[r] ?? (ut[r] = new RegExp(
|
|
1622
|
-
r === "*" ? "" : `^${r.replace(
|
|
1623
|
-
/\/\*$|([.\\+*[^\]$()])/g,
|
|
1624
|
-
(e, t) => t ? `\\${t}` : "(?:|/.*)"
|
|
1625
|
-
)}$`
|
|
1626
|
-
));
|
|
1627
|
-
}
|
|
1628
|
-
function xn() {
|
|
1629
|
-
ut = /* @__PURE__ */ Object.create(null);
|
|
1630
|
-
}
|
|
1631
|
-
function On(r) {
|
|
1632
|
-
var u;
|
|
1633
|
-
const e = new bn(), t = [];
|
|
1634
|
-
if (r.length === 0)
|
|
1635
|
-
return wn;
|
|
1636
|
-
const n = r.map(
|
|
1637
|
-
(d) => [!/\*|\/:/.test(d[0]), ...d]
|
|
1638
|
-
).sort(
|
|
1639
|
-
([d, f], [k, E]) => d ? 1 : k ? -1 : f.length - E.length
|
|
1640
|
-
), s = /* @__PURE__ */ Object.create(null);
|
|
1641
|
-
for (let d = 0, f = -1, k = n.length; d < k; d++) {
|
|
1642
|
-
const [E, R, b] = n[d];
|
|
1643
|
-
E ? s[R] = [b.map(([D]) => [D, /* @__PURE__ */ Object.create(null)]), ar] : f++;
|
|
1644
|
-
let S;
|
|
1645
|
-
try {
|
|
1646
|
-
S = e.insert(R, f, E);
|
|
1647
|
-
} catch (D) {
|
|
1648
|
-
throw D === Ae ? new nr(R) : D;
|
|
1649
|
-
}
|
|
1650
|
-
E || (t[f] = b.map(([D, G]) => {
|
|
1651
|
-
const V = /* @__PURE__ */ Object.create(null);
|
|
1652
|
-
for (G -= 1; G >= 0; G--) {
|
|
1653
|
-
const [ge, ne] = S[G];
|
|
1654
|
-
V[ge] = ne;
|
|
1655
|
-
}
|
|
1656
|
-
return [D, V];
|
|
1657
|
-
}));
|
|
1658
|
-
}
|
|
1659
|
-
const [a, i, o] = e.buildRegExp();
|
|
1660
|
-
for (let d = 0, f = t.length; d < f; d++)
|
|
1661
|
-
for (let k = 0, E = t[d].length; k < E; k++) {
|
|
1662
|
-
const R = (u = t[d][k]) == null ? void 0 : u[1];
|
|
1663
|
-
if (!R)
|
|
1664
|
-
continue;
|
|
1665
|
-
const b = Object.keys(R);
|
|
1666
|
-
for (let S = 0, D = b.length; S < D; S++)
|
|
1667
|
-
R[b[S]] = o[R[b[S]]];
|
|
1668
|
-
}
|
|
1669
|
-
const c = [];
|
|
1670
|
-
for (const d in i)
|
|
1671
|
-
c[d] = t[i[d]];
|
|
1672
|
-
return [a, c, s];
|
|
1673
|
-
}
|
|
1674
|
-
function _e(r, e) {
|
|
1675
|
-
if (r) {
|
|
1676
|
-
for (const t of Object.keys(r).sort((n, s) => s.length - n.length))
|
|
1677
|
-
if (ir(t).test(e))
|
|
1678
|
-
return [...r[t]];
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
var kn = class {
|
|
1682
|
-
constructor() {
|
|
1683
|
-
p(this, "name", "RegExpRouter");
|
|
1684
|
-
p(this, "middleware");
|
|
1685
|
-
p(this, "routes");
|
|
1686
|
-
this.middleware = { [A]: /* @__PURE__ */ Object.create(null) }, this.routes = { [A]: /* @__PURE__ */ Object.create(null) };
|
|
1687
|
-
}
|
|
1688
|
-
add(r, e, t) {
|
|
1689
|
-
var o;
|
|
1690
|
-
const { middleware: n, routes: s } = this;
|
|
1691
|
-
if (!n || !s)
|
|
1692
|
-
throw new Error(rr);
|
|
1693
|
-
n[r] || [n, s].forEach((c) => {
|
|
1694
|
-
c[r] = /* @__PURE__ */ Object.create(null), Object.keys(c[A]).forEach((u) => {
|
|
1695
|
-
c[r][u] = [...c[A][u]];
|
|
1696
|
-
});
|
|
1697
|
-
}), e === "/*" && (e = "*");
|
|
1698
|
-
const a = (e.match(/\/:/g) || []).length;
|
|
1699
|
-
if (/\*$/.test(e)) {
|
|
1700
|
-
const c = ir(e);
|
|
1701
|
-
r === A ? Object.keys(n).forEach((u) => {
|
|
1702
|
-
var d;
|
|
1703
|
-
(d = n[u])[e] || (d[e] = _e(n[u], e) || _e(n[A], e) || []);
|
|
1704
|
-
}) : (o = n[r])[e] || (o[e] = _e(n[r], e) || _e(n[A], e) || []), Object.keys(n).forEach((u) => {
|
|
1705
|
-
(r === A || r === u) && Object.keys(n[u]).forEach((d) => {
|
|
1706
|
-
c.test(d) && n[u][d].push([t, a]);
|
|
1707
|
-
});
|
|
1708
|
-
}), Object.keys(s).forEach((u) => {
|
|
1709
|
-
(r === A || r === u) && Object.keys(s[u]).forEach(
|
|
1710
|
-
(d) => c.test(d) && s[u][d].push([t, a])
|
|
1711
|
-
);
|
|
1712
|
-
});
|
|
1713
|
-
return;
|
|
1714
|
-
}
|
|
1715
|
-
const i = Qt(e) || [e];
|
|
1716
|
-
for (let c = 0, u = i.length; c < u; c++) {
|
|
1717
|
-
const d = i[c];
|
|
1718
|
-
Object.keys(s).forEach((f) => {
|
|
1719
|
-
var k;
|
|
1720
|
-
(r === A || r === f) && ((k = s[f])[d] || (k[d] = [
|
|
1721
|
-
..._e(n[f], d) || _e(n[A], d) || []
|
|
1722
|
-
]), s[f][d].push([t, a - u + c + 1]));
|
|
1723
|
-
});
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
match(r, e) {
|
|
1727
|
-
xn();
|
|
1728
|
-
const t = this.buildAllMatchers();
|
|
1729
|
-
return this.match = (n, s) => {
|
|
1730
|
-
const a = t[n] || t[A], i = a[2][s];
|
|
1731
|
-
if (i)
|
|
1732
|
-
return i;
|
|
1733
|
-
const o = s.match(a[0]);
|
|
1734
|
-
if (!o)
|
|
1735
|
-
return [[], ar];
|
|
1736
|
-
const c = o.indexOf("", 1);
|
|
1737
|
-
return [a[1][c], o];
|
|
1738
|
-
}, this.match(r, e);
|
|
1739
|
-
}
|
|
1740
|
-
buildAllMatchers() {
|
|
1741
|
-
const r = /* @__PURE__ */ Object.create(null);
|
|
1742
|
-
return [...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((e) => {
|
|
1743
|
-
r[e] || (r[e] = this.buildMatcher(e));
|
|
1744
|
-
}), this.middleware = this.routes = void 0, r;
|
|
1745
|
-
}
|
|
1746
|
-
buildMatcher(r) {
|
|
1747
|
-
const e = [];
|
|
1748
|
-
let t = r === A;
|
|
1749
|
-
return [this.middleware, this.routes].forEach((n) => {
|
|
1750
|
-
const s = n[r] ? Object.keys(n[r]).map((a) => [a, n[r][a]]) : [];
|
|
1751
|
-
s.length !== 0 ? (t || (t = !0), e.push(...s)) : r !== A && e.push(
|
|
1752
|
-
...Object.keys(n[A]).map((a) => [a, n[A][a]])
|
|
1753
|
-
);
|
|
1754
|
-
}), t ? On(e) : null;
|
|
1755
|
-
}
|
|
1756
|
-
}, Tn = class {
|
|
1757
|
-
constructor(r) {
|
|
1758
|
-
p(this, "name", "SmartRouter");
|
|
1759
|
-
p(this, "routers", []);
|
|
1760
|
-
p(this, "routes", []);
|
|
1761
|
-
Object.assign(this, r);
|
|
1762
|
-
}
|
|
1763
|
-
add(r, e, t) {
|
|
1764
|
-
if (!this.routes)
|
|
1765
|
-
throw new Error(rr);
|
|
1766
|
-
this.routes.push([r, e, t]);
|
|
1767
|
-
}
|
|
1768
|
-
match(r, e) {
|
|
1769
|
-
if (!this.routes)
|
|
1770
|
-
throw new Error("Fatal error");
|
|
1771
|
-
const { routers: t, routes: n } = this, s = t.length;
|
|
1772
|
-
let a = 0, i;
|
|
1773
|
-
for (; a < s; a++) {
|
|
1774
|
-
const o = t[a];
|
|
1775
|
-
try {
|
|
1776
|
-
n.forEach((c) => {
|
|
1777
|
-
o.add(...c);
|
|
1778
|
-
}), i = o.match(r, e);
|
|
1779
|
-
} catch (c) {
|
|
1780
|
-
if (c instanceof nr)
|
|
1781
|
-
continue;
|
|
1782
|
-
throw c;
|
|
1783
|
-
}
|
|
1784
|
-
this.match = o.match.bind(o), this.routers = [o], this.routes = void 0;
|
|
1785
|
-
break;
|
|
1786
|
-
}
|
|
1787
|
-
if (a === s)
|
|
1788
|
-
throw new Error("Fatal error");
|
|
1789
|
-
return this.name = `SmartRouter + ${this.activeRouter.name}`, i;
|
|
1790
|
-
}
|
|
1791
|
-
get activeRouter() {
|
|
1792
|
-
if (this.routes || this.routers.length !== 1)
|
|
1793
|
-
throw new Error("No active router has been determined yet.");
|
|
1794
|
-
return this.routers[0];
|
|
1795
|
-
}
|
|
1796
|
-
}, or = class {
|
|
1797
|
-
constructor(r, e, t) {
|
|
1798
|
-
p(this, "methods");
|
|
1799
|
-
p(this, "children");
|
|
1800
|
-
p(this, "patterns");
|
|
1801
|
-
p(this, "order", 0);
|
|
1802
|
-
p(this, "name");
|
|
1803
|
-
p(this, "params", /* @__PURE__ */ Object.create(null));
|
|
1804
|
-
if (this.children = t || /* @__PURE__ */ Object.create(null), this.methods = [], this.name = "", r && e) {
|
|
1805
|
-
const n = /* @__PURE__ */ Object.create(null);
|
|
1806
|
-
n[r] = { handler: e, possibleKeys: [], score: 0, name: this.name }, this.methods = [n];
|
|
1807
|
-
}
|
|
1808
|
-
this.patterns = [];
|
|
1809
|
-
}
|
|
1810
|
-
insert(r, e, t) {
|
|
1811
|
-
this.name = `${r} ${e}`, this.order = ++this.order;
|
|
1812
|
-
let n = this;
|
|
1813
|
-
const s = Gr(e), a = [];
|
|
1814
|
-
for (let c = 0, u = s.length; c < u; c++) {
|
|
1815
|
-
const d = s[c];
|
|
1816
|
-
if (Object.keys(n.children).includes(d)) {
|
|
1817
|
-
n = n.children[d];
|
|
1818
|
-
const k = Vt(d);
|
|
1819
|
-
k && a.push(k[1]);
|
|
1820
|
-
continue;
|
|
1821
|
-
}
|
|
1822
|
-
n.children[d] = new or();
|
|
1823
|
-
const f = Vt(d);
|
|
1824
|
-
f && (n.patterns.push(f), a.push(f[1])), n = n.children[d];
|
|
1825
|
-
}
|
|
1826
|
-
n.methods.length || (n.methods = []);
|
|
1827
|
-
const i = /* @__PURE__ */ Object.create(null), o = {
|
|
1828
|
-
handler: t,
|
|
1829
|
-
possibleKeys: a.filter((c, u, d) => d.indexOf(c) === u),
|
|
1830
|
-
name: this.name,
|
|
1831
|
-
score: this.order
|
|
1832
|
-
};
|
|
1833
|
-
return i[r] = o, n.methods.push(i), n;
|
|
1834
|
-
}
|
|
1835
|
-
gHSets(r, e, t, n) {
|
|
1836
|
-
const s = [];
|
|
1837
|
-
for (let a = 0, i = r.methods.length; a < i; a++) {
|
|
1838
|
-
const o = r.methods[a], c = o[e] || o[A], u = /* @__PURE__ */ Object.create(null);
|
|
1839
|
-
c !== void 0 && (c.params = /* @__PURE__ */ Object.create(null), c.possibleKeys.forEach((d) => {
|
|
1840
|
-
const f = u[c.name];
|
|
1841
|
-
c.params[d] = n[d] && !f ? n[d] : t[d] ?? n[d], u[c.name] = !0;
|
|
1842
|
-
}), s.push(c));
|
|
1843
|
-
}
|
|
1844
|
-
return s;
|
|
1845
|
-
}
|
|
1846
|
-
search(r, e) {
|
|
1847
|
-
const t = [];
|
|
1848
|
-
this.params = /* @__PURE__ */ Object.create(null);
|
|
1849
|
-
let s = [this];
|
|
1850
|
-
const a = Yt(e);
|
|
1851
|
-
for (let o = 0, c = a.length; o < c; o++) {
|
|
1852
|
-
const u = a[o], d = o === c - 1, f = [];
|
|
1853
|
-
for (let k = 0, E = s.length; k < E; k++) {
|
|
1854
|
-
const R = s[k], b = R.children[u];
|
|
1855
|
-
b && (b.params = R.params, d === !0 ? (b.children["*"] && t.push(
|
|
1856
|
-
...this.gHSets(b.children["*"], r, R.params, /* @__PURE__ */ Object.create(null))
|
|
1857
|
-
), t.push(...this.gHSets(b, r, R.params, /* @__PURE__ */ Object.create(null)))) : f.push(b));
|
|
1858
|
-
for (let S = 0, D = R.patterns.length; S < D; S++) {
|
|
1859
|
-
const G = R.patterns[S], V = { ...R.params };
|
|
1860
|
-
if (G === "*") {
|
|
1861
|
-
const de = R.children["*"];
|
|
1862
|
-
de && (t.push(...this.gHSets(de, r, R.params, /* @__PURE__ */ Object.create(null))), f.push(de));
|
|
1863
|
-
continue;
|
|
1864
|
-
}
|
|
1865
|
-
if (u === "")
|
|
1866
|
-
continue;
|
|
1867
|
-
const [ge, ne, Q] = G, K = R.children[ge], ve = a.slice(o).join("/");
|
|
1868
|
-
if (Q instanceof RegExp && Q.test(ve)) {
|
|
1869
|
-
V[ne] = ve, t.push(...this.gHSets(K, r, R.params, V));
|
|
1870
|
-
continue;
|
|
1871
|
-
}
|
|
1872
|
-
(Q === !0 || Q instanceof RegExp && Q.test(u)) && typeof ge == "string" && (V[ne] = u, d === !0 ? (t.push(...this.gHSets(K, r, V, R.params)), K.children["*"] && t.push(...this.gHSets(K.children["*"], r, V, R.params))) : (K.params = V, f.push(K)));
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
s = f;
|
|
1876
|
-
}
|
|
1877
|
-
return [t.sort((o, c) => o.score - c.score).map(({ handler: o, params: c }) => [o, c])];
|
|
1878
|
-
}
|
|
1879
|
-
}, jn = class {
|
|
1880
|
-
constructor() {
|
|
1881
|
-
p(this, "name", "TrieRouter");
|
|
1882
|
-
p(this, "node");
|
|
1883
|
-
this.node = new or();
|
|
1884
|
-
}
|
|
1885
|
-
add(r, e, t) {
|
|
1886
|
-
const n = Qt(e);
|
|
1887
|
-
if (n) {
|
|
1888
|
-
for (const s of n)
|
|
1889
|
-
this.node.insert(r, s, t);
|
|
1890
|
-
return;
|
|
1891
|
-
}
|
|
1892
|
-
this.node.insert(r, e, t);
|
|
1893
|
-
}
|
|
1894
|
-
match(r, e) {
|
|
1895
|
-
return this.node.search(r, e);
|
|
1896
|
-
}
|
|
1897
|
-
}, Rn = class extends sr {
|
|
1898
|
-
constructor(r = {}) {
|
|
1899
|
-
super(r), this.router = r.router ?? new Tn({
|
|
1900
|
-
routers: [new kn(), new jn()]
|
|
1901
|
-
});
|
|
1902
|
-
}
|
|
1903
|
-
}, j;
|
|
1904
|
-
(function(r) {
|
|
1905
|
-
r.assertEqual = (s) => s;
|
|
1906
|
-
function e(s) {
|
|
1907
|
-
}
|
|
1908
|
-
r.assertIs = e;
|
|
1909
|
-
function t(s) {
|
|
1910
|
-
throw new Error();
|
|
1911
|
-
}
|
|
1912
|
-
r.assertNever = t, r.arrayToEnum = (s) => {
|
|
1913
|
-
const a = {};
|
|
1914
|
-
for (const i of s)
|
|
1915
|
-
a[i] = i;
|
|
1916
|
-
return a;
|
|
1917
|
-
}, r.getValidEnumValues = (s) => {
|
|
1918
|
-
const a = r.objectKeys(s).filter((o) => typeof s[s[o]] != "number"), i = {};
|
|
1919
|
-
for (const o of a)
|
|
1920
|
-
i[o] = s[o];
|
|
1921
|
-
return r.objectValues(i);
|
|
1922
|
-
}, r.objectValues = (s) => r.objectKeys(s).map(function(a) {
|
|
1923
|
-
return s[a];
|
|
1924
|
-
}), r.objectKeys = typeof Object.keys == "function" ? (s) => Object.keys(s) : (s) => {
|
|
1925
|
-
const a = [];
|
|
1926
|
-
for (const i in s)
|
|
1927
|
-
Object.prototype.hasOwnProperty.call(s, i) && a.push(i);
|
|
1928
|
-
return a;
|
|
1929
|
-
}, r.find = (s, a) => {
|
|
1930
|
-
for (const i of s)
|
|
1931
|
-
if (a(i))
|
|
1932
|
-
return i;
|
|
1933
|
-
}, r.isInteger = typeof Number.isInteger == "function" ? (s) => Number.isInteger(s) : (s) => typeof s == "number" && isFinite(s) && Math.floor(s) === s;
|
|
1934
|
-
function n(s, a = " | ") {
|
|
1935
|
-
return s.map((i) => typeof i == "string" ? `'${i}'` : i).join(a);
|
|
1936
|
-
}
|
|
1937
|
-
r.joinValues = n, r.jsonStringifyReplacer = (s, a) => typeof a == "bigint" ? a.toString() : a;
|
|
1938
|
-
})(j || (j = {}));
|
|
1939
|
-
var Ct;
|
|
1940
|
-
(function(r) {
|
|
1941
|
-
r.mergeShapes = (e, t) => ({
|
|
1942
|
-
...e,
|
|
1943
|
-
...t
|
|
1944
|
-
// second overwrites first
|
|
1945
|
-
});
|
|
1946
|
-
})(Ct || (Ct = {}));
|
|
1947
|
-
const g = j.arrayToEnum([
|
|
1948
|
-
"string",
|
|
1949
|
-
"nan",
|
|
1950
|
-
"number",
|
|
1951
|
-
"integer",
|
|
1952
|
-
"float",
|
|
1953
|
-
"boolean",
|
|
1954
|
-
"date",
|
|
1955
|
-
"bigint",
|
|
1956
|
-
"symbol",
|
|
1957
|
-
"function",
|
|
1958
|
-
"undefined",
|
|
1959
|
-
"null",
|
|
1960
|
-
"array",
|
|
1961
|
-
"object",
|
|
1962
|
-
"unknown",
|
|
1963
|
-
"promise",
|
|
1964
|
-
"void",
|
|
1965
|
-
"never",
|
|
1966
|
-
"map",
|
|
1967
|
-
"set"
|
|
1968
|
-
]), se = (r) => {
|
|
1969
|
-
switch (typeof r) {
|
|
1970
|
-
case "undefined":
|
|
1971
|
-
return g.undefined;
|
|
1972
|
-
case "string":
|
|
1973
|
-
return g.string;
|
|
1974
|
-
case "number":
|
|
1975
|
-
return isNaN(r) ? g.nan : g.number;
|
|
1976
|
-
case "boolean":
|
|
1977
|
-
return g.boolean;
|
|
1978
|
-
case "function":
|
|
1979
|
-
return g.function;
|
|
1980
|
-
case "bigint":
|
|
1981
|
-
return g.bigint;
|
|
1982
|
-
case "symbol":
|
|
1983
|
-
return g.symbol;
|
|
1984
|
-
case "object":
|
|
1985
|
-
return Array.isArray(r) ? g.array : r === null ? g.null : r.then && typeof r.then == "function" && r.catch && typeof r.catch == "function" ? g.promise : typeof Map < "u" && r instanceof Map ? g.map : typeof Set < "u" && r instanceof Set ? g.set : typeof Date < "u" && r instanceof Date ? g.date : g.object;
|
|
1986
|
-
default:
|
|
1987
|
-
return g.unknown;
|
|
1988
|
-
}
|
|
1989
|
-
}, l = j.arrayToEnum([
|
|
1990
|
-
"invalid_type",
|
|
1991
|
-
"invalid_literal",
|
|
1992
|
-
"custom",
|
|
1993
|
-
"invalid_union",
|
|
1994
|
-
"invalid_union_discriminator",
|
|
1995
|
-
"invalid_enum_value",
|
|
1996
|
-
"unrecognized_keys",
|
|
1997
|
-
"invalid_arguments",
|
|
1998
|
-
"invalid_return_type",
|
|
1999
|
-
"invalid_date",
|
|
2000
|
-
"invalid_string",
|
|
2001
|
-
"too_small",
|
|
2002
|
-
"too_big",
|
|
2003
|
-
"invalid_intersection_types",
|
|
2004
|
-
"not_multiple_of",
|
|
2005
|
-
"not_finite"
|
|
2006
|
-
]), En = (r) => JSON.stringify(r, null, 2).replace(/"([^"]+)":/g, "$1:");
|
|
2007
|
-
class L extends Error {
|
|
2008
|
-
constructor(e) {
|
|
2009
|
-
super(), this.issues = [], this.addIssue = (n) => {
|
|
2010
|
-
this.issues = [...this.issues, n];
|
|
2011
|
-
}, this.addIssues = (n = []) => {
|
|
2012
|
-
this.issues = [...this.issues, ...n];
|
|
2013
|
-
};
|
|
2014
|
-
const t = new.target.prototype;
|
|
2015
|
-
Object.setPrototypeOf ? Object.setPrototypeOf(this, t) : this.__proto__ = t, this.name = "ZodError", this.issues = e;
|
|
2016
|
-
}
|
|
2017
|
-
get errors() {
|
|
2018
|
-
return this.issues;
|
|
2019
|
-
}
|
|
2020
|
-
format(e) {
|
|
2021
|
-
const t = e || function(a) {
|
|
2022
|
-
return a.message;
|
|
2023
|
-
}, n = { _errors: [] }, s = (a) => {
|
|
2024
|
-
for (const i of a.issues)
|
|
2025
|
-
if (i.code === "invalid_union")
|
|
2026
|
-
i.unionErrors.map(s);
|
|
2027
|
-
else if (i.code === "invalid_return_type")
|
|
2028
|
-
s(i.returnTypeError);
|
|
2029
|
-
else if (i.code === "invalid_arguments")
|
|
2030
|
-
s(i.argumentsError);
|
|
2031
|
-
else if (i.path.length === 0)
|
|
2032
|
-
n._errors.push(t(i));
|
|
2033
|
-
else {
|
|
2034
|
-
let o = n, c = 0;
|
|
2035
|
-
for (; c < i.path.length; ) {
|
|
2036
|
-
const u = i.path[c];
|
|
2037
|
-
c === i.path.length - 1 ? (o[u] = o[u] || { _errors: [] }, o[u]._errors.push(t(i))) : o[u] = o[u] || { _errors: [] }, o = o[u], c++;
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2040
|
-
};
|
|
2041
|
-
return s(this), n;
|
|
2042
|
-
}
|
|
2043
|
-
static assert(e) {
|
|
2044
|
-
if (!(e instanceof L))
|
|
2045
|
-
throw new Error(`Not a ZodError: ${e}`);
|
|
2046
|
-
}
|
|
2047
|
-
toString() {
|
|
2048
|
-
return this.message;
|
|
2049
|
-
}
|
|
2050
|
-
get message() {
|
|
2051
|
-
return JSON.stringify(this.issues, j.jsonStringifyReplacer, 2);
|
|
2052
|
-
}
|
|
2053
|
-
get isEmpty() {
|
|
2054
|
-
return this.issues.length === 0;
|
|
2055
|
-
}
|
|
2056
|
-
flatten(e = (t) => t.message) {
|
|
2057
|
-
const t = {}, n = [];
|
|
2058
|
-
for (const s of this.issues)
|
|
2059
|
-
s.path.length > 0 ? (t[s.path[0]] = t[s.path[0]] || [], t[s.path[0]].push(e(s))) : n.push(e(s));
|
|
2060
|
-
return { formErrors: n, fieldErrors: t };
|
|
2061
|
-
}
|
|
2062
|
-
get formErrors() {
|
|
2063
|
-
return this.flatten();
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
L.create = (r) => new L(r);
|
|
2067
|
-
const Re = (r, e) => {
|
|
2068
|
-
let t;
|
|
2069
|
-
switch (r.code) {
|
|
2070
|
-
case l.invalid_type:
|
|
2071
|
-
r.received === g.undefined ? t = "Required" : t = `Expected ${r.expected}, received ${r.received}`;
|
|
2072
|
-
break;
|
|
2073
|
-
case l.invalid_literal:
|
|
2074
|
-
t = `Invalid literal value, expected ${JSON.stringify(r.expected, j.jsonStringifyReplacer)}`;
|
|
2075
|
-
break;
|
|
2076
|
-
case l.unrecognized_keys:
|
|
2077
|
-
t = `Unrecognized key(s) in object: ${j.joinValues(r.keys, ", ")}`;
|
|
2078
|
-
break;
|
|
2079
|
-
case l.invalid_union:
|
|
2080
|
-
t = "Invalid input";
|
|
2081
|
-
break;
|
|
2082
|
-
case l.invalid_union_discriminator:
|
|
2083
|
-
t = `Invalid discriminator value. Expected ${j.joinValues(r.options)}`;
|
|
2084
|
-
break;
|
|
2085
|
-
case l.invalid_enum_value:
|
|
2086
|
-
t = `Invalid enum value. Expected ${j.joinValues(r.options)}, received '${r.received}'`;
|
|
2087
|
-
break;
|
|
2088
|
-
case l.invalid_arguments:
|
|
2089
|
-
t = "Invalid function arguments";
|
|
2090
|
-
break;
|
|
2091
|
-
case l.invalid_return_type:
|
|
2092
|
-
t = "Invalid function return type";
|
|
2093
|
-
break;
|
|
2094
|
-
case l.invalid_date:
|
|
2095
|
-
t = "Invalid date";
|
|
2096
|
-
break;
|
|
2097
|
-
case l.invalid_string:
|
|
2098
|
-
typeof r.validation == "object" ? "includes" in r.validation ? (t = `Invalid input: must include "${r.validation.includes}"`, typeof r.validation.position == "number" && (t = `${t} at one or more positions greater than or equal to ${r.validation.position}`)) : "startsWith" in r.validation ? t = `Invalid input: must start with "${r.validation.startsWith}"` : "endsWith" in r.validation ? t = `Invalid input: must end with "${r.validation.endsWith}"` : j.assertNever(r.validation) : r.validation !== "regex" ? t = `Invalid ${r.validation}` : t = "Invalid";
|
|
2099
|
-
break;
|
|
2100
|
-
case l.too_small:
|
|
2101
|
-
r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "more than"} ${r.minimum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "over"} ${r.minimum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${r.minimum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(r.minimum))}` : t = "Invalid input";
|
|
2102
|
-
break;
|
|
2103
|
-
case l.too_big:
|
|
2104
|
-
r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "less than"} ${r.maximum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "under"} ${r.maximum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "bigint" ? t = `BigInt must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly" : r.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(r.maximum))}` : t = "Invalid input";
|
|
2105
|
-
break;
|
|
2106
|
-
case l.custom:
|
|
2107
|
-
t = "Invalid input";
|
|
2108
|
-
break;
|
|
2109
|
-
case l.invalid_intersection_types:
|
|
2110
|
-
t = "Intersection results could not be merged";
|
|
2111
|
-
break;
|
|
2112
|
-
case l.not_multiple_of:
|
|
2113
|
-
t = `Number must be a multiple of ${r.multipleOf}`;
|
|
2114
|
-
break;
|
|
2115
|
-
case l.not_finite:
|
|
2116
|
-
t = "Number must be finite";
|
|
2117
|
-
break;
|
|
2118
|
-
default:
|
|
2119
|
-
t = e.defaultError, j.assertNever(r);
|
|
2120
|
-
}
|
|
2121
|
-
return { message: t };
|
|
2122
|
-
};
|
|
2123
|
-
let cr = Re;
|
|
2124
|
-
function In(r) {
|
|
2125
|
-
cr = r;
|
|
2126
|
-
}
|
|
2127
|
-
function pt() {
|
|
2128
|
-
return cr;
|
|
2129
|
-
}
|
|
2130
|
-
const mt = (r) => {
|
|
2131
|
-
const { data: e, path: t, errorMaps: n, issueData: s } = r, a = [...t, ...s.path || []], i = {
|
|
2132
|
-
...s,
|
|
2133
|
-
path: a
|
|
2134
|
-
};
|
|
2135
|
-
if (s.message !== void 0)
|
|
2136
|
-
return {
|
|
2137
|
-
...s,
|
|
2138
|
-
path: a,
|
|
2139
|
-
message: s.message
|
|
2140
|
-
};
|
|
2141
|
-
let o = "";
|
|
2142
|
-
const c = n.filter((u) => !!u).slice().reverse();
|
|
2143
|
-
for (const u of c)
|
|
2144
|
-
o = u(i, { data: e, defaultError: o }).message;
|
|
2145
|
-
return {
|
|
2146
|
-
...s,
|
|
2147
|
-
path: a,
|
|
2148
|
-
message: o
|
|
2149
|
-
};
|
|
2150
|
-
}, Pn = [];
|
|
2151
|
-
function m(r, e) {
|
|
2152
|
-
const t = pt(), n = mt({
|
|
2153
|
-
issueData: e,
|
|
2154
|
-
data: r.data,
|
|
2155
|
-
path: r.path,
|
|
2156
|
-
errorMaps: [
|
|
2157
|
-
r.common.contextualErrorMap,
|
|
2158
|
-
r.schemaErrorMap,
|
|
2159
|
-
t,
|
|
2160
|
-
t === Re ? void 0 : Re
|
|
2161
|
-
// then global default map
|
|
2162
|
-
].filter((s) => !!s)
|
|
2163
|
-
});
|
|
2164
|
-
r.common.issues.push(n);
|
|
2165
|
-
}
|
|
2166
|
-
class M {
|
|
2167
|
-
constructor() {
|
|
2168
|
-
this.value = "valid";
|
|
2169
|
-
}
|
|
2170
|
-
dirty() {
|
|
2171
|
-
this.value === "valid" && (this.value = "dirty");
|
|
2172
|
-
}
|
|
2173
|
-
abort() {
|
|
2174
|
-
this.value !== "aborted" && (this.value = "aborted");
|
|
2175
|
-
}
|
|
2176
|
-
static mergeArray(e, t) {
|
|
2177
|
-
const n = [];
|
|
2178
|
-
for (const s of t) {
|
|
2179
|
-
if (s.status === "aborted")
|
|
2180
|
-
return _;
|
|
2181
|
-
s.status === "dirty" && e.dirty(), n.push(s.value);
|
|
2182
|
-
}
|
|
2183
|
-
return { status: e.value, value: n };
|
|
2184
|
-
}
|
|
2185
|
-
static async mergeObjectAsync(e, t) {
|
|
2186
|
-
const n = [];
|
|
2187
|
-
for (const s of t) {
|
|
2188
|
-
const a = await s.key, i = await s.value;
|
|
2189
|
-
n.push({
|
|
2190
|
-
key: a,
|
|
2191
|
-
value: i
|
|
2192
|
-
});
|
|
2193
|
-
}
|
|
2194
|
-
return M.mergeObjectSync(e, n);
|
|
2195
|
-
}
|
|
2196
|
-
static mergeObjectSync(e, t) {
|
|
2197
|
-
const n = {};
|
|
2198
|
-
for (const s of t) {
|
|
2199
|
-
const { key: a, value: i } = s;
|
|
2200
|
-
if (a.status === "aborted" || i.status === "aborted")
|
|
2201
|
-
return _;
|
|
2202
|
-
a.status === "dirty" && e.dirty(), i.status === "dirty" && e.dirty(), a.value !== "__proto__" && (typeof i.value < "u" || s.alwaysSet) && (n[a.value] = i.value);
|
|
2203
|
-
}
|
|
2204
|
-
return { status: e.value, value: n };
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
const _ = Object.freeze({
|
|
2208
|
-
status: "aborted"
|
|
2209
|
-
}), we = (r) => ({ status: "dirty", value: r }), $ = (r) => ({ status: "valid", value: r }), Zt = (r) => r.status === "aborted", St = (r) => r.status === "dirty", Ue = (r) => r.status === "valid", He = (r) => typeof Promise < "u" && r instanceof Promise;
|
|
2210
|
-
function gt(r, e, t, n) {
|
|
2211
|
-
if (typeof e == "function" ? r !== e || !n : !e.has(r)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
2212
|
-
return e.get(r);
|
|
2213
|
-
}
|
|
2214
|
-
function ur(r, e, t, n, s) {
|
|
2215
|
-
if (typeof e == "function" ? r !== e || !s : !e.has(r)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
2216
|
-
return e.set(r, t), t;
|
|
2217
|
-
}
|
|
2218
|
-
var v;
|
|
2219
|
-
(function(r) {
|
|
2220
|
-
r.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, r.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message;
|
|
2221
|
-
})(v || (v = {}));
|
|
2222
|
-
var Ne, De;
|
|
2223
|
-
class Y {
|
|
2224
|
-
constructor(e, t, n, s) {
|
|
2225
|
-
this._cachedPath = [], this.parent = e, this.data = t, this._path = n, this._key = s;
|
|
2226
|
-
}
|
|
2227
|
-
get path() {
|
|
2228
|
-
return this._cachedPath.length || (this._key instanceof Array ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
const qt = (r, e) => {
|
|
2232
|
-
if (Ue(e))
|
|
2233
|
-
return { success: !0, data: e.value };
|
|
2234
|
-
if (!r.common.issues.length)
|
|
2235
|
-
throw new Error("Validation failed but no issues detected.");
|
|
2236
|
-
return {
|
|
2237
|
-
success: !1,
|
|
2238
|
-
get error() {
|
|
2239
|
-
if (this._error)
|
|
2240
|
-
return this._error;
|
|
2241
|
-
const t = new L(r.common.issues);
|
|
2242
|
-
return this._error = t, this._error;
|
|
2243
|
-
}
|
|
2244
|
-
};
|
|
2245
|
-
};
|
|
2246
|
-
function w(r) {
|
|
2247
|
-
if (!r)
|
|
2248
|
-
return {};
|
|
2249
|
-
const { errorMap: e, invalid_type_error: t, required_error: n, description: s } = r;
|
|
2250
|
-
if (e && (t || n))
|
|
2251
|
-
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
2252
|
-
return e ? { errorMap: e, description: s } : { errorMap: (i, o) => {
|
|
2253
|
-
var c, u;
|
|
2254
|
-
const { message: d } = r;
|
|
2255
|
-
return i.code === "invalid_enum_value" ? { message: d ?? o.defaultError } : typeof o.data > "u" ? { message: (c = d ?? n) !== null && c !== void 0 ? c : o.defaultError } : i.code !== "invalid_type" ? { message: o.defaultError } : { message: (u = d ?? t) !== null && u !== void 0 ? u : o.defaultError };
|
|
2256
|
-
}, description: s };
|
|
2257
|
-
}
|
|
2258
|
-
class O {
|
|
2259
|
-
constructor(e) {
|
|
2260
|
-
this.spa = this.safeParseAsync, this._def = e, this.parse = this.parse.bind(this), this.safeParse = this.safeParse.bind(this), this.parseAsync = this.parseAsync.bind(this), this.safeParseAsync = this.safeParseAsync.bind(this), this.spa = this.spa.bind(this), this.refine = this.refine.bind(this), this.refinement = this.refinement.bind(this), this.superRefine = this.superRefine.bind(this), this.optional = this.optional.bind(this), this.nullable = this.nullable.bind(this), this.nullish = this.nullish.bind(this), this.array = this.array.bind(this), this.promise = this.promise.bind(this), this.or = this.or.bind(this), this.and = this.and.bind(this), this.transform = this.transform.bind(this), this.brand = this.brand.bind(this), this.default = this.default.bind(this), this.catch = this.catch.bind(this), this.describe = this.describe.bind(this), this.pipe = this.pipe.bind(this), this.readonly = this.readonly.bind(this), this.isNullable = this.isNullable.bind(this), this.isOptional = this.isOptional.bind(this);
|
|
2261
|
-
}
|
|
2262
|
-
get description() {
|
|
2263
|
-
return this._def.description;
|
|
2264
|
-
}
|
|
2265
|
-
_getType(e) {
|
|
2266
|
-
return se(e.data);
|
|
2267
|
-
}
|
|
2268
|
-
_getOrReturnCtx(e, t) {
|
|
2269
|
-
return t || {
|
|
2270
|
-
common: e.parent.common,
|
|
2271
|
-
data: e.data,
|
|
2272
|
-
parsedType: se(e.data),
|
|
2273
|
-
schemaErrorMap: this._def.errorMap,
|
|
2274
|
-
path: e.path,
|
|
2275
|
-
parent: e.parent
|
|
2276
|
-
};
|
|
2277
|
-
}
|
|
2278
|
-
_processInputParams(e) {
|
|
2279
|
-
return {
|
|
2280
|
-
status: new M(),
|
|
2281
|
-
ctx: {
|
|
2282
|
-
common: e.parent.common,
|
|
2283
|
-
data: e.data,
|
|
2284
|
-
parsedType: se(e.data),
|
|
2285
|
-
schemaErrorMap: this._def.errorMap,
|
|
2286
|
-
path: e.path,
|
|
2287
|
-
parent: e.parent
|
|
2288
|
-
}
|
|
2289
|
-
};
|
|
2290
|
-
}
|
|
2291
|
-
_parseSync(e) {
|
|
2292
|
-
const t = this._parse(e);
|
|
2293
|
-
if (He(t))
|
|
2294
|
-
throw new Error("Synchronous parse encountered promise.");
|
|
2295
|
-
return t;
|
|
2296
|
-
}
|
|
2297
|
-
_parseAsync(e) {
|
|
2298
|
-
const t = this._parse(e);
|
|
2299
|
-
return Promise.resolve(t);
|
|
2300
|
-
}
|
|
2301
|
-
parse(e, t) {
|
|
2302
|
-
const n = this.safeParse(e, t);
|
|
2303
|
-
if (n.success)
|
|
2304
|
-
return n.data;
|
|
2305
|
-
throw n.error;
|
|
2306
|
-
}
|
|
2307
|
-
safeParse(e, t) {
|
|
2308
|
-
var n;
|
|
2309
|
-
const s = {
|
|
2310
|
-
common: {
|
|
2311
|
-
issues: [],
|
|
2312
|
-
async: (n = t == null ? void 0 : t.async) !== null && n !== void 0 ? n : !1,
|
|
2313
|
-
contextualErrorMap: t == null ? void 0 : t.errorMap
|
|
2314
|
-
},
|
|
2315
|
-
path: (t == null ? void 0 : t.path) || [],
|
|
2316
|
-
schemaErrorMap: this._def.errorMap,
|
|
2317
|
-
parent: null,
|
|
2318
|
-
data: e,
|
|
2319
|
-
parsedType: se(e)
|
|
2320
|
-
}, a = this._parseSync({ data: e, path: s.path, parent: s });
|
|
2321
|
-
return qt(s, a);
|
|
2322
|
-
}
|
|
2323
|
-
async parseAsync(e, t) {
|
|
2324
|
-
const n = await this.safeParseAsync(e, t);
|
|
2325
|
-
if (n.success)
|
|
2326
|
-
return n.data;
|
|
2327
|
-
throw n.error;
|
|
2328
|
-
}
|
|
2329
|
-
async safeParseAsync(e, t) {
|
|
2330
|
-
const n = {
|
|
2331
|
-
common: {
|
|
2332
|
-
issues: [],
|
|
2333
|
-
contextualErrorMap: t == null ? void 0 : t.errorMap,
|
|
2334
|
-
async: !0
|
|
2335
|
-
},
|
|
2336
|
-
path: (t == null ? void 0 : t.path) || [],
|
|
2337
|
-
schemaErrorMap: this._def.errorMap,
|
|
2338
|
-
parent: null,
|
|
2339
|
-
data: e,
|
|
2340
|
-
parsedType: se(e)
|
|
2341
|
-
}, s = this._parse({ data: e, path: n.path, parent: n }), a = await (He(s) ? s : Promise.resolve(s));
|
|
2342
|
-
return qt(n, a);
|
|
2343
|
-
}
|
|
2344
|
-
refine(e, t) {
|
|
2345
|
-
const n = (s) => typeof t == "string" || typeof t > "u" ? { message: t } : typeof t == "function" ? t(s) : t;
|
|
2346
|
-
return this._refinement((s, a) => {
|
|
2347
|
-
const i = e(s), o = () => a.addIssue({
|
|
2348
|
-
code: l.custom,
|
|
2349
|
-
...n(s)
|
|
2350
|
-
});
|
|
2351
|
-
return typeof Promise < "u" && i instanceof Promise ? i.then((c) => c ? !0 : (o(), !1)) : i ? !0 : (o(), !1);
|
|
2352
|
-
});
|
|
2353
|
-
}
|
|
2354
|
-
refinement(e, t) {
|
|
2355
|
-
return this._refinement((n, s) => e(n) ? !0 : (s.addIssue(typeof t == "function" ? t(n, s) : t), !1));
|
|
2356
|
-
}
|
|
2357
|
-
_refinement(e) {
|
|
2358
|
-
return new F({
|
|
2359
|
-
schema: this,
|
|
2360
|
-
typeName: y.ZodEffects,
|
|
2361
|
-
effect: { type: "refinement", refinement: e }
|
|
2362
|
-
});
|
|
2363
|
-
}
|
|
2364
|
-
superRefine(e) {
|
|
2365
|
-
return this._refinement(e);
|
|
2366
|
-
}
|
|
2367
|
-
optional() {
|
|
2368
|
-
return J.create(this, this._def);
|
|
2369
|
-
}
|
|
2370
|
-
nullable() {
|
|
2371
|
-
return ue.create(this, this._def);
|
|
2372
|
-
}
|
|
2373
|
-
nullish() {
|
|
2374
|
-
return this.nullable().optional();
|
|
2375
|
-
}
|
|
2376
|
-
array() {
|
|
2377
|
-
return W.create(this, this._def);
|
|
2378
|
-
}
|
|
2379
|
-
promise() {
|
|
2380
|
-
return Ie.create(this, this._def);
|
|
2381
|
-
}
|
|
2382
|
-
or(e) {
|
|
2383
|
-
return Fe.create([this, e], this._def);
|
|
2384
|
-
}
|
|
2385
|
-
and(e) {
|
|
2386
|
-
return Ge.create(this, e, this._def);
|
|
2387
|
-
}
|
|
2388
|
-
transform(e) {
|
|
2389
|
-
return new F({
|
|
2390
|
-
...w(this._def),
|
|
2391
|
-
schema: this,
|
|
2392
|
-
typeName: y.ZodEffects,
|
|
2393
|
-
effect: { type: "transform", transform: e }
|
|
2394
|
-
});
|
|
2395
|
-
}
|
|
2396
|
-
default(e) {
|
|
2397
|
-
const t = typeof e == "function" ? e : () => e;
|
|
2398
|
-
return new Qe({
|
|
2399
|
-
...w(this._def),
|
|
2400
|
-
innerType: this,
|
|
2401
|
-
defaultValue: t,
|
|
2402
|
-
typeName: y.ZodDefault
|
|
2403
|
-
});
|
|
2404
|
-
}
|
|
2405
|
-
brand() {
|
|
2406
|
-
return new Dt({
|
|
2407
|
-
typeName: y.ZodBranded,
|
|
2408
|
-
type: this,
|
|
2409
|
-
...w(this._def)
|
|
2410
|
-
});
|
|
2411
|
-
}
|
|
2412
|
-
catch(e) {
|
|
2413
|
-
const t = typeof e == "function" ? e : () => e;
|
|
2414
|
-
return new ze({
|
|
2415
|
-
...w(this._def),
|
|
2416
|
-
innerType: this,
|
|
2417
|
-
catchValue: t,
|
|
2418
|
-
typeName: y.ZodCatch
|
|
2419
|
-
});
|
|
2420
|
-
}
|
|
2421
|
-
describe(e) {
|
|
2422
|
-
const t = this.constructor;
|
|
2423
|
-
return new t({
|
|
2424
|
-
...this._def,
|
|
2425
|
-
description: e
|
|
2426
|
-
});
|
|
2427
|
-
}
|
|
2428
|
-
pipe(e) {
|
|
2429
|
-
return it.create(this, e);
|
|
2430
|
-
}
|
|
2431
|
-
readonly() {
|
|
2432
|
-
return et.create(this);
|
|
2433
|
-
}
|
|
2434
|
-
isOptional() {
|
|
2435
|
-
return this.safeParse(void 0).success;
|
|
2436
|
-
}
|
|
2437
|
-
isNullable() {
|
|
2438
|
-
return this.safeParse(null).success;
|
|
2439
|
-
}
|
|
2440
|
-
}
|
|
2441
|
-
const Cn = /^c[^\s-]{8,}$/i, Zn = /^[0-9a-z]+$/, Sn = /^[0-9A-HJKMNP-TV-Z]{26}$/, An = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i, Nn = /^[a-z0-9_-]{21}$/i, Dn = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/, Mn = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, $n = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
|
|
2442
|
-
let Et;
|
|
2443
|
-
const Ln = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/, Vn = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/, Un = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, dr = "((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))", Hn = new RegExp(`^${dr}$`);
|
|
2444
|
-
function lr(r) {
|
|
2445
|
-
let e = "([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";
|
|
2446
|
-
return r.precision ? e = `${e}\\.\\d{${r.precision}}` : r.precision == null && (e = `${e}(\\.\\d+)?`), e;
|
|
2447
|
-
}
|
|
2448
|
-
function qn(r) {
|
|
2449
|
-
return new RegExp(`^${lr(r)}$`);
|
|
2450
|
-
}
|
|
2451
|
-
function fr(r) {
|
|
2452
|
-
let e = `${dr}T${lr(r)}`;
|
|
2453
|
-
const t = [];
|
|
2454
|
-
return t.push(r.local ? "Z?" : "Z"), r.offset && t.push("([+-]\\d{2}:?\\d{2})"), e = `${e}(${t.join("|")})`, new RegExp(`^${e}$`);
|
|
2455
|
-
}
|
|
2456
|
-
function Bn(r, e) {
|
|
2457
|
-
return !!((e === "v4" || !e) && Ln.test(r) || (e === "v6" || !e) && Vn.test(r));
|
|
2458
|
-
}
|
|
2459
|
-
class B extends O {
|
|
2460
|
-
_parse(e) {
|
|
2461
|
-
if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== g.string) {
|
|
2462
|
-
const a = this._getOrReturnCtx(e);
|
|
2463
|
-
return m(a, {
|
|
2464
|
-
code: l.invalid_type,
|
|
2465
|
-
expected: g.string,
|
|
2466
|
-
received: a.parsedType
|
|
2467
|
-
}), _;
|
|
2468
|
-
}
|
|
2469
|
-
const n = new M();
|
|
2470
|
-
let s;
|
|
2471
|
-
for (const a of this._def.checks)
|
|
2472
|
-
if (a.kind === "min")
|
|
2473
|
-
e.data.length < a.value && (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2474
|
-
code: l.too_small,
|
|
2475
|
-
minimum: a.value,
|
|
2476
|
-
type: "string",
|
|
2477
|
-
inclusive: !0,
|
|
2478
|
-
exact: !1,
|
|
2479
|
-
message: a.message
|
|
2480
|
-
}), n.dirty());
|
|
2481
|
-
else if (a.kind === "max")
|
|
2482
|
-
e.data.length > a.value && (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2483
|
-
code: l.too_big,
|
|
2484
|
-
maximum: a.value,
|
|
2485
|
-
type: "string",
|
|
2486
|
-
inclusive: !0,
|
|
2487
|
-
exact: !1,
|
|
2488
|
-
message: a.message
|
|
2489
|
-
}), n.dirty());
|
|
2490
|
-
else if (a.kind === "length") {
|
|
2491
|
-
const i = e.data.length > a.value, o = e.data.length < a.value;
|
|
2492
|
-
(i || o) && (s = this._getOrReturnCtx(e, s), i ? m(s, {
|
|
2493
|
-
code: l.too_big,
|
|
2494
|
-
maximum: a.value,
|
|
2495
|
-
type: "string",
|
|
2496
|
-
inclusive: !0,
|
|
2497
|
-
exact: !0,
|
|
2498
|
-
message: a.message
|
|
2499
|
-
}) : o && m(s, {
|
|
2500
|
-
code: l.too_small,
|
|
2501
|
-
minimum: a.value,
|
|
2502
|
-
type: "string",
|
|
2503
|
-
inclusive: !0,
|
|
2504
|
-
exact: !0,
|
|
2505
|
-
message: a.message
|
|
2506
|
-
}), n.dirty());
|
|
2507
|
-
} else if (a.kind === "email")
|
|
2508
|
-
Mn.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2509
|
-
validation: "email",
|
|
2510
|
-
code: l.invalid_string,
|
|
2511
|
-
message: a.message
|
|
2512
|
-
}), n.dirty());
|
|
2513
|
-
else if (a.kind === "emoji")
|
|
2514
|
-
Et || (Et = new RegExp($n, "u")), Et.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2515
|
-
validation: "emoji",
|
|
2516
|
-
code: l.invalid_string,
|
|
2517
|
-
message: a.message
|
|
2518
|
-
}), n.dirty());
|
|
2519
|
-
else if (a.kind === "uuid")
|
|
2520
|
-
An.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2521
|
-
validation: "uuid",
|
|
2522
|
-
code: l.invalid_string,
|
|
2523
|
-
message: a.message
|
|
2524
|
-
}), n.dirty());
|
|
2525
|
-
else if (a.kind === "nanoid")
|
|
2526
|
-
Nn.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2527
|
-
validation: "nanoid",
|
|
2528
|
-
code: l.invalid_string,
|
|
2529
|
-
message: a.message
|
|
2530
|
-
}), n.dirty());
|
|
2531
|
-
else if (a.kind === "cuid")
|
|
2532
|
-
Cn.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2533
|
-
validation: "cuid",
|
|
2534
|
-
code: l.invalid_string,
|
|
2535
|
-
message: a.message
|
|
2536
|
-
}), n.dirty());
|
|
2537
|
-
else if (a.kind === "cuid2")
|
|
2538
|
-
Zn.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2539
|
-
validation: "cuid2",
|
|
2540
|
-
code: l.invalid_string,
|
|
2541
|
-
message: a.message
|
|
2542
|
-
}), n.dirty());
|
|
2543
|
-
else if (a.kind === "ulid")
|
|
2544
|
-
Sn.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2545
|
-
validation: "ulid",
|
|
2546
|
-
code: l.invalid_string,
|
|
2547
|
-
message: a.message
|
|
2548
|
-
}), n.dirty());
|
|
2549
|
-
else if (a.kind === "url")
|
|
2550
|
-
try {
|
|
2551
|
-
new URL(e.data);
|
|
2552
|
-
} catch {
|
|
2553
|
-
s = this._getOrReturnCtx(e, s), m(s, {
|
|
2554
|
-
validation: "url",
|
|
2555
|
-
code: l.invalid_string,
|
|
2556
|
-
message: a.message
|
|
2557
|
-
}), n.dirty();
|
|
2558
|
-
}
|
|
2559
|
-
else a.kind === "regex" ? (a.regex.lastIndex = 0, a.regex.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2560
|
-
validation: "regex",
|
|
2561
|
-
code: l.invalid_string,
|
|
2562
|
-
message: a.message
|
|
2563
|
-
}), n.dirty())) : a.kind === "trim" ? e.data = e.data.trim() : a.kind === "includes" ? e.data.includes(a.value, a.position) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2564
|
-
code: l.invalid_string,
|
|
2565
|
-
validation: { includes: a.value, position: a.position },
|
|
2566
|
-
message: a.message
|
|
2567
|
-
}), n.dirty()) : a.kind === "toLowerCase" ? e.data = e.data.toLowerCase() : a.kind === "toUpperCase" ? e.data = e.data.toUpperCase() : a.kind === "startsWith" ? e.data.startsWith(a.value) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2568
|
-
code: l.invalid_string,
|
|
2569
|
-
validation: { startsWith: a.value },
|
|
2570
|
-
message: a.message
|
|
2571
|
-
}), n.dirty()) : a.kind === "endsWith" ? e.data.endsWith(a.value) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2572
|
-
code: l.invalid_string,
|
|
2573
|
-
validation: { endsWith: a.value },
|
|
2574
|
-
message: a.message
|
|
2575
|
-
}), n.dirty()) : a.kind === "datetime" ? fr(a).test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2576
|
-
code: l.invalid_string,
|
|
2577
|
-
validation: "datetime",
|
|
2578
|
-
message: a.message
|
|
2579
|
-
}), n.dirty()) : a.kind === "date" ? Hn.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2580
|
-
code: l.invalid_string,
|
|
2581
|
-
validation: "date",
|
|
2582
|
-
message: a.message
|
|
2583
|
-
}), n.dirty()) : a.kind === "time" ? qn(a).test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2584
|
-
code: l.invalid_string,
|
|
2585
|
-
validation: "time",
|
|
2586
|
-
message: a.message
|
|
2587
|
-
}), n.dirty()) : a.kind === "duration" ? Dn.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2588
|
-
validation: "duration",
|
|
2589
|
-
code: l.invalid_string,
|
|
2590
|
-
message: a.message
|
|
2591
|
-
}), n.dirty()) : a.kind === "ip" ? Bn(e.data, a.version) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2592
|
-
validation: "ip",
|
|
2593
|
-
code: l.invalid_string,
|
|
2594
|
-
message: a.message
|
|
2595
|
-
}), n.dirty()) : a.kind === "base64" ? Un.test(e.data) || (s = this._getOrReturnCtx(e, s), m(s, {
|
|
2596
|
-
validation: "base64",
|
|
2597
|
-
code: l.invalid_string,
|
|
2598
|
-
message: a.message
|
|
2599
|
-
}), n.dirty()) : j.assertNever(a);
|
|
2600
|
-
return { status: n.value, value: e.data };
|
|
2601
|
-
}
|
|
2602
|
-
_regex(e, t, n) {
|
|
2603
|
-
return this.refinement((s) => e.test(s), {
|
|
2604
|
-
validation: t,
|
|
2605
|
-
code: l.invalid_string,
|
|
2606
|
-
...v.errToObj(n)
|
|
2607
|
-
});
|
|
2608
|
-
}
|
|
2609
|
-
_addCheck(e) {
|
|
2610
|
-
return new B({
|
|
2611
|
-
...this._def,
|
|
2612
|
-
checks: [...this._def.checks, e]
|
|
2613
|
-
});
|
|
2614
|
-
}
|
|
2615
|
-
email(e) {
|
|
2616
|
-
return this._addCheck({ kind: "email", ...v.errToObj(e) });
|
|
2617
|
-
}
|
|
2618
|
-
url(e) {
|
|
2619
|
-
return this._addCheck({ kind: "url", ...v.errToObj(e) });
|
|
2620
|
-
}
|
|
2621
|
-
emoji(e) {
|
|
2622
|
-
return this._addCheck({ kind: "emoji", ...v.errToObj(e) });
|
|
2623
|
-
}
|
|
2624
|
-
uuid(e) {
|
|
2625
|
-
return this._addCheck({ kind: "uuid", ...v.errToObj(e) });
|
|
2626
|
-
}
|
|
2627
|
-
nanoid(e) {
|
|
2628
|
-
return this._addCheck({ kind: "nanoid", ...v.errToObj(e) });
|
|
2629
|
-
}
|
|
2630
|
-
cuid(e) {
|
|
2631
|
-
return this._addCheck({ kind: "cuid", ...v.errToObj(e) });
|
|
2632
|
-
}
|
|
2633
|
-
cuid2(e) {
|
|
2634
|
-
return this._addCheck({ kind: "cuid2", ...v.errToObj(e) });
|
|
2635
|
-
}
|
|
2636
|
-
ulid(e) {
|
|
2637
|
-
return this._addCheck({ kind: "ulid", ...v.errToObj(e) });
|
|
2638
|
-
}
|
|
2639
|
-
base64(e) {
|
|
2640
|
-
return this._addCheck({ kind: "base64", ...v.errToObj(e) });
|
|
2641
|
-
}
|
|
2642
|
-
ip(e) {
|
|
2643
|
-
return this._addCheck({ kind: "ip", ...v.errToObj(e) });
|
|
2644
|
-
}
|
|
2645
|
-
datetime(e) {
|
|
2646
|
-
var t, n;
|
|
2647
|
-
return typeof e == "string" ? this._addCheck({
|
|
2648
|
-
kind: "datetime",
|
|
2649
|
-
precision: null,
|
|
2650
|
-
offset: !1,
|
|
2651
|
-
local: !1,
|
|
2652
|
-
message: e
|
|
2653
|
-
}) : this._addCheck({
|
|
2654
|
-
kind: "datetime",
|
|
2655
|
-
precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
|
|
2656
|
-
offset: (t = e == null ? void 0 : e.offset) !== null && t !== void 0 ? t : !1,
|
|
2657
|
-
local: (n = e == null ? void 0 : e.local) !== null && n !== void 0 ? n : !1,
|
|
2658
|
-
...v.errToObj(e == null ? void 0 : e.message)
|
|
2659
|
-
});
|
|
2660
|
-
}
|
|
2661
|
-
date(e) {
|
|
2662
|
-
return this._addCheck({ kind: "date", message: e });
|
|
2663
|
-
}
|
|
2664
|
-
time(e) {
|
|
2665
|
-
return typeof e == "string" ? this._addCheck({
|
|
2666
|
-
kind: "time",
|
|
2667
|
-
precision: null,
|
|
2668
|
-
message: e
|
|
2669
|
-
}) : this._addCheck({
|
|
2670
|
-
kind: "time",
|
|
2671
|
-
precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
|
|
2672
|
-
...v.errToObj(e == null ? void 0 : e.message)
|
|
2673
|
-
});
|
|
2674
|
-
}
|
|
2675
|
-
duration(e) {
|
|
2676
|
-
return this._addCheck({ kind: "duration", ...v.errToObj(e) });
|
|
2677
|
-
}
|
|
2678
|
-
regex(e, t) {
|
|
2679
|
-
return this._addCheck({
|
|
2680
|
-
kind: "regex",
|
|
2681
|
-
regex: e,
|
|
2682
|
-
...v.errToObj(t)
|
|
2683
|
-
});
|
|
2684
|
-
}
|
|
2685
|
-
includes(e, t) {
|
|
2686
|
-
return this._addCheck({
|
|
2687
|
-
kind: "includes",
|
|
2688
|
-
value: e,
|
|
2689
|
-
position: t == null ? void 0 : t.position,
|
|
2690
|
-
...v.errToObj(t == null ? void 0 : t.message)
|
|
2691
|
-
});
|
|
2692
|
-
}
|
|
2693
|
-
startsWith(e, t) {
|
|
2694
|
-
return this._addCheck({
|
|
2695
|
-
kind: "startsWith",
|
|
2696
|
-
value: e,
|
|
2697
|
-
...v.errToObj(t)
|
|
2698
|
-
});
|
|
2699
|
-
}
|
|
2700
|
-
endsWith(e, t) {
|
|
2701
|
-
return this._addCheck({
|
|
2702
|
-
kind: "endsWith",
|
|
2703
|
-
value: e,
|
|
2704
|
-
...v.errToObj(t)
|
|
2705
|
-
});
|
|
2706
|
-
}
|
|
2707
|
-
min(e, t) {
|
|
2708
|
-
return this._addCheck({
|
|
2709
|
-
kind: "min",
|
|
2710
|
-
value: e,
|
|
2711
|
-
...v.errToObj(t)
|
|
2712
|
-
});
|
|
2713
|
-
}
|
|
2714
|
-
max(e, t) {
|
|
2715
|
-
return this._addCheck({
|
|
2716
|
-
kind: "max",
|
|
2717
|
-
value: e,
|
|
2718
|
-
...v.errToObj(t)
|
|
2719
|
-
});
|
|
2720
|
-
}
|
|
2721
|
-
length(e, t) {
|
|
2722
|
-
return this._addCheck({
|
|
2723
|
-
kind: "length",
|
|
2724
|
-
value: e,
|
|
2725
|
-
...v.errToObj(t)
|
|
2726
|
-
});
|
|
2727
|
-
}
|
|
2728
|
-
/**
|
|
2729
|
-
* @deprecated Use z.string().min(1) instead.
|
|
2730
|
-
* @see {@link ZodString.min}
|
|
2731
|
-
*/
|
|
2732
|
-
nonempty(e) {
|
|
2733
|
-
return this.min(1, v.errToObj(e));
|
|
2734
|
-
}
|
|
2735
|
-
trim() {
|
|
2736
|
-
return new B({
|
|
2737
|
-
...this._def,
|
|
2738
|
-
checks: [...this._def.checks, { kind: "trim" }]
|
|
2739
|
-
});
|
|
2740
|
-
}
|
|
2741
|
-
toLowerCase() {
|
|
2742
|
-
return new B({
|
|
2743
|
-
...this._def,
|
|
2744
|
-
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
2745
|
-
});
|
|
2746
|
-
}
|
|
2747
|
-
toUpperCase() {
|
|
2748
|
-
return new B({
|
|
2749
|
-
...this._def,
|
|
2750
|
-
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
2751
|
-
});
|
|
2752
|
-
}
|
|
2753
|
-
get isDatetime() {
|
|
2754
|
-
return !!this._def.checks.find((e) => e.kind === "datetime");
|
|
2755
|
-
}
|
|
2756
|
-
get isDate() {
|
|
2757
|
-
return !!this._def.checks.find((e) => e.kind === "date");
|
|
2758
|
-
}
|
|
2759
|
-
get isTime() {
|
|
2760
|
-
return !!this._def.checks.find((e) => e.kind === "time");
|
|
2761
|
-
}
|
|
2762
|
-
get isDuration() {
|
|
2763
|
-
return !!this._def.checks.find((e) => e.kind === "duration");
|
|
2764
|
-
}
|
|
2765
|
-
get isEmail() {
|
|
2766
|
-
return !!this._def.checks.find((e) => e.kind === "email");
|
|
2767
|
-
}
|
|
2768
|
-
get isURL() {
|
|
2769
|
-
return !!this._def.checks.find((e) => e.kind === "url");
|
|
2770
|
-
}
|
|
2771
|
-
get isEmoji() {
|
|
2772
|
-
return !!this._def.checks.find((e) => e.kind === "emoji");
|
|
2773
|
-
}
|
|
2774
|
-
get isUUID() {
|
|
2775
|
-
return !!this._def.checks.find((e) => e.kind === "uuid");
|
|
2776
|
-
}
|
|
2777
|
-
get isNANOID() {
|
|
2778
|
-
return !!this._def.checks.find((e) => e.kind === "nanoid");
|
|
2779
|
-
}
|
|
2780
|
-
get isCUID() {
|
|
2781
|
-
return !!this._def.checks.find((e) => e.kind === "cuid");
|
|
2782
|
-
}
|
|
2783
|
-
get isCUID2() {
|
|
2784
|
-
return !!this._def.checks.find((e) => e.kind === "cuid2");
|
|
2785
|
-
}
|
|
2786
|
-
get isULID() {
|
|
2787
|
-
return !!this._def.checks.find((e) => e.kind === "ulid");
|
|
2788
|
-
}
|
|
2789
|
-
get isIP() {
|
|
2790
|
-
return !!this._def.checks.find((e) => e.kind === "ip");
|
|
2791
|
-
}
|
|
2792
|
-
get isBase64() {
|
|
2793
|
-
return !!this._def.checks.find((e) => e.kind === "base64");
|
|
2794
|
-
}
|
|
2795
|
-
get minLength() {
|
|
2796
|
-
let e = null;
|
|
2797
|
-
for (const t of this._def.checks)
|
|
2798
|
-
t.kind === "min" && (e === null || t.value > e) && (e = t.value);
|
|
2799
|
-
return e;
|
|
2800
|
-
}
|
|
2801
|
-
get maxLength() {
|
|
2802
|
-
let e = null;
|
|
2803
|
-
for (const t of this._def.checks)
|
|
2804
|
-
t.kind === "max" && (e === null || t.value < e) && (e = t.value);
|
|
2805
|
-
return e;
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
B.create = (r) => {
|
|
2809
|
-
var e;
|
|
2810
|
-
return new B({
|
|
2811
|
-
checks: [],
|
|
2812
|
-
typeName: y.ZodString,
|
|
2813
|
-
coerce: (e = r == null ? void 0 : r.coerce) !== null && e !== void 0 ? e : !1,
|
|
2814
|
-
...w(r)
|
|
2815
|
-
});
|
|
2816
|
-
};
|
|
2817
|
-
function Wn(r, e) {
|
|
2818
|
-
const t = (r.toString().split(".")[1] || "").length, n = (e.toString().split(".")[1] || "").length, s = t > n ? t : n, a = parseInt(r.toFixed(s).replace(".", "")), i = parseInt(e.toFixed(s).replace(".", ""));
|
|
2819
|
-
return a % i / Math.pow(10, s);
|
|
2820
|
-
}
|
|
2821
|
-
class ie extends O {
|
|
2822
|
-
constructor() {
|
|
2823
|
-
super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
|
|
2824
|
-
}
|
|
2825
|
-
_parse(e) {
|
|
2826
|
-
if (this._def.coerce && (e.data = Number(e.data)), this._getType(e) !== g.number) {
|
|
2827
|
-
const a = this._getOrReturnCtx(e);
|
|
2828
|
-
return m(a, {
|
|
2829
|
-
code: l.invalid_type,
|
|
2830
|
-
expected: g.number,
|
|
2831
|
-
received: a.parsedType
|
|
2832
|
-
}), _;
|
|
2833
|
-
}
|
|
2834
|
-
let n;
|
|
2835
|
-
const s = new M();
|
|
2836
|
-
for (const a of this._def.checks)
|
|
2837
|
-
a.kind === "int" ? j.isInteger(e.data) || (n = this._getOrReturnCtx(e, n), m(n, {
|
|
2838
|
-
code: l.invalid_type,
|
|
2839
|
-
expected: "integer",
|
|
2840
|
-
received: "float",
|
|
2841
|
-
message: a.message
|
|
2842
|
-
}), s.dirty()) : a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (n = this._getOrReturnCtx(e, n), m(n, {
|
|
2843
|
-
code: l.too_small,
|
|
2844
|
-
minimum: a.value,
|
|
2845
|
-
type: "number",
|
|
2846
|
-
inclusive: a.inclusive,
|
|
2847
|
-
exact: !1,
|
|
2848
|
-
message: a.message
|
|
2849
|
-
}), s.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (n = this._getOrReturnCtx(e, n), m(n, {
|
|
2850
|
-
code: l.too_big,
|
|
2851
|
-
maximum: a.value,
|
|
2852
|
-
type: "number",
|
|
2853
|
-
inclusive: a.inclusive,
|
|
2854
|
-
exact: !1,
|
|
2855
|
-
message: a.message
|
|
2856
|
-
}), s.dirty()) : a.kind === "multipleOf" ? Wn(e.data, a.value) !== 0 && (n = this._getOrReturnCtx(e, n), m(n, {
|
|
2857
|
-
code: l.not_multiple_of,
|
|
2858
|
-
multipleOf: a.value,
|
|
2859
|
-
message: a.message
|
|
2860
|
-
}), s.dirty()) : a.kind === "finite" ? Number.isFinite(e.data) || (n = this._getOrReturnCtx(e, n), m(n, {
|
|
2861
|
-
code: l.not_finite,
|
|
2862
|
-
message: a.message
|
|
2863
|
-
}), s.dirty()) : j.assertNever(a);
|
|
2864
|
-
return { status: s.value, value: e.data };
|
|
2865
|
-
}
|
|
2866
|
-
gte(e, t) {
|
|
2867
|
-
return this.setLimit("min", e, !0, v.toString(t));
|
|
2868
|
-
}
|
|
2869
|
-
gt(e, t) {
|
|
2870
|
-
return this.setLimit("min", e, !1, v.toString(t));
|
|
2871
|
-
}
|
|
2872
|
-
lte(e, t) {
|
|
2873
|
-
return this.setLimit("max", e, !0, v.toString(t));
|
|
2874
|
-
}
|
|
2875
|
-
lt(e, t) {
|
|
2876
|
-
return this.setLimit("max", e, !1, v.toString(t));
|
|
2877
|
-
}
|
|
2878
|
-
setLimit(e, t, n, s) {
|
|
2879
|
-
return new ie({
|
|
2880
|
-
...this._def,
|
|
2881
|
-
checks: [
|
|
2882
|
-
...this._def.checks,
|
|
2883
|
-
{
|
|
2884
|
-
kind: e,
|
|
2885
|
-
value: t,
|
|
2886
|
-
inclusive: n,
|
|
2887
|
-
message: v.toString(s)
|
|
2888
|
-
}
|
|
2889
|
-
]
|
|
2890
|
-
});
|
|
2891
|
-
}
|
|
2892
|
-
_addCheck(e) {
|
|
2893
|
-
return new ie({
|
|
2894
|
-
...this._def,
|
|
2895
|
-
checks: [...this._def.checks, e]
|
|
2896
|
-
});
|
|
2897
|
-
}
|
|
2898
|
-
int(e) {
|
|
2899
|
-
return this._addCheck({
|
|
2900
|
-
kind: "int",
|
|
2901
|
-
message: v.toString(e)
|
|
2902
|
-
});
|
|
2903
|
-
}
|
|
2904
|
-
positive(e) {
|
|
2905
|
-
return this._addCheck({
|
|
2906
|
-
kind: "min",
|
|
2907
|
-
value: 0,
|
|
2908
|
-
inclusive: !1,
|
|
2909
|
-
message: v.toString(e)
|
|
2910
|
-
});
|
|
2911
|
-
}
|
|
2912
|
-
negative(e) {
|
|
2913
|
-
return this._addCheck({
|
|
2914
|
-
kind: "max",
|
|
2915
|
-
value: 0,
|
|
2916
|
-
inclusive: !1,
|
|
2917
|
-
message: v.toString(e)
|
|
2918
|
-
});
|
|
2919
|
-
}
|
|
2920
|
-
nonpositive(e) {
|
|
2921
|
-
return this._addCheck({
|
|
2922
|
-
kind: "max",
|
|
2923
|
-
value: 0,
|
|
2924
|
-
inclusive: !0,
|
|
2925
|
-
message: v.toString(e)
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2928
|
-
nonnegative(e) {
|
|
2929
|
-
return this._addCheck({
|
|
2930
|
-
kind: "min",
|
|
2931
|
-
value: 0,
|
|
2932
|
-
inclusive: !0,
|
|
2933
|
-
message: v.toString(e)
|
|
2934
|
-
});
|
|
2935
|
-
}
|
|
2936
|
-
multipleOf(e, t) {
|
|
2937
|
-
return this._addCheck({
|
|
2938
|
-
kind: "multipleOf",
|
|
2939
|
-
value: e,
|
|
2940
|
-
message: v.toString(t)
|
|
2941
|
-
});
|
|
2942
|
-
}
|
|
2943
|
-
finite(e) {
|
|
2944
|
-
return this._addCheck({
|
|
2945
|
-
kind: "finite",
|
|
2946
|
-
message: v.toString(e)
|
|
2947
|
-
});
|
|
2948
|
-
}
|
|
2949
|
-
safe(e) {
|
|
2950
|
-
return this._addCheck({
|
|
2951
|
-
kind: "min",
|
|
2952
|
-
inclusive: !0,
|
|
2953
|
-
value: Number.MIN_SAFE_INTEGER,
|
|
2954
|
-
message: v.toString(e)
|
|
2955
|
-
})._addCheck({
|
|
2956
|
-
kind: "max",
|
|
2957
|
-
inclusive: !0,
|
|
2958
|
-
value: Number.MAX_SAFE_INTEGER,
|
|
2959
|
-
message: v.toString(e)
|
|
2960
|
-
});
|
|
2961
|
-
}
|
|
2962
|
-
get minValue() {
|
|
2963
|
-
let e = null;
|
|
2964
|
-
for (const t of this._def.checks)
|
|
2965
|
-
t.kind === "min" && (e === null || t.value > e) && (e = t.value);
|
|
2966
|
-
return e;
|
|
2967
|
-
}
|
|
2968
|
-
get maxValue() {
|
|
2969
|
-
let e = null;
|
|
2970
|
-
for (const t of this._def.checks)
|
|
2971
|
-
t.kind === "max" && (e === null || t.value < e) && (e = t.value);
|
|
2972
|
-
return e;
|
|
2973
|
-
}
|
|
2974
|
-
get isInt() {
|
|
2975
|
-
return !!this._def.checks.find((e) => e.kind === "int" || e.kind === "multipleOf" && j.isInteger(e.value));
|
|
2976
|
-
}
|
|
2977
|
-
get isFinite() {
|
|
2978
|
-
let e = null, t = null;
|
|
2979
|
-
for (const n of this._def.checks) {
|
|
2980
|
-
if (n.kind === "finite" || n.kind === "int" || n.kind === "multipleOf")
|
|
2981
|
-
return !0;
|
|
2982
|
-
n.kind === "min" ? (t === null || n.value > t) && (t = n.value) : n.kind === "max" && (e === null || n.value < e) && (e = n.value);
|
|
2983
|
-
}
|
|
2984
|
-
return Number.isFinite(t) && Number.isFinite(e);
|
|
2985
|
-
}
|
|
2986
|
-
}
|
|
2987
|
-
ie.create = (r) => new ie({
|
|
2988
|
-
checks: [],
|
|
2989
|
-
typeName: y.ZodNumber,
|
|
2990
|
-
coerce: (r == null ? void 0 : r.coerce) || !1,
|
|
2991
|
-
...w(r)
|
|
2992
|
-
});
|
|
2993
|
-
class oe extends O {
|
|
2994
|
-
constructor() {
|
|
2995
|
-
super(...arguments), this.min = this.gte, this.max = this.lte;
|
|
2996
|
-
}
|
|
2997
|
-
_parse(e) {
|
|
2998
|
-
if (this._def.coerce && (e.data = BigInt(e.data)), this._getType(e) !== g.bigint) {
|
|
2999
|
-
const a = this._getOrReturnCtx(e);
|
|
3000
|
-
return m(a, {
|
|
3001
|
-
code: l.invalid_type,
|
|
3002
|
-
expected: g.bigint,
|
|
3003
|
-
received: a.parsedType
|
|
3004
|
-
}), _;
|
|
3005
|
-
}
|
|
3006
|
-
let n;
|
|
3007
|
-
const s = new M();
|
|
3008
|
-
for (const a of this._def.checks)
|
|
3009
|
-
a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (n = this._getOrReturnCtx(e, n), m(n, {
|
|
3010
|
-
code: l.too_small,
|
|
3011
|
-
type: "bigint",
|
|
3012
|
-
minimum: a.value,
|
|
3013
|
-
inclusive: a.inclusive,
|
|
3014
|
-
message: a.message
|
|
3015
|
-
}), s.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (n = this._getOrReturnCtx(e, n), m(n, {
|
|
3016
|
-
code: l.too_big,
|
|
3017
|
-
type: "bigint",
|
|
3018
|
-
maximum: a.value,
|
|
3019
|
-
inclusive: a.inclusive,
|
|
3020
|
-
message: a.message
|
|
3021
|
-
}), s.dirty()) : a.kind === "multipleOf" ? e.data % a.value !== BigInt(0) && (n = this._getOrReturnCtx(e, n), m(n, {
|
|
3022
|
-
code: l.not_multiple_of,
|
|
3023
|
-
multipleOf: a.value,
|
|
3024
|
-
message: a.message
|
|
3025
|
-
}), s.dirty()) : j.assertNever(a);
|
|
3026
|
-
return { status: s.value, value: e.data };
|
|
3027
|
-
}
|
|
3028
|
-
gte(e, t) {
|
|
3029
|
-
return this.setLimit("min", e, !0, v.toString(t));
|
|
3030
|
-
}
|
|
3031
|
-
gt(e, t) {
|
|
3032
|
-
return this.setLimit("min", e, !1, v.toString(t));
|
|
3033
|
-
}
|
|
3034
|
-
lte(e, t) {
|
|
3035
|
-
return this.setLimit("max", e, !0, v.toString(t));
|
|
3036
|
-
}
|
|
3037
|
-
lt(e, t) {
|
|
3038
|
-
return this.setLimit("max", e, !1, v.toString(t));
|
|
3039
|
-
}
|
|
3040
|
-
setLimit(e, t, n, s) {
|
|
3041
|
-
return new oe({
|
|
3042
|
-
...this._def,
|
|
3043
|
-
checks: [
|
|
3044
|
-
...this._def.checks,
|
|
3045
|
-
{
|
|
3046
|
-
kind: e,
|
|
3047
|
-
value: t,
|
|
3048
|
-
inclusive: n,
|
|
3049
|
-
message: v.toString(s)
|
|
3050
|
-
}
|
|
3051
|
-
]
|
|
3052
|
-
});
|
|
3053
|
-
}
|
|
3054
|
-
_addCheck(e) {
|
|
3055
|
-
return new oe({
|
|
3056
|
-
...this._def,
|
|
3057
|
-
checks: [...this._def.checks, e]
|
|
3058
|
-
});
|
|
3059
|
-
}
|
|
3060
|
-
positive(e) {
|
|
3061
|
-
return this._addCheck({
|
|
3062
|
-
kind: "min",
|
|
3063
|
-
value: BigInt(0),
|
|
3064
|
-
inclusive: !1,
|
|
3065
|
-
message: v.toString(e)
|
|
3066
|
-
});
|
|
3067
|
-
}
|
|
3068
|
-
negative(e) {
|
|
3069
|
-
return this._addCheck({
|
|
3070
|
-
kind: "max",
|
|
3071
|
-
value: BigInt(0),
|
|
3072
|
-
inclusive: !1,
|
|
3073
|
-
message: v.toString(e)
|
|
3074
|
-
});
|
|
3075
|
-
}
|
|
3076
|
-
nonpositive(e) {
|
|
3077
|
-
return this._addCheck({
|
|
3078
|
-
kind: "max",
|
|
3079
|
-
value: BigInt(0),
|
|
3080
|
-
inclusive: !0,
|
|
3081
|
-
message: v.toString(e)
|
|
3082
|
-
});
|
|
3083
|
-
}
|
|
3084
|
-
nonnegative(e) {
|
|
3085
|
-
return this._addCheck({
|
|
3086
|
-
kind: "min",
|
|
3087
|
-
value: BigInt(0),
|
|
3088
|
-
inclusive: !0,
|
|
3089
|
-
message: v.toString(e)
|
|
3090
|
-
});
|
|
3091
|
-
}
|
|
3092
|
-
multipleOf(e, t) {
|
|
3093
|
-
return this._addCheck({
|
|
3094
|
-
kind: "multipleOf",
|
|
3095
|
-
value: e,
|
|
3096
|
-
message: v.toString(t)
|
|
3097
|
-
});
|
|
3098
|
-
}
|
|
3099
|
-
get minValue() {
|
|
3100
|
-
let e = null;
|
|
3101
|
-
for (const t of this._def.checks)
|
|
3102
|
-
t.kind === "min" && (e === null || t.value > e) && (e = t.value);
|
|
3103
|
-
return e;
|
|
3104
|
-
}
|
|
3105
|
-
get maxValue() {
|
|
3106
|
-
let e = null;
|
|
3107
|
-
for (const t of this._def.checks)
|
|
3108
|
-
t.kind === "max" && (e === null || t.value < e) && (e = t.value);
|
|
3109
|
-
return e;
|
|
3110
|
-
}
|
|
3111
|
-
}
|
|
3112
|
-
oe.create = (r) => {
|
|
3113
|
-
var e;
|
|
3114
|
-
return new oe({
|
|
3115
|
-
checks: [],
|
|
3116
|
-
typeName: y.ZodBigInt,
|
|
3117
|
-
coerce: (e = r == null ? void 0 : r.coerce) !== null && e !== void 0 ? e : !1,
|
|
3118
|
-
...w(r)
|
|
3119
|
-
});
|
|
3120
|
-
};
|
|
3121
|
-
class qe extends O {
|
|
3122
|
-
_parse(e) {
|
|
3123
|
-
if (this._def.coerce && (e.data = !!e.data), this._getType(e) !== g.boolean) {
|
|
3124
|
-
const n = this._getOrReturnCtx(e);
|
|
3125
|
-
return m(n, {
|
|
3126
|
-
code: l.invalid_type,
|
|
3127
|
-
expected: g.boolean,
|
|
3128
|
-
received: n.parsedType
|
|
3129
|
-
}), _;
|
|
3130
|
-
}
|
|
3131
|
-
return $(e.data);
|
|
3132
|
-
}
|
|
3133
|
-
}
|
|
3134
|
-
qe.create = (r) => new qe({
|
|
3135
|
-
typeName: y.ZodBoolean,
|
|
3136
|
-
coerce: (r == null ? void 0 : r.coerce) || !1,
|
|
3137
|
-
...w(r)
|
|
3138
|
-
});
|
|
3139
|
-
class pe extends O {
|
|
3140
|
-
_parse(e) {
|
|
3141
|
-
if (this._def.coerce && (e.data = new Date(e.data)), this._getType(e) !== g.date) {
|
|
3142
|
-
const a = this._getOrReturnCtx(e);
|
|
3143
|
-
return m(a, {
|
|
3144
|
-
code: l.invalid_type,
|
|
3145
|
-
expected: g.date,
|
|
3146
|
-
received: a.parsedType
|
|
3147
|
-
}), _;
|
|
3148
|
-
}
|
|
3149
|
-
if (isNaN(e.data.getTime())) {
|
|
3150
|
-
const a = this._getOrReturnCtx(e);
|
|
3151
|
-
return m(a, {
|
|
3152
|
-
code: l.invalid_date
|
|
3153
|
-
}), _;
|
|
3154
|
-
}
|
|
3155
|
-
const n = new M();
|
|
3156
|
-
let s;
|
|
3157
|
-
for (const a of this._def.checks)
|
|
3158
|
-
a.kind === "min" ? e.data.getTime() < a.value && (s = this._getOrReturnCtx(e, s), m(s, {
|
|
3159
|
-
code: l.too_small,
|
|
3160
|
-
message: a.message,
|
|
3161
|
-
inclusive: !0,
|
|
3162
|
-
exact: !1,
|
|
3163
|
-
minimum: a.value,
|
|
3164
|
-
type: "date"
|
|
3165
|
-
}), n.dirty()) : a.kind === "max" ? e.data.getTime() > a.value && (s = this._getOrReturnCtx(e, s), m(s, {
|
|
3166
|
-
code: l.too_big,
|
|
3167
|
-
message: a.message,
|
|
3168
|
-
inclusive: !0,
|
|
3169
|
-
exact: !1,
|
|
3170
|
-
maximum: a.value,
|
|
3171
|
-
type: "date"
|
|
3172
|
-
}), n.dirty()) : j.assertNever(a);
|
|
3173
|
-
return {
|
|
3174
|
-
status: n.value,
|
|
3175
|
-
value: new Date(e.data.getTime())
|
|
3176
|
-
};
|
|
3177
|
-
}
|
|
3178
|
-
_addCheck(e) {
|
|
3179
|
-
return new pe({
|
|
3180
|
-
...this._def,
|
|
3181
|
-
checks: [...this._def.checks, e]
|
|
3182
|
-
});
|
|
3183
|
-
}
|
|
3184
|
-
min(e, t) {
|
|
3185
|
-
return this._addCheck({
|
|
3186
|
-
kind: "min",
|
|
3187
|
-
value: e.getTime(),
|
|
3188
|
-
message: v.toString(t)
|
|
3189
|
-
});
|
|
3190
|
-
}
|
|
3191
|
-
max(e, t) {
|
|
3192
|
-
return this._addCheck({
|
|
3193
|
-
kind: "max",
|
|
3194
|
-
value: e.getTime(),
|
|
3195
|
-
message: v.toString(t)
|
|
3196
|
-
});
|
|
3197
|
-
}
|
|
3198
|
-
get minDate() {
|
|
3199
|
-
let e = null;
|
|
3200
|
-
for (const t of this._def.checks)
|
|
3201
|
-
t.kind === "min" && (e === null || t.value > e) && (e = t.value);
|
|
3202
|
-
return e != null ? new Date(e) : null;
|
|
3203
|
-
}
|
|
3204
|
-
get maxDate() {
|
|
3205
|
-
let e = null;
|
|
3206
|
-
for (const t of this._def.checks)
|
|
3207
|
-
t.kind === "max" && (e === null || t.value < e) && (e = t.value);
|
|
3208
|
-
return e != null ? new Date(e) : null;
|
|
3209
|
-
}
|
|
3210
|
-
}
|
|
3211
|
-
pe.create = (r) => new pe({
|
|
3212
|
-
checks: [],
|
|
3213
|
-
coerce: (r == null ? void 0 : r.coerce) || !1,
|
|
3214
|
-
typeName: y.ZodDate,
|
|
3215
|
-
...w(r)
|
|
3216
|
-
});
|
|
3217
|
-
class vt extends O {
|
|
3218
|
-
_parse(e) {
|
|
3219
|
-
if (this._getType(e) !== g.symbol) {
|
|
3220
|
-
const n = this._getOrReturnCtx(e);
|
|
3221
|
-
return m(n, {
|
|
3222
|
-
code: l.invalid_type,
|
|
3223
|
-
expected: g.symbol,
|
|
3224
|
-
received: n.parsedType
|
|
3225
|
-
}), _;
|
|
3226
|
-
}
|
|
3227
|
-
return $(e.data);
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
vt.create = (r) => new vt({
|
|
3231
|
-
typeName: y.ZodSymbol,
|
|
3232
|
-
...w(r)
|
|
3233
|
-
});
|
|
3234
|
-
class Be extends O {
|
|
3235
|
-
_parse(e) {
|
|
3236
|
-
if (this._getType(e) !== g.undefined) {
|
|
3237
|
-
const n = this._getOrReturnCtx(e);
|
|
3238
|
-
return m(n, {
|
|
3239
|
-
code: l.invalid_type,
|
|
3240
|
-
expected: g.undefined,
|
|
3241
|
-
received: n.parsedType
|
|
3242
|
-
}), _;
|
|
3243
|
-
}
|
|
3244
|
-
return $(e.data);
|
|
3245
|
-
}
|
|
3246
|
-
}
|
|
3247
|
-
Be.create = (r) => new Be({
|
|
3248
|
-
typeName: y.ZodUndefined,
|
|
3249
|
-
...w(r)
|
|
3250
|
-
});
|
|
3251
|
-
class We extends O {
|
|
3252
|
-
_parse(e) {
|
|
3253
|
-
if (this._getType(e) !== g.null) {
|
|
3254
|
-
const n = this._getOrReturnCtx(e);
|
|
3255
|
-
return m(n, {
|
|
3256
|
-
code: l.invalid_type,
|
|
3257
|
-
expected: g.null,
|
|
3258
|
-
received: n.parsedType
|
|
3259
|
-
}), _;
|
|
3260
|
-
}
|
|
3261
|
-
return $(e.data);
|
|
3262
|
-
}
|
|
3263
|
-
}
|
|
3264
|
-
We.create = (r) => new We({
|
|
3265
|
-
typeName: y.ZodNull,
|
|
3266
|
-
...w(r)
|
|
3267
|
-
});
|
|
3268
|
-
class Ee extends O {
|
|
3269
|
-
constructor() {
|
|
3270
|
-
super(...arguments), this._any = !0;
|
|
3271
|
-
}
|
|
3272
|
-
_parse(e) {
|
|
3273
|
-
return $(e.data);
|
|
3274
|
-
}
|
|
3275
|
-
}
|
|
3276
|
-
Ee.create = (r) => new Ee({
|
|
3277
|
-
typeName: y.ZodAny,
|
|
3278
|
-
...w(r)
|
|
3279
|
-
});
|
|
3280
|
-
class he extends O {
|
|
3281
|
-
constructor() {
|
|
3282
|
-
super(...arguments), this._unknown = !0;
|
|
3283
|
-
}
|
|
3284
|
-
_parse(e) {
|
|
3285
|
-
return $(e.data);
|
|
3286
|
-
}
|
|
3287
|
-
}
|
|
3288
|
-
he.create = (r) => new he({
|
|
3289
|
-
typeName: y.ZodUnknown,
|
|
3290
|
-
...w(r)
|
|
3291
|
-
});
|
|
3292
|
-
class re extends O {
|
|
3293
|
-
_parse(e) {
|
|
3294
|
-
const t = this._getOrReturnCtx(e);
|
|
3295
|
-
return m(t, {
|
|
3296
|
-
code: l.invalid_type,
|
|
3297
|
-
expected: g.never,
|
|
3298
|
-
received: t.parsedType
|
|
3299
|
-
}), _;
|
|
3300
|
-
}
|
|
3301
|
-
}
|
|
3302
|
-
re.create = (r) => new re({
|
|
3303
|
-
typeName: y.ZodNever,
|
|
3304
|
-
...w(r)
|
|
3305
|
-
});
|
|
3306
|
-
class yt extends O {
|
|
3307
|
-
_parse(e) {
|
|
3308
|
-
if (this._getType(e) !== g.undefined) {
|
|
3309
|
-
const n = this._getOrReturnCtx(e);
|
|
3310
|
-
return m(n, {
|
|
3311
|
-
code: l.invalid_type,
|
|
3312
|
-
expected: g.void,
|
|
3313
|
-
received: n.parsedType
|
|
3314
|
-
}), _;
|
|
3315
|
-
}
|
|
3316
|
-
return $(e.data);
|
|
3317
|
-
}
|
|
3318
|
-
}
|
|
3319
|
-
yt.create = (r) => new yt({
|
|
3320
|
-
typeName: y.ZodVoid,
|
|
3321
|
-
...w(r)
|
|
3322
|
-
});
|
|
3323
|
-
class W extends O {
|
|
3324
|
-
_parse(e) {
|
|
3325
|
-
const { ctx: t, status: n } = this._processInputParams(e), s = this._def;
|
|
3326
|
-
if (t.parsedType !== g.array)
|
|
3327
|
-
return m(t, {
|
|
3328
|
-
code: l.invalid_type,
|
|
3329
|
-
expected: g.array,
|
|
3330
|
-
received: t.parsedType
|
|
3331
|
-
}), _;
|
|
3332
|
-
if (s.exactLength !== null) {
|
|
3333
|
-
const i = t.data.length > s.exactLength.value, o = t.data.length < s.exactLength.value;
|
|
3334
|
-
(i || o) && (m(t, {
|
|
3335
|
-
code: i ? l.too_big : l.too_small,
|
|
3336
|
-
minimum: o ? s.exactLength.value : void 0,
|
|
3337
|
-
maximum: i ? s.exactLength.value : void 0,
|
|
3338
|
-
type: "array",
|
|
3339
|
-
inclusive: !0,
|
|
3340
|
-
exact: !0,
|
|
3341
|
-
message: s.exactLength.message
|
|
3342
|
-
}), n.dirty());
|
|
3343
|
-
}
|
|
3344
|
-
if (s.minLength !== null && t.data.length < s.minLength.value && (m(t, {
|
|
3345
|
-
code: l.too_small,
|
|
3346
|
-
minimum: s.minLength.value,
|
|
3347
|
-
type: "array",
|
|
3348
|
-
inclusive: !0,
|
|
3349
|
-
exact: !1,
|
|
3350
|
-
message: s.minLength.message
|
|
3351
|
-
}), n.dirty()), s.maxLength !== null && t.data.length > s.maxLength.value && (m(t, {
|
|
3352
|
-
code: l.too_big,
|
|
3353
|
-
maximum: s.maxLength.value,
|
|
3354
|
-
type: "array",
|
|
3355
|
-
inclusive: !0,
|
|
3356
|
-
exact: !1,
|
|
3357
|
-
message: s.maxLength.message
|
|
3358
|
-
}), n.dirty()), t.common.async)
|
|
3359
|
-
return Promise.all([...t.data].map((i, o) => s.type._parseAsync(new Y(t, i, t.path, o)))).then((i) => M.mergeArray(n, i));
|
|
3360
|
-
const a = [...t.data].map((i, o) => s.type._parseSync(new Y(t, i, t.path, o)));
|
|
3361
|
-
return M.mergeArray(n, a);
|
|
3362
|
-
}
|
|
3363
|
-
get element() {
|
|
3364
|
-
return this._def.type;
|
|
3365
|
-
}
|
|
3366
|
-
min(e, t) {
|
|
3367
|
-
return new W({
|
|
3368
|
-
...this._def,
|
|
3369
|
-
minLength: { value: e, message: v.toString(t) }
|
|
3370
|
-
});
|
|
3371
|
-
}
|
|
3372
|
-
max(e, t) {
|
|
3373
|
-
return new W({
|
|
3374
|
-
...this._def,
|
|
3375
|
-
maxLength: { value: e, message: v.toString(t) }
|
|
3376
|
-
});
|
|
3377
|
-
}
|
|
3378
|
-
length(e, t) {
|
|
3379
|
-
return new W({
|
|
3380
|
-
...this._def,
|
|
3381
|
-
exactLength: { value: e, message: v.toString(t) }
|
|
3382
|
-
});
|
|
3383
|
-
}
|
|
3384
|
-
nonempty(e) {
|
|
3385
|
-
return this.min(1, e);
|
|
3386
|
-
}
|
|
3387
|
-
}
|
|
3388
|
-
W.create = (r, e) => new W({
|
|
3389
|
-
type: r,
|
|
3390
|
-
minLength: null,
|
|
3391
|
-
maxLength: null,
|
|
3392
|
-
exactLength: null,
|
|
3393
|
-
typeName: y.ZodArray,
|
|
3394
|
-
...w(e)
|
|
3395
|
-
});
|
|
3396
|
-
function be(r) {
|
|
3397
|
-
if (r instanceof C) {
|
|
3398
|
-
const e = {};
|
|
3399
|
-
for (const t in r.shape) {
|
|
3400
|
-
const n = r.shape[t];
|
|
3401
|
-
e[t] = J.create(be(n));
|
|
3402
|
-
}
|
|
3403
|
-
return new C({
|
|
3404
|
-
...r._def,
|
|
3405
|
-
shape: () => e
|
|
3406
|
-
});
|
|
3407
|
-
} else return r instanceof W ? new W({
|
|
3408
|
-
...r._def,
|
|
3409
|
-
type: be(r.element)
|
|
3410
|
-
}) : r instanceof J ? J.create(be(r.unwrap())) : r instanceof ue ? ue.create(be(r.unwrap())) : r instanceof X ? X.create(r.items.map((e) => be(e))) : r;
|
|
3411
|
-
}
|
|
3412
|
-
class C extends O {
|
|
3413
|
-
constructor() {
|
|
3414
|
-
super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
|
|
3415
|
-
}
|
|
3416
|
-
_getCached() {
|
|
3417
|
-
if (this._cached !== null)
|
|
3418
|
-
return this._cached;
|
|
3419
|
-
const e = this._def.shape(), t = j.objectKeys(e);
|
|
3420
|
-
return this._cached = { shape: e, keys: t };
|
|
3421
|
-
}
|
|
3422
|
-
_parse(e) {
|
|
3423
|
-
if (this._getType(e) !== g.object) {
|
|
3424
|
-
const u = this._getOrReturnCtx(e);
|
|
3425
|
-
return m(u, {
|
|
3426
|
-
code: l.invalid_type,
|
|
3427
|
-
expected: g.object,
|
|
3428
|
-
received: u.parsedType
|
|
3429
|
-
}), _;
|
|
3430
|
-
}
|
|
3431
|
-
const { status: n, ctx: s } = this._processInputParams(e), { shape: a, keys: i } = this._getCached(), o = [];
|
|
3432
|
-
if (!(this._def.catchall instanceof re && this._def.unknownKeys === "strip"))
|
|
3433
|
-
for (const u in s.data)
|
|
3434
|
-
i.includes(u) || o.push(u);
|
|
3435
|
-
const c = [];
|
|
3436
|
-
for (const u of i) {
|
|
3437
|
-
const d = a[u], f = s.data[u];
|
|
3438
|
-
c.push({
|
|
3439
|
-
key: { status: "valid", value: u },
|
|
3440
|
-
value: d._parse(new Y(s, f, s.path, u)),
|
|
3441
|
-
alwaysSet: u in s.data
|
|
3442
|
-
});
|
|
3443
|
-
}
|
|
3444
|
-
if (this._def.catchall instanceof re) {
|
|
3445
|
-
const u = this._def.unknownKeys;
|
|
3446
|
-
if (u === "passthrough")
|
|
3447
|
-
for (const d of o)
|
|
3448
|
-
c.push({
|
|
3449
|
-
key: { status: "valid", value: d },
|
|
3450
|
-
value: { status: "valid", value: s.data[d] }
|
|
3451
|
-
});
|
|
3452
|
-
else if (u === "strict")
|
|
3453
|
-
o.length > 0 && (m(s, {
|
|
3454
|
-
code: l.unrecognized_keys,
|
|
3455
|
-
keys: o
|
|
3456
|
-
}), n.dirty());
|
|
3457
|
-
else if (u !== "strip") throw new Error("Internal ZodObject error: invalid unknownKeys value.");
|
|
3458
|
-
} else {
|
|
3459
|
-
const u = this._def.catchall;
|
|
3460
|
-
for (const d of o) {
|
|
3461
|
-
const f = s.data[d];
|
|
3462
|
-
c.push({
|
|
3463
|
-
key: { status: "valid", value: d },
|
|
3464
|
-
value: u._parse(
|
|
3465
|
-
new Y(s, f, s.path, d)
|
|
3466
|
-
//, ctx.child(key), value, getParsedType(value)
|
|
3467
|
-
),
|
|
3468
|
-
alwaysSet: d in s.data
|
|
3469
|
-
});
|
|
3470
|
-
}
|
|
3471
|
-
}
|
|
3472
|
-
return s.common.async ? Promise.resolve().then(async () => {
|
|
3473
|
-
const u = [];
|
|
3474
|
-
for (const d of c) {
|
|
3475
|
-
const f = await d.key, k = await d.value;
|
|
3476
|
-
u.push({
|
|
3477
|
-
key: f,
|
|
3478
|
-
value: k,
|
|
3479
|
-
alwaysSet: d.alwaysSet
|
|
3480
|
-
});
|
|
3481
|
-
}
|
|
3482
|
-
return u;
|
|
3483
|
-
}).then((u) => M.mergeObjectSync(n, u)) : M.mergeObjectSync(n, c);
|
|
3484
|
-
}
|
|
3485
|
-
get shape() {
|
|
3486
|
-
return this._def.shape();
|
|
3487
|
-
}
|
|
3488
|
-
strict(e) {
|
|
3489
|
-
return v.errToObj, new C({
|
|
3490
|
-
...this._def,
|
|
3491
|
-
unknownKeys: "strict",
|
|
3492
|
-
...e !== void 0 ? {
|
|
3493
|
-
errorMap: (t, n) => {
|
|
3494
|
-
var s, a, i, o;
|
|
3495
|
-
const c = (i = (a = (s = this._def).errorMap) === null || a === void 0 ? void 0 : a.call(s, t, n).message) !== null && i !== void 0 ? i : n.defaultError;
|
|
3496
|
-
return t.code === "unrecognized_keys" ? {
|
|
3497
|
-
message: (o = v.errToObj(e).message) !== null && o !== void 0 ? o : c
|
|
3498
|
-
} : {
|
|
3499
|
-
message: c
|
|
3500
|
-
};
|
|
3501
|
-
}
|
|
3502
|
-
} : {}
|
|
3503
|
-
});
|
|
3504
|
-
}
|
|
3505
|
-
strip() {
|
|
3506
|
-
return new C({
|
|
3507
|
-
...this._def,
|
|
3508
|
-
unknownKeys: "strip"
|
|
3509
|
-
});
|
|
3510
|
-
}
|
|
3511
|
-
passthrough() {
|
|
3512
|
-
return new C({
|
|
3513
|
-
...this._def,
|
|
3514
|
-
unknownKeys: "passthrough"
|
|
3515
|
-
});
|
|
3516
|
-
}
|
|
3517
|
-
// const AugmentFactory =
|
|
3518
|
-
// <Def extends ZodObjectDef>(def: Def) =>
|
|
3519
|
-
// <Augmentation extends ZodRawShape>(
|
|
3520
|
-
// augmentation: Augmentation
|
|
3521
|
-
// ): ZodObject<
|
|
3522
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
3523
|
-
// Def["unknownKeys"],
|
|
3524
|
-
// Def["catchall"]
|
|
3525
|
-
// > => {
|
|
3526
|
-
// return new ZodObject({
|
|
3527
|
-
// ...def,
|
|
3528
|
-
// shape: () => ({
|
|
3529
|
-
// ...def.shape(),
|
|
3530
|
-
// ...augmentation,
|
|
3531
|
-
// }),
|
|
3532
|
-
// }) as any;
|
|
3533
|
-
// };
|
|
3534
|
-
extend(e) {
|
|
3535
|
-
return new C({
|
|
3536
|
-
...this._def,
|
|
3537
|
-
shape: () => ({
|
|
3538
|
-
...this._def.shape(),
|
|
3539
|
-
...e
|
|
3540
|
-
})
|
|
3541
|
-
});
|
|
3542
|
-
}
|
|
3543
|
-
/**
|
|
3544
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
3545
|
-
* inferred type of merged objects. Please
|
|
3546
|
-
* upgrade if you are experiencing issues.
|
|
3547
|
-
*/
|
|
3548
|
-
merge(e) {
|
|
3549
|
-
return new C({
|
|
3550
|
-
unknownKeys: e._def.unknownKeys,
|
|
3551
|
-
catchall: e._def.catchall,
|
|
3552
|
-
shape: () => ({
|
|
3553
|
-
...this._def.shape(),
|
|
3554
|
-
...e._def.shape()
|
|
3555
|
-
}),
|
|
3556
|
-
typeName: y.ZodObject
|
|
3557
|
-
});
|
|
3558
|
-
}
|
|
3559
|
-
// merge<
|
|
3560
|
-
// Incoming extends AnyZodObject,
|
|
3561
|
-
// Augmentation extends Incoming["shape"],
|
|
3562
|
-
// NewOutput extends {
|
|
3563
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
3564
|
-
// ? Augmentation[k]["_output"]
|
|
3565
|
-
// : k extends keyof Output
|
|
3566
|
-
// ? Output[k]
|
|
3567
|
-
// : never;
|
|
3568
|
-
// },
|
|
3569
|
-
// NewInput extends {
|
|
3570
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
3571
|
-
// ? Augmentation[k]["_input"]
|
|
3572
|
-
// : k extends keyof Input
|
|
3573
|
-
// ? Input[k]
|
|
3574
|
-
// : never;
|
|
3575
|
-
// }
|
|
3576
|
-
// >(
|
|
3577
|
-
// merging: Incoming
|
|
3578
|
-
// ): ZodObject<
|
|
3579
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
3580
|
-
// Incoming["_def"]["unknownKeys"],
|
|
3581
|
-
// Incoming["_def"]["catchall"],
|
|
3582
|
-
// NewOutput,
|
|
3583
|
-
// NewInput
|
|
3584
|
-
// > {
|
|
3585
|
-
// const merged: any = new ZodObject({
|
|
3586
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
3587
|
-
// catchall: merging._def.catchall,
|
|
3588
|
-
// shape: () =>
|
|
3589
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
3590
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3591
|
-
// }) as any;
|
|
3592
|
-
// return merged;
|
|
3593
|
-
// }
|
|
3594
|
-
setKey(e, t) {
|
|
3595
|
-
return this.augment({ [e]: t });
|
|
3596
|
-
}
|
|
3597
|
-
// merge<Incoming extends AnyZodObject>(
|
|
3598
|
-
// merging: Incoming
|
|
3599
|
-
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
3600
|
-
// ZodObject<
|
|
3601
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
3602
|
-
// Incoming["_def"]["unknownKeys"],
|
|
3603
|
-
// Incoming["_def"]["catchall"]
|
|
3604
|
-
// > {
|
|
3605
|
-
// // const mergedShape = objectUtil.mergeShapes(
|
|
3606
|
-
// // this._def.shape(),
|
|
3607
|
-
// // merging._def.shape()
|
|
3608
|
-
// // );
|
|
3609
|
-
// const merged: any = new ZodObject({
|
|
3610
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
3611
|
-
// catchall: merging._def.catchall,
|
|
3612
|
-
// shape: () =>
|
|
3613
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
3614
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3615
|
-
// }) as any;
|
|
3616
|
-
// return merged;
|
|
3617
|
-
// }
|
|
3618
|
-
catchall(e) {
|
|
3619
|
-
return new C({
|
|
3620
|
-
...this._def,
|
|
3621
|
-
catchall: e
|
|
3622
|
-
});
|
|
3623
|
-
}
|
|
3624
|
-
pick(e) {
|
|
3625
|
-
const t = {};
|
|
3626
|
-
return j.objectKeys(e).forEach((n) => {
|
|
3627
|
-
e[n] && this.shape[n] && (t[n] = this.shape[n]);
|
|
3628
|
-
}), new C({
|
|
3629
|
-
...this._def,
|
|
3630
|
-
shape: () => t
|
|
3631
|
-
});
|
|
3632
|
-
}
|
|
3633
|
-
omit(e) {
|
|
3634
|
-
const t = {};
|
|
3635
|
-
return j.objectKeys(this.shape).forEach((n) => {
|
|
3636
|
-
e[n] || (t[n] = this.shape[n]);
|
|
3637
|
-
}), new C({
|
|
3638
|
-
...this._def,
|
|
3639
|
-
shape: () => t
|
|
3640
|
-
});
|
|
3641
|
-
}
|
|
3642
|
-
/**
|
|
3643
|
-
* @deprecated
|
|
3644
|
-
*/
|
|
3645
|
-
deepPartial() {
|
|
3646
|
-
return be(this);
|
|
3647
|
-
}
|
|
3648
|
-
partial(e) {
|
|
3649
|
-
const t = {};
|
|
3650
|
-
return j.objectKeys(this.shape).forEach((n) => {
|
|
3651
|
-
const s = this.shape[n];
|
|
3652
|
-
e && !e[n] ? t[n] = s : t[n] = s.optional();
|
|
3653
|
-
}), new C({
|
|
3654
|
-
...this._def,
|
|
3655
|
-
shape: () => t
|
|
3656
|
-
});
|
|
3657
|
-
}
|
|
3658
|
-
required(e) {
|
|
3659
|
-
const t = {};
|
|
3660
|
-
return j.objectKeys(this.shape).forEach((n) => {
|
|
3661
|
-
if (e && !e[n])
|
|
3662
|
-
t[n] = this.shape[n];
|
|
3663
|
-
else {
|
|
3664
|
-
let a = this.shape[n];
|
|
3665
|
-
for (; a instanceof J; )
|
|
3666
|
-
a = a._def.innerType;
|
|
3667
|
-
t[n] = a;
|
|
3668
|
-
}
|
|
3669
|
-
}), new C({
|
|
3670
|
-
...this._def,
|
|
3671
|
-
shape: () => t
|
|
3672
|
-
});
|
|
3673
|
-
}
|
|
3674
|
-
keyof() {
|
|
3675
|
-
return hr(j.objectKeys(this.shape));
|
|
3676
|
-
}
|
|
3677
|
-
}
|
|
3678
|
-
C.create = (r, e) => new C({
|
|
3679
|
-
shape: () => r,
|
|
3680
|
-
unknownKeys: "strip",
|
|
3681
|
-
catchall: re.create(),
|
|
3682
|
-
typeName: y.ZodObject,
|
|
3683
|
-
...w(e)
|
|
3684
|
-
});
|
|
3685
|
-
C.strictCreate = (r, e) => new C({
|
|
3686
|
-
shape: () => r,
|
|
3687
|
-
unknownKeys: "strict",
|
|
3688
|
-
catchall: re.create(),
|
|
3689
|
-
typeName: y.ZodObject,
|
|
3690
|
-
...w(e)
|
|
3691
|
-
});
|
|
3692
|
-
C.lazycreate = (r, e) => new C({
|
|
3693
|
-
shape: r,
|
|
3694
|
-
unknownKeys: "strip",
|
|
3695
|
-
catchall: re.create(),
|
|
3696
|
-
typeName: y.ZodObject,
|
|
3697
|
-
...w(e)
|
|
3698
|
-
});
|
|
3699
|
-
class Fe extends O {
|
|
3700
|
-
_parse(e) {
|
|
3701
|
-
const { ctx: t } = this._processInputParams(e), n = this._def.options;
|
|
3702
|
-
function s(a) {
|
|
3703
|
-
for (const o of a)
|
|
3704
|
-
if (o.result.status === "valid")
|
|
3705
|
-
return o.result;
|
|
3706
|
-
for (const o of a)
|
|
3707
|
-
if (o.result.status === "dirty")
|
|
3708
|
-
return t.common.issues.push(...o.ctx.common.issues), o.result;
|
|
3709
|
-
const i = a.map((o) => new L(o.ctx.common.issues));
|
|
3710
|
-
return m(t, {
|
|
3711
|
-
code: l.invalid_union,
|
|
3712
|
-
unionErrors: i
|
|
3713
|
-
}), _;
|
|
3714
|
-
}
|
|
3715
|
-
if (t.common.async)
|
|
3716
|
-
return Promise.all(n.map(async (a) => {
|
|
3717
|
-
const i = {
|
|
3718
|
-
...t,
|
|
3719
|
-
common: {
|
|
3720
|
-
...t.common,
|
|
3721
|
-
issues: []
|
|
3722
|
-
},
|
|
3723
|
-
parent: null
|
|
3724
|
-
};
|
|
3725
|
-
return {
|
|
3726
|
-
result: await a._parseAsync({
|
|
3727
|
-
data: t.data,
|
|
3728
|
-
path: t.path,
|
|
3729
|
-
parent: i
|
|
3730
|
-
}),
|
|
3731
|
-
ctx: i
|
|
3732
|
-
};
|
|
3733
|
-
})).then(s);
|
|
3734
|
-
{
|
|
3735
|
-
let a;
|
|
3736
|
-
const i = [];
|
|
3737
|
-
for (const c of n) {
|
|
3738
|
-
const u = {
|
|
3739
|
-
...t,
|
|
3740
|
-
common: {
|
|
3741
|
-
...t.common,
|
|
3742
|
-
issues: []
|
|
3743
|
-
},
|
|
3744
|
-
parent: null
|
|
3745
|
-
}, d = c._parseSync({
|
|
3746
|
-
data: t.data,
|
|
3747
|
-
path: t.path,
|
|
3748
|
-
parent: u
|
|
3749
|
-
});
|
|
3750
|
-
if (d.status === "valid")
|
|
3751
|
-
return d;
|
|
3752
|
-
d.status === "dirty" && !a && (a = { result: d, ctx: u }), u.common.issues.length && i.push(u.common.issues);
|
|
3753
|
-
}
|
|
3754
|
-
if (a)
|
|
3755
|
-
return t.common.issues.push(...a.ctx.common.issues), a.result;
|
|
3756
|
-
const o = i.map((c) => new L(c));
|
|
3757
|
-
return m(t, {
|
|
3758
|
-
code: l.invalid_union,
|
|
3759
|
-
unionErrors: o
|
|
3760
|
-
}), _;
|
|
3761
|
-
}
|
|
3762
|
-
}
|
|
3763
|
-
get options() {
|
|
3764
|
-
return this._def.options;
|
|
3765
|
-
}
|
|
3766
|
-
}
|
|
3767
|
-
Fe.create = (r, e) => new Fe({
|
|
3768
|
-
options: r,
|
|
3769
|
-
typeName: y.ZodUnion,
|
|
3770
|
-
...w(e)
|
|
3771
|
-
});
|
|
3772
|
-
const z = (r) => r instanceof Je ? z(r.schema) : r instanceof F ? z(r.innerType()) : r instanceof Ye ? [r.value] : r instanceof ce ? r.options : r instanceof Xe ? j.objectValues(r.enum) : r instanceof Qe ? z(r._def.innerType) : r instanceof Be ? [void 0] : r instanceof We ? [null] : r instanceof J ? [void 0, ...z(r.unwrap())] : r instanceof ue ? [null, ...z(r.unwrap())] : r instanceof Dt || r instanceof et ? z(r.unwrap()) : r instanceof ze ? z(r._def.innerType) : [];
|
|
3773
|
-
class xt extends O {
|
|
3774
|
-
_parse(e) {
|
|
3775
|
-
const { ctx: t } = this._processInputParams(e);
|
|
3776
|
-
if (t.parsedType !== g.object)
|
|
3777
|
-
return m(t, {
|
|
3778
|
-
code: l.invalid_type,
|
|
3779
|
-
expected: g.object,
|
|
3780
|
-
received: t.parsedType
|
|
3781
|
-
}), _;
|
|
3782
|
-
const n = this.discriminator, s = t.data[n], a = this.optionsMap.get(s);
|
|
3783
|
-
return a ? t.common.async ? a._parseAsync({
|
|
3784
|
-
data: t.data,
|
|
3785
|
-
path: t.path,
|
|
3786
|
-
parent: t
|
|
3787
|
-
}) : a._parseSync({
|
|
3788
|
-
data: t.data,
|
|
3789
|
-
path: t.path,
|
|
3790
|
-
parent: t
|
|
3791
|
-
}) : (m(t, {
|
|
3792
|
-
code: l.invalid_union_discriminator,
|
|
3793
|
-
options: Array.from(this.optionsMap.keys()),
|
|
3794
|
-
path: [n]
|
|
3795
|
-
}), _);
|
|
3796
|
-
}
|
|
3797
|
-
get discriminator() {
|
|
3798
|
-
return this._def.discriminator;
|
|
3799
|
-
}
|
|
3800
|
-
get options() {
|
|
3801
|
-
return this._def.options;
|
|
3802
|
-
}
|
|
3803
|
-
get optionsMap() {
|
|
3804
|
-
return this._def.optionsMap;
|
|
3805
|
-
}
|
|
3806
|
-
/**
|
|
3807
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
3808
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
3809
|
-
* have a different value for each object in the union.
|
|
3810
|
-
* @param discriminator the name of the discriminator property
|
|
3811
|
-
* @param types an array of object schemas
|
|
3812
|
-
* @param params
|
|
3813
|
-
*/
|
|
3814
|
-
static create(e, t, n) {
|
|
3815
|
-
const s = /* @__PURE__ */ new Map();
|
|
3816
|
-
for (const a of t) {
|
|
3817
|
-
const i = z(a.shape[e]);
|
|
3818
|
-
if (!i.length)
|
|
3819
|
-
throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);
|
|
3820
|
-
for (const o of i) {
|
|
3821
|
-
if (s.has(o))
|
|
3822
|
-
throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);
|
|
3823
|
-
s.set(o, a);
|
|
3824
|
-
}
|
|
3825
|
-
}
|
|
3826
|
-
return new xt({
|
|
3827
|
-
typeName: y.ZodDiscriminatedUnion,
|
|
3828
|
-
discriminator: e,
|
|
3829
|
-
options: t,
|
|
3830
|
-
optionsMap: s,
|
|
3831
|
-
...w(n)
|
|
3832
|
-
});
|
|
3833
|
-
}
|
|
3834
|
-
}
|
|
3835
|
-
function At(r, e) {
|
|
3836
|
-
const t = se(r), n = se(e);
|
|
3837
|
-
if (r === e)
|
|
3838
|
-
return { valid: !0, data: r };
|
|
3839
|
-
if (t === g.object && n === g.object) {
|
|
3840
|
-
const s = j.objectKeys(e), a = j.objectKeys(r).filter((o) => s.indexOf(o) !== -1), i = { ...r, ...e };
|
|
3841
|
-
for (const o of a) {
|
|
3842
|
-
const c = At(r[o], e[o]);
|
|
3843
|
-
if (!c.valid)
|
|
3844
|
-
return { valid: !1 };
|
|
3845
|
-
i[o] = c.data;
|
|
3846
|
-
}
|
|
3847
|
-
return { valid: !0, data: i };
|
|
3848
|
-
} else if (t === g.array && n === g.array) {
|
|
3849
|
-
if (r.length !== e.length)
|
|
3850
|
-
return { valid: !1 };
|
|
3851
|
-
const s = [];
|
|
3852
|
-
for (let a = 0; a < r.length; a++) {
|
|
3853
|
-
const i = r[a], o = e[a], c = At(i, o);
|
|
3854
|
-
if (!c.valid)
|
|
3855
|
-
return { valid: !1 };
|
|
3856
|
-
s.push(c.data);
|
|
3857
|
-
}
|
|
3858
|
-
return { valid: !0, data: s };
|
|
3859
|
-
} else return t === g.date && n === g.date && +r == +e ? { valid: !0, data: r } : { valid: !1 };
|
|
3860
|
-
}
|
|
3861
|
-
class Ge extends O {
|
|
3862
|
-
_parse(e) {
|
|
3863
|
-
const { status: t, ctx: n } = this._processInputParams(e), s = (a, i) => {
|
|
3864
|
-
if (Zt(a) || Zt(i))
|
|
3865
|
-
return _;
|
|
3866
|
-
const o = At(a.value, i.value);
|
|
3867
|
-
return o.valid ? ((St(a) || St(i)) && t.dirty(), { status: t.value, value: o.data }) : (m(n, {
|
|
3868
|
-
code: l.invalid_intersection_types
|
|
3869
|
-
}), _);
|
|
3870
|
-
};
|
|
3871
|
-
return n.common.async ? Promise.all([
|
|
3872
|
-
this._def.left._parseAsync({
|
|
3873
|
-
data: n.data,
|
|
3874
|
-
path: n.path,
|
|
3875
|
-
parent: n
|
|
3876
|
-
}),
|
|
3877
|
-
this._def.right._parseAsync({
|
|
3878
|
-
data: n.data,
|
|
3879
|
-
path: n.path,
|
|
3880
|
-
parent: n
|
|
3881
|
-
})
|
|
3882
|
-
]).then(([a, i]) => s(a, i)) : s(this._def.left._parseSync({
|
|
3883
|
-
data: n.data,
|
|
3884
|
-
path: n.path,
|
|
3885
|
-
parent: n
|
|
3886
|
-
}), this._def.right._parseSync({
|
|
3887
|
-
data: n.data,
|
|
3888
|
-
path: n.path,
|
|
3889
|
-
parent: n
|
|
3890
|
-
}));
|
|
3891
|
-
}
|
|
3892
|
-
}
|
|
3893
|
-
Ge.create = (r, e, t) => new Ge({
|
|
3894
|
-
left: r,
|
|
3895
|
-
right: e,
|
|
3896
|
-
typeName: y.ZodIntersection,
|
|
3897
|
-
...w(t)
|
|
3898
|
-
});
|
|
3899
|
-
class X extends O {
|
|
3900
|
-
_parse(e) {
|
|
3901
|
-
const { status: t, ctx: n } = this._processInputParams(e);
|
|
3902
|
-
if (n.parsedType !== g.array)
|
|
3903
|
-
return m(n, {
|
|
3904
|
-
code: l.invalid_type,
|
|
3905
|
-
expected: g.array,
|
|
3906
|
-
received: n.parsedType
|
|
3907
|
-
}), _;
|
|
3908
|
-
if (n.data.length < this._def.items.length)
|
|
3909
|
-
return m(n, {
|
|
3910
|
-
code: l.too_small,
|
|
3911
|
-
minimum: this._def.items.length,
|
|
3912
|
-
inclusive: !0,
|
|
3913
|
-
exact: !1,
|
|
3914
|
-
type: "array"
|
|
3915
|
-
}), _;
|
|
3916
|
-
!this._def.rest && n.data.length > this._def.items.length && (m(n, {
|
|
3917
|
-
code: l.too_big,
|
|
3918
|
-
maximum: this._def.items.length,
|
|
3919
|
-
inclusive: !0,
|
|
3920
|
-
exact: !1,
|
|
3921
|
-
type: "array"
|
|
3922
|
-
}), t.dirty());
|
|
3923
|
-
const a = [...n.data].map((i, o) => {
|
|
3924
|
-
const c = this._def.items[o] || this._def.rest;
|
|
3925
|
-
return c ? c._parse(new Y(n, i, n.path, o)) : null;
|
|
3926
|
-
}).filter((i) => !!i);
|
|
3927
|
-
return n.common.async ? Promise.all(a).then((i) => M.mergeArray(t, i)) : M.mergeArray(t, a);
|
|
3928
|
-
}
|
|
3929
|
-
get items() {
|
|
3930
|
-
return this._def.items;
|
|
3931
|
-
}
|
|
3932
|
-
rest(e) {
|
|
3933
|
-
return new X({
|
|
3934
|
-
...this._def,
|
|
3935
|
-
rest: e
|
|
3936
|
-
});
|
|
3937
|
-
}
|
|
3938
|
-
}
|
|
3939
|
-
X.create = (r, e) => {
|
|
3940
|
-
if (!Array.isArray(r))
|
|
3941
|
-
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3942
|
-
return new X({
|
|
3943
|
-
items: r,
|
|
3944
|
-
typeName: y.ZodTuple,
|
|
3945
|
-
rest: null,
|
|
3946
|
-
...w(e)
|
|
3947
|
-
});
|
|
3948
|
-
};
|
|
3949
|
-
class Ke extends O {
|
|
3950
|
-
get keySchema() {
|
|
3951
|
-
return this._def.keyType;
|
|
3952
|
-
}
|
|
3953
|
-
get valueSchema() {
|
|
3954
|
-
return this._def.valueType;
|
|
3955
|
-
}
|
|
3956
|
-
_parse(e) {
|
|
3957
|
-
const { status: t, ctx: n } = this._processInputParams(e);
|
|
3958
|
-
if (n.parsedType !== g.object)
|
|
3959
|
-
return m(n, {
|
|
3960
|
-
code: l.invalid_type,
|
|
3961
|
-
expected: g.object,
|
|
3962
|
-
received: n.parsedType
|
|
3963
|
-
}), _;
|
|
3964
|
-
const s = [], a = this._def.keyType, i = this._def.valueType;
|
|
3965
|
-
for (const o in n.data)
|
|
3966
|
-
s.push({
|
|
3967
|
-
key: a._parse(new Y(n, o, n.path, o)),
|
|
3968
|
-
value: i._parse(new Y(n, n.data[o], n.path, o)),
|
|
3969
|
-
alwaysSet: o in n.data
|
|
3970
|
-
});
|
|
3971
|
-
return n.common.async ? M.mergeObjectAsync(t, s) : M.mergeObjectSync(t, s);
|
|
3972
|
-
}
|
|
3973
|
-
get element() {
|
|
3974
|
-
return this._def.valueType;
|
|
3975
|
-
}
|
|
3976
|
-
static create(e, t, n) {
|
|
3977
|
-
return t instanceof O ? new Ke({
|
|
3978
|
-
keyType: e,
|
|
3979
|
-
valueType: t,
|
|
3980
|
-
typeName: y.ZodRecord,
|
|
3981
|
-
...w(n)
|
|
3982
|
-
}) : new Ke({
|
|
3983
|
-
keyType: B.create(),
|
|
3984
|
-
valueType: e,
|
|
3985
|
-
typeName: y.ZodRecord,
|
|
3986
|
-
...w(t)
|
|
3987
|
-
});
|
|
3988
|
-
}
|
|
3989
|
-
}
|
|
3990
|
-
class _t extends O {
|
|
3991
|
-
get keySchema() {
|
|
3992
|
-
return this._def.keyType;
|
|
3993
|
-
}
|
|
3994
|
-
get valueSchema() {
|
|
3995
|
-
return this._def.valueType;
|
|
3996
|
-
}
|
|
3997
|
-
_parse(e) {
|
|
3998
|
-
const { status: t, ctx: n } = this._processInputParams(e);
|
|
3999
|
-
if (n.parsedType !== g.map)
|
|
4000
|
-
return m(n, {
|
|
4001
|
-
code: l.invalid_type,
|
|
4002
|
-
expected: g.map,
|
|
4003
|
-
received: n.parsedType
|
|
4004
|
-
}), _;
|
|
4005
|
-
const s = this._def.keyType, a = this._def.valueType, i = [...n.data.entries()].map(([o, c], u) => ({
|
|
4006
|
-
key: s._parse(new Y(n, o, n.path, [u, "key"])),
|
|
4007
|
-
value: a._parse(new Y(n, c, n.path, [u, "value"]))
|
|
4008
|
-
}));
|
|
4009
|
-
if (n.common.async) {
|
|
4010
|
-
const o = /* @__PURE__ */ new Map();
|
|
4011
|
-
return Promise.resolve().then(async () => {
|
|
4012
|
-
for (const c of i) {
|
|
4013
|
-
const u = await c.key, d = await c.value;
|
|
4014
|
-
if (u.status === "aborted" || d.status === "aborted")
|
|
4015
|
-
return _;
|
|
4016
|
-
(u.status === "dirty" || d.status === "dirty") && t.dirty(), o.set(u.value, d.value);
|
|
4017
|
-
}
|
|
4018
|
-
return { status: t.value, value: o };
|
|
4019
|
-
});
|
|
4020
|
-
} else {
|
|
4021
|
-
const o = /* @__PURE__ */ new Map();
|
|
4022
|
-
for (const c of i) {
|
|
4023
|
-
const u = c.key, d = c.value;
|
|
4024
|
-
if (u.status === "aborted" || d.status === "aborted")
|
|
4025
|
-
return _;
|
|
4026
|
-
(u.status === "dirty" || d.status === "dirty") && t.dirty(), o.set(u.value, d.value);
|
|
4027
|
-
}
|
|
4028
|
-
return { status: t.value, value: o };
|
|
4029
|
-
}
|
|
4030
|
-
}
|
|
4031
|
-
}
|
|
4032
|
-
_t.create = (r, e, t) => new _t({
|
|
4033
|
-
valueType: e,
|
|
4034
|
-
keyType: r,
|
|
4035
|
-
typeName: y.ZodMap,
|
|
4036
|
-
...w(t)
|
|
4037
|
-
});
|
|
4038
|
-
class me extends O {
|
|
4039
|
-
_parse(e) {
|
|
4040
|
-
const { status: t, ctx: n } = this._processInputParams(e);
|
|
4041
|
-
if (n.parsedType !== g.set)
|
|
4042
|
-
return m(n, {
|
|
4043
|
-
code: l.invalid_type,
|
|
4044
|
-
expected: g.set,
|
|
4045
|
-
received: n.parsedType
|
|
4046
|
-
}), _;
|
|
4047
|
-
const s = this._def;
|
|
4048
|
-
s.minSize !== null && n.data.size < s.minSize.value && (m(n, {
|
|
4049
|
-
code: l.too_small,
|
|
4050
|
-
minimum: s.minSize.value,
|
|
4051
|
-
type: "set",
|
|
4052
|
-
inclusive: !0,
|
|
4053
|
-
exact: !1,
|
|
4054
|
-
message: s.minSize.message
|
|
4055
|
-
}), t.dirty()), s.maxSize !== null && n.data.size > s.maxSize.value && (m(n, {
|
|
4056
|
-
code: l.too_big,
|
|
4057
|
-
maximum: s.maxSize.value,
|
|
4058
|
-
type: "set",
|
|
4059
|
-
inclusive: !0,
|
|
4060
|
-
exact: !1,
|
|
4061
|
-
message: s.maxSize.message
|
|
4062
|
-
}), t.dirty());
|
|
4063
|
-
const a = this._def.valueType;
|
|
4064
|
-
function i(c) {
|
|
4065
|
-
const u = /* @__PURE__ */ new Set();
|
|
4066
|
-
for (const d of c) {
|
|
4067
|
-
if (d.status === "aborted")
|
|
4068
|
-
return _;
|
|
4069
|
-
d.status === "dirty" && t.dirty(), u.add(d.value);
|
|
4070
|
-
}
|
|
4071
|
-
return { status: t.value, value: u };
|
|
4072
|
-
}
|
|
4073
|
-
const o = [...n.data.values()].map((c, u) => a._parse(new Y(n, c, n.path, u)));
|
|
4074
|
-
return n.common.async ? Promise.all(o).then((c) => i(c)) : i(o);
|
|
4075
|
-
}
|
|
4076
|
-
min(e, t) {
|
|
4077
|
-
return new me({
|
|
4078
|
-
...this._def,
|
|
4079
|
-
minSize: { value: e, message: v.toString(t) }
|
|
4080
|
-
});
|
|
4081
|
-
}
|
|
4082
|
-
max(e, t) {
|
|
4083
|
-
return new me({
|
|
4084
|
-
...this._def,
|
|
4085
|
-
maxSize: { value: e, message: v.toString(t) }
|
|
4086
|
-
});
|
|
4087
|
-
}
|
|
4088
|
-
size(e, t) {
|
|
4089
|
-
return this.min(e, t).max(e, t);
|
|
4090
|
-
}
|
|
4091
|
-
nonempty(e) {
|
|
4092
|
-
return this.min(1, e);
|
|
4093
|
-
}
|
|
4094
|
-
}
|
|
4095
|
-
me.create = (r, e) => new me({
|
|
4096
|
-
valueType: r,
|
|
4097
|
-
minSize: null,
|
|
4098
|
-
maxSize: null,
|
|
4099
|
-
typeName: y.ZodSet,
|
|
4100
|
-
...w(e)
|
|
4101
|
-
});
|
|
4102
|
-
class Oe extends O {
|
|
4103
|
-
constructor() {
|
|
4104
|
-
super(...arguments), this.validate = this.implement;
|
|
4105
|
-
}
|
|
4106
|
-
_parse(e) {
|
|
4107
|
-
const { ctx: t } = this._processInputParams(e);
|
|
4108
|
-
if (t.parsedType !== g.function)
|
|
4109
|
-
return m(t, {
|
|
4110
|
-
code: l.invalid_type,
|
|
4111
|
-
expected: g.function,
|
|
4112
|
-
received: t.parsedType
|
|
4113
|
-
}), _;
|
|
4114
|
-
function n(o, c) {
|
|
4115
|
-
return mt({
|
|
4116
|
-
data: o,
|
|
4117
|
-
path: t.path,
|
|
4118
|
-
errorMaps: [
|
|
4119
|
-
t.common.contextualErrorMap,
|
|
4120
|
-
t.schemaErrorMap,
|
|
4121
|
-
pt(),
|
|
4122
|
-
Re
|
|
4123
|
-
].filter((u) => !!u),
|
|
4124
|
-
issueData: {
|
|
4125
|
-
code: l.invalid_arguments,
|
|
4126
|
-
argumentsError: c
|
|
4127
|
-
}
|
|
4128
|
-
});
|
|
4129
|
-
}
|
|
4130
|
-
function s(o, c) {
|
|
4131
|
-
return mt({
|
|
4132
|
-
data: o,
|
|
4133
|
-
path: t.path,
|
|
4134
|
-
errorMaps: [
|
|
4135
|
-
t.common.contextualErrorMap,
|
|
4136
|
-
t.schemaErrorMap,
|
|
4137
|
-
pt(),
|
|
4138
|
-
Re
|
|
4139
|
-
].filter((u) => !!u),
|
|
4140
|
-
issueData: {
|
|
4141
|
-
code: l.invalid_return_type,
|
|
4142
|
-
returnTypeError: c
|
|
4143
|
-
}
|
|
4144
|
-
});
|
|
4145
|
-
}
|
|
4146
|
-
const a = { errorMap: t.common.contextualErrorMap }, i = t.data;
|
|
4147
|
-
if (this._def.returns instanceof Ie) {
|
|
4148
|
-
const o = this;
|
|
4149
|
-
return $(async function(...c) {
|
|
4150
|
-
const u = new L([]), d = await o._def.args.parseAsync(c, a).catch((E) => {
|
|
4151
|
-
throw u.addIssue(n(c, E)), u;
|
|
4152
|
-
}), f = await Reflect.apply(i, this, d);
|
|
4153
|
-
return await o._def.returns._def.type.parseAsync(f, a).catch((E) => {
|
|
4154
|
-
throw u.addIssue(s(f, E)), u;
|
|
4155
|
-
});
|
|
4156
|
-
});
|
|
4157
|
-
} else {
|
|
4158
|
-
const o = this;
|
|
4159
|
-
return $(function(...c) {
|
|
4160
|
-
const u = o._def.args.safeParse(c, a);
|
|
4161
|
-
if (!u.success)
|
|
4162
|
-
throw new L([n(c, u.error)]);
|
|
4163
|
-
const d = Reflect.apply(i, this, u.data), f = o._def.returns.safeParse(d, a);
|
|
4164
|
-
if (!f.success)
|
|
4165
|
-
throw new L([s(d, f.error)]);
|
|
4166
|
-
return f.data;
|
|
4167
|
-
});
|
|
4168
|
-
}
|
|
4169
|
-
}
|
|
4170
|
-
parameters() {
|
|
4171
|
-
return this._def.args;
|
|
4172
|
-
}
|
|
4173
|
-
returnType() {
|
|
4174
|
-
return this._def.returns;
|
|
4175
|
-
}
|
|
4176
|
-
args(...e) {
|
|
4177
|
-
return new Oe({
|
|
4178
|
-
...this._def,
|
|
4179
|
-
args: X.create(e).rest(he.create())
|
|
4180
|
-
});
|
|
4181
|
-
}
|
|
4182
|
-
returns(e) {
|
|
4183
|
-
return new Oe({
|
|
4184
|
-
...this._def,
|
|
4185
|
-
returns: e
|
|
4186
|
-
});
|
|
4187
|
-
}
|
|
4188
|
-
implement(e) {
|
|
4189
|
-
return this.parse(e);
|
|
4190
|
-
}
|
|
4191
|
-
strictImplement(e) {
|
|
4192
|
-
return this.parse(e);
|
|
4193
|
-
}
|
|
4194
|
-
static create(e, t, n) {
|
|
4195
|
-
return new Oe({
|
|
4196
|
-
args: e || X.create([]).rest(he.create()),
|
|
4197
|
-
returns: t || he.create(),
|
|
4198
|
-
typeName: y.ZodFunction,
|
|
4199
|
-
...w(n)
|
|
4200
|
-
});
|
|
4201
|
-
}
|
|
4202
|
-
}
|
|
4203
|
-
class Je extends O {
|
|
4204
|
-
get schema() {
|
|
4205
|
-
return this._def.getter();
|
|
4206
|
-
}
|
|
4207
|
-
_parse(e) {
|
|
4208
|
-
const { ctx: t } = this._processInputParams(e);
|
|
4209
|
-
return this._def.getter()._parse({ data: t.data, path: t.path, parent: t });
|
|
4210
|
-
}
|
|
4211
|
-
}
|
|
4212
|
-
Je.create = (r, e) => new Je({
|
|
4213
|
-
getter: r,
|
|
4214
|
-
typeName: y.ZodLazy,
|
|
4215
|
-
...w(e)
|
|
4216
|
-
});
|
|
4217
|
-
class Ye extends O {
|
|
4218
|
-
_parse(e) {
|
|
4219
|
-
if (e.data !== this._def.value) {
|
|
4220
|
-
const t = this._getOrReturnCtx(e);
|
|
4221
|
-
return m(t, {
|
|
4222
|
-
received: t.data,
|
|
4223
|
-
code: l.invalid_literal,
|
|
4224
|
-
expected: this._def.value
|
|
4225
|
-
}), _;
|
|
4226
|
-
}
|
|
4227
|
-
return { status: "valid", value: e.data };
|
|
4228
|
-
}
|
|
4229
|
-
get value() {
|
|
4230
|
-
return this._def.value;
|
|
4231
|
-
}
|
|
4232
|
-
}
|
|
4233
|
-
Ye.create = (r, e) => new Ye({
|
|
4234
|
-
value: r,
|
|
4235
|
-
typeName: y.ZodLiteral,
|
|
4236
|
-
...w(e)
|
|
4237
|
-
});
|
|
4238
|
-
function hr(r, e) {
|
|
4239
|
-
return new ce({
|
|
4240
|
-
values: r,
|
|
4241
|
-
typeName: y.ZodEnum,
|
|
4242
|
-
...w(e)
|
|
4243
|
-
});
|
|
4244
|
-
}
|
|
4245
|
-
class ce extends O {
|
|
4246
|
-
constructor() {
|
|
4247
|
-
super(...arguments), Ne.set(this, void 0);
|
|
4248
|
-
}
|
|
4249
|
-
_parse(e) {
|
|
4250
|
-
if (typeof e.data != "string") {
|
|
4251
|
-
const t = this._getOrReturnCtx(e), n = this._def.values;
|
|
4252
|
-
return m(t, {
|
|
4253
|
-
expected: j.joinValues(n),
|
|
4254
|
-
received: t.parsedType,
|
|
4255
|
-
code: l.invalid_type
|
|
4256
|
-
}), _;
|
|
4257
|
-
}
|
|
4258
|
-
if (gt(this, Ne) || ur(this, Ne, new Set(this._def.values)), !gt(this, Ne).has(e.data)) {
|
|
4259
|
-
const t = this._getOrReturnCtx(e), n = this._def.values;
|
|
4260
|
-
return m(t, {
|
|
4261
|
-
received: t.data,
|
|
4262
|
-
code: l.invalid_enum_value,
|
|
4263
|
-
options: n
|
|
4264
|
-
}), _;
|
|
4265
|
-
}
|
|
4266
|
-
return $(e.data);
|
|
4267
|
-
}
|
|
4268
|
-
get options() {
|
|
4269
|
-
return this._def.values;
|
|
4270
|
-
}
|
|
4271
|
-
get enum() {
|
|
4272
|
-
const e = {};
|
|
4273
|
-
for (const t of this._def.values)
|
|
4274
|
-
e[t] = t;
|
|
4275
|
-
return e;
|
|
4276
|
-
}
|
|
4277
|
-
get Values() {
|
|
4278
|
-
const e = {};
|
|
4279
|
-
for (const t of this._def.values)
|
|
4280
|
-
e[t] = t;
|
|
4281
|
-
return e;
|
|
4282
|
-
}
|
|
4283
|
-
get Enum() {
|
|
4284
|
-
const e = {};
|
|
4285
|
-
for (const t of this._def.values)
|
|
4286
|
-
e[t] = t;
|
|
4287
|
-
return e;
|
|
4288
|
-
}
|
|
4289
|
-
extract(e, t = this._def) {
|
|
4290
|
-
return ce.create(e, {
|
|
4291
|
-
...this._def,
|
|
4292
|
-
...t
|
|
4293
|
-
});
|
|
4294
|
-
}
|
|
4295
|
-
exclude(e, t = this._def) {
|
|
4296
|
-
return ce.create(this.options.filter((n) => !e.includes(n)), {
|
|
4297
|
-
...this._def,
|
|
4298
|
-
...t
|
|
4299
|
-
});
|
|
4300
|
-
}
|
|
4301
|
-
}
|
|
4302
|
-
Ne = /* @__PURE__ */ new WeakMap();
|
|
4303
|
-
ce.create = hr;
|
|
4304
|
-
class Xe extends O {
|
|
4305
|
-
constructor() {
|
|
4306
|
-
super(...arguments), De.set(this, void 0);
|
|
4307
|
-
}
|
|
4308
|
-
_parse(e) {
|
|
4309
|
-
const t = j.getValidEnumValues(this._def.values), n = this._getOrReturnCtx(e);
|
|
4310
|
-
if (n.parsedType !== g.string && n.parsedType !== g.number) {
|
|
4311
|
-
const s = j.objectValues(t);
|
|
4312
|
-
return m(n, {
|
|
4313
|
-
expected: j.joinValues(s),
|
|
4314
|
-
received: n.parsedType,
|
|
4315
|
-
code: l.invalid_type
|
|
4316
|
-
}), _;
|
|
4317
|
-
}
|
|
4318
|
-
if (gt(this, De) || ur(this, De, new Set(j.getValidEnumValues(this._def.values))), !gt(this, De).has(e.data)) {
|
|
4319
|
-
const s = j.objectValues(t);
|
|
4320
|
-
return m(n, {
|
|
4321
|
-
received: n.data,
|
|
4322
|
-
code: l.invalid_enum_value,
|
|
4323
|
-
options: s
|
|
4324
|
-
}), _;
|
|
4325
|
-
}
|
|
4326
|
-
return $(e.data);
|
|
4327
|
-
}
|
|
4328
|
-
get enum() {
|
|
4329
|
-
return this._def.values;
|
|
4330
|
-
}
|
|
4331
|
-
}
|
|
4332
|
-
De = /* @__PURE__ */ new WeakMap();
|
|
4333
|
-
Xe.create = (r, e) => new Xe({
|
|
4334
|
-
values: r,
|
|
4335
|
-
typeName: y.ZodNativeEnum,
|
|
4336
|
-
...w(e)
|
|
4337
|
-
});
|
|
4338
|
-
class Ie extends O {
|
|
4339
|
-
unwrap() {
|
|
4340
|
-
return this._def.type;
|
|
4341
|
-
}
|
|
4342
|
-
_parse(e) {
|
|
4343
|
-
const { ctx: t } = this._processInputParams(e);
|
|
4344
|
-
if (t.parsedType !== g.promise && t.common.async === !1)
|
|
4345
|
-
return m(t, {
|
|
4346
|
-
code: l.invalid_type,
|
|
4347
|
-
expected: g.promise,
|
|
4348
|
-
received: t.parsedType
|
|
4349
|
-
}), _;
|
|
4350
|
-
const n = t.parsedType === g.promise ? t.data : Promise.resolve(t.data);
|
|
4351
|
-
return $(n.then((s) => this._def.type.parseAsync(s, {
|
|
4352
|
-
path: t.path,
|
|
4353
|
-
errorMap: t.common.contextualErrorMap
|
|
4354
|
-
})));
|
|
4355
|
-
}
|
|
4356
|
-
}
|
|
4357
|
-
Ie.create = (r, e) => new Ie({
|
|
4358
|
-
type: r,
|
|
4359
|
-
typeName: y.ZodPromise,
|
|
4360
|
-
...w(e)
|
|
4361
|
-
});
|
|
4362
|
-
class F extends O {
|
|
4363
|
-
innerType() {
|
|
4364
|
-
return this._def.schema;
|
|
4365
|
-
}
|
|
4366
|
-
sourceType() {
|
|
4367
|
-
return this._def.schema._def.typeName === y.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
4368
|
-
}
|
|
4369
|
-
_parse(e) {
|
|
4370
|
-
const { status: t, ctx: n } = this._processInputParams(e), s = this._def.effect || null, a = {
|
|
4371
|
-
addIssue: (i) => {
|
|
4372
|
-
m(n, i), i.fatal ? t.abort() : t.dirty();
|
|
4373
|
-
},
|
|
4374
|
-
get path() {
|
|
4375
|
-
return n.path;
|
|
4376
|
-
}
|
|
4377
|
-
};
|
|
4378
|
-
if (a.addIssue = a.addIssue.bind(a), s.type === "preprocess") {
|
|
4379
|
-
const i = s.transform(n.data, a);
|
|
4380
|
-
if (n.common.async)
|
|
4381
|
-
return Promise.resolve(i).then(async (o) => {
|
|
4382
|
-
if (t.value === "aborted")
|
|
4383
|
-
return _;
|
|
4384
|
-
const c = await this._def.schema._parseAsync({
|
|
4385
|
-
data: o,
|
|
4386
|
-
path: n.path,
|
|
4387
|
-
parent: n
|
|
4388
|
-
});
|
|
4389
|
-
return c.status === "aborted" ? _ : c.status === "dirty" || t.value === "dirty" ? we(c.value) : c;
|
|
4390
|
-
});
|
|
4391
|
-
{
|
|
4392
|
-
if (t.value === "aborted")
|
|
4393
|
-
return _;
|
|
4394
|
-
const o = this._def.schema._parseSync({
|
|
4395
|
-
data: i,
|
|
4396
|
-
path: n.path,
|
|
4397
|
-
parent: n
|
|
4398
|
-
});
|
|
4399
|
-
return o.status === "aborted" ? _ : o.status === "dirty" || t.value === "dirty" ? we(o.value) : o;
|
|
4400
|
-
}
|
|
4401
|
-
}
|
|
4402
|
-
if (s.type === "refinement") {
|
|
4403
|
-
const i = (o) => {
|
|
4404
|
-
const c = s.refinement(o, a);
|
|
4405
|
-
if (n.common.async)
|
|
4406
|
-
return Promise.resolve(c);
|
|
4407
|
-
if (c instanceof Promise)
|
|
4408
|
-
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
4409
|
-
return o;
|
|
4410
|
-
};
|
|
4411
|
-
if (n.common.async === !1) {
|
|
4412
|
-
const o = this._def.schema._parseSync({
|
|
4413
|
-
data: n.data,
|
|
4414
|
-
path: n.path,
|
|
4415
|
-
parent: n
|
|
4416
|
-
});
|
|
4417
|
-
return o.status === "aborted" ? _ : (o.status === "dirty" && t.dirty(), i(o.value), { status: t.value, value: o.value });
|
|
4418
|
-
} else
|
|
4419
|
-
return this._def.schema._parseAsync({ data: n.data, path: n.path, parent: n }).then((o) => o.status === "aborted" ? _ : (o.status === "dirty" && t.dirty(), i(o.value).then(() => ({ status: t.value, value: o.value }))));
|
|
4420
|
-
}
|
|
4421
|
-
if (s.type === "transform")
|
|
4422
|
-
if (n.common.async === !1) {
|
|
4423
|
-
const i = this._def.schema._parseSync({
|
|
4424
|
-
data: n.data,
|
|
4425
|
-
path: n.path,
|
|
4426
|
-
parent: n
|
|
4427
|
-
});
|
|
4428
|
-
if (!Ue(i))
|
|
4429
|
-
return i;
|
|
4430
|
-
const o = s.transform(i.value, a);
|
|
4431
|
-
if (o instanceof Promise)
|
|
4432
|
-
throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
4433
|
-
return { status: t.value, value: o };
|
|
4434
|
-
} else
|
|
4435
|
-
return this._def.schema._parseAsync({ data: n.data, path: n.path, parent: n }).then((i) => Ue(i) ? Promise.resolve(s.transform(i.value, a)).then((o) => ({ status: t.value, value: o })) : i);
|
|
4436
|
-
j.assertNever(s);
|
|
4437
|
-
}
|
|
4438
|
-
}
|
|
4439
|
-
F.create = (r, e, t) => new F({
|
|
4440
|
-
schema: r,
|
|
4441
|
-
typeName: y.ZodEffects,
|
|
4442
|
-
effect: e,
|
|
4443
|
-
...w(t)
|
|
4444
|
-
});
|
|
4445
|
-
F.createWithPreprocess = (r, e, t) => new F({
|
|
4446
|
-
schema: e,
|
|
4447
|
-
effect: { type: "preprocess", transform: r },
|
|
4448
|
-
typeName: y.ZodEffects,
|
|
4449
|
-
...w(t)
|
|
4450
|
-
});
|
|
4451
|
-
class J extends O {
|
|
4452
|
-
_parse(e) {
|
|
4453
|
-
return this._getType(e) === g.undefined ? $(void 0) : this._def.innerType._parse(e);
|
|
4454
|
-
}
|
|
4455
|
-
unwrap() {
|
|
4456
|
-
return this._def.innerType;
|
|
4457
|
-
}
|
|
4458
|
-
}
|
|
4459
|
-
J.create = (r, e) => new J({
|
|
4460
|
-
innerType: r,
|
|
4461
|
-
typeName: y.ZodOptional,
|
|
4462
|
-
...w(e)
|
|
4463
|
-
});
|
|
4464
|
-
class ue extends O {
|
|
4465
|
-
_parse(e) {
|
|
4466
|
-
return this._getType(e) === g.null ? $(null) : this._def.innerType._parse(e);
|
|
4467
|
-
}
|
|
4468
|
-
unwrap() {
|
|
4469
|
-
return this._def.innerType;
|
|
4470
|
-
}
|
|
4471
|
-
}
|
|
4472
|
-
ue.create = (r, e) => new ue({
|
|
4473
|
-
innerType: r,
|
|
4474
|
-
typeName: y.ZodNullable,
|
|
4475
|
-
...w(e)
|
|
4476
|
-
});
|
|
4477
|
-
class Qe extends O {
|
|
4478
|
-
_parse(e) {
|
|
4479
|
-
const { ctx: t } = this._processInputParams(e);
|
|
4480
|
-
let n = t.data;
|
|
4481
|
-
return t.parsedType === g.undefined && (n = this._def.defaultValue()), this._def.innerType._parse({
|
|
4482
|
-
data: n,
|
|
4483
|
-
path: t.path,
|
|
4484
|
-
parent: t
|
|
4485
|
-
});
|
|
4486
|
-
}
|
|
4487
|
-
removeDefault() {
|
|
4488
|
-
return this._def.innerType;
|
|
4489
|
-
}
|
|
4490
|
-
}
|
|
4491
|
-
Qe.create = (r, e) => new Qe({
|
|
4492
|
-
innerType: r,
|
|
4493
|
-
typeName: y.ZodDefault,
|
|
4494
|
-
defaultValue: typeof e.default == "function" ? e.default : () => e.default,
|
|
4495
|
-
...w(e)
|
|
4496
|
-
});
|
|
4497
|
-
class ze extends O {
|
|
4498
|
-
_parse(e) {
|
|
4499
|
-
const { ctx: t } = this._processInputParams(e), n = {
|
|
4500
|
-
...t,
|
|
4501
|
-
common: {
|
|
4502
|
-
...t.common,
|
|
4503
|
-
issues: []
|
|
4504
|
-
}
|
|
4505
|
-
}, s = this._def.innerType._parse({
|
|
4506
|
-
data: n.data,
|
|
4507
|
-
path: n.path,
|
|
4508
|
-
parent: {
|
|
4509
|
-
...n
|
|
4510
|
-
}
|
|
4511
|
-
});
|
|
4512
|
-
return He(s) ? s.then((a) => ({
|
|
4513
|
-
status: "valid",
|
|
4514
|
-
value: a.status === "valid" ? a.value : this._def.catchValue({
|
|
4515
|
-
get error() {
|
|
4516
|
-
return new L(n.common.issues);
|
|
4517
|
-
},
|
|
4518
|
-
input: n.data
|
|
4519
|
-
})
|
|
4520
|
-
})) : {
|
|
4521
|
-
status: "valid",
|
|
4522
|
-
value: s.status === "valid" ? s.value : this._def.catchValue({
|
|
4523
|
-
get error() {
|
|
4524
|
-
return new L(n.common.issues);
|
|
4525
|
-
},
|
|
4526
|
-
input: n.data
|
|
4527
|
-
})
|
|
4528
|
-
};
|
|
4529
|
-
}
|
|
4530
|
-
removeCatch() {
|
|
4531
|
-
return this._def.innerType;
|
|
4532
|
-
}
|
|
4533
|
-
}
|
|
4534
|
-
ze.create = (r, e) => new ze({
|
|
4535
|
-
innerType: r,
|
|
4536
|
-
typeName: y.ZodCatch,
|
|
4537
|
-
catchValue: typeof e.catch == "function" ? e.catch : () => e.catch,
|
|
4538
|
-
...w(e)
|
|
4539
|
-
});
|
|
4540
|
-
class bt extends O {
|
|
4541
|
-
_parse(e) {
|
|
4542
|
-
if (this._getType(e) !== g.nan) {
|
|
4543
|
-
const n = this._getOrReturnCtx(e);
|
|
4544
|
-
return m(n, {
|
|
4545
|
-
code: l.invalid_type,
|
|
4546
|
-
expected: g.nan,
|
|
4547
|
-
received: n.parsedType
|
|
4548
|
-
}), _;
|
|
4549
|
-
}
|
|
4550
|
-
return { status: "valid", value: e.data };
|
|
4551
|
-
}
|
|
4552
|
-
}
|
|
4553
|
-
bt.create = (r) => new bt({
|
|
4554
|
-
typeName: y.ZodNaN,
|
|
4555
|
-
...w(r)
|
|
4556
|
-
});
|
|
4557
|
-
const Fn = Symbol("zod_brand");
|
|
4558
|
-
class Dt extends O {
|
|
4559
|
-
_parse(e) {
|
|
4560
|
-
const { ctx: t } = this._processInputParams(e), n = t.data;
|
|
4561
|
-
return this._def.type._parse({
|
|
4562
|
-
data: n,
|
|
4563
|
-
path: t.path,
|
|
4564
|
-
parent: t
|
|
4565
|
-
});
|
|
4566
|
-
}
|
|
4567
|
-
unwrap() {
|
|
4568
|
-
return this._def.type;
|
|
4569
|
-
}
|
|
4570
|
-
}
|
|
4571
|
-
class it extends O {
|
|
4572
|
-
_parse(e) {
|
|
4573
|
-
const { status: t, ctx: n } = this._processInputParams(e);
|
|
4574
|
-
if (n.common.async)
|
|
4575
|
-
return (async () => {
|
|
4576
|
-
const a = await this._def.in._parseAsync({
|
|
4577
|
-
data: n.data,
|
|
4578
|
-
path: n.path,
|
|
4579
|
-
parent: n
|
|
4580
|
-
});
|
|
4581
|
-
return a.status === "aborted" ? _ : a.status === "dirty" ? (t.dirty(), we(a.value)) : this._def.out._parseAsync({
|
|
4582
|
-
data: a.value,
|
|
4583
|
-
path: n.path,
|
|
4584
|
-
parent: n
|
|
4585
|
-
});
|
|
4586
|
-
})();
|
|
4587
|
-
{
|
|
4588
|
-
const s = this._def.in._parseSync({
|
|
4589
|
-
data: n.data,
|
|
4590
|
-
path: n.path,
|
|
4591
|
-
parent: n
|
|
4592
|
-
});
|
|
4593
|
-
return s.status === "aborted" ? _ : s.status === "dirty" ? (t.dirty(), {
|
|
4594
|
-
status: "dirty",
|
|
4595
|
-
value: s.value
|
|
4596
|
-
}) : this._def.out._parseSync({
|
|
4597
|
-
data: s.value,
|
|
4598
|
-
path: n.path,
|
|
4599
|
-
parent: n
|
|
4600
|
-
});
|
|
4601
|
-
}
|
|
4602
|
-
}
|
|
4603
|
-
static create(e, t) {
|
|
4604
|
-
return new it({
|
|
4605
|
-
in: e,
|
|
4606
|
-
out: t,
|
|
4607
|
-
typeName: y.ZodPipeline
|
|
4608
|
-
});
|
|
4609
|
-
}
|
|
4610
|
-
}
|
|
4611
|
-
class et extends O {
|
|
4612
|
-
_parse(e) {
|
|
4613
|
-
const t = this._def.innerType._parse(e), n = (s) => (Ue(s) && (s.value = Object.freeze(s.value)), s);
|
|
4614
|
-
return He(t) ? t.then((s) => n(s)) : n(t);
|
|
4615
|
-
}
|
|
4616
|
-
unwrap() {
|
|
4617
|
-
return this._def.innerType;
|
|
4618
|
-
}
|
|
4619
|
-
}
|
|
4620
|
-
et.create = (r, e) => new et({
|
|
4621
|
-
innerType: r,
|
|
4622
|
-
typeName: y.ZodReadonly,
|
|
4623
|
-
...w(e)
|
|
4624
|
-
});
|
|
4625
|
-
function pr(r, e = {}, t) {
|
|
4626
|
-
return r ? Ee.create().superRefine((n, s) => {
|
|
4627
|
-
var a, i;
|
|
4628
|
-
if (!r(n)) {
|
|
4629
|
-
const o = typeof e == "function" ? e(n) : typeof e == "string" ? { message: e } : e, c = (i = (a = o.fatal) !== null && a !== void 0 ? a : t) !== null && i !== void 0 ? i : !0, u = typeof o == "string" ? { message: o } : o;
|
|
4630
|
-
s.addIssue({ code: "custom", ...u, fatal: c });
|
|
4631
|
-
}
|
|
4632
|
-
}) : Ee.create();
|
|
4633
|
-
}
|
|
4634
|
-
const Gn = {
|
|
4635
|
-
object: C.lazycreate
|
|
4636
|
-
};
|
|
4637
|
-
var y;
|
|
4638
|
-
(function(r) {
|
|
4639
|
-
r.ZodString = "ZodString", r.ZodNumber = "ZodNumber", r.ZodNaN = "ZodNaN", r.ZodBigInt = "ZodBigInt", r.ZodBoolean = "ZodBoolean", r.ZodDate = "ZodDate", r.ZodSymbol = "ZodSymbol", r.ZodUndefined = "ZodUndefined", r.ZodNull = "ZodNull", r.ZodAny = "ZodAny", r.ZodUnknown = "ZodUnknown", r.ZodNever = "ZodNever", r.ZodVoid = "ZodVoid", r.ZodArray = "ZodArray", r.ZodObject = "ZodObject", r.ZodUnion = "ZodUnion", r.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", r.ZodIntersection = "ZodIntersection", r.ZodTuple = "ZodTuple", r.ZodRecord = "ZodRecord", r.ZodMap = "ZodMap", r.ZodSet = "ZodSet", r.ZodFunction = "ZodFunction", r.ZodLazy = "ZodLazy", r.ZodLiteral = "ZodLiteral", r.ZodEnum = "ZodEnum", r.ZodEffects = "ZodEffects", r.ZodNativeEnum = "ZodNativeEnum", r.ZodOptional = "ZodOptional", r.ZodNullable = "ZodNullable", r.ZodDefault = "ZodDefault", r.ZodCatch = "ZodCatch", r.ZodPromise = "ZodPromise", r.ZodBranded = "ZodBranded", r.ZodPipeline = "ZodPipeline", r.ZodReadonly = "ZodReadonly";
|
|
4640
|
-
})(y || (y = {}));
|
|
4641
|
-
const Kn = (r, e = {
|
|
4642
|
-
message: `Input not instance of ${r.name}`
|
|
4643
|
-
}) => pr((t) => t instanceof r, e), mr = B.create, gr = ie.create, Jn = bt.create, Yn = oe.create, vr = qe.create, Xn = pe.create, Qn = vt.create, zn = Be.create, es = We.create, ts = Ee.create, rs = he.create, ns = re.create, ss = yt.create, as = W.create, is = C.create, os = C.strictCreate, cs = Fe.create, us = xt.create, ds = Ge.create, ls = X.create, fs = Ke.create, hs = _t.create, ps = me.create, ms = Oe.create, gs = Je.create, vs = Ye.create, ys = ce.create, _s = Xe.create, bs = Ie.create, Bt = F.create, ws = J.create, xs = ue.create, Os = F.createWithPreprocess, ks = it.create, Ts = () => mr().optional(), js = () => gr().optional(), Rs = () => vr().optional(), Es = {
|
|
4644
|
-
string: (r) => B.create({ ...r, coerce: !0 }),
|
|
4645
|
-
number: (r) => ie.create({ ...r, coerce: !0 }),
|
|
4646
|
-
boolean: (r) => qe.create({
|
|
4647
|
-
...r,
|
|
4648
|
-
coerce: !0
|
|
4649
|
-
}),
|
|
4650
|
-
bigint: (r) => oe.create({ ...r, coerce: !0 }),
|
|
4651
|
-
date: (r) => pe.create({ ...r, coerce: !0 })
|
|
4652
|
-
}, Is = _;
|
|
4653
|
-
var Ps = /* @__PURE__ */ Object.freeze({
|
|
4654
|
-
__proto__: null,
|
|
4655
|
-
defaultErrorMap: Re,
|
|
4656
|
-
setErrorMap: In,
|
|
4657
|
-
getErrorMap: pt,
|
|
4658
|
-
makeIssue: mt,
|
|
4659
|
-
EMPTY_PATH: Pn,
|
|
4660
|
-
addIssueToContext: m,
|
|
4661
|
-
ParseStatus: M,
|
|
4662
|
-
INVALID: _,
|
|
4663
|
-
DIRTY: we,
|
|
4664
|
-
OK: $,
|
|
4665
|
-
isAborted: Zt,
|
|
4666
|
-
isDirty: St,
|
|
4667
|
-
isValid: Ue,
|
|
4668
|
-
isAsync: He,
|
|
4669
|
-
get util() {
|
|
4670
|
-
return j;
|
|
4671
|
-
},
|
|
4672
|
-
get objectUtil() {
|
|
4673
|
-
return Ct;
|
|
4674
|
-
},
|
|
4675
|
-
ZodParsedType: g,
|
|
4676
|
-
getParsedType: se,
|
|
4677
|
-
ZodType: O,
|
|
4678
|
-
datetimeRegex: fr,
|
|
4679
|
-
ZodString: B,
|
|
4680
|
-
ZodNumber: ie,
|
|
4681
|
-
ZodBigInt: oe,
|
|
4682
|
-
ZodBoolean: qe,
|
|
4683
|
-
ZodDate: pe,
|
|
4684
|
-
ZodSymbol: vt,
|
|
4685
|
-
ZodUndefined: Be,
|
|
4686
|
-
ZodNull: We,
|
|
4687
|
-
ZodAny: Ee,
|
|
4688
|
-
ZodUnknown: he,
|
|
4689
|
-
ZodNever: re,
|
|
4690
|
-
ZodVoid: yt,
|
|
4691
|
-
ZodArray: W,
|
|
4692
|
-
ZodObject: C,
|
|
4693
|
-
ZodUnion: Fe,
|
|
4694
|
-
ZodDiscriminatedUnion: xt,
|
|
4695
|
-
ZodIntersection: Ge,
|
|
4696
|
-
ZodTuple: X,
|
|
4697
|
-
ZodRecord: Ke,
|
|
4698
|
-
ZodMap: _t,
|
|
4699
|
-
ZodSet: me,
|
|
4700
|
-
ZodFunction: Oe,
|
|
4701
|
-
ZodLazy: Je,
|
|
4702
|
-
ZodLiteral: Ye,
|
|
4703
|
-
ZodEnum: ce,
|
|
4704
|
-
ZodNativeEnum: Xe,
|
|
4705
|
-
ZodPromise: Ie,
|
|
4706
|
-
ZodEffects: F,
|
|
4707
|
-
ZodTransformer: F,
|
|
4708
|
-
ZodOptional: J,
|
|
4709
|
-
ZodNullable: ue,
|
|
4710
|
-
ZodDefault: Qe,
|
|
4711
|
-
ZodCatch: ze,
|
|
4712
|
-
ZodNaN: bt,
|
|
4713
|
-
BRAND: Fn,
|
|
4714
|
-
ZodBranded: Dt,
|
|
4715
|
-
ZodPipeline: it,
|
|
4716
|
-
ZodReadonly: et,
|
|
4717
|
-
custom: pr,
|
|
4718
|
-
Schema: O,
|
|
4719
|
-
ZodSchema: O,
|
|
4720
|
-
late: Gn,
|
|
4721
|
-
get ZodFirstPartyTypeKind() {
|
|
4722
|
-
return y;
|
|
4723
|
-
},
|
|
4724
|
-
coerce: Es,
|
|
4725
|
-
any: ts,
|
|
4726
|
-
array: as,
|
|
4727
|
-
bigint: Yn,
|
|
4728
|
-
boolean: vr,
|
|
4729
|
-
date: Xn,
|
|
4730
|
-
discriminatedUnion: us,
|
|
4731
|
-
effect: Bt,
|
|
4732
|
-
enum: ys,
|
|
4733
|
-
function: ms,
|
|
4734
|
-
instanceof: Kn,
|
|
4735
|
-
intersection: ds,
|
|
4736
|
-
lazy: gs,
|
|
4737
|
-
literal: vs,
|
|
4738
|
-
map: hs,
|
|
4739
|
-
nan: Jn,
|
|
4740
|
-
nativeEnum: _s,
|
|
4741
|
-
never: ns,
|
|
4742
|
-
null: es,
|
|
4743
|
-
nullable: xs,
|
|
4744
|
-
number: gr,
|
|
4745
|
-
object: is,
|
|
4746
|
-
oboolean: Rs,
|
|
4747
|
-
onumber: js,
|
|
4748
|
-
optional: ws,
|
|
4749
|
-
ostring: Ts,
|
|
4750
|
-
pipeline: ks,
|
|
4751
|
-
preprocess: Os,
|
|
4752
|
-
promise: bs,
|
|
4753
|
-
record: fs,
|
|
4754
|
-
set: ps,
|
|
4755
|
-
strictObject: os,
|
|
4756
|
-
string: mr,
|
|
4757
|
-
symbol: Qn,
|
|
4758
|
-
transformer: Bt,
|
|
4759
|
-
tuple: ls,
|
|
4760
|
-
undefined: zn,
|
|
4761
|
-
union: cs,
|
|
4762
|
-
unknown: rs,
|
|
4763
|
-
void: ss,
|
|
4764
|
-
NEVER: Is,
|
|
4765
|
-
ZodIssueCode: l,
|
|
4766
|
-
quotelessJson: En,
|
|
4767
|
-
ZodError: L
|
|
4768
|
-
}), Cs = class Nt extends Rn {
|
|
4769
|
-
constructor(t) {
|
|
4770
|
-
super(t);
|
|
4771
|
-
p(this, "openAPIRegistry");
|
|
4772
|
-
p(this, "defaultHook");
|
|
4773
|
-
/**
|
|
4774
|
-
*
|
|
4775
|
-
* @param {RouteConfig} route - The route definition which you create with `createRoute()`.
|
|
4776
|
-
* @param {Handler} handler - The handler. If you want to return a JSON object, you should specify the status code with `c.json()`.
|
|
4777
|
-
* @param {Hook} hook - Optional. The hook method defines what it should do after validation.
|
|
4778
|
-
* @example
|
|
4779
|
-
* app.openapi(
|
|
4780
|
-
* route,
|
|
4781
|
-
* (c) => {
|
|
4782
|
-
* // ...
|
|
4783
|
-
* return c.json(
|
|
4784
|
-
* {
|
|
4785
|
-
* age: 20,
|
|
4786
|
-
* name: 'Young man',
|
|
4787
|
-
* },
|
|
4788
|
-
* 200 // You should specify the status code even if it's 200.
|
|
4789
|
-
* )
|
|
4790
|
-
* },
|
|
4791
|
-
* (result, c) => {
|
|
4792
|
-
* if (!result.success) {
|
|
4793
|
-
* return c.json(
|
|
4794
|
-
* {
|
|
4795
|
-
* code: 400,
|
|
4796
|
-
* message: 'Custom Message',
|
|
4797
|
-
* },
|
|
4798
|
-
* 400
|
|
4799
|
-
* )
|
|
4800
|
-
* }
|
|
4801
|
-
* }
|
|
4802
|
-
*)
|
|
4803
|
-
*/
|
|
4804
|
-
p(this, "openapi", ({ middleware: t, ...n }, s, a = this.defaultHook) => {
|
|
4805
|
-
var u, d, f, k, E, R;
|
|
4806
|
-
this.openAPIRegistry.registerPath(n);
|
|
4807
|
-
const i = [];
|
|
4808
|
-
if ((u = n.request) != null && u.query) {
|
|
4809
|
-
const b = ye("query", n.request.query, a);
|
|
4810
|
-
i.push(b);
|
|
4811
|
-
}
|
|
4812
|
-
if ((d = n.request) != null && d.params) {
|
|
4813
|
-
const b = ye("param", n.request.params, a);
|
|
4814
|
-
i.push(b);
|
|
4815
|
-
}
|
|
4816
|
-
if ((f = n.request) != null && f.headers) {
|
|
4817
|
-
const b = ye("header", n.request.headers, a);
|
|
4818
|
-
i.push(b);
|
|
4819
|
-
}
|
|
4820
|
-
if ((k = n.request) != null && k.cookies) {
|
|
4821
|
-
const b = ye("cookie", n.request.cookies, a);
|
|
4822
|
-
i.push(b);
|
|
4823
|
-
}
|
|
4824
|
-
const o = (R = (E = n.request) == null ? void 0 : E.body) == null ? void 0 : R.content;
|
|
4825
|
-
if (o)
|
|
4826
|
-
for (const b of Object.keys(o)) {
|
|
4827
|
-
if (!o[b])
|
|
4828
|
-
continue;
|
|
4829
|
-
const S = o[b].schema;
|
|
4830
|
-
if (S instanceof O) {
|
|
4831
|
-
if (b.startsWith("application/json")) {
|
|
4832
|
-
const D = ye("json", S, a);
|
|
4833
|
-
i.push(D);
|
|
4834
|
-
}
|
|
4835
|
-
if (b.startsWith("multipart/form-data") || b.startsWith("application/x-www-form-urlencoded")) {
|
|
4836
|
-
const D = ye("form", S, a);
|
|
4837
|
-
i.push(D);
|
|
4838
|
-
}
|
|
4839
|
-
}
|
|
4840
|
-
}
|
|
4841
|
-
const c = t ? Array.isArray(t) ? t : [t] : [];
|
|
4842
|
-
return this.on(
|
|
4843
|
-
[n.method],
|
|
4844
|
-
n.path.replaceAll(/\/{(.+?)}/g, "/:$1"),
|
|
4845
|
-
...c,
|
|
4846
|
-
...i,
|
|
4847
|
-
s
|
|
4848
|
-
), this;
|
|
4849
|
-
});
|
|
4850
|
-
p(this, "getOpenAPIDocument", (t) => new qr(this.openAPIRegistry.definitions).generateDocument(t));
|
|
4851
|
-
p(this, "getOpenAPI31Document", (t) => new Fr(this.openAPIRegistry.definitions).generateDocument(t));
|
|
4852
|
-
p(this, "doc", (t, n) => this.get(t, (s) => {
|
|
4853
|
-
const a = typeof n == "function" ? n(s) : n;
|
|
4854
|
-
try {
|
|
4855
|
-
const i = this.getOpenAPIDocument(a);
|
|
4856
|
-
return s.json(i);
|
|
4857
|
-
} catch (i) {
|
|
4858
|
-
return s.json(i, 500);
|
|
4859
|
-
}
|
|
4860
|
-
}));
|
|
4861
|
-
p(this, "doc31", (t, n) => this.get(t, (s) => {
|
|
4862
|
-
const a = typeof n == "function" ? n(s) : n;
|
|
4863
|
-
try {
|
|
4864
|
-
const i = this.getOpenAPI31Document(a);
|
|
4865
|
-
return s.json(i);
|
|
4866
|
-
} catch (i) {
|
|
4867
|
-
return s.json(i, 500);
|
|
4868
|
-
}
|
|
4869
|
-
}));
|
|
4870
|
-
this.openAPIRegistry = new Tr(), this.defaultHook = t == null ? void 0 : t.defaultHook;
|
|
4871
|
-
}
|
|
4872
|
-
route(t, n) {
|
|
4873
|
-
const s = t.replaceAll(/:([^\/]+)/g, "{$1}");
|
|
4874
|
-
return super.route(t, n), n instanceof Nt ? (n.openAPIRegistry.definitions.forEach((a) => {
|
|
4875
|
-
switch (a.type) {
|
|
4876
|
-
case "component":
|
|
4877
|
-
return this.openAPIRegistry.registerComponent(a.componentType, a.name, a.component);
|
|
4878
|
-
case "route":
|
|
4879
|
-
return this.openAPIRegistry.registerPath({
|
|
4880
|
-
...a.route,
|
|
4881
|
-
path: le(s, a.route.path)
|
|
4882
|
-
});
|
|
4883
|
-
case "webhook":
|
|
4884
|
-
return this.openAPIRegistry.registerWebhook({
|
|
4885
|
-
...a.webhook,
|
|
4886
|
-
path: le(s, a.webhook.path)
|
|
4887
|
-
});
|
|
4888
|
-
case "schema":
|
|
4889
|
-
return this.openAPIRegistry.register(a.schema._def.openapi._internal.refId, a.schema);
|
|
4890
|
-
case "parameter":
|
|
4891
|
-
return this.openAPIRegistry.registerParameter(
|
|
4892
|
-
a.schema._def.openapi._internal.refId,
|
|
4893
|
-
a.schema
|
|
4894
|
-
);
|
|
4895
|
-
default: {
|
|
4896
|
-
const i = a;
|
|
4897
|
-
throw new Error(`Unknown registry type: ${i}`);
|
|
4898
|
-
}
|
|
4899
|
-
}
|
|
4900
|
-
}), this) : this;
|
|
4901
|
-
}
|
|
4902
|
-
basePath(t) {
|
|
4903
|
-
return new Nt({ ...super.basePath(t), defaultHook: this.defaultHook });
|
|
4904
|
-
}
|
|
4905
|
-
};
|
|
4906
|
-
wr(Ps);
|
|
4907
|
-
function Ns() {
|
|
4908
|
-
new Cs().get("/test", (e) => e.text("Hello, world!"));
|
|
4909
|
-
}
|
|
4910
|
-
export {
|
|
4911
|
-
Ns as init
|
|
4912
|
-
};
|