@hammadj/better-auth-core 1.5.0-beta.9

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