@better-auth/core 1.3.23 → 1.3.24

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.
@@ -1,21 +1,22 @@
1
1
 
2
- > @better-auth/core@1.3.23 build /home/runner/work/better-auth/better-auth/packages/core
2
+ > @better-auth/core@1.3.24 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/db/index.cjs (total size: 15 B, chunk size: 15 B)
15
18
  [log] dist/index.mjs (total size: 1 B, chunk size: 1 B)
16
19
 
17
- Σ Total dist size (byte size): 55 B
20
+ [log] dist/db/index.mjs (total size: 1 B, chunk size: 1 B)
21
+ Σ Total dist size (byte size): 11.1 kB
18
22
  [log]
19
- [warn] Build is done with some warnings:
20
-
21
- - Potential missing package.json files: dist/index.d.cjs
package/build.config.ts CHANGED
@@ -8,5 +8,5 @@ export default defineBuildConfig({
8
8
  outDir: "dist",
9
9
  clean: true,
10
10
  failOnWarn: false,
11
- entries: ["./src/index.ts"],
11
+ entries: ["./src/index.ts", "./src/db/index.ts"],
12
12
  });
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -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.23",
3
+ "version": "1.3.24",
4
4
  "description": "The most comprehensive authentication library for TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -12,21 +12,38 @@
12
12
  "default": "./dist/index.mjs"
13
13
  },
14
14
  "require": {
15
- "types": "./dist/index.d.cjs",
15
+ "types": "./dist/index.d.cts",
16
16
  "default": "./dist/index.cjs"
17
17
  }
18
+ },
19
+ "./db": {
20
+ "import": {
21
+ "types": "./dist/db/index.d.ts",
22
+ "default": "./dist/db/index.mjs"
23
+ },
24
+ "require": {
25
+ "types": "./dist/db/index.d.cts",
26
+ "default": "./dist/db/index.cjs"
27
+ }
18
28
  }
19
29
  },
20
30
  "typesVersions": {
21
31
  "*": {
22
32
  "index": [
23
33
  "dist/index.d.ts"
34
+ ],
35
+ "db": [
36
+ "dist/db.d.ts"
24
37
  ]
25
38
  }
26
39
  },
27
40
  "devDependencies": {
28
41
  "unbuild": "3.6.1"
29
42
  },
43
+ "dependencies": {
44
+ "better-call": "1.0.19",
45
+ "zod": "^4.1.5"
46
+ },
30
47
  "scripts": {
31
48
  "build": "unbuild --clean",
32
49
  "stub": "unbuild --stub",
@@ -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";