@coursebuilder/adapter-drizzle 0.1.1 → 0.1.3

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 (100) hide show
  1. package/dist/{chunk-ISURSRBK.js → chunk-3LWFRGZT.js} +519 -313
  2. package/dist/{chunk-RVYJDDZD.js → chunk-NXFHRDLS.js} +2 -2
  3. package/dist/{chunk-44VDBYFU.js → chunk-QK6CINAJ.js} +3 -3
  4. package/dist/{chunk-MYRB6GLJ.js → chunk-ULABK6XG.js} +2 -2
  5. package/dist/{chunk-MCFL2YV4.js → chunk-XSXWLOIN.js} +4625 -449
  6. package/dist/{chunk-QZOBGJSV.js → chunk-XXZQBN6S.js} +2 -2
  7. package/dist/index.d.ts +0 -2
  8. package/dist/index.js +11 -27
  9. package/dist/lib/mysql/index.cjs +909 -750
  10. package/dist/lib/mysql/index.cjs.map +1 -1
  11. package/dist/lib/mysql/index.d.ts +212 -10
  12. package/dist/lib/mysql/index.js +11 -14
  13. package/dist/lib/mysql/schemas/auth/accounts.cjs +73 -57
  14. package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
  15. package/dist/lib/mysql/schemas/auth/accounts.js +5 -4
  16. package/dist/lib/mysql/schemas/auth/role-permissions.cjs +64 -48
  17. package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
  18. package/dist/lib/mysql/schemas/auth/role-permissions.js +6 -5
  19. package/dist/lib/mysql/schemas/auth/roles.cjs +64 -48
  20. package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
  21. package/dist/lib/mysql/schemas/auth/roles.js +5 -4
  22. package/dist/lib/mysql/schemas/auth/sessions.cjs +64 -48
  23. package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
  24. package/dist/lib/mysql/schemas/auth/sessions.js +6 -5
  25. package/dist/lib/mysql/schemas/auth/user-permissions.cjs +65 -49
  26. package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
  27. package/dist/lib/mysql/schemas/auth/user-permissions.js +5 -4
  28. package/dist/lib/mysql/schemas/auth/user-roles.cjs +67 -51
  29. package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
  30. package/dist/lib/mysql/schemas/auth/user-roles.js +5 -4
  31. package/dist/lib/mysql/schemas/auth/users.cjs +170 -154
  32. package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
  33. package/dist/lib/mysql/schemas/auth/users.js +5 -4
  34. package/dist/lib/mysql/schemas/commerce/coupon.cjs +1 -1
  35. package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
  36. package/dist/lib/mysql/schemas/commerce/coupon.d.ts +4 -4
  37. package/dist/lib/mysql/schemas/commerce/coupon.js +1 -1
  38. package/dist/lib/mysql/schemas/commerce/price.cjs +189 -11
  39. package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
  40. package/dist/lib/mysql/schemas/commerce/price.d.ts +6 -1
  41. package/dist/lib/mysql/schemas/commerce/price.js +14 -3
  42. package/dist/lib/mysql/schemas/commerce/product.cjs +227 -9
  43. package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
  44. package/dist/lib/mysql/schemas/commerce/product.d.ts +8 -2
  45. package/dist/lib/mysql/schemas/commerce/product.js +12 -1
  46. package/dist/lib/mysql/schemas/commerce/purchase.cjs +140 -122
  47. package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
  48. package/dist/lib/mysql/schemas/commerce/purchase.js +5 -4
  49. package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs +107 -24
  50. package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -1
  51. package/dist/lib/mysql/schemas/commerce/upgradable-products.js +11 -2
  52. package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +84 -68
  53. package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
  54. package/dist/lib/mysql/schemas/communication/communication-preferences.js +5 -4
  55. package/dist/lib/mysql/schemas/content/content-contributions.cjs +92 -76
  56. package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
  57. package/dist/lib/mysql/schemas/content/content-contributions.js +5 -4
  58. package/dist/lib/mysql/schemas/content/content-resource-product.cjs +243 -0
  59. package/dist/lib/mysql/schemas/content/content-resource-product.cjs.map +1 -0
  60. package/dist/lib/mysql/schemas/content/content-resource-product.d.ts +101 -0
  61. package/dist/lib/mysql/schemas/content/content-resource-product.js +19 -0
  62. package/dist/lib/mysql/schemas/content/content-resource-resource.cjs +67 -51
  63. package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
  64. package/dist/lib/mysql/schemas/content/content-resource-resource.js +5 -4
  65. package/dist/lib/mysql/schemas/content/content-resource.cjs +116 -62
  66. package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
  67. package/dist/lib/mysql/schemas/content/content-resource.d.ts +1 -0
  68. package/dist/lib/mysql/schemas/content/content-resource.js +5 -4
  69. package/dist/lib/utils.cjs.map +1 -1
  70. package/dist/lib/utils.d.ts +3 -7
  71. package/dist/lib/utils.js +12 -3
  72. package/dist/lib/utils.js.map +1 -1
  73. package/package.json +2 -2
  74. package/src/index.ts +0 -8
  75. package/src/lib/mysql/index.ts +155 -24
  76. package/src/lib/mysql/schemas/auth/user-roles.ts +2 -2
  77. package/src/lib/mysql/schemas/commerce/coupon.ts +2 -2
  78. package/src/lib/mysql/schemas/commerce/price.ts +22 -1
  79. package/src/lib/mysql/schemas/commerce/product.ts +26 -2
  80. package/src/lib/mysql/schemas/content/content-resource-product.ts +62 -0
  81. package/src/lib/mysql/schemas/content/content-resource.ts +5 -0
  82. package/src/lib/utils.ts +1 -9
  83. package/dist/chunk-7LAAAEVE.js +0 -379
  84. package/dist/chunk-AFQGYW7Z.js +0 -45
  85. package/dist/chunk-CPE4P26C.js +0 -42
  86. package/dist/chunk-GFUUJRX7.js +0 -18
  87. package/dist/chunk-O2KKII62.js +0 -381
  88. package/dist/chunk-Y34AIPU7.js +0 -4137
  89. package/dist/lib/pg.cjs +0 -4527
  90. package/dist/lib/pg.cjs.map +0 -1
  91. package/dist/lib/pg.d.ts +0 -496
  92. package/dist/lib/pg.js +0 -11
  93. package/dist/lib/sqlite.cjs +0 -4536
  94. package/dist/lib/sqlite.cjs.map +0 -1
  95. package/dist/lib/sqlite.d.ts +0 -496
  96. package/dist/lib/sqlite.js +0 -12
  97. package/dist/lib/sqlite.js.map +0 -1
  98. package/src/lib/pg.ts +0 -579
  99. package/src/lib/sqlite.ts +0 -562
  100. /package/dist/lib/{pg.js.map → mysql/schemas/content/content-resource-product.js.map} +0 -0
package/src/lib/pg.ts DELETED
@@ -1,579 +0,0 @@
1
- import type {
2
- AdapterAccount,
3
- AdapterSession,
4
- AdapterUser,
5
- } from '@auth/core/adapters'
6
- import { and, asc, eq } from 'drizzle-orm'
7
- import {
8
- pgTable as defaultPgTableFn,
9
- integer,
10
- json,
11
- PgDatabase,
12
- pgEnum,
13
- PgTableFn,
14
- primaryKey,
15
- text,
16
- timestamp,
17
- varchar,
18
- } from 'drizzle-orm/pg-core'
19
-
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'
36
-
37
- export function createTables(pgTable: PgTableFn) {
38
- const users = pgTable('user', {
39
- id: text('id').notNull().primaryKey(),
40
- name: text('name'),
41
- email: text('email').notNull(),
42
- emailVerified: timestamp('emailVerified', { mode: 'date' }),
43
- role: pgEnum('role', ['user', 'admin'])('role').default('user'),
44
- image: text('image'),
45
- })
46
-
47
- const accounts = pgTable(
48
- 'account',
49
- {
50
- userId: text('userId')
51
- .notNull()
52
- .references(() => users.id, { onDelete: 'cascade' }),
53
- type: text('type').$type<AdapterAccount['type']>().notNull(),
54
- provider: text('provider').notNull(),
55
- providerAccountId: text('providerAccountId').notNull(),
56
- refresh_token: text('refresh_token'),
57
- access_token: text('access_token'),
58
- expires_at: integer('expires_at'),
59
- token_type: text('token_type'),
60
- scope: text('scope'),
61
- id_token: text('id_token'),
62
- session_state: text('session_state'),
63
- },
64
- (account) => ({
65
- pk: primaryKey({
66
- columns: [account.provider, account.providerAccountId],
67
- }),
68
- }),
69
- )
70
-
71
- const sessions = pgTable('session', {
72
- sessionToken: text('sessionToken').notNull().primaryKey(),
73
- userId: text('userId')
74
- .notNull()
75
- .references(() => users.id, { onDelete: 'cascade' }),
76
- expires: timestamp('expires', { mode: 'date' }).notNull(),
77
- })
78
-
79
- const verificationTokens = pgTable(
80
- 'verificationToken',
81
- {
82
- identifier: text('identifier').notNull(),
83
- token: text('token').notNull(),
84
- expires: timestamp('expires', { mode: 'date' }).notNull(),
85
- },
86
- (vt) => ({
87
- pk: primaryKey({ columns: [vt.identifier, vt.token] }),
88
- }),
89
- )
90
-
91
- const contentResource = pgTable('contentResource', {
92
- id: varchar('id', { length: 255 }).notNull().primaryKey(),
93
- type: varchar('type', { length: 255 }).notNull(),
94
- createdById: varchar('createdById', { length: 255 }).notNull(),
95
- fields: json('fields').$type<Record<string, any>>().default({}),
96
- createdAt: timestamp('createdAt', {
97
- mode: 'date',
98
- precision: 6,
99
- withTimezone: true,
100
- }).defaultNow(),
101
- updatedAt: timestamp('updatedAt', {
102
- mode: 'date',
103
- precision: 6,
104
- withTimezone: true,
105
- }).defaultNow(),
106
- deletedAt: timestamp('deletedAt', {
107
- mode: 'date',
108
- precision: 6,
109
- withTimezone: true,
110
- }),
111
- })
112
-
113
- const contentResourceResource = pgTable(
114
- 'contentResourceResource',
115
- {
116
- resourceOfId: varchar('resourceOfId', { length: 255 }).notNull(),
117
- resourceId: varchar('resourceId', { length: 255 }).notNull(),
118
- position: integer('position').notNull().default(0),
119
- metadata: json('fields').$type<Record<string, any>>().default({}),
120
- createdAt: timestamp('createdAt', {
121
- mode: 'date',
122
- precision: 6,
123
- withTimezone: true,
124
- }).defaultNow(),
125
- updatedAt: timestamp('updatedAt', {
126
- mode: 'date',
127
- precision: 6,
128
- withTimezone: true,
129
- }).defaultNow(),
130
- deletedAt: timestamp('deletedAt', {
131
- mode: 'date',
132
- precision: 6,
133
- withTimezone: true,
134
- }),
135
- },
136
- (crr) => ({
137
- pk: primaryKey({ columns: [crr.resourceOfId, crr.resourceId] }),
138
- }),
139
- )
140
-
141
- return {
142
- users,
143
- accounts,
144
- sessions,
145
- verificationTokens,
146
- contentResource,
147
- contentResourceResource,
148
- }
149
- }
150
-
151
- export type DefaultSchema = ReturnType<typeof createTables>
152
-
153
- export function pgDrizzleAdapter(
154
- client: InstanceType<typeof PgDatabase>,
155
- tableFn = defaultPgTableFn,
156
- ): CourseBuilderAdapter {
157
- const {
158
- users,
159
- accounts,
160
- sessions,
161
- verificationTokens,
162
- contentResource,
163
- contentResourceResource,
164
- } = createTables(tableFn)
165
-
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
- },
370
- async updateContentResourceFields(options) {
371
- return null
372
- },
373
- async getVideoResource(id) {
374
- // TODO Implement
375
- return null
376
- },
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
411
- },
412
- async getContentResource(data) {
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
442
- },
443
- async createUser(data) {
444
- return await client
445
- .insert(users)
446
- .values({ ...data, id: crypto.randomUUID() })
447
- .returning()
448
- .then((res) => (res[0] as AdapterUser) ?? null)
449
- },
450
- async getUser(data) {
451
- return await client
452
- .select()
453
- .from(users)
454
- .where(eq(users.id, data))
455
- .then((res) => res[0] ?? null)
456
- },
457
- async getUserByEmail(data) {
458
- return await client
459
- .select()
460
- .from(users)
461
- .where(eq(users.email, data))
462
- .then((res) => res[0] ?? null)
463
- },
464
- async createSession(data) {
465
- return await client
466
- .insert(sessions)
467
- .values(data)
468
- .returning()
469
- .then((res) => res[0] as AdapterSession)
470
- },
471
- async getSessionAndUser(data) {
472
- return await client
473
- .select({
474
- session: sessions,
475
- user: users,
476
- })
477
- .from(sessions)
478
- .where(eq(sessions.sessionToken, data))
479
- .innerJoin(users, eq(users.id, sessions.userId))
480
- .then((res) => res[0] ?? null)
481
- },
482
- async updateUser(data) {
483
- if (!data.id) {
484
- throw new Error('No user id.')
485
- }
486
-
487
- return await client
488
- .update(users)
489
- .set(data)
490
- .where(eq(users.id, data.id))
491
- .returning()
492
- .then((res) => res[0] as AdapterUser)
493
- },
494
- async updateSession(data) {
495
- return await client
496
- .update(sessions)
497
- .set(data)
498
- .where(eq(sessions.sessionToken, data.sessionToken))
499
- .returning()
500
- .then((res) => res[0])
501
- },
502
- async linkAccount(rawAccount) {
503
- await client
504
- .insert(accounts)
505
- .values(rawAccount)
506
- .returning()
507
- .then((res) => res[0])
508
- },
509
- async getUserByAccount(account) {
510
- const dbAccount =
511
- (await client
512
- .select()
513
- .from(accounts)
514
- .where(
515
- and(
516
- eq(accounts.providerAccountId, account.providerAccountId),
517
- eq(accounts.provider, account.provider),
518
- ),
519
- )
520
- .leftJoin(users, eq(accounts.userId, users.id))
521
- .then((res) => res[0])) ?? null
522
-
523
- return dbAccount?.user ?? null
524
- },
525
- async deleteSession(sessionToken) {
526
- const session = await client
527
- .delete(sessions)
528
- .where(eq(sessions.sessionToken, sessionToken))
529
- .returning()
530
- .then((res) => res[0] ?? null)
531
-
532
- return session
533
- },
534
- async createVerificationToken(token) {
535
- return await client
536
- .insert(verificationTokens)
537
- .values(token)
538
- .returning()
539
- .then((res) => res[0])
540
- },
541
- async useVerificationToken(token) {
542
- try {
543
- return await client
544
- .delete(verificationTokens)
545
- .where(
546
- and(
547
- eq(verificationTokens.identifier, token.identifier),
548
- eq(verificationTokens.token, token.token),
549
- ),
550
- )
551
- .returning()
552
- .then((res) => res[0] ?? null)
553
- } catch (err) {
554
- throw new Error('No verification token found.')
555
- }
556
- },
557
- async deleteUser(id) {
558
- await client
559
- .delete(users)
560
- .where(eq(users.id, id))
561
- .returning()
562
- .then((res) => res[0] ?? null)
563
- },
564
- async unlinkAccount(account) {
565
- const { type, provider, providerAccountId, userId } = await client
566
- .delete(accounts)
567
- .where(
568
- and(
569
- eq(accounts.providerAccountId, account.providerAccountId),
570
- eq(accounts.provider, account.provider),
571
- ),
572
- )
573
- .returning()
574
- .then((res) => (res[0] as AdapterAccount) ?? null)
575
-
576
- return { provider, type, providerAccountId, userId }
577
- },
578
- }
579
- }