@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,86 @@
1
+ import { $ZodAsyncError, config } from './core.mjs';
2
+ import { $ZodError, $ZodRealError } from './errors.mjs';
3
+ import { finalizeIssue, captureStackTrace } from './util.mjs';
4
+
5
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
6
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
7
+ const result = schema._zod.run({ value, issues: [] }, ctx);
8
+ if (result instanceof Promise) {
9
+ throw new $ZodAsyncError();
10
+ }
11
+ if (result.issues.length) {
12
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
13
+ captureStackTrace(e, _params?.callee);
14
+ throw e;
15
+ }
16
+ return result.value;
17
+ };
18
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
19
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
20
+ let result = schema._zod.run({ value, issues: [] }, ctx);
21
+ if (result instanceof Promise)
22
+ result = await result;
23
+ if (result.issues.length) {
24
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
25
+ captureStackTrace(e, params?.callee);
26
+ throw e;
27
+ }
28
+ return result.value;
29
+ };
30
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
31
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
32
+ const result = schema._zod.run({ value, issues: [] }, ctx);
33
+ if (result instanceof Promise) {
34
+ throw new $ZodAsyncError();
35
+ }
36
+ return result.issues.length
37
+ ? {
38
+ success: false,
39
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
40
+ }
41
+ : { success: true, data: result.value };
42
+ };
43
+ const safeParse = /* @__PURE__*/ _safeParse($ZodRealError);
44
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
45
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
46
+ let result = schema._zod.run({ value, issues: [] }, ctx);
47
+ if (result instanceof Promise)
48
+ result = await result;
49
+ return result.issues.length
50
+ ? {
51
+ success: false,
52
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
53
+ }
54
+ : { success: true, data: result.value };
55
+ };
56
+ const safeParseAsync = /* @__PURE__*/ _safeParseAsync($ZodRealError);
57
+ const _encode = (_Err) => (schema, value, _ctx) => {
58
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
59
+ return _parse(_Err)(schema, value, ctx);
60
+ };
61
+ const _decode = (_Err) => (schema, value, _ctx) => {
62
+ return _parse(_Err)(schema, value, _ctx);
63
+ };
64
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
65
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
66
+ return _parseAsync(_Err)(schema, value, ctx);
67
+ };
68
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
69
+ return _parseAsync(_Err)(schema, value, _ctx);
70
+ };
71
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
72
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
73
+ return _safeParse(_Err)(schema, value, ctx);
74
+ };
75
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
76
+ return _safeParse(_Err)(schema, value, _ctx);
77
+ };
78
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
79
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
80
+ return _safeParseAsync(_Err)(schema, value, ctx);
81
+ };
82
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
83
+ return _safeParseAsync(_Err)(schema, value, _ctx);
84
+ };
85
+
86
+ export { _decode, _decodeAsync, _encode, _encodeAsync, _parse, _parseAsync, _safeDecode, _safeDecodeAsync, _safeEncode, _safeEncodeAsync, _safeParse, _safeParseAsync, safeParse, safeParseAsync };
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+
3
+ const cuid = /^[cC][^\s-]{8,}$/;
4
+ const cuid2 = /^[0-9a-z]+$/;
5
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
6
+ const xid = /^[0-9a-vA-V]{20}$/;
7
+ const ksuid = /^[A-Za-z0-9]{27}$/;
8
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
9
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
10
+ const duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
11
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
12
+ const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
13
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
14
+ *
15
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
16
+ const uuid = (version) => {
17
+ if (!version)
18
+ return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
19
+ return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
20
+ };
21
+ /** Practical email validation */
22
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
23
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
24
+ const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
25
+ function emoji() {
26
+ return new RegExp(_emoji, "u");
27
+ }
28
+ const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
29
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
30
+ const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
31
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
32
+ // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
33
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
34
+ const base64url = /^[A-Za-z0-9_-]*$/;
35
+ // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
36
+ // export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
37
+ const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
38
+ // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
39
+ const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
40
+ // const dateSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
41
+ const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
42
+ const date = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
43
+ function timeSource(args) {
44
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
45
+ const regex = typeof args.precision === "number"
46
+ ? args.precision === -1
47
+ ? `${hhmm}`
48
+ : args.precision === 0
49
+ ? `${hhmm}:[0-5]\\d`
50
+ : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
51
+ : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
52
+ return regex;
53
+ }
54
+ function time(args) {
55
+ return new RegExp(`^${timeSource(args)}$`);
56
+ }
57
+ // Adapted from https://stackoverflow.com/a/3143231
58
+ function datetime(args) {
59
+ const time = timeSource({ precision: args.precision });
60
+ const opts = ["Z"];
61
+ if (args.local)
62
+ opts.push("");
63
+ // if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
64
+ if (args.offset)
65
+ opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
66
+ const timeRegex = `${time}(?:${opts.join("|")})`;
67
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
68
+ }
69
+ const string = (params) => {
70
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
71
+ return new RegExp(`^${regex}$`);
72
+ };
73
+ // regex for string with no uppercase letters
74
+ const lowercase = /^[^A-Z]*$/;
75
+ // regex for string with no lowercase letters
76
+ const uppercase = /^[^a-z]*$/;
77
+
78
+ exports.base64 = base64;
79
+ exports.base64url = base64url;
80
+ exports.cidrv4 = cidrv4;
81
+ exports.cidrv6 = cidrv6;
82
+ exports.cuid = cuid;
83
+ exports.cuid2 = cuid2;
84
+ exports.date = date;
85
+ exports.datetime = datetime;
86
+ exports.duration = duration;
87
+ exports.e164 = e164;
88
+ exports.email = email;
89
+ exports.emoji = emoji;
90
+ exports.guid = guid;
91
+ exports.hostname = hostname;
92
+ exports.ipv4 = ipv4;
93
+ exports.ipv6 = ipv6;
94
+ exports.ksuid = ksuid;
95
+ exports.lowercase = lowercase;
96
+ exports.nanoid = nanoid;
97
+ exports.string = string;
98
+ exports.time = time;
99
+ exports.ulid = ulid;
100
+ exports.uppercase = uppercase;
101
+ exports.uuid = uuid;
102
+ exports.xid = xid;
@@ -0,0 +1,76 @@
1
+ const cuid = /^[cC][^\s-]{8,}$/;
2
+ const cuid2 = /^[0-9a-z]+$/;
3
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
4
+ const xid = /^[0-9a-vA-V]{20}$/;
5
+ const ksuid = /^[A-Za-z0-9]{27}$/;
6
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
7
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
8
+ const duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
9
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
10
+ const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
11
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
12
+ *
13
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
14
+ const uuid = (version) => {
15
+ if (!version)
16
+ return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
17
+ return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
18
+ };
19
+ /** Practical email validation */
20
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
21
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
22
+ const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
23
+ function emoji() {
24
+ return new RegExp(_emoji, "u");
25
+ }
26
+ const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
27
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
28
+ const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
29
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
30
+ // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
31
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
32
+ const base64url = /^[A-Za-z0-9_-]*$/;
33
+ // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
34
+ // export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
35
+ const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
36
+ // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
37
+ const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
38
+ // const dateSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
39
+ const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
40
+ const date = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
41
+ function timeSource(args) {
42
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
43
+ const regex = typeof args.precision === "number"
44
+ ? args.precision === -1
45
+ ? `${hhmm}`
46
+ : args.precision === 0
47
+ ? `${hhmm}:[0-5]\\d`
48
+ : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
49
+ : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
50
+ return regex;
51
+ }
52
+ function time(args) {
53
+ return new RegExp(`^${timeSource(args)}$`);
54
+ }
55
+ // Adapted from https://stackoverflow.com/a/3143231
56
+ function datetime(args) {
57
+ const time = timeSource({ precision: args.precision });
58
+ const opts = ["Z"];
59
+ if (args.local)
60
+ opts.push("");
61
+ // if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
62
+ if (args.offset)
63
+ opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
64
+ const timeRegex = `${time}(?:${opts.join("|")})`;
65
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
66
+ }
67
+ const string = (params) => {
68
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
69
+ return new RegExp(`^${regex}$`);
70
+ };
71
+ // regex for string with no uppercase letters
72
+ const lowercase = /^[^A-Z]*$/;
73
+ // regex for string with no lowercase letters
74
+ const uppercase = /^[^a-z]*$/;
75
+
76
+ export { base64, base64url, cidrv4, cidrv6, cuid, cuid2, date, datetime, duration, e164, email, emoji, guid, hostname, ipv4, ipv6, ksuid, lowercase, nanoid, string, time, ulid, uppercase, uuid, xid };
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ class $ZodRegistry {
4
+ constructor() {
5
+ this._map = new WeakMap();
6
+ this._idmap = new Map();
7
+ }
8
+ add(schema, ..._meta) {
9
+ const meta = _meta[0];
10
+ this._map.set(schema, meta);
11
+ if (meta && typeof meta === "object" && "id" in meta) {
12
+ if (this._idmap.has(meta.id)) {
13
+ throw new Error(`ID ${meta.id} already exists in the registry`);
14
+ }
15
+ this._idmap.set(meta.id, schema);
16
+ }
17
+ return this;
18
+ }
19
+ clear() {
20
+ this._map = new WeakMap();
21
+ this._idmap = new Map();
22
+ return this;
23
+ }
24
+ remove(schema) {
25
+ const meta = this._map.get(schema);
26
+ if (meta && typeof meta === "object" && "id" in meta) {
27
+ this._idmap.delete(meta.id);
28
+ }
29
+ this._map.delete(schema);
30
+ return this;
31
+ }
32
+ get(schema) {
33
+ // return this._map.get(schema) as any;
34
+ // inherit metadata
35
+ const p = schema._zod.parent;
36
+ if (p) {
37
+ const pm = { ...(this.get(p) ?? {}) };
38
+ delete pm.id; // do not inherit id
39
+ const f = { ...pm, ...this._map.get(schema) };
40
+ return Object.keys(f).length ? f : undefined;
41
+ }
42
+ return this._map.get(schema);
43
+ }
44
+ has(schema) {
45
+ return this._map.has(schema);
46
+ }
47
+ }
48
+ // registries
49
+ function registry() {
50
+ return new $ZodRegistry();
51
+ }
52
+ const globalRegistry = /*@__PURE__*/ registry();
53
+
54
+ exports.$ZodRegistry = $ZodRegistry;
55
+ exports.globalRegistry = globalRegistry;
56
+ exports.registry = registry;
@@ -0,0 +1,52 @@
1
+ class $ZodRegistry {
2
+ constructor() {
3
+ this._map = new WeakMap();
4
+ this._idmap = new Map();
5
+ }
6
+ add(schema, ..._meta) {
7
+ const meta = _meta[0];
8
+ this._map.set(schema, meta);
9
+ if (meta && typeof meta === "object" && "id" in meta) {
10
+ if (this._idmap.has(meta.id)) {
11
+ throw new Error(`ID ${meta.id} already exists in the registry`);
12
+ }
13
+ this._idmap.set(meta.id, schema);
14
+ }
15
+ return this;
16
+ }
17
+ clear() {
18
+ this._map = new WeakMap();
19
+ this._idmap = new Map();
20
+ return this;
21
+ }
22
+ remove(schema) {
23
+ const meta = this._map.get(schema);
24
+ if (meta && typeof meta === "object" && "id" in meta) {
25
+ this._idmap.delete(meta.id);
26
+ }
27
+ this._map.delete(schema);
28
+ return this;
29
+ }
30
+ get(schema) {
31
+ // return this._map.get(schema) as any;
32
+ // inherit metadata
33
+ const p = schema._zod.parent;
34
+ if (p) {
35
+ const pm = { ...(this.get(p) ?? {}) };
36
+ delete pm.id; // do not inherit id
37
+ const f = { ...pm, ...this._map.get(schema) };
38
+ return Object.keys(f).length ? f : undefined;
39
+ }
40
+ return this._map.get(schema);
41
+ }
42
+ has(schema) {
43
+ return this._map.has(schema);
44
+ }
45
+ }
46
+ // registries
47
+ function registry() {
48
+ return new $ZodRegistry();
49
+ }
50
+ const globalRegistry = /*@__PURE__*/ registry();
51
+
52
+ export { $ZodRegistry, globalRegistry, registry };