@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.
Files changed (198) hide show
  1. package/LICENSE +21 -0
  2. package/dist/app/api/stripe/checkout/route.d.ts +19 -0
  3. package/dist/app/api/stripe/checkout/route.d.ts.map +1 -0
  4. package/dist/app/api/stripe/checkout/route.js +120 -0
  5. package/dist/app/api/stripe/checkout/route.mjs +118 -0
  6. package/dist/app/api/stripe/customer-portal/route.d.ts +11 -0
  7. package/dist/app/api/stripe/customer-portal/route.d.ts.map +1 -0
  8. package/dist/app/api/stripe/customer-portal/route.js +73 -0
  9. package/dist/app/api/stripe/customer-portal/route.mjs +71 -0
  10. package/dist/app/api/user/anonymous/init/route.d.ts +7 -0
  11. package/dist/app/api/user/anonymous/init/route.d.ts.map +1 -0
  12. package/dist/app/api/user/anonymous/init/route.js +210 -0
  13. package/dist/app/api/user/anonymous/init/route.mjs +208 -0
  14. package/dist/app/api/webhook/clerk/user/route.d.ts +7 -0
  15. package/dist/app/api/webhook/clerk/user/route.d.ts.map +1 -0
  16. package/dist/app/api/webhook/clerk/user/route.js +202 -0
  17. package/dist/app/api/webhook/clerk/user/route.mjs +200 -0
  18. package/dist/app/api/webhook/stripe/route.d.ts +8 -0
  19. package/dist/app/api/webhook/stripe/route.d.ts.map +1 -0
  20. package/dist/app/api/webhook/stripe/route.js +70 -0
  21. package/dist/app/api/webhook/stripe/route.mjs +67 -0
  22. package/dist/index.d.ts +7 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +83 -0
  25. package/dist/index.mjs +18 -0
  26. package/dist/lib/auth-utils.d.ts +46 -0
  27. package/dist/lib/auth-utils.d.ts.map +1 -0
  28. package/dist/lib/auth-utils.js +107 -0
  29. package/dist/lib/auth-utils.mjs +102 -0
  30. package/dist/lib/credit-init.d.ts +8 -0
  31. package/dist/lib/credit-init.d.ts.map +1 -0
  32. package/dist/lib/credit-init.js +16 -0
  33. package/dist/lib/credit-init.mjs +10 -0
  34. package/dist/lib/index.d.ts +5 -0
  35. package/dist/lib/index.d.ts.map +1 -0
  36. package/dist/lib/index.js +31 -0
  37. package/dist/lib/index.mjs +4 -0
  38. package/dist/lib/money-price-config.d.ts +51 -0
  39. package/dist/lib/money-price-config.d.ts.map +1 -0
  40. package/dist/lib/money-price-config.js +156 -0
  41. package/dist/lib/money-price-config.mjs +151 -0
  42. package/dist/lib/stripe-config.d.ts +31 -0
  43. package/dist/lib/stripe-config.d.ts.map +1 -0
  44. package/dist/lib/stripe-config.js +278 -0
  45. package/dist/lib/stripe-config.mjs +268 -0
  46. 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
  47. 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
  48. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.js +54 -0
  49. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.mjs +51 -0
  50. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.js +44 -0
  51. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.mjs +35 -0
  52. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.js +31 -0
  53. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.mjs +18 -0
  54. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.js +587 -0
  55. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.mjs +527 -0
  56. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.js +447 -0
  57. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.mjs +399 -0
  58. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.js +245 -0
  59. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.mjs +232 -0
  60. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.js +68 -0
  61. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.mjs +62 -0
  62. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.js +39 -0
  63. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.mjs +37 -0
  64. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.js +80 -0
  65. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.mjs +75 -0
  66. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.js +101 -0
  67. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.mjs +86 -0
  68. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.js +102 -0
  69. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.mjs +76 -0
  70. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.js +56 -0
  71. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.mjs +52 -0
  72. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.js +1205 -0
  73. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.mjs +1157 -0
  74. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.js +407 -0
  75. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.mjs +374 -0
  76. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.js +9 -0
  77. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.mjs +7 -0
  78. package/dist/prisma/client.d.ts +2 -0
  79. package/dist/prisma/client.d.ts.map +1 -0
  80. package/dist/prisma/client.js +12 -0
  81. package/dist/prisma/client.mjs +1 -0
  82. package/dist/prisma/index.d.ts +4 -0
  83. package/dist/prisma/index.d.ts.map +1 -0
  84. package/dist/prisma/index.js +10 -0
  85. package/dist/prisma/index.mjs +2 -0
  86. package/dist/prisma/prisma-transaction-util.d.ts +3 -0
  87. package/dist/prisma/prisma-transaction-util.d.ts.map +1 -0
  88. package/dist/prisma/prisma-transaction-util.js +29 -0
  89. package/dist/prisma/prisma-transaction-util.mjs +27 -0
  90. package/dist/prisma/prisma.d.ts +4 -0
  91. package/dist/prisma/prisma.d.ts.map +1 -0
  92. package/dist/prisma/prisma.js +109 -0
  93. package/dist/prisma/prisma.mjs +106 -0
  94. package/dist/services/aggregate/billing.aggregate.service.d.ts +83 -0
  95. package/dist/services/aggregate/billing.aggregate.service.d.ts.map +1 -0
  96. package/dist/services/aggregate/billing.aggregate.service.js +308 -0
  97. package/dist/services/aggregate/billing.aggregate.service.mjs +306 -0
  98. package/dist/services/aggregate/index.d.ts +3 -0
  99. package/dist/services/aggregate/index.d.ts.map +1 -0
  100. package/dist/services/aggregate/index.js +9 -0
  101. package/dist/services/aggregate/index.mjs +2 -0
  102. package/dist/services/aggregate/user.aggregate.service.d.ts +34 -0
  103. package/dist/services/aggregate/user.aggregate.service.d.ts.map +1 -0
  104. package/dist/services/aggregate/user.aggregate.service.js +136 -0
  105. package/dist/services/aggregate/user.aggregate.service.mjs +133 -0
  106. package/dist/services/context/index.d.ts +2 -0
  107. package/dist/services/context/index.d.ts.map +1 -0
  108. package/dist/services/context/index.js +13 -0
  109. package/dist/services/context/index.mjs +1 -0
  110. package/dist/services/context/user-context-service.d.ts +30 -0
  111. package/dist/services/context/user-context-service.d.ts.map +1 -0
  112. package/dist/services/context/user-context-service.js +170 -0
  113. package/dist/services/context/user-context-service.mjs +162 -0
  114. package/dist/services/database/apilog.service.d.ts +39 -0
  115. package/dist/services/database/apilog.service.d.ts.map +1 -0
  116. package/dist/services/database/apilog.service.js +174 -0
  117. package/dist/services/database/apilog.service.mjs +170 -0
  118. package/dist/services/database/constants.d.ts +73 -0
  119. package/dist/services/database/constants.d.ts.map +1 -0
  120. package/dist/services/database/constants.js +135 -0
  121. package/dist/services/database/constants.mjs +117 -0
  122. package/dist/services/database/credit.service.d.ts +107 -0
  123. package/dist/services/database/credit.service.d.ts.map +1 -0
  124. package/dist/services/database/credit.service.js +515 -0
  125. package/dist/services/database/credit.service.mjs +512 -0
  126. package/dist/services/database/creditAuditLog.service.d.ts +73 -0
  127. package/dist/services/database/creditAuditLog.service.d.ts.map +1 -0
  128. package/dist/services/database/creditAuditLog.service.js +305 -0
  129. package/dist/services/database/creditAuditLog.service.mjs +302 -0
  130. package/dist/services/database/index.d.ts +10 -0
  131. package/dist/services/database/index.d.ts.map +1 -0
  132. package/dist/services/database/index.js +38 -0
  133. package/dist/services/database/index.mjs +8 -0
  134. package/dist/services/database/prisma-model-type.d.ts +3 -0
  135. package/dist/services/database/prisma-model-type.d.ts.map +1 -0
  136. package/dist/services/database/subscription.service.d.ts +48 -0
  137. package/dist/services/database/subscription.service.d.ts.map +1 -0
  138. package/dist/services/database/subscription.service.js +267 -0
  139. package/dist/services/database/subscription.service.mjs +264 -0
  140. package/dist/services/database/transaction.service.d.ts +92 -0
  141. package/dist/services/database/transaction.service.d.ts.map +1 -0
  142. package/dist/services/database/transaction.service.js +326 -0
  143. package/dist/services/database/transaction.service.mjs +323 -0
  144. package/dist/services/database/user.service.d.ts +45 -0
  145. package/dist/services/database/user.service.d.ts.map +1 -0
  146. package/dist/services/database/user.service.js +180 -0
  147. package/dist/services/database/user.service.mjs +177 -0
  148. package/dist/services/database/userBackup.service.d.ts +45 -0
  149. package/dist/services/database/userBackup.service.d.ts.map +1 -0
  150. package/dist/services/database/userBackup.service.js +249 -0
  151. package/dist/services/database/userBackup.service.mjs +246 -0
  152. package/dist/services/stripe/index.d.ts +2 -0
  153. package/dist/services/stripe/index.d.ts.map +1 -0
  154. package/dist/services/stripe/index.js +7 -0
  155. package/dist/services/stripe/index.mjs +1 -0
  156. package/dist/services/stripe/webhook-handler.d.ts +6 -0
  157. package/dist/services/stripe/webhook-handler.d.ts.map +1 -0
  158. package/dist/services/stripe/webhook-handler.js +537 -0
  159. package/dist/services/stripe/webhook-handler.mjs +535 -0
  160. package/migrations/create.sql +176 -0
  161. package/migrations/db.init.sql +13 -0
  162. package/migrations/init-schema.sql +19 -0
  163. package/migrations/purge.sql +27 -0
  164. package/migrations/test-check.sql +167 -0
  165. package/package.json +123 -0
  166. package/prisma/schema.prisma +191 -0
  167. package/src/app/api/stripe/checkout/route.ts +145 -0
  168. package/src/app/api/stripe/customer-portal/route.ts +83 -0
  169. package/src/app/api/user/anonymous/init/route.ts +284 -0
  170. package/src/app/api/webhook/clerk/user/route.ts +249 -0
  171. package/src/app/api/webhook/stripe/route.ts +93 -0
  172. package/src/index.ts +6 -0
  173. package/src/lib/auth-utils.ts +101 -0
  174. package/src/lib/credit-init.ts +9 -0
  175. package/src/lib/index.ts +4 -0
  176. package/src/lib/money-price-config.ts +168 -0
  177. package/src/lib/stripe-config.ts +333 -0
  178. package/src/prisma/client.ts +2 -0
  179. package/src/prisma/index.ts +3 -0
  180. package/src/prisma/prisma-transaction-util.ts +24 -0
  181. package/src/prisma/prisma.ts +122 -0
  182. package/src/services/aggregate/billing.aggregate.service.ts +498 -0
  183. package/src/services/aggregate/index.ts +2 -0
  184. package/src/services/aggregate/user.aggregate.service.ts +168 -0
  185. package/src/services/context/index.ts +1 -0
  186. package/src/services/context/user-context-service.ts +200 -0
  187. package/src/services/database/apilog.service.ts +185 -0
  188. package/src/services/database/constants.ts +148 -0
  189. package/src/services/database/credit.service.ts +747 -0
  190. package/src/services/database/creditAuditLog.service.ts +402 -0
  191. package/src/services/database/index.ts +41 -0
  192. package/src/services/database/prisma-model-type.ts +13 -0
  193. package/src/services/database/subscription.service.ts +319 -0
  194. package/src/services/database/transaction.service.ts +447 -0
  195. package/src/services/database/user.service.ts +218 -0
  196. package/src/services/database/userBackup.service.ts +290 -0
  197. package/src/services/stripe/index.ts +1 -0
  198. package/src/services/stripe/webhook-handler.ts +648 -0
@@ -0,0 +1,1205 @@
1
+ 'use strict';
2
+
3
+ var checks = require('./checks.js');
4
+ var core = require('./core.js');
5
+ var doc = require('./doc.js');
6
+ var parse = require('./parse.js');
7
+ var regexes = require('./regexes.js');
8
+ var util = require('./util.js');
9
+ var versions = require('./versions.js');
10
+
11
+ const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def) => {
12
+ var _a;
13
+ inst ?? (inst = {});
14
+ inst._zod.def = def; // set _def property
15
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
16
+ inst._zod.version = versions.version;
17
+ const checks = [...(inst._zod.def.checks ?? [])];
18
+ // if inst is itself a checks.$ZodCheck, run it as a check
19
+ if (inst._zod.traits.has("$ZodCheck")) {
20
+ checks.unshift(inst);
21
+ }
22
+ for (const ch of checks) {
23
+ for (const fn of ch._zod.onattach) {
24
+ fn(inst);
25
+ }
26
+ }
27
+ if (checks.length === 0) {
28
+ // deferred initializer
29
+ // inst._zod.parse is not yet defined
30
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
31
+ inst._zod.deferred?.push(() => {
32
+ inst._zod.run = inst._zod.parse;
33
+ });
34
+ }
35
+ else {
36
+ const runChecks = (payload, checks, ctx) => {
37
+ let isAborted = util.aborted(payload);
38
+ let asyncResult;
39
+ for (const ch of checks) {
40
+ if (ch._zod.def.when) {
41
+ const shouldRun = ch._zod.def.when(payload);
42
+ if (!shouldRun)
43
+ continue;
44
+ }
45
+ else if (isAborted) {
46
+ continue;
47
+ }
48
+ const currLen = payload.issues.length;
49
+ const _ = ch._zod.check(payload);
50
+ if (_ instanceof Promise && ctx?.async === false) {
51
+ throw new core.$ZodAsyncError();
52
+ }
53
+ if (asyncResult || _ instanceof Promise) {
54
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
55
+ await _;
56
+ const nextLen = payload.issues.length;
57
+ if (nextLen === currLen)
58
+ return;
59
+ if (!isAborted)
60
+ isAborted = util.aborted(payload, currLen);
61
+ });
62
+ }
63
+ else {
64
+ const nextLen = payload.issues.length;
65
+ if (nextLen === currLen)
66
+ continue;
67
+ if (!isAborted)
68
+ isAborted = util.aborted(payload, currLen);
69
+ }
70
+ }
71
+ if (asyncResult) {
72
+ return asyncResult.then(() => {
73
+ return payload;
74
+ });
75
+ }
76
+ return payload;
77
+ };
78
+ // const handleChecksResult = (
79
+ // checkResult: ParsePayload,
80
+ // originalResult: ParsePayload,
81
+ // ctx: ParseContextInternal
82
+ // ): util.MaybeAsync<ParsePayload> => {
83
+ // // if the checks mutated the value && there are no issues, re-parse the result
84
+ // if (checkResult.value !== originalResult.value && !checkResult.issues.length)
85
+ // return inst._zod.parse(checkResult, ctx);
86
+ // return originalResult;
87
+ // };
88
+ const handleCanaryResult = (canary, payload, ctx) => {
89
+ // abort if the canary is aborted
90
+ if (util.aborted(canary)) {
91
+ canary.aborted = true;
92
+ return canary;
93
+ }
94
+ // run checks first, then
95
+ const checkResult = runChecks(payload, checks, ctx);
96
+ if (checkResult instanceof Promise) {
97
+ if (ctx.async === false)
98
+ throw new core.$ZodAsyncError();
99
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
100
+ }
101
+ return inst._zod.parse(checkResult, ctx);
102
+ };
103
+ inst._zod.run = (payload, ctx) => {
104
+ if (ctx.skipChecks) {
105
+ return inst._zod.parse(payload, ctx);
106
+ }
107
+ if (ctx.direction === "backward") {
108
+ // run canary
109
+ // initial pass (no checks)
110
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
111
+ if (canary instanceof Promise) {
112
+ return canary.then((canary) => {
113
+ return handleCanaryResult(canary, payload, ctx);
114
+ });
115
+ }
116
+ return handleCanaryResult(canary, payload, ctx);
117
+ }
118
+ // forward
119
+ const result = inst._zod.parse(payload, ctx);
120
+ if (result instanceof Promise) {
121
+ if (ctx.async === false)
122
+ throw new core.$ZodAsyncError();
123
+ return result.then((result) => runChecks(result, checks, ctx));
124
+ }
125
+ return runChecks(result, checks, ctx);
126
+ };
127
+ }
128
+ inst["~standard"] = {
129
+ validate: (value) => {
130
+ try {
131
+ const r = parse.safeParse(inst, value);
132
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
133
+ }
134
+ catch (_) {
135
+ return parse.safeParseAsync(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
136
+ }
137
+ },
138
+ vendor: "zod",
139
+ version: 1,
140
+ };
141
+ });
142
+ const $ZodString = /*@__PURE__*/ core.$constructor("$ZodString", (inst, def) => {
143
+ $ZodType.init(inst, def);
144
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? regexes.string(inst._zod.bag);
145
+ inst._zod.parse = (payload, _) => {
146
+ if (def.coerce)
147
+ try {
148
+ payload.value = String(payload.value);
149
+ }
150
+ catch (_) { }
151
+ if (typeof payload.value === "string")
152
+ return payload;
153
+ payload.issues.push({
154
+ expected: "string",
155
+ code: "invalid_type",
156
+ input: payload.value,
157
+ inst,
158
+ });
159
+ return payload;
160
+ };
161
+ });
162
+ const $ZodStringFormat = /*@__PURE__*/ core.$constructor("$ZodStringFormat", (inst, def) => {
163
+ // check initialization must come first
164
+ checks.$ZodCheckStringFormat.init(inst, def);
165
+ $ZodString.init(inst, def);
166
+ });
167
+ const $ZodGUID = /*@__PURE__*/ core.$constructor("$ZodGUID", (inst, def) => {
168
+ def.pattern ?? (def.pattern = regexes.guid);
169
+ $ZodStringFormat.init(inst, def);
170
+ });
171
+ const $ZodUUID = /*@__PURE__*/ core.$constructor("$ZodUUID", (inst, def) => {
172
+ if (def.version) {
173
+ const versionMap = {
174
+ v1: 1,
175
+ v2: 2,
176
+ v3: 3,
177
+ v4: 4,
178
+ v5: 5,
179
+ v6: 6,
180
+ v7: 7,
181
+ v8: 8,
182
+ };
183
+ const v = versionMap[def.version];
184
+ if (v === undefined)
185
+ throw new Error(`Invalid UUID version: "${def.version}"`);
186
+ def.pattern ?? (def.pattern = regexes.uuid(v));
187
+ }
188
+ else
189
+ def.pattern ?? (def.pattern = regexes.uuid());
190
+ $ZodStringFormat.init(inst, def);
191
+ });
192
+ const $ZodEmail = /*@__PURE__*/ core.$constructor("$ZodEmail", (inst, def) => {
193
+ def.pattern ?? (def.pattern = regexes.email);
194
+ $ZodStringFormat.init(inst, def);
195
+ });
196
+ const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) => {
197
+ $ZodStringFormat.init(inst, def);
198
+ inst._zod.check = (payload) => {
199
+ try {
200
+ // Trim whitespace from input
201
+ const trimmed = payload.value.trim();
202
+ // @ts-ignore
203
+ const url = new URL(trimmed);
204
+ if (def.hostname) {
205
+ def.hostname.lastIndex = 0;
206
+ if (!def.hostname.test(url.hostname)) {
207
+ payload.issues.push({
208
+ code: "invalid_format",
209
+ format: "url",
210
+ note: "Invalid hostname",
211
+ pattern: regexes.hostname.source,
212
+ input: payload.value,
213
+ inst,
214
+ continue: !def.abort,
215
+ });
216
+ }
217
+ }
218
+ if (def.protocol) {
219
+ def.protocol.lastIndex = 0;
220
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
221
+ payload.issues.push({
222
+ code: "invalid_format",
223
+ format: "url",
224
+ note: "Invalid protocol",
225
+ pattern: def.protocol.source,
226
+ input: payload.value,
227
+ inst,
228
+ continue: !def.abort,
229
+ });
230
+ }
231
+ }
232
+ // Set the output value based on normalize flag
233
+ if (def.normalize) {
234
+ // Use normalized URL
235
+ payload.value = url.href;
236
+ }
237
+ else {
238
+ // Preserve the original input (trimmed)
239
+ payload.value = trimmed;
240
+ }
241
+ return;
242
+ }
243
+ catch (_) {
244
+ payload.issues.push({
245
+ code: "invalid_format",
246
+ format: "url",
247
+ input: payload.value,
248
+ inst,
249
+ continue: !def.abort,
250
+ });
251
+ }
252
+ };
253
+ });
254
+ const $ZodEmoji = /*@__PURE__*/ core.$constructor("$ZodEmoji", (inst, def) => {
255
+ def.pattern ?? (def.pattern = regexes.emoji());
256
+ $ZodStringFormat.init(inst, def);
257
+ });
258
+ const $ZodNanoID = /*@__PURE__*/ core.$constructor("$ZodNanoID", (inst, def) => {
259
+ def.pattern ?? (def.pattern = regexes.nanoid);
260
+ $ZodStringFormat.init(inst, def);
261
+ });
262
+ const $ZodCUID = /*@__PURE__*/ core.$constructor("$ZodCUID", (inst, def) => {
263
+ def.pattern ?? (def.pattern = regexes.cuid);
264
+ $ZodStringFormat.init(inst, def);
265
+ });
266
+ const $ZodCUID2 = /*@__PURE__*/ core.$constructor("$ZodCUID2", (inst, def) => {
267
+ def.pattern ?? (def.pattern = regexes.cuid2);
268
+ $ZodStringFormat.init(inst, def);
269
+ });
270
+ const $ZodULID = /*@__PURE__*/ core.$constructor("$ZodULID", (inst, def) => {
271
+ def.pattern ?? (def.pattern = regexes.ulid);
272
+ $ZodStringFormat.init(inst, def);
273
+ });
274
+ const $ZodXID = /*@__PURE__*/ core.$constructor("$ZodXID", (inst, def) => {
275
+ def.pattern ?? (def.pattern = regexes.xid);
276
+ $ZodStringFormat.init(inst, def);
277
+ });
278
+ const $ZodKSUID = /*@__PURE__*/ core.$constructor("$ZodKSUID", (inst, def) => {
279
+ def.pattern ?? (def.pattern = regexes.ksuid);
280
+ $ZodStringFormat.init(inst, def);
281
+ });
282
+ const $ZodISODateTime = /*@__PURE__*/ core.$constructor("$ZodISODateTime", (inst, def) => {
283
+ def.pattern ?? (def.pattern = regexes.datetime(def));
284
+ $ZodStringFormat.init(inst, def);
285
+ });
286
+ const $ZodISODate = /*@__PURE__*/ core.$constructor("$ZodISODate", (inst, def) => {
287
+ def.pattern ?? (def.pattern = regexes.date);
288
+ $ZodStringFormat.init(inst, def);
289
+ });
290
+ const $ZodISOTime = /*@__PURE__*/ core.$constructor("$ZodISOTime", (inst, def) => {
291
+ def.pattern ?? (def.pattern = regexes.time(def));
292
+ $ZodStringFormat.init(inst, def);
293
+ });
294
+ const $ZodISODuration = /*@__PURE__*/ core.$constructor("$ZodISODuration", (inst, def) => {
295
+ def.pattern ?? (def.pattern = regexes.duration);
296
+ $ZodStringFormat.init(inst, def);
297
+ });
298
+ const $ZodIPv4 = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def) => {
299
+ def.pattern ?? (def.pattern = regexes.ipv4);
300
+ $ZodStringFormat.init(inst, def);
301
+ inst._zod.onattach.push((inst) => {
302
+ const bag = inst._zod.bag;
303
+ bag.format = `ipv4`;
304
+ });
305
+ });
306
+ const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def) => {
307
+ def.pattern ?? (def.pattern = regexes.ipv6);
308
+ $ZodStringFormat.init(inst, def);
309
+ inst._zod.onattach.push((inst) => {
310
+ const bag = inst._zod.bag;
311
+ bag.format = `ipv6`;
312
+ });
313
+ inst._zod.check = (payload) => {
314
+ try {
315
+ // @ts-ignore
316
+ new URL(`http://[${payload.value}]`);
317
+ // return;
318
+ }
319
+ catch {
320
+ payload.issues.push({
321
+ code: "invalid_format",
322
+ format: "ipv6",
323
+ input: payload.value,
324
+ inst,
325
+ continue: !def.abort,
326
+ });
327
+ }
328
+ };
329
+ });
330
+ const $ZodCIDRv4 = /*@__PURE__*/ core.$constructor("$ZodCIDRv4", (inst, def) => {
331
+ def.pattern ?? (def.pattern = regexes.cidrv4);
332
+ $ZodStringFormat.init(inst, def);
333
+ });
334
+ const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, def) => {
335
+ def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
336
+ $ZodStringFormat.init(inst, def);
337
+ inst._zod.check = (payload) => {
338
+ const parts = payload.value.split("/");
339
+ try {
340
+ if (parts.length !== 2)
341
+ throw new Error();
342
+ const [address, prefix] = parts;
343
+ if (!prefix)
344
+ throw new Error();
345
+ const prefixNum = Number(prefix);
346
+ if (`${prefixNum}` !== prefix)
347
+ throw new Error();
348
+ if (prefixNum < 0 || prefixNum > 128)
349
+ throw new Error();
350
+ // @ts-ignore
351
+ new URL(`http://[${address}]`);
352
+ }
353
+ catch {
354
+ payload.issues.push({
355
+ code: "invalid_format",
356
+ format: "cidrv6",
357
+ input: payload.value,
358
+ inst,
359
+ continue: !def.abort,
360
+ });
361
+ }
362
+ };
363
+ });
364
+ ////////////////////////////// ZodBase64 //////////////////////////////
365
+ function isValidBase64(data) {
366
+ if (data === "")
367
+ return true;
368
+ if (data.length % 4 !== 0)
369
+ return false;
370
+ try {
371
+ // @ts-ignore
372
+ atob(data);
373
+ return true;
374
+ }
375
+ catch {
376
+ return false;
377
+ }
378
+ }
379
+ const $ZodBase64 = /*@__PURE__*/ core.$constructor("$ZodBase64", (inst, def) => {
380
+ def.pattern ?? (def.pattern = regexes.base64);
381
+ $ZodStringFormat.init(inst, def);
382
+ inst._zod.onattach.push((inst) => {
383
+ inst._zod.bag.contentEncoding = "base64";
384
+ });
385
+ inst._zod.check = (payload) => {
386
+ if (isValidBase64(payload.value))
387
+ return;
388
+ payload.issues.push({
389
+ code: "invalid_format",
390
+ format: "base64",
391
+ input: payload.value,
392
+ inst,
393
+ continue: !def.abort,
394
+ });
395
+ };
396
+ });
397
+ ////////////////////////////// ZodBase64 //////////////////////////////
398
+ function isValidBase64URL(data) {
399
+ if (!regexes.base64url.test(data))
400
+ return false;
401
+ const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
402
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
403
+ return isValidBase64(padded);
404
+ }
405
+ const $ZodBase64URL = /*@__PURE__*/ core.$constructor("$ZodBase64URL", (inst, def) => {
406
+ def.pattern ?? (def.pattern = regexes.base64url);
407
+ $ZodStringFormat.init(inst, def);
408
+ inst._zod.onattach.push((inst) => {
409
+ inst._zod.bag.contentEncoding = "base64url";
410
+ });
411
+ inst._zod.check = (payload) => {
412
+ if (isValidBase64URL(payload.value))
413
+ return;
414
+ payload.issues.push({
415
+ code: "invalid_format",
416
+ format: "base64url",
417
+ input: payload.value,
418
+ inst,
419
+ continue: !def.abort,
420
+ });
421
+ };
422
+ });
423
+ const $ZodE164 = /*@__PURE__*/ core.$constructor("$ZodE164", (inst, def) => {
424
+ def.pattern ?? (def.pattern = regexes.e164);
425
+ $ZodStringFormat.init(inst, def);
426
+ });
427
+ ////////////////////////////// ZodJWT //////////////////////////////
428
+ function isValidJWT(token, algorithm = null) {
429
+ try {
430
+ const tokensParts = token.split(".");
431
+ if (tokensParts.length !== 3)
432
+ return false;
433
+ const [header] = tokensParts;
434
+ if (!header)
435
+ return false;
436
+ // @ts-ignore
437
+ const parsedHeader = JSON.parse(atob(header));
438
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
439
+ return false;
440
+ if (!parsedHeader.alg)
441
+ return false;
442
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
443
+ return false;
444
+ return true;
445
+ }
446
+ catch {
447
+ return false;
448
+ }
449
+ }
450
+ const $ZodJWT = /*@__PURE__*/ core.$constructor("$ZodJWT", (inst, def) => {
451
+ $ZodStringFormat.init(inst, def);
452
+ inst._zod.check = (payload) => {
453
+ if (isValidJWT(payload.value, def.alg))
454
+ return;
455
+ payload.issues.push({
456
+ code: "invalid_format",
457
+ format: "jwt",
458
+ input: payload.value,
459
+ inst,
460
+ continue: !def.abort,
461
+ });
462
+ };
463
+ });
464
+ const $ZodUnknown = /*@__PURE__*/ core.$constructor("$ZodUnknown", (inst, def) => {
465
+ $ZodType.init(inst, def);
466
+ inst._zod.parse = (payload) => payload;
467
+ });
468
+ const $ZodNever = /*@__PURE__*/ core.$constructor("$ZodNever", (inst, def) => {
469
+ $ZodType.init(inst, def);
470
+ inst._zod.parse = (payload, _ctx) => {
471
+ payload.issues.push({
472
+ expected: "never",
473
+ code: "invalid_type",
474
+ input: payload.value,
475
+ inst,
476
+ });
477
+ return payload;
478
+ };
479
+ });
480
+ function handleArrayResult(result, final, index) {
481
+ if (result.issues.length) {
482
+ final.issues.push(...util.prefixIssues(index, result.issues));
483
+ }
484
+ final.value[index] = result.value;
485
+ }
486
+ const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def) => {
487
+ $ZodType.init(inst, def);
488
+ inst._zod.parse = (payload, ctx) => {
489
+ const input = payload.value;
490
+ if (!Array.isArray(input)) {
491
+ payload.issues.push({
492
+ expected: "array",
493
+ code: "invalid_type",
494
+ input,
495
+ inst,
496
+ });
497
+ return payload;
498
+ }
499
+ payload.value = Array(input.length);
500
+ const proms = [];
501
+ for (let i = 0; i < input.length; i++) {
502
+ const item = input[i];
503
+ const result = def.element._zod.run({
504
+ value: item,
505
+ issues: [],
506
+ }, ctx);
507
+ if (result instanceof Promise) {
508
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
509
+ }
510
+ else {
511
+ handleArrayResult(result, payload, i);
512
+ }
513
+ }
514
+ if (proms.length) {
515
+ return Promise.all(proms).then(() => payload);
516
+ }
517
+ return payload; //handleArrayResultsAsync(parseResults, final);
518
+ };
519
+ });
520
+ function handlePropertyResult(result, final, key, input) {
521
+ if (result.issues.length) {
522
+ final.issues.push(...util.prefixIssues(key, result.issues));
523
+ }
524
+ if (result.value === undefined) {
525
+ if (key in input) {
526
+ final.value[key] = undefined;
527
+ }
528
+ }
529
+ else {
530
+ final.value[key] = result.value;
531
+ }
532
+ }
533
+ function normalizeDef(def) {
534
+ const keys = Object.keys(def.shape);
535
+ for (const k of keys) {
536
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
537
+ throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
538
+ }
539
+ }
540
+ const okeys = util.optionalKeys(def.shape);
541
+ return {
542
+ ...def,
543
+ keys,
544
+ keySet: new Set(keys),
545
+ numKeys: keys.length,
546
+ optionalKeys: new Set(okeys),
547
+ };
548
+ }
549
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
550
+ const unrecognized = [];
551
+ // iterate over input keys
552
+ const keySet = def.keySet;
553
+ const _catchall = def.catchall._zod;
554
+ const t = _catchall.def.type;
555
+ for (const key of Object.keys(input)) {
556
+ if (keySet.has(key))
557
+ continue;
558
+ if (t === "never") {
559
+ unrecognized.push(key);
560
+ continue;
561
+ }
562
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
563
+ if (r instanceof Promise) {
564
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
565
+ }
566
+ else {
567
+ handlePropertyResult(r, payload, key, input);
568
+ }
569
+ }
570
+ if (unrecognized.length) {
571
+ payload.issues.push({
572
+ code: "unrecognized_keys",
573
+ keys: unrecognized,
574
+ input,
575
+ inst,
576
+ });
577
+ }
578
+ if (!proms.length)
579
+ return payload;
580
+ return Promise.all(proms).then(() => {
581
+ return payload;
582
+ });
583
+ }
584
+ const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
585
+ // requires cast because technically $ZodObject doesn't extend
586
+ $ZodType.init(inst, def);
587
+ // const sh = def.shape;
588
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
589
+ if (!desc?.get) {
590
+ const sh = def.shape;
591
+ Object.defineProperty(def, "shape", {
592
+ get: () => {
593
+ const newSh = { ...sh };
594
+ Object.defineProperty(def, "shape", {
595
+ value: newSh,
596
+ });
597
+ return newSh;
598
+ },
599
+ });
600
+ }
601
+ const _normalized = util.cached(() => normalizeDef(def));
602
+ util.defineLazy(inst._zod, "propValues", () => {
603
+ const shape = def.shape;
604
+ const propValues = {};
605
+ for (const key in shape) {
606
+ const field = shape[key]._zod;
607
+ if (field.values) {
608
+ propValues[key] ?? (propValues[key] = new Set());
609
+ for (const v of field.values)
610
+ propValues[key].add(v);
611
+ }
612
+ }
613
+ return propValues;
614
+ });
615
+ const isObject = util.isObject;
616
+ const catchall = def.catchall;
617
+ let value;
618
+ inst._zod.parse = (payload, ctx) => {
619
+ value ?? (value = _normalized.value);
620
+ const input = payload.value;
621
+ if (!isObject(input)) {
622
+ payload.issues.push({
623
+ expected: "object",
624
+ code: "invalid_type",
625
+ input,
626
+ inst,
627
+ });
628
+ return payload;
629
+ }
630
+ payload.value = {};
631
+ const proms = [];
632
+ const shape = value.shape;
633
+ for (const key of value.keys) {
634
+ const el = shape[key];
635
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
636
+ if (r instanceof Promise) {
637
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
638
+ }
639
+ else {
640
+ handlePropertyResult(r, payload, key, input);
641
+ }
642
+ }
643
+ if (!catchall) {
644
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
645
+ }
646
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
647
+ };
648
+ });
649
+ const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (inst, def) => {
650
+ // requires cast because technically $ZodObject doesn't extend
651
+ $ZodObject.init(inst, def);
652
+ const superParse = inst._zod.parse;
653
+ const _normalized = util.cached(() => normalizeDef(def));
654
+ const generateFastpass = (shape) => {
655
+ const doc$1 = new doc.Doc(["shape", "payload", "ctx"]);
656
+ const normalized = _normalized.value;
657
+ const parseStr = (key) => {
658
+ const k = util.esc(key);
659
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
660
+ };
661
+ doc$1.write(`const input = payload.value;`);
662
+ const ids = Object.create(null);
663
+ let counter = 0;
664
+ for (const key of normalized.keys) {
665
+ ids[key] = `key_${counter++}`;
666
+ }
667
+ // A: preserve key order {
668
+ doc$1.write(`const newResult = {};`);
669
+ for (const key of normalized.keys) {
670
+ const id = ids[key];
671
+ const k = util.esc(key);
672
+ doc$1.write(`const ${id} = ${parseStr(key)};`);
673
+ doc$1.write(`
674
+ if (${id}.issues.length) {
675
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
676
+ ...iss,
677
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
678
+ })));
679
+ }
680
+
681
+
682
+ if (${id}.value === undefined) {
683
+ if (${k} in input) {
684
+ newResult[${k}] = undefined;
685
+ }
686
+ } else {
687
+ newResult[${k}] = ${id}.value;
688
+ }
689
+
690
+ `);
691
+ }
692
+ doc$1.write(`payload.value = newResult;`);
693
+ doc$1.write(`return payload;`);
694
+ const fn = doc$1.compile();
695
+ return (payload, ctx) => fn(shape, payload, ctx);
696
+ };
697
+ let fastpass;
698
+ const isObject = util.isObject;
699
+ const jit = !core.globalConfig.jitless;
700
+ const allowsEval = util.allowsEval;
701
+ const fastEnabled = jit && allowsEval.value; // && !def.catchall;
702
+ const catchall = def.catchall;
703
+ let value;
704
+ inst._zod.parse = (payload, ctx) => {
705
+ value ?? (value = _normalized.value);
706
+ const input = payload.value;
707
+ if (!isObject(input)) {
708
+ payload.issues.push({
709
+ expected: "object",
710
+ code: "invalid_type",
711
+ input,
712
+ inst,
713
+ });
714
+ return payload;
715
+ }
716
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
717
+ // always synchronous
718
+ if (!fastpass)
719
+ fastpass = generateFastpass(def.shape);
720
+ payload = fastpass(payload, ctx);
721
+ if (!catchall)
722
+ return payload;
723
+ return handleCatchall([], input, payload, ctx, value, inst);
724
+ }
725
+ return superParse(payload, ctx);
726
+ };
727
+ });
728
+ function handleUnionResults(results, final, inst, ctx) {
729
+ for (const result of results) {
730
+ if (result.issues.length === 0) {
731
+ final.value = result.value;
732
+ return final;
733
+ }
734
+ }
735
+ const nonaborted = results.filter((r) => !util.aborted(r));
736
+ if (nonaborted.length === 1) {
737
+ final.value = nonaborted[0].value;
738
+ return nonaborted[0];
739
+ }
740
+ final.issues.push({
741
+ code: "invalid_union",
742
+ input: final.value,
743
+ inst,
744
+ errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
745
+ });
746
+ return final;
747
+ }
748
+ const $ZodUnion = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def) => {
749
+ $ZodType.init(inst, def);
750
+ util.defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
751
+ util.defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
752
+ util.defineLazy(inst._zod, "values", () => {
753
+ if (def.options.every((o) => o._zod.values)) {
754
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
755
+ }
756
+ return undefined;
757
+ });
758
+ util.defineLazy(inst._zod, "pattern", () => {
759
+ if (def.options.every((o) => o._zod.pattern)) {
760
+ const patterns = def.options.map((o) => o._zod.pattern);
761
+ return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p.source)).join("|")})$`);
762
+ }
763
+ return undefined;
764
+ });
765
+ const single = def.options.length === 1;
766
+ const first = def.options[0]._zod.run;
767
+ inst._zod.parse = (payload, ctx) => {
768
+ if (single) {
769
+ return first(payload, ctx);
770
+ }
771
+ let async = false;
772
+ const results = [];
773
+ for (const option of def.options) {
774
+ const result = option._zod.run({
775
+ value: payload.value,
776
+ issues: [],
777
+ }, ctx);
778
+ if (result instanceof Promise) {
779
+ results.push(result);
780
+ async = true;
781
+ }
782
+ else {
783
+ if (result.issues.length === 0)
784
+ return result;
785
+ results.push(result);
786
+ }
787
+ }
788
+ if (!async)
789
+ return handleUnionResults(results, payload, inst, ctx);
790
+ return Promise.all(results).then((results) => {
791
+ return handleUnionResults(results, payload, inst, ctx);
792
+ });
793
+ };
794
+ });
795
+ const $ZodIntersection = /*@__PURE__*/ core.$constructor("$ZodIntersection", (inst, def) => {
796
+ $ZodType.init(inst, def);
797
+ inst._zod.parse = (payload, ctx) => {
798
+ const input = payload.value;
799
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
800
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
801
+ const async = left instanceof Promise || right instanceof Promise;
802
+ if (async) {
803
+ return Promise.all([left, right]).then(([left, right]) => {
804
+ return handleIntersectionResults(payload, left, right);
805
+ });
806
+ }
807
+ return handleIntersectionResults(payload, left, right);
808
+ };
809
+ });
810
+ function mergeValues(a, b) {
811
+ // const aType = parse.t(a);
812
+ // const bType = parse.t(b);
813
+ if (a === b) {
814
+ return { valid: true, data: a };
815
+ }
816
+ if (a instanceof Date && b instanceof Date && +a === +b) {
817
+ return { valid: true, data: a };
818
+ }
819
+ if (util.isPlainObject(a) && util.isPlainObject(b)) {
820
+ const bKeys = Object.keys(b);
821
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
822
+ const newObj = { ...a, ...b };
823
+ for (const key of sharedKeys) {
824
+ const sharedValue = mergeValues(a[key], b[key]);
825
+ if (!sharedValue.valid) {
826
+ return {
827
+ valid: false,
828
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
829
+ };
830
+ }
831
+ newObj[key] = sharedValue.data;
832
+ }
833
+ return { valid: true, data: newObj };
834
+ }
835
+ if (Array.isArray(a) && Array.isArray(b)) {
836
+ if (a.length !== b.length) {
837
+ return { valid: false, mergeErrorPath: [] };
838
+ }
839
+ const newArray = [];
840
+ for (let index = 0; index < a.length; index++) {
841
+ const itemA = a[index];
842
+ const itemB = b[index];
843
+ const sharedValue = mergeValues(itemA, itemB);
844
+ if (!sharedValue.valid) {
845
+ return {
846
+ valid: false,
847
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
848
+ };
849
+ }
850
+ newArray.push(sharedValue.data);
851
+ }
852
+ return { valid: true, data: newArray };
853
+ }
854
+ return { valid: false, mergeErrorPath: [] };
855
+ }
856
+ function handleIntersectionResults(result, left, right) {
857
+ if (left.issues.length) {
858
+ result.issues.push(...left.issues);
859
+ }
860
+ if (right.issues.length) {
861
+ result.issues.push(...right.issues);
862
+ }
863
+ if (util.aborted(result))
864
+ return result;
865
+ const merged = mergeValues(left.value, right.value);
866
+ if (!merged.valid) {
867
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
868
+ }
869
+ result.value = merged.data;
870
+ return result;
871
+ }
872
+ const $ZodEnum = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def) => {
873
+ $ZodType.init(inst, def);
874
+ const values = util.getEnumValues(def.entries);
875
+ const valuesSet = new Set(values);
876
+ inst._zod.values = valuesSet;
877
+ inst._zod.pattern = new RegExp(`^(${values
878
+ .filter((k) => util.propertyKeyTypes.has(typeof k))
879
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
880
+ .join("|")})$`);
881
+ inst._zod.parse = (payload, _ctx) => {
882
+ const input = payload.value;
883
+ if (valuesSet.has(input)) {
884
+ return payload;
885
+ }
886
+ payload.issues.push({
887
+ code: "invalid_value",
888
+ values,
889
+ input,
890
+ inst,
891
+ });
892
+ return payload;
893
+ };
894
+ });
895
+ const $ZodTransform = /*@__PURE__*/ core.$constructor("$ZodTransform", (inst, def) => {
896
+ $ZodType.init(inst, def);
897
+ inst._zod.parse = (payload, ctx) => {
898
+ if (ctx.direction === "backward") {
899
+ throw new core.$ZodEncodeError(inst.constructor.name);
900
+ }
901
+ const _out = def.transform(payload.value, payload);
902
+ if (ctx.async) {
903
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
904
+ return output.then((output) => {
905
+ payload.value = output;
906
+ return payload;
907
+ });
908
+ }
909
+ if (_out instanceof Promise) {
910
+ throw new core.$ZodAsyncError();
911
+ }
912
+ payload.value = _out;
913
+ return payload;
914
+ };
915
+ });
916
+ function handleOptionalResult(result, input) {
917
+ if (result.issues.length && input === undefined) {
918
+ return { issues: [], value: undefined };
919
+ }
920
+ return result;
921
+ }
922
+ const $ZodOptional = /*@__PURE__*/ core.$constructor("$ZodOptional", (inst, def) => {
923
+ $ZodType.init(inst, def);
924
+ inst._zod.optin = "optional";
925
+ inst._zod.optout = "optional";
926
+ util.defineLazy(inst._zod, "values", () => {
927
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
928
+ });
929
+ util.defineLazy(inst._zod, "pattern", () => {
930
+ const pattern = def.innerType._zod.pattern;
931
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
932
+ });
933
+ inst._zod.parse = (payload, ctx) => {
934
+ if (def.innerType._zod.optin === "optional") {
935
+ const result = def.innerType._zod.run(payload, ctx);
936
+ if (result instanceof Promise)
937
+ return result.then((r) => handleOptionalResult(r, payload.value));
938
+ return handleOptionalResult(result, payload.value);
939
+ }
940
+ if (payload.value === undefined) {
941
+ return payload;
942
+ }
943
+ return def.innerType._zod.run(payload, ctx);
944
+ };
945
+ });
946
+ const $ZodNullable = /*@__PURE__*/ core.$constructor("$ZodNullable", (inst, def) => {
947
+ $ZodType.init(inst, def);
948
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
949
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
950
+ util.defineLazy(inst._zod, "pattern", () => {
951
+ const pattern = def.innerType._zod.pattern;
952
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
953
+ });
954
+ util.defineLazy(inst._zod, "values", () => {
955
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
956
+ });
957
+ inst._zod.parse = (payload, ctx) => {
958
+ // Forward direction (decode): allow null to pass through
959
+ if (payload.value === null)
960
+ return payload;
961
+ return def.innerType._zod.run(payload, ctx);
962
+ };
963
+ });
964
+ const $ZodDefault = /*@__PURE__*/ core.$constructor("$ZodDefault", (inst, def) => {
965
+ $ZodType.init(inst, def);
966
+ // inst._zod.qin = "true";
967
+ inst._zod.optin = "optional";
968
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
969
+ inst._zod.parse = (payload, ctx) => {
970
+ if (ctx.direction === "backward") {
971
+ return def.innerType._zod.run(payload, ctx);
972
+ }
973
+ // Forward direction (decode): apply defaults for undefined input
974
+ if (payload.value === undefined) {
975
+ payload.value = def.defaultValue;
976
+ /**
977
+ * $ZodDefault returns the default value immediately in forward direction.
978
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
979
+ return payload;
980
+ }
981
+ // Forward direction: continue with default handling
982
+ const result = def.innerType._zod.run(payload, ctx);
983
+ if (result instanceof Promise) {
984
+ return result.then((result) => handleDefaultResult(result, def));
985
+ }
986
+ return handleDefaultResult(result, def);
987
+ };
988
+ });
989
+ function handleDefaultResult(payload, def) {
990
+ if (payload.value === undefined) {
991
+ payload.value = def.defaultValue;
992
+ }
993
+ return payload;
994
+ }
995
+ const $ZodPrefault = /*@__PURE__*/ core.$constructor("$ZodPrefault", (inst, def) => {
996
+ $ZodType.init(inst, def);
997
+ inst._zod.optin = "optional";
998
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
999
+ inst._zod.parse = (payload, ctx) => {
1000
+ if (ctx.direction === "backward") {
1001
+ return def.innerType._zod.run(payload, ctx);
1002
+ }
1003
+ // Forward direction (decode): apply prefault for undefined input
1004
+ if (payload.value === undefined) {
1005
+ payload.value = def.defaultValue;
1006
+ }
1007
+ return def.innerType._zod.run(payload, ctx);
1008
+ };
1009
+ });
1010
+ const $ZodNonOptional = /*@__PURE__*/ core.$constructor("$ZodNonOptional", (inst, def) => {
1011
+ $ZodType.init(inst, def);
1012
+ util.defineLazy(inst._zod, "values", () => {
1013
+ const v = def.innerType._zod.values;
1014
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
1015
+ });
1016
+ inst._zod.parse = (payload, ctx) => {
1017
+ const result = def.innerType._zod.run(payload, ctx);
1018
+ if (result instanceof Promise) {
1019
+ return result.then((result) => handleNonOptionalResult(result, inst));
1020
+ }
1021
+ return handleNonOptionalResult(result, inst);
1022
+ };
1023
+ });
1024
+ function handleNonOptionalResult(payload, inst) {
1025
+ if (!payload.issues.length && payload.value === undefined) {
1026
+ payload.issues.push({
1027
+ code: "invalid_type",
1028
+ expected: "nonoptional",
1029
+ input: payload.value,
1030
+ inst,
1031
+ });
1032
+ }
1033
+ return payload;
1034
+ }
1035
+ const $ZodCatch = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
1036
+ $ZodType.init(inst, def);
1037
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1038
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1039
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1040
+ inst._zod.parse = (payload, ctx) => {
1041
+ if (ctx.direction === "backward") {
1042
+ return def.innerType._zod.run(payload, ctx);
1043
+ }
1044
+ // Forward direction (decode): apply catch logic
1045
+ const result = def.innerType._zod.run(payload, ctx);
1046
+ if (result instanceof Promise) {
1047
+ return result.then((result) => {
1048
+ payload.value = result.value;
1049
+ if (result.issues.length) {
1050
+ payload.value = def.catchValue({
1051
+ ...payload,
1052
+ error: {
1053
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1054
+ },
1055
+ input: payload.value,
1056
+ });
1057
+ payload.issues = [];
1058
+ }
1059
+ return payload;
1060
+ });
1061
+ }
1062
+ payload.value = result.value;
1063
+ if (result.issues.length) {
1064
+ payload.value = def.catchValue({
1065
+ ...payload,
1066
+ error: {
1067
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1068
+ },
1069
+ input: payload.value,
1070
+ });
1071
+ payload.issues = [];
1072
+ }
1073
+ return payload;
1074
+ };
1075
+ });
1076
+ const $ZodPipe = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def) => {
1077
+ $ZodType.init(inst, def);
1078
+ util.defineLazy(inst._zod, "values", () => def.in._zod.values);
1079
+ util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1080
+ util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1081
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
1082
+ inst._zod.parse = (payload, ctx) => {
1083
+ if (ctx.direction === "backward") {
1084
+ const right = def.out._zod.run(payload, ctx);
1085
+ if (right instanceof Promise) {
1086
+ return right.then((right) => handlePipeResult(right, def.in, ctx));
1087
+ }
1088
+ return handlePipeResult(right, def.in, ctx);
1089
+ }
1090
+ const left = def.in._zod.run(payload, ctx);
1091
+ if (left instanceof Promise) {
1092
+ return left.then((left) => handlePipeResult(left, def.out, ctx));
1093
+ }
1094
+ return handlePipeResult(left, def.out, ctx);
1095
+ };
1096
+ });
1097
+ function handlePipeResult(left, next, ctx) {
1098
+ if (left.issues.length) {
1099
+ // prevent further checks
1100
+ left.aborted = true;
1101
+ return left;
1102
+ }
1103
+ return next._zod.run({ value: left.value, issues: left.issues }, ctx);
1104
+ }
1105
+ const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (inst, def) => {
1106
+ $ZodType.init(inst, def);
1107
+ util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1108
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1109
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1110
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1111
+ inst._zod.parse = (payload, ctx) => {
1112
+ if (ctx.direction === "backward") {
1113
+ return def.innerType._zod.run(payload, ctx);
1114
+ }
1115
+ const result = def.innerType._zod.run(payload, ctx);
1116
+ if (result instanceof Promise) {
1117
+ return result.then(handleReadonlyResult);
1118
+ }
1119
+ return handleReadonlyResult(result);
1120
+ };
1121
+ });
1122
+ function handleReadonlyResult(payload) {
1123
+ payload.value = Object.freeze(payload.value);
1124
+ return payload;
1125
+ }
1126
+ const $ZodCustom = /*@__PURE__*/ core.$constructor("$ZodCustom", (inst, def) => {
1127
+ checks.$ZodCheck.init(inst, def);
1128
+ $ZodType.init(inst, def);
1129
+ inst._zod.parse = (payload, _) => {
1130
+ return payload;
1131
+ };
1132
+ inst._zod.check = (payload) => {
1133
+ const input = payload.value;
1134
+ const r = def.fn(input);
1135
+ if (r instanceof Promise) {
1136
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
1137
+ }
1138
+ handleRefineResult(r, payload, input, inst);
1139
+ return;
1140
+ };
1141
+ });
1142
+ function handleRefineResult(result, payload, input, inst) {
1143
+ if (!result) {
1144
+ const _iss = {
1145
+ code: "custom",
1146
+ input,
1147
+ inst, // incorporates params.error into issue reporting
1148
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
1149
+ continue: !inst._zod.def.abort,
1150
+ // params: inst._zod.def.params,
1151
+ };
1152
+ if (inst._zod.def.params)
1153
+ _iss.params = inst._zod.def.params;
1154
+ payload.issues.push(util.issue(_iss));
1155
+ }
1156
+ }
1157
+
1158
+ exports.clone = util.clone;
1159
+ exports.$ZodArray = $ZodArray;
1160
+ exports.$ZodBase64 = $ZodBase64;
1161
+ exports.$ZodBase64URL = $ZodBase64URL;
1162
+ exports.$ZodCIDRv4 = $ZodCIDRv4;
1163
+ exports.$ZodCIDRv6 = $ZodCIDRv6;
1164
+ exports.$ZodCUID = $ZodCUID;
1165
+ exports.$ZodCUID2 = $ZodCUID2;
1166
+ exports.$ZodCatch = $ZodCatch;
1167
+ exports.$ZodCustom = $ZodCustom;
1168
+ exports.$ZodDefault = $ZodDefault;
1169
+ exports.$ZodE164 = $ZodE164;
1170
+ exports.$ZodEmail = $ZodEmail;
1171
+ exports.$ZodEmoji = $ZodEmoji;
1172
+ exports.$ZodEnum = $ZodEnum;
1173
+ exports.$ZodGUID = $ZodGUID;
1174
+ exports.$ZodIPv4 = $ZodIPv4;
1175
+ exports.$ZodIPv6 = $ZodIPv6;
1176
+ exports.$ZodISODate = $ZodISODate;
1177
+ exports.$ZodISODateTime = $ZodISODateTime;
1178
+ exports.$ZodISODuration = $ZodISODuration;
1179
+ exports.$ZodISOTime = $ZodISOTime;
1180
+ exports.$ZodIntersection = $ZodIntersection;
1181
+ exports.$ZodJWT = $ZodJWT;
1182
+ exports.$ZodKSUID = $ZodKSUID;
1183
+ exports.$ZodNanoID = $ZodNanoID;
1184
+ exports.$ZodNever = $ZodNever;
1185
+ exports.$ZodNonOptional = $ZodNonOptional;
1186
+ exports.$ZodNullable = $ZodNullable;
1187
+ exports.$ZodObject = $ZodObject;
1188
+ exports.$ZodObjectJIT = $ZodObjectJIT;
1189
+ exports.$ZodOptional = $ZodOptional;
1190
+ exports.$ZodPipe = $ZodPipe;
1191
+ exports.$ZodPrefault = $ZodPrefault;
1192
+ exports.$ZodReadonly = $ZodReadonly;
1193
+ exports.$ZodString = $ZodString;
1194
+ exports.$ZodStringFormat = $ZodStringFormat;
1195
+ exports.$ZodTransform = $ZodTransform;
1196
+ exports.$ZodType = $ZodType;
1197
+ exports.$ZodULID = $ZodULID;
1198
+ exports.$ZodURL = $ZodURL;
1199
+ exports.$ZodUUID = $ZodUUID;
1200
+ exports.$ZodUnion = $ZodUnion;
1201
+ exports.$ZodUnknown = $ZodUnknown;
1202
+ exports.$ZodXID = $ZodXID;
1203
+ exports.isValidBase64 = isValidBase64;
1204
+ exports.isValidBase64URL = isValidBase64URL;
1205
+ exports.isValidJWT = isValidJWT;