@coursebuilder/adapter-drizzle 2.0.1-canary.cd34f124e → 2.1.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 (67) hide show
  1. package/dist/{chunk-WPDVDHLH.js → chunk-2AW5KYAK.js} +2 -2
  2. package/dist/chunk-62VSIVME.js +4714 -0
  3. package/dist/{chunk-6VDGZ4KA.js → chunk-7FBSP3VD.js} +2 -2
  4. package/dist/{chunk-QDWLBCD3.js → chunk-AP5HBIV4.js} +2 -2
  5. package/dist/{chunk-DHII2GRW.js → chunk-EZEQQJNH.js} +2 -2
  6. package/dist/{chunk-Q5NZ5UFZ.js → chunk-F56AI52P.js} +2 -2
  7. package/dist/{chunk-RDAVEULA.js → chunk-KIQLUFJX.js} +2 -2
  8. package/dist/{chunk-3XHKEHGF.js → chunk-M3WM5Q7W.js} +2 -2
  9. package/dist/{chunk-4SMVVOU5.js → chunk-PJORQUQP.js} +2 -2
  10. package/dist/{chunk-DB473RZJ.js → chunk-PNPTKVJ4.js} +4 -4
  11. package/dist/{chunk-ULJCXOOM.js → chunk-RVXF3JZ7.js} +627 -5096
  12. package/dist/chunk-WEJL5OFI.js +8732 -0
  13. package/dist/{chunk-52A4W4YI.js → chunk-WWBSNLRC.js} +2 -2
  14. package/dist/index.d.ts +5 -0
  15. package/dist/index.js +14 -13
  16. package/dist/lib/mysql/cms-resource-actions.cjs +4733 -0
  17. package/dist/lib/mysql/cms-resource-actions.cjs.map +1 -0
  18. package/dist/lib/mysql/cms-resource-actions.d.cts +155 -0
  19. package/dist/lib/mysql/cms-resource-actions.d.ts +155 -0
  20. package/dist/lib/mysql/cms-resource-actions.js +8 -0
  21. package/dist/lib/mysql/cms-resource-actions.js.map +1 -0
  22. package/dist/lib/mysql/index.cjs +420 -187
  23. package/dist/lib/mysql/index.cjs.map +1 -1
  24. package/dist/lib/mysql/index.d.cts +5 -0
  25. package/dist/lib/mysql/index.d.ts +5 -0
  26. package/dist/lib/mysql/index.js +17 -13
  27. package/dist/lib/mysql/schemas/auth/accounts.js +2 -2
  28. package/dist/lib/mysql/schemas/auth/device-access-token.js +3 -3
  29. package/dist/lib/mysql/schemas/auth/device-verification.js +3 -3
  30. package/dist/lib/mysql/schemas/auth/personal-access-token.js +3 -3
  31. package/dist/lib/mysql/schemas/auth/profiles.js +2 -2
  32. package/dist/lib/mysql/schemas/auth/role-permissions.js +3 -3
  33. package/dist/lib/mysql/schemas/auth/roles.js +2 -2
  34. package/dist/lib/mysql/schemas/auth/sessions.js +3 -3
  35. package/dist/lib/mysql/schemas/auth/user-permissions.js +2 -2
  36. package/dist/lib/mysql/schemas/auth/user-prefs.js +2 -2
  37. package/dist/lib/mysql/schemas/auth/user-roles.js +2 -2
  38. package/dist/lib/mysql/schemas/auth/users.js +2 -2
  39. package/dist/lib/mysql/schemas/commerce/coupon.js +2 -2
  40. package/dist/lib/mysql/schemas/commerce/merchant-charge.js +2 -2
  41. package/dist/lib/mysql/schemas/commerce/merchant-subscription.js +2 -2
  42. package/dist/lib/mysql/schemas/commerce/price.js +2 -2
  43. package/dist/lib/mysql/schemas/commerce/product.js +2 -2
  44. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +3 -3
  45. package/dist/lib/mysql/schemas/commerce/purchase.js +2 -2
  46. package/dist/lib/mysql/schemas/commerce/subscription.js +2 -2
  47. package/dist/lib/mysql/schemas/commerce/upgradable-products.js +3 -3
  48. package/dist/lib/mysql/schemas/communication/comment.js +2 -2
  49. package/dist/lib/mysql/schemas/communication/communication-preferences.js +2 -2
  50. package/dist/lib/mysql/schemas/communication/question-response.js +3 -3
  51. package/dist/lib/mysql/schemas/content/content-contributions.js +2 -2
  52. package/dist/lib/mysql/schemas/content/content-resource-product.js +2 -2
  53. package/dist/lib/mysql/schemas/content/content-resource-resource.js +2 -2
  54. package/dist/lib/mysql/schemas/content/content-resource-tag.js +2 -2
  55. package/dist/lib/mysql/schemas/content/content-resource-version.js +2 -2
  56. package/dist/lib/mysql/schemas/content/content-resource.js +2 -2
  57. package/dist/lib/mysql/schemas/content/tag-tag.js +2 -2
  58. package/dist/lib/mysql/schemas/content/tag.js +2 -2
  59. package/dist/lib/mysql/schemas/entitlements/entitlement.js +3 -3
  60. package/dist/lib/mysql/schemas/org/organization-membership-roles.js +2 -2
  61. package/dist/lib/mysql/schemas/org/organization-memberships.js +2 -2
  62. package/dist/lib/mysql/schemas/org/organizations.js +2 -2
  63. package/dist/lib/utils.d.cts +5 -0
  64. package/dist/lib/utils.d.ts +5 -0
  65. package/package.json +3 -3
  66. package/src/lib/mysql/cms-resource-actions.ts +527 -0
  67. package/src/lib/mysql/index.ts +3 -0
@@ -10,11 +10,11 @@ var __export = (target, all) => {
10
10
  for (var name in all)
11
11
  __defProp(target, name, { get: all[name], enumerable: true });
12
12
  };
13
- var __copyProps = (to, from, except, desc2) => {
13
+ var __copyProps = (to, from, except, desc3) => {
14
14
  if (from && typeof from === "object" || typeof from === "function") {
15
15
  for (let key of __getOwnPropNames(from))
16
16
  if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc2 = __getOwnPropDesc(from, key)) || desc2.enumerable });
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc3 = __getOwnPropDesc(from, key)) || desc3.enumerable });
18
18
  }
19
19
  return to;
20
20
  };
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/lib/mysql/index.ts
32
32
  var mysql_exports = {};
33
33
  __export(mysql_exports, {
34
+ createCmsResourceActions: () => createCmsResourceActions,
34
35
  createTables: () => createTables,
35
36
  getCourseBuilderSchema: () => getCourseBuilderSchema,
36
37
  guid: () => guid,
@@ -40,7 +41,7 @@ __export(mysql_exports, {
40
41
  module.exports = __toCommonJS(mysql_exports);
41
42
  var import_slugify = __toESM(require("@sindresorhus/slugify"), 1);
42
43
  var import_date_fns2 = require("date-fns");
43
- var import_drizzle_orm46 = require("drizzle-orm");
44
+ var import_drizzle_orm47 = require("drizzle-orm");
44
45
  var import_mysql_core52 = require("drizzle-orm/mysql-core");
45
46
  var import_nanoid = require("nanoid");
46
47
  var import_uuid = require("uuid");
@@ -9348,7 +9349,7 @@ var upgradableProductSchema = external_exports2.object({
9348
9349
  deletedAt: external_exports2.date().nullable()
9349
9350
  });
9350
9351
 
9351
- // ../core/dist/chunk-QHRMESWX.js
9352
+ // ../core/dist/chunk-F3WB3QT7.js
9352
9353
  var VideoChapterSchema = external_exports2.object({
9353
9354
  startTime: external_exports2.number().min(0),
9354
9355
  title: external_exports2.string().min(1).max(120)
@@ -9359,6 +9360,8 @@ var VideoResourceSchema = external_exports2.object({
9359
9360
  createdAt: external_exports2.coerce.date().optional(),
9360
9361
  title: external_exports2.string().optional().nullable(),
9361
9362
  duration: external_exports2.number().optional().nullable(),
9363
+ /** Max stored resolution, e.g. '1080p' — persisted on Mux asset.ready. */
9364
+ resolution: external_exports2.string().optional().nullable(),
9362
9365
  muxPlaybackId: external_exports2.string().optional().nullable(),
9363
9366
  muxAssetId: external_exports2.string().optional().nullable(),
9364
9367
  transcript: external_exports2.string().optional().nullable(),
@@ -13282,6 +13285,234 @@ function getEntitlementRelationsSchema(mysqlTable, overrides = {}) {
13282
13285
  }
13283
13286
  __name(getEntitlementRelationsSchema, "getEntitlementRelationsSchema");
13284
13287
 
13288
+ // src/lib/mysql/cms-resource-actions.ts
13289
+ var import_drizzle_orm46 = require("drizzle-orm");
13290
+ var jsonNumber = external_exports.preprocess((value) => value == null ? null : Number(value), external_exports.number().nullable().optional());
13291
+ var CmsImageResourceRowSchema = external_exports.object({
13292
+ id: external_exports.string(),
13293
+ url: external_exports.string(),
13294
+ alt: external_exports.string().optional().nullable(),
13295
+ // Human filename (the uploaded file's name) — the media grid prefers it
13296
+ // over `alt` for the tile label; absent on older rows.
13297
+ name: external_exports.string().optional().nullable(),
13298
+ // Row creation time — the media tab's unified grid sorts by it.
13299
+ createdAt: external_exports.coerce.date().optional().nullable(),
13300
+ // Cloudinary metadata — optional/nullable so pre-metadata rows keep
13301
+ // working (JSON_EXTRACT returns NULL when the key is absent). Numeric
13302
+ // coercion preserves null (plain z.coerce.number() would turn it into 0);
13303
+ // MySQL JSON numerics can arrive as strings through some drivers.
13304
+ width: jsonNumber,
13305
+ height: jsonNumber,
13306
+ bytes: jsonNumber,
13307
+ format: external_exports.string().optional().nullable()
13308
+ });
13309
+ var ListResourcesForPickerInputSchema = external_exports.object({
13310
+ types: external_exports.array(external_exports.string()).min(1),
13311
+ search: external_exports.string().trim().max(200).optional(),
13312
+ excludeIds: external_exports.array(external_exports.string()).default([]),
13313
+ limit: external_exports.number().int().min(1).max(100).default(20)
13314
+ });
13315
+ function createCmsResourceActions(options) {
13316
+ const { db, contentResource, contentResourceResource, contentResourceProduct, getAuthContext, getEditHref } = options;
13317
+ const dbQuery = db.query;
13318
+ async function assertCanUpdateContent() {
13319
+ const { session, ability } = await getAuthContext();
13320
+ if (!session?.user || !ability.can("update", "Content")) {
13321
+ throw new Error("Unauthorized");
13322
+ }
13323
+ }
13324
+ __name(assertCanUpdateContent, "assertCanUpdateContent");
13325
+ async function listResourcesForPicker(input) {
13326
+ await assertCanUpdateContent();
13327
+ const { types, search, excludeIds, limit } = ListResourcesForPickerInputSchema.parse(input);
13328
+ const conditions = [
13329
+ (0, import_drizzle_orm46.inArray)(contentResource.type, types),
13330
+ (0, import_drizzle_orm46.isNull)(contentResource.deletedAt)
13331
+ ];
13332
+ if (excludeIds.length > 0) {
13333
+ conditions.push((0, import_drizzle_orm46.notInArray)(contentResource.id, excludeIds));
13334
+ }
13335
+ if (search) {
13336
+ const escaped = search.replace(/[\\%_]/g, "\\$&");
13337
+ conditions.push(import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.title')) LIKE ${`%${escaped}%`}`);
13338
+ }
13339
+ const rows = await db.select({
13340
+ id: contentResource.id,
13341
+ type: contentResource.type,
13342
+ title: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.title'))`,
13343
+ // Generated (indexed) column — cheaper than a JSON_EXTRACT here.
13344
+ slug: contentResource.slug,
13345
+ state: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.state'))`,
13346
+ postType: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.postType'))`,
13347
+ updatedAt: contentResource.updatedAt
13348
+ }).from(contentResource).where((0, import_drizzle_orm46.and)(...conditions)).orderBy((0, import_drizzle_orm46.desc)(contentResource.updatedAt)).limit(limit);
13349
+ return rows.map((row) => ({
13350
+ id: row.id,
13351
+ type: row.type,
13352
+ title: row.title ?? row.slug ?? row.id,
13353
+ slug: row.slug ?? "",
13354
+ state: row.state ?? "draft",
13355
+ detail: row.postType ?? void 0,
13356
+ updatedAt: row.updatedAt ?? void 0
13357
+ }));
13358
+ }
13359
+ __name(listResourcesForPicker, "listResourcesForPicker");
13360
+ async function listVideoResourcesForPicker(input) {
13361
+ await assertCanUpdateContent();
13362
+ const excludeIds = input.excludeIds ?? [];
13363
+ const limit = Math.min(Math.max(input.limit ?? 20, 1), 200);
13364
+ const offset = Math.max(0, Math.floor(input.offset ?? 0));
13365
+ const conditions = [
13366
+ (0, import_drizzle_orm46.eq)(contentResource.type, "videoResource"),
13367
+ (0, import_drizzle_orm46.isNull)(contentResource.deletedAt)
13368
+ ];
13369
+ if (excludeIds.length > 0) {
13370
+ conditions.push((0, import_drizzle_orm46.notInArray)(contentResource.id, excludeIds));
13371
+ }
13372
+ if (input.search) {
13373
+ const escaped = input.search.replace(/[\\%_]/g, "\\$&");
13374
+ conditions.push(import_drizzle_orm46.sql`${contentResource.id} LIKE ${`%${escaped}%`}`);
13375
+ }
13376
+ const pageRows = await db.select({
13377
+ id: contentResource.id,
13378
+ createdAt: contentResource.createdAt
13379
+ }).from(contentResource).where((0, import_drizzle_orm46.and)(...conditions)).orderBy((0, import_drizzle_orm46.desc)(contentResource.createdAt)).limit(offset + limit + 50);
13380
+ if (pageRows.length === 0)
13381
+ return [];
13382
+ const detailRows = await db.select({
13383
+ id: contentResource.id,
13384
+ state: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.state'))`,
13385
+ muxPlaybackId: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.muxPlaybackId'))`,
13386
+ duration: import_drizzle_orm46.sql`JSON_EXTRACT(${contentResource.fields}, '$.duration')`,
13387
+ createdAt: contentResource.createdAt
13388
+ }).from(contentResource).where((0, import_drizzle_orm46.inArray)(contentResource.id, pageRows.map((row) => row.id)));
13389
+ const byId = new Map(detailRows.map((row) => [
13390
+ row.id,
13391
+ row
13392
+ ]));
13393
+ const rows = pageRows.flatMap((page) => byId.get(page.id) ?? []).filter((row) => row.state !== "deleted" && row.state !== "errored").slice(offset, offset + limit);
13394
+ return rows.map((row) => ({
13395
+ id: row.id,
13396
+ // videoResources have no title/slug — the filename-derived id is the
13397
+ // human-readable handle.
13398
+ title: row.id,
13399
+ state: row.state ?? "processing",
13400
+ thumbnailUrl: row.muxPlaybackId ? `https://image.mux.com/${row.muxPlaybackId}/thumbnail.png?width=96&height=54&fit_mode=smartcrop` : void 0,
13401
+ duration: row.duration != null ? Number(row.duration) : null,
13402
+ createdAt: row.createdAt
13403
+ }));
13404
+ }
13405
+ __name(listVideoResourcesForPicker, "listVideoResourcesForPicker");
13406
+ async function listImageResources({ limit, offset = 0 }) {
13407
+ const capped = Math.min(Math.max(1, Math.floor(limit)), 200);
13408
+ const skip = Math.max(0, Math.floor(offset));
13409
+ const rows = await db.select({
13410
+ id: contentResource.id,
13411
+ url: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.url'))`,
13412
+ alt: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.alt'))`,
13413
+ name: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.name'))`,
13414
+ createdAt: contentResource.createdAt,
13415
+ // Cloudinary metadata — NULL on pre-metadata rows (backfillable).
13416
+ width: import_drizzle_orm46.sql`JSON_EXTRACT(${contentResource.fields}, '$.width')`,
13417
+ height: import_drizzle_orm46.sql`JSON_EXTRACT(${contentResource.fields}, '$.height')`,
13418
+ bytes: import_drizzle_orm46.sql`JSON_EXTRACT(${contentResource.fields}, '$.bytes')`,
13419
+ format: import_drizzle_orm46.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.format'))`
13420
+ }).from(contentResource).where((0, import_drizzle_orm46.eq)(contentResource.type, "imageResource")).orderBy((0, import_drizzle_orm46.desc)(contentResource.createdAt)).limit(capped).offset(skip);
13421
+ const parsed = external_exports.array(CmsImageResourceRowSchema).safeParse(rows);
13422
+ return parsed.success ? parsed.data : [];
13423
+ }
13424
+ __name(listImageResources, "listImageResources");
13425
+ async function getPostListMemberships(postId) {
13426
+ await assertCanUpdateContent();
13427
+ const links = await dbQuery.contentResourceResource.findMany({
13428
+ where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(contentResourceResource.resourceId, postId), (0, import_drizzle_orm46.isNull)(contentResourceResource.deletedAt)),
13429
+ with: {
13430
+ resourceOf: true
13431
+ }
13432
+ });
13433
+ return links.filter((link) => link.resourceOf?.type === "list" && !link.resourceOf.deletedAt).map((link) => {
13434
+ const fields = link.resourceOf.fields ?? {};
13435
+ return {
13436
+ listId: link.resourceOf.id,
13437
+ title: fields.title ?? fields.slug ?? link.resourceOf.id,
13438
+ slug: fields.slug ?? void 0,
13439
+ href: fields.slug ? getEditHref("list", fields.slug) : void 0,
13440
+ position: link.position
13441
+ };
13442
+ });
13443
+ }
13444
+ __name(getPostListMemberships, "getPostListMemberships");
13445
+ async function getResourceParents(resourceId) {
13446
+ await assertCanUpdateContent();
13447
+ const [containerLinks, productLinks] = await Promise.all([
13448
+ dbQuery.contentResourceResource.findMany({
13449
+ where: (0, import_drizzle_orm46.eq)(contentResourceResource.resourceId, resourceId),
13450
+ with: {
13451
+ resourceOf: {
13452
+ with: {
13453
+ // Sibling JOIN rows only (no nested resource objects) —
13454
+ // cheap, and enough to compute this resource's ordinal.
13455
+ resources: {
13456
+ orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
13457
+ }
13458
+ }
13459
+ }
13460
+ }
13461
+ }),
13462
+ dbQuery.contentResourceProduct.findMany({
13463
+ where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(contentResourceProduct.resourceId, resourceId), (0, import_drizzle_orm46.isNull)(contentResourceProduct.deletedAt)),
13464
+ with: {
13465
+ product: true
13466
+ }
13467
+ })
13468
+ ]);
13469
+ const parents = [];
13470
+ for (const link of containerLinks) {
13471
+ const parent = link.resourceOf;
13472
+ if (!parent || parent.deletedAt)
13473
+ continue;
13474
+ if (parent.type === "videoResource")
13475
+ continue;
13476
+ const slug = parent.fields?.slug ?? "";
13477
+ const siblings = parent.resources ?? [];
13478
+ const index48 = siblings.findIndex((sibling) => sibling.resourceId === resourceId);
13479
+ parents.push({
13480
+ id: parent.id,
13481
+ type: parent.type,
13482
+ title: parent.fields?.title ?? (slug || parent.id),
13483
+ href: getEditHref(parent.type, slug || parent.id),
13484
+ ...index48 !== -1 && {
13485
+ detail: `#${index48 + 1} of ${siblings.length}`
13486
+ }
13487
+ });
13488
+ }
13489
+ for (const link of productLinks) {
13490
+ const product = link.product;
13491
+ if (!product)
13492
+ continue;
13493
+ const slug = product.fields?.slug ?? "";
13494
+ parents.push({
13495
+ id: product.id,
13496
+ type: "product",
13497
+ title: product.name,
13498
+ // Products aren't in the resource-paths registries; every app's
13499
+ // product editor lives at /products/[slug]/edit.
13500
+ href: `/products/${slug || product.id}/edit`
13501
+ });
13502
+ }
13503
+ return parents;
13504
+ }
13505
+ __name(getResourceParents, "getResourceParents");
13506
+ return {
13507
+ listResourcesForPicker,
13508
+ listVideoResourcesForPicker,
13509
+ listImageResources,
13510
+ getPostListMemberships,
13511
+ getResourceParents
13512
+ };
13513
+ }
13514
+ __name(createCmsResourceActions, "createCmsResourceActions");
13515
+
13285
13516
  // src/lib/mysql/index.ts
13286
13517
  var guid = (0, import_nanoid.customAlphabet)("1234567890abcdefghijklmnopqrstuvwxyz", 5);
13287
13518
  var normalizeExpirationDate = /* @__PURE__ */ __name((date) => {
@@ -13457,7 +13688,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13457
13688
  const redeemingForCurrentUser = currentUser?.id === user.id;
13458
13689
  if (bulkCouponRedemption) {
13459
13690
  const existingValidRedemption = await client.query.purchases.findFirst({
13460
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(purchaseTable.redeemedBulkCouponId, coupon2.id), (0, import_drizzle_orm46.eq)(purchaseTable.userId, user.id), (0, import_drizzle_orm46.eq)(purchaseTable.status, "Valid"))
13691
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.redeemedBulkCouponId, coupon2.id), (0, import_drizzle_orm47.eq)(purchaseTable.userId, user.id), (0, import_drizzle_orm47.eq)(purchaseTable.status, "Valid"))
13461
13692
  });
13462
13693
  if (existingValidRedemption) {
13463
13694
  logger2.info("adapter.coupon.redeem.duplicate_team_seat", {
@@ -13539,12 +13770,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13539
13770
  },
13540
13771
  incrementCouponUsedCount: async (couponId) => {
13541
13772
  await client.update(coupon).set({
13542
- usedCount: import_drizzle_orm46.sql`${coupon.usedCount} + 1`
13543
- }).where((0, import_drizzle_orm46.eq)(coupon.id, couponId));
13773
+ usedCount: import_drizzle_orm47.sql`${coupon.usedCount} + 1`
13774
+ }).where((0, import_drizzle_orm47.eq)(coupon.id, couponId));
13544
13775
  },
13545
13776
  getExistingNonBulkValidPurchasesOfProduct: async ({ userId, productId }) => {
13546
13777
  const existingPurchases = await client.query.purchases.findMany({
13547
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(purchaseTable.userId, userId), productId ? (0, import_drizzle_orm46.eq)(purchaseTable.productId, productId) : void 0, (0, import_drizzle_orm46.eq)(purchaseTable.status, "Valid"), (0, import_drizzle_orm46.isNull)(purchaseTable.bulkCouponId))
13778
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), productId ? (0, import_drizzle_orm47.eq)(purchaseTable.productId, productId) : void 0, (0, import_drizzle_orm47.eq)(purchaseTable.status, "Valid"), (0, import_drizzle_orm47.isNull)(purchaseTable.bulkCouponId))
13548
13779
  });
13549
13780
  return external_exports.array(purchaseSchema).parse(existingPurchases);
13550
13781
  },
@@ -13557,7 +13788,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13557
13788
  status: 1
13558
13789
  });
13559
13790
  return merchantCustomerSchema.parse(await client.query.merchantCustomer.findFirst({
13560
- where: (0, import_drizzle_orm46.eq)(merchantCustomer.identifier, options.identifier)
13791
+ where: (0, import_drizzle_orm47.eq)(merchantCustomer.identifier, options.identifier)
13561
13792
  }));
13562
13793
  },
13563
13794
  createMerchantCoupon: async (options) => {
@@ -13570,17 +13801,17 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13570
13801
  status: 1
13571
13802
  });
13572
13803
  return merchantCouponSchema.parse(await client.query.merchantCoupon.findFirst({
13573
- where: (0, import_drizzle_orm46.eq)(merchantCoupon.identifier, options.identifier)
13804
+ where: (0, import_drizzle_orm47.eq)(merchantCoupon.identifier, options.identifier)
13574
13805
  }));
13575
13806
  },
13576
13807
  getMerchantAccount: async (options) => {
13577
13808
  return merchantAccountSchema.parse(await client.query.merchantAccount.findFirst({
13578
- where: (0, import_drizzle_orm46.eq)(merchantAccount.label, options.provider)
13809
+ where: (0, import_drizzle_orm47.eq)(merchantAccount.label, options.provider)
13579
13810
  }));
13580
13811
  },
13581
13812
  getMerchantPriceForProductId: async (productId) => {
13582
13813
  const merchantPriceData = await client.query.merchantPrice.findFirst({
13583
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(merchantPrice.merchantProductId, productId), (0, import_drizzle_orm46.eq)(merchantPrice.status, 1))
13814
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantPrice.merchantProductId, productId), (0, import_drizzle_orm47.eq)(merchantPrice.status, 1))
13584
13815
  });
13585
13816
  const parsedMerchantPrice = merchantPriceSchema.safeParse(merchantPriceData);
13586
13817
  if (!parsedMerchantPrice.success) {
@@ -13594,7 +13825,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13594
13825
  },
13595
13826
  getMerchantProductForProductId: async (productId) => {
13596
13827
  const merchantProductData = await client.query.merchantProduct.findFirst({
13597
- where: (0, import_drizzle_orm46.eq)(merchantProduct.productId, productId)
13828
+ where: (0, import_drizzle_orm47.eq)(merchantProduct.productId, productId)
13598
13829
  });
13599
13830
  if (!merchantProductData)
13600
13831
  return null;
@@ -13602,7 +13833,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13602
13833
  },
13603
13834
  getMerchantCustomerForUserId: async (userId) => {
13604
13835
  const merchantCustomerData = await client.query.merchantCustomer.findFirst({
13605
- where: (0, import_drizzle_orm46.eq)(merchantCustomer.userId, userId)
13836
+ where: (0, import_drizzle_orm47.eq)(merchantCustomer.userId, userId)
13606
13837
  });
13607
13838
  if (!merchantCustomerData)
13608
13839
  return null;
@@ -13611,14 +13842,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13611
13842
  getUpgradableProducts: async (options) => {
13612
13843
  const { upgradableFromId, upgradableToId } = options;
13613
13844
  return external_exports.array(upgradableProductSchema).parse(await client.query.upgradableProducts.findMany({
13614
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(upgradableProducts.upgradableFromId, upgradableFromId), (0, import_drizzle_orm46.eq)(upgradableProducts.upgradableToId, upgradableToId))
13845
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(upgradableProducts.upgradableFromId, upgradableFromId), (0, import_drizzle_orm47.eq)(upgradableProducts.upgradableToId, upgradableToId))
13615
13846
  }));
13616
13847
  },
13617
13848
  async availableUpgradesForProduct(purchases, productId) {
13618
13849
  const previousPurchaseProductIds = purchases.map(({ productId: productId2 }) => productId2);
13619
13850
  if (previousPurchaseProductIds.length > 0) {
13620
13851
  return client.query.upgradableProducts.findMany({
13621
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(upgradableProducts.upgradableToId, productId), (0, import_drizzle_orm46.inArray)(upgradableProducts.upgradableFromId, previousPurchaseProductIds))
13852
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(upgradableProducts.upgradableToId, productId), (0, import_drizzle_orm47.inArray)(upgradableProducts.upgradableFromId, previousPurchaseProductIds))
13622
13853
  });
13623
13854
  }
13624
13855
  return [];
@@ -13631,7 +13862,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13631
13862
  throw new Error("No lessonId provided");
13632
13863
  }
13633
13864
  let lessonProgress = await client.query.resourceProgress.findFirst({
13634
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm46.eq)(resourceProgress.resourceId, options.lessonId))
13865
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId))
13635
13866
  });
13636
13867
  const now = /* @__PURE__ */ new Date();
13637
13868
  if (lessonProgress) {
@@ -13639,7 +13870,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13639
13870
  await client.update(resourceProgress).set({
13640
13871
  completedAt: now,
13641
13872
  updatedAt: now
13642
- }).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm46.eq)(resourceProgress.resourceId, options.lessonId)));
13873
+ }).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId)));
13643
13874
  }
13644
13875
  } else {
13645
13876
  await client.insert(resourceProgress).values({
@@ -13650,7 +13881,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13650
13881
  });
13651
13882
  }
13652
13883
  lessonProgress = await client.query.resourceProgress.findFirst({
13653
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm46.eq)(resourceProgress.resourceId, options.lessonId))
13884
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId))
13654
13885
  });
13655
13886
  const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
13656
13887
  if (!parsedLessonProgress.success) {
@@ -13667,7 +13898,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13667
13898
  if (!options.couponId && !options.code)
13668
13899
  return null;
13669
13900
  const couponForIdOrCode = await client.query.coupon.findFirst({
13670
- where: (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.or)(options.code ? (0, import_drizzle_orm46.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm46.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm46.gte)(coupon.expires, /* @__PURE__ */ new Date())), (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.or)(options.code ? (0, import_drizzle_orm46.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm46.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm46.isNull)(coupon.expires))),
13901
+ where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.or)(options.code ? (0, import_drizzle_orm47.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm47.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm47.gte)(coupon.expires, /* @__PURE__ */ new Date())), (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.or)(options.code ? (0, import_drizzle_orm47.eq)(coupon.code, options.code) : void 0, options.couponId ? (0, import_drizzle_orm47.eq)(coupon.id, options.couponId) : void 0), (0, import_drizzle_orm47.isNull)(coupon.expires))),
13671
13902
  with: {
13672
13903
  merchantCoupon: true
13673
13904
  }
@@ -13698,7 +13929,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13698
13929
  } : {}
13699
13930
  });
13700
13931
  return MerchantSessionSchema.parse(await client.query.merchantSession.findFirst({
13701
- where: (0, import_drizzle_orm46.eq)(merchantSession.id, id)
13932
+ where: (0, import_drizzle_orm47.eq)(merchantSession.id, id)
13702
13933
  }));
13703
13934
  },
13704
13935
  async createMerchantChargeAndPurchase(options) {
@@ -13706,10 +13937,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13706
13937
  try {
13707
13938
  const { userId, stripeChargeId, stripeCouponId, merchantAccountId, merchantProductId, merchantCustomerId, productId, stripeChargeAmount, quantity = 1, checkoutSessionId, appliedPPPStripeCouponId, upgradedFromPurchaseId, country, usedCouponId, organizationId, attributionSnapshot } = options;
13708
13939
  const existingMerchantCharge = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
13709
- where: (0, import_drizzle_orm46.eq)(merchantCharge.identifier, stripeChargeId)
13940
+ where: (0, import_drizzle_orm47.eq)(merchantCharge.identifier, stripeChargeId)
13710
13941
  }) || null);
13711
13942
  const existingPurchaseForCharge = existingMerchantCharge ? await client.query.purchases.findFirst({
13712
- where: (0, import_drizzle_orm46.eq)(purchaseTable.merchantChargeId, existingMerchantCharge.id),
13943
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.merchantChargeId, existingMerchantCharge.id),
13713
13944
  with: {
13714
13945
  user: true,
13715
13946
  product: true,
@@ -13730,12 +13961,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13730
13961
  merchantCustomerId
13731
13962
  });
13732
13963
  const existingPurchase = purchaseSchema.nullable().parse(await client.query.purchases.findFirst({
13733
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm46.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm46.inArray)(purchaseTable.status, [
13964
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, [
13734
13965
  "Valid",
13735
13966
  "Restricted"
13736
13967
  ]))
13737
13968
  }) || null);
13738
- const existingBulkCoupon = couponSchema.nullable().parse(await client.select().from(coupon).leftJoin(purchaseTable, (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(coupon.id, purchaseTable.bulkCouponId), (0, import_drizzle_orm46.eq)(purchaseTable.userId, userId))).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(coupon.restrictedToProductId, productId), (0, import_drizzle_orm46.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm46.eq)(purchaseTable.status, "Valid"))).then((res) => {
13969
+ const existingBulkCoupon = couponSchema.nullable().parse(await client.select().from(coupon).leftJoin(purchaseTable, (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(coupon.id, purchaseTable.bulkCouponId), (0, import_drizzle_orm47.eq)(purchaseTable.userId, userId))).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(coupon.restrictedToProductId, productId), (0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.eq)(purchaseTable.status, "Valid"))).then((res) => {
13739
13970
  return res[0]?.Coupon ?? null;
13740
13971
  }));
13741
13972
  const isBulkPurchase = quantity > 1 || Boolean(existingBulkCoupon) || Boolean(options.bulk);
@@ -13767,18 +13998,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13767
13998
  ...organizationId ? {
13768
13999
  organizationId
13769
14000
  } : {}
13770
- }).where((0, import_drizzle_orm46.eq)(coupon.id, bulkCouponId));
14001
+ }).where((0, import_drizzle_orm47.eq)(coupon.id, bulkCouponId));
13771
14002
  } else {
13772
14003
  let merchantCouponToUse = stripeCouponId ? merchantCouponSchema.nullable().parse(await client.query.merchantCoupon.findFirst({
13773
- where: (0, import_drizzle_orm46.eq)(merchantCoupon.identifier, stripeCouponId)
14004
+ where: (0, import_drizzle_orm47.eq)(merchantCoupon.identifier, stripeCouponId)
13774
14005
  }) || null) : null;
13775
14006
  if (!merchantCouponToUse && usedCouponId) {
13776
14007
  const usedCoupon = couponSchema.nullable().parse(await client.query.coupon.findFirst({
13777
- where: (0, import_drizzle_orm46.eq)(coupon.id, usedCouponId)
14008
+ where: (0, import_drizzle_orm47.eq)(coupon.id, usedCouponId)
13778
14009
  }) || null);
13779
14010
  if (usedCoupon?.merchantCouponId) {
13780
14011
  merchantCouponToUse = merchantCouponSchema.nullable().parse(await client.query.merchantCoupon.findFirst({
13781
- where: (0, import_drizzle_orm46.eq)(merchantCoupon.id, usedCoupon.merchantCouponId)
14012
+ where: (0, import_drizzle_orm47.eq)(merchantCoupon.id, usedCoupon.merchantCouponId)
13782
14013
  }) || null);
13783
14014
  }
13784
14015
  }
@@ -13806,10 +14037,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13806
14037
  merchantAccountId
13807
14038
  });
13808
14039
  const merchantCouponUsed = stripeCouponId ? await client.query.merchantCoupon.findFirst({
13809
- where: (0, import_drizzle_orm46.eq)(merchantCoupon.identifier, stripeCouponId)
14040
+ where: (0, import_drizzle_orm47.eq)(merchantCoupon.identifier, stripeCouponId)
13810
14041
  }) : null;
13811
14042
  const pppMerchantCoupon = appliedPPPStripeCouponId ? await client.query.merchantCoupon.findFirst({
13812
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(merchantCoupon.identifier, appliedPPPStripeCouponId), (0, import_drizzle_orm46.eq)(merchantCoupon.type, "ppp"))
14043
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.identifier, appliedPPPStripeCouponId), (0, import_drizzle_orm47.eq)(merchantCoupon.type, "ppp"))
13813
14044
  }) : null;
13814
14045
  const newPurchaseStatus = merchantCouponUsed?.type === "ppp" || pppMerchantCoupon ? "Restricted" : "Valid";
13815
14046
  await client.insert(purchaseTable).values({
@@ -13859,7 +14090,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13859
14090
  }
13860
14091
  });
13861
14092
  const parsedPurchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
13862
- where: (0, import_drizzle_orm46.eq)(purchaseTable.id, purchaseId)
14093
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.id, purchaseId)
13863
14094
  }));
13864
14095
  if (!parsedPurchase.success) {
13865
14096
  logger2.error(parsedPurchase.error, {
@@ -13874,7 +14105,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13874
14105
  },
13875
14106
  async findOrCreateMerchantCustomer(options) {
13876
14107
  const merchantCustomer2 = merchantCustomerSchema.nullable().optional().parse(await client.query.merchantCustomer.findFirst({
13877
- where: (merchantCustomer3, { eq: eq2 }) => eq2(merchantCustomer3.identifier, options.identifier)
14108
+ where: (merchantCustomer3, { eq: eq3 }) => eq3(merchantCustomer3.identifier, options.identifier)
13878
14109
  }));
13879
14110
  if (merchantCustomer2) {
13880
14111
  return merchantCustomer2;
@@ -13894,21 +14125,21 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13894
14125
  payload: options.payload
13895
14126
  });
13896
14127
  const createdEvent = await client.query.merchantEvents.findFirst({
13897
- where: (0, import_drizzle_orm46.eq)(merchantEvents.id, eventId)
14128
+ where: (0, import_drizzle_orm47.eq)(merchantEvents.id, eventId)
13898
14129
  });
13899
14130
  return merchantEventsSchema.parse(createdEvent);
13900
14131
  },
13901
14132
  async getMerchantEventByIdentifier(identifier) {
13902
14133
  const event = await client.query.merchantEvents.findFirst({
13903
- where: (0, import_drizzle_orm46.eq)(merchantEvents.identifier, identifier)
14134
+ where: (0, import_drizzle_orm47.eq)(merchantEvents.identifier, identifier)
13904
14135
  });
13905
14136
  return event ? merchantEventsSchema.parse(event) : null;
13906
14137
  },
13907
14138
  async getMerchantEventsByAccount(merchantAccountId) {
13908
14139
  const events = await client.query.merchantEvents.findMany({
13909
- where: (0, import_drizzle_orm46.eq)(merchantEvents.merchantAccountId, merchantAccountId),
14140
+ where: (0, import_drizzle_orm47.eq)(merchantEvents.merchantAccountId, merchantAccountId),
13910
14141
  orderBy: [
13911
- (0, import_drizzle_orm46.desc)(merchantEvents.createdAt)
14142
+ (0, import_drizzle_orm47.desc)(merchantEvents.createdAt)
13912
14143
  ]
13913
14144
  });
13914
14145
  return events.map((event) => merchantEventsSchema.parse(event));
@@ -13941,7 +14172,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13941
14172
  },
13942
14173
  async getCoupon(couponIdOrCode) {
13943
14174
  const loadedCoupon = await client.query.coupon.findFirst({
13944
- where: (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(coupon.id, couponIdOrCode), (0, import_drizzle_orm46.eq)(coupon.code, couponIdOrCode))
14175
+ where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(coupon.id, couponIdOrCode), (0, import_drizzle_orm47.eq)(coupon.code, couponIdOrCode))
13945
14176
  }) || null;
13946
14177
  logger2.debug("getCoupon", {
13947
14178
  couponIdOrCode,
@@ -13953,7 +14184,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13953
14184
  return external_exports.array(purchaseSchema.extend({
13954
14185
  user: userSchema
13955
14186
  })).parse(await client.query.purchases.findMany({
13956
- where: (0, import_drizzle_orm46.eq)(purchaseTable.bulkCouponId, bulkCouponId),
14187
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.bulkCouponId, bulkCouponId),
13957
14188
  with: {
13958
14189
  user: true
13959
14190
  }
@@ -13967,7 +14198,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13967
14198
  let bulkCouponPurchases = [];
13968
14199
  try {
13969
14200
  couponData = await client.query.coupon.findFirst({
13970
- where: (0, import_drizzle_orm46.eq)(coupon.id, couponId),
14201
+ where: (0, import_drizzle_orm47.eq)(coupon.id, couponId),
13971
14202
  with: {
13972
14203
  bulkPurchases: true,
13973
14204
  redeemedBulkCouponPurchases: true
@@ -13982,7 +14213,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
13982
14213
  }
13983
14214
  try {
13984
14215
  bulkCouponPurchases = await client.query.purchases.findMany({
13985
- where: (0, import_drizzle_orm46.eq)(purchaseTable.redeemedBulkCouponId, couponId),
14216
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.redeemedBulkCouponId, couponId),
13986
14217
  with: {
13987
14218
  user: true
13988
14219
  }
@@ -14024,8 +14255,8 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14024
14255
  },
14025
14256
  async getDefaultCoupon(productIds) {
14026
14257
  const activeSaleCoupon = await client.query.coupon.findFirst({
14027
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(coupon.status, 1), (0, import_drizzle_orm46.eq)(coupon.default, true), (0, import_drizzle_orm46.gte)(coupon.expires, /* @__PURE__ */ new Date()), (0, import_drizzle_orm46.or)(productIds ? (0, import_drizzle_orm46.inArray)(coupon.restrictedToProductId, productIds) : void 0, (0, import_drizzle_orm46.isNull)(coupon.restrictedToProductId))),
14028
- orderBy: (0, import_drizzle_orm46.desc)(coupon.percentageDiscount),
14258
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(coupon.status, 1), (0, import_drizzle_orm47.eq)(coupon.default, true), (0, import_drizzle_orm47.gte)(coupon.expires, /* @__PURE__ */ new Date()), (0, import_drizzle_orm47.or)(productIds ? (0, import_drizzle_orm47.inArray)(coupon.restrictedToProductId, productIds) : void 0, (0, import_drizzle_orm47.isNull)(coupon.restrictedToProductId))),
14259
+ orderBy: (0, import_drizzle_orm47.desc)(coupon.percentageDiscount),
14029
14260
  with: {
14030
14261
  merchantCoupon: true,
14031
14262
  product: true
@@ -14049,7 +14280,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14049
14280
  },
14050
14281
  async getLessonProgressForUser(userId) {
14051
14282
  const userProgress = await client.query.resourceProgress.findMany({
14052
- where: (0, import_drizzle_orm46.eq)(resourceProgress.userId, userId)
14283
+ where: (0, import_drizzle_orm47.eq)(resourceProgress.userId, userId)
14053
14284
  });
14054
14285
  const parsed = external_exports.array(resourceProgressSchema).safeParse(userProgress);
14055
14286
  if (!parsed.success) {
@@ -14063,7 +14294,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14063
14294
  },
14064
14295
  async getModuleProgressForUser(userIdOrEmail, moduleIdOrSlug) {
14065
14296
  const user = await client.query.users.findFirst({
14066
- where: (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(users.id, userIdOrEmail), (0, import_drizzle_orm46.eq)(users.email, userIdOrEmail)),
14297
+ where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(users.id, userIdOrEmail), (0, import_drizzle_orm47.eq)(users.email, userIdOrEmail)),
14067
14298
  columns: {
14068
14299
  id: true
14069
14300
  }
@@ -14081,7 +14312,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14081
14312
  resource_slug: external_exports.string().nullable(),
14082
14313
  completed_at: external_exports.string().nullable().transform((val) => val ? new Date(val) : null)
14083
14314
  });
14084
- const results = await client.execute(import_drizzle_orm46.sql`
14315
+ const results = await client.execute(import_drizzle_orm47.sql`
14085
14316
  WITH RECURSIVE workshop AS (
14086
14317
  SELECT id, fields->>'$.slug' AS slug
14087
14318
  FROM ${contentResource}
@@ -14188,7 +14419,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14188
14419
  },
14189
14420
  async getMerchantCharge(merchantChargeId) {
14190
14421
  const mCharge = await client.query.merchantCharge.findFirst({
14191
- where: (0, import_drizzle_orm46.eq)(merchantCharge.id, merchantChargeId)
14422
+ where: (0, import_drizzle_orm47.eq)(merchantCharge.id, merchantChargeId)
14192
14423
  });
14193
14424
  const parsed = merchantChargeSchema.safeParse(mCharge);
14194
14425
  if (!parsed.success) {
@@ -14202,12 +14433,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14202
14433
  },
14203
14434
  async getMerchantCouponsForTypeAndPercent(params) {
14204
14435
  return external_exports.array(merchantCouponSchema).parse(await client.query.merchantCoupon.findMany({
14205
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm46.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
14436
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm47.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
14206
14437
  }));
14207
14438
  },
14208
14439
  async getMerchantCouponForTypeAndPercent(params) {
14209
14440
  const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
14210
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm46.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
14441
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm47.eq)(merchantCoupon.percentageDiscount, params.percentageDiscount.toString()))
14211
14442
  });
14212
14443
  const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
14213
14444
  if (parsed.success) {
@@ -14217,7 +14448,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14217
14448
  },
14218
14449
  async getMerchantCouponForTypeAndAmount(params) {
14219
14450
  const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
14220
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm46.eq)(merchantCoupon.amountDiscount, params.amountDiscount))
14451
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.type, params.type), (0, import_drizzle_orm47.eq)(merchantCoupon.amountDiscount, params.amountDiscount))
14221
14452
  });
14222
14453
  const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
14223
14454
  if (parsed.success) {
@@ -14227,7 +14458,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14227
14458
  },
14228
14459
  async getMerchantCoupon(merchantCouponId) {
14229
14460
  const foundMerchantCoupon = await client.query.merchantCoupon.findFirst({
14230
- where: (0, import_drizzle_orm46.eq)(merchantCoupon.id, merchantCouponId)
14461
+ where: (0, import_drizzle_orm47.eq)(merchantCoupon.id, merchantCouponId)
14231
14462
  });
14232
14463
  const parsed = merchantCouponSchema.nullable().safeParse(foundMerchantCoupon);
14233
14464
  if (parsed.success) {
@@ -14237,7 +14468,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14237
14468
  },
14238
14469
  async getMerchantProduct(stripeProductId) {
14239
14470
  return merchantProductSchema.nullable().parse(await client.query.merchantProduct.findFirst({
14240
- where: (0, import_drizzle_orm46.eq)(merchantProduct.identifier, stripeProductId)
14471
+ where: (0, import_drizzle_orm47.eq)(merchantProduct.identifier, stripeProductId)
14241
14472
  }));
14242
14473
  },
14243
14474
  getPrice(productId) {
@@ -14245,7 +14476,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14245
14476
  },
14246
14477
  async getPriceForProduct(productId) {
14247
14478
  return priceSchema.nullable().parse(await client.query.prices.findFirst({
14248
- where: (0, import_drizzle_orm46.eq)(prices.productId, productId)
14479
+ where: (0, import_drizzle_orm47.eq)(prices.productId, productId)
14249
14480
  }));
14250
14481
  },
14251
14482
  async archiveProduct(productId) {
@@ -14261,19 +14492,19 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14261
14492
  await client.update(products).set({
14262
14493
  status: 0,
14263
14494
  name: `${product.name} (Archived)`
14264
- }).where((0, import_drizzle_orm46.eq)(products.id, productId));
14495
+ }).where((0, import_drizzle_orm47.eq)(products.id, productId));
14265
14496
  await client.update(prices).set({
14266
14497
  status: 0,
14267
14498
  nickname: `${product.name} (Archived)`
14268
- }).where((0, import_drizzle_orm46.eq)(prices.productId, productId));
14499
+ }).where((0, import_drizzle_orm47.eq)(prices.productId, productId));
14269
14500
  await client.update(merchantProduct).set({
14270
14501
  status: 0
14271
- }).where((0, import_drizzle_orm46.eq)(merchantProduct.productId, productId));
14502
+ }).where((0, import_drizzle_orm47.eq)(merchantProduct.productId, productId));
14272
14503
  await client.update(merchantPrice).set({
14273
14504
  status: 0
14274
- }).where((0, import_drizzle_orm46.eq)(merchantPrice.priceId, product.price.id));
14505
+ }).where((0, import_drizzle_orm47.eq)(merchantPrice.priceId, product.price.id));
14275
14506
  const currentMerchantProduct = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
14276
- where: (0, import_drizzle_orm46.eq)(merchantProduct.productId, productId)
14507
+ where: (0, import_drizzle_orm47.eq)(merchantProduct.productId, productId)
14277
14508
  }));
14278
14509
  if (!currentMerchantProduct || !currentMerchantProduct.identifier) {
14279
14510
  throw new Error(`Merchant product not found for id (${productId})`);
@@ -14282,7 +14513,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14282
14513
  active: false
14283
14514
  });
14284
14515
  const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
14285
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(merchantPrice.priceId, product.price.id), (0, import_drizzle_orm46.eq)(merchantPrice.status, 1))
14516
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantPrice.priceId, product.price.id), (0, import_drizzle_orm47.eq)(merchantPrice.status, 1))
14286
14517
  }));
14287
14518
  if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
14288
14519
  throw new Error(`Merchant price not found for id (${productId})`);
@@ -14303,7 +14534,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14303
14534
  throw new Error(`Product has no price`);
14304
14535
  }
14305
14536
  const merchantProduct2 = merchantProductSchema.nullish().parse(await client.query.merchantProduct.findFirst({
14306
- where: (merchantProduct3, { eq: eq2 }) => eq2(merchantProduct3.productId, input.id)
14537
+ where: (merchantProduct3, { eq: eq3 }) => eq3(merchantProduct3.productId, input.id)
14307
14538
  }));
14308
14539
  if (!merchantProduct2 || !merchantProduct2.identifier) {
14309
14540
  throw new Error(`Merchant product not found`);
@@ -14311,7 +14542,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14311
14542
  const stripeProduct = await paymentProvider.getProduct(merchantProduct2.identifier);
14312
14543
  const priceChanged = currentProduct.price.unitAmount.toString() !== input.price?.unitAmount.toString();
14313
14544
  const currentMerchantPrice = merchantPriceSchema.nullish().parse(await client.query.merchantPrice.findFirst({
14314
- where: (merchantPrice2, { eq: eq2, and: and2 }) => and2(eq2(merchantPrice2.merchantProductId, merchantProduct2.id), eq2(merchantPrice2.status, 1))
14545
+ where: (merchantPrice2, { eq: eq3, and: and3 }) => and3(eq3(merchantPrice2.merchantProductId, merchantProduct2.id), eq3(merchantPrice2.status, 1))
14315
14546
  }));
14316
14547
  if (!currentMerchantPrice || !currentMerchantPrice.identifier) {
14317
14548
  throw new Error(`Merchant price not found`);
@@ -14366,12 +14597,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14366
14597
  if (currentMerchantPrice) {
14367
14598
  await client.update(merchantPrice).set({
14368
14599
  status: 0
14369
- }).where((0, import_drizzle_orm46.eq)(merchantPrice.id, currentMerchantPrice.id));
14600
+ }).where((0, import_drizzle_orm47.eq)(merchantPrice.id, currentMerchantPrice.id));
14370
14601
  }
14371
14602
  await client.update(prices).set({
14372
14603
  unitAmount: Math.floor(Number(input.price?.unitAmount || 0)).toString(),
14373
14604
  nickname: input.name
14374
- }).where((0, import_drizzle_orm46.eq)(prices.id, currentProduct.price.id));
14605
+ }).where((0, import_drizzle_orm47.eq)(prices.id, currentProduct.price.id));
14375
14606
  if (currentStripePrice) {
14376
14607
  await paymentProvider.updatePrice(currentStripePrice.id, {
14377
14608
  active: false
@@ -14401,14 +14632,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14401
14632
  }
14402
14633
  },
14403
14634
  type: input.type
14404
- }).where((0, import_drizzle_orm46.eq)(products.id, currentProduct.id));
14635
+ }).where((0, import_drizzle_orm47.eq)(products.id, currentProduct.id));
14405
14636
  return adapter.getProduct(currentProduct.id);
14406
14637
  },
14407
14638
  async createProduct(input) {
14408
14639
  if (!paymentProvider)
14409
14640
  throw new Error("Payment provider not found");
14410
14641
  const merchantAccount2 = merchantAccountSchema.nullish().parse(await client.query.merchantAccount.findFirst({
14411
- where: (merchantAccount3, { eq: eq2 }) => eq2(merchantAccount3.label, "stripe")
14642
+ where: (merchantAccount3, { eq: eq3 }) => eq3(merchantAccount3.label, "stripe")
14412
14643
  }));
14413
14644
  if (!merchantAccount2) {
14414
14645
  throw new Error("Merchant account not found");
@@ -14495,7 +14726,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14495
14726
  }
14496
14727
  try {
14497
14728
  const productData = await client.query.products.findFirst({
14498
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(import_drizzle_orm46.sql`JSON_EXTRACT (${products.fields}, "$.slug")`, `${productSlugOrId}`), (0, import_drizzle_orm46.eq)(products.id, productSlugOrId))),
14729
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${products.fields}, "$.slug")`, `${productSlugOrId}`), (0, import_drizzle_orm47.eq)(products.id, productSlugOrId))),
14499
14730
  with: {
14500
14731
  price: true,
14501
14732
  ...withResources && {
@@ -14532,20 +14763,20 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14532
14763
  },
14533
14764
  async getProductResources(productId) {
14534
14765
  const contentResourceProductsForProduct = external_exports.array(ContentResourceProductSchema).nullable().parse(await client.query.contentResourceProduct.findMany({
14535
- where: (0, import_drizzle_orm46.eq)(contentResourceProduct.productId, productId)
14766
+ where: (0, import_drizzle_orm47.eq)(contentResourceProduct.productId, productId)
14536
14767
  }));
14537
14768
  if (!contentResourceProductsForProduct) {
14538
14769
  return null;
14539
14770
  } else {
14540
14771
  const contentResources = external_exports.array(ContentResourceSchema).parse(await client.query.contentResource.findMany({
14541
- where: (0, import_drizzle_orm46.inArray)(contentResource.id, contentResourceProductsForProduct.map((crp) => crp.resourceId))
14772
+ where: (0, import_drizzle_orm47.inArray)(contentResource.id, contentResourceProductsForProduct.map((crp) => crp.resourceId))
14542
14773
  }));
14543
14774
  return contentResources;
14544
14775
  }
14545
14776
  },
14546
14777
  async getPurchaseCountForProduct(productId) {
14547
14778
  return await client.query.purchases.findMany({
14548
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm46.inArray)(purchaseTable.status, [
14779
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.productId, productId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, [
14549
14780
  "Valid",
14550
14781
  "Restricted"
14551
14782
  ]))
@@ -14553,7 +14784,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14553
14784
  },
14554
14785
  async getPurchase(purchaseId) {
14555
14786
  const purchase = await client.query.purchases.findFirst({
14556
- where: (0, import_drizzle_orm46.eq)(purchaseTable.id, purchaseId)
14787
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.id, purchaseId)
14557
14788
  });
14558
14789
  return purchase ? purchaseSchema.parse(purchase) : null;
14559
14790
  },
@@ -14571,7 +14802,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14571
14802
  stripeChargeId
14572
14803
  });
14573
14804
  const chargeForPurchase = merchantChargeSchema.nullable().parse(await client.query.merchantCharge.findFirst({
14574
- where: (0, import_drizzle_orm46.eq)(merchantCharge.identifier, stripeChargeId)
14805
+ where: (0, import_drizzle_orm47.eq)(merchantCharge.identifier, stripeChargeId)
14575
14806
  }) || null);
14576
14807
  if (!chargeForPurchase) {
14577
14808
  logger2.debug("getPurchaseForStripeCharge: no matching charge", {
@@ -14581,7 +14812,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14581
14812
  return null;
14582
14813
  }
14583
14814
  const purchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
14584
- where: (0, import_drizzle_orm46.eq)(purchaseTable.merchantChargeId, chargeForPurchase.id),
14815
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.merchantChargeId, chargeForPurchase.id),
14585
14816
  with: {
14586
14817
  user: true,
14587
14818
  product: true,
@@ -14598,7 +14829,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14598
14829
  checkoutSessionId
14599
14830
  });
14600
14831
  const session = await client.query.merchantSession.findFirst({
14601
- where: (0, import_drizzle_orm46.eq)(merchantSession.identifier, checkoutSessionId)
14832
+ where: (0, import_drizzle_orm47.eq)(merchantSession.identifier, checkoutSessionId)
14602
14833
  });
14603
14834
  if (!session) {
14604
14835
  logger2.debug("getPurchaseByCheckoutSessionId: no matching session", {
@@ -14607,7 +14838,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14607
14838
  return null;
14608
14839
  }
14609
14840
  const purchase = purchaseSchema.safeParse(await client.query.purchases.findFirst({
14610
- where: (0, import_drizzle_orm46.eq)(purchaseTable.merchantSessionId, String(session.id)),
14841
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.merchantSessionId, String(session.id)),
14611
14842
  with: {
14612
14843
  user: true,
14613
14844
  product: true,
@@ -14621,7 +14852,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14621
14852
  },
14622
14853
  async getPurchaseUserTransferById(options) {
14623
14854
  const purchaseTransferData = await client.query.purchaseUserTransfer.findFirst({
14624
- where: (0, import_drizzle_orm46.eq)(purchaseUserTransfer.id, options.id),
14855
+ where: (0, import_drizzle_orm47.eq)(purchaseUserTransfer.id, options.id),
14625
14856
  with: {
14626
14857
  sourceUser: true,
14627
14858
  targetUser: true,
@@ -14637,7 +14868,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14637
14868
  },
14638
14869
  async getPurchaseWithUser(purchaseId) {
14639
14870
  const purchaseData = await client.query.purchases.findFirst({
14640
- where: (0, import_drizzle_orm46.eq)(purchaseTable.id, purchaseId),
14871
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.id, purchaseId),
14641
14872
  with: {
14642
14873
  user: true
14643
14874
  }
@@ -14664,13 +14895,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14664
14895
  "Restricted"
14665
14896
  ];
14666
14897
  const userPurchases = await client.query.purchases.findMany({
14667
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm46.inArray)(purchaseTable.status, visiblePurchaseStates)),
14898
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, visiblePurchaseStates)),
14668
14899
  with: {
14669
14900
  user: true,
14670
14901
  product: true,
14671
14902
  bulkCoupon: true
14672
14903
  },
14673
- orderBy: (0, import_drizzle_orm46.asc)(purchaseTable.createdAt)
14904
+ orderBy: (0, import_drizzle_orm47.asc)(purchaseTable.createdAt)
14674
14905
  });
14675
14906
  const parsedPurchases = external_exports.array(purchaseSchema).safeParse(userPurchases);
14676
14907
  if (!parsedPurchases.success) {
@@ -14689,22 +14920,22 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14689
14920
  return [];
14690
14921
  }
14691
14922
  const conditions = [
14692
- (0, import_drizzle_orm46.eq)(entitlementTable.userId, userId)
14923
+ (0, import_drizzle_orm47.eq)(entitlementTable.userId, userId)
14693
14924
  ];
14694
14925
  if (sourceType) {
14695
- conditions.push((0, import_drizzle_orm46.eq)(entitlementTable.sourceType, sourceType));
14926
+ conditions.push((0, import_drizzle_orm47.eq)(entitlementTable.sourceType, sourceType));
14696
14927
  }
14697
14928
  if (entitlementType) {
14698
- conditions.push((0, import_drizzle_orm46.eq)(entitlementTable.entitlementType, entitlementType));
14929
+ conditions.push((0, import_drizzle_orm47.eq)(entitlementTable.entitlementType, entitlementType));
14699
14930
  }
14700
- conditions.push((0, import_drizzle_orm46.isNull)(entitlementTable.deletedAt));
14701
- const expiresCondition = (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.isNull)(entitlementTable.expiresAt), (0, import_drizzle_orm46.gte)(entitlementTable.expiresAt, import_drizzle_orm46.sql`CURRENT_TIMESTAMP`));
14931
+ conditions.push((0, import_drizzle_orm47.isNull)(entitlementTable.deletedAt));
14932
+ const expiresCondition = (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.isNull)(entitlementTable.expiresAt), (0, import_drizzle_orm47.gte)(entitlementTable.expiresAt, import_drizzle_orm47.sql`CURRENT_TIMESTAMP`));
14702
14933
  if (expiresCondition) {
14703
14934
  conditions.push(expiresCondition);
14704
14935
  }
14705
14936
  const userEntitlements = await client.query.entitlements.findMany({
14706
- where: conditions.length > 0 ? (0, import_drizzle_orm46.and)(...conditions) : void 0,
14707
- orderBy: (0, import_drizzle_orm46.asc)(entitlementTable.createdAt)
14937
+ where: conditions.length > 0 ? (0, import_drizzle_orm47.and)(...conditions) : void 0,
14938
+ orderBy: (0, import_drizzle_orm47.asc)(entitlementTable.createdAt)
14708
14939
  });
14709
14940
  const parsedEntitlements = external_exports.array(entitlementSchema).safeParse(userEntitlements);
14710
14941
  if (!parsedEntitlements.success) {
@@ -14721,7 +14952,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14721
14952
  },
14722
14953
  async getEntitlementTypeByName(name) {
14723
14954
  const entitlementType = await client.query.entitlementTypes.findFirst({
14724
- where: (0, import_drizzle_orm46.eq)(entitlementTypes.name, name)
14955
+ where: (0, import_drizzle_orm47.eq)(entitlementTypes.name, name)
14725
14956
  });
14726
14957
  if (!entitlementType) {
14727
14958
  return null;
@@ -14738,18 +14969,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14738
14969
  "Restricted"
14739
14970
  ];
14740
14971
  const userPurchases = await client.query.purchases.findMany({
14741
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm46.inArray)(purchaseTable.status, visiblePurchaseStates)),
14972
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, visiblePurchaseStates)),
14742
14973
  with: {
14743
14974
  user: true,
14744
14975
  product: true,
14745
14976
  bulkCoupon: true
14746
14977
  },
14747
- orderBy: (0, import_drizzle_orm46.asc)(purchaseTable.createdAt)
14978
+ orderBy: (0, import_drizzle_orm47.asc)(purchaseTable.createdAt)
14748
14979
  });
14749
14980
  const parsedPurchases = external_exports.array(purchaseSchema).safeParse(userPurchases);
14750
14981
  const allPurchases = parsedPurchases.success ? parsedPurchases.data : [];
14751
14982
  const thePurchase = await client.query.purchases.findFirst({
14752
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(purchaseTable.id, purchaseId), (0, import_drizzle_orm46.eq)(purchaseTable.userId, userId)),
14983
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.id, purchaseId), (0, import_drizzle_orm47.eq)(purchaseTable.userId, userId)),
14753
14984
  with: {
14754
14985
  user: true,
14755
14986
  product: true,
@@ -14774,7 +15005,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14774
15005
  let availableUpgrades = [];
14775
15006
  if (purchaseCanUpgrade) {
14776
15007
  availableUpgrades = await client.query.upgradableProducts.findMany({
14777
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(upgradableProducts.upgradableFromId, parsedPurchase.data.product?.id), (0, import_drizzle_orm46.not)((0, import_drizzle_orm46.inArray)(upgradableProducts.upgradableToId, allPurchases.map((p) => p.product?.id)))),
15008
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(upgradableProducts.upgradableFromId, parsedPurchase.data.product?.id), (0, import_drizzle_orm47.not)((0, import_drizzle_orm47.inArray)(upgradableProducts.upgradableToId, allPurchases.map((p) => p.product?.id)))),
14778
15009
  with: {
14779
15010
  upgradableTo: true,
14780
15011
  upgradableFrom: true
@@ -14782,10 +15013,10 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14782
15013
  });
14783
15014
  }
14784
15015
  const existingPurchase = purchaseSchema.optional().nullable().parse(await client.query.purchases.findFirst({
14785
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm46.eq)(purchaseTable.productId, parsedPurchase.data.productId), (0, import_drizzle_orm46.inArray)(purchaseTable.status, [
15016
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.eq)(purchaseTable.productId, parsedPurchase.data.productId), (0, import_drizzle_orm47.inArray)(purchaseTable.status, [
14786
15017
  "Valid",
14787
15018
  "Restricted"
14788
- ]), (0, import_drizzle_orm46.isNull)(purchaseTable.bulkCouponId), (0, import_drizzle_orm46.not)((0, import_drizzle_orm46.eq)(purchaseTable.id, parsedPurchase.data.id))),
15019
+ ]), (0, import_drizzle_orm47.isNull)(purchaseTable.bulkCouponId), (0, import_drizzle_orm47.not)((0, import_drizzle_orm47.eq)(purchaseTable.id, parsedPurchase.data.id))),
14789
15020
  with: {
14790
15021
  user: true,
14791
15022
  product: true,
@@ -14800,7 +15031,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14800
15031
  },
14801
15032
  async getUserWithPurchasersByEmail(email) {
14802
15033
  const user = await client.query.users.findFirst({
14803
- where: (0, import_drizzle_orm46.eq)(users.email, email.trim().toLowerCase()),
15034
+ where: (0, import_drizzle_orm47.eq)(users.email, email.trim().toLowerCase()),
14804
15035
  with: {
14805
15036
  // merchantCustomer: true,
14806
15037
  roles: {
@@ -14827,7 +15058,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14827
15058
  },
14828
15059
  async getUserById(userId) {
14829
15060
  const user = await client.query.users.findFirst({
14830
- where: (0, import_drizzle_orm46.eq)(users.id, userId),
15061
+ where: (0, import_drizzle_orm47.eq)(users.id, userId),
14831
15062
  with: {
14832
15063
  roles: {
14833
15064
  with: {
@@ -14849,13 +15080,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14849
15080
  if (userId === void 0)
14850
15081
  return [];
14851
15082
  const canUpgradeProducts = await client.query.upgradableProducts.findMany({
14852
- where: (0, import_drizzle_orm46.eq)(upgradableProducts.upgradableToId, bundleId)
15083
+ where: (0, import_drizzle_orm47.eq)(upgradableProducts.upgradableToId, bundleId)
14853
15084
  });
14854
15085
  const upgradableFrom = external_exports.array(external_exports.string()).parse(canUpgradeProducts.map((product) => {
14855
15086
  return product.upgradableFromId;
14856
15087
  }));
14857
15088
  const purchases = await client.query.purchases.findMany({
14858
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm46.inArray)(purchaseTable.productId, upgradableFrom))
15089
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(purchaseTable.userId, userId), (0, import_drizzle_orm47.inArray)(purchaseTable.productId, upgradableFrom))
14859
15090
  });
14860
15091
  const productsPurchased = external_exports.array(external_exports.string()).parse(purchases.map((purchase) => {
14861
15092
  return purchase.productId;
@@ -14863,7 +15094,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14863
15094
  if (productsPurchased.length === 0)
14864
15095
  return [];
14865
15096
  const foundPrices = await client.query.prices.findMany({
14866
- where: (0, import_drizzle_orm46.inArray)(prices.productId, productsPurchased)
15097
+ where: (0, import_drizzle_orm47.inArray)(prices.productId, productsPurchased)
14867
15098
  });
14868
15099
  return external_exports.array(priceSchema).parse(foundPrices);
14869
15100
  },
@@ -14872,14 +15103,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14872
15103
  throw new Error("No lessonId provided");
14873
15104
  }
14874
15105
  let lessonProgress = await client.query.resourceProgress.findFirst({
14875
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm46.eq)(resourceProgress.resourceId, options.lessonId))
15106
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId))
14876
15107
  });
14877
15108
  const now = /* @__PURE__ */ new Date();
14878
15109
  if (lessonProgress) {
14879
15110
  await client.update(resourceProgress).set({
14880
15111
  completedAt: lessonProgress.completedAt ? null : now,
14881
15112
  updatedAt: now
14882
- }).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm46.eq)(resourceProgress.resourceId, options.lessonId)));
15113
+ }).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId)));
14883
15114
  } else {
14884
15115
  await client.insert(resourceProgress).values({
14885
15116
  userId: options.userId,
@@ -14889,7 +15120,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14889
15120
  });
14890
15121
  }
14891
15122
  lessonProgress = await client.query.resourceProgress.findFirst({
14892
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm46.eq)(resourceProgress.resourceId, options.lessonId))
15123
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(resourceProgress.userId, options.userId), (0, import_drizzle_orm47.eq)(resourceProgress.resourceId, options.lessonId))
14893
15124
  });
14894
15125
  const parsedLessonProgress = resourceProgressSchema.safeParse(lessonProgress);
14895
15126
  if (!parsedLessonProgress.success) {
@@ -14915,7 +15146,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14915
15146
  throw new Error("No purchase found");
14916
15147
  await trx.update(purchaseTable).set({
14917
15148
  userId: targetUserId
14918
- }).where((0, import_drizzle_orm46.eq)(purchaseTable.id, purchase.id));
15149
+ }).where((0, import_drizzle_orm47.eq)(purchaseTable.id, purchase.id));
14919
15150
  await trx.insert(purchaseUserTransfer).values({
14920
15151
  id: transferId,
14921
15152
  purchaseId: purchase.id,
@@ -14930,21 +15161,21 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14930
15161
  if (paymentProvider && purchase.merchantChargeId) {
14931
15162
  await trx.update(merchantCharge).set({
14932
15163
  userId: targetUserId
14933
- }).where((0, import_drizzle_orm46.eq)(merchantCharge.id, purchase.merchantChargeId));
15164
+ }).where((0, import_drizzle_orm47.eq)(merchantCharge.id, purchase.merchantChargeId));
14934
15165
  const updatedMerchantCharge = await adapter.getMerchantCharge(purchase.merchantChargeId);
14935
15166
  if (!updatedMerchantCharge)
14936
15167
  throw new Error("No merchant charge found");
14937
15168
  await trx.update(merchantCustomer).set({
14938
15169
  userId: targetUserId
14939
- }).where((0, import_drizzle_orm46.eq)(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId));
15170
+ }).where((0, import_drizzle_orm47.eq)(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId));
14940
15171
  const updatedMerchantCustomer = merchantCustomerSchema.parse(await client.query.merchantCustomer.findFirst({
14941
- where: (0, import_drizzle_orm46.eq)(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId)
15172
+ where: (0, import_drizzle_orm47.eq)(merchantCustomer.id, updatedMerchantCharge.merchantCustomerId)
14942
15173
  }));
14943
15174
  const targetUser = userSchema.parse(await client.query.users.findFirst({
14944
- where: (0, import_drizzle_orm46.eq)(users.id, targetUserId)
15175
+ where: (0, import_drizzle_orm47.eq)(users.id, targetUserId)
14945
15176
  }));
14946
15177
  const sourceUser = userSchema.parse(await client.query.users.findFirst({
14947
- where: (0, import_drizzle_orm46.eq)(users.id, sourceUserId)
15178
+ where: (0, import_drizzle_orm47.eq)(users.id, sourceUserId)
14948
15179
  }));
14949
15180
  await paymentProvider.updateCustomer(updatedMerchantCustomer.identifier, {
14950
15181
  email: targetUser.email,
@@ -14971,7 +15202,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14971
15202
  status
14972
15203
  });
14973
15204
  const merchantChargeForPurchase = await client.query.merchantCharge.findFirst({
14974
- where: (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(merchantCharge.identifier, chargeId), (0, import_drizzle_orm46.eq)(merchantCharge.id, chargeId))
15205
+ where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(merchantCharge.identifier, chargeId), (0, import_drizzle_orm47.eq)(merchantCharge.id, chargeId))
14975
15206
  });
14976
15207
  logger2.debug("adapter.purchase.status_update.charge_resolved", {
14977
15208
  chargeId,
@@ -14982,15 +15213,15 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
14982
15213
  if (!parsedMerchantChargeForPurchase)
14983
15214
  throw new Error(`no-charge-found-for-purchase ${chargeId}`);
14984
15215
  const purchase = await client.query.purchases.findFirst({
14985
- where: (0, import_drizzle_orm46.eq)(purchaseTable.merchantChargeId, parsedMerchantChargeForPurchase.id)
15216
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.merchantChargeId, parsedMerchantChargeForPurchase.id)
14986
15217
  });
14987
15218
  const parsedPurchase = purchaseSchema.nullable().parse(purchase);
14988
15219
  if (parsedPurchase) {
14989
15220
  await client.update(purchaseTable).set({
14990
15221
  status
14991
- }).where((0, import_drizzle_orm46.eq)(purchaseTable.id, parsedPurchase.id));
15222
+ }).where((0, import_drizzle_orm47.eq)(purchaseTable.id, parsedPurchase.id));
14992
15223
  const newPurchase = await client.query.purchases.findFirst({
14993
- where: (0, import_drizzle_orm46.eq)(purchaseTable.id, parsedPurchase.id)
15224
+ where: (0, import_drizzle_orm47.eq)(purchaseTable.id, parsedPurchase.id)
14994
15225
  });
14995
15226
  return purchaseSchema.optional().parse(newPurchase);
14996
15227
  } else {
@@ -15008,16 +15239,16 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15008
15239
  async updatePurchaseUserTransferTransferState(options) {
15009
15240
  await client.update(purchaseUserTransfer).set({
15010
15241
  transferState: options.transferState
15011
- }).where((0, import_drizzle_orm46.eq)(purchaseUserTransfer.id, options.id));
15242
+ }).where((0, import_drizzle_orm47.eq)(purchaseUserTransfer.id, options.id));
15012
15243
  const purchaseUserTransferData = await client.query.purchaseUserTransfer.findFirst({
15013
- where: (0, import_drizzle_orm46.eq)(purchaseUserTransfer.id, options.id)
15244
+ where: (0, import_drizzle_orm47.eq)(purchaseUserTransfer.id, options.id)
15014
15245
  }) || null;
15015
15246
  return purchaseUserTransferSchema.nullable().parse(purchaseUserTransferData);
15016
15247
  },
15017
15248
  addResourceToResource: async function(options) {
15018
15249
  const { parentResourceId, childResourceId } = options;
15019
15250
  const parentResourceData = await client.query.contentResource.findFirst({
15020
- where: (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(import_drizzle_orm46.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, parentResourceId), (0, import_drizzle_orm46.eq)(contentResource.id, parentResourceId)),
15251
+ where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, parentResourceId), (0, import_drizzle_orm47.eq)(contentResource.id, parentResourceId)),
15021
15252
  with: {
15022
15253
  resources: true
15023
15254
  }
@@ -15033,7 +15264,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15033
15264
  position: parentResource.resources?.length || 0
15034
15265
  });
15035
15266
  const resourceJoin = await client.query.contentResourceResource.findFirst({
15036
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(contentResourceResource.resourceOfId, parentResource.id), (0, import_drizzle_orm46.eq)(contentResourceResource.resourceId, childResourceId)),
15267
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(contentResourceResource.resourceOfId, parentResource.id), (0, import_drizzle_orm47.eq)(contentResourceResource.resourceId, childResourceId)),
15037
15268
  with: {
15038
15269
  resource: true
15039
15270
  }
@@ -15047,7 +15278,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15047
15278
  async removeResourceFromResource(options) {
15048
15279
  const { childResourceId, parentResourceId } = options;
15049
15280
  const parentResourceData = await client.query.contentResource.findFirst({
15050
- where: (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(import_drizzle_orm46.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, parentResourceId), (0, import_drizzle_orm46.eq)(contentResource.id, parentResourceId))
15281
+ where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, parentResourceId), (0, import_drizzle_orm47.eq)(contentResource.id, parentResourceId))
15051
15282
  });
15052
15283
  const parsedParentResource = ContentResourceSchema.safeParse(parentResourceData);
15053
15284
  if (!parsedParentResource.success) {
@@ -15055,7 +15286,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15055
15286
  }
15056
15287
  const parentResource = parsedParentResource.data;
15057
15288
  const resourceJoin = await client.query.contentResourceResource.findFirst({
15058
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(contentResourceResource.resourceOfId, parentResource.id), (0, import_drizzle_orm46.eq)(contentResourceResource.resourceId, childResourceId)),
15289
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(contentResourceResource.resourceOfId, parentResource.id), (0, import_drizzle_orm47.eq)(contentResourceResource.resourceId, childResourceId)),
15059
15290
  with: {
15060
15291
  resource: true
15061
15292
  }
@@ -15064,22 +15295,22 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15064
15295
  if (!parsedResourceJoin.success) {
15065
15296
  return null;
15066
15297
  }
15067
- await client.delete(contentResourceResource).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(contentResourceResource.resourceOfId, parentResource.id), (0, import_drizzle_orm46.eq)(contentResourceResource.resourceId, childResourceId)));
15298
+ await client.delete(contentResourceResource).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(contentResourceResource.resourceOfId, parentResource.id), (0, import_drizzle_orm47.eq)(contentResourceResource.resourceId, childResourceId)));
15068
15299
  return parsedResourceJoin.data.resource;
15069
15300
  },
15070
15301
  async updateContentResourceFields(options) {
15071
15302
  if (!options.id) {
15072
15303
  throw new Error("No content resource id.");
15073
15304
  }
15074
- const currentResource = await client.select().from(contentResource).where((0, import_drizzle_orm46.eq)(contentResource.id, options.id)).then((res) => res[0]);
15305
+ const currentResource = await client.select().from(contentResource).where((0, import_drizzle_orm47.eq)(contentResource.id, options.id)).then((res) => res[0]);
15075
15306
  await client.update(contentResource).set({
15076
15307
  fields: {
15077
15308
  ...currentResource.fields,
15078
15309
  ...options.fields
15079
15310
  }
15080
- }).where((0, import_drizzle_orm46.eq)(contentResource.id, options.id));
15311
+ }).where((0, import_drizzle_orm47.eq)(contentResource.id, options.id));
15081
15312
  const resource = await client.query.contentResource.findFirst({
15082
- where: (0, import_drizzle_orm46.eq)(contentResource.id, options.id),
15313
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, options.id),
15083
15314
  with: {
15084
15315
  resources: {
15085
15316
  with: {
@@ -15089,12 +15320,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15089
15320
  with: {
15090
15321
  resource: true
15091
15322
  },
15092
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15323
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15093
15324
  }
15094
15325
  }
15095
15326
  }
15096
15327
  },
15097
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15328
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15098
15329
  }
15099
15330
  }
15100
15331
  });
@@ -15112,13 +15343,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15112
15343
  if (!id) {
15113
15344
  return null;
15114
15345
  }
15115
- const query = import_drizzle_orm46.sql`
15346
+ const query = import_drizzle_orm47.sql`
15116
15347
  SELECT
15117
15348
  id as id,
15118
15349
  CAST(updatedAt AS DATETIME) as updatedAt,
15119
15350
  CAST(createdAt AS DATETIME) as createdAt,
15120
15351
  JSON_EXTRACT (${contentResource.fields}, "$.state") AS state,
15121
15352
  JSON_EXTRACT (${contentResource.fields}, "$.duration") AS duration,
15353
+ JSON_UNQUOTE(JSON_EXTRACT (${contentResource.fields}, "$.resolution")) AS resolution,
15122
15354
  JSON_EXTRACT (${contentResource.fields}, "$.muxPlaybackId") AS muxPlaybackId,
15123
15355
  JSON_EXTRACT (${contentResource.fields}, "$.muxAssetId") AS muxAssetId,
15124
15356
  JSON_EXTRACT (${contentResource.fields}, "$.transcript") AS transcript,
@@ -15145,7 +15377,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15145
15377
  if (!videoResourceId) {
15146
15378
  return null;
15147
15379
  }
15148
- const results = await client.select().from(contentResource).innerJoin(contentResourceResource, (0, import_drizzle_orm46.eq)(contentResourceResource.resourceOfId, contentResource.id)).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(contentResourceResource.resourceId, videoResourceId), (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(contentResource.type, "post"), (0, import_drizzle_orm46.eq)(contentResource.type, "lesson")))).limit(1);
15380
+ const results = await client.select().from(contentResource).innerJoin(contentResourceResource, (0, import_drizzle_orm47.eq)(contentResourceResource.resourceOfId, contentResource.id)).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(contentResourceResource.resourceId, videoResourceId), (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(contentResource.type, "post"), (0, import_drizzle_orm47.eq)(contentResource.type, "lesson")))).limit(1);
15149
15381
  if (!results || results.length === 0) {
15150
15382
  return null;
15151
15383
  }
@@ -15154,7 +15386,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15154
15386
  return null;
15155
15387
  }
15156
15388
  const fullResource = await client.query.contentResource.findFirst({
15157
- where: (0, import_drizzle_orm46.eq)(contentResource.id, resourceData.id),
15389
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, resourceData.id),
15158
15390
  with: {
15159
15391
  resources: true
15160
15392
  }
@@ -15171,7 +15403,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15171
15403
  id
15172
15404
  });
15173
15405
  const resource = await client.query.contentResource.findFirst({
15174
- where: (0, import_drizzle_orm46.eq)(contentResource.id, id),
15406
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, id),
15175
15407
  with: {
15176
15408
  resources: {
15177
15409
  with: {
@@ -15181,12 +15413,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15181
15413
  with: {
15182
15414
  resource: true
15183
15415
  },
15184
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15416
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15185
15417
  }
15186
15418
  }
15187
15419
  }
15188
15420
  },
15189
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15421
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15190
15422
  }
15191
15423
  }
15192
15424
  });
@@ -15203,7 +15435,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15203
15435
  },
15204
15436
  async getContentResource(data) {
15205
15437
  const resource = await client.query.contentResource.findFirst({
15206
- where: (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(contentResource.id, data), (0, import_drizzle_orm46.eq)(import_drizzle_orm46.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, `${data}`)),
15438
+ where: (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(contentResource.id, data), (0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, `${data}`)),
15207
15439
  with: {
15208
15440
  resources: {
15209
15441
  with: {
@@ -15221,12 +15453,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15221
15453
  }
15222
15454
  }
15223
15455
  },
15224
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15456
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15225
15457
  }
15226
15458
  }
15227
15459
  }
15228
15460
  },
15229
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15461
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15230
15462
  }
15231
15463
  }
15232
15464
  });
@@ -15244,14 +15476,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15244
15476
  async getEvent(eventIdOrSlug, options) {
15245
15477
  const { withResources = false, withTags = false, withProducts = false, withPricing = false } = options || {};
15246
15478
  const eventQuery = await client.query.contentResource.findFirst({
15247
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(contentResource.type, "event"), (0, import_drizzle_orm46.eq)(contentResource.type, "event-series")), (0, import_drizzle_orm46.or)((0, import_drizzle_orm46.eq)(contentResource.id, eventIdOrSlug), (0, import_drizzle_orm46.eq)(import_drizzle_orm46.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, eventIdOrSlug))),
15479
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(contentResource.type, "event"), (0, import_drizzle_orm47.eq)(contentResource.type, "event-series")), (0, import_drizzle_orm47.or)((0, import_drizzle_orm47.eq)(contentResource.id, eventIdOrSlug), (0, import_drizzle_orm47.eq)(import_drizzle_orm47.sql`JSON_EXTRACT (${contentResource.fields}, "$.slug")`, eventIdOrSlug))),
15248
15480
  with: {
15249
15481
  ...withResources && {
15250
15482
  resources: {
15251
15483
  with: {
15252
15484
  resource: true
15253
15485
  },
15254
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15486
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15255
15487
  }
15256
15488
  },
15257
15489
  ...withTags && {
@@ -15259,7 +15491,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15259
15491
  with: {
15260
15492
  tag: true
15261
15493
  },
15262
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceTag.position)
15494
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceTag.position)
15263
15495
  }
15264
15496
  },
15265
15497
  ...withProducts && {
@@ -15302,7 +15534,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15302
15534
  }
15303
15535
  });
15304
15536
  const resourceProduct = await client.query.contentResourceProduct.findFirst({
15305
- where: (0, import_drizzle_orm46.eq)(contentResourceProduct.resourceId, resource.id),
15537
+ where: (0, import_drizzle_orm47.eq)(contentResourceProduct.resourceId, resource.id),
15306
15538
  with: {
15307
15539
  resource: true,
15308
15540
  product: true
@@ -15464,7 +15696,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15464
15696
  };
15465
15697
  await tx.insert(contentResource).values(newEventSeries);
15466
15698
  const eventSeriesResource = await tx.query.contentResource.findFirst({
15467
- where: (0, import_drizzle_orm46.eq)(contentResource.id, eventSeriesResourceId),
15699
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, eventSeriesResourceId),
15468
15700
  with: {
15469
15701
  resources: {
15470
15702
  with: {
@@ -15474,18 +15706,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15474
15706
  with: {
15475
15707
  resource: true
15476
15708
  },
15477
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15709
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15478
15710
  }
15479
15711
  }
15480
15712
  }
15481
15713
  },
15482
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15714
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15483
15715
  },
15484
15716
  tags: {
15485
15717
  with: {
15486
15718
  tag: true
15487
15719
  },
15488
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceTag.position)
15720
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceTag.position)
15489
15721
  },
15490
15722
  resourceProducts: {
15491
15723
  with: {
@@ -15538,7 +15770,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15538
15770
  };
15539
15771
  await tx.insert(contentResource).values(newChildEvent);
15540
15772
  const childEventResource = await tx.query.contentResource.findFirst({
15541
- where: (0, import_drizzle_orm46.eq)(contentResource.id, childEventResourceId),
15773
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, childEventResourceId),
15542
15774
  with: {
15543
15775
  resources: {
15544
15776
  with: {
@@ -15548,18 +15780,18 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15548
15780
  with: {
15549
15781
  resource: true
15550
15782
  },
15551
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15783
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15552
15784
  }
15553
15785
  }
15554
15786
  }
15555
15787
  },
15556
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15788
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15557
15789
  },
15558
15790
  tags: {
15559
15791
  with: {
15560
15792
  tag: true
15561
15793
  },
15562
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceTag.position)
15794
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceTag.position)
15563
15795
  },
15564
15796
  resourceProducts: {
15565
15797
  with: {
@@ -15686,13 +15918,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15686
15918
  }
15687
15919
  });
15688
15920
  const cohort2 = await tx.query.contentResource.findFirst({
15689
- where: (0, import_drizzle_orm46.eq)(contentResource.id, cohortId),
15921
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, cohortId),
15690
15922
  with: {
15691
15923
  resources: {
15692
15924
  with: {
15693
15925
  resource: true
15694
15926
  },
15695
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
15927
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15696
15928
  }
15697
15929
  }
15698
15930
  });
@@ -15805,7 +16037,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15805
16037
  }
15806
16038
  });
15807
16039
  const workshop = await tx.query.contentResource.findFirst({
15808
- where: (0, import_drizzle_orm46.eq)(contentResource.id, workshopId),
16040
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, workshopId),
15809
16041
  with: {
15810
16042
  resources: {
15811
16043
  with: {
@@ -15815,12 +16047,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15815
16047
  with: {
15816
16048
  resource: true
15817
16049
  },
15818
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
16050
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15819
16051
  }
15820
16052
  }
15821
16053
  }
15822
16054
  },
15823
- orderBy: (0, import_drizzle_orm46.asc)(contentResourceResource.position)
16055
+ orderBy: (0, import_drizzle_orm47.asc)(contentResourceResource.position)
15824
16056
  }
15825
16057
  }
15826
16058
  });
@@ -15864,7 +16096,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15864
16096
  position
15865
16097
  });
15866
16098
  const section = await tx.query.contentResource.findFirst({
15867
- where: (0, import_drizzle_orm46.eq)(contentResource.id, sectionId)
16099
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, sectionId)
15868
16100
  });
15869
16101
  if (section) {
15870
16102
  createdSections.push(section);
@@ -15898,7 +16130,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15898
16130
  position: lessonPosition
15899
16131
  });
15900
16132
  const lesson = await tx.query.contentResource.findFirst({
15901
- where: (0, import_drizzle_orm46.eq)(contentResource.id, lessonId)
16133
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, lessonId)
15902
16134
  });
15903
16135
  if (lesson) {
15904
16136
  createdLessons.push(lesson);
@@ -15934,7 +16166,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
15934
16166
  position
15935
16167
  });
15936
16168
  const lesson = await tx.query.contentResource.findFirst({
15937
- where: (0, import_drizzle_orm46.eq)(contentResource.id, lessonId)
16169
+ where: (0, import_drizzle_orm47.eq)(contentResource.id, lessonId)
15938
16170
  });
15939
16171
  if (lesson) {
15940
16172
  createdLessons.push(lesson);
@@ -16037,7 +16269,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16037
16269
  __name(findClosestDiscount, "findClosestDiscount");
16038
16270
  const percentageDiscount = findClosestDiscount(Number(input.percentageDiscount) * 100);
16039
16271
  const merchantCouponResult = percentageDiscount < 1 ? await client.query.merchantCoupon.findFirst({
16040
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(merchantCoupon.percentageDiscount, percentageDiscount.toString()), (0, import_drizzle_orm46.eq)(merchantCoupon.type, "special"))
16272
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(merchantCoupon.percentageDiscount, percentageDiscount.toString()), (0, import_drizzle_orm47.eq)(merchantCoupon.type, "special"))
16041
16273
  }) : null;
16042
16274
  if (!merchantCouponResult) {
16043
16275
  return [];
@@ -16084,54 +16316,54 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16084
16316
  }
16085
16317
  },
16086
16318
  async getUser(data) {
16087
- return await client.select().from(users).where((0, import_drizzle_orm46.eq)(users.id, data)).then((res) => res[0]) ?? null;
16319
+ return await client.select().from(users).where((0, import_drizzle_orm47.eq)(users.id, data)).then((res) => res[0]) ?? null;
16088
16320
  },
16089
16321
  async getUserByEmail(data) {
16090
- return await client.select().from(users).where((0, import_drizzle_orm46.eq)(users.email, data)).then((res) => res[0]) ?? null;
16322
+ return await client.select().from(users).where((0, import_drizzle_orm47.eq)(users.email, data)).then((res) => res[0]) ?? null;
16091
16323
  },
16092
16324
  async createSession(data) {
16093
16325
  await client.insert(sessions).values(data);
16094
- return await client.select().from(sessions).where((0, import_drizzle_orm46.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
16326
+ return await client.select().from(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
16095
16327
  },
16096
16328
  async getSessionAndUser(data) {
16097
16329
  return await client.select({
16098
16330
  session: sessions,
16099
16331
  user: users
16100
- }).from(sessions).where((0, import_drizzle_orm46.eq)(sessions.sessionToken, data)).innerJoin(users, (0, import_drizzle_orm46.eq)(users.id, sessions.userId)).then((res) => res[0]) ?? null;
16332
+ }).from(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, data)).innerJoin(users, (0, import_drizzle_orm47.eq)(users.id, sessions.userId)).then((res) => res[0]) ?? null;
16101
16333
  },
16102
16334
  async updateUser(data) {
16103
16335
  if (!data.id) {
16104
16336
  throw new Error("No user id.");
16105
16337
  }
16106
- await client.update(users).set(data).where((0, import_drizzle_orm46.eq)(users.id, data.id));
16107
- return await client.select().from(users).where((0, import_drizzle_orm46.eq)(users.id, data.id)).then((res) => res[0]);
16338
+ await client.update(users).set(data).where((0, import_drizzle_orm47.eq)(users.id, data.id));
16339
+ return await client.select().from(users).where((0, import_drizzle_orm47.eq)(users.id, data.id)).then((res) => res[0]);
16108
16340
  },
16109
16341
  async updateSession(data) {
16110
- await client.update(sessions).set(data).where((0, import_drizzle_orm46.eq)(sessions.sessionToken, data.sessionToken));
16111
- return await client.select().from(sessions).where((0, import_drizzle_orm46.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
16342
+ await client.update(sessions).set(data).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, data.sessionToken));
16343
+ return await client.select().from(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, data.sessionToken)).then((res) => res[0]);
16112
16344
  },
16113
16345
  async linkAccount(rawAccount) {
16114
16346
  await client.insert(accounts).values(rawAccount);
16115
16347
  },
16116
16348
  async getUserByAccount(account) {
16117
- const dbAccount = await client.select().from(accounts).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm46.eq)(accounts.provider, account.provider))).leftJoin(users, (0, import_drizzle_orm46.eq)(accounts.userId, users.id)).then((res) => res[0]) ?? null;
16349
+ const dbAccount = await client.select().from(accounts).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm47.eq)(accounts.provider, account.provider))).leftJoin(users, (0, import_drizzle_orm47.eq)(accounts.userId, users.id)).then((res) => res[0]) ?? null;
16118
16350
  if (!dbAccount) {
16119
16351
  return null;
16120
16352
  }
16121
16353
  return dbAccount.User;
16122
16354
  },
16123
16355
  async deleteSession(sessionToken) {
16124
- const session = await client.select().from(sessions).where((0, import_drizzle_orm46.eq)(sessions.sessionToken, sessionToken)).then((res) => res[0]) ?? null;
16125
- await client.delete(sessions).where((0, import_drizzle_orm46.eq)(sessions.sessionToken, sessionToken));
16356
+ const session = await client.select().from(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, sessionToken)).then((res) => res[0]) ?? null;
16357
+ await client.delete(sessions).where((0, import_drizzle_orm47.eq)(sessions.sessionToken, sessionToken));
16126
16358
  return session;
16127
16359
  },
16128
16360
  async createVerificationToken(token) {
16129
16361
  await client.insert(verificationTokens).values(token);
16130
- return await client.select().from(verificationTokens).where((0, import_drizzle_orm46.eq)(verificationTokens.identifier, token.identifier)).then((res) => res[0]);
16362
+ return await client.select().from(verificationTokens).where((0, import_drizzle_orm47.eq)(verificationTokens.identifier, token.identifier)).then((res) => res[0]);
16131
16363
  },
16132
16364
  async useVerificationToken(token) {
16133
16365
  try {
16134
- const deletedToken = await client.select().from(verificationTokens).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm46.eq)(verificationTokens.token, token.token))).then((res) => res[0]) ?? null;
16366
+ const deletedToken = await client.select().from(verificationTokens).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm47.eq)(verificationTokens.token, token.token))).then((res) => res[0]) ?? null;
16135
16367
  if (deletedToken?.createdAt) {
16136
16368
  const TIMEOUT_IN_SECONDS = 90;
16137
16369
  const expireMultipleClicks = (0, import_date_fns2.addSeconds)(deletedToken.createdAt, TIMEOUT_IN_SECONDS);
@@ -16140,7 +16372,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16140
16372
  const { id: _, ...verificationToken } = token;
16141
16373
  return deletedToken;
16142
16374
  } else {
16143
- await client.delete(verificationTokens).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm46.eq)(verificationTokens.token, token.token)));
16375
+ await client.delete(verificationTokens).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(verificationTokens.identifier, token.identifier), (0, import_drizzle_orm47.eq)(verificationTokens.token, token.token)));
16144
16376
  return deletedToken;
16145
16377
  }
16146
16378
  }
@@ -16150,14 +16382,14 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16150
16382
  }
16151
16383
  },
16152
16384
  async deleteUser(id) {
16153
- const user = await client.select().from(users).where((0, import_drizzle_orm46.eq)(users.id, id)).then((res) => res[0] ?? null);
16154
- await client.delete(users).where((0, import_drizzle_orm46.eq)(users.id, id));
16155
- await client.delete(sessions).where((0, import_drizzle_orm46.eq)(sessions.userId, id));
16156
- await client.delete(accounts).where((0, import_drizzle_orm46.eq)(accounts.userId, id));
16385
+ const user = await client.select().from(users).where((0, import_drizzle_orm47.eq)(users.id, id)).then((res) => res[0] ?? null);
16386
+ await client.delete(users).where((0, import_drizzle_orm47.eq)(users.id, id));
16387
+ await client.delete(sessions).where((0, import_drizzle_orm47.eq)(sessions.userId, id));
16388
+ await client.delete(accounts).where((0, import_drizzle_orm47.eq)(accounts.userId, id));
16157
16389
  return user;
16158
16390
  },
16159
16391
  async unlinkAccount(account) {
16160
- await client.delete(accounts).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm46.eq)(accounts.provider, account.provider)));
16392
+ await client.delete(accounts).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(accounts.providerAccountId, account.providerAccountId), (0, import_drizzle_orm47.eq)(accounts.provider, account.provider)));
16161
16393
  return void 0;
16162
16394
  },
16163
16395
  createOrganization: async (options) => {
@@ -16170,12 +16402,12 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16170
16402
  },
16171
16403
  getOrganization: async (organizationId) => {
16172
16404
  return OrganizationSchema.parse(await client.query.organization.findFirst({
16173
- where: (0, import_drizzle_orm46.eq)(organizationTable.id, organizationId)
16405
+ where: (0, import_drizzle_orm47.eq)(organizationTable.id, organizationId)
16174
16406
  }));
16175
16407
  },
16176
16408
  addMemberToOrganization: async (options) => {
16177
16409
  const currentMembership = await client.query.organizationMemberships.findFirst({
16178
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(organizationMembershipTable.organizationId, options.organizationId), (0, import_drizzle_orm46.eq)(organizationMembershipTable.userId, options.userId)),
16410
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(organizationMembershipTable.organizationId, options.organizationId), (0, import_drizzle_orm47.eq)(organizationMembershipTable.userId, options.userId)),
16179
16411
  with: {
16180
16412
  organization: true,
16181
16413
  user: true
@@ -16190,7 +16422,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16190
16422
  id
16191
16423
  });
16192
16424
  return OrganizationMemberSchema.parse(await client.query.organizationMemberships.findFirst({
16193
- where: (0, import_drizzle_orm46.eq)(organizationMembershipTable.id, id),
16425
+ where: (0, import_drizzle_orm47.eq)(organizationMembershipTable.id, id),
16194
16426
  with: {
16195
16427
  organization: true,
16196
16428
  user: true
@@ -16199,13 +16431,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16199
16431
  }
16200
16432
  },
16201
16433
  removeMemberFromOrganization: async (options) => {
16202
- await client.delete(organizationMembershipTable).where((0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(organizationMembershipTable.organizationId, options.organizationId), (0, import_drizzle_orm46.eq)(organizationMembershipTable.userId, options.userId)));
16434
+ await client.delete(organizationMembershipTable).where((0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(organizationMembershipTable.organizationId, options.organizationId), (0, import_drizzle_orm47.eq)(organizationMembershipTable.userId, options.userId)));
16203
16435
  },
16204
16436
  addRoleForMember: async (options) => {
16205
16437
  const existingRole = external_exports.object({
16206
16438
  id: external_exports.string()
16207
16439
  }).nullish().parse(await client.query.roles.findFirst({
16208
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(roleTable.organizationId, options.organizationId), (0, import_drizzle_orm46.eq)(roleTable.name, options.role))
16440
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(roleTable.organizationId, options.organizationId), (0, import_drizzle_orm47.eq)(roleTable.name, options.role))
16209
16441
  }));
16210
16442
  const roleId = existingRole?.id || crypto.randomUUID();
16211
16443
  if (!existingRole) {
@@ -16216,7 +16448,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16216
16448
  });
16217
16449
  }
16218
16450
  const currentOrgMembershipRole = await client.query.organizationMembershipRoles.findFirst({
16219
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(organizationMembershipRoleTable.organizationMembershipId, options.memberId), (0, import_drizzle_orm46.eq)(organizationMembershipRoleTable.roleId, roleId))
16451
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(organizationMembershipRoleTable.organizationMembershipId, options.memberId), (0, import_drizzle_orm47.eq)(organizationMembershipRoleTable.roleId, roleId))
16220
16452
  });
16221
16453
  if (!currentOrgMembershipRole) {
16222
16454
  await client.insert(organizationMembershipRoleTable).values({
@@ -16230,16 +16462,16 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16230
16462
  const existingRole = external_exports.object({
16231
16463
  id: external_exports.string()
16232
16464
  }).nullable().parse(await client.query.roles.findFirst({
16233
- where: (0, import_drizzle_orm46.and)((0, import_drizzle_orm46.eq)(roleTable.organizationId, options.organizationId), (0, import_drizzle_orm46.eq)(roleTable.name, options.role))
16465
+ where: (0, import_drizzle_orm47.and)((0, import_drizzle_orm47.eq)(roleTable.organizationId, options.organizationId), (0, import_drizzle_orm47.eq)(roleTable.name, options.role))
16234
16466
  }));
16235
16467
  const roleId = existingRole?.id;
16236
16468
  if (roleId) {
16237
- await client.delete(organizationMembershipRoleTable).where((0, import_drizzle_orm46.eq)(organizationMembershipRoleTable.roleId, roleId));
16469
+ await client.delete(organizationMembershipRoleTable).where((0, import_drizzle_orm47.eq)(organizationMembershipRoleTable.roleId, roleId));
16238
16470
  }
16239
16471
  },
16240
16472
  getMembershipsForUser: async (userId) => {
16241
16473
  return OrganizationMemberSchema.array().parse(await client.query.organizationMemberships.findMany({
16242
- where: (0, import_drizzle_orm46.eq)(organizationMembershipTable.userId, userId),
16474
+ where: (0, import_drizzle_orm47.eq)(organizationMembershipTable.userId, userId),
16243
16475
  with: {
16244
16476
  organization: true,
16245
16477
  user: true
@@ -16248,7 +16480,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16248
16480
  },
16249
16481
  getOrganizationMembers: async (organizationId) => {
16250
16482
  return OrganizationMemberSchema.array().parse(await client.query.organizationMemberships.findMany({
16251
- where: (0, import_drizzle_orm46.eq)(organizationMembershipTable.organizationId, organizationId)
16483
+ where: (0, import_drizzle_orm47.eq)(organizationMembershipTable.organizationId, organizationId)
16252
16484
  }) || []);
16253
16485
  },
16254
16486
  createSubscription: async (options) => {
@@ -16258,7 +16490,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16258
16490
  id
16259
16491
  });
16260
16492
  return SubscriptionSchema.parse(await client.query.subscription.findFirst({
16261
- where: (0, import_drizzle_orm46.eq)(subscriptionTable.id, id),
16493
+ where: (0, import_drizzle_orm47.eq)(subscriptionTable.id, id),
16262
16494
  with: {
16263
16495
  product: true
16264
16496
  }
@@ -16266,7 +16498,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16266
16498
  },
16267
16499
  getMerchantSubscription: async (merchantSubscriptionId) => {
16268
16500
  return MerchantSubscriptionSchema.parse(await client.query.merchantSubscription.findFirst({
16269
- where: (0, import_drizzle_orm46.eq)(merchantSubscriptionTable.id, merchantSubscriptionId)
16501
+ where: (0, import_drizzle_orm47.eq)(merchantSubscriptionTable.id, merchantSubscriptionId)
16270
16502
  }));
16271
16503
  },
16272
16504
  createMerchantSubscription: async (options) => {
@@ -16276,7 +16508,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16276
16508
  id
16277
16509
  });
16278
16510
  return MerchantSubscriptionSchema.parse(await client.query.merchantSubscription.findFirst({
16279
- where: (0, import_drizzle_orm46.eq)(merchantSubscriptionTable.id, id)
16511
+ where: (0, import_drizzle_orm47.eq)(merchantSubscriptionTable.id, id)
16280
16512
  }));
16281
16513
  },
16282
16514
  updateMerchantSubscription: async (options) => {
@@ -16287,13 +16519,13 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16287
16519
  },
16288
16520
  getSubscriptionForStripeId: async (stripeSubscriptionId) => {
16289
16521
  const merchantSubscriptionParsed = MerchantSubscriptionSchema.safeParse(await client.query.merchantSubscription.findFirst({
16290
- where: (0, import_drizzle_orm46.eq)(merchantSubscriptionTable.identifier, stripeSubscriptionId)
16522
+ where: (0, import_drizzle_orm47.eq)(merchantSubscriptionTable.identifier, stripeSubscriptionId)
16291
16523
  }));
16292
16524
  if (!merchantSubscriptionParsed.success) {
16293
16525
  throw new Error(`No merchant subscription found for stripe id ${stripeSubscriptionId} ${merchantSubscriptionParsed.error}`);
16294
16526
  }
16295
16527
  const subscriptionParsed = SubscriptionSchema.safeParse(await client.query.subscription.findFirst({
16296
- where: (0, import_drizzle_orm46.eq)(subscriptionTable.merchantSubscriptionId, merchantSubscriptionParsed.data.id),
16528
+ where: (0, import_drizzle_orm47.eq)(subscriptionTable.merchantSubscriptionId, merchantSubscriptionParsed.data.id),
16297
16529
  with: {
16298
16530
  product: true
16299
16531
  }
@@ -16306,7 +16538,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16306
16538
  updateSubscriptionStatus: async (subscriptionId, status) => {
16307
16539
  await client.update(subscriptionTable).set({
16308
16540
  status
16309
- }).where((0, import_drizzle_orm46.eq)(subscriptionTable.id, subscriptionId));
16541
+ }).where((0, import_drizzle_orm47.eq)(subscriptionTable.id, subscriptionId));
16310
16542
  }
16311
16543
  };
16312
16544
  return adapter;
@@ -16314,6 +16546,7 @@ function mySqlDrizzleAdapter(client, tableFn = import_mysql_core52.mysqlTable, p
16314
16546
  __name(mySqlDrizzleAdapter, "mySqlDrizzleAdapter");
16315
16547
  // Annotate the CommonJS export names for ESM import in node:
16316
16548
  0 && (module.exports = {
16549
+ createCmsResourceActions,
16317
16550
  createTables,
16318
16551
  getCourseBuilderSchema,
16319
16552
  guid,