@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,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
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
//#region src/db/get-tables.ts
|
|
2
|
+
const getAuthTables = (options) => {
|
|
3
|
+
const pluginSchema = (options.plugins ?? []).reduce((acc, plugin) => {
|
|
4
|
+
const schema = plugin.schema;
|
|
5
|
+
if (!schema) return acc;
|
|
6
|
+
for (const [key, value] of Object.entries(schema)) acc[key] = {
|
|
7
|
+
fields: {
|
|
8
|
+
...acc[key]?.fields,
|
|
9
|
+
...value.fields
|
|
10
|
+
},
|
|
11
|
+
modelName: value.modelName || key
|
|
12
|
+
};
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
const shouldAddRateLimitTable = options.rateLimit?.storage === "database";
|
|
16
|
+
const rateLimitTable = { rateLimit: {
|
|
17
|
+
modelName: options.rateLimit?.modelName || "rateLimit",
|
|
18
|
+
fields: {
|
|
19
|
+
key: {
|
|
20
|
+
type: "string",
|
|
21
|
+
unique: true,
|
|
22
|
+
required: true,
|
|
23
|
+
fieldName: options.rateLimit?.fields?.key || "key"
|
|
24
|
+
},
|
|
25
|
+
count: {
|
|
26
|
+
type: "number",
|
|
27
|
+
required: true,
|
|
28
|
+
fieldName: options.rateLimit?.fields?.count || "count"
|
|
29
|
+
},
|
|
30
|
+
lastRequest: {
|
|
31
|
+
type: "number",
|
|
32
|
+
bigint: true,
|
|
33
|
+
required: true,
|
|
34
|
+
fieldName: options.rateLimit?.fields?.lastRequest || "lastRequest",
|
|
35
|
+
defaultValue: () => Date.now()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} };
|
|
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
|
+
} };
|
|
77
|
+
const sessionTable = { session: {
|
|
78
|
+
modelName: options.session?.modelName || "session",
|
|
79
|
+
fields: {
|
|
80
|
+
expiresAt: {
|
|
81
|
+
type: "date",
|
|
82
|
+
required: true,
|
|
83
|
+
fieldName: options.session?.fields?.expiresAt || "expiresAt"
|
|
84
|
+
},
|
|
85
|
+
token: {
|
|
86
|
+
type: "string",
|
|
87
|
+
required: true,
|
|
88
|
+
fieldName: options.session?.fields?.token || "token",
|
|
89
|
+
unique: true
|
|
90
|
+
},
|
|
91
|
+
createdAt: {
|
|
92
|
+
type: "date",
|
|
93
|
+
required: true,
|
|
94
|
+
fieldName: options.session?.fields?.createdAt || "createdAt",
|
|
95
|
+
defaultValue: () => /* @__PURE__ */ new Date()
|
|
96
|
+
},
|
|
97
|
+
updatedAt: {
|
|
98
|
+
type: "date",
|
|
99
|
+
required: true,
|
|
100
|
+
fieldName: options.session?.fields?.updatedAt || "updatedAt",
|
|
101
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
102
|
+
},
|
|
103
|
+
ipAddress: {
|
|
104
|
+
type: "string",
|
|
105
|
+
required: false,
|
|
106
|
+
fieldName: options.session?.fields?.ipAddress || "ipAddress"
|
|
107
|
+
},
|
|
108
|
+
userAgent: {
|
|
109
|
+
type: "string",
|
|
110
|
+
required: false,
|
|
111
|
+
fieldName: options.session?.fields?.userAgent || "userAgent"
|
|
112
|
+
},
|
|
113
|
+
userId: {
|
|
114
|
+
type: "string",
|
|
115
|
+
fieldName: options.session?.fields?.userId || "userId",
|
|
116
|
+
references: {
|
|
117
|
+
model: options.user?.modelName || "user",
|
|
118
|
+
field: "id",
|
|
119
|
+
onDelete: "cascade"
|
|
120
|
+
},
|
|
121
|
+
required: true,
|
|
122
|
+
index: true
|
|
123
|
+
},
|
|
124
|
+
...session?.fields,
|
|
125
|
+
...options.session?.additionalFields
|
|
126
|
+
},
|
|
127
|
+
order: 2
|
|
128
|
+
} };
|
|
129
|
+
return {
|
|
130
|
+
user: {
|
|
131
|
+
modelName: options.user?.modelName || "user",
|
|
132
|
+
fields: {
|
|
133
|
+
name: {
|
|
134
|
+
type: "string",
|
|
135
|
+
required: true,
|
|
136
|
+
fieldName: options.user?.fields?.name || "name",
|
|
137
|
+
sortable: true
|
|
138
|
+
},
|
|
139
|
+
email: {
|
|
140
|
+
type: "string",
|
|
141
|
+
unique: true,
|
|
142
|
+
required: true,
|
|
143
|
+
fieldName: options.user?.fields?.email || "email",
|
|
144
|
+
sortable: true
|
|
145
|
+
},
|
|
146
|
+
emailVerified: {
|
|
147
|
+
type: "boolean",
|
|
148
|
+
defaultValue: false,
|
|
149
|
+
required: true,
|
|
150
|
+
fieldName: options.user?.fields?.emailVerified || "emailVerified",
|
|
151
|
+
input: false
|
|
152
|
+
},
|
|
153
|
+
image: {
|
|
154
|
+
type: "string",
|
|
155
|
+
required: false,
|
|
156
|
+
fieldName: options.user?.fields?.image || "image"
|
|
157
|
+
},
|
|
158
|
+
createdAt: {
|
|
159
|
+
type: "date",
|
|
160
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
161
|
+
required: true,
|
|
162
|
+
fieldName: options.user?.fields?.createdAt || "createdAt"
|
|
163
|
+
},
|
|
164
|
+
updatedAt: {
|
|
165
|
+
type: "date",
|
|
166
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
167
|
+
onUpdate: () => /* @__PURE__ */ new Date(),
|
|
168
|
+
required: true,
|
|
169
|
+
fieldName: options.user?.fields?.updatedAt || "updatedAt"
|
|
170
|
+
},
|
|
171
|
+
...user?.fields,
|
|
172
|
+
...options.user?.additionalFields
|
|
173
|
+
},
|
|
174
|
+
order: 1
|
|
175
|
+
},
|
|
176
|
+
...!options.secondaryStorage || options.session?.storeSessionInDatabase ? sessionTable : {},
|
|
177
|
+
account: {
|
|
178
|
+
modelName: options.account?.modelName || "account",
|
|
179
|
+
fields: {
|
|
180
|
+
accountId: {
|
|
181
|
+
type: "string",
|
|
182
|
+
required: true,
|
|
183
|
+
fieldName: options.account?.fields?.accountId || "accountId"
|
|
184
|
+
},
|
|
185
|
+
providerId: {
|
|
186
|
+
type: "string",
|
|
187
|
+
required: true,
|
|
188
|
+
fieldName: options.account?.fields?.providerId || "providerId"
|
|
189
|
+
},
|
|
190
|
+
userId: {
|
|
191
|
+
type: "string",
|
|
192
|
+
references: {
|
|
193
|
+
model: options.user?.modelName || "user",
|
|
194
|
+
field: "id",
|
|
195
|
+
onDelete: "cascade"
|
|
196
|
+
},
|
|
197
|
+
required: true,
|
|
198
|
+
fieldName: options.account?.fields?.userId || "userId",
|
|
199
|
+
index: true
|
|
200
|
+
},
|
|
201
|
+
accessToken: {
|
|
202
|
+
type: "string",
|
|
203
|
+
required: false,
|
|
204
|
+
returned: false,
|
|
205
|
+
fieldName: options.account?.fields?.accessToken || "accessToken"
|
|
206
|
+
},
|
|
207
|
+
refreshToken: {
|
|
208
|
+
type: "string",
|
|
209
|
+
required: false,
|
|
210
|
+
returned: false,
|
|
211
|
+
fieldName: options.account?.fields?.refreshToken || "refreshToken"
|
|
212
|
+
},
|
|
213
|
+
idToken: {
|
|
214
|
+
type: "string",
|
|
215
|
+
required: false,
|
|
216
|
+
returned: false,
|
|
217
|
+
fieldName: options.account?.fields?.idToken || "idToken"
|
|
218
|
+
},
|
|
219
|
+
accessTokenExpiresAt: {
|
|
220
|
+
type: "date",
|
|
221
|
+
required: false,
|
|
222
|
+
returned: false,
|
|
223
|
+
fieldName: options.account?.fields?.accessTokenExpiresAt || "accessTokenExpiresAt"
|
|
224
|
+
},
|
|
225
|
+
refreshTokenExpiresAt: {
|
|
226
|
+
type: "date",
|
|
227
|
+
required: false,
|
|
228
|
+
returned: false,
|
|
229
|
+
fieldName: options.account?.fields?.refreshTokenExpiresAt || "refreshTokenExpiresAt"
|
|
230
|
+
},
|
|
231
|
+
scope: {
|
|
232
|
+
type: "string",
|
|
233
|
+
required: false,
|
|
234
|
+
fieldName: options.account?.fields?.scope || "scope"
|
|
235
|
+
},
|
|
236
|
+
password: {
|
|
237
|
+
type: "string",
|
|
238
|
+
required: false,
|
|
239
|
+
returned: false,
|
|
240
|
+
fieldName: options.account?.fields?.password || "password"
|
|
241
|
+
},
|
|
242
|
+
createdAt: {
|
|
243
|
+
type: "date",
|
|
244
|
+
required: true,
|
|
245
|
+
fieldName: options.account?.fields?.createdAt || "createdAt",
|
|
246
|
+
defaultValue: () => /* @__PURE__ */ new Date()
|
|
247
|
+
},
|
|
248
|
+
updatedAt: {
|
|
249
|
+
type: "date",
|
|
250
|
+
required: true,
|
|
251
|
+
fieldName: options.account?.fields?.updatedAt || "updatedAt",
|
|
252
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
253
|
+
},
|
|
254
|
+
...account?.fields,
|
|
255
|
+
...options.account?.additionalFields
|
|
256
|
+
},
|
|
257
|
+
order: 3
|
|
258
|
+
},
|
|
259
|
+
...!options.secondaryStorage || options.verification?.storeInDatabase ? verificationTable : {},
|
|
260
|
+
...pluginTables,
|
|
261
|
+
...shouldAddRateLimitTable ? rateLimitTable : {}
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
//#endregion
|
|
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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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseModelNames, BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, ModelNames, SecondaryStorage } from "./type.mjs";
|
|
2
|
+
import { getAuthTables } from "./get-tables.mjs";
|
|
3
|
+
import { BetterAuthPluginDBSchema } from "./plugin.mjs";
|
|
4
|
+
import { Account, accountSchema } from "./schema/account.mjs";
|
|
5
|
+
import { RateLimit, rateLimitSchema } from "./schema/rate-limit.mjs";
|
|
6
|
+
import { Session, sessionSchema } from "./schema/session.mjs";
|
|
7
|
+
import { coreSchema } from "./schema/shared.mjs";
|
|
8
|
+
import { User, userSchema } from "./schema/user.mjs";
|
|
9
|
+
import { Verification, verificationSchema } from "./schema/verification.mjs";
|
|
10
|
+
export { type Account, type BaseModelNames, type BetterAuthDBSchema, type BetterAuthPluginDBSchema, type DBFieldAttribute, type DBFieldAttributeConfig, type DBFieldType, type DBPrimitive, type ModelNames, type RateLimit, type SecondaryStorage, type Session, type User, type Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
|
|
@@ -0,0 +1,9 @@
|
|
|
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";
|
|
8
|
+
|
|
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,27 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/account.d.ts
|
|
4
|
+
declare const accountSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
providerId: z.ZodString;
|
|
9
|
+
accountId: z.ZodString;
|
|
10
|
+
userId: z.ZodCoercedString<unknown>;
|
|
11
|
+
accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
|
+
accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
15
|
+
refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
16
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/**
|
|
20
|
+
* Account schema type used by better-auth, note that it's possible that account could have additional fields
|
|
21
|
+
*
|
|
22
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
23
|
+
*/
|
|
24
|
+
type Account = z.infer<typeof accountSchema>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Account, accountSchema };
|
|
27
|
+
//# 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 { 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\n/**\n * Account schema type used by better-auth, note that it's possible that account could have additional fields\n *\n * todo: we should use generics to extend this type with additional fields from plugins and options in the future\n */\nexport type Account = z.infer<typeof accountSchema>;\n"],"mappings":";;;;AAGA,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,15 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/rate-limit.d.ts
|
|
4
|
+
declare const rateLimitSchema: z.ZodObject<{
|
|
5
|
+
key: z.ZodString;
|
|
6
|
+
count: z.ZodNumber;
|
|
7
|
+
lastRequest: z.ZodNumber;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
/**
|
|
10
|
+
* Rate limit schema type used by better-auth for rate limiting
|
|
11
|
+
*/
|
|
12
|
+
type RateLimit = z.infer<typeof rateLimitSchema>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { RateLimit, rateLimitSchema };
|
|
15
|
+
//# 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\";\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\n/**\n * Rate limit schema type used by better-auth for rate limiting\n */\nexport type RateLimit = z.infer<typeof rateLimitSchema>;\n"],"mappings":";;;AAEA,MAAa,kBAAkB,EAAE,OAAO;CAIvC,KAAK,EAAE,QAAQ;CAIf,OAAO,EAAE,QAAQ;CAIjB,aAAa,EAAE,QAAQ;CACvB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/session.d.ts
|
|
4
|
+
declare const sessionSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
userId: z.ZodCoercedString<unknown>;
|
|
9
|
+
expiresAt: z.ZodDate;
|
|
10
|
+
token: z.ZodString;
|
|
11
|
+
ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
/**
|
|
15
|
+
* Session schema type used by better-auth, note that it's possible that session could have additional fields
|
|
16
|
+
*
|
|
17
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
18
|
+
*/
|
|
19
|
+
type Session = z.infer<typeof sessionSchema>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Session, sessionSchema };
|
|
22
|
+
//# 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.mjs","names":[],"sources":["../../../src/db/schema/session.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { coreSchema } from \"./shared\";\n\nexport const sessionSchema = coreSchema.extend({\n\tuserId: z.coerce.string(),\n\texpiresAt: z.date(),\n\ttoken: z.string(),\n\tipAddress: z.string().nullish(),\n\tuserAgent: z.string().nullish(),\n});\n\n/**\n * Session schema type used by better-auth, note that it's possible that session could have additional fields\n *\n * todo: we should use generics to extend this type with additional fields from plugins and options in the future\n */\nexport type Session = z.infer<typeof sessionSchema>;\n"],"mappings":";;;;AAGA,MAAa,gBAAgB,WAAW,OAAO;CAC9C,QAAQ,EAAE,OAAO,QAAQ;CACzB,WAAW,EAAE,MAAM;CACnB,OAAO,EAAE,QAAQ;CACjB,WAAW,EAAE,QAAQ,CAAC,SAAS;CAC/B,WAAW,EAAE,QAAQ,CAAC,SAAS;CAC/B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/shared.d.ts
|
|
4
|
+
declare const coreSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { coreSchema };
|
|
11
|
+
//# sourceMappingURL=shared.d.mts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/shared.ts
|
|
4
|
+
const coreSchema = z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
|
|
7
|
+
updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { coreSchema };
|
|
12
|
+
//# sourceMappingURL=shared.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.mjs","names":[],"sources":["../../../src/db/schema/shared.ts"],"sourcesContent":["import * as z from \"zod\";\n\nexport const coreSchema = z.object({\n\tid: z.string(),\n\tcreatedAt: z.date().default(() => new Date()),\n\tupdatedAt: z.date().default(() => new Date()),\n});\n"],"mappings":";;;AAEA,MAAa,aAAa,EAAE,OAAO;CAClC,IAAI,EAAE,QAAQ;CACd,WAAW,EAAE,MAAM,CAAC,8BAAc,IAAI,MAAM,CAAC;CAC7C,WAAW,EAAE,MAAM,CAAC,8BAAc,IAAI,MAAM,CAAC;CAC7C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/user.d.ts
|
|
4
|
+
declare const userSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
9
|
+
emailVerified: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
+
name: z.ZodString;
|
|
11
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
/**
|
|
14
|
+
* User schema type used by better-auth, note that it's possible that user could have additional fields
|
|
15
|
+
*
|
|
16
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
17
|
+
*/
|
|
18
|
+
type User = z.infer<typeof userSchema>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { User, userSchema };
|
|
21
|
+
//# sourceMappingURL=user.d.mts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/db/schema/user.ts
|
|
5
|
+
const userSchema = coreSchema.extend({
|
|
6
|
+
email: z.string().transform((val) => val.toLowerCase()),
|
|
7
|
+
emailVerified: z.boolean().default(false),
|
|
8
|
+
name: z.string(),
|
|
9
|
+
image: z.string().nullish()
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { userSchema };
|
|
14
|
+
//# sourceMappingURL=user.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.mjs","names":[],"sources":["../../../src/db/schema/user.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { coreSchema } from \"./shared\";\n\nexport const userSchema = coreSchema.extend({\n\temail: z.string().transform((val) => val.toLowerCase()),\n\temailVerified: z.boolean().default(false),\n\tname: z.string(),\n\timage: z.string().nullish(),\n});\n\n/**\n * User schema type used by better-auth, note that it's possible that user could have additional fields\n *\n * todo: we should use generics to extend this type with additional fields from plugins and options in the future\n */\nexport type User = z.infer<typeof userSchema>;\n"],"mappings":";;;;AAGA,MAAa,aAAa,WAAW,OAAO;CAC3C,OAAO,EAAE,QAAQ,CAAC,WAAW,QAAQ,IAAI,aAAa,CAAC;CACvD,eAAe,EAAE,SAAS,CAAC,QAAQ,MAAM;CACzC,MAAM,EAAE,QAAQ;CAChB,OAAO,EAAE,QAAQ,CAAC,SAAS;CAC3B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/verification.d.ts
|
|
4
|
+
declare const verificationSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
value: z.ZodString;
|
|
9
|
+
expiresAt: z.ZodDate;
|
|
10
|
+
identifier: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
/**
|
|
13
|
+
* Verification schema type used by better-auth, note that it's possible that verification could have additional fields
|
|
14
|
+
*
|
|
15
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
16
|
+
*/
|
|
17
|
+
type Verification = z.infer<typeof verificationSchema>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Verification, verificationSchema };
|
|
20
|
+
//# sourceMappingURL=verification.d.mts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/db/schema/verification.ts
|
|
5
|
+
const verificationSchema = coreSchema.extend({
|
|
6
|
+
value: z.string(),
|
|
7
|
+
expiresAt: z.date(),
|
|
8
|
+
identifier: z.string()
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { verificationSchema };
|
|
13
|
+
//# sourceMappingURL=verification.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification.mjs","names":[],"sources":["../../../src/db/schema/verification.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { coreSchema } from \"./shared\";\n\nexport const verificationSchema = coreSchema.extend({\n\tvalue: z.string(),\n\texpiresAt: z.date(),\n\tidentifier: z.string(),\n});\n\n/**\n * Verification schema type used by better-auth, note that it's possible that verification could have additional fields\n *\n * todo: we should use generics to extend this type with additional fields from plugins and options in the future\n */\nexport type Verification = z.infer<typeof verificationSchema>;\n"],"mappings":";;;;AAGA,MAAa,qBAAqB,WAAW,OAAO;CACnD,OAAO,EAAE,QAAQ;CACjB,WAAW,EAAE,MAAM;CACnB,YAAY,EAAE,QAAQ;CACtB,CAAC"}
|