@better-auth/core 1.5.7-beta.1 → 1.6.0-beta.0

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 (273) hide show
  1. package/dist/api/index.d.mts +1 -2
  2. package/dist/api/index.mjs +0 -3
  3. package/dist/async_hooks/index.d.mts +1 -2
  4. package/dist/async_hooks/index.mjs +0 -2
  5. package/dist/async_hooks/pure.index.d.mts +1 -2
  6. package/dist/async_hooks/pure.index.mjs +0 -2
  7. package/dist/context/endpoint-context.d.mts +1 -2
  8. package/dist/context/endpoint-context.mjs +0 -2
  9. package/dist/context/global.d.mts +1 -2
  10. package/dist/context/global.mjs +1 -3
  11. package/dist/context/request-state.d.mts +1 -2
  12. package/dist/context/request-state.mjs +0 -2
  13. package/dist/context/transaction.d.mts +1 -2
  14. package/dist/context/transaction.mjs +0 -2
  15. package/dist/db/adapter/factory.d.mts +1 -2
  16. package/dist/db/adapter/factory.mjs +3 -6
  17. package/dist/db/adapter/get-default-field-name.d.mts +1 -2
  18. package/dist/db/adapter/get-default-field-name.mjs +0 -2
  19. package/dist/db/adapter/get-default-model-name.d.mts +1 -2
  20. package/dist/db/adapter/get-default-model-name.mjs +0 -2
  21. package/dist/db/adapter/get-field-attributes.d.mts +1 -2
  22. package/dist/db/adapter/get-field-attributes.mjs +0 -2
  23. package/dist/db/adapter/get-field-name.d.mts +1 -2
  24. package/dist/db/adapter/get-field-name.mjs +0 -2
  25. package/dist/db/adapter/get-id-field.d.mts +1 -2
  26. package/dist/db/adapter/get-id-field.mjs +0 -3
  27. package/dist/db/adapter/get-model-name.d.mts +1 -2
  28. package/dist/db/adapter/get-model-name.mjs +0 -2
  29. package/dist/db/adapter/index.d.mts +9 -2
  30. package/dist/db/adapter/index.mjs +0 -2
  31. package/dist/db/adapter/types.d.mts +1 -2
  32. package/dist/db/adapter/utils.d.mts +1 -2
  33. package/dist/db/adapter/utils.mjs +0 -2
  34. package/dist/db/get-tables.d.mts +1 -2
  35. package/dist/db/get-tables.mjs +0 -2
  36. package/dist/db/plugin.d.mts +1 -2
  37. package/dist/db/schema/account.d.mts +1 -2
  38. package/dist/db/schema/account.mjs +0 -2
  39. package/dist/db/schema/rate-limit.d.mts +1 -2
  40. package/dist/db/schema/rate-limit.mjs +0 -2
  41. package/dist/db/schema/session.d.mts +1 -2
  42. package/dist/db/schema/session.mjs +0 -2
  43. package/dist/db/schema/shared.d.mts +1 -2
  44. package/dist/db/schema/shared.mjs +0 -2
  45. package/dist/db/schema/user.d.mts +1 -2
  46. package/dist/db/schema/user.mjs +0 -2
  47. package/dist/db/schema/verification.d.mts +1 -2
  48. package/dist/db/schema/verification.mjs +0 -2
  49. package/dist/db/type.d.mts +1 -2
  50. package/dist/env/color-depth.d.mts +1 -2
  51. package/dist/env/color-depth.mjs +0 -2
  52. package/dist/env/env-impl.d.mts +1 -2
  53. package/dist/env/env-impl.mjs +0 -2
  54. package/dist/env/logger.d.mts +1 -2
  55. package/dist/env/logger.mjs +0 -2
  56. package/dist/error/codes.d.mts +1 -2
  57. package/dist/error/codes.mjs +0 -2
  58. package/dist/error/index.d.mts +1 -2
  59. package/dist/error/index.mjs +0 -2
  60. package/dist/instrumentation/attributes.d.mts +1 -2
  61. package/dist/instrumentation/attributes.mjs +0 -2
  62. package/dist/instrumentation/tracer.d.mts +1 -2
  63. package/dist/instrumentation/tracer.mjs +29 -15
  64. package/dist/oauth2/client-credentials-token.d.mts +1 -2
  65. package/dist/oauth2/client-credentials-token.mjs +0 -2
  66. package/dist/oauth2/create-authorization-url.d.mts +1 -2
  67. package/dist/oauth2/create-authorization-url.mjs +0 -2
  68. package/dist/oauth2/oauth-provider.d.mts +1 -2
  69. package/dist/oauth2/refresh-access-token.d.mts +1 -2
  70. package/dist/oauth2/refresh-access-token.mjs +0 -2
  71. package/dist/oauth2/utils.d.mts +1 -2
  72. package/dist/oauth2/utils.mjs +0 -2
  73. package/dist/oauth2/validate-authorization-code.d.mts +1 -2
  74. package/dist/oauth2/validate-authorization-code.mjs +0 -3
  75. package/dist/oauth2/verify.d.mts +1 -2
  76. package/dist/oauth2/verify.mjs +0 -3
  77. package/dist/social-providers/apple.d.mts +1 -2
  78. package/dist/social-providers/apple.mjs +0 -3
  79. package/dist/social-providers/atlassian.d.mts +1 -2
  80. package/dist/social-providers/atlassian.mjs +0 -4
  81. package/dist/social-providers/cognito.d.mts +1 -2
  82. package/dist/social-providers/cognito.mjs +0 -4
  83. package/dist/social-providers/discord.d.mts +1 -2
  84. package/dist/social-providers/discord.mjs +0 -3
  85. package/dist/social-providers/dropbox.d.mts +1 -2
  86. package/dist/social-providers/dropbox.mjs +0 -3
  87. package/dist/social-providers/facebook.d.mts +1 -2
  88. package/dist/social-providers/facebook.mjs +0 -3
  89. package/dist/social-providers/figma.d.mts +1 -2
  90. package/dist/social-providers/figma.mjs +0 -4
  91. package/dist/social-providers/github.d.mts +1 -2
  92. package/dist/social-providers/github.mjs +0 -4
  93. package/dist/social-providers/gitlab.d.mts +1 -2
  94. package/dist/social-providers/gitlab.mjs +0 -3
  95. package/dist/social-providers/google.d.mts +1 -2
  96. package/dist/social-providers/google.mjs +0 -4
  97. package/dist/social-providers/huggingface.d.mts +1 -2
  98. package/dist/social-providers/huggingface.mjs +0 -3
  99. package/dist/social-providers/index.d.mts +1 -2
  100. package/dist/social-providers/index.mjs +0 -2
  101. package/dist/social-providers/kakao.d.mts +1 -2
  102. package/dist/social-providers/kakao.mjs +0 -3
  103. package/dist/social-providers/kick.d.mts +1 -2
  104. package/dist/social-providers/kick.mjs +0 -3
  105. package/dist/social-providers/line.d.mts +1 -2
  106. package/dist/social-providers/line.mjs +0 -3
  107. package/dist/social-providers/linear.d.mts +1 -2
  108. package/dist/social-providers/linear.mjs +0 -3
  109. package/dist/social-providers/linkedin.d.mts +1 -2
  110. package/dist/social-providers/linkedin.mjs +0 -3
  111. package/dist/social-providers/microsoft-entra-id.d.mts +1 -2
  112. package/dist/social-providers/microsoft-entra-id.mjs +0 -4
  113. package/dist/social-providers/naver.d.mts +1 -2
  114. package/dist/social-providers/naver.mjs +0 -3
  115. package/dist/social-providers/notion.d.mts +1 -2
  116. package/dist/social-providers/notion.mjs +0 -3
  117. package/dist/social-providers/paybin.d.mts +1 -2
  118. package/dist/social-providers/paybin.mjs +0 -4
  119. package/dist/social-providers/paypal.d.mts +1 -2
  120. package/dist/social-providers/paypal.mjs +0 -4
  121. package/dist/social-providers/polar.d.mts +1 -2
  122. package/dist/social-providers/polar.mjs +0 -3
  123. package/dist/social-providers/railway.d.mts +1 -2
  124. package/dist/social-providers/railway.mjs +0 -3
  125. package/dist/social-providers/reddit.d.mts +1 -2
  126. package/dist/social-providers/reddit.mjs +0 -3
  127. package/dist/social-providers/roblox.d.mts +1 -2
  128. package/dist/social-providers/roblox.mjs +0 -3
  129. package/dist/social-providers/salesforce.d.mts +1 -2
  130. package/dist/social-providers/salesforce.mjs +0 -4
  131. package/dist/social-providers/slack.d.mts +1 -2
  132. package/dist/social-providers/slack.mjs +0 -3
  133. package/dist/social-providers/spotify.d.mts +1 -2
  134. package/dist/social-providers/spotify.mjs +0 -3
  135. package/dist/social-providers/tiktok.d.mts +1 -2
  136. package/dist/social-providers/tiktok.mjs +0 -3
  137. package/dist/social-providers/twitch.d.mts +1 -2
  138. package/dist/social-providers/twitch.mjs +0 -4
  139. package/dist/social-providers/twitter.d.mts +1 -2
  140. package/dist/social-providers/twitter.mjs +0 -3
  141. package/dist/social-providers/vercel.d.mts +1 -2
  142. package/dist/social-providers/vercel.mjs +0 -3
  143. package/dist/social-providers/vk.d.mts +1 -2
  144. package/dist/social-providers/vk.mjs +0 -3
  145. package/dist/social-providers/wechat.d.mts +1 -2
  146. package/dist/social-providers/wechat.mjs +0 -2
  147. package/dist/social-providers/zoom.d.mts +1 -2
  148. package/dist/social-providers/zoom.mjs +0 -3
  149. package/dist/types/context.d.mts +2 -2
  150. package/dist/types/cookie.d.mts +1 -2
  151. package/dist/types/helper.d.mts +1 -2
  152. package/dist/types/init-options.d.mts +14 -6
  153. package/dist/types/plugin-client.d.mts +2 -2
  154. package/dist/types/plugin.d.mts +2 -2
  155. package/dist/types/secret.d.mts +1 -2
  156. package/dist/utils/db.d.mts +1 -2
  157. package/dist/utils/db.mjs +0 -2
  158. package/dist/utils/deprecate.d.mts +1 -2
  159. package/dist/utils/deprecate.mjs +0 -2
  160. package/dist/utils/error-codes.d.mts +1 -2
  161. package/dist/utils/error-codes.mjs +0 -2
  162. package/dist/utils/fetch-metadata.d.mts +1 -2
  163. package/dist/utils/fetch-metadata.mjs +0 -2
  164. package/dist/utils/id.d.mts +1 -2
  165. package/dist/utils/id.mjs +0 -2
  166. package/dist/utils/ip.d.mts +1 -2
  167. package/dist/utils/ip.mjs +0 -2
  168. package/dist/utils/json.d.mts +1 -2
  169. package/dist/utils/json.mjs +0 -3
  170. package/dist/utils/string.d.mts +1 -2
  171. package/dist/utils/string.mjs +0 -2
  172. package/dist/utils/url.d.mts +1 -2
  173. package/dist/utils/url.mjs +0 -2
  174. package/package.json +9 -7
  175. package/src/db/adapter/factory.ts +2 -0
  176. package/src/db/adapter/index.ts +8 -0
  177. package/src/instrumentation/tracer.ts +40 -12
  178. package/src/social-providers/index.ts +0 -2
  179. package/src/types/context.ts +1 -0
  180. package/src/types/init-options.ts +13 -4
  181. package/src/types/plugin-client.ts +1 -0
  182. package/src/types/plugin.ts +1 -0
  183. package/dist/api/index.mjs.map +0 -1
  184. package/dist/async_hooks/index.mjs.map +0 -1
  185. package/dist/async_hooks/pure.index.mjs.map +0 -1
  186. package/dist/context/endpoint-context.mjs.map +0 -1
  187. package/dist/context/global.mjs.map +0 -1
  188. package/dist/context/request-state.mjs.map +0 -1
  189. package/dist/context/transaction.mjs.map +0 -1
  190. package/dist/db/adapter/factory.mjs.map +0 -1
  191. package/dist/db/adapter/get-default-field-name.mjs.map +0 -1
  192. package/dist/db/adapter/get-default-model-name.mjs.map +0 -1
  193. package/dist/db/adapter/get-field-attributes.mjs.map +0 -1
  194. package/dist/db/adapter/get-field-name.mjs.map +0 -1
  195. package/dist/db/adapter/get-id-field.mjs.map +0 -1
  196. package/dist/db/adapter/get-model-name.mjs.map +0 -1
  197. package/dist/db/adapter/index.mjs.map +0 -1
  198. package/dist/db/adapter/utils.mjs.map +0 -1
  199. package/dist/db/get-tables.mjs.map +0 -1
  200. package/dist/db/schema/account.mjs.map +0 -1
  201. package/dist/db/schema/rate-limit.mjs.map +0 -1
  202. package/dist/db/schema/session.mjs.map +0 -1
  203. package/dist/db/schema/shared.mjs.map +0 -1
  204. package/dist/db/schema/user.mjs.map +0 -1
  205. package/dist/db/schema/verification.mjs.map +0 -1
  206. package/dist/env/color-depth.mjs.map +0 -1
  207. package/dist/env/env-impl.mjs.map +0 -1
  208. package/dist/env/logger.mjs.map +0 -1
  209. package/dist/error/codes.mjs.map +0 -1
  210. package/dist/error/index.mjs.map +0 -1
  211. package/dist/instrumentation/attributes.mjs.map +0 -1
  212. package/dist/instrumentation/tracer.mjs.map +0 -1
  213. package/dist/oauth2/client-credentials-token.mjs.map +0 -1
  214. package/dist/oauth2/create-authorization-url.mjs.map +0 -1
  215. package/dist/oauth2/refresh-access-token.mjs.map +0 -1
  216. package/dist/oauth2/utils.mjs.map +0 -1
  217. package/dist/oauth2/validate-authorization-code.mjs.map +0 -1
  218. package/dist/oauth2/verify.mjs.map +0 -1
  219. package/dist/social-providers/apple.mjs.map +0 -1
  220. package/dist/social-providers/atlassian.mjs.map +0 -1
  221. package/dist/social-providers/cognito.mjs.map +0 -1
  222. package/dist/social-providers/discord.mjs.map +0 -1
  223. package/dist/social-providers/dropbox.mjs.map +0 -1
  224. package/dist/social-providers/facebook.mjs.map +0 -1
  225. package/dist/social-providers/figma.mjs.map +0 -1
  226. package/dist/social-providers/github.mjs.map +0 -1
  227. package/dist/social-providers/gitlab.mjs.map +0 -1
  228. package/dist/social-providers/google.mjs.map +0 -1
  229. package/dist/social-providers/huggingface.mjs.map +0 -1
  230. package/dist/social-providers/index.mjs.map +0 -1
  231. package/dist/social-providers/kakao.mjs.map +0 -1
  232. package/dist/social-providers/kick.mjs.map +0 -1
  233. package/dist/social-providers/line.mjs.map +0 -1
  234. package/dist/social-providers/linear.mjs.map +0 -1
  235. package/dist/social-providers/linkedin.mjs.map +0 -1
  236. package/dist/social-providers/microsoft-entra-id.mjs.map +0 -1
  237. package/dist/social-providers/naver.mjs.map +0 -1
  238. package/dist/social-providers/notion.mjs.map +0 -1
  239. package/dist/social-providers/paybin.mjs.map +0 -1
  240. package/dist/social-providers/paypal.mjs.map +0 -1
  241. package/dist/social-providers/polar.mjs.map +0 -1
  242. package/dist/social-providers/railway.mjs.map +0 -1
  243. package/dist/social-providers/reddit.mjs.map +0 -1
  244. package/dist/social-providers/roblox.mjs.map +0 -1
  245. package/dist/social-providers/salesforce.mjs.map +0 -1
  246. package/dist/social-providers/slack.mjs.map +0 -1
  247. package/dist/social-providers/spotify.mjs.map +0 -1
  248. package/dist/social-providers/tiktok.mjs.map +0 -1
  249. package/dist/social-providers/twitch.mjs.map +0 -1
  250. package/dist/social-providers/twitter.mjs.map +0 -1
  251. package/dist/social-providers/vercel.mjs.map +0 -1
  252. package/dist/social-providers/vk.mjs.map +0 -1
  253. package/dist/social-providers/wechat.mjs.map +0 -1
  254. package/dist/social-providers/zoom.mjs.map +0 -1
  255. package/dist/utils/db.mjs.map +0 -1
  256. package/dist/utils/deprecate.mjs.map +0 -1
  257. package/dist/utils/error-codes.mjs.map +0 -1
  258. package/dist/utils/fetch-metadata.mjs.map +0 -1
  259. package/dist/utils/id.mjs.map +0 -1
  260. package/dist/utils/ip.mjs.map +0 -1
  261. package/dist/utils/json.mjs.map +0 -1
  262. package/dist/utils/string.mjs.map +0 -1
  263. package/dist/utils/url.mjs.map +0 -1
  264. package/src/context/request-state.test.ts +0 -94
  265. package/src/db/adapter/get-id-field.test.ts +0 -222
  266. package/src/db/test/get-tables.test.ts +0 -116
  267. package/src/env/logger.test.ts +0 -34
  268. package/src/instrumentation/instrumentation.test.ts +0 -139
  269. package/src/oauth2/refresh-access-token.test.ts +0 -90
  270. package/src/oauth2/validate-token.test.ts +0 -229
  271. package/src/utils/deprecate.test.ts +0 -71
  272. package/src/utils/fetch-metadata.test.ts +0 -28
  273. package/src/utils/ip.test.ts +0 -255
@@ -496,6 +496,7 @@ export const createAdapterFactory =
496
496
  value,
497
497
  operator = "eq",
498
498
  connector = "AND",
499
+ mode = "sensitive",
499
500
  } = w;
500
501
  if (operator === "in") {
501
502
  if (!Array.isArray(value)) {
@@ -606,6 +607,7 @@ export const createAdapterFactory =
606
607
  connector,
607
608
  field: fieldName,
608
609
  value: newValue,
610
+ mode,
609
611
  } satisfies CleanedWhere;
610
612
  }) as any;
611
613
  };
@@ -328,6 +328,14 @@ export type Where = {
328
328
  * @default AND
329
329
  */
330
330
  connector?: ("AND" | "OR") | undefined;
331
+ /**
332
+ * Case sensitivity for string comparisons.
333
+ * When "insensitive", string equality and pattern matching (contains, starts_with, ends_with)
334
+ * will be case-insensitive. Only applies to string values.
335
+ *
336
+ * @default "sensitive"
337
+ */
338
+ mode?: "sensitive" | "insensitive" | undefined;
331
339
  };
332
340
 
333
341
  /**
@@ -1,10 +1,48 @@
1
+ import type { Span } from "@opentelemetry/api";
1
2
  import { SpanStatusCode, trace } from "@opentelemetry/api";
3
+ import { ATTR_HTTP_RESPONSE_STATUS_CODE } from "./attributes";
2
4
 
3
5
  const INSTRUMENTATION_SCOPE = "better-auth";
4
6
  const INSTRUMENTATION_VERSION = import.meta.env?.BETTER_AUTH_VERSION ?? "1.0.0";
5
7
 
6
8
  const tracer = trace.getTracer(INSTRUMENTATION_SCOPE, INSTRUMENTATION_VERSION);
7
9
 
10
+ /**
11
+ * Better-auth uses `throw ctx.redirect(url)` for flow control (e.g. OAuth
12
+ * callbacks). These are APIErrors with 3xx status codes and should not be
13
+ * recorded as span errors.
14
+ */
15
+ function isRedirectError(err: unknown): boolean {
16
+ if (
17
+ err != null &&
18
+ typeof err === "object" &&
19
+ "name" in err &&
20
+ (err as { name: string }).name === "APIError" &&
21
+ "statusCode" in err
22
+ ) {
23
+ const status = (err as { statusCode: number }).statusCode;
24
+ return status >= 300 && status < 400;
25
+ }
26
+ return false;
27
+ }
28
+
29
+ function endSpanWithError(span: Span, err: unknown) {
30
+ if (isRedirectError(err)) {
31
+ span.setAttribute(
32
+ ATTR_HTTP_RESPONSE_STATUS_CODE,
33
+ (err as { statusCode: number }).statusCode,
34
+ );
35
+ span.setStatus({ code: SpanStatusCode.OK });
36
+ } else {
37
+ span.recordException(err as Error);
38
+ span.setStatus({
39
+ code: SpanStatusCode.ERROR,
40
+ message: String((err as Error)?.message ?? err),
41
+ });
42
+ }
43
+ span.end();
44
+ }
45
+
8
46
  /**
9
47
  * Creates a child span whose lifetime is bound to the execution of the given function
10
48
  *
@@ -38,24 +76,14 @@ export function withSpan<T>(
38
76
  return value;
39
77
  })
40
78
  .catch((err) => {
41
- span.recordException(err);
42
- span.setStatus({
43
- code: SpanStatusCode.ERROR,
44
- message: String(err.message ?? err),
45
- });
46
- span.end();
79
+ endSpanWithError(span, err);
47
80
  throw err;
48
81
  }) as Promise<T>;
49
82
  }
50
83
  span.end();
51
84
  return result;
52
85
  } catch (err) {
53
- span.recordException(err as Error);
54
- span.setStatus({
55
- code: SpanStatusCode.ERROR,
56
- message: String((err as Error)?.message ?? err),
57
- });
58
- span.end();
86
+ endSpanWithError(span, err);
59
87
  throw err;
60
88
  }
61
89
  });
@@ -106,11 +106,9 @@ export * from "./google";
106
106
  export * from "./huggingface";
107
107
  export * from "./kakao";
108
108
  export * from "./kick";
109
- export * from "./kick";
110
109
  export * from "./line";
111
110
  export * from "./linear";
112
111
  export * from "./linkedin";
113
- export * from "./linkedin";
114
112
  export * from "./microsoft-entra-id";
115
113
  export * from "./naver";
116
114
  export * from "./notion";
@@ -58,6 +58,7 @@ type InferPluginOptions<
58
58
  *
59
59
  * const createMyPlugin = <Options extends MyPluginOptions>(options?: Options) => ({
60
60
  * id: 'my-plugin',
61
+ * version: '1.0.0',
61
62
  * options,
62
63
  * } satisfies BetterAuthPlugin);
63
64
  *
@@ -216,7 +216,9 @@ export type BetterAuthAdvancedOptions = {
216
216
  }
217
217
  | undefined;
218
218
  /**
219
- * Use secure cookies
219
+ * Force cookies to always use the `Secure` attribute. By default,
220
+ * cookies are secure in production environments. Set this to `true`
221
+ * to enforce secure cookies in all environments.
220
222
  *
221
223
  * @default false
222
224
  */
@@ -384,9 +386,11 @@ export type BetterAuthAdvancedOptions = {
384
386
 
385
387
  export type BetterAuthOptions = {
386
388
  /**
387
- * The name of the application
389
+ * The name of your application. Used as a display name in contexts
390
+ * where your app needs to be identified — for example, as the default
391
+ * issuer name in authenticator apps when users set up 2FA/TOTP.
388
392
  *
389
- * process.env.APP_NAME
393
+ * Can also be set via the `APP_NAME` environment variable.
390
394
  *
391
395
  * @default "Better Auth"
392
396
  */
@@ -1145,7 +1149,12 @@ export type BetterAuthOptions = {
1145
1149
  })
1146
1150
  | undefined;
1147
1151
  /**
1148
- * List of trusted origins.
1152
+ * Additional trusted origins. By default, Better Auth trusts your
1153
+ * app's {@link baseURL}. Use this option to allow additional origins
1154
+ * (e.g. a separate frontend domain).
1155
+ *
1156
+ * Can be a static array, a function that returns origins dynamically,
1157
+ * or use wildcard patterns (e.g. `"https://*.example.com"`).
1149
1158
  *
1150
1159
  * @param request - The request object.
1151
1160
  * It'll be undefined if no request was
@@ -79,6 +79,7 @@ export interface BetterAuthClientOptions {
79
79
 
80
80
  export interface BetterAuthClientPlugin {
81
81
  id: LiteralString;
82
+ version?: string | undefined;
82
83
  /**
83
84
  * only used for type inference. don't pass the
84
85
  * actual plugin
@@ -51,6 +51,7 @@ export type BetterAuthPluginErrorCodePart = {
51
51
 
52
52
  export type BetterAuthPlugin = BetterAuthPluginErrorCodePart & {
53
53
  id: LiteralString;
54
+ version?: string | undefined;
54
55
  /**
55
56
  * The init function is called when the plugin is initialized.
56
57
  * You can return a new context or modify the existing context.
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/api/index.ts"],"sourcesContent":["import type {\n\tEndpoint,\n\tEndpointContext,\n\tEndpointMetadata,\n\tEndpointRuntimeOptions,\n\tHTTPMethod,\n\tMiddleware,\n\tResolveBodyInput,\n\tResolveErrorInput,\n\tResolveMetaInput,\n\tResolveQueryInput,\n\tStandardSchemaV1,\n} from \"better-call\";\nimport { createEndpoint, createMiddleware } from \"better-call\";\nimport { runWithEndpointContext } from \"../context\";\nimport type { AuthContext } from \"../types\";\n\nexport const optionsMiddleware = createMiddleware(async () => {\n\t/**\n\t * This will be passed on the instance of\n\t * the context. Used to infer the type\n\t * here.\n\t */\n\treturn {} as AuthContext;\n});\n\nexport const createAuthMiddleware = createMiddleware.create({\n\tuse: [\n\t\toptionsMiddleware,\n\t\t/**\n\t\t * Only use for post hooks\n\t\t */\n\t\tcreateMiddleware(async () => {\n\t\t\treturn {} as {\n\t\t\t\treturned?: unknown | undefined;\n\t\t\t\tresponseHeaders?: Headers | undefined;\n\t\t\t};\n\t\t}),\n\t],\n});\n\nconst use = [optionsMiddleware];\n\ntype BodyOption<M, B extends object | undefined = undefined> = M extends\n\t| \"GET\"\n\t| \"HEAD\"\n\t| (\"GET\" | \"HEAD\")[]\n\t? { body?: never }\n\t: { body?: B };\n\ntype AuthEndpointOptions<\n\tMethod extends HTTPMethod | HTTPMethod[] | \"*\",\n\tBodySchema extends object | undefined,\n\tQuerySchema extends object | undefined,\n\tUse extends Middleware[],\n\tReqHeaders extends boolean,\n\tReqRequest extends boolean,\n\tMeta extends EndpointMetadata | undefined,\n\tErrorSchema extends StandardSchemaV1 | undefined = undefined,\n> = { method: Method } & BodyOption<Method, BodySchema> & {\n\t\tquery?: QuerySchema;\n\t\tuse?: [...Use];\n\t\trequireHeaders?: ReqHeaders;\n\t\trequireRequest?: ReqRequest;\n\t\terror?: ErrorSchema;\n\t\tcloneRequest?: boolean;\n\t\tdisableBody?: boolean;\n\t\tmetadata?: Meta;\n\t\t[key: string]: any;\n\t};\n\n/**\n * Normalize readonly tuples produced by `const` type parameters\n * into mutable arrays so downstream `M extends Array<any>` checks work.\n */\ntype NormalizeMethod<M> = M extends readonly (infer E)[] ? E[] : M;\n\n// Path + options + handler overload\nexport function createAuthEndpoint<\n\tPath extends string,\n\tconst Method extends HTTPMethod | HTTPMethod[] | \"*\",\n\tBodySchema extends object | undefined = undefined,\n\tQuerySchema extends object | undefined = undefined,\n\tUse extends Middleware[] = [],\n\tReqHeaders extends boolean = false,\n\tReqRequest extends boolean = false,\n\tR = unknown,\n\tMeta extends EndpointMetadata | undefined = undefined,\n\tErrorSchema extends StandardSchemaV1 | undefined = undefined,\n>(\n\tpath: Path,\n\toptions: AuthEndpointOptions<\n\t\tMethod,\n\t\tBodySchema,\n\t\tQuerySchema,\n\t\tUse,\n\t\tReqHeaders,\n\t\tReqRequest,\n\t\tMeta,\n\t\tErrorSchema\n\t>,\n\thandler: (\n\t\tctx: EndpointContext<\n\t\t\tPath,\n\t\t\tMethod,\n\t\t\tBodySchema,\n\t\t\tQuerySchema,\n\t\t\tUse,\n\t\t\tReqHeaders,\n\t\t\tReqRequest,\n\t\t\tAuthContext,\n\t\t\tMeta\n\t\t>,\n\t) => Promise<R>,\n): Endpoint<\n\tPath,\n\tNormalizeMethod<Method>,\n\tResolveBodyInput<BodySchema, Meta>,\n\tResolveQueryInput<QuerySchema, Meta>,\n\tUse,\n\tR,\n\tResolveMetaInput<Meta>,\n\tResolveErrorInput<ErrorSchema, Meta>\n>;\n\n// Options-only (virtual/path-less) overload\nexport function createAuthEndpoint<\n\tconst Method extends HTTPMethod | HTTPMethod[] | \"*\",\n\tBodySchema extends object | undefined = undefined,\n\tQuerySchema extends object | undefined = undefined,\n\tUse extends Middleware[] = [],\n\tReqHeaders extends boolean = false,\n\tReqRequest extends boolean = false,\n\tR = unknown,\n\tMeta extends EndpointMetadata | undefined = undefined,\n\tErrorSchema extends StandardSchemaV1 | undefined = undefined,\n>(\n\toptions: AuthEndpointOptions<\n\t\tMethod,\n\t\tBodySchema,\n\t\tQuerySchema,\n\t\tUse,\n\t\tReqHeaders,\n\t\tReqRequest,\n\t\tMeta,\n\t\tErrorSchema\n\t>,\n\thandler: (\n\t\tctx: EndpointContext<\n\t\t\tstring,\n\t\t\tMethod,\n\t\t\tBodySchema,\n\t\t\tQuerySchema,\n\t\t\tUse,\n\t\t\tReqHeaders,\n\t\t\tReqRequest,\n\t\t\tAuthContext,\n\t\t\tMeta\n\t\t>,\n\t) => Promise<R>,\n): Endpoint<\n\tstring,\n\tNormalizeMethod<Method>,\n\tResolveBodyInput<BodySchema, Meta>,\n\tResolveQueryInput<QuerySchema, Meta>,\n\tUse,\n\tR,\n\tResolveMetaInput<Meta>,\n\tResolveErrorInput<ErrorSchema, Meta>\n>;\n\n// Implementation\nexport function createAuthEndpoint(\n\tpathOrOptions: any,\n\thandlerOrOptions: any,\n\thandlerOrNever?: any,\n) {\n\tconst path: string | undefined =\n\t\ttypeof pathOrOptions === \"string\" ? pathOrOptions : undefined;\n\tconst options: EndpointRuntimeOptions =\n\t\ttypeof handlerOrOptions === \"object\" ? handlerOrOptions : pathOrOptions;\n\tconst handler =\n\t\ttypeof handlerOrOptions === \"function\" ? handlerOrOptions : handlerOrNever;\n\n\tif (path) {\n\t\treturn createEndpoint(\n\t\t\tpath,\n\t\t\t{\n\t\t\t\t...options,\n\t\t\t\tuse: [...(options?.use || []), ...use],\n\t\t\t} as any,\n\t\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\t\tasync (ctx: any) => runWithEndpointContext(ctx, () => handler(ctx)),\n\t\t);\n\t}\n\n\treturn createEndpoint(\n\t\t{\n\t\t\t...options,\n\t\t\tuse: [...(options?.use || []), ...use],\n\t\t} as any,\n\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\tasync (ctx: any) => runWithEndpointContext(ctx, () => handler(ctx)),\n\t);\n}\n\nexport type AuthEndpoint = ReturnType<typeof createAuthEndpoint>;\n/**\n * The handler type for plugin hooks.\n *\n * Accepts both `Middleware` instances (from `createAuthMiddleware`)\n * and plain async functions for better-call v1/v2 compatibility.\n */\nexport type AuthMiddleware = (\n\tinputContext: Record<string, any>,\n) => Promise<unknown>;\n"],"mappings":";;;;AAiBA,MAAa,oBAAoB,iBAAiB,YAAY;;;;;;AAM7D,QAAO,EAAE;EACR;AAEF,MAAa,uBAAuB,iBAAiB,OAAO,EAC3D,KAAK,CACJ,mBAIA,iBAAiB,YAAY;AAC5B,QAAO,EAAE;EAIR,CACF,EACD,CAAC;AAEF,MAAM,MAAM,CAAC,kBAAkB;AAmI/B,SAAgB,mBACf,eACA,kBACA,gBACC;CACD,MAAM,OACL,OAAO,kBAAkB,WAAW,gBAAgB,KAAA;CACrD,MAAM,UACL,OAAO,qBAAqB,WAAW,mBAAmB;CAC3D,MAAM,UACL,OAAO,qBAAqB,aAAa,mBAAmB;AAE7D,KAAI,KACH,QAAO,eACN,MACA;EACC,GAAG;EACH,KAAK,CAAC,GAAI,SAAS,OAAO,EAAE,EAAG,GAAG,IAAI;EACtC,EAED,OAAO,QAAa,uBAAuB,WAAW,QAAQ,IAAI,CAAC,CACnE;AAGF,QAAO,eACN;EACC,GAAG;EACH,KAAK,CAAC,GAAI,SAAS,OAAO,EAAE,EAAG,GAAG,IAAI;EACtC,EAED,OAAO,QAAa,uBAAuB,WAAW,QAAQ,IAAI,CAAC,CACnE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/async_hooks/index.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\n\nexport type { AsyncLocalStorage };\n\nconst AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =\n\timport(\n\t\t/* @vite-ignore */\n\t\t/* webpackIgnore: true */\n\t\t\"node:async_hooks\"\n\t)\n\t\t.then((mod) => mod.AsyncLocalStorage)\n\t\t.catch((err) => {\n\t\t\tif (\"AsyncLocalStorage\" in globalThis) {\n\t\t\t\treturn (globalThis as any).AsyncLocalStorage;\n\t\t\t}\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.\",\n\t\t\t);\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler\",\n\t\t\t);\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag\",\n\t\t\t);\n\t\t\tthrow err;\n\t\t});\n\nexport async function getAsyncLocalStorage(): Promise<\n\ttypeof AsyncLocalStorage\n> {\n\tconst mod = await AsyncLocalStoragePromise;\n\tif (mod === null) {\n\t\tthrow new Error(\"getAsyncLocalStorage is only available in server code\");\n\t} else {\n\t\treturn mod;\n\t}\n}\n"],"mappings":";AAIA,MAAM,2BACL;;;CAGC;EAEC,MAAM,QAAQ,IAAI,kBAAkB,CACpC,OAAO,QAAQ;AACf,KAAI,uBAAuB,WAC1B,QAAQ,WAAmB;AAE5B,KAAI,OAAO,WAAW,YACrB,QAAO;AAER,SAAQ,KACP,yHACA;AACD,SAAQ,KACP,+GACA;AACD,SAAQ,KACP,wKACA;AACD,OAAM;EACL;AAEJ,eAAsB,uBAEpB;CACD,MAAM,MAAM,MAAM;AAClB,KAAI,QAAQ,KACX,OAAM,IAAI,MAAM,wDAAwD;KAExE,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"pure.index.mjs","names":["#current"],"sources":["../../src/async_hooks/pure.index.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\n\n/**\n * Due to the lack of AsyncLocalStorage in some environments (like Convex),\n *\n * We assume serverless functions are short-lived and single-threaded, so we can use a simple polyfill.\n */\nclass AsyncLocalStoragePolyfill<T> {\n\t#current: T | undefined = undefined;\n\n\trun(store: T, fn: () => unknown): unknown {\n\t\tconst prev = this.#current;\n\t\tthis.#current = store;\n\t\tconst result = fn();\n\t\tif (result instanceof Promise) {\n\t\t\treturn result.finally(() => {\n\t\t\t\tthis.#current = prev;\n\t\t\t});\n\t\t}\n\t\tthis.#current = prev;\n\t\treturn result;\n\t}\n\n\tgetStore(): T | undefined {\n\t\treturn this.#current;\n\t}\n}\n\nconst AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =\n\tPromise.resolve().then(() => {\n\t\tif (\"AsyncLocalStorage\" in globalThis) {\n\t\t\treturn (globalThis as any).AsyncLocalStorage;\n\t\t}\n\t\treturn AsyncLocalStoragePolyfill;\n\t});\n\nexport async function getAsyncLocalStorage(): Promise<\n\ttypeof AsyncLocalStorage\n> {\n\tconst mod = await AsyncLocalStoragePromise;\n\tif (mod === null) {\n\t\tthrow new Error(\"getAsyncLocalStorage is only available in server code\");\n\t} else {\n\t\treturn mod;\n\t}\n}\n"],"mappings":";;;;;;AAOA,IAAM,4BAAN,MAAmC;CAClC,WAA0B,KAAA;CAE1B,IAAI,OAAU,IAA4B;EACzC,MAAM,OAAO,MAAA;AACb,QAAA,UAAgB;EAChB,MAAM,SAAS,IAAI;AACnB,MAAI,kBAAkB,QACrB,QAAO,OAAO,cAAc;AAC3B,SAAA,UAAgB;IACf;AAEH,QAAA,UAAgB;AAChB,SAAO;;CAGR,WAA0B;AACzB,SAAO,MAAA;;;AAIT,MAAM,2BACL,QAAQ,SAAS,CAAC,WAAW;AAC5B,KAAI,uBAAuB,WAC1B,QAAQ,WAAmB;AAE5B,QAAO;EACN;AAEH,eAAsB,uBAEpB;CACD,MAAM,MAAM,MAAM;AAClB,KAAI,QAAQ,KACX,OAAM,IAAI,MAAM,wDAAwD;KAExE,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"endpoint-context.mjs","names":[],"sources":["../../src/context/endpoint-context.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport { getAsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport type { EndpointContext, InputContext } from \"better-call\";\nimport type { AuthContext } from \"../types\";\nimport { __getBetterAuthGlobal } from \"./global\";\n\nexport type AuthEndpointContext = Partial<\n\tInputContext<string, any, any, any, any, any> &\n\t\tEndpointContext<string, any, any, any, any, any, any, AuthContext>\n> & {\n\tcontext: AuthContext;\n};\n\nconst ensureAsyncStorage = async () => {\n\tconst betterAuthGlobal = __getBetterAuthGlobal();\n\tif (!betterAuthGlobal.context.endpointContextAsyncStorage) {\n\t\tconst AsyncLocalStorage = await getAsyncLocalStorage();\n\t\tbetterAuthGlobal.context.endpointContextAsyncStorage =\n\t\t\tnew AsyncLocalStorage<AuthEndpointContext>();\n\t}\n\treturn betterAuthGlobal.context\n\t\t.endpointContextAsyncStorage as AsyncLocalStorage<AuthEndpointContext>;\n};\n\n/**\n * This is for internal use only. Most users should use `getCurrentAuthContext` instead.\n *\n * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.\n */\nexport async function getCurrentAuthContextAsyncLocalStorage() {\n\treturn ensureAsyncStorage();\n}\n\nexport async function getCurrentAuthContext(): Promise<AuthEndpointContext> {\n\tconst als = await ensureAsyncStorage();\n\tconst context = als.getStore();\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.\",\n\t\t);\n\t}\n\treturn context;\n}\n\nexport async function runWithEndpointContext<T>(\n\tcontext: AuthEndpointContext,\n\tfn: () => T,\n): Promise<T> {\n\tconst als = await ensureAsyncStorage();\n\treturn als.run(context, fn);\n}\n"],"mappings":";;;AAaA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,6BAA6B;EAC1D,MAAM,oBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,8BACxB,IAAI,mBAAwC;;AAE9C,QAAO,iBAAiB,QACtB;;;;;;;AAQH,eAAsB,yCAAyC;AAC9D,QAAO,oBAAoB;;AAG5B,eAAsB,wBAAsD;CAE3E,MAAM,WADM,MAAM,oBAAoB,EAClB,UAAU;AAC9B,KAAI,CAAC,QACJ,OAAM,IAAI,MACT,oHACA;AAEF,QAAO;;AAGR,eAAsB,uBACrB,SACA,IACa;AAEb,SADY,MAAM,oBAAoB,EAC3B,IAAI,SAAS,GAAG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"global.mjs","names":[],"sources":["../../src/context/global.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\n\ninterface BetterAuthGlobal {\n\t/**\n\t * The version of BetterAuth.\n\t */\n\tversion: string;\n\t/**\n\t * Used to track the number of BetterAuth instances in the same process.\n\t *\n\t * Debugging purposes only.\n\t */\n\tepoch: number;\n\t/**\n\t * Stores the AsyncLocalStorage instances for each context.\n\t */\n\tcontext: Record<string, AsyncLocalStorage<unknown>>;\n}\n\nconst symbol = Symbol.for(\"better-auth:global\");\nlet bind: BetterAuthGlobal | null = null;\n\nconst __context: Record<string, AsyncLocalStorage<unknown>> = {};\nconst __betterAuthVersion: string = import.meta.env\n\t.BETTER_AUTH_VERSION as string;\n\n/**\n * We store context instance in the globalThis.\n *\n * The reason we do this is that some bundlers, web framework, or package managers might\n * create multiple copies of BetterAuth in the same process intentionally or unintentionally.\n *\n * For example, yarn v1, Next.js, SSR, Vite...\n *\n * @internal\n */\nexport function __getBetterAuthGlobal(): BetterAuthGlobal {\n\tif (!(globalThis as any)[symbol]) {\n\t\t(globalThis as any)[symbol] = {\n\t\t\tversion: __betterAuthVersion,\n\t\t\tepoch: 1,\n\t\t\tcontext: __context,\n\t\t};\n\t\tbind = (globalThis as any)[symbol] as BetterAuthGlobal;\n\t}\n\tbind = (globalThis as any)[symbol] as BetterAuthGlobal;\n\tif (bind.version !== __betterAuthVersion) {\n\t\tbind.version = __betterAuthVersion;\n\t\t// Different versions of BetterAuth are loaded in the same process.\n\t\tbind.epoch++;\n\t}\n\treturn (globalThis as any)[symbol] as BetterAuthGlobal;\n}\n\nexport function getBetterAuthVersion(): string {\n\treturn __getBetterAuthGlobal().version;\n}\n"],"mappings":";AAmBA,MAAM,SAAS,OAAO,IAAI,qBAAqB;AAC/C,IAAI,OAAgC;AAEpC,MAAM,YAAwD,EAAE;AAChE,MAAM,sBAAA;;;;;;;;;;;AAaN,SAAgB,wBAA0C;AACzD,KAAI,CAAE,WAAmB,SAAS;AAChC,aAAmB,UAAU;GAC7B,SAAS;GACT,OAAO;GACP,SAAS;GACT;AACD,SAAQ,WAAmB;;AAE5B,QAAQ,WAAmB;AAC3B,KAAI,KAAK,YAAY,qBAAqB;AACzC,OAAK,UAAU;AAEf,OAAK;;AAEN,QAAQ,WAAmB;;AAG5B,SAAgB,uBAA+B;AAC9C,QAAO,uBAAuB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"request-state.mjs","names":[],"sources":["../../src/context/request-state.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport { getAsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport { __getBetterAuthGlobal } from \"./global\";\n\nexport type RequestStateWeakMap = WeakMap<object, any>;\n\nconst ensureAsyncStorage = async () => {\n\tconst betterAuthGlobal = __getBetterAuthGlobal();\n\tif (!betterAuthGlobal.context.requestStateAsyncStorage) {\n\t\tconst AsyncLocalStorage = await getAsyncLocalStorage();\n\t\tbetterAuthGlobal.context.requestStateAsyncStorage =\n\t\t\tnew AsyncLocalStorage<RequestStateWeakMap>();\n\t}\n\treturn betterAuthGlobal.context\n\t\t.requestStateAsyncStorage as AsyncLocalStorage<RequestStateWeakMap>;\n};\n\nexport async function getRequestStateAsyncLocalStorage() {\n\treturn ensureAsyncStorage();\n}\n\nexport async function hasRequestState() {\n\tconst als = await ensureAsyncStorage();\n\treturn als.getStore() !== undefined;\n}\n\nexport async function getCurrentRequestState(): Promise<RequestStateWeakMap> {\n\tconst als = await ensureAsyncStorage();\n\tconst store = als.getStore();\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t\"No request state found. Please make sure you are calling this function within a `runWithRequestState` callback.\",\n\t\t);\n\t}\n\treturn store;\n}\n\nexport async function runWithRequestState<T>(\n\tstore: RequestStateWeakMap,\n\tfn: () => T,\n): Promise<T> {\n\tconst als = await ensureAsyncStorage();\n\treturn als.run(store, fn);\n}\n\nexport interface RequestState<T> {\n\tget(): Promise<T>;\n\tset(value: T): Promise<void>;\n\n\t// A unique reference used as a key to identify this state within the request's WeakMap. Useful for debugging purposes.\n\treadonly ref: Readonly<object>;\n}\n\n/**\n * Defines a request-scoped state with lazy initialization.\n *\n * @param initFn - A function that initializes the state. It is called the first time `get()` is invoked within each request context, and only once per context.\n * @returns A RequestState object with `get` and `set` methods, and a unique `ref` for debugging.\n *\n * @example\n * const userState = defineRequestState(() => ({ id: '', name: '' }));\n * // Later, within a request context:\n * const user = await userState.get();\n */\nexport function defineRequestState<T>(\n\tinitFn: () => T | Promise<T>,\n): RequestState<T>;\nexport function defineRequestState(\n\tinitFn: () => any | Promise<any>,\n): RequestState<any> {\n\tconst ref = Object.freeze({});\n\treturn {\n\t\tget ref(): Readonly<object> {\n\t\t\treturn ref;\n\t\t},\n\t\tasync get() {\n\t\t\tconst store = await getCurrentRequestState();\n\t\t\tif (!store.has(ref)) {\n\t\t\t\tconst initialValue = await initFn();\n\t\t\t\tstore.set(ref, initialValue);\n\t\t\t\treturn initialValue;\n\t\t\t}\n\t\t\treturn store.get(ref);\n\t\t},\n\n\t\tasync set(value) {\n\t\t\tconst store = await getCurrentRequestState();\n\t\t\tstore.set(ref, value);\n\t\t},\n\t};\n}\n"],"mappings":";;;AAMA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,0BAA0B;EACvD,MAAM,oBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,2BACxB,IAAI,mBAAwC;;AAE9C,QAAO,iBAAiB,QACtB;;AAGH,eAAsB,mCAAmC;AACxD,QAAO,oBAAoB;;AAG5B,eAAsB,kBAAkB;AAEvC,SADY,MAAM,oBAAoB,EAC3B,UAAU,KAAK,KAAA;;AAG3B,eAAsB,yBAAuD;CAE5E,MAAM,SADM,MAAM,oBAAoB,EACpB,UAAU;AAC5B,KAAI,CAAC,MACJ,OAAM,IAAI,MACT,kHACA;AAEF,QAAO;;AAGR,eAAsB,oBACrB,OACA,IACa;AAEb,SADY,MAAM,oBAAoB,EAC3B,IAAI,OAAO,GAAG;;AAyB1B,SAAgB,mBACf,QACoB;CACpB,MAAM,MAAM,OAAO,OAAO,EAAE,CAAC;AAC7B,QAAO;EACN,IAAI,MAAwB;AAC3B,UAAO;;EAER,MAAM,MAAM;GACX,MAAM,QAAQ,MAAM,wBAAwB;AAC5C,OAAI,CAAC,MAAM,IAAI,IAAI,EAAE;IACpB,MAAM,eAAe,MAAM,QAAQ;AACnC,UAAM,IAAI,KAAK,aAAa;AAC5B,WAAO;;AAER,UAAO,MAAM,IAAI,IAAI;;EAGtB,MAAM,IAAI,OAAO;AAEhB,IADc,MAAM,wBAAwB,EACtC,IAAI,KAAK,MAAM;;EAEtB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"transaction.mjs","names":[],"sources":["../../src/context/transaction.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\nimport { getAsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport type { DBAdapter, DBTransactionAdapter } from \"../db/adapter\";\nimport { __getBetterAuthGlobal } from \"./global\";\n\ntype HookContext = {\n\tadapter: DBTransactionAdapter;\n\tpendingHooks: Array<() => Promise<void>>;\n};\n\nconst ensureAsyncStorage = async () => {\n\tconst betterAuthGlobal = __getBetterAuthGlobal();\n\tif (!betterAuthGlobal.context.adapterAsyncStorage) {\n\t\tconst AsyncLocalStorage = await getAsyncLocalStorage();\n\t\tbetterAuthGlobal.context.adapterAsyncStorage = new AsyncLocalStorage();\n\t}\n\treturn betterAuthGlobal.context\n\t\t.adapterAsyncStorage as AsyncLocalStorage<HookContext>;\n};\n\n/**\n * This is for internal use only. Most users should use `getCurrentAdapter` instead.\n *\n * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.\n */\nexport const getCurrentDBAdapterAsyncLocalStorage = async () => {\n\treturn ensureAsyncStorage();\n};\n\nexport const getCurrentAdapter = async (\n\tfallback: DBTransactionAdapter,\n): Promise<DBTransactionAdapter> => {\n\treturn ensureAsyncStorage()\n\t\t.then((als) => {\n\t\t\tconst store = als.getStore();\n\t\t\treturn store?.adapter || fallback;\n\t\t})\n\t\t.catch(() => {\n\t\t\treturn fallback;\n\t\t});\n};\n\nexport const runWithAdapter = async <R>(\n\tadapter: DBAdapter,\n\tfn: () => R,\n): Promise<R> => {\n\tlet called = false;\n\treturn ensureAsyncStorage()\n\t\t.then(async (als) => {\n\t\t\tcalled = true;\n\t\t\tconst pendingHooks: Array<() => Promise<void>> = [];\n\t\t\tlet result: Awaited<R>;\n\t\t\tlet error: unknown;\n\t\t\tlet hasError = false;\n\t\t\ttry {\n\t\t\t\tresult = await als.run({ adapter, pendingHooks }, fn);\n\t\t\t} catch (err) {\n\t\t\t\terror = err;\n\t\t\t\thasError = true;\n\t\t\t}\n\t\t\t// Execute pending hooks after the function completes (even if it threw)\n\t\t\tfor (const hook of pendingHooks) {\n\t\t\t\tawait hook();\n\t\t\t}\n\t\t\tif (hasError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn result!;\n\t\t})\n\t\t.catch((err) => {\n\t\t\tif (!called) {\n\t\t\t\treturn fn();\n\t\t\t}\n\t\t\tthrow err;\n\t\t});\n};\n\nexport const runWithTransaction = async <R>(\n\tadapter: DBAdapter,\n\tfn: () => R,\n): Promise<R> => {\n\tlet called = true;\n\treturn ensureAsyncStorage()\n\t\t.then(async (als) => {\n\t\t\tcalled = true;\n\t\t\tconst pendingHooks: Array<() => Promise<void>> = [];\n\t\t\tlet result: Awaited<R>;\n\t\t\tlet error: unknown;\n\t\t\tlet hasError = false;\n\t\t\ttry {\n\t\t\t\tresult = await adapter.transaction(async (trx) => {\n\t\t\t\t\treturn als.run({ adapter: trx, pendingHooks }, fn);\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\thasError = true;\n\t\t\t\terror = e;\n\t\t\t}\n\t\t\tfor (const hook of pendingHooks) {\n\t\t\t\tawait hook();\n\t\t\t}\n\t\t\tif (hasError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn result!;\n\t\t})\n\t\t.catch((err) => {\n\t\t\tif (!called) {\n\t\t\t\treturn fn();\n\t\t\t}\n\t\t\tthrow err;\n\t\t});\n};\n\n/**\n * Queue a hook to be executed after the current transaction commits.\n * If not in a transaction, the hook will execute immediately.\n */\nexport const queueAfterTransactionHook = async (\n\thook: () => Promise<void>,\n): Promise<void> => {\n\treturn ensureAsyncStorage()\n\t\t.then((als) => {\n\t\t\tconst store = als.getStore();\n\t\t\tif (store) {\n\t\t\t\t// We're in a transaction context, queue the hook\n\t\t\t\tstore.pendingHooks.push(hook);\n\t\t\t} else {\n\t\t\t\t// Not in a transaction, execute immediately\n\t\t\t\treturn hook();\n\t\t\t}\n\t\t})\n\t\t.catch(() => {\n\t\t\t// No async storage available, execute immediately\n\t\t\treturn hook();\n\t\t});\n};\n"],"mappings":";;;AAUA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,qBAAqB;EAClD,MAAM,oBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,sBAAsB,IAAI,mBAAmB;;AAEvE,QAAO,iBAAiB,QACtB;;;;;;;AAQH,MAAa,uCAAuC,YAAY;AAC/D,QAAO,oBAAoB;;AAG5B,MAAa,oBAAoB,OAChC,aACmC;AACnC,QAAO,oBAAoB,CACzB,MAAM,QAAQ;AAEd,SADc,IAAI,UAAU,EACd,WAAW;GACxB,CACD,YAAY;AACZ,SAAO;GAC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ent":["import { createLogger, getColorDepth, TTY_COLORS } from \"../../env\";\nimport { BetterAuthError } from \"../../error\";\nimport {\n\tATTR_DB_COLLECTION_NAME,\n\tATTR_DB_OPERATION_NAME,\n\twithSpan,\n} from \"../../instrumentation\";\nimport type { BetterAuthOptions } from \"../../types\";\nimport { safeJSONParse } from \"../../utils/json\";\nimport { getAuthTables } from \"../get-tables\";\nimport { initGetDefaultFieldName } from \"./get-default-field-name\";\nimport { initGetDefaultModelName } from \"./get-default-model-name\";\nimport { initGetFieldAttributes } from \"./get-field-attributes\";\nimport { initGetFieldName } from \"./get-field-name\";\nimport { initGetIdField } from \"./get-id-field\";\nimport { initGetModelName } from \"./get-model-name\";\nimport type {\n\tCleanedWhere,\n\tDBAdapter,\n\tDBTransactionAdapter,\n\tJoinConfig,\n\tJoinOption,\n\tWhere,\n} from \"./index\";\nimport type {\n\tAdapterFactoryConfig,\n\tAdapterFactoryOptions,\n\tAdapterTestDebugLogs,\n} from \"./types\";\nimport { withApplyDefault } from \"./utils\";\n\nexport {\n\tinitGetDefaultModelName,\n\tinitGetDefaultFieldName,\n\tinitGetModelName,\n\tinitGetFieldName,\n\tinitGetFieldAttributes,\n\tinitGetIdField,\n};\nexport * from \"./types\";\n\nlet debugLogs: { instance: string; args: any[] }[] = [];\nlet transactionId = -1;\n\nconst createAsIsTransaction =\n\t<Options extends BetterAuthOptions>(adapter: DBAdapter<Options>) =>\n\t<R>(fn: (trx: DBTransactionAdapter<Options>) => Promise<R>) =>\n\t\tfn(adapter);\n\nexport type AdapterFactory<Options extends BetterAuthOptions> = (\n\toptions: Options,\n) => DBAdapter<Options>;\n\nexport const createAdapterFactory =\n\t<Options extends BetterAuthOptions>({\n\t\tadapter: customAdapter,\n\t\tconfig: cfg,\n\t}: AdapterFactoryOptions): AdapterFactory<Options> =>\n\t(options: Options): DBAdapter<Options> => {\n\t\tconst uniqueAdapterFactoryInstanceId = Math.random()\n\t\t\t.toString(36)\n\t\t\t.substring(2, 15);\n\n\t\tconst config = {\n\t\t\t...cfg,\n\t\t\tsupportsBooleans: cfg.supportsBooleans ?? true,\n\t\t\tsupportsDates: cfg.supportsDates ?? true,\n\t\t\tsupportsJSON: cfg.supportsJSON ?? false,\n\t\t\tadapterName: cfg.adapterName ?? cfg.adapterId,\n\t\t\tsupportsNumericIds: cfg.supportsNumericIds ?? true,\n\t\t\tsupportsUUIDs: cfg.supportsUUIDs ?? false,\n\t\t\tsupportsArrays: cfg.supportsArrays ?? false,\n\t\t\ttransaction: cfg.transaction ?? false,\n\t\t\tdisableTransformInput: cfg.disableTransformInput ?? false,\n\t\t\tdisableTransformOutput: cfg.disableTransformOutput ?? false,\n\t\t\tdisableTransformJoin: cfg.disableTransformJoin ?? false,\n\t\t} satisfies AdapterFactoryConfig;\n\n\t\tconst useNumberId = options.advanced?.database?.generateId === \"serial\";\n\t\tif (useNumberId && config.supportsNumericIds === false) {\n\t\t\tthrow new BetterAuthError(\n\t\t\t\t`[${config.adapterName}] Your database or database adapter does not support numeric ids. Please disable \"useNumberId\" in your config.`,\n\t\t\t);\n\t\t}\n\n\t\t// End-user's Better-Auth instance's schema\n\t\tconst schema = getAuthTables(options);\n\n\t\tconst debugLog = (...args: any[]) => {\n\t\t\tif (config.debugLogs === true || typeof config.debugLogs === \"object\") {\n\t\t\t\tconst logger = createLogger({ level: \"info\" });\n\t\t\t\t// If we're running adapter tests, we'll keep debug logs in memory, then print them out if a test fails.\n\t\t\t\tif (\n\t\t\t\t\ttypeof config.debugLogs === \"object\" &&\n\t\t\t\t\t\"isRunningAdapterTests\" in config.debugLogs\n\t\t\t\t) {\n\t\t\t\t\tif (config.debugLogs.isRunningAdapterTests) {\n\t\t\t\t\t\targs.shift(); // Removes the {method: \"...\"} object from the args array.\n\t\t\t\t\t\tdebugLogs.push({ instance: uniqueAdapterFactoryInstanceId, args });\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof config.debugLogs === \"object\" &&\n\t\t\t\t\tconfig.debugLogs.logCondition &&\n\t\t\t\t\t!config.debugLogs.logCondition?.()\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (typeof args[0] === \"object\" && \"method\" in args[0]) {\n\t\t\t\t\tconst method = args.shift().method;\n\t\t\t\t\t// Make sure the method is enabled in the config.\n\t\t\t\t\tif (typeof config.debugLogs === \"object\") {\n\t\t\t\t\t\tif (method === \"create\" && !config.debugLogs.create) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else if (method === \"update\" && !config.debugLogs.update) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tmethod === \"updateMany\" &&\n\t\t\t\t\t\t\t!config.debugLogs.updateMany\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else if (method === \"findOne\" && !config.debugLogs.findOne) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else if (method === \"findMany\" && !config.debugLogs.findMany) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else if (method === \"delete\" && !config.debugLogs.delete) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tmethod === \"deleteMany\" &&\n\t\t\t\t\t\t\t!config.debugLogs.deleteMany\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else if (method === \"count\" && !config.debugLogs.count) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tlogger.info(`[${config.adapterName}]`, ...args);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.info(`[${config.adapterName}]`, ...args);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tconst logger = createLogger(options.logger);\n\n\t\tconst getDefaultModelName = initGetDefaultModelName({\n\t\t\tusePlural: config.usePlural,\n\t\t\tschema,\n\t\t});\n\n\t\tconst getDefaultFieldName = initGetDefaultFieldName({\n\t\t\tusePlural: config.usePlural,\n\t\t\tschema,\n\t\t});\n\n\t\tconst getModelName = initGetModelName({\n\t\t\tusePlural: config.usePlural,\n\t\t\tschema,\n\t\t});\n\t\tconst getFieldName = initGetFieldName({\n\t\t\tschema,\n\t\t\tusePlural: config.usePlural,\n\t\t});\n\n\t\tconst idField = initGetIdField({\n\t\t\tschema,\n\t\t\toptions,\n\t\t\tusePlural: config.usePlural,\n\t\t\tdisableIdGeneration: config.disableIdGeneration,\n\t\t\tcustomIdGenerator: config.customIdGenerator,\n\t\t\tsupportsUUIDs: config.supportsUUIDs,\n\t\t});\n\n\t\tconst getFieldAttributes = initGetFieldAttributes({\n\t\t\tschema,\n\t\t\toptions,\n\t\t\tusePlural: config.usePlural,\n\t\t\tdisableIdGeneration: config.disableIdGeneration,\n\t\t\tcustomIdGenerator: config.customIdGenerator,\n\t\t});\n\n\t\tconst transformInput = async (\n\t\t\tdata: Record<string, any>,\n\t\t\tdefaultModelName: string,\n\t\t\taction: \"create\" | \"update\" | \"findOne\" | \"findMany\",\n\t\t\tforceAllowId?: boolean,\n\t\t) => {\n\t\t\tconst transformedData: Record<string, any> = {};\n\t\t\tconst fields = schema[defaultModelName]!.fields;\n\n\t\t\tconst newMappedKeys = config.mapKeysTransformInput ?? {};\n\t\t\tconst useNumberId = options.advanced?.database?.generateId === \"serial\";\n\t\t\tfields.id = idField({\n\t\t\t\tcustomModelName: defaultModelName,\n\t\t\t\tforceAllowId: forceAllowId && \"id\" in data,\n\t\t\t});\n\t\t\tfor (const field in fields) {\n\t\t\t\tlet value = data[field];\n\t\t\t\tconst fieldAttributes = fields[field];\n\n\t\t\t\tconst newFieldName: string =\n\t\t\t\t\tnewMappedKeys[field] || fields[field]!.fieldName || field;\n\t\t\t\tif (\n\t\t\t\t\tvalue === undefined &&\n\t\t\t\t\t((fieldAttributes!.defaultValue === undefined &&\n\t\t\t\t\t\t!fieldAttributes!.transform?.input &&\n\t\t\t\t\t\t!(action === \"update\" && fieldAttributes!.onUpdate)) ||\n\t\t\t\t\t\t(action === \"update\" && !fieldAttributes!.onUpdate))\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// In some endpoints (like signUpEmail) where there isn't proper Zod validation,\n\t\t\t\t// we might receive a date as a string (this is because of the client converting the Date to a string\n\t\t\t\t// when sending to the server). Because of this, we'll convert the string to a Date.\n\t\t\t\tif (\n\t\t\t\t\tfieldAttributes &&\n\t\t\t\t\tfieldAttributes.type === \"date\" &&\n\t\t\t\t\t!(value instanceof Date) &&\n\t\t\t\t\ttypeof value === \"string\"\n\t\t\t\t) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tvalue = new Date(value);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tlogger.error(\"[Adapter Factory] Failed to convert string to date\", {\n\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If the value is undefined, but the fieldAttr provides a `defaultValue`, then we'll use that.\n\t\t\t\tlet newValue = withApplyDefault(value, fieldAttributes!, action);\n\n\t\t\t\t// If the field attr provides a custom transform input, then we'll let it handle the value transformation.\n\t\t\t\t// Afterwards, we'll continue to apply the default transformations just to make sure it saves in the correct format.\n\t\t\t\tif (fieldAttributes!.transform?.input) {\n\t\t\t\t\tnewValue = await fieldAttributes!.transform.input(newValue);\n\t\t\t\t}\n\n\t\t\t\tif (fieldAttributes!.references?.field === \"id\" && useNumberId) {\n\t\t\t\t\tif (Array.isArray(newValue)) {\n\t\t\t\t\t\tnewValue = newValue.map((x) => (x !== null ? Number(x) : null));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewValue = newValue !== null ? Number(newValue) : null;\n\t\t\t\t\t}\n\t\t\t\t} else if (\n\t\t\t\t\tconfig.supportsJSON === false &&\n\t\t\t\t\ttypeof newValue === \"object\" &&\n\t\t\t\t\tfieldAttributes!.type === \"json\"\n\t\t\t\t) {\n\t\t\t\t\tnewValue = JSON.stringify(newValue);\n\t\t\t\t} else if (\n\t\t\t\t\tconfig.supportsArrays === false &&\n\t\t\t\t\tArray.isArray(newValue) &&\n\t\t\t\t\t(fieldAttributes!.type === \"string[]\" ||\n\t\t\t\t\t\tfieldAttributes!.type === \"number[]\")\n\t\t\t\t) {\n\t\t\t\t\tnewValue = JSON.stringify(newValue);\n\t\t\t\t} else if (\n\t\t\t\t\tconfig.supportsDates === false &&\n\t\t\t\t\tnewValue instanceof Date &&\n\t\t\t\t\tfieldAttributes!.type === \"date\"\n\t\t\t\t) {\n\t\t\t\t\tnewValue = newValue.toISOString();\n\t\t\t\t} else if (\n\t\t\t\t\tconfig.supportsBooleans === false &&\n\t\t\t\t\ttypeof newValue === \"boolean\"\n\t\t\t\t) {\n\t\t\t\t\tnewValue = newValue ? 1 : 0;\n\t\t\t\t}\n\n\t\t\t\tif (config.customTransformInput) {\n\t\t\t\t\tnewValue = config.customTransformInput({\n\t\t\t\t\t\tdata: newValue,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tfield: newFieldName,\n\t\t\t\t\t\tfieldAttributes: fieldAttributes!,\n\t\t\t\t\t\tmodel: getModelName(defaultModelName),\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (newValue !== undefined) {\n\t\t\t\t\ttransformedData[newFieldName] = newValue;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn transformedData;\n\t\t};\n\n\t\tconst transformOutput = async (\n\t\t\tdata: Record<string, any> | null,\n\t\t\tunsafe_model: string,\n\t\t\tselect: string[] = [],\n\t\t\tjoin: JoinConfig | undefined,\n\t\t) => {\n\t\t\tconst transformSingleOutput = async (\n\t\t\t\tdata: Record<string, any> | null,\n\t\t\t\tunsafe_model: string,\n\t\t\t\tselect: string[] = [],\n\t\t\t) => {\n\t\t\t\tif (!data) return null;\n\t\t\t\tconst newMappedKeys = config.mapKeysTransformOutput ?? {};\n\t\t\t\tconst transformedData: Record<string, any> = {};\n\t\t\t\tconst tableSchema = schema[getDefaultModelName(unsafe_model)]!.fields;\n\t\t\t\tconst idKey = Object.entries(newMappedKeys).find(\n\t\t\t\t\t([_, v]) => v === \"id\",\n\t\t\t\t)?.[0];\n\t\t\t\tconst useNumberId = options.advanced?.database?.generateId === \"serial\";\n\t\t\t\ttableSchema[idKey ?? \"id\"] = {\n\t\t\t\t\ttype: useNumberId ? \"number\" : \"string\",\n\t\t\t\t};\n\t\t\t\tfor (const key in tableSchema) {\n\t\t\t\t\tif (select.length && !select.includes(key)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst field = tableSchema[key];\n\t\t\t\t\tif (field) {\n\t\t\t\t\t\tconst originalKey = field.fieldName || key;\n\n\t\t\t\t\t\t// If the field is mapped, we'll use the mapped key. Otherwise, we'll use the original key.\n\t\t\t\t\t\tlet newValue =\n\t\t\t\t\t\t\tdata[\n\t\t\t\t\t\t\t\tObject.entries(newMappedKeys).find(\n\t\t\t\t\t\t\t\t\t([_, v]) => v === originalKey,\n\t\t\t\t\t\t\t\t)?.[0] || originalKey\n\t\t\t\t\t\t\t];\n\n\t\t\t\t\t\tif (field.transform?.output) {\n\t\t\t\t\t\t\tnewValue = await field.transform.output(newValue);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst newFieldName: string = newMappedKeys[key] || key;\n\n\t\t\t\t\t\tif (originalKey === \"id\" || field.references?.field === \"id\") {\n\t\t\t\t\t\t\t// Even if `useNumberId` is true, we must always return a string `id` output.\n\t\t\t\t\t\t\tif (typeof newValue !== \"undefined\" && newValue !== null)\n\t\t\t\t\t\t\t\tnewValue = String(newValue);\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tconfig.supportsJSON === false &&\n\t\t\t\t\t\t\ttypeof newValue === \"string\" &&\n\t\t\t\t\t\t\tfield.type === \"json\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewValue = safeJSONParse(newValue);\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tconfig.supportsArrays === false &&\n\t\t\t\t\t\t\ttypeof newValue === \"string\" &&\n\t\t\t\t\t\t\t(field.type === \"string[]\" || field.type === \"number[]\")\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewValue = safeJSONParse(newValue);\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tconfig.supportsDates === false &&\n\t\t\t\t\t\t\ttypeof newValue === \"string\" &&\n\t\t\t\t\t\t\tfield.type === \"date\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewValue = new Date(newValue);\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tconfig.supportsBooleans === false &&\n\t\t\t\t\t\t\ttypeof newValue === \"number\" &&\n\t\t\t\t\t\t\tfield.type === \"boolean\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewValue = newValue === 1;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (config.customTransformOutput) {\n\t\t\t\t\t\t\tnewValue = config.customTransformOutput({\n\t\t\t\t\t\t\t\tdata: newValue,\n\t\t\t\t\t\t\t\tfield: newFieldName,\n\t\t\t\t\t\t\t\tfieldAttributes: field,\n\t\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\t\tmodel: getModelName(unsafe_model),\n\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ttransformedData[newFieldName] = newValue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn transformedData as any;\n\t\t\t};\n\n\t\t\tif (!join || Object.keys(join).length === 0) {\n\t\t\t\treturn await transformSingleOutput(data, unsafe_model, select);\n\t\t\t}\n\n\t\t\tunsafe_model = getDefaultModelName(unsafe_model);\n\t\t\t// for now we just transform the base model\n\t\t\t// later we append the joined models to this object.\n\t\t\tconst transformedData: Record<string, any> = await transformSingleOutput(\n\t\t\t\tdata,\n\t\t\t\tunsafe_model,\n\t\t\t\tselect,\n\t\t\t);\n\n\t\t\t// Get all the models that are required to be joined.\n\t\t\tconst requiredModels = Object.entries(join).map(\n\t\t\t\t([model, joinConfig]) => ({\n\t\t\t\t\tmodelName: getModelName(model),\n\t\t\t\t\tdefaultModelName: getDefaultModelName(model),\n\t\t\t\t\tjoinConfig,\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\tif (!data) return null;\n\t\t\t// Data is now the base model object directly (not wrapped under a key)\n\n\t\t\tfor (const {\n\t\t\t\tmodelName,\n\t\t\t\tdefaultModelName,\n\t\t\t\tjoinConfig,\n\t\t\t} of requiredModels) {\n\t\t\t\tlet joinedData = await (async () => {\n\t\t\t\t\tif (options.experimental?.joins) {\n\t\t\t\t\t\tconst result = data[modelName];\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// doesn't support joins, so fallback to handleFallbackJoin\n\t\t\t\t\t\tconst result = await handleFallbackJoin({\n\t\t\t\t\t\t\tbaseModel: unsafe_model,\n\t\t\t\t\t\t\tbaseData: transformedData,\n\t\t\t\t\t\t\tjoinModel: modelName,\n\t\t\t\t\t\t\tspecificJoinConfig: joinConfig,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t})();\n\n\t\t\t\t// If joinedData is undefined, initialize it based on relationship type\n\t\t\t\tif (joinedData === undefined || joinedData === null) {\n\t\t\t\t\tjoinedData = joinConfig.relation === \"one-to-one\" ? null : [];\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\tjoinConfig.relation === \"one-to-many\" &&\n\t\t\t\t\t!Array.isArray(joinedData)\n\t\t\t\t) {\n\t\t\t\t\tjoinedData = [joinedData];\n\t\t\t\t}\n\n\t\t\t\tconst transformed = [];\n\n\t\t\t\tif (Array.isArray(joinedData)) {\n\t\t\t\t\tfor (const item of joinedData) {\n\t\t\t\t\t\tconst transformedItem = await transformSingleOutput(\n\t\t\t\t\t\t\titem,\n\t\t\t\t\t\t\tmodelName,\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t);\n\t\t\t\t\t\ttransformed.push(transformedItem);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst transformedItem = await transformSingleOutput(\n\t\t\t\t\t\tjoinedData,\n\t\t\t\t\t\tmodelName,\n\t\t\t\t\t\t[],\n\t\t\t\t\t);\n\t\t\t\t\ttransformed.push(transformedItem);\n\t\t\t\t}\n\n\t\t\t\tconst result =\n\t\t\t\t\tjoinConfig.relation === \"one-to-one\" ? transformed[0] : transformed;\n\t\t\t\ttransformedData[defaultModelName] = result ?? null;\n\t\t\t}\n\n\t\t\treturn transformedData as any;\n\t\t};\n\n\t\tconst transformWhereClause = <W extends Where[] | undefined>({\n\t\t\tmodel,\n\t\t\twhere,\n\t\t\taction,\n\t\t}: {\n\t\t\twhere: W;\n\t\t\tmodel: string;\n\t\t\taction:\n\t\t\t\t| \"create\"\n\t\t\t\t| \"update\"\n\t\t\t\t| \"findOne\"\n\t\t\t\t| \"findMany\"\n\t\t\t\t| \"updateMany\"\n\t\t\t\t| \"delete\"\n\t\t\t\t| \"deleteMany\"\n\t\t\t\t| \"count\";\n\t\t}): W extends undefined ? undefined : CleanedWhere[] => {\n\t\t\tif (!where) return undefined as any;\n\t\t\tconst newMappedKeys = config.mapKeysTransformInput ?? {};\n\n\t\t\treturn where.map((w) => {\n\t\t\t\tconst {\n\t\t\t\t\tfield: unsafe_field,\n\t\t\t\t\tvalue,\n\t\t\t\t\toperator = \"eq\",\n\t\t\t\t\tconnector = \"AND\",\n\t\t\t\t} = w;\n\t\t\t\tif (operator === \"in\") {\n\t\t\t\t\tif (!Array.isArray(value)) {\n\t\t\t\t\t\tthrow new BetterAuthError(\"Value must be an array\");\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet newValue = value;\n\n\t\t\t\tconst defaultModelName = getDefaultModelName(model);\n\t\t\t\tconst defaultFieldName = getDefaultFieldName({\n\t\t\t\t\tfield: unsafe_field,\n\t\t\t\t\tmodel,\n\t\t\t\t});\n\t\t\t\tconst fieldName: string =\n\t\t\t\t\tnewMappedKeys[defaultFieldName] ||\n\t\t\t\t\tgetFieldName({\n\t\t\t\t\t\tfield: defaultFieldName,\n\t\t\t\t\t\tmodel: defaultModelName,\n\t\t\t\t\t});\n\n\t\t\t\tconst fieldAttr = getFieldAttributes({\n\t\t\t\t\tfield: defaultFieldName,\n\t\t\t\t\tmodel: defaultModelName,\n\t\t\t\t});\n\n\t\t\t\tconst useNumberId = options.advanced?.database?.generateId === \"serial\";\n\n\t\t\t\tif (\n\t\t\t\t\tdefaultFieldName === \"id\" ||\n\t\t\t\t\tfieldAttr!.references?.field === \"id\"\n\t\t\t\t) {\n\t\t\t\t\tif (useNumberId) {\n\t\t\t\t\t\tif (Array.isArray(value)) {\n\t\t\t\t\t\t\tnewValue = value.map(Number);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnewValue = Number(value);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\tfieldAttr.type === \"date\" &&\n\t\t\t\t\tvalue instanceof Date &&\n\t\t\t\t\t!config.supportsDates\n\t\t\t\t) {\n\t\t\t\t\tnewValue = value.toISOString();\n\t\t\t\t}\n\n\t\t\t\tif (fieldAttr.type === \"boolean\" && typeof newValue === \"string\") {\n\t\t\t\t\tnewValue = newValue === \"true\";\n\t\t\t\t}\n\n\t\t\t\tif (fieldAttr.type === \"number\") {\n\t\t\t\t\tif (typeof newValue === \"string\" && newValue.trim() !== \"\") {\n\t\t\t\t\t\tconst parsed = Number(newValue);\n\t\t\t\t\t\tif (!Number.isNaN(parsed)) {\n\t\t\t\t\t\t\tnewValue = parsed;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (Array.isArray(newValue)) {\n\t\t\t\t\t\tconst parsed = newValue.map((v) =>\n\t\t\t\t\t\t\ttypeof v === \"string\" && v.trim() !== \"\" ? Number(v) : NaN,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (parsed.every((n) => !Number.isNaN(n))) {\n\t\t\t\t\t\t\tnewValue = parsed;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\tfieldAttr.type === \"boolean\" &&\n\t\t\t\t\ttypeof newValue === \"boolean\" &&\n\t\t\t\t\t!config.supportsBooleans\n\t\t\t\t) {\n\t\t\t\t\tnewValue = newValue ? 1 : 0;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\tfieldAttr.type === \"json\" &&\n\t\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t\t!config.supportsJSON\n\t\t\t\t) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst stringifiedJSON = JSON.stringify(value);\n\t\t\t\t\t\tnewValue = stringifiedJSON;\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Failed to stringify JSON value for field ${fieldName}`,\n\t\t\t\t\t\t\t{ cause: error },\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (config.customTransformInput) {\n\t\t\t\t\tnewValue = config.customTransformInput({\n\t\t\t\t\t\tdata: newValue,\n\t\t\t\t\t\tfieldAttributes: fieldAttr,\n\t\t\t\t\t\tfield: fieldName,\n\t\t\t\t\t\tmodel: getModelName(model),\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\taction,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\toperator,\n\t\t\t\t\tconnector,\n\t\t\t\t\tfield: fieldName,\n\t\t\t\t\tvalue: newValue,\n\t\t\t\t} satisfies CleanedWhere;\n\t\t\t}) as any;\n\t\t};\n\n\t\tconst transformJoinClause = (\n\t\t\tbaseModel: string,\n\t\t\tunsanitizedJoin: JoinOption | undefined,\n\t\t\tselect: string[] | undefined,\n\t\t): { join: JoinConfig; select: string[] | undefined } | undefined => {\n\t\t\tif (!unsanitizedJoin) return undefined;\n\t\t\tif (Object.keys(unsanitizedJoin).length === 0) return undefined;\n\t\t\tconst transformedJoin: JoinConfig = {};\n\t\t\tfor (const [model, join] of Object.entries(unsanitizedJoin)) {\n\t\t\t\tif (!join) continue;\n\t\t\t\tconst defaultModelName = getDefaultModelName(model);\n\t\t\t\tconst defaultBaseModelName = getDefaultModelName(baseModel);\n\n\t\t\t\t// First, check if the joined model has FKs to the base model (forward join)\n\t\t\t\tlet foreignKeys = Object.entries(\n\t\t\t\t\tschema[defaultModelName]!.fields,\n\t\t\t\t).filter(\n\t\t\t\t\t([field, fieldAttributes]) =>\n\t\t\t\t\t\tfieldAttributes.references &&\n\t\t\t\t\t\tgetDefaultModelName(fieldAttributes.references.model) ===\n\t\t\t\t\t\t\tdefaultBaseModelName,\n\t\t\t\t);\n\n\t\t\t\tlet isForwardJoin = true;\n\n\t\t\t\t// If no forward join found, check backwards: does the base model have FKs to the joined model?\n\t\t\t\tif (!foreignKeys.length) {\n\t\t\t\t\tforeignKeys = Object.entries(\n\t\t\t\t\t\tschema[defaultBaseModelName]!.fields,\n\t\t\t\t\t).filter(\n\t\t\t\t\t\t([field, fieldAttributes]) =>\n\t\t\t\t\t\t\tfieldAttributes.references &&\n\t\t\t\t\t\t\tgetDefaultModelName(fieldAttributes.references.model) ===\n\t\t\t\t\t\t\t\tdefaultModelName,\n\t\t\t\t\t);\n\t\t\t\t\tisForwardJoin = false;\n\t\t\t\t}\n\n\t\t\t\tif (!foreignKeys.length) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t`No foreign key found for model ${model} and base model ${baseModel} while performing join operation.`,\n\t\t\t\t\t);\n\t\t\t\t} else if (foreignKeys.length > 1) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t`Multiple foreign keys found for model ${model} and base model ${baseModel} while performing join operation. Only one foreign key is supported.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst [foreignKey, foreignKeyAttributes] = foreignKeys[0]!;\n\t\t\t\tif (!foreignKeyAttributes.references) {\n\t\t\t\t\t// this should never happen, as we filter for references in the foreign keys.\n\t\t\t\t\t// it's here for typescript to be happy.\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t`No references found for foreign key ${foreignKey} on model ${model} while performing join operation.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tlet from: string;\n\t\t\t\tlet to: string;\n\t\t\t\tlet requiredSelectField: string;\n\n\t\t\t\tif (isForwardJoin) {\n\t\t\t\t\t// joined model has FK to base model\n\t\t\t\t\t// The field we need in select is the referenced field in the base model\n\t\t\t\t\trequiredSelectField = foreignKeyAttributes.references.field;\n\t\t\t\t\tfrom = getFieldName({\n\t\t\t\t\t\tmodel: baseModel,\n\t\t\t\t\t\tfield: requiredSelectField,\n\t\t\t\t\t});\n\n\t\t\t\t\tto = getFieldName({\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tfield: foreignKey,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\t// base model has FK to joined model\n\t\t\t\t\t// The field we need in select is the foreign key field in the base model\n\t\t\t\t\trequiredSelectField = foreignKey;\n\t\t\t\t\tfrom = getFieldName({\n\t\t\t\t\t\tmodel: baseModel,\n\t\t\t\t\t\tfield: requiredSelectField,\n\t\t\t\t\t});\n\n\t\t\t\t\tto = getFieldName({\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tfield: foreignKeyAttributes.references.field,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Ensure the required field is in select if select is provided\n\t\t\t\tif (select && !select.includes(requiredSelectField)) {\n\t\t\t\t\tselect.push(requiredSelectField);\n\t\t\t\t}\n\n\t\t\t\tconst isUnique =\n\t\t\t\t\tto === \"id\" ? true : (foreignKeyAttributes.unique ?? false);\n\n\t\t\t\tlet limit: number =\n\t\t\t\t\toptions.advanced?.database?.defaultFindManyLimit ?? 100;\n\t\t\t\tif (isUnique) {\n\t\t\t\t\tlimit = 1;\n\t\t\t\t} else if (typeof join === \"object\" && typeof join.limit === \"number\") {\n\t\t\t\t\tlimit = join.limit;\n\t\t\t\t}\n\n\t\t\t\ttransformedJoin[getModelName(model)] = {\n\t\t\t\t\ton: {\n\t\t\t\t\t\tfrom,\n\t\t\t\t\t\tto,\n\t\t\t\t\t},\n\t\t\t\t\tlimit,\n\t\t\t\t\trelation: isUnique ? \"one-to-one\" : \"one-to-many\",\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { join: transformedJoin, select };\n\t\t};\n\n\t\t/**\n\t\t * Handle joins by making separate queries and combining results (fallback for adapters that don't support native joins).\n\t\t */\n\t\tconst handleFallbackJoin = async <T extends Record<string, any> | null>({\n\t\t\tbaseModel,\n\t\t\tbaseData,\n\t\t\tjoinModel,\n\t\t\tspecificJoinConfig: joinConfig,\n\t\t}: {\n\t\t\tbaseModel: string;\n\t\t\tbaseData: T;\n\t\t\tjoinModel: string;\n\t\t\tspecificJoinConfig: JoinConfig[number];\n\t\t}) => {\n\t\t\tif (!baseData) return baseData;\n\t\t\tconst modelName = getModelName(joinModel);\n\t\t\tconst field = joinConfig.on.to;\n\t\t\tconst value =\n\t\t\t\tbaseData[\n\t\t\t\t\tgetDefaultFieldName({ field: joinConfig.on.from, model: baseModel })\n\t\t\t\t];\n\n\t\t\tif (value === null || value === undefined) {\n\t\t\t\t// If there is no value, it could mean that the query used a `select` clause that didn't include the field.\n\t\t\t\t// or the query result is purely empty.\n\t\t\t\t// In any case, we return null/empty array.\n\t\t\t\treturn joinConfig.relation === \"one-to-one\" ? null : [];\n\t\t\t}\n\t\t\tlet result: Record<string, any> | Record<string, any>[] | null;\n\t\t\tconst where = transformWhereClause({\n\t\t\t\tmodel: modelName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\taction: \"findOne\",\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tif (joinConfig.relation === \"one-to-one\") {\n\t\t\t\t\tresult = await withSpan(\n\t\t\t\t\t\t`db findOne ${modelName}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"findOne\",\n\t\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: modelName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\tadapterInstance.findOne<Record<string, any>>({\n\t\t\t\t\t\t\t\tmodel: modelName,\n\t\t\t\t\t\t\t\twhere: where,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tconst limit =\n\t\t\t\t\t\tjoinConfig.limit ??\n\t\t\t\t\t\toptions.advanced?.database?.defaultFindManyLimit ??\n\t\t\t\t\t\t100;\n\t\t\t\t\tresult = await withSpan(\n\t\t\t\t\t\t`db findMany ${modelName}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"findMany\",\n\t\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: modelName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\tadapterInstance.findMany<Record<string, any>>({\n\t\t\t\t\t\t\t\tmodel: modelName,\n\t\t\t\t\t\t\t\twhere: where,\n\t\t\t\t\t\t\t\tlimit,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Failed to query fallback join for model ${modelName}:`, {\n\t\t\t\t\twhere,\n\t\t\t\t\tlimit: joinConfig.limit,\n\t\t\t\t});\n\t\t\t\tconsole.error(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\n\t\tconst adapterInstance = customAdapter({\n\t\t\toptions,\n\t\t\tschema,\n\t\t\tdebugLog,\n\t\t\tgetFieldName,\n\t\t\tgetModelName,\n\t\t\tgetDefaultModelName,\n\t\t\tgetDefaultFieldName,\n\t\t\tgetFieldAttributes,\n\t\t\ttransformInput,\n\t\t\ttransformOutput,\n\t\t\ttransformWhereClause,\n\t\t});\n\n\t\tlet lazyLoadTransaction: DBAdapter<Options>[\"transaction\"] | null = null;\n\t\tconst adapter: DBAdapter<Options> = {\n\t\t\ttransaction: async (cb) => {\n\t\t\t\tif (!lazyLoadTransaction) {\n\t\t\t\t\tif (!config.transaction) {\n\t\t\t\t\t\tlazyLoadTransaction = createAsIsTransaction(adapter);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t\t`[${config.adapterName}] - Using provided transaction implementation.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlazyLoadTransaction = config.transaction;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn lazyLoadTransaction(cb);\n\t\t\t},\n\t\t\tcreate: async <T extends Record<string, any>, R = T>({\n\t\t\t\tdata: unsafeData,\n\t\t\t\tmodel: unsafeModel,\n\t\t\t\tselect,\n\t\t\t\tforceAllowId = false,\n\t\t\t}: {\n\t\t\t\tmodel: string;\n\t\t\t\tdata: T;\n\t\t\t\tselect?: string[];\n\t\t\t\tforceAllowId?: boolean;\n\t\t\t}): Promise<R> => {\n\t\t\t\ttransactionId++;\n\t\t\t\tconst thisTransactionId = transactionId;\n\t\t\t\tconst model = getModelName(unsafeModel);\n\t\t\t\tunsafeModel = getDefaultModelName(unsafeModel);\n\t\t\t\tif (\n\t\t\t\t\t\"id\" in unsafeData &&\n\t\t\t\t\ttypeof unsafeData.id !== \"undefined\" &&\n\t\t\t\t\t!forceAllowId\n\t\t\t\t) {\n\t\t\t\t\t// The reason why `forceAllowId` was introduced was because we used to handle\n\t\t\t\t\t// id generation ourselves (eg adapter.create({ data: { id: \"123\" } }))\n\t\t\t\t\t// This was bad as certain things (such as number ids) would not work as expected.\n\t\t\t\t\t// Since then, we have introduced the `forceAllowId` parameter to allow users to\n\t\t\t\t\t// bypass this check. Otherwise, we would throw a warning stating that the id will be ignored\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t`[${config.adapterName}] - You are trying to create a record with an id. This is not allowed as we handle id generation for you, unless you pass in the \\`forceAllowId\\` parameter. The id will be ignored.`,\n\t\t\t\t\t);\n\t\t\t\t\tconst err = new Error();\n\t\t\t\t\tconst stack = err.stack\n\t\t\t\t\t\t?.split(\"\\n\")\n\t\t\t\t\t\t.filter((_, i) => i !== 1)\n\t\t\t\t\t\t.join(\"\\n\")\n\t\t\t\t\t\t.replace(\"Error:\", \"Create method with `id` being called at:\");\n\t\t\t\t\tconsole.log(stack);\n\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\tunsafeData.id = undefined;\n\t\t\t\t}\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"create\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`,\n\t\t\t\t\t`${formatMethod(\"create\")} ${formatAction(\"Unsafe Input\")}:`,\n\t\t\t\t\t{ model, data: unsafeData },\n\t\t\t\t);\n\t\t\t\tlet data = unsafeData;\n\t\t\t\tif (!config.disableTransformInput) {\n\t\t\t\t\tdata = (await transformInput(\n\t\t\t\t\t\tunsafeData,\n\t\t\t\t\t\tunsafeModel,\n\t\t\t\t\t\t\"create\",\n\t\t\t\t\t\tforceAllowId,\n\t\t\t\t\t)) as T;\n\t\t\t\t}\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"create\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`,\n\t\t\t\t\t`${formatMethod(\"create\")} ${formatAction(\"Parsed Input\")}:`,\n\t\t\t\t\t{ model, data },\n\t\t\t\t);\n\t\t\t\tconst res = await withSpan(\n\t\t\t\t\t`db create ${model}`,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"create\",\n\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: model,\n\t\t\t\t\t},\n\t\t\t\t\t() => adapterInstance.create<T>({ data, model }),\n\t\t\t\t);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"create\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`,\n\t\t\t\t\t`${formatMethod(\"create\")} ${formatAction(\"DB Result\")}:`,\n\t\t\t\t\t{ model, res },\n\t\t\t\t);\n\t\t\t\tlet transformed = res as any;\n\t\t\t\tif (!config.disableTransformOutput) {\n\t\t\t\t\ttransformed = await transformOutput(\n\t\t\t\t\t\tres as any,\n\t\t\t\t\t\tunsafeModel,\n\t\t\t\t\t\tselect,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"create\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`,\n\t\t\t\t\t`${formatMethod(\"create\")} ${formatAction(\"Parsed Result\")}:`,\n\t\t\t\t\t{ model, data: transformed },\n\t\t\t\t);\n\t\t\t\treturn transformed;\n\t\t\t},\n\t\t\tupdate: async <T>({\n\t\t\t\tmodel: unsafeModel,\n\t\t\t\twhere: unsafeWhere,\n\t\t\t\tupdate: unsafeData,\n\t\t\t}: {\n\t\t\t\tmodel: string;\n\t\t\t\twhere: Where[];\n\t\t\t\tupdate: Record<string, any>;\n\t\t\t}): Promise<T | null> => {\n\t\t\t\ttransactionId++;\n\t\t\t\tconst thisTransactionId = transactionId;\n\t\t\t\tunsafeModel = getDefaultModelName(unsafeModel);\n\t\t\t\tconst model = getModelName(unsafeModel);\n\t\t\t\tconst where = transformWhereClause({\n\t\t\t\t\tmodel: unsafeModel,\n\t\t\t\t\twhere: unsafeWhere,\n\t\t\t\t\taction: \"update\",\n\t\t\t\t});\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"update\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`,\n\t\t\t\t\t`${formatMethod(\"update\")} ${formatAction(\"Unsafe Input\")}:`,\n\t\t\t\t\t{ model, data: unsafeData },\n\t\t\t\t);\n\t\t\t\tlet data = unsafeData as T;\n\t\t\t\tif (!config.disableTransformInput) {\n\t\t\t\t\tdata = (await transformInput(unsafeData, unsafeModel, \"update\")) as T;\n\t\t\t\t}\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"update\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`,\n\t\t\t\t\t`${formatMethod(\"update\")} ${formatAction(\"Parsed Input\")}:`,\n\t\t\t\t\t{ model, data },\n\t\t\t\t);\n\t\t\t\tconst res = await withSpan(\n\t\t\t\t\t`db update ${model}`,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"update\",\n\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: model,\n\t\t\t\t\t},\n\t\t\t\t\t() =>\n\t\t\t\t\t\tadapterInstance.update<T>({\n\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\twhere,\n\t\t\t\t\t\t\tupdate: data,\n\t\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"update\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`,\n\t\t\t\t\t`${formatMethod(\"update\")} ${formatAction(\"DB Result\")}:`,\n\t\t\t\t\t{ model, data: res },\n\t\t\t\t);\n\t\t\t\tlet transformed = res as any;\n\t\t\t\tif (!config.disableTransformOutput) {\n\t\t\t\t\ttransformed = await transformOutput(\n\t\t\t\t\t\tres as any,\n\t\t\t\t\t\tunsafeModel,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"update\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`,\n\t\t\t\t\t`${formatMethod(\"update\")} ${formatAction(\"Parsed Result\")}:`,\n\t\t\t\t\t{ model, data: transformed },\n\t\t\t\t);\n\t\t\t\treturn transformed;\n\t\t\t},\n\t\t\tupdateMany: async ({\n\t\t\t\tmodel: unsafeModel,\n\t\t\t\twhere: unsafeWhere,\n\t\t\t\tupdate: unsafeData,\n\t\t\t}: {\n\t\t\t\tmodel: string;\n\t\t\t\twhere: Where[];\n\t\t\t\tupdate: Record<string, any>;\n\t\t\t}) => {\n\t\t\t\ttransactionId++;\n\t\t\t\tconst thisTransactionId = transactionId;\n\t\t\t\tconst model = getModelName(unsafeModel);\n\t\t\t\tconst where = transformWhereClause({\n\t\t\t\t\tmodel: unsafeModel,\n\t\t\t\t\twhere: unsafeWhere,\n\t\t\t\t\taction: \"updateMany\",\n\t\t\t\t});\n\t\t\t\tunsafeModel = getDefaultModelName(unsafeModel);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"updateMany\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`,\n\t\t\t\t\t`${formatMethod(\"updateMany\")} ${formatAction(\"Unsafe Input\")}:`,\n\t\t\t\t\t{ model, data: unsafeData },\n\t\t\t\t);\n\t\t\t\tlet data = unsafeData;\n\t\t\t\tif (!config.disableTransformInput) {\n\t\t\t\t\tdata = await transformInput(unsafeData, unsafeModel, \"update\");\n\t\t\t\t}\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"updateMany\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`,\n\t\t\t\t\t`${formatMethod(\"updateMany\")} ${formatAction(\"Parsed Input\")}:`,\n\t\t\t\t\t{ model, data },\n\t\t\t\t);\n\n\t\t\t\tconst updatedCount = await withSpan(\n\t\t\t\t\t`db updateMany ${model}`,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"updateMany\",\n\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: model,\n\t\t\t\t\t},\n\t\t\t\t\t() =>\n\t\t\t\t\t\tadapterInstance.updateMany({\n\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\twhere,\n\t\t\t\t\t\t\tupdate: data,\n\t\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"updateMany\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`,\n\t\t\t\t\t`${formatMethod(\"updateMany\")} ${formatAction(\"DB Result\")}:`,\n\t\t\t\t\t{ model, data: updatedCount },\n\t\t\t\t);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"updateMany\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`,\n\t\t\t\t\t`${formatMethod(\"updateMany\")} ${formatAction(\"Parsed Result\")}:`,\n\t\t\t\t\t{ model, data: updatedCount },\n\t\t\t\t);\n\t\t\t\treturn updatedCount;\n\t\t\t},\n\t\t\tfindOne: async <T extends Record<string, any>>({\n\t\t\t\tmodel: unsafeModel,\n\t\t\t\twhere: unsafeWhere,\n\t\t\t\tselect,\n\t\t\t\tjoin: unsafeJoin,\n\t\t\t}: {\n\t\t\t\tmodel: string;\n\t\t\t\twhere: Where[];\n\t\t\t\tselect?: string[];\n\t\t\t\tjoin?: JoinOption;\n\t\t\t}) => {\n\t\t\t\ttransactionId++;\n\t\t\t\tconst thisTransactionId = transactionId;\n\t\t\t\tconst model = getModelName(unsafeModel);\n\t\t\t\tconst where = transformWhereClause({\n\t\t\t\t\tmodel: unsafeModel,\n\t\t\t\t\twhere: unsafeWhere,\n\t\t\t\t\taction: \"findOne\",\n\t\t\t\t});\n\t\t\t\tunsafeModel = getDefaultModelName(unsafeModel);\n\t\t\t\tlet join: JoinConfig | undefined;\n\t\t\t\tlet passJoinToAdapter = true;\n\t\t\t\tif (!config.disableTransformJoin) {\n\t\t\t\t\tconst result = transformJoinClause(unsafeModel, unsafeJoin, select);\n\t\t\t\t\tif (result) {\n\t\t\t\t\t\tjoin = result.join;\n\t\t\t\t\t\tselect = result.select;\n\t\t\t\t\t}\n\t\t\t\t\t// If adapter doesn't support joins and we have joins, don't pass them to the adapter\n\t\t\t\t\tconst experimentalJoins = options.experimental?.joins;\n\t\t\t\t\tif (!experimentalJoins && join && Object.keys(join).length > 0) {\n\t\t\t\t\t\tpassJoinToAdapter = false;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// assume it's already transformed if transformation is disabled\n\t\t\t\t\tjoin = unsafeJoin as never as JoinConfig;\n\t\t\t\t}\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"findOne\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`,\n\t\t\t\t\t`${formatMethod(\"findOne\")}:`,\n\t\t\t\t\t{ model, where, select, join },\n\t\t\t\t);\n\n\t\t\t\tconst res = await withSpan(\n\t\t\t\t\t`db findOne ${model}`,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"findOne\",\n\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: model,\n\t\t\t\t\t},\n\t\t\t\t\t() =>\n\t\t\t\t\t\tadapterInstance.findOne<T>({\n\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\twhere,\n\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\tjoin: passJoinToAdapter ? join : undefined,\n\t\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"findOne\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(2, 3)}`,\n\t\t\t\t\t`${formatMethod(\"findOne\")} ${formatAction(\"DB Result\")}:`,\n\t\t\t\t\t{ model, data: res },\n\t\t\t\t);\n\n\t\t\t\t// Handle fallback join if adapter doesn't support joins\n\t\t\t\tlet transformed = res as any;\n\t\t\t\tif (!config.disableTransformOutput) {\n\t\t\t\t\ttransformed = await transformOutput(res, unsafeModel, select, join);\n\t\t\t\t}\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"findOne\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(3, 3)}`,\n\t\t\t\t\t`${formatMethod(\"findOne\")} ${formatAction(\"Parsed Result\")}:`,\n\t\t\t\t\t{ model, data: transformed },\n\t\t\t\t);\n\t\t\t\treturn transformed;\n\t\t\t},\n\t\t\tfindMany: async <T extends Record<string, any>>({\n\t\t\t\tmodel: unsafeModel,\n\t\t\t\twhere: unsafeWhere,\n\t\t\t\tlimit: unsafeLimit,\n\t\t\t\tselect,\n\t\t\t\tsortBy,\n\t\t\t\toffset,\n\t\t\t\tjoin: unsafeJoin,\n\t\t\t}: {\n\t\t\t\tmodel: string;\n\t\t\t\twhere?: Where[];\n\t\t\t\tlimit?: number;\n\t\t\t\tselect?: string[] | undefined;\n\t\t\t\tsortBy?: { field: string; direction: \"asc\" | \"desc\" };\n\t\t\t\toffset?: number;\n\t\t\t\tjoin?: JoinOption;\n\t\t\t}) => {\n\t\t\t\ttransactionId++;\n\t\t\t\tconst thisTransactionId = transactionId;\n\t\t\t\tconst limit =\n\t\t\t\t\tunsafeLimit ??\n\t\t\t\t\toptions.advanced?.database?.defaultFindManyLimit ??\n\t\t\t\t\t100;\n\t\t\t\tconst model = getModelName(unsafeModel);\n\t\t\t\tconst where = transformWhereClause({\n\t\t\t\t\tmodel: unsafeModel,\n\t\t\t\t\twhere: unsafeWhere,\n\t\t\t\t\taction: \"findMany\",\n\t\t\t\t});\n\t\t\t\tunsafeModel = getDefaultModelName(unsafeModel);\n\t\t\t\tlet join: JoinConfig | undefined;\n\t\t\t\tlet passJoinToAdapter = true;\n\t\t\t\tif (!config.disableTransformJoin) {\n\t\t\t\t\tconst result = transformJoinClause(unsafeModel, unsafeJoin, select);\n\t\t\t\t\tif (result) {\n\t\t\t\t\t\tjoin = result.join;\n\t\t\t\t\t\tselect = result.select;\n\t\t\t\t\t}\n\t\t\t\t\t// If adapter doesn't support joins and we have joins, don't pass them to the adapter\n\t\t\t\t\tconst experimentalJoins = options.experimental?.joins;\n\t\t\t\t\tif (!experimentalJoins && join && Object.keys(join).length > 0) {\n\t\t\t\t\t\tpassJoinToAdapter = false;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// assume it's already transformed if transformation is disabled\n\t\t\t\t\tjoin = unsafeJoin as never as JoinConfig;\n\t\t\t\t}\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"findMany\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`,\n\t\t\t\t\t`${formatMethod(\"findMany\")}:`,\n\t\t\t\t\t{ model, where, limit, sortBy, offset, join },\n\t\t\t\t);\n\t\t\t\tconst res = await withSpan(\n\t\t\t\t\t`db findMany ${model}`,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"findMany\",\n\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: model,\n\t\t\t\t\t},\n\t\t\t\t\t() =>\n\t\t\t\t\t\tadapterInstance.findMany<T>({\n\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\twhere,\n\t\t\t\t\t\t\tlimit: limit,\n\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\tsortBy,\n\t\t\t\t\t\t\toffset,\n\t\t\t\t\t\t\tjoin: passJoinToAdapter ? join : undefined,\n\t\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"findMany\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(2, 3)}`,\n\t\t\t\t\t`${formatMethod(\"findMany\")} ${formatAction(\"DB Result\")}:`,\n\t\t\t\t\t{ model, data: res },\n\t\t\t\t);\n\n\t\t\t\tlet transformed = res as any;\n\t\t\t\tif (!config.disableTransformOutput) {\n\t\t\t\t\ttransformed = await Promise.all(\n\t\t\t\t\t\tres.map(async (r: Record<string, any>) => {\n\t\t\t\t\t\t\treturn await transformOutput(r, unsafeModel, undefined, join);\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"findMany\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(3, 3)}`,\n\t\t\t\t\t`${formatMethod(\"findMany\")} ${formatAction(\"Parsed Result\")}:`,\n\t\t\t\t\t{ model, data: transformed },\n\t\t\t\t);\n\t\t\t\treturn transformed;\n\t\t\t},\n\t\t\tdelete: async ({\n\t\t\t\tmodel: unsafeModel,\n\t\t\t\twhere: unsafeWhere,\n\t\t\t}: {\n\t\t\t\tmodel: string;\n\t\t\t\twhere: Where[];\n\t\t\t}) => {\n\t\t\t\ttransactionId++;\n\t\t\t\tconst thisTransactionId = transactionId;\n\t\t\t\tconst model = getModelName(unsafeModel);\n\t\t\t\tconst where = transformWhereClause({\n\t\t\t\t\tmodel: unsafeModel,\n\t\t\t\t\twhere: unsafeWhere,\n\t\t\t\t\taction: \"delete\",\n\t\t\t\t});\n\t\t\t\tunsafeModel = getDefaultModelName(unsafeModel);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"delete\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`,\n\t\t\t\t\t`${formatMethod(\"delete\")}:`,\n\t\t\t\t\t{ model, where },\n\t\t\t\t);\n\t\t\t\tawait withSpan(\n\t\t\t\t\t`db delete ${model}`,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"delete\",\n\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: model,\n\t\t\t\t\t},\n\t\t\t\t\t() => adapterInstance.delete({ model, where }),\n\t\t\t\t);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"delete\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`,\n\t\t\t\t\t`${formatMethod(\"delete\")} ${formatAction(\"DB Result\")}:`,\n\t\t\t\t\t{ model },\n\t\t\t\t);\n\t\t\t},\n\t\t\tdeleteMany: async ({\n\t\t\t\tmodel: unsafeModel,\n\t\t\t\twhere: unsafeWhere,\n\t\t\t}: {\n\t\t\t\tmodel: string;\n\t\t\t\twhere: Where[];\n\t\t\t}) => {\n\t\t\t\ttransactionId++;\n\t\t\t\tconst thisTransactionId = transactionId;\n\t\t\t\tconst model = getModelName(unsafeModel);\n\t\t\t\tconst where = transformWhereClause({\n\t\t\t\t\tmodel: unsafeModel,\n\t\t\t\t\twhere: unsafeWhere,\n\t\t\t\t\taction: \"deleteMany\",\n\t\t\t\t});\n\t\t\t\tunsafeModel = getDefaultModelName(unsafeModel);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"deleteMany\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`,\n\t\t\t\t\t`${formatMethod(\"deleteMany\")} ${formatAction(\"DeleteMany\")}:`,\n\t\t\t\t\t{ model, where },\n\t\t\t\t);\n\t\t\t\tconst res = await withSpan(\n\t\t\t\t\t`db deleteMany ${model}`,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"deleteMany\",\n\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: model,\n\t\t\t\t\t},\n\t\t\t\t\t() => adapterInstance.deleteMany({ model, where }),\n\t\t\t\t);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"deleteMany\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`,\n\t\t\t\t\t`${formatMethod(\"deleteMany\")} ${formatAction(\"DB Result\")}:`,\n\t\t\t\t\t{ model, data: res },\n\t\t\t\t);\n\t\t\t\treturn res;\n\t\t\t},\n\t\t\tcount: async ({\n\t\t\t\tmodel: unsafeModel,\n\t\t\t\twhere: unsafeWhere,\n\t\t\t}: {\n\t\t\t\tmodel: string;\n\t\t\t\twhere?: Where[];\n\t\t\t}) => {\n\t\t\t\ttransactionId++;\n\t\t\t\tconst thisTransactionId = transactionId;\n\t\t\t\tconst model = getModelName(unsafeModel);\n\t\t\t\tconst where = transformWhereClause({\n\t\t\t\t\tmodel: unsafeModel,\n\t\t\t\t\twhere: unsafeWhere,\n\t\t\t\t\taction: \"count\",\n\t\t\t\t});\n\t\t\t\tunsafeModel = getDefaultModelName(unsafeModel);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"count\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`,\n\t\t\t\t\t`${formatMethod(\"count\")}:`,\n\t\t\t\t\t{\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\twhere,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tconst res = await withSpan(\n\t\t\t\t\t`db count ${model}`,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ATTR_DB_OPERATION_NAME]: \"count\",\n\t\t\t\t\t\t[ATTR_DB_COLLECTION_NAME]: model,\n\t\t\t\t\t},\n\t\t\t\t\t() => adapterInstance.count({ model, where }),\n\t\t\t\t);\n\t\t\t\tdebugLog(\n\t\t\t\t\t{ method: \"count\" },\n\t\t\t\t\t`${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`,\n\t\t\t\t\t`${formatMethod(\"count\")}:`,\n\t\t\t\t\t{\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tdata: res,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn res;\n\t\t\t},\n\t\t\tcreateSchema: adapterInstance.createSchema\n\t\t\t\t? async (_, file) => {\n\t\t\t\t\t\tconst tables = getAuthTables(options);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\toptions.secondaryStorage &&\n\t\t\t\t\t\t\t!options.session?.storeSessionInDatabase\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// biome-ignore lint/performance/noDelete: If the user has enabled secondaryStorage, as well as not specifying to store session table in DB, then createSchema shouldn't generate schema table.\n\t\t\t\t\t\t\tdelete tables.session;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn adapterInstance.createSchema!({ file, tables });\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\t\toptions: {\n\t\t\t\tadapterConfig: config,\n\t\t\t\t...(adapterInstance.options ?? {}),\n\t\t\t},\n\t\t\tid: config.adapterId,\n\n\t\t\t// Secretly export values ONLY if this adapter has enabled adapter-test-debug-logs.\n\t\t\t// This would then be used during our adapter-tests to help print debug logs if a test fails.\n\t\t\t//@ts-expect-error - ^^\n\t\t\t...(config.debugLogs?.isRunningAdapterTests\n\t\t\t\t? {\n\t\t\t\t\t\tadapterTestDebugLogs: {\n\t\t\t\t\t\t\tresetDebugLogs() {\n\t\t\t\t\t\t\t\tdebugLogs = debugLogs.filter(\n\t\t\t\t\t\t\t\t\t(log) => log.instance !== uniqueAdapterFactoryInstanceId,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tprintDebugLogs() {\n\t\t\t\t\t\t\t\tconst separator = `─`.repeat(80);\n\t\t\t\t\t\t\t\tconst logs = debugLogs.filter(\n\t\t\t\t\t\t\t\t\t(log) => log.instance === uniqueAdapterFactoryInstanceId,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif (logs.length === 0) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t//`${colors.fg.blue}|${colors.reset} `,\n\t\t\t\t\t\t\t\tconst log: any[] = logs\n\t\t\t\t\t\t\t\t\t.reverse()\n\t\t\t\t\t\t\t\t\t.map((log) => {\n\t\t\t\t\t\t\t\t\t\tlog.args[0] = `\\n${log.args[0]}`;\n\t\t\t\t\t\t\t\t\t\treturn [...log.args, \"\\n\"];\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t.reduce(\n\t\t\t\t\t\t\t\t\t\t(prev, curr) => {\n\t\t\t\t\t\t\t\t\t\t\treturn [...curr, ...prev];\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t[`\\n${separator}`],\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tconsole.log(...log);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} satisfies AdapterTestDebugLogs,\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t};\n\t\treturn adapter;\n\t};\n\nfunction formatTransactionId(transactionId: number) {\n\tif (getColorDepth() < 8) {\n\t\treturn `#${transactionId}`;\n\t}\n\treturn `${TTY_COLORS.fg.magenta}#${transactionId}${TTY_COLORS.reset}`;\n}\n\nfunction formatStep(step: number, total: number) {\n\treturn `${TTY_COLORS.bg.black}${TTY_COLORS.fg.yellow}[${step}/${total}]${TTY_COLORS.reset}`;\n}\n\nfunction formatMethod(method: string) {\n\treturn `${TTY_COLORS.bright}${method}${TTY_COLORS.reset}`;\n}\n\nfunction formatAction(action: string) {\n\treturn `${TTY_COLORS.dim}(${action})${TTY_COLORS.reset}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyCA,IAAI,YAAiD,EAAE;AACvD,IAAI,gBAAgB;AAEpB,MAAM,yBAC+B,aAChC,OACH,GAAG,QAAQ;AAMb,MAAa,wBACwB,EACnC,SAAS,eACT,QAAQ,WAER,YAAyC;CACzC,MAAM,iCAAiC,KAAK,QAAQ,CAClD,SAAS,GAAG,CACZ,UAAU,GAAG,GAAG;CAElB,MAAM,SAAS;EACd,GAAG;EACH,kBAAkB,IAAI,oBAAoB;EAC1C,eAAe,IAAI,iBAAiB;EACpC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,KAAK,KAAK,KAAK,IAAI,KAAK;AAC5B,YAAO,CAAC,GAAG,IAAI,MAAM,KAAK;MACzB,CACD,QACC,MAAM,SAAS;AACf,YAAO,CAAC,GAAG,MAAM,GAAG,KAAK;OAE1B,CAAC,KAAK,YAAY,CAClB;AAEF,YAAQ,IAAI,GAAG,IAAI;;GAEpB,EACD,GACA,EAAE;EACL;AACD,QAAO;;AAGT,SAAS,oBAAoB,eAAuB;AACnD,KAAI,eAAe,GAAG,EACrB,QAAO,IAAI;AAEZ,QAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,gBAAgB,WAAW;;AAG/D,SAAS,WAAW,MAAc,OAAe;AAChD,QAAO,GAAG,WAAW,GAAG,QAAQ,WAAW,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,WAAW;;AAGrF,SAAS,aAAa,QAAgB;AACrC,QAAO,GAAG,WAAW,SAAS,SAAS,WAAW;;AAGnD,SAAS,aAAa,QAAgB;AACrC,QAAO,GAAG,WAAW,IAAI,GAAG,OAAO,GAAG,WAAW"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-default-field-name.mjs","names":[],"sources":["../../../src/db/adapter/get-default-field-name.ts"],"sourcesContent":["import { BetterAuthError } from \"../../error\";\nimport type { BetterAuthDBSchema } from \"../type\";\nimport { initGetDefaultModelName } from \"./get-default-model-name\";\n\nexport const initGetDefaultFieldName = ({\n\tschema,\n\tusePlural,\n}: {\n\tschema: BetterAuthDBSchema;\n\tusePlural: boolean | undefined;\n}) => {\n\tconst getDefaultModelName = initGetDefaultModelName({\n\t\tschema,\n\t\tusePlural,\n\t});\n\n\t/**\n\t * This function helps us get the default field name from the schema defined by devs.\n\t * Often times, the user will be using the `fieldName` which could had been customized by the users.\n\t * This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])\n\t *\n\t * If it's still unclear what this does:\n\t *\n\t * 1. User can define a custom fieldName.\n\t * 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.\n\t */\n\tconst getDefaultFieldName = ({\n\t\tfield,\n\t\tmodel: unsafeModel,\n\t}: {\n\t\tmodel: string;\n\t\tfield: string;\n\t}) => {\n\t\t// Plugin `schema`s can't define their own `id`. Better-auth auto provides `id` to every schema model.\n\t\t// Given this, we can't just check if the `field` (that being `id`) is within the schema's fields, since it is never defined.\n\t\t// So we check if the `field` is `id` and if so, we return `id` itself. Otherwise, we return the `field` from the schema.\n\t\tif (field === \"id\" || field === \"_id\") {\n\t\t\treturn \"id\";\n\t\t}\n\t\tconst model = getDefaultModelName(unsafeModel); // Just to make sure the model name is correct.\n\n\t\tlet f = schema[model]?.fields[field];\n\t\tif (!f) {\n\t\t\tconst result = Object.entries(schema[model]!.fields!).find(\n\t\t\t\t([_, f]) => f.fieldName === field,\n\t\t\t);\n\t\t\tif (result) {\n\t\t\t\tf = result[1];\n\t\t\t\tfield = result[0];\n\t\t\t}\n\t\t}\n\t\tif (!f) {\n\t\t\tthrow new BetterAuthError(`Field ${field} not found in model ${model}`);\n\t\t}\n\t\treturn field;\n\t};\n\n\treturn getDefaultFieldName;\n};\n"],"mappings":";;;AAIA,MAAa,2BAA2B,EACvC,QACA,gBAIK;CACL,MAAM,sBAAsB,wBAAwB;EACnD;EACA;EACA,CAAC;;;;;;;;;;;CAYF,MAAM,uBAAuB,EAC5B,OACA,OAAO,kBAIF;AAIL,MAAI,UAAU,QAAQ,UAAU,MAC/B,QAAO;EAER,MAAM,QAAQ,oBAAoB,YAAY;EAE9C,IAAI,IAAI,OAAO,QAAQ,OAAO;AAC9B,MAAI,CAAC,GAAG;GACP,MAAM,SAAS,OAAO,QAAQ,OAAO,OAAQ,OAAQ,CAAC,MACpD,CAAC,GAAG,OAAO,EAAE,cAAc,MAC5B;AACD,OAAI,QAAQ;AACX,QAAI,OAAO;AACX,YAAQ,OAAO;;;AAGjB,MAAI,CAAC,EACJ,OAAM,IAAI,gBAAgB,SAAS,MAAM,sBAAsB,QAAQ;AAExE,SAAO;;AAGR,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-default-model-name.mjs","names":[],"sources":["../../../src/db/adapter/get-default-model-name.ts"],"sourcesContent":["import { BetterAuthError } from \"../../error\";\nimport type { BetterAuthDBSchema } from \"../type\";\n\nexport const initGetDefaultModelName = ({\n\tusePlural,\n\tschema,\n}: {\n\tusePlural: boolean | undefined;\n\tschema: BetterAuthDBSchema;\n}) => {\n\t/**\n\t * This function helps us get the default model name from the schema defined by devs.\n\t * Often times, the user will be using the `modelName` which could had been customized by the users.\n\t * This function helps us get the actual model name useful to match against the schema. (eg: schema[model])\n\t *\n\t * If it's still unclear what this does:\n\t *\n\t * 1. User can define a custom modelName.\n\t * 2. When using a custom modelName, doing something like `schema[model]` will not work.\n\t * 3. Using this function helps us get the actual model name based on the user's defined custom modelName.\n\t */\n\tconst getDefaultModelName = (model: string) => {\n\t\t// It's possible this `model` could had applied `usePlural`.\n\t\t// Thus we'll try the search but without the trailing `s`.\n\t\tif (usePlural && model.charAt(model.length - 1) === \"s\") {\n\t\t\tconst pluralessModel = model.slice(0, -1);\n\t\t\tlet m = schema[pluralessModel] ? pluralessModel : undefined;\n\t\t\tif (!m) {\n\t\t\t\tm = Object.entries(schema).find(\n\t\t\t\t\t([_, f]) => f.modelName === pluralessModel,\n\t\t\t\t)?.[0];\n\t\t\t}\n\n\t\t\tif (m) {\n\t\t\t\treturn m;\n\t\t\t}\n\t\t}\n\n\t\tlet m = schema[model] ? model : undefined;\n\t\tif (!m) {\n\t\t\tm = Object.entries(schema).find(([_, f]) => f.modelName === model)?.[0];\n\t\t}\n\n\t\tif (!m) {\n\t\t\tthrow new BetterAuthError(`Model \"${model}\" not found in schema`);\n\t\t}\n\t\treturn m;\n\t};\n\n\treturn getDefaultModelName;\n};\n"],"mappings":";;AAGA,MAAa,2BAA2B,EACvC,WACA,aAIK;;;;;;;;;;;;CAYL,MAAM,uBAAuB,UAAkB;AAG9C,MAAI,aAAa,MAAM,OAAO,MAAM,SAAS,EAAE,KAAK,KAAK;GACxD,MAAM,iBAAiB,MAAM,MAAM,GAAG,GAAG;GACzC,IAAI,IAAI,OAAO,kBAAkB,iBAAiB,KAAA;AAClD,OAAI,CAAC,EACJ,KAAI,OAAO,QAAQ,OAAO,CAAC,MACzB,CAAC,GAAG,OAAO,EAAE,cAAc,eAC5B,GAAG;AAGL,OAAI,EACH,QAAO;;EAIT,IAAI,IAAI,OAAO,SAAS,QAAQ,KAAA;AAChC,MAAI,CAAC,EACJ,KAAI,OAAO,QAAQ,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,EAAE,cAAc,MAAM,GAAG;AAGtE,MAAI,CAAC,EACJ,OAAM,IAAI,gBAAgB,UAAU,MAAM,uBAAuB;AAElE,SAAO;;AAGR,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-field-attributes.mjs","names":[],"sources":["../../../src/db/adapter/get-field-attributes.ts"],"sourcesContent":["import { BetterAuthError } from \"../../error\";\nimport type { BetterAuthOptions } from \"../../types\";\nimport type { BetterAuthDBSchema } from \"../type\";\nimport { initGetDefaultFieldName } from \"./get-default-field-name\";\nimport { initGetDefaultModelName } from \"./get-default-model-name\";\nimport { initGetIdField } from \"./get-id-field\";\n\nexport const initGetFieldAttributes = ({\n\tusePlural,\n\tschema,\n\toptions,\n\tcustomIdGenerator,\n\tdisableIdGeneration,\n}: {\n\tusePlural?: boolean;\n\tschema: BetterAuthDBSchema;\n\toptions: BetterAuthOptions;\n\tdisableIdGeneration?: boolean;\n\tcustomIdGenerator?: ((props: { model: string }) => string) | undefined;\n}) => {\n\tconst getDefaultModelName = initGetDefaultModelName({\n\t\tusePlural,\n\t\tschema,\n\t});\n\n\tconst getDefaultFieldName = initGetDefaultFieldName({\n\t\tusePlural,\n\t\tschema,\n\t});\n\n\tconst idField = initGetIdField({\n\t\tusePlural,\n\t\tschema,\n\t\toptions,\n\t\tcustomIdGenerator,\n\t\tdisableIdGeneration,\n\t});\n\n\tconst getFieldAttributes = ({\n\t\tmodel,\n\t\tfield,\n\t}: {\n\t\tmodel: string;\n\t\tfield: string;\n\t}) => {\n\t\tconst defaultModelName = getDefaultModelName(model);\n\t\tconst defaultFieldName = getDefaultFieldName({\n\t\t\tfield: field,\n\t\t\tmodel: defaultModelName,\n\t\t});\n\n\t\tconst fields = schema[defaultModelName]!.fields;\n\t\tfields.id = idField({ customModelName: defaultModelName });\n\t\tconst fieldAttributes = fields[defaultFieldName];\n\t\tif (!fieldAttributes) {\n\t\t\tthrow new BetterAuthError(`Field ${field} not found in model ${model}`);\n\t\t}\n\t\treturn fieldAttributes;\n\t};\n\n\treturn getFieldAttributes;\n};\n"],"mappings":";;;;;AAOA,MAAa,0BAA0B,EACtC,WACA,QACA,SACA,mBACA,0BAOK;CACL,MAAM,sBAAsB,wBAAwB;EACnD;EACA;EACA,CAAC;CAEF,MAAM,sBAAsB,wBAAwB;EACnD;EACA;EACA,CAAC;CAEF,MAAM,UAAU,eAAe;EAC9B;EACA;EACA;EACA;EACA;EACA,CAAC;CAEF,MAAM,sBAAsB,EAC3B,OACA,YAIK;EACL,MAAM,mBAAmB,oBAAoB,MAAM;EACnD,MAAM,mBAAmB,oBAAoB;GACrC;GACP,OAAO;GACP,CAAC;EAEF,MAAM,SAAS,OAAO,kBAAmB;AACzC,SAAO,KAAK,QAAQ,EAAE,iBAAiB,kBAAkB,CAAC;EAC1D,MAAM,kBAAkB,OAAO;AAC/B,MAAI,CAAC,gBACJ,OAAM,IAAI,gBAAgB,SAAS,MAAM,sBAAsB,QAAQ;AAExE,SAAO;;AAGR,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-field-name.mjs","names":[],"sources":["../../../src/db/adapter/get-field-name.ts"],"sourcesContent":["import type { BetterAuthDBSchema } from \"../type\";\nimport { initGetDefaultFieldName } from \"./get-default-field-name\";\nimport { initGetDefaultModelName } from \"./get-default-model-name\";\n\nexport const initGetFieldName = ({\n\tschema,\n\tusePlural,\n}: {\n\tschema: BetterAuthDBSchema;\n\tusePlural: boolean | undefined;\n}) => {\n\tconst getDefaultModelName = initGetDefaultModelName({\n\t\tschema,\n\t\tusePlural,\n\t});\n\n\tconst getDefaultFieldName = initGetDefaultFieldName({\n\t\tschema,\n\t\tusePlural,\n\t});\n\n\t/**\n\t * Get the field name which is expected to be saved in the database based on the user's schema.\n\t *\n\t * This function is useful if you need to save the field name to the database.\n\t *\n\t * For example, if the user has defined a custom field name for the `user` model, then you can use this function to get the actual field name from the schema.\n\t */\n\tfunction getFieldName({\n\t\tmodel: modelName,\n\t\tfield: fieldName,\n\t}: {\n\t\tmodel: string;\n\t\tfield: string;\n\t}) {\n\t\tconst model = getDefaultModelName(modelName);\n\t\tconst field = getDefaultFieldName({ model, field: fieldName });\n\n\t\treturn schema[model]?.fields[field]?.fieldName || field;\n\t}\n\n\treturn getFieldName;\n};\n"],"mappings":";;;AAIA,MAAa,oBAAoB,EAChC,QACA,gBAIK;CACL,MAAM,sBAAsB,wBAAwB;EACnD;EACA;EACA,CAAC;CAEF,MAAM,sBAAsB,wBAAwB;EACnD;EACA;EACA,CAAC;;;;;;;;CASF,SAAS,aAAa,EACrB,OAAO,WACP,OAAO,aAIL;EACF,MAAM,QAAQ,oBAAoB,UAAU;EAC5C,MAAM,QAAQ,oBAAoB;GAAE;GAAO,OAAO;GAAW,CAAC;AAE9D,SAAO,OAAO,QAAQ,OAAO,QAAQ,aAAa;;AAGnD,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-id-field.mjs","names":["generateId","defaultGenerateId"],"sources":["../../../src/db/adapter/get-id-field.ts"],"sourcesContent":["import { logger } from \"../../env\";\nimport type { BetterAuthOptions } from \"../../types\";\nimport { generateId as defaultGenerateId } from \"../../utils/id\";\nimport type { BetterAuthDBSchema, DBFieldAttribute } from \"../type\";\nimport { initGetDefaultModelName } from \"./get-default-model-name\";\n\nexport const initGetIdField = ({\n\tusePlural,\n\tschema,\n\tdisableIdGeneration,\n\toptions,\n\tcustomIdGenerator,\n\tsupportsUUIDs,\n}: {\n\tusePlural?: boolean;\n\tschema: BetterAuthDBSchema;\n\toptions: BetterAuthOptions;\n\tdisableIdGeneration?: boolean;\n\tcustomIdGenerator?: ((props: { model: string }) => string) | undefined;\n\tsupportsUUIDs?: boolean;\n}) => {\n\tconst getDefaultModelName = initGetDefaultModelName({\n\t\tusePlural: usePlural,\n\t\tschema,\n\t});\n\n\tconst idField = ({\n\t\tcustomModelName,\n\t\tforceAllowId,\n\t}: {\n\t\tcustomModelName?: string;\n\t\tforceAllowId?: boolean;\n\t}) => {\n\t\tconst useNumberId = options.advanced?.database?.generateId === \"serial\";\n\t\tconst useUUIDs = options.advanced?.database?.generateId === \"uuid\";\n\n\t\tconst shouldGenerateId: boolean = (() => {\n\t\t\tif (disableIdGeneration) {\n\t\t\t\treturn false;\n\t\t\t} else if (useNumberId && !forceAllowId) {\n\t\t\t\t// if force allow is true, then we should be using their custom provided id.\n\t\t\t\treturn false;\n\t\t\t} else if (useUUIDs) {\n\t\t\t\t// should only generate UUIDs via JS if the database doesn't support natively generating UUIDs.\n\t\t\t\treturn !supportsUUIDs;\n\t\t\t} else {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t})();\n\n\t\tconst model = getDefaultModelName(customModelName ?? \"id\");\n\t\treturn {\n\t\t\ttype: useNumberId ? \"number\" : \"string\",\n\t\t\trequired: shouldGenerateId ? true : false,\n\t\t\t...(shouldGenerateId\n\t\t\t\t? {\n\t\t\t\t\t\tdefaultValue() {\n\t\t\t\t\t\t\tif (disableIdGeneration) return undefined;\n\t\t\t\t\t\t\tconst generateId = options.advanced?.database?.generateId;\n\n\t\t\t\t\t\t\t// let the database handle id generation\n\t\t\t\t\t\t\tif (generateId === false || generateId === \"serial\")\n\t\t\t\t\t\t\t\treturn undefined;\n\n\t\t\t\t\t\t\t// user-provided function takes highest priority\n\t\t\t\t\t\t\tif (typeof generateId === \"function\") {\n\t\t\t\t\t\t\t\treturn generateId({\n\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// user-provided \"uuid\" option\n\t\t\t\t\t\t\tif (generateId === \"uuid\") {\n\t\t\t\t\t\t\t\treturn crypto.randomUUID();\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// database adapter-level custom id generator\n\t\t\t\t\t\t\tif (customIdGenerator) {\n\t\t\t\t\t\t\t\treturn customIdGenerator({ model });\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// fallback to default id generation\n\t\t\t\t\t\t\treturn defaultGenerateId();\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\ttransform: {\n\t\t\t\tinput: (value) => {\n\t\t\t\t\t// Uncomment if need to debug id transformation\n\t\t\t\t\t// console.log(`transforming id: `, {\n\t\t\t\t\t// \tid: value,\n\t\t\t\t\t// \t...(useNumberId ? { useNumberId } : {}),\n\t\t\t\t\t// \t...(useUUIDs ? { useUUIDs } : {}),\n\t\t\t\t\t// \t...(forceAllowId ? { forceAllowId } : {}),\n\t\t\t\t\t// });\n\t\t\t\t\tif (!value) return undefined;\n\n\t\t\t\t\tif (useNumberId) {\n\t\t\t\t\t\tconst numberValue = Number(value);\n\t\t\t\t\t\t// if invalid number, fallback to DB generated number id.\n\t\t\t\t\t\tif (isNaN(numberValue)) {\n\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn numberValue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (useUUIDs) {\n\t\t\t\t\t\t// if it's generated by us, then we should return the value as is.\n\t\t\t\t\t\tif (shouldGenerateId && !forceAllowId) return value;\n\t\t\t\t\t\tif (disableIdGeneration) return undefined;\n\t\t\t\t\t\t// if DB will handle UUID generation, then we should return undefined.\n\t\t\t\t\t\tif (supportsUUIDs) return undefined;\n\t\t\t\t\t\t// if forceAllowId is true, it means we should be using the ID provided during the adapter call.\n\t\t\t\t\t\tif (forceAllowId && typeof value === \"string\") {\n\t\t\t\t\t\t\tconst uuidRegex =\n\t\t\t\t\t\t\t\t/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\t\t\t\t\t\t\tif (uuidRegex.test(value)) {\n\t\t\t\t\t\t\t\treturn value;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconst err = new Error();\n\t\t\t\t\t\t\t\tconst stack = err.stack\n\t\t\t\t\t\t\t\t\t?.split(\"\\n\")\n\t\t\t\t\t\t\t\t\t.filter((_, i) => i !== 1)\n\t\t\t\t\t\t\t\t\t.join(\"\\n\")\n\t\t\t\t\t\t\t\t\t.replace(\"Error:\", \"\");\n\t\t\t\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t\t\t\t\"[Adapter Factory] - Invalid UUID value for field `id` provided when `forceAllowId` is true. Generating a new UUID.\",\n\t\t\t\t\t\t\t\t\tstack,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// if the value is not a string, and the database doesn't support generating it's own UUIDs, then we should be generating the UUID.\n\t\t\t\t\t\tif (typeof value !== \"string\" && !supportsUUIDs) {\n\t\t\t\t\t\t\treturn crypto.randomUUID();\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value;\n\t\t\t\t},\n\t\t\t\toutput: (value) => {\n\t\t\t\t\tif (!value) return undefined;\n\t\t\t\t\treturn String(value);\n\t\t\t\t},\n\t\t\t},\n\t\t} satisfies DBFieldAttribute;\n\t};\n\n\treturn idField;\n};\n"],"mappings":";;;;;AAMA,MAAa,kBAAkB,EAC9B,WACA,QACA,qBACA,SACA,mBACA,oBAQK;CACL,MAAM,sBAAsB,wBAAwB;EACxC;EACX;EACA,CAAC;CAEF,MAAM,WAAW,EAChB,iBACA,mBAIK;EACL,MAAM,cAAc,QAAQ,UAAU,UAAU,eAAe;EA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AU;AAClB,SAAI,CAAC,MAAO,QAAO,KAAA;AACnB,YAAO,OAAO,MAAM;;IAErB;GACD;;AAGF,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-model-name.mjs","names":[],"sources":["../../../src/db/adapter/get-model-name.ts"],"sourcesContent":["import type { BetterAuthDBSchema } from \"../type\";\nimport { initGetDefaultModelName } from \"./get-default-model-name\";\n\nexport const initGetModelName = ({\n\tusePlural,\n\tschema,\n}: {\n\tusePlural: boolean | undefined;\n\tschema: BetterAuthDBSchema;\n}) => {\n\tconst getDefaultModelName = initGetDefaultModelName({\n\t\tschema,\n\t\tusePlural,\n\t});\n\t/**\n\t * Users can overwrite the default model of some tables. This function helps find the correct model name.\n\t * Furthermore, if the user passes `usePlural` as true in their adapter config,\n\t * then we should return the model name ending with an `s`.\n\t */\n\tconst getModelName = (model: string) => {\n\t\tconst defaultModelKey = getDefaultModelName(model);\n\t\tconst useCustomModelName =\n\t\t\tschema &&\n\t\t\tschema[defaultModelKey] &&\n\t\t\tschema[defaultModelKey].modelName !== model;\n\n\t\tif (useCustomModelName) {\n\t\t\treturn usePlural\n\t\t\t\t? `${schema[defaultModelKey]!.modelName}s`\n\t\t\t\t: schema[defaultModelKey]!.modelName;\n\t\t}\n\n\t\treturn usePlural ? `${model}s` : model;\n\t};\n\treturn getModelName;\n};\n"],"mappings":";;AAGA,MAAa,oBAAoB,EAChC,WACA,aAIK;CACL,MAAM,sBAAsB,wBAAwB;EACnD;EACA;EACA,CAAC;;;;;;CAMF,MAAM,gBAAgB,UAAkB;EACvC,MAAM,kBAAkB,oBAAoB,MAAM;AAMlD,MAJC,UACA,OAAO,oBACP,OAAO,iBAAiB,cAAc,MAGtC,QAAO,YACJ,GAAG,OAAO,iBAAkB,UAAU,KACtC,OAAO,iBAAkB;AAG7B,SAAO,YAAY,GAAG,MAAM,KAAK;;AAElC,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/db/adapter/index.ts"],"sourcesContent":["import type { BetterAuthOptions } from \"../../types\";\nimport type { BetterAuthDBSchema, DBFieldAttribute } from \"../type\";\n\nexport type DBAdapterDebugLogOption =\n\t| boolean\n\t| {\n\t\t\t/**\n\t\t\t * Useful when you want to log only certain conditions.\n\t\t\t */\n\t\t\tlogCondition?: (() => boolean) | undefined;\n\t\t\tcreate?: boolean | undefined;\n\t\t\tupdate?: boolean | undefined;\n\t\t\tupdateMany?: boolean | undefined;\n\t\t\tfindOne?: boolean | undefined;\n\t\t\tfindMany?: boolean | undefined;\n\t\t\tdelete?: boolean | undefined;\n\t\t\tdeleteMany?: boolean | undefined;\n\t\t\tcount?: boolean | undefined;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * Only used for adapter tests to show debug logs if a test fails.\n\t\t\t *\n\t\t\t * @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.\n\t\t\t */\n\t\t\tisRunningAdapterTests: boolean;\n\t };\n\nexport type DBAdapterSchemaCreation = {\n\t/**\n\t * Code to be inserted into the file\n\t */\n\tcode: string;\n\t/**\n\t * Path to the file, including the file name and extension.\n\t * Relative paths are supported, with the current working directory of the developer's project as the base.\n\t */\n\tpath: string;\n\t/**\n\t * Append the file if it already exists.\n\t * Note: This will not apply if `overwrite` is set to true.\n\t */\n\tappend?: boolean | undefined;\n\t/**\n\t * Overwrite the file if it already exists\n\t */\n\toverwrite?: boolean | undefined;\n};\n\nexport interface DBAdapterFactoryConfig<\n\tOptions extends BetterAuthOptions = BetterAuthOptions,\n> {\n\t/**\n\t * Use plural table names.\n\t *\n\t * All tables will be named with an `s` at the end.\n\t *\n\t * @default false\n\t */\n\tusePlural?: boolean | undefined;\n\t/**\n\t * Enable debug logs.\n\t *\n\t * @default false\n\t */\n\tdebugLogs?: DBAdapterDebugLogOption | undefined;\n\t/**\n\t * Name of the adapter.\n\t *\n\t * This is used to identify the adapter in the debug logs.\n\t *\n\t * @default `adapterId`\n\t */\n\tadapterName?: string | undefined;\n\t/**\n\t * Adapter id\n\t */\n\tadapterId: string;\n\t/**\n\t * If the database supports numeric ids, set this to `true`.\n\t *\n\t * @default true\n\t */\n\tsupportsNumericIds?: boolean | undefined;\n\t/**\n\t * If the database supports natively generating UUIDs, set this to `true`.\n\t *\n\t * @default false\n\t */\n\tsupportsUUIDs?: boolean | undefined;\n\t/**\n\t * If the database doesn't support JSON columns, set this to `false`.\n\t *\n\t * We will handle the translation between using `JSON` columns, and saving `string`s to the database.\n\t *\n\t * @default false\n\t */\n\tsupportsJSON?: boolean | undefined;\n\t/**\n\t * If the database doesn't support dates, set this to `false`.\n\t *\n\t * We will handle the translation between using `Date` objects, and saving `string`s to the database.\n\t *\n\t * @default true\n\t */\n\tsupportsDates?: boolean | undefined;\n\t/**\n\t * If the database doesn't support booleans, set this to `false`.\n\t *\n\t * We will handle the translation between using `boolean`s, and saving `0`s and `1`s to the database.\n\t *\n\t * @default true\n\t */\n\tsupportsBooleans?: boolean | undefined;\n\t/**\n\t * If the database doesn't support arrays, set this to `false`.\n\t *\n\t * We will handle the translation between using `array`s, and saving `string`s to the database.\n\t *\n\t * @default false\n\t */\n\tsupportsArrays?: boolean | undefined;\n\t/**\n\t * Execute multiple operations in a transaction.\n\t *\n\t * If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.\n\t *\n\t * @default false\n\t */\n\ttransaction?:\n\t\t| (\n\t\t\t\t| false\n\t\t\t\t| (<R>(\n\t\t\t\t\t\tcallback: (trx: DBTransactionAdapter<Options>) => Promise<R>,\n\t\t\t\t ) => Promise<R>)\n\t\t )\n\t\t| undefined;\n\t/**\n\t * Disable id generation for the `create` method.\n\t *\n\t * This is useful for databases that don't support custom id values and would auto-generate them for you.\n\t *\n\t * @default false\n\t */\n\tdisableIdGeneration?: boolean | undefined;\n\t/**\n\t * Map the keys of the input data.\n\t *\n\t * This is useful for databases that expect a different key name for a given situation.\n\t *\n\t * For example, MongoDB uses `_id` while in Better-Auth we use `id`.\n\t *\n\t *\n\t * @example\n\t * Each key represents the old key to replace.\n\t * The value represents the new key\n\t *\n\t * This can be a partial object that only transforms some keys.\n\t *\n\t * ```ts\n\t * mapKeysTransformInput: {\n\t * id: \"_id\" // We want to replace `id` to `_id` to save into MongoDB\n\t * }\n\t * ```\n\t */\n\tmapKeysTransformInput?: Record<string, string> | undefined;\n\t/**\n\t * Map the keys of the output data.\n\t *\n\t * This is useful for databases that expect a different key name for a given situation.\n\t *\n\t * For example, MongoDB uses `_id` while in Better-Auth we use `id`.\n\t *\n\t * @example\n\t * Each key represents the old key to replace.\n\t * The value represents the new key\n\t *\n\t * This can be a partial object that only transforms some keys.\n\t *\n\t * ```ts\n\t * mapKeysTransformOutput: {\n\t * _id: \"id\" // In MongoDB, we save `id` as `_id`. So we want to replace `_id` with `id` when we get the data back.\n\t * }\n\t * ```\n\t */\n\tmapKeysTransformOutput?: Record<string, string> | undefined;\n\t/**\n\t * Custom transform input function.\n\t *\n\t * This function is used to transform the input data before it is saved to the database.\n\t */\n\tcustomTransformInput?:\n\t\t| ((props: {\n\t\t\t\tdata: any;\n\t\t\t\t/**\n\t\t\t\t * The fields of the model.\n\t\t\t\t */\n\t\t\t\tfieldAttributes: DBFieldAttribute;\n\t\t\t\t/**\n\t\t\t\t * The field to transform.\n\t\t\t\t */\n\t\t\t\tfield: string;\n\t\t\t\t/**\n\t\t\t\t * The action which was called from the adapter.\n\t\t\t\t */\n\t\t\t\taction:\n\t\t\t\t\t| \"create\"\n\t\t\t\t\t| \"update\"\n\t\t\t\t\t| \"findOne\"\n\t\t\t\t\t| \"findMany\"\n\t\t\t\t\t| \"updateMany\"\n\t\t\t\t\t| \"delete\"\n\t\t\t\t\t| \"deleteMany\"\n\t\t\t\t\t| \"count\";\n\t\t\t\t/**\n\t\t\t\t * The model name.\n\t\t\t\t */\n\t\t\t\tmodel: string;\n\t\t\t\t/**\n\t\t\t\t * The schema of the user's Better-Auth instance.\n\t\t\t\t */\n\t\t\t\tschema: BetterAuthDBSchema;\n\t\t\t\t/**\n\t\t\t\t * The options of the user's Better-Auth instance.\n\t\t\t\t */\n\t\t\t\toptions: Options;\n\t\t }) => any)\n\t\t| undefined;\n\t/**\n\t * Custom transform output function.\n\t *\n\t * This function is used to transform the output data before it is returned to the user.\n\t */\n\tcustomTransformOutput?:\n\t\t| ((props: {\n\t\t\t\tdata: any;\n\t\t\t\t/**\n\t\t\t\t * The fields of the model.\n\t\t\t\t */\n\t\t\t\tfieldAttributes: DBFieldAttribute;\n\t\t\t\t/**\n\t\t\t\t * The field to transform.\n\t\t\t\t */\n\t\t\t\tfield: string;\n\t\t\t\t/**\n\t\t\t\t * The fields to select.\n\t\t\t\t */\n\t\t\t\tselect: string[];\n\t\t\t\t/**\n\t\t\t\t * The model name.\n\t\t\t\t */\n\t\t\t\tmodel: string;\n\t\t\t\t/**\n\t\t\t\t * The schema of the user's Better-Auth instance.\n\t\t\t\t */\n\t\t\t\tschema: BetterAuthDBSchema;\n\t\t\t\t/**\n\t\t\t\t * The options of the user's Better-Auth instance.\n\t\t\t\t */\n\t\t\t\toptions: Options;\n\t\t }) => any)\n\t\t| undefined;\n\t/**\n\t * Custom ID generator function.\n\t *\n\t * By default, we can handle ID generation for you, however if the database your adapter is for only supports a specific custom id generation,\n\t * then you can use this function to generate your own IDs.\n\t *\n\t *\n\t * Notes:\n\t * - 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`.\n\t * - If `generateId` is `false` in the user's Better-Auth config, then this option will be ignored.\n\t * - If `generateId` is a function, then it will override this option.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * customIdGenerator: ({ model }) => {\n\t * return \"my-super-unique-id\";\n\t * }\n\t * ```\n\t */\n\tcustomIdGenerator?: ((props: { model: string }) => string) | undefined;\n\t/**\n\t * Whether to disable the transform output.\n\t * Do not use this option unless you know what you are doing.\n\t * @default false\n\t */\n\tdisableTransformOutput?: boolean | undefined;\n\t/**\n\t * Whether to disable the transform input.\n\t * Do not use this option unless you know what you are doing.\n\t * @default false\n\t */\n\tdisableTransformInput?: boolean | undefined;\n\t/**\n\t * Whether to disable the transform join.\n\t * Do not use this option unless you know what you are doing.\n\t * @default false\n\t */\n\tdisableTransformJoin?: boolean | undefined;\n}\n\nexport const whereOperators = [\n\t\"eq\",\n\t\"ne\",\n\t\"lt\",\n\t\"lte\",\n\t\"gt\",\n\t\"gte\",\n\t\"in\",\n\t\"not_in\",\n\t\"contains\",\n\t\"starts_with\",\n\t\"ends_with\",\n] as const;\n\nexport type WhereOperator = (typeof whereOperators)[number];\n\nexport type Where = {\n\t/**\n\t * @default eq\n\t */\n\toperator?: WhereOperator | undefined;\n\tvalue: string | number | boolean | string[] | number[] | Date | null;\n\tfield: string;\n\t/**\n\t * @default AND\n\t */\n\tconnector?: (\"AND\" | \"OR\") | undefined;\n};\n\n/**\n * JoinOption configuration for relational queries.\n *\n * Allows you to join related tables/models in a single query operation.\n * Each key represents the name of the joined table/model, and the value\n * configures how the join should be performed.\n */\nexport type JoinOption = {\n\t[model: string]: boolean | { limit?: number };\n};\n\n/**\n * Once `JoinOption` has gone through the adapter factory, it will be transformed into a `JoinConfig`.\n */\nexport type JoinConfig = {\n\t[model: string]: {\n\t\t/**\n\t\t * The joining column names.\n\t\t */\n\t\ton: {\n\t\t\t/**\n\t\t\t * Column name from the main table\n\t\t\t */\n\t\t\tfrom: string;\n\t\t\t/**\n\t\t\t * Column name from the joined table\n\t\t\t */\n\t\t\tto: string;\n\t\t};\n\t\t/**\n\t\t * Limit the number of rows to return.\n\t\t *\n\t\t * If the relation has `unique` constraint, then this option will be ignored and limit will be set to 1.\n\t\t *\n\t\t * @default 100\n\t\t */\n\t\tlimit?: number;\n\t\t/**\n\t\t * The relation type. Determines the output joined model data.\n\t\t *\n\t\t * `one-to-one` would have a single object in the output.\n\t\t * `one-to-many` would have an array of objects in the output.\n\t\t * `many-to-many` would have an array of objects in the output.\n\t\t *\n\t\t * @default \"one-to-many\"\n\t\t */\n\t\trelation?: \"one-to-one\" | \"one-to-many\" | \"many-to-many\";\n\t};\n};\n\nexport type DBTransactionAdapter<\n\tOptions extends BetterAuthOptions = BetterAuthOptions,\n> = Omit<DBAdapter<Options>, \"transaction\">;\n\nexport type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {\n\tid: string;\n\tcreate: <T extends Record<string, any>, R = T>(data: {\n\t\tmodel: string;\n\t\tdata: Omit<T, \"id\">;\n\t\tselect?: string[] | undefined;\n\t\t/**\n\t\t * By default, any `id` provided in `data` will be ignored.\n\t\t *\n\t\t * If you want to force the `id` to be the same as the `data.id`, set this to `true`.\n\t\t */\n\t\tforceAllowId?: boolean | undefined;\n\t}) => Promise<R>;\n\tfindOne: <T>(data: {\n\t\tmodel: string;\n\t\twhere: Where[];\n\t\tselect?: string[] | undefined;\n\t\tjoin?: JoinOption | undefined;\n\t}) => Promise<T | null>;\n\tfindMany: <T>(data: {\n\t\tmodel: string;\n\t\twhere?: Where[] | undefined;\n\t\tlimit?: number | undefined;\n\t\tselect?: string[] | undefined;\n\t\tsortBy?:\n\t\t\t| {\n\t\t\t\t\tfield: string;\n\t\t\t\t\tdirection: \"asc\" | \"desc\";\n\t\t\t }\n\t\t\t| undefined;\n\t\toffset?: number | undefined;\n\t\tjoin?: JoinOption | undefined;\n\t}) => Promise<T[]>;\n\tcount: (data: {\n\t\tmodel: string;\n\t\twhere?: Where[] | undefined;\n\t}) => Promise<number>;\n\t/**\n\t * ⚠︎ Update may not return the updated data\n\t * if multiple where clauses are provided\n\t */\n\tupdate: <T>(data: {\n\t\tmodel: string;\n\t\twhere: Where[];\n\t\tupdate: Record<string, any>;\n\t}) => Promise<T | null>;\n\tupdateMany: (data: {\n\t\tmodel: string;\n\t\twhere: Where[];\n\t\tupdate: Record<string, any>;\n\t}) => Promise<number>;\n\tdelete: <_T>(data: { model: string; where: Where[] }) => Promise<void>;\n\tdeleteMany: (data: { model: string; where: Where[] }) => Promise<number>;\n\t/**\n\t * Execute multiple operations in a transaction.\n\t * If the adapter doesn't support transactions, operations will be executed sequentially.\n\t */\n\ttransaction: <R>(\n\t\tcallback: (trx: DBTransactionAdapter<Options>) => Promise<R>,\n\t) => Promise<R>;\n\t/**\n\t *\n\t * @param options\n\t * @param file - file path if provided by the user\n\t */\n\tcreateSchema?:\n\t\t| ((options: Options, file?: string) => Promise<DBAdapterSchemaCreation>)\n\t\t| undefined;\n\toptions?:\n\t\t| ({\n\t\t\t\tadapterConfig: DBAdapterFactoryConfig<Options>;\n\t\t } & CustomAdapter[\"options\"])\n\t\t| undefined;\n};\n\nexport type CleanedWhere = Required<Where>;\n\nexport interface CustomAdapter {\n\tcreate: <T extends Record<string, any>>({\n\t\tdata,\n\t\tmodel,\n\t\tselect,\n\t}: {\n\t\tmodel: string;\n\t\tdata: T;\n\t\tselect?: string[] | undefined;\n\t}) => Promise<T>;\n\tupdate: <T>(data: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t\tupdate: T;\n\t}) => Promise<T | null>;\n\tupdateMany: (data: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t\tupdate: Record<string, any>;\n\t}) => Promise<number>;\n\tfindOne: <T>({\n\t\tmodel,\n\t\twhere,\n\t\tselect,\n\t\tjoin,\n\t}: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t\tselect?: string[] | undefined;\n\t\tjoin?: JoinConfig | undefined;\n\t}) => Promise<T | null>;\n\tfindMany: <T>({\n\t\tmodel,\n\t\twhere,\n\t\tlimit,\n\t\tselect,\n\t\tsortBy,\n\t\toffset,\n\t\tjoin,\n\t}: {\n\t\tmodel: string;\n\t\twhere?: CleanedWhere[] | undefined;\n\t\tlimit: number;\n\t\tselect?: string[] | undefined;\n\t\tsortBy?: { field: string; direction: \"asc\" | \"desc\" } | undefined;\n\t\toffset?: number | undefined;\n\t\tjoin?: JoinConfig | undefined;\n\t}) => Promise<T[]>;\n\tdelete: ({\n\t\tmodel,\n\t\twhere,\n\t}: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t}) => Promise<void>;\n\tdeleteMany: ({\n\t\tmodel,\n\t\twhere,\n\t}: {\n\t\tmodel: string;\n\t\twhere: CleanedWhere[];\n\t}) => Promise<number>;\n\tcount: ({\n\t\tmodel,\n\t\twhere,\n\t}: {\n\t\tmodel: string;\n\t\twhere?: CleanedWhere[] | undefined;\n\t}) => Promise<number>;\n\tcreateSchema?:\n\t\t| ((props: {\n\t\t\t\t/**\n\t\t\t\t * The file the user may have passed in to the `generate` command as the expected schema file output path.\n\t\t\t\t */\n\t\t\t\tfile?: string;\n\t\t\t\t/**\n\t\t\t\t * The tables from the user's Better-Auth instance schema.\n\t\t\t\t */\n\t\t\t\ttables: BetterAuthDBSchema;\n\t\t }) => Promise<DBAdapterSchemaCreation>)\n\t\t| undefined;\n\t/**\n\t * Your adapter's options.\n\t */\n\toptions?: Record<string, any> | undefined;\n}\n\nexport interface DBAdapterInstance<\n\tOptions extends BetterAuthOptions = BetterAuthOptions,\n> {\n\t(options: BetterAuthOptions): DBAdapter<Options>;\n}\n\nexport * from \"./factory\";\nexport * from \"./types\";\nexport * from \"./utils\";\n"],"mappings":";;;;;;;;;AA+SA,MAAa,iBAAiB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/db/adapter/utils.ts"],"sourcesContent":["import type { DBFieldAttribute } from \"../type\";\n\nexport function withApplyDefault(\n\tvalue: any,\n\tfield: DBFieldAttribute,\n\taction: \"create\" | \"update\" | \"findOne\" | \"findMany\",\n) {\n\tif (action === \"update\") {\n\t\t// Apply onUpdate if value is undefined\n\t\tif (value === undefined && field.onUpdate !== undefined) {\n\t\t\tif (typeof field.onUpdate === \"function\") {\n\t\t\t\treturn field.onUpdate();\n\t\t\t}\n\t\t\treturn field.onUpdate;\n\t\t}\n\t\treturn value;\n\t}\n\tif (action === \"create\") {\n\t\t// we do not want to apply default values if the value is null & not required\n\t\tif (value === undefined || (field.required === true && value === null)) {\n\t\t\tif (field.defaultValue !== undefined) {\n\t\t\t\tif (typeof field.defaultValue === \"function\") {\n\t\t\t\t\treturn field.defaultValue();\n\t\t\t\t}\n\t\t\t\treturn field.defaultValue;\n\t\t\t}\n\t\t}\n\t}\n\treturn value;\n}\n\nfunction isObject(item: unknown): item is Record<string, unknown> {\n\treturn item !== null && typeof item === \"object\" && !Array.isArray(item);\n}\n\nexport function deepmerge<T>(target: T, source: Partial<T>): T {\n\tif (Array.isArray(target) && Array.isArray(source)) {\n\t\t// merge arrays by concatenation\n\t\treturn [...target, ...source] as T;\n\t} else if (isObject(target) && isObject(source)) {\n\t\tconst result: Record<string, unknown> = { ...target };\n\n\t\tfor (const [key, value] of Object.entries(source)) {\n\t\t\tif (value === undefined) continue; // skip undefined\n\n\t\t\tif (key in target) {\n\t\t\t\tresult[key] = deepmerge(\n\t\t\t\t\t(target as Record<string, unknown>)[key],\n\t\t\t\t\tvalue as unknown as Partial<T>,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tresult[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn result as T;\n\t}\n\n\t// primitives and fallback: source overrides target\n\treturn source as T;\n}\n"],"mappings":";AAEA,SAAgB,iBACf,OACA,OACA,QACC;AACD,KAAI,WAAW,UAAU;AAExB,MAAI,UAAU,KAAA,KAAa,MAAM,aAAa,KAAA,GAAW;AACxD,OAAI,OAAO,MAAM,aAAa,WAC7B,QAAO,MAAM,UAAU;AAExB,UAAO,MAAM;;AAEd,SAAO;;AAER,KAAI,WAAW;MAEV,UAAU,KAAA,KAAc,MAAM,aAAa,QAAQ,UAAU;OAC5D,MAAM,iBAAiB,KAAA,GAAW;AACrC,QAAI,OAAO,MAAM,iBAAiB,WACjC,QAAO,MAAM,cAAc;AAE5B,WAAO,MAAM;;;;AAIhB,QAAO;;AAGR,SAAS,SAAS,MAAgD;AACjE,QAAO,SAAS,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,KAAK;;AAGzE,SAAgB,UAAa,QAAW,QAAuB;AAC9D,KAAI,MAAM,QAAQ,OAAO,IAAI,MAAM,QAAQ,OAAO,CAEjD,QAAO,CAAC,GAAG,QAAQ,GAAG,OAAO;UACnB,SAAS,OAAO,IAAI,SAAS,OAAO,EAAE;EAChD,MAAM,SAAkC,EAAE,GAAG,QAAQ;AAErD,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,EAAE;AAClD,OAAI,UAAU,KAAA,EAAW;AAEzB,OAAI,OAAO,OACV,QAAO,OAAO,UACZ,OAAmC,MACpC,MACA;OAED,QAAO,OAAO;;AAIhB,SAAO;;AAIR,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-tables.mjs","names":[],"sources":["../../src/db/get-tables.ts"],"sourcesContent":["import type { BetterAuthOptions } from \"../types\";\nimport type { BetterAuthDBSchema, DBFieldAttribute } from \"./type\";\n\nexport const getAuthTables = (\n\toptions: BetterAuthOptions,\n): BetterAuthDBSchema => {\n\tconst pluginSchema = (options.plugins ?? []).reduce(\n\t\t(acc, plugin) => {\n\t\t\tconst schema = plugin.schema;\n\t\t\tif (!schema) return acc;\n\t\t\tfor (const [key, value] of Object.entries(schema)) {\n\t\t\t\tacc[key] = {\n\t\t\t\t\tfields: {\n\t\t\t\t\t\t...acc[key]?.fields,\n\t\t\t\t\t\t...value.fields,\n\t\t\t\t\t},\n\t\t\t\t\tmodelName: value.modelName || key,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<\n\t\t\tstring,\n\t\t\t{ fields: Record<string, DBFieldAttribute>; modelName: string }\n\t\t>,\n\t);\n\n\tconst shouldAddRateLimitTable = options.rateLimit?.storage === \"database\";\n\tconst rateLimitTable = {\n\t\trateLimit: {\n\t\t\tmodelName: options.rateLimit?.modelName || \"rateLimit\",\n\t\t\tfields: {\n\t\t\t\tkey: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tunique: true,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.rateLimit?.fields?.key || \"key\",\n\t\t\t\t},\n\t\t\t\tcount: {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.rateLimit?.fields?.count || \"count\",\n\t\t\t\t},\n\t\t\t\tlastRequest: {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tbigint: true,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.rateLimit?.fields?.lastRequest || \"lastRequest\",\n\t\t\t\t\tdefaultValue: () => Date.now(),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t} satisfies BetterAuthDBSchema;\n\n\tconst { user, session, account, verification, ...pluginTables } =\n\t\tpluginSchema;\n\n\tconst verificationTable = {\n\t\tverification: {\n\t\t\tmodelName: options.verification?.modelName || \"verification\",\n\t\t\tfields: {\n\t\t\t\tidentifier: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.verification?.fields?.identifier || \"identifier\",\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.verification?.fields?.value || \"value\",\n\t\t\t\t},\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.verification?.fields?.expiresAt || \"expiresAt\",\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\tfieldName: options.verification?.fields?.createdAt || \"createdAt\",\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t\tfieldName: options.verification?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t},\n\t\t\t\t...verification?.fields,\n\t\t\t\t...options.verification?.additionalFields,\n\t\t\t},\n\t\t\torder: 4,\n\t\t},\n\t} satisfies BetterAuthDBSchema;\n\n\tconst sessionTable = {\n\t\tsession: {\n\t\t\tmodelName: options.session?.modelName || \"session\",\n\t\t\tfields: {\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.expiresAt || \"expiresAt\",\n\t\t\t\t},\n\t\t\t\ttoken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.token || \"token\",\n\t\t\t\t\tunique: true,\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.createdAt || \"createdAt\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t},\n\t\t\t\tipAddress: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.session?.fields?.ipAddress || \"ipAddress\",\n\t\t\t\t},\n\t\t\t\tuserAgent: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.session?.fields?.userAgent || \"userAgent\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tfieldName: options.session?.fields?.userId || \"userId\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: options.user?.modelName || \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t\trequired: true,\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t\t...session?.fields,\n\t\t\t\t...options.session?.additionalFields,\n\t\t\t},\n\t\t\torder: 2,\n\t\t},\n\t} satisfies BetterAuthDBSchema;\n\n\treturn {\n\t\tuser: {\n\t\t\tmodelName: options.user?.modelName || \"user\",\n\t\t\tfields: {\n\t\t\t\tname: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.name || \"name\",\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\temail: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tunique: true,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.email || \"email\",\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\temailVerified: {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdefaultValue: false,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.emailVerified || \"emailVerified\",\n\t\t\t\t\tinput: false,\n\t\t\t\t},\n\t\t\t\timage: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.user?.fields?.image || \"image\",\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.createdAt || \"createdAt\",\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t},\n\t\t\t\t...user?.fields,\n\t\t\t\t...options.user?.additionalFields,\n\t\t\t},\n\t\t\torder: 1,\n\t\t},\n\t\t//only add session table if it's not stored in secondary storage\n\t\t...(!options.secondaryStorage || options.session?.storeSessionInDatabase\n\t\t\t? sessionTable\n\t\t\t: {}),\n\t\taccount: {\n\t\t\tmodelName: options.account?.modelName || \"account\",\n\t\t\tfields: {\n\t\t\t\taccountId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.accountId || \"accountId\",\n\t\t\t\t},\n\t\t\t\tproviderId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.providerId || \"providerId\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: options.user?.modelName || \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.userId || \"userId\",\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t\taccessToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.accessToken || \"accessToken\",\n\t\t\t\t},\n\t\t\t\trefreshToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.refreshToken || \"refreshToken\",\n\t\t\t\t},\n\t\t\t\tidToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.idToken || \"idToken\",\n\t\t\t\t},\n\t\t\t\taccessTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName:\n\t\t\t\t\t\toptions.account?.fields?.accessTokenExpiresAt ||\n\t\t\t\t\t\t\"accessTokenExpiresAt\",\n\t\t\t\t},\n\t\t\t\trefreshTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName:\n\t\t\t\t\t\toptions.account?.fields?.refreshTokenExpiresAt ||\n\t\t\t\t\t\t\"refreshTokenExpiresAt\",\n\t\t\t\t},\n\t\t\t\tscope: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.account?.fields?.scope || \"scope\",\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.password || \"password\",\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.createdAt || \"createdAt\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t},\n\t\t\t\t...account?.fields,\n\t\t\t\t...options.account?.additionalFields,\n\t\t\t},\n\t\t\torder: 3,\n\t\t},\n\t\t...(!options.secondaryStorage || options.verification?.storeInDatabase\n\t\t\t? verificationTable\n\t\t\t: {}),\n\t\t...pluginTables,\n\t\t...(shouldAddRateLimitTable ? rateLimitTable : {}),\n\t} satisfies BetterAuthDBSchema;\n};\n"],"mappings":";AAGA,MAAa,iBACZ,Y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WACC,QAAQ,SAAS,QAAQ,wBACzB;KACD;IACD,uBAAuB;KACtB,MAAM;KACN,UAAU;KACV,UAAU;KACV,WACC,QAAQ,SAAS,QAAQ,yBACzB;KACD;IACD,OAAO;KACN,MAAM;KACN,UAAU;KACV,WAAW,QAAQ,SAAS,QAAQ,SAAS;KAC7C;IACD,UAAU;KACT,MAAM;KACN,UAAU;KACV,UAAU;KACV,WAAW,QAAQ,SAAS,QAAQ,YAAY;KAChD;IACD,WAAW;KACV,MAAM;KACN,UAAU;KACV,WAAW,QAAQ,SAAS,QAAQ,aAAa;KACjD,oCAAoB,IAAI,MAAM;KAC9B;IACD,WAAW;KACV,MAAM;KACN,UAAU;KACV,WAAW,QAAQ,SAAS,QAAQ,aAAa;KACjD,gCAAgB,IAAI,MAAM;KAC1B;IACD,GAAG,SAAS;IACZ,GAAG,QAAQ,SAAS;IACpB;GACD,OAAO;GACP;EACD,GAAI,CAAC,QAAQ,oBAAoB,QAAQ,cAAc,kBACpD,oBACA,EAAE;EACL,GAAG;EACH,GAAI,0BAA0B,iBAAiB,EAAE;EACjD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.mjs","names":[],"sources":["../../../src/db/schema/account.ts"],"sourcesContent":["import * as z from \"zod\";\nimport type { Prettify } from \"../../types\";\nimport type { BetterAuthOptions } from \"../../types/init-options\";\nimport type {\n\tInferDBFieldsFromOptions,\n\tInferDBFieldsFromPlugins,\n} from \"../type\";\nimport { coreSchema } from \"./shared\";\n\nexport const accountSchema = coreSchema.extend({\n\tproviderId: z.string(),\n\taccountId: z.string(),\n\tuserId: z.coerce.string(),\n\taccessToken: z.string().nullish(),\n\trefreshToken: z.string().nullish(),\n\tidToken: z.string().nullish(),\n\t/**\n\t * Access token expires at\n\t */\n\taccessTokenExpiresAt: z.date().nullish(),\n\t/**\n\t * Refresh token expires at\n\t */\n\trefreshTokenExpiresAt: z.date().nullish(),\n\t/**\n\t * The scopes that the user has authorized\n\t */\n\tscope: z.string().nullish(),\n\t/**\n\t * Password is only stored in the credential provider\n\t */\n\tpassword: z.string().nullish(),\n});\n\nexport type BaseAccount = z.infer<typeof accountSchema>;\n\n/**\n * Account schema type used by better-auth, note that it's possible that account could have additional fields\n */\nexport type Account<\n\tDBOptions extends BetterAuthOptions[\"account\"] = BetterAuthOptions[\"account\"],\n\tPlugins extends BetterAuthOptions[\"plugins\"] = BetterAuthOptions[\"plugins\"],\n> = Prettify<\n\tBaseAccount &\n\t\tInferDBFieldsFromOptions<DBOptions> &\n\t\tInferDBFieldsFromPlugins<\"account\", Plugins>\n>;\n"],"mappings":";;;AASA,MAAa,gBAAgB,WAAW,OAAO;CAC9C,YAAY,EAAE,QAAQ;CACtB,WAAW,EAAE,QAAQ;CACrB,QAAQ,EAAE,OAAO,QAAQ;CACzB,aAAa,EAAE,QAAQ,CAAC,SAAS;CACjC,cAAc,EAAE,QAAQ,CAAC,SAAS;CAClC,SAAS,EAAE,QAAQ,CAAC,SAAS;CAI7B,sBAAsB,EAAE,MAAM,CAAC,SAAS;CAIxC,uBAAuB,EAAE,MAAM,CAAC,SAAS;CAIzC,OAAO,EAAE,QAAQ,CAAC,SAAS;CAI3B,UAAU,EAAE,QAAQ,CAAC,SAAS;CAC9B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"rate-limit.mjs","names":[],"sources":["../../../src/db/schema/rate-limit.ts"],"sourcesContent":["import * as z from \"zod\";\nimport type { BetterAuthOptions, Prettify } from \"../../types\";\nimport type {\n\tInferDBFieldsFromOptions,\n\tInferDBFieldsFromPlugins,\n} from \"../type\";\n\nexport const rateLimitSchema = z.object({\n\t/**\n\t * The key to use for rate limiting\n\t */\n\tkey: z.string(),\n\t/**\n\t * The number of requests made\n\t */\n\tcount: z.number(),\n\t/**\n\t * The last request time in milliseconds\n\t */\n\tlastRequest: z.number(),\n});\n\nexport type BaseRateLimit = z.infer<typeof rateLimitSchema>;\n\n/**\n * Rate limit schema type used by better-auth for rate limiting\n */\nexport type RateLimit<\n\tDBOptions extends\n\t\tBetterAuthOptions[\"rateLimit\"] = BetterAuthOptions[\"rateLimit\"],\n\tPlugins extends BetterAuthOptions[\"plugins\"] = BetterAuthOptions[\"plugins\"],\n> = Prettify<\n\tBaseRateLimit &\n\t\tInferDBFieldsFromOptions<DBOptions> &\n\t\tInferDBFieldsFromPlugins<\"rateLimit\", Plugins>\n>;\n"],"mappings":";;AAOA,MAAa,kBAAkB,EAAE,OAAO;CAIvC,KAAK,EAAE,QAAQ;CAIf,OAAO,EAAE,QAAQ;CAIjB,aAAa,EAAE,QAAQ;CACvB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"session.mjs","names":[],"sources":["../../../src/db/schema/session.ts"],"sourcesContent":["import * as z from \"zod\";\nimport type { BetterAuthOptions, Prettify } from \"../../types\";\nimport type {\n\tInferDBFieldsFromOptions,\n\tInferDBFieldsFromPlugins,\n} from \"../type\";\nimport { coreSchema } from \"./shared\";\n\nexport const sessionSchema = coreSchema.extend({\n\tuserId: z.coerce.string(),\n\texpiresAt: z.date(),\n\ttoken: z.string(),\n\tipAddress: z.string().nullish(),\n\tuserAgent: z.string().nullish(),\n});\n\nexport type BaseSession = z.infer<typeof sessionSchema>;\n\n/**\n * Session schema type used by better-auth, note that it's possible that session could have additional fields\n */\nexport type Session<\n\tDBOptions extends BetterAuthOptions[\"session\"] = BetterAuthOptions[\"session\"],\n\tPlugins extends BetterAuthOptions[\"plugins\"] = BetterAuthOptions[\"plugins\"],\n> = Prettify<\n\tz.infer<typeof sessionSchema> &\n\t\tInferDBFieldsFromOptions<DBOptions> &\n\t\tInferDBFieldsFromPlugins<\"session\", Plugins>\n>;\n"],"mappings":";;;AAQA,MAAa,gBAAgB,WAAW,OAAO;CAC9C,QAAQ,EAAE,OAAO,QAAQ;CACzB,WAAW,EAAE,MAAM;CACnB,OAAO,EAAE,QAAQ;CACjB,WAAW,EAAE,QAAQ,CAAC,SAAS;CAC/B,WAAW,EAAE,QAAQ,CAAC,SAAS;CAC/B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"shared.mjs","names":[],"sources":["../../../src/db/schema/shared.ts"],"sourcesContent":["import * as z from \"zod\";\n\nexport const coreSchema = z.object({\n\tid: z.string(),\n\tcreatedAt: z.date().default(() => new Date()),\n\tupdatedAt: z.date().default(() => new Date()),\n});\n"],"mappings":";;AAEA,MAAa,aAAa,EAAE,OAAO;CAClC,IAAI,EAAE,QAAQ;CACd,WAAW,EAAE,MAAM,CAAC,8BAAc,IAAI,MAAM,CAAC;CAC7C,WAAW,EAAE,MAAM,CAAC,8BAAc,IAAI,MAAM,CAAC;CAC7C,CAAC"}