@better-auth/core 1.5.0-beta.2 → 1.5.0-beta.20
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/LICENSE.md +15 -12
- package/README.md +17 -0
- package/dist/api/index.d.mts +280 -2
- package/dist/api/index.mjs +4 -2
- package/dist/api/index.mjs.map +1 -0
- package/dist/async_hooks/index.d.mts +2 -1
- package/dist/async_hooks/index.mjs +2 -1
- package/dist/async_hooks/index.mjs.map +1 -0
- package/dist/async_hooks/pure.index.d.mts +2 -1
- package/dist/async_hooks/pure.index.mjs +2 -1
- package/dist/async_hooks/pure.index.mjs.map +1 -0
- package/dist/context/endpoint-context.d.mts +20 -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 -53
- package/dist/context/index.mjs +5 -2
- package/dist/context/request-state.d.mts +28 -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 +20 -0
- package/dist/db/adapter/factory.mjs +725 -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 +520 -2
- package/dist/db/adapter/index.mjs +27 -972
- package/dist/db/adapter/index.mjs.map +1 -0
- package/dist/db/adapter/types.d.mts +108 -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/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +52 -39
- package/dist/db/get-tables.mjs.map +1 -0
- package/dist/db/index.d.mts +10 -2
- package/dist/db/index.mjs +7 -60
- package/dist/db/plugin.d.mts +13 -0
- package/dist/db/schema/account.d.mts +30 -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 +20 -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 +25 -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 +24 -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 +23 -0
- package/dist/db/schema/verification.mjs +13 -0
- package/dist/db/schema/verification.mjs.map +1 -0
- package/dist/db/type.d.mts +169 -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 -2
- package/dist/env/index.mjs +3 -1
- package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +2 -35
- package/dist/env/logger.mjs +82 -0
- package/dist/env/logger.mjs.map +1 -0
- package/dist/error/codes.d.mts +69 -0
- package/dist/{error-C7mY-p0f.mjs → error/codes.mjs} +7 -30
- package/dist/error/codes.mjs.map +1 -0
- package/dist/error/index.d.mts +6 -187
- package/dist/error/index.mjs +29 -4
- package/dist/error/index.mjs.map +1 -0
- package/dist/index.d.mts +8 -2
- package/dist/oauth2/client-credentials-token.d.mts +58 -0
- package/dist/oauth2/client-credentials-token.mjs +67 -0
- package/dist/oauth2/client-credentials-token.mjs.map +1 -0
- package/dist/oauth2/create-authorization-url.d.mts +48 -0
- package/dist/oauth2/create-authorization-url.mjs +44 -0
- package/dist/oauth2/create-authorization-url.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +8 -2
- package/dist/oauth2/index.mjs +7 -3
- package/dist/oauth2/oauth-provider.d.mts +195 -0
- package/dist/oauth2/refresh-access-token.d.mts +56 -0
- package/dist/oauth2/refresh-access-token.mjs +76 -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 +88 -0
- package/dist/oauth2/validate-authorization-code.mjs +83 -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 +113 -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 +1777 -2
- package/dist/social-providers/index.mjs +37 -2570
- 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 +177 -0
- package/dist/social-providers/microsoft-entra-id.mjs +140 -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/railway.d.mts +68 -0
- package/dist/social-providers/railway.mjs +78 -0
- package/dist/social-providers/railway.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 +166 -0
- package/dist/social-providers/zoom.mjs +73 -0
- package/dist/social-providers/zoom.mjs.map +1 -0
- package/dist/types/context.d.mts +274 -0
- package/dist/types/cookie.d.mts +16 -0
- package/dist/types/helper.d.mts +11 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1298 -0
- package/dist/types/plugin-client.d.mts +113 -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/{index.d.mts → error-codes.d.mts} +9 -16
- 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 +36 -18
- package/src/context/endpoint-context.ts +7 -6
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +2 -0
- package/src/context/request-state.ts +7 -6
- package/src/context/transaction.ts +77 -14
- package/src/db/adapter/factory.ts +54 -86
- package/src/db/adapter/get-default-model-name.ts +1 -1
- package/src/db/adapter/get-id-field.ts +4 -6
- package/src/db/adapter/index.ts +20 -15
- package/src/db/adapter/types.ts +2 -41
- package/src/db/get-tables.ts +54 -37
- package/src/db/index.ts +30 -5
- package/src/db/schema/account.ts +16 -3
- package/src/db/schema/rate-limit.ts +16 -1
- package/src/db/schema/session.ts +15 -3
- package/src/db/schema/user.ts +15 -3
- package/src/db/schema/verification.ts +16 -3
- package/src/db/test/get-tables.test.ts +33 -0
- package/src/db/type.ts +154 -1
- package/src/env/env-impl.ts +2 -2
- package/src/env/logger.ts +1 -1
- package/src/error/codes.ts +18 -1
- package/src/error/index.ts +2 -3
- package/src/oauth2/client-credentials-token.ts +26 -2
- package/src/oauth2/create-authorization-url.ts +4 -2
- package/src/oauth2/index.ts +3 -0
- package/src/oauth2/oauth-provider.ts +7 -1
- package/src/oauth2/refresh-access-token.test.ts +90 -0
- package/src/oauth2/refresh-access-token.ts +37 -4
- package/src/oauth2/validate-authorization-code.ts +55 -29
- package/src/oauth2/validate-token.test.ts +229 -0
- package/src/social-providers/apple.ts +38 -29
- package/src/social-providers/cognito.ts +6 -5
- package/src/social-providers/dropbox.ts +1 -1
- package/src/social-providers/facebook.ts +3 -3
- package/src/social-providers/figma.ts +5 -3
- package/src/social-providers/github.ts +26 -4
- package/src/social-providers/gitlab.ts +2 -2
- package/src/social-providers/google.ts +18 -14
- package/src/social-providers/huggingface.ts +1 -1
- package/src/social-providers/index.ts +9 -5
- package/src/social-providers/kakao.ts +1 -1
- package/src/social-providers/line.ts +1 -1
- package/src/social-providers/microsoft-entra-id.ts +84 -1
- package/src/social-providers/naver.ts +1 -1
- package/src/social-providers/notion.ts +1 -1
- package/src/social-providers/paybin.ts +1 -5
- package/src/social-providers/polar.ts +1 -1
- package/src/social-providers/railway.ts +100 -0
- package/src/social-providers/tiktok.ts +2 -1
- package/src/social-providers/vercel.ts +1 -1
- package/src/social-providers/zoom.ts +0 -8
- package/src/types/context.ts +241 -132
- package/src/types/cookie.ts +6 -4
- package/src/types/helper.ts +9 -0
- package/src/types/index.ts +19 -2
- package/src/types/init-options.ts +301 -186
- package/src/types/plugin-client.ts +1 -0
- package/src/types/plugin.ts +11 -6
- package/src/utils/db.ts +20 -0
- package/src/utils/deprecate.test.ts +71 -0
- package/src/utils/deprecate.ts +21 -0
- package/src/utils/error-codes.ts +12 -9
- package/src/utils/ip.test.ts +255 -0
- package/src/utils/ip.ts +211 -0
- package/src/utils/url.ts +43 -0
- package/.turbo/turbo-build.log +0 -43
- package/dist/context-DblZrIwO.mjs +0 -114
- package/dist/env-DbssmzoK.mjs +0 -245
- package/dist/index-BpRqx5_q.d.mts +0 -7833
- package/dist/oauth2-BjWM15hm.mjs +0 -326
- package/dist/utils/index.mjs +0 -4
- package/dist/utils-s65Fz0OM.mjs +0 -47
- package/src/utils/index.ts +0 -4
- package/tsconfig.json +0 -7
- package/tsdown.config.ts +0 -22
- package/vitest.config.ts +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/db/adapter/index.ts"],"sourcesContent":["import type { BetterAuthOptions } from \"../../types\";\nimport type { BetterAuthDBSchema, DBFieldAttribute } from \"../type\";\n\nexport type DBAdapterDebugLogOption =\n\t| boolean\n\t| {\n\t\t\t/**\n\t\t\t * Useful when you want to log only certain conditions.\n\t\t\t */\n\t\t\tlogCondition?: (() => boolean) | undefined;\n\t\t\tcreate?: boolean | undefined;\n\t\t\tupdate?: boolean | undefined;\n\t\t\tupdateMany?: boolean | undefined;\n\t\t\tfindOne?: boolean | undefined;\n\t\t\tfindMany?: boolean | undefined;\n\t\t\tdelete?: boolean | undefined;\n\t\t\tdeleteMany?: boolean | undefined;\n\t\t\tcount?: boolean | undefined;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * Only used for adapter tests to show debug logs if a test fails.\n\t\t\t *\n\t\t\t * @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.\n\t\t\t */\n\t\t\tisRunningAdapterTests: boolean;\n\t };\n\nexport type DBAdapterSchemaCreation = {\n\t/**\n\t * Code to be inserted into the file\n\t */\n\tcode: string;\n\t/**\n\t * Path to the file, including the file name and extension.\n\t * Relative paths are supported, with the current working directory of the developer's project as the base.\n\t */\n\tpath: string;\n\t/**\n\t * Append the file if it already exists.\n\t * Note: This will not apply if `overwrite` is set to true.\n\t */\n\tappend?: boolean | undefined;\n\t/**\n\t * Overwrite the file if it already exists\n\t */\n\toverwrite?: boolean | undefined;\n};\n\nexport interface DBAdapterFactoryConfig<\n\tOptions extends BetterAuthOptions = BetterAuthOptions,\n> {\n\t/**\n\t * Use plural table names.\n\t *\n\t * All tables will be named with an `s` at the end.\n\t *\n\t * @default false\n\t */\n\tusePlural?: boolean | undefined;\n\t/**\n\t * Enable debug logs.\n\t *\n\t * @default false\n\t */\n\tdebugLogs?: DBAdapterDebugLogOption | undefined;\n\t/**\n\t * Name of the adapter.\n\t *\n\t * This is used to identify the adapter in the debug logs.\n\t *\n\t * @default `adapterId`\n\t */\n\tadapterName?: string | undefined;\n\t/**\n\t * Adapter id\n\t */\n\tadapterId: string;\n\t/**\n\t * If the database supports numeric ids, set this to `true`.\n\t *\n\t * @default true\n\t */\n\tsupportsNumericIds?: boolean | undefined;\n\t/**\n\t * If the database supports natively generating UUIDs, set this to `true`.\n\t *\n\t * @default false\n\t */\n\tsupportsUUIDs?: boolean | undefined;\n\t/**\n\t * If the database doesn't support JSON columns, set this to `false`.\n\t *\n\t * We will handle the translation between using `JSON` columns, and saving `string`s to the database.\n\t *\n\t * @default false\n\t */\n\tsupportsJSON?: boolean | undefined;\n\t/**\n\t * If the database doesn't support dates, set this to `false`.\n\t *\n\t * We will handle the translation between using `Date` objects, and saving `string`s to the database.\n\t *\n\t * @default true\n\t */\n\tsupportsDates?: boolean | undefined;\n\t/**\n\t * If the database doesn't support booleans, set this to `false`.\n\t *\n\t * We will handle the translation between using `boolean`s, and saving `0`s and `1`s to the database.\n\t *\n\t * @default true\n\t */\n\tsupportsBooleans?: boolean | undefined;\n\t/**\n\t * If the database doesn't support arrays, set this to `false`.\n\t *\n\t * We will handle the translation between using `array`s, and saving `string`s to the database.\n\t *\n\t * @default false\n\t */\n\tsupportsArrays?: boolean | undefined;\n\t/**\n\t * Execute multiple operations in a transaction.\n\t *\n\t * If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.\n\t *\n\t * @default false\n\t */\n\ttransaction?:\n\t\t| (\n\t\t\t\t| false\n\t\t\t\t| (<R>(\n\t\t\t\t\t\tcallback: (trx: DBTransactionAdapter<Options>) => Promise<R>,\n\t\t\t\t ) => Promise<R>)\n\t\t )\n\t\t| undefined;\n\t/**\n\t * Disable id generation for the `create` method.\n\t *\n\t * This is useful for databases that don't support custom id values and would auto-generate them for you.\n\t *\n\t * @default false\n\t */\n\tdisableIdGeneration?: boolean | undefined;\n\t/**\n\t * Map the keys of the input data.\n\t *\n\t * This is useful for databases that expect a different key name for a given situation.\n\t *\n\t * For example, MongoDB uses `_id` while in Better-Auth we use `id`.\n\t *\n\t *\n\t * @example\n\t * Each key represents the old key to replace.\n\t * The value represents the new key\n\t *\n\t * This can be a partial object that only transforms some keys.\n\t *\n\t * ```ts\n\t * mapKeysTransformInput: {\n\t * id: \"_id\" // We want to replace `id` to `_id` to save into MongoDB\n\t * }\n\t * ```\n\t */\n\tmapKeysTransformInput?: Record<string, string> | undefined;\n\t/**\n\t * Map the keys of the output data.\n\t *\n\t * This is useful for databases that expect a different key name for a given situation.\n\t *\n\t * For example, MongoDB uses `_id` while in Better-Auth we use `id`.\n\t *\n\t * @example\n\t * Each key represents the old key to replace.\n\t * The value represents the new key\n\t *\n\t * This can be a partial object that only transforms some keys.\n\t *\n\t * ```ts\n\t * mapKeysTransformOutput: {\n\t * _id: \"id\" // In MongoDB, we save `id` as `_id`. So we want to replace `_id` with `id` when we get the data back.\n\t * }\n\t * ```\n\t */\n\tmapKeysTransformOutput?: Record<string, string> | undefined;\n\t/**\n\t * Custom transform input function.\n\t *\n\t * This function is used to transform the input data before it is saved to the database.\n\t */\n\tcustomTransformInput?:\n\t\t| ((props: {\n\t\t\t\tdata: any;\n\t\t\t\t/**\n\t\t\t\t * The fields of the model.\n\t\t\t\t */\n\t\t\t\tfieldAttributes: DBFieldAttribute;\n\t\t\t\t/**\n\t\t\t\t * The field to transform.\n\t\t\t\t */\n\t\t\t\tfield: string;\n\t\t\t\t/**\n\t\t\t\t * The action which was called from the adapter.\n\t\t\t\t */\n\t\t\t\taction:\n\t\t\t\t\t| \"create\"\n\t\t\t\t\t| \"update\"\n\t\t\t\t\t| \"findOne\"\n\t\t\t\t\t| \"findMany\"\n\t\t\t\t\t| \"updateMany\"\n\t\t\t\t\t| \"delete\"\n\t\t\t\t\t| \"deleteMany\"\n\t\t\t\t\t| \"count\";\n\t\t\t\t/**\n\t\t\t\t * The model name.\n\t\t\t\t */\n\t\t\t\tmodel: string;\n\t\t\t\t/**\n\t\t\t\t * The schema of the user's Better-Auth instance.\n\t\t\t\t */\n\t\t\t\tschema: BetterAuthDBSchema;\n\t\t\t\t/**\n\t\t\t\t * The options of the user's Better-Auth instance.\n\t\t\t\t */\n\t\t\t\toptions: Options;\n\t\t }) => any)\n\t\t| undefined;\n\t/**\n\t * Custom transform output function.\n\t *\n\t * This function is used to transform the output data before it is returned to the user.\n\t */\n\tcustomTransformOutput?:\n\t\t| ((props: {\n\t\t\t\tdata: any;\n\t\t\t\t/**\n\t\t\t\t * The fields of the model.\n\t\t\t\t */\n\t\t\t\tfieldAttributes: DBFieldAttribute;\n\t\t\t\t/**\n\t\t\t\t * The field to transform.\n\t\t\t\t */\n\t\t\t\tfield: string;\n\t\t\t\t/**\n\t\t\t\t * The fields to select.\n\t\t\t\t */\n\t\t\t\tselect: string[];\n\t\t\t\t/**\n\t\t\t\t * The model name.\n\t\t\t\t */\n\t\t\t\tmodel: string;\n\t\t\t\t/**\n\t\t\t\t * The schema of the user's Better-Auth instance.\n\t\t\t\t */\n\t\t\t\tschema: BetterAuthDBSchema;\n\t\t\t\t/**\n\t\t\t\t * The options of the user's Better-Auth instance.\n\t\t\t\t */\n\t\t\t\toptions: Options;\n\t\t }) => any)\n\t\t| undefined;\n\t/**\n\t * Custom ID generator function.\n\t *\n\t * By default, we can handle ID generation for you, however if the database your adapter is for only supports a specific custom id generation,\n\t * then you can use this function to generate your own IDs.\n\t *\n\t *\n\t * Notes:\n\t * - 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`.\n\t * - If `generateId` is `false` in the user's Better-Auth config, then this option will be ignored.\n\t * - If `generateId` is a function, then it will override this option.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * customIdGenerator: ({ model }) => {\n\t * return \"my-super-unique-id\";\n\t * }\n\t * ```\n\t */\n\tcustomIdGenerator?: ((props: { model: string }) => string) | undefined;\n\t/**\n\t * Whether to disable the transform output.\n\t * Do not use this option unless you know what you are doing.\n\t * @default false\n\t */\n\tdisableTransformOutput?: boolean | undefined;\n\t/**\n\t * Whether to disable the transform input.\n\t * Do not use this option unless you know what you are doing.\n\t * @default false\n\t */\n\tdisableTransformInput?: boolean | undefined;\n\t/**\n\t * Whether to disable the transform join.\n\t * Do not use this option unless you know what you are doing.\n\t * @default false\n\t */\n\tdisableTransformJoin?: boolean | undefined;\n}\n\nexport const whereOperators = [\n\t\"eq\",\n\t\"ne\",\n\t\"lt\",\n\t\"lte\",\n\t\"gt\",\n\t\"gte\",\n\t\"in\",\n\t\"not_in\",\n\t\"contains\",\n\t\"starts_with\",\n\t\"ends_with\",\n] as const;\n\nexport type WhereOperator = (typeof whereOperators)[number];\n\nexport type Where = {\n\t/**\n\t * @default eq\n\t */\n\toperator?: WhereOperator | undefined;\n\tvalue: string | number | boolean | string[] | number[] | Date | null;\n\tfield: string;\n\t/**\n\t * @default AND\n\t */\n\tconnector?: (\"AND\" | \"OR\") | undefined;\n};\n\n/**\n * JoinOption configuration for relational queries.\n *\n * Allows you to join related tables/models in a single query operation.\n * Each key represents the name of the joined table/model, and the value\n * configures how the join should be performed.\n */\nexport type JoinOption = {\n\t[model: string]: boolean | { limit?: number };\n};\n\n/**\n * Once `JoinOption` has gone through the adapter factory, it will be transformed into a `JoinConfig`.\n */\nexport type JoinConfig = {\n\t[model: string]: {\n\t\t/**\n\t\t * The joining column names.\n\t\t */\n\t\ton: {\n\t\t\t/**\n\t\t\t * Column name from the main table\n\t\t\t */\n\t\t\tfrom: string;\n\t\t\t/**\n\t\t\t * Column name from the joined table\n\t\t\t */\n\t\t\tto: string;\n\t\t};\n\t\t/**\n\t\t * Limit the number of rows to return.\n\t\t *\n\t\t * If the relation has `unique` constraint, then this option will be ignored and limit will be set to 1.\n\t\t *\n\t\t * @default 100\n\t\t */\n\t\tlimit?: number;\n\t\t/**\n\t\t * The relation type. Determines the output joined model data.\n\t\t *\n\t\t * `one-to-one` would have a single object in the output.\n\t\t * `one-to-many` would have an array of objects in the output.\n\t\t * `many-to-many` would have an array of objects in the output.\n\t\t *\n\t\t * @default \"one-to-many\"\n\t\t */\n\t\trelation?: \"one-to-one\" | \"one-to-many\" | \"many-to-many\";\n\t};\n};\n\nexport type DBTransactionAdapter<\n\tOptions extends BetterAuthOptions = BetterAuthOptions,\n> = Omit<DBAdapter<Options>, \"transaction\">;\n\nexport type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {\n\tid: string;\n\tcreate: <T extends Record<string, any>, R = T>(data: {\n\t\tmodel: string;\n\t\tdata: Omit<T, \"id\">;\n\t\tselect?: string[] | undefined;\n\t\t/**\n\t\t * By default, any `id` provided in `data` will be ignored.\n\t\t *\n\t\t * If you want to force the `id` to be the same as the `data.id`, set this to `true`.\n\t\t */\n\t\tforceAllowId?: boolean | undefined;\n\t}) => Promise<R>;\n\tfindOne: <T>(data: {\n\t\tmodel: string;\n\t\twhere: Where[];\n\t\tselect?: string[] | undefined;\n\t\tjoin?: JoinOption | undefined;\n\t}) => Promise<T | null>;\n\tfindMany: <T>(data: {\n\t\tmodel: string;\n\t\twhere?: Where[] | undefined;\n\t\tlimit?: number | undefined;\n\t\tselect?: string[] | undefined;\n\t\tsortBy?:\n\t\t\t| {\n\t\t\t\t\tfield: string;\n\t\t\t\t\tdirection: \"asc\" | \"desc\";\n\t\t\t }\n\t\t\t| undefined;\n\t\toffset?: number | undefined;\n\t\tjoin?: JoinOption | undefined;\n\t}) => Promise<T[]>;\n\tcount: (data: {\n\t\tmodel: string;\n\t\twhere?: Where[] | undefined;\n\t}) => Promise<number>;\n\t/**\n\t * ⚠︎ Update may not return the updated data\n\t * if multiple where clauses are provided\n\t */\n\tupdate: <T>(data: {\n\t\tmodel: string;\n\t\twhere: Where[];\n\t\tupdate: Record<string, any>;\n\t}) => Promise<T | null>;\n\tupdateMany: (data: {\n\t\tmodel: string;\n\t\twhere: Where[];\n\t\tupdate: Record<string, any>;\n\t}) => Promise<number>;\n\tdelete: <_T>(data: { model: string; where: Where[] }) => Promise<void>;\n\tdeleteMany: (data: { model: string; where: Where[] }) => Promise<number>;\n\t/**\n\t * Execute multiple operations in a transaction.\n\t * If the adapter doesn't support transactions, operations will be executed sequentially.\n\t */\n\ttransaction: <R>(\n\t\tcallback: (trx: DBTransactionAdapter<Options>) => Promise<R>,\n\t) => Promise<R>;\n\t/**\n\t *\n\t * @param options\n\t * @param file - file path if provided by the user\n\t */\n\tcreateSchema?:\n\t\t| ((options: Options, file?: string) => Promise<DBAdapterSchemaCreation>)\n\t\t| undefined;\n\toptions?:\n\t\t| ({\n\t\t\t\tadapterConfig: DBAdapterFactoryConfig<Options>;\n\t\t } & CustomAdapter[\"options\"])\n\t\t| undefined;\n};\n\nexport type CleanedWhere = Required<Where>;\n\nexport interface CustomAdapter {\n\tcreate: <T extends Record<string, any>>({\n\t\tdata,\n\t\tmodel,\n\t\tselect,\n\t}: {\n\t\tmodel: string;\n\t\tdata: T;\n\t\tselect?: string[] | undefined;\n\t}) => Promise<T>;\n\tupdate: <T>(data: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t\tupdate: T;\n\t}) => Promise<T | null>;\n\tupdateMany: (data: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t\tupdate: Record<string, any>;\n\t}) => Promise<number>;\n\tfindOne: <T>({\n\t\tmodel,\n\t\twhere,\n\t\tselect,\n\t\tjoin,\n\t}: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t\tselect?: string[] | undefined;\n\t\tjoin?: JoinConfig | undefined;\n\t}) => Promise<T | null>;\n\tfindMany: <T>({\n\t\tmodel,\n\t\twhere,\n\t\tlimit,\n\t\tselect,\n\t\tsortBy,\n\t\toffset,\n\t\tjoin,\n\t}: {\n\t\tmodel: string;\n\t\twhere?: CleanedWhere[] | undefined;\n\t\tlimit: number;\n\t\tselect?: string[] | undefined;\n\t\tsortBy?: { field: string; direction: \"asc\" | \"desc\" } | undefined;\n\t\toffset?: number | undefined;\n\t\tjoin?: JoinConfig | undefined;\n\t}) => Promise<T[]>;\n\tdelete: ({\n\t\tmodel,\n\t\twhere,\n\t}: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t}) => Promise<void>;\n\tdeleteMany: ({\n\t\tmodel,\n\t\twhere,\n\t}: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t}) => Promise<number>;\n\tcount: ({\n\t\tmodel,\n\t\twhere,\n\t}: {\n\t\tmodel: string;\n\t\twhere?: CleanedWhere[] | undefined;\n\t}) => Promise<number>;\n\tcreateSchema?:\n\t\t| ((props: {\n\t\t\t\t/**\n\t\t\t\t * The file the user may have passed in to the `generate` command as the expected schema file output path.\n\t\t\t\t */\n\t\t\t\tfile?: string;\n\t\t\t\t/**\n\t\t\t\t * The tables from the user's Better-Auth instance schema.\n\t\t\t\t */\n\t\t\t\ttables: BetterAuthDBSchema;\n\t\t }) => Promise<DBAdapterSchemaCreation>)\n\t\t| undefined;\n\t/**\n\t * Your adapter's options.\n\t */\n\toptions?: Record<string, any> | undefined;\n}\n\nexport interface DBAdapterInstance<\n\tOptions extends BetterAuthOptions = BetterAuthOptions,\n> {\n\t(options: BetterAuthOptions): DBAdapter<Options>;\n}\n\nexport * from \"./factory\";\nexport * from \"./types\";\nexport * from \"./utils\";\n"],"mappings":";;;;;;;;;;AA+SA,MAAa,iBAAiB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
import { CleanedWhere, CustomAdapter, DBAdapterFactoryConfig, DBTransactionAdapter, JoinConfig, Where } from "./index.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
import "../../types/index.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/db/adapter/types.d.ts
|
|
7
|
+
type AdapterFactoryOptions = {
|
|
8
|
+
config: AdapterFactoryConfig;
|
|
9
|
+
adapter: AdapterFactoryCustomizeAdapterCreator;
|
|
10
|
+
};
|
|
11
|
+
interface AdapterFactoryConfig extends Omit<DBAdapterFactoryConfig<BetterAuthOptions>, "transaction"> {
|
|
12
|
+
/**
|
|
13
|
+
* Execute multiple operations in a transaction.
|
|
14
|
+
*
|
|
15
|
+
* If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
transaction?: (false | (<R>(callback: (trx: DBTransactionAdapter) => Promise<R>) => Promise<R>)) | undefined;
|
|
20
|
+
}
|
|
21
|
+
type AdapterFactoryCustomizeAdapterCreator = (config: {
|
|
22
|
+
options: BetterAuthOptions;
|
|
23
|
+
/**
|
|
24
|
+
* The schema of the user's Better-Auth instance.
|
|
25
|
+
*/
|
|
26
|
+
schema: BetterAuthDBSchema;
|
|
27
|
+
/**
|
|
28
|
+
* The debug log function.
|
|
29
|
+
*
|
|
30
|
+
* If the config has defined `debugLogs` as `false`, no logs will be shown.
|
|
31
|
+
*/
|
|
32
|
+
debugLog: (...args: unknown[]) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Get the model name which is expected to be saved in the database based on the user's schema.
|
|
35
|
+
*/
|
|
36
|
+
getModelName: (model: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
39
|
+
*/
|
|
40
|
+
getFieldName: ({
|
|
41
|
+
model,
|
|
42
|
+
field
|
|
43
|
+
}: {
|
|
44
|
+
model: string;
|
|
45
|
+
field: string;
|
|
46
|
+
}) => string;
|
|
47
|
+
/**
|
|
48
|
+
* This function helps us get the default model name from the schema defined by devs.
|
|
49
|
+
* Often times, the user will be using the `modelName` which could had been customized by the users.
|
|
50
|
+
* This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
|
|
51
|
+
*
|
|
52
|
+
* If it's still unclear what this does:
|
|
53
|
+
*
|
|
54
|
+
* 1. User can define a custom modelName.
|
|
55
|
+
* 2. When using a custom modelName, doing something like `schema[model]` will not work.
|
|
56
|
+
* 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
|
|
57
|
+
* 4. Thus allowing us to use `schema[model]`.
|
|
58
|
+
*/
|
|
59
|
+
getDefaultModelName: (model: string) => string;
|
|
60
|
+
/**
|
|
61
|
+
* This function helps us get the default field name from the schema defined by devs.
|
|
62
|
+
* Often times, the user will be using the `fieldName` which could had been customized by the users.
|
|
63
|
+
* This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
|
|
64
|
+
*
|
|
65
|
+
* If it's still unclear what this does:
|
|
66
|
+
*
|
|
67
|
+
* 1. User can define a custom fieldName.
|
|
68
|
+
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
getDefaultFieldName: ({
|
|
72
|
+
model,
|
|
73
|
+
field
|
|
74
|
+
}: {
|
|
75
|
+
model: string;
|
|
76
|
+
field: string;
|
|
77
|
+
}) => string;
|
|
78
|
+
/**
|
|
79
|
+
* Get the field attributes for a given model and field.
|
|
80
|
+
*
|
|
81
|
+
* Note: any model name or field name is allowed, whether default to schema or not.
|
|
82
|
+
*/
|
|
83
|
+
getFieldAttributes: ({
|
|
84
|
+
model,
|
|
85
|
+
field
|
|
86
|
+
}: {
|
|
87
|
+
model: string;
|
|
88
|
+
field: string;
|
|
89
|
+
}) => DBFieldAttribute;
|
|
90
|
+
transformInput: (data: Record<string, unknown>, defaultModelName: string, action: "create" | "update", forceAllowId?: boolean | undefined) => Promise<Record<string, unknown>>;
|
|
91
|
+
transformOutput: (data: Record<string, unknown>, defaultModelName: string, select?: string[] | undefined, joinConfig?: JoinConfig | undefined) => Promise<Record<string, unknown>>;
|
|
92
|
+
transformWhereClause: <W extends Where[] | undefined>({
|
|
93
|
+
model,
|
|
94
|
+
where,
|
|
95
|
+
action
|
|
96
|
+
}: {
|
|
97
|
+
where: W;
|
|
98
|
+
model: string;
|
|
99
|
+
action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "count";
|
|
100
|
+
}) => W extends undefined ? undefined : CleanedWhere[];
|
|
101
|
+
}) => CustomAdapter;
|
|
102
|
+
type AdapterTestDebugLogs = {
|
|
103
|
+
resetDebugLogs: () => void;
|
|
104
|
+
printDebugLogs: () => void;
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
export { AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs };
|
|
108
|
+
//# 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
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/db/adapter/utils.ts
|
|
2
|
+
function withApplyDefault(value, field, action) {
|
|
3
|
+
if (action === "update") {
|
|
4
|
+
if (value === void 0 && field.onUpdate !== void 0) {
|
|
5
|
+
if (typeof field.onUpdate === "function") return field.onUpdate();
|
|
6
|
+
return field.onUpdate;
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
if (action === "create") {
|
|
11
|
+
if (value === void 0 || field.required === true && value === null) {
|
|
12
|
+
if (field.defaultValue !== void 0) {
|
|
13
|
+
if (typeof field.defaultValue === "function") return field.defaultValue();
|
|
14
|
+
return field.defaultValue;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function isObject(item) {
|
|
21
|
+
return item !== null && typeof item === "object" && !Array.isArray(item);
|
|
22
|
+
}
|
|
23
|
+
function deepmerge(target, source) {
|
|
24
|
+
if (Array.isArray(target) && Array.isArray(source)) return [...target, ...source];
|
|
25
|
+
else if (isObject(target) && isObject(source)) {
|
|
26
|
+
const result = { ...target };
|
|
27
|
+
for (const [key, value] of Object.entries(source)) {
|
|
28
|
+
if (value === void 0) continue;
|
|
29
|
+
if (key in target) result[key] = deepmerge(target[key], value);
|
|
30
|
+
else result[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
return source;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { deepmerge, withApplyDefault };
|
|
39
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/db/adapter/utils.ts"],"sourcesContent":["import type { DBFieldAttribute } from \"../type\";\n\nexport function withApplyDefault(\n\tvalue: any,\n\tfield: DBFieldAttribute,\n\taction: \"create\" | \"update\" | \"findOne\" | \"findMany\",\n) {\n\tif (action === \"update\") {\n\t\t// Apply onUpdate if value is undefined\n\t\tif (value === undefined && field.onUpdate !== undefined) {\n\t\t\tif (typeof field.onUpdate === \"function\") {\n\t\t\t\treturn field.onUpdate();\n\t\t\t}\n\t\t\treturn field.onUpdate;\n\t\t}\n\t\treturn value;\n\t}\n\tif (action === \"create\") {\n\t\t// we do not want to apply default values if the value is null & not required\n\t\tif (value === undefined || (field.required === true && value === null)) {\n\t\t\tif (field.defaultValue !== undefined) {\n\t\t\t\tif (typeof field.defaultValue === \"function\") {\n\t\t\t\t\treturn field.defaultValue();\n\t\t\t\t}\n\t\t\t\treturn field.defaultValue;\n\t\t\t}\n\t\t}\n\t}\n\treturn value;\n}\n\nfunction isObject(item: unknown): item is Record<string, unknown> {\n\treturn item !== null && typeof item === \"object\" && !Array.isArray(item);\n}\n\nexport function deepmerge<T>(target: T, source: Partial<T>): T {\n\tif (Array.isArray(target) && Array.isArray(source)) {\n\t\t// merge arrays by concatenation\n\t\treturn [...target, ...source] as T;\n\t} else if (isObject(target) && isObject(source)) {\n\t\tconst result: Record<string, unknown> = { ...target };\n\n\t\tfor (const [key, value] of Object.entries(source)) {\n\t\t\tif (value === undefined) continue; // skip undefined\n\n\t\t\tif (key in target) {\n\t\t\t\tresult[key] = deepmerge(\n\t\t\t\t\t(target as Record<string, unknown>)[key],\n\t\t\t\t\tvalue as unknown as Partial<T>,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tresult[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn result as T;\n\t}\n\n\t// primitives and fallback: source overrides target\n\treturn source as T;\n}\n"],"mappings":";AAEA,SAAgB,iBACf,OACA,OACA,QACC;AACD,KAAI,WAAW,UAAU;AAExB,MAAI,UAAU,UAAa,MAAM,aAAa,QAAW;AACxD,OAAI,OAAO,MAAM,aAAa,WAC7B,QAAO,MAAM,UAAU;AAExB,UAAO,MAAM;;AAEd,SAAO;;AAER,KAAI,WAAW,UAEd;MAAI,UAAU,UAAc,MAAM,aAAa,QAAQ,UAAU,MAChE;OAAI,MAAM,iBAAiB,QAAW;AACrC,QAAI,OAAO,MAAM,iBAAiB,WACjC,QAAO,MAAM,cAAc;AAE5B,WAAO,MAAM;;;;AAIhB,QAAO;;AAGR,SAAS,SAAS,MAAgD;AACjE,QAAO,SAAS,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,KAAK;;AAGzE,SAAgB,UAAa,QAAW,QAAuB;AAC9D,KAAI,MAAM,QAAQ,OAAO,IAAI,MAAM,QAAQ,OAAO,CAEjD,QAAO,CAAC,GAAG,QAAQ,GAAG,OAAO;UACnB,SAAS,OAAO,IAAI,SAAS,OAAO,EAAE;EAChD,MAAM,SAAkC,EAAE,GAAG,QAAQ;AAErD,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,EAAE;AAClD,OAAI,UAAU,OAAW;AAEzB,OAAI,OAAO,OACV,QAAO,OAAO,UACZ,OAAmC,MACpC,MACA;OAED,QAAO,OAAO;;AAIhB,SAAO;;AAIR,QAAO"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BetterAuthDBSchema } from "./type.mjs";
|
|
2
|
+
import { BetterAuthOptions } from "../types/init-options.mjs";
|
|
3
|
+
import "../types/index.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/db/get-tables.d.ts
|
|
6
|
+
declare const getAuthTables: (options: BetterAuthOptions) => BetterAuthDBSchema;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getAuthTables };
|
|
9
|
+
//# sourceMappingURL=get-tables.d.mts.map
|
|
@@ -18,20 +18,62 @@ const getAuthTables = (options) => {
|
|
|
18
18
|
fields: {
|
|
19
19
|
key: {
|
|
20
20
|
type: "string",
|
|
21
|
+
unique: true,
|
|
22
|
+
required: true,
|
|
21
23
|
fieldName: options.rateLimit?.fields?.key || "key"
|
|
22
24
|
},
|
|
23
25
|
count: {
|
|
24
26
|
type: "number",
|
|
27
|
+
required: true,
|
|
25
28
|
fieldName: options.rateLimit?.fields?.count || "count"
|
|
26
29
|
},
|
|
27
30
|
lastRequest: {
|
|
28
31
|
type: "number",
|
|
29
32
|
bigint: true,
|
|
30
|
-
|
|
33
|
+
required: true,
|
|
34
|
+
fieldName: options.rateLimit?.fields?.lastRequest || "lastRequest",
|
|
35
|
+
defaultValue: () => Date.now()
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
} };
|
|
34
39
|
const { user, session, account, verification, ...pluginTables } = pluginSchema;
|
|
40
|
+
const verificationTable = { verification: {
|
|
41
|
+
modelName: options.verification?.modelName || "verification",
|
|
42
|
+
fields: {
|
|
43
|
+
identifier: {
|
|
44
|
+
type: "string",
|
|
45
|
+
required: true,
|
|
46
|
+
fieldName: options.verification?.fields?.identifier || "identifier",
|
|
47
|
+
index: true
|
|
48
|
+
},
|
|
49
|
+
value: {
|
|
50
|
+
type: "string",
|
|
51
|
+
required: true,
|
|
52
|
+
fieldName: options.verification?.fields?.value || "value"
|
|
53
|
+
},
|
|
54
|
+
expiresAt: {
|
|
55
|
+
type: "date",
|
|
56
|
+
required: true,
|
|
57
|
+
fieldName: options.verification?.fields?.expiresAt || "expiresAt"
|
|
58
|
+
},
|
|
59
|
+
createdAt: {
|
|
60
|
+
type: "date",
|
|
61
|
+
required: true,
|
|
62
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
63
|
+
fieldName: options.verification?.fields?.createdAt || "createdAt"
|
|
64
|
+
},
|
|
65
|
+
updatedAt: {
|
|
66
|
+
type: "date",
|
|
67
|
+
required: true,
|
|
68
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
69
|
+
onUpdate: () => /* @__PURE__ */ new Date(),
|
|
70
|
+
fieldName: options.verification?.fields?.updatedAt || "updatedAt"
|
|
71
|
+
},
|
|
72
|
+
...verification?.fields,
|
|
73
|
+
...options.verification?.additionalFields
|
|
74
|
+
},
|
|
75
|
+
order: 4
|
|
76
|
+
} };
|
|
35
77
|
const sessionTable = { session: {
|
|
36
78
|
modelName: options.session?.modelName || "session",
|
|
37
79
|
fields: {
|
|
@@ -159,26 +201,31 @@ const getAuthTables = (options) => {
|
|
|
159
201
|
accessToken: {
|
|
160
202
|
type: "string",
|
|
161
203
|
required: false,
|
|
204
|
+
returned: false,
|
|
162
205
|
fieldName: options.account?.fields?.accessToken || "accessToken"
|
|
163
206
|
},
|
|
164
207
|
refreshToken: {
|
|
165
208
|
type: "string",
|
|
166
209
|
required: false,
|
|
210
|
+
returned: false,
|
|
167
211
|
fieldName: options.account?.fields?.refreshToken || "refreshToken"
|
|
168
212
|
},
|
|
169
213
|
idToken: {
|
|
170
214
|
type: "string",
|
|
171
215
|
required: false,
|
|
216
|
+
returned: false,
|
|
172
217
|
fieldName: options.account?.fields?.idToken || "idToken"
|
|
173
218
|
},
|
|
174
219
|
accessTokenExpiresAt: {
|
|
175
220
|
type: "date",
|
|
176
221
|
required: false,
|
|
222
|
+
returned: false,
|
|
177
223
|
fieldName: options.account?.fields?.accessTokenExpiresAt || "accessTokenExpiresAt"
|
|
178
224
|
},
|
|
179
225
|
refreshTokenExpiresAt: {
|
|
180
226
|
type: "date",
|
|
181
227
|
required: false,
|
|
228
|
+
returned: false,
|
|
182
229
|
fieldName: options.account?.fields?.refreshTokenExpiresAt || "refreshTokenExpiresAt"
|
|
183
230
|
},
|
|
184
231
|
scope: {
|
|
@@ -189,6 +236,7 @@ const getAuthTables = (options) => {
|
|
|
189
236
|
password: {
|
|
190
237
|
type: "string",
|
|
191
238
|
required: false,
|
|
239
|
+
returned: false,
|
|
192
240
|
fieldName: options.account?.fields?.password || "password"
|
|
193
241
|
},
|
|
194
242
|
createdAt: {
|
|
@@ -208,47 +256,12 @@ const getAuthTables = (options) => {
|
|
|
208
256
|
},
|
|
209
257
|
order: 3
|
|
210
258
|
},
|
|
211
|
-
verification: {
|
|
212
|
-
modelName: options.verification?.modelName || "verification",
|
|
213
|
-
fields: {
|
|
214
|
-
identifier: {
|
|
215
|
-
type: "string",
|
|
216
|
-
required: true,
|
|
217
|
-
fieldName: options.verification?.fields?.identifier || "identifier",
|
|
218
|
-
index: true
|
|
219
|
-
},
|
|
220
|
-
value: {
|
|
221
|
-
type: "string",
|
|
222
|
-
required: true,
|
|
223
|
-
fieldName: options.verification?.fields?.value || "value"
|
|
224
|
-
},
|
|
225
|
-
expiresAt: {
|
|
226
|
-
type: "date",
|
|
227
|
-
required: true,
|
|
228
|
-
fieldName: options.verification?.fields?.expiresAt || "expiresAt"
|
|
229
|
-
},
|
|
230
|
-
createdAt: {
|
|
231
|
-
type: "date",
|
|
232
|
-
required: true,
|
|
233
|
-
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
234
|
-
fieldName: options.verification?.fields?.createdAt || "createdAt"
|
|
235
|
-
},
|
|
236
|
-
updatedAt: {
|
|
237
|
-
type: "date",
|
|
238
|
-
required: true,
|
|
239
|
-
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
240
|
-
onUpdate: () => /* @__PURE__ */ new Date(),
|
|
241
|
-
fieldName: options.verification?.fields?.updatedAt || "updatedAt"
|
|
242
|
-
},
|
|
243
|
-
...verification?.fields,
|
|
244
|
-
...options.verification?.additionalFields
|
|
245
|
-
},
|
|
246
|
-
order: 4
|
|
247
|
-
},
|
|
259
|
+
...!options.secondaryStorage || options.verification?.storeInDatabase ? verificationTable : {},
|
|
248
260
|
...pluginTables,
|
|
249
261
|
...shouldAddRateLimitTable ? rateLimitTable : {}
|
|
250
262
|
};
|
|
251
263
|
};
|
|
252
264
|
|
|
253
265
|
//#endregion
|
|
254
|
-
export { getAuthTables
|
|
266
|
+
export { getAuthTables };
|
|
267
|
+
//# sourceMappingURL=get-tables.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-tables.mjs","names":[],"sources":["../../src/db/get-tables.ts"],"sourcesContent":["import type { BetterAuthOptions } from \"../types\";\nimport type { BetterAuthDBSchema, DBFieldAttribute } from \"./type\";\n\nexport const getAuthTables = (\n\toptions: BetterAuthOptions,\n): BetterAuthDBSchema => {\n\tconst pluginSchema = (options.plugins ?? []).reduce(\n\t\t(acc, plugin) => {\n\t\t\tconst schema = plugin.schema;\n\t\t\tif (!schema) return acc;\n\t\t\tfor (const [key, value] of Object.entries(schema)) {\n\t\t\t\tacc[key] = {\n\t\t\t\t\tfields: {\n\t\t\t\t\t\t...acc[key]?.fields,\n\t\t\t\t\t\t...value.fields,\n\t\t\t\t\t},\n\t\t\t\t\tmodelName: value.modelName || key,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<\n\t\t\tstring,\n\t\t\t{ fields: Record<string, DBFieldAttribute>; modelName: string }\n\t\t>,\n\t);\n\n\tconst shouldAddRateLimitTable = options.rateLimit?.storage === \"database\";\n\tconst rateLimitTable = {\n\t\trateLimit: {\n\t\t\tmodelName: options.rateLimit?.modelName || \"rateLimit\",\n\t\t\tfields: {\n\t\t\t\tkey: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tunique: true,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.rateLimit?.fields?.key || \"key\",\n\t\t\t\t},\n\t\t\t\tcount: {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.rateLimit?.fields?.count || \"count\",\n\t\t\t\t},\n\t\t\t\tlastRequest: {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tbigint: true,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.rateLimit?.fields?.lastRequest || \"lastRequest\",\n\t\t\t\t\tdefaultValue: () => Date.now(),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t} satisfies BetterAuthDBSchema;\n\n\tconst { user, session, account, verification, ...pluginTables } =\n\t\tpluginSchema;\n\n\tconst verificationTable = {\n\t\tverification: {\n\t\t\tmodelName: options.verification?.modelName || \"verification\",\n\t\t\tfields: {\n\t\t\t\tidentifier: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.verification?.fields?.identifier || \"identifier\",\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.verification?.fields?.value || \"value\",\n\t\t\t\t},\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.verification?.fields?.expiresAt || \"expiresAt\",\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\tfieldName: options.verification?.fields?.createdAt || \"createdAt\",\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t\tfieldName: options.verification?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t},\n\t\t\t\t...verification?.fields,\n\t\t\t\t...options.verification?.additionalFields,\n\t\t\t},\n\t\t\torder: 4,\n\t\t},\n\t} satisfies BetterAuthDBSchema;\n\n\tconst sessionTable = {\n\t\tsession: {\n\t\t\tmodelName: options.session?.modelName || \"session\",\n\t\t\tfields: {\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.expiresAt || \"expiresAt\",\n\t\t\t\t},\n\t\t\t\ttoken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.token || \"token\",\n\t\t\t\t\tunique: true,\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.createdAt || \"createdAt\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t},\n\t\t\t\tipAddress: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.session?.fields?.ipAddress || \"ipAddress\",\n\t\t\t\t},\n\t\t\t\tuserAgent: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.session?.fields?.userAgent || \"userAgent\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tfieldName: options.session?.fields?.userId || \"userId\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: options.user?.modelName || \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t\trequired: true,\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t\t...session?.fields,\n\t\t\t\t...options.session?.additionalFields,\n\t\t\t},\n\t\t\torder: 2,\n\t\t},\n\t} satisfies BetterAuthDBSchema;\n\n\treturn {\n\t\tuser: {\n\t\t\tmodelName: options.user?.modelName || \"user\",\n\t\t\tfields: {\n\t\t\t\tname: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.name || \"name\",\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\temail: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tunique: true,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.email || \"email\",\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\temailVerified: {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdefaultValue: false,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.emailVerified || \"emailVerified\",\n\t\t\t\t\tinput: false,\n\t\t\t\t},\n\t\t\t\timage: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.user?.fields?.image || \"image\",\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.createdAt || \"createdAt\",\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t},\n\t\t\t\t...user?.fields,\n\t\t\t\t...options.user?.additionalFields,\n\t\t\t},\n\t\t\torder: 1,\n\t\t},\n\t\t//only add session table if it's not stored in secondary storage\n\t\t...(!options.secondaryStorage || options.session?.storeSessionInDatabase\n\t\t\t? sessionTable\n\t\t\t: {}),\n\t\taccount: {\n\t\t\tmodelName: options.account?.modelName || \"account\",\n\t\t\tfields: {\n\t\t\t\taccountId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.accountId || \"accountId\",\n\t\t\t\t},\n\t\t\t\tproviderId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.providerId || \"providerId\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: options.user?.modelName || \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.userId || \"userId\",\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t\taccessToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.accessToken || \"accessToken\",\n\t\t\t\t},\n\t\t\t\trefreshToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.refreshToken || \"refreshToken\",\n\t\t\t\t},\n\t\t\t\tidToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.idToken || \"idToken\",\n\t\t\t\t},\n\t\t\t\taccessTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName:\n\t\t\t\t\t\toptions.account?.fields?.accessTokenExpiresAt ||\n\t\t\t\t\t\t\"accessTokenExpiresAt\",\n\t\t\t\t},\n\t\t\t\trefreshTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName:\n\t\t\t\t\t\toptions.account?.fields?.refreshTokenExpiresAt ||\n\t\t\t\t\t\t\"refreshTokenExpiresAt\",\n\t\t\t\t},\n\t\t\t\tscope: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.account?.fields?.scope || \"scope\",\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.password || \"password\",\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.createdAt || \"createdAt\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t},\n\t\t\t\t...account?.fields,\n\t\t\t\t...options.account?.additionalFields,\n\t\t\t},\n\t\t\torder: 3,\n\t\t},\n\t\t...(!options.secondaryStorage || options.verification?.storeInDatabase\n\t\t\t? verificationTable\n\t\t\t: {}),\n\t\t...pluginTables,\n\t\t...(shouldAddRateLimitTable ? rateLimitTable : {}),\n\t} satisfies BetterAuthDBSchema;\n};\n"],"mappings":"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"}
|
package/dist/db/index.d.mts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BaseModelNames, BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, InferDBFieldInput, InferDBFieldOutput, InferDBFieldsFromOptions, InferDBFieldsFromOptionsInput, InferDBFieldsFromPlugins, InferDBFieldsFromPluginsInput, InferDBFieldsInput, InferDBFieldsOutput, InferDBValueType, ModelNames, SecondaryStorage } from "./type.mjs";
|
|
2
|
+
import { getAuthTables } from "./get-tables.mjs";
|
|
3
|
+
import { BetterAuthPluginDBSchema } from "./plugin.mjs";
|
|
4
|
+
import { BaseRateLimit, RateLimit, rateLimitSchema } from "./schema/rate-limit.mjs";
|
|
5
|
+
import { BaseSession, Session, sessionSchema } from "./schema/session.mjs";
|
|
6
|
+
import { BaseUser, User, userSchema } from "./schema/user.mjs";
|
|
7
|
+
import { BaseVerification, Verification, verificationSchema } from "./schema/verification.mjs";
|
|
8
|
+
import { Account, BaseAccount, accountSchema } from "./schema/account.mjs";
|
|
9
|
+
import { coreSchema } from "./schema/shared.mjs";
|
|
10
|
+
export { type Account, type BaseAccount, type BaseModelNames, type BaseRateLimit, type BaseSession, type BaseUser, type BaseVerification, type BetterAuthDBSchema, type BetterAuthPluginDBSchema, type DBFieldAttribute, type DBFieldAttributeConfig, type DBFieldType, type DBPrimitive, type InferDBFieldInput, type InferDBFieldOutput, type InferDBFieldsFromOptions, type InferDBFieldsFromOptionsInput, type InferDBFieldsFromPlugins, type InferDBFieldsFromPluginsInput, type InferDBFieldsInput, type InferDBFieldsOutput, type InferDBValueType, type ModelNames, type RateLimit, type SecondaryStorage, type Session, type User, type Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
|
package/dist/db/index.mjs
CHANGED
|
@@ -1,62 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { getAuthTables } from "./get-tables.mjs";
|
|
2
|
+
import { coreSchema } from "./schema/shared.mjs";
|
|
3
|
+
import { accountSchema } from "./schema/account.mjs";
|
|
4
|
+
import { rateLimitSchema } from "./schema/rate-limit.mjs";
|
|
5
|
+
import { sessionSchema } from "./schema/session.mjs";
|
|
6
|
+
import { userSchema } from "./schema/user.mjs";
|
|
7
|
+
import { verificationSchema } from "./schema/verification.mjs";
|
|
3
8
|
|
|
4
|
-
//#region src/db/schema/shared.ts
|
|
5
|
-
const coreSchema = z.object({
|
|
6
|
-
id: z.string(),
|
|
7
|
-
createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
|
|
8
|
-
updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/db/schema/account.ts
|
|
13
|
-
const accountSchema = coreSchema.extend({
|
|
14
|
-
providerId: z.string(),
|
|
15
|
-
accountId: z.string(),
|
|
16
|
-
userId: z.coerce.string(),
|
|
17
|
-
accessToken: z.string().nullish(),
|
|
18
|
-
refreshToken: z.string().nullish(),
|
|
19
|
-
idToken: z.string().nullish(),
|
|
20
|
-
accessTokenExpiresAt: z.date().nullish(),
|
|
21
|
-
refreshTokenExpiresAt: z.date().nullish(),
|
|
22
|
-
scope: z.string().nullish(),
|
|
23
|
-
password: z.string().nullish()
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/db/schema/rate-limit.ts
|
|
28
|
-
const rateLimitSchema = z.object({
|
|
29
|
-
key: z.string(),
|
|
30
|
-
count: z.number(),
|
|
31
|
-
lastRequest: z.number()
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/db/schema/session.ts
|
|
36
|
-
const sessionSchema = coreSchema.extend({
|
|
37
|
-
userId: z.coerce.string(),
|
|
38
|
-
expiresAt: z.date(),
|
|
39
|
-
token: z.string(),
|
|
40
|
-
ipAddress: z.string().nullish(),
|
|
41
|
-
userAgent: z.string().nullish()
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/db/schema/user.ts
|
|
46
|
-
const userSchema = coreSchema.extend({
|
|
47
|
-
email: z.string().transform((val) => val.toLowerCase()),
|
|
48
|
-
emailVerified: z.boolean().default(false),
|
|
49
|
-
name: z.string(),
|
|
50
|
-
image: z.string().nullish()
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/db/schema/verification.ts
|
|
55
|
-
const verificationSchema = coreSchema.extend({
|
|
56
|
-
value: z.string(),
|
|
57
|
-
expiresAt: z.date(),
|
|
58
|
-
identifier: z.string()
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
9
|
export { accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DBFieldAttribute } from "./type.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/db/plugin.d.ts
|
|
4
|
+
type BetterAuthPluginDBSchema = { [table in string]: {
|
|
5
|
+
fields: {
|
|
6
|
+
[field: string]: DBFieldAttribute;
|
|
7
|
+
};
|
|
8
|
+
disableMigration?: boolean | undefined;
|
|
9
|
+
modelName?: string | undefined;
|
|
10
|
+
} };
|
|
11
|
+
//#endregion
|
|
12
|
+
export { BetterAuthPluginDBSchema };
|
|
13
|
+
//# sourceMappingURL=plugin.d.mts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
import "../../types/index.mjs";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/db/schema/account.d.ts
|
|
8
|
+
declare const accountSchema: z.ZodObject<{
|
|
9
|
+
id: z.ZodString;
|
|
10
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
11
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
12
|
+
providerId: z.ZodString;
|
|
13
|
+
accountId: z.ZodString;
|
|
14
|
+
userId: z.ZodCoercedString<unknown>;
|
|
15
|
+
accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
|
+
refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
18
|
+
accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
19
|
+
refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
20
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
type BaseAccount = z.infer<typeof accountSchema>;
|
|
24
|
+
/**
|
|
25
|
+
* Account schema type used by better-auth, note that it's possible that account could have additional fields
|
|
26
|
+
*/
|
|
27
|
+
type Account<DBOptions extends BetterAuthOptions["account"] = BetterAuthOptions["account"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify<BaseAccount & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"account", Plugins>>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Account, BaseAccount, accountSchema };
|
|
30
|
+
//# sourceMappingURL=account.d.mts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/db/schema/account.ts
|
|
5
|
+
const accountSchema = coreSchema.extend({
|
|
6
|
+
providerId: z.string(),
|
|
7
|
+
accountId: z.string(),
|
|
8
|
+
userId: z.coerce.string(),
|
|
9
|
+
accessToken: z.string().nullish(),
|
|
10
|
+
refreshToken: z.string().nullish(),
|
|
11
|
+
idToken: z.string().nullish(),
|
|
12
|
+
accessTokenExpiresAt: z.date().nullish(),
|
|
13
|
+
refreshTokenExpiresAt: z.date().nullish(),
|
|
14
|
+
scope: z.string().nullish(),
|
|
15
|
+
password: z.string().nullish()
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { accountSchema };
|
|
20
|
+
//# sourceMappingURL=account.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.mjs","names":[],"sources":["../../../src/db/schema/account.ts"],"sourcesContent":["import * as z from \"zod\";\nimport type { Prettify } from \"../../types\";\nimport type { BetterAuthOptions } from \"../../types/init-options\";\nimport type {\n\tInferDBFieldsFromOptions,\n\tInferDBFieldsFromPlugins,\n} from \"../type\";\nimport { coreSchema } from \"./shared\";\n\nexport const accountSchema = coreSchema.extend({\n\tproviderId: z.string(),\n\taccountId: z.string(),\n\tuserId: z.coerce.string(),\n\taccessToken: z.string().nullish(),\n\trefreshToken: z.string().nullish(),\n\tidToken: z.string().nullish(),\n\t/**\n\t * Access token expires at\n\t */\n\taccessTokenExpiresAt: z.date().nullish(),\n\t/**\n\t * Refresh token expires at\n\t */\n\trefreshTokenExpiresAt: z.date().nullish(),\n\t/**\n\t * The scopes that the user has authorized\n\t */\n\tscope: z.string().nullish(),\n\t/**\n\t * Password is only stored in the credential provider\n\t */\n\tpassword: z.string().nullish(),\n});\n\nexport type BaseAccount = z.infer<typeof accountSchema>;\n\n/**\n * Account schema type used by better-auth, note that it's possible that account could have additional fields\n */\nexport type Account<\n\tDBOptions extends BetterAuthOptions[\"account\"] = BetterAuthOptions[\"account\"],\n\tPlugins extends BetterAuthOptions[\"plugins\"] = BetterAuthOptions[\"plugins\"],\n> = Prettify<\n\tBaseAccount &\n\t\tInferDBFieldsFromOptions<DBOptions> &\n\t\tInferDBFieldsFromPlugins<\"account\", Plugins>\n>;\n"],"mappings":";;;;AASA,MAAa,gBAAgB,WAAW,OAAO;CAC9C,YAAY,EAAE,QAAQ;CACtB,WAAW,EAAE,QAAQ;CACrB,QAAQ,EAAE,OAAO,QAAQ;CACzB,aAAa,EAAE,QAAQ,CAAC,SAAS;CACjC,cAAc,EAAE,QAAQ,CAAC,SAAS;CAClC,SAAS,EAAE,QAAQ,CAAC,SAAS;CAI7B,sBAAsB,EAAE,MAAM,CAAC,SAAS;CAIxC,uBAAuB,EAAE,MAAM,CAAC,SAAS;CAIzC,OAAO,EAAE,QAAQ,CAAC,SAAS;CAI3B,UAAU,EAAE,QAAQ,CAAC,SAAS;CAC9B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
import "../../types/index.mjs";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/db/schema/rate-limit.d.ts
|
|
8
|
+
declare const rateLimitSchema: z.ZodObject<{
|
|
9
|
+
key: z.ZodString;
|
|
10
|
+
count: z.ZodNumber;
|
|
11
|
+
lastRequest: z.ZodNumber;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
type BaseRateLimit = z.infer<typeof rateLimitSchema>;
|
|
14
|
+
/**
|
|
15
|
+
* Rate limit schema type used by better-auth for rate limiting
|
|
16
|
+
*/
|
|
17
|
+
type RateLimit<DBOptions extends BetterAuthOptions["rateLimit"] = BetterAuthOptions["rateLimit"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify<BaseRateLimit & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"rateLimit", Plugins>>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { BaseRateLimit, RateLimit, rateLimitSchema };
|
|
20
|
+
//# sourceMappingURL=rate-limit.d.mts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/rate-limit.ts
|
|
4
|
+
const rateLimitSchema = z.object({
|
|
5
|
+
key: z.string(),
|
|
6
|
+
count: z.number(),
|
|
7
|
+
lastRequest: z.number()
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { rateLimitSchema };
|
|
12
|
+
//# sourceMappingURL=rate-limit.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.mjs","names":[],"sources":["../../../src/db/schema/rate-limit.ts"],"sourcesContent":["import * as z from \"zod\";\nimport type { BetterAuthOptions, Prettify } from \"../../types\";\nimport type {\n\tInferDBFieldsFromOptions,\n\tInferDBFieldsFromPlugins,\n} from \"../type\";\n\nexport const rateLimitSchema = z.object({\n\t/**\n\t * The key to use for rate limiting\n\t */\n\tkey: z.string(),\n\t/**\n\t * The number of requests made\n\t */\n\tcount: z.number(),\n\t/**\n\t * The last request time in milliseconds\n\t */\n\tlastRequest: z.number(),\n});\n\nexport type BaseRateLimit = z.infer<typeof rateLimitSchema>;\n\n/**\n * Rate limit schema type used by better-auth for rate limiting\n */\nexport type RateLimit<\n\tDBOptions extends\n\t\tBetterAuthOptions[\"rateLimit\"] = BetterAuthOptions[\"rateLimit\"],\n\tPlugins extends BetterAuthOptions[\"plugins\"] = BetterAuthOptions[\"plugins\"],\n> = Prettify<\n\tBaseRateLimit &\n\t\tInferDBFieldsFromOptions<DBOptions> &\n\t\tInferDBFieldsFromPlugins<\"rateLimit\", Plugins>\n>;\n"],"mappings":";;;AAOA,MAAa,kBAAkB,EAAE,OAAO;CAIvC,KAAK,EAAE,QAAQ;CAIf,OAAO,EAAE,QAAQ;CAIjB,aAAa,EAAE,QAAQ;CACvB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
import "../../types/index.mjs";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/db/schema/session.d.ts
|
|
8
|
+
declare const sessionSchema: z.ZodObject<{
|
|
9
|
+
id: z.ZodString;
|
|
10
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
11
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
12
|
+
userId: z.ZodCoercedString<unknown>;
|
|
13
|
+
expiresAt: z.ZodDate;
|
|
14
|
+
token: z.ZodString;
|
|
15
|
+
ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
|
+
userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
type BaseSession = z.infer<typeof sessionSchema>;
|
|
19
|
+
/**
|
|
20
|
+
* Session schema type used by better-auth, note that it's possible that session could have additional fields
|
|
21
|
+
*/
|
|
22
|
+
type Session<DBOptions extends BetterAuthOptions["session"] = BetterAuthOptions["session"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify<z.infer<typeof sessionSchema> & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"session", Plugins>>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { BaseSession, Session, sessionSchema };
|
|
25
|
+
//# sourceMappingURL=session.d.mts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/db/schema/session.ts
|
|
5
|
+
const sessionSchema = coreSchema.extend({
|
|
6
|
+
userId: z.coerce.string(),
|
|
7
|
+
expiresAt: z.date(),
|
|
8
|
+
token: z.string(),
|
|
9
|
+
ipAddress: z.string().nullish(),
|
|
10
|
+
userAgent: z.string().nullish()
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { sessionSchema };
|
|
15
|
+
//# sourceMappingURL=session.mjs.map
|