@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
@@ -1,379 +0,0 @@
1
- import {
2
- ContentResourceSchema
3
- } from "./chunk-Y34AIPU7.js";
4
- import {
5
- __name
6
- } from "./chunk-VNI36MMC.js";
7
-
8
- // src/lib/pg.ts
9
- import { and, asc, eq } from "drizzle-orm";
10
- import { pgTable as defaultPgTableFn, integer, json, pgEnum, primaryKey, text, timestamp, varchar } from "drizzle-orm/pg-core";
11
- function createTables(pgTable) {
12
- const users = pgTable("user", {
13
- id: text("id").notNull().primaryKey(),
14
- name: text("name"),
15
- email: text("email").notNull(),
16
- emailVerified: timestamp("emailVerified", {
17
- mode: "date"
18
- }),
19
- role: pgEnum("role", [
20
- "user",
21
- "admin"
22
- ])("role").default("user"),
23
- image: text("image")
24
- });
25
- const accounts = pgTable("account", {
26
- userId: text("userId").notNull().references(() => users.id, {
27
- onDelete: "cascade"
28
- }),
29
- type: text("type").$type().notNull(),
30
- provider: text("provider").notNull(),
31
- providerAccountId: text("providerAccountId").notNull(),
32
- refresh_token: text("refresh_token"),
33
- access_token: text("access_token"),
34
- expires_at: integer("expires_at"),
35
- token_type: text("token_type"),
36
- scope: text("scope"),
37
- id_token: text("id_token"),
38
- session_state: text("session_state")
39
- }, (account) => ({
40
- pk: primaryKey({
41
- columns: [
42
- account.provider,
43
- account.providerAccountId
44
- ]
45
- })
46
- }));
47
- const sessions = pgTable("session", {
48
- sessionToken: text("sessionToken").notNull().primaryKey(),
49
- userId: text("userId").notNull().references(() => users.id, {
50
- onDelete: "cascade"
51
- }),
52
- expires: timestamp("expires", {
53
- mode: "date"
54
- }).notNull()
55
- });
56
- const verificationTokens = pgTable("verificationToken", {
57
- identifier: text("identifier").notNull(),
58
- token: text("token").notNull(),
59
- expires: timestamp("expires", {
60
- mode: "date"
61
- }).notNull()
62
- }, (vt) => ({
63
- pk: primaryKey({
64
- columns: [
65
- vt.identifier,
66
- vt.token
67
- ]
68
- })
69
- }));
70
- const contentResource = pgTable("contentResource", {
71
- id: varchar("id", {
72
- length: 255
73
- }).notNull().primaryKey(),
74
- type: varchar("type", {
75
- length: 255
76
- }).notNull(),
77
- createdById: varchar("createdById", {
78
- length: 255
79
- }).notNull(),
80
- fields: json("fields").$type().default({}),
81
- createdAt: timestamp("createdAt", {
82
- mode: "date",
83
- precision: 6,
84
- withTimezone: true
85
- }).defaultNow(),
86
- updatedAt: timestamp("updatedAt", {
87
- mode: "date",
88
- precision: 6,
89
- withTimezone: true
90
- }).defaultNow(),
91
- deletedAt: timestamp("deletedAt", {
92
- mode: "date",
93
- precision: 6,
94
- withTimezone: true
95
- })
96
- });
97
- const contentResourceResource = pgTable("contentResourceResource", {
98
- resourceOfId: varchar("resourceOfId", {
99
- length: 255
100
- }).notNull(),
101
- resourceId: varchar("resourceId", {
102
- length: 255
103
- }).notNull(),
104
- position: integer("position").notNull().default(0),
105
- metadata: json("fields").$type().default({}),
106
- createdAt: timestamp("createdAt", {
107
- mode: "date",
108
- precision: 6,
109
- withTimezone: true
110
- }).defaultNow(),
111
- updatedAt: timestamp("updatedAt", {
112
- mode: "date",
113
- precision: 6,
114
- withTimezone: true
115
- }).defaultNow(),
116
- deletedAt: timestamp("deletedAt", {
117
- mode: "date",
118
- precision: 6,
119
- withTimezone: true
120
- })
121
- }, (crr) => ({
122
- pk: primaryKey({
123
- columns: [
124
- crr.resourceOfId,
125
- crr.resourceId
126
- ]
127
- })
128
- }));
129
- return {
130
- users,
131
- accounts,
132
- sessions,
133
- verificationTokens,
134
- contentResource,
135
- contentResourceResource
136
- };
137
- }
138
- __name(createTables, "createTables");
139
- function pgDrizzleAdapter(client, tableFn = defaultPgTableFn) {
140
- const { users, accounts, sessions, verificationTokens, contentResource, contentResourceResource } = createTables(tableFn);
141
- return {
142
- client,
143
- async createPurchase(options) {
144
- throw new Error("Method not implemented.");
145
- },
146
- availableUpgradesForProduct(purchases, productId) {
147
- return Promise.resolve([]);
148
- },
149
- clearLessonProgressForUser(options) {
150
- return Promise.resolve(void 0);
151
- },
152
- completeLessonProgressForUser(options) {
153
- return Promise.resolve(null);
154
- },
155
- couponForIdOrCode(options) {
156
- return Promise.resolve(null);
157
- },
158
- createMerchantChargeAndPurchase(options) {
159
- throw new Error("Method not implemented.");
160
- },
161
- findOrCreateMerchantCustomer(options) {
162
- return Promise.resolve(null);
163
- },
164
- findOrCreateUser(email, name) {
165
- throw new Error("Method not implemented.");
166
- },
167
- getCoupon(couponIdOrCode) {
168
- return Promise.resolve(null);
169
- },
170
- getCouponWithBulkPurchases(couponId) {
171
- return Promise.resolve(null);
172
- },
173
- getDefaultCoupon(productIds) {
174
- return Promise.resolve(null);
175
- },
176
- getLessonProgressCountsByDate() {
177
- return Promise.resolve([]);
178
- },
179
- getLessonProgressForUser(userId) {
180
- return Promise.resolve([]);
181
- },
182
- getLessonProgresses() {
183
- return Promise.resolve([]);
184
- },
185
- getMerchantCharge(merchantChargeId) {
186
- return Promise.resolve(null);
187
- },
188
- getMerchantCoupon(merchantCouponId) {
189
- return Promise.resolve(null);
190
- },
191
- getMerchantProduct(stripeProductId) {
192
- return Promise.resolve(null);
193
- },
194
- getPrice(productId) {
195
- return Promise.resolve(null);
196
- },
197
- getProduct(productId) {
198
- return Promise.resolve(null);
199
- },
200
- getPurchase(purchaseId) {
201
- return Promise.resolve(null);
202
- },
203
- getPurchaseDetails(purchaseId, userId) {
204
- return Promise.resolve({
205
- availableUpgrades: []
206
- });
207
- },
208
- getPurchaseForStripeCharge(stripeChargeId) {
209
- return Promise.resolve(null);
210
- },
211
- getPurchaseUserTransferById(options) {
212
- return Promise.resolve(null);
213
- },
214
- getPurchaseWithUser(purchaseId) {
215
- return Promise.resolve(null);
216
- },
217
- getPurchasesForUser(userId) {
218
- return Promise.resolve([]);
219
- },
220
- getUserById(userId) {
221
- return Promise.resolve(null);
222
- },
223
- pricesOfPurchasesTowardOneBundle(options) {
224
- return Promise.resolve([]);
225
- },
226
- toggleLessonProgressForUser(options) {
227
- return Promise.resolve(null);
228
- },
229
- transferPurchasesToNewUser(options) {
230
- return Promise.resolve(void 0);
231
- },
232
- updatePurchaseStatusForCharge(chargeId, status) {
233
- return Promise.resolve(void 0);
234
- },
235
- updatePurchaseUserTransferTransferState(options) {
236
- return Promise.resolve(null);
237
- },
238
- async addResourceToResource(options) {
239
- return null;
240
- },
241
- async updateContentResourceFields(options) {
242
- return null;
243
- },
244
- async getVideoResource(id) {
245
- return null;
246
- },
247
- async createContentResource(data) {
248
- const id = data.id || crypto.randomUUID();
249
- await client.insert(contentResource).values({
250
- ...data,
251
- id
252
- });
253
- const resource = await client.query.contentResource.findFirst({
254
- where: eq(contentResource.id, id),
255
- with: {
256
- resources: {
257
- with: {
258
- resource: {
259
- with: {
260
- resources: {
261
- with: {
262
- resource: true
263
- },
264
- orderBy: asc(contentResourceResource.position)
265
- }
266
- }
267
- }
268
- },
269
- orderBy: asc(contentResourceResource.position)
270
- }
271
- }
272
- });
273
- const parsedResource = ContentResourceSchema.safeParse(resource);
274
- if (!parsedResource.success) {
275
- console.error("Error parsing resource", resource);
276
- throw new Error("Error parsing resource");
277
- }
278
- return parsedResource.data;
279
- },
280
- async getContentResource(data) {
281
- const resource = await client.query.contentResource.findFirst({
282
- where: eq(contentResource.id, data),
283
- with: {
284
- resources: {
285
- with: {
286
- resource: {
287
- with: {
288
- resources: {
289
- with: {
290
- resource: true
291
- },
292
- orderBy: asc(contentResourceResource.position)
293
- }
294
- }
295
- }
296
- },
297
- orderBy: asc(contentResourceResource.position)
298
- }
299
- }
300
- });
301
- const parsedResource = ContentResourceSchema.safeParse(resource);
302
- if (!parsedResource.success) {
303
- console.error("Error parsing resource", resource);
304
- return null;
305
- }
306
- return parsedResource.data;
307
- },
308
- async createUser(data) {
309
- return await client.insert(users).values({
310
- ...data,
311
- id: crypto.randomUUID()
312
- }).returning().then((res) => res[0] ?? null);
313
- },
314
- async getUser(data) {
315
- return await client.select().from(users).where(eq(users.id, data)).then((res) => res[0] ?? null);
316
- },
317
- async getUserByEmail(data) {
318
- return await client.select().from(users).where(eq(users.email, data)).then((res) => res[0] ?? null);
319
- },
320
- async createSession(data) {
321
- return await client.insert(sessions).values(data).returning().then((res) => res[0]);
322
- },
323
- async getSessionAndUser(data) {
324
- return await client.select({
325
- session: sessions,
326
- user: users
327
- }).from(sessions).where(eq(sessions.sessionToken, data)).innerJoin(users, eq(users.id, sessions.userId)).then((res) => res[0] ?? null);
328
- },
329
- async updateUser(data) {
330
- if (!data.id) {
331
- throw new Error("No user id.");
332
- }
333
- return await client.update(users).set(data).where(eq(users.id, data.id)).returning().then((res) => res[0]);
334
- },
335
- async updateSession(data) {
336
- return await client.update(sessions).set(data).where(eq(sessions.sessionToken, data.sessionToken)).returning().then((res) => res[0]);
337
- },
338
- async linkAccount(rawAccount) {
339
- await client.insert(accounts).values(rawAccount).returning().then((res) => res[0]);
340
- },
341
- async getUserByAccount(account) {
342
- const dbAccount = await client.select().from(accounts).where(and(eq(accounts.providerAccountId, account.providerAccountId), eq(accounts.provider, account.provider))).leftJoin(users, eq(accounts.userId, users.id)).then((res) => res[0]) ?? null;
343
- return dbAccount?.user ?? null;
344
- },
345
- async deleteSession(sessionToken) {
346
- const session = await client.delete(sessions).where(eq(sessions.sessionToken, sessionToken)).returning().then((res) => res[0] ?? null);
347
- return session;
348
- },
349
- async createVerificationToken(token) {
350
- return await client.insert(verificationTokens).values(token).returning().then((res) => res[0]);
351
- },
352
- async useVerificationToken(token) {
353
- try {
354
- return await client.delete(verificationTokens).where(and(eq(verificationTokens.identifier, token.identifier), eq(verificationTokens.token, token.token))).returning().then((res) => res[0] ?? null);
355
- } catch (err) {
356
- throw new Error("No verification token found.");
357
- }
358
- },
359
- async deleteUser(id) {
360
- await client.delete(users).where(eq(users.id, id)).returning().then((res) => res[0] ?? null);
361
- },
362
- async unlinkAccount(account) {
363
- const { type, provider, providerAccountId, userId } = await client.delete(accounts).where(and(eq(accounts.providerAccountId, account.providerAccountId), eq(accounts.provider, account.provider))).returning().then((res) => res[0] ?? null);
364
- return {
365
- provider,
366
- type,
367
- providerAccountId,
368
- userId
369
- };
370
- }
371
- };
372
- }
373
- __name(pgDrizzleAdapter, "pgDrizzleAdapter");
374
-
375
- export {
376
- createTables,
377
- pgDrizzleAdapter
378
- };
379
- //# sourceMappingURL=chunk-7LAAAEVE.js.map
@@ -1,45 +0,0 @@
1
- import {
2
- __name
3
- } from "./chunk-VNI36MMC.js";
4
-
5
- // src/lib/mysql/schemas/commerce/price.ts
6
- import { sql } from "drizzle-orm";
7
- import { decimal, int, json, primaryKey, timestamp, varchar } from "drizzle-orm/mysql-core";
8
- function getPriceSchema(mysqlTable) {
9
- return mysqlTable("prices", {
10
- id: varchar("id", {
11
- length: 191
12
- }).notNull(),
13
- productId: varchar("productId", {
14
- length: 191
15
- }),
16
- nickname: varchar("nickname", {
17
- length: 191
18
- }),
19
- status: int("status").default(0).notNull(),
20
- unitAmount: decimal("unitAmount", {
21
- precision: 10,
22
- scale: 2
23
- }).notNull(),
24
- createdAt: timestamp("createdAt", {
25
- mode: "date",
26
- fsp: 3
27
- }).default(sql`CURRENT_TIMESTAMP(3)`).notNull(),
28
- metadata: json("fields").$type().default({})
29
- }, (table) => {
30
- return {
31
- priceId: primaryKey({
32
- columns: [
33
- table.id
34
- ],
35
- name: "Price_id"
36
- })
37
- };
38
- });
39
- }
40
- __name(getPriceSchema, "getPriceSchema");
41
-
42
- export {
43
- getPriceSchema
44
- };
45
- //# sourceMappingURL=chunk-AFQGYW7Z.js.map
@@ -1,42 +0,0 @@
1
- import {
2
- __name
3
- } from "./chunk-VNI36MMC.js";
4
-
5
- // src/lib/mysql/schemas/commerce/product.ts
6
- import { sql } from "drizzle-orm";
7
- import { int, json, primaryKey, timestamp, varchar } from "drizzle-orm/mysql-core";
8
- function getProductSchema(mysqlTable) {
9
- return mysqlTable("products", {
10
- id: varchar("id", {
11
- length: 191
12
- }).notNull(),
13
- name: varchar("name", {
14
- length: 191
15
- }).notNull(),
16
- key: varchar("key", {
17
- length: 191
18
- }),
19
- metadata: json("fields").$type().default({}),
20
- createdAt: timestamp("createdAt", {
21
- mode: "date",
22
- fsp: 3
23
- }).default(sql`CURRENT_TIMESTAMP(3)`).notNull(),
24
- status: int("status").default(0).notNull(),
25
- quantityAvailable: int("quantityAvailable").default(-1).notNull()
26
- }, (table) => {
27
- return {
28
- productId: primaryKey({
29
- columns: [
30
- table.id
31
- ],
32
- name: "Product_id"
33
- })
34
- };
35
- });
36
- }
37
- __name(getProductSchema, "getProductSchema");
38
-
39
- export {
40
- getProductSchema
41
- };
42
- //# sourceMappingURL=chunk-CPE4P26C.js.map
@@ -1,18 +0,0 @@
1
- import {
2
- __name
3
- } from "./chunk-VNI36MMC.js";
4
-
5
- // src/lib/utils.ts
6
- function stripUndefined(obj) {
7
- const result = {};
8
- for (const key in obj)
9
- if (obj[key] !== void 0)
10
- result[key] = obj[key];
11
- return result;
12
- }
13
- __name(stripUndefined, "stripUndefined");
14
-
15
- export {
16
- stripUndefined
17
- };
18
- //# sourceMappingURL=chunk-GFUUJRX7.js.map