better-auth 1.2.6-beta.7 → 1.2.7-beta.1
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/adapters/drizzle-adapter/index.cjs +186 -249
- package/dist/adapters/drizzle-adapter/index.d.cts +11 -49
- package/dist/adapters/drizzle-adapter/index.d.mts +11 -49
- package/dist/adapters/drizzle-adapter/index.d.ts +11 -49
- package/dist/adapters/drizzle-adapter/index.mjs +186 -249
- package/dist/adapters/index.cjs +26 -0
- package/dist/adapters/index.d.cts +17 -0
- package/dist/adapters/index.d.mts +17 -0
- package/dist/adapters/index.d.ts +17 -0
- package/dist/adapters/index.mjs +20 -0
- package/dist/adapters/kysely-adapter/index.cjs +7 -7
- package/dist/adapters/kysely-adapter/index.d.cts +17 -49
- package/dist/adapters/kysely-adapter/index.d.mts +17 -49
- package/dist/adapters/kysely-adapter/index.d.ts +17 -49
- package/dist/adapters/kysely-adapter/index.mjs +8 -8
- package/dist/adapters/memory-adapter/index.cjs +7 -8
- package/dist/adapters/memory-adapter/index.d.cts +9 -49
- package/dist/adapters/memory-adapter/index.d.mts +9 -49
- package/dist/adapters/memory-adapter/index.d.ts +9 -49
- package/dist/adapters/memory-adapter/index.mjs +8 -9
- package/dist/adapters/mongodb-adapter/index.cjs +2 -2
- package/dist/adapters/mongodb-adapter/index.d.cts +4 -4
- package/dist/adapters/mongodb-adapter/index.d.mts +4 -4
- package/dist/adapters/mongodb-adapter/index.d.ts +4 -4
- package/dist/adapters/mongodb-adapter/index.mjs +3 -3
- package/dist/adapters/prisma-adapter/index.cjs +130 -203
- package/dist/adapters/prisma-adapter/index.d.cts +17 -49
- package/dist/adapters/prisma-adapter/index.d.mts +17 -49
- package/dist/adapters/prisma-adapter/index.d.ts +17 -49
- package/dist/adapters/prisma-adapter/index.mjs +131 -204
- package/dist/adapters/test.cjs +710 -377
- package/dist/adapters/test.d.cts +64 -5
- package/dist/adapters/test.d.mts +64 -5
- package/dist/adapters/test.d.ts +64 -5
- package/dist/adapters/test.mjs +712 -380
- package/dist/api/index.cjs +61 -25
- package/dist/api/index.d.cts +3 -3
- package/dist/api/index.d.mts +3 -3
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.mjs +63 -27
- package/dist/client/index.d.cts +3 -3
- package/dist/client/index.d.mts +3 -3
- package/dist/client/index.d.ts +3 -3
- package/dist/client/plugins/index.cjs +13 -15
- package/dist/client/plugins/index.d.cts +80 -19
- package/dist/client/plugins/index.d.mts +80 -19
- package/dist/client/plugins/index.d.ts +80 -19
- package/dist/client/plugins/index.mjs +13 -16
- package/dist/client/react/index.cjs +4 -4
- package/dist/client/react/index.d.cts +3 -3
- package/dist/client/react/index.d.mts +3 -3
- package/dist/client/react/index.d.ts +3 -3
- package/dist/client/solid/index.d.cts +3 -3
- package/dist/client/solid/index.d.mts +3 -3
- package/dist/client/solid/index.d.ts +3 -3
- package/dist/client/svelte/index.d.cts +3 -3
- package/dist/client/svelte/index.d.mts +3 -3
- package/dist/client/svelte/index.d.ts +3 -3
- package/dist/client/vue/index.d.cts +3 -3
- package/dist/client/vue/index.d.mts +3 -3
- package/dist/client/vue/index.d.ts +3 -3
- package/dist/cookies/index.cjs +13 -2
- package/dist/cookies/index.d.cts +3 -3
- package/dist/cookies/index.d.mts +3 -3
- package/dist/cookies/index.d.ts +3 -3
- package/dist/cookies/index.mjs +13 -2
- package/dist/db/index.cjs +6 -5
- package/dist/db/index.d.cts +4 -4
- package/dist/db/index.d.mts +4 -4
- package/dist/db/index.d.ts +4 -4
- package/dist/db/index.mjs +7 -6
- package/dist/index.cjs +11 -7
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +14 -10
- package/dist/integrations/next-js.cjs +4 -5
- package/dist/integrations/next-js.d.cts +3 -3
- package/dist/integrations/next-js.d.mts +3 -3
- package/dist/integrations/next-js.d.ts +3 -3
- package/dist/integrations/next-js.mjs +5 -6
- package/dist/integrations/node.d.cts +3 -3
- package/dist/integrations/node.d.mts +3 -3
- package/dist/integrations/node.d.ts +3 -3
- package/dist/integrations/react-start.cjs +5 -6
- package/dist/integrations/react-start.d.cts +3 -3
- package/dist/integrations/react-start.d.mts +3 -3
- package/dist/integrations/react-start.d.ts +3 -3
- package/dist/integrations/react-start.mjs +6 -7
- package/dist/integrations/svelte-kit.d.cts +3 -3
- package/dist/integrations/svelte-kit.d.mts +3 -3
- package/dist/integrations/svelte-kit.d.ts +3 -3
- package/dist/oauth2/index.d.cts +5 -5
- package/dist/oauth2/index.d.mts +5 -5
- package/dist/oauth2/index.d.ts +5 -5
- package/dist/plugins/access/index.d.cts +1 -1
- package/dist/plugins/access/index.d.mts +1 -1
- package/dist/plugins/access/index.d.ts +1 -1
- package/dist/plugins/admin/access/index.d.cts +1 -1
- package/dist/plugins/admin/access/index.d.mts +1 -1
- package/dist/plugins/admin/access/index.d.ts +1 -1
- package/dist/plugins/admin/index.cjs +4 -4
- package/dist/plugins/admin/index.d.cts +74 -14
- package/dist/plugins/admin/index.d.mts +74 -14
- package/dist/plugins/admin/index.d.ts +74 -14
- package/dist/plugins/admin/index.mjs +5 -5
- package/dist/plugins/anonymous/index.cjs +4 -5
- package/dist/plugins/anonymous/index.d.cts +3 -3
- package/dist/plugins/anonymous/index.d.mts +3 -3
- package/dist/plugins/anonymous/index.d.ts +3 -3
- package/dist/plugins/anonymous/index.mjs +5 -6
- package/dist/plugins/bearer/index.cjs +2 -2
- package/dist/plugins/bearer/index.d.cts +3 -3
- package/dist/plugins/bearer/index.d.mts +3 -3
- package/dist/plugins/bearer/index.d.ts +3 -3
- package/dist/plugins/bearer/index.mjs +3 -3
- package/dist/plugins/captcha/index.cjs +110 -45
- package/dist/plugins/captcha/index.d.cts +26 -6
- package/dist/plugins/captcha/index.d.mts +26 -6
- package/dist/plugins/captcha/index.d.ts +26 -6
- package/dist/plugins/captcha/index.mjs +110 -45
- package/dist/plugins/custom-session/index.cjs +24 -5
- package/dist/plugins/custom-session/index.d.cts +25 -6
- package/dist/plugins/custom-session/index.d.mts +25 -6
- package/dist/plugins/custom-session/index.d.ts +25 -6
- package/dist/plugins/custom-session/index.mjs +25 -6
- package/dist/plugins/email-otp/index.cjs +96 -30
- package/dist/plugins/email-otp/index.d.cts +33 -10
- package/dist/plugins/email-otp/index.d.mts +33 -10
- package/dist/plugins/email-otp/index.d.ts +33 -10
- package/dist/plugins/email-otp/index.mjs +97 -31
- package/dist/plugins/generic-oauth/index.cjs +81 -20
- package/dist/plugins/generic-oauth/index.d.cts +46 -3
- package/dist/plugins/generic-oauth/index.d.mts +46 -3
- package/dist/plugins/generic-oauth/index.d.ts +46 -3
- package/dist/plugins/generic-oauth/index.mjs +82 -21
- package/dist/plugins/haveibeenpwned/index.cjs +98 -0
- package/dist/plugins/haveibeenpwned/index.d.cts +36 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +36 -0
- package/dist/plugins/haveibeenpwned/index.d.ts +36 -0
- package/dist/plugins/haveibeenpwned/index.mjs +96 -0
- package/dist/plugins/index.cjs +583 -19
- package/dist/plugins/index.d.cts +7 -5
- package/dist/plugins/index.d.mts +7 -5
- package/dist/plugins/index.d.ts +7 -5
- package/dist/plugins/index.mjs +583 -21
- package/dist/plugins/jwt/index.cjs +45 -21
- package/dist/plugins/jwt/index.d.cts +52 -6
- package/dist/plugins/jwt/index.d.mts +52 -6
- package/dist/plugins/jwt/index.d.ts +52 -6
- package/dist/plugins/jwt/index.mjs +46 -22
- package/dist/plugins/magic-link/index.cjs +3 -3
- package/dist/plugins/magic-link/index.mjs +4 -4
- package/dist/plugins/multi-session/index.cjs +3 -3
- package/dist/plugins/multi-session/index.d.cts +3 -3
- package/dist/plugins/multi-session/index.d.mts +3 -3
- package/dist/plugins/multi-session/index.d.ts +3 -3
- package/dist/plugins/multi-session/index.mjs +4 -4
- package/dist/plugins/oauth-proxy/index.cjs +4 -4
- package/dist/plugins/oauth-proxy/index.d.cts +3 -3
- package/dist/plugins/oauth-proxy/index.d.mts +3 -3
- package/dist/plugins/oauth-proxy/index.d.ts +3 -3
- package/dist/plugins/oauth-proxy/index.mjs +5 -5
- package/dist/plugins/oidc-provider/index.cjs +227 -8
- package/dist/plugins/oidc-provider/index.d.cts +215 -3
- package/dist/plugins/oidc-provider/index.d.mts +215 -3
- package/dist/plugins/oidc-provider/index.d.ts +215 -3
- package/dist/plugins/oidc-provider/index.mjs +228 -9
- package/dist/plugins/one-tap/index.cjs +5 -5
- package/dist/plugins/one-tap/index.mjs +6 -6
- package/dist/plugins/one-time-token/index.cjs +119 -0
- package/dist/plugins/one-time-token/index.d.cts +134 -0
- package/dist/plugins/one-time-token/index.d.mts +134 -0
- package/dist/plugins/one-time-token/index.d.ts +134 -0
- package/dist/plugins/one-time-token/index.mjs +117 -0
- package/dist/plugins/open-api/index.cjs +3 -3
- package/dist/plugins/open-api/index.d.cts +3 -3
- package/dist/plugins/open-api/index.d.mts +3 -3
- package/dist/plugins/open-api/index.d.ts +3 -3
- package/dist/plugins/open-api/index.mjs +4 -4
- package/dist/plugins/organization/access/index.d.cts +1 -1
- package/dist/plugins/organization/access/index.d.mts +1 -1
- package/dist/plugins/organization/access/index.d.ts +1 -1
- package/dist/plugins/organization/index.cjs +4 -4
- package/dist/plugins/organization/index.d.cts +708 -55
- package/dist/plugins/organization/index.d.mts +708 -55
- package/dist/plugins/organization/index.d.ts +708 -55
- package/dist/plugins/organization/index.mjs +5 -5
- package/dist/plugins/passkey/index.cjs +82 -8
- package/dist/plugins/passkey/index.d.cts +72 -3
- package/dist/plugins/passkey/index.d.mts +72 -3
- package/dist/plugins/passkey/index.d.ts +72 -3
- package/dist/plugins/passkey/index.mjs +83 -9
- package/dist/plugins/phone-number/index.cjs +194 -26
- package/dist/plugins/phone-number/index.d.cts +132 -8
- package/dist/plugins/phone-number/index.d.mts +132 -8
- package/dist/plugins/phone-number/index.d.ts +132 -8
- package/dist/plugins/phone-number/index.mjs +195 -27
- package/dist/plugins/sso/index.cjs +190 -7
- package/dist/plugins/sso/index.d.cts +181 -15
- package/dist/plugins/sso/index.d.mts +181 -15
- package/dist/plugins/sso/index.d.ts +181 -15
- package/dist/plugins/sso/index.mjs +191 -8
- package/dist/plugins/two-factor/index.cjs +443 -92
- package/dist/plugins/two-factor/index.d.cts +230 -396
- package/dist/plugins/two-factor/index.d.mts +230 -396
- package/dist/plugins/two-factor/index.d.ts +230 -396
- package/dist/plugins/two-factor/index.mjs +431 -80
- package/dist/plugins/username/index.cjs +34 -31
- package/dist/plugins/username/index.d.cts +15 -12
- package/dist/plugins/username/index.d.mts +15 -12
- package/dist/plugins/username/index.d.ts +15 -12
- package/dist/plugins/username/index.mjs +35 -32
- package/dist/shared/better-auth.1DR6suCQ.mjs +307 -0
- package/dist/shared/{better-auth.BSsp73pg.cjs → better-auth.B7cZ2juS.cjs} +15 -14
- package/dist/shared/{better-auth.bKwabe3I.d.mts → better-auth.B88xucNq.d.mts} +529 -39
- package/dist/shared/{better-auth.CApEjVDP.cjs → better-auth.BW8BpneG.cjs} +4 -1
- package/dist/shared/{better-auth.BiQsvaIP.d.cts → better-auth.BcU1Kjyq.d.cts} +2051 -518
- package/dist/shared/better-auth.BfG24BjZ.cjs +118 -0
- package/dist/shared/{better-auth.A3TjrU8G.mjs → better-auth.Bk5IMdhM.mjs} +32 -12
- package/dist/shared/{better-auth.D9VnBkRI.mjs → better-auth.Bm9HxIzE.mjs} +47 -24
- package/dist/shared/{better-auth.BRf6Iynu.d.ts → better-auth.Bwc-6kOr.d.ts} +1 -1
- package/dist/shared/{better-auth.D-oLmHIj.d.mts → better-auth.CA2hFK4N.d.ts} +2051 -518
- package/dist/shared/{better-auth.Dmhe30iW.d.mts → better-auth.CGukGrxT.d.cts} +1 -1
- package/dist/shared/{better-auth.CsSpq0zL.cjs → better-auth.CHUzBidy.cjs} +46 -23
- package/dist/shared/{better-auth.DWRligF8.d.cts → better-auth.CT9J6rD-.d.cts} +539 -7
- package/dist/shared/better-auth.CVCo5Z2T.cjs +310 -0
- package/dist/shared/{better-auth.D4jH-sJA.mjs → better-auth.CWwVo_61.mjs} +458 -118
- package/dist/shared/{better-auth.Bi8FQwDD.d.cts → better-auth.CYegVoq1.d.cts} +1 -1
- package/dist/shared/{better-auth.Bi8FQwDD.d.mts → better-auth.CYegVoq1.d.mts} +1 -1
- package/dist/shared/{better-auth.Bi8FQwDD.d.ts → better-auth.CYegVoq1.d.ts} +1 -1
- package/dist/shared/{better-auth.CepcSj5H.mjs → better-auth.Cc72UxUH.mjs} +1 -2
- package/dist/shared/{better-auth.BWp5dztg.d.ts → better-auth.CmN4mlPh.d.ts} +539 -7
- package/dist/shared/{better-auth.DH3YjMQH.mjs → better-auth.Cqykj82J.mjs} +1 -1
- package/dist/shared/{better-auth.wcdMj2cT.d.mts → better-auth.DIt2e3lu.d.mts} +539 -7
- package/dist/shared/{better-auth.BANAxdkL.d.ts → better-auth.DNTAFSt1.d.ts} +529 -39
- package/dist/shared/{better-auth.DU2QNVc_.d.ts → better-auth.DQ7OSJbI.d.mts} +2051 -518
- package/dist/shared/{better-auth.DLTzKoOS.cjs → better-auth.DSVbLSt7.cjs} +4 -1
- package/dist/shared/{better-auth.B2Fw1vhH.d.cts → better-auth.DTiSPWEk.d.cts} +529 -39
- package/dist/shared/better-auth.DURsStt9.mjs +116 -0
- package/dist/shared/{better-auth.BIjcZ_vt.cjs → better-auth.DYoLD99C.cjs} +31 -11
- package/dist/shared/{better-auth.CV1L7TPV.cjs → better-auth.D_ZIX1O8.cjs} +317 -47
- package/dist/shared/{better-auth.C5H9XEzZ.cjs → better-auth.DcWKCjjf.cjs} +1 -2
- package/dist/shared/{better-auth.BDYXUcLv.cjs → better-auth.Dg0siV5C.cjs} +457 -117
- package/dist/shared/better-auth.DjryM8pE.cjs +760 -0
- package/dist/shared/{better-auth.DPBQN9Fs.mjs → better-auth.Dn_Ms1Uf.mjs} +318 -48
- package/dist/shared/{better-auth.DiG4KL2x.mjs → better-auth.OuYYTHC7.mjs} +4 -1
- package/dist/shared/{better-auth.DtC8i3pf.d.cts → better-auth.S1jimRbX.d.mts} +1 -1
- package/dist/shared/better-auth.SPmq4a4z.d.mts +344 -0
- package/dist/shared/{better-auth.cOCrlspr.mjs → better-auth.bkwPl2G4.mjs} +4 -1
- package/dist/shared/better-auth.cp2rC2iM.d.ts +344 -0
- package/dist/shared/better-auth.eVy4DZvP.d.cts +344 -0
- package/dist/shared/{better-auth.BrOpzmqo.mjs → better-auth.iKoUsdFE.mjs} +15 -14
- package/dist/shared/better-auth.rSYJCd3o.mjs +758 -0
- package/dist/social-providers/index.cjs +75 -3
- package/dist/social-providers/index.d.cts +2 -2
- package/dist/social-providers/index.d.mts +2 -2
- package/dist/social-providers/index.d.ts +2 -2
- package/dist/social-providers/index.mjs +77 -6
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.mts +4 -4
- package/dist/types/index.d.ts +4 -4
- package/package.json +42 -5
- package/dist/chunks/server.cjs +0 -905
- package/dist/chunks/server.mjs +0 -895
- package/dist/shared/better-auth.BcoSd9tC.mjs +0 -10
- package/dist/shared/better-auth.BnRFp-t0.mjs +0 -405
- package/dist/shared/better-auth.C1-vpKly.cjs +0 -12
- package/dist/shared/better-auth.ClTSOgiD.mjs +0 -140
- package/dist/shared/better-auth.DC8JQbiE.mjs +0 -173
- package/dist/shared/better-auth.DWHWPllD.cjs +0 -175
- package/dist/shared/better-auth.DqLjzBlO.cjs +0 -408
- package/dist/shared/better-auth.m575EIBC.cjs +0 -144
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { F as FieldAttribute, h as BetterAuthDbSchema, f as BetterAuthOptions, W as Where, i as AdapterSchemaCreation } from './better-auth.DQ7OSJbI.mjs';
|
|
2
|
+
import { P as Prettify } from './better-auth.CYegVoq1.mjs';
|
|
3
|
+
|
|
4
|
+
type AdapterDebugLogs = boolean | {
|
|
5
|
+
/**
|
|
6
|
+
* Useful when you want to log only certain conditions.
|
|
7
|
+
*/
|
|
8
|
+
logCondition?: (() => boolean) | undefined;
|
|
9
|
+
create?: boolean;
|
|
10
|
+
update?: boolean;
|
|
11
|
+
updateMany?: boolean;
|
|
12
|
+
findOne?: boolean;
|
|
13
|
+
findMany?: boolean;
|
|
14
|
+
delete?: boolean;
|
|
15
|
+
deleteMany?: boolean;
|
|
16
|
+
count?: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
/**
|
|
19
|
+
* Only used for adapter tests to show debug logs if a test fails.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
|
|
22
|
+
*/
|
|
23
|
+
isRunningAdapterTests: boolean;
|
|
24
|
+
};
|
|
25
|
+
interface AdapterConfig {
|
|
26
|
+
/**
|
|
27
|
+
* Use plural table names.
|
|
28
|
+
*
|
|
29
|
+
* All tables will be named with an `s` at the end.
|
|
30
|
+
*
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
usePlural?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Enable debug logs.
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
debugLogs?: AdapterDebugLogs;
|
|
40
|
+
/**
|
|
41
|
+
* Name of the adapter.
|
|
42
|
+
*
|
|
43
|
+
* This is used to identify the adapter in the debug logs.
|
|
44
|
+
*
|
|
45
|
+
* @default `adapterId`
|
|
46
|
+
*/
|
|
47
|
+
adapterName?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Adapter id
|
|
50
|
+
*/
|
|
51
|
+
adapterId: string;
|
|
52
|
+
/**
|
|
53
|
+
* If the database supports numeric ids, set this to `true`.
|
|
54
|
+
*
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
supportsNumericIds?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* If the database doesn't support JSON columns, set this to `false`.
|
|
60
|
+
*
|
|
61
|
+
* We will handle the translation between using `JSON` columns, and saving `string`s to the database.
|
|
62
|
+
*
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
65
|
+
supportsJSON?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* If the database doesn't support dates, set this to `false`.
|
|
68
|
+
*
|
|
69
|
+
* We will handle the translation between using `Date` objects, and saving `string`s to the database.
|
|
70
|
+
*
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
supportsDates?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* If the database doesn't support booleans, set this to `false`.
|
|
76
|
+
*
|
|
77
|
+
* We will handle the translation between using `boolean`s, and saving `0`s and `1`s to the database.
|
|
78
|
+
*
|
|
79
|
+
* @default true
|
|
80
|
+
*/
|
|
81
|
+
supportsBooleans?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Disable id generation for the `create` method.
|
|
84
|
+
*
|
|
85
|
+
* This is useful for databases that don't support custom id values and would auto-generate them for you.
|
|
86
|
+
*
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
disableIdGeneration?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Map the keys of the input data.
|
|
92
|
+
*
|
|
93
|
+
* This is useful for databases that expect a different key name for a given situation.
|
|
94
|
+
*
|
|
95
|
+
* For example, MongoDB uses `_id` while in Better-Auth we use `id`.
|
|
96
|
+
*
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* Each key represents the old key to replace.
|
|
100
|
+
* The value represents the new key
|
|
101
|
+
*
|
|
102
|
+
* This can be a partial object that only transforms some keys.
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* mapKeysTransformInput: {
|
|
106
|
+
* id: "_id" // We want to replace `id` to `_id` to save into MongoDB
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
mapKeysTransformInput?: Record<string, string>;
|
|
111
|
+
/**
|
|
112
|
+
* Map the keys of the output data.
|
|
113
|
+
*
|
|
114
|
+
* This is useful for databases that expect a different key name for a given situation.
|
|
115
|
+
*
|
|
116
|
+
* For example, MongoDB uses `_id` while in Better-Auth we use `id`.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* Each key represents the old key to replace.
|
|
120
|
+
* The value represents the new key
|
|
121
|
+
*
|
|
122
|
+
* This can be a partial object that only transforms some keys.
|
|
123
|
+
*
|
|
124
|
+
* ```ts
|
|
125
|
+
* mapKeysTransformOutput: {
|
|
126
|
+
* _id: "id" // In MongoDB, we save `id` as `_id`. So we want to replace `_id` with `id` when we get the data back.
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
mapKeysTransformOutput?: Record<string, string>;
|
|
131
|
+
/**
|
|
132
|
+
* Custom transform input function.
|
|
133
|
+
*
|
|
134
|
+
* This function is used to transform the input data before it is saved to the database.
|
|
135
|
+
*/
|
|
136
|
+
customTransformInput?: (props: {
|
|
137
|
+
data: any;
|
|
138
|
+
/**
|
|
139
|
+
* The fields of the model.
|
|
140
|
+
*/
|
|
141
|
+
fieldAttributes: FieldAttribute;
|
|
142
|
+
/**
|
|
143
|
+
* The field to transform.
|
|
144
|
+
*/
|
|
145
|
+
field: string;
|
|
146
|
+
/**
|
|
147
|
+
* The action which was called from the adapter.
|
|
148
|
+
*/
|
|
149
|
+
action: "create" | "update";
|
|
150
|
+
/**
|
|
151
|
+
* The model name.
|
|
152
|
+
*/
|
|
153
|
+
model: string;
|
|
154
|
+
/**
|
|
155
|
+
* The schema of the user's Better-Auth instance.
|
|
156
|
+
*/
|
|
157
|
+
schema: BetterAuthDbSchema;
|
|
158
|
+
/**
|
|
159
|
+
* The options of the user's Better-Auth instance.
|
|
160
|
+
*/
|
|
161
|
+
options: BetterAuthOptions;
|
|
162
|
+
}) => any;
|
|
163
|
+
/**
|
|
164
|
+
* Custom transform output function.
|
|
165
|
+
*
|
|
166
|
+
* This function is used to transform the output data before it is returned to the user.
|
|
167
|
+
*/
|
|
168
|
+
customTransformOutput?: (props: {
|
|
169
|
+
data: any;
|
|
170
|
+
/**
|
|
171
|
+
* The fields of the model.
|
|
172
|
+
*/
|
|
173
|
+
fieldAttributes: FieldAttribute;
|
|
174
|
+
/**
|
|
175
|
+
* The field to transform.
|
|
176
|
+
*/
|
|
177
|
+
field: string;
|
|
178
|
+
/**
|
|
179
|
+
* The fields to select.
|
|
180
|
+
*/
|
|
181
|
+
select: string[];
|
|
182
|
+
/**
|
|
183
|
+
* The model name.
|
|
184
|
+
*/
|
|
185
|
+
model: string;
|
|
186
|
+
/**
|
|
187
|
+
* The schema of the user's Better-Auth instance.
|
|
188
|
+
*/
|
|
189
|
+
schema: BetterAuthDbSchema;
|
|
190
|
+
/**
|
|
191
|
+
* The options of the user's Better-Auth instance.
|
|
192
|
+
*/
|
|
193
|
+
options: BetterAuthOptions;
|
|
194
|
+
}) => any;
|
|
195
|
+
/**
|
|
196
|
+
* Custom ID generator function.
|
|
197
|
+
*
|
|
198
|
+
* By default, we can handle ID generation for you, however if the database your adapter is for only supports a specific custom id generation,
|
|
199
|
+
* then you can use this function to generate your own IDs.
|
|
200
|
+
*
|
|
201
|
+
*
|
|
202
|
+
* Notes:
|
|
203
|
+
* - If the user enabled `useNumberId`, then this option will be ignored. Unless this adapter config has `supportsNumericIds` set to `false`.
|
|
204
|
+
* - If `generateId` is `false` in the user's Better-Auth config, then this option will be ignored.
|
|
205
|
+
* - If `generateId` is a function, then it will override this option.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
*
|
|
209
|
+
* ```ts
|
|
210
|
+
* customIdGenerator: ({ model }) => {
|
|
211
|
+
* return "my-super-unique-id";
|
|
212
|
+
* }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
customIdGenerator?: (props: {
|
|
216
|
+
model: string;
|
|
217
|
+
}) => string;
|
|
218
|
+
}
|
|
219
|
+
type CreateCustomAdapter = ({ options, debugLog, schema, getDefaultModelName, getDefaultFieldName, }: {
|
|
220
|
+
options: BetterAuthOptions;
|
|
221
|
+
/**
|
|
222
|
+
* The schema of the user's Better-Auth instance.
|
|
223
|
+
*/
|
|
224
|
+
schema: BetterAuthDbSchema;
|
|
225
|
+
/**
|
|
226
|
+
* The debug log function.
|
|
227
|
+
*
|
|
228
|
+
* If the config has defined `debugLogs` as `false`, no logs will be shown.
|
|
229
|
+
*/
|
|
230
|
+
debugLog: (...args: any[]) => void;
|
|
231
|
+
/**
|
|
232
|
+
* Get the model name which is expected to be saved in the database based on the user's schema.
|
|
233
|
+
*/
|
|
234
|
+
getModelName: (model: string) => string;
|
|
235
|
+
/**
|
|
236
|
+
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
237
|
+
*/
|
|
238
|
+
getFieldName: ({ model, field }: {
|
|
239
|
+
model: string;
|
|
240
|
+
field: string;
|
|
241
|
+
}) => string;
|
|
242
|
+
/**
|
|
243
|
+
* This function helps us get the default model name from the schema defined by devs.
|
|
244
|
+
* Often times, the user will be using the `modelName` which could had been customized by the users.
|
|
245
|
+
* This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
|
|
246
|
+
*
|
|
247
|
+
* If it's still unclear what this does:
|
|
248
|
+
*
|
|
249
|
+
* 1. User can define a custom modelName.
|
|
250
|
+
* 2. When using a custom modelName, doing something like `schema[model]` will not work.
|
|
251
|
+
* 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
|
|
252
|
+
* 4. Thus allowing us to use `schema[model]`.
|
|
253
|
+
*/
|
|
254
|
+
getDefaultModelName: (model: string) => string;
|
|
255
|
+
/**
|
|
256
|
+
* This function helps us get the default field name from the schema defined by devs.
|
|
257
|
+
* Often times, the user will be using the `fieldName` which could had been customized by the users.
|
|
258
|
+
* This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
|
|
259
|
+
*
|
|
260
|
+
* If it's still unclear what this does:
|
|
261
|
+
*
|
|
262
|
+
* 1. User can define a custom fieldName.
|
|
263
|
+
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
264
|
+
*
|
|
265
|
+
*/
|
|
266
|
+
getDefaultFieldName: ({ model, field, }: {
|
|
267
|
+
model: string;
|
|
268
|
+
field: string;
|
|
269
|
+
}) => string;
|
|
270
|
+
/**
|
|
271
|
+
* Get the field attributes for a given model and field.
|
|
272
|
+
*
|
|
273
|
+
* Note: any model name or field name is allowed, whether default to schema or not.
|
|
274
|
+
*/
|
|
275
|
+
getFieldAttributes: ({ model, field, }: {
|
|
276
|
+
model: string;
|
|
277
|
+
field: string;
|
|
278
|
+
}) => FieldAttribute;
|
|
279
|
+
}) => CustomAdapter;
|
|
280
|
+
interface CustomAdapter {
|
|
281
|
+
create: <T extends Record<string, any>>({ data, model, select, }: {
|
|
282
|
+
model: string;
|
|
283
|
+
data: T;
|
|
284
|
+
select?: string[];
|
|
285
|
+
}) => Promise<T>;
|
|
286
|
+
update: <T>(data: {
|
|
287
|
+
model: string;
|
|
288
|
+
where: CleanedWhere[];
|
|
289
|
+
update: T;
|
|
290
|
+
}) => Promise<T | null>;
|
|
291
|
+
updateMany: (data: {
|
|
292
|
+
model: string;
|
|
293
|
+
where: CleanedWhere[];
|
|
294
|
+
update: Record<string, any>;
|
|
295
|
+
}) => Promise<number>;
|
|
296
|
+
findOne: <T>({ model, where, select, }: {
|
|
297
|
+
model: string;
|
|
298
|
+
where: CleanedWhere[];
|
|
299
|
+
select?: string[];
|
|
300
|
+
}) => Promise<T | null>;
|
|
301
|
+
findMany: <T>({ model, where, limit, sortBy, offset, }: {
|
|
302
|
+
model: string;
|
|
303
|
+
where?: CleanedWhere[];
|
|
304
|
+
limit: number;
|
|
305
|
+
sortBy?: {
|
|
306
|
+
field: string;
|
|
307
|
+
direction: "asc" | "desc";
|
|
308
|
+
};
|
|
309
|
+
offset?: number;
|
|
310
|
+
}) => Promise<T[]>;
|
|
311
|
+
delete: ({ model, where, }: {
|
|
312
|
+
model: string;
|
|
313
|
+
where: CleanedWhere[];
|
|
314
|
+
}) => Promise<void>;
|
|
315
|
+
deleteMany: ({ model, where, }: {
|
|
316
|
+
model: string;
|
|
317
|
+
where: CleanedWhere[];
|
|
318
|
+
}) => Promise<number>;
|
|
319
|
+
count: ({ model, where, }: {
|
|
320
|
+
model: string;
|
|
321
|
+
where?: CleanedWhere[];
|
|
322
|
+
}) => Promise<number>;
|
|
323
|
+
createSchema?: (props: {
|
|
324
|
+
/**
|
|
325
|
+
* The file the user may have passed in to the `generate` command as the expected schema file output path.
|
|
326
|
+
*/
|
|
327
|
+
file?: string;
|
|
328
|
+
/**
|
|
329
|
+
* The tables from the user's Better-Auth instance schema.
|
|
330
|
+
*/
|
|
331
|
+
tables: BetterAuthDbSchema;
|
|
332
|
+
}) => Promise<AdapterSchemaCreation>;
|
|
333
|
+
/**
|
|
334
|
+
* Your adapter's options.
|
|
335
|
+
*/
|
|
336
|
+
options?: Record<string, any> | undefined;
|
|
337
|
+
}
|
|
338
|
+
type CleanedWhere = Prettify<Required<Where>>;
|
|
339
|
+
type AdapterTestDebugLogs = {
|
|
340
|
+
resetDebugLogs: () => void;
|
|
341
|
+
printDebugLogs: () => void;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export type { AdapterDebugLogs as A, CreateCustomAdapter as C, AdapterConfig as a, CustomAdapter as b, CleanedWhere as c, AdapterTestDebugLogs as d };
|
|
@@ -4,11 +4,14 @@ const hasPermission = (input) => {
|
|
|
4
4
|
if (input.userId && input.options?.adminUserIds?.includes(input.userId)) {
|
|
5
5
|
return true;
|
|
6
6
|
}
|
|
7
|
+
if (!input.permissions && !input.permission) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
7
10
|
const roles = (input.role || input.options?.defaultRole || "user").split(",");
|
|
8
11
|
const acRoles = input.options?.roles || defaultRoles;
|
|
9
12
|
for (const role of roles) {
|
|
10
13
|
const _role = acRoles[role];
|
|
11
|
-
const result = _role?.authorize(input.permission);
|
|
14
|
+
const result = _role?.authorize(input.permission ?? input.permissions);
|
|
12
15
|
if (result?.success) {
|
|
13
16
|
return true;
|
|
14
17
|
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { F as FieldAttribute, h as BetterAuthDbSchema, f as BetterAuthOptions, W as Where, i as AdapterSchemaCreation } from './better-auth.CA2hFK4N.js';
|
|
2
|
+
import { P as Prettify } from './better-auth.CYegVoq1.js';
|
|
3
|
+
|
|
4
|
+
type AdapterDebugLogs = boolean | {
|
|
5
|
+
/**
|
|
6
|
+
* Useful when you want to log only certain conditions.
|
|
7
|
+
*/
|
|
8
|
+
logCondition?: (() => boolean) | undefined;
|
|
9
|
+
create?: boolean;
|
|
10
|
+
update?: boolean;
|
|
11
|
+
updateMany?: boolean;
|
|
12
|
+
findOne?: boolean;
|
|
13
|
+
findMany?: boolean;
|
|
14
|
+
delete?: boolean;
|
|
15
|
+
deleteMany?: boolean;
|
|
16
|
+
count?: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
/**
|
|
19
|
+
* Only used for adapter tests to show debug logs if a test fails.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
|
|
22
|
+
*/
|
|
23
|
+
isRunningAdapterTests: boolean;
|
|
24
|
+
};
|
|
25
|
+
interface AdapterConfig {
|
|
26
|
+
/**
|
|
27
|
+
* Use plural table names.
|
|
28
|
+
*
|
|
29
|
+
* All tables will be named with an `s` at the end.
|
|
30
|
+
*
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
usePlural?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Enable debug logs.
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
debugLogs?: AdapterDebugLogs;
|
|
40
|
+
/**
|
|
41
|
+
* Name of the adapter.
|
|
42
|
+
*
|
|
43
|
+
* This is used to identify the adapter in the debug logs.
|
|
44
|
+
*
|
|
45
|
+
* @default `adapterId`
|
|
46
|
+
*/
|
|
47
|
+
adapterName?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Adapter id
|
|
50
|
+
*/
|
|
51
|
+
adapterId: string;
|
|
52
|
+
/**
|
|
53
|
+
* If the database supports numeric ids, set this to `true`.
|
|
54
|
+
*
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
supportsNumericIds?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* If the database doesn't support JSON columns, set this to `false`.
|
|
60
|
+
*
|
|
61
|
+
* We will handle the translation between using `JSON` columns, and saving `string`s to the database.
|
|
62
|
+
*
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
65
|
+
supportsJSON?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* If the database doesn't support dates, set this to `false`.
|
|
68
|
+
*
|
|
69
|
+
* We will handle the translation between using `Date` objects, and saving `string`s to the database.
|
|
70
|
+
*
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
supportsDates?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* If the database doesn't support booleans, set this to `false`.
|
|
76
|
+
*
|
|
77
|
+
* We will handle the translation between using `boolean`s, and saving `0`s and `1`s to the database.
|
|
78
|
+
*
|
|
79
|
+
* @default true
|
|
80
|
+
*/
|
|
81
|
+
supportsBooleans?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Disable id generation for the `create` method.
|
|
84
|
+
*
|
|
85
|
+
* This is useful for databases that don't support custom id values and would auto-generate them for you.
|
|
86
|
+
*
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
disableIdGeneration?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Map the keys of the input data.
|
|
92
|
+
*
|
|
93
|
+
* This is useful for databases that expect a different key name for a given situation.
|
|
94
|
+
*
|
|
95
|
+
* For example, MongoDB uses `_id` while in Better-Auth we use `id`.
|
|
96
|
+
*
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* Each key represents the old key to replace.
|
|
100
|
+
* The value represents the new key
|
|
101
|
+
*
|
|
102
|
+
* This can be a partial object that only transforms some keys.
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* mapKeysTransformInput: {
|
|
106
|
+
* id: "_id" // We want to replace `id` to `_id` to save into MongoDB
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
mapKeysTransformInput?: Record<string, string>;
|
|
111
|
+
/**
|
|
112
|
+
* Map the keys of the output data.
|
|
113
|
+
*
|
|
114
|
+
* This is useful for databases that expect a different key name for a given situation.
|
|
115
|
+
*
|
|
116
|
+
* For example, MongoDB uses `_id` while in Better-Auth we use `id`.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* Each key represents the old key to replace.
|
|
120
|
+
* The value represents the new key
|
|
121
|
+
*
|
|
122
|
+
* This can be a partial object that only transforms some keys.
|
|
123
|
+
*
|
|
124
|
+
* ```ts
|
|
125
|
+
* mapKeysTransformOutput: {
|
|
126
|
+
* _id: "id" // In MongoDB, we save `id` as `_id`. So we want to replace `_id` with `id` when we get the data back.
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
mapKeysTransformOutput?: Record<string, string>;
|
|
131
|
+
/**
|
|
132
|
+
* Custom transform input function.
|
|
133
|
+
*
|
|
134
|
+
* This function is used to transform the input data before it is saved to the database.
|
|
135
|
+
*/
|
|
136
|
+
customTransformInput?: (props: {
|
|
137
|
+
data: any;
|
|
138
|
+
/**
|
|
139
|
+
* The fields of the model.
|
|
140
|
+
*/
|
|
141
|
+
fieldAttributes: FieldAttribute;
|
|
142
|
+
/**
|
|
143
|
+
* The field to transform.
|
|
144
|
+
*/
|
|
145
|
+
field: string;
|
|
146
|
+
/**
|
|
147
|
+
* The action which was called from the adapter.
|
|
148
|
+
*/
|
|
149
|
+
action: "create" | "update";
|
|
150
|
+
/**
|
|
151
|
+
* The model name.
|
|
152
|
+
*/
|
|
153
|
+
model: string;
|
|
154
|
+
/**
|
|
155
|
+
* The schema of the user's Better-Auth instance.
|
|
156
|
+
*/
|
|
157
|
+
schema: BetterAuthDbSchema;
|
|
158
|
+
/**
|
|
159
|
+
* The options of the user's Better-Auth instance.
|
|
160
|
+
*/
|
|
161
|
+
options: BetterAuthOptions;
|
|
162
|
+
}) => any;
|
|
163
|
+
/**
|
|
164
|
+
* Custom transform output function.
|
|
165
|
+
*
|
|
166
|
+
* This function is used to transform the output data before it is returned to the user.
|
|
167
|
+
*/
|
|
168
|
+
customTransformOutput?: (props: {
|
|
169
|
+
data: any;
|
|
170
|
+
/**
|
|
171
|
+
* The fields of the model.
|
|
172
|
+
*/
|
|
173
|
+
fieldAttributes: FieldAttribute;
|
|
174
|
+
/**
|
|
175
|
+
* The field to transform.
|
|
176
|
+
*/
|
|
177
|
+
field: string;
|
|
178
|
+
/**
|
|
179
|
+
* The fields to select.
|
|
180
|
+
*/
|
|
181
|
+
select: string[];
|
|
182
|
+
/**
|
|
183
|
+
* The model name.
|
|
184
|
+
*/
|
|
185
|
+
model: string;
|
|
186
|
+
/**
|
|
187
|
+
* The schema of the user's Better-Auth instance.
|
|
188
|
+
*/
|
|
189
|
+
schema: BetterAuthDbSchema;
|
|
190
|
+
/**
|
|
191
|
+
* The options of the user's Better-Auth instance.
|
|
192
|
+
*/
|
|
193
|
+
options: BetterAuthOptions;
|
|
194
|
+
}) => any;
|
|
195
|
+
/**
|
|
196
|
+
* Custom ID generator function.
|
|
197
|
+
*
|
|
198
|
+
* By default, we can handle ID generation for you, however if the database your adapter is for only supports a specific custom id generation,
|
|
199
|
+
* then you can use this function to generate your own IDs.
|
|
200
|
+
*
|
|
201
|
+
*
|
|
202
|
+
* Notes:
|
|
203
|
+
* - If the user enabled `useNumberId`, then this option will be ignored. Unless this adapter config has `supportsNumericIds` set to `false`.
|
|
204
|
+
* - If `generateId` is `false` in the user's Better-Auth config, then this option will be ignored.
|
|
205
|
+
* - If `generateId` is a function, then it will override this option.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
*
|
|
209
|
+
* ```ts
|
|
210
|
+
* customIdGenerator: ({ model }) => {
|
|
211
|
+
* return "my-super-unique-id";
|
|
212
|
+
* }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
customIdGenerator?: (props: {
|
|
216
|
+
model: string;
|
|
217
|
+
}) => string;
|
|
218
|
+
}
|
|
219
|
+
type CreateCustomAdapter = ({ options, debugLog, schema, getDefaultModelName, getDefaultFieldName, }: {
|
|
220
|
+
options: BetterAuthOptions;
|
|
221
|
+
/**
|
|
222
|
+
* The schema of the user's Better-Auth instance.
|
|
223
|
+
*/
|
|
224
|
+
schema: BetterAuthDbSchema;
|
|
225
|
+
/**
|
|
226
|
+
* The debug log function.
|
|
227
|
+
*
|
|
228
|
+
* If the config has defined `debugLogs` as `false`, no logs will be shown.
|
|
229
|
+
*/
|
|
230
|
+
debugLog: (...args: any[]) => void;
|
|
231
|
+
/**
|
|
232
|
+
* Get the model name which is expected to be saved in the database based on the user's schema.
|
|
233
|
+
*/
|
|
234
|
+
getModelName: (model: string) => string;
|
|
235
|
+
/**
|
|
236
|
+
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
237
|
+
*/
|
|
238
|
+
getFieldName: ({ model, field }: {
|
|
239
|
+
model: string;
|
|
240
|
+
field: string;
|
|
241
|
+
}) => string;
|
|
242
|
+
/**
|
|
243
|
+
* This function helps us get the default model name from the schema defined by devs.
|
|
244
|
+
* Often times, the user will be using the `modelName` which could had been customized by the users.
|
|
245
|
+
* This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
|
|
246
|
+
*
|
|
247
|
+
* If it's still unclear what this does:
|
|
248
|
+
*
|
|
249
|
+
* 1. User can define a custom modelName.
|
|
250
|
+
* 2. When using a custom modelName, doing something like `schema[model]` will not work.
|
|
251
|
+
* 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
|
|
252
|
+
* 4. Thus allowing us to use `schema[model]`.
|
|
253
|
+
*/
|
|
254
|
+
getDefaultModelName: (model: string) => string;
|
|
255
|
+
/**
|
|
256
|
+
* This function helps us get the default field name from the schema defined by devs.
|
|
257
|
+
* Often times, the user will be using the `fieldName` which could had been customized by the users.
|
|
258
|
+
* This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
|
|
259
|
+
*
|
|
260
|
+
* If it's still unclear what this does:
|
|
261
|
+
*
|
|
262
|
+
* 1. User can define a custom fieldName.
|
|
263
|
+
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
264
|
+
*
|
|
265
|
+
*/
|
|
266
|
+
getDefaultFieldName: ({ model, field, }: {
|
|
267
|
+
model: string;
|
|
268
|
+
field: string;
|
|
269
|
+
}) => string;
|
|
270
|
+
/**
|
|
271
|
+
* Get the field attributes for a given model and field.
|
|
272
|
+
*
|
|
273
|
+
* Note: any model name or field name is allowed, whether default to schema or not.
|
|
274
|
+
*/
|
|
275
|
+
getFieldAttributes: ({ model, field, }: {
|
|
276
|
+
model: string;
|
|
277
|
+
field: string;
|
|
278
|
+
}) => FieldAttribute;
|
|
279
|
+
}) => CustomAdapter;
|
|
280
|
+
interface CustomAdapter {
|
|
281
|
+
create: <T extends Record<string, any>>({ data, model, select, }: {
|
|
282
|
+
model: string;
|
|
283
|
+
data: T;
|
|
284
|
+
select?: string[];
|
|
285
|
+
}) => Promise<T>;
|
|
286
|
+
update: <T>(data: {
|
|
287
|
+
model: string;
|
|
288
|
+
where: CleanedWhere[];
|
|
289
|
+
update: T;
|
|
290
|
+
}) => Promise<T | null>;
|
|
291
|
+
updateMany: (data: {
|
|
292
|
+
model: string;
|
|
293
|
+
where: CleanedWhere[];
|
|
294
|
+
update: Record<string, any>;
|
|
295
|
+
}) => Promise<number>;
|
|
296
|
+
findOne: <T>({ model, where, select, }: {
|
|
297
|
+
model: string;
|
|
298
|
+
where: CleanedWhere[];
|
|
299
|
+
select?: string[];
|
|
300
|
+
}) => Promise<T | null>;
|
|
301
|
+
findMany: <T>({ model, where, limit, sortBy, offset, }: {
|
|
302
|
+
model: string;
|
|
303
|
+
where?: CleanedWhere[];
|
|
304
|
+
limit: number;
|
|
305
|
+
sortBy?: {
|
|
306
|
+
field: string;
|
|
307
|
+
direction: "asc" | "desc";
|
|
308
|
+
};
|
|
309
|
+
offset?: number;
|
|
310
|
+
}) => Promise<T[]>;
|
|
311
|
+
delete: ({ model, where, }: {
|
|
312
|
+
model: string;
|
|
313
|
+
where: CleanedWhere[];
|
|
314
|
+
}) => Promise<void>;
|
|
315
|
+
deleteMany: ({ model, where, }: {
|
|
316
|
+
model: string;
|
|
317
|
+
where: CleanedWhere[];
|
|
318
|
+
}) => Promise<number>;
|
|
319
|
+
count: ({ model, where, }: {
|
|
320
|
+
model: string;
|
|
321
|
+
where?: CleanedWhere[];
|
|
322
|
+
}) => Promise<number>;
|
|
323
|
+
createSchema?: (props: {
|
|
324
|
+
/**
|
|
325
|
+
* The file the user may have passed in to the `generate` command as the expected schema file output path.
|
|
326
|
+
*/
|
|
327
|
+
file?: string;
|
|
328
|
+
/**
|
|
329
|
+
* The tables from the user's Better-Auth instance schema.
|
|
330
|
+
*/
|
|
331
|
+
tables: BetterAuthDbSchema;
|
|
332
|
+
}) => Promise<AdapterSchemaCreation>;
|
|
333
|
+
/**
|
|
334
|
+
* Your adapter's options.
|
|
335
|
+
*/
|
|
336
|
+
options?: Record<string, any> | undefined;
|
|
337
|
+
}
|
|
338
|
+
type CleanedWhere = Prettify<Required<Where>>;
|
|
339
|
+
type AdapterTestDebugLogs = {
|
|
340
|
+
resetDebugLogs: () => void;
|
|
341
|
+
printDebugLogs: () => void;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export type { AdapterDebugLogs as A, CreateCustomAdapter as C, AdapterConfig as a, CustomAdapter as b, CleanedWhere as c, AdapterTestDebugLogs as d };
|