@better-auth/core 1.3.23 → 1.3.25
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 -5
- package/build.config.ts +5 -1
- package/dist/async_hooks/index.cjs +27 -0
- package/dist/async_hooks/index.d.cts +10 -0
- package/dist/async_hooks/index.d.mts +10 -0
- package/dist/async_hooks/index.d.ts +10 -0
- package/dist/async_hooks/index.mjs +25 -0
- package/dist/db/index.cjs +2 -0
- package/dist/db/index.d.cts +130 -0
- package/dist/db/index.d.mts +130 -0
- package/dist/db/index.d.ts +130 -0
- package/dist/db/index.mjs +1 -0
- package/package.json +32 -2
- package/src/async_hooks/index.ts +43 -0
- package/src/db/index.ts +36 -0
- package/src/db/type.ts +133 -0
- package/src/types/helper.ts +1 -0
- package/src/types/index.ts +1 -0
- package/tsconfig.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/core@1.3.
|
|
2
|
+
> @better-auth/core@1.3.25 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".
|
|
8
9
|
Generated an empty chunk: "index".
|
|
10
|
+
Generated an empty chunk: "db/index".
|
|
9
11
|
Generated an empty chunk: "index".
|
|
10
12
|
Generated an empty chunk: "index".
|
|
11
13
|
Generated an empty chunk: "index".
|
|
12
14
|
[success] Build succeeded for core
|
|
13
15
|
[log] dist/index.cjs (total size: 15 B, chunk size: 15 B)
|
|
14
16
|
|
|
17
|
+
[log] dist/async_hooks/index.cjs (total size: 922 B, chunk size: 922 B, exports: getAsyncLocalStorage)
|
|
18
|
+
|
|
19
|
+
[log] dist/db/index.cjs (total size: 15 B, chunk size: 15 B)
|
|
15
20
|
[log] dist/index.mjs (total size: 1 B, chunk size: 1 B)
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
[log]
|
|
19
|
-
[warn] Build is done with some warnings:
|
|
22
|
+
[log] dist/async_hooks/index.mjs (total size: 887 B, chunk size: 887 B, exports: getAsyncLocalStorage)
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
[log] dist/db/index.mjs (total size: 1 B, chunk size: 1 B)
|
|
25
|
+
Σ Total dist size (byte size): 13.8 kB
|
|
26
|
+
[log]
|
package/build.config.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let moduleName = "node:async_hooks";
|
|
4
|
+
const AsyncLocalStoragePromise = import(
|
|
5
|
+
/* @vite-ignore */
|
|
6
|
+
/* webpackIgnore: true */
|
|
7
|
+
moduleName
|
|
8
|
+
).then((mod) => mod.AsyncLocalStorage).catch((err) => {
|
|
9
|
+
if ("AsyncLocalStorage" in globalThis) {
|
|
10
|
+
return globalThis.AsyncLocalStorage;
|
|
11
|
+
}
|
|
12
|
+
console.warn(
|
|
13
|
+
"[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected."
|
|
14
|
+
);
|
|
15
|
+
console.warn(
|
|
16
|
+
"[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler"
|
|
17
|
+
);
|
|
18
|
+
console.warn(
|
|
19
|
+
"[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag"
|
|
20
|
+
);
|
|
21
|
+
throw err;
|
|
22
|
+
});
|
|
23
|
+
async function getAsyncLocalStorage() {
|
|
24
|
+
return AsyncLocalStoragePromise;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.getAsyncLocalStorage = getAsyncLocalStorage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
export { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AsyncLocalStorage will be import directly in 1.5.x
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
|
|
9
|
+
|
|
10
|
+
export { getAsyncLocalStorage };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
export { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AsyncLocalStorage will be import directly in 1.5.x
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
|
|
9
|
+
|
|
10
|
+
export { getAsyncLocalStorage };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
export { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AsyncLocalStorage will be import directly in 1.5.x
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
|
|
9
|
+
|
|
10
|
+
export { getAsyncLocalStorage };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
let moduleName = "node:async_hooks";
|
|
2
|
+
const AsyncLocalStoragePromise = import(
|
|
3
|
+
/* @vite-ignore */
|
|
4
|
+
/* webpackIgnore: true */
|
|
5
|
+
moduleName
|
|
6
|
+
).then((mod) => mod.AsyncLocalStorage).catch((err) => {
|
|
7
|
+
if ("AsyncLocalStorage" in globalThis) {
|
|
8
|
+
return globalThis.AsyncLocalStorage;
|
|
9
|
+
}
|
|
10
|
+
console.warn(
|
|
11
|
+
"[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected."
|
|
12
|
+
);
|
|
13
|
+
console.warn(
|
|
14
|
+
"[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler"
|
|
15
|
+
);
|
|
16
|
+
console.warn(
|
|
17
|
+
"[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag"
|
|
18
|
+
);
|
|
19
|
+
throw err;
|
|
20
|
+
});
|
|
21
|
+
async function getAsyncLocalStorage() {
|
|
22
|
+
return AsyncLocalStoragePromise;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { getAsyncLocalStorage };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
|
|
3
|
+
type LiteralString = "" | (string & Record<never, never>);
|
|
4
|
+
|
|
5
|
+
type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
|
|
6
|
+
type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
|
|
7
|
+
type DBFieldAttributeConfig = {
|
|
8
|
+
/**
|
|
9
|
+
* If the field should be required on a new record.
|
|
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;
|
|
73
|
+
};
|
|
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
|
+
};
|
|
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
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
111
|
+
*/
|
|
112
|
+
type FieldAttribute = DBFieldAttribute;
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
115
|
+
*/
|
|
116
|
+
type FieldAttributeConfig = DBFieldAttributeConfig;
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
119
|
+
*/
|
|
120
|
+
type FieldType = DBFieldType;
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
123
|
+
*/
|
|
124
|
+
type Primitive = DBPrimitive;
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
127
|
+
*/
|
|
128
|
+
type BetterAuthDbSchema = BetterAuthDBSchema;
|
|
129
|
+
|
|
130
|
+
export type { BetterAuthDBSchema, BetterAuthDbSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, Primitive };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
|
|
3
|
+
type LiteralString = "" | (string & Record<never, never>);
|
|
4
|
+
|
|
5
|
+
type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
|
|
6
|
+
type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
|
|
7
|
+
type DBFieldAttributeConfig = {
|
|
8
|
+
/**
|
|
9
|
+
* If the field should be required on a new record.
|
|
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;
|
|
73
|
+
};
|
|
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
|
+
};
|
|
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
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
111
|
+
*/
|
|
112
|
+
type FieldAttribute = DBFieldAttribute;
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
115
|
+
*/
|
|
116
|
+
type FieldAttributeConfig = DBFieldAttributeConfig;
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
119
|
+
*/
|
|
120
|
+
type FieldType = DBFieldType;
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
123
|
+
*/
|
|
124
|
+
type Primitive = DBPrimitive;
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
127
|
+
*/
|
|
128
|
+
type BetterAuthDbSchema = BetterAuthDBSchema;
|
|
129
|
+
|
|
130
|
+
export type { BetterAuthDBSchema, BetterAuthDbSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, Primitive };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
|
|
3
|
+
type LiteralString = "" | (string & Record<never, never>);
|
|
4
|
+
|
|
5
|
+
type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
|
|
6
|
+
type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
|
|
7
|
+
type DBFieldAttributeConfig = {
|
|
8
|
+
/**
|
|
9
|
+
* If the field should be required on a new record.
|
|
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;
|
|
73
|
+
};
|
|
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
|
+
};
|
|
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
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
111
|
+
*/
|
|
112
|
+
type FieldAttribute = DBFieldAttribute;
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
115
|
+
*/
|
|
116
|
+
type FieldAttributeConfig = DBFieldAttributeConfig;
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
119
|
+
*/
|
|
120
|
+
type FieldType = DBFieldType;
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
123
|
+
*/
|
|
124
|
+
type Primitive = DBPrimitive;
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
127
|
+
*/
|
|
128
|
+
type BetterAuthDbSchema = BetterAuthDBSchema;
|
|
129
|
+
|
|
130
|
+
export type { BetterAuthDBSchema, BetterAuthDbSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, Primitive };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/core",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.25",
|
|
4
4
|
"description": "The most comprehensive authentication library for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -12,21 +12,51 @@
|
|
|
12
12
|
"default": "./dist/index.mjs"
|
|
13
13
|
},
|
|
14
14
|
"require": {
|
|
15
|
-
"types": "./dist/index.d.
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
16
|
"default": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
|
+
},
|
|
19
|
+
"./async_hooks": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/async_hooks/index.d.ts",
|
|
22
|
+
"default": "./dist/async_hooks/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/async_hooks/index.d.cts",
|
|
26
|
+
"default": "./dist/async_hooks/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"./db": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/db/index.d.ts",
|
|
32
|
+
"default": "./dist/db/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/db/index.d.cts",
|
|
36
|
+
"default": "./dist/db/index.cjs"
|
|
37
|
+
}
|
|
18
38
|
}
|
|
19
39
|
},
|
|
20
40
|
"typesVersions": {
|
|
21
41
|
"*": {
|
|
22
42
|
"index": [
|
|
23
43
|
"dist/index.d.ts"
|
|
44
|
+
],
|
|
45
|
+
"async_hooks": [
|
|
46
|
+
"dist/async_hooks.d.ts"
|
|
47
|
+
],
|
|
48
|
+
"db": [
|
|
49
|
+
"dist/db.d.ts"
|
|
24
50
|
]
|
|
25
51
|
}
|
|
26
52
|
},
|
|
27
53
|
"devDependencies": {
|
|
28
54
|
"unbuild": "3.6.1"
|
|
29
55
|
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"better-call": "1.0.19",
|
|
58
|
+
"zod": "^4.1.5"
|
|
59
|
+
},
|
|
30
60
|
"scripts": {
|
|
31
61
|
"build": "unbuild --clean",
|
|
32
62
|
"stub": "unbuild --stub",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncLocalStorage will be import directly in 1.5.x
|
|
3
|
+
*/
|
|
4
|
+
import type { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
|
|
6
|
+
// We only export the type here to avoid issues in environments where AsyncLocalStorage is not available.
|
|
7
|
+
export type { AsyncLocalStorage };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Dynamically import AsyncLocalStorage to avoid issues in environments where it's not available.
|
|
11
|
+
*
|
|
12
|
+
* Right now, this is primarily for Cloudflare Workers.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
let moduleName: string = "node:async_hooks";
|
|
16
|
+
|
|
17
|
+
const AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage> = import(
|
|
18
|
+
/* @vite-ignore */
|
|
19
|
+
/* webpackIgnore: true */
|
|
20
|
+
moduleName
|
|
21
|
+
)
|
|
22
|
+
.then((mod) => mod.AsyncLocalStorage)
|
|
23
|
+
.catch((err) => {
|
|
24
|
+
if ("AsyncLocalStorage" in globalThis) {
|
|
25
|
+
return (globalThis as any).AsyncLocalStorage;
|
|
26
|
+
}
|
|
27
|
+
console.warn(
|
|
28
|
+
"[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.",
|
|
29
|
+
);
|
|
30
|
+
console.warn(
|
|
31
|
+
"[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler",
|
|
32
|
+
);
|
|
33
|
+
console.warn(
|
|
34
|
+
"[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag",
|
|
35
|
+
);
|
|
36
|
+
throw err;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export async function getAsyncLocalStorage(): Promise<
|
|
40
|
+
typeof AsyncLocalStorage
|
|
41
|
+
> {
|
|
42
|
+
return AsyncLocalStoragePromise;
|
|
43
|
+
}
|
package/src/db/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DBFieldAttribute,
|
|
3
|
+
DBFieldAttributeConfig,
|
|
4
|
+
DBFieldType,
|
|
5
|
+
DBPrimitive,
|
|
6
|
+
BetterAuthDBSchema,
|
|
7
|
+
} from "./type";
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
DBFieldAttribute,
|
|
11
|
+
DBFieldAttributeConfig,
|
|
12
|
+
DBFieldType,
|
|
13
|
+
DBPrimitive,
|
|
14
|
+
BetterAuthDBSchema,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
19
|
+
*/
|
|
20
|
+
export type FieldAttribute = DBFieldAttribute;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
23
|
+
*/
|
|
24
|
+
export type FieldAttributeConfig = DBFieldAttributeConfig;
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
27
|
+
*/
|
|
28
|
+
export type FieldType = DBFieldType;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
31
|
+
*/
|
|
32
|
+
export type Primitive = DBPrimitive;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
35
|
+
*/
|
|
36
|
+
export type BetterAuthDbSchema = BetterAuthDBSchema;
|
package/src/db/type.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
2
|
+
import type { LiteralString } from "../types";
|
|
3
|
+
|
|
4
|
+
export type DBFieldType =
|
|
5
|
+
| "string"
|
|
6
|
+
| "number"
|
|
7
|
+
| "boolean"
|
|
8
|
+
| "date"
|
|
9
|
+
| "json"
|
|
10
|
+
| `${"string" | "number"}[]`
|
|
11
|
+
| Array<LiteralString>;
|
|
12
|
+
|
|
13
|
+
export type DBPrimitive =
|
|
14
|
+
| string
|
|
15
|
+
| number
|
|
16
|
+
| boolean
|
|
17
|
+
| Date
|
|
18
|
+
| null
|
|
19
|
+
| undefined
|
|
20
|
+
| string[]
|
|
21
|
+
| number[];
|
|
22
|
+
|
|
23
|
+
export type DBFieldAttributeConfig = {
|
|
24
|
+
/**
|
|
25
|
+
* If the field should be required on a new record.
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
required?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* If the value should be returned on a response body.
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
returned?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* If a value should be provided when creating a new record.
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
input?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Default value for the field
|
|
41
|
+
*
|
|
42
|
+
* Note: This will not create a default value on the database level. It will only
|
|
43
|
+
* be used when creating a new record.
|
|
44
|
+
*/
|
|
45
|
+
defaultValue?: DBPrimitive | (() => DBPrimitive);
|
|
46
|
+
/**
|
|
47
|
+
* Update value for the field
|
|
48
|
+
*
|
|
49
|
+
* Note: This will create an onUpdate trigger on the database level for supported adapters.
|
|
50
|
+
* It will be called when updating a record.
|
|
51
|
+
*/
|
|
52
|
+
onUpdate?: () => DBPrimitive;
|
|
53
|
+
/**
|
|
54
|
+
* transform the value before storing it.
|
|
55
|
+
*/
|
|
56
|
+
transform?: {
|
|
57
|
+
input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
58
|
+
output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Reference to another model.
|
|
62
|
+
*/
|
|
63
|
+
references?: {
|
|
64
|
+
/**
|
|
65
|
+
* The model to reference.
|
|
66
|
+
*/
|
|
67
|
+
model: string;
|
|
68
|
+
/**
|
|
69
|
+
* The field on the referenced model.
|
|
70
|
+
*/
|
|
71
|
+
field: string;
|
|
72
|
+
/**
|
|
73
|
+
* The action to perform when the reference is deleted.
|
|
74
|
+
* @default "cascade"
|
|
75
|
+
*/
|
|
76
|
+
onDelete?:
|
|
77
|
+
| "no action"
|
|
78
|
+
| "restrict"
|
|
79
|
+
| "cascade"
|
|
80
|
+
| "set null"
|
|
81
|
+
| "set default";
|
|
82
|
+
};
|
|
83
|
+
unique?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* If the field should be a bigint on the database instead of integer.
|
|
86
|
+
*/
|
|
87
|
+
bigint?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* A zod schema to validate the value.
|
|
90
|
+
*/
|
|
91
|
+
validator?: {
|
|
92
|
+
input?: ZodType;
|
|
93
|
+
output?: ZodType;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The name of the field on the database.
|
|
97
|
+
*/
|
|
98
|
+
fieldName?: string;
|
|
99
|
+
/**
|
|
100
|
+
* If the field should be sortable.
|
|
101
|
+
*
|
|
102
|
+
* applicable only for `text` type.
|
|
103
|
+
* It's useful to mark fields varchar instead of text.
|
|
104
|
+
*/
|
|
105
|
+
sortable?: boolean;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
|
|
109
|
+
type: T;
|
|
110
|
+
} & DBFieldAttributeConfig;
|
|
111
|
+
|
|
112
|
+
export type BetterAuthDBSchema = Record<
|
|
113
|
+
string,
|
|
114
|
+
{
|
|
115
|
+
/**
|
|
116
|
+
* The name of the table in the database
|
|
117
|
+
*/
|
|
118
|
+
modelName: string;
|
|
119
|
+
/**
|
|
120
|
+
* The fields of the table
|
|
121
|
+
*/
|
|
122
|
+
fields: Record<string, DBFieldAttribute>;
|
|
123
|
+
/**
|
|
124
|
+
* Whether to disable migrations for this table
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
disableMigrations?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* The order of the table
|
|
130
|
+
*/
|
|
131
|
+
order?: number;
|
|
132
|
+
}
|
|
133
|
+
>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type LiteralString = "" | (string & Record<never, never>);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./helper";
|