@better-auth/core 1.4.12-beta.2 → 1.4.13
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 +172 -35
- package/dist/api/index.d.mts +178 -1
- package/dist/api/index.mjs +2 -1
- package/dist/context/endpoint-context.d.mts +19 -0
- package/dist/context/endpoint-context.mjs +31 -0
- package/dist/context/global.d.mts +7 -0
- package/dist/context/global.mjs +37 -0
- package/dist/context/index.d.mts +5 -53
- package/dist/context/index.mjs +5 -2
- package/dist/context/request-state.d.mts +27 -0
- package/dist/context/request-state.mjs +49 -0
- package/dist/context/transaction.d.mts +16 -0
- package/dist/context/transaction.mjs +52 -0
- package/dist/db/adapter/factory.d.mts +27 -0
- package/dist/db/adapter/factory.mjs +738 -0
- package/dist/db/adapter/get-default-field-name.d.mts +18 -0
- package/dist/db/adapter/get-default-field-name.mjs +38 -0
- package/dist/db/adapter/get-default-model-name.d.mts +12 -0
- package/dist/db/adapter/get-default-model-name.mjs +32 -0
- package/dist/db/adapter/get-field-attributes.d.mts +29 -0
- package/dist/db/adapter/get-field-attributes.mjs +39 -0
- package/dist/db/adapter/get-field-name.d.mts +18 -0
- package/dist/db/adapter/get-field-name.mjs +33 -0
- package/dist/db/adapter/get-id-field.d.mts +39 -0
- package/dist/db/adapter/get-id-field.mjs +68 -0
- package/dist/db/adapter/get-model-name.d.mts +12 -0
- package/dist/db/adapter/get-model-name.mjs +23 -0
- package/dist/db/adapter/index.d.mts +513 -1
- package/dist/db/adapter/index.mjs +8 -970
- package/dist/db/adapter/types.d.mts +139 -0
- package/dist/db/adapter/utils.d.mts +7 -0
- package/dist/db/adapter/utils.mjs +38 -0
- package/dist/db/get-tables.d.mts +8 -0
- package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +1 -1
- package/dist/db/index.d.mts +10 -2
- package/dist/db/index.mjs +7 -60
- package/dist/db/plugin.d.mts +12 -0
- package/dist/db/schema/account.d.mts +26 -0
- package/dist/db/schema/account.mjs +19 -0
- package/dist/db/schema/rate-limit.d.mts +14 -0
- package/dist/db/schema/rate-limit.mjs +11 -0
- package/dist/db/schema/session.d.mts +21 -0
- package/dist/db/schema/session.mjs +14 -0
- package/dist/db/schema/shared.d.mts +10 -0
- package/dist/db/schema/shared.mjs +11 -0
- package/dist/db/schema/user.d.mts +20 -0
- package/dist/db/schema/user.mjs +13 -0
- package/dist/db/schema/verification.d.mts +19 -0
- package/dist/db/schema/verification.mjs +12 -0
- package/dist/db/type.d.mts +143 -0
- package/dist/env/color-depth.d.mts +4 -0
- package/dist/env/color-depth.mjs +88 -0
- package/dist/env/env-impl.d.mts +32 -0
- package/dist/env/env-impl.mjs +82 -0
- package/dist/env/index.d.mts +4 -2
- package/dist/env/index.mjs +3 -1
- package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
- package/dist/env/logger.mjs +81 -0
- package/dist/error/codes.d.mts +48 -0
- package/dist/{error-DP1xOn7P.mjs → error/codes.mjs} +3 -14
- package/dist/error/index.d.mts +5 -48
- package/dist/error/index.mjs +12 -3
- package/dist/index.d.mts +8 -2
- package/dist/oauth2/client-credentials-token.d.mts +36 -0
- package/dist/oauth2/client-credentials-token.mjs +54 -0
- package/dist/oauth2/create-authorization-url.d.mts +45 -0
- package/dist/oauth2/create-authorization-url.mjs +42 -0
- package/dist/oauth2/index.d.mts +8 -2
- package/dist/oauth2/index.mjs +6 -2
- package/dist/oauth2/oauth-provider.d.mts +194 -0
- package/dist/oauth2/refresh-access-token.d.mts +36 -0
- package/dist/oauth2/refresh-access-token.mjs +58 -0
- package/dist/oauth2/utils.d.mts +7 -0
- package/dist/oauth2/utils.mjs +27 -0
- package/dist/oauth2/validate-authorization-code.d.mts +55 -0
- package/dist/oauth2/validate-authorization-code.mjs +71 -0
- package/dist/oauth2/verify.d.mts +49 -0
- package/dist/oauth2/verify.mjs +95 -0
- package/dist/social-providers/apple.d.mts +119 -0
- package/dist/social-providers/apple.mjs +102 -0
- package/dist/social-providers/atlassian.d.mts +72 -0
- package/dist/social-providers/atlassian.mjs +83 -0
- package/dist/social-providers/cognito.d.mts +87 -0
- package/dist/social-providers/cognito.mjs +166 -0
- package/dist/social-providers/discord.d.mts +126 -0
- package/dist/social-providers/discord.mjs +64 -0
- package/dist/social-providers/dropbox.d.mts +71 -0
- package/dist/social-providers/dropbox.mjs +75 -0
- package/dist/social-providers/facebook.d.mts +81 -0
- package/dist/social-providers/facebook.mjs +120 -0
- package/dist/social-providers/figma.d.mts +63 -0
- package/dist/social-providers/figma.mjs +84 -0
- package/dist/social-providers/github.d.mts +104 -0
- package/dist/social-providers/github.mjs +80 -0
- package/dist/social-providers/gitlab.d.mts +125 -0
- package/dist/social-providers/gitlab.mjs +82 -0
- package/dist/social-providers/google.d.mts +99 -0
- package/dist/social-providers/google.mjs +109 -0
- package/dist/social-providers/huggingface.d.mts +85 -0
- package/dist/social-providers/huggingface.mjs +75 -0
- package/dist/social-providers/index.d.mts +1723 -1
- package/dist/social-providers/index.mjs +33 -2570
- package/dist/social-providers/kakao.d.mts +163 -0
- package/dist/social-providers/kakao.mjs +72 -0
- package/dist/social-providers/kick.d.mts +75 -0
- package/dist/social-providers/kick.mjs +71 -0
- package/dist/social-providers/line.d.mts +107 -0
- package/dist/social-providers/line.mjs +113 -0
- package/dist/social-providers/linear.d.mts +70 -0
- package/dist/social-providers/linear.mjs +88 -0
- package/dist/social-providers/linkedin.d.mts +69 -0
- package/dist/social-providers/linkedin.mjs +76 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
- package/dist/social-providers/microsoft-entra-id.mjs +106 -0
- package/dist/social-providers/naver.d.mts +104 -0
- package/dist/social-providers/naver.mjs +67 -0
- package/dist/social-providers/notion.d.mts +66 -0
- package/dist/social-providers/notion.mjs +75 -0
- package/dist/social-providers/paybin.d.mts +73 -0
- package/dist/social-providers/paybin.mjs +85 -0
- package/dist/social-providers/paypal.d.mts +131 -0
- package/dist/social-providers/paypal.mjs +144 -0
- package/dist/social-providers/polar.d.mts +76 -0
- package/dist/social-providers/polar.mjs +73 -0
- package/dist/social-providers/reddit.d.mts +64 -0
- package/dist/social-providers/reddit.mjs +83 -0
- package/dist/social-providers/roblox.d.mts +72 -0
- package/dist/social-providers/roblox.mjs +59 -0
- package/dist/social-providers/salesforce.d.mts +81 -0
- package/dist/social-providers/salesforce.mjs +91 -0
- package/dist/social-providers/slack.d.mts +85 -0
- package/dist/social-providers/slack.mjs +68 -0
- package/dist/social-providers/spotify.d.mts +65 -0
- package/dist/social-providers/spotify.mjs +71 -0
- package/dist/social-providers/tiktok.d.mts +171 -0
- package/dist/social-providers/tiktok.mjs +62 -0
- package/dist/social-providers/twitch.d.mts +81 -0
- package/dist/social-providers/twitch.mjs +78 -0
- package/dist/social-providers/twitter.d.mts +140 -0
- package/dist/social-providers/twitter.mjs +87 -0
- package/dist/social-providers/vercel.d.mts +64 -0
- package/dist/social-providers/vercel.mjs +61 -0
- package/dist/social-providers/vk.d.mts +72 -0
- package/dist/social-providers/vk.mjs +83 -0
- package/dist/social-providers/zoom.d.mts +173 -0
- package/dist/social-providers/zoom.mjs +72 -0
- package/dist/types/context.d.mts +215 -0
- package/dist/types/cookie.d.mts +15 -0
- package/dist/types/helper.d.mts +8 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1266 -0
- package/dist/types/plugin-client.d.mts +103 -0
- package/dist/types/plugin.d.mts +121 -0
- package/dist/utils/deprecate.d.mts +10 -0
- package/dist/utils/deprecate.mjs +17 -0
- package/dist/utils/error-codes.d.mts +9 -0
- package/dist/utils/error-codes.mjs +7 -0
- package/dist/utils/id.d.mts +4 -0
- package/dist/utils/id.mjs +9 -0
- package/dist/utils/index.d.mts +5 -26
- package/dist/utils/index.mjs +5 -2
- package/dist/utils/json.d.mts +4 -0
- package/dist/utils/json.mjs +25 -0
- package/dist/utils/string.d.mts +4 -0
- package/dist/utils/string.mjs +7 -0
- package/package.json +1 -1
- package/src/context/endpoint-context.ts +7 -15
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +1 -0
- package/src/context/request-state.ts +7 -12
- package/src/context/transaction.ts +7 -16
- package/src/db/adapter/factory.ts +13 -13
- package/src/db/adapter/get-default-model-name.ts +1 -1
- package/src/db/adapter/get-id-field.ts +2 -2
- package/src/error/index.ts +2 -3
- package/src/social-providers/gitlab.ts +1 -1
- package/src/types/context.ts +137 -131
- package/src/types/cookie.ts +6 -4
- package/src/types/index.ts +2 -1
- package/tsdown.config.ts +9 -0
- package/dist/context-BGZ8V6DD.mjs +0 -126
- package/dist/env-DbssmzoK.mjs +0 -245
- package/dist/index-zgYuzZ7O.d.mts +0 -8020
- package/dist/oauth2-COJkghlT.mjs +0 -326
- package/dist/utils-U2L7n92V.mjs +0 -59
|
@@ -1,2 +1,514 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
import { initGetDefaultFieldName } from "./get-default-field-name.mjs";
|
|
3
|
+
import { initGetDefaultModelName } from "./get-default-model-name.mjs";
|
|
4
|
+
import { initGetFieldAttributes } from "./get-field-attributes.mjs";
|
|
5
|
+
import { initGetFieldName } from "./get-field-name.mjs";
|
|
6
|
+
import { initGetIdField } from "./get-id-field.mjs";
|
|
7
|
+
import { initGetModelName } from "./get-model-name.mjs";
|
|
8
|
+
import { AdapterConfig, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CreateAdapterOptions, CreateCustomAdapter } from "./types.mjs";
|
|
9
|
+
import { AdapterFactory, createAdapter, createAdapterFactory } from "./factory.mjs";
|
|
10
|
+
import { deepmerge, withApplyDefault } from "./utils.mjs";
|
|
11
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
12
|
+
import "../../types/index.mjs";
|
|
13
|
+
|
|
14
|
+
//#region src/db/adapter/index.d.ts
|
|
15
|
+
type DBAdapterDebugLogOption = boolean | {
|
|
16
|
+
/**
|
|
17
|
+
* Useful when you want to log only certain conditions.
|
|
18
|
+
*/
|
|
19
|
+
logCondition?: (() => boolean) | undefined;
|
|
20
|
+
create?: boolean | undefined;
|
|
21
|
+
update?: boolean | undefined;
|
|
22
|
+
updateMany?: boolean | undefined;
|
|
23
|
+
findOne?: boolean | undefined;
|
|
24
|
+
findMany?: boolean | undefined;
|
|
25
|
+
delete?: boolean | undefined;
|
|
26
|
+
deleteMany?: boolean | undefined;
|
|
27
|
+
count?: boolean | undefined;
|
|
28
|
+
} | {
|
|
29
|
+
/**
|
|
30
|
+
* Only used for adapter tests to show debug logs if a test fails.
|
|
31
|
+
*
|
|
32
|
+
* @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
|
|
33
|
+
*/
|
|
34
|
+
isRunningAdapterTests: boolean;
|
|
35
|
+
};
|
|
36
|
+
type DBAdapterSchemaCreation = {
|
|
37
|
+
/**
|
|
38
|
+
* Code to be inserted into the file
|
|
39
|
+
*/
|
|
40
|
+
code: string;
|
|
41
|
+
/**
|
|
42
|
+
* Path to the file, including the file name and extension.
|
|
43
|
+
* Relative paths are supported, with the current working directory of the developer's project as the base.
|
|
44
|
+
*/
|
|
45
|
+
path: string;
|
|
46
|
+
/**
|
|
47
|
+
* Append the file if it already exists.
|
|
48
|
+
* Note: This will not apply if `overwrite` is set to true.
|
|
49
|
+
*/
|
|
50
|
+
append?: boolean | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Overwrite the file if it already exists
|
|
53
|
+
*/
|
|
54
|
+
overwrite?: boolean | undefined;
|
|
55
|
+
};
|
|
56
|
+
interface DBAdapterFactoryConfig<Options extends BetterAuthOptions = BetterAuthOptions> {
|
|
57
|
+
/**
|
|
58
|
+
* Use plural table names.
|
|
59
|
+
*
|
|
60
|
+
* All tables will be named with an `s` at the end.
|
|
61
|
+
*
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
usePlural?: boolean | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Enable debug logs.
|
|
67
|
+
*
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
debugLogs?: DBAdapterDebugLogOption | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Name of the adapter.
|
|
73
|
+
*
|
|
74
|
+
* This is used to identify the adapter in the debug logs.
|
|
75
|
+
*
|
|
76
|
+
* @default `adapterId`
|
|
77
|
+
*/
|
|
78
|
+
adapterName?: string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Adapter id
|
|
81
|
+
*/
|
|
82
|
+
adapterId: string;
|
|
83
|
+
/**
|
|
84
|
+
* If the database supports numeric ids, set this to `true`.
|
|
85
|
+
*
|
|
86
|
+
* @default true
|
|
87
|
+
*/
|
|
88
|
+
supportsNumericIds?: boolean | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* If the database supports natively generating UUIDs, set this to `true`.
|
|
91
|
+
*
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
supportsUUIDs?: boolean | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* If the database doesn't support JSON columns, set this to `false`.
|
|
97
|
+
*
|
|
98
|
+
* We will handle the translation between using `JSON` columns, and saving `string`s to the database.
|
|
99
|
+
*
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
102
|
+
supportsJSON?: boolean | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* If the database doesn't support dates, set this to `false`.
|
|
105
|
+
*
|
|
106
|
+
* We will handle the translation between using `Date` objects, and saving `string`s to the database.
|
|
107
|
+
*
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
supportsDates?: boolean | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* If the database doesn't support booleans, set this to `false`.
|
|
113
|
+
*
|
|
114
|
+
* We will handle the translation between using `boolean`s, and saving `0`s and `1`s to the database.
|
|
115
|
+
*
|
|
116
|
+
* @default true
|
|
117
|
+
*/
|
|
118
|
+
supportsBooleans?: boolean | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* If the database doesn't support arrays, set this to `false`.
|
|
121
|
+
*
|
|
122
|
+
* We will handle the translation between using `array`s, and saving `string`s to the database.
|
|
123
|
+
*
|
|
124
|
+
* @default false
|
|
125
|
+
*/
|
|
126
|
+
supportsArrays?: boolean | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Execute multiple operations in a transaction.
|
|
129
|
+
*
|
|
130
|
+
* If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
|
|
131
|
+
*
|
|
132
|
+
* @default false
|
|
133
|
+
*/
|
|
134
|
+
transaction?: (false | (<R>(callback: (trx: DBTransactionAdapter<Options>) => Promise<R>) => Promise<R>)) | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Disable id generation for the `create` method.
|
|
137
|
+
*
|
|
138
|
+
* This is useful for databases that don't support custom id values and would auto-generate them for you.
|
|
139
|
+
*
|
|
140
|
+
* @default false
|
|
141
|
+
*/
|
|
142
|
+
disableIdGeneration?: boolean | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Map the keys of the input data.
|
|
145
|
+
*
|
|
146
|
+
* This is useful for databases that expect a different key name for a given situation.
|
|
147
|
+
*
|
|
148
|
+
* For example, MongoDB uses `_id` while in Better-Auth we use `id`.
|
|
149
|
+
*
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* Each key represents the old key to replace.
|
|
153
|
+
* The value represents the new key
|
|
154
|
+
*
|
|
155
|
+
* This can be a partial object that only transforms some keys.
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* mapKeysTransformInput: {
|
|
159
|
+
* id: "_id" // We want to replace `id` to `_id` to save into MongoDB
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
mapKeysTransformInput?: Record<string, string> | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Map the keys of the output data.
|
|
166
|
+
*
|
|
167
|
+
* This is useful for databases that expect a different key name for a given situation.
|
|
168
|
+
*
|
|
169
|
+
* For example, MongoDB uses `_id` while in Better-Auth we use `id`.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* Each key represents the old key to replace.
|
|
173
|
+
* The value represents the new key
|
|
174
|
+
*
|
|
175
|
+
* This can be a partial object that only transforms some keys.
|
|
176
|
+
*
|
|
177
|
+
* ```ts
|
|
178
|
+
* mapKeysTransformOutput: {
|
|
179
|
+
* _id: "id" // In MongoDB, we save `id` as `_id`. So we want to replace `_id` with `id` when we get the data back.
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
mapKeysTransformOutput?: Record<string, string> | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Custom transform input function.
|
|
186
|
+
*
|
|
187
|
+
* This function is used to transform the input data before it is saved to the database.
|
|
188
|
+
*/
|
|
189
|
+
customTransformInput?: ((props: {
|
|
190
|
+
data: any;
|
|
191
|
+
/**
|
|
192
|
+
* The fields of the model.
|
|
193
|
+
*/
|
|
194
|
+
fieldAttributes: DBFieldAttribute;
|
|
195
|
+
/**
|
|
196
|
+
* The field to transform.
|
|
197
|
+
*/
|
|
198
|
+
field: string;
|
|
199
|
+
/**
|
|
200
|
+
* The action which was called from the adapter.
|
|
201
|
+
*/
|
|
202
|
+
action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "count";
|
|
203
|
+
/**
|
|
204
|
+
* The model name.
|
|
205
|
+
*/
|
|
206
|
+
model: string;
|
|
207
|
+
/**
|
|
208
|
+
* The schema of the user's Better-Auth instance.
|
|
209
|
+
*/
|
|
210
|
+
schema: BetterAuthDBSchema;
|
|
211
|
+
/**
|
|
212
|
+
* The options of the user's Better-Auth instance.
|
|
213
|
+
*/
|
|
214
|
+
options: Options;
|
|
215
|
+
}) => any) | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Custom transform output function.
|
|
218
|
+
*
|
|
219
|
+
* This function is used to transform the output data before it is returned to the user.
|
|
220
|
+
*/
|
|
221
|
+
customTransformOutput?: ((props: {
|
|
222
|
+
data: any;
|
|
223
|
+
/**
|
|
224
|
+
* The fields of the model.
|
|
225
|
+
*/
|
|
226
|
+
fieldAttributes: DBFieldAttribute;
|
|
227
|
+
/**
|
|
228
|
+
* The field to transform.
|
|
229
|
+
*/
|
|
230
|
+
field: string;
|
|
231
|
+
/**
|
|
232
|
+
* The fields to select.
|
|
233
|
+
*/
|
|
234
|
+
select: string[];
|
|
235
|
+
/**
|
|
236
|
+
* The model name.
|
|
237
|
+
*/
|
|
238
|
+
model: string;
|
|
239
|
+
/**
|
|
240
|
+
* The schema of the user's Better-Auth instance.
|
|
241
|
+
*/
|
|
242
|
+
schema: BetterAuthDBSchema;
|
|
243
|
+
/**
|
|
244
|
+
* The options of the user's Better-Auth instance.
|
|
245
|
+
*/
|
|
246
|
+
options: Options;
|
|
247
|
+
}) => any) | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* Custom ID generator function.
|
|
250
|
+
*
|
|
251
|
+
* By default, we can handle ID generation for you, however if the database your adapter is for only supports a specific custom id generation,
|
|
252
|
+
* then you can use this function to generate your own IDs.
|
|
253
|
+
*
|
|
254
|
+
*
|
|
255
|
+
* Notes:
|
|
256
|
+
* - If the user enabled `useNumberId` or `generateId` set to `serial`, then this option will be ignored. Unless this adapter config has `supportsNumericIds` set to `false`.
|
|
257
|
+
* - If `generateId` is `false` in the user's Better-Auth config, then this option will be ignored.
|
|
258
|
+
* - If `generateId` is a function, then it will override this option.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
*
|
|
262
|
+
* ```ts
|
|
263
|
+
* customIdGenerator: ({ model }) => {
|
|
264
|
+
* return "my-super-unique-id";
|
|
265
|
+
* }
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
customIdGenerator?: ((props: {
|
|
269
|
+
model: string;
|
|
270
|
+
}) => string) | undefined;
|
|
271
|
+
/**
|
|
272
|
+
* Whether to disable the transform output.
|
|
273
|
+
* Do not use this option unless you know what you are doing.
|
|
274
|
+
* @default false
|
|
275
|
+
*/
|
|
276
|
+
disableTransformOutput?: boolean | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* Whether to disable the transform input.
|
|
279
|
+
* Do not use this option unless you know what you are doing.
|
|
280
|
+
* @default false
|
|
281
|
+
*/
|
|
282
|
+
disableTransformInput?: boolean | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* Whether to disable the transform join.
|
|
285
|
+
* Do not use this option unless you know what you are doing.
|
|
286
|
+
* @default false
|
|
287
|
+
*/
|
|
288
|
+
disableTransformJoin?: boolean | undefined;
|
|
289
|
+
}
|
|
290
|
+
type Where = {
|
|
291
|
+
/**
|
|
292
|
+
* @default eq
|
|
293
|
+
*/
|
|
294
|
+
operator?: ("eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with") | undefined;
|
|
295
|
+
value: string | number | boolean | string[] | number[] | Date | null;
|
|
296
|
+
field: string;
|
|
297
|
+
/**
|
|
298
|
+
* @default AND
|
|
299
|
+
*/
|
|
300
|
+
connector?: ("AND" | "OR") | undefined;
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* JoinOption configuration for relational queries.
|
|
304
|
+
*
|
|
305
|
+
* Allows you to join related tables/models in a single query operation.
|
|
306
|
+
* Each key represents the name of the joined table/model, and the value
|
|
307
|
+
* configures how the join should be performed.
|
|
308
|
+
*/
|
|
309
|
+
type JoinOption = {
|
|
310
|
+
[model: string]: boolean | {
|
|
311
|
+
limit?: number;
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Once `JoinOption` has gone through the adapter factory, it will be transformed into a `JoinConfig`.
|
|
316
|
+
*/
|
|
317
|
+
type JoinConfig = {
|
|
318
|
+
[model: string]: {
|
|
319
|
+
/**
|
|
320
|
+
* The joining column names.
|
|
321
|
+
*/
|
|
322
|
+
on: {
|
|
323
|
+
/**
|
|
324
|
+
* Column name from the main table
|
|
325
|
+
*/
|
|
326
|
+
from: string;
|
|
327
|
+
/**
|
|
328
|
+
* Column name from the joined table
|
|
329
|
+
*/
|
|
330
|
+
to: string;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Limit the number of rows to return.
|
|
334
|
+
*
|
|
335
|
+
* If the relation has `unique` constraint, then this option will be ignored and limit will be set to 1.
|
|
336
|
+
*
|
|
337
|
+
* @default 100
|
|
338
|
+
*/
|
|
339
|
+
limit?: number;
|
|
340
|
+
/**
|
|
341
|
+
* The relation type. Determines the output joined model data.
|
|
342
|
+
*
|
|
343
|
+
* `one-to-one` would have a single object in the output.
|
|
344
|
+
* `one-to-many` would have an array of objects in the output.
|
|
345
|
+
* `many-to-many` would have an array of objects in the output.
|
|
346
|
+
*
|
|
347
|
+
* @default "one-to-many"
|
|
348
|
+
*/
|
|
349
|
+
relation?: "one-to-one" | "one-to-many" | "many-to-many";
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
type DBTransactionAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = Omit<DBAdapter<Options>, "transaction">;
|
|
353
|
+
type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
|
|
354
|
+
id: string;
|
|
355
|
+
create: <T extends Record<string, any>, R = T>(data: {
|
|
356
|
+
model: string;
|
|
357
|
+
data: Omit<T, "id">;
|
|
358
|
+
select?: string[] | undefined;
|
|
359
|
+
/**
|
|
360
|
+
* By default, any `id` provided in `data` will be ignored.
|
|
361
|
+
*
|
|
362
|
+
* If you want to force the `id` to be the same as the `data.id`, set this to `true`.
|
|
363
|
+
*/
|
|
364
|
+
forceAllowId?: boolean | undefined;
|
|
365
|
+
}) => Promise<R>;
|
|
366
|
+
findOne: <T>(data: {
|
|
367
|
+
model: string;
|
|
368
|
+
where: Where[];
|
|
369
|
+
select?: string[] | undefined;
|
|
370
|
+
join?: JoinOption | undefined;
|
|
371
|
+
}) => Promise<T | null>;
|
|
372
|
+
findMany: <T>(data: {
|
|
373
|
+
model: string;
|
|
374
|
+
where?: Where[] | undefined;
|
|
375
|
+
limit?: number | undefined;
|
|
376
|
+
sortBy?: {
|
|
377
|
+
field: string;
|
|
378
|
+
direction: "asc" | "desc";
|
|
379
|
+
} | undefined;
|
|
380
|
+
offset?: number | undefined;
|
|
381
|
+
join?: JoinOption | undefined;
|
|
382
|
+
}) => Promise<T[]>;
|
|
383
|
+
count: (data: {
|
|
384
|
+
model: string;
|
|
385
|
+
where?: Where[] | undefined;
|
|
386
|
+
}) => Promise<number>;
|
|
387
|
+
/**
|
|
388
|
+
* ⚠︎ Update may not return the updated data
|
|
389
|
+
* if multiple where clauses are provided
|
|
390
|
+
*/
|
|
391
|
+
update: <T>(data: {
|
|
392
|
+
model: string;
|
|
393
|
+
where: Where[];
|
|
394
|
+
update: Record<string, any>;
|
|
395
|
+
}) => Promise<T | null>;
|
|
396
|
+
updateMany: (data: {
|
|
397
|
+
model: string;
|
|
398
|
+
where: Where[];
|
|
399
|
+
update: Record<string, any>;
|
|
400
|
+
}) => Promise<number>;
|
|
401
|
+
delete: <_T>(data: {
|
|
402
|
+
model: string;
|
|
403
|
+
where: Where[];
|
|
404
|
+
}) => Promise<void>;
|
|
405
|
+
deleteMany: (data: {
|
|
406
|
+
model: string;
|
|
407
|
+
where: Where[];
|
|
408
|
+
}) => Promise<number>;
|
|
409
|
+
/**
|
|
410
|
+
* Execute multiple operations in a transaction.
|
|
411
|
+
* If the adapter doesn't support transactions, operations will be executed sequentially.
|
|
412
|
+
*/
|
|
413
|
+
transaction: <R>(callback: (trx: DBTransactionAdapter<Options>) => Promise<R>) => Promise<R>;
|
|
414
|
+
/**
|
|
415
|
+
*
|
|
416
|
+
* @param options
|
|
417
|
+
* @param file - file path if provided by the user
|
|
418
|
+
*/
|
|
419
|
+
createSchema?: ((options: Options, file?: string) => Promise<DBAdapterSchemaCreation>) | undefined;
|
|
420
|
+
options?: ({
|
|
421
|
+
adapterConfig: DBAdapterFactoryConfig<Options>;
|
|
422
|
+
} & CustomAdapter["options"]) | undefined;
|
|
423
|
+
};
|
|
424
|
+
type CleanedWhere = Required<Where>;
|
|
425
|
+
interface CustomAdapter {
|
|
426
|
+
create: <T extends Record<string, any>>({
|
|
427
|
+
data,
|
|
428
|
+
model,
|
|
429
|
+
select
|
|
430
|
+
}: {
|
|
431
|
+
model: string;
|
|
432
|
+
data: T;
|
|
433
|
+
select?: string[] | undefined;
|
|
434
|
+
}) => Promise<T>;
|
|
435
|
+
update: <T>(data: {
|
|
436
|
+
model: string;
|
|
437
|
+
where: CleanedWhere[];
|
|
438
|
+
update: T;
|
|
439
|
+
}) => Promise<T | null>;
|
|
440
|
+
updateMany: (data: {
|
|
441
|
+
model: string;
|
|
442
|
+
where: CleanedWhere[];
|
|
443
|
+
update: Record<string, any>;
|
|
444
|
+
}) => Promise<number>;
|
|
445
|
+
findOne: <T>({
|
|
446
|
+
model,
|
|
447
|
+
where,
|
|
448
|
+
select,
|
|
449
|
+
join
|
|
450
|
+
}: {
|
|
451
|
+
model: string;
|
|
452
|
+
where: CleanedWhere[];
|
|
453
|
+
select?: string[] | undefined;
|
|
454
|
+
join?: JoinConfig | undefined;
|
|
455
|
+
}) => Promise<T | null>;
|
|
456
|
+
findMany: <T>({
|
|
457
|
+
model,
|
|
458
|
+
where,
|
|
459
|
+
limit,
|
|
460
|
+
sortBy,
|
|
461
|
+
offset,
|
|
462
|
+
join
|
|
463
|
+
}: {
|
|
464
|
+
model: string;
|
|
465
|
+
where?: CleanedWhere[] | undefined;
|
|
466
|
+
limit: number;
|
|
467
|
+
sortBy?: {
|
|
468
|
+
field: string;
|
|
469
|
+
direction: "asc" | "desc";
|
|
470
|
+
} | undefined;
|
|
471
|
+
offset?: number | undefined;
|
|
472
|
+
join?: JoinConfig | undefined;
|
|
473
|
+
}) => Promise<T[]>;
|
|
474
|
+
delete: ({
|
|
475
|
+
model,
|
|
476
|
+
where
|
|
477
|
+
}: {
|
|
478
|
+
model: string;
|
|
479
|
+
where: CleanedWhere[];
|
|
480
|
+
}) => Promise<void>;
|
|
481
|
+
deleteMany: ({
|
|
482
|
+
model,
|
|
483
|
+
where
|
|
484
|
+
}: {
|
|
485
|
+
model: string;
|
|
486
|
+
where: CleanedWhere[];
|
|
487
|
+
}) => Promise<number>;
|
|
488
|
+
count: ({
|
|
489
|
+
model,
|
|
490
|
+
where
|
|
491
|
+
}: {
|
|
492
|
+
model: string;
|
|
493
|
+
where?: CleanedWhere[] | undefined;
|
|
494
|
+
}) => Promise<number>;
|
|
495
|
+
createSchema?: ((props: {
|
|
496
|
+
/**
|
|
497
|
+
* The file the user may have passed in to the `generate` command as the expected schema file output path.
|
|
498
|
+
*/
|
|
499
|
+
file?: string;
|
|
500
|
+
/**
|
|
501
|
+
* The tables from the user's Better-Auth instance schema.
|
|
502
|
+
*/
|
|
503
|
+
tables: BetterAuthDBSchema;
|
|
504
|
+
}) => Promise<DBAdapterSchemaCreation>) | undefined;
|
|
505
|
+
/**
|
|
506
|
+
* Your adapter's options.
|
|
507
|
+
*/
|
|
508
|
+
options?: Record<string, any> | undefined;
|
|
509
|
+
}
|
|
510
|
+
interface DBAdapterInstance<Options extends BetterAuthOptions = BetterAuthOptions> {
|
|
511
|
+
(options: BetterAuthOptions): DBAdapter<Options>;
|
|
512
|
+
}
|
|
513
|
+
//#endregion
|
|
2
514
|
export { AdapterConfig, AdapterFactory, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, JoinOption, Where, createAdapter, createAdapterFactory, deepmerge, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName, withApplyDefault };
|