@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,232 @@
1
+ import { $constructor } from './core.mjs';
2
+ import { lowercase, uppercase } from './regexes.mjs';
3
+ import { escapeRegex, nullish, getLengthableOrigin } from './util.mjs';
4
+
5
+ // import { $ZodType } from "./schemas.js";
6
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
7
+ var _a;
8
+ inst._zod ?? (inst._zod = {});
9
+ inst._zod.def = def;
10
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
11
+ });
12
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
13
+ var _a;
14
+ $ZodCheck.init(inst, def);
15
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
16
+ const val = payload.value;
17
+ return !nullish(val) && val.length !== undefined;
18
+ });
19
+ inst._zod.onattach.push((inst) => {
20
+ const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
21
+ if (def.maximum < curr)
22
+ inst._zod.bag.maximum = def.maximum;
23
+ });
24
+ inst._zod.check = (payload) => {
25
+ const input = payload.value;
26
+ const length = input.length;
27
+ if (length <= def.maximum)
28
+ return;
29
+ const origin = getLengthableOrigin(input);
30
+ payload.issues.push({
31
+ origin,
32
+ code: "too_big",
33
+ maximum: def.maximum,
34
+ inclusive: true,
35
+ input,
36
+ inst,
37
+ continue: !def.abort,
38
+ });
39
+ };
40
+ });
41
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
42
+ var _a;
43
+ $ZodCheck.init(inst, def);
44
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
45
+ const val = payload.value;
46
+ return !nullish(val) && val.length !== undefined;
47
+ });
48
+ inst._zod.onattach.push((inst) => {
49
+ const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
50
+ if (def.minimum > curr)
51
+ inst._zod.bag.minimum = def.minimum;
52
+ });
53
+ inst._zod.check = (payload) => {
54
+ const input = payload.value;
55
+ const length = input.length;
56
+ if (length >= def.minimum)
57
+ return;
58
+ const origin = getLengthableOrigin(input);
59
+ payload.issues.push({
60
+ origin,
61
+ code: "too_small",
62
+ minimum: def.minimum,
63
+ inclusive: true,
64
+ input,
65
+ inst,
66
+ continue: !def.abort,
67
+ });
68
+ };
69
+ });
70
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
71
+ var _a;
72
+ $ZodCheck.init(inst, def);
73
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
74
+ const val = payload.value;
75
+ return !nullish(val) && val.length !== undefined;
76
+ });
77
+ inst._zod.onattach.push((inst) => {
78
+ const bag = inst._zod.bag;
79
+ bag.minimum = def.length;
80
+ bag.maximum = def.length;
81
+ bag.length = def.length;
82
+ });
83
+ inst._zod.check = (payload) => {
84
+ const input = payload.value;
85
+ const length = input.length;
86
+ if (length === def.length)
87
+ return;
88
+ const origin = getLengthableOrigin(input);
89
+ const tooBig = length > def.length;
90
+ payload.issues.push({
91
+ origin,
92
+ ...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
93
+ inclusive: true,
94
+ exact: true,
95
+ input: payload.value,
96
+ inst,
97
+ continue: !def.abort,
98
+ });
99
+ };
100
+ });
101
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
102
+ var _a, _b;
103
+ $ZodCheck.init(inst, def);
104
+ inst._zod.onattach.push((inst) => {
105
+ const bag = inst._zod.bag;
106
+ bag.format = def.format;
107
+ if (def.pattern) {
108
+ bag.patterns ?? (bag.patterns = new Set());
109
+ bag.patterns.add(def.pattern);
110
+ }
111
+ });
112
+ if (def.pattern)
113
+ (_a = inst._zod).check ?? (_a.check = (payload) => {
114
+ def.pattern.lastIndex = 0;
115
+ if (def.pattern.test(payload.value))
116
+ return;
117
+ payload.issues.push({
118
+ origin: "string",
119
+ code: "invalid_format",
120
+ format: def.format,
121
+ input: payload.value,
122
+ ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
123
+ inst,
124
+ continue: !def.abort,
125
+ });
126
+ });
127
+ else
128
+ (_b = inst._zod).check ?? (_b.check = () => { });
129
+ });
130
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
131
+ $ZodCheckStringFormat.init(inst, def);
132
+ inst._zod.check = (payload) => {
133
+ def.pattern.lastIndex = 0;
134
+ if (def.pattern.test(payload.value))
135
+ return;
136
+ payload.issues.push({
137
+ origin: "string",
138
+ code: "invalid_format",
139
+ format: "regex",
140
+ input: payload.value,
141
+ pattern: def.pattern.toString(),
142
+ inst,
143
+ continue: !def.abort,
144
+ });
145
+ };
146
+ });
147
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
148
+ def.pattern ?? (def.pattern = lowercase);
149
+ $ZodCheckStringFormat.init(inst, def);
150
+ });
151
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
152
+ def.pattern ?? (def.pattern = uppercase);
153
+ $ZodCheckStringFormat.init(inst, def);
154
+ });
155
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
156
+ $ZodCheck.init(inst, def);
157
+ const escapedRegex = escapeRegex(def.includes);
158
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
159
+ def.pattern = pattern;
160
+ inst._zod.onattach.push((inst) => {
161
+ const bag = inst._zod.bag;
162
+ bag.patterns ?? (bag.patterns = new Set());
163
+ bag.patterns.add(pattern);
164
+ });
165
+ inst._zod.check = (payload) => {
166
+ if (payload.value.includes(def.includes, def.position))
167
+ return;
168
+ payload.issues.push({
169
+ origin: "string",
170
+ code: "invalid_format",
171
+ format: "includes",
172
+ includes: def.includes,
173
+ input: payload.value,
174
+ inst,
175
+ continue: !def.abort,
176
+ });
177
+ };
178
+ });
179
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
180
+ $ZodCheck.init(inst, def);
181
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
182
+ def.pattern ?? (def.pattern = pattern);
183
+ inst._zod.onattach.push((inst) => {
184
+ const bag = inst._zod.bag;
185
+ bag.patterns ?? (bag.patterns = new Set());
186
+ bag.patterns.add(pattern);
187
+ });
188
+ inst._zod.check = (payload) => {
189
+ if (payload.value.startsWith(def.prefix))
190
+ return;
191
+ payload.issues.push({
192
+ origin: "string",
193
+ code: "invalid_format",
194
+ format: "starts_with",
195
+ prefix: def.prefix,
196
+ input: payload.value,
197
+ inst,
198
+ continue: !def.abort,
199
+ });
200
+ };
201
+ });
202
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
203
+ $ZodCheck.init(inst, def);
204
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
205
+ def.pattern ?? (def.pattern = pattern);
206
+ inst._zod.onattach.push((inst) => {
207
+ const bag = inst._zod.bag;
208
+ bag.patterns ?? (bag.patterns = new Set());
209
+ bag.patterns.add(pattern);
210
+ });
211
+ inst._zod.check = (payload) => {
212
+ if (payload.value.endsWith(def.suffix))
213
+ return;
214
+ payload.issues.push({
215
+ origin: "string",
216
+ code: "invalid_format",
217
+ format: "ends_with",
218
+ suffix: def.suffix,
219
+ input: payload.value,
220
+ inst,
221
+ continue: !def.abort,
222
+ });
223
+ };
224
+ });
225
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
226
+ $ZodCheck.init(inst, def);
227
+ inst._zod.check = (payload) => {
228
+ payload.value = def.tx(payload.value);
229
+ };
230
+ });
231
+
232
+ export { $ZodCheck, $ZodCheckEndsWith, $ZodCheckIncludes, $ZodCheckLengthEquals, $ZodCheckLowerCase, $ZodCheckMaxLength, $ZodCheckMinLength, $ZodCheckOverwrite, $ZodCheckRegex, $ZodCheckStartsWith, $ZodCheckStringFormat, $ZodCheckUpperCase };
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ /** A special constant with type `never` */
4
+ function $constructor(name, initializer, params) {
5
+ function init(inst, def) {
6
+ var _a;
7
+ Object.defineProperty(inst, "_zod", {
8
+ value: inst._zod ?? {},
9
+ enumerable: false,
10
+ });
11
+ (_a = inst._zod).traits ?? (_a.traits = new Set());
12
+ inst._zod.traits.add(name);
13
+ initializer(inst, def);
14
+ // support prototype modifications
15
+ for (const k in _.prototype) {
16
+ if (!(k in inst))
17
+ Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
18
+ }
19
+ inst._zod.constr = _;
20
+ inst._zod.def = def;
21
+ }
22
+ // doesn't work if Parent has a constructor with arguments
23
+ const Parent = params?.Parent ?? Object;
24
+ class Definition extends Parent {
25
+ }
26
+ Object.defineProperty(Definition, "name", { value: name });
27
+ function _(def) {
28
+ var _a;
29
+ const inst = params?.Parent ? new Definition() : this;
30
+ init(inst, def);
31
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
32
+ for (const fn of inst._zod.deferred) {
33
+ fn();
34
+ }
35
+ return inst;
36
+ }
37
+ Object.defineProperty(_, "init", { value: init });
38
+ Object.defineProperty(_, Symbol.hasInstance, {
39
+ value: (inst) => {
40
+ if (params?.Parent && inst instanceof params.Parent)
41
+ return true;
42
+ return inst?._zod?.traits?.has(name);
43
+ },
44
+ });
45
+ Object.defineProperty(_, "name", { value: name });
46
+ return _;
47
+ }
48
+ class $ZodAsyncError extends Error {
49
+ constructor() {
50
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
51
+ }
52
+ }
53
+ class $ZodEncodeError extends Error {
54
+ constructor(name) {
55
+ super(`Encountered unidirectional transform during encode: ${name}`);
56
+ this.name = "ZodEncodeError";
57
+ }
58
+ }
59
+ const globalConfig = {};
60
+ function config(newConfig) {
61
+ return globalConfig;
62
+ }
63
+
64
+ exports.$ZodAsyncError = $ZodAsyncError;
65
+ exports.$ZodEncodeError = $ZodEncodeError;
66
+ exports.$constructor = $constructor;
67
+ exports.config = config;
68
+ exports.globalConfig = globalConfig;
@@ -0,0 +1,62 @@
1
+ /** A special constant with type `never` */
2
+ function $constructor(name, initializer, params) {
3
+ function init(inst, def) {
4
+ var _a;
5
+ Object.defineProperty(inst, "_zod", {
6
+ value: inst._zod ?? {},
7
+ enumerable: false,
8
+ });
9
+ (_a = inst._zod).traits ?? (_a.traits = new Set());
10
+ inst._zod.traits.add(name);
11
+ initializer(inst, def);
12
+ // support prototype modifications
13
+ for (const k in _.prototype) {
14
+ if (!(k in inst))
15
+ Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
16
+ }
17
+ inst._zod.constr = _;
18
+ inst._zod.def = def;
19
+ }
20
+ // doesn't work if Parent has a constructor with arguments
21
+ const Parent = params?.Parent ?? Object;
22
+ class Definition extends Parent {
23
+ }
24
+ Object.defineProperty(Definition, "name", { value: name });
25
+ function _(def) {
26
+ var _a;
27
+ const inst = params?.Parent ? new Definition() : this;
28
+ init(inst, def);
29
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
30
+ for (const fn of inst._zod.deferred) {
31
+ fn();
32
+ }
33
+ return inst;
34
+ }
35
+ Object.defineProperty(_, "init", { value: init });
36
+ Object.defineProperty(_, Symbol.hasInstance, {
37
+ value: (inst) => {
38
+ if (params?.Parent && inst instanceof params.Parent)
39
+ return true;
40
+ return inst?._zod?.traits?.has(name);
41
+ },
42
+ });
43
+ Object.defineProperty(_, "name", { value: name });
44
+ return _;
45
+ }
46
+ class $ZodAsyncError extends Error {
47
+ constructor() {
48
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
49
+ }
50
+ }
51
+ class $ZodEncodeError extends Error {
52
+ constructor(name) {
53
+ super(`Encountered unidirectional transform during encode: ${name}`);
54
+ this.name = "ZodEncodeError";
55
+ }
56
+ }
57
+ const globalConfig = {};
58
+ function config(newConfig) {
59
+ return globalConfig;
60
+ }
61
+
62
+ export { $ZodAsyncError, $ZodEncodeError, $constructor, config, globalConfig };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ class Doc {
4
+ constructor(args = []) {
5
+ this.content = [];
6
+ this.indent = 0;
7
+ if (this)
8
+ this.args = args;
9
+ }
10
+ indented(fn) {
11
+ this.indent += 1;
12
+ fn(this);
13
+ this.indent -= 1;
14
+ }
15
+ write(arg) {
16
+ if (typeof arg === "function") {
17
+ arg(this, { execution: "sync" });
18
+ arg(this, { execution: "async" });
19
+ return;
20
+ }
21
+ const content = arg;
22
+ const lines = content.split("\n").filter((x) => x);
23
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
24
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
25
+ for (const line of dedented) {
26
+ this.content.push(line);
27
+ }
28
+ }
29
+ compile() {
30
+ const F = Function;
31
+ const args = this?.args;
32
+ const content = this?.content ?? [``];
33
+ const lines = [...content.map((x) => ` ${x}`)];
34
+ // console.log(lines.join("\n"));
35
+ return new F(...args, lines.join("\n"));
36
+ }
37
+ }
38
+
39
+ exports.Doc = Doc;
@@ -0,0 +1,37 @@
1
+ class Doc {
2
+ constructor(args = []) {
3
+ this.content = [];
4
+ this.indent = 0;
5
+ if (this)
6
+ this.args = args;
7
+ }
8
+ indented(fn) {
9
+ this.indent += 1;
10
+ fn(this);
11
+ this.indent -= 1;
12
+ }
13
+ write(arg) {
14
+ if (typeof arg === "function") {
15
+ arg(this, { execution: "sync" });
16
+ arg(this, { execution: "async" });
17
+ return;
18
+ }
19
+ const content = arg;
20
+ const lines = content.split("\n").filter((x) => x);
21
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
22
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
23
+ for (const line of dedented) {
24
+ this.content.push(line);
25
+ }
26
+ }
27
+ compile() {
28
+ const F = Function;
29
+ const args = this?.args;
30
+ const content = this?.content ?? [``];
31
+ const lines = [...content.map((x) => ` ${x}`)];
32
+ // console.log(lines.join("\n"));
33
+ return new F(...args, lines.join("\n"));
34
+ }
35
+ }
36
+
37
+ export { Doc };
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ var core = require('./core.js');
4
+ var util = require('./util.js');
5
+
6
+ const initializer = (inst, def) => {
7
+ inst.name = "$ZodError";
8
+ Object.defineProperty(inst, "_zod", {
9
+ value: inst._zod,
10
+ enumerable: false,
11
+ });
12
+ Object.defineProperty(inst, "issues", {
13
+ value: def,
14
+ enumerable: false,
15
+ });
16
+ inst.message = JSON.stringify(def, util.jsonStringifyReplacer, 2);
17
+ Object.defineProperty(inst, "toString", {
18
+ value: () => inst.message,
19
+ enumerable: false,
20
+ });
21
+ };
22
+ const $ZodError = core.$constructor("$ZodError", initializer);
23
+ const $ZodRealError = core.$constructor("$ZodError", initializer, { Parent: Error });
24
+ function flattenError(error, mapper = (issue) => issue.message) {
25
+ const fieldErrors = {};
26
+ const formErrors = [];
27
+ for (const sub of error.issues) {
28
+ if (sub.path.length > 0) {
29
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
30
+ fieldErrors[sub.path[0]].push(mapper(sub));
31
+ }
32
+ else {
33
+ formErrors.push(mapper(sub));
34
+ }
35
+ }
36
+ return { formErrors, fieldErrors };
37
+ }
38
+ function formatError(error, mapper = (issue) => issue.message) {
39
+ const fieldErrors = { _errors: [] };
40
+ const processError = (error) => {
41
+ for (const issue of error.issues) {
42
+ if (issue.code === "invalid_union" && issue.errors.length) {
43
+ issue.errors.map((issues) => processError({ issues }));
44
+ }
45
+ else if (issue.code === "invalid_key") {
46
+ processError({ issues: issue.issues });
47
+ }
48
+ else if (issue.code === "invalid_element") {
49
+ processError({ issues: issue.issues });
50
+ }
51
+ else if (issue.path.length === 0) {
52
+ fieldErrors._errors.push(mapper(issue));
53
+ }
54
+ else {
55
+ let curr = fieldErrors;
56
+ let i = 0;
57
+ while (i < issue.path.length) {
58
+ const el = issue.path[i];
59
+ const terminal = i === issue.path.length - 1;
60
+ if (!terminal) {
61
+ curr[el] = curr[el] || { _errors: [] };
62
+ }
63
+ else {
64
+ curr[el] = curr[el] || { _errors: [] };
65
+ curr[el]._errors.push(mapper(issue));
66
+ }
67
+ curr = curr[el];
68
+ i++;
69
+ }
70
+ }
71
+ }
72
+ };
73
+ processError(error);
74
+ return fieldErrors;
75
+ }
76
+
77
+ exports.$ZodError = $ZodError;
78
+ exports.$ZodRealError = $ZodRealError;
79
+ exports.flattenError = flattenError;
80
+ exports.formatError = formatError;
@@ -0,0 +1,75 @@
1
+ import { $constructor } from './core.mjs';
2
+ import { jsonStringifyReplacer } from './util.mjs';
3
+
4
+ const initializer = (inst, def) => {
5
+ inst.name = "$ZodError";
6
+ Object.defineProperty(inst, "_zod", {
7
+ value: inst._zod,
8
+ enumerable: false,
9
+ });
10
+ Object.defineProperty(inst, "issues", {
11
+ value: def,
12
+ enumerable: false,
13
+ });
14
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
15
+ Object.defineProperty(inst, "toString", {
16
+ value: () => inst.message,
17
+ enumerable: false,
18
+ });
19
+ };
20
+ const $ZodError = $constructor("$ZodError", initializer);
21
+ const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
22
+ function flattenError(error, mapper = (issue) => issue.message) {
23
+ const fieldErrors = {};
24
+ const formErrors = [];
25
+ for (const sub of error.issues) {
26
+ if (sub.path.length > 0) {
27
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
28
+ fieldErrors[sub.path[0]].push(mapper(sub));
29
+ }
30
+ else {
31
+ formErrors.push(mapper(sub));
32
+ }
33
+ }
34
+ return { formErrors, fieldErrors };
35
+ }
36
+ function formatError(error, mapper = (issue) => issue.message) {
37
+ const fieldErrors = { _errors: [] };
38
+ const processError = (error) => {
39
+ for (const issue of error.issues) {
40
+ if (issue.code === "invalid_union" && issue.errors.length) {
41
+ issue.errors.map((issues) => processError({ issues }));
42
+ }
43
+ else if (issue.code === "invalid_key") {
44
+ processError({ issues: issue.issues });
45
+ }
46
+ else if (issue.code === "invalid_element") {
47
+ processError({ issues: issue.issues });
48
+ }
49
+ else if (issue.path.length === 0) {
50
+ fieldErrors._errors.push(mapper(issue));
51
+ }
52
+ else {
53
+ let curr = fieldErrors;
54
+ let i = 0;
55
+ while (i < issue.path.length) {
56
+ const el = issue.path[i];
57
+ const terminal = i === issue.path.length - 1;
58
+ if (!terminal) {
59
+ curr[el] = curr[el] || { _errors: [] };
60
+ }
61
+ else {
62
+ curr[el] = curr[el] || { _errors: [] };
63
+ curr[el]._errors.push(mapper(issue));
64
+ }
65
+ curr = curr[el];
66
+ i++;
67
+ }
68
+ }
69
+ }
70
+ };
71
+ processError(error);
72
+ return fieldErrors;
73
+ }
74
+
75
+ export { $ZodError, $ZodRealError, flattenError, formatError };
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ var core = require('./core.js');
4
+ var errors = require('./errors.js');
5
+ var util = require('./util.js');
6
+
7
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
8
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
9
+ const result = schema._zod.run({ value, issues: [] }, ctx);
10
+ if (result instanceof Promise) {
11
+ throw new core.$ZodAsyncError();
12
+ }
13
+ if (result.issues.length) {
14
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())));
15
+ util.captureStackTrace(e, _params?.callee);
16
+ throw e;
17
+ }
18
+ return result.value;
19
+ };
20
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
21
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
22
+ let result = schema._zod.run({ value, issues: [] }, ctx);
23
+ if (result instanceof Promise)
24
+ result = await result;
25
+ if (result.issues.length) {
26
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())));
27
+ util.captureStackTrace(e, params?.callee);
28
+ throw e;
29
+ }
30
+ return result.value;
31
+ };
32
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
33
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
34
+ const result = schema._zod.run({ value, issues: [] }, ctx);
35
+ if (result instanceof Promise) {
36
+ throw new core.$ZodAsyncError();
37
+ }
38
+ return result.issues.length
39
+ ? {
40
+ success: false,
41
+ error: new (_Err ?? errors.$ZodError)(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
42
+ }
43
+ : { success: true, data: result.value };
44
+ };
45
+ const safeParse = /* @__PURE__*/ _safeParse(errors.$ZodRealError);
46
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
47
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
48
+ let result = schema._zod.run({ value, issues: [] }, ctx);
49
+ if (result instanceof Promise)
50
+ result = await result;
51
+ return result.issues.length
52
+ ? {
53
+ success: false,
54
+ error: new _Err(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
55
+ }
56
+ : { success: true, data: result.value };
57
+ };
58
+ const safeParseAsync = /* @__PURE__*/ _safeParseAsync(errors.$ZodRealError);
59
+ const _encode = (_Err) => (schema, value, _ctx) => {
60
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
61
+ return _parse(_Err)(schema, value, ctx);
62
+ };
63
+ const _decode = (_Err) => (schema, value, _ctx) => {
64
+ return _parse(_Err)(schema, value, _ctx);
65
+ };
66
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
67
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
68
+ return _parseAsync(_Err)(schema, value, ctx);
69
+ };
70
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
71
+ return _parseAsync(_Err)(schema, value, _ctx);
72
+ };
73
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
74
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
75
+ return _safeParse(_Err)(schema, value, ctx);
76
+ };
77
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
78
+ return _safeParse(_Err)(schema, value, _ctx);
79
+ };
80
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
81
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
82
+ return _safeParseAsync(_Err)(schema, value, ctx);
83
+ };
84
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
85
+ return _safeParseAsync(_Err)(schema, value, _ctx);
86
+ };
87
+
88
+ exports._decode = _decode;
89
+ exports._decodeAsync = _decodeAsync;
90
+ exports._encode = _encode;
91
+ exports._encodeAsync = _encodeAsync;
92
+ exports._parse = _parse;
93
+ exports._parseAsync = _parseAsync;
94
+ exports._safeDecode = _safeDecode;
95
+ exports._safeDecodeAsync = _safeDecodeAsync;
96
+ exports._safeEncode = _safeEncode;
97
+ exports._safeEncodeAsync = _safeEncodeAsync;
98
+ exports._safeParse = _safeParse;
99
+ exports._safeParseAsync = _safeParseAsync;
100
+ exports.safeParse = safeParse;
101
+ exports.safeParseAsync = safeParseAsync;