@coursebuilder/adapter-drizzle 0.4.0 → 0.5.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 (255) hide show
  1. package/dist/{chunk-57CX5SOI.js → chunk-2UU2F4DM.js} +5 -4
  2. package/dist/{chunk-V23SCQL7.js → chunk-3NUCFLQJ.js} +2 -2
  3. package/dist/{chunk-Y7QZGEPT.js → chunk-4ZWS76VQ.js} +2 -2
  4. package/dist/{chunk-PPBEA4EM.js → chunk-6ON2O6UD.js} +2 -2
  5. package/dist/{chunk-ULEUIL2Y.js → chunk-7ISZNMPU.js} +3 -3
  6. package/dist/{chunk-DL3UMWB4.js → chunk-7X7TMG4A.js} +3 -3
  7. package/dist/{chunk-IDINCRHK.js → chunk-DAP5KOAO.js} +3 -3
  8. package/dist/{chunk-J4LBG2TH.js → chunk-GINRTL6J.js} +2 -2
  9. package/dist/{chunk-GLPDG7UE.js → chunk-KDEWFXEP.js} +2 -2
  10. package/dist/chunk-KDOSK7KN.js +62 -0
  11. package/dist/{chunk-MBB4GIJI.js → chunk-LERR6HQ3.js} +2 -2
  12. package/dist/{chunk-VDVCCU7D.js → chunk-LZHZDFNZ.js} +2 -2
  13. package/dist/{chunk-BX5SO2JG.js → chunk-P4VXXTVA.js} +2 -2
  14. package/dist/{chunk-VXZRMVNY.js → chunk-QP6YMUQX.js} +2 -2
  15. package/dist/{chunk-XJHSXR42.js → chunk-QPXUGIXO.js} +4 -4
  16. package/dist/{chunk-ZD3R6UPJ.js → chunk-SRTIWWLG.js} +7 -7
  17. package/dist/{chunk-N7UDJAI3.js → chunk-UHH4OVKA.js} +464 -349
  18. package/dist/chunk-UK6EHYS5.js +54 -0
  19. package/dist/{chunk-A26D3TCA.js → chunk-VUS77FG3.js} +577 -185
  20. package/dist/{chunk-FNYW3XKR.js → chunk-XIGJFVUM.js} +8 -8
  21. package/dist/{chunk-JKOYOL7A.js → chunk-YGRYHMCG.js} +2 -2
  22. package/dist/chunk-YVVXDJHI.js +56 -0
  23. package/dist/index.d.ts +2 -1
  24. package/dist/index.js +26 -23
  25. package/dist/lib/mysql/index.cjs +1424 -786
  26. package/dist/lib/mysql/index.cjs.map +1 -1
  27. package/dist/lib/mysql/index.d.cts +2056 -1162
  28. package/dist/lib/mysql/index.d.ts +2056 -1162
  29. package/dist/lib/mysql/index.js +24 -19
  30. package/dist/lib/mysql/schemas/auth/accounts.cjs +85 -77
  31. package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
  32. package/dist/lib/mysql/schemas/auth/accounts.d.cts +17 -17
  33. package/dist/lib/mysql/schemas/auth/accounts.d.ts +17 -17
  34. package/dist/lib/mysql/schemas/auth/accounts.js +12 -12
  35. package/dist/lib/mysql/schemas/auth/device-access-token.cjs +214 -0
  36. package/dist/lib/mysql/schemas/auth/device-access-token.cjs.map +1 -0
  37. package/dist/lib/mysql/schemas/auth/device-access-token.d.cts +52 -0
  38. package/dist/lib/mysql/schemas/auth/device-access-token.d.ts +52 -0
  39. package/dist/lib/mysql/schemas/auth/device-access-token.js +22 -0
  40. package/dist/lib/mysql/schemas/auth/device-access-token.js.map +1 -0
  41. package/dist/lib/mysql/schemas/auth/device-verification.cjs +222 -0
  42. package/dist/lib/mysql/schemas/auth/device-verification.cjs.map +1 -0
  43. package/dist/lib/mysql/schemas/auth/device-verification.d.cts +88 -0
  44. package/dist/lib/mysql/schemas/auth/device-verification.d.ts +88 -0
  45. package/dist/lib/mysql/schemas/auth/device-verification.js +22 -0
  46. package/dist/lib/mysql/schemas/auth/device-verification.js.map +1 -0
  47. package/dist/lib/mysql/schemas/auth/permissions.cjs +1 -1
  48. package/dist/lib/mysql/schemas/auth/permissions.cjs.map +1 -1
  49. package/dist/lib/mysql/schemas/auth/permissions.d.cts +9 -9
  50. package/dist/lib/mysql/schemas/auth/permissions.d.ts +9 -9
  51. package/dist/lib/mysql/schemas/auth/permissions.js +1 -1
  52. package/dist/lib/mysql/schemas/auth/role-permissions.cjs +74 -66
  53. package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
  54. package/dist/lib/mysql/schemas/auth/role-permissions.d.cts +10 -10
  55. package/dist/lib/mysql/schemas/auth/role-permissions.d.ts +10 -10
  56. package/dist/lib/mysql/schemas/auth/role-permissions.js +13 -13
  57. package/dist/lib/mysql/schemas/auth/roles.cjs +72 -64
  58. package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
  59. package/dist/lib/mysql/schemas/auth/roles.d.cts +10 -10
  60. package/dist/lib/mysql/schemas/auth/roles.d.ts +10 -10
  61. package/dist/lib/mysql/schemas/auth/roles.js +12 -12
  62. package/dist/lib/mysql/schemas/auth/sessions.cjs +75 -67
  63. package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
  64. package/dist/lib/mysql/schemas/auth/sessions.d.cts +6 -6
  65. package/dist/lib/mysql/schemas/auth/sessions.d.ts +6 -6
  66. package/dist/lib/mysql/schemas/auth/sessions.js +13 -13
  67. package/dist/lib/mysql/schemas/auth/user-permissions.cjs +77 -69
  68. package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
  69. package/dist/lib/mysql/schemas/auth/user-permissions.d.cts +10 -10
  70. package/dist/lib/mysql/schemas/auth/user-permissions.d.ts +10 -10
  71. package/dist/lib/mysql/schemas/auth/user-permissions.js +12 -12
  72. package/dist/lib/mysql/schemas/auth/user-prefs.cjs +222 -0
  73. package/dist/lib/mysql/schemas/auth/user-prefs.cjs.map +1 -0
  74. package/dist/lib/mysql/schemas/auth/user-prefs.d.cts +100 -0
  75. package/dist/lib/mysql/schemas/auth/user-prefs.d.ts +100 -0
  76. package/dist/lib/mysql/schemas/auth/user-prefs.js +21 -0
  77. package/dist/lib/mysql/schemas/auth/user-prefs.js.map +1 -0
  78. package/dist/lib/mysql/schemas/auth/user-roles.cjs +77 -69
  79. package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
  80. package/dist/lib/mysql/schemas/auth/user-roles.d.cts +10 -10
  81. package/dist/lib/mysql/schemas/auth/user-roles.d.ts +10 -10
  82. package/dist/lib/mysql/schemas/auth/user-roles.js +12 -12
  83. package/dist/lib/mysql/schemas/auth/users.cjs +263 -180
  84. package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
  85. package/dist/lib/mysql/schemas/auth/users.d.cts +35 -21
  86. package/dist/lib/mysql/schemas/auth/users.d.ts +35 -21
  87. package/dist/lib/mysql/schemas/auth/users.js +12 -12
  88. package/dist/lib/mysql/schemas/auth/verification-tokens.cjs +1 -1
  89. package/dist/lib/mysql/schemas/auth/verification-tokens.cjs.map +1 -1
  90. package/dist/lib/mysql/schemas/auth/verification-tokens.d.cts +5 -5
  91. package/dist/lib/mysql/schemas/auth/verification-tokens.d.ts +5 -5
  92. package/dist/lib/mysql/schemas/auth/verification-tokens.js +1 -1
  93. package/dist/lib/mysql/schemas/commerce/coupon.cjs +76 -77
  94. package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
  95. package/dist/lib/mysql/schemas/commerce/coupon.d.cts +18 -30
  96. package/dist/lib/mysql/schemas/commerce/coupon.d.ts +18 -30
  97. package/dist/lib/mysql/schemas/commerce/coupon.js +12 -12
  98. package/dist/lib/mysql/schemas/commerce/merchant-account.cjs +1 -1
  99. package/dist/lib/mysql/schemas/commerce/merchant-account.cjs.map +1 -1
  100. package/dist/lib/mysql/schemas/commerce/merchant-account.d.cts +6 -6
  101. package/dist/lib/mysql/schemas/commerce/merchant-account.d.ts +6 -6
  102. package/dist/lib/mysql/schemas/commerce/merchant-account.js +1 -1
  103. package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs +6 -5
  104. package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs.map +1 -1
  105. package/dist/lib/mysql/schemas/commerce/merchant-charge.d.cts +13 -13
  106. package/dist/lib/mysql/schemas/commerce/merchant-charge.d.ts +13 -13
  107. package/dist/lib/mysql/schemas/commerce/merchant-charge.js +4 -4
  108. package/dist/lib/mysql/schemas/commerce/merchant-coupon.cjs +1 -1
  109. package/dist/lib/mysql/schemas/commerce/merchant-coupon.cjs.map +1 -1
  110. package/dist/lib/mysql/schemas/commerce/merchant-coupon.d.cts +7 -7
  111. package/dist/lib/mysql/schemas/commerce/merchant-coupon.d.ts +7 -7
  112. package/dist/lib/mysql/schemas/commerce/merchant-coupon.js +1 -1
  113. package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs +3 -2
  114. package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs.map +1 -1
  115. package/dist/lib/mysql/schemas/commerce/merchant-customer.d.cts +7 -7
  116. package/dist/lib/mysql/schemas/commerce/merchant-customer.d.ts +7 -7
  117. package/dist/lib/mysql/schemas/commerce/merchant-customer.js +1 -1
  118. package/dist/lib/mysql/schemas/commerce/merchant-price.cjs +1 -1
  119. package/dist/lib/mysql/schemas/commerce/merchant-price.cjs.map +1 -1
  120. package/dist/lib/mysql/schemas/commerce/merchant-price.d.cts +8 -8
  121. package/dist/lib/mysql/schemas/commerce/merchant-price.d.ts +8 -8
  122. package/dist/lib/mysql/schemas/commerce/merchant-price.js +1 -1
  123. package/dist/lib/mysql/schemas/commerce/merchant-product.cjs +1 -1
  124. package/dist/lib/mysql/schemas/commerce/merchant-product.cjs.map +1 -1
  125. package/dist/lib/mysql/schemas/commerce/merchant-product.d.cts +7 -7
  126. package/dist/lib/mysql/schemas/commerce/merchant-product.d.ts +7 -7
  127. package/dist/lib/mysql/schemas/commerce/merchant-product.js +1 -1
  128. package/dist/lib/mysql/schemas/commerce/merchant-session.cjs +1 -1
  129. package/dist/lib/mysql/schemas/commerce/merchant-session.cjs.map +1 -1
  130. package/dist/lib/mysql/schemas/commerce/merchant-session.d.cts +4 -4
  131. package/dist/lib/mysql/schemas/commerce/merchant-session.d.ts +4 -4
  132. package/dist/lib/mysql/schemas/commerce/merchant-session.js +1 -1
  133. package/dist/lib/mysql/schemas/commerce/price.cjs +60 -52
  134. package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
  135. package/dist/lib/mysql/schemas/commerce/price.d.cts +11 -11
  136. package/dist/lib/mysql/schemas/commerce/price.d.ts +11 -11
  137. package/dist/lib/mysql/schemas/commerce/price.js +12 -12
  138. package/dist/lib/mysql/schemas/commerce/product.cjs +75 -67
  139. package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
  140. package/dist/lib/mysql/schemas/commerce/product.d.cts +13 -13
  141. package/dist/lib/mysql/schemas/commerce/product.d.ts +13 -13
  142. package/dist/lib/mysql/schemas/commerce/product.js +12 -12
  143. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs +105 -96
  144. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs.map +1 -1
  145. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.cts +15 -15
  146. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.ts +15 -15
  147. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +13 -13
  148. package/dist/lib/mysql/schemas/commerce/purchase.cjs +136 -131
  149. package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
  150. package/dist/lib/mysql/schemas/commerce/purchase.d.cts +25 -25
  151. package/dist/lib/mysql/schemas/commerce/purchase.d.ts +25 -25
  152. package/dist/lib/mysql/schemas/commerce/purchase.js +12 -12
  153. package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs +66 -58
  154. package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -1
  155. package/dist/lib/mysql/schemas/commerce/upgradable-products.d.cts +11 -11
  156. package/dist/lib/mysql/schemas/commerce/upgradable-products.d.ts +11 -11
  157. package/dist/lib/mysql/schemas/commerce/upgradable-products.js +13 -13
  158. package/dist/lib/mysql/schemas/communication/comment.cjs +220 -0
  159. package/dist/lib/mysql/schemas/communication/comment.cjs.map +1 -0
  160. package/dist/lib/mysql/schemas/communication/comment.d.cts +100 -0
  161. package/dist/lib/mysql/schemas/communication/comment.d.ts +100 -0
  162. package/dist/lib/mysql/schemas/communication/comment.js +21 -0
  163. package/dist/lib/mysql/schemas/communication/comment.js.map +1 -0
  164. package/dist/lib/mysql/schemas/communication/communication-channel.cjs +1 -1
  165. package/dist/lib/mysql/schemas/communication/communication-channel.cjs.map +1 -1
  166. package/dist/lib/mysql/schemas/communication/communication-channel.d.cts +8 -8
  167. package/dist/lib/mysql/schemas/communication/communication-channel.d.ts +8 -8
  168. package/dist/lib/mysql/schemas/communication/communication-channel.js +1 -1
  169. package/dist/lib/mysql/schemas/communication/communication-preference-types.cjs +1 -1
  170. package/dist/lib/mysql/schemas/communication/communication-preference-types.cjs.map +1 -1
  171. package/dist/lib/mysql/schemas/communication/communication-preference-types.d.cts +8 -8
  172. package/dist/lib/mysql/schemas/communication/communication-preference-types.d.ts +8 -8
  173. package/dist/lib/mysql/schemas/communication/communication-preference-types.js +1 -1
  174. package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +99 -91
  175. package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
  176. package/dist/lib/mysql/schemas/communication/communication-preferences.d.cts +16 -16
  177. package/dist/lib/mysql/schemas/communication/communication-preferences.d.ts +16 -16
  178. package/dist/lib/mysql/schemas/communication/communication-preferences.js +12 -12
  179. package/dist/lib/mysql/schemas/content/content-contributions.cjs +67 -59
  180. package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
  181. package/dist/lib/mysql/schemas/content/content-contributions.d.cts +13 -13
  182. package/dist/lib/mysql/schemas/content/content-contributions.d.ts +13 -13
  183. package/dist/lib/mysql/schemas/content/content-contributions.js +12 -12
  184. package/dist/lib/mysql/schemas/content/content-resource-product.cjs +61 -53
  185. package/dist/lib/mysql/schemas/content/content-resource-product.cjs.map +1 -1
  186. package/dist/lib/mysql/schemas/content/content-resource-product.d.cts +11 -11
  187. package/dist/lib/mysql/schemas/content/content-resource-product.d.ts +11 -11
  188. package/dist/lib/mysql/schemas/content/content-resource-product.js +12 -12
  189. package/dist/lib/mysql/schemas/content/content-resource-resource.cjs +58 -50
  190. package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
  191. package/dist/lib/mysql/schemas/content/content-resource-resource.d.cts +11 -11
  192. package/dist/lib/mysql/schemas/content/content-resource-resource.d.ts +11 -11
  193. package/dist/lib/mysql/schemas/content/content-resource-resource.js +12 -12
  194. package/dist/lib/mysql/schemas/content/content-resource.cjs +114 -66
  195. package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
  196. package/dist/lib/mysql/schemas/content/content-resource.d.cts +14 -13
  197. package/dist/lib/mysql/schemas/content/content-resource.d.ts +14 -13
  198. package/dist/lib/mysql/schemas/content/content-resource.js +12 -12
  199. package/dist/lib/mysql/schemas/content/contribution-types.cjs +1 -1
  200. package/dist/lib/mysql/schemas/content/contribution-types.cjs.map +1 -1
  201. package/dist/lib/mysql/schemas/content/contribution-types.d.cts +10 -10
  202. package/dist/lib/mysql/schemas/content/contribution-types.d.ts +10 -10
  203. package/dist/lib/mysql/schemas/content/contribution-types.js +1 -1
  204. package/dist/lib/mysql/schemas/content/lesson-progress.cjs +77 -0
  205. package/dist/lib/mysql/schemas/content/lesson-progress.cjs.map +1 -0
  206. package/dist/lib/mysql/schemas/content/lesson-progress.d.cts +132 -0
  207. package/dist/lib/mysql/schemas/content/lesson-progress.d.ts +132 -0
  208. package/dist/lib/mysql/schemas/content/lesson-progress.js +8 -0
  209. package/dist/lib/mysql/schemas/content/lesson-progress.js.map +1 -0
  210. package/dist/lib/mysql/schemas/content/resource-progress.cjs +7 -7
  211. package/dist/lib/mysql/schemas/content/resource-progress.cjs.map +1 -1
  212. package/dist/lib/mysql/schemas/content/resource-progress.d.cts +9 -9
  213. package/dist/lib/mysql/schemas/content/resource-progress.d.ts +9 -9
  214. package/dist/lib/mysql/schemas/content/resource-progress.js +1 -1
  215. package/dist/lib/utils.d.cts +1 -0
  216. package/dist/lib/utils.d.ts +1 -0
  217. package/package.json +7 -5
  218. package/src/index.ts +14 -4
  219. package/src/lib/mysql/index.ts +675 -153
  220. package/src/lib/mysql/schemas/auth/accounts.ts +1 -1
  221. package/src/lib/mysql/schemas/auth/device-access-token.ts +40 -0
  222. package/src/lib/mysql/schemas/auth/device-verification.ts +48 -0
  223. package/src/lib/mysql/schemas/auth/permissions.ts +1 -1
  224. package/src/lib/mysql/schemas/auth/role-permissions.ts +1 -1
  225. package/src/lib/mysql/schemas/auth/roles.ts +1 -1
  226. package/src/lib/mysql/schemas/auth/sessions.ts +1 -1
  227. package/src/lib/mysql/schemas/auth/user-permissions.ts +1 -1
  228. package/src/lib/mysql/schemas/auth/user-prefs.ts +52 -0
  229. package/src/lib/mysql/schemas/auth/user-roles.ts +1 -1
  230. package/src/lib/mysql/schemas/auth/users.ts +14 -2
  231. package/src/lib/mysql/schemas/auth/verification-tokens.ts +1 -1
  232. package/src/lib/mysql/schemas/commerce/coupon.ts +4 -13
  233. package/src/lib/mysql/schemas/commerce/merchant-account.ts +1 -1
  234. package/src/lib/mysql/schemas/commerce/merchant-charge.ts +1 -1
  235. package/src/lib/mysql/schemas/commerce/merchant-coupon.ts +1 -1
  236. package/src/lib/mysql/schemas/commerce/merchant-customer.ts +3 -1
  237. package/src/lib/mysql/schemas/commerce/merchant-price.ts +1 -1
  238. package/src/lib/mysql/schemas/commerce/merchant-product.ts +1 -1
  239. package/src/lib/mysql/schemas/commerce/merchant-session.ts +1 -1
  240. package/src/lib/mysql/schemas/commerce/price.ts +1 -1
  241. package/src/lib/mysql/schemas/commerce/product.ts +1 -1
  242. package/src/lib/mysql/schemas/commerce/purchase-user-transfer.ts +1 -1
  243. package/src/lib/mysql/schemas/commerce/purchase.ts +5 -4
  244. package/src/lib/mysql/schemas/commerce/upgradable-products.ts +1 -1
  245. package/src/lib/mysql/schemas/communication/comment.ts +52 -0
  246. package/src/lib/mysql/schemas/communication/communication-channel.ts +1 -1
  247. package/src/lib/mysql/schemas/communication/communication-preference-types.ts +1 -1
  248. package/src/lib/mysql/schemas/communication/communication-preferences.ts +1 -1
  249. package/src/lib/mysql/schemas/content/content-contributions.ts +1 -1
  250. package/src/lib/mysql/schemas/content/content-resource-product.ts +1 -1
  251. package/src/lib/mysql/schemas/content/content-resource-resource.ts +1 -1
  252. package/src/lib/mysql/schemas/content/content-resource.ts +6 -2
  253. package/src/lib/mysql/schemas/content/contribution-types.ts +1 -1
  254. package/src/lib/mysql/schemas/content/lesson-progress.ts +39 -0
  255. package/src/lib/mysql/schemas/content/resource-progress.ts +6 -8
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
9
  var __export = (target, all) => {
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc2) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
 
21
31
  // src/lib/mysql/index.ts
@@ -23,12 +33,15 @@ var mysql_exports = {};
23
33
  __export(mysql_exports, {
24
34
  createTables: () => createTables,
25
35
  getCourseBuilderSchema: () => getCourseBuilderSchema,
36
+ guid: () => guid,
26
37
  mySqlDrizzleAdapter: () => mySqlDrizzleAdapter
27
38
  });
28
39
  module.exports = __toCommonJS(mysql_exports);
40
+ var import_slugify = __toESM(require("@sindresorhus/slugify"), 1);
29
41
  var import_date_fns2 = require("date-fns");
30
- var import_drizzle_orm27 = require("drizzle-orm");
31
- var import_mysql_core32 = require("drizzle-orm/mysql-core");
42
+ var import_drizzle_orm32 = require("drizzle-orm");
43
+ var import_mysql_core37 = require("drizzle-orm/mysql-core");
44
+ var import_nanoid = require("nanoid");
32
45
  var import_uuid = require("uuid");
33
46
 
34
47
  // ../../node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
@@ -185,8 +198,8 @@ var ZodIssueCode = util.arrayToEnum([
185
198
  "not_finite"
186
199
  ]);
187
200
  var quotelessJson = /* @__PURE__ */ __name((obj) => {
188
- const json10 = JSON.stringify(obj, null, 2);
189
- return json10.replace(/"([^"]+)":/g, "$1:");
201
+ const json13 = JSON.stringify(obj, null, 2);
202
+ return json13.replace(/"([^"]+)":/g, "$1:");
190
203
  }, "quotelessJson");
191
204
  var _ZodError = class _ZodError extends Error {
192
205
  constructor(issues) {
@@ -2305,10 +2318,10 @@ var _ZodObject = class _ZodObject extends ZodType {
2305
2318
  // }) as any;
2306
2319
  // return merged;
2307
2320
  // }
2308
- catchall(index19) {
2321
+ catchall(index25) {
2309
2322
  return new _ZodObject({
2310
2323
  ...this._def,
2311
- catchall: index19
2324
+ catchall: index25
2312
2325
  });
2313
2326
  }
2314
2327
  pick(mask) {
@@ -2623,9 +2636,9 @@ function mergeValues(a, b) {
2623
2636
  return { valid: false };
2624
2637
  }
2625
2638
  const newArray = [];
2626
- for (let index19 = 0; index19 < a.length; index19++) {
2627
- const itemA = a[index19];
2628
- const itemB = b[index19];
2639
+ for (let index25 = 0; index25 < a.length; index25++) {
2640
+ const itemA = a[index25];
2641
+ const itemB = b[index25];
2629
2642
  const sharedValue = mergeValues(itemA, itemB);
2630
2643
  if (!sharedValue.valid) {
2631
2644
  return { valid: false };
@@ -2837,10 +2850,10 @@ var _ZodMap = class _ZodMap extends ZodType {
2837
2850
  }
2838
2851
  const keyType = this._def.keyType;
2839
2852
  const valueType = this._def.valueType;
2840
- const pairs = [...ctx.data.entries()].map(([key, value], index19) => {
2853
+ const pairs = [...ctx.data.entries()].map(([key, value], index25) => {
2841
2854
  return {
2842
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index19, "key"])),
2843
- value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index19, "value"]))
2855
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index25, "key"])),
2856
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index25, "value"]))
2844
2857
  };
2845
2858
  });
2846
2859
  if (ctx.common.async) {
@@ -4033,8 +4046,8 @@ var ZodIssueCode2 = util2.arrayToEnum([
4033
4046
  "not_finite"
4034
4047
  ]);
4035
4048
  var quotelessJson2 = /* @__PURE__ */ __name2((obj) => {
4036
- const json10 = JSON.stringify(obj, null, 2);
4037
- return json10.replace(/"([^"]+)":/g, "$1:");
4049
+ const json13 = JSON.stringify(obj, null, 2);
4050
+ return json13.replace(/"([^"]+)":/g, "$1:");
4038
4051
  }, "quotelessJson");
4039
4052
  var _a;
4040
4053
  var _ZodError2 = (_a = class extends Error {
@@ -6338,10 +6351,10 @@ var _ZodObject2 = (_a18 = class extends ZodType2 {
6338
6351
  // }) as any;
6339
6352
  // return merged;
6340
6353
  // }
6341
- catchall(index19) {
6354
+ catchall(index25) {
6342
6355
  return new _a18({
6343
6356
  ...this._def,
6344
- catchall: index19
6357
+ catchall: index25
6345
6358
  });
6346
6359
  }
6347
6360
  pick(mask) {
@@ -6683,9 +6696,9 @@ function mergeValues2(a, b) {
6683
6696
  };
6684
6697
  }
6685
6698
  const newArray = [];
6686
- for (let index19 = 0; index19 < a.length; index19++) {
6687
- const itemA = a[index19];
6688
- const itemB = b[index19];
6699
+ for (let index25 = 0; index25 < a.length; index25++) {
6700
+ const itemA = a[index25];
6701
+ const itemB = b[index25];
6689
6702
  const sharedValue = mergeValues2(itemA, itemB);
6690
6703
  if (!sharedValue.valid) {
6691
6704
  return {
@@ -6919,14 +6932,14 @@ var _ZodMap2 = (_a24 = class extends ZodType2 {
6919
6932
  const valueType = this._def.valueType;
6920
6933
  const pairs = [
6921
6934
  ...ctx.data.entries()
6922
- ].map(([key, value], index19) => {
6935
+ ].map(([key, value], index25) => {
6923
6936
  return {
6924
6937
  key: keyType._parse(new ParseInputLazyPath2(ctx, key, ctx.path, [
6925
- index19,
6938
+ index25,
6926
6939
  "key"
6927
6940
  ])),
6928
6941
  value: valueType._parse(new ParseInputLazyPath2(ctx, value, ctx.path, [
6929
- index19,
6942
+ index25,
6930
6943
  "value"
6931
6944
  ]))
6932
6945
  };
@@ -8044,6 +8057,29 @@ var z2 = /* @__PURE__ */ Object.freeze({
8044
8057
  ZodError: ZodError2
8045
8058
  });
8046
8059
 
8060
+ // ../core/dist/chunk-CMH4QQ3R.js
8061
+ var VideoResourceSchema = z2.object({
8062
+ id: z2.string(),
8063
+ updatedAt: z2.coerce.date().optional(),
8064
+ createdAt: z2.coerce.date().optional(),
8065
+ title: z2.string().optional().nullable(),
8066
+ duration: z2.number().optional().nullable(),
8067
+ muxPlaybackId: z2.string().optional().nullable(),
8068
+ muxAssetId: z2.string().optional().nullable(),
8069
+ transcript: z2.string().optional().nullable(),
8070
+ transcriptWithScreenshots: z2.string().optional().nullable(),
8071
+ srt: z2.string().optional().nullable(),
8072
+ wordLevelSrt: z2.string().optional().nullable(),
8073
+ state: z2.enum([
8074
+ "new",
8075
+ "processing",
8076
+ "preparing",
8077
+ "ready",
8078
+ "errored",
8079
+ "deleted"
8080
+ ])
8081
+ });
8082
+
8047
8083
  // ../core/dist/chunk-CHYUPSYW.js
8048
8084
  var userSchema = z2.object({
8049
8085
  id: z2.string().max(255),
@@ -8078,15 +8114,15 @@ var priceSchema = z2.object({
8078
8114
  fields: z2.record(z2.any()).default({})
8079
8115
  });
8080
8116
 
8081
- // ../core/dist/chunk-YYIPQN6H.js
8117
+ // ../core/dist/chunk-5BAEWUNU.js
8082
8118
  var ContentResourceResourceSchema = z2.object({
8083
8119
  resourceId: z2.string(),
8084
8120
  resourceOfId: z2.string(),
8085
8121
  position: z2.number().default(0),
8086
8122
  metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
8087
- createdAt: z2.date().nullable(),
8088
- updatedAt: z2.date().nullable(),
8089
- deletedAt: z2.date().nullable(),
8123
+ createdAt: z2.coerce.date().nullable(),
8124
+ updatedAt: z2.coerce.date().nullable(),
8125
+ deletedAt: z2.coerce.date().nullable(),
8090
8126
  resource: z2.any()
8091
8127
  });
8092
8128
  var ContentResourceSchema = z2.object({
@@ -8094,9 +8130,9 @@ var ContentResourceSchema = z2.object({
8094
8130
  type: z2.string(),
8095
8131
  createdById: z2.string(),
8096
8132
  fields: z2.record(z2.string(), z2.any()).default({}).nullable().optional(),
8097
- createdAt: z2.date().nullable(),
8098
- updatedAt: z2.date().nullable(),
8099
- deletedAt: z2.date().nullable(),
8133
+ createdAt: z2.coerce.date().nullable(),
8134
+ updatedAt: z2.coerce.date().nullable(),
8135
+ deletedAt: z2.coerce.date().nullable(),
8100
8136
  resources: z2.array(ContentResourceResourceSchema).default([]).nullable()
8101
8137
  });
8102
8138
  var ContentResourceProductSchema = z2.object({
@@ -8104,9 +8140,9 @@ var ContentResourceProductSchema = z2.object({
8104
8140
  productId: z2.string(),
8105
8141
  position: z2.number().default(0),
8106
8142
  metadata: z2.record(z2.string(), z2.any()).default({}).nullable(),
8107
- createdAt: z2.date().nullable(),
8108
- updatedAt: z2.date().nullable(),
8109
- deletedAt: z2.date().nullable(),
8143
+ createdAt: z2.coerce.date().nullable(),
8144
+ updatedAt: z2.coerce.date().nullable(),
8145
+ deletedAt: z2.coerce.date().nullable(),
8110
8146
  resource: z2.any(),
8111
8147
  product: z2.any()
8112
8148
  });
@@ -8122,7 +8158,7 @@ var ResourceVisibilitySchema = z2.union([
8122
8158
  z2.literal("unlisted")
8123
8159
  ]);
8124
8160
 
8125
- // ../core/dist/chunk-DGMGNBW7.js
8161
+ // ../core/dist/chunk-SVQMPVCK.js
8126
8162
  var productSchema = z2.object({
8127
8163
  id: z2.string().max(191),
8128
8164
  name: z2.string().max(191),
@@ -8133,10 +8169,10 @@ var productSchema = z2.object({
8133
8169
  ]).default("self-paced"),
8134
8170
  fields: z2.object({
8135
8171
  body: z2.string().nullable().optional(),
8136
- description: z2.string().optional().nullable(),
8172
+ description: z2.string().nullish(),
8137
8173
  slug: z2.string(),
8138
8174
  image: z2.object({
8139
- url: z2.string().url(),
8175
+ url: z2.string(),
8140
8176
  alt: z2.string().optional().nullable(),
8141
8177
  width: z2.number().optional().nullable(),
8142
8178
  height: z2.number().optional().nullable()
@@ -8154,14 +8190,19 @@ var productSchema = z2.object({
8154
8190
  "unlisted"
8155
8191
  ]).default("unlisted")
8156
8192
  }),
8157
- createdAt: z2.date().nullable(),
8193
+ createdAt: z2.coerce.date().nullable(),
8158
8194
  status: z2.number().int().default(0),
8159
8195
  quantityAvailable: z2.number().int().default(-1),
8160
8196
  price: priceSchema.nullable().optional(),
8161
8197
  resources: z2.array(ContentResourceProductSchema).default([]).nullable()
8162
8198
  });
8199
+ var NewProductSchema = z2.object({
8200
+ name: z2.string().min(2).max(90),
8201
+ quantityAvailable: z2.coerce.number().default(-1),
8202
+ price: z2.coerce.number().gte(0).default(0)
8203
+ });
8163
8204
 
8164
- // ../core/dist/chunk-VDB4YSMY.js
8205
+ // ../core/dist/chunk-RCFZC3SN.js
8165
8206
  var couponSchema = z2.object({
8166
8207
  id: z2.string(),
8167
8208
  code: z2.string().max(191).optional().nullable(),
@@ -8178,11 +8219,12 @@ var couponSchema = z2.object({
8178
8219
  return decimalPlaces <= 2;
8179
8220
  }),
8180
8221
  restrictedToProductId: z2.string().max(191).optional().nullable(),
8181
- bulkPurchaseId: z2.string().max(191).optional().nullable(),
8182
- bulkCouponPurchases: z2.any().optional().nullable()
8222
+ bulkPurchases: z2.array(z2.any()).default([]),
8223
+ redeemedBulkCouponPurchases: z2.array(z2.any()).default([]),
8224
+ bulkPurchaseId: z2.string().max(191).optional().nullable()
8183
8225
  });
8184
8226
 
8185
- // ../core/dist/chunk-OUYYSWMK.js
8227
+ // ../core/dist/chunk-5OFQV6YX.js
8186
8228
  var purchaseSchema = z2.object({
8187
8229
  id: z2.string().max(191),
8188
8230
  userId: z2.string().max(191).optional().nullable(),
@@ -8231,18 +8273,15 @@ var purchaseUserTransferSchema = z2.object({
8231
8273
  completedAt: z2.date().nullable()
8232
8274
  });
8233
8275
 
8234
- // ../core/dist/chunk-GCYJ74DO.js
8276
+ // ../core/dist/chunk-CWQHSOPP.js
8235
8277
  var resourceProgressSchema = z2.object({
8236
8278
  userId: z2.string().max(191),
8237
- contentResourceId: z2.string().max(191).optional().nullable(),
8238
- fields: z2.record(z2.any()).default({}),
8239
- completedAt: z2.date().nullable(),
8240
- updatedAt: z2.date().nullable(),
8241
- createdAt: z2.date().nullable()
8279
+ resourceId: z2.string().max(191).optional().nullable(),
8280
+ completedAt: z2.date().nullable()
8242
8281
  });
8243
8282
  var moduleProgressSchema = z2.object({
8244
8283
  completedLessons: z2.array(resourceProgressSchema),
8245
- nextResource: ContentResourceSchema.nullable(),
8284
+ nextResource: ContentResourceSchema.partial().nullable(),
8246
8285
  percentCompleted: z2.number().default(0),
8247
8286
  completedLessonsCount: z2.number().default(0),
8248
8287
  totalLessonsCount: z2.number().default(0)
@@ -8259,28 +8298,6 @@ var upgradableProductSchema = z2.object({
8259
8298
  deletedAt: z2.date().nullable()
8260
8299
  });
8261
8300
 
8262
- // ../core/dist/chunk-G22WGQ3G.js
8263
- var VideoResourceSchema = z2.object({
8264
- id: z2.string(),
8265
- updatedAt: z2.string().optional(),
8266
- createdAt: z2.string().optional(),
8267
- title: z2.string().optional().nullable(),
8268
- duration: z2.number().optional().nullable(),
8269
- muxPlaybackId: z2.string().optional().nullable(),
8270
- muxAssetId: z2.string().optional().nullable(),
8271
- transcript: z2.string().optional().nullable(),
8272
- transcriptWithScreenshots: z2.string().optional().nullable(),
8273
- srt: z2.string().optional().nullable(),
8274
- wordLevelSrt: z2.string().optional().nullable(),
8275
- state: z2.enum([
8276
- "new",
8277
- "processing",
8278
- "preparing",
8279
- "ready",
8280
- "errored"
8281
- ])
8282
- });
8283
-
8284
8301
  // ../core/dist/chunk-EDDT2FFU.js
8285
8302
  var merchantCustomerSchema = z2.object({
8286
8303
  id: z2.string().max(191),
@@ -8476,25 +8493,25 @@ var validateCoupon = /* @__PURE__ */ __name2((coupon, productIds = []) => {
8476
8493
  }, "validateCoupon");
8477
8494
 
8478
8495
  // src/lib/mysql/schemas/auth/accounts.ts
8479
- var import_drizzle_orm21 = require("drizzle-orm");
8480
- var import_mysql_core25 = require("drizzle-orm/mysql-core");
8496
+ var import_drizzle_orm23 = require("drizzle-orm");
8497
+ var import_mysql_core27 = require("drizzle-orm/mysql-core");
8481
8498
 
8482
8499
  // src/lib/mysql/schemas/auth/users.ts
8483
- var import_drizzle_orm20 = require("drizzle-orm");
8484
- var import_mysql_core24 = require("drizzle-orm/mysql-core");
8500
+ var import_drizzle_orm22 = require("drizzle-orm");
8501
+ var import_mysql_core26 = require("drizzle-orm/mysql-core");
8485
8502
 
8486
8503
  // src/lib/mysql/schemas/commerce/purchase.ts
8487
- var import_drizzle_orm12 = require("drizzle-orm");
8488
- var import_mysql_core14 = require("drizzle-orm/mysql-core");
8504
+ var import_drizzle_orm14 = require("drizzle-orm");
8505
+ var import_mysql_core16 = require("drizzle-orm/mysql-core");
8489
8506
 
8490
8507
  // src/lib/mysql/schemas/commerce/coupon.ts
8491
- var import_drizzle_orm8 = require("drizzle-orm");
8492
- var import_mysql_core9 = require("drizzle-orm/mysql-core");
8508
+ var import_drizzle_orm10 = require("drizzle-orm");
8509
+ var import_mysql_core11 = require("drizzle-orm/mysql-core");
8493
8510
 
8494
8511
  // src/lib/mysql/schemas/commerce/merchant-coupon.ts
8495
8512
  var import_mysql_core = require("drizzle-orm/mysql-core");
8496
8513
  function getMerchantCouponSchema(mysqlTable) {
8497
- return mysqlTable("merchantCoupons", {
8514
+ return mysqlTable("MerchantCoupon", {
8498
8515
  id: (0, import_mysql_core.varchar)("id", {
8499
8516
  length: 191
8500
8517
  }).notNull(),
@@ -8527,58 +8544,174 @@ function getMerchantCouponSchema(mysqlTable) {
8527
8544
  __name(getMerchantCouponSchema, "getMerchantCouponSchema");
8528
8545
 
8529
8546
  // src/lib/mysql/schemas/commerce/product.ts
8530
- var import_drizzle_orm7 = require("drizzle-orm");
8531
- var import_mysql_core8 = require("drizzle-orm/mysql-core");
8547
+ var import_drizzle_orm9 = require("drizzle-orm");
8548
+ var import_mysql_core10 = require("drizzle-orm/mysql-core");
8532
8549
 
8533
8550
  // src/lib/mysql/schemas/content/content-resource-product.ts
8534
- var import_drizzle_orm3 = require("drizzle-orm");
8535
- var import_mysql_core4 = require("drizzle-orm/mysql-core");
8551
+ var import_drizzle_orm5 = require("drizzle-orm");
8552
+ var import_mysql_core6 = require("drizzle-orm/mysql-core");
8536
8553
 
8537
8554
  // src/lib/mysql/schemas/content/content-resource.ts
8555
+ var import_drizzle_orm4 = require("drizzle-orm");
8556
+ var import_mysql_core5 = require("drizzle-orm/mysql-core");
8557
+
8558
+ // src/lib/mysql/schemas/content/content-contributions.ts
8538
8559
  var import_drizzle_orm2 = require("drizzle-orm");
8539
8560
  var import_mysql_core3 = require("drizzle-orm/mysql-core");
8540
8561
 
8541
- // src/lib/mysql/schemas/content/content-resource-resource.ts
8562
+ // src/lib/mysql/schemas/content/contribution-types.ts
8542
8563
  var import_drizzle_orm = require("drizzle-orm");
8543
8564
  var import_mysql_core2 = require("drizzle-orm/mysql-core");
8544
- function getContentResourceResourceSchema(mysqlTable) {
8545
- return mysqlTable("contentResourceResource", {
8546
- resourceOfId: (0, import_mysql_core2.varchar)("resourceOfId", {
8565
+ function getContributionTypesSchema(mysqlTable) {
8566
+ return mysqlTable("ContributionType", {
8567
+ id: (0, import_mysql_core2.varchar)("id", {
8547
8568
  length: 255
8548
- }).notNull(),
8549
- resourceId: (0, import_mysql_core2.varchar)("resourceId", {
8569
+ }).notNull().primaryKey(),
8570
+ slug: (0, import_mysql_core2.varchar)("slug", {
8571
+ length: 255
8572
+ }).notNull().unique(),
8573
+ name: (0, import_mysql_core2.varchar)("name", {
8550
8574
  length: 255
8551
8575
  }).notNull(),
8552
- position: (0, import_mysql_core2.double)("position").notNull().default(0),
8553
- metadata: (0, import_mysql_core2.json)("metadata").$type().default({}),
8576
+ description: (0, import_mysql_core2.text)("description"),
8577
+ active: (0, import_mysql_core2.boolean)("active").notNull().default(true),
8554
8578
  createdAt: (0, import_mysql_core2.timestamp)("createdAt", {
8555
8579
  mode: "date",
8556
8580
  fsp: 3
8557
- }).default(import_drizzle_orm.sql`CURRENT_TIMESTAMP(3)`),
8581
+ }).defaultNow(),
8558
8582
  updatedAt: (0, import_mysql_core2.timestamp)("updatedAt", {
8559
8583
  mode: "date",
8560
8584
  fsp: 3
8561
- }).default(import_drizzle_orm.sql`CURRENT_TIMESTAMP(3)`),
8585
+ }).defaultNow(),
8562
8586
  deletedAt: (0, import_mysql_core2.timestamp)("deletedAt", {
8563
8587
  mode: "date",
8564
8588
  fsp: 3
8565
8589
  })
8590
+ }, (ct) => ({
8591
+ nameIdx: (0, import_mysql_core2.index)("name_idx").on(ct.name),
8592
+ slugIdx: (0, import_mysql_core2.index)("slug_idx").on(ct.slug)
8593
+ }));
8594
+ }
8595
+ __name(getContributionTypesSchema, "getContributionTypesSchema");
8596
+ function getContributionTypesRelationsSchema(mysqlTable) {
8597
+ const contributionTypes = getContributionTypesSchema(mysqlTable);
8598
+ return (0, import_drizzle_orm.relations)(contributionTypes, ({ many }) => ({}));
8599
+ }
8600
+ __name(getContributionTypesRelationsSchema, "getContributionTypesRelationsSchema");
8601
+
8602
+ // src/lib/mysql/schemas/content/content-contributions.ts
8603
+ function getContentContributionsSchema(mysqlTable) {
8604
+ return mysqlTable("ContentContribution", {
8605
+ id: (0, import_mysql_core3.varchar)("id", {
8606
+ length: 255
8607
+ }).notNull().primaryKey(),
8608
+ userId: (0, import_mysql_core3.varchar)("userId", {
8609
+ length: 255
8610
+ }).notNull(),
8611
+ contentId: (0, import_mysql_core3.varchar)("contentId", {
8612
+ length: 255
8613
+ }).notNull(),
8614
+ contributionTypeId: (0, import_mysql_core3.varchar)("contributionTypeId", {
8615
+ length: 255
8616
+ }).notNull(),
8617
+ active: (0, import_mysql_core3.boolean)("active").notNull().default(true),
8618
+ createdAt: (0, import_mysql_core3.timestamp)("createdAt", {
8619
+ mode: "date",
8620
+ fsp: 3
8621
+ }).defaultNow(),
8622
+ updatedAt: (0, import_mysql_core3.timestamp)("updatedAt", {
8623
+ mode: "date",
8624
+ fsp: 3
8625
+ }).defaultNow(),
8626
+ deletedAt: (0, import_mysql_core3.timestamp)("deletedAt", {
8627
+ mode: "date",
8628
+ fsp: 3
8629
+ })
8630
+ }, (cc) => ({
8631
+ userIdIdx: (0, import_mysql_core3.index)("userId_idx").on(cc.userId),
8632
+ contentIdIdx: (0, import_mysql_core3.index)("contentId_idx").on(cc.contentId),
8633
+ contributionTypeIdIdx: (0, import_mysql_core3.index)("contributionTypeId_idx").on(cc.contributionTypeId)
8634
+ }));
8635
+ }
8636
+ __name(getContentContributionsSchema, "getContentContributionsSchema");
8637
+ function getContentContributionRelationsSchema(mysqlTable) {
8638
+ const contentContributions = getContentContributionsSchema(mysqlTable);
8639
+ const users = getUsersSchema(mysqlTable);
8640
+ const contentResource = getContentResourceSchema(mysqlTable);
8641
+ const contributionTypes = getContributionTypesSchema(mysqlTable);
8642
+ return (0, import_drizzle_orm2.relations)(contentContributions, ({ one }) => ({
8643
+ user: one(users, {
8644
+ fields: [
8645
+ contentContributions.userId
8646
+ ],
8647
+ references: [
8648
+ users.id
8649
+ ],
8650
+ relationName: "user"
8651
+ }),
8652
+ content: one(contentResource, {
8653
+ fields: [
8654
+ contentContributions.contentId
8655
+ ],
8656
+ references: [
8657
+ contentResource.id
8658
+ ],
8659
+ relationName: "contributions"
8660
+ }),
8661
+ contributionType: one(contributionTypes, {
8662
+ fields: [
8663
+ contentContributions.contributionTypeId
8664
+ ],
8665
+ references: [
8666
+ contributionTypes.id
8667
+ ],
8668
+ relationName: "contributionType"
8669
+ })
8670
+ }));
8671
+ }
8672
+ __name(getContentContributionRelationsSchema, "getContentContributionRelationsSchema");
8673
+
8674
+ // src/lib/mysql/schemas/content/content-resource-resource.ts
8675
+ var import_drizzle_orm3 = require("drizzle-orm");
8676
+ var import_mysql_core4 = require("drizzle-orm/mysql-core");
8677
+ function getContentResourceResourceSchema(mysqlTable) {
8678
+ return mysqlTable("ContentResourceResource", {
8679
+ resourceOfId: (0, import_mysql_core4.varchar)("resourceOfId", {
8680
+ length: 255
8681
+ }).notNull(),
8682
+ resourceId: (0, import_mysql_core4.varchar)("resourceId", {
8683
+ length: 255
8684
+ }).notNull(),
8685
+ position: (0, import_mysql_core4.double)("position").notNull().default(0),
8686
+ metadata: (0, import_mysql_core4.json)("metadata").$type().default({}),
8687
+ createdAt: (0, import_mysql_core4.timestamp)("createdAt", {
8688
+ mode: "date",
8689
+ fsp: 3
8690
+ }).default(import_drizzle_orm3.sql`CURRENT_TIMESTAMP(3)`),
8691
+ updatedAt: (0, import_mysql_core4.timestamp)("updatedAt", {
8692
+ mode: "date",
8693
+ fsp: 3
8694
+ }).default(import_drizzle_orm3.sql`CURRENT_TIMESTAMP(3)`),
8695
+ deletedAt: (0, import_mysql_core4.timestamp)("deletedAt", {
8696
+ mode: "date",
8697
+ fsp: 3
8698
+ })
8566
8699
  }, (crr) => ({
8567
- pk: (0, import_mysql_core2.primaryKey)({
8700
+ pk: (0, import_mysql_core4.primaryKey)({
8568
8701
  columns: [
8569
8702
  crr.resourceOfId,
8570
8703
  crr.resourceId
8571
8704
  ]
8572
8705
  }),
8573
- contentResourceIdIdx: (0, import_mysql_core2.index)("contentResourceId_idx").on(crr.resourceOfId),
8574
- resourceIdIdx: (0, import_mysql_core2.index)("resourceId_idx").on(crr.resourceId)
8706
+ contentResourceIdIdx: (0, import_mysql_core4.index)("contentResourceId_idx").on(crr.resourceOfId),
8707
+ resourceIdIdx: (0, import_mysql_core4.index)("resourceId_idx").on(crr.resourceId)
8575
8708
  }));
8576
8709
  }
8577
8710
  __name(getContentResourceResourceSchema, "getContentResourceResourceSchema");
8578
8711
  function getContentResourceResourceRelationsSchema(mysqlTable) {
8579
8712
  const contentResource = getContentResourceSchema(mysqlTable);
8580
8713
  const contentResourceResource = getContentResourceResourceSchema(mysqlTable);
8581
- return (0, import_drizzle_orm.relations)(contentResourceResource, ({ one }) => ({
8714
+ return (0, import_drizzle_orm3.relations)(contentResourceResource, ({ one }) => ({
8582
8715
  resourceOf: one(contentResource, {
8583
8716
  fields: [
8584
8717
  contentResourceResource.resourceOfId
@@ -8603,33 +8736,33 @@ __name(getContentResourceResourceRelationsSchema, "getContentResourceResourceRel
8603
8736
 
8604
8737
  // src/lib/mysql/schemas/content/content-resource.ts
8605
8738
  function getContentResourceSchema(mysqlTable) {
8606
- return mysqlTable("contentResource", {
8607
- id: (0, import_mysql_core3.varchar)("id", {
8739
+ return mysqlTable("ContentResource", {
8740
+ id: (0, import_mysql_core5.varchar)("id", {
8608
8741
  length: 255
8609
8742
  }).notNull().primaryKey(),
8610
- type: (0, import_mysql_core3.varchar)("type", {
8743
+ type: (0, import_mysql_core5.varchar)("type", {
8611
8744
  length: 255
8612
8745
  }).notNull(),
8613
- createdById: (0, import_mysql_core3.varchar)("createdById", {
8746
+ createdById: (0, import_mysql_core5.varchar)("createdById", {
8614
8747
  length: 255
8615
8748
  }).notNull(),
8616
- fields: (0, import_mysql_core3.json)("fields").$type().default({}),
8617
- createdAt: (0, import_mysql_core3.timestamp)("createdAt", {
8749
+ fields: (0, import_mysql_core5.json)("fields").$type().default({}),
8750
+ createdAt: (0, import_mysql_core5.timestamp)("createdAt", {
8618
8751
  mode: "date",
8619
8752
  fsp: 3
8620
- }).default(import_drizzle_orm2.sql`CURRENT_TIMESTAMP(3)`),
8621
- updatedAt: (0, import_mysql_core3.timestamp)("updatedAt", {
8753
+ }).default(import_drizzle_orm4.sql`CURRENT_TIMESTAMP(3)`),
8754
+ updatedAt: (0, import_mysql_core5.timestamp)("updatedAt", {
8622
8755
  mode: "date",
8623
8756
  fsp: 3
8624
- }).default(import_drizzle_orm2.sql`CURRENT_TIMESTAMP(3)`),
8625
- deletedAt: (0, import_mysql_core3.timestamp)("deletedAt", {
8757
+ }).default(import_drizzle_orm4.sql`CURRENT_TIMESTAMP(3)`),
8758
+ deletedAt: (0, import_mysql_core5.timestamp)("deletedAt", {
8626
8759
  mode: "date",
8627
8760
  fsp: 3
8628
8761
  })
8629
8762
  }, (cm) => ({
8630
- typeIdx: (0, import_mysql_core3.index)("type_idx").on(cm.type),
8631
- createdByIdx: (0, import_mysql_core3.index)("createdById_idx").on(cm.createdById),
8632
- createdAtIdx: (0, import_mysql_core3.index)("createdAt_idx").on(cm.createdAt)
8763
+ typeIdx: (0, import_mysql_core5.index)("type_idx").on(cm.type),
8764
+ createdByIdx: (0, import_mysql_core5.index)("createdById_idx").on(cm.createdById),
8765
+ createdAtIdx: (0, import_mysql_core5.index)("createdAt_idx").on(cm.createdAt)
8633
8766
  }));
8634
8767
  }
8635
8768
  __name(getContentResourceSchema, "getContentResourceSchema");
@@ -8638,7 +8771,8 @@ function getContentResourceRelationsSchema(mysqlTable) {
8638
8771
  const users = getUsersSchema(mysqlTable);
8639
8772
  const contentResourceResource = getContentResourceResourceSchema(mysqlTable);
8640
8773
  const contentResourceProduct = getContentResourceProductSchema(mysqlTable);
8641
- return (0, import_drizzle_orm2.relations)(contentResource, ({ one, many }) => ({
8774
+ const contentContributions = getContentContributionsSchema(mysqlTable);
8775
+ return (0, import_drizzle_orm4.relations)(contentResource, ({ one, many }) => ({
8642
8776
  createdBy: one(users, {
8643
8777
  fields: [
8644
8778
  contentResource.createdById
@@ -8646,7 +8780,7 @@ function getContentResourceRelationsSchema(mysqlTable) {
8646
8780
  references: [
8647
8781
  users.id
8648
8782
  ],
8649
- relationName: "user"
8783
+ relationName: "creator"
8650
8784
  }),
8651
8785
  resources: many(contentResourceResource, {
8652
8786
  relationName: "resourceOf"
@@ -8656,6 +8790,9 @@ function getContentResourceRelationsSchema(mysqlTable) {
8656
8790
  }),
8657
8791
  resourceProducts: many(contentResourceProduct, {
8658
8792
  relationName: "resource"
8793
+ }),
8794
+ contributions: many(contentContributions, {
8795
+ relationName: "contributions"
8659
8796
  })
8660
8797
  }));
8661
8798
  }
@@ -8663,36 +8800,36 @@ __name(getContentResourceRelationsSchema, "getContentResourceRelationsSchema");
8663
8800
 
8664
8801
  // src/lib/mysql/schemas/content/content-resource-product.ts
8665
8802
  function getContentResourceProductSchema(mysqlTable) {
8666
- return mysqlTable("contentResourceProduct", {
8667
- productId: (0, import_mysql_core4.varchar)("productId", {
8803
+ return mysqlTable("ContentResourceProduct", {
8804
+ productId: (0, import_mysql_core6.varchar)("productId", {
8668
8805
  length: 255
8669
8806
  }).notNull(),
8670
- resourceId: (0, import_mysql_core4.varchar)("resourceId", {
8807
+ resourceId: (0, import_mysql_core6.varchar)("resourceId", {
8671
8808
  length: 255
8672
8809
  }).notNull(),
8673
- position: (0, import_mysql_core4.double)("position").notNull().default(0),
8674
- metadata: (0, import_mysql_core4.json)("metadata").$type().default({}),
8675
- createdAt: (0, import_mysql_core4.timestamp)("createdAt", {
8810
+ position: (0, import_mysql_core6.double)("position").notNull().default(0),
8811
+ metadata: (0, import_mysql_core6.json)("metadata").$type().default({}),
8812
+ createdAt: (0, import_mysql_core6.timestamp)("createdAt", {
8676
8813
  mode: "date",
8677
8814
  fsp: 3
8678
- }).default(import_drizzle_orm3.sql`CURRENT_TIMESTAMP(3)`),
8679
- updatedAt: (0, import_mysql_core4.timestamp)("updatedAt", {
8815
+ }).default(import_drizzle_orm5.sql`CURRENT_TIMESTAMP(3)`),
8816
+ updatedAt: (0, import_mysql_core6.timestamp)("updatedAt", {
8680
8817
  mode: "date",
8681
8818
  fsp: 3
8682
- }).default(import_drizzle_orm3.sql`CURRENT_TIMESTAMP(3)`),
8683
- deletedAt: (0, import_mysql_core4.timestamp)("deletedAt", {
8819
+ }).default(import_drizzle_orm5.sql`CURRENT_TIMESTAMP(3)`),
8820
+ deletedAt: (0, import_mysql_core6.timestamp)("deletedAt", {
8684
8821
  mode: "date",
8685
8822
  fsp: 3
8686
8823
  })
8687
8824
  }, (crr) => ({
8688
- pk: (0, import_mysql_core4.primaryKey)({
8825
+ pk: (0, import_mysql_core6.primaryKey)({
8689
8826
  columns: [
8690
8827
  crr.productId,
8691
8828
  crr.resourceId
8692
8829
  ]
8693
8830
  }),
8694
- contentResourceIdIdx: (0, import_mysql_core4.index)("contentResourceId_idx").on(crr.productId),
8695
- resourceIdIdx: (0, import_mysql_core4.index)("resourceId_idx").on(crr.resourceId)
8831
+ contentResourceIdIdx: (0, import_mysql_core6.index)("contentResourceId_idx").on(crr.productId),
8832
+ resourceIdIdx: (0, import_mysql_core6.index)("resourceId_idx").on(crr.resourceId)
8696
8833
  }));
8697
8834
  }
8698
8835
  __name(getContentResourceProductSchema, "getContentResourceProductSchema");
@@ -8700,7 +8837,7 @@ function getContentResourceProductRelationsSchema(mysqlTable) {
8700
8837
  const contentResource = getContentResourceSchema(mysqlTable);
8701
8838
  const contentResourceProduct = getContentResourceProductSchema(mysqlTable);
8702
8839
  const product = getProductSchema(mysqlTable);
8703
- return (0, import_drizzle_orm3.relations)(contentResourceProduct, ({ one }) => ({
8840
+ return (0, import_drizzle_orm5.relations)(contentResourceProduct, ({ one }) => ({
8704
8841
  product: one(product, {
8705
8842
  fields: [
8706
8843
  contentResourceProduct.productId
@@ -8724,79 +8861,79 @@ function getContentResourceProductRelationsSchema(mysqlTable) {
8724
8861
  __name(getContentResourceProductRelationsSchema, "getContentResourceProductRelationsSchema");
8725
8862
 
8726
8863
  // src/lib/mysql/schemas/commerce/merchant-product.ts
8727
- var import_drizzle_orm4 = require("drizzle-orm");
8728
- var import_mysql_core5 = require("drizzle-orm/mysql-core");
8864
+ var import_drizzle_orm6 = require("drizzle-orm");
8865
+ var import_mysql_core7 = require("drizzle-orm/mysql-core");
8729
8866
  function getMerchantProductSchema(mysqlTable) {
8730
- return mysqlTable("merchantProducts", {
8731
- id: (0, import_mysql_core5.varchar)("id", {
8867
+ return mysqlTable("MerchantProduct", {
8868
+ id: (0, import_mysql_core7.varchar)("id", {
8732
8869
  length: 191
8733
8870
  }).notNull(),
8734
- merchantAccountId: (0, import_mysql_core5.varchar)("merchantAccountId", {
8871
+ merchantAccountId: (0, import_mysql_core7.varchar)("merchantAccountId", {
8735
8872
  length: 191
8736
8873
  }).notNull(),
8737
- productId: (0, import_mysql_core5.varchar)("productId", {
8874
+ productId: (0, import_mysql_core7.varchar)("productId", {
8738
8875
  length: 191
8739
8876
  }).notNull(),
8740
- status: (0, import_mysql_core5.int)("status").default(0).notNull(),
8741
- identifier: (0, import_mysql_core5.varchar)("identifier", {
8877
+ status: (0, import_mysql_core7.int)("status").default(0).notNull(),
8878
+ identifier: (0, import_mysql_core7.varchar)("identifier", {
8742
8879
  length: 191
8743
8880
  }),
8744
- createdAt: (0, import_mysql_core5.timestamp)("createdAt", {
8881
+ createdAt: (0, import_mysql_core7.timestamp)("createdAt", {
8745
8882
  mode: "date",
8746
8883
  fsp: 3
8747
- }).default(import_drizzle_orm4.sql`CURRENT_TIMESTAMP(3)`).notNull()
8884
+ }).default(import_drizzle_orm6.sql`CURRENT_TIMESTAMP(3)`).notNull()
8748
8885
  }, (table) => {
8749
8886
  return {
8750
- merchantProductId: (0, import_mysql_core5.primaryKey)({
8887
+ merchantProductId: (0, import_mysql_core7.primaryKey)({
8751
8888
  columns: [
8752
8889
  table.id
8753
8890
  ],
8754
8891
  name: "MerchantProduct_id"
8755
8892
  }),
8756
- merchantProductIdentifierKey: (0, import_mysql_core5.unique)("MerchantProduct_identifier_key").on(table.identifier)
8893
+ merchantProductIdentifierKey: (0, import_mysql_core7.unique)("MerchantProduct_identifier_key").on(table.identifier)
8757
8894
  };
8758
8895
  });
8759
8896
  }
8760
8897
  __name(getMerchantProductSchema, "getMerchantProductSchema");
8761
8898
 
8762
8899
  // src/lib/mysql/schemas/commerce/price.ts
8763
- var import_drizzle_orm6 = require("drizzle-orm");
8764
- var import_mysql_core7 = require("drizzle-orm/mysql-core");
8900
+ var import_drizzle_orm8 = require("drizzle-orm");
8901
+ var import_mysql_core9 = require("drizzle-orm/mysql-core");
8765
8902
 
8766
8903
  // src/lib/mysql/schemas/commerce/merchant-price.ts
8767
- var import_drizzle_orm5 = require("drizzle-orm");
8768
- var import_mysql_core6 = require("drizzle-orm/mysql-core");
8904
+ var import_drizzle_orm7 = require("drizzle-orm");
8905
+ var import_mysql_core8 = require("drizzle-orm/mysql-core");
8769
8906
  function getMerchantPriceSchema(mysqlTable) {
8770
- return mysqlTable("merchantPrices", {
8771
- id: (0, import_mysql_core6.varchar)("id", {
8907
+ return mysqlTable("MerchantPrice", {
8908
+ id: (0, import_mysql_core8.varchar)("id", {
8772
8909
  length: 191
8773
8910
  }).notNull(),
8774
- merchantAccountId: (0, import_mysql_core6.varchar)("merchantAccountId", {
8911
+ merchantAccountId: (0, import_mysql_core8.varchar)("merchantAccountId", {
8775
8912
  length: 191
8776
8913
  }).notNull(),
8777
- merchantProductId: (0, import_mysql_core6.varchar)("merchantProductId", {
8914
+ merchantProductId: (0, import_mysql_core8.varchar)("merchantProductId", {
8778
8915
  length: 191
8779
8916
  }).notNull(),
8780
- status: (0, import_mysql_core6.int)("status").default(0),
8781
- identifier: (0, import_mysql_core6.varchar)("identifier", {
8917
+ status: (0, import_mysql_core8.int)("status").default(0),
8918
+ identifier: (0, import_mysql_core8.varchar)("identifier", {
8782
8919
  length: 191
8783
8920
  }),
8784
- createdAt: (0, import_mysql_core6.timestamp)("createdAt", {
8921
+ createdAt: (0, import_mysql_core8.timestamp)("createdAt", {
8785
8922
  mode: "date",
8786
8923
  fsp: 3
8787
- }).default(import_drizzle_orm5.sql`CURRENT_TIMESTAMP(3)`).notNull(),
8788
- priceId: (0, import_mysql_core6.varchar)("priceId", {
8924
+ }).default(import_drizzle_orm7.sql`CURRENT_TIMESTAMP(3)`).notNull(),
8925
+ priceId: (0, import_mysql_core8.varchar)("priceId", {
8789
8926
  length: 191
8790
8927
  })
8791
8928
  }, (table) => {
8792
8929
  return {
8793
- merchantPriceId: (0, import_mysql_core6.primaryKey)({
8930
+ merchantPriceId: (0, import_mysql_core8.primaryKey)({
8794
8931
  columns: [
8795
8932
  table.id
8796
8933
  ],
8797
8934
  name: "MerchantPrice_id"
8798
8935
  }),
8799
- merchantPriceIdentifierKey: (0, import_mysql_core6.unique)("MerchantPrice_identifier_key").on(table.identifier)
8936
+ merchantPriceIdentifierKey: (0, import_mysql_core8.unique)("MerchantPrice_identifier_key").on(table.identifier)
8800
8937
  };
8801
8938
  });
8802
8939
  }
@@ -8804,29 +8941,29 @@ __name(getMerchantPriceSchema, "getMerchantPriceSchema");
8804
8941
 
8805
8942
  // src/lib/mysql/schemas/commerce/price.ts
8806
8943
  function getPriceSchema(mysqlTable) {
8807
- return mysqlTable("prices", {
8808
- id: (0, import_mysql_core7.varchar)("id", {
8944
+ return mysqlTable("Price", {
8945
+ id: (0, import_mysql_core9.varchar)("id", {
8809
8946
  length: 191
8810
8947
  }).notNull(),
8811
- productId: (0, import_mysql_core7.varchar)("productId", {
8948
+ productId: (0, import_mysql_core9.varchar)("productId", {
8812
8949
  length: 191
8813
8950
  }),
8814
- nickname: (0, import_mysql_core7.varchar)("nickname", {
8951
+ nickname: (0, import_mysql_core9.varchar)("nickname", {
8815
8952
  length: 191
8816
8953
  }),
8817
- status: (0, import_mysql_core7.int)("status").default(0).notNull(),
8818
- unitAmount: (0, import_mysql_core7.decimal)("unitAmount", {
8954
+ status: (0, import_mysql_core9.int)("status").default(0).notNull(),
8955
+ unitAmount: (0, import_mysql_core9.decimal)("unitAmount", {
8819
8956
  precision: 10,
8820
8957
  scale: 2
8821
8958
  }).notNull(),
8822
- createdAt: (0, import_mysql_core7.timestamp)("createdAt", {
8959
+ createdAt: (0, import_mysql_core9.timestamp)("createdAt", {
8823
8960
  mode: "date",
8824
8961
  fsp: 3
8825
- }).default(import_drizzle_orm6.sql`CURRENT_TIMESTAMP(3)`).notNull(),
8826
- fields: (0, import_mysql_core7.json)("fields").$type().default({})
8962
+ }).default(import_drizzle_orm8.sql`CURRENT_TIMESTAMP(3)`).notNull(),
8963
+ fields: (0, import_mysql_core9.json)("fields").$type().default({})
8827
8964
  }, (table) => {
8828
8965
  return {
8829
- priceId: (0, import_mysql_core7.primaryKey)({
8966
+ priceId: (0, import_mysql_core9.primaryKey)({
8830
8967
  columns: [
8831
8968
  table.id
8832
8969
  ],
@@ -8839,29 +8976,29 @@ __name(getPriceSchema, "getPriceSchema");
8839
8976
 
8840
8977
  // src/lib/mysql/schemas/commerce/product.ts
8841
8978
  function getProductSchema(mysqlTable) {
8842
- return mysqlTable("products", {
8843
- id: (0, import_mysql_core8.varchar)("id", {
8979
+ return mysqlTable("Product", {
8980
+ id: (0, import_mysql_core10.varchar)("id", {
8844
8981
  length: 191
8845
8982
  }).notNull(),
8846
- name: (0, import_mysql_core8.varchar)("name", {
8983
+ name: (0, import_mysql_core10.varchar)("name", {
8847
8984
  length: 191
8848
8985
  }).notNull(),
8849
- key: (0, import_mysql_core8.varchar)("key", {
8986
+ key: (0, import_mysql_core10.varchar)("key", {
8850
8987
  length: 191
8851
8988
  }),
8852
- type: (0, import_mysql_core8.varchar)("type", {
8989
+ type: (0, import_mysql_core10.varchar)("type", {
8853
8990
  length: 191
8854
8991
  }),
8855
- fields: (0, import_mysql_core8.json)("fields").$type().default({}),
8856
- createdAt: (0, import_mysql_core8.timestamp)("createdAt", {
8992
+ fields: (0, import_mysql_core10.json)("fields").$type().default({}),
8993
+ createdAt: (0, import_mysql_core10.timestamp)("createdAt", {
8857
8994
  mode: "date",
8858
8995
  fsp: 3
8859
- }).default(import_drizzle_orm7.sql`CURRENT_TIMESTAMP(3)`).notNull(),
8860
- status: (0, import_mysql_core8.int)("status").default(0).notNull(),
8861
- quantityAvailable: (0, import_mysql_core8.int)("quantityAvailable").default(-1).notNull()
8996
+ }).default(import_drizzle_orm9.sql`CURRENT_TIMESTAMP(3)`).notNull(),
8997
+ status: (0, import_mysql_core10.int)("status").default(0).notNull(),
8998
+ quantityAvailable: (0, import_mysql_core10.int)("quantityAvailable").default(-1).notNull()
8862
8999
  }, (table) => {
8863
9000
  return {
8864
- productId: (0, import_mysql_core8.primaryKey)({
9001
+ productId: (0, import_mysql_core10.primaryKey)({
8865
9002
  columns: [
8866
9003
  table.id
8867
9004
  ],
@@ -8876,7 +9013,7 @@ function getProductRelationsSchema(mysqlTable) {
8876
9013
  const price = getPriceSchema(mysqlTable);
8877
9014
  const merchantProduct = getMerchantProductSchema(mysqlTable);
8878
9015
  const contentResourceProduct = getContentResourceProductSchema(mysqlTable);
8879
- return (0, import_drizzle_orm7.relations)(product, ({ one, many }) => ({
9016
+ return (0, import_drizzle_orm9.relations)(product, ({ one, many }) => ({
8880
9017
  price: one(price, {
8881
9018
  fields: [
8882
9019
  product.id
@@ -8904,50 +9041,46 @@ __name(getProductRelationsSchema, "getProductRelationsSchema");
8904
9041
 
8905
9042
  // src/lib/mysql/schemas/commerce/coupon.ts
8906
9043
  function getCouponSchema(mysqlTable) {
8907
- return mysqlTable("coupons", {
8908
- id: (0, import_mysql_core9.varchar)("id", {
9044
+ return mysqlTable("Coupon", {
9045
+ id: (0, import_mysql_core11.varchar)("id", {
8909
9046
  length: 191
8910
9047
  }).notNull(),
8911
- code: (0, import_mysql_core9.varchar)("code", {
9048
+ code: (0, import_mysql_core11.varchar)("code", {
8912
9049
  length: 191
8913
9050
  }),
8914
- createdAt: (0, import_mysql_core9.timestamp)("createdAt", {
9051
+ createdAt: (0, import_mysql_core11.timestamp)("createdAt", {
8915
9052
  mode: "date",
8916
9053
  fsp: 3
8917
- }).default(import_drizzle_orm8.sql`CURRENT_TIMESTAMP(3)`).notNull(),
8918
- expires: (0, import_mysql_core9.timestamp)("expires", {
9054
+ }).default(import_drizzle_orm10.sql`CURRENT_TIMESTAMP(3)`).notNull(),
9055
+ expires: (0, import_mysql_core11.timestamp)("expires", {
8919
9056
  mode: "date",
8920
9057
  fsp: 3
8921
9058
  }),
8922
- fields: (0, import_mysql_core9.json)("fields").$type().default({}),
8923
- maxUses: (0, import_mysql_core9.int)("maxUses").default(-1).notNull(),
8924
- default: (0, import_mysql_core9.boolean)("default").default(false).notNull(),
8925
- merchantCouponId: (0, import_mysql_core9.varchar)("merchantCouponId", {
9059
+ fields: (0, import_mysql_core11.json)("fields").$type().default({}),
9060
+ maxUses: (0, import_mysql_core11.int)("maxUses").default(-1).notNull(),
9061
+ default: (0, import_mysql_core11.boolean)("default").default(false).notNull(),
9062
+ merchantCouponId: (0, import_mysql_core11.varchar)("merchantCouponId", {
8926
9063
  length: 191
8927
9064
  }),
8928
- status: (0, import_mysql_core9.int)("status").default(0).notNull(),
8929
- usedCount: (0, import_mysql_core9.int)("usedCount").default(0).notNull(),
8930
- percentageDiscount: (0, import_mysql_core9.decimal)("percentageDiscount", {
9065
+ status: (0, import_mysql_core11.int)("status").default(0).notNull(),
9066
+ usedCount: (0, import_mysql_core11.int)("usedCount").default(0).notNull(),
9067
+ percentageDiscount: (0, import_mysql_core11.decimal)("percentageDiscount", {
8931
9068
  precision: 3,
8932
9069
  scale: 2
8933
9070
  }).notNull(),
8934
- restrictedToProductId: (0, import_mysql_core9.varchar)("restrictedToProductId", {
8935
- length: 191
8936
- }),
8937
- bulkPurchaseId: (0, import_mysql_core9.varchar)("bulkPurchaseId", {
9071
+ restrictedToProductId: (0, import_mysql_core11.varchar)("restrictedToProductId", {
8938
9072
  length: 191
8939
9073
  })
8940
9074
  }, (table) => {
8941
9075
  return {
8942
- couponIdCodeIndex: (0, import_mysql_core9.index)("Coupon_id_code_index").on(table.id, table.code),
8943
- couponId: (0, import_mysql_core9.primaryKey)({
9076
+ couponIdCodeIndex: (0, import_mysql_core11.index)("Coupon_id_code_index").on(table.id, table.code),
9077
+ couponId: (0, import_mysql_core11.primaryKey)({
8944
9078
  columns: [
8945
9079
  table.id
8946
9080
  ],
8947
9081
  name: "Coupon_id"
8948
9082
  }),
8949
- couponBulkPurchaseIdKey: (0, import_mysql_core9.unique)("Coupon_bulkPurchaseId_key").on(table.bulkPurchaseId),
8950
- couponCodeKey: (0, import_mysql_core9.unique)("Coupon_code_key").on(table.code)
9083
+ couponCodeKey: (0, import_mysql_core11.unique)("Coupon_code_key").on(table.code)
8951
9084
  };
8952
9085
  });
8953
9086
  }
@@ -8956,8 +9089,8 @@ function getCouponRelationsSchema(mysqlTable) {
8956
9089
  const purchase = getPurchaseSchema(mysqlTable);
8957
9090
  const coupon = getCouponSchema(mysqlTable);
8958
9091
  const merchantCoupon = getMerchantCouponSchema(mysqlTable);
8959
- return (0, import_drizzle_orm8.relations)(coupon, ({ many, one }) => ({
8960
- bulkCouponPurchases: many(purchase, {
9092
+ return (0, import_drizzle_orm10.relations)(coupon, ({ many, one }) => ({
9093
+ redeemedBulkCouponPurchases: many(purchase, {
8961
9094
  relationName: "redeemedBulkCoupon"
8962
9095
  }),
8963
9096
  merchantCoupon: one(merchantCoupon, {
@@ -8978,45 +9111,39 @@ function getCouponRelationsSchema(mysqlTable) {
8978
9111
  ],
8979
9112
  relationName: "product"
8980
9113
  }),
8981
- bulkPurchase: one(purchase, {
8982
- fields: [
8983
- coupon.bulkPurchaseId
8984
- ],
8985
- references: [
8986
- purchase.id
8987
- ],
8988
- relationName: "bulkPurchase"
9114
+ bulkPurchases: many(purchase, {
9115
+ relationName: "bulkCoupon"
8989
9116
  })
8990
9117
  }));
8991
9118
  }
8992
9119
  __name(getCouponRelationsSchema, "getCouponRelationsSchema");
8993
9120
 
8994
9121
  // src/lib/mysql/schemas/commerce/merchant-charge.ts
8995
- var import_drizzle_orm11 = require("drizzle-orm");
8996
- var import_mysql_core12 = require("drizzle-orm/mysql-core");
9122
+ var import_drizzle_orm13 = require("drizzle-orm");
9123
+ var import_mysql_core14 = require("drizzle-orm/mysql-core");
8997
9124
 
8998
9125
  // src/lib/mysql/schemas/commerce/merchant-account.ts
8999
- var import_drizzle_orm9 = require("drizzle-orm");
9000
- var import_mysql_core10 = require("drizzle-orm/mysql-core");
9126
+ var import_drizzle_orm11 = require("drizzle-orm");
9127
+ var import_mysql_core12 = require("drizzle-orm/mysql-core");
9001
9128
  function getMerchantAccountSchema(mysqlTable) {
9002
- return mysqlTable("merchantAccounts", {
9003
- id: (0, import_mysql_core10.varchar)("id", {
9129
+ return mysqlTable("MerchantAccount", {
9130
+ id: (0, import_mysql_core12.varchar)("id", {
9004
9131
  length: 191
9005
9132
  }).notNull(),
9006
- status: (0, import_mysql_core10.int)("status").default(0).notNull(),
9007
- createdAt: (0, import_mysql_core10.timestamp)("createdAt", {
9133
+ status: (0, import_mysql_core12.int)("status").default(0).notNull(),
9134
+ createdAt: (0, import_mysql_core12.timestamp)("createdAt", {
9008
9135
  mode: "date",
9009
9136
  fsp: 3
9010
- }).default(import_drizzle_orm9.sql`CURRENT_TIMESTAMP(3)`).notNull(),
9011
- label: (0, import_mysql_core10.varchar)("label", {
9137
+ }).default(import_drizzle_orm11.sql`CURRENT_TIMESTAMP(3)`).notNull(),
9138
+ label: (0, import_mysql_core12.varchar)("label", {
9012
9139
  length: 191
9013
9140
  }),
9014
- identifier: (0, import_mysql_core10.varchar)("identifier", {
9141
+ identifier: (0, import_mysql_core12.varchar)("identifier", {
9015
9142
  length: 191
9016
9143
  })
9017
9144
  }, (table) => {
9018
9145
  return {
9019
- merchantAccountId: (0, import_mysql_core10.primaryKey)({
9146
+ merchantAccountId: (0, import_mysql_core12.primaryKey)({
9020
9147
  columns: [
9021
9148
  table.id
9022
9149
  ],
@@ -9028,36 +9155,37 @@ function getMerchantAccountSchema(mysqlTable) {
9028
9155
  __name(getMerchantAccountSchema, "getMerchantAccountSchema");
9029
9156
 
9030
9157
  // src/lib/mysql/schemas/commerce/merchant-customer.ts
9031
- var import_drizzle_orm10 = require("drizzle-orm");
9032
- var import_mysql_core11 = require("drizzle-orm/mysql-core");
9158
+ var import_drizzle_orm12 = require("drizzle-orm");
9159
+ var import_mysql_core13 = require("drizzle-orm/mysql-core");
9033
9160
  function getMerchantCustomerSchema(mysqlTable) {
9034
- return mysqlTable("merchantCustomers", {
9035
- id: (0, import_mysql_core11.varchar)("id", {
9161
+ return mysqlTable("MerchantCustomer", {
9162
+ id: (0, import_mysql_core13.varchar)("id", {
9036
9163
  length: 191
9037
9164
  }).notNull(),
9038
- userId: (0, import_mysql_core11.varchar)("userId", {
9165
+ userId: (0, import_mysql_core13.varchar)("userId", {
9039
9166
  length: 191
9040
9167
  }).notNull(),
9041
- merchantAccountId: (0, import_mysql_core11.varchar)("merchantAccountId", {
9168
+ merchantAccountId: (0, import_mysql_core13.varchar)("merchantAccountId", {
9042
9169
  length: 191
9043
9170
  }).notNull(),
9044
- identifier: (0, import_mysql_core11.varchar)("identifier", {
9171
+ identifier: (0, import_mysql_core13.varchar)("identifier", {
9045
9172
  length: 191
9046
9173
  }).notNull(),
9047
- createdAt: (0, import_mysql_core11.timestamp)("createdAt", {
9174
+ createdAt: (0, import_mysql_core13.timestamp)("createdAt", {
9048
9175
  mode: "date",
9049
9176
  fsp: 3
9050
- }).default(import_drizzle_orm10.sql`CURRENT_TIMESTAMP(3)`).notNull(),
9051
- status: (0, import_mysql_core11.int)("status").default(0)
9177
+ }).default(import_drizzle_orm12.sql`CURRENT_TIMESTAMP(3)`).notNull(),
9178
+ status: (0, import_mysql_core13.int)("status").default(0)
9052
9179
  }, (table) => {
9053
9180
  return {
9054
- merchantCustomerId: (0, import_mysql_core11.primaryKey)({
9181
+ merchantCustomerId: (0, import_mysql_core13.primaryKey)({
9055
9182
  columns: [
9056
9183
  table.id
9057
9184
  ],
9058
9185
  name: "MerchantCustomer_id"
9059
9186
  }),
9060
- merchantCustomerIdentifierKey: (0, import_mysql_core11.unique)("MerchantCustomer_identifier_key").on(table.identifier)
9187
+ merchantCustomerIdentifierKey: (0, import_mysql_core13.unique)("MerchantCustomer_identifier_key").on(table.identifier),
9188
+ userIdIdx: (0, import_mysql_core13.index)("idx_MerchantCustomer_on_userId").on(table.userId)
9061
9189
  };
9062
9190
  });
9063
9191
  }
@@ -9065,39 +9193,39 @@ __name(getMerchantCustomerSchema, "getMerchantCustomerSchema");
9065
9193
 
9066
9194
  // src/lib/mysql/schemas/commerce/merchant-charge.ts
9067
9195
  function getMerchantChargeSchema(mysqlTable) {
9068
- return mysqlTable("merchantCharges", {
9069
- id: (0, import_mysql_core12.varchar)("id", {
9196
+ return mysqlTable("MerchantCharge", {
9197
+ id: (0, import_mysql_core14.varchar)("id", {
9070
9198
  length: 191
9071
9199
  }).notNull(),
9072
- status: (0, import_mysql_core12.int)("status").default(0).notNull(),
9073
- identifier: (0, import_mysql_core12.varchar)("identifier", {
9200
+ status: (0, import_mysql_core14.int)("status").default(0).notNull(),
9201
+ identifier: (0, import_mysql_core14.varchar)("identifier", {
9074
9202
  length: 191
9075
9203
  }).notNull(),
9076
- userId: (0, import_mysql_core12.varchar)("userId", {
9204
+ userId: (0, import_mysql_core14.varchar)("userId", {
9077
9205
  length: 191
9078
9206
  }).notNull(),
9079
- merchantAccountId: (0, import_mysql_core12.varchar)("merchantAccountId", {
9207
+ merchantAccountId: (0, import_mysql_core14.varchar)("merchantAccountId", {
9080
9208
  length: 191
9081
9209
  }).notNull(),
9082
- merchantProductId: (0, import_mysql_core12.varchar)("merchantProductId", {
9210
+ merchantProductId: (0, import_mysql_core14.varchar)("merchantProductId", {
9083
9211
  length: 191
9084
9212
  }).notNull(),
9085
- createdAt: (0, import_mysql_core12.timestamp)("createdAt", {
9213
+ createdAt: (0, import_mysql_core14.timestamp)("createdAt", {
9086
9214
  mode: "date",
9087
9215
  fsp: 3
9088
- }).default(import_drizzle_orm11.sql`CURRENT_TIMESTAMP(3)`).notNull(),
9089
- merchantCustomerId: (0, import_mysql_core12.varchar)("merchantCustomerId", {
9216
+ }).default(import_drizzle_orm13.sql`CURRENT_TIMESTAMP(3)`).notNull(),
9217
+ merchantCustomerId: (0, import_mysql_core14.varchar)("merchantCustomerId", {
9090
9218
  length: 191
9091
9219
  }).notNull()
9092
9220
  }, (table) => {
9093
9221
  return {
9094
- merchantChargeId: (0, import_mysql_core12.primaryKey)({
9222
+ merchantChargeId: (0, import_mysql_core14.primaryKey)({
9095
9223
  columns: [
9096
9224
  table.id
9097
9225
  ],
9098
9226
  name: "MerchantCharge_id"
9099
9227
  }),
9100
- merchantChargeIdentifierKey: (0, import_mysql_core12.unique)("MerchantCharge_identifier_key").on(table.identifier)
9228
+ merchantChargeIdentifierKey: (0, import_mysql_core14.unique)("MerchantCharge_identifier_key").on(table.identifier)
9101
9229
  };
9102
9230
  });
9103
9231
  }
@@ -9107,7 +9235,7 @@ function getMerchantChargeRelationsSchema(mysqlTable) {
9107
9235
  const merchantAccount = getMerchantAccountSchema(mysqlTable);
9108
9236
  const merchantProduct = getMerchantProductSchema(mysqlTable);
9109
9237
  const merchantCustomer = getMerchantCustomerSchema(mysqlTable);
9110
- return (0, import_drizzle_orm11.relations)(merchantCharge, ({ one }) => ({
9238
+ return (0, import_drizzle_orm13.relations)(merchantCharge, ({ one }) => ({
9111
9239
  merchantAccount: one(merchantAccount, {
9112
9240
  fields: [
9113
9241
  merchantCharge.merchantAccountId
@@ -9140,21 +9268,21 @@ function getMerchantChargeRelationsSchema(mysqlTable) {
9140
9268
  __name(getMerchantChargeRelationsSchema, "getMerchantChargeRelationsSchema");
9141
9269
 
9142
9270
  // src/lib/mysql/schemas/commerce/merchant-session.ts
9143
- var import_mysql_core13 = require("drizzle-orm/mysql-core");
9271
+ var import_mysql_core15 = require("drizzle-orm/mysql-core");
9144
9272
  function getMerchantSessionSchema(mysqlTable) {
9145
- return mysqlTable("merchantSessions", {
9146
- id: (0, import_mysql_core13.varchar)("id", {
9273
+ return mysqlTable("MerchantSession", {
9274
+ id: (0, import_mysql_core15.varchar)("id", {
9147
9275
  length: 191
9148
9276
  }).notNull(),
9149
- identifier: (0, import_mysql_core13.varchar)("identifier", {
9277
+ identifier: (0, import_mysql_core15.varchar)("identifier", {
9150
9278
  length: 191
9151
9279
  }).notNull(),
9152
- merchantAccountId: (0, import_mysql_core13.varchar)("merchantAccountId", {
9280
+ merchantAccountId: (0, import_mysql_core15.varchar)("merchantAccountId", {
9153
9281
  length: 191
9154
9282
  }).notNull()
9155
9283
  }, (table) => {
9156
9284
  return {
9157
- merchantSessionId: (0, import_mysql_core13.primaryKey)({
9285
+ merchantSessionId: (0, import_mysql_core15.primaryKey)({
9158
9286
  columns: [
9159
9287
  table.id
9160
9288
  ],
@@ -9167,67 +9295,68 @@ __name(getMerchantSessionSchema, "getMerchantSessionSchema");
9167
9295
 
9168
9296
  // src/lib/mysql/schemas/commerce/purchase.ts
9169
9297
  function getPurchaseSchema(mysqlTable) {
9170
- return mysqlTable("purchases", {
9171
- id: (0, import_mysql_core14.varchar)("id", {
9298
+ return mysqlTable("Purchase", {
9299
+ id: (0, import_mysql_core16.varchar)("id", {
9172
9300
  length: 191
9173
9301
  }).notNull(),
9174
- userId: (0, import_mysql_core14.varchar)("userId", {
9302
+ userId: (0, import_mysql_core16.varchar)("userId", {
9175
9303
  length: 191
9176
9304
  }),
9177
- createdAt: (0, import_mysql_core14.timestamp)("createdAt", {
9305
+ createdAt: (0, import_mysql_core16.timestamp)("createdAt", {
9178
9306
  mode: "date",
9179
9307
  fsp: 3
9180
- }).default(import_drizzle_orm12.sql`CURRENT_TIMESTAMP(3)`).notNull(),
9181
- totalAmount: (0, import_mysql_core14.decimal)("totalAmount", {
9308
+ }).default(import_drizzle_orm14.sql`CURRENT_TIMESTAMP(3)`).notNull(),
9309
+ totalAmount: (0, import_mysql_core16.decimal)("totalAmount", {
9182
9310
  precision: 65,
9183
9311
  scale: 30
9184
9312
  }).notNull(),
9185
- ipAddress: (0, import_mysql_core14.varchar)("ip_address", {
9313
+ ipAddress: (0, import_mysql_core16.varchar)("ip_address", {
9186
9314
  length: 191
9187
9315
  }),
9188
- city: (0, import_mysql_core14.varchar)("city", {
9316
+ city: (0, import_mysql_core16.varchar)("city", {
9189
9317
  length: 191
9190
9318
  }),
9191
- state: (0, import_mysql_core14.varchar)("state", {
9319
+ state: (0, import_mysql_core16.varchar)("state", {
9192
9320
  length: 191
9193
9321
  }),
9194
- country: (0, import_mysql_core14.varchar)("country", {
9322
+ country: (0, import_mysql_core16.varchar)("country", {
9195
9323
  length: 191
9196
9324
  }),
9197
- couponId: (0, import_mysql_core14.varchar)("couponId", {
9325
+ couponId: (0, import_mysql_core16.varchar)("couponId", {
9198
9326
  length: 191
9199
9327
  }),
9200
- productId: (0, import_mysql_core14.varchar)("productId", {
9328
+ productId: (0, import_mysql_core16.varchar)("productId", {
9201
9329
  length: 191
9202
9330
  }).notNull(),
9203
- merchantChargeId: (0, import_mysql_core14.varchar)("merchantChargeId", {
9331
+ merchantChargeId: (0, import_mysql_core16.varchar)("merchantChargeId", {
9204
9332
  length: 191
9205
9333
  }),
9206
- upgradedFromId: (0, import_mysql_core14.varchar)("upgradedFromId", {
9334
+ upgradedFromId: (0, import_mysql_core16.varchar)("upgradedFromId", {
9207
9335
  length: 191
9208
9336
  }),
9209
- status: (0, import_mysql_core14.varchar)("status", {
9337
+ status: (0, import_mysql_core16.varchar)("status", {
9210
9338
  length: 191
9211
9339
  }).default("Valid").notNull(),
9212
- bulkCouponId: (0, import_mysql_core14.varchar)("bulkCouponId", {
9340
+ bulkCouponId: (0, import_mysql_core16.varchar)("bulkCouponId", {
9213
9341
  length: 191
9214
9342
  }),
9215
- merchantSessionId: (0, import_mysql_core14.varchar)("merchantSessionId", {
9343
+ merchantSessionId: (0, import_mysql_core16.varchar)("merchantSessionId", {
9216
9344
  length: 191
9217
9345
  }),
9218
- redeemedBulkCouponId: (0, import_mysql_core14.varchar)("redeemedBulkCouponId", {
9346
+ redeemedBulkCouponId: (0, import_mysql_core16.varchar)("redeemedBulkCouponId", {
9219
9347
  length: 191
9220
9348
  }),
9221
- fields: (0, import_mysql_core14.json)("fields").$type().default({})
9349
+ fields: (0, import_mysql_core16.json)("fields").$type().default({})
9222
9350
  }, (table) => {
9223
9351
  return {
9224
- purchaseId: (0, import_mysql_core14.primaryKey)({
9352
+ purchaseId: (0, import_mysql_core16.primaryKey)({
9225
9353
  columns: [
9226
9354
  table.id
9227
9355
  ],
9228
9356
  name: "Purchase_id"
9229
9357
  }),
9230
- purchaseUpgradedFromIdKey: (0, import_mysql_core14.unique)("Purchase_upgradedFromId_key").on(table.upgradedFromId)
9358
+ merchantChargeIdIdx: (0, import_mysql_core16.index)("idx_Purchase_on_merchantChargeId").on(table.merchantChargeId),
9359
+ purchaseUpgradedFromIdKey: (0, import_mysql_core16.unique)("Purchase_upgradedFromId_key").on(table.upgradedFromId)
9231
9360
  };
9232
9361
  });
9233
9362
  }
@@ -9239,7 +9368,7 @@ function getPurchaseRelationsSchema(mysqlTable) {
9239
9368
  const merchantCharges = getMerchantChargeSchema(mysqlTable);
9240
9369
  const merchantSessions = getMerchantSessionSchema(mysqlTable);
9241
9370
  const coupons = getCouponSchema(mysqlTable);
9242
- return (0, import_drizzle_orm12.relations)(purchases, ({ many, one }) => ({
9371
+ return (0, import_drizzle_orm14.relations)(purchases, ({ many, one }) => ({
9243
9372
  redeemedBulkCoupon: one(coupons, {
9244
9373
  fields: [
9245
9374
  purchases.redeemedBulkCouponId
@@ -9298,61 +9427,113 @@ function getPurchaseRelationsSchema(mysqlTable) {
9298
9427
  }
9299
9428
  __name(getPurchaseRelationsSchema, "getPurchaseRelationsSchema");
9300
9429
 
9301
- // src/lib/mysql/schemas/communication/communication-preferences.ts
9302
- var import_drizzle_orm13 = require("drizzle-orm");
9430
+ // src/lib/mysql/schemas/communication/comment.ts
9431
+ var import_drizzle_orm15 = require("drizzle-orm");
9303
9432
  var import_mysql_core17 = require("drizzle-orm/mysql-core");
9433
+ function getCommentsSchema(mysqlTable) {
9434
+ return mysqlTable("Comment", {
9435
+ id: (0, import_mysql_core17.varchar)("id", {
9436
+ length: 191
9437
+ }).notNull(),
9438
+ userId: (0, import_mysql_core17.varchar)("userId", {
9439
+ length: 255
9440
+ }).notNull(),
9441
+ context: (0, import_mysql_core17.json)("context").$type().default({}),
9442
+ text: (0, import_mysql_core17.text)("text").notNull(),
9443
+ createdAt: (0, import_mysql_core17.timestamp)("createdAt", {
9444
+ mode: "date",
9445
+ fsp: 3
9446
+ }).default(import_drizzle_orm15.sql`CURRENT_TIMESTAMP(3)`),
9447
+ updatedAt: (0, import_mysql_core17.timestamp)("updatedAt", {
9448
+ mode: "date",
9449
+ fsp: 3
9450
+ }).default(import_drizzle_orm15.sql`CURRENT_TIMESTAMP(3)`),
9451
+ deletedAt: (0, import_mysql_core17.timestamp)("deletedAt", {
9452
+ mode: "date",
9453
+ fsp: 3
9454
+ })
9455
+ }, (crr) => ({
9456
+ pk: (0, import_mysql_core17.primaryKey)({
9457
+ columns: [
9458
+ crr.id
9459
+ ]
9460
+ }),
9461
+ crrUserIdIdKey: (0, import_mysql_core17.index)("crr_userIdId_idx").on(crr.userId)
9462
+ }));
9463
+ }
9464
+ __name(getCommentsSchema, "getCommentsSchema");
9465
+ function getCommentRelationsSchema(mysqlTable) {
9466
+ const comment = getCommentsSchema(mysqlTable);
9467
+ const user = getUsersSchema(mysqlTable);
9468
+ return (0, import_drizzle_orm15.relations)(comment, ({ one }) => ({
9469
+ user: one(user, {
9470
+ fields: [
9471
+ comment.userId
9472
+ ],
9473
+ references: [
9474
+ user.id
9475
+ ],
9476
+ relationName: "user"
9477
+ })
9478
+ }));
9479
+ }
9480
+ __name(getCommentRelationsSchema, "getCommentRelationsSchema");
9481
+
9482
+ // src/lib/mysql/schemas/communication/communication-preferences.ts
9483
+ var import_drizzle_orm16 = require("drizzle-orm");
9484
+ var import_mysql_core20 = require("drizzle-orm/mysql-core");
9304
9485
 
9305
9486
  // src/lib/mysql/schemas/communication/communication-channel.ts
9306
- var import_mysql_core15 = require("drizzle-orm/mysql-core");
9487
+ var import_mysql_core18 = require("drizzle-orm/mysql-core");
9307
9488
  function getCommunicationChannelSchema(mysqlTable) {
9308
- return mysqlTable("communicationChannel", {
9309
- id: (0, import_mysql_core15.varchar)("id", {
9489
+ return mysqlTable("CommunicationChannel", {
9490
+ id: (0, import_mysql_core18.varchar)("id", {
9310
9491
  length: 255
9311
9492
  }).notNull().primaryKey(),
9312
- name: (0, import_mysql_core15.varchar)("name", {
9493
+ name: (0, import_mysql_core18.varchar)("name", {
9313
9494
  length: 255
9314
9495
  }).notNull(),
9315
- description: (0, import_mysql_core15.text)("description"),
9316
- active: (0, import_mysql_core15.boolean)("active").notNull().default(true),
9317
- createdAt: (0, import_mysql_core15.timestamp)("createdAt", {
9496
+ description: (0, import_mysql_core18.text)("description"),
9497
+ active: (0, import_mysql_core18.boolean)("active").notNull().default(true),
9498
+ createdAt: (0, import_mysql_core18.timestamp)("createdAt", {
9318
9499
  mode: "date",
9319
9500
  fsp: 3
9320
9501
  }).defaultNow(),
9321
- updatedAt: (0, import_mysql_core15.timestamp)("updatedAt", {
9502
+ updatedAt: (0, import_mysql_core18.timestamp)("updatedAt", {
9322
9503
  mode: "date",
9323
9504
  fsp: 3
9324
9505
  }).defaultNow(),
9325
- deletedAt: (0, import_mysql_core15.timestamp)("deletedAt", {
9506
+ deletedAt: (0, import_mysql_core18.timestamp)("deletedAt", {
9326
9507
  mode: "date",
9327
9508
  fsp: 3
9328
9509
  })
9329
9510
  }, (cc) => ({
9330
- nameIdx: (0, import_mysql_core15.index)("name_idx").on(cc.name)
9511
+ nameIdx: (0, import_mysql_core18.index)("name_idx").on(cc.name)
9331
9512
  }));
9332
9513
  }
9333
9514
  __name(getCommunicationChannelSchema, "getCommunicationChannelSchema");
9334
9515
 
9335
9516
  // src/lib/mysql/schemas/communication/communication-preference-types.ts
9336
- var import_mysql_core16 = require("drizzle-orm/mysql-core");
9517
+ var import_mysql_core19 = require("drizzle-orm/mysql-core");
9337
9518
  function getCommunicationPreferenceTypesSchema(mysqlTable) {
9338
- return mysqlTable("communicationPreferenceType", {
9339
- id: (0, import_mysql_core16.varchar)("id", {
9519
+ return mysqlTable("CommunicationPreferenceType", {
9520
+ id: (0, import_mysql_core19.varchar)("id", {
9340
9521
  length: 255
9341
9522
  }).notNull().primaryKey(),
9342
- name: (0, import_mysql_core16.varchar)("name", {
9523
+ name: (0, import_mysql_core19.varchar)("name", {
9343
9524
  length: 255
9344
9525
  }).notNull(),
9345
- description: (0, import_mysql_core16.text)("description"),
9346
- active: (0, import_mysql_core16.boolean)("active").notNull().default(true),
9347
- createdAt: (0, import_mysql_core16.timestamp)("createdAt", {
9526
+ description: (0, import_mysql_core19.text)("description"),
9527
+ active: (0, import_mysql_core19.boolean)("active").notNull().default(true),
9528
+ createdAt: (0, import_mysql_core19.timestamp)("createdAt", {
9348
9529
  mode: "date",
9349
9530
  fsp: 3
9350
9531
  }).defaultNow(),
9351
- updatedAt: (0, import_mysql_core16.timestamp)("updatedAt", {
9532
+ updatedAt: (0, import_mysql_core19.timestamp)("updatedAt", {
9352
9533
  mode: "date",
9353
9534
  fsp: 3
9354
9535
  }),
9355
- deletedAt: (0, import_mysql_core16.timestamp)("deletedAt", {
9536
+ deletedAt: (0, import_mysql_core19.timestamp)("deletedAt", {
9356
9537
  mode: "date",
9357
9538
  fsp: 3
9358
9539
  })
@@ -9362,49 +9543,49 @@ __name(getCommunicationPreferenceTypesSchema, "getCommunicationPreferenceTypesSc
9362
9543
 
9363
9544
  // src/lib/mysql/schemas/communication/communication-preferences.ts
9364
9545
  function getCommunicationPreferencesSchema(mysqlTable) {
9365
- return mysqlTable("communicationPreference", {
9366
- id: (0, import_mysql_core17.varchar)("id", {
9546
+ return mysqlTable("CommunicationPreference", {
9547
+ id: (0, import_mysql_core20.varchar)("id", {
9367
9548
  length: 255
9368
9549
  }).notNull().primaryKey(),
9369
- userId: (0, import_mysql_core17.varchar)("userId", {
9550
+ userId: (0, import_mysql_core20.varchar)("userId", {
9370
9551
  length: 255
9371
9552
  }).notNull(),
9372
- channelId: (0, import_mysql_core17.varchar)("channelId", {
9553
+ channelId: (0, import_mysql_core20.varchar)("channelId", {
9373
9554
  length: 255
9374
9555
  }).notNull(),
9375
- preferenceLevel: (0, import_mysql_core17.mysqlEnum)("preferenceLevel", [
9556
+ preferenceLevel: (0, import_mysql_core20.mysqlEnum)("preferenceLevel", [
9376
9557
  "low",
9377
9558
  "medium",
9378
9559
  "high"
9379
9560
  ]).notNull().default("medium"),
9380
- preferenceTypeId: (0, import_mysql_core17.varchar)("preferenceTypeId", {
9561
+ preferenceTypeId: (0, import_mysql_core20.varchar)("preferenceTypeId", {
9381
9562
  length: 255
9382
9563
  }).notNull(),
9383
- active: (0, import_mysql_core17.boolean)("active").notNull().default(true),
9384
- createdAt: (0, import_mysql_core17.timestamp)("createdAt", {
9564
+ active: (0, import_mysql_core20.boolean)("active").notNull().default(true),
9565
+ createdAt: (0, import_mysql_core20.timestamp)("createdAt", {
9385
9566
  mode: "date",
9386
9567
  fsp: 3
9387
9568
  }).defaultNow(),
9388
- optInAt: (0, import_mysql_core17.timestamp)("optInAt", {
9569
+ optInAt: (0, import_mysql_core20.timestamp)("optInAt", {
9389
9570
  mode: "date",
9390
9571
  fsp: 3
9391
9572
  }),
9392
- optOutAt: (0, import_mysql_core17.timestamp)("optOutAt", {
9573
+ optOutAt: (0, import_mysql_core20.timestamp)("optOutAt", {
9393
9574
  mode: "date",
9394
9575
  fsp: 3
9395
9576
  }),
9396
- updatedAt: (0, import_mysql_core17.timestamp)("updatedAt", {
9577
+ updatedAt: (0, import_mysql_core20.timestamp)("updatedAt", {
9397
9578
  mode: "date",
9398
9579
  fsp: 3
9399
9580
  }).defaultNow(),
9400
- deletedAt: (0, import_mysql_core17.timestamp)("deletedAt", {
9581
+ deletedAt: (0, import_mysql_core20.timestamp)("deletedAt", {
9401
9582
  mode: "date",
9402
9583
  fsp: 3
9403
9584
  })
9404
9585
  }, (cp) => ({
9405
- userIdIdx: (0, import_mysql_core17.index)("userId_idx").on(cp.userId),
9406
- preferenceTypeIdx: (0, import_mysql_core17.index)("preferenceTypeId_idx").on(cp.preferenceTypeId),
9407
- channelIdIdx: (0, import_mysql_core17.index)("channelId_idx").on(cp.channelId)
9586
+ userIdIdx: (0, import_mysql_core20.index)("userId_idx").on(cp.userId),
9587
+ preferenceTypeIdx: (0, import_mysql_core20.index)("preferenceTypeId_idx").on(cp.preferenceTypeId),
9588
+ channelIdIdx: (0, import_mysql_core20.index)("channelId_idx").on(cp.channelId)
9408
9589
  }));
9409
9590
  }
9410
9591
  __name(getCommunicationPreferencesSchema, "getCommunicationPreferencesSchema");
@@ -9413,7 +9594,7 @@ function getCommunicationPreferencesRelationsSchema(mysqlTable) {
9413
9594
  const users = getUsersSchema(mysqlTable);
9414
9595
  const communicationChannel = getCommunicationChannelSchema(mysqlTable);
9415
9596
  const communicationPreferenceTypes = getCommunicationPreferenceTypesSchema(mysqlTable);
9416
- return (0, import_drizzle_orm13.relations)(communicationPreferences, ({ one }) => ({
9597
+ return (0, import_drizzle_orm16.relations)(communicationPreferences, ({ one }) => ({
9417
9598
  user: one(users, {
9418
9599
  fields: [
9419
9600
  communicationPreferences.userId
@@ -9445,192 +9626,76 @@ function getCommunicationPreferencesRelationsSchema(mysqlTable) {
9445
9626
  }
9446
9627
  __name(getCommunicationPreferencesRelationsSchema, "getCommunicationPreferencesRelationsSchema");
9447
9628
 
9448
- // src/lib/mysql/schemas/content/content-contributions.ts
9449
- var import_drizzle_orm15 = require("drizzle-orm");
9450
- var import_mysql_core19 = require("drizzle-orm/mysql-core");
9451
-
9452
- // src/lib/mysql/schemas/content/contribution-types.ts
9453
- var import_drizzle_orm14 = require("drizzle-orm");
9454
- var import_mysql_core18 = require("drizzle-orm/mysql-core");
9455
- function getContributionTypesSchema(mysqlTable) {
9456
- return mysqlTable("contributionType", {
9457
- id: (0, import_mysql_core18.varchar)("id", {
9458
- length: 255
9459
- }).notNull().primaryKey(),
9460
- slug: (0, import_mysql_core18.varchar)("slug", {
9461
- length: 255
9462
- }).notNull().unique(),
9463
- name: (0, import_mysql_core18.varchar)("name", {
9464
- length: 255
9465
- }).notNull(),
9466
- description: (0, import_mysql_core18.text)("description"),
9467
- active: (0, import_mysql_core18.boolean)("active").notNull().default(true),
9468
- createdAt: (0, import_mysql_core18.timestamp)("createdAt", {
9469
- mode: "date",
9470
- fsp: 3
9471
- }).defaultNow(),
9472
- updatedAt: (0, import_mysql_core18.timestamp)("updatedAt", {
9473
- mode: "date",
9474
- fsp: 3
9475
- }).defaultNow(),
9476
- deletedAt: (0, import_mysql_core18.timestamp)("deletedAt", {
9477
- mode: "date",
9478
- fsp: 3
9479
- })
9480
- }, (ct) => ({
9481
- nameIdx: (0, import_mysql_core18.index)("name_idx").on(ct.name),
9482
- slugIdx: (0, import_mysql_core18.index)("slug_idx").on(ct.slug)
9483
- }));
9484
- }
9485
- __name(getContributionTypesSchema, "getContributionTypesSchema");
9486
- function getContributionTypesRelationsSchema(mysqlTable) {
9487
- const contributionTypes = getContributionTypesSchema(mysqlTable);
9488
- return (0, import_drizzle_orm14.relations)(contributionTypes, ({ many }) => ({}));
9489
- }
9490
- __name(getContributionTypesRelationsSchema, "getContributionTypesRelationsSchema");
9491
-
9492
- // src/lib/mysql/schemas/content/content-contributions.ts
9493
- function getContentContributionsSchema(mysqlTable) {
9494
- return mysqlTable("contentContribution", {
9495
- id: (0, import_mysql_core19.varchar)("id", {
9496
- length: 255
9497
- }).notNull().primaryKey(),
9498
- userId: (0, import_mysql_core19.varchar)("userId", {
9499
- length: 255
9500
- }).notNull(),
9501
- contentId: (0, import_mysql_core19.varchar)("contentId", {
9502
- length: 255
9503
- }).notNull(),
9504
- contributionTypeId: (0, import_mysql_core19.varchar)("contributionTypeId", {
9505
- length: 255
9506
- }).notNull(),
9507
- active: (0, import_mysql_core19.boolean)("active").notNull().default(true),
9508
- createdAt: (0, import_mysql_core19.timestamp)("createdAt", {
9509
- mode: "date",
9510
- fsp: 3
9511
- }).defaultNow(),
9512
- updatedAt: (0, import_mysql_core19.timestamp)("updatedAt", {
9513
- mode: "date",
9514
- fsp: 3
9515
- }).defaultNow(),
9516
- deletedAt: (0, import_mysql_core19.timestamp)("deletedAt", {
9517
- mode: "date",
9518
- fsp: 3
9519
- })
9520
- }, (cc) => ({
9521
- userIdIdx: (0, import_mysql_core19.index)("userId_idx").on(cc.userId),
9522
- contentIdIdx: (0, import_mysql_core19.index)("contentId_idx").on(cc.contentId),
9523
- contributionTypeIdIdx: (0, import_mysql_core19.index)("contributionTypeId_idx").on(cc.contributionTypeId)
9524
- }));
9525
- }
9526
- __name(getContentContributionsSchema, "getContentContributionsSchema");
9527
- function getContentContributionRelationsSchema(mysqlTable) {
9528
- const contentContributions = getContentContributionsSchema(mysqlTable);
9529
- const users = getUsersSchema(mysqlTable);
9530
- const contentResource = getContentResourceSchema(mysqlTable);
9531
- const contributionTypes = getContributionTypesSchema(mysqlTable);
9532
- return (0, import_drizzle_orm15.relations)(contentContributions, ({ one }) => ({
9533
- user: one(users, {
9534
- fields: [
9535
- contentContributions.userId
9536
- ],
9537
- references: [
9538
- users.id
9539
- ],
9540
- relationName: "user"
9541
- }),
9542
- content: one(contentResource, {
9543
- fields: [
9544
- contentContributions.contentId
9545
- ],
9546
- references: [
9547
- contentResource.id
9548
- ],
9549
- relationName: "contributions"
9550
- }),
9551
- contributionType: one(contributionTypes, {
9552
- fields: [
9553
- contentContributions.contributionTypeId
9554
- ],
9555
- references: [
9556
- contributionTypes.id
9557
- ],
9558
- relationName: "contributionType"
9559
- })
9560
- }));
9561
- }
9562
- __name(getContentContributionRelationsSchema, "getContentContributionRelationsSchema");
9563
-
9564
9629
  // src/lib/mysql/schemas/auth/user-permissions.ts
9565
- var import_drizzle_orm17 = require("drizzle-orm");
9566
- var import_mysql_core21 = require("drizzle-orm/mysql-core");
9630
+ var import_drizzle_orm18 = require("drizzle-orm");
9631
+ var import_mysql_core22 = require("drizzle-orm/mysql-core");
9567
9632
 
9568
9633
  // src/lib/mysql/schemas/auth/permissions.ts
9569
- var import_drizzle_orm16 = require("drizzle-orm");
9570
- var import_mysql_core20 = require("drizzle-orm/mysql-core");
9634
+ var import_drizzle_orm17 = require("drizzle-orm");
9635
+ var import_mysql_core21 = require("drizzle-orm/mysql-core");
9571
9636
  function getPermissionsSchema(mysqlTable) {
9572
- return mysqlTable("permission", {
9573
- id: (0, import_mysql_core20.varchar)("id", {
9637
+ return mysqlTable("Permission", {
9638
+ id: (0, import_mysql_core21.varchar)("id", {
9574
9639
  length: 255
9575
9640
  }).notNull().primaryKey(),
9576
- name: (0, import_mysql_core20.varchar)("name", {
9641
+ name: (0, import_mysql_core21.varchar)("name", {
9577
9642
  length: 255
9578
9643
  }).notNull().unique(),
9579
- description: (0, import_mysql_core20.text)("description"),
9580
- active: (0, import_mysql_core20.boolean)("active").notNull().default(true),
9581
- createdAt: (0, import_mysql_core20.timestamp)("createdAt", {
9644
+ description: (0, import_mysql_core21.text)("description"),
9645
+ active: (0, import_mysql_core21.boolean)("active").notNull().default(true),
9646
+ createdAt: (0, import_mysql_core21.timestamp)("createdAt", {
9582
9647
  mode: "date",
9583
9648
  fsp: 3
9584
9649
  }).defaultNow(),
9585
- updatedAt: (0, import_mysql_core20.timestamp)("updatedAt", {
9650
+ updatedAt: (0, import_mysql_core21.timestamp)("updatedAt", {
9586
9651
  mode: "date",
9587
9652
  fsp: 3
9588
9653
  }).defaultNow(),
9589
- deletedAt: (0, import_mysql_core20.timestamp)("deletedAt", {
9654
+ deletedAt: (0, import_mysql_core21.timestamp)("deletedAt", {
9590
9655
  mode: "date",
9591
9656
  fsp: 3
9592
9657
  })
9593
9658
  }, (permission) => ({
9594
- nameIdx: (0, import_mysql_core20.index)("name_idx").on(permission.name)
9659
+ nameIdx: (0, import_mysql_core21.index)("name_idx").on(permission.name)
9595
9660
  }));
9596
9661
  }
9597
9662
  __name(getPermissionsSchema, "getPermissionsSchema");
9598
9663
  function getPermissionsRelationsSchema(mysqlTable) {
9599
- return (0, import_drizzle_orm16.relations)(getPermissionsSchema(mysqlTable), ({ many }) => ({}));
9664
+ return (0, import_drizzle_orm17.relations)(getPermissionsSchema(mysqlTable), ({ many }) => ({}));
9600
9665
  }
9601
9666
  __name(getPermissionsRelationsSchema, "getPermissionsRelationsSchema");
9602
9667
 
9603
9668
  // src/lib/mysql/schemas/auth/user-permissions.ts
9604
9669
  function getUserPermissionsSchema(mysqlTable) {
9605
- return mysqlTable("userPermission", {
9606
- userId: (0, import_mysql_core21.varchar)("userId", {
9670
+ return mysqlTable("UserPermission", {
9671
+ userId: (0, import_mysql_core22.varchar)("userId", {
9607
9672
  length: 255
9608
9673
  }).notNull(),
9609
- permissionId: (0, import_mysql_core21.varchar)("permissionId", {
9674
+ permissionId: (0, import_mysql_core22.varchar)("permissionId", {
9610
9675
  length: 255
9611
9676
  }).notNull(),
9612
- active: (0, import_mysql_core21.boolean)("active").notNull().default(true),
9613
- createdAt: (0, import_mysql_core21.timestamp)("createdAt", {
9677
+ active: (0, import_mysql_core22.boolean)("active").notNull().default(true),
9678
+ createdAt: (0, import_mysql_core22.timestamp)("createdAt", {
9614
9679
  mode: "date",
9615
9680
  fsp: 3
9616
9681
  }).defaultNow(),
9617
- updatedAt: (0, import_mysql_core21.timestamp)("updatedAt", {
9682
+ updatedAt: (0, import_mysql_core22.timestamp)("updatedAt", {
9618
9683
  mode: "date",
9619
9684
  fsp: 3
9620
9685
  }).defaultNow(),
9621
- deletedAt: (0, import_mysql_core21.timestamp)("deletedAt", {
9686
+ deletedAt: (0, import_mysql_core22.timestamp)("deletedAt", {
9622
9687
  mode: "date",
9623
9688
  fsp: 3
9624
9689
  })
9625
9690
  }, (up) => ({
9626
- pk: (0, import_mysql_core21.primaryKey)({
9691
+ pk: (0, import_mysql_core22.primaryKey)({
9627
9692
  columns: [
9628
9693
  up.userId,
9629
9694
  up.permissionId
9630
9695
  ]
9631
9696
  }),
9632
- userIdIdx: (0, import_mysql_core21.index)("userId_idx").on(up.userId),
9633
- permissionIdIdx: (0, import_mysql_core21.index)("permissionId_idx").on(up.permissionId)
9697
+ userIdIdx: (0, import_mysql_core22.index)("userId_idx").on(up.userId),
9698
+ permissionIdIdx: (0, import_mysql_core22.index)("permissionId_idx").on(up.permissionId)
9634
9699
  }));
9635
9700
  }
9636
9701
  __name(getUserPermissionsSchema, "getUserPermissionsSchema");
@@ -9638,7 +9703,7 @@ function getUserPermissionsRelationsSchema(mysqlTable) {
9638
9703
  const userPermissions = getUserPermissionsSchema(mysqlTable);
9639
9704
  const users = getUsersSchema(mysqlTable);
9640
9705
  const permissions = getPermissionsSchema(mysqlTable);
9641
- return (0, import_drizzle_orm17.relations)(userPermissions, ({ one }) => ({
9706
+ return (0, import_drizzle_orm18.relations)(userPermissions, ({ one }) => ({
9642
9707
  user: one(users, {
9643
9708
  fields: [
9644
9709
  userPermissions.userId
@@ -9661,44 +9726,98 @@ function getUserPermissionsRelationsSchema(mysqlTable) {
9661
9726
  }
9662
9727
  __name(getUserPermissionsRelationsSchema, "getUserPermissionsRelationsSchema");
9663
9728
 
9664
- // src/lib/mysql/schemas/auth/user-roles.ts
9729
+ // src/lib/mysql/schemas/auth/user-prefs.ts
9665
9730
  var import_drizzle_orm19 = require("drizzle-orm");
9666
9731
  var import_mysql_core23 = require("drizzle-orm/mysql-core");
9732
+ function getUserPrefsSchema(mysqlTable) {
9733
+ return mysqlTable("UserPrefs", {
9734
+ id: (0, import_mysql_core23.varchar)("id", {
9735
+ length: 191
9736
+ }).notNull(),
9737
+ type: (0, import_mysql_core23.varchar)("type", {
9738
+ length: 191
9739
+ }).default("Global").notNull(),
9740
+ userId: (0, import_mysql_core23.varchar)("userId", {
9741
+ length: 255
9742
+ }).notNull(),
9743
+ fields: (0, import_mysql_core23.json)("fields").$type().default({}),
9744
+ createdAt: (0, import_mysql_core23.timestamp)("createdAt", {
9745
+ mode: "date",
9746
+ fsp: 3
9747
+ }).default(import_drizzle_orm19.sql`CURRENT_TIMESTAMP(3)`),
9748
+ updatedAt: (0, import_mysql_core23.timestamp)("updatedAt", {
9749
+ mode: "date",
9750
+ fsp: 3
9751
+ }).default(import_drizzle_orm19.sql`CURRENT_TIMESTAMP(3)`),
9752
+ deletedAt: (0, import_mysql_core23.timestamp)("deletedAt", {
9753
+ mode: "date",
9754
+ fsp: 3
9755
+ })
9756
+ }, (crr) => ({
9757
+ pk: (0, import_mysql_core23.primaryKey)({
9758
+ columns: [
9759
+ crr.id
9760
+ ]
9761
+ }),
9762
+ crrUserIdIdKey: (0, import_mysql_core23.index)("crr_userIdId_idx").on(crr.userId)
9763
+ }));
9764
+ }
9765
+ __name(getUserPrefsSchema, "getUserPrefsSchema");
9766
+ function getUserPrefsRelationsSchema(mysqlTable) {
9767
+ const userPrefs = getUserPrefsSchema(mysqlTable);
9768
+ const user = getUsersSchema(mysqlTable);
9769
+ return (0, import_drizzle_orm19.relations)(userPrefs, ({ one }) => ({
9770
+ user: one(user, {
9771
+ fields: [
9772
+ userPrefs.userId
9773
+ ],
9774
+ references: [
9775
+ user.id
9776
+ ],
9777
+ relationName: "user"
9778
+ })
9779
+ }));
9780
+ }
9781
+ __name(getUserPrefsRelationsSchema, "getUserPrefsRelationsSchema");
9782
+
9783
+ // src/lib/mysql/schemas/auth/user-roles.ts
9784
+ var import_drizzle_orm21 = require("drizzle-orm");
9785
+ var import_mysql_core25 = require("drizzle-orm/mysql-core");
9667
9786
 
9668
9787
  // src/lib/mysql/schemas/auth/roles.ts
9669
- var import_drizzle_orm18 = require("drizzle-orm");
9670
- var import_mysql_core22 = require("drizzle-orm/mysql-core");
9788
+ var import_drizzle_orm20 = require("drizzle-orm");
9789
+ var import_mysql_core24 = require("drizzle-orm/mysql-core");
9671
9790
  function getRolesSchema(mysqlTable) {
9672
- return mysqlTable("role", {
9673
- id: (0, import_mysql_core22.varchar)("id", {
9791
+ return mysqlTable("Role", {
9792
+ id: (0, import_mysql_core24.varchar)("id", {
9674
9793
  length: 255
9675
9794
  }).notNull().primaryKey(),
9676
- name: (0, import_mysql_core22.varchar)("name", {
9795
+ name: (0, import_mysql_core24.varchar)("name", {
9677
9796
  length: 255
9678
9797
  }).notNull().unique(),
9679
- description: (0, import_mysql_core22.text)("description"),
9680
- active: (0, import_mysql_core22.boolean)("active").notNull().default(true),
9681
- createdAt: (0, import_mysql_core22.timestamp)("createdAt", {
9798
+ description: (0, import_mysql_core24.text)("description"),
9799
+ active: (0, import_mysql_core24.boolean)("active").notNull().default(true),
9800
+ createdAt: (0, import_mysql_core24.timestamp)("createdAt", {
9682
9801
  mode: "date",
9683
9802
  fsp: 3
9684
9803
  }).defaultNow(),
9685
- updatedAt: (0, import_mysql_core22.timestamp)("updatedAt", {
9804
+ updatedAt: (0, import_mysql_core24.timestamp)("updatedAt", {
9686
9805
  mode: "date",
9687
9806
  fsp: 3
9688
9807
  }).defaultNow(),
9689
- deletedAt: (0, import_mysql_core22.timestamp)("deletedAt", {
9808
+ deletedAt: (0, import_mysql_core24.timestamp)("deletedAt", {
9690
9809
  mode: "date",
9691
9810
  fsp: 3
9692
9811
  })
9693
9812
  }, (role) => ({
9694
- nameIdx: (0, import_mysql_core22.index)("name_idx").on(role.name)
9813
+ nameIdx: (0, import_mysql_core24.index)("name_idx").on(role.name)
9695
9814
  }));
9696
9815
  }
9697
9816
  __name(getRolesSchema, "getRolesSchema");
9698
9817
  function getRolesRelationsSchema(mysqlTable) {
9699
9818
  const roles = getRolesSchema(mysqlTable);
9700
9819
  const userRoles = getUserRolesSchema(mysqlTable);
9701
- return (0, import_drizzle_orm18.relations)(roles, ({ many }) => ({
9820
+ return (0, import_drizzle_orm20.relations)(roles, ({ many }) => ({
9702
9821
  userRoles: many(userRoles, {
9703
9822
  relationName: "role"
9704
9823
  })
@@ -9708,35 +9827,35 @@ __name(getRolesRelationsSchema, "getRolesRelationsSchema");
9708
9827
 
9709
9828
  // src/lib/mysql/schemas/auth/user-roles.ts
9710
9829
  function getUserRolesSchema(mysqlTable) {
9711
- return mysqlTable("userRole", {
9712
- userId: (0, import_mysql_core23.varchar)("userId", {
9830
+ return mysqlTable("UserRole", {
9831
+ userId: (0, import_mysql_core25.varchar)("userId", {
9713
9832
  length: 255
9714
9833
  }).notNull(),
9715
- roleId: (0, import_mysql_core23.varchar)("roleId", {
9834
+ roleId: (0, import_mysql_core25.varchar)("roleId", {
9716
9835
  length: 255
9717
9836
  }).notNull(),
9718
- active: (0, import_mysql_core23.boolean)("active").notNull().default(true),
9719
- createdAt: (0, import_mysql_core23.timestamp)("createdAt", {
9837
+ active: (0, import_mysql_core25.boolean)("active").notNull().default(true),
9838
+ createdAt: (0, import_mysql_core25.timestamp)("createdAt", {
9720
9839
  mode: "date",
9721
9840
  fsp: 3
9722
9841
  }).defaultNow(),
9723
- updatedAt: (0, import_mysql_core23.timestamp)("updatedAt", {
9842
+ updatedAt: (0, import_mysql_core25.timestamp)("updatedAt", {
9724
9843
  mode: "date",
9725
9844
  fsp: 3
9726
9845
  }).defaultNow(),
9727
- deletedAt: (0, import_mysql_core23.timestamp)("deletedAt", {
9846
+ deletedAt: (0, import_mysql_core25.timestamp)("deletedAt", {
9728
9847
  mode: "date",
9729
9848
  fsp: 3
9730
9849
  })
9731
9850
  }, (ur) => ({
9732
- pk: (0, import_mysql_core23.primaryKey)({
9851
+ pk: (0, import_mysql_core25.primaryKey)({
9733
9852
  columns: [
9734
9853
  ur.userId,
9735
9854
  ur.roleId
9736
9855
  ]
9737
9856
  }),
9738
- userIdIdx: (0, import_mysql_core23.index)("userId_idx").on(ur.userId),
9739
- roleIdIdx: (0, import_mysql_core23.index)("roleId_idx").on(ur.roleId)
9857
+ userIdIdx: (0, import_mysql_core25.index)("userId_idx").on(ur.userId),
9858
+ roleIdIdx: (0, import_mysql_core25.index)("roleId_idx").on(ur.roleId)
9740
9859
  }));
9741
9860
  }
9742
9861
  __name(getUserRolesSchema, "getUserRolesSchema");
@@ -9744,7 +9863,7 @@ function getUserRolesRelationsSchema(mysqlTable) {
9744
9863
  const userRoles = getUserRolesSchema(mysqlTable);
9745
9864
  const users = getUsersSchema(mysqlTable);
9746
9865
  const roles = getRolesSchema(mysqlTable);
9747
- return (0, import_drizzle_orm19.relations)(userRoles, ({ one }) => ({
9866
+ return (0, import_drizzle_orm21.relations)(userRoles, ({ one }) => ({
9748
9867
  user: one(users, {
9749
9868
  fields: [
9750
9869
  userRoles.userId
@@ -9769,35 +9888,35 @@ __name(getUserRolesRelationsSchema, "getUserRolesRelationsSchema");
9769
9888
 
9770
9889
  // src/lib/mysql/schemas/auth/users.ts
9771
9890
  function getUsersSchema(mysqlTable) {
9772
- return mysqlTable("user", {
9773
- id: (0, import_mysql_core24.varchar)("id", {
9891
+ return mysqlTable("User", {
9892
+ id: (0, import_mysql_core26.varchar)("id", {
9774
9893
  length: 255
9775
9894
  }).notNull().primaryKey(),
9776
- name: (0, import_mysql_core24.varchar)("name", {
9895
+ name: (0, import_mysql_core26.varchar)("name", {
9777
9896
  length: 255
9778
9897
  }),
9779
- role: (0, import_mysql_core24.mysqlEnum)("role", [
9780
- "user",
9781
- "admin"
9782
- ]).default("user"),
9783
- email: (0, import_mysql_core24.varchar)("email", {
9898
+ role: (0, import_mysql_core26.varchar)("role", {
9899
+ length: 191
9900
+ }).notNull().default("user"),
9901
+ email: (0, import_mysql_core26.varchar)("email", {
9784
9902
  length: 255
9785
9903
  }).notNull().unique(),
9786
- emailVerified: (0, import_mysql_core24.timestamp)("emailVerified", {
9904
+ fields: (0, import_mysql_core26.json)("fields").$type().default({}),
9905
+ emailVerified: (0, import_mysql_core26.timestamp)("emailVerified", {
9787
9906
  mode: "date",
9788
9907
  fsp: 3
9789
9908
  }),
9790
- image: (0, import_mysql_core24.varchar)("image", {
9909
+ image: (0, import_mysql_core26.varchar)("image", {
9791
9910
  length: 255
9792
9911
  }),
9793
- createdAt: (0, import_mysql_core24.timestamp)("createdAt", {
9912
+ createdAt: (0, import_mysql_core26.timestamp)("createdAt", {
9794
9913
  mode: "date",
9795
9914
  fsp: 3
9796
- }).default(import_drizzle_orm20.sql`CURRENT_TIMESTAMP(3)`)
9915
+ }).default(import_drizzle_orm22.sql`CURRENT_TIMESTAMP(3)`)
9797
9916
  }, (user) => ({
9798
- emailIdx: (0, import_mysql_core24.index)("email_idx").on(user.email),
9799
- roleIdx: (0, import_mysql_core24.index)("role_idx").on(user.role),
9800
- createdAtIdx: (0, import_mysql_core24.index)("created_at_idx").on(user.createdAt)
9917
+ emailIdx: (0, import_mysql_core26.index)("email_idx").on(user.email),
9918
+ roleIdx: (0, import_mysql_core26.index)("role_idx").on(user.role),
9919
+ createdAtIdx: (0, import_mysql_core26.index)("created_at_idx").on(user.createdAt)
9801
9920
  }));
9802
9921
  }
9803
9922
  __name(getUsersSchema, "getUsersSchema");
@@ -9810,7 +9929,9 @@ function getUsersRelationsSchema(mysqlTable) {
9810
9929
  const contentContributions = getContentContributionsSchema(mysqlTable);
9811
9930
  const contentResource = getContentResourceSchema(mysqlTable);
9812
9931
  const purchases = getPurchaseSchema(mysqlTable);
9813
- return (0, import_drizzle_orm20.relations)(users, ({ many }) => ({
9932
+ const comments = getCommentsSchema(mysqlTable);
9933
+ const userPrefs = getUserPrefsSchema(mysqlTable);
9934
+ return (0, import_drizzle_orm22.relations)(users, ({ many }) => ({
9814
9935
  accounts: many(accounts, {
9815
9936
  relationName: "user"
9816
9937
  }),
@@ -9831,6 +9952,12 @@ function getUsersRelationsSchema(mysqlTable) {
9831
9952
  }),
9832
9953
  createdContent: many(contentResource, {
9833
9954
  relationName: "user"
9955
+ }),
9956
+ comments: many(comments, {
9957
+ relationName: "user"
9958
+ }),
9959
+ prefs: many(userPrefs, {
9960
+ relationName: "user"
9834
9961
  })
9835
9962
  }));
9836
9963
  }
@@ -9838,96 +9965,188 @@ __name(getUsersRelationsSchema, "getUsersRelationsSchema");
9838
9965
 
9839
9966
  // src/lib/mysql/schemas/auth/accounts.ts
9840
9967
  function getAccountsSchema(mysqlTable) {
9841
- return mysqlTable("account", {
9842
- userId: (0, import_mysql_core25.varchar)("userId", {
9968
+ return mysqlTable("Account", {
9969
+ userId: (0, import_mysql_core27.varchar)("userId", {
9843
9970
  length: 255
9844
9971
  }).notNull(),
9845
- type: (0, import_mysql_core25.varchar)("type", {
9972
+ type: (0, import_mysql_core27.varchar)("type", {
9846
9973
  length: 255
9847
9974
  }).$type().notNull(),
9848
- provider: (0, import_mysql_core25.varchar)("provider", {
9975
+ provider: (0, import_mysql_core27.varchar)("provider", {
9849
9976
  length: 255
9850
9977
  }).notNull(),
9851
- providerAccountId: (0, import_mysql_core25.varchar)("providerAccountId", {
9978
+ providerAccountId: (0, import_mysql_core27.varchar)("providerAccountId", {
9852
9979
  length: 255
9853
9980
  }).notNull(),
9854
- refresh_token: (0, import_mysql_core25.text)("refresh_token"),
9855
- access_token: (0, import_mysql_core25.text)("access_token"),
9856
- oauth_token: (0, import_mysql_core25.text)("oauth_token"),
9857
- oauth_token_secret: (0, import_mysql_core25.text)("oauth_token_secret"),
9858
- expires_at: (0, import_mysql_core25.int)("expires_at"),
9859
- token_type: (0, import_mysql_core25.varchar)("token_type", {
9981
+ refresh_token: (0, import_mysql_core27.text)("refresh_token"),
9982
+ access_token: (0, import_mysql_core27.text)("access_token"),
9983
+ oauth_token: (0, import_mysql_core27.text)("oauth_token"),
9984
+ oauth_token_secret: (0, import_mysql_core27.text)("oauth_token_secret"),
9985
+ expires_at: (0, import_mysql_core27.int)("expires_at"),
9986
+ token_type: (0, import_mysql_core27.varchar)("token_type", {
9860
9987
  length: 255
9861
9988
  }),
9862
- scope: (0, import_mysql_core25.varchar)("scope", {
9989
+ scope: (0, import_mysql_core27.varchar)("scope", {
9863
9990
  length: 255
9864
9991
  }),
9865
- id_token: (0, import_mysql_core25.text)("id_token"),
9866
- session_state: (0, import_mysql_core25.varchar)("session_state", {
9992
+ id_token: (0, import_mysql_core27.text)("id_token"),
9993
+ session_state: (0, import_mysql_core27.varchar)("session_state", {
9994
+ length: 255
9995
+ }),
9996
+ refresh_token_expires_in: (0, import_mysql_core27.int)("refresh_token_expires_in")
9997
+ }, (account) => ({
9998
+ pk: (0, import_mysql_core27.primaryKey)({
9999
+ columns: [
10000
+ account.provider,
10001
+ account.providerAccountId
10002
+ ]
10003
+ }),
10004
+ userIdIdx: (0, import_mysql_core27.index)("userId_idx").on(account.userId)
10005
+ }));
10006
+ }
10007
+ __name(getAccountsSchema, "getAccountsSchema");
10008
+ function getAccountsRelationsSchema(mysqlTable) {
10009
+ const accounts = getAccountsSchema(mysqlTable);
10010
+ const users = getUsersSchema(mysqlTable);
10011
+ return (0, import_drizzle_orm23.relations)(accounts, ({ one }) => ({
10012
+ user: one(users, {
10013
+ fields: [
10014
+ accounts.userId
10015
+ ],
10016
+ references: [
10017
+ users.id
10018
+ ],
10019
+ relationName: "user"
10020
+ })
10021
+ }));
10022
+ }
10023
+ __name(getAccountsRelationsSchema, "getAccountsRelationsSchema");
10024
+
10025
+ // src/lib/mysql/schemas/auth/device-access-token.ts
10026
+ var import_drizzle_orm24 = require("drizzle-orm");
10027
+ var import_mysql_core28 = require("drizzle-orm/mysql-core");
10028
+ function getDeviceAccessTokenSchema(mysqlTable) {
10029
+ return mysqlTable("DeviceAccessToken", {
10030
+ token: (0, import_mysql_core28.varchar)("token", {
10031
+ length: 191
10032
+ }).notNull(),
10033
+ userId: (0, import_mysql_core28.varchar)("userId", {
10034
+ length: 191
10035
+ }).notNull(),
10036
+ createdAt: (0, import_mysql_core28.timestamp)("createdAt", {
10037
+ mode: "date",
10038
+ fsp: 3
10039
+ }).default(import_drizzle_orm24.sql`CURRENT_TIMESTAMP(3)`)
10040
+ }, (crr) => ({
10041
+ pk: (0, import_mysql_core28.primaryKey)({
10042
+ columns: [
10043
+ crr.token
10044
+ ]
10045
+ }),
10046
+ userIdIdx: (0, import_mysql_core28.index)("userId_idx").on(crr.userId)
10047
+ }));
10048
+ }
10049
+ __name(getDeviceAccessTokenSchema, "getDeviceAccessTokenSchema");
10050
+ function getDeviceAccessTokenRelationsSchema(mysqlTable) {
10051
+ const deviceAccessToken = getDeviceAccessTokenSchema(mysqlTable);
10052
+ const user = getUsersSchema(mysqlTable);
10053
+ return (0, import_drizzle_orm24.relations)(deviceAccessToken, ({ one }) => ({
10054
+ verifiedBy: one(user, {
10055
+ fields: [
10056
+ deviceAccessToken.userId
10057
+ ],
10058
+ references: [
10059
+ user.id
10060
+ ],
10061
+ relationName: "user"
10062
+ })
10063
+ }));
10064
+ }
10065
+ __name(getDeviceAccessTokenRelationsSchema, "getDeviceAccessTokenRelationsSchema");
10066
+
10067
+ // src/lib/mysql/schemas/auth/device-verification.ts
10068
+ var import_drizzle_orm25 = require("drizzle-orm");
10069
+ var import_mysql_core29 = require("drizzle-orm/mysql-core");
10070
+ function getDeviceVerificationSchema(mysqlTable) {
10071
+ return mysqlTable("DeviceVerification", {
10072
+ verifiedByUserId: (0, import_mysql_core29.varchar)("verifiedByUserId", {
9867
10073
  length: 255
9868
10074
  }),
9869
- refresh_token_expires_in: (0, import_mysql_core25.int)("refresh_token_expires_in")
9870
- }, (account) => ({
9871
- pk: (0, import_mysql_core25.primaryKey)({
10075
+ deviceCode: (0, import_mysql_core29.varchar)("deviceCode", {
10076
+ length: 191
10077
+ }).notNull(),
10078
+ userCode: (0, import_mysql_core29.text)("userCode").notNull(),
10079
+ expires: (0, import_mysql_core29.timestamp)("expires", {
10080
+ mode: "date",
10081
+ fsp: 3
10082
+ }).notNull(),
10083
+ createdAt: (0, import_mysql_core29.timestamp)("createdAt", {
10084
+ mode: "date",
10085
+ fsp: 3
10086
+ }).default(import_drizzle_orm25.sql`CURRENT_TIMESTAMP(3)`),
10087
+ verifiedAt: (0, import_mysql_core29.timestamp)("verifiedAt", {
10088
+ mode: "date",
10089
+ fsp: 3
10090
+ })
10091
+ }, (crr) => ({
10092
+ pk: (0, import_mysql_core29.primaryKey)({
9872
10093
  columns: [
9873
- account.provider,
9874
- account.providerAccountId
10094
+ crr.deviceCode
9875
10095
  ]
9876
- }),
9877
- userIdIdx: (0, import_mysql_core25.index)("userId_idx").on(account.userId)
10096
+ })
9878
10097
  }));
9879
10098
  }
9880
- __name(getAccountsSchema, "getAccountsSchema");
9881
- function getAccountsRelationsSchema(mysqlTable) {
9882
- const accounts = getAccountsSchema(mysqlTable);
9883
- const users = getUsersSchema(mysqlTable);
9884
- return (0, import_drizzle_orm21.relations)(accounts, ({ one }) => ({
9885
- user: one(users, {
10099
+ __name(getDeviceVerificationSchema, "getDeviceVerificationSchema");
10100
+ function getDeviceVerificationRelationsSchema(mysqlTable) {
10101
+ const deviceVerification = getDeviceVerificationSchema(mysqlTable);
10102
+ const user = getUsersSchema(mysqlTable);
10103
+ return (0, import_drizzle_orm25.relations)(deviceVerification, ({ one }) => ({
10104
+ verifiedBy: one(user, {
9886
10105
  fields: [
9887
- accounts.userId
10106
+ deviceVerification.verifiedByUserId
9888
10107
  ],
9889
10108
  references: [
9890
- users.id
10109
+ user.id
9891
10110
  ],
9892
10111
  relationName: "user"
9893
10112
  })
9894
10113
  }));
9895
10114
  }
9896
- __name(getAccountsRelationsSchema, "getAccountsRelationsSchema");
10115
+ __name(getDeviceVerificationRelationsSchema, "getDeviceVerificationRelationsSchema");
9897
10116
 
9898
10117
  // src/lib/mysql/schemas/auth/role-permissions.ts
9899
- var import_drizzle_orm22 = require("drizzle-orm");
9900
- var import_mysql_core26 = require("drizzle-orm/mysql-core");
10118
+ var import_drizzle_orm26 = require("drizzle-orm");
10119
+ var import_mysql_core30 = require("drizzle-orm/mysql-core");
9901
10120
  function getRolePermissionsSchema(mysqlTable) {
9902
- return mysqlTable("rolePermission", {
9903
- roleId: (0, import_mysql_core26.varchar)("roleId", {
10121
+ return mysqlTable("RolePermission", {
10122
+ roleId: (0, import_mysql_core30.varchar)("roleId", {
9904
10123
  length: 255
9905
10124
  }).notNull(),
9906
- permissionId: (0, import_mysql_core26.varchar)("permissionId", {
10125
+ permissionId: (0, import_mysql_core30.varchar)("permissionId", {
9907
10126
  length: 255
9908
10127
  }).notNull(),
9909
- active: (0, import_mysql_core26.boolean)("active").notNull().default(true),
9910
- createdAt: (0, import_mysql_core26.timestamp)("createdAt", {
10128
+ active: (0, import_mysql_core30.boolean)("active").notNull().default(true),
10129
+ createdAt: (0, import_mysql_core30.timestamp)("createdAt", {
9911
10130
  mode: "date",
9912
10131
  fsp: 3
9913
10132
  }).defaultNow(),
9914
- updatedAt: (0, import_mysql_core26.timestamp)("updatedAt", {
10133
+ updatedAt: (0, import_mysql_core30.timestamp)("updatedAt", {
9915
10134
  mode: "date",
9916
10135
  fsp: 3
9917
10136
  }).defaultNow(),
9918
- deletedAt: (0, import_mysql_core26.timestamp)("deletedAt", {
10137
+ deletedAt: (0, import_mysql_core30.timestamp)("deletedAt", {
9919
10138
  mode: "date",
9920
10139
  fsp: 3
9921
10140
  })
9922
10141
  }, (rp) => ({
9923
- pk: (0, import_mysql_core26.primaryKey)({
10142
+ pk: (0, import_mysql_core30.primaryKey)({
9924
10143
  columns: [
9925
10144
  rp.roleId,
9926
10145
  rp.permissionId
9927
10146
  ]
9928
10147
  }),
9929
- roleIdIdx: (0, import_mysql_core26.index)("roleId_idx").on(rp.roleId),
9930
- permissionIdIdx: (0, import_mysql_core26.index)("permissionId_idx").on(rp.permissionId)
10148
+ roleIdIdx: (0, import_mysql_core30.index)("roleId_idx").on(rp.roleId),
10149
+ permissionIdIdx: (0, import_mysql_core30.index)("permissionId_idx").on(rp.permissionId)
9931
10150
  }));
9932
10151
  }
9933
10152
  __name(getRolePermissionsSchema, "getRolePermissionsSchema");
@@ -9935,7 +10154,7 @@ function getRolePermissionsRelationsSchema(mysqlTable) {
9935
10154
  const permissions = getPermissionsSchema(mysqlTable);
9936
10155
  const roles = getRolesSchema(mysqlTable);
9937
10156
  const rolePermissions = getRolePermissionsSchema(mysqlTable);
9938
- return (0, import_drizzle_orm22.relations)(rolePermissions, ({ one }) => ({
10157
+ return (0, import_drizzle_orm26.relations)(rolePermissions, ({ one }) => ({
9939
10158
  role: one(roles, {
9940
10159
  fields: [
9941
10160
  rolePermissions.roleId
@@ -9959,28 +10178,28 @@ function getRolePermissionsRelationsSchema(mysqlTable) {
9959
10178
  __name(getRolePermissionsRelationsSchema, "getRolePermissionsRelationsSchema");
9960
10179
 
9961
10180
  // src/lib/mysql/schemas/auth/sessions.ts
9962
- var import_drizzle_orm23 = require("drizzle-orm");
9963
- var import_mysql_core27 = require("drizzle-orm/mysql-core");
10181
+ var import_drizzle_orm27 = require("drizzle-orm");
10182
+ var import_mysql_core31 = require("drizzle-orm/mysql-core");
9964
10183
  function getSessionsSchema(mysqlTable) {
9965
- return mysqlTable("session", {
9966
- sessionToken: (0, import_mysql_core27.varchar)("sessionToken", {
10184
+ return mysqlTable("Session", {
10185
+ sessionToken: (0, import_mysql_core31.varchar)("sessionToken", {
9967
10186
  length: 255
9968
10187
  }).notNull().primaryKey(),
9969
- userId: (0, import_mysql_core27.varchar)("userId", {
10188
+ userId: (0, import_mysql_core31.varchar)("userId", {
9970
10189
  length: 255
9971
10190
  }).notNull(),
9972
- expires: (0, import_mysql_core27.timestamp)("expires", {
10191
+ expires: (0, import_mysql_core31.timestamp)("expires", {
9973
10192
  mode: "date"
9974
10193
  }).notNull()
9975
10194
  }, (session) => ({
9976
- userIdIdx: (0, import_mysql_core27.index)("userId_idx").on(session.userId)
10195
+ userIdIdx: (0, import_mysql_core31.index)("userId_idx").on(session.userId)
9977
10196
  }));
9978
10197
  }
9979
10198
  __name(getSessionsSchema, "getSessionsSchema");
9980
10199
  function getSessionRelationsSchema(mysqlTable) {
9981
10200
  const sessions = getSessionsSchema(mysqlTable);
9982
10201
  const users = getUsersSchema(mysqlTable);
9983
- return (0, import_drizzle_orm23.relations)(sessions, ({ one }) => ({
10202
+ return (0, import_drizzle_orm27.relations)(sessions, ({ one }) => ({
9984
10203
  user: one(users, {
9985
10204
  fields: [
9986
10205
  sessions.userId
@@ -9995,24 +10214,24 @@ function getSessionRelationsSchema(mysqlTable) {
9995
10214
  __name(getSessionRelationsSchema, "getSessionRelationsSchema");
9996
10215
 
9997
10216
  // src/lib/mysql/schemas/auth/verification-tokens.ts
9998
- var import_mysql_core28 = require("drizzle-orm/mysql-core");
10217
+ var import_mysql_core32 = require("drizzle-orm/mysql-core");
9999
10218
  function getVerificationTokensSchema(mysqlTable) {
10000
- return mysqlTable("verificationToken", {
10001
- identifier: (0, import_mysql_core28.varchar)("identifier", {
10219
+ return mysqlTable("VerificationToken", {
10220
+ identifier: (0, import_mysql_core32.varchar)("identifier", {
10002
10221
  length: 255
10003
10222
  }).notNull(),
10004
- token: (0, import_mysql_core28.varchar)("token", {
10223
+ token: (0, import_mysql_core32.varchar)("token", {
10005
10224
  length: 255
10006
10225
  }).notNull(),
10007
- expires: (0, import_mysql_core28.timestamp)("expires", {
10226
+ expires: (0, import_mysql_core32.timestamp)("expires", {
10008
10227
  mode: "date"
10009
10228
  }).notNull(),
10010
- createdAt: (0, import_mysql_core28.timestamp)("createdAt", {
10229
+ createdAt: (0, import_mysql_core32.timestamp)("createdAt", {
10011
10230
  mode: "date",
10012
10231
  fsp: 3
10013
10232
  }).defaultNow()
10014
10233
  }, (vt) => ({
10015
- pk: (0, import_mysql_core28.primaryKey)({
10234
+ pk: (0, import_mysql_core32.primaryKey)({
10016
10235
  columns: [
10017
10236
  vt.identifier,
10018
10237
  vt.token
@@ -10023,14 +10242,14 @@ function getVerificationTokensSchema(mysqlTable) {
10023
10242
  __name(getVerificationTokensSchema, "getVerificationTokensSchema");
10024
10243
 
10025
10244
  // src/lib/mysql/schemas/commerce/purchase-user-transfer.ts
10026
- var import_drizzle_orm24 = require("drizzle-orm");
10027
- var import_mysql_core29 = require("drizzle-orm/mysql-core");
10245
+ var import_drizzle_orm28 = require("drizzle-orm");
10246
+ var import_mysql_core33 = require("drizzle-orm/mysql-core");
10028
10247
  function getPurchaseUserTransferSchema(mysqlTable) {
10029
- return mysqlTable("purchaseUserTransfers", {
10030
- id: (0, import_mysql_core29.varchar)("id", {
10248
+ return mysqlTable("PurchaseUserTransfer", {
10249
+ id: (0, import_mysql_core33.varchar)("id", {
10031
10250
  length: 191
10032
10251
  }).notNull(),
10033
- transferState: (0, import_mysql_core29.mysqlEnum)("transferState", [
10252
+ transferState: (0, import_mysql_core33.mysqlEnum)("transferState", [
10034
10253
  "AVAILABLE",
10035
10254
  "INITIATED",
10036
10255
  "VERIFIED",
@@ -10039,38 +10258,38 @@ function getPurchaseUserTransferSchema(mysqlTable) {
10039
10258
  "CONFIRMED",
10040
10259
  "COMPLETED"
10041
10260
  ]).default("AVAILABLE").notNull(),
10042
- purchaseId: (0, import_mysql_core29.varchar)("purchaseId", {
10261
+ purchaseId: (0, import_mysql_core33.varchar)("purchaseId", {
10043
10262
  length: 191
10044
10263
  }).notNull(),
10045
- sourceUserId: (0, import_mysql_core29.varchar)("sourceUserId", {
10264
+ sourceUserId: (0, import_mysql_core33.varchar)("sourceUserId", {
10046
10265
  length: 191
10047
10266
  }).notNull(),
10048
- targetUserId: (0, import_mysql_core29.varchar)("targetUserId", {
10267
+ targetUserId: (0, import_mysql_core33.varchar)("targetUserId", {
10049
10268
  length: 191
10050
10269
  }),
10051
- createdAt: (0, import_mysql_core29.timestamp)("createdAt", {
10270
+ createdAt: (0, import_mysql_core33.timestamp)("createdAt", {
10052
10271
  mode: "date",
10053
10272
  fsp: 3
10054
- }).default(import_drizzle_orm24.sql`CURRENT_TIMESTAMP(3)`).notNull(),
10055
- expiresAt: (0, import_mysql_core29.timestamp)("expiresAt", {
10273
+ }).default(import_drizzle_orm28.sql`CURRENT_TIMESTAMP(3)`).notNull(),
10274
+ expiresAt: (0, import_mysql_core33.timestamp)("expiresAt", {
10056
10275
  mode: "date",
10057
10276
  fsp: 3
10058
10277
  }),
10059
- canceledAt: (0, import_mysql_core29.timestamp)("canceledAt", {
10278
+ canceledAt: (0, import_mysql_core33.timestamp)("canceledAt", {
10060
10279
  mode: "date",
10061
10280
  fsp: 3
10062
10281
  }),
10063
- confirmedAt: (0, import_mysql_core29.timestamp)("confirmedAt", {
10282
+ confirmedAt: (0, import_mysql_core33.timestamp)("confirmedAt", {
10064
10283
  mode: "date",
10065
10284
  fsp: 3
10066
10285
  }),
10067
- completedAt: (0, import_mysql_core29.timestamp)("completedAt", {
10286
+ completedAt: (0, import_mysql_core33.timestamp)("completedAt", {
10068
10287
  mode: "date",
10069
10288
  fsp: 3
10070
10289
  })
10071
10290
  }, (table) => {
10072
10291
  return {
10073
- purchaseUserTransferId: (0, import_mysql_core29.primaryKey)({
10292
+ purchaseUserTransferId: (0, import_mysql_core33.primaryKey)({
10074
10293
  columns: [
10075
10294
  table.id
10076
10295
  ],
@@ -10084,7 +10303,7 @@ function getPurchaseUserTransferRelationsSchema(mysqlTable) {
10084
10303
  const purchaseUserTransfer = getPurchaseUserTransferSchema(mysqlTable);
10085
10304
  const user = getUsersSchema(mysqlTable);
10086
10305
  const purchase = getPurchaseSchema(mysqlTable);
10087
- return (0, import_drizzle_orm24.relations)(purchaseUserTransfer, ({ one }) => ({
10306
+ return (0, import_drizzle_orm28.relations)(purchaseUserTransfer, ({ one }) => ({
10088
10307
  sourceUser: one(user, {
10089
10308
  fields: [
10090
10309
  purchaseUserTransfer.sourceUserId
@@ -10117,46 +10336,46 @@ function getPurchaseUserTransferRelationsSchema(mysqlTable) {
10117
10336
  __name(getPurchaseUserTransferRelationsSchema, "getPurchaseUserTransferRelationsSchema");
10118
10337
 
10119
10338
  // src/lib/mysql/schemas/commerce/upgradable-products.ts
10120
- var import_drizzle_orm25 = require("drizzle-orm");
10121
- var import_mysql_core30 = require("drizzle-orm/mysql-core");
10339
+ var import_drizzle_orm29 = require("drizzle-orm");
10340
+ var import_mysql_core34 = require("drizzle-orm/mysql-core");
10122
10341
  function getUpgradableProductsSchema(mysqlTable) {
10123
- return mysqlTable("upgradableProducts", {
10124
- upgradableToId: (0, import_mysql_core30.varchar)("upgradableToId", {
10342
+ return mysqlTable("UpgradableProducts", {
10343
+ upgradableToId: (0, import_mysql_core34.varchar)("upgradableToId", {
10125
10344
  length: 255
10126
10345
  }).notNull(),
10127
- upgradableFromId: (0, import_mysql_core30.varchar)("upgradableFrom", {
10346
+ upgradableFromId: (0, import_mysql_core34.varchar)("upgradableFrom", {
10128
10347
  length: 255
10129
10348
  }).notNull(),
10130
- position: (0, import_mysql_core30.double)("position").notNull().default(0),
10131
- metadata: (0, import_mysql_core30.json)("metadata").$type().default({}),
10132
- createdAt: (0, import_mysql_core30.timestamp)("createdAt", {
10349
+ position: (0, import_mysql_core34.double)("position").notNull().default(0),
10350
+ metadata: (0, import_mysql_core34.json)("metadata").$type().default({}),
10351
+ createdAt: (0, import_mysql_core34.timestamp)("createdAt", {
10133
10352
  mode: "date",
10134
10353
  fsp: 3
10135
- }).default(import_drizzle_orm25.sql`CURRENT_TIMESTAMP(3)`),
10136
- updatedAt: (0, import_mysql_core30.timestamp)("updatedAt", {
10354
+ }).default(import_drizzle_orm29.sql`CURRENT_TIMESTAMP(3)`),
10355
+ updatedAt: (0, import_mysql_core34.timestamp)("updatedAt", {
10137
10356
  mode: "date",
10138
10357
  fsp: 3
10139
- }).default(import_drizzle_orm25.sql`CURRENT_TIMESTAMP(3)`),
10140
- deletedAt: (0, import_mysql_core30.timestamp)("deletedAt", {
10358
+ }).default(import_drizzle_orm29.sql`CURRENT_TIMESTAMP(3)`),
10359
+ deletedAt: (0, import_mysql_core34.timestamp)("deletedAt", {
10141
10360
  mode: "date",
10142
10361
  fsp: 3
10143
10362
  })
10144
10363
  }, (crr) => ({
10145
- pk: (0, import_mysql_core30.primaryKey)({
10364
+ pk: (0, import_mysql_core34.primaryKey)({
10146
10365
  columns: [
10147
10366
  crr.upgradableToId,
10148
10367
  crr.upgradableFromId
10149
10368
  ]
10150
10369
  }),
10151
- upgradableToIdIdx: (0, import_mysql_core30.index)("upgradableFromId_idx").on(crr.upgradableToId),
10152
- upgradableFromIdIdx: (0, import_mysql_core30.index)("upgradableToId_idx").on(crr.upgradableFromId)
10370
+ upgradableToIdIdx: (0, import_mysql_core34.index)("upgradableFromId_idx").on(crr.upgradableToId),
10371
+ upgradableFromIdIdx: (0, import_mysql_core34.index)("upgradableToId_idx").on(crr.upgradableFromId)
10153
10372
  }));
10154
10373
  }
10155
10374
  __name(getUpgradableProductsSchema, "getUpgradableProductsSchema");
10156
10375
  function getUpgradableProductsRelationsSchema(mysqlTable) {
10157
10376
  const product = getProductSchema(mysqlTable);
10158
10377
  const upgradableProduct = getUpgradableProductsSchema(mysqlTable);
10159
- return (0, import_drizzle_orm25.relations)(upgradableProduct, ({ one }) => ({
10378
+ return (0, import_drizzle_orm29.relations)(upgradableProduct, ({ one }) => ({
10160
10379
  upgradableTo: one(product, {
10161
10380
  fields: [
10162
10381
  upgradableProduct.upgradableToId
@@ -10179,47 +10398,96 @@ function getUpgradableProductsRelationsSchema(mysqlTable) {
10179
10398
  }
10180
10399
  __name(getUpgradableProductsRelationsSchema, "getUpgradableProductsRelationsSchema");
10181
10400
 
10182
- // src/lib/mysql/schemas/content/resource-progress.ts
10183
- var import_drizzle_orm26 = require("drizzle-orm");
10184
- var import_mysql_core31 = require("drizzle-orm/mysql-core");
10185
- function getResourceProgressSchema(mysqlTable) {
10186
- return mysqlTable("resourceProgresses", {
10187
- userId: (0, import_mysql_core31.varchar)("userId", {
10401
+ // src/lib/mysql/schemas/content/lesson-progress.ts
10402
+ var import_drizzle_orm30 = require("drizzle-orm");
10403
+ var import_mysql_core35 = require("drizzle-orm/mysql-core");
10404
+ function getLessonProgressSchema(mysqlTable) {
10405
+ return mysqlTable("LessonProgress", {
10406
+ id: (0, import_mysql_core35.varchar)("id", {
10407
+ length: 191
10408
+ }).notNull().primaryKey(),
10409
+ userId: (0, import_mysql_core35.varchar)("userId", {
10188
10410
  length: 191
10189
10411
  }).notNull(),
10190
- contentResourceId: (0, import_mysql_core31.varchar)("contentResourceId", {
10412
+ lessonId: (0, import_mysql_core35.varchar)("lessonId", {
10413
+ length: 191
10414
+ }),
10415
+ lessonSlug: (0, import_mysql_core35.varchar)("lessonSlug", {
10191
10416
  length: 191
10192
10417
  }),
10193
- fields: (0, import_mysql_core31.json)("fields").$type().default({}),
10194
- completedAt: (0, import_mysql_core31.datetime)("completedAt", {
10418
+ lessonVersion: (0, import_mysql_core35.varchar)("lessonVersion", {
10419
+ length: 191
10420
+ }),
10421
+ sectionId: (0, import_mysql_core35.varchar)("sectionId", {
10422
+ length: 191
10423
+ }),
10424
+ moduleId: (0, import_mysql_core35.varchar)("moduleId", {
10425
+ length: 191
10426
+ }),
10427
+ completedAt: (0, import_mysql_core35.datetime)("completedAt", {
10428
+ mode: "date",
10429
+ fsp: 3
10430
+ }),
10431
+ updatedAt: (0, import_mysql_core35.datetime)("updatedAt", {
10432
+ mode: "date",
10433
+ fsp: 3
10434
+ }),
10435
+ createdAt: (0, import_mysql_core35.datetime)("createdAt", {
10436
+ mode: "date",
10437
+ fsp: 3
10438
+ }).default(import_drizzle_orm30.sql`CURRENT_TIMESTAMP(3)`).notNull()
10439
+ }, (crp) => {
10440
+ return {
10441
+ userIdLessonIdIdx: (0, import_mysql_core35.index)("crp_userId_contentResourceId_idx").on(crp.userId, crp.lessonId),
10442
+ userIdIdx: (0, import_mysql_core35.index)("userId_idx").on(crp.userId),
10443
+ lessonIdIdx: (0, import_mysql_core35.index)("lessonId_idx").on(crp.lessonId)
10444
+ };
10445
+ });
10446
+ }
10447
+ __name(getLessonProgressSchema, "getLessonProgressSchema");
10448
+
10449
+ // src/lib/mysql/schemas/content/resource-progress.ts
10450
+ var import_drizzle_orm31 = require("drizzle-orm");
10451
+ var import_mysql_core36 = require("drizzle-orm/mysql-core");
10452
+ function getResourceProgressSchema(mysqlTable) {
10453
+ return mysqlTable("ResourceProgress", {
10454
+ userId: (0, import_mysql_core36.varchar)("userId", {
10455
+ length: 255
10456
+ }).notNull(),
10457
+ resourceId: (0, import_mysql_core36.varchar)("resourceId", {
10458
+ length: 255
10459
+ }),
10460
+ fields: (0, import_mysql_core36.json)("fields").$type().default({}),
10461
+ completedAt: (0, import_mysql_core36.datetime)("completedAt", {
10195
10462
  mode: "date",
10196
10463
  fsp: 3
10197
10464
  }),
10198
- updatedAt: (0, import_mysql_core31.datetime)("updatedAt", {
10465
+ updatedAt: (0, import_mysql_core36.datetime)("updatedAt", {
10199
10466
  mode: "date",
10200
10467
  fsp: 3
10201
10468
  }),
10202
- createdAt: (0, import_mysql_core31.datetime)("createdAt", {
10469
+ createdAt: (0, import_mysql_core36.datetime)("createdAt", {
10203
10470
  mode: "date",
10204
10471
  fsp: 3
10205
- }).default(import_drizzle_orm26.sql`CURRENT_TIMESTAMP(3)`).notNull()
10472
+ }).default(import_drizzle_orm31.sql`CURRENT_TIMESTAMP(3)`).notNull()
10206
10473
  }, (crp) => {
10207
10474
  return {
10208
- userIdLessonIdIdx: (0, import_mysql_core31.index)("crp_userId_contentResourceId_idx").on(crp.userId, crp.contentResourceId),
10209
- pk: (0, import_mysql_core31.primaryKey)({
10475
+ userIdLessonIdIdx: (0, import_mysql_core36.index)("crp_userId_contentResourceId_idx").on(crp.userId, crp.resourceId),
10476
+ pk: (0, import_mysql_core36.primaryKey)({
10210
10477
  columns: [
10211
10478
  crp.userId,
10212
- crp.contentResourceId
10479
+ crp.resourceId
10213
10480
  ]
10214
10481
  }),
10215
- contentResourceIdIdx: (0, import_mysql_core31.index)("contentResourceId_idx").on(crp.contentResourceId),
10216
- userIdIdx: (0, import_mysql_core31.index)("resourceId_idx").on(crp.userId)
10482
+ contentResourceIdIdx: (0, import_mysql_core36.index)("contentResourceId_idx").on(crp.resourceId),
10483
+ userIdIdx: (0, import_mysql_core36.index)("resourceId_idx").on(crp.userId)
10217
10484
  };
10218
10485
  });
10219
10486
  }
10220
10487
  __name(getResourceProgressSchema, "getResourceProgressSchema");
10221
10488
 
10222
10489
  // src/lib/mysql/index.ts
10490
+ var guid = (0, import_nanoid.customAlphabet)("1234567890abcdefghijklmnopqrstuvwxyz", 5);
10223
10491
  function getCourseBuilderSchema(mysqlTable) {
10224
10492
  return {
10225
10493
  accounts: getAccountsSchema(mysqlTable),
@@ -10241,6 +10509,7 @@ function getCourseBuilderSchema(mysqlTable) {
10241
10509
  verificationTokens: getVerificationTokensSchema(mysqlTable),
10242
10510
  coupon: getCouponSchema(mysqlTable),
10243
10511
  couponRelations: getCouponRelationsSchema(mysqlTable),
10512
+ lessonProgress: getLessonProgressSchema(mysqlTable),
10244
10513
  merchantAccount: getMerchantAccountSchema(mysqlTable),
10245
10514
  merchantCharge: getMerchantChargeSchema(mysqlTable),
10246
10515
  merchantChargeRelations: getMerchantChargeRelationsSchema(mysqlTable),
@@ -10272,7 +10541,15 @@ function getCourseBuilderSchema(mysqlTable) {
10272
10541
  upgradableProductsRelations: getUpgradableProductsRelationsSchema(mysqlTable),
10273
10542
  contentResourceProduct: getContentResourceProductSchema(mysqlTable),
10274
10543
  contentResourceProductRelations: getContentResourceProductRelationsSchema(mysqlTable),
10275
- productRelations: getProductRelationsSchema(mysqlTable)
10544
+ productRelations: getProductRelationsSchema(mysqlTable),
10545
+ comments: getCommentsSchema(mysqlTable),
10546
+ commentsRelations: getCommentRelationsSchema(mysqlTable),
10547
+ deviceVerifications: getDeviceVerificationSchema(mysqlTable),
10548
+ deviceVerificationRelations: getDeviceVerificationRelationsSchema(mysqlTable),
10549
+ deviceAccessToken: getDeviceAccessTokenSchema(mysqlTable),
10550
+ deviceAccessTokenRelations: getDeviceAccessTokenRelationsSchema(mysqlTable),
10551
+ userPrefs: getUserPrefsSchema(mysqlTable),
10552
+ userPrefsRelations: getUserPrefsRelationsSchema(mysqlTable)
10276
10553
  };
10277
10554
  }
10278
10555
  __name(getCourseBuilderSchema, "getCourseBuilderSchema");
@@ -10280,8 +10557,8 @@ function createTables(mySqlTable) {
10280
10557
  return getCourseBuilderSchema(mySqlTable);
10281
10558
  }
10282
10559
  __name(createTables, "createTables");
10283
- function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10284
- const { users, accounts, sessions, verificationTokens, contentResource, contentResourceResource, purchases: purchaseTable, purchaseUserTransfer, coupon, merchantCoupon, merchantCharge, merchantAccount, merchantPrice, merchantCustomer, merchantSession, merchantProduct, prices, products, upgradableProducts, resourceProgress } = createTables(tableFn);
10560
+ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core37.mysqlTable, paymentProvider) {
10561
+ const { users, accounts, sessions, verificationTokens, contentResource, contentResourceResource, contentResourceProduct, purchases: purchaseTable, purchaseUserTransfer, coupon, merchantCoupon, merchantCharge, merchantAccount, merchantPrice, merchantCustomer, merchantSession, merchantProduct, prices, products, upgradableProducts, resourceProgress, comments } = createTables(tableFn);
10285
10562
  const adapter = {
10286
10563
  client,
10287
10564
  async redeemFullPriceCoupon(options) {
@@ -10293,7 +10570,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10293
10570
  throw new Error(`unable-to-find-any-product-id`);
10294
10571
  const couponValidation = validateCoupon(coupon2, productIds);
10295
10572
  if (coupon2 && couponValidation.isRedeemable) {
10296
- const bulkCouponRedemption = Boolean(coupon2.bulkPurchase?.bulkCouponId);
10573
+ const bulkCouponRedemption = Boolean(coupon2.maxUses > 1);
10297
10574
  const { user } = await adapter.findOrCreateUser(email);
10298
10575
  if (!user)
10299
10576
  throw new Error(`unable-to-create-user-${email}`);
@@ -10303,8 +10580,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10303
10580
  userId: user.id,
10304
10581
  productId
10305
10582
  });
10306
- if (existingPurchases.length > 0)
10307
- throw new Error(`already-purchased-${email}`);
10583
+ if (existingPurchases.length > 0) {
10584
+ const errorMessage = `already-purchased-${email}`;
10585
+ console.error(errorMessage);
10586
+ return {
10587
+ error: {
10588
+ message: errorMessage
10589
+ },
10590
+ redeemingForCurrentUser,
10591
+ purchase: null
10592
+ };
10593
+ throw new Error(errorMessage);
10594
+ }
10308
10595
  const purchaseId = `purchase-${(0, import_uuid.v4)()}`;
10309
10596
  await adapter.createPurchase({
10310
10597
  id: purchaseId,
@@ -10342,12 +10629,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10342
10629
  },
10343
10630
  incrementCouponUsedCount: async (couponId) => {
10344
10631
  await client.update(coupon).set({
10345
- usedCount: import_drizzle_orm27.sql`${coupon.usedCount} + 1`
10346
- }).where((0, import_drizzle_orm27.eq)(coupon.id, couponId));
10632
+ usedCount: import_drizzle_orm32.sql`${coupon.usedCount} + 1`
10633
+ }).where((0, import_drizzle_orm32.eq)(coupon.id, couponId));
10347
10634
  },
10348
10635
  getExistingNonBulkValidPurchasesOfProduct: async ({ userId, productId }) => {
10349
10636
  const existingPurchases = await client.query.purchases.findMany({
10350
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(purchaseTable.userId, userId), productId ? (0, import_drizzle_orm27.eq)(purchaseTable.productId, productId) : void 0, (0, import_drizzle_orm27.eq)(purchaseTable.status, "Valid"), (0, import_drizzle_orm27.isNull)(purchaseTable.bulkCouponId))
10637
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(purchaseTable.userId, userId), productId ? (0, import_drizzle_orm32.eq)(purchaseTable.productId, productId) : void 0, (0, import_drizzle_orm32.eq)(purchaseTable.status, "Valid"), (0, import_drizzle_orm32.isNull)(purchaseTable.bulkCouponId))
10351
10638
  });
10352
10639
  return z.array(purchaseSchema).parse(existingPurchases);
10353
10640
  },
@@ -10360,17 +10647,17 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10360
10647
  status: 1
10361
10648
  });
10362
10649
  return merchantCustomerSchema.parse(await client.query.merchantCustomer.findFirst({
10363
- where: (0, import_drizzle_orm27.eq)(merchantCustomer.identifier, options.identifier)
10650
+ where: (0, import_drizzle_orm32.eq)(merchantCustomer.identifier, options.identifier)
10364
10651
  }));
10365
10652
  },
10366
10653
  getMerchantAccount: async (options) => {
10367
10654
  return merchantAccountSchema.parse(await client.query.merchantAccount.findFirst({
10368
- where: (0, import_drizzle_orm27.eq)(merchantAccount.label, options.provider)
10655
+ where: (0, import_drizzle_orm32.eq)(merchantAccount.label, options.provider)
10369
10656
  }));
10370
10657
  },
10371
10658
  getMerchantPriceForProductId: async (productId) => {
10372
10659
  const merchantPriceData = await client.query.merchantPrice.findFirst({
10373
- where: (0, import_drizzle_orm27.eq)(merchantPrice.merchantProductId, productId)
10660
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(merchantPrice.merchantProductId, productId), (0, import_drizzle_orm32.eq)(merchantPrice.status, 1))
10374
10661
  });
10375
10662
  const parsedMerchantPrice = merchantPriceSchema.safeParse(merchantPriceData);
10376
10663
  if (!parsedMerchantPrice.success) {
@@ -10381,7 +10668,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10381
10668
  },
10382
10669
  getMerchantProductForProductId: async (productId) => {
10383
10670
  const merchantProductData = await client.query.merchantProduct.findFirst({
10384
- where: (0, import_drizzle_orm27.eq)(merchantProduct.productId, productId)
10671
+ where: (0, import_drizzle_orm32.eq)(merchantProduct.productId, productId)
10385
10672
  });
10386
10673
  if (!merchantProductData)
10387
10674
  return null;
@@ -10389,7 +10676,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10389
10676
  },
10390
10677
  getMerchantCustomerForUserId: async (userId) => {
10391
10678
  const merchantCustomerData = await client.query.merchantCustomer.findFirst({
10392
- where: (0, import_drizzle_orm27.eq)(merchantCustomer.userId, userId)
10679
+ where: (0, import_drizzle_orm32.eq)(merchantCustomer.userId, userId)
10393
10680
  });
10394
10681
  if (!merchantCustomerData)
10395
10682
  return null;
@@ -10398,14 +10685,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10398
10685
  getUpgradableProducts: async (options) => {
10399
10686
  const { upgradableFromId, upgradableToId } = options;
10400
10687
  return z.array(upgradableProductSchema).parse(await client.query.upgradableProducts.findMany({
10401
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(upgradableProducts.upgradableFromId, upgradableFromId), (0, import_drizzle_orm27.eq)(upgradableProducts.upgradableToId, upgradableToId))
10688
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(upgradableProducts.upgradableFromId, upgradableFromId), (0, import_drizzle_orm32.eq)(upgradableProducts.upgradableToId, upgradableToId))
10402
10689
  }));
10403
10690
  },
10404
10691
  async availableUpgradesForProduct(purchases, productId) {
10405
10692
  const previousPurchaseProductIds = purchases.map(({ productId: productId2 }) => productId2);
10406
10693
  if (previousPurchaseProductIds.length > 0) {
10407
- return await client.query.upgradableProducts.findMany({
10408
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(upgradableProducts.upgradableToId, productId), (0, import_drizzle_orm27.inArray)(upgradableProducts.upgradableFromId, previousPurchaseProductIds))
10694
+ return client.query.upgradableProducts.findMany({
10695
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(upgradableProducts.upgradableToId, productId), (0, import_drizzle_orm32.inArray)(upgradableProducts.upgradableFromId, previousPurchaseProductIds))
10409
10696
  });
10410
10697
  }
10411
10698
  return [];
@@ -10418,7 +10705,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10418
10705
  throw new Error("No lessonId provided");
10419
10706
  }
10420
10707
  let lessonProgress = await client.query.resourceProgress.findFirst({
10421
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm27.eq)(resourceProgress.contentResourceId, options.lessonId))
10708
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm32.eq)(resourceProgress.resourceId, options.lessonId))
10422
10709
  });
10423
10710
  const now = /* @__PURE__ */ new Date();
10424
10711
  if (lessonProgress) {
@@ -10426,18 +10713,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10426
10713
  await client.update(resourceProgress).set({
10427
10714
  completedAt: now,
10428
10715
  updatedAt: now
10429
- }).where((0, import_drizzle_orm27.eq)(resourceProgress.contentResourceId, options.lessonId));
10716
+ }).where((0, import_drizzle_orm32.eq)(resourceProgress.resourceId, options.lessonId));
10430
10717
  }
10431
10718
  } else {
10432
10719
  await client.insert(resourceProgress).values({
10433
10720
  userId: options.userId,
10434
- contentResourceId: options.lessonId,
10721
+ resourceId: options.lessonId,
10435
10722
  completedAt: now,
10436
10723
  updatedAt: now
10437
10724
  });
10438
10725
  }
10439
10726
  lessonProgress = await client.query.resourceProgress.findFirst({
10440
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm27.eq)(resourceProgress.contentResourceId, options.lessonId))
10727
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm32.eq)(resourceProgress.resourceId, options.lessonId))
10441
10728
  });
10442
10729
  const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
10443
10730
  if (!parsedLessonProgress.success) {
@@ -10450,26 +10737,31 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10450
10737
  if (!options.couponId && !options.code)
10451
10738
  return null;
10452
10739
  const couponForIdOrCode = await client.query.coupon.findFirst({
10453
- where: (0, import_drizzle_orm27.or)((0, import_drizzle_orm27.and)((0, import_drizzle_orm27.or)(options.code ? (0, import_drizzle_orm27.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm27.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm27.gte)(coupon.expires, /* @__PURE__ */ new Date())), (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.or)(options.code ? (0, import_drizzle_orm27.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm27.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm27.isNull)(coupon.expires))),
10740
+ where: (0, import_drizzle_orm32.or)((0, import_drizzle_orm32.and)((0, import_drizzle_orm32.or)(options.code ? (0, import_drizzle_orm32.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm32.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm32.gte)(coupon.expires, /* @__PURE__ */ new Date())), (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.or)(options.code ? (0, import_drizzle_orm32.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm32.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm32.isNull)(coupon.expires))),
10454
10741
  with: {
10455
10742
  merchantCoupon: true
10456
10743
  }
10457
10744
  });
10458
10745
  if (!couponForIdOrCode)
10459
10746
  return null;
10460
- return couponSchema.extend({
10747
+ const parsedCoupon = couponSchema.extend({
10461
10748
  merchantCoupon: merchantCouponSchema
10462
- }).parse(couponForIdOrCode);
10749
+ }).safeParse(couponForIdOrCode);
10750
+ if (!parsedCoupon.success) {
10751
+ console.error("Error parsing coupon", JSON.stringify(parsedCoupon.error));
10752
+ return null;
10753
+ }
10754
+ return parsedCoupon.data;
10463
10755
  },
10464
10756
  async createMerchantChargeAndPurchase(options) {
10465
10757
  const purchaseId = await client.transaction(async (trx) => {
10466
10758
  try {
10467
10759
  const { userId, stripeChargeId, stripeCouponId, merchantAccountId, merchantProductId, merchantCustomerId, productId, stripeChargeAmount, quantity = 1, checkoutSessionId, appliedPPPStripeCouponId, upgradedFromPurchaseId, country, usedCouponId } = options;
10468
10760
  const existingMerchantCharge = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
10469
- where: (0, import_drizzle_orm27.eq)(merchantCharge.identifier, stripeChargeId)
10761
+ where: (0, import_drizzle_orm32.eq)(merchantCharge.identifier, stripeChargeId)
10470
10762
  }) || null);
10471
10763
  const existingPurchaseForCharge = existingMerchantCharge ? await client.query.purchases.findFirst({
10472
- where: (0, import_drizzle_orm27.eq)(purchaseTable.merchantChargeId, existingMerchantCharge.id),
10764
+ where: (0, import_drizzle_orm32.eq)(purchaseTable.merchantChargeId, existingMerchantCharge.id),
10473
10765
  with: {
10474
10766
  user: true,
10475
10767
  product: true,
@@ -10490,13 +10782,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10490
10782
  merchantCustomerId
10491
10783
  });
10492
10784
  const existingPurchase = purchaseSchema.nullable().parse(await client.query.purchases.findFirst({
10493
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm27.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm27.inArray)(purchaseTable.status, [
10785
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm32.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm32.inArray)(purchaseTable.status, [
10494
10786
  "Valid",
10495
10787
  "Restricted"
10496
10788
  ]))
10497
10789
  }) || null);
10498
- const existingBulkCoupon = couponSchema.nullable().parse(await client.select().from(coupon).leftJoin(purchaseTable, (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(coupon.id, purchaseTable.bulkCouponId), (0, import_drizzle_orm27.eq)(purchaseTable.userId, userId))).where((0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(coupon.restrictedToProductId, productId), (0, import_drizzle_orm27.eq)(purchaseTable.userId, userId))).then((res) => {
10499
- return res[0]?.coupons ?? null;
10790
+ const existingBulkCoupon = couponSchema.nullable().parse(await client.select().from(coupon).leftJoin(purchaseTable, (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(coupon.id, purchaseTable.bulkCouponId), (0, import_drizzle_orm32.eq)(purchaseTable.userId, userId))).where((0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(coupon.restrictedToProductId, productId), (0, import_drizzle_orm32.eq)(purchaseTable.userId, userId))).then((res) => {
10791
+ return res[0]?.Coupon ?? null;
10500
10792
  }));
10501
10793
  const isBulkPurchase = quantity > 1 || Boolean(existingBulkCoupon) || options.bulk || Boolean(existingPurchase?.status === "Valid");
10502
10794
  let bulkCouponId = null;
@@ -10506,10 +10798,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10506
10798
  if (existingBulkCoupon !== null) {
10507
10799
  couponToUpdate = await client.update(coupon).set({
10508
10800
  maxUses: (existingBulkCoupon?.maxUses || 0) + quantity
10509
- }).where((0, import_drizzle_orm27.eq)(coupon.id, bulkCouponId));
10801
+ }).where((0, import_drizzle_orm32.eq)(coupon.id, bulkCouponId));
10510
10802
  } else {
10511
10803
  const merchantCouponToUse = stripeCouponId ? merchantCouponSchema.nullable().parse(await client.query.merchantCoupon.findFirst({
10512
- where: (0, import_drizzle_orm27.eq)(merchantCoupon.identifier, stripeCouponId)
10804
+ where: (0, import_drizzle_orm32.eq)(merchantCoupon.identifier, stripeCouponId)
10513
10805
  })) : null;
10514
10806
  couponToUpdate = await client.insert(coupon).values({
10515
10807
  id: bulkCouponId,
@@ -10530,10 +10822,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10530
10822
  merchantAccountId
10531
10823
  });
10532
10824
  const merchantCouponUsed = stripeCouponId ? await client.query.merchantCoupon.findFirst({
10533
- where: (0, import_drizzle_orm27.eq)(merchantCoupon.identifier, stripeCouponId)
10825
+ where: (0, import_drizzle_orm32.eq)(merchantCoupon.identifier, stripeCouponId)
10534
10826
  }) : null;
10535
10827
  const pppMerchantCoupon = appliedPPPStripeCouponId ? await client.query.merchantCoupon.findFirst({
10536
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(merchantCoupon.identifier, appliedPPPStripeCouponId), (0, import_drizzle_orm27.eq)(merchantCoupon.type, "ppp"))
10828
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(merchantCoupon.identifier, appliedPPPStripeCouponId), (0, import_drizzle_orm32.eq)(merchantCoupon.type, "ppp"))
10537
10829
  }) : null;
10538
10830
  const newPurchaseStatus = merchantCouponUsed?.type === "ppp" || pppMerchantCoupon ? "Restricted" : "Valid";
10539
10831
  const newPurchase = await client.insert(purchaseTable).values({
@@ -10564,7 +10856,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10564
10856
  }
10565
10857
  });
10566
10858
  const parsedPurchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
10567
- where: (0, import_drizzle_orm27.eq)(purchaseTable.id, purchaseId)
10859
+ where: (0, import_drizzle_orm32.eq)(purchaseTable.id, purchaseId)
10568
10860
  }));
10569
10861
  if (!parsedPurchase.success) {
10570
10862
  console.error("Error parsing purchase", parsedPurchase, JSON.stringify(parsedPurchase, null, 2));
@@ -10609,7 +10901,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10609
10901
  },
10610
10902
  async getCoupon(couponIdOrCode) {
10611
10903
  const loadedCoupon = await client.query.coupon.findFirst({
10612
- where: (0, import_drizzle_orm27.or)((0, import_drizzle_orm27.eq)(coupon.id, couponIdOrCode), (0, import_drizzle_orm27.eq)(coupon.code, couponIdOrCode))
10904
+ where: (0, import_drizzle_orm32.or)((0, import_drizzle_orm32.eq)(coupon.id, couponIdOrCode), (0, import_drizzle_orm32.eq)(coupon.code, couponIdOrCode))
10613
10905
  }) || null;
10614
10906
  logger.debug("loadedCoupon", {
10615
10907
  loadedCoupon
@@ -10621,18 +10913,31 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10621
10913
  couponId
10622
10914
  });
10623
10915
  let couponData;
10916
+ let bulkCouponPurchases;
10624
10917
  try {
10625
10918
  couponData = await client.query.coupon.findFirst({
10626
- where: (0, import_drizzle_orm27.eq)(coupon.id, couponId),
10919
+ where: (0, import_drizzle_orm32.eq)(coupon.id, couponId),
10627
10920
  with: {
10628
- bulkPurchase: true,
10629
- bulkCouponPurchases: true
10921
+ bulkPurchases: true,
10922
+ redeemedBulkCouponPurchases: true
10630
10923
  }
10631
10924
  }) || null;
10632
10925
  } catch (e) {
10633
10926
  console.log("getCouponWithBulkPurchases");
10634
10927
  logger.error(e);
10635
10928
  }
10929
+ try {
10930
+ bulkCouponPurchases = await client.query.purchases.findMany({
10931
+ where: (0, import_drizzle_orm32.eq)(purchaseTable.redeemedBulkCouponId, couponId),
10932
+ with: {
10933
+ user: true
10934
+ }
10935
+ });
10936
+ console.log("purchases with redeemedBulkCouponId", bulkCouponPurchases);
10937
+ } catch (e) {
10938
+ console.log("getCouponWithBulkPurchases");
10939
+ logger.error(e);
10940
+ }
10636
10941
  if (!couponData) {
10637
10942
  logger.debug("getCouponWithBulkPurchases", {
10638
10943
  couponId,
@@ -10640,20 +10945,23 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10640
10945
  });
10641
10946
  return null;
10642
10947
  }
10948
+ const couponWithBulkPurchases = {
10949
+ ...couponData,
10950
+ redeemedBulkCouponPurchases: bulkCouponPurchases || []
10951
+ };
10643
10952
  const parsedCoupon = couponSchema.merge(z.object({
10644
- bulkCouponPurchases: z.array(purchaseSchema),
10645
- bulkPurchase: purchaseSchema.nullable().optional()
10646
- })).nullable().safeParse(couponData);
10953
+ redeemedBulkCouponPurchases: z.array(purchaseSchema)
10954
+ })).nullable().safeParse(couponWithBulkPurchases);
10647
10955
  if (!parsedCoupon.success) {
10648
- console.error("Error parsing coupon", couponData);
10956
+ console.error("Error parsing coupon", JSON.stringify(parsedCoupon.error), couponData);
10649
10957
  return null;
10650
10958
  }
10651
10959
  return parsedCoupon.data;
10652
10960
  },
10653
10961
  async getDefaultCoupon(productIds) {
10654
10962
  const activeSaleCoupon = await client.query.coupon.findFirst({
10655
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(coupon.status, 1), (0, import_drizzle_orm27.eq)(coupon.default, true), (0, import_drizzle_orm27.gte)(coupon.expires, /* @__PURE__ */ new Date()), (0, import_drizzle_orm27.or)(productIds ? (0, import_drizzle_orm27.inArray)(coupon.restrictedToProductId, productIds) : void 0, (0, import_drizzle_orm27.isNull)(coupon.restrictedToProductId))),
10656
- orderBy: (0, import_drizzle_orm27.desc)(coupon.percentageDiscount),
10963
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(coupon.status, 1), (0, import_drizzle_orm32.eq)(coupon.default, true), (0, import_drizzle_orm32.gte)(coupon.expires, /* @__PURE__ */ new Date()), (0, import_drizzle_orm32.or)(productIds ? (0, import_drizzle_orm32.inArray)(coupon.restrictedToProductId, productIds) : void 0, (0, import_drizzle_orm32.isNull)(coupon.restrictedToProductId))),
10964
+ orderBy: (0, import_drizzle_orm32.desc)(coupon.percentageDiscount),
10657
10965
  with: {
10658
10966
  merchantCoupon: true,
10659
10967
  product: true
@@ -10677,7 +10985,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10677
10985
  },
10678
10986
  async getLessonProgressForUser(userId) {
10679
10987
  const userProgress = await client.query.resourceProgress.findMany({
10680
- where: (0, import_drizzle_orm27.eq)(resourceProgress.userId, userId)
10988
+ where: (0, import_drizzle_orm32.eq)(resourceProgress.userId, userId)
10681
10989
  });
10682
10990
  const parsed = z.array(resourceProgressSchema).safeParse(userProgress);
10683
10991
  if (!parsed.success) {
@@ -10687,95 +10995,98 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10687
10995
  return parsed.data;
10688
10996
  },
10689
10997
  async getModuleProgressForUser(userIdOrEmail, moduleIdOrSlug) {
10690
- const module2 = await client.query.contentResource.findFirst({
10691
- where: (0, import_drizzle_orm27.or)((0, import_drizzle_orm27.eq)(contentResource.id, moduleIdOrSlug), (0, import_drizzle_orm27.eq)(import_drizzle_orm27.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, moduleIdOrSlug)),
10692
- with: {
10693
- resources: {
10694
- orderBy: (0, import_drizzle_orm27.asc)(contentResourceResource.position)
10695
- }
10696
- }
10697
- });
10698
- const parsedModule = ContentResourceSchema.parse(module2);
10699
- const moduleResources = await client.query.contentResourceResource.findMany({
10700
- where: (0, import_drizzle_orm27.inArray)(contentResourceResource.resourceOfId, parsedModule.resources?.map((r) => r.resourceId) ?? []),
10701
- orderBy: (0, import_drizzle_orm27.asc)(contentResourceResource.position)
10702
- });
10703
- const parsedModuleResources = z.array(ContentResourceResourceSchema).safeParse(moduleResources);
10704
- if (!parsedModuleResources.success) {
10705
- console.error("Error parsing module resources", parsedModuleResources.error);
10706
- return {
10707
- completedLessons: [],
10708
- nextResource: null,
10709
- percentCompleted: 0,
10710
- completedLessonsCount: 0,
10711
- totalLessonsCount: 0
10712
- };
10713
- }
10714
10998
  const user = await client.query.users.findFirst({
10715
- where: (0, import_drizzle_orm27.or)((0, import_drizzle_orm27.eq)(users.id, userIdOrEmail), (0, import_drizzle_orm27.eq)(users.email, userIdOrEmail)),
10716
- with: {
10717
- roles: {
10718
- with: {
10719
- role: true
10720
- }
10721
- }
10722
- }
10723
- }).then(async (res) => {
10724
- if (res) {
10725
- return {
10726
- ...res,
10727
- roles: res.roles.map((r) => r.role)
10728
- };
10999
+ where: (0, import_drizzle_orm32.or)((0, import_drizzle_orm32.eq)(users.id, userIdOrEmail), (0, import_drizzle_orm32.eq)(users.email, userIdOrEmail)),
11000
+ columns: {
11001
+ id: true
10729
11002
  }
10730
11003
  });
10731
11004
  if (!user) {
10732
- console.error("User not found", userIdOrEmail);
10733
- return {
10734
- completedLessons: [],
10735
- nextResource: null,
10736
- percentCompleted: 0,
10737
- completedLessonsCount: 0,
10738
- totalLessonsCount: parsedModuleResources.data.length
10739
- };
11005
+ return null;
10740
11006
  }
10741
- const parsedUser = userSchema.safeParse(user);
10742
- if (!parsedUser.success) {
10743
- console.error("Error parsing user", parsedUser.error);
11007
+ const ResultRowSchema = z.object({
11008
+ resource_id: z.string(),
11009
+ resource_type: z.enum([
11010
+ "lesson",
11011
+ "exercise"
11012
+ ]),
11013
+ resource_slug: z.string().nullable(),
11014
+ completed_at: z.string().nullable().transform((val) => val ? new Date(val) : null)
11015
+ });
11016
+ const results = await client.execute(import_drizzle_orm32.sql`
11017
+ SELECT
11018
+ cr.id AS resource_id,
11019
+ cr.type AS resource_type,
11020
+ cr.fields->>'$.slug' AS resource_slug,
11021
+ rp.completedAt AS completed_at
11022
+ FROM
11023
+ (SELECT id, fields->>'$.slug' AS slug
11024
+ FROM ${contentResource}
11025
+ WHERE id = ${moduleIdOrSlug}
11026
+ OR fields->>'$.slug' = ${moduleIdOrSlug}) AS w
11027
+ LEFT JOIN
11028
+ (SELECT
11029
+ crr.resourceOfId AS workshop_id,
11030
+ crr.resourceId,
11031
+ crr.position
11032
+ FROM ${contentResourceResource} crr) AS tlr ON w.id = tlr.workshop_id
11033
+ LEFT JOIN ${contentResource} sections ON sections.id = tlr.resourceId AND sections.type = 'section'
11034
+ LEFT JOIN
11035
+ (SELECT
11036
+ crr.resourceOfId AS section_id,
11037
+ crr.resourceId AS resource_id,
11038
+ crr.position AS position_in_section,
11039
+ section_crr.position AS section_position
11040
+ FROM ${contentResourceResource} crr
11041
+ JOIN ${contentResourceResource} section_crr ON crr.resourceOfId = section_crr.resourceId) AS sr
11042
+ ON sr.section_id = sections.id
11043
+ JOIN ${contentResource} cr ON cr.id = COALESCE(sr.resource_id, tlr.resourceId)
11044
+ LEFT JOIN ${resourceProgress} rp ON rp.resourceId = cr.id
11045
+ AND rp.userId = ${user.id}
11046
+ WHERE
11047
+ cr.type IN ('lesson', 'exercise')
11048
+
11049
+ `);
11050
+ const completedLessons = [];
11051
+ let nextResource = null;
11052
+ let completedLessonsCount = 0;
11053
+ let totalLessonsCount = results.rows.length;
11054
+ const parsedRows = z.array(ResultRowSchema).safeParse(results.rows);
11055
+ if (!parsedRows.success) {
11056
+ console.error("Error parsing rows", parsedRows.error);
10744
11057
  return {
10745
11058
  completedLessons: [],
10746
11059
  nextResource: null,
10747
11060
  percentCompleted: 0,
10748
11061
  completedLessonsCount: 0,
10749
- totalLessonsCount: parsedModuleResources.data.length
11062
+ totalLessonsCount
10750
11063
  };
10751
11064
  }
10752
- const userProgress = await client.query.resourceProgress.findMany({
10753
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(resourceProgress.userId, parsedUser.data.id), (0, import_drizzle_orm27.isNotNull)(resourceProgress.completedAt), (0, import_drizzle_orm27.inArray)(resourceProgress.contentResourceId, parsedModuleResources.data.map((r) => r.resourceId))),
10754
- orderBy: (0, import_drizzle_orm27.asc)(resourceProgress.completedAt)
10755
- });
10756
- const nextResourceId = moduleResources.find((r) => !userProgress.find((p) => p.contentResourceId === r.resourceId))?.resourceId;
10757
- const nextResource = await client.query.contentResource.findFirst({
10758
- where: (0, import_drizzle_orm27.eq)(contentResource.id, nextResourceId)
10759
- });
10760
- const parsedNextResource = ContentResourceSchema.nullable().optional().default(null).parse(nextResource);
10761
- const parsedProgress = z.array(resourceProgressSchema).safeParse(userProgress);
10762
- if (!parsedProgress.success) {
10763
- console.error("Error parsing user progress", parsedProgress.error);
10764
- return {
10765
- completedLessons: [],
10766
- nextResource: null,
10767
- percentCompleted: 0,
10768
- completedLessonsCount: 0,
10769
- totalLessonsCount: parsedModuleResources.data.length
10770
- };
11065
+ for (const row of parsedRows.data) {
11066
+ if (row.completed_at) {
11067
+ completedLessonsCount++;
11068
+ completedLessons.push({
11069
+ userId: user.id,
11070
+ resourceId: row.resource_id,
11071
+ completedAt: new Date(row.completed_at)
11072
+ });
11073
+ } else if (!nextResource) {
11074
+ nextResource = {
11075
+ id: row.resource_id,
11076
+ type: row.resource_type,
11077
+ fields: {
11078
+ slug: row.resource_slug
11079
+ }
11080
+ };
11081
+ }
10771
11082
  }
10772
- const percentCompleted = Math.round(parsedProgress.data.length / parsedModuleResources.data.length * 100);
11083
+ const percentCompleted = totalLessonsCount > 0 ? Math.ceil(completedLessonsCount / totalLessonsCount * 100) : 0;
10773
11084
  return {
10774
- completedLessons: parsedProgress.data,
10775
- nextResource: parsedNextResource,
11085
+ completedLessons,
11086
+ nextResource,
10776
11087
  percentCompleted,
10777
- completedLessonsCount: parsedProgress.data.length,
10778
- totalLessonsCount: parsedModuleResources.data.length
11088
+ completedLessonsCount,
11089
+ totalLessonsCount
10779
11090
  };
10780
11091
  },
10781
11092
  getLessonProgresses() {
@@ -10783,23 +11094,23 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10783
11094
  },
10784
11095
  async getMerchantCharge(merchantChargeId) {
10785
11096
  const mCharge = await client.query.merchantCharge.findFirst({
10786
- where: (0, import_drizzle_orm27.eq)(merchantCharge.id, merchantChargeId)
11097
+ where: (0, import_drizzle_orm32.eq)(merchantCharge.id, merchantChargeId)
10787
11098
  });
10788
11099
  const parsed = merchantChargeSchema.safeParse(mCharge);
10789
11100
  if (!parsed.success) {
10790
- console.error("Error parsing merchantCharge", mCharge);
11101
+ console.info("Error parsing merchantCharge", mCharge);
10791
11102
  return null;
10792
11103
  }
10793
11104
  return parsed.data;
10794
11105
  },
10795
11106
  async getMerchantCouponsForTypeAndPercent(params) {
10796
11107
  return z.array(merchantCouponSchema).parse(await client.query.merchantCoupon.findMany({
10797
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm27.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
11108
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm32.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
10798
11109
  }));
10799
11110
  },
10800
11111
  async getMerchantCouponForTypeAndPercent(params) {
10801
11112
  const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
10802
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm27.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
11113
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm32.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
10803
11114
  });
10804
11115
  const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
10805
11116
  if (parsed.success) {
@@ -10809,7 +11120,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10809
11120
  },
10810
11121
  async getMerchantCoupon(merchantCouponId) {
10811
11122
  const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
10812
- where: (0, import_drizzle_orm27.eq)(merchantCoupon.id, merchantCouponId)
11123
+ where: (0, import_drizzle_orm32.eq)(merchantCoupon.id, merchantCouponId)
10813
11124
  });
10814
11125
  const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
10815
11126
  if (parsed.success) {
@@ -10819,7 +11130,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10819
11130
  },
10820
11131
  async getMerchantProduct(stripeProductId) {
10821
11132
  return merchantProductSchema.nullable().parse(await client.query.merchantProduct.findFirst({
10822
- where: (0, import_drizzle_orm27.eq)(merchantProduct.identifier, stripeProductId)
11133
+ where: (0, import_drizzle_orm32.eq)(merchantProduct.identifier, stripeProductId)
10823
11134
  }));
10824
11135
  },
10825
11136
  getPrice(productId) {
@@ -10827,17 +11138,264 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10827
11138
  },
10828
11139
  async getPriceForProduct(productId) {
10829
11140
  return priceSchema.nullable().parse(await client.query.prices.findFirst({
10830
- where: (0, import_drizzle_orm27.eq)(prices.productId, productId)
11141
+ where: (0, import_drizzle_orm32.eq)(prices.productId, productId)
11142
+ }));
11143
+ },
11144
+ async archiveProduct(productId) {
11145
+ if (!paymentProvider)
11146
+ throw new Error("Payment provider not found");
11147
+ const product = await adapter.getProduct(productId);
11148
+ if (!product) {
11149
+ throw new Error(`Product not found for id (${productId})`);
11150
+ }
11151
+ if (!product.price) {
11152
+ throw new Error(`Product has no price`);
11153
+ }
11154
+ await client.update(products).set({
11155
+ status: 0,
11156
+ name: `${product.name} (Archived)`
11157
+ }).where((0, import_drizzle_orm32.eq)(products.id, productId));
11158
+ await client.update(prices).set({
11159
+ status: 0,
11160
+ nickname: `${product.name} (Archived)`
11161
+ }).where((0, import_drizzle_orm32.eq)(prices.productId, productId));
11162
+ await client.update(merchantProduct).set({
11163
+ status: 0
11164
+ }).where((0, import_drizzle_orm32.eq)(merchantProduct.productId, productId));
11165
+ await client.update(merchantPrice).set({
11166
+ status: 0
11167
+ }).where((0, import_drizzle_orm32.eq)(merchantPrice.priceId, product.price.id));
11168
+ const currentMerchantProduct = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
11169
+ where: (0, import_drizzle_orm32.eq)(merchantProduct.productId, productId)
11170
+ }));
11171
+ if (!currentMerchantProduct || !currentMerchantProduct.identifier) {
11172
+ throw new Error(`Merchant product not found for id (${productId})`);
11173
+ }
11174
+ await paymentProvider.updateProduct(currentMerchantProduct.identifier, {
11175
+ active: false
11176
+ });
11177
+ const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
11178
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(merchantPrice.priceId, product.price.id), (0, import_drizzle_orm32.eq)(merchantPrice.status, 1))
11179
+ }));
11180
+ if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
11181
+ throw new Error(`Merchant price not found for id (${productId})`);
11182
+ }
11183
+ await paymentProvider.updatePrice(currentMerchantPrice.identifier, {
11184
+ active: false
11185
+ });
11186
+ return adapter.getProduct(productId);
11187
+ },
11188
+ async updateProduct(input) {
11189
+ if (!paymentProvider)
11190
+ throw new Error("Payment provider not found");
11191
+ const currentProduct = await adapter.getProduct(input.id);
11192
+ if (!currentProduct) {
11193
+ throw new Error(`Product not found`);
11194
+ }
11195
+ if (!currentProduct.price) {
11196
+ throw new Error(`Product has no price`);
11197
+ }
11198
+ const merchantProduct2 = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
11199
+ where: (merchantProduct3, { eq: eq2 }) => eq2(merchantProduct3.productId, input.id)
11200
+ }));
11201
+ if (!merchantProduct2 || !merchantProduct2.identifier) {
11202
+ throw new Error(`Merchant product not found`);
11203
+ }
11204
+ const stripeProduct = await paymentProvider.getProduct(merchantProduct2.identifier);
11205
+ const priceChanged = currentProduct.price.unitAmount.toString() !== input.price?.unitAmount.toString();
11206
+ if (priceChanged) {
11207
+ const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
11208
+ where: (merchantPrice2, { eq: eq2, and: and2 }) => and2(eq2(merchantPrice2.merchantProductId, merchantProduct2.id), eq2(merchantPrice2.status, 1))
11209
+ }));
11210
+ if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
11211
+ throw new Error(`Merchant price not found`);
11212
+ }
11213
+ const currentStripePrice = await paymentProvider.getPrice(currentMerchantPrice.identifier);
11214
+ const newStripePrice = await paymentProvider.createPrice({
11215
+ product: stripeProduct.id,
11216
+ unit_amount: Math.floor(Number(input.price?.unitAmount || 0) * 100),
11217
+ currency: "usd",
11218
+ metadata: {
11219
+ slug: input.fields.slug
11220
+ },
11221
+ active: true
11222
+ });
11223
+ await paymentProvider.updateProduct(stripeProduct.id, {
11224
+ default_price: newStripePrice.id
11225
+ });
11226
+ const newMerchantPriceId = `mprice_${(0, import_uuid.v4)()}`;
11227
+ await client.insert(merchantPrice).values({
11228
+ id: newMerchantPriceId,
11229
+ merchantProductId: merchantProduct2.id,
11230
+ merchantAccountId: merchantProduct2.merchantAccountId,
11231
+ priceId: currentProduct.price.id,
11232
+ status: 1,
11233
+ identifier: newStripePrice.id
11234
+ });
11235
+ if (currentMerchantPrice) {
11236
+ await client.update(merchantPrice).set({
11237
+ status: 0
11238
+ }).where((0, import_drizzle_orm32.eq)(merchantPrice.id, currentMerchantPrice.id));
11239
+ }
11240
+ await client.update(prices).set({
11241
+ unitAmount: Math.floor(Number(input.price?.unitAmount || 0)).toString(),
11242
+ nickname: input.name
11243
+ }).where((0, import_drizzle_orm32.eq)(prices.id, currentProduct.price.id));
11244
+ if (currentStripePrice) {
11245
+ await paymentProvider.updatePrice(currentStripePrice.id, {
11246
+ active: false
11247
+ });
11248
+ }
11249
+ }
11250
+ await paymentProvider.updateProduct(stripeProduct.id, {
11251
+ name: input.name,
11252
+ active: true,
11253
+ images: input.fields.image?.url ? [
11254
+ input.fields.image.url
11255
+ ] : void 0,
11256
+ description: input.fields.description || "",
11257
+ metadata: {
11258
+ slug: input.fields.slug
11259
+ }
11260
+ });
11261
+ const { image, ...fieldsNoImage } = input.fields;
11262
+ await client.update(products).set({
11263
+ name: input.name,
11264
+ quantityAvailable: input.quantityAvailable,
11265
+ status: 1,
11266
+ fields: {
11267
+ ...fieldsNoImage,
11268
+ ...image?.url && {
11269
+ image
11270
+ }
11271
+ }
11272
+ }).where((0, import_drizzle_orm32.eq)(products.id, currentProduct.id));
11273
+ return adapter.getProduct(currentProduct.id);
11274
+ },
11275
+ async createProduct(input) {
11276
+ if (!paymentProvider)
11277
+ throw new Error("Payment provider not found");
11278
+ const merchantAccount2 = merchantAccountSchema.nullish().parse(await client.query.merchantAccount.findFirst({
11279
+ where: (merchantAccount3, { eq: eq2 }) => eq2(merchantAccount3.label, "stripe")
10831
11280
  }));
11281
+ if (!merchantAccount2) {
11282
+ throw new Error("Merchant account not found");
11283
+ }
11284
+ const hash = guid();
11285
+ const newProductId = (0, import_slugify.default)(`product-${hash}`);
11286
+ const newProduct = {
11287
+ id: newProductId,
11288
+ name: input.name,
11289
+ status: 1,
11290
+ type: "self-paced",
11291
+ quantityAvailable: input.quantityAvailable,
11292
+ fields: {
11293
+ state: "draft",
11294
+ visibility: "unlisted",
11295
+ slug: (0, import_slugify.default)(`${input.name}-${hash}`)
11296
+ }
11297
+ };
11298
+ await client.insert(products).values(newProduct);
11299
+ const priceHash = guid();
11300
+ const newPriceId = `price-${priceHash}`;
11301
+ await client.insert(prices).values({
11302
+ id: newPriceId,
11303
+ productId: newProductId,
11304
+ unitAmount: input.price.toString(),
11305
+ status: 1
11306
+ });
11307
+ const product = await adapter.getProduct(newProductId);
11308
+ const stripeProduct = await paymentProvider.createProduct({
11309
+ name: input.name,
11310
+ metadata: {
11311
+ slug: product?.fields?.slug || null
11312
+ }
11313
+ });
11314
+ const stripePrice = await paymentProvider.createPrice({
11315
+ product: stripeProduct.id,
11316
+ unit_amount: Math.floor(Number(input.price) * 100),
11317
+ currency: "usd",
11318
+ nickname: input.name,
11319
+ metadata: {
11320
+ slug: product?.fields?.slug || null
11321
+ }
11322
+ });
11323
+ const newMerchantProductId = `mproduct_${(0, import_uuid.v4)()}`;
11324
+ await client.insert(merchantProduct).values({
11325
+ id: newMerchantProductId,
11326
+ merchantAccountId: merchantAccount2.id,
11327
+ productId: newProductId,
11328
+ identifier: stripeProduct.id,
11329
+ status: 1
11330
+ });
11331
+ const newMerchantPriceId = `mprice_${(0, import_uuid.v4)()}`;
11332
+ await client.insert(merchantPrice).values({
11333
+ id: newMerchantPriceId,
11334
+ merchantAccountId: merchantAccount2.id,
11335
+ merchantProductId: newMerchantProductId,
11336
+ priceId: newPriceId,
11337
+ identifier: stripePrice.id,
11338
+ status: 1
11339
+ });
11340
+ return product;
11341
+ },
11342
+ async getProduct(productSlugOrId, withResources = true) {
11343
+ if (!productSlugOrId) {
11344
+ return null;
11345
+ }
11346
+ try {
11347
+ const productData = await client.query.products.findFirst({
11348
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.or)((0, import_drizzle_orm32.eq)(import_drizzle_orm32.sql`JSON_EXTRACT (${products.fields}, "$.slug")`, `${productSlugOrId}`), (0, import_drizzle_orm32.eq)(products.id, productSlugOrId))),
11349
+ with: {
11350
+ price: true,
11351
+ ...withResources && {
11352
+ resources: {
11353
+ with: {
11354
+ resource: {
11355
+ with: {
11356
+ resources: true
11357
+ }
11358
+ }
11359
+ }
11360
+ }
11361
+ }
11362
+ }
11363
+ });
11364
+ const parsedProduct = productSchema.safeParse(productData);
11365
+ if (!parsedProduct.success) {
11366
+ console.error("Error parsing product", JSON.stringify(parsedProduct.error), JSON.stringify(productData));
11367
+ return null;
11368
+ }
11369
+ return parsedProduct.data;
11370
+ } catch (e) {
11371
+ console.log("getProduct error", e);
11372
+ return null;
11373
+ }
10832
11374
  },
10833
- async getProduct(productId) {
10834
- return productSchema.nullable().parse(await client.query.products.findFirst({
10835
- where: (0, import_drizzle_orm27.eq)(products.id, productId)
11375
+ async getProductResources(productId) {
11376
+ const contentResourceProductsForProduct = z.array(ContentResourceProductSchema).nullable().parse(await client.query.contentResourceProduct.findMany({
11377
+ where: (0, import_drizzle_orm32.eq)(contentResourceProduct.productId, productId)
10836
11378
  }));
11379
+ if (!contentResourceProductsForProduct) {
11380
+ return null;
11381
+ } else {
11382
+ const contentResources = z.array(ContentResourceSchema).parse(await client.query.contentResource.findMany({
11383
+ where: (0, import_drizzle_orm32.inArray)(contentResource.id, contentResourceProductsForProduct.map((crp) => crp.resourceId))
11384
+ }));
11385
+ return contentResources;
11386
+ }
11387
+ },
11388
+ async getPurchaseCountForProduct(productId) {
11389
+ return await client.query.purchases.findMany({
11390
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm32.inArray)(purchaseTable.status, [
11391
+ "Valid",
11392
+ "Restricted"
11393
+ ]))
11394
+ }).then((res) => res.length);
10837
11395
  },
10838
11396
  async getPurchase(purchaseId) {
10839
11397
  const purchase = await client.query.purchases.findFirst({
10840
- where: (0, import_drizzle_orm27.eq)(purchaseTable.id, purchaseId)
11398
+ where: (0, import_drizzle_orm32.eq)(purchaseTable.id, purchaseId)
10841
11399
  });
10842
11400
  return purchase ? purchaseSchema.parse(purchase) : null;
10843
11401
  },
@@ -10855,14 +11413,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10855
11413
  stripeChargeId
10856
11414
  });
10857
11415
  const chargeForPurchase = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
10858
- where: (0, import_drizzle_orm27.eq)(merchantCharge.identifier, stripeChargeId)
11416
+ where: (0, import_drizzle_orm32.eq)(merchantCharge.identifier, stripeChargeId)
10859
11417
  }) || null);
10860
11418
  if (!chargeForPurchase) {
10861
- logger.error(new Error("No charge found for purchase"));
11419
+ logger.error(new Error(`No charge found for purchase: Stripe Charge ID: ${stripeChargeId}`));
10862
11420
  return null;
10863
11421
  }
10864
11422
  const purchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
10865
- where: (0, import_drizzle_orm27.eq)(purchaseTable.merchantChargeId, chargeForPurchase.id),
11423
+ where: (0, import_drizzle_orm32.eq)(purchaseTable.merchantChargeId, chargeForPurchase.id),
10866
11424
  with: {
10867
11425
  user: true,
10868
11426
  product: true,
@@ -10876,7 +11434,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10876
11434
  },
10877
11435
  async getPurchaseUserTransferById(options) {
10878
11436
  const purchaseTransferData = await client.query.purchaseUserTransfer.findFirst({
10879
- where: (0, import_drizzle_orm27.eq)(purchaseUserTransfer.id, options.id),
11437
+ where: (0, import_drizzle_orm32.eq)(purchaseUserTransfer.id, options.id),
10880
11438
  with: {
10881
11439
  sourceUser: true,
10882
11440
  targetUser: true,
@@ -10891,7 +11449,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10891
11449
  },
10892
11450
  async getPurchaseWithUser(purchaseId) {
10893
11451
  const purchaseData = await client.query.purchases.findFirst({
10894
- where: (0, import_drizzle_orm27.eq)(purchaseTable.id, purchaseId),
11452
+ where: (0, import_drizzle_orm32.eq)(purchaseTable.id, purchaseId),
10895
11453
  with: {
10896
11454
  user: true
10897
11455
  }
@@ -10915,13 +11473,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10915
11473
  "Restricted"
10916
11474
  ];
10917
11475
  const userPurchases = await client.query.purchases.findMany({
10918
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm27.inArray)(purchaseTable.status, visiblePurchaseStates)),
11476
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm32.inArray)(purchaseTable.status, visiblePurchaseStates)),
10919
11477
  with: {
10920
11478
  user: true,
10921
11479
  product: true,
10922
11480
  bulkCoupon: true
10923
11481
  },
10924
- orderBy: (0, import_drizzle_orm27.asc)(purchaseTable.createdAt)
11482
+ orderBy: (0, import_drizzle_orm32.asc)(purchaseTable.createdAt)
10925
11483
  });
10926
11484
  const parsedPurchases = z.array(purchaseSchema).safeParse(userPurchases);
10927
11485
  if (!parsedPurchases.success) {
@@ -10937,18 +11495,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10937
11495
  "Restricted"
10938
11496
  ];
10939
11497
  const userPurchases = await client.query.purchases.findMany({
10940
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm27.inArray)(purchaseTable.status, visiblePurchaseStates)),
11498
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm32.inArray)(purchaseTable.status, visiblePurchaseStates)),
10941
11499
  with: {
10942
11500
  user: true,
10943
11501
  product: true,
10944
11502
  bulkCoupon: true
10945
11503
  },
10946
- orderBy: (0, import_drizzle_orm27.asc)(purchaseTable.createdAt)
11504
+ orderBy: (0, import_drizzle_orm32.asc)(purchaseTable.createdAt)
10947
11505
  });
10948
11506
  const parsedPurchases = z.array(purchaseSchema).safeParse(userPurchases);
10949
11507
  const allPurchases = parsedPurchases.success ? parsedPurchases.data : [];
10950
11508
  const thePurchase = await client.query.purchases.findFirst({
10951
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(purchaseTable.id, purchaseId), (0, import_drizzle_orm27.eq)(purchaseTable.userId, userId)),
11509
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(purchaseTable.id, purchaseId), (0, import_drizzle_orm32.eq)(purchaseTable.userId, userId)),
10952
11510
  with: {
10953
11511
  user: true,
10954
11512
  product: true,
@@ -10969,7 +11527,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10969
11527
  let availableUpgrades = [];
10970
11528
  if (purchaseCanUpgrade) {
10971
11529
  availableUpgrades = await client.query.upgradableProducts.findMany({
10972
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(upgradableProducts.upgradableFromId, parsedPurchase.data.product?.id), (0, import_drizzle_orm27.not)((0, import_drizzle_orm27.inArray)(upgradableProducts.upgradableToId, allPurchases.map((p) => p.product?.id)))),
11530
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(upgradableProducts.upgradableFromId, parsedPurchase.data.product?.id), (0, import_drizzle_orm32.not)((0, import_drizzle_orm32.inArray)(upgradableProducts.upgradableToId, allPurchases.map((p) => p.product?.id)))),
10973
11531
  with: {
10974
11532
  upgradableTo: true,
10975
11533
  upgradableFrom: true
@@ -10977,10 +11535,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10977
11535
  });
10978
11536
  }
10979
11537
  const existingPurchase = purchaseSchema.optional().nullable().parse(await client.query.purchases.findFirst({
10980
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm27.eq)(purchaseTable.productId, parsedPurchase.data.productId), (0, import_drizzle_orm27.inArray)(purchaseTable.status, [
11538
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm32.eq)(purchaseTable.productId, parsedPurchase.data.productId), (0, import_drizzle_orm32.inArray)(purchaseTable.status, [
10981
11539
  "Valid",
10982
11540
  "Restricted"
10983
- ]), (0, import_drizzle_orm27.isNull)(purchaseTable.bulkCouponId), (0, import_drizzle_orm27.not)((0, import_drizzle_orm27.eq)(purchaseTable.id, parsedPurchase.data.id))),
11541
+ ]), (0, import_drizzle_orm32.isNull)(purchaseTable.bulkCouponId), (0, import_drizzle_orm32.not)((0, import_drizzle_orm32.eq)(purchaseTable.id, parsedPurchase.data.id))),
10984
11542
  with: {
10985
11543
  user: true,
10986
11544
  product: true,
@@ -10993,9 +11551,36 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
10993
11551
  purchase: parsedPurchase.data
10994
11552
  };
10995
11553
  },
11554
+ async getUserWithPurchasersByEmail(email) {
11555
+ const user = await client.query.users.findFirst({
11556
+ where: (0, import_drizzle_orm32.eq)(users.email, email.trim().toLowerCase()),
11557
+ with: {
11558
+ // merchantCustomer: true,
11559
+ roles: {
11560
+ with: {
11561
+ role: true
11562
+ }
11563
+ },
11564
+ purchases: {
11565
+ with: {
11566
+ bulkCoupon: true,
11567
+ merchantCharge: true,
11568
+ product: {
11569
+ columns: {
11570
+ id: true,
11571
+ name: true,
11572
+ key: true
11573
+ }
11574
+ }
11575
+ }
11576
+ }
11577
+ }
11578
+ });
11579
+ return user;
11580
+ },
10996
11581
  async getUserById(userId) {
10997
11582
  const user = await client.query.users.findFirst({
10998
- where: (0, import_drizzle_orm27.eq)(users.id, userId),
11583
+ where: (0, import_drizzle_orm32.eq)(users.id, userId),
10999
11584
  with: {
11000
11585
  roles: {
11001
11586
  with: {
@@ -11017,13 +11602,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11017
11602
  if (userId === void 0)
11018
11603
  return [];
11019
11604
  const canUpgradeProducts = await client.query.upgradableProducts.findMany({
11020
- where: (0, import_drizzle_orm27.eq)(upgradableProducts.upgradableToId, bundleId)
11605
+ where: (0, import_drizzle_orm32.eq)(upgradableProducts.upgradableToId, bundleId)
11021
11606
  });
11022
11607
  const upgradableFrom = z.array(z.string()).parse(canUpgradeProducts.map((product) => {
11023
11608
  return product.upgradableFromId;
11024
11609
  }));
11025
11610
  const purchases = await client.query.purchases.findMany({
11026
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm27.inArray)(purchaseTable.productId, upgradableFrom))
11611
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm32.inArray)(purchaseTable.productId, upgradableFrom))
11027
11612
  });
11028
11613
  const productsPurchased = z.array(z.string()).parse(purchases.map((purchase) => {
11029
11614
  return purchase.productId;
@@ -11031,7 +11616,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11031
11616
  if (productsPurchased.length === 0)
11032
11617
  return [];
11033
11618
  const foundPrices = await client.query.prices.findMany({
11034
- where: (0, import_drizzle_orm27.inArray)(prices.productId, productsPurchased)
11619
+ where: (0, import_drizzle_orm32.inArray)(prices.productId, productsPurchased)
11035
11620
  });
11036
11621
  return z.array(priceSchema).parse(foundPrices);
11037
11622
  },
@@ -11040,24 +11625,24 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11040
11625
  throw new Error("No lessonId provided");
11041
11626
  }
11042
11627
  let lessonProgress = await client.query.resourceProgress.findFirst({
11043
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm27.eq)(resourceProgress.contentResourceId, options.lessonId))
11628
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm32.eq)(resourceProgress.resourceId, options.lessonId))
11044
11629
  });
11045
11630
  const now = /* @__PURE__ */ new Date();
11046
11631
  if (lessonProgress) {
11047
11632
  await client.update(resourceProgress).set({
11048
11633
  completedAt: lessonProgress.completedAt ? null : now,
11049
11634
  updatedAt: now
11050
- }).where((0, import_drizzle_orm27.eq)(resourceProgress.contentResourceId, options.lessonId));
11635
+ }).where((0, import_drizzle_orm32.eq)(resourceProgress.resourceId, options.lessonId));
11051
11636
  } else {
11052
11637
  await client.insert(resourceProgress).values({
11053
11638
  userId: options.userId,
11054
- contentResourceId: options.lessonId,
11639
+ resourceId: options.lessonId,
11055
11640
  completedAt: now,
11056
11641
  updatedAt: now
11057
11642
  });
11058
11643
  }
11059
11644
  lessonProgress = await client.query.resourceProgress.findFirst({
11060
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm27.eq)(resourceProgress.contentResourceId, options.lessonId))
11645
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm32.eq)(resourceProgress.resourceId, options.lessonId))
11061
11646
  });
11062
11647
  const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
11063
11648
  if (!parsedLessonProgress.success) {
@@ -11069,22 +11654,54 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11069
11654
  transferPurchasesToNewUser(options) {
11070
11655
  throw new Error("Method not implemented.");
11071
11656
  },
11072
- updatePurchaseStatusForCharge(chargeId, status) {
11073
- throw new Error("updatePurchaseStatusForCharge Method not implemented.");
11657
+ async updatePurchaseStatusForCharge(chargeId, status) {
11658
+ try {
11659
+ console.log("updatePurchaseStatusForCharge", {
11660
+ chargeId,
11661
+ status
11662
+ });
11663
+ const merchantChargeForPurchase = await client.query.merchantCharge.findFirst({
11664
+ where: (0, import_drizzle_orm32.or)((0, import_drizzle_orm32.eq)(merchantCharge.identifier, chargeId), (0, import_drizzle_orm32.eq)(merchantCharge.id, chargeId))
11665
+ });
11666
+ console.log("merchantChargeForPurchase", {
11667
+ merchantChargeForPurchase
11668
+ });
11669
+ const parsedMerchantChargeForPurchase = merchantChargeSchema.parse(merchantChargeForPurchase);
11670
+ if (!parsedMerchantChargeForPurchase)
11671
+ throw new Error(`no-charge-found-for-purchase ${chargeId}`);
11672
+ const purchase = await client.query.purchases.findFirst({
11673
+ where: (0, import_drizzle_orm32.eq)(purchaseTable.merchantChargeId, parsedMerchantChargeForPurchase.id)
11674
+ });
11675
+ const parsedPurchase = purchaseSchema.nullable().parse(purchase);
11676
+ if (parsedPurchase) {
11677
+ await client.update(purchaseTable).set({
11678
+ status
11679
+ }).where((0, import_drizzle_orm32.eq)(purchaseTable.id, parsedPurchase.id));
11680
+ const newPurchase = await client.query.purchases.findFirst({
11681
+ where: (0, import_drizzle_orm32.eq)(purchaseTable.id, parsedPurchase.id)
11682
+ });
11683
+ return purchaseSchema.optional().parse(newPurchase);
11684
+ } else {
11685
+ throw new Error(`no-purchase-found-for-charge ${chargeId}`);
11686
+ }
11687
+ } catch (e) {
11688
+ console.log("error updating purchase status", e);
11689
+ throw e;
11690
+ }
11074
11691
  },
11075
11692
  async updatePurchaseUserTransferTransferState(options) {
11076
11693
  await client.update(purchaseUserTransfer).set({
11077
11694
  transferState: options.transferState
11078
- }).where((0, import_drizzle_orm27.eq)(purchaseUserTransfer.id, options.id));
11695
+ }).where((0, import_drizzle_orm32.eq)(purchaseUserTransfer.id, options.id));
11079
11696
  const purchaseUserTransferData = await client.query.purchaseUserTransfer.findFirst({
11080
- where: (0, import_drizzle_orm27.eq)(purchaseUserTransfer.id, options.id)
11697
+ where: (0, import_drizzle_orm32.eq)(purchaseUserTransfer.id, options.id)
11081
11698
  }) || null;
11082
11699
  return purchaseUserTransferSchema.nullable().parse(purchaseUserTransferData);
11083
11700
  },
11084
11701
  addResourceToResource: async function(options) {
11085
11702
  const { parentResourceId, childResourceId } = options;
11086
11703
  const parentResourceData = await client.query.contentResource.findFirst({
11087
- where: (0, import_drizzle_orm27.or)((0, import_drizzle_orm27.eq)(import_drizzle_orm27.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, parentResourceId), (0, import_drizzle_orm27.eq)(contentResource.id, parentResourceId)),
11704
+ where: (0, import_drizzle_orm32.or)((0, import_drizzle_orm32.eq)(import_drizzle_orm32.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, parentResourceId), (0, import_drizzle_orm32.eq)(contentResource.id, parentResourceId)),
11088
11705
  with: {
11089
11706
  resources: true
11090
11707
  }
@@ -11096,7 +11713,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11096
11713
  position: parentResource.resources?.length || 0
11097
11714
  });
11098
11715
  const resourceJoin = client.query.contentResourceResource.findFirst({
11099
- where: (0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(contentResourceResource.resourceOfId, parentResourceId), (0, import_drizzle_orm27.eq)(contentResourceResource.resourceId, childResourceId)),
11716
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(contentResourceResource.resourceOfId, parentResourceId), (0, import_drizzle_orm32.eq)(contentResourceResource.resourceId, childResourceId)),
11100
11717
  with: {
11101
11718
  resource: true
11102
11719
  }
@@ -11107,19 +11724,31 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11107
11724
  }
11108
11725
  return parsedResourceJoin.data;
11109
11726
  },
11727
+ async removeResourceFromResource(options) {
11728
+ const { childResourceId, parentResourceId } = options;
11729
+ const resourceJoin = await client.query.contentResourceResource.findFirst({
11730
+ where: (0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(contentResourceResource.resourceOfId, parentResourceId), (0, import_drizzle_orm32.eq)(contentResourceResource.resourceId, childResourceId))
11731
+ });
11732
+ const parsedResourceJoin = ContentResourceResourceSchema.safeParse(resourceJoin);
11733
+ if (!parsedResourceJoin.success) {
11734
+ return null;
11735
+ }
11736
+ await client.delete(contentResourceResource).where((0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(contentResourceResource.resourceOfId, parentResourceId), (0, import_drizzle_orm32.eq)(contentResourceResource.resourceId, childResourceId)));
11737
+ return parsedResourceJoin.data.resource;
11738
+ },
11110
11739
  async updateContentResourceFields(options) {
11111
11740
  if (!options.id) {
11112
11741
  throw new Error("No content resource id.");
11113
11742
  }
11114
- const currentResource = await client.select().from(contentResource).where((0, import_drizzle_orm27.eq)(contentResource.id, options.id)).then((res) => res[0]);
11743
+ const currentResource = await client.select().from(contentResource).where((0, import_drizzle_orm32.eq)(contentResource.id, options.id)).then((res) => res[0]);
11115
11744
  await client.update(contentResource).set({
11116
11745
  fields: {
11117
11746
  ...currentResource.fields,
11118
11747
  ...options.fields
11119
11748
  }
11120
- }).where((0, import_drizzle_orm27.eq)(contentResource.id, options.id));
11749
+ }).where((0, import_drizzle_orm32.eq)(contentResource.id, options.id));
11121
11750
  const resource = await client.query.contentResource.findFirst({
11122
- where: (0, import_drizzle_orm27.eq)(contentResource.id, options.id),
11751
+ where: (0, import_drizzle_orm32.eq)(contentResource.id, options.id),
11123
11752
  with: {
11124
11753
  resources: {
11125
11754
  with: {
@@ -11129,12 +11758,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11129
11758
  with: {
11130
11759
  resource: true
11131
11760
  },
11132
- orderBy: (0, import_drizzle_orm27.asc)(contentResourceResource.position)
11761
+ orderBy: (0, import_drizzle_orm32.asc)(contentResourceResource.position)
11133
11762
  }
11134
11763
  }
11135
11764
  }
11136
11765
  },
11137
- orderBy: (0, import_drizzle_orm27.asc)(contentResourceResource.position)
11766
+ orderBy: (0, import_drizzle_orm32.asc)(contentResourceResource.position)
11138
11767
  }
11139
11768
  }
11140
11769
  });
@@ -11149,7 +11778,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11149
11778
  if (!id) {
11150
11779
  return null;
11151
11780
  }
11152
- const query = import_drizzle_orm27.sql`
11781
+ const query = import_drizzle_orm32.sql`
11153
11782
  SELECT
11154
11783
  id as id,
11155
11784
  CAST(updatedAt AS DATETIME) as updatedAt,
@@ -11181,7 +11810,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11181
11810
  id
11182
11811
  });
11183
11812
  const resource = await client.query.contentResource.findFirst({
11184
- where: (0, import_drizzle_orm27.eq)(contentResource.id, id),
11813
+ where: (0, import_drizzle_orm32.eq)(contentResource.id, id),
11185
11814
  with: {
11186
11815
  resources: {
11187
11816
  with: {
@@ -11191,12 +11820,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11191
11820
  with: {
11192
11821
  resource: true
11193
11822
  },
11194
- orderBy: (0, import_drizzle_orm27.asc)(contentResourceResource.position)
11823
+ orderBy: (0, import_drizzle_orm32.asc)(contentResourceResource.position)
11195
11824
  }
11196
11825
  }
11197
11826
  }
11198
11827
  },
11199
- orderBy: (0, import_drizzle_orm27.asc)(contentResourceResource.position)
11828
+ orderBy: (0, import_drizzle_orm32.asc)(contentResourceResource.position)
11200
11829
  }
11201
11830
  }
11202
11831
  });
@@ -11209,7 +11838,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11209
11838
  },
11210
11839
  async getContentResource(data) {
11211
11840
  const resource = await client.query.contentResource.findFirst({
11212
- where: (0, import_drizzle_orm27.or)((0, import_drizzle_orm27.eq)(contentResource.id, data), (0, import_drizzle_orm27.eq)(import_drizzle_orm27.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, `${data}`)),
11841
+ where: (0, import_drizzle_orm32.or)((0, import_drizzle_orm32.eq)(contentResource.id, data), (0, import_drizzle_orm32.eq)(import_drizzle_orm32.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, `${data}`)),
11213
11842
  with: {
11214
11843
  resources: {
11215
11844
  with: {
@@ -11217,14 +11846,22 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11217
11846
  with: {
11218
11847
  resources: {
11219
11848
  with: {
11220
- resource: true
11849
+ resource: {
11850
+ with: {
11851
+ resources: {
11852
+ with: {
11853
+ resource: true
11854
+ }
11855
+ }
11856
+ }
11857
+ }
11221
11858
  },
11222
- orderBy: (0, import_drizzle_orm27.asc)(contentResourceResource.position)
11859
+ orderBy: (0, import_drizzle_orm32.asc)(contentResourceResource.position)
11223
11860
  }
11224
11861
  }
11225
11862
  }
11226
11863
  },
11227
- orderBy: (0, import_drizzle_orm27.asc)(contentResourceResource.position)
11864
+ orderBy: (0, import_drizzle_orm32.asc)(contentResourceResource.position)
11228
11865
  }
11229
11866
  }
11230
11867
  });
@@ -11242,61 +11879,61 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11242
11879
  ...data,
11243
11880
  id
11244
11881
  });
11245
- return await client.select().from(users).where((0, import_drizzle_orm27.eq)(users.id, id)).then((res) => res[0]);
11882
+ return await client.select().from(users).where((0, import_drizzle_orm32.eq)(users.id, id)).then((res) => res[0]);
11246
11883
  } catch (error) {
11247
11884
  console.error(error);
11248
11885
  throw error;
11249
11886
  }
11250
11887
  },
11251
11888
  async getUser(data) {
11252
- return await client.select().from(users).where((0, import_drizzle_orm27.eq)(users.id, data)).then((res) => res[0]) ?? null;
11889
+ return await client.select().from(users).where((0, import_drizzle_orm32.eq)(users.id, data)).then((res) => res[0]) ?? null;
11253
11890
  },
11254
11891
  async getUserByEmail(data) {
11255
- return await client.select().from(users).where((0, import_drizzle_orm27.eq)(users.email, data)).then((res) => res[0]) ?? null;
11892
+ return await client.select().from(users).where((0, import_drizzle_orm32.eq)(users.email, data)).then((res) => res[0]) ?? null;
11256
11893
  },
11257
11894
  async createSession(data) {
11258
11895
  await client.insert(sessions).values(data);
11259
- return await client.select().from(sessions).where((0, import_drizzle_orm27.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
11896
+ return await client.select().from(sessions).where((0, import_drizzle_orm32.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
11260
11897
  },
11261
11898
  async getSessionAndUser(data) {
11262
11899
  return await client.select({
11263
11900
  session: sessions,
11264
11901
  user: users
11265
- }).from(sessions).where((0, import_drizzle_orm27.eq)(sessions.sessionToken, data)).innerJoin(users, (0, import_drizzle_orm27.eq)(users.id, sessions.userId)).then((res) => res[0]) ?? null;
11902
+ }).from(sessions).where((0, import_drizzle_orm32.eq)(sessions.sessionToken, data)).innerJoin(users, (0, import_drizzle_orm32.eq)(users.id, sessions.userId)).then((res) => res[0]) ?? null;
11266
11903
  },
11267
11904
  async updateUser(data) {
11268
11905
  if (!data.id) {
11269
11906
  throw new Error("No user id.");
11270
11907
  }
11271
- await client.update(users).set(data).where((0, import_drizzle_orm27.eq)(users.id, data.id));
11272
- return await client.select().from(users).where((0, import_drizzle_orm27.eq)(users.id, data.id)).then((res) => res[0]);
11908
+ await client.update(users).set(data).where((0, import_drizzle_orm32.eq)(users.id, data.id));
11909
+ return await client.select().from(users).where((0, import_drizzle_orm32.eq)(users.id, data.id)).then((res) => res[0]);
11273
11910
  },
11274
11911
  async updateSession(data) {
11275
- await client.update(sessions).set(data).where((0, import_drizzle_orm27.eq)(sessions.sessionToken, data.sessionToken));
11276
- return await client.select().from(sessions).where((0, import_drizzle_orm27.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
11912
+ await client.update(sessions).set(data).where((0, import_drizzle_orm32.eq)(sessions.sessionToken, data.sessionToken));
11913
+ return await client.select().from(sessions).where((0, import_drizzle_orm32.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
11277
11914
  },
11278
11915
  async linkAccount(rawAccount) {
11279
11916
  await client.insert(accounts).values(rawAccount);
11280
11917
  },
11281
11918
  async getUserByAccount(account) {
11282
- const dbAccount = await client.select().from(accounts).where((0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm27.eq)(accounts.provider, account.provider))).leftJoin(users, (0, import_drizzle_orm27.eq)(accounts.userId, users.id)).then((res) => res[0]) ?? null;
11919
+ const dbAccount = await client.select().from(accounts).where((0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm32.eq)(accounts.provider, account.provider))).leftJoin(users, (0, import_drizzle_orm32.eq)(accounts.userId, users.id)).then((res) => res[0]) ?? null;
11283
11920
  if (!dbAccount) {
11284
11921
  return null;
11285
11922
  }
11286
- return dbAccount.user;
11923
+ return dbAccount.User;
11287
11924
  },
11288
11925
  async deleteSession(sessionToken) {
11289
- const session = await client.select().from(sessions).where((0, import_drizzle_orm27.eq)(sessions.sessionToken, sessionToken)).then((res) => res[0]) ?? null;
11290
- await client.delete(sessions).where((0, import_drizzle_orm27.eq)(sessions.sessionToken, sessionToken));
11926
+ const session = await client.select().from(sessions).where((0, import_drizzle_orm32.eq)(sessions.sessionToken, sessionToken)).then((res) => res[0]) ?? null;
11927
+ await client.delete(sessions).where((0, import_drizzle_orm32.eq)(sessions.sessionToken, sessionToken));
11291
11928
  return session;
11292
11929
  },
11293
11930
  async createVerificationToken(token) {
11294
11931
  await client.insert(verificationTokens).values(token);
11295
- return await client.select().from(verificationTokens).where((0, import_drizzle_orm27.eq)(verificationTokens.identifier, token.identifier)).then((res) => res[0]);
11932
+ return await client.select().from(verificationTokens).where((0, import_drizzle_orm32.eq)(verificationTokens.identifier, token.identifier)).then((res) => res[0]);
11296
11933
  },
11297
11934
  async useVerificationToken(token) {
11298
11935
  try {
11299
- const deletedToken = await client.select().from(verificationTokens).where((0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm27.eq)(verificationTokens.token, token.token))).then((res) => res[0]) ?? null;
11936
+ const deletedToken = await client.select().from(verificationTokens).where((0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm32.eq)(verificationTokens.token, token.token))).then((res) => res[0]) ?? null;
11300
11937
  if (deletedToken?.createdAt) {
11301
11938
  const TIMEOUT_IN_SECONDS = 90;
11302
11939
  const expireMultipleClicks = (0, import_date_fns2.addSeconds)(deletedToken.createdAt, TIMEOUT_IN_SECONDS);
@@ -11305,7 +11942,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11305
11942
  const { id: _, ...verificationToken } = token;
11306
11943
  return deletedToken;
11307
11944
  } else {
11308
- await client.delete(verificationTokens).where((0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm27.eq)(verificationTokens.token, token.token)));
11945
+ await client.delete(verificationTokens).where((0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm32.eq)(verificationTokens.token, token.token)));
11309
11946
  return deletedToken;
11310
11947
  }
11311
11948
  }
@@ -11315,14 +11952,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core32.mysqlTable) {
11315
11952
  }
11316
11953
  },
11317
11954
  async deleteUser(id) {
11318
- const user = await client.select().from(users).where((0, import_drizzle_orm27.eq)(users.id, id)).then((res) => res[0] ?? null);
11319
- await client.delete(users).where((0, import_drizzle_orm27.eq)(users.id, id));
11320
- await client.delete(sessions).where((0, import_drizzle_orm27.eq)(sessions.userId, id));
11321
- await client.delete(accounts).where((0, import_drizzle_orm27.eq)(accounts.userId, id));
11955
+ const user = await client.select().from(users).where((0, import_drizzle_orm32.eq)(users.id, id)).then((res) => res[0] ?? null);
11956
+ await client.delete(users).where((0, import_drizzle_orm32.eq)(users.id, id));
11957
+ await client.delete(sessions).where((0, import_drizzle_orm32.eq)(sessions.userId, id));
11958
+ await client.delete(accounts).where((0, import_drizzle_orm32.eq)(accounts.userId, id));
11322
11959
  return user;
11323
11960
  },
11324
11961
  async unlinkAccount(account) {
11325
- await client.delete(accounts).where((0, import_drizzle_orm27.and)((0, import_drizzle_orm27.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm27.eq)(accounts.provider, account.provider)));
11962
+ await client.delete(accounts).where((0, import_drizzle_orm32.and)((0, import_drizzle_orm32.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm32.eq)(accounts.provider, account.provider)));
11326
11963
  return void 0;
11327
11964
  }
11328
11965
  };
@@ -11333,6 +11970,7 @@ __name(mySqlDrizzleAdapter, "mySqlDrizzleAdapter");
11333
11970
  0 && (module.exports = {
11334
11971
  createTables,
11335
11972
  getCourseBuilderSchema,
11973
+ guid,
11336
11974
  mySqlDrizzleAdapter
11337
11975
  });
11338
11976
  //# sourceMappingURL=index.cjs.map