@better-auth/core 1.4.0-beta.7 → 1.4.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.
Files changed (124) hide show
  1. package/.turbo/turbo-build.log +54 -4
  2. package/build.config.ts +6 -0
  3. package/dist/db/adapter/index.d.cts +14 -23
  4. package/dist/db/adapter/index.d.mts +14 -23
  5. package/dist/db/adapter/index.d.ts +14 -23
  6. package/dist/db/index.cjs +16 -0
  7. package/dist/db/index.d.cts +6 -83
  8. package/dist/db/index.d.mts +6 -83
  9. package/dist/db/index.d.ts +6 -83
  10. package/dist/db/index.mjs +16 -1
  11. package/dist/env/index.cjs +315 -0
  12. package/dist/env/index.d.cts +36 -0
  13. package/dist/env/index.d.mts +36 -0
  14. package/dist/env/index.d.ts +36 -0
  15. package/dist/env/index.mjs +300 -0
  16. package/dist/error/index.cjs +44 -0
  17. package/dist/error/index.d.cts +33 -0
  18. package/dist/error/index.d.mts +33 -0
  19. package/dist/error/index.d.ts +33 -0
  20. package/dist/error/index.mjs +41 -0
  21. package/dist/index.d.cts +159 -94
  22. package/dist/index.d.mts +159 -94
  23. package/dist/index.d.ts +159 -94
  24. package/dist/middleware/index.cjs +25 -0
  25. package/dist/middleware/index.d.cts +14 -0
  26. package/dist/middleware/index.d.mts +14 -0
  27. package/dist/middleware/index.d.ts +14 -0
  28. package/dist/middleware/index.mjs +21 -0
  29. package/dist/oauth2/index.cjs +368 -0
  30. package/dist/oauth2/index.d.cts +99 -0
  31. package/dist/oauth2/index.d.mts +99 -0
  32. package/dist/oauth2/index.d.ts +99 -0
  33. package/dist/oauth2/index.mjs +357 -0
  34. package/dist/shared/core.2rWMW9q9.d.ts +13 -0
  35. package/dist/shared/core.40VTWh-p.d.cts +217 -0
  36. package/dist/shared/core.BfcVdsSf.d.cts +181 -0
  37. package/dist/shared/core.Bisb2Bdk.d.mts +181 -0
  38. package/dist/shared/core.BwoNUcJQ.d.cts +53 -0
  39. package/dist/shared/core.BwoNUcJQ.d.mts +53 -0
  40. package/dist/shared/core.BwoNUcJQ.d.ts +53 -0
  41. package/dist/shared/core.CErFRCOZ.d.mts +1684 -0
  42. package/dist/shared/core.CGN6D-Mh.d.ts +181 -0
  43. package/dist/shared/core.CPuIItYE.d.ts +217 -0
  44. package/dist/shared/core.CftpHMDz.d.cts +13 -0
  45. package/dist/shared/core.Db7zJyxf.d.ts +1684 -0
  46. package/dist/shared/core.DqaxObkf.d.cts +1684 -0
  47. package/dist/shared/core.MjcDoj7R.d.cts +5 -0
  48. package/dist/shared/core.MjcDoj7R.d.mts +5 -0
  49. package/dist/shared/core.MjcDoj7R.d.ts +5 -0
  50. package/dist/shared/core.g2ZbxAEV.d.mts +217 -0
  51. package/dist/shared/core.g9ACQ8v2.d.mts +13 -0
  52. package/dist/social-providers/index.cjs +2793 -0
  53. package/dist/social-providers/index.d.cts +3903 -0
  54. package/dist/social-providers/index.d.mts +3903 -0
  55. package/dist/social-providers/index.d.ts +3903 -0
  56. package/dist/social-providers/index.mjs +2743 -0
  57. package/dist/utils/index.cjs +7 -0
  58. package/dist/utils/index.d.cts +10 -0
  59. package/dist/utils/index.d.mts +10 -0
  60. package/dist/utils/index.d.ts +10 -0
  61. package/dist/utils/index.mjs +5 -0
  62. package/package.json +99 -2
  63. package/src/db/adapter/index.ts +424 -0
  64. package/src/db/index.ts +4 -0
  65. package/src/db/schema/rate-limit.ts +21 -0
  66. package/src/db/type.ts +29 -10
  67. package/src/env/color-depth.ts +171 -0
  68. package/src/env/env-impl.ts +123 -0
  69. package/src/env/index.ts +23 -0
  70. package/src/env/logger.test.ts +33 -0
  71. package/src/env/logger.ts +145 -0
  72. package/src/error/codes.ts +31 -0
  73. package/src/error/index.ts +11 -0
  74. package/src/index.ts +0 -2
  75. package/src/middleware/index.ts +33 -0
  76. package/src/oauth2/client-credentials-token.ts +102 -0
  77. package/src/oauth2/create-authorization-url.ts +85 -0
  78. package/src/oauth2/index.ts +22 -0
  79. package/src/oauth2/oauth-provider.ts +194 -0
  80. package/src/oauth2/refresh-access-token.ts +124 -0
  81. package/src/oauth2/utils.ts +36 -0
  82. package/src/oauth2/validate-authorization-code.ts +156 -0
  83. package/src/social-providers/apple.ts +213 -0
  84. package/src/social-providers/atlassian.ts +130 -0
  85. package/src/social-providers/cognito.ts +269 -0
  86. package/src/social-providers/discord.ts +172 -0
  87. package/src/social-providers/dropbox.ts +112 -0
  88. package/src/social-providers/facebook.ts +204 -0
  89. package/src/social-providers/figma.ts +115 -0
  90. package/src/social-providers/github.ts +154 -0
  91. package/src/social-providers/gitlab.ts +152 -0
  92. package/src/social-providers/google.ts +171 -0
  93. package/src/social-providers/huggingface.ts +116 -0
  94. package/src/social-providers/index.ts +118 -0
  95. package/src/social-providers/kakao.ts +178 -0
  96. package/src/social-providers/kick.ts +95 -0
  97. package/src/social-providers/line.ts +169 -0
  98. package/src/social-providers/linear.ts +120 -0
  99. package/src/social-providers/linkedin.ts +110 -0
  100. package/src/social-providers/microsoft-entra-id.ts +243 -0
  101. package/src/social-providers/naver.ts +112 -0
  102. package/src/social-providers/notion.ts +106 -0
  103. package/src/social-providers/paypal.ts +261 -0
  104. package/src/social-providers/reddit.ts +122 -0
  105. package/src/social-providers/roblox.ts +110 -0
  106. package/src/social-providers/salesforce.ts +157 -0
  107. package/src/social-providers/slack.ts +114 -0
  108. package/src/social-providers/spotify.ts +93 -0
  109. package/src/social-providers/tiktok.ts +211 -0
  110. package/src/social-providers/twitch.ts +111 -0
  111. package/src/social-providers/twitter.ts +194 -0
  112. package/src/social-providers/vk.ts +128 -0
  113. package/src/social-providers/zoom.ts +218 -0
  114. package/src/types/context.ts +270 -0
  115. package/src/types/cookie.ts +7 -0
  116. package/src/types/index.ts +19 -1
  117. package/src/types/init-options.ts +1039 -2
  118. package/src/types/plugin-client.ts +69 -0
  119. package/src/types/plugin.ts +134 -0
  120. package/src/utils/error-codes.ts +51 -0
  121. package/src/utils/index.ts +1 -0
  122. package/dist/shared/core.CnvFgghY.d.cts +0 -117
  123. package/dist/shared/core.CnvFgghY.d.mts +0 -117
  124. package/dist/shared/core.CnvFgghY.d.ts +0 -117
@@ -0,0 +1,69 @@
1
+ import type { BetterAuthPlugin } from "./plugin";
2
+ import type {
3
+ BetterFetch,
4
+ BetterFetchOption,
5
+ BetterFetchPlugin,
6
+ } from "@better-fetch/fetch";
7
+ import type { LiteralString } from "./helper";
8
+ import type { BetterAuthOptions } from "./init-options";
9
+ import type { WritableAtom, Atom } from "nanostores";
10
+
11
+ export interface ClientStore {
12
+ notify: (signal: string) => void;
13
+ listen: (signal: string, listener: () => void) => void;
14
+ atoms: Record<string, WritableAtom<any>>;
15
+ }
16
+
17
+ export type ClientAtomListener = {
18
+ matcher: (path: string) => boolean;
19
+ signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
20
+ };
21
+
22
+ export interface BetterAuthClientOptions {
23
+ fetchOptions?: BetterFetchOption;
24
+ plugins?: BetterAuthClientPlugin[];
25
+ baseURL?: string;
26
+ basePath?: string;
27
+ disableDefaultFetchPlugins?: boolean;
28
+ $InferAuth?: BetterAuthOptions;
29
+ }
30
+
31
+ export interface BetterAuthClientPlugin {
32
+ id: LiteralString;
33
+ /**
34
+ * only used for type inference. don't pass the
35
+ * actual plugin
36
+ */
37
+ $InferServerPlugin?: BetterAuthPlugin;
38
+ /**
39
+ * Custom actions
40
+ */
41
+ getActions?: (
42
+ $fetch: BetterFetch,
43
+ $store: ClientStore,
44
+ /**
45
+ * better-auth client options
46
+ */
47
+ options: BetterAuthClientOptions | undefined,
48
+ ) => Record<string, any>;
49
+ /**
50
+ * State atoms that'll be resolved by each framework
51
+ * auth store.
52
+ */
53
+ getAtoms?: ($fetch: BetterFetch) => Record<string, Atom<any>>;
54
+ /**
55
+ * specify path methods for server plugin inferred
56
+ * endpoints to force a specific method.
57
+ */
58
+ pathMethods?: Record<string, "POST" | "GET">;
59
+ /**
60
+ * Better fetch plugins
61
+ */
62
+ fetchPlugins?: BetterFetchPlugin[];
63
+ /**
64
+ * a list of recaller based on a matcher function.
65
+ * The signal name needs to match a signal in this
66
+ * plugin or any plugin the user might have added.
67
+ */
68
+ atomListeners?: ClientAtomListener[];
69
+ }
@@ -0,0 +1,134 @@
1
+ import type { Migration } from "kysely";
2
+ import type { AuthContext } from "./context";
3
+ import type {
4
+ Endpoint,
5
+ EndpointContext,
6
+ InputContext,
7
+ Middleware,
8
+ } from "better-call";
9
+ import type { BetterAuthPluginDBSchema } from "../db";
10
+ import type { LiteralString } from "./helper";
11
+ import type { BetterAuthOptions } from "./init-options";
12
+ import type { AuthMiddleware } from "../middleware";
13
+
14
+ type Awaitable<T> = T | Promise<T>;
15
+ type DeepPartial<T> = T extends Function
16
+ ? T
17
+ : T extends object
18
+ ? { [K in keyof T]?: DeepPartial<T[K]> }
19
+ : T;
20
+
21
+ type HookEndpointContext = EndpointContext<string, any> &
22
+ Omit<InputContext<string, any>, "method"> & {
23
+ context: AuthContext & {
24
+ returned?: unknown;
25
+ responseHeaders?: Headers;
26
+ };
27
+ headers?: Headers;
28
+ };
29
+
30
+ export type BetterAuthPlugin = {
31
+ id: LiteralString;
32
+ /**
33
+ * The init function is called when the plugin is initialized.
34
+ * You can return a new context or modify the existing context.
35
+ */
36
+ init?: (ctx: AuthContext) =>
37
+ | Awaitable<{
38
+ context?: DeepPartial<Omit<AuthContext, "options">>;
39
+ options?: Partial<BetterAuthOptions>;
40
+ }>
41
+ | void
42
+ | Promise<void>;
43
+ endpoints?: {
44
+ [key: string]: Endpoint;
45
+ };
46
+ middlewares?: {
47
+ path: string;
48
+ middleware: Middleware;
49
+ }[];
50
+ onRequest?: (
51
+ request: Request,
52
+ ctx: AuthContext,
53
+ ) => Promise<
54
+ | {
55
+ response: Response;
56
+ }
57
+ | {
58
+ request: Request;
59
+ }
60
+ | void
61
+ >;
62
+ onResponse?: (
63
+ response: Response,
64
+ ctx: AuthContext,
65
+ ) => Promise<{
66
+ response: Response;
67
+ } | void>;
68
+ hooks?: {
69
+ before?: {
70
+ matcher: (context: HookEndpointContext) => boolean;
71
+ handler: AuthMiddleware;
72
+ }[];
73
+ after?: {
74
+ matcher: (context: HookEndpointContext) => boolean;
75
+ handler: AuthMiddleware;
76
+ }[];
77
+ };
78
+ /**
79
+ * Schema the plugin needs
80
+ *
81
+ * This will also be used to migrate the database. If the fields are dynamic from the plugins
82
+ * configuration each time the configuration is changed a new migration will be created.
83
+ *
84
+ * NOTE: If you want to create migrations manually using
85
+ * migrations option or any other way you
86
+ * can disable migration per table basis.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * schema: {
91
+ * user: {
92
+ * fields: {
93
+ * email: {
94
+ * type: "string",
95
+ * },
96
+ * emailVerified: {
97
+ * type: "boolean",
98
+ * defaultValue: false,
99
+ * },
100
+ * },
101
+ * }
102
+ * } as AuthPluginSchema
103
+ * ```
104
+ */
105
+ schema?: BetterAuthPluginDBSchema;
106
+ /**
107
+ * The migrations of the plugin. If you define schema that will automatically create
108
+ * migrations for you.
109
+ *
110
+ * ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
111
+ * the tables.
112
+ */
113
+ migrations?: Record<string, Migration>;
114
+ /**
115
+ * The options of the plugin
116
+ */
117
+ options?: Record<string, any> | undefined;
118
+ /**
119
+ * types to be inferred
120
+ */
121
+ $Infer?: Record<string, any>;
122
+ /**
123
+ * The rate limit rules to apply to specific paths.
124
+ */
125
+ rateLimit?: {
126
+ window: number;
127
+ max: number;
128
+ pathMatcher: (path: string) => boolean;
129
+ }[];
130
+ /**
131
+ * The error codes returned by the plugin
132
+ */
133
+ $ERROR_CODES?: Record<string, string>;
134
+ };
@@ -0,0 +1,51 @@
1
+ type UpperLetter =
2
+ | "A"
3
+ | "B"
4
+ | "C"
5
+ | "D"
6
+ | "E"
7
+ | "F"
8
+ | "G"
9
+ | "H"
10
+ | "I"
11
+ | "J"
12
+ | "K"
13
+ | "L"
14
+ | "M"
15
+ | "N"
16
+ | "O"
17
+ | "P"
18
+ | "Q"
19
+ | "R"
20
+ | "S"
21
+ | "T"
22
+ | "U"
23
+ | "V"
24
+ | "W"
25
+ | "X"
26
+ | "Y"
27
+ | "Z";
28
+ type SpecialCharacter = "_";
29
+
30
+ type IsValidUpperSnakeCase<S extends string> = S extends `${infer F}${infer R}`
31
+ ? F extends UpperLetter | SpecialCharacter
32
+ ? IsValidUpperSnakeCase<R>
33
+ : false
34
+ : true;
35
+
36
+ type InvalidKeyError<K extends string> =
37
+ `Invalid error code key: "${K}" - must only contain uppercase letters (A-Z) and underscores (_)`;
38
+
39
+ type ValidateErrorCodes<T> = {
40
+ [K in keyof T]: K extends string
41
+ ? IsValidUpperSnakeCase<K> extends false
42
+ ? InvalidKeyError<K>
43
+ : T[K]
44
+ : T[K];
45
+ };
46
+
47
+ export function defineErrorCodes<const T extends Record<string, string>>(
48
+ codes: ValidateErrorCodes<T>,
49
+ ): T {
50
+ return codes as T;
51
+ }
@@ -0,0 +1 @@
1
+ export { defineErrorCodes } from "./error-codes";
@@ -1,117 +0,0 @@
1
- import { ZodType } from 'zod';
2
-
3
- type Primitive = string | number | symbol | bigint | boolean | null | undefined;
4
- type LiteralString = "" | (string & Record<never, never>);
5
- type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
6
-
7
- declare module "../index" {
8
- interface BetterAuthMutators<O, C> {
9
- "better-auth/db": {};
10
- }
11
- }
12
- type Models = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
13
- type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
14
- type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
15
- type DBFieldAttributeConfig = {
16
- /**
17
- * If the field should be required on a new record.
18
- * @default true
19
- */
20
- required?: boolean;
21
- /**
22
- * If the value should be returned on a response body.
23
- * @default true
24
- */
25
- returned?: boolean;
26
- /**
27
- * If a value should be provided when creating a new record.
28
- * @default true
29
- */
30
- input?: boolean;
31
- /**
32
- * Default value for the field
33
- *
34
- * Note: This will not create a default value on the database level. It will only
35
- * be used when creating a new record.
36
- */
37
- defaultValue?: DBPrimitive | (() => DBPrimitive);
38
- /**
39
- * Update value for the field
40
- *
41
- * Note: This will create an onUpdate trigger on the database level for supported adapters.
42
- * It will be called when updating a record.
43
- */
44
- onUpdate?: () => DBPrimitive;
45
- /**
46
- * transform the value before storing it.
47
- */
48
- transform?: {
49
- input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
50
- output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
51
- };
52
- /**
53
- * Reference to another model.
54
- */
55
- references?: {
56
- /**
57
- * The model to reference.
58
- */
59
- model: string;
60
- /**
61
- * The field on the referenced model.
62
- */
63
- field: string;
64
- /**
65
- * The action to perform when the reference is deleted.
66
- * @default "cascade"
67
- */
68
- onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
69
- };
70
- unique?: boolean;
71
- /**
72
- * If the field should be a bigint on the database instead of integer.
73
- */
74
- bigint?: boolean;
75
- /**
76
- * A zod schema to validate the value.
77
- */
78
- validator?: {
79
- input?: ZodType;
80
- output?: ZodType;
81
- };
82
- /**
83
- * The name of the field on the database.
84
- */
85
- fieldName?: string;
86
- /**
87
- * If the field should be sortable.
88
- *
89
- * applicable only for `text` type.
90
- * It's useful to mark fields varchar instead of text.
91
- */
92
- sortable?: boolean;
93
- };
94
- type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
95
- type: T;
96
- } & DBFieldAttributeConfig;
97
- type BetterAuthDBSchema = Record<string, {
98
- /**
99
- * The name of the table in the database
100
- */
101
- modelName: string;
102
- /**
103
- * The fields of the table
104
- */
105
- fields: Record<string, DBFieldAttribute>;
106
- /**
107
- * Whether to disable migrations for this table
108
- * @default false
109
- */
110
- disableMigrations?: boolean;
111
- /**
112
- * The order of the table
113
- */
114
- order?: number;
115
- }>;
116
-
117
- export type { BetterAuthDBSchema as B, DBFieldAttribute as D, LiteralUnion as L, Models as M, LiteralString as a, DBFieldAttributeConfig as b, DBFieldType as c, DBPrimitive as d };
@@ -1,117 +0,0 @@
1
- import { ZodType } from 'zod';
2
-
3
- type Primitive = string | number | symbol | bigint | boolean | null | undefined;
4
- type LiteralString = "" | (string & Record<never, never>);
5
- type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
6
-
7
- declare module "../index" {
8
- interface BetterAuthMutators<O, C> {
9
- "better-auth/db": {};
10
- }
11
- }
12
- type Models = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
13
- type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
14
- type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
15
- type DBFieldAttributeConfig = {
16
- /**
17
- * If the field should be required on a new record.
18
- * @default true
19
- */
20
- required?: boolean;
21
- /**
22
- * If the value should be returned on a response body.
23
- * @default true
24
- */
25
- returned?: boolean;
26
- /**
27
- * If a value should be provided when creating a new record.
28
- * @default true
29
- */
30
- input?: boolean;
31
- /**
32
- * Default value for the field
33
- *
34
- * Note: This will not create a default value on the database level. It will only
35
- * be used when creating a new record.
36
- */
37
- defaultValue?: DBPrimitive | (() => DBPrimitive);
38
- /**
39
- * Update value for the field
40
- *
41
- * Note: This will create an onUpdate trigger on the database level for supported adapters.
42
- * It will be called when updating a record.
43
- */
44
- onUpdate?: () => DBPrimitive;
45
- /**
46
- * transform the value before storing it.
47
- */
48
- transform?: {
49
- input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
50
- output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
51
- };
52
- /**
53
- * Reference to another model.
54
- */
55
- references?: {
56
- /**
57
- * The model to reference.
58
- */
59
- model: string;
60
- /**
61
- * The field on the referenced model.
62
- */
63
- field: string;
64
- /**
65
- * The action to perform when the reference is deleted.
66
- * @default "cascade"
67
- */
68
- onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
69
- };
70
- unique?: boolean;
71
- /**
72
- * If the field should be a bigint on the database instead of integer.
73
- */
74
- bigint?: boolean;
75
- /**
76
- * A zod schema to validate the value.
77
- */
78
- validator?: {
79
- input?: ZodType;
80
- output?: ZodType;
81
- };
82
- /**
83
- * The name of the field on the database.
84
- */
85
- fieldName?: string;
86
- /**
87
- * If the field should be sortable.
88
- *
89
- * applicable only for `text` type.
90
- * It's useful to mark fields varchar instead of text.
91
- */
92
- sortable?: boolean;
93
- };
94
- type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
95
- type: T;
96
- } & DBFieldAttributeConfig;
97
- type BetterAuthDBSchema = Record<string, {
98
- /**
99
- * The name of the table in the database
100
- */
101
- modelName: string;
102
- /**
103
- * The fields of the table
104
- */
105
- fields: Record<string, DBFieldAttribute>;
106
- /**
107
- * Whether to disable migrations for this table
108
- * @default false
109
- */
110
- disableMigrations?: boolean;
111
- /**
112
- * The order of the table
113
- */
114
- order?: number;
115
- }>;
116
-
117
- export type { BetterAuthDBSchema as B, DBFieldAttribute as D, LiteralUnion as L, Models as M, LiteralString as a, DBFieldAttributeConfig as b, DBFieldType as c, DBPrimitive as d };
@@ -1,117 +0,0 @@
1
- import { ZodType } from 'zod';
2
-
3
- type Primitive = string | number | symbol | bigint | boolean | null | undefined;
4
- type LiteralString = "" | (string & Record<never, never>);
5
- type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
6
-
7
- declare module "../index" {
8
- interface BetterAuthMutators<O, C> {
9
- "better-auth/db": {};
10
- }
11
- }
12
- type Models = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
13
- type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
14
- type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
15
- type DBFieldAttributeConfig = {
16
- /**
17
- * If the field should be required on a new record.
18
- * @default true
19
- */
20
- required?: boolean;
21
- /**
22
- * If the value should be returned on a response body.
23
- * @default true
24
- */
25
- returned?: boolean;
26
- /**
27
- * If a value should be provided when creating a new record.
28
- * @default true
29
- */
30
- input?: boolean;
31
- /**
32
- * Default value for the field
33
- *
34
- * Note: This will not create a default value on the database level. It will only
35
- * be used when creating a new record.
36
- */
37
- defaultValue?: DBPrimitive | (() => DBPrimitive);
38
- /**
39
- * Update value for the field
40
- *
41
- * Note: This will create an onUpdate trigger on the database level for supported adapters.
42
- * It will be called when updating a record.
43
- */
44
- onUpdate?: () => DBPrimitive;
45
- /**
46
- * transform the value before storing it.
47
- */
48
- transform?: {
49
- input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
50
- output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
51
- };
52
- /**
53
- * Reference to another model.
54
- */
55
- references?: {
56
- /**
57
- * The model to reference.
58
- */
59
- model: string;
60
- /**
61
- * The field on the referenced model.
62
- */
63
- field: string;
64
- /**
65
- * The action to perform when the reference is deleted.
66
- * @default "cascade"
67
- */
68
- onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
69
- };
70
- unique?: boolean;
71
- /**
72
- * If the field should be a bigint on the database instead of integer.
73
- */
74
- bigint?: boolean;
75
- /**
76
- * A zod schema to validate the value.
77
- */
78
- validator?: {
79
- input?: ZodType;
80
- output?: ZodType;
81
- };
82
- /**
83
- * The name of the field on the database.
84
- */
85
- fieldName?: string;
86
- /**
87
- * If the field should be sortable.
88
- *
89
- * applicable only for `text` type.
90
- * It's useful to mark fields varchar instead of text.
91
- */
92
- sortable?: boolean;
93
- };
94
- type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
95
- type: T;
96
- } & DBFieldAttributeConfig;
97
- type BetterAuthDBSchema = Record<string, {
98
- /**
99
- * The name of the table in the database
100
- */
101
- modelName: string;
102
- /**
103
- * The fields of the table
104
- */
105
- fields: Record<string, DBFieldAttribute>;
106
- /**
107
- * Whether to disable migrations for this table
108
- * @default false
109
- */
110
- disableMigrations?: boolean;
111
- /**
112
- * The order of the table
113
- */
114
- order?: number;
115
- }>;
116
-
117
- export type { BetterAuthDBSchema as B, DBFieldAttribute as D, LiteralUnion as L, Models as M, LiteralString as a, DBFieldAttributeConfig as b, DBFieldType as c, DBPrimitive as d };