@windrun-huaiin/backend-core 10.0.1
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/LICENSE +21 -0
- package/dist/app/api/stripe/checkout/route.d.ts +19 -0
- package/dist/app/api/stripe/checkout/route.d.ts.map +1 -0
- package/dist/app/api/stripe/checkout/route.js +120 -0
- package/dist/app/api/stripe/checkout/route.mjs +118 -0
- package/dist/app/api/stripe/customer-portal/route.d.ts +11 -0
- package/dist/app/api/stripe/customer-portal/route.d.ts.map +1 -0
- package/dist/app/api/stripe/customer-portal/route.js +73 -0
- package/dist/app/api/stripe/customer-portal/route.mjs +71 -0
- package/dist/app/api/user/anonymous/init/route.d.ts +7 -0
- package/dist/app/api/user/anonymous/init/route.d.ts.map +1 -0
- package/dist/app/api/user/anonymous/init/route.js +210 -0
- package/dist/app/api/user/anonymous/init/route.mjs +208 -0
- package/dist/app/api/webhook/clerk/user/route.d.ts +7 -0
- package/dist/app/api/webhook/clerk/user/route.d.ts.map +1 -0
- package/dist/app/api/webhook/clerk/user/route.js +202 -0
- package/dist/app/api/webhook/clerk/user/route.mjs +200 -0
- package/dist/app/api/webhook/stripe/route.d.ts +8 -0
- package/dist/app/api/webhook/stripe/route.d.ts.map +1 -0
- package/dist/app/api/webhook/stripe/route.js +70 -0
- package/dist/app/api/webhook/stripe/route.mjs +67 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -0
- package/dist/index.mjs +18 -0
- package/dist/lib/auth-utils.d.ts +46 -0
- package/dist/lib/auth-utils.d.ts.map +1 -0
- package/dist/lib/auth-utils.js +107 -0
- package/dist/lib/auth-utils.mjs +102 -0
- package/dist/lib/credit-init.d.ts +8 -0
- package/dist/lib/credit-init.d.ts.map +1 -0
- package/dist/lib/credit-init.js +16 -0
- package/dist/lib/credit-init.mjs +10 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +31 -0
- package/dist/lib/index.mjs +4 -0
- package/dist/lib/money-price-config.d.ts +51 -0
- package/dist/lib/money-price-config.d.ts.map +1 -0
- package/dist/lib/money-price-config.js +156 -0
- package/dist/lib/money-price-config.mjs +151 -0
- package/dist/lib/stripe-config.d.ts +31 -0
- package/dist/lib/stripe-config.d.ts.map +1 -0
- package/dist/lib/stripe-config.js +278 -0
- package/dist/lib/stripe-config.mjs +268 -0
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js +48 -0
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs +45 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.js +54 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.mjs +51 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.js +44 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.mjs +35 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.js +31 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.mjs +18 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.js +587 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.mjs +527 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.js +447 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.mjs +399 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.js +245 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.mjs +232 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.js +68 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.mjs +62 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.js +39 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.mjs +37 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.js +80 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.mjs +75 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.js +101 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.mjs +86 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.js +102 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.mjs +76 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.js +56 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.mjs +52 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.js +1205 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.mjs +1157 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.js +407 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.mjs +374 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.js +9 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.mjs +7 -0
- package/dist/prisma/client.d.ts +2 -0
- package/dist/prisma/client.d.ts.map +1 -0
- package/dist/prisma/client.js +12 -0
- package/dist/prisma/client.mjs +1 -0
- package/dist/prisma/index.d.ts +4 -0
- package/dist/prisma/index.d.ts.map +1 -0
- package/dist/prisma/index.js +10 -0
- package/dist/prisma/index.mjs +2 -0
- package/dist/prisma/prisma-transaction-util.d.ts +3 -0
- package/dist/prisma/prisma-transaction-util.d.ts.map +1 -0
- package/dist/prisma/prisma-transaction-util.js +29 -0
- package/dist/prisma/prisma-transaction-util.mjs +27 -0
- package/dist/prisma/prisma.d.ts +4 -0
- package/dist/prisma/prisma.d.ts.map +1 -0
- package/dist/prisma/prisma.js +109 -0
- package/dist/prisma/prisma.mjs +106 -0
- package/dist/services/aggregate/billing.aggregate.service.d.ts +83 -0
- package/dist/services/aggregate/billing.aggregate.service.d.ts.map +1 -0
- package/dist/services/aggregate/billing.aggregate.service.js +308 -0
- package/dist/services/aggregate/billing.aggregate.service.mjs +306 -0
- package/dist/services/aggregate/index.d.ts +3 -0
- package/dist/services/aggregate/index.d.ts.map +1 -0
- package/dist/services/aggregate/index.js +9 -0
- package/dist/services/aggregate/index.mjs +2 -0
- package/dist/services/aggregate/user.aggregate.service.d.ts +34 -0
- package/dist/services/aggregate/user.aggregate.service.d.ts.map +1 -0
- package/dist/services/aggregate/user.aggregate.service.js +136 -0
- package/dist/services/aggregate/user.aggregate.service.mjs +133 -0
- package/dist/services/context/index.d.ts +2 -0
- package/dist/services/context/index.d.ts.map +1 -0
- package/dist/services/context/index.js +13 -0
- package/dist/services/context/index.mjs +1 -0
- package/dist/services/context/user-context-service.d.ts +30 -0
- package/dist/services/context/user-context-service.d.ts.map +1 -0
- package/dist/services/context/user-context-service.js +170 -0
- package/dist/services/context/user-context-service.mjs +162 -0
- package/dist/services/database/apilog.service.d.ts +39 -0
- package/dist/services/database/apilog.service.d.ts.map +1 -0
- package/dist/services/database/apilog.service.js +174 -0
- package/dist/services/database/apilog.service.mjs +170 -0
- package/dist/services/database/constants.d.ts +73 -0
- package/dist/services/database/constants.d.ts.map +1 -0
- package/dist/services/database/constants.js +135 -0
- package/dist/services/database/constants.mjs +117 -0
- package/dist/services/database/credit.service.d.ts +107 -0
- package/dist/services/database/credit.service.d.ts.map +1 -0
- package/dist/services/database/credit.service.js +515 -0
- package/dist/services/database/credit.service.mjs +512 -0
- package/dist/services/database/creditAuditLog.service.d.ts +73 -0
- package/dist/services/database/creditAuditLog.service.d.ts.map +1 -0
- package/dist/services/database/creditAuditLog.service.js +305 -0
- package/dist/services/database/creditAuditLog.service.mjs +302 -0
- package/dist/services/database/index.d.ts +10 -0
- package/dist/services/database/index.d.ts.map +1 -0
- package/dist/services/database/index.js +38 -0
- package/dist/services/database/index.mjs +8 -0
- package/dist/services/database/prisma-model-type.d.ts +3 -0
- package/dist/services/database/prisma-model-type.d.ts.map +1 -0
- package/dist/services/database/subscription.service.d.ts +48 -0
- package/dist/services/database/subscription.service.d.ts.map +1 -0
- package/dist/services/database/subscription.service.js +267 -0
- package/dist/services/database/subscription.service.mjs +264 -0
- package/dist/services/database/transaction.service.d.ts +92 -0
- package/dist/services/database/transaction.service.d.ts.map +1 -0
- package/dist/services/database/transaction.service.js +326 -0
- package/dist/services/database/transaction.service.mjs +323 -0
- package/dist/services/database/user.service.d.ts +45 -0
- package/dist/services/database/user.service.d.ts.map +1 -0
- package/dist/services/database/user.service.js +180 -0
- package/dist/services/database/user.service.mjs +177 -0
- package/dist/services/database/userBackup.service.d.ts +45 -0
- package/dist/services/database/userBackup.service.d.ts.map +1 -0
- package/dist/services/database/userBackup.service.js +249 -0
- package/dist/services/database/userBackup.service.mjs +246 -0
- package/dist/services/stripe/index.d.ts +2 -0
- package/dist/services/stripe/index.d.ts.map +1 -0
- package/dist/services/stripe/index.js +7 -0
- package/dist/services/stripe/index.mjs +1 -0
- package/dist/services/stripe/webhook-handler.d.ts +6 -0
- package/dist/services/stripe/webhook-handler.d.ts.map +1 -0
- package/dist/services/stripe/webhook-handler.js +537 -0
- package/dist/services/stripe/webhook-handler.mjs +535 -0
- package/migrations/create.sql +176 -0
- package/migrations/db.init.sql +13 -0
- package/migrations/init-schema.sql +19 -0
- package/migrations/purge.sql +27 -0
- package/migrations/test-check.sql +167 -0
- package/package.json +123 -0
- package/prisma/schema.prisma +191 -0
- package/src/app/api/stripe/checkout/route.ts +145 -0
- package/src/app/api/stripe/customer-portal/route.ts +83 -0
- package/src/app/api/user/anonymous/init/route.ts +284 -0
- package/src/app/api/webhook/clerk/user/route.ts +249 -0
- package/src/app/api/webhook/stripe/route.ts +93 -0
- package/src/index.ts +6 -0
- package/src/lib/auth-utils.ts +101 -0
- package/src/lib/credit-init.ts +9 -0
- package/src/lib/index.ts +4 -0
- package/src/lib/money-price-config.ts +168 -0
- package/src/lib/stripe-config.ts +333 -0
- package/src/prisma/client.ts +2 -0
- package/src/prisma/index.ts +3 -0
- package/src/prisma/prisma-transaction-util.ts +24 -0
- package/src/prisma/prisma.ts +122 -0
- package/src/services/aggregate/billing.aggregate.service.ts +498 -0
- package/src/services/aggregate/index.ts +2 -0
- package/src/services/aggregate/user.aggregate.service.ts +168 -0
- package/src/services/context/index.ts +1 -0
- package/src/services/context/user-context-service.ts +200 -0
- package/src/services/database/apilog.service.ts +185 -0
- package/src/services/database/constants.ts +148 -0
- package/src/services/database/credit.service.ts +747 -0
- package/src/services/database/creditAuditLog.service.ts +402 -0
- package/src/services/database/index.ts +41 -0
- package/src/services/database/prisma-model-type.ts +13 -0
- package/src/services/database/subscription.service.ts +319 -0
- package/src/services/database/transaction.service.ts +447 -0
- package/src/services/database/user.service.ts +218 -0
- package/src/services/database/userBackup.service.ts +290 -0
- package/src/services/stripe/index.ts +1 -0
- package/src/services/stripe/webhook-handler.ts +648 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// functions
|
|
4
|
+
function getEnumValues(entries) {
|
|
5
|
+
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
6
|
+
const values = Object.entries(entries)
|
|
7
|
+
.filter(([k, _]) => numericValues.indexOf(+k) === -1)
|
|
8
|
+
.map(([_, v]) => v);
|
|
9
|
+
return values;
|
|
10
|
+
}
|
|
11
|
+
function jsonStringifyReplacer(_, value) {
|
|
12
|
+
if (typeof value === "bigint")
|
|
13
|
+
return value.toString();
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function cached(getter) {
|
|
17
|
+
return {
|
|
18
|
+
get value() {
|
|
19
|
+
{
|
|
20
|
+
const value = getter();
|
|
21
|
+
Object.defineProperty(this, "value", { value });
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function nullish(input) {
|
|
28
|
+
return input === null || input === undefined;
|
|
29
|
+
}
|
|
30
|
+
function cleanRegex(source) {
|
|
31
|
+
const start = source.startsWith("^") ? 1 : 0;
|
|
32
|
+
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
33
|
+
return source.slice(start, end);
|
|
34
|
+
}
|
|
35
|
+
const EVALUATING = Symbol("evaluating");
|
|
36
|
+
function defineLazy(object, key, getter) {
|
|
37
|
+
let value = undefined;
|
|
38
|
+
Object.defineProperty(object, key, {
|
|
39
|
+
get() {
|
|
40
|
+
if (value === EVALUATING) {
|
|
41
|
+
// Circular reference detected, return undefined to break the cycle
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
if (value === undefined) {
|
|
45
|
+
value = EVALUATING;
|
|
46
|
+
value = getter();
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
},
|
|
50
|
+
set(v) {
|
|
51
|
+
Object.defineProperty(object, key, {
|
|
52
|
+
value: v,
|
|
53
|
+
// configurable: true,
|
|
54
|
+
});
|
|
55
|
+
// object[key] = v;
|
|
56
|
+
},
|
|
57
|
+
configurable: true,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function assignProp(target, prop, value) {
|
|
61
|
+
Object.defineProperty(target, prop, {
|
|
62
|
+
value,
|
|
63
|
+
writable: true,
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function mergeDefs(...defs) {
|
|
69
|
+
const mergedDescriptors = {};
|
|
70
|
+
for (const def of defs) {
|
|
71
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
72
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
73
|
+
}
|
|
74
|
+
return Object.defineProperties({}, mergedDescriptors);
|
|
75
|
+
}
|
|
76
|
+
function esc(str) {
|
|
77
|
+
return JSON.stringify(str);
|
|
78
|
+
}
|
|
79
|
+
const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
|
|
80
|
+
function isObject(data) {
|
|
81
|
+
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
82
|
+
}
|
|
83
|
+
const allowsEval = cached(() => {
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const F = Function;
|
|
90
|
+
new F("");
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
catch (_) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
function isPlainObject(o) {
|
|
98
|
+
if (isObject(o) === false)
|
|
99
|
+
return false;
|
|
100
|
+
// modified constructor
|
|
101
|
+
const ctor = o.constructor;
|
|
102
|
+
if (ctor === undefined)
|
|
103
|
+
return true;
|
|
104
|
+
// modified prototype
|
|
105
|
+
const prot = ctor.prototype;
|
|
106
|
+
if (isObject(prot) === false)
|
|
107
|
+
return false;
|
|
108
|
+
// ctor doesn't have static `isPrototypeOf`
|
|
109
|
+
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
function shallowClone(o) {
|
|
115
|
+
if (isPlainObject(o))
|
|
116
|
+
return { ...o };
|
|
117
|
+
if (Array.isArray(o))
|
|
118
|
+
return [...o];
|
|
119
|
+
return o;
|
|
120
|
+
}
|
|
121
|
+
const propertyKeyTypes = new Set(["string", "number", "symbol"]);
|
|
122
|
+
function escapeRegex(str) {
|
|
123
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
124
|
+
}
|
|
125
|
+
// zod-specific utils
|
|
126
|
+
function clone(inst, def, params) {
|
|
127
|
+
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
128
|
+
if (!def || params?.parent)
|
|
129
|
+
cl._zod.parent = inst;
|
|
130
|
+
return cl;
|
|
131
|
+
}
|
|
132
|
+
function normalizeParams(_params) {
|
|
133
|
+
const params = _params;
|
|
134
|
+
if (!params)
|
|
135
|
+
return {};
|
|
136
|
+
if (typeof params === "string")
|
|
137
|
+
return { error: () => params };
|
|
138
|
+
if (params?.message !== undefined) {
|
|
139
|
+
if (params?.error !== undefined)
|
|
140
|
+
throw new Error("Cannot specify both `message` and `error` params");
|
|
141
|
+
params.error = params.message;
|
|
142
|
+
}
|
|
143
|
+
delete params.message;
|
|
144
|
+
if (typeof params.error === "string")
|
|
145
|
+
return { ...params, error: () => params.error };
|
|
146
|
+
return params;
|
|
147
|
+
}
|
|
148
|
+
function optionalKeys(shape) {
|
|
149
|
+
return Object.keys(shape).filter((k) => {
|
|
150
|
+
return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function pick(schema, mask) {
|
|
154
|
+
const currDef = schema._zod.def;
|
|
155
|
+
const def = mergeDefs(schema._zod.def, {
|
|
156
|
+
get shape() {
|
|
157
|
+
const newShape = {};
|
|
158
|
+
for (const key in mask) {
|
|
159
|
+
if (!(key in currDef.shape)) {
|
|
160
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
161
|
+
}
|
|
162
|
+
if (!mask[key])
|
|
163
|
+
continue;
|
|
164
|
+
newShape[key] = currDef.shape[key];
|
|
165
|
+
}
|
|
166
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
167
|
+
return newShape;
|
|
168
|
+
},
|
|
169
|
+
checks: [],
|
|
170
|
+
});
|
|
171
|
+
return clone(schema, def);
|
|
172
|
+
}
|
|
173
|
+
function omit(schema, mask) {
|
|
174
|
+
const currDef = schema._zod.def;
|
|
175
|
+
const def = mergeDefs(schema._zod.def, {
|
|
176
|
+
get shape() {
|
|
177
|
+
const newShape = { ...schema._zod.def.shape };
|
|
178
|
+
for (const key in mask) {
|
|
179
|
+
if (!(key in currDef.shape)) {
|
|
180
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
181
|
+
}
|
|
182
|
+
if (!mask[key])
|
|
183
|
+
continue;
|
|
184
|
+
delete newShape[key];
|
|
185
|
+
}
|
|
186
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
187
|
+
return newShape;
|
|
188
|
+
},
|
|
189
|
+
checks: [],
|
|
190
|
+
});
|
|
191
|
+
return clone(schema, def);
|
|
192
|
+
}
|
|
193
|
+
function extend(schema, shape) {
|
|
194
|
+
if (!isPlainObject(shape)) {
|
|
195
|
+
throw new Error("Invalid input to extend: expected a plain object");
|
|
196
|
+
}
|
|
197
|
+
const checks = schema._zod.def.checks;
|
|
198
|
+
const hasChecks = checks && checks.length > 0;
|
|
199
|
+
if (hasChecks) {
|
|
200
|
+
throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
|
|
201
|
+
}
|
|
202
|
+
const def = mergeDefs(schema._zod.def, {
|
|
203
|
+
get shape() {
|
|
204
|
+
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
205
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
206
|
+
return _shape;
|
|
207
|
+
},
|
|
208
|
+
checks: [],
|
|
209
|
+
});
|
|
210
|
+
return clone(schema, def);
|
|
211
|
+
}
|
|
212
|
+
function safeExtend(schema, shape) {
|
|
213
|
+
if (!isPlainObject(shape)) {
|
|
214
|
+
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
215
|
+
}
|
|
216
|
+
const def = {
|
|
217
|
+
...schema._zod.def,
|
|
218
|
+
get shape() {
|
|
219
|
+
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
220
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
221
|
+
return _shape;
|
|
222
|
+
},
|
|
223
|
+
checks: schema._zod.def.checks,
|
|
224
|
+
};
|
|
225
|
+
return clone(schema, def);
|
|
226
|
+
}
|
|
227
|
+
function merge(a, b) {
|
|
228
|
+
const def = mergeDefs(a._zod.def, {
|
|
229
|
+
get shape() {
|
|
230
|
+
const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
|
|
231
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
232
|
+
return _shape;
|
|
233
|
+
},
|
|
234
|
+
get catchall() {
|
|
235
|
+
return b._zod.def.catchall;
|
|
236
|
+
},
|
|
237
|
+
checks: [], // delete existing checks
|
|
238
|
+
});
|
|
239
|
+
return clone(a, def);
|
|
240
|
+
}
|
|
241
|
+
function partial(Class, schema, mask) {
|
|
242
|
+
const def = mergeDefs(schema._zod.def, {
|
|
243
|
+
get shape() {
|
|
244
|
+
const oldShape = schema._zod.def.shape;
|
|
245
|
+
const shape = { ...oldShape };
|
|
246
|
+
if (mask) {
|
|
247
|
+
for (const key in mask) {
|
|
248
|
+
if (!(key in oldShape)) {
|
|
249
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
250
|
+
}
|
|
251
|
+
if (!mask[key])
|
|
252
|
+
continue;
|
|
253
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
254
|
+
shape[key] = Class
|
|
255
|
+
? new Class({
|
|
256
|
+
type: "optional",
|
|
257
|
+
innerType: oldShape[key],
|
|
258
|
+
})
|
|
259
|
+
: oldShape[key];
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
for (const key in oldShape) {
|
|
264
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
265
|
+
shape[key] = Class
|
|
266
|
+
? new Class({
|
|
267
|
+
type: "optional",
|
|
268
|
+
innerType: oldShape[key],
|
|
269
|
+
})
|
|
270
|
+
: oldShape[key];
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
assignProp(this, "shape", shape); // self-caching
|
|
274
|
+
return shape;
|
|
275
|
+
},
|
|
276
|
+
checks: [],
|
|
277
|
+
});
|
|
278
|
+
return clone(schema, def);
|
|
279
|
+
}
|
|
280
|
+
function required(Class, schema, mask) {
|
|
281
|
+
const def = mergeDefs(schema._zod.def, {
|
|
282
|
+
get shape() {
|
|
283
|
+
const oldShape = schema._zod.def.shape;
|
|
284
|
+
const shape = { ...oldShape };
|
|
285
|
+
if (mask) {
|
|
286
|
+
for (const key in mask) {
|
|
287
|
+
if (!(key in shape)) {
|
|
288
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
289
|
+
}
|
|
290
|
+
if (!mask[key])
|
|
291
|
+
continue;
|
|
292
|
+
// overwrite with non-optional
|
|
293
|
+
shape[key] = new Class({
|
|
294
|
+
type: "nonoptional",
|
|
295
|
+
innerType: oldShape[key],
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
for (const key in oldShape) {
|
|
301
|
+
// overwrite with non-optional
|
|
302
|
+
shape[key] = new Class({
|
|
303
|
+
type: "nonoptional",
|
|
304
|
+
innerType: oldShape[key],
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
assignProp(this, "shape", shape); // self-caching
|
|
309
|
+
return shape;
|
|
310
|
+
},
|
|
311
|
+
checks: [],
|
|
312
|
+
});
|
|
313
|
+
return clone(schema, def);
|
|
314
|
+
}
|
|
315
|
+
// invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
|
|
316
|
+
function aborted(x, startIndex = 0) {
|
|
317
|
+
if (x.aborted === true)
|
|
318
|
+
return true;
|
|
319
|
+
for (let i = startIndex; i < x.issues.length; i++) {
|
|
320
|
+
if (x.issues[i]?.continue !== true) {
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
function prefixIssues(path, issues) {
|
|
327
|
+
return issues.map((iss) => {
|
|
328
|
+
var _a;
|
|
329
|
+
(_a = iss).path ?? (_a.path = []);
|
|
330
|
+
iss.path.unshift(path);
|
|
331
|
+
return iss;
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
function unwrapMessage(message) {
|
|
335
|
+
return typeof message === "string" ? message : message?.message;
|
|
336
|
+
}
|
|
337
|
+
function finalizeIssue(iss, ctx, config) {
|
|
338
|
+
const full = { ...iss, path: iss.path ?? [] };
|
|
339
|
+
// for backwards compatibility
|
|
340
|
+
if (!iss.message) {
|
|
341
|
+
const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
|
|
342
|
+
unwrapMessage(ctx?.error?.(iss)) ??
|
|
343
|
+
unwrapMessage(config.customError?.(iss)) ??
|
|
344
|
+
unwrapMessage(config.localeError?.(iss)) ??
|
|
345
|
+
"Invalid input";
|
|
346
|
+
full.message = message;
|
|
347
|
+
}
|
|
348
|
+
// delete (full as any).def;
|
|
349
|
+
delete full.inst;
|
|
350
|
+
delete full.continue;
|
|
351
|
+
if (!ctx?.reportInput) {
|
|
352
|
+
delete full.input;
|
|
353
|
+
}
|
|
354
|
+
return full;
|
|
355
|
+
}
|
|
356
|
+
function getLengthableOrigin(input) {
|
|
357
|
+
if (Array.isArray(input))
|
|
358
|
+
return "array";
|
|
359
|
+
if (typeof input === "string")
|
|
360
|
+
return "string";
|
|
361
|
+
return "unknown";
|
|
362
|
+
}
|
|
363
|
+
function issue(...args) {
|
|
364
|
+
const [iss, input, inst] = args;
|
|
365
|
+
if (typeof iss === "string") {
|
|
366
|
+
return {
|
|
367
|
+
message: iss,
|
|
368
|
+
code: "custom",
|
|
369
|
+
input,
|
|
370
|
+
inst,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
return { ...iss };
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
exports.aborted = aborted;
|
|
377
|
+
exports.allowsEval = allowsEval;
|
|
378
|
+
exports.assignProp = assignProp;
|
|
379
|
+
exports.cached = cached;
|
|
380
|
+
exports.captureStackTrace = captureStackTrace;
|
|
381
|
+
exports.cleanRegex = cleanRegex;
|
|
382
|
+
exports.clone = clone;
|
|
383
|
+
exports.defineLazy = defineLazy;
|
|
384
|
+
exports.esc = esc;
|
|
385
|
+
exports.escapeRegex = escapeRegex;
|
|
386
|
+
exports.extend = extend;
|
|
387
|
+
exports.finalizeIssue = finalizeIssue;
|
|
388
|
+
exports.getEnumValues = getEnumValues;
|
|
389
|
+
exports.getLengthableOrigin = getLengthableOrigin;
|
|
390
|
+
exports.isObject = isObject;
|
|
391
|
+
exports.isPlainObject = isPlainObject;
|
|
392
|
+
exports.issue = issue;
|
|
393
|
+
exports.jsonStringifyReplacer = jsonStringifyReplacer;
|
|
394
|
+
exports.merge = merge;
|
|
395
|
+
exports.mergeDefs = mergeDefs;
|
|
396
|
+
exports.normalizeParams = normalizeParams;
|
|
397
|
+
exports.nullish = nullish;
|
|
398
|
+
exports.omit = omit;
|
|
399
|
+
exports.optionalKeys = optionalKeys;
|
|
400
|
+
exports.partial = partial;
|
|
401
|
+
exports.pick = pick;
|
|
402
|
+
exports.prefixIssues = prefixIssues;
|
|
403
|
+
exports.propertyKeyTypes = propertyKeyTypes;
|
|
404
|
+
exports.required = required;
|
|
405
|
+
exports.safeExtend = safeExtend;
|
|
406
|
+
exports.shallowClone = shallowClone;
|
|
407
|
+
exports.unwrapMessage = unwrapMessage;
|