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