@better-auth/core 1.3.25 → 1.3.27
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 +10 -9
- package/build.config.ts +1 -0
- package/dist/db/adapter/index.cjs +2 -0
- package/dist/db/adapter/index.d.cts +23 -0
- package/dist/db/adapter/index.d.mts +23 -0
- package/dist/db/adapter/index.d.ts +23 -0
- package/dist/db/adapter/index.mjs +1 -0
- package/dist/db/index.cjs +73 -0
- package/dist/db/index.d.cts +91 -105
- package/dist/db/index.d.mts +91 -105
- package/dist/db/index.d.ts +91 -105
- package/dist/db/index.mjs +54 -0
- package/dist/index.d.cts +123 -1
- package/dist/index.d.mts +123 -1
- package/dist/index.d.ts +123 -1
- package/dist/shared/core.CnvFgghY.d.cts +117 -0
- package/dist/shared/core.CnvFgghY.d.mts +117 -0
- package/dist/shared/core.CnvFgghY.d.ts +117 -0
- package/package.json +11 -1
- package/src/db/adapter/index.ts +24 -0
- package/src/db/index.ts +11 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +34 -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/type.ts +22 -0
- package/src/index.ts +3 -1
- package/src/types/helper.ts +5 -0
- package/src/types/index.ts +2 -1
- package/src/types/init-options.ts +128 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/core@1.3.
|
|
2
|
+
> @better-auth/core@1.3.27 build /home/runner/work/better-auth/better-auth/packages/core
|
|
3
3
|
> unbuild --clean
|
|
4
4
|
|
|
5
5
|
[info] Building core
|
|
6
6
|
[info] Cleaning dist directory: `./dist`
|
|
7
7
|
Generated an empty chunk: "index".
|
|
8
|
-
Generated an empty chunk: "db/index".
|
|
9
|
-
Generated an empty chunk: "index".
|
|
10
|
-
Generated an empty chunk: "db/index".
|
|
11
|
-
Generated an empty chunk: "index".
|
|
12
|
-
Generated an empty chunk: "index".
|
|
8
|
+
Generated an empty chunk: "db/adapter/index".
|
|
13
9
|
Generated an empty chunk: "index".
|
|
10
|
+
Generated an empty chunk: "db/adapter/index".
|
|
14
11
|
[success] Build succeeded for core
|
|
15
12
|
[log] dist/index.cjs (total size: 15 B, chunk size: 15 B)
|
|
16
13
|
|
|
17
14
|
[log] dist/async_hooks/index.cjs (total size: 922 B, chunk size: 922 B, exports: getAsyncLocalStorage)
|
|
18
15
|
|
|
19
|
-
[log] dist/db/index.cjs (total size:
|
|
16
|
+
[log] dist/db/index.cjs (total size: 2.09 kB, chunk size: 2.09 kB, exports: accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema)
|
|
17
|
+
|
|
18
|
+
[log] dist/db/adapter/index.cjs (total size: 15 B, chunk size: 15 B)
|
|
20
19
|
[log] dist/index.mjs (total size: 1 B, chunk size: 1 B)
|
|
21
20
|
|
|
22
21
|
[log] dist/async_hooks/index.mjs (total size: 887 B, chunk size: 887 B, exports: getAsyncLocalStorage)
|
|
23
22
|
|
|
24
|
-
[log] dist/db/index.mjs (total size: 1
|
|
25
|
-
|
|
23
|
+
[log] dist/db/index.mjs (total size: 1.4 kB, chunk size: 1.4 kB, exports: accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema)
|
|
24
|
+
|
|
25
|
+
[log] dist/db/adapter/index.mjs (total size: 1 B, chunk size: 1 B)
|
|
26
|
+
Σ Total dist size (byte size): 43 kB
|
|
26
27
|
[log]
|
package/build.config.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type DBAdapterDebugLogOption = boolean | {
|
|
2
|
+
/**
|
|
3
|
+
* Useful when you want to log only certain conditions.
|
|
4
|
+
*/
|
|
5
|
+
logCondition?: (() => boolean) | undefined;
|
|
6
|
+
create?: boolean;
|
|
7
|
+
update?: boolean;
|
|
8
|
+
updateMany?: boolean;
|
|
9
|
+
findOne?: boolean;
|
|
10
|
+
findMany?: boolean;
|
|
11
|
+
delete?: boolean;
|
|
12
|
+
deleteMany?: boolean;
|
|
13
|
+
count?: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
/**
|
|
16
|
+
* Only used for adapter tests to show debug logs if a test fails.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
|
|
19
|
+
*/
|
|
20
|
+
isRunningAdapterTests: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type { DBAdapterDebugLogOption };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type DBAdapterDebugLogOption = boolean | {
|
|
2
|
+
/**
|
|
3
|
+
* Useful when you want to log only certain conditions.
|
|
4
|
+
*/
|
|
5
|
+
logCondition?: (() => boolean) | undefined;
|
|
6
|
+
create?: boolean;
|
|
7
|
+
update?: boolean;
|
|
8
|
+
updateMany?: boolean;
|
|
9
|
+
findOne?: boolean;
|
|
10
|
+
findMany?: boolean;
|
|
11
|
+
delete?: boolean;
|
|
12
|
+
deleteMany?: boolean;
|
|
13
|
+
count?: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
/**
|
|
16
|
+
* Only used for adapter tests to show debug logs if a test fails.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
|
|
19
|
+
*/
|
|
20
|
+
isRunningAdapterTests: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type { DBAdapterDebugLogOption };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type DBAdapterDebugLogOption = boolean | {
|
|
2
|
+
/**
|
|
3
|
+
* Useful when you want to log only certain conditions.
|
|
4
|
+
*/
|
|
5
|
+
logCondition?: (() => boolean) | undefined;
|
|
6
|
+
create?: boolean;
|
|
7
|
+
update?: boolean;
|
|
8
|
+
updateMany?: boolean;
|
|
9
|
+
findOne?: boolean;
|
|
10
|
+
findMany?: boolean;
|
|
11
|
+
delete?: boolean;
|
|
12
|
+
deleteMany?: boolean;
|
|
13
|
+
count?: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
/**
|
|
16
|
+
* Only used for adapter tests to show debug logs if a test fails.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
|
|
19
|
+
*/
|
|
20
|
+
isRunningAdapterTests: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type { DBAdapterDebugLogOption };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/db/index.cjs
CHANGED
|
@@ -1,2 +1,75 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const z = require('zod');
|
|
4
|
+
|
|
5
|
+
function _interopNamespaceCompat(e) {
|
|
6
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
7
|
+
const n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
for (const k in e) {
|
|
10
|
+
n[k] = e[k];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
n.default = e;
|
|
14
|
+
return n;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
|
|
18
|
+
|
|
19
|
+
const coreSchema = z__namespace.object({
|
|
20
|
+
id: z__namespace.string(),
|
|
21
|
+
createdAt: z__namespace.date().default(() => /* @__PURE__ */ new Date()),
|
|
22
|
+
updatedAt: z__namespace.date().default(() => /* @__PURE__ */ new Date())
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const userSchema = coreSchema.extend({
|
|
26
|
+
email: z__namespace.string().transform((val) => val.toLowerCase()),
|
|
27
|
+
emailVerified: z__namespace.boolean().default(false),
|
|
28
|
+
name: z__namespace.string(),
|
|
29
|
+
image: z__namespace.string().nullish()
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const accountSchema = coreSchema.extend({
|
|
33
|
+
providerId: z__namespace.string(),
|
|
34
|
+
accountId: z__namespace.string(),
|
|
35
|
+
userId: z__namespace.coerce.string(),
|
|
36
|
+
accessToken: z__namespace.string().nullish(),
|
|
37
|
+
refreshToken: z__namespace.string().nullish(),
|
|
38
|
+
idToken: z__namespace.string().nullish(),
|
|
39
|
+
/**
|
|
40
|
+
* Access token expires at
|
|
41
|
+
*/
|
|
42
|
+
accessTokenExpiresAt: z__namespace.date().nullish(),
|
|
43
|
+
/**
|
|
44
|
+
* Refresh token expires at
|
|
45
|
+
*/
|
|
46
|
+
refreshTokenExpiresAt: z__namespace.date().nullish(),
|
|
47
|
+
/**
|
|
48
|
+
* The scopes that the user has authorized
|
|
49
|
+
*/
|
|
50
|
+
scope: z__namespace.string().nullish(),
|
|
51
|
+
/**
|
|
52
|
+
* Password is only stored in the credential provider
|
|
53
|
+
*/
|
|
54
|
+
password: z__namespace.string().nullish()
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const sessionSchema = coreSchema.extend({
|
|
58
|
+
userId: z__namespace.coerce.string(),
|
|
59
|
+
expiresAt: z__namespace.date(),
|
|
60
|
+
token: z__namespace.string(),
|
|
61
|
+
ipAddress: z__namespace.string().nullish(),
|
|
62
|
+
userAgent: z__namespace.string().nullish()
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const verificationSchema = coreSchema.extend({
|
|
66
|
+
value: z__namespace.string(),
|
|
67
|
+
expiresAt: z__namespace.date(),
|
|
68
|
+
identifier: z__namespace.string()
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
exports.accountSchema = accountSchema;
|
|
72
|
+
exports.coreSchema = coreSchema;
|
|
73
|
+
exports.sessionSchema = sessionSchema;
|
|
74
|
+
exports.userSchema = userSchema;
|
|
75
|
+
exports.verificationSchema = verificationSchema;
|
package/dist/db/index.d.cts
CHANGED
|
@@ -1,111 +1,96 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.CnvFgghY.cjs';
|
|
2
|
+
import * as z from 'zod';
|
|
2
3
|
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @default true
|
|
11
|
-
*/
|
|
12
|
-
required?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* If the value should be returned on a response body.
|
|
15
|
-
* @default true
|
|
16
|
-
*/
|
|
17
|
-
returned?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* If a value should be provided when creating a new record.
|
|
20
|
-
* @default true
|
|
21
|
-
*/
|
|
22
|
-
input?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Default value for the field
|
|
25
|
-
*
|
|
26
|
-
* Note: This will not create a default value on the database level. It will only
|
|
27
|
-
* be used when creating a new record.
|
|
28
|
-
*/
|
|
29
|
-
defaultValue?: DBPrimitive | (() => DBPrimitive);
|
|
30
|
-
/**
|
|
31
|
-
* Update value for the field
|
|
32
|
-
*
|
|
33
|
-
* Note: This will create an onUpdate trigger on the database level for supported adapters.
|
|
34
|
-
* It will be called when updating a record.
|
|
35
|
-
*/
|
|
36
|
-
onUpdate?: () => DBPrimitive;
|
|
37
|
-
/**
|
|
38
|
-
* transform the value before storing it.
|
|
39
|
-
*/
|
|
40
|
-
transform?: {
|
|
41
|
-
input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
42
|
-
output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Reference to another model.
|
|
46
|
-
*/
|
|
47
|
-
references?: {
|
|
48
|
-
/**
|
|
49
|
-
* The model to reference.
|
|
50
|
-
*/
|
|
51
|
-
model: string;
|
|
52
|
-
/**
|
|
53
|
-
* The field on the referenced model.
|
|
54
|
-
*/
|
|
55
|
-
field: string;
|
|
56
|
-
/**
|
|
57
|
-
* The action to perform when the reference is deleted.
|
|
58
|
-
* @default "cascade"
|
|
59
|
-
*/
|
|
60
|
-
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
61
|
-
};
|
|
62
|
-
unique?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* If the field should be a bigint on the database instead of integer.
|
|
65
|
-
*/
|
|
66
|
-
bigint?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* A zod schema to validate the value.
|
|
69
|
-
*/
|
|
70
|
-
validator?: {
|
|
71
|
-
input?: ZodType;
|
|
72
|
-
output?: ZodType;
|
|
4
|
+
type BetterAuthPluginDBSchema = {
|
|
5
|
+
[table in string]: {
|
|
6
|
+
fields: {
|
|
7
|
+
[field in string]: DBFieldAttribute;
|
|
8
|
+
};
|
|
9
|
+
disableMigration?: boolean;
|
|
10
|
+
modelName?: string;
|
|
73
11
|
};
|
|
74
|
-
/**
|
|
75
|
-
* The name of the field on the database.
|
|
76
|
-
*/
|
|
77
|
-
fieldName?: string;
|
|
78
|
-
/**
|
|
79
|
-
* If the field should be sortable.
|
|
80
|
-
*
|
|
81
|
-
* applicable only for `text` type.
|
|
82
|
-
* It's useful to mark fields varchar instead of text.
|
|
83
|
-
*/
|
|
84
|
-
sortable?: boolean;
|
|
85
12
|
};
|
|
86
|
-
type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
|
|
87
|
-
type: T;
|
|
88
|
-
} & DBFieldAttributeConfig;
|
|
89
|
-
type BetterAuthDBSchema = Record<string, {
|
|
90
|
-
/**
|
|
91
|
-
* The name of the table in the database
|
|
92
|
-
*/
|
|
93
|
-
modelName: string;
|
|
94
|
-
/**
|
|
95
|
-
* The fields of the table
|
|
96
|
-
*/
|
|
97
|
-
fields: Record<string, DBFieldAttribute>;
|
|
98
|
-
/**
|
|
99
|
-
* Whether to disable migrations for this table
|
|
100
|
-
* @default false
|
|
101
|
-
*/
|
|
102
|
-
disableMigrations?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* The order of the table
|
|
105
|
-
*/
|
|
106
|
-
order?: number;
|
|
107
|
-
}>;
|
|
108
13
|
|
|
14
|
+
declare const coreSchema: z.ZodObject<{
|
|
15
|
+
id: z.ZodString;
|
|
16
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
17
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
|
|
20
|
+
declare const userSchema: z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
23
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
24
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
25
|
+
emailVerified: z.ZodDefault<z.ZodBoolean>;
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
/**
|
|
30
|
+
* User schema type used by better-auth, note that it's possible that user could have additional fields
|
|
31
|
+
*
|
|
32
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
33
|
+
*/
|
|
34
|
+
type User = z.infer<typeof userSchema>;
|
|
35
|
+
|
|
36
|
+
declare const accountSchema: z.ZodObject<{
|
|
37
|
+
id: z.ZodString;
|
|
38
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
39
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
40
|
+
providerId: z.ZodString;
|
|
41
|
+
accountId: z.ZodString;
|
|
42
|
+
userId: z.ZodCoercedString<unknown>;
|
|
43
|
+
accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
44
|
+
refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
+
idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
47
|
+
refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
48
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
49
|
+
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
/**
|
|
52
|
+
* Account schema type used by better-auth, note that it's possible that account could have additional fields
|
|
53
|
+
*
|
|
54
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
55
|
+
*/
|
|
56
|
+
type Account = z.infer<typeof accountSchema>;
|
|
57
|
+
|
|
58
|
+
declare const sessionSchema: z.ZodObject<{
|
|
59
|
+
id: z.ZodString;
|
|
60
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
61
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
62
|
+
userId: z.ZodCoercedString<unknown>;
|
|
63
|
+
expiresAt: z.ZodDate;
|
|
64
|
+
token: z.ZodString;
|
|
65
|
+
ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
66
|
+
userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
/**
|
|
69
|
+
* Session schema type used by better-auth, note that it's possible that session could have additional fields
|
|
70
|
+
*
|
|
71
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
72
|
+
*/
|
|
73
|
+
type Session = z.infer<typeof sessionSchema>;
|
|
74
|
+
|
|
75
|
+
declare const verificationSchema: z.ZodObject<{
|
|
76
|
+
id: z.ZodString;
|
|
77
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
78
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
79
|
+
value: z.ZodString;
|
|
80
|
+
expiresAt: z.ZodDate;
|
|
81
|
+
identifier: z.ZodString;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
/**
|
|
84
|
+
* Verification schema type used by better-auth, note that it's possible that verification could have additional fields
|
|
85
|
+
*
|
|
86
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
87
|
+
*/
|
|
88
|
+
type Verification = z.infer<typeof verificationSchema>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
92
|
+
*/
|
|
93
|
+
type AuthPluginSchema = BetterAuthPluginDBSchema;
|
|
109
94
|
/**
|
|
110
95
|
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
111
96
|
*/
|
|
@@ -127,4 +112,5 @@ type Primitive = DBPrimitive;
|
|
|
127
112
|
*/
|
|
128
113
|
type BetterAuthDbSchema = BetterAuthDBSchema;
|
|
129
114
|
|
|
130
|
-
export
|
|
115
|
+
export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema };
|
|
116
|
+
export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, Session, User, Verification };
|
package/dist/db/index.d.mts
CHANGED
|
@@ -1,111 +1,96 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.CnvFgghY.mjs';
|
|
2
|
+
import * as z from 'zod';
|
|
2
3
|
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @default true
|
|
11
|
-
*/
|
|
12
|
-
required?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* If the value should be returned on a response body.
|
|
15
|
-
* @default true
|
|
16
|
-
*/
|
|
17
|
-
returned?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* If a value should be provided when creating a new record.
|
|
20
|
-
* @default true
|
|
21
|
-
*/
|
|
22
|
-
input?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Default value for the field
|
|
25
|
-
*
|
|
26
|
-
* Note: This will not create a default value on the database level. It will only
|
|
27
|
-
* be used when creating a new record.
|
|
28
|
-
*/
|
|
29
|
-
defaultValue?: DBPrimitive | (() => DBPrimitive);
|
|
30
|
-
/**
|
|
31
|
-
* Update value for the field
|
|
32
|
-
*
|
|
33
|
-
* Note: This will create an onUpdate trigger on the database level for supported adapters.
|
|
34
|
-
* It will be called when updating a record.
|
|
35
|
-
*/
|
|
36
|
-
onUpdate?: () => DBPrimitive;
|
|
37
|
-
/**
|
|
38
|
-
* transform the value before storing it.
|
|
39
|
-
*/
|
|
40
|
-
transform?: {
|
|
41
|
-
input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
42
|
-
output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Reference to another model.
|
|
46
|
-
*/
|
|
47
|
-
references?: {
|
|
48
|
-
/**
|
|
49
|
-
* The model to reference.
|
|
50
|
-
*/
|
|
51
|
-
model: string;
|
|
52
|
-
/**
|
|
53
|
-
* The field on the referenced model.
|
|
54
|
-
*/
|
|
55
|
-
field: string;
|
|
56
|
-
/**
|
|
57
|
-
* The action to perform when the reference is deleted.
|
|
58
|
-
* @default "cascade"
|
|
59
|
-
*/
|
|
60
|
-
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
61
|
-
};
|
|
62
|
-
unique?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* If the field should be a bigint on the database instead of integer.
|
|
65
|
-
*/
|
|
66
|
-
bigint?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* A zod schema to validate the value.
|
|
69
|
-
*/
|
|
70
|
-
validator?: {
|
|
71
|
-
input?: ZodType;
|
|
72
|
-
output?: ZodType;
|
|
4
|
+
type BetterAuthPluginDBSchema = {
|
|
5
|
+
[table in string]: {
|
|
6
|
+
fields: {
|
|
7
|
+
[field in string]: DBFieldAttribute;
|
|
8
|
+
};
|
|
9
|
+
disableMigration?: boolean;
|
|
10
|
+
modelName?: string;
|
|
73
11
|
};
|
|
74
|
-
/**
|
|
75
|
-
* The name of the field on the database.
|
|
76
|
-
*/
|
|
77
|
-
fieldName?: string;
|
|
78
|
-
/**
|
|
79
|
-
* If the field should be sortable.
|
|
80
|
-
*
|
|
81
|
-
* applicable only for `text` type.
|
|
82
|
-
* It's useful to mark fields varchar instead of text.
|
|
83
|
-
*/
|
|
84
|
-
sortable?: boolean;
|
|
85
12
|
};
|
|
86
|
-
type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
|
|
87
|
-
type: T;
|
|
88
|
-
} & DBFieldAttributeConfig;
|
|
89
|
-
type BetterAuthDBSchema = Record<string, {
|
|
90
|
-
/**
|
|
91
|
-
* The name of the table in the database
|
|
92
|
-
*/
|
|
93
|
-
modelName: string;
|
|
94
|
-
/**
|
|
95
|
-
* The fields of the table
|
|
96
|
-
*/
|
|
97
|
-
fields: Record<string, DBFieldAttribute>;
|
|
98
|
-
/**
|
|
99
|
-
* Whether to disable migrations for this table
|
|
100
|
-
* @default false
|
|
101
|
-
*/
|
|
102
|
-
disableMigrations?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* The order of the table
|
|
105
|
-
*/
|
|
106
|
-
order?: number;
|
|
107
|
-
}>;
|
|
108
13
|
|
|
14
|
+
declare const coreSchema: z.ZodObject<{
|
|
15
|
+
id: z.ZodString;
|
|
16
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
17
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
|
|
20
|
+
declare const userSchema: z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
23
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
24
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
25
|
+
emailVerified: z.ZodDefault<z.ZodBoolean>;
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
/**
|
|
30
|
+
* User schema type used by better-auth, note that it's possible that user could have additional fields
|
|
31
|
+
*
|
|
32
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
33
|
+
*/
|
|
34
|
+
type User = z.infer<typeof userSchema>;
|
|
35
|
+
|
|
36
|
+
declare const accountSchema: z.ZodObject<{
|
|
37
|
+
id: z.ZodString;
|
|
38
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
39
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
40
|
+
providerId: z.ZodString;
|
|
41
|
+
accountId: z.ZodString;
|
|
42
|
+
userId: z.ZodCoercedString<unknown>;
|
|
43
|
+
accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
44
|
+
refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
+
idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
47
|
+
refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
48
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
49
|
+
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
/**
|
|
52
|
+
* Account schema type used by better-auth, note that it's possible that account could have additional fields
|
|
53
|
+
*
|
|
54
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
55
|
+
*/
|
|
56
|
+
type Account = z.infer<typeof accountSchema>;
|
|
57
|
+
|
|
58
|
+
declare const sessionSchema: z.ZodObject<{
|
|
59
|
+
id: z.ZodString;
|
|
60
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
61
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
62
|
+
userId: z.ZodCoercedString<unknown>;
|
|
63
|
+
expiresAt: z.ZodDate;
|
|
64
|
+
token: z.ZodString;
|
|
65
|
+
ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
66
|
+
userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
/**
|
|
69
|
+
* Session schema type used by better-auth, note that it's possible that session could have additional fields
|
|
70
|
+
*
|
|
71
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
72
|
+
*/
|
|
73
|
+
type Session = z.infer<typeof sessionSchema>;
|
|
74
|
+
|
|
75
|
+
declare const verificationSchema: z.ZodObject<{
|
|
76
|
+
id: z.ZodString;
|
|
77
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
78
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
79
|
+
value: z.ZodString;
|
|
80
|
+
expiresAt: z.ZodDate;
|
|
81
|
+
identifier: z.ZodString;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
/**
|
|
84
|
+
* Verification schema type used by better-auth, note that it's possible that verification could have additional fields
|
|
85
|
+
*
|
|
86
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
87
|
+
*/
|
|
88
|
+
type Verification = z.infer<typeof verificationSchema>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
92
|
+
*/
|
|
93
|
+
type AuthPluginSchema = BetterAuthPluginDBSchema;
|
|
109
94
|
/**
|
|
110
95
|
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
111
96
|
*/
|
|
@@ -127,4 +112,5 @@ type Primitive = DBPrimitive;
|
|
|
127
112
|
*/
|
|
128
113
|
type BetterAuthDbSchema = BetterAuthDBSchema;
|
|
129
114
|
|
|
130
|
-
export
|
|
115
|
+
export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema };
|
|
116
|
+
export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, Session, User, Verification };
|