@coursebuilder/adapter-drizzle 0.0.7 → 0.1.0
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-ICL7XZ2Y.js → chunk-27KREOQW.js} +4 -4
- package/dist/{chunk-KVN3JV7C.js → chunk-44VDBYFU.js} +6 -6
- package/dist/{chunk-VEFCDI73.js → chunk-75V6F7LZ.js} +12 -12
- package/dist/{chunk-SQR6UWVO.js → chunk-7LAAAEVE.js} +165 -11
- package/dist/{chunk-TA6VLEV5.js → chunk-AFQGYW7Z.js} +4 -4
- package/dist/{chunk-US2EXVMI.js → chunk-CPE4P26C.js} +4 -4
- package/dist/chunk-GVURJJRV.js +4679 -0
- package/dist/{chunk-VZABQCFH.js → chunk-IN6G6MTW.js} +4 -4
- package/dist/{chunk-4HDU7QIB.js → chunk-ISURSRBK.js} +345 -324
- package/dist/{chunk-AIDEJDKJ.js → chunk-JKRFXYAR.js} +4 -4
- package/dist/{chunk-KI47TR7F.js → chunk-L2TQQYG4.js} +4 -4
- package/dist/{chunk-UY3DVPP3.js → chunk-LSOPFMDB.js} +4 -4
- package/dist/{chunk-PFN4YUQZ.js → chunk-MYRB6GLJ.js} +4 -3
- package/dist/chunk-NZDLUQWP.js +44 -0
- package/dist/{chunk-22KIKVBY.js → chunk-O2KKII62.js} +163 -10
- package/dist/{chunk-MBQ3TMHH.js → chunk-OIUOQ3TT.js} +4 -4
- package/dist/chunk-QZOBGJSV.js +78 -0
- package/dist/chunk-RVYJDDZD.js +75 -0
- package/dist/chunk-V6QEDDFG.js +49 -0
- package/dist/{chunk-FRNVLW7N.js → chunk-Y34AIPU7.js} +34 -303
- package/dist/index.js +21 -17
- package/dist/lib/mysql/index.cjs +5896 -1367
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.ts +325 -129
- package/dist/lib/mysql/index.js +19 -15
- package/dist/lib/mysql/schemas/auth/accounts.cjs +73 -57
- package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/accounts.js +7 -1
- package/dist/lib/mysql/schemas/auth/permissions.cjs +9 -98
- package/dist/lib/mysql/schemas/auth/permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/permissions.d.ts +1 -3
- package/dist/lib/mysql/schemas/auth/permissions.js +1 -3
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs +64 -43
- package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/role-permissions.js +8 -1
- package/dist/lib/mysql/schemas/auth/roles.cjs +63 -46
- package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/roles.js +7 -1
- package/dist/lib/mysql/schemas/auth/sessions.cjs +63 -47
- package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/sessions.js +8 -2
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs +97 -82
- package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-permissions.js +7 -1
- package/dist/lib/mysql/schemas/auth/user-roles.cjs +65 -48
- package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/user-roles.js +7 -1
- package/dist/lib/mysql/schemas/auth/users.cjs +233 -132
- package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
- package/dist/lib/mysql/schemas/auth/users.d.ts +2 -1
- package/dist/lib/mysql/schemas/auth/users.js +7 -1
- package/dist/lib/mysql/schemas/commerce/coupon.cjs +4 -4
- package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/coupon.d.ts +6 -6
- package/dist/lib/mysql/schemas/commerce/coupon.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-account.cjs +2 -2
- package/dist/lib/mysql/schemas/commerce/merchant-account.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-account.d.ts +3 -3
- package/dist/lib/mysql/schemas/commerce/merchant-account.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs +2 -2
- package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-charge.d.ts +3 -3
- package/dist/lib/mysql/schemas/commerce/merchant-charge.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs +2 -2
- package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-customer.d.ts +3 -3
- package/dist/lib/mysql/schemas/commerce/merchant-customer.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-price.cjs +2 -2
- package/dist/lib/mysql/schemas/commerce/merchant-price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-price.d.ts +3 -3
- package/dist/lib/mysql/schemas/commerce/merchant-price.js +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-product.cjs +2 -2
- package/dist/lib/mysql/schemas/commerce/merchant-product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/merchant-product.d.ts +3 -3
- package/dist/lib/mysql/schemas/commerce/merchant-product.js +1 -1
- package/dist/lib/mysql/schemas/commerce/price.cjs +2 -2
- package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/price.d.ts +3 -3
- package/dist/lib/mysql/schemas/commerce/price.js +1 -1
- package/dist/lib/mysql/schemas/commerce/product.cjs +2 -2
- package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/product.d.ts +3 -3
- package/dist/lib/mysql/schemas/commerce/product.js +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs +10 -10
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.ts +15 -15
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase.cjs +320 -21
- package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
- package/dist/lib/mysql/schemas/commerce/purchase.d.ts +12 -4
- package/dist/lib/mysql/schemas/commerce/purchase.js +11 -1
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs +130 -0
- package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -0
- package/dist/lib/mysql/schemas/commerce/upgradable-products.d.ts +101 -0
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js +11 -0
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js.map +1 -0
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +90 -72
- package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
- package/dist/lib/mysql/schemas/communication/communication-preferences.js +7 -1
- package/dist/lib/mysql/schemas/content/content-contributions.cjs +94 -76
- package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-contributions.js +7 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs +68 -53
- package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.d.ts +1 -1
- package/dist/lib/mysql/schemas/content/content-resource-resource.js +7 -1
- package/dist/lib/mysql/schemas/content/content-resource.cjs +81 -103
- package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/content-resource.d.ts +0 -1
- package/dist/lib/mysql/schemas/content/content-resource.js +7 -1
- package/dist/lib/mysql/schemas/content/contribution-types.cjs +11 -102
- package/dist/lib/mysql/schemas/content/contribution-types.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/contribution-types.d.ts +1 -3
- package/dist/lib/mysql/schemas/content/contribution-types.js +1 -3
- package/dist/lib/mysql/schemas/content/resource-progress.cjs +3 -3
- package/dist/lib/mysql/schemas/content/resource-progress.cjs.map +1 -1
- package/dist/lib/mysql/schemas/content/resource-progress.d.ts +9 -9
- package/dist/lib/mysql/schemas/content/resource-progress.js +1 -1
- package/dist/lib/mysql/utils.cjs +51 -0
- package/dist/lib/mysql/utils.cjs.map +1 -0
- package/dist/lib/mysql/utils.d.ts +12 -0
- package/dist/lib/mysql/utils.js +29 -0
- package/dist/lib/mysql/utils.js.map +1 -0
- package/dist/lib/pg.cjs +4289 -9
- package/dist/lib/pg.cjs.map +1 -1
- package/dist/lib/pg.d.ts +91 -0
- package/dist/lib/pg.js +2 -1
- package/dist/lib/sqlite.cjs +4285 -8
- package/dist/lib/sqlite.cjs.map +1 -1
- package/dist/lib/sqlite.js +2 -1
- package/package.json +6 -4
- package/src/lib/mysql/index.ts +688 -34
- package/src/lib/mysql/schemas/auth/accounts.ts +5 -1
- package/src/lib/mysql/schemas/auth/permissions.ts +1 -3
- package/src/lib/mysql/schemas/auth/role-permissions.ts +2 -0
- package/src/lib/mysql/schemas/auth/roles.ts +1 -1
- package/src/lib/mysql/schemas/auth/sessions.ts +5 -1
- package/src/lib/mysql/schemas/auth/user-permissions.ts +2 -0
- package/src/lib/mysql/schemas/auth/user-roles.ts +2 -0
- package/src/lib/mysql/schemas/auth/users.ts +23 -6
- package/src/lib/mysql/schemas/commerce/coupon.ts +3 -3
- package/src/lib/mysql/schemas/commerce/merchant-account.ts +2 -2
- package/src/lib/mysql/schemas/commerce/merchant-charge.ts +2 -2
- package/src/lib/mysql/schemas/commerce/merchant-customer.ts +2 -2
- package/src/lib/mysql/schemas/commerce/merchant-price.ts +2 -2
- package/src/lib/mysql/schemas/commerce/merchant-product.ts +2 -2
- package/src/lib/mysql/schemas/commerce/price.ts +2 -2
- package/src/lib/mysql/schemas/commerce/product.ts +2 -2
- package/src/lib/mysql/schemas/commerce/purchase-user-transfer.ts +6 -6
- package/src/lib/mysql/schemas/commerce/purchase.ts +49 -3
- package/src/lib/mysql/schemas/commerce/upgradable-products.ts +58 -0
- package/src/lib/mysql/schemas/communication/communication-preferences.ts +3 -0
- package/src/lib/mysql/schemas/content/content-contributions.ts +3 -0
- package/src/lib/mysql/schemas/content/content-resource-resource.ts +1 -1
- package/src/lib/mysql/schemas/content/content-resource.ts +1 -2
- package/src/lib/mysql/schemas/content/contribution-types.ts +1 -4
- package/src/lib/mysql/schemas/content/resource-progress.ts +3 -3
- package/src/lib/mysql/utils.ts +23 -0
- package/src/lib/pg.ts +298 -16
- package/src/lib/sqlite.ts +290 -15
- package/dist/chunk-BRGTUNY2.js +0 -78
package/src/lib/pg.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
AdapterSession,
|
|
4
4
|
AdapterUser,
|
|
5
5
|
} from '@auth/core/adapters'
|
|
6
|
-
import { and, eq } from 'drizzle-orm'
|
|
6
|
+
import { and, asc, eq } from 'drizzle-orm'
|
|
7
7
|
import {
|
|
8
8
|
pgTable as defaultPgTableFn,
|
|
9
9
|
integer,
|
|
@@ -18,6 +18,21 @@ import {
|
|
|
18
18
|
} from 'drizzle-orm/pg-core'
|
|
19
19
|
|
|
20
20
|
import { type CourseBuilderAdapter } from '@coursebuilder/core/adapters'
|
|
21
|
+
import {
|
|
22
|
+
Coupon,
|
|
23
|
+
MerchantCoupon,
|
|
24
|
+
MerchantCustomer,
|
|
25
|
+
MerchantProduct,
|
|
26
|
+
Price,
|
|
27
|
+
Product,
|
|
28
|
+
Purchase,
|
|
29
|
+
PurchaseUserTransfer,
|
|
30
|
+
PurchaseUserTransferState,
|
|
31
|
+
ResourceProgress,
|
|
32
|
+
UpgradableProduct,
|
|
33
|
+
User,
|
|
34
|
+
} from '@coursebuilder/core/schemas'
|
|
35
|
+
import { ContentResourceSchema } from '@coursebuilder/core/schemas/content-resource-schema'
|
|
21
36
|
|
|
22
37
|
export function createTables(pgTable: PgTableFn) {
|
|
23
38
|
const users = pgTable('user', {
|
|
@@ -123,7 +138,14 @@ export function createTables(pgTable: PgTableFn) {
|
|
|
123
138
|
}),
|
|
124
139
|
)
|
|
125
140
|
|
|
126
|
-
return {
|
|
141
|
+
return {
|
|
142
|
+
users,
|
|
143
|
+
accounts,
|
|
144
|
+
sessions,
|
|
145
|
+
verificationTokens,
|
|
146
|
+
contentResource,
|
|
147
|
+
contentResourceResource,
|
|
148
|
+
}
|
|
127
149
|
}
|
|
128
150
|
|
|
129
151
|
export type DefaultSchema = ReturnType<typeof createTables>
|
|
@@ -132,10 +154,219 @@ export function pgDrizzleAdapter(
|
|
|
132
154
|
client: InstanceType<typeof PgDatabase>,
|
|
133
155
|
tableFn = defaultPgTableFn,
|
|
134
156
|
): CourseBuilderAdapter {
|
|
135
|
-
const {
|
|
136
|
-
|
|
157
|
+
const {
|
|
158
|
+
users,
|
|
159
|
+
accounts,
|
|
160
|
+
sessions,
|
|
161
|
+
verificationTokens,
|
|
162
|
+
contentResource,
|
|
163
|
+
contentResourceResource,
|
|
164
|
+
} = createTables(tableFn)
|
|
137
165
|
|
|
138
166
|
return {
|
|
167
|
+
client,
|
|
168
|
+
async createPurchase(options): Promise<Purchase> {
|
|
169
|
+
throw new Error('Method not implemented.')
|
|
170
|
+
},
|
|
171
|
+
availableUpgradesForProduct(
|
|
172
|
+
purchases: any,
|
|
173
|
+
productId: string,
|
|
174
|
+
): Promise<
|
|
175
|
+
{
|
|
176
|
+
upgradableTo: { id: string; name: string }
|
|
177
|
+
upgradableFrom: { id: string; name: string }
|
|
178
|
+
}[]
|
|
179
|
+
> {
|
|
180
|
+
return Promise.resolve([])
|
|
181
|
+
},
|
|
182
|
+
clearLessonProgressForUser(options: {
|
|
183
|
+
userId: string
|
|
184
|
+
lessons: { id: string; slug: string }[]
|
|
185
|
+
}): Promise<void> {
|
|
186
|
+
return Promise.resolve(undefined)
|
|
187
|
+
},
|
|
188
|
+
completeLessonProgressForUser(options: {
|
|
189
|
+
userId: string
|
|
190
|
+
lessonId?: string
|
|
191
|
+
}): Promise<ResourceProgress | null> {
|
|
192
|
+
return Promise.resolve(null)
|
|
193
|
+
},
|
|
194
|
+
couponForIdOrCode(options: {
|
|
195
|
+
code?: string
|
|
196
|
+
couponId?: string
|
|
197
|
+
}): Promise<(Coupon & { merchantCoupon: MerchantCoupon }) | null> {
|
|
198
|
+
return Promise.resolve(null)
|
|
199
|
+
},
|
|
200
|
+
createMerchantChargeAndPurchase(options: {
|
|
201
|
+
userId: string
|
|
202
|
+
productId: string
|
|
203
|
+
stripeChargeId: string
|
|
204
|
+
stripeCouponId?: string
|
|
205
|
+
merchantAccountId: string
|
|
206
|
+
merchantProductId: string
|
|
207
|
+
merchantCustomerId: string
|
|
208
|
+
stripeChargeAmount: number
|
|
209
|
+
quantity?: number
|
|
210
|
+
bulk?: boolean
|
|
211
|
+
checkoutSessionId: string
|
|
212
|
+
appliedPPPStripeCouponId: string | undefined
|
|
213
|
+
upgradedFromPurchaseId: string | undefined
|
|
214
|
+
usedCouponId: string | undefined
|
|
215
|
+
country?: string
|
|
216
|
+
}): Promise<Purchase> {
|
|
217
|
+
throw new Error('Method not implemented.')
|
|
218
|
+
},
|
|
219
|
+
findOrCreateMerchantCustomer(options: {
|
|
220
|
+
user: User
|
|
221
|
+
identifier: string
|
|
222
|
+
merchantAccountId: string
|
|
223
|
+
}): Promise<MerchantCustomer | null> {
|
|
224
|
+
return Promise.resolve(null)
|
|
225
|
+
},
|
|
226
|
+
findOrCreateUser(
|
|
227
|
+
email: string,
|
|
228
|
+
name?: string | null,
|
|
229
|
+
): Promise<{
|
|
230
|
+
user: User
|
|
231
|
+
isNewUser: boolean
|
|
232
|
+
}> {
|
|
233
|
+
throw new Error('Method not implemented.')
|
|
234
|
+
},
|
|
235
|
+
getCoupon(couponIdOrCode: string): Promise<Coupon | null> {
|
|
236
|
+
return Promise.resolve(null)
|
|
237
|
+
},
|
|
238
|
+
getCouponWithBulkPurchases(couponId: string): Promise<
|
|
239
|
+
| (Coupon & {
|
|
240
|
+
bulkCouponPurchases: { bulkCouponId: string }[]
|
|
241
|
+
})
|
|
242
|
+
| null
|
|
243
|
+
> {
|
|
244
|
+
return Promise.resolve(null)
|
|
245
|
+
},
|
|
246
|
+
getDefaultCoupon(productIds?: string[]): Promise<{
|
|
247
|
+
defaultMerchantCoupon: MerchantCoupon
|
|
248
|
+
defaultCoupon: Coupon
|
|
249
|
+
} | null> {
|
|
250
|
+
return Promise.resolve(null)
|
|
251
|
+
},
|
|
252
|
+
getLessonProgressCountsByDate(): Promise<
|
|
253
|
+
{
|
|
254
|
+
count: number
|
|
255
|
+
completedAt: string
|
|
256
|
+
}[]
|
|
257
|
+
> {
|
|
258
|
+
return Promise.resolve([])
|
|
259
|
+
},
|
|
260
|
+
getLessonProgressForUser(userId: string): Promise<ResourceProgress[]> {
|
|
261
|
+
return Promise.resolve([])
|
|
262
|
+
},
|
|
263
|
+
getLessonProgresses(): Promise<ResourceProgress[]> {
|
|
264
|
+
return Promise.resolve([])
|
|
265
|
+
},
|
|
266
|
+
getMerchantCharge(merchantChargeId: string): Promise<{
|
|
267
|
+
id: string
|
|
268
|
+
identifier: string
|
|
269
|
+
merchantProductId: string
|
|
270
|
+
} | null> {
|
|
271
|
+
return Promise.resolve(null)
|
|
272
|
+
},
|
|
273
|
+
getMerchantCoupon(
|
|
274
|
+
merchantCouponId: string,
|
|
275
|
+
): Promise<MerchantCoupon | null> {
|
|
276
|
+
return Promise.resolve(null)
|
|
277
|
+
},
|
|
278
|
+
getMerchantProduct(
|
|
279
|
+
stripeProductId: string,
|
|
280
|
+
): Promise<MerchantProduct | null> {
|
|
281
|
+
return Promise.resolve(null)
|
|
282
|
+
},
|
|
283
|
+
getPrice(productId: string): Promise<Price | null> {
|
|
284
|
+
return Promise.resolve(null)
|
|
285
|
+
},
|
|
286
|
+
getProduct(productId: string): Promise<Product | null> {
|
|
287
|
+
return Promise.resolve(null)
|
|
288
|
+
},
|
|
289
|
+
getPurchase(purchaseId: string): Promise<Purchase | null> {
|
|
290
|
+
return Promise.resolve(null)
|
|
291
|
+
},
|
|
292
|
+
getPurchaseDetails(
|
|
293
|
+
purchaseId: string,
|
|
294
|
+
userId: string,
|
|
295
|
+
): Promise<{
|
|
296
|
+
purchase?: Purchase
|
|
297
|
+
existingPurchase?: Purchase
|
|
298
|
+
availableUpgrades: UpgradableProduct[]
|
|
299
|
+
}> {
|
|
300
|
+
return Promise.resolve({ availableUpgrades: [] })
|
|
301
|
+
},
|
|
302
|
+
getPurchaseForStripeCharge(
|
|
303
|
+
stripeChargeId: string,
|
|
304
|
+
): Promise<Purchase | null> {
|
|
305
|
+
return Promise.resolve(null)
|
|
306
|
+
},
|
|
307
|
+
getPurchaseUserTransferById(options: { id: string }): Promise<
|
|
308
|
+
| (PurchaseUserTransfer & {
|
|
309
|
+
sourceUser: User
|
|
310
|
+
targetUser: User | null
|
|
311
|
+
purchase: Purchase
|
|
312
|
+
})
|
|
313
|
+
| null
|
|
314
|
+
> {
|
|
315
|
+
return Promise.resolve(null)
|
|
316
|
+
},
|
|
317
|
+
getPurchaseWithUser(purchaseId: string): Promise<
|
|
318
|
+
| (Purchase & {
|
|
319
|
+
user: User
|
|
320
|
+
})
|
|
321
|
+
| null
|
|
322
|
+
> {
|
|
323
|
+
return Promise.resolve(null)
|
|
324
|
+
},
|
|
325
|
+
getPurchasesForUser(userId?: string): Promise<
|
|
326
|
+
(Purchase & {
|
|
327
|
+
bulkCoupon: { id: string; maxUses: number; usedCount: number } | null
|
|
328
|
+
product: { id: string; name: string }
|
|
329
|
+
})[]
|
|
330
|
+
> {
|
|
331
|
+
return Promise.resolve([])
|
|
332
|
+
},
|
|
333
|
+
getUserById(userId: string): Promise<User | null> {
|
|
334
|
+
return Promise.resolve(null)
|
|
335
|
+
},
|
|
336
|
+
pricesOfPurchasesTowardOneBundle(options: {
|
|
337
|
+
userId: string | undefined
|
|
338
|
+
bundleId: string
|
|
339
|
+
}): Promise<Price[]> {
|
|
340
|
+
return Promise.resolve([])
|
|
341
|
+
},
|
|
342
|
+
toggleLessonProgressForUser(options: {
|
|
343
|
+
userId: string
|
|
344
|
+
lessonId?: string
|
|
345
|
+
lessonSlug?: string
|
|
346
|
+
}): Promise<ResourceProgress | null> {
|
|
347
|
+
return Promise.resolve(null)
|
|
348
|
+
},
|
|
349
|
+
transferPurchasesToNewUser(options: {
|
|
350
|
+
merchantCustomerId: string
|
|
351
|
+
userId: string
|
|
352
|
+
}): Promise<unknown> {
|
|
353
|
+
return Promise.resolve(undefined)
|
|
354
|
+
},
|
|
355
|
+
updatePurchaseStatusForCharge(
|
|
356
|
+
chargeId: string,
|
|
357
|
+
status: 'Valid' | 'Refunded' | 'Disputed' | 'Banned' | 'Restricted',
|
|
358
|
+
): Promise<Purchase | undefined> {
|
|
359
|
+
return Promise.resolve(undefined)
|
|
360
|
+
},
|
|
361
|
+
updatePurchaseUserTransferTransferState(options: {
|
|
362
|
+
id: string
|
|
363
|
+
transferState: PurchaseUserTransferState
|
|
364
|
+
}): Promise<PurchaseUserTransfer | null> {
|
|
365
|
+
return Promise.resolve(null)
|
|
366
|
+
},
|
|
367
|
+
async addResourceToResource(options) {
|
|
368
|
+
return null
|
|
369
|
+
},
|
|
139
370
|
async updateContentResourceFields(options) {
|
|
140
371
|
return null
|
|
141
372
|
},
|
|
@@ -143,20 +374,71 @@ export function pgDrizzleAdapter(
|
|
|
143
374
|
// TODO Implement
|
|
144
375
|
return null
|
|
145
376
|
},
|
|
146
|
-
async createContentResource(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
377
|
+
async createContentResource(data) {
|
|
378
|
+
const id = data.id || crypto.randomUUID()
|
|
379
|
+
|
|
380
|
+
await client.insert(contentResource).values({ ...data, id })
|
|
381
|
+
|
|
382
|
+
const resource = await client.query.contentResource.findFirst({
|
|
383
|
+
where: eq(contentResource.id, id),
|
|
384
|
+
with: {
|
|
385
|
+
resources: {
|
|
386
|
+
with: {
|
|
387
|
+
resource: {
|
|
388
|
+
with: {
|
|
389
|
+
resources: {
|
|
390
|
+
with: {
|
|
391
|
+
resource: true,
|
|
392
|
+
},
|
|
393
|
+
orderBy: asc(contentResourceResource.position),
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
orderBy: asc(contentResourceResource.position),
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
const parsedResource = ContentResourceSchema.safeParse(resource)
|
|
404
|
+
|
|
405
|
+
if (!parsedResource.success) {
|
|
406
|
+
console.error('Error parsing resource', resource)
|
|
407
|
+
throw new Error('Error parsing resource')
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return parsedResource.data
|
|
152
411
|
},
|
|
153
412
|
async getContentResource(data) {
|
|
154
|
-
const
|
|
155
|
-
.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
413
|
+
const resource = await client.query.contentResource.findFirst({
|
|
414
|
+
where: eq(contentResource.id, data),
|
|
415
|
+
with: {
|
|
416
|
+
resources: {
|
|
417
|
+
with: {
|
|
418
|
+
resource: {
|
|
419
|
+
with: {
|
|
420
|
+
resources: {
|
|
421
|
+
with: {
|
|
422
|
+
resource: true,
|
|
423
|
+
},
|
|
424
|
+
orderBy: asc(contentResourceResource.position),
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
orderBy: asc(contentResourceResource.position),
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
const parsedResource = ContentResourceSchema.safeParse(resource)
|
|
435
|
+
|
|
436
|
+
if (!parsedResource.success) {
|
|
437
|
+
console.error('Error parsing resource', resource)
|
|
438
|
+
return null
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return parsedResource.data
|
|
160
442
|
},
|
|
161
443
|
async createUser(data) {
|
|
162
444
|
return await client
|
package/src/lib/sqlite.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AdapterAccount } from '@auth/core/adapters'
|
|
2
|
-
import { and, eq, sql } from 'drizzle-orm'
|
|
2
|
+
import { and, asc, eq, sql } from 'drizzle-orm'
|
|
3
3
|
import {
|
|
4
4
|
BaseSQLiteDatabase,
|
|
5
5
|
sqliteTable as defaultSqliteTableFn,
|
|
@@ -10,6 +10,21 @@ import {
|
|
|
10
10
|
} from 'drizzle-orm/sqlite-core'
|
|
11
11
|
|
|
12
12
|
import { type CourseBuilderAdapter } from '@coursebuilder/core/adapters'
|
|
13
|
+
import {
|
|
14
|
+
Coupon,
|
|
15
|
+
MerchantCoupon,
|
|
16
|
+
MerchantCustomer,
|
|
17
|
+
MerchantProduct,
|
|
18
|
+
Price,
|
|
19
|
+
Product,
|
|
20
|
+
Purchase,
|
|
21
|
+
PurchaseUserTransfer,
|
|
22
|
+
PurchaseUserTransferState,
|
|
23
|
+
ResourceProgress,
|
|
24
|
+
UpgradableProduct,
|
|
25
|
+
User,
|
|
26
|
+
} from '@coursebuilder/core/schemas'
|
|
27
|
+
import { ContentResourceSchema } from '@coursebuilder/core/schemas/content-resource-schema'
|
|
13
28
|
|
|
14
29
|
import { stripUndefined } from './utils.js'
|
|
15
30
|
|
|
@@ -125,10 +140,219 @@ export function SQLiteDrizzleAdapter(
|
|
|
125
140
|
client: InstanceType<typeof BaseSQLiteDatabase>,
|
|
126
141
|
tableFn = defaultSqliteTableFn,
|
|
127
142
|
): CourseBuilderAdapter {
|
|
128
|
-
const {
|
|
129
|
-
|
|
143
|
+
const {
|
|
144
|
+
users,
|
|
145
|
+
accounts,
|
|
146
|
+
sessions,
|
|
147
|
+
verificationTokens,
|
|
148
|
+
contentResource,
|
|
149
|
+
contentResourceResource,
|
|
150
|
+
} = createTables(tableFn)
|
|
130
151
|
|
|
131
152
|
return {
|
|
153
|
+
client,
|
|
154
|
+
availableUpgradesForProduct(
|
|
155
|
+
purchases: any,
|
|
156
|
+
productId: string,
|
|
157
|
+
): Promise<
|
|
158
|
+
{
|
|
159
|
+
upgradableTo: { id: string; name: string }
|
|
160
|
+
upgradableFrom: { id: string; name: string }
|
|
161
|
+
}[]
|
|
162
|
+
> {
|
|
163
|
+
return Promise.resolve([])
|
|
164
|
+
},
|
|
165
|
+
clearLessonProgressForUser(options: {
|
|
166
|
+
userId: string
|
|
167
|
+
lessons: { id: string; slug: string }[]
|
|
168
|
+
}): Promise<void> {
|
|
169
|
+
return Promise.resolve(undefined)
|
|
170
|
+
},
|
|
171
|
+
completeLessonProgressForUser(options: {
|
|
172
|
+
userId: string
|
|
173
|
+
lessonId?: string
|
|
174
|
+
}): Promise<ResourceProgress | null> {
|
|
175
|
+
return Promise.resolve(null)
|
|
176
|
+
},
|
|
177
|
+
couponForIdOrCode(options: {
|
|
178
|
+
code?: string
|
|
179
|
+
couponId?: string
|
|
180
|
+
}): Promise<(Coupon & { merchantCoupon: MerchantCoupon }) | null> {
|
|
181
|
+
return Promise.resolve(null)
|
|
182
|
+
},
|
|
183
|
+
createMerchantChargeAndPurchase(options: {
|
|
184
|
+
userId: string
|
|
185
|
+
productId: string
|
|
186
|
+
stripeChargeId: string
|
|
187
|
+
stripeCouponId?: string
|
|
188
|
+
merchantAccountId: string
|
|
189
|
+
merchantProductId: string
|
|
190
|
+
merchantCustomerId: string
|
|
191
|
+
stripeChargeAmount: number
|
|
192
|
+
quantity?: number
|
|
193
|
+
bulk?: boolean
|
|
194
|
+
checkoutSessionId: string
|
|
195
|
+
appliedPPPStripeCouponId: string | undefined
|
|
196
|
+
upgradedFromPurchaseId: string | undefined
|
|
197
|
+
usedCouponId: string | undefined
|
|
198
|
+
country?: string
|
|
199
|
+
}): Promise<Purchase> {
|
|
200
|
+
throw new Error('Method not implemented.')
|
|
201
|
+
},
|
|
202
|
+
findOrCreateMerchantCustomer(options: {
|
|
203
|
+
user: User
|
|
204
|
+
identifier: string
|
|
205
|
+
merchantAccountId: string
|
|
206
|
+
}): Promise<MerchantCustomer | null> {
|
|
207
|
+
return Promise.resolve(null)
|
|
208
|
+
},
|
|
209
|
+
findOrCreateUser(
|
|
210
|
+
email: string,
|
|
211
|
+
name?: string | null,
|
|
212
|
+
): Promise<{
|
|
213
|
+
user: User
|
|
214
|
+
isNewUser: boolean
|
|
215
|
+
}> {
|
|
216
|
+
throw new Error('Method not implemented.')
|
|
217
|
+
},
|
|
218
|
+
getCoupon(couponIdOrCode: string): Promise<Coupon | null> {
|
|
219
|
+
return Promise.resolve(null)
|
|
220
|
+
},
|
|
221
|
+
getCouponWithBulkPurchases(couponId: string): Promise<
|
|
222
|
+
| (Coupon & {
|
|
223
|
+
bulkCouponPurchases: { bulkCouponId: string }[]
|
|
224
|
+
})
|
|
225
|
+
| null
|
|
226
|
+
> {
|
|
227
|
+
return Promise.resolve(null)
|
|
228
|
+
},
|
|
229
|
+
getDefaultCoupon(productIds?: string[]): Promise<{
|
|
230
|
+
defaultMerchantCoupon: MerchantCoupon
|
|
231
|
+
defaultCoupon: Coupon
|
|
232
|
+
} | null> {
|
|
233
|
+
return Promise.resolve(null)
|
|
234
|
+
},
|
|
235
|
+
getLessonProgressCountsByDate(): Promise<
|
|
236
|
+
{
|
|
237
|
+
count: number
|
|
238
|
+
completedAt: string
|
|
239
|
+
}[]
|
|
240
|
+
> {
|
|
241
|
+
return Promise.resolve([])
|
|
242
|
+
},
|
|
243
|
+
getLessonProgressForUser(userId: string): Promise<ResourceProgress[]> {
|
|
244
|
+
return Promise.resolve([])
|
|
245
|
+
},
|
|
246
|
+
getLessonProgresses(): Promise<ResourceProgress[]> {
|
|
247
|
+
return Promise.resolve([])
|
|
248
|
+
},
|
|
249
|
+
getMerchantCharge(merchantChargeId: string): Promise<{
|
|
250
|
+
id: string
|
|
251
|
+
identifier: string
|
|
252
|
+
merchantProductId: string
|
|
253
|
+
} | null> {
|
|
254
|
+
return Promise.resolve(null)
|
|
255
|
+
},
|
|
256
|
+
getMerchantCoupon(
|
|
257
|
+
merchantCouponId: string,
|
|
258
|
+
): Promise<MerchantCoupon | null> {
|
|
259
|
+
return Promise.resolve(null)
|
|
260
|
+
},
|
|
261
|
+
getMerchantProduct(
|
|
262
|
+
stripeProductId: string,
|
|
263
|
+
): Promise<MerchantProduct | null> {
|
|
264
|
+
return Promise.resolve(null)
|
|
265
|
+
},
|
|
266
|
+
getPrice(productId: string): Promise<Price | null> {
|
|
267
|
+
return Promise.resolve(null)
|
|
268
|
+
},
|
|
269
|
+
getProduct(productId: string): Promise<Product | null> {
|
|
270
|
+
return Promise.resolve(null)
|
|
271
|
+
},
|
|
272
|
+
getPurchase(purchaseId: string): Promise<Purchase | null> {
|
|
273
|
+
return Promise.resolve(null)
|
|
274
|
+
},
|
|
275
|
+
getPurchaseDetails(
|
|
276
|
+
purchaseId: string,
|
|
277
|
+
userId: string,
|
|
278
|
+
): Promise<{
|
|
279
|
+
purchase?: Purchase
|
|
280
|
+
existingPurchase?: Purchase
|
|
281
|
+
availableUpgrades: UpgradableProduct[]
|
|
282
|
+
}> {
|
|
283
|
+
return Promise.resolve({ availableUpgrades: [] })
|
|
284
|
+
},
|
|
285
|
+
getPurchaseForStripeCharge(
|
|
286
|
+
stripeChargeId: string,
|
|
287
|
+
): Promise<Purchase | null> {
|
|
288
|
+
return Promise.resolve(null)
|
|
289
|
+
},
|
|
290
|
+
getPurchaseUserTransferById(options: { id: string }): Promise<
|
|
291
|
+
| (PurchaseUserTransfer & {
|
|
292
|
+
sourceUser: User
|
|
293
|
+
targetUser: User | null
|
|
294
|
+
purchase: Purchase
|
|
295
|
+
})
|
|
296
|
+
| null
|
|
297
|
+
> {
|
|
298
|
+
return Promise.resolve(null)
|
|
299
|
+
},
|
|
300
|
+
getPurchaseWithUser(purchaseId: string): Promise<
|
|
301
|
+
| (Purchase & {
|
|
302
|
+
user: User
|
|
303
|
+
})
|
|
304
|
+
| null
|
|
305
|
+
> {
|
|
306
|
+
return Promise.resolve(null)
|
|
307
|
+
},
|
|
308
|
+
getPurchasesForUser(userId?: string): Promise<
|
|
309
|
+
(Purchase & {
|
|
310
|
+
bulkCoupon: { id: string; maxUses: number; usedCount: number } | null
|
|
311
|
+
product: { id: string; name: string }
|
|
312
|
+
})[]
|
|
313
|
+
> {
|
|
314
|
+
return Promise.resolve([])
|
|
315
|
+
},
|
|
316
|
+
getUserById(userId: string): Promise<User | null> {
|
|
317
|
+
return Promise.resolve(null)
|
|
318
|
+
},
|
|
319
|
+
pricesOfPurchasesTowardOneBundle(options: {
|
|
320
|
+
userId: string | undefined
|
|
321
|
+
bundleId: string
|
|
322
|
+
}): Promise<Price[]> {
|
|
323
|
+
return Promise.resolve([])
|
|
324
|
+
},
|
|
325
|
+
async createPurchase(options): Promise<Purchase> {
|
|
326
|
+
throw new Error('Method not implemented.')
|
|
327
|
+
},
|
|
328
|
+
toggleLessonProgressForUser(options: {
|
|
329
|
+
userId: string
|
|
330
|
+
lessonId?: string
|
|
331
|
+
lessonSlug?: string
|
|
332
|
+
}): Promise<ResourceProgress | null> {
|
|
333
|
+
return Promise.resolve(null)
|
|
334
|
+
},
|
|
335
|
+
transferPurchasesToNewUser(options: {
|
|
336
|
+
merchantCustomerId: string
|
|
337
|
+
userId: string
|
|
338
|
+
}): Promise<unknown> {
|
|
339
|
+
return Promise.resolve(undefined)
|
|
340
|
+
},
|
|
341
|
+
updatePurchaseStatusForCharge(
|
|
342
|
+
chargeId: string,
|
|
343
|
+
status: 'Valid' | 'Refunded' | 'Disputed' | 'Banned' | 'Restricted',
|
|
344
|
+
): Promise<Purchase | undefined> {
|
|
345
|
+
return Promise.resolve(undefined)
|
|
346
|
+
},
|
|
347
|
+
updatePurchaseUserTransferTransferState(options: {
|
|
348
|
+
id: string
|
|
349
|
+
transferState: PurchaseUserTransferState
|
|
350
|
+
}): Promise<PurchaseUserTransfer | null> {
|
|
351
|
+
return Promise.resolve(null)
|
|
352
|
+
},
|
|
353
|
+
async addResourceToResource(options) {
|
|
354
|
+
return null
|
|
355
|
+
},
|
|
132
356
|
async updateContentResourceFields(options) {
|
|
133
357
|
return null
|
|
134
358
|
},
|
|
@@ -136,20 +360,71 @@ export function SQLiteDrizzleAdapter(
|
|
|
136
360
|
// TODO Implement
|
|
137
361
|
return null
|
|
138
362
|
},
|
|
139
|
-
async createContentResource(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
363
|
+
async createContentResource(data) {
|
|
364
|
+
const id = data.id || crypto.randomUUID()
|
|
365
|
+
|
|
366
|
+
await client.insert(contentResource).values({ ...data, id })
|
|
367
|
+
|
|
368
|
+
const resource = await client.query.contentResource.findFirst({
|
|
369
|
+
where: eq(contentResource.id, id),
|
|
370
|
+
with: {
|
|
371
|
+
resources: {
|
|
372
|
+
with: {
|
|
373
|
+
resource: {
|
|
374
|
+
with: {
|
|
375
|
+
resources: {
|
|
376
|
+
with: {
|
|
377
|
+
resource: true,
|
|
378
|
+
},
|
|
379
|
+
orderBy: asc(contentResourceResource.position),
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
orderBy: asc(contentResourceResource.position),
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
const parsedResource = ContentResourceSchema.safeParse(resource)
|
|
390
|
+
|
|
391
|
+
if (!parsedResource.success) {
|
|
392
|
+
console.error('Error parsing resource', resource)
|
|
393
|
+
throw new Error('Error parsing resource')
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return parsedResource.data
|
|
145
397
|
},
|
|
146
398
|
async getContentResource(data) {
|
|
147
|
-
const
|
|
148
|
-
.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
399
|
+
const resource = await client.query.contentResource.findFirst({
|
|
400
|
+
where: eq(contentResource.id, data),
|
|
401
|
+
with: {
|
|
402
|
+
resources: {
|
|
403
|
+
with: {
|
|
404
|
+
resource: {
|
|
405
|
+
with: {
|
|
406
|
+
resources: {
|
|
407
|
+
with: {
|
|
408
|
+
resource: true,
|
|
409
|
+
},
|
|
410
|
+
orderBy: asc(contentResourceResource.position),
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
orderBy: asc(contentResourceResource.position),
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
const parsedResource = ContentResourceSchema.safeParse(resource)
|
|
421
|
+
|
|
422
|
+
if (!parsedResource.success) {
|
|
423
|
+
console.error('Error parsing resource', resource)
|
|
424
|
+
return null
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return parsedResource.data
|
|
153
428
|
},
|
|
154
429
|
async createUser(data) {
|
|
155
430
|
return client
|