faire-auth 1.0.3 → 1.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/{adapter-factory-lKIOf2OR.mjs → adapter-factory-qPVW8x9-.mjs} +34 -36
- package/dist/{adapter-factory-D1I7joki.cjs → adapter-factory-u8r3oTez.cjs} +66 -68
- package/dist/adapters/drizzle-adapter/index.cjs +34 -40
- package/dist/adapters/drizzle-adapter/index.d.cts +4 -9
- package/dist/adapters/drizzle-adapter/index.d.mts +4 -9
- package/dist/adapters/drizzle-adapter/index.mjs +20 -26
- package/dist/adapters/index.cjs +11 -16
- package/dist/adapters/index.d.cts +11 -37
- package/dist/adapters/index.d.mts +11 -37
- package/dist/adapters/index.mjs +4 -13
- package/dist/adapters/kysely-adapter/index.cjs +270 -11
- package/dist/adapters/kysely-adapter/index.d.cts +9 -19
- package/dist/adapters/kysely-adapter/index.d.mts +9 -19
- package/dist/adapters/kysely-adapter/index.mjs +267 -9
- package/dist/adapters/memory-adapter/index.cjs +146 -9
- package/dist/adapters/memory-adapter/index.d.cts +4 -10
- package/dist/adapters/memory-adapter/index.d.mts +4 -10
- package/dist/adapters/memory-adapter/index.mjs +145 -9
- package/dist/adapters/mongodb-adapter/index.cjs +13 -21
- package/dist/adapters/mongodb-adapter/index.d.cts +3 -8
- package/dist/adapters/mongodb-adapter/index.d.mts +4 -9
- package/dist/adapters/mongodb-adapter/index.mjs +12 -20
- package/dist/adapters/prisma-adapter/index.cjs +12 -20
- package/dist/adapters/prisma-adapter/index.d.cts +4 -8
- package/dist/adapters/prisma-adapter/index.d.mts +4 -8
- package/dist/adapters/prisma-adapter/index.mjs +5 -13
- package/dist/adapters/test.cjs +86 -69
- package/dist/adapters/test.d.cts +7 -11
- package/dist/adapters/test.d.mts +7 -11
- package/dist/adapters/test.mjs +83 -66
- package/dist/api/index.cjs +3 -20
- package/dist/api/index.d.cts +2 -3
- package/dist/api/index.d.mts +2 -3
- package/dist/api/index.mjs +1 -20
- package/dist/api/middleware/index.cjs +4 -11
- package/dist/api/middleware/index.d.cts +3 -9
- package/dist/api/middleware/index.d.mts +3 -9
- package/dist/api/middleware/index.mjs +3 -11
- package/dist/{api-B4RDwBty.mjs → api-0f-F-Fi2.mjs} +292 -189
- package/dist/{api-CaRC1Gio.cjs → api-LjfH6hQi.cjs} +557 -452
- package/dist/{test-utils/bun-sqlite-dialect-BZBvHchL.cjs → bun-sqlite-dialect-BHkarnxN.cjs} +5 -9
- package/dist/{test-utils/bun-sqlite-dialect-BSWhhKNs.mjs → bun-sqlite-dialect-BiZBuEF6.mjs} +6 -9
- package/dist/client/index.cjs +8 -15
- package/dist/client/index.d.cts +9 -14
- package/dist/client/index.d.mts +9 -14
- package/dist/client/index.mjs +7 -15
- package/dist/client/lynx/index.cjs +10 -18
- package/dist/client/lynx/index.d.cts +402 -71
- package/dist/client/lynx/index.d.mts +402 -71
- package/dist/client/lynx/index.mjs +5 -13
- package/dist/client/plugins/index.cjs +3 -5
- package/dist/client/plugins/index.d.cts +5 -10
- package/dist/client/plugins/index.d.mts +5 -10
- package/dist/client/plugins/index.mjs +2 -4
- package/dist/client/react/index.cjs +6 -14
- package/dist/client/react/index.d.cts +402 -71
- package/dist/client/react/index.d.mts +402 -71
- package/dist/client/react/index.mjs +5 -13
- package/dist/client/solid/index.cjs +6 -14
- package/dist/client/solid/index.d.cts +393 -57
- package/dist/client/solid/index.d.mts +393 -57
- package/dist/client/solid/index.mjs +5 -13
- package/dist/client/svelte/index.cjs +5 -10
- package/dist/client/svelte/index.d.cts +400 -67
- package/dist/client/svelte/index.d.mts +400 -67
- package/dist/client/svelte/index.mjs +4 -10
- package/dist/client/vue/index.cjs +6 -14
- package/dist/client/vue/index.d.cts +401 -68
- package/dist/client/vue/index.d.mts +401 -68
- package/dist/client/vue/index.mjs +5 -13
- package/dist/{cookies-BTs1o992.mjs → cookies-D9aY_gJh.mjs} +25 -21
- package/dist/{cookies-BTl72THv.cjs → cookies-DQ52rcOy.cjs} +119 -115
- package/dist/crypto/index.cjs +10 -8
- package/dist/crypto/index.d.cts +5 -13
- package/dist/crypto/index.d.mts +5 -13
- package/dist/crypto/index.mjs +2 -5
- package/dist/{crypto-DH2Aa7jN.mjs → crypto-BH-hD0lJ.mjs} +7 -10
- package/dist/{crypto-DpSCnrTp.cjs → crypto-BITfWVwD.cjs} +24 -27
- package/dist/db/index.cjs +1135 -29
- package/dist/db/index.d.cts +1 -2
- package/dist/db/index.d.mts +1 -2
- package/dist/db/index.mjs +1115 -16
- package/dist/defu-D2h4S3X-.mjs +87 -0
- package/dist/defu-DWS5RPWt.cjs +134 -0
- package/dist/{email-verification-DI_0H4JC.cjs → email-verification-DOPnSgbI.cjs} +65 -71
- package/dist/{email-verification-C_lBu_JY.mjs → email-verification-YSR5n5lb.mjs} +23 -29
- package/dist/{hono-CO-zsqI-.mjs → hono-BAV2wQkK.mjs} +16 -33
- package/dist/hono-SVQuc5Ru.mjs +4 -0
- package/dist/hono-pgK4H_U1.cjs +9 -0
- package/dist/{hono-DnW5crl1.cjs → hono-tyFFJFdS.cjs} +42 -60
- package/dist/index-B86Cy0dE.d.cts +2 -0
- package/dist/index-B86Cy0dE.d.mts +2 -0
- package/dist/index.cjs +115 -150
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +46 -81
- package/dist/integrations/next-js.cjs +5 -9
- package/dist/integrations/next-js.d.cts +6 -14
- package/dist/integrations/next-js.d.mts +6 -14
- package/dist/integrations/next-js.mjs +4 -9
- package/dist/integrations/node.cjs +16 -14
- package/dist/integrations/node.d.cts +6 -14
- package/dist/integrations/node.d.mts +6 -14
- package/dist/integrations/node.mjs +15 -13
- package/dist/integrations/react-start.cjs +7 -11
- package/dist/integrations/react-start.d.cts +5 -13
- package/dist/integrations/react-start.d.mts +5 -13
- package/dist/integrations/react-start.mjs +6 -11
- package/dist/integrations/solid-start.cjs +3 -5
- package/dist/integrations/solid-start.d.cts +2 -5
- package/dist/integrations/solid-start.d.mts +2 -5
- package/dist/integrations/solid-start.mjs +2 -4
- package/dist/integrations/svelte-kit.cjs +6 -10
- package/dist/integrations/svelte-kit.d.cts +11 -23
- package/dist/integrations/svelte-kit.d.mts +11 -23
- package/dist/integrations/svelte-kit.mjs +5 -10
- package/dist/{ip-BjNYspCH.mjs → ip-6Lv2o42m.mjs} +4 -9
- package/dist/{ip-C17Qdq-G.cjs → ip-DPydExzV.cjs} +21 -27
- package/dist/{json--tl7Grvs.cjs → json-D3aq-nH2.cjs} +9 -13
- package/dist/{json-B1v2qRTQ.mjs → json-DooGMtnJ.mjs} +2 -5
- package/dist/{logged-CyGfp8_H.mjs → logged-B83SzMnJ.mjs} +6 -10
- package/dist/{logged-Dv3st5qc.cjs → logged-BIpCpnVY.cjs} +13 -18
- package/dist/{middleware-CE6OhDkq.mjs → middleware-Cakg4e1D.mjs} +2 -4
- package/dist/{middleware-CWvRH4EW.cjs → middleware-Cd-VkNxB.cjs} +17 -20
- package/dist/{node-sqlite-dialect-w4DAg0PH.mjs → node-sqlite-dialect-BMVOjEMh.mjs} +6 -9
- package/dist/{test-utils/node-sqlite-dialect-BgJqjBOu.cjs → node-sqlite-dialect-D3QPFROH.cjs} +5 -9
- package/dist/oauth2/index.cjs +166 -22
- package/dist/oauth2/index.d.cts +5 -17
- package/dist/oauth2/index.d.mts +5 -17
- package/dist/oauth2/index.mjs +156 -16
- package/dist/{origin-check-DjLTuZQ8.cjs → origin-check-BflGhEEN.cjs} +34 -38
- package/dist/{origin-check-8Gajklvh.mjs → origin-check-CRgs1M7k.mjs} +13 -16
- package/dist/{parser-B25ylT5u.mjs → parser-CqwvpF6l.cjs} +12 -10
- package/dist/{parser-B_wxvaAr.cjs → parser-DcKDjjHO.mjs} +7 -22
- package/dist/plugins/access/index.cjs +38 -4
- package/dist/plugins/access/index.d.cts +36 -2
- package/dist/plugins/access/index.d.mts +36 -2
- package/dist/plugins/access/index.mjs +36 -3
- package/dist/plugins/bearer/index.cjs +52 -7
- package/dist/plugins/bearer/index.d.cts +27 -4
- package/dist/plugins/bearer/index.d.mts +27 -4
- package/dist/plugins/bearer/index.mjs +51 -7
- package/dist/plugins/index.cjs +1385 -842
- package/dist/plugins/index.d.cts +489 -7566
- package/dist/plugins/index.d.mts +489 -7566
- package/dist/plugins/index.mjs +1118 -576
- package/dist/plugins/passkey/index.cjs +551 -15
- package/dist/plugins/passkey/index.d.cts +123 -4
- package/dist/plugins/passkey/index.d.mts +123 -4
- package/dist/plugins/passkey/index.mjs +547 -15
- package/dist/{chunk-BFnQceUY.mjs → rolldown-runtime-BKpuH2hG.mjs} +6 -7
- package/dist/{chunk-fPmz2rbM.cjs → rolldown-runtime-C_Pgydhf.cjs} +22 -24
- package/dist/{schema-DTIwLLmf.mjs → schema-CFCpv0tK.mjs} +3 -6
- package/dist/{schema-CirKflVs.cjs → schema-b-lKhMkG.cjs} +51 -55
- package/dist/{session-CM3rmOYF.mjs → session-BGjJgihS.mjs} +51 -74
- package/dist/{session-Cwrj4GfV.cjs → session-CzZSMmQC.cjs} +197 -219
- package/dist/shared.d.cts +1581 -0
- package/dist/shared.d.mts +1581 -0
- package/dist/social-providers/index.cjs +9 -9
- package/dist/social-providers/index.d.cts +1 -1
- package/dist/social-providers/index.d.mts +1 -1
- package/dist/social-providers/index.mjs +3 -5
- package/dist/social-providers-CjPww-qf.mjs +6 -0
- package/dist/social-providers-D7w_7Ym8.cjs +10 -0
- package/dist/{state-CvSihlVT.cjs → state-2OrNjOO-.cjs} +24 -24
- package/dist/{state-CQghgH9I.mjs → state-Dooeisfq.mjs} +17 -17
- package/dist/{bun-sqlite-dialect-DPgTzc0w.cjs → test-utils/bun-sqlite-dialect-BHkarnxN.cjs} +5 -9
- package/dist/{bun-sqlite-dialect-6NqeV3px.mjs → test-utils/bun-sqlite-dialect-BiZBuEF6.mjs} +6 -9
- package/dist/test-utils/index.cjs +8831 -7941
- package/dist/test-utils/index.d.cts +310 -12440
- package/dist/test-utils/index.d.mts +313 -12440
- package/dist/test-utils/index.mjs +8591 -7701
- package/dist/test-utils/{node-sqlite-dialect-DAQXiobH.mjs → node-sqlite-dialect-BMVOjEMh.mjs} +6 -9
- package/dist/{node-sqlite-dialect-DP11CB0y.cjs → test-utils/node-sqlite-dialect-D3QPFROH.cjs} +5 -9
- package/dist/types/index.d.cts +2 -3
- package/dist/types/index.d.mts +2 -3
- package/dist/types/index.mjs +1 -1
- package/dist/{url-BoUuoIwZ.mjs → url-CJtdrrUu.mjs} +12 -13
- package/dist/{url-Ce7CVaQD.cjs → url-DjCmCUHS.cjs} +42 -44
- package/dist/utils/cookies.cjs +29 -30
- package/dist/utils/cookies.d.cts +21 -25
- package/dist/utils/cookies.d.mts +20 -24
- package/dist/utils/cookies.mjs +2 -7
- package/dist/utils-C7OHyfHa.mjs +4 -0
- package/dist/utils-iX0Vy_UL.cjs +3 -0
- package/package.json +40 -30
- package/dist/access-BZ7-AbTM.cjs +0 -51
- package/dist/access-D0DRqUKC.mjs +0 -39
- package/dist/bearer-DDzrp5M7.cjs +0 -60
- package/dist/bearer-WZcs7gxL.mjs +0 -54
- package/dist/db-4tUsQJXd.mjs +0 -1119
- package/dist/db-ChMbb_U-.cjs +0 -1180
- package/dist/defu-BmOYq4PU.cjs +0 -34
- package/dist/defu-D9ZTXqlo.mjs +0 -28
- package/dist/hono-C14rpOEa.cjs +0 -13
- package/dist/hono-CoKYWnXA.mjs +0 -7
- package/dist/hono-D0VqxVy1.d.mts +0 -18
- package/dist/hono-DOM31WQz.d.cts +0 -18
- package/dist/index-BCTFWP_o.d.mts +0 -992
- package/dist/index-BDhhaE6Y.d.cts +0 -3
- package/dist/index-BVRfQy6L.d.mts +0 -992
- package/dist/index-Baarsq5J.d.mts +0 -33
- package/dist/index-By364WbF.d.cts +0 -992
- package/dist/index-BzWwMgxr.d.cts +0 -992
- package/dist/index-CF9iq55a.d.mts +0 -3
- package/dist/index-CJD2yB-W.d.cts +0 -33
- package/dist/index-CRt_fppq.d.mts +0 -41
- package/dist/index-CdLyn7qP.d.cts +0 -41
- package/dist/index-CsWF3f7U.d.cts +0 -13350
- package/dist/index-CzidsAyA.d.mts +0 -13350
- package/dist/index-DvW-GCcI.d.cts +0 -33
- package/dist/index-f-5OJ9yV.d.cts +0 -13350
- package/dist/index-rFv8Hxld.d.mts +0 -13350
- package/dist/index-ztVZPQdV.d.mts +0 -33
- package/dist/kysely-adapter-CtIdoHa8.mjs +0 -270
- package/dist/kysely-adapter-QZTx077T.cjs +0 -288
- package/dist/memory-adapter-17RZd5df.cjs +0 -154
- package/dist/memory-adapter-Dp4XdCZK.mjs +0 -148
- package/dist/oauth2-5RL4cVNS.cjs +0 -177
- package/dist/oauth2-C56wz-n9.mjs +0 -159
- package/dist/passkey-BTT-v5c-.cjs +0 -512
- package/dist/passkey-CzY_W2us.mjs +0 -505
- package/dist/request-1NL_1lyJ.mjs +0 -58
- package/dist/request-CPNlp-DK.cjs +0 -100
- package/dist/social-providers-B8RK5yqI.mjs +0 -9
- package/dist/social-providers-BmFOIIPk.cjs +0 -13
- package/dist/utils-44aDDP8f.cjs +0 -2
- package/dist/utils-D4vZd1-9.mjs +0 -4
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { r as generateId } from "./utils-C7OHyfHa.mjs";
|
|
2
|
+
import { t as safeJSONParse } from "./json-DooGMtnJ.mjs";
|
|
3
3
|
import { TTY_COLORS, getColorDepth, logger } from "@faire-auth/core/env";
|
|
4
4
|
import { FaireAuthError } from "@faire-auth/core/error";
|
|
5
5
|
import { isPromise } from "@faire-auth/core/static";
|
|
6
|
-
|
|
7
|
-
//#region src/adapters/utils.ts
|
|
6
|
+
// src/adapters/utils.ts
|
|
8
7
|
function withApplyDefault(value, field, action) {
|
|
9
8
|
if (action === "update") {
|
|
10
9
|
if (value === void 0 && field.onUpdate !== void 0) {
|
|
@@ -21,9 +20,7 @@ function withApplyDefault(value, field, action) {
|
|
|
21
20
|
}
|
|
22
21
|
return value;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/db/get-tables.ts
|
|
23
|
+
// src/db/get-tables.ts
|
|
27
24
|
const getAuthTables = (options) => {
|
|
28
25
|
const pluginSchema = (options.plugins ?? []).reduce((acc, plugin) => {
|
|
29
26
|
const schema = plugin.schema;
|
|
@@ -56,7 +53,7 @@ const getAuthTables = (options) => {
|
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
55
|
} };
|
|
59
|
-
const { user, session, account
|
|
56
|
+
const { user, session, account, ...pluginTables } = pluginSchema;
|
|
60
57
|
const sessionTable = { session: {
|
|
61
58
|
modelName: options.session?.modelName || "session",
|
|
62
59
|
fields: {
|
|
@@ -268,9 +265,7 @@ const getAuthTables = (options) => {
|
|
|
268
265
|
...shouldAddRateLimitTable ? rateLimitTable : {}
|
|
269
266
|
};
|
|
270
267
|
};
|
|
271
|
-
|
|
272
|
-
//#endregion
|
|
273
|
-
//#region src/adapters/adapter-factory/index.ts
|
|
268
|
+
// src/adapters/adapter-factory/index.ts
|
|
274
269
|
let debugLogs = [];
|
|
275
270
|
let transactionId = -1;
|
|
276
271
|
const createAsIsTransaction = (adapter) => (fn) => {
|
|
@@ -307,7 +302,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
307
302
|
const model = getDefaultModelName(unsafe_model);
|
|
308
303
|
let f = schema[model]?.fields[field];
|
|
309
304
|
if (!f) {
|
|
310
|
-
const result = Object.entries(schema[model].fields).find(([_, f
|
|
305
|
+
const result = Object.entries(schema[model].fields).find(([_, f]) => f.fieldName === field);
|
|
311
306
|
if (result) {
|
|
312
307
|
f = result[1];
|
|
313
308
|
field = result[0];
|
|
@@ -334,9 +329,9 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
334
329
|
const getDefaultModelName = (model) => {
|
|
335
330
|
if (config.usePlural && model.charAt(model.length - 1) === "s") {
|
|
336
331
|
let pluralessModel = model.slice(0, -1);
|
|
337
|
-
let m
|
|
338
|
-
if (!m
|
|
339
|
-
if (m
|
|
332
|
+
let m = schema[pluralessModel] ? pluralessModel : void 0;
|
|
333
|
+
if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === pluralessModel)?.[0];
|
|
334
|
+
if (m) return m;
|
|
340
335
|
}
|
|
341
336
|
let m = schema[model] ? model : void 0;
|
|
342
337
|
if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === model)?.[0];
|
|
@@ -450,9 +445,10 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
450
445
|
if (value === void 0 && (fieldAttributes.defaultValue === void 0 && !fieldAttributes.transform?.input && !(action === "update" && fieldAttributes.onUpdate) || action === "update" && !fieldAttributes.onUpdate)) continue;
|
|
451
446
|
let newValue = withApplyDefault(value, fieldAttributes, action);
|
|
452
447
|
if (fieldAttributes.transform?.input) newValue = await fieldAttributes.transform.input(newValue);
|
|
453
|
-
if (fieldAttributes.references?.field === "id" && options.advanced?.database?.useNumberId)
|
|
454
|
-
|
|
455
|
-
|
|
448
|
+
if (fieldAttributes.references?.field === "id" && options.advanced?.database?.useNumberId) {
|
|
449
|
+
if (Array.isArray(newValue)) newValue = newValue.map((x) => x !== null ? Number(x) : null);
|
|
450
|
+
else newValue = newValue !== null ? Number(newValue) : null;
|
|
451
|
+
} else if (config.supportsJSON === false && typeof newValue === "object" && fieldAttributes.type === "json") newValue = JSON.stringify(newValue);
|
|
456
452
|
else if (config.supportsDates === false && newValue instanceof Date && fieldAttributes.type === "date") newValue = newValue.toISOString();
|
|
457
453
|
else if (config.supportsBooleans === false && typeof newValue === "boolean") newValue = newValue ? 1 : 0;
|
|
458
454
|
if (config.customTransformInput) newValue = config.customTransformInput({
|
|
@@ -525,8 +521,10 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
525
521
|
model: defaultModelName
|
|
526
522
|
});
|
|
527
523
|
if (defaultFieldName === "id" || fieldAttr.references?.field === "id") {
|
|
528
|
-
if (options.advanced?.database?.useNumberId)
|
|
529
|
-
|
|
524
|
+
if (options.advanced?.database?.useNumberId) {
|
|
525
|
+
if (Array.isArray(value)) newValue = value.map(Number);
|
|
526
|
+
else newValue = Number(value);
|
|
527
|
+
}
|
|
530
528
|
}
|
|
531
529
|
if (fieldAttr.type === "date" && value instanceof Date && !config.supportsDates) newValue = value.toISOString();
|
|
532
530
|
if (fieldAttr.type === "boolean" && typeof value === "boolean" && !config.supportsBooleans) newValue = value ? 1 : 0;
|
|
@@ -559,12 +557,14 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
559
557
|
let lazyLoadTransaction = null;
|
|
560
558
|
const adapter = {
|
|
561
559
|
transaction: (cb) => {
|
|
562
|
-
if (!lazyLoadTransaction)
|
|
563
|
-
if (
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
560
|
+
if (!lazyLoadTransaction) {
|
|
561
|
+
if (!config.transaction) {
|
|
562
|
+
if (typeof config.debugLogs === "object" && "isRunningAdapterTests" in config.debugLogs && config.debugLogs.isRunningAdapterTests) {} else logger.warn(`[${config.adapterName}] - Transactions are not supported. Executing operations sequentially.`);
|
|
563
|
+
lazyLoadTransaction = createAsIsTransaction(adapter);
|
|
564
|
+
} else {
|
|
565
|
+
logger.debug(`[${config.adapterName}] - Using provided transaction implementation.`);
|
|
566
|
+
lazyLoadTransaction = config.transaction;
|
|
567
|
+
}
|
|
568
568
|
}
|
|
569
569
|
return lazyLoadTransaction(cb);
|
|
570
570
|
},
|
|
@@ -849,11 +849,11 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
849
849
|
},
|
|
850
850
|
printDebugLogs() {
|
|
851
851
|
const separator = `─`.repeat(80);
|
|
852
|
-
const logs = debugLogs.filter((log
|
|
852
|
+
const logs = debugLogs.filter((log) => log.instance === uniqueAdapterFactoryInstanceId);
|
|
853
853
|
if (logs.length === 0) return;
|
|
854
|
-
let log = logs.reverse().map((log
|
|
855
|
-
log
|
|
856
|
-
return [...log
|
|
854
|
+
let log = logs.reverse().map((log) => {
|
|
855
|
+
log.args[0] = `\n${log.args[0]}`;
|
|
856
|
+
return [...log.args, "\n"];
|
|
857
857
|
}).reduce((prev, curr) => {
|
|
858
858
|
return [...curr, ...prev];
|
|
859
859
|
}, [`\n${separator}`]);
|
|
@@ -863,9 +863,9 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
863
863
|
};
|
|
864
864
|
return adapter;
|
|
865
865
|
};
|
|
866
|
-
function formatTransactionId(transactionId
|
|
867
|
-
if (getColorDepth() < 8) return `#${transactionId
|
|
868
|
-
return `${TTY_COLORS.fg.magenta}#${transactionId
|
|
866
|
+
function formatTransactionId(transactionId) {
|
|
867
|
+
if (getColorDepth() < 8) return `#${transactionId}`;
|
|
868
|
+
return `${TTY_COLORS.fg.magenta}#${transactionId}${TTY_COLORS.reset}`;
|
|
869
869
|
}
|
|
870
870
|
function formatStep(step, total) {
|
|
871
871
|
return `${TTY_COLORS.bg.black}${TTY_COLORS.fg.yellow}[${step}/${total}]${TTY_COLORS.reset}`;
|
|
@@ -876,6 +876,4 @@ function formatMethod(method) {
|
|
|
876
876
|
function formatAction(action) {
|
|
877
877
|
return `${TTY_COLORS.dim}(${action})${TTY_COLORS.reset}`;
|
|
878
878
|
}
|
|
879
|
-
|
|
880
|
-
//#endregion
|
|
881
|
-
export { getAuthTables as n, createAdapterFactory as t };
|
|
879
|
+
export { getAuthTables as n, createAdapterFactory as t };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
const require_json = require(
|
|
3
|
-
let
|
|
4
|
-
let
|
|
5
|
-
let
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
//#region src/adapters/utils.ts
|
|
1
|
+
require("./utils-iX0Vy_UL.cjs");
|
|
2
|
+
const require_json = require("./json-D3aq-nH2.cjs");
|
|
3
|
+
let _faire_auth_core_env = require("@faire-auth/core/env");
|
|
4
|
+
let _faire_auth_core_error = require("@faire-auth/core/error");
|
|
5
|
+
let _faire_auth_core_static = require("@faire-auth/core/static");
|
|
6
|
+
let _faire_auth_core_crypto = require("@faire-auth/core/crypto");
|
|
7
|
+
// src/adapters/utils.ts
|
|
9
8
|
function withApplyDefault(value, field, action) {
|
|
10
9
|
if (action === "update") {
|
|
11
10
|
if (value === void 0 && field.onUpdate !== void 0) {
|
|
@@ -22,9 +21,7 @@ function withApplyDefault(value, field, action) {
|
|
|
22
21
|
}
|
|
23
22
|
return value;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/db/get-tables.ts
|
|
24
|
+
// src/db/get-tables.ts
|
|
28
25
|
const getAuthTables = (options) => {
|
|
29
26
|
const pluginSchema = (options.plugins ?? []).reduce((acc, plugin) => {
|
|
30
27
|
const schema = plugin.schema;
|
|
@@ -57,7 +54,7 @@ const getAuthTables = (options) => {
|
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
56
|
} };
|
|
60
|
-
const { user, session, account
|
|
57
|
+
const { user, session, account, ...pluginTables } = pluginSchema;
|
|
61
58
|
const sessionTable = { session: {
|
|
62
59
|
modelName: options.session?.modelName || "session",
|
|
63
60
|
fields: {
|
|
@@ -269,14 +266,12 @@ const getAuthTables = (options) => {
|
|
|
269
266
|
...shouldAddRateLimitTable ? rateLimitTable : {}
|
|
270
267
|
};
|
|
271
268
|
};
|
|
272
|
-
|
|
273
|
-
//#endregion
|
|
274
|
-
//#region src/adapters/adapter-factory/index.ts
|
|
269
|
+
// src/adapters/adapter-factory/index.ts
|
|
275
270
|
let debugLogs = [];
|
|
276
271
|
let transactionId = -1;
|
|
277
272
|
const createAsIsTransaction = (adapter) => (fn) => {
|
|
278
273
|
const res = fn(adapter);
|
|
279
|
-
return (0,
|
|
274
|
+
return (0, _faire_auth_core_static.isPromise)(res) ? res : Promise.resolve(res);
|
|
280
275
|
};
|
|
281
276
|
const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (options) => {
|
|
282
277
|
const uniqueAdapterFactoryInstanceId = Math.random().toString(36).substring(2, 15);
|
|
@@ -291,7 +286,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
291
286
|
disableTransformInput: cfg.disableTransformInput ?? false,
|
|
292
287
|
disableTransformOutput: cfg.disableTransformOutput ?? false
|
|
293
288
|
};
|
|
294
|
-
if (options.advanced?.database?.useNumberId === true && config.supportsNumericIds === false) throw new
|
|
289
|
+
if (options.advanced?.database?.useNumberId === true && config.supportsNumericIds === false) throw new _faire_auth_core_error.FaireAuthError(`[${config.adapterName}] Your database or database adapter does not support numeric ids. Please disable "useNumberId" in your config.`);
|
|
295
290
|
const schema = getAuthTables(options);
|
|
296
291
|
/**
|
|
297
292
|
* This function helps us get the default field name from the schema defined by devs.
|
|
@@ -308,7 +303,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
308
303
|
const model = getDefaultModelName(unsafe_model);
|
|
309
304
|
let f = schema[model]?.fields[field];
|
|
310
305
|
if (!f) {
|
|
311
|
-
const result = Object.entries(schema[model].fields).find(([_, f
|
|
306
|
+
const result = Object.entries(schema[model].fields).find(([_, f]) => f.fieldName === field);
|
|
312
307
|
if (result) {
|
|
313
308
|
f = result[1];
|
|
314
309
|
field = result[0];
|
|
@@ -317,7 +312,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
317
312
|
if (!f) {
|
|
318
313
|
debugLog(`Field ${field} not found in model ${model}`);
|
|
319
314
|
debugLog(`Schema:`, schema);
|
|
320
|
-
throw new
|
|
315
|
+
throw new _faire_auth_core_error.FaireAuthError(`Field ${field} not found in model ${model}`);
|
|
321
316
|
}
|
|
322
317
|
return field;
|
|
323
318
|
};
|
|
@@ -335,16 +330,16 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
335
330
|
const getDefaultModelName = (model) => {
|
|
336
331
|
if (config.usePlural && model.charAt(model.length - 1) === "s") {
|
|
337
332
|
let pluralessModel = model.slice(0, -1);
|
|
338
|
-
let m
|
|
339
|
-
if (!m
|
|
340
|
-
if (m
|
|
333
|
+
let m = schema[pluralessModel] ? pluralessModel : void 0;
|
|
334
|
+
if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === pluralessModel)?.[0];
|
|
335
|
+
if (m) return m;
|
|
341
336
|
}
|
|
342
337
|
let m = schema[model] ? model : void 0;
|
|
343
338
|
if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === model)?.[0];
|
|
344
339
|
if (!m) {
|
|
345
340
|
debugLog(`Model "${model}" not found in schema`);
|
|
346
341
|
debugLog(`Schema:`, schema);
|
|
347
|
-
throw new
|
|
342
|
+
throw new _faire_auth_core_error.FaireAuthError(`Model "${model}" not found in schema`);
|
|
348
343
|
}
|
|
349
344
|
return m;
|
|
350
345
|
};
|
|
@@ -399,8 +394,8 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
399
394
|
else if (method === "deleteMany" && !config.debugLogs.deleteMany) return;
|
|
400
395
|
else if (method === "count" && !config.debugLogs.count) return;
|
|
401
396
|
}
|
|
402
|
-
|
|
403
|
-
} else
|
|
397
|
+
_faire_auth_core_env.logger.info(`[${config.adapterName}]`, ...args);
|
|
398
|
+
} else _faire_auth_core_env.logger.info(`[${config.adapterName}]`, ...args);
|
|
404
399
|
}
|
|
405
400
|
};
|
|
406
401
|
const idField = ({ customModelName, forceAllowId }) => {
|
|
@@ -412,15 +407,15 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
412
407
|
...shouldGenerateId ? { defaultValue() {
|
|
413
408
|
if (config.disableIdGeneration) return void 0;
|
|
414
409
|
const useNumberId = options.advanced?.database?.useNumberId;
|
|
415
|
-
let generateId
|
|
410
|
+
let generateId = options.advanced?.database?.generateId;
|
|
416
411
|
if (options.advanced?.generateId !== void 0) {
|
|
417
|
-
|
|
418
|
-
generateId
|
|
412
|
+
_faire_auth_core_env.logger.warn("Your Faire Auth config includes advanced.generateId which is deprecated. Please use advanced.database.generateId instead. This will be removed in future releases.");
|
|
413
|
+
generateId = options.advanced?.generateId;
|
|
419
414
|
}
|
|
420
|
-
if (generateId
|
|
421
|
-
if (generateId
|
|
415
|
+
if (generateId === false || useNumberId) return void 0;
|
|
416
|
+
if (generateId) return generateId({ model });
|
|
422
417
|
if (config.customIdGenerator) return config.customIdGenerator({ model });
|
|
423
|
-
return (0,
|
|
418
|
+
return (0, _faire_auth_core_crypto.generateId)();
|
|
424
419
|
} } : {}
|
|
425
420
|
};
|
|
426
421
|
};
|
|
@@ -433,7 +428,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
433
428
|
const fields = schema[defaultModelName].fields;
|
|
434
429
|
fields.id = idField({ customModelName: defaultModelName });
|
|
435
430
|
const fieldAttributes = fields[defaultFieldName];
|
|
436
|
-
if (!fieldAttributes) throw new
|
|
431
|
+
if (!fieldAttributes) throw new _faire_auth_core_error.FaireAuthError(`Field ${field} not found in model ${model}`);
|
|
437
432
|
return fieldAttributes;
|
|
438
433
|
};
|
|
439
434
|
const transformInput = async (data, defaultModelName, action, forceAllowId) => {
|
|
@@ -451,9 +446,10 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
451
446
|
if (value === void 0 && (fieldAttributes.defaultValue === void 0 && !fieldAttributes.transform?.input && !(action === "update" && fieldAttributes.onUpdate) || action === "update" && !fieldAttributes.onUpdate)) continue;
|
|
452
447
|
let newValue = withApplyDefault(value, fieldAttributes, action);
|
|
453
448
|
if (fieldAttributes.transform?.input) newValue = await fieldAttributes.transform.input(newValue);
|
|
454
|
-
if (fieldAttributes.references?.field === "id" && options.advanced?.database?.useNumberId)
|
|
455
|
-
|
|
456
|
-
|
|
449
|
+
if (fieldAttributes.references?.field === "id" && options.advanced?.database?.useNumberId) {
|
|
450
|
+
if (Array.isArray(newValue)) newValue = newValue.map((x) => x !== null ? Number(x) : null);
|
|
451
|
+
else newValue = newValue !== null ? Number(newValue) : null;
|
|
452
|
+
} else if (config.supportsJSON === false && typeof newValue === "object" && fieldAttributes.type === "json") newValue = JSON.stringify(newValue);
|
|
457
453
|
else if (config.supportsDates === false && newValue instanceof Date && fieldAttributes.type === "date") newValue = newValue.toISOString();
|
|
458
454
|
else if (config.supportsBooleans === false && typeof newValue === "boolean") newValue = newValue ? 1 : 0;
|
|
459
455
|
if (config.customTransformInput) newValue = config.customTransformInput({
|
|
@@ -509,7 +505,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
509
505
|
return where.map((w) => {
|
|
510
506
|
const { field: unsafe_field, value, operator = "eq", connector = "AND" } = w;
|
|
511
507
|
if (operator === "in") {
|
|
512
|
-
if (!Array.isArray(value)) throw new
|
|
508
|
+
if (!Array.isArray(value)) throw new _faire_auth_core_error.FaireAuthError("Value must be an array");
|
|
513
509
|
}
|
|
514
510
|
let newValue = value;
|
|
515
511
|
const defaultModelName = getDefaultModelName(model);
|
|
@@ -526,8 +522,10 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
526
522
|
model: defaultModelName
|
|
527
523
|
});
|
|
528
524
|
if (defaultFieldName === "id" || fieldAttr.references?.field === "id") {
|
|
529
|
-
if (options.advanced?.database?.useNumberId)
|
|
530
|
-
|
|
525
|
+
if (options.advanced?.database?.useNumberId) {
|
|
526
|
+
if (Array.isArray(value)) newValue = value.map(Number);
|
|
527
|
+
else newValue = Number(value);
|
|
528
|
+
}
|
|
531
529
|
}
|
|
532
530
|
if (fieldAttr.type === "date" && value instanceof Date && !config.supportsDates) newValue = value.toISOString();
|
|
533
531
|
if (fieldAttr.type === "boolean" && typeof value === "boolean" && !config.supportsBooleans) newValue = value ? 1 : 0;
|
|
@@ -560,12 +558,14 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
560
558
|
let lazyLoadTransaction = null;
|
|
561
559
|
const adapter = {
|
|
562
560
|
transaction: (cb) => {
|
|
563
|
-
if (!lazyLoadTransaction)
|
|
564
|
-
if (
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
561
|
+
if (!lazyLoadTransaction) {
|
|
562
|
+
if (!config.transaction) {
|
|
563
|
+
if (typeof config.debugLogs === "object" && "isRunningAdapterTests" in config.debugLogs && config.debugLogs.isRunningAdapterTests) {} else _faire_auth_core_env.logger.warn(`[${config.adapterName}] - Transactions are not supported. Executing operations sequentially.`);
|
|
564
|
+
lazyLoadTransaction = createAsIsTransaction(adapter);
|
|
565
|
+
} else {
|
|
566
|
+
_faire_auth_core_env.logger.debug(`[${config.adapterName}] - Using provided transaction implementation.`);
|
|
567
|
+
lazyLoadTransaction = config.transaction;
|
|
568
|
+
}
|
|
569
569
|
}
|
|
570
570
|
return lazyLoadTransaction(cb);
|
|
571
571
|
},
|
|
@@ -575,7 +575,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
575
575
|
const model = getModelName(unsafeModel);
|
|
576
576
|
unsafeModel = getDefaultModelName(unsafeModel);
|
|
577
577
|
if ("id" in unsafeData && !forceAllowId) {
|
|
578
|
-
|
|
578
|
+
_faire_auth_core_env.logger.warn(`[${config.adapterName}] - You are trying to create a record with an id. This is not allowed as we handle id generation for you, unless you pass in the \`forceAllowId\` parameter. The id will be ignored.`);
|
|
579
579
|
const stack = (/* @__PURE__ */ new Error()).stack?.split("\n").filter((_, i) => i !== 1).join("\n").replace("Error:", "Create method with `id` being called at:");
|
|
580
580
|
console.log(stack);
|
|
581
581
|
unsafeData.id = void 0;
|
|
@@ -850,11 +850,11 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
850
850
|
},
|
|
851
851
|
printDebugLogs() {
|
|
852
852
|
const separator = `─`.repeat(80);
|
|
853
|
-
const logs = debugLogs.filter((log
|
|
853
|
+
const logs = debugLogs.filter((log) => log.instance === uniqueAdapterFactoryInstanceId);
|
|
854
854
|
if (logs.length === 0) return;
|
|
855
|
-
let log = logs.reverse().map((log
|
|
856
|
-
log
|
|
857
|
-
return [...log
|
|
855
|
+
let log = logs.reverse().map((log) => {
|
|
856
|
+
log.args[0] = `\n${log.args[0]}`;
|
|
857
|
+
return [...log.args, "\n"];
|
|
858
858
|
}).reduce((prev, curr) => {
|
|
859
859
|
return [...curr, ...prev];
|
|
860
860
|
}, [`\n${separator}`]);
|
|
@@ -864,30 +864,28 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
|
|
|
864
864
|
};
|
|
865
865
|
return adapter;
|
|
866
866
|
};
|
|
867
|
-
function formatTransactionId(transactionId
|
|
868
|
-
if ((0,
|
|
869
|
-
return `${
|
|
867
|
+
function formatTransactionId(transactionId) {
|
|
868
|
+
if ((0, _faire_auth_core_env.getColorDepth)() < 8) return `#${transactionId}`;
|
|
869
|
+
return `${_faire_auth_core_env.TTY_COLORS.fg.magenta}#${transactionId}${_faire_auth_core_env.TTY_COLORS.reset}`;
|
|
870
870
|
}
|
|
871
871
|
function formatStep(step, total) {
|
|
872
|
-
return `${
|
|
872
|
+
return `${_faire_auth_core_env.TTY_COLORS.bg.black}${_faire_auth_core_env.TTY_COLORS.fg.yellow}[${step}/${total}]${_faire_auth_core_env.TTY_COLORS.reset}`;
|
|
873
873
|
}
|
|
874
874
|
function formatMethod(method) {
|
|
875
|
-
return `${
|
|
875
|
+
return `${_faire_auth_core_env.TTY_COLORS.bright}${method}${_faire_auth_core_env.TTY_COLORS.reset}`;
|
|
876
876
|
}
|
|
877
877
|
function formatAction(action) {
|
|
878
|
-
return `${
|
|
878
|
+
return `${_faire_auth_core_env.TTY_COLORS.dim}(${action})${_faire_auth_core_env.TTY_COLORS.reset}`;
|
|
879
879
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
880
|
+
Object.defineProperty(exports, "createAdapterFactory", {
|
|
881
|
+
enumerable: true,
|
|
882
|
+
get: function() {
|
|
883
|
+
return createAdapterFactory;
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
Object.defineProperty(exports, "getAuthTables", {
|
|
887
|
+
enumerable: true,
|
|
888
|
+
get: function() {
|
|
889
|
+
return getAuthTables;
|
|
890
|
+
}
|
|
887
891
|
});
|
|
888
|
-
Object.defineProperty(exports, 'getAuthTables', {
|
|
889
|
-
enumerable: true,
|
|
890
|
-
get: function () {
|
|
891
|
-
return getAuthTables;
|
|
892
|
-
}
|
|
893
|
-
});
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
require(
|
|
3
|
-
require(
|
|
4
|
-
require('../../state-CvSihlVT.cjs');
|
|
5
|
-
require('../../request-CPNlp-DK.cjs');
|
|
6
|
-
require('../../utils-44aDDP8f.cjs');
|
|
7
|
-
const require_adapter_factory = require('../../adapter-factory-D1I7joki.cjs');
|
|
8
|
-
let __faire_auth_core_error = require("@faire-auth/core/error");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_adapter_factory = require("../../adapter-factory-u8r3oTez.cjs");
|
|
3
|
+
let _faire_auth_core_error = require("@faire-auth/core/error");
|
|
9
4
|
let drizzle_orm = require("drizzle-orm");
|
|
10
|
-
|
|
11
|
-
//#region src/adapters/drizzle-adapter/drizzle-adapter.ts
|
|
5
|
+
// src/adapters/drizzle-adapter/drizzle-adapter.ts
|
|
12
6
|
const drizzleAdapter = (db, config) => {
|
|
13
7
|
let lazyOptions = null;
|
|
14
|
-
const createCustomAdapter = (db
|
|
8
|
+
const createCustomAdapter = (db) => ({ getFieldName, debugLog }) => {
|
|
15
9
|
function getSchema(model) {
|
|
16
|
-
const schema = config.schema || db
|
|
17
|
-
if (!schema) throw new
|
|
10
|
+
const schema = config.schema || db._.fullSchema;
|
|
11
|
+
if (!schema) throw new _faire_auth_core_error.FaireAuthError("Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object.");
|
|
18
12
|
const schemaModel = schema[model];
|
|
19
|
-
if (!schemaModel) throw new
|
|
13
|
+
if (!schemaModel) throw new _faire_auth_core_error.FaireAuthError(`[# Drizzle Adapter]: The model "${model}" was not found in the schema object. Please pass the schema directly to the adapter options.`);
|
|
20
14
|
return schemaModel;
|
|
21
15
|
}
|
|
22
16
|
const withReturning = async (model, builder, data, where) => {
|
|
@@ -32,15 +26,15 @@ const drizzleAdapter = (db, config) => {
|
|
|
32
26
|
};
|
|
33
27
|
return w;
|
|
34
28
|
}), model);
|
|
35
|
-
return (await db
|
|
29
|
+
return (await db.select().from(schemaModel).where(...clause))[0];
|
|
36
30
|
} else if (builderVal && builderVal[0]?.id?.value) {
|
|
37
31
|
let tId = builderVal[0]?.id?.value;
|
|
38
|
-
if (!tId) tId = (await db
|
|
39
|
-
return (await db
|
|
40
|
-
} else if (data.id) return (await db
|
|
32
|
+
if (!tId) tId = (await db.select({ id: drizzle_orm.sql`LAST_INSERT_ID()` }).from(schemaModel).orderBy((0, drizzle_orm.desc)(schemaModel.id)).limit(1))[0].id;
|
|
33
|
+
return (await db.select().from(schemaModel).where((0, drizzle_orm.eq)(schemaModel.id, tId)).limit(1).execute())[0];
|
|
34
|
+
} else if (data.id) return (await db.select().from(schemaModel).where((0, drizzle_orm.eq)(schemaModel.id, data.id)).limit(1).execute())[0];
|
|
41
35
|
else {
|
|
42
|
-
if (!("id" in schemaModel)) throw new
|
|
43
|
-
return (await db
|
|
36
|
+
if (!("id" in schemaModel)) throw new _faire_auth_core_error.FaireAuthError(`The model "${model}" does not have an "id" field. Please use the "id" field as your primary key.`);
|
|
37
|
+
return (await db.select().from(schemaModel).orderBy((0, drizzle_orm.desc)(schemaModel.id)).limit(1).execute())[0];
|
|
44
38
|
}
|
|
45
39
|
};
|
|
46
40
|
function convertWhereClause(where, model) {
|
|
@@ -53,13 +47,13 @@ const drizzleAdapter = (db, config) => {
|
|
|
53
47
|
model,
|
|
54
48
|
field: w.field
|
|
55
49
|
});
|
|
56
|
-
if (!schemaModel[field]) throw new
|
|
50
|
+
if (!schemaModel[field]) throw new _faire_auth_core_error.FaireAuthError(`The field "${w.field}" does not exist in the schema for the model "${model}". Please update your schema.`);
|
|
57
51
|
if (w.operator === "in") {
|
|
58
|
-
if (!Array.isArray(w.value)) throw new
|
|
52
|
+
if (!Array.isArray(w.value)) throw new _faire_auth_core_error.FaireAuthError(`The value for the field "${w.field}" must be an array when using the "in" operator.`);
|
|
59
53
|
return [(0, drizzle_orm.inArray)(schemaModel[field], w.value)];
|
|
60
54
|
}
|
|
61
55
|
if (w.operator === "not_in") {
|
|
62
|
-
if (!Array.isArray(w.value)) throw new
|
|
56
|
+
if (!Array.isArray(w.value)) throw new _faire_auth_core_error.FaireAuthError(`The value for the field "${w.field}" must be an array when using the "not_in" operator.`);
|
|
63
57
|
return [(0, drizzle_orm.notInArray)(schemaModel[field], w.value)];
|
|
64
58
|
}
|
|
65
59
|
if (w.operator === "contains") return [(0, drizzle_orm.like)(schemaModel[field], `%${w.value}%`)];
|
|
@@ -80,11 +74,11 @@ const drizzleAdapter = (db, config) => {
|
|
|
80
74
|
field: w.field
|
|
81
75
|
});
|
|
82
76
|
if (w.operator === "in") {
|
|
83
|
-
if (!Array.isArray(w.value)) throw new
|
|
77
|
+
if (!Array.isArray(w.value)) throw new _faire_auth_core_error.FaireAuthError(`The value for the field "${w.field}" must be an array when using the "in" operator.`);
|
|
84
78
|
return (0, drizzle_orm.inArray)(schemaModel[field], w.value);
|
|
85
79
|
}
|
|
86
80
|
if (w.operator === "not_in") {
|
|
87
|
-
if (!Array.isArray(w.value)) throw new
|
|
81
|
+
if (!Array.isArray(w.value)) throw new _faire_auth_core_error.FaireAuthError(`The value for the field "${w.field}" must be an array when using the "not_in" operator.`);
|
|
88
82
|
return (0, drizzle_orm.notInArray)(schemaModel[field], w.value);
|
|
89
83
|
}
|
|
90
84
|
if (w.operator === "contains") return (0, drizzle_orm.like)(schemaModel[field], `%${w.value}%`);
|
|
@@ -103,11 +97,11 @@ const drizzleAdapter = (db, config) => {
|
|
|
103
97
|
field: w.field
|
|
104
98
|
});
|
|
105
99
|
if (w.operator === "in") {
|
|
106
|
-
if (!Array.isArray(w.value)) throw new
|
|
100
|
+
if (!Array.isArray(w.value)) throw new _faire_auth_core_error.FaireAuthError(`The value for the field "${w.field}" must be an array when using the "in" operator.`);
|
|
107
101
|
return (0, drizzle_orm.inArray)(schemaModel[field], w.value);
|
|
108
102
|
}
|
|
109
103
|
if (w.operator === "not_in") {
|
|
110
|
-
if (!Array.isArray(w.value)) throw new
|
|
104
|
+
if (!Array.isArray(w.value)) throw new _faire_auth_core_error.FaireAuthError(`The value for the field "${w.field}" must be an array when using the "not_in" operator.`);
|
|
111
105
|
return (0, drizzle_orm.notInArray)(schemaModel[field], w.value);
|
|
112
106
|
}
|
|
113
107
|
if (w.operator === "contains") return (0, drizzle_orm.like)(schemaModel[field], `%${w.value}%`);
|
|
@@ -126,19 +120,20 @@ const drizzleAdapter = (db, config) => {
|
|
|
126
120
|
return clause;
|
|
127
121
|
}
|
|
128
122
|
function checkMissingFields(schema, model, values) {
|
|
129
|
-
if (!schema) throw new
|
|
130
|
-
for (const key in values) if (!schema[key]) throw new
|
|
123
|
+
if (!schema) throw new _faire_auth_core_error.FaireAuthError("Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object.");
|
|
124
|
+
for (const key in values) if (!schema[key]) throw new _faire_auth_core_error.FaireAuthError(`The field "${key}" does not exist in the "${model}" schema. Please update your drizzle schema or re-generate using "npx @faire-auth/cli generate".`);
|
|
131
125
|
}
|
|
132
126
|
return {
|
|
133
127
|
async create({ model, data: values }) {
|
|
134
128
|
const schemaModel = getSchema(model);
|
|
135
129
|
checkMissingFields(schemaModel, model, values);
|
|
136
|
-
|
|
130
|
+
const builder = db.insert(schemaModel).values(values);
|
|
131
|
+
return await withReturning(model, builder, values);
|
|
137
132
|
},
|
|
138
133
|
async findOne({ model, where }) {
|
|
139
134
|
const schemaModel = getSchema(model);
|
|
140
135
|
const clause = convertWhereClause(where, model);
|
|
141
|
-
const res = await db
|
|
136
|
+
const res = await db.select().from(schemaModel).where(...clause);
|
|
142
137
|
if (!res.length) return null;
|
|
143
138
|
return res[0];
|
|
144
139
|
},
|
|
@@ -146,7 +141,7 @@ const drizzleAdapter = (db, config) => {
|
|
|
146
141
|
const schemaModel = getSchema(model);
|
|
147
142
|
const clause = where ? convertWhereClause(where, model) : [];
|
|
148
143
|
const sortFn = sortBy?.direction === "desc" ? drizzle_orm.desc : drizzle_orm.asc;
|
|
149
|
-
const builder = db
|
|
144
|
+
const builder = db.select().from(schemaModel).limit(limit || 100).offset(offset || 0);
|
|
150
145
|
if (sortBy?.field) builder.orderBy(sortFn(schemaModel[getFieldName({
|
|
151
146
|
model,
|
|
152
147
|
field: sortBy?.field
|
|
@@ -156,27 +151,28 @@ const drizzleAdapter = (db, config) => {
|
|
|
156
151
|
async count({ model, where }) {
|
|
157
152
|
const schemaModel = getSchema(model);
|
|
158
153
|
const clause = where ? convertWhereClause(where, model) : [];
|
|
159
|
-
return (await db
|
|
154
|
+
return (await db.select({ count: (0, drizzle_orm.count)() }).from(schemaModel).where(...clause))[0].count;
|
|
160
155
|
},
|
|
161
156
|
async update({ model, where, update: values }) {
|
|
162
157
|
const schemaModel = getSchema(model);
|
|
163
158
|
const clause = convertWhereClause(where, model);
|
|
164
|
-
|
|
159
|
+
const builder = db.update(schemaModel).set(values).where(...clause);
|
|
160
|
+
return await withReturning(model, builder, values, where);
|
|
165
161
|
},
|
|
166
162
|
async updateMany({ model, where, update: values }) {
|
|
167
163
|
const schemaModel = getSchema(model);
|
|
168
164
|
const clause = convertWhereClause(where, model);
|
|
169
|
-
return await db
|
|
165
|
+
return await db.update(schemaModel).set(values).where(...clause);
|
|
170
166
|
},
|
|
171
167
|
async delete({ model, where }) {
|
|
172
168
|
const schemaModel = getSchema(model);
|
|
173
169
|
const clause = convertWhereClause(where, model);
|
|
174
|
-
return await db
|
|
170
|
+
return await db.delete(schemaModel).where(...clause);
|
|
175
171
|
},
|
|
176
172
|
async deleteMany({ model, where }) {
|
|
177
173
|
const schemaModel = getSchema(model);
|
|
178
174
|
const clause = convertWhereClause(where, model);
|
|
179
|
-
return await db
|
|
175
|
+
return await db.delete(schemaModel).where(...clause);
|
|
180
176
|
},
|
|
181
177
|
options: config
|
|
182
178
|
};
|
|
@@ -203,6 +199,4 @@ const drizzleAdapter = (db, config) => {
|
|
|
203
199
|
return adapter(options);
|
|
204
200
|
};
|
|
205
201
|
};
|
|
206
|
-
|
|
207
|
-
//#endregion
|
|
208
|
-
exports.drizzleAdapter = drizzleAdapter;
|
|
202
|
+
exports.drizzleAdapter = drizzleAdapter;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../../hono-DOM31WQz.cjs";
|
|
1
|
+
import { ht as FaireAuthOptions } from "../../shared.cjs";
|
|
3
2
|
import { DBAdapter, DBAdapterDebugLogOption } from "@faire-auth/core/db/adapter";
|
|
4
|
-
|
|
5
|
-
//#region src/adapters/drizzle-adapter/drizzle-adapter.d.ts
|
|
6
|
-
interface DB {
|
|
3
|
+
export interface DB {
|
|
7
4
|
[key: string]: any;
|
|
8
5
|
}
|
|
9
|
-
interface DrizzleAdapterConfig {
|
|
6
|
+
export interface DrizzleAdapterConfig {
|
|
10
7
|
/**
|
|
11
8
|
* The schema object that defines the tables and fields
|
|
12
9
|
*/
|
|
@@ -43,6 +40,4 @@ interface DrizzleAdapterConfig {
|
|
|
43
40
|
*/
|
|
44
41
|
transaction?: boolean;
|
|
45
42
|
}
|
|
46
|
-
declare const drizzleAdapter: (db: DB, config: DrizzleAdapterConfig) => (options: FaireAuthOptions) => DBAdapter<FaireAuthOptions>;
|
|
47
|
-
//#endregion
|
|
48
|
-
export { DB, DrizzleAdapterConfig, drizzleAdapter };
|
|
43
|
+
export declare const drizzleAdapter: (db: DB, config: DrizzleAdapterConfig) => (options: FaireAuthOptions) => DBAdapter<FaireAuthOptions>;
|