@coursebuilder/adapter-drizzle 2.1.1 → 3.0.0-canary.0.0c9beb2ae
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.
- package/dist/{chunk-KIQLUFJX.js → chunk-2GW3BJE2.js} +2 -2
- package/dist/{chunk-M3WM5Q7W.js → chunk-33ZN7FN7.js} +2 -2
- package/dist/chunk-4VZJQAPV.js +74 -0
- package/dist/chunk-5FLS4ZBX.js +109 -0
- package/dist/chunk-5YR5M22S.js +147 -0
- package/dist/chunk-6XQ6C3IX.js +18 -0
- package/dist/chunk-AIDM2CH6.js +146 -0
- package/dist/chunk-ALTODDUX.js +173 -0
- package/dist/chunk-AZY2VRAE.js +63 -0
- package/dist/chunk-BS7T27VL.js +239 -0
- package/dist/chunk-CN3FCRLR.js +55 -0
- package/dist/chunk-EAXC4CQD.js +245 -0
- package/dist/chunk-EDDG2YFS.js +249 -0
- package/dist/chunk-EDKWCMA7.js +210 -0
- package/dist/{chunk-7FBSP3VD.js → chunk-EDM6DKA5.js} +2 -2
- package/dist/{chunk-EZEQQJNH.js → chunk-EIQBTF5J.js} +2 -2
- package/dist/chunk-FYT7RTVW.js +248 -0
- package/dist/{chunk-F56AI52P.js → chunk-INZTF6QV.js} +2 -2
- package/dist/{chunk-AP5HBIV4.js → chunk-JVHX4JHA.js} +2 -2
- package/dist/chunk-LWEKWDLC.js +300 -0
- package/dist/chunk-OJPEBGGE.js +139 -0
- package/dist/chunk-QKOSV34V.js +16268 -0
- package/dist/chunk-QO3QE3LE.js +330 -0
- package/dist/chunk-QQKNNFFB.js +399 -0
- package/dist/chunk-RBHCV3UW.js +20 -0
- package/dist/chunk-TNH2C27F.js +252 -0
- package/dist/chunk-TNWNW666.js +133 -0
- package/dist/chunk-VBEXYQ6L.js +156 -0
- package/dist/chunk-W3ILNMLD.js +265 -0
- package/dist/chunk-WJ2ZUXL3.js +71 -0
- package/dist/{chunk-PJORQUQP.js → chunk-WUMDFFN3.js} +2 -2
- package/dist/{chunk-2AW5KYAK.js → chunk-X7DRYXB7.js} +2 -2
- package/dist/{chunk-PNPTKVJ4.js → chunk-XUBZKYH6.js} +24 -15
- package/dist/{chunk-WWBSNLRC.js → chunk-ZY4AFKUQ.js} +2 -2
- package/dist/index.d.ts +5 -11
- package/dist/index.js +41 -18
- package/dist/lib/mysql/cms-resource-actions.cjs +15912 -4127
- package/dist/lib/mysql/cms-resource-actions.cjs.map +1 -1
- package/dist/lib/mysql/cms-resource-actions.d.cts +8 -38
- package/dist/lib/mysql/cms-resource-actions.d.ts +8 -38
- package/dist/lib/mysql/cms-resource-actions.js +2 -1
- package/dist/lib/mysql/context.cjs +3380 -0
- package/dist/lib/mysql/context.cjs.map +1 -0
- package/dist/lib/mysql/context.d.cts +15 -0
- package/dist/lib/mysql/context.d.ts +15 -0
- package/dist/lib/mysql/context.js +34 -0
- package/dist/lib/mysql/context.js.map +1 -0
- package/dist/lib/mysql/index.cjs +21875 -15261
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.cts +24 -14300
- package/dist/lib/mysql/index.d.ts +24 -14300
- package/dist/lib/mysql/index.js +46 -22
- package/dist/lib/mysql/ports/auth-storage.cjs +84 -0
- package/dist/lib/mysql/ports/auth-storage.cjs.map +1 -0
- package/dist/lib/mysql/ports/auth-storage.d.cts +22 -0
- package/dist/lib/mysql/ports/auth-storage.d.ts +22 -0
- package/dist/lib/mysql/ports/auth-storage.js +8 -0
- package/dist/lib/mysql/ports/auth-storage.js.map +1 -0
- package/dist/lib/mysql/ports/catalog.cjs +16688 -0
- package/dist/lib/mysql/ports/catalog.cjs.map +1 -0
- package/dist/lib/mysql/ports/catalog.d.cts +24 -0
- package/dist/lib/mysql/ports/catalog.d.ts +24 -0
- package/dist/lib/mysql/ports/catalog.js +9 -0
- package/dist/lib/mysql/ports/catalog.js.map +1 -0
- package/dist/lib/mysql/ports/content-resource.cjs +321 -0
- package/dist/lib/mysql/ports/content-resource.cjs.map +1 -0
- package/dist/lib/mysql/ports/content-resource.d.cts +23 -0
- package/dist/lib/mysql/ports/content-resource.d.ts +23 -0
- package/dist/lib/mysql/ports/content-resource.js +8 -0
- package/dist/lib/mysql/ports/content-resource.js.map +1 -0
- package/dist/lib/mysql/ports/coupon.cjs +16524 -0
- package/dist/lib/mysql/ports/coupon.cjs.map +1 -0
- package/dist/lib/mysql/ports/coupon.d.cts +22 -0
- package/dist/lib/mysql/ports/coupon.d.ts +22 -0
- package/dist/lib/mysql/ports/coupon.js +9 -0
- package/dist/lib/mysql/ports/coupon.js.map +1 -0
- package/dist/lib/mysql/ports/entitlement.cjs +16350 -0
- package/dist/lib/mysql/ports/entitlement.cjs.map +1 -0
- package/dist/lib/mysql/ports/entitlement.d.cts +22 -0
- package/dist/lib/mysql/ports/entitlement.d.ts +22 -0
- package/dist/lib/mysql/ports/entitlement.js +9 -0
- package/dist/lib/mysql/ports/entitlement.js.map +1 -0
- package/dist/lib/mysql/ports/identity.cjs +154 -0
- package/dist/lib/mysql/ports/identity.cjs.map +1 -0
- package/dist/lib/mysql/ports/identity.d.cts +22 -0
- package/dist/lib/mysql/ports/identity.d.ts +22 -0
- package/dist/lib/mysql/ports/identity.js +8 -0
- package/dist/lib/mysql/ports/identity.js.map +1 -0
- package/dist/lib/mysql/ports/merchant.cjs +194 -0
- package/dist/lib/mysql/ports/merchant.cjs.map +1 -0
- package/dist/lib/mysql/ports/merchant.d.cts +22 -0
- package/dist/lib/mysql/ports/merchant.d.ts +22 -0
- package/dist/lib/mysql/ports/merchant.js +8 -0
- package/dist/lib/mysql/ports/merchant.js.map +1 -0
- package/dist/lib/mysql/ports/organization.cjs +16426 -0
- package/dist/lib/mysql/ports/organization.cjs.map +1 -0
- package/dist/lib/mysql/ports/organization.d.cts +22 -0
- package/dist/lib/mysql/ports/organization.d.ts +22 -0
- package/dist/lib/mysql/ports/organization.js +9 -0
- package/dist/lib/mysql/ports/organization.js.map +1 -0
- package/dist/lib/mysql/ports/progress.cjs +16544 -0
- package/dist/lib/mysql/ports/progress.cjs.map +1 -0
- package/dist/lib/mysql/ports/progress.d.cts +22 -0
- package/dist/lib/mysql/ports/progress.d.ts +22 -0
- package/dist/lib/mysql/ports/progress.js +9 -0
- package/dist/lib/mysql/ports/progress.js.map +1 -0
- package/dist/lib/mysql/ports/purchase.cjs +16609 -0
- package/dist/lib/mysql/ports/purchase.cjs.map +1 -0
- package/dist/lib/mysql/ports/purchase.d.cts +23 -0
- package/dist/lib/mysql/ports/purchase.d.ts +23 -0
- package/dist/lib/mysql/ports/purchase.js +9 -0
- package/dist/lib/mysql/ports/purchase.js.map +1 -0
- package/dist/lib/mysql/ports/subscription.cjs +76 -0
- package/dist/lib/mysql/ports/subscription.cjs.map +1 -0
- package/dist/lib/mysql/ports/subscription.d.cts +22 -0
- package/dist/lib/mysql/ports/subscription.d.ts +22 -0
- package/dist/lib/mysql/ports/subscription.js +8 -0
- package/dist/lib/mysql/ports/subscription.js.map +1 -0
- package/dist/lib/mysql/schema.cjs +3373 -0
- package/dist/lib/mysql/schema.cjs.map +1 -0
- package/dist/lib/mysql/schema.d.cts +14385 -0
- package/dist/lib/mysql/schema.d.ts +14385 -0
- package/dist/lib/mysql/schema.js +35 -0
- package/dist/lib/mysql/schema.js.map +1 -0
- package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/accounts.js +4 -4
- package/dist/lib/mysql/schemas/auth/device-access-token.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/device-access-token.js +5 -5
- package/dist/lib/mysql/schemas/auth/device-verification.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/device-verification.js +5 -5
- package/dist/lib/mysql/schemas/auth/personal-access-token.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/personal-access-token.js +5 -5
- package/dist/lib/mysql/schemas/auth/profiles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/profiles.js +4 -4
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/role-permissions.js +5 -5
- package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/roles.js +4 -4
- package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/sessions.js +5 -5
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-permissions.js +4 -4
- package/dist/lib/mysql/schemas/auth/user-prefs.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-prefs.js +4 -4
- package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-roles.js +4 -4
- package/dist/lib/mysql/schemas/auth/users.cjs +5 -1
- package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/users.js +4 -4
- package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/coupon.js +4 -4
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.js +4 -4
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.js +4 -4
- package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/price.js +4 -4
- package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/product.js +4 -4
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +5 -5
- package/dist/lib/mysql/schemas/commerce/purchase.cjs +11 -2
- package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase.js +4 -4
- package/dist/lib/mysql/schemas/commerce/subscription.cjs +6 -1
- package/dist/lib/mysql/schemas/commerce/subscription.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/subscription.js +4 -4
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js +5 -5
- package/dist/lib/mysql/schemas/communication/comment.cjs +5 -1
- package/dist/lib/mysql/schemas/communication/comment.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/comment.js +4 -4
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +5 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.js +4 -4
- package/dist/lib/mysql/schemas/communication/question-response.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/question-response.js +5 -5
- package/dist/lib/mysql/schemas/content/content-contributions.cjs +5 -1
- package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-contributions.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource-product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-product.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource-tag.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-tag.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource-version.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-version.js +4 -4
- package/dist/lib/mysql/schemas/content/content-resource.cjs +5 -1
- package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource.js +4 -4
- package/dist/lib/mysql/schemas/content/tag-tag.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/tag-tag.js +4 -4
- package/dist/lib/mysql/schemas/content/tag.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/tag.js +4 -4
- package/dist/lib/mysql/schemas/entitlements/entitlement.cjs +11 -2
- package/dist/lib/mysql/schemas/entitlements/entitlement.cjs.map +1 -1
- package/dist/lib/mysql/schemas/entitlements/entitlement.js +5 -5
- package/dist/lib/mysql/schemas/org/organization-membership-roles.cjs +11 -2
- package/dist/lib/mysql/schemas/org/organization-membership-roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/org/organization-membership-roles.js +4 -4
- package/dist/lib/mysql/schemas/org/organization-memberships.cjs +11 -2
- package/dist/lib/mysql/schemas/org/organization-memberships.cjs.map +1 -1
- package/dist/lib/mysql/schemas/org/organization-memberships.d.cts +16 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.d.ts +16 -0
- package/dist/lib/mysql/schemas/org/organization-memberships.js +4 -4
- package/dist/lib/mysql/schemas/org/organizations.cjs +11 -2
- package/dist/lib/mysql/schemas/org/organizations.cjs.map +1 -1
- package/dist/lib/mysql/schemas/org/organizations.d.cts +16 -0
- package/dist/lib/mysql/schemas/org/organizations.d.ts +16 -0
- package/dist/lib/mysql/schemas/org/organizations.js +4 -4
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.cjs +40 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.cjs.map +1 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.d.cts +4 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.d.ts +4 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.js +10 -0
- package/dist/lib/mysql/workflows/content-resource-workflow-utils.js.map +1 -0
- package/dist/lib/mysql/workflows/create-cohort.cjs +184 -0
- package/dist/lib/mysql/workflows/create-cohort.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-cohort.d.cts +24 -0
- package/dist/lib/mysql/workflows/create-cohort.d.ts +24 -0
- package/dist/lib/mysql/workflows/create-cohort.js +9 -0
- package/dist/lib/mysql/workflows/create-cohort.js.map +1 -0
- package/dist/lib/mysql/workflows/create-event-series.cjs +283 -0
- package/dist/lib/mysql/workflows/create-event-series.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-event-series.d.cts +24 -0
- package/dist/lib/mysql/workflows/create-event-series.d.ts +24 -0
- package/dist/lib/mysql/workflows/create-event-series.js +9 -0
- package/dist/lib/mysql/workflows/create-event-series.js.map +1 -0
- package/dist/lib/mysql/workflows/create-event.cjs +194 -0
- package/dist/lib/mysql/workflows/create-event.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-event.d.cts +24 -0
- package/dist/lib/mysql/workflows/create-event.d.ts +24 -0
- package/dist/lib/mysql/workflows/create-event.js +9 -0
- package/dist/lib/mysql/workflows/create-event.js.map +1 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.cjs +231 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.d.cts +22 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.d.ts +22 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.js +8 -0
- package/dist/lib/mysql/workflows/create-merchant-charge-and-purchase.js.map +1 -0
- package/dist/lib/mysql/workflows/create-workshop.cjs +286 -0
- package/dist/lib/mysql/workflows/create-workshop.cjs.map +1 -0
- package/dist/lib/mysql/workflows/create-workshop.d.cts +24 -0
- package/dist/lib/mysql/workflows/create-workshop.d.ts +24 -0
- package/dist/lib/mysql/workflows/create-workshop.js +9 -0
- package/dist/lib/mysql/workflows/create-workshop.js.map +1 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.cjs +130 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.cjs.map +1 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.d.cts +24 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.d.ts +24 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.js +8 -0
- package/dist/lib/mysql/workflows/redeem-full-price-coupon.js.map +1 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.cjs +95 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.cjs.map +1 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.d.cts +30 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.d.ts +30 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.js +8 -0
- package/dist/lib/mysql/workflows/transfer-purchase-to-user.js.map +1 -0
- package/dist/lib/utils.d.cts +1 -10
- package/dist/lib/utils.d.ts +1 -10
- package/dist/types.d.ts +14 -0
- package/dist/types.js +1 -0
- package/package.json +9 -5
- package/src/index.ts +3 -2
- package/src/lib/mysql/context.ts +20 -0
- package/src/lib/mysql/index.ts +118 -4873
- package/src/lib/mysql/ports/auth-storage.ts +139 -0
- package/src/lib/mysql/ports/catalog.ts +610 -0
- package/src/lib/mysql/ports/content-resource.ts +442 -0
- package/src/lib/mysql/ports/coupon.ts +387 -0
- package/src/lib/mysql/ports/entitlement.ts +96 -0
- package/src/lib/mysql/ports/identity.ts +160 -0
- package/src/lib/mysql/ports/merchant.ts +274 -0
- package/src/lib/mysql/ports/organization.ts +216 -0
- package/src/lib/mysql/ports/progress.ts +366 -0
- package/src/lib/mysql/ports/purchase.ts +517 -0
- package/src/lib/mysql/ports/subscription.ts +93 -0
- package/src/lib/mysql/schema.ts +374 -0
- package/src/lib/mysql/schemas/org/organization-memberships.ts +7 -0
- package/src/lib/mysql/schemas/org/organizations.ts +8 -0
- package/src/lib/mysql/workflows/content-resource-workflow-utils.ts +22 -0
- package/src/lib/mysql/workflows/create-cohort.ts +239 -0
- package/src/lib/mysql/workflows/create-event-series.ts +384 -0
- package/src/lib/mysql/workflows/create-event.ts +232 -0
- package/src/lib/mysql/workflows/create-merchant-charge-and-purchase.ts +365 -0
- package/src/lib/mysql/workflows/create-workshop.ts +372 -0
- package/src/lib/mysql/workflows/redeem-full-price-coupon.ts +179 -0
- package/src/lib/mysql/workflows/transfer-purchase-to-user.ts +142 -0
- package/src/types.ts +33 -0
- package/dist/authjs.d.ts +0 -27
- package/dist/authjs.js +0 -1
- package/dist/chunk-62VSIVME.js +0 -4714
- package/dist/chunk-RVXF3JZ7.js +0 -8732
- package/dist/chunk-WEJL5OFI.js +0 -8732
- package/src/authjs.ts +0 -34
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import type { MySqlTableFn } from 'drizzle-orm/mysql-core'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getAccountsRelationsSchema,
|
|
5
|
+
getAccountsSchema,
|
|
6
|
+
} from './schemas/auth/accounts.js'
|
|
7
|
+
import {
|
|
8
|
+
getDeviceAccessTokenRelationsSchema,
|
|
9
|
+
getDeviceAccessTokenSchema,
|
|
10
|
+
} from './schemas/auth/device-access-token.js'
|
|
11
|
+
import {
|
|
12
|
+
getDeviceVerificationRelationsSchema,
|
|
13
|
+
getDeviceVerificationSchema,
|
|
14
|
+
} from './schemas/auth/device-verification.js'
|
|
15
|
+
import {
|
|
16
|
+
getPermissionsRelationsSchema,
|
|
17
|
+
getPermissionsSchema,
|
|
18
|
+
} from './schemas/auth/permissions.js'
|
|
19
|
+
import {
|
|
20
|
+
getPersonalAccessTokenRelationsSchema,
|
|
21
|
+
getPersonalAccessTokenSchema,
|
|
22
|
+
} from './schemas/auth/personal-access-token.js'
|
|
23
|
+
import {
|
|
24
|
+
getProfilesRelationsSchema,
|
|
25
|
+
getProfilesSchema,
|
|
26
|
+
} from './schemas/auth/profiles.js'
|
|
27
|
+
import {
|
|
28
|
+
getRolePermissionsRelationsSchema,
|
|
29
|
+
getRolePermissionsSchema,
|
|
30
|
+
} from './schemas/auth/role-permissions.js'
|
|
31
|
+
import {
|
|
32
|
+
getRolesRelationsSchema,
|
|
33
|
+
getRolesSchema,
|
|
34
|
+
} from './schemas/auth/roles.js'
|
|
35
|
+
import {
|
|
36
|
+
getSessionRelationsSchema,
|
|
37
|
+
getSessionsSchema,
|
|
38
|
+
} from './schemas/auth/sessions.js'
|
|
39
|
+
import {
|
|
40
|
+
getUserPermissionsRelationsSchema,
|
|
41
|
+
getUserPermissionsSchema,
|
|
42
|
+
} from './schemas/auth/user-permissions.js'
|
|
43
|
+
import {
|
|
44
|
+
getUserPrefsRelationsSchema,
|
|
45
|
+
getUserPrefsSchema,
|
|
46
|
+
} from './schemas/auth/user-prefs.js'
|
|
47
|
+
import {
|
|
48
|
+
getUserRolesRelationsSchema,
|
|
49
|
+
getUserRolesSchema,
|
|
50
|
+
} from './schemas/auth/user-roles.js'
|
|
51
|
+
import {
|
|
52
|
+
getUsersRelationsSchema,
|
|
53
|
+
getUsersSchema,
|
|
54
|
+
type UsersSchemaOverrides,
|
|
55
|
+
} from './schemas/auth/users.js'
|
|
56
|
+
import { getVerificationTokensSchema } from './schemas/auth/verification-tokens.js'
|
|
57
|
+
import {
|
|
58
|
+
getCouponRelationsSchema,
|
|
59
|
+
getCouponSchema,
|
|
60
|
+
} from './schemas/commerce/coupon.js'
|
|
61
|
+
import { getMerchantAccountSchema } from './schemas/commerce/merchant-account.js'
|
|
62
|
+
import {
|
|
63
|
+
getMerchantChargeRelationsSchema,
|
|
64
|
+
getMerchantChargeSchema,
|
|
65
|
+
} from './schemas/commerce/merchant-charge.js'
|
|
66
|
+
import { getMerchantCouponSchema } from './schemas/commerce/merchant-coupon.js'
|
|
67
|
+
import { getMerchantCustomerSchema } from './schemas/commerce/merchant-customer.js'
|
|
68
|
+
import {
|
|
69
|
+
getMerchantEventsRelationsSchema,
|
|
70
|
+
getMerchantEventsSchema,
|
|
71
|
+
} from './schemas/commerce/merchant-events.js'
|
|
72
|
+
import { getMerchantPriceSchema } from './schemas/commerce/merchant-price.js'
|
|
73
|
+
import { getMerchantProductSchema } from './schemas/commerce/merchant-product.js'
|
|
74
|
+
import { getMerchantSessionSchema } from './schemas/commerce/merchant-session.js'
|
|
75
|
+
import {
|
|
76
|
+
getMerchantSubscriptionRelationsSchema,
|
|
77
|
+
getMerchantSubscriptionSchema,
|
|
78
|
+
} from './schemas/commerce/merchant-subscription.js'
|
|
79
|
+
import { getPriceSchema } from './schemas/commerce/price.js'
|
|
80
|
+
import {
|
|
81
|
+
getProductRelationsSchema,
|
|
82
|
+
getProductSchema,
|
|
83
|
+
} from './schemas/commerce/product.js'
|
|
84
|
+
import {
|
|
85
|
+
getPurchaseUserTransferRelationsSchema,
|
|
86
|
+
getPurchaseUserTransferSchema,
|
|
87
|
+
} from './schemas/commerce/purchase-user-transfer.js'
|
|
88
|
+
import {
|
|
89
|
+
getPurchaseRelationsSchema,
|
|
90
|
+
getPurchaseSchema,
|
|
91
|
+
} from './schemas/commerce/purchase.js'
|
|
92
|
+
import {
|
|
93
|
+
getSubscriptionRelationsSchema,
|
|
94
|
+
getSubscriptionSchema,
|
|
95
|
+
} from './schemas/commerce/subscription.js'
|
|
96
|
+
import {
|
|
97
|
+
getUpgradableProductsRelationsSchema,
|
|
98
|
+
getUpgradableProductsSchema,
|
|
99
|
+
} from './schemas/commerce/upgradable-products.js'
|
|
100
|
+
import {
|
|
101
|
+
getCommentRelationsSchema,
|
|
102
|
+
getCommentsSchema,
|
|
103
|
+
} from './schemas/communication/comment.js'
|
|
104
|
+
import { getCommunicationChannelSchema } from './schemas/communication/communication-channel.js'
|
|
105
|
+
import { getCommunicationPreferenceTypesSchema } from './schemas/communication/communication-preference-types.js'
|
|
106
|
+
import {
|
|
107
|
+
getCommunicationPreferencesRelationsSchema,
|
|
108
|
+
getCommunicationPreferencesSchema,
|
|
109
|
+
} from './schemas/communication/communication-preferences.js'
|
|
110
|
+
import {
|
|
111
|
+
getQuestionResponseRelationsSchema,
|
|
112
|
+
getQuestionResponseSchema,
|
|
113
|
+
} from './schemas/communication/question-response.js'
|
|
114
|
+
import {
|
|
115
|
+
getContentContributionRelationsSchema,
|
|
116
|
+
getContentContributionsSchema,
|
|
117
|
+
} from './schemas/content/content-contributions.js'
|
|
118
|
+
import {
|
|
119
|
+
getContentResourceProductRelationsSchema,
|
|
120
|
+
getContentResourceProductSchema,
|
|
121
|
+
} from './schemas/content/content-resource-product.js'
|
|
122
|
+
import {
|
|
123
|
+
getContentResourceResourceRelationsSchema,
|
|
124
|
+
getContentResourceResourceSchema,
|
|
125
|
+
} from './schemas/content/content-resource-resource.js'
|
|
126
|
+
import {
|
|
127
|
+
getContentResourceTagRelationsSchema,
|
|
128
|
+
getContentResourceTagSchema,
|
|
129
|
+
} from './schemas/content/content-resource-tag.js'
|
|
130
|
+
import {
|
|
131
|
+
getContentResourceVersionRelationsSchema,
|
|
132
|
+
getContentResourceVersionSchema,
|
|
133
|
+
} from './schemas/content/content-resource-version.js'
|
|
134
|
+
import {
|
|
135
|
+
getContentResourceRelationsSchema,
|
|
136
|
+
getContentResourceSchema,
|
|
137
|
+
} from './schemas/content/content-resource.js'
|
|
138
|
+
import {
|
|
139
|
+
getContributionTypesRelationsSchema,
|
|
140
|
+
getContributionTypesSchema,
|
|
141
|
+
} from './schemas/content/contribution-types.js'
|
|
142
|
+
import { getLessonProgressSchema } from './schemas/content/lesson-progress.js'
|
|
143
|
+
import { getResourceProgressSchema } from './schemas/content/resource-progress.js'
|
|
144
|
+
import {
|
|
145
|
+
getTagTagRelationsSchema,
|
|
146
|
+
getTagTagSchema,
|
|
147
|
+
} from './schemas/content/tag-tag.js'
|
|
148
|
+
import { getTagRelationsSchema, getTagSchema } from './schemas/content/tag.js'
|
|
149
|
+
import { getEntitlementTypesSchema } from './schemas/entitlements/entitlement-type.js'
|
|
150
|
+
import {
|
|
151
|
+
getEntitlementRelationsSchema,
|
|
152
|
+
getEntitlementsSchema,
|
|
153
|
+
} from './schemas/entitlements/entitlement.js'
|
|
154
|
+
import {
|
|
155
|
+
getOrganizationMembershipRolesRelationsSchema,
|
|
156
|
+
getOrganizationMembershipRolesSchema,
|
|
157
|
+
} from './schemas/org/organization-membership-roles.js'
|
|
158
|
+
import {
|
|
159
|
+
getOrganizationMembershipsRelationsSchema,
|
|
160
|
+
getOrganizationMembershipsSchema,
|
|
161
|
+
} from './schemas/org/organization-memberships.js'
|
|
162
|
+
import {
|
|
163
|
+
getOrganizationsRelationsSchema,
|
|
164
|
+
getOrganizationsSchema,
|
|
165
|
+
} from './schemas/org/organizations.js'
|
|
166
|
+
|
|
167
|
+
/** Overrides for constructing a Course Builder MySQL schema with custom user tables. */
|
|
168
|
+
export type CourseBuilderSchemaOverrides<
|
|
169
|
+
TUsers extends ReturnType<typeof getUsersSchema> = ReturnType<
|
|
170
|
+
typeof getUsersSchema
|
|
171
|
+
>,
|
|
172
|
+
> = UsersSchemaOverrides<TUsers>
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Constructs the complete Course Builder MySQL table and relation set.
|
|
176
|
+
*
|
|
177
|
+
* @param mysqlTable - Drizzle table factory, optionally configured with a prefix.
|
|
178
|
+
* @param overrides - Optional schema factories for custom user tables.
|
|
179
|
+
* @returns The shared table and relation objects used by the MySQL adapter.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* const schema = getCourseBuilderSchema(mysqlTable)
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export function getCourseBuilderSchema<
|
|
187
|
+
TUsers extends ReturnType<typeof getUsersSchema> = ReturnType<
|
|
188
|
+
typeof getUsersSchema
|
|
189
|
+
>,
|
|
190
|
+
>(
|
|
191
|
+
mysqlTable: MySqlTableFn,
|
|
192
|
+
overrides: CourseBuilderSchemaOverrides<TUsers> = {},
|
|
193
|
+
) {
|
|
194
|
+
const resolvedGetUsersSchema = (overrides.getUsersSchema ??
|
|
195
|
+
getUsersSchema) as (mysqlTable: MySqlTableFn) => TUsers
|
|
196
|
+
const userRelationsOverrides: UsersSchemaOverrides<TUsers> = {
|
|
197
|
+
getUsersSchema: resolvedGetUsersSchema,
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
accounts: getAccountsSchema(mysqlTable),
|
|
201
|
+
accountsRelations: getAccountsRelationsSchema(
|
|
202
|
+
mysqlTable,
|
|
203
|
+
userRelationsOverrides,
|
|
204
|
+
),
|
|
205
|
+
permissions: getPermissionsSchema(mysqlTable),
|
|
206
|
+
permissionsRelations: getPermissionsRelationsSchema(mysqlTable),
|
|
207
|
+
rolePermissions: getRolePermissionsSchema(mysqlTable),
|
|
208
|
+
rolePermissionsRelations: getRolePermissionsRelationsSchema(mysqlTable),
|
|
209
|
+
roles: getRolesSchema(mysqlTable),
|
|
210
|
+
rolesRelations: getRolesRelationsSchema(mysqlTable),
|
|
211
|
+
sessions: getSessionsSchema(mysqlTable),
|
|
212
|
+
sessionsRelations: getSessionRelationsSchema(
|
|
213
|
+
mysqlTable,
|
|
214
|
+
userRelationsOverrides,
|
|
215
|
+
),
|
|
216
|
+
userPermissions: getUserPermissionsSchema(mysqlTable),
|
|
217
|
+
userPermissionsRelations: getUserPermissionsRelationsSchema(
|
|
218
|
+
mysqlTable,
|
|
219
|
+
userRelationsOverrides,
|
|
220
|
+
),
|
|
221
|
+
userRoles: getUserRolesSchema(mysqlTable),
|
|
222
|
+
userRolesRelations: getUserRolesRelationsSchema(
|
|
223
|
+
mysqlTable,
|
|
224
|
+
userRelationsOverrides,
|
|
225
|
+
),
|
|
226
|
+
users: resolvedGetUsersSchema(mysqlTable),
|
|
227
|
+
usersRelations: getUsersRelationsSchema(mysqlTable, userRelationsOverrides),
|
|
228
|
+
verificationTokens: getVerificationTokensSchema(mysqlTable),
|
|
229
|
+
coupon: getCouponSchema(mysqlTable),
|
|
230
|
+
couponRelations: getCouponRelationsSchema(mysqlTable),
|
|
231
|
+
lessonProgress: getLessonProgressSchema(mysqlTable),
|
|
232
|
+
merchantAccount: getMerchantAccountSchema(mysqlTable),
|
|
233
|
+
merchantCharge: getMerchantChargeSchema(mysqlTable),
|
|
234
|
+
merchantChargeRelations: getMerchantChargeRelationsSchema(mysqlTable),
|
|
235
|
+
merchantEvents: getMerchantEventsSchema(mysqlTable),
|
|
236
|
+
merchantEventsRelations: getMerchantEventsRelationsSchema(mysqlTable),
|
|
237
|
+
merchantCoupon: getMerchantCouponSchema(mysqlTable),
|
|
238
|
+
merchantCustomer: getMerchantCustomerSchema(mysqlTable),
|
|
239
|
+
merchantPrice: getMerchantPriceSchema(mysqlTable),
|
|
240
|
+
merchantProduct: getMerchantProductSchema(mysqlTable),
|
|
241
|
+
merchantSession: getMerchantSessionSchema(mysqlTable),
|
|
242
|
+
prices: getPriceSchema(mysqlTable),
|
|
243
|
+
products: getProductSchema(mysqlTable),
|
|
244
|
+
purchases: getPurchaseSchema(mysqlTable),
|
|
245
|
+
purchaseRelations: getPurchaseRelationsSchema(
|
|
246
|
+
mysqlTable,
|
|
247
|
+
userRelationsOverrides,
|
|
248
|
+
),
|
|
249
|
+
purchaseUserTransfer: getPurchaseUserTransferSchema(mysqlTable),
|
|
250
|
+
purchaseUserTransferRelations: getPurchaseUserTransferRelationsSchema(
|
|
251
|
+
mysqlTable,
|
|
252
|
+
userRelationsOverrides,
|
|
253
|
+
),
|
|
254
|
+
communicationChannel: getCommunicationChannelSchema(mysqlTable),
|
|
255
|
+
communicationPreferenceTypes:
|
|
256
|
+
getCommunicationPreferenceTypesSchema(mysqlTable),
|
|
257
|
+
communicationPreferences: getCommunicationPreferencesSchema(mysqlTable),
|
|
258
|
+
communicationPreferencesRelations:
|
|
259
|
+
getCommunicationPreferencesRelationsSchema(
|
|
260
|
+
mysqlTable,
|
|
261
|
+
userRelationsOverrides,
|
|
262
|
+
),
|
|
263
|
+
contentContributions: getContentContributionsSchema(mysqlTable),
|
|
264
|
+
contentContributionRelations: getContentContributionRelationsSchema(
|
|
265
|
+
mysqlTable,
|
|
266
|
+
userRelationsOverrides,
|
|
267
|
+
),
|
|
268
|
+
contentResource: getContentResourceSchema(mysqlTable),
|
|
269
|
+
contentResourceVersion: getContentResourceVersionSchema(mysqlTable),
|
|
270
|
+
contentResourceVersionRelations: getContentResourceVersionRelationsSchema(
|
|
271
|
+
mysqlTable,
|
|
272
|
+
userRelationsOverrides,
|
|
273
|
+
),
|
|
274
|
+
contentResourceRelations: getContentResourceRelationsSchema(
|
|
275
|
+
mysqlTable,
|
|
276
|
+
userRelationsOverrides,
|
|
277
|
+
),
|
|
278
|
+
contentResourceResource: getContentResourceResourceSchema(mysqlTable),
|
|
279
|
+
contentResourceResourceRelations:
|
|
280
|
+
getContentResourceResourceRelationsSchema(mysqlTable),
|
|
281
|
+
contentResourceTag: getContentResourceTagSchema(mysqlTable),
|
|
282
|
+
contentResourceTagRelations:
|
|
283
|
+
getContentResourceTagRelationsSchema(mysqlTable),
|
|
284
|
+
contributionTypes: getContributionTypesSchema(mysqlTable),
|
|
285
|
+
contributionTypesRelations: getContributionTypesRelationsSchema(mysqlTable),
|
|
286
|
+
resourceProgress: getResourceProgressSchema(mysqlTable),
|
|
287
|
+
questionResponse: getQuestionResponseSchema(mysqlTable),
|
|
288
|
+
questionResponseRelations: getQuestionResponseRelationsSchema(
|
|
289
|
+
mysqlTable,
|
|
290
|
+
userRelationsOverrides,
|
|
291
|
+
),
|
|
292
|
+
upgradableProducts: getUpgradableProductsSchema(mysqlTable),
|
|
293
|
+
upgradableProductsRelations:
|
|
294
|
+
getUpgradableProductsRelationsSchema(mysqlTable),
|
|
295
|
+
contentResourceProduct: getContentResourceProductSchema(mysqlTable),
|
|
296
|
+
contentResourceProductRelations:
|
|
297
|
+
getContentResourceProductRelationsSchema(mysqlTable),
|
|
298
|
+
productRelations: getProductRelationsSchema(mysqlTable),
|
|
299
|
+
comments: getCommentsSchema(mysqlTable),
|
|
300
|
+
commentsRelations: getCommentRelationsSchema(
|
|
301
|
+
mysqlTable,
|
|
302
|
+
userRelationsOverrides,
|
|
303
|
+
),
|
|
304
|
+
deviceVerifications: getDeviceVerificationSchema(mysqlTable),
|
|
305
|
+
deviceVerificationRelations: getDeviceVerificationRelationsSchema(
|
|
306
|
+
mysqlTable,
|
|
307
|
+
userRelationsOverrides,
|
|
308
|
+
),
|
|
309
|
+
deviceAccessToken: getDeviceAccessTokenSchema(mysqlTable),
|
|
310
|
+
deviceAccessTokenRelations: getDeviceAccessTokenRelationsSchema(
|
|
311
|
+
mysqlTable,
|
|
312
|
+
userRelationsOverrides,
|
|
313
|
+
),
|
|
314
|
+
personalAccessToken: getPersonalAccessTokenSchema(mysqlTable),
|
|
315
|
+
personalAccessTokenRelations: getPersonalAccessTokenRelationsSchema(
|
|
316
|
+
mysqlTable,
|
|
317
|
+
userRelationsOverrides,
|
|
318
|
+
),
|
|
319
|
+
tag: getTagSchema(mysqlTable),
|
|
320
|
+
tagRelations: getTagRelationsSchema(mysqlTable),
|
|
321
|
+
tagTag: getTagTagSchema(mysqlTable),
|
|
322
|
+
tagTagRelations: getTagTagRelationsSchema(mysqlTable),
|
|
323
|
+
userPrefs: getUserPrefsSchema(mysqlTable),
|
|
324
|
+
userPrefsRelations: getUserPrefsRelationsSchema(
|
|
325
|
+
mysqlTable,
|
|
326
|
+
userRelationsOverrides,
|
|
327
|
+
),
|
|
328
|
+
organization: getOrganizationsSchema(mysqlTable),
|
|
329
|
+
organizationRelations: getOrganizationsRelationsSchema(mysqlTable),
|
|
330
|
+
organizationMemberships: getOrganizationMembershipsSchema(mysqlTable),
|
|
331
|
+
organizationMembershipRelations: getOrganizationMembershipsRelationsSchema(
|
|
332
|
+
mysqlTable,
|
|
333
|
+
userRelationsOverrides,
|
|
334
|
+
),
|
|
335
|
+
organizationMembershipRoles:
|
|
336
|
+
getOrganizationMembershipRolesSchema(mysqlTable),
|
|
337
|
+
organizationMembershipRolesRelations:
|
|
338
|
+
getOrganizationMembershipRolesRelationsSchema(mysqlTable),
|
|
339
|
+
merchantSubscription: getMerchantSubscriptionSchema(mysqlTable),
|
|
340
|
+
merchantSubscriptionRelations:
|
|
341
|
+
getMerchantSubscriptionRelationsSchema(mysqlTable),
|
|
342
|
+
subscription: getSubscriptionSchema(mysqlTable),
|
|
343
|
+
subscriptionRelations: getSubscriptionRelationsSchema(mysqlTable),
|
|
344
|
+
profiles: getProfilesSchema(mysqlTable),
|
|
345
|
+
profilesRelations: getProfilesRelationsSchema(
|
|
346
|
+
mysqlTable,
|
|
347
|
+
userRelationsOverrides,
|
|
348
|
+
),
|
|
349
|
+
entitlementTypes: getEntitlementTypesSchema(mysqlTable),
|
|
350
|
+
entitlements: getEntitlementsSchema(mysqlTable),
|
|
351
|
+
entitlementsRelations: getEntitlementRelationsSchema(
|
|
352
|
+
mysqlTable,
|
|
353
|
+
userRelationsOverrides,
|
|
354
|
+
),
|
|
355
|
+
} as const
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Creates the default Course Builder MySQL schema.
|
|
360
|
+
*
|
|
361
|
+
* @param mySqlTable - Drizzle table factory used for every schema object.
|
|
362
|
+
* @returns The complete default table and relation set.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```ts
|
|
366
|
+
* const tables = createTables(mysqlTable)
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
export function createTables(mySqlTable: MySqlTableFn) {
|
|
370
|
+
return getCourseBuilderSchema(mySqlTable)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** Default schema type shared by MySQL adapter factories. */
|
|
374
|
+
export type DefaultSchema = ReturnType<typeof createTables>
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
mysqlEnum,
|
|
6
6
|
MySqlTableFn,
|
|
7
7
|
timestamp,
|
|
8
|
+
uniqueIndex,
|
|
8
9
|
varchar,
|
|
9
10
|
} from 'drizzle-orm/mysql-core'
|
|
10
11
|
|
|
@@ -22,6 +23,9 @@ export function getOrganizationMembershipsSchema(mysqlTable: MySqlTableFn) {
|
|
|
22
23
|
role: varchar('role', { length: 191 }).notNull().default('user'),
|
|
23
24
|
invitedById: varchar('invitedById', { length: 255 }).notNull(),
|
|
24
25
|
userId: varchar('userId', { length: 255 }).notNull(),
|
|
26
|
+
personalOrganizationUserId: varchar('personalOrganizationUserId', {
|
|
27
|
+
length: 255,
|
|
28
|
+
}),
|
|
25
29
|
fields: json('fields').$type<Record<string, any>>().default({}),
|
|
26
30
|
createdAt: timestamp('createdAt', {
|
|
27
31
|
mode: 'date',
|
|
@@ -36,6 +40,9 @@ export function getOrganizationMembershipsSchema(mysqlTable: MySqlTableFn) {
|
|
|
36
40
|
organizationIdIdx: index('organizationId_idx').on(
|
|
37
41
|
organizationMembership.organizationId,
|
|
38
42
|
),
|
|
43
|
+
personalOrganizationUserIdIdx: uniqueIndex(
|
|
44
|
+
'personalOrganizationUserId_idx',
|
|
45
|
+
).on(organizationMembership.personalOrganizationUserId),
|
|
39
46
|
}),
|
|
40
47
|
)
|
|
41
48
|
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
mysqlEnum,
|
|
6
6
|
MySqlTableFn,
|
|
7
7
|
timestamp,
|
|
8
|
+
uniqueIndex,
|
|
8
9
|
varchar,
|
|
9
10
|
} from 'drizzle-orm/mysql-core'
|
|
10
11
|
|
|
@@ -18,6 +19,10 @@ export function getOrganizationsSchema(mysqlTable: MySqlTableFn) {
|
|
|
18
19
|
{
|
|
19
20
|
id: varchar('id', { length: 255 }).notNull().primaryKey(),
|
|
20
21
|
name: varchar('name', { length: 255 }),
|
|
22
|
+
// ADR-0012 P3: identity is stable even when email/name presentation changes.
|
|
23
|
+
personalOrganizationUserId: varchar('personalOrganizationUserId', {
|
|
24
|
+
length: 255,
|
|
25
|
+
}),
|
|
21
26
|
fields: json('fields').$type<Record<string, any>>().default({}),
|
|
22
27
|
image: varchar('image', { length: 255 }),
|
|
23
28
|
createdAt: timestamp('createdAt', {
|
|
@@ -27,6 +32,9 @@ export function getOrganizationsSchema(mysqlTable: MySqlTableFn) {
|
|
|
27
32
|
},
|
|
28
33
|
(organization) => ({
|
|
29
34
|
createdAtIdx: index('created_at_idx').on(organization.createdAt),
|
|
35
|
+
personalOrganizationUserIdIdx: uniqueIndex(
|
|
36
|
+
'personalOrganizationUserId_idx',
|
|
37
|
+
).on(organization.personalOrganizationUserId),
|
|
30
38
|
}),
|
|
31
39
|
)
|
|
32
40
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { customAlphabet } from 'nanoid'
|
|
2
|
+
|
|
3
|
+
export const guid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 5)
|
|
4
|
+
|
|
5
|
+
export const normalizeExpirationDate = (date: Date | undefined) => {
|
|
6
|
+
if (!date) return undefined
|
|
7
|
+
|
|
8
|
+
// Create a new Date object for 23:59:59 UTC on the date part of the input date
|
|
9
|
+
// The input date should be a JS Date representing 00:00:00 LA time for the chosen day.
|
|
10
|
+
// Its UTC date parts (getUTCFullYear, etc.) will give us the correct calendar day.
|
|
11
|
+
return new Date(
|
|
12
|
+
Date.UTC(
|
|
13
|
+
date.getUTCFullYear(),
|
|
14
|
+
date.getUTCMonth(), // 0-indexed
|
|
15
|
+
date.getUTCDate(),
|
|
16
|
+
23, // hours
|
|
17
|
+
59, // minutes
|
|
18
|
+
59, // seconds
|
|
19
|
+
0, // milliseconds
|
|
20
|
+
),
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import slugify from '@sindresorhus/slugify'
|
|
2
|
+
import { asc, eq } from 'drizzle-orm'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
CatalogPort,
|
|
6
|
+
ContentResourcePort,
|
|
7
|
+
CouponPort,
|
|
8
|
+
} from '@coursebuilder/core/ports'
|
|
9
|
+
import {
|
|
10
|
+
ContentResourceSchema,
|
|
11
|
+
type ContentResource,
|
|
12
|
+
} from '@coursebuilder/core/schemas/content-resource-schema'
|
|
13
|
+
import { logger as baseLogger } from '@coursebuilder/utils/logger'
|
|
14
|
+
|
|
15
|
+
import type { MySqlContext } from '../context.js'
|
|
16
|
+
import {
|
|
17
|
+
guid,
|
|
18
|
+
normalizeExpirationDate,
|
|
19
|
+
} from './content-resource-workflow-utils.js'
|
|
20
|
+
|
|
21
|
+
const logger = baseLogger as unknown as {
|
|
22
|
+
debug: (message: string, attrs?: Record<string, unknown>) => void
|
|
23
|
+
error: (error: Error, attrs?: Record<string, unknown>) => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type CreateCohortOperations = Pick<CatalogPort, 'createProduct'> &
|
|
27
|
+
Pick<CouponPort, 'createCoupon'>
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates the private cohort creation workflow.
|
|
31
|
+
*
|
|
32
|
+
* @param context - The shared MySQL client and table set.
|
|
33
|
+
* @param operations - Narrow catalog, coupon, and content resource operations.
|
|
34
|
+
* @returns The content resource creation operation.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const workflow = createCohortWorkflow(context, operations)
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function createCohortWorkflow(
|
|
42
|
+
{ client, tables }: MySqlContext,
|
|
43
|
+
operations: CreateCohortOperations,
|
|
44
|
+
): Pick<ContentResourcePort, 'createCohort'> {
|
|
45
|
+
const {
|
|
46
|
+
contentResource,
|
|
47
|
+
contentResourceResource,
|
|
48
|
+
contentResourceProduct,
|
|
49
|
+
contentResourceTag,
|
|
50
|
+
} = tables
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
async createCohort(
|
|
54
|
+
input: {
|
|
55
|
+
cohort: {
|
|
56
|
+
title: string
|
|
57
|
+
description?: string
|
|
58
|
+
tagIds?:
|
|
59
|
+
| { id: string; fields: { label: string; name: string } }[]
|
|
60
|
+
| null
|
|
61
|
+
}
|
|
62
|
+
dates: {
|
|
63
|
+
start: Date
|
|
64
|
+
end: Date
|
|
65
|
+
}
|
|
66
|
+
createProduct?: boolean
|
|
67
|
+
pricing: {
|
|
68
|
+
price?: number | null
|
|
69
|
+
}
|
|
70
|
+
coupon?: {
|
|
71
|
+
enabled: boolean
|
|
72
|
+
percentageDiscount?: string
|
|
73
|
+
expires?: Date
|
|
74
|
+
}
|
|
75
|
+
workshops: { id: string }[]
|
|
76
|
+
},
|
|
77
|
+
userId: string,
|
|
78
|
+
) {
|
|
79
|
+
const hash = guid()
|
|
80
|
+
const cohortId = `cohort~${hash}`
|
|
81
|
+
|
|
82
|
+
// Transaction only handles database operations
|
|
83
|
+
const cohort = await client.transaction(async (tx) => {
|
|
84
|
+
// Create cohort content resource
|
|
85
|
+
await tx.insert(contentResource).values({
|
|
86
|
+
id: cohortId,
|
|
87
|
+
type: 'cohort',
|
|
88
|
+
createdById: userId,
|
|
89
|
+
fields: {
|
|
90
|
+
title: input.cohort.title,
|
|
91
|
+
description: input.cohort.description,
|
|
92
|
+
state: 'draft',
|
|
93
|
+
visibility: 'unlisted',
|
|
94
|
+
slug: slugify(`${input.cohort.title}~${hash}`),
|
|
95
|
+
startsAt: input.dates.start,
|
|
96
|
+
endsAt: input.dates.end,
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
// Fetch created cohort
|
|
101
|
+
const cohort = await tx.query.contentResource.findFirst({
|
|
102
|
+
where: eq(contentResource.id, cohortId),
|
|
103
|
+
with: {
|
|
104
|
+
resources: {
|
|
105
|
+
with: {
|
|
106
|
+
resource: true,
|
|
107
|
+
},
|
|
108
|
+
orderBy: asc(contentResourceResource.position),
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
if (!cohort) {
|
|
114
|
+
throw new Error('Failed to create cohort')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const parsedCohort = ContentResourceSchema.safeParse(cohort)
|
|
118
|
+
if (!parsedCohort.success) {
|
|
119
|
+
throw new Error('Invalid cohort data')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Associate tags with cohort
|
|
123
|
+
if (input.cohort.tagIds) {
|
|
124
|
+
await tx.insert(contentResourceTag).values(
|
|
125
|
+
input.cohort.tagIds.map((tag) => ({
|
|
126
|
+
contentResourceId: cohortId,
|
|
127
|
+
tagId: tag.id,
|
|
128
|
+
createdAt: new Date(),
|
|
129
|
+
updatedAt: new Date(),
|
|
130
|
+
position: 0,
|
|
131
|
+
})),
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Link workshops to cohort
|
|
136
|
+
let position = 0
|
|
137
|
+
for (const workshop of input.workshops) {
|
|
138
|
+
await tx.insert(contentResourceResource).values({
|
|
139
|
+
resourceOfId: cohortId,
|
|
140
|
+
resourceId: workshop.id,
|
|
141
|
+
position,
|
|
142
|
+
})
|
|
143
|
+
position++
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return parsedCohort.data
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// Handle product and coupon creation outside transaction
|
|
150
|
+
let product: any = null
|
|
151
|
+
if (
|
|
152
|
+
input.createProduct &&
|
|
153
|
+
input.pricing.price &&
|
|
154
|
+
input.pricing.price > 0
|
|
155
|
+
) {
|
|
156
|
+
try {
|
|
157
|
+
product = await operations.createProduct({
|
|
158
|
+
name: input.cohort.title,
|
|
159
|
+
price: input.pricing.price,
|
|
160
|
+
quantityAvailable: -1,
|
|
161
|
+
type: 'cohort',
|
|
162
|
+
state: 'published',
|
|
163
|
+
visibility: 'public',
|
|
164
|
+
openEnrollment: new Date().toISOString(),
|
|
165
|
+
closeEnrollment: input.dates.start.toISOString(),
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
if (product) {
|
|
169
|
+
// Link product to cohort resource
|
|
170
|
+
await client.insert(contentResourceProduct).values({
|
|
171
|
+
resourceId: cohortId,
|
|
172
|
+
productId: product.id,
|
|
173
|
+
position: 0,
|
|
174
|
+
metadata: {
|
|
175
|
+
addedBy: userId,
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
// Create coupon if enabled
|
|
180
|
+
if (
|
|
181
|
+
input.coupon?.enabled &&
|
|
182
|
+
input.coupon.percentageDiscount &&
|
|
183
|
+
input.coupon.expires
|
|
184
|
+
) {
|
|
185
|
+
try {
|
|
186
|
+
const finalExpires = normalizeExpirationDate(
|
|
187
|
+
input.coupon.expires,
|
|
188
|
+
)
|
|
189
|
+
await operations.createCoupon({
|
|
190
|
+
percentageDiscount: input.coupon.percentageDiscount,
|
|
191
|
+
expires: finalExpires || null,
|
|
192
|
+
restrictedToProductId: product.id,
|
|
193
|
+
default: true,
|
|
194
|
+
maxUses: -1,
|
|
195
|
+
quantity: '-1',
|
|
196
|
+
status: 1,
|
|
197
|
+
fields: {},
|
|
198
|
+
})
|
|
199
|
+
logger.debug('cohort.create.coupon.success', {
|
|
200
|
+
cohortId,
|
|
201
|
+
productId: product.id,
|
|
202
|
+
userId,
|
|
203
|
+
percentageDiscount: input.coupon.percentageDiscount,
|
|
204
|
+
})
|
|
205
|
+
} catch (couponError) {
|
|
206
|
+
logger.error(
|
|
207
|
+
new Error(
|
|
208
|
+
`Failed to create coupon for cohort: ${couponError}`,
|
|
209
|
+
),
|
|
210
|
+
)
|
|
211
|
+
logger.debug('cohort.create.coupon.failed', {
|
|
212
|
+
cohortId,
|
|
213
|
+
productId: product.id,
|
|
214
|
+
userId,
|
|
215
|
+
})
|
|
216
|
+
// Don't throw - cohort creation should succeed even if coupon fails
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
} catch (productError) {
|
|
221
|
+
logger.error(
|
|
222
|
+
new Error(`Failed to create product for cohort: ${productError}`),
|
|
223
|
+
)
|
|
224
|
+
logger.debug('cohort.create.product.failed', {
|
|
225
|
+
cohortId,
|
|
226
|
+
userId,
|
|
227
|
+
price: input.pricing.price,
|
|
228
|
+
})
|
|
229
|
+
// Don't throw - cohort creation should succeed even if product fails
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
cohort,
|
|
235
|
+
product,
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
}
|
|
239
|
+
}
|