@hammadj/better-auth-core 1.5.0-beta.9
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/.turbo/turbo-build.log +266 -0
- package/.turbo/turbo-test.log +2 -0
- package/LICENSE.md +20 -0
- package/dist/api/index.d.mts +181 -0
- package/dist/api/index.mjs +34 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/async_hooks/index.d.mts +7 -0
- package/dist/async_hooks/index.mjs +22 -0
- package/dist/async_hooks/index.mjs.map +1 -0
- package/dist/async_hooks/pure.index.d.mts +7 -0
- package/dist/async_hooks/pure.index.mjs +35 -0
- package/dist/async_hooks/pure.index.mjs.map +1 -0
- package/dist/context/endpoint-context.d.mts +19 -0
- package/dist/context/endpoint-context.mjs +32 -0
- package/dist/context/endpoint-context.mjs.map +1 -0
- package/dist/context/global.d.mts +7 -0
- package/dist/context/global.mjs +38 -0
- package/dist/context/global.mjs.map +1 -0
- package/dist/context/index.d.mts +5 -0
- package/dist/context/index.mjs +6 -0
- package/dist/context/request-state.d.mts +26 -0
- package/dist/context/request-state.mjs +50 -0
- package/dist/context/request-state.mjs.map +1 -0
- package/dist/context/transaction.d.mts +25 -0
- package/dist/context/transaction.mjs +96 -0
- package/dist/context/transaction.mjs.map +1 -0
- package/dist/db/adapter/factory.d.mts +28 -0
- package/dist/db/adapter/factory.mjs +716 -0
- package/dist/db/adapter/factory.mjs.map +1 -0
- package/dist/db/adapter/get-default-field-name.d.mts +19 -0
- package/dist/db/adapter/get-default-field-name.mjs +39 -0
- package/dist/db/adapter/get-default-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-default-model-name.d.mts +13 -0
- package/dist/db/adapter/get-default-model-name.mjs +33 -0
- package/dist/db/adapter/get-default-model-name.mjs.map +1 -0
- package/dist/db/adapter/get-field-attributes.d.mts +30 -0
- package/dist/db/adapter/get-field-attributes.mjs +40 -0
- package/dist/db/adapter/get-field-attributes.mjs.map +1 -0
- package/dist/db/adapter/get-field-name.d.mts +19 -0
- package/dist/db/adapter/get-field-name.mjs +34 -0
- package/dist/db/adapter/get-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-id-field.d.mts +40 -0
- package/dist/db/adapter/get-id-field.mjs +68 -0
- package/dist/db/adapter/get-id-field.mjs.map +1 -0
- package/dist/db/adapter/get-model-name.d.mts +13 -0
- package/dist/db/adapter/get-model-name.mjs +24 -0
- package/dist/db/adapter/get-model-name.mjs.map +1 -0
- package/dist/db/adapter/index.d.mts +515 -0
- package/dist/db/adapter/index.mjs +10 -0
- package/dist/db/adapter/types.d.mts +140 -0
- package/dist/db/adapter/utils.d.mts +8 -0
- package/dist/db/adapter/utils.mjs +39 -0
- package/dist/db/adapter/utils.mjs.map +1 -0
- package/dist/db/get-tables.d.mts +9 -0
- package/dist/db/get-tables.mjs +267 -0
- package/dist/db/get-tables.mjs.map +1 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +9 -0
- package/dist/db/plugin.d.mts +13 -0
- package/dist/db/schema/account.d.mts +27 -0
- package/dist/db/schema/account.mjs +20 -0
- package/dist/db/schema/account.mjs.map +1 -0
- package/dist/db/schema/rate-limit.d.mts +15 -0
- package/dist/db/schema/rate-limit.mjs +12 -0
- package/dist/db/schema/rate-limit.mjs.map +1 -0
- package/dist/db/schema/session.d.mts +22 -0
- package/dist/db/schema/session.mjs +15 -0
- package/dist/db/schema/session.mjs.map +1 -0
- package/dist/db/schema/shared.d.mts +11 -0
- package/dist/db/schema/shared.mjs +12 -0
- package/dist/db/schema/shared.mjs.map +1 -0
- package/dist/db/schema/user.d.mts +21 -0
- package/dist/db/schema/user.mjs +14 -0
- package/dist/db/schema/user.mjs.map +1 -0
- package/dist/db/schema/verification.d.mts +20 -0
- package/dist/db/schema/verification.mjs +13 -0
- package/dist/db/schema/verification.mjs.map +1 -0
- package/dist/db/type.d.mts +147 -0
- package/dist/env/color-depth.d.mts +5 -0
- package/dist/env/color-depth.mjs +89 -0
- package/dist/env/color-depth.mjs.map +1 -0
- package/dist/env/env-impl.d.mts +33 -0
- package/dist/env/env-impl.mjs +83 -0
- package/dist/env/env-impl.mjs.map +1 -0
- package/dist/env/index.d.mts +4 -0
- package/dist/env/index.mjs +5 -0
- package/dist/env/logger.d.mts +49 -0
- package/dist/env/logger.mjs +82 -0
- package/dist/env/logger.mjs.map +1 -0
- package/dist/error/codes.d.mts +199 -0
- package/dist/error/codes.mjs +57 -0
- package/dist/error/codes.mjs.map +1 -0
- package/dist/error/index.d.mts +20 -0
- package/dist/error/index.mjs +30 -0
- package/dist/error/index.mjs.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +1 -0
- package/dist/oauth2/client-credentials-token.d.mts +37 -0
- package/dist/oauth2/client-credentials-token.mjs +55 -0
- package/dist/oauth2/client-credentials-token.mjs.map +1 -0
- package/dist/oauth2/create-authorization-url.d.mts +46 -0
- package/dist/oauth2/create-authorization-url.mjs +43 -0
- package/dist/oauth2/create-authorization-url.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +8 -0
- package/dist/oauth2/index.mjs +8 -0
- package/dist/oauth2/oauth-provider.d.mts +195 -0
- package/dist/oauth2/refresh-access-token.d.mts +36 -0
- package/dist/oauth2/refresh-access-token.mjs +59 -0
- package/dist/oauth2/refresh-access-token.mjs.map +1 -0
- package/dist/oauth2/utils.d.mts +8 -0
- package/dist/oauth2/utils.mjs +28 -0
- package/dist/oauth2/utils.mjs.map +1 -0
- package/dist/oauth2/validate-authorization-code.d.mts +56 -0
- package/dist/oauth2/validate-authorization-code.mjs +72 -0
- package/dist/oauth2/validate-authorization-code.mjs.map +1 -0
- package/dist/oauth2/verify.d.mts +43 -0
- package/dist/oauth2/verify.mjs +96 -0
- package/dist/oauth2/verify.mjs.map +1 -0
- package/dist/social-providers/apple.d.mts +120 -0
- package/dist/social-providers/apple.mjs +105 -0
- package/dist/social-providers/apple.mjs.map +1 -0
- package/dist/social-providers/atlassian.d.mts +73 -0
- package/dist/social-providers/atlassian.mjs +84 -0
- package/dist/social-providers/atlassian.mjs.map +1 -0
- package/dist/social-providers/cognito.d.mts +88 -0
- package/dist/social-providers/cognito.mjs +166 -0
- package/dist/social-providers/cognito.mjs.map +1 -0
- package/dist/social-providers/discord.d.mts +127 -0
- package/dist/social-providers/discord.mjs +65 -0
- package/dist/social-providers/discord.mjs.map +1 -0
- package/dist/social-providers/dropbox.d.mts +72 -0
- package/dist/social-providers/dropbox.mjs +76 -0
- package/dist/social-providers/dropbox.mjs.map +1 -0
- package/dist/social-providers/facebook.d.mts +82 -0
- package/dist/social-providers/facebook.mjs +121 -0
- package/dist/social-providers/facebook.mjs.map +1 -0
- package/dist/social-providers/figma.d.mts +64 -0
- package/dist/social-providers/figma.mjs +87 -0
- package/dist/social-providers/figma.mjs.map +1 -0
- package/dist/social-providers/github.d.mts +105 -0
- package/dist/social-providers/github.mjs +97 -0
- package/dist/social-providers/github.mjs.map +1 -0
- package/dist/social-providers/gitlab.d.mts +126 -0
- package/dist/social-providers/gitlab.mjs +83 -0
- package/dist/social-providers/gitlab.mjs.map +1 -0
- package/dist/social-providers/google.d.mts +100 -0
- package/dist/social-providers/google.mjs +109 -0
- package/dist/social-providers/google.mjs.map +1 -0
- package/dist/social-providers/huggingface.d.mts +86 -0
- package/dist/social-providers/huggingface.mjs +76 -0
- package/dist/social-providers/huggingface.mjs.map +1 -0
- package/dist/social-providers/index.d.mts +1725 -0
- package/dist/social-providers/index.mjs +77 -0
- package/dist/social-providers/index.mjs.map +1 -0
- package/dist/social-providers/kakao.d.mts +164 -0
- package/dist/social-providers/kakao.mjs +73 -0
- package/dist/social-providers/kakao.mjs.map +1 -0
- package/dist/social-providers/kick.d.mts +76 -0
- package/dist/social-providers/kick.mjs +72 -0
- package/dist/social-providers/kick.mjs.map +1 -0
- package/dist/social-providers/line.d.mts +108 -0
- package/dist/social-providers/line.mjs +114 -0
- package/dist/social-providers/line.mjs.map +1 -0
- package/dist/social-providers/linear.d.mts +71 -0
- package/dist/social-providers/linear.mjs +89 -0
- package/dist/social-providers/linear.mjs.map +1 -0
- package/dist/social-providers/linkedin.d.mts +70 -0
- package/dist/social-providers/linkedin.mjs +77 -0
- package/dist/social-providers/linkedin.mjs.map +1 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +175 -0
- package/dist/social-providers/microsoft-entra-id.mjs +107 -0
- package/dist/social-providers/microsoft-entra-id.mjs.map +1 -0
- package/dist/social-providers/naver.d.mts +95 -0
- package/dist/social-providers/naver.mjs +68 -0
- package/dist/social-providers/naver.mjs.map +1 -0
- package/dist/social-providers/notion.d.mts +67 -0
- package/dist/social-providers/notion.mjs +76 -0
- package/dist/social-providers/notion.mjs.map +1 -0
- package/dist/social-providers/paybin.d.mts +74 -0
- package/dist/social-providers/paybin.mjs +86 -0
- package/dist/social-providers/paybin.mjs.map +1 -0
- package/dist/social-providers/paypal.d.mts +132 -0
- package/dist/social-providers/paypal.mjs +145 -0
- package/dist/social-providers/paypal.mjs.map +1 -0
- package/dist/social-providers/polar.d.mts +77 -0
- package/dist/social-providers/polar.mjs +74 -0
- package/dist/social-providers/polar.mjs.map +1 -0
- package/dist/social-providers/reddit.d.mts +65 -0
- package/dist/social-providers/reddit.mjs +84 -0
- package/dist/social-providers/reddit.mjs.map +1 -0
- package/dist/social-providers/roblox.d.mts +73 -0
- package/dist/social-providers/roblox.mjs +60 -0
- package/dist/social-providers/roblox.mjs.map +1 -0
- package/dist/social-providers/salesforce.d.mts +82 -0
- package/dist/social-providers/salesforce.mjs +92 -0
- package/dist/social-providers/salesforce.mjs.map +1 -0
- package/dist/social-providers/slack.d.mts +86 -0
- package/dist/social-providers/slack.mjs +69 -0
- package/dist/social-providers/slack.mjs.map +1 -0
- package/dist/social-providers/spotify.d.mts +66 -0
- package/dist/social-providers/spotify.mjs +72 -0
- package/dist/social-providers/spotify.mjs.map +1 -0
- package/dist/social-providers/tiktok.d.mts +171 -0
- package/dist/social-providers/tiktok.mjs +63 -0
- package/dist/social-providers/tiktok.mjs.map +1 -0
- package/dist/social-providers/twitch.d.mts +82 -0
- package/dist/social-providers/twitch.mjs +79 -0
- package/dist/social-providers/twitch.mjs.map +1 -0
- package/dist/social-providers/twitter.d.mts +129 -0
- package/dist/social-providers/twitter.mjs +88 -0
- package/dist/social-providers/twitter.mjs.map +1 -0
- package/dist/social-providers/vercel.d.mts +65 -0
- package/dist/social-providers/vercel.mjs +62 -0
- package/dist/social-providers/vercel.mjs.map +1 -0
- package/dist/social-providers/vk.d.mts +73 -0
- package/dist/social-providers/vk.mjs +84 -0
- package/dist/social-providers/vk.mjs.map +1 -0
- package/dist/social-providers/zoom.d.mts +173 -0
- package/dist/social-providers/zoom.mjs +73 -0
- package/dist/social-providers/zoom.mjs.map +1 -0
- package/dist/types/context.d.mts +267 -0
- package/dist/types/cookie.d.mts +16 -0
- package/dist/types/helper.d.mts +10 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1314 -0
- package/dist/types/plugin-client.d.mts +112 -0
- package/dist/types/plugin.d.mts +125 -0
- package/dist/utils/db.d.mts +12 -0
- package/dist/utils/db.mjs +17 -0
- package/dist/utils/db.mjs.map +1 -0
- package/dist/utils/deprecate.d.mts +10 -0
- package/dist/utils/deprecate.mjs +18 -0
- package/dist/utils/deprecate.mjs.map +1 -0
- package/dist/utils/error-codes.d.mts +13 -0
- package/dist/utils/error-codes.mjs +12 -0
- package/dist/utils/error-codes.mjs.map +1 -0
- package/dist/utils/id.d.mts +5 -0
- package/dist/utils/id.mjs +10 -0
- package/dist/utils/id.mjs.map +1 -0
- package/dist/utils/ip.d.mts +55 -0
- package/dist/utils/ip.mjs +119 -0
- package/dist/utils/ip.mjs.map +1 -0
- package/dist/utils/json.d.mts +5 -0
- package/dist/utils/json.mjs +26 -0
- package/dist/utils/json.mjs.map +1 -0
- package/dist/utils/string.d.mts +5 -0
- package/dist/utils/string.mjs +8 -0
- package/dist/utils/string.mjs.map +1 -0
- package/dist/utils/url.d.mts +21 -0
- package/dist/utils/url.mjs +33 -0
- package/dist/utils/url.mjs.map +1 -0
- package/package.json +147 -0
- package/src/api/index.ts +106 -0
- package/src/async_hooks/index.ts +40 -0
- package/src/async_hooks/pure.index.ts +46 -0
- package/src/context/endpoint-context.ts +50 -0
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +23 -0
- package/src/context/request-state.test.ts +94 -0
- package/src/context/request-state.ts +91 -0
- package/src/context/transaction.ts +136 -0
- package/src/db/adapter/factory.ts +1362 -0
- package/src/db/adapter/get-default-field-name.ts +59 -0
- package/src/db/adapter/get-default-model-name.ts +51 -0
- package/src/db/adapter/get-field-attributes.ts +62 -0
- package/src/db/adapter/get-field-name.ts +43 -0
- package/src/db/adapter/get-id-field.ts +141 -0
- package/src/db/adapter/get-model-name.ts +36 -0
- package/src/db/adapter/index.ts +554 -0
- package/src/db/adapter/types.ts +171 -0
- package/src/db/adapter/utils.ts +61 -0
- package/src/db/get-tables.ts +296 -0
- package/src/db/index.ts +18 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +34 -0
- package/src/db/schema/rate-limit.ts +21 -0
- package/src/db/schema/session.ts +17 -0
- package/src/db/schema/shared.ts +7 -0
- package/src/db/schema/user.ts +16 -0
- package/src/db/schema/verification.ts +15 -0
- package/src/db/test/get-tables.test.ts +116 -0
- package/src/db/type.ts +180 -0
- package/src/env/color-depth.ts +172 -0
- package/src/env/env-impl.ts +124 -0
- package/src/env/index.ts +23 -0
- package/src/env/logger.test.ts +34 -0
- package/src/env/logger.ts +145 -0
- package/src/error/codes.ts +58 -0
- package/src/error/index.ts +35 -0
- package/src/index.ts +1 -0
- package/src/oauth2/client-credentials-token.ts +102 -0
- package/src/oauth2/create-authorization-url.ts +87 -0
- package/src/oauth2/index.ts +26 -0
- package/src/oauth2/oauth-provider.ts +222 -0
- package/src/oauth2/refresh-access-token.ts +124 -0
- package/src/oauth2/utils.ts +38 -0
- package/src/oauth2/validate-authorization-code.ts +149 -0
- package/src/oauth2/validate-token.test.ts +174 -0
- package/src/oauth2/verify.ts +221 -0
- package/src/social-providers/apple.ts +223 -0
- package/src/social-providers/atlassian.ts +132 -0
- package/src/social-providers/cognito.ts +279 -0
- package/src/social-providers/discord.ts +169 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +206 -0
- package/src/social-providers/figma.ts +117 -0
- package/src/social-providers/github.ts +184 -0
- package/src/social-providers/gitlab.ts +155 -0
- package/src/social-providers/google.ts +199 -0
- package/src/social-providers/huggingface.ts +118 -0
- package/src/social-providers/index.ts +127 -0
- package/src/social-providers/kakao.ts +178 -0
- package/src/social-providers/kick.ts +109 -0
- package/src/social-providers/line.ts +169 -0
- package/src/social-providers/linear.ts +121 -0
- package/src/social-providers/linkedin.ts +110 -0
- package/src/social-providers/microsoft-entra-id.ts +259 -0
- package/src/social-providers/naver.ts +112 -0
- package/src/social-providers/notion.ts +108 -0
- package/src/social-providers/paybin.ts +122 -0
- package/src/social-providers/paypal.ts +263 -0
- package/src/social-providers/polar.ts +110 -0
- package/src/social-providers/reddit.ts +122 -0
- package/src/social-providers/roblox.ts +111 -0
- package/src/social-providers/salesforce.ts +159 -0
- package/src/social-providers/slack.ts +111 -0
- package/src/social-providers/spotify.ts +93 -0
- package/src/social-providers/tiktok.ts +209 -0
- package/src/social-providers/twitch.ts +111 -0
- package/src/social-providers/twitter.ts +198 -0
- package/src/social-providers/vercel.ts +87 -0
- package/src/social-providers/vk.ts +124 -0
- package/src/social-providers/zoom.ts +238 -0
- package/src/types/context.ts +396 -0
- package/src/types/cookie.ts +10 -0
- package/src/types/helper.ts +26 -0
- package/src/types/index.ts +32 -0
- package/src/types/init-options.ts +1529 -0
- package/src/types/plugin-client.ts +127 -0
- package/src/types/plugin.ts +157 -0
- package/src/utils/db.ts +20 -0
- package/src/utils/deprecate.test.ts +72 -0
- package/src/utils/deprecate.ts +21 -0
- package/src/utils/error-codes.ts +65 -0
- package/src/utils/id.ts +5 -0
- package/src/utils/ip.test.ts +255 -0
- package/src/utils/ip.ts +211 -0
- package/src/utils/json.ts +25 -0
- package/src/utils/string.ts +3 -0
- package/src/utils/url.ts +43 -0
- package/tsconfig.json +7 -0
- package/tsdown.config.ts +35 -0
- package/vitest.config.ts +3 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
import { initGetDefaultFieldName } from "./get-default-field-name.mjs";
|
|
3
|
+
import { initGetDefaultModelName } from "./get-default-model-name.mjs";
|
|
4
|
+
import { initGetFieldAttributes } from "./get-field-attributes.mjs";
|
|
5
|
+
import { initGetFieldName } from "./get-field-name.mjs";
|
|
6
|
+
import { initGetIdField } from "./get-id-field.mjs";
|
|
7
|
+
import { initGetModelName } from "./get-model-name.mjs";
|
|
8
|
+
import { AdapterConfig, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CreateAdapterOptions, CreateCustomAdapter } from "./types.mjs";
|
|
9
|
+
import { AdapterFactory, createAdapter, createAdapterFactory } from "./factory.mjs";
|
|
10
|
+
import { deepmerge, withApplyDefault } from "./utils.mjs";
|
|
11
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
12
|
+
import "../../types/index.mjs";
|
|
13
|
+
|
|
14
|
+
//#region src/db/adapter/index.d.ts
|
|
15
|
+
type DBAdapterDebugLogOption = boolean | {
|
|
16
|
+
/**
|
|
17
|
+
* Useful when you want to log only certain conditions.
|
|
18
|
+
*/
|
|
19
|
+
logCondition?: (() => boolean) | undefined;
|
|
20
|
+
create?: boolean | undefined;
|
|
21
|
+
update?: boolean | undefined;
|
|
22
|
+
updateMany?: boolean | undefined;
|
|
23
|
+
findOne?: boolean | undefined;
|
|
24
|
+
findMany?: boolean | undefined;
|
|
25
|
+
delete?: boolean | undefined;
|
|
26
|
+
deleteMany?: boolean | undefined;
|
|
27
|
+
count?: boolean | undefined;
|
|
28
|
+
} | {
|
|
29
|
+
/**
|
|
30
|
+
* Only used for adapter tests to show debug logs if a test fails.
|
|
31
|
+
*
|
|
32
|
+
* @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
|
|
33
|
+
*/
|
|
34
|
+
isRunningAdapterTests: boolean;
|
|
35
|
+
};
|
|
36
|
+
type DBAdapterSchemaCreation = {
|
|
37
|
+
/**
|
|
38
|
+
* Code to be inserted into the file
|
|
39
|
+
*/
|
|
40
|
+
code: string;
|
|
41
|
+
/**
|
|
42
|
+
* Path to the file, including the file name and extension.
|
|
43
|
+
* Relative paths are supported, with the current working directory of the developer's project as the base.
|
|
44
|
+
*/
|
|
45
|
+
path: string;
|
|
46
|
+
/**
|
|
47
|
+
* Append the file if it already exists.
|
|
48
|
+
* Note: This will not apply if `overwrite` is set to true.
|
|
49
|
+
*/
|
|
50
|
+
append?: boolean | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Overwrite the file if it already exists
|
|
53
|
+
*/
|
|
54
|
+
overwrite?: boolean | undefined;
|
|
55
|
+
};
|
|
56
|
+
interface DBAdapterFactoryConfig<Options extends BetterAuthOptions = BetterAuthOptions> {
|
|
57
|
+
/**
|
|
58
|
+
* Use plural table names.
|
|
59
|
+
*
|
|
60
|
+
* All tables will be named with an `s` at the end.
|
|
61
|
+
*
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
usePlural?: boolean | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Enable debug logs.
|
|
67
|
+
*
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
debugLogs?: DBAdapterDebugLogOption | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Name of the adapter.
|
|
73
|
+
*
|
|
74
|
+
* This is used to identify the adapter in the debug logs.
|
|
75
|
+
*
|
|
76
|
+
* @default `adapterId`
|
|
77
|
+
*/
|
|
78
|
+
adapterName?: string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Adapter id
|
|
81
|
+
*/
|
|
82
|
+
adapterId: string;
|
|
83
|
+
/**
|
|
84
|
+
* If the database supports numeric ids, set this to `true`.
|
|
85
|
+
*
|
|
86
|
+
* @default true
|
|
87
|
+
*/
|
|
88
|
+
supportsNumericIds?: boolean | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* If the database supports natively generating UUIDs, set this to `true`.
|
|
91
|
+
*
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
supportsUUIDs?: boolean | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* If the database doesn't support JSON columns, set this to `false`.
|
|
97
|
+
*
|
|
98
|
+
* We will handle the translation between using `JSON` columns, and saving `string`s to the database.
|
|
99
|
+
*
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
102
|
+
supportsJSON?: boolean | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* If the database doesn't support dates, set this to `false`.
|
|
105
|
+
*
|
|
106
|
+
* We will handle the translation between using `Date` objects, and saving `string`s to the database.
|
|
107
|
+
*
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
supportsDates?: boolean | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* If the database doesn't support booleans, set this to `false`.
|
|
113
|
+
*
|
|
114
|
+
* We will handle the translation between using `boolean`s, and saving `0`s and `1`s to the database.
|
|
115
|
+
*
|
|
116
|
+
* @default true
|
|
117
|
+
*/
|
|
118
|
+
supportsBooleans?: boolean | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* If the database doesn't support arrays, set this to `false`.
|
|
121
|
+
*
|
|
122
|
+
* We will handle the translation between using `array`s, and saving `string`s to the database.
|
|
123
|
+
*
|
|
124
|
+
* @default false
|
|
125
|
+
*/
|
|
126
|
+
supportsArrays?: boolean | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Execute multiple operations in a transaction.
|
|
129
|
+
*
|
|
130
|
+
* If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
|
|
131
|
+
*
|
|
132
|
+
* @default false
|
|
133
|
+
*/
|
|
134
|
+
transaction?: (false | (<R>(callback: (trx: DBTransactionAdapter<Options>) => Promise<R>) => Promise<R>)) | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Disable id generation for the `create` method.
|
|
137
|
+
*
|
|
138
|
+
* This is useful for databases that don't support custom id values and would auto-generate them for you.
|
|
139
|
+
*
|
|
140
|
+
* @default false
|
|
141
|
+
*/
|
|
142
|
+
disableIdGeneration?: boolean | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Map the keys of the input data.
|
|
145
|
+
*
|
|
146
|
+
* This is useful for databases that expect a different key name for a given situation.
|
|
147
|
+
*
|
|
148
|
+
* For example, MongoDB uses `_id` while in Better-Auth we use `id`.
|
|
149
|
+
*
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* Each key represents the old key to replace.
|
|
153
|
+
* The value represents the new key
|
|
154
|
+
*
|
|
155
|
+
* This can be a partial object that only transforms some keys.
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* mapKeysTransformInput: {
|
|
159
|
+
* id: "_id" // We want to replace `id` to `_id` to save into MongoDB
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
mapKeysTransformInput?: Record<string, string> | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Map the keys of the output data.
|
|
166
|
+
*
|
|
167
|
+
* This is useful for databases that expect a different key name for a given situation.
|
|
168
|
+
*
|
|
169
|
+
* For example, MongoDB uses `_id` while in Better-Auth we use `id`.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* Each key represents the old key to replace.
|
|
173
|
+
* The value represents the new key
|
|
174
|
+
*
|
|
175
|
+
* This can be a partial object that only transforms some keys.
|
|
176
|
+
*
|
|
177
|
+
* ```ts
|
|
178
|
+
* mapKeysTransformOutput: {
|
|
179
|
+
* _id: "id" // In MongoDB, we save `id` as `_id`. So we want to replace `_id` with `id` when we get the data back.
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
mapKeysTransformOutput?: Record<string, string> | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Custom transform input function.
|
|
186
|
+
*
|
|
187
|
+
* This function is used to transform the input data before it is saved to the database.
|
|
188
|
+
*/
|
|
189
|
+
customTransformInput?: ((props: {
|
|
190
|
+
data: any;
|
|
191
|
+
/**
|
|
192
|
+
* The fields of the model.
|
|
193
|
+
*/
|
|
194
|
+
fieldAttributes: DBFieldAttribute;
|
|
195
|
+
/**
|
|
196
|
+
* The field to transform.
|
|
197
|
+
*/
|
|
198
|
+
field: string;
|
|
199
|
+
/**
|
|
200
|
+
* The action which was called from the adapter.
|
|
201
|
+
*/
|
|
202
|
+
action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "count";
|
|
203
|
+
/**
|
|
204
|
+
* The model name.
|
|
205
|
+
*/
|
|
206
|
+
model: string;
|
|
207
|
+
/**
|
|
208
|
+
* The schema of the user's Better-Auth instance.
|
|
209
|
+
*/
|
|
210
|
+
schema: BetterAuthDBSchema;
|
|
211
|
+
/**
|
|
212
|
+
* The options of the user's Better-Auth instance.
|
|
213
|
+
*/
|
|
214
|
+
options: Options;
|
|
215
|
+
}) => any) | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Custom transform output function.
|
|
218
|
+
*
|
|
219
|
+
* This function is used to transform the output data before it is returned to the user.
|
|
220
|
+
*/
|
|
221
|
+
customTransformOutput?: ((props: {
|
|
222
|
+
data: any;
|
|
223
|
+
/**
|
|
224
|
+
* The fields of the model.
|
|
225
|
+
*/
|
|
226
|
+
fieldAttributes: DBFieldAttribute;
|
|
227
|
+
/**
|
|
228
|
+
* The field to transform.
|
|
229
|
+
*/
|
|
230
|
+
field: string;
|
|
231
|
+
/**
|
|
232
|
+
* The fields to select.
|
|
233
|
+
*/
|
|
234
|
+
select: string[];
|
|
235
|
+
/**
|
|
236
|
+
* The model name.
|
|
237
|
+
*/
|
|
238
|
+
model: string;
|
|
239
|
+
/**
|
|
240
|
+
* The schema of the user's Better-Auth instance.
|
|
241
|
+
*/
|
|
242
|
+
schema: BetterAuthDBSchema;
|
|
243
|
+
/**
|
|
244
|
+
* The options of the user's Better-Auth instance.
|
|
245
|
+
*/
|
|
246
|
+
options: Options;
|
|
247
|
+
}) => any) | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* Custom ID generator function.
|
|
250
|
+
*
|
|
251
|
+
* By default, we can handle ID generation for you, however if the database your adapter is for only supports a specific custom id generation,
|
|
252
|
+
* then you can use this function to generate your own IDs.
|
|
253
|
+
*
|
|
254
|
+
*
|
|
255
|
+
* Notes:
|
|
256
|
+
* - If the user enabled `useNumberId` or `generateId` set to `serial`, then this option will be ignored. Unless this adapter config has `supportsNumericIds` set to `false`.
|
|
257
|
+
* - If `generateId` is `false` in the user's Better-Auth config, then this option will be ignored.
|
|
258
|
+
* - If `generateId` is a function, then it will override this option.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
*
|
|
262
|
+
* ```ts
|
|
263
|
+
* customIdGenerator: ({ model }) => {
|
|
264
|
+
* return "my-super-unique-id";
|
|
265
|
+
* }
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
customIdGenerator?: ((props: {
|
|
269
|
+
model: string;
|
|
270
|
+
}) => string) | undefined;
|
|
271
|
+
/**
|
|
272
|
+
* Whether to disable the transform output.
|
|
273
|
+
* Do not use this option unless you know what you are doing.
|
|
274
|
+
* @default false
|
|
275
|
+
*/
|
|
276
|
+
disableTransformOutput?: boolean | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* Whether to disable the transform input.
|
|
279
|
+
* Do not use this option unless you know what you are doing.
|
|
280
|
+
* @default false
|
|
281
|
+
*/
|
|
282
|
+
disableTransformInput?: boolean | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* Whether to disable the transform join.
|
|
285
|
+
* Do not use this option unless you know what you are doing.
|
|
286
|
+
* @default false
|
|
287
|
+
*/
|
|
288
|
+
disableTransformJoin?: boolean | undefined;
|
|
289
|
+
}
|
|
290
|
+
type Where = {
|
|
291
|
+
/**
|
|
292
|
+
* @default eq
|
|
293
|
+
*/
|
|
294
|
+
operator?: ("eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with") | undefined;
|
|
295
|
+
value: string | number | boolean | string[] | number[] | Date | null;
|
|
296
|
+
field: string;
|
|
297
|
+
/**
|
|
298
|
+
* @default AND
|
|
299
|
+
*/
|
|
300
|
+
connector?: ("AND" | "OR") | undefined;
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* JoinOption configuration for relational queries.
|
|
304
|
+
*
|
|
305
|
+
* Allows you to join related tables/models in a single query operation.
|
|
306
|
+
* Each key represents the name of the joined table/model, and the value
|
|
307
|
+
* configures how the join should be performed.
|
|
308
|
+
*/
|
|
309
|
+
type JoinOption = {
|
|
310
|
+
[model: string]: boolean | {
|
|
311
|
+
limit?: number;
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Once `JoinOption` has gone through the adapter factory, it will be transformed into a `JoinConfig`.
|
|
316
|
+
*/
|
|
317
|
+
type JoinConfig = {
|
|
318
|
+
[model: string]: {
|
|
319
|
+
/**
|
|
320
|
+
* The joining column names.
|
|
321
|
+
*/
|
|
322
|
+
on: {
|
|
323
|
+
/**
|
|
324
|
+
* Column name from the main table
|
|
325
|
+
*/
|
|
326
|
+
from: string;
|
|
327
|
+
/**
|
|
328
|
+
* Column name from the joined table
|
|
329
|
+
*/
|
|
330
|
+
to: string;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Limit the number of rows to return.
|
|
334
|
+
*
|
|
335
|
+
* If the relation has `unique` constraint, then this option will be ignored and limit will be set to 1.
|
|
336
|
+
*
|
|
337
|
+
* @default 100
|
|
338
|
+
*/
|
|
339
|
+
limit?: number;
|
|
340
|
+
/**
|
|
341
|
+
* The relation type. Determines the output joined model data.
|
|
342
|
+
*
|
|
343
|
+
* `one-to-one` would have a single object in the output.
|
|
344
|
+
* `one-to-many` would have an array of objects in the output.
|
|
345
|
+
* `many-to-many` would have an array of objects in the output.
|
|
346
|
+
*
|
|
347
|
+
* @default "one-to-many"
|
|
348
|
+
*/
|
|
349
|
+
relation?: "one-to-one" | "one-to-many" | "many-to-many";
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
type DBTransactionAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = Omit<DBAdapter<Options>, "transaction">;
|
|
353
|
+
type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
|
|
354
|
+
id: string;
|
|
355
|
+
create: <T extends Record<string, any>, R = T>(data: {
|
|
356
|
+
model: string;
|
|
357
|
+
data: Omit<T, "id">;
|
|
358
|
+
select?: string[] | undefined;
|
|
359
|
+
/**
|
|
360
|
+
* By default, any `id` provided in `data` will be ignored.
|
|
361
|
+
*
|
|
362
|
+
* If you want to force the `id` to be the same as the `data.id`, set this to `true`.
|
|
363
|
+
*/
|
|
364
|
+
forceAllowId?: boolean | undefined;
|
|
365
|
+
}) => Promise<R>;
|
|
366
|
+
findOne: <T>(data: {
|
|
367
|
+
model: string;
|
|
368
|
+
where: Where[];
|
|
369
|
+
select?: string[] | undefined;
|
|
370
|
+
join?: JoinOption | undefined;
|
|
371
|
+
}) => Promise<T | null>;
|
|
372
|
+
findMany: <T>(data: {
|
|
373
|
+
model: string;
|
|
374
|
+
where?: Where[] | undefined;
|
|
375
|
+
limit?: number | undefined;
|
|
376
|
+
sortBy?: {
|
|
377
|
+
field: string;
|
|
378
|
+
direction: "asc" | "desc";
|
|
379
|
+
} | undefined;
|
|
380
|
+
offset?: number | undefined;
|
|
381
|
+
join?: JoinOption | undefined;
|
|
382
|
+
}) => Promise<T[]>;
|
|
383
|
+
count: (data: {
|
|
384
|
+
model: string;
|
|
385
|
+
where?: Where[] | undefined;
|
|
386
|
+
}) => Promise<number>;
|
|
387
|
+
/**
|
|
388
|
+
* ⚠︎ Update may not return the updated data
|
|
389
|
+
* if multiple where clauses are provided
|
|
390
|
+
*/
|
|
391
|
+
update: <T>(data: {
|
|
392
|
+
model: string;
|
|
393
|
+
where: Where[];
|
|
394
|
+
update: Record<string, any>;
|
|
395
|
+
}) => Promise<T | null>;
|
|
396
|
+
updateMany: (data: {
|
|
397
|
+
model: string;
|
|
398
|
+
where: Where[];
|
|
399
|
+
update: Record<string, any>;
|
|
400
|
+
}) => Promise<number>;
|
|
401
|
+
delete: <_T>(data: {
|
|
402
|
+
model: string;
|
|
403
|
+
where: Where[];
|
|
404
|
+
}) => Promise<void>;
|
|
405
|
+
deleteMany: (data: {
|
|
406
|
+
model: string;
|
|
407
|
+
where: Where[];
|
|
408
|
+
}) => Promise<number>;
|
|
409
|
+
/**
|
|
410
|
+
* Execute multiple operations in a transaction.
|
|
411
|
+
* If the adapter doesn't support transactions, operations will be executed sequentially.
|
|
412
|
+
*/
|
|
413
|
+
transaction: <R>(callback: (trx: DBTransactionAdapter<Options>) => Promise<R>) => Promise<R>;
|
|
414
|
+
/**
|
|
415
|
+
*
|
|
416
|
+
* @param options
|
|
417
|
+
* @param file - file path if provided by the user
|
|
418
|
+
*/
|
|
419
|
+
createSchema?: ((options: Options, file?: string) => Promise<DBAdapterSchemaCreation>) | undefined;
|
|
420
|
+
options?: ({
|
|
421
|
+
adapterConfig: DBAdapterFactoryConfig<Options>;
|
|
422
|
+
} & CustomAdapter["options"]) | undefined;
|
|
423
|
+
};
|
|
424
|
+
type CleanedWhere = Required<Where>;
|
|
425
|
+
interface CustomAdapter {
|
|
426
|
+
create: <T extends Record<string, any>>({
|
|
427
|
+
data,
|
|
428
|
+
model,
|
|
429
|
+
select
|
|
430
|
+
}: {
|
|
431
|
+
model: string;
|
|
432
|
+
data: T;
|
|
433
|
+
select?: string[] | undefined;
|
|
434
|
+
}) => Promise<T>;
|
|
435
|
+
update: <T>(data: {
|
|
436
|
+
model: string;
|
|
437
|
+
where: CleanedWhere[];
|
|
438
|
+
update: T;
|
|
439
|
+
}) => Promise<T | null>;
|
|
440
|
+
updateMany: (data: {
|
|
441
|
+
model: string;
|
|
442
|
+
where: CleanedWhere[];
|
|
443
|
+
update: Record<string, any>;
|
|
444
|
+
}) => Promise<number>;
|
|
445
|
+
findOne: <T>({
|
|
446
|
+
model,
|
|
447
|
+
where,
|
|
448
|
+
select,
|
|
449
|
+
join
|
|
450
|
+
}: {
|
|
451
|
+
model: string;
|
|
452
|
+
where: CleanedWhere[];
|
|
453
|
+
select?: string[] | undefined;
|
|
454
|
+
join?: JoinConfig | undefined;
|
|
455
|
+
}) => Promise<T | null>;
|
|
456
|
+
findMany: <T>({
|
|
457
|
+
model,
|
|
458
|
+
where,
|
|
459
|
+
limit,
|
|
460
|
+
sortBy,
|
|
461
|
+
offset,
|
|
462
|
+
join
|
|
463
|
+
}: {
|
|
464
|
+
model: string;
|
|
465
|
+
where?: CleanedWhere[] | undefined;
|
|
466
|
+
limit: number;
|
|
467
|
+
sortBy?: {
|
|
468
|
+
field: string;
|
|
469
|
+
direction: "asc" | "desc";
|
|
470
|
+
} | undefined;
|
|
471
|
+
offset?: number | undefined;
|
|
472
|
+
join?: JoinConfig | undefined;
|
|
473
|
+
}) => Promise<T[]>;
|
|
474
|
+
delete: ({
|
|
475
|
+
model,
|
|
476
|
+
where
|
|
477
|
+
}: {
|
|
478
|
+
model: string;
|
|
479
|
+
where: CleanedWhere[];
|
|
480
|
+
}) => Promise<void>;
|
|
481
|
+
deleteMany: ({
|
|
482
|
+
model,
|
|
483
|
+
where
|
|
484
|
+
}: {
|
|
485
|
+
model: string;
|
|
486
|
+
where: CleanedWhere[];
|
|
487
|
+
}) => Promise<number>;
|
|
488
|
+
count: ({
|
|
489
|
+
model,
|
|
490
|
+
where
|
|
491
|
+
}: {
|
|
492
|
+
model: string;
|
|
493
|
+
where?: CleanedWhere[] | undefined;
|
|
494
|
+
}) => Promise<number>;
|
|
495
|
+
createSchema?: ((props: {
|
|
496
|
+
/**
|
|
497
|
+
* The file the user may have passed in to the `generate` command as the expected schema file output path.
|
|
498
|
+
*/
|
|
499
|
+
file?: string;
|
|
500
|
+
/**
|
|
501
|
+
* The tables from the user's Better-Auth instance schema.
|
|
502
|
+
*/
|
|
503
|
+
tables: BetterAuthDBSchema;
|
|
504
|
+
}) => Promise<DBAdapterSchemaCreation>) | undefined;
|
|
505
|
+
/**
|
|
506
|
+
* Your adapter's options.
|
|
507
|
+
*/
|
|
508
|
+
options?: Record<string, any> | undefined;
|
|
509
|
+
}
|
|
510
|
+
interface DBAdapterInstance<Options extends BetterAuthOptions = BetterAuthOptions> {
|
|
511
|
+
(options: BetterAuthOptions): DBAdapter<Options>;
|
|
512
|
+
}
|
|
513
|
+
//#endregion
|
|
514
|
+
export { AdapterConfig, AdapterFactory, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, JoinOption, Where, createAdapter, createAdapterFactory, deepmerge, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName, withApplyDefault };
|
|
515
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { initGetDefaultModelName } from "./get-default-model-name.mjs";
|
|
2
|
+
import { initGetDefaultFieldName } from "./get-default-field-name.mjs";
|
|
3
|
+
import { initGetIdField } from "./get-id-field.mjs";
|
|
4
|
+
import { initGetFieldAttributes } from "./get-field-attributes.mjs";
|
|
5
|
+
import { initGetFieldName } from "./get-field-name.mjs";
|
|
6
|
+
import { initGetModelName } from "./get-model-name.mjs";
|
|
7
|
+
import { deepmerge, withApplyDefault } from "./utils.mjs";
|
|
8
|
+
import { createAdapter, createAdapterFactory } from "./factory.mjs";
|
|
9
|
+
|
|
10
|
+
export { createAdapter, createAdapterFactory, deepmerge, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName, withApplyDefault };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { CustomAdapter as CustomAdapter$1, DBAdapterFactoryConfig, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, Where } from "./index.mjs";
|
|
4
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
5
|
+
import "../../types/index.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/db/adapter/types.d.ts
|
|
8
|
+
type AdapterFactoryOptions = {
|
|
9
|
+
config: AdapterFactoryConfig;
|
|
10
|
+
adapter: AdapterFactoryCustomizeAdapterCreator;
|
|
11
|
+
};
|
|
12
|
+
interface AdapterFactoryConfig extends Omit<DBAdapterFactoryConfig<BetterAuthOptions>, "transaction"> {
|
|
13
|
+
/**
|
|
14
|
+
* Execute multiple operations in a transaction.
|
|
15
|
+
*
|
|
16
|
+
* If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
|
|
17
|
+
*
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
transaction?: (false | (<R>(callback: (trx: DBTransactionAdapter) => Promise<R>) => Promise<R>)) | undefined;
|
|
21
|
+
}
|
|
22
|
+
type AdapterFactoryCustomizeAdapterCreator = (config: {
|
|
23
|
+
options: BetterAuthOptions;
|
|
24
|
+
/**
|
|
25
|
+
* The schema of the user's Better-Auth instance.
|
|
26
|
+
*/
|
|
27
|
+
schema: BetterAuthDBSchema;
|
|
28
|
+
/**
|
|
29
|
+
* The debug log function.
|
|
30
|
+
*
|
|
31
|
+
* If the config has defined `debugLogs` as `false`, no logs will be shown.
|
|
32
|
+
*/
|
|
33
|
+
debugLog: (...args: unknown[]) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the model name which is expected to be saved in the database based on the user's schema.
|
|
36
|
+
*/
|
|
37
|
+
getModelName: (model: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
40
|
+
*/
|
|
41
|
+
getFieldName: ({
|
|
42
|
+
model,
|
|
43
|
+
field
|
|
44
|
+
}: {
|
|
45
|
+
model: string;
|
|
46
|
+
field: string;
|
|
47
|
+
}) => string;
|
|
48
|
+
/**
|
|
49
|
+
* This function helps us get the default model name from the schema defined by devs.
|
|
50
|
+
* Often times, the user will be using the `modelName` which could had been customized by the users.
|
|
51
|
+
* This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
|
|
52
|
+
*
|
|
53
|
+
* If it's still unclear what this does:
|
|
54
|
+
*
|
|
55
|
+
* 1. User can define a custom modelName.
|
|
56
|
+
* 2. When using a custom modelName, doing something like `schema[model]` will not work.
|
|
57
|
+
* 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
|
|
58
|
+
* 4. Thus allowing us to use `schema[model]`.
|
|
59
|
+
*/
|
|
60
|
+
getDefaultModelName: (model: string) => string;
|
|
61
|
+
/**
|
|
62
|
+
* This function helps us get the default field name from the schema defined by devs.
|
|
63
|
+
* Often times, the user will be using the `fieldName` which could had been customized by the users.
|
|
64
|
+
* This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
|
|
65
|
+
*
|
|
66
|
+
* If it's still unclear what this does:
|
|
67
|
+
*
|
|
68
|
+
* 1. User can define a custom fieldName.
|
|
69
|
+
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
getDefaultFieldName: ({
|
|
73
|
+
model,
|
|
74
|
+
field
|
|
75
|
+
}: {
|
|
76
|
+
model: string;
|
|
77
|
+
field: string;
|
|
78
|
+
}) => string;
|
|
79
|
+
/**
|
|
80
|
+
* Get the field attributes for a given model and field.
|
|
81
|
+
*
|
|
82
|
+
* Note: any model name or field name is allowed, whether default to schema or not.
|
|
83
|
+
*/
|
|
84
|
+
getFieldAttributes: ({
|
|
85
|
+
model,
|
|
86
|
+
field
|
|
87
|
+
}: {
|
|
88
|
+
model: string;
|
|
89
|
+
field: string;
|
|
90
|
+
}) => DBFieldAttribute;
|
|
91
|
+
transformInput: (data: Record<string, unknown>, defaultModelName: string, action: "create" | "update", forceAllowId?: boolean | undefined) => Promise<Record<string, unknown>>;
|
|
92
|
+
transformOutput: (data: Record<string, unknown>, defaultModelName: string, select?: string[] | undefined, joinConfig?: JoinConfig | undefined) => Promise<Record<string, unknown>>;
|
|
93
|
+
transformWhereClause: <W extends Where[] | undefined>({
|
|
94
|
+
model,
|
|
95
|
+
where,
|
|
96
|
+
action
|
|
97
|
+
}: {
|
|
98
|
+
where: W;
|
|
99
|
+
model: string;
|
|
100
|
+
action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "count";
|
|
101
|
+
}) => W extends undefined ? undefined : CleanedWhere[];
|
|
102
|
+
}) => CustomAdapter;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Use `CustomAdapter` from `@better-auth/core/db/adapter` instead.
|
|
105
|
+
*/
|
|
106
|
+
interface CustomAdapter extends Omit<CustomAdapter$1, "createSchema"> {
|
|
107
|
+
createSchema?: ((props: {
|
|
108
|
+
/**
|
|
109
|
+
* The file the user may have passed in to the `generate` command as the expected schema file output path.
|
|
110
|
+
*/
|
|
111
|
+
file?: string;
|
|
112
|
+
/**
|
|
113
|
+
* The tables from the user's Better-Auth instance schema.
|
|
114
|
+
*/
|
|
115
|
+
tables: BetterAuthDBSchema;
|
|
116
|
+
}) => Promise<DBAdapterSchemaCreation>) | undefined;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated Use `CleanedWhere` from `@better-auth/core/db/adapter` instead.
|
|
120
|
+
*/
|
|
121
|
+
type CleanedWhere = Prettify<Required<Where>>;
|
|
122
|
+
type AdapterTestDebugLogs = {
|
|
123
|
+
resetDebugLogs: () => void;
|
|
124
|
+
printDebugLogs: () => void;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated Use `AdapterFactoryOptions` instead. This export will be removed in a future version.
|
|
128
|
+
*/
|
|
129
|
+
type CreateAdapterOptions = AdapterFactoryOptions;
|
|
130
|
+
/**
|
|
131
|
+
* @deprecated Use `AdapterFactoryConfig` instead. This export will be removed in a future version.
|
|
132
|
+
*/
|
|
133
|
+
type AdapterConfig = AdapterFactoryConfig;
|
|
134
|
+
/**
|
|
135
|
+
* @deprecated Use `AdapterFactoryCustomizeAdapterCreator` instead. This export will be removed in a future version.
|
|
136
|
+
*/
|
|
137
|
+
type CreateCustomAdapter = AdapterFactoryCustomizeAdapterCreator;
|
|
138
|
+
//#endregion
|
|
139
|
+
export { AdapterConfig, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter };
|
|
140
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/db/adapter/utils.d.ts
|
|
4
|
+
declare function withApplyDefault(value: any, field: DBFieldAttribute, action: "create" | "update" | "findOne" | "findMany"): any;
|
|
5
|
+
declare function deepmerge<T>(target: T, source: Partial<T>): T;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { deepmerge, withApplyDefault };
|
|
8
|
+
//# sourceMappingURL=utils.d.mts.map
|