@better-auth/core 1.4.17 → 1.4.19

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 (261) hide show
  1. package/.turbo/turbo-build.log +253 -176
  2. package/dist/api/index.d.mts +11 -5
  3. package/dist/api/index.mjs +2 -1
  4. package/dist/api/index.mjs.map +1 -0
  5. package/dist/async_hooks/index.d.mts +2 -1
  6. package/dist/async_hooks/index.mjs +2 -1
  7. package/dist/async_hooks/index.mjs.map +1 -0
  8. package/dist/async_hooks/pure.index.d.mts +2 -1
  9. package/dist/async_hooks/pure.index.mjs +2 -1
  10. package/dist/async_hooks/pure.index.mjs.map +1 -0
  11. package/dist/context/endpoint-context.d.mts +2 -1
  12. package/dist/context/endpoint-context.mjs +2 -1
  13. package/dist/context/endpoint-context.mjs.map +1 -0
  14. package/dist/context/global.d.mts +2 -1
  15. package/dist/context/global.mjs +3 -2
  16. package/dist/context/global.mjs.map +1 -0
  17. package/dist/context/request-state.d.mts +2 -1
  18. package/dist/context/request-state.mjs +2 -1
  19. package/dist/context/request-state.mjs.map +1 -0
  20. package/dist/context/transaction.d.mts +2 -1
  21. package/dist/context/transaction.mjs +2 -1
  22. package/dist/context/transaction.mjs.map +1 -0
  23. package/dist/db/adapter/factory.d.mts +2 -1
  24. package/dist/db/adapter/factory.mjs +9 -27
  25. package/dist/db/adapter/factory.mjs.map +1 -0
  26. package/dist/db/adapter/get-default-field-name.d.mts +2 -1
  27. package/dist/db/adapter/get-default-field-name.mjs +2 -1
  28. package/dist/db/adapter/get-default-field-name.mjs.map +1 -0
  29. package/dist/db/adapter/get-default-model-name.d.mts +2 -1
  30. package/dist/db/adapter/get-default-model-name.mjs +2 -1
  31. package/dist/db/adapter/get-default-model-name.mjs.map +1 -0
  32. package/dist/db/adapter/get-field-attributes.d.mts +2 -1
  33. package/dist/db/adapter/get-field-attributes.mjs +2 -1
  34. package/dist/db/adapter/get-field-attributes.mjs.map +1 -0
  35. package/dist/db/adapter/get-field-name.d.mts +2 -1
  36. package/dist/db/adapter/get-field-name.mjs +2 -1
  37. package/dist/db/adapter/get-field-name.mjs.map +1 -0
  38. package/dist/db/adapter/get-id-field.d.mts +2 -1
  39. package/dist/db/adapter/get-id-field.mjs +2 -1
  40. package/dist/db/adapter/get-id-field.mjs.map +1 -0
  41. package/dist/db/adapter/get-model-name.d.mts +2 -1
  42. package/dist/db/adapter/get-model-name.mjs +2 -1
  43. package/dist/db/adapter/get-model-name.mjs.map +1 -0
  44. package/dist/db/adapter/index.d.mts +5 -1
  45. package/dist/db/adapter/types.d.mts +2 -1
  46. package/dist/db/adapter/utils.d.mts +2 -1
  47. package/dist/db/adapter/utils.mjs +2 -1
  48. package/dist/db/adapter/utils.mjs.map +1 -0
  49. package/dist/db/get-tables.d.mts +2 -1
  50. package/dist/db/get-tables.mjs +8 -2
  51. package/dist/db/get-tables.mjs.map +1 -0
  52. package/dist/db/plugin.d.mts +2 -1
  53. package/dist/db/schema/account.d.mts +2 -1
  54. package/dist/db/schema/account.mjs +2 -1
  55. package/dist/db/schema/account.mjs.map +1 -0
  56. package/dist/db/schema/rate-limit.d.mts +2 -1
  57. package/dist/db/schema/rate-limit.mjs +2 -1
  58. package/dist/db/schema/rate-limit.mjs.map +1 -0
  59. package/dist/db/schema/session.d.mts +2 -1
  60. package/dist/db/schema/session.mjs +2 -1
  61. package/dist/db/schema/session.mjs.map +1 -0
  62. package/dist/db/schema/shared.d.mts +2 -1
  63. package/dist/db/schema/shared.mjs +2 -1
  64. package/dist/db/schema/shared.mjs.map +1 -0
  65. package/dist/db/schema/user.d.mts +2 -1
  66. package/dist/db/schema/user.mjs +2 -1
  67. package/dist/db/schema/user.mjs.map +1 -0
  68. package/dist/db/schema/verification.d.mts +2 -1
  69. package/dist/db/schema/verification.mjs +2 -1
  70. package/dist/db/schema/verification.mjs.map +1 -0
  71. package/dist/db/type.d.mts +2 -1
  72. package/dist/env/color-depth.d.mts +2 -1
  73. package/dist/env/color-depth.mjs +2 -1
  74. package/dist/env/color-depth.mjs.map +1 -0
  75. package/dist/env/env-impl.d.mts +3 -2
  76. package/dist/env/env-impl.mjs +3 -2
  77. package/dist/env/env-impl.mjs.map +1 -0
  78. package/dist/env/logger.d.mts +2 -1
  79. package/dist/env/logger.mjs +3 -2
  80. package/dist/env/logger.mjs.map +1 -0
  81. package/dist/error/codes.d.mts +2 -1
  82. package/dist/error/codes.mjs +2 -1
  83. package/dist/error/codes.mjs.map +1 -0
  84. package/dist/error/index.d.mts +2 -1
  85. package/dist/error/index.mjs +2 -1
  86. package/dist/error/index.mjs.map +1 -0
  87. package/dist/index.d.mts +2 -2
  88. package/dist/oauth2/client-credentials-token.d.mts +2 -1
  89. package/dist/oauth2/client-credentials-token.mjs +2 -1
  90. package/dist/oauth2/client-credentials-token.mjs.map +1 -0
  91. package/dist/oauth2/create-authorization-url.d.mts +2 -1
  92. package/dist/oauth2/create-authorization-url.mjs +2 -1
  93. package/dist/oauth2/create-authorization-url.mjs.map +1 -0
  94. package/dist/oauth2/oauth-provider.d.mts +3 -2
  95. package/dist/oauth2/refresh-access-token.d.mts +2 -1
  96. package/dist/oauth2/refresh-access-token.mjs +2 -1
  97. package/dist/oauth2/refresh-access-token.mjs.map +1 -0
  98. package/dist/oauth2/utils.d.mts +2 -1
  99. package/dist/oauth2/utils.mjs +2 -1
  100. package/dist/oauth2/utils.mjs.map +1 -0
  101. package/dist/oauth2/validate-authorization-code.d.mts +6 -2
  102. package/dist/oauth2/validate-authorization-code.mjs +7 -12
  103. package/dist/oauth2/validate-authorization-code.mjs.map +1 -0
  104. package/dist/oauth2/verify.d.mts +2 -1
  105. package/dist/oauth2/verify.mjs +2 -1
  106. package/dist/oauth2/verify.mjs.map +1 -0
  107. package/dist/social-providers/apple.d.mts +2 -1
  108. package/dist/social-providers/apple.mjs +22 -15
  109. package/dist/social-providers/apple.mjs.map +1 -0
  110. package/dist/social-providers/atlassian.d.mts +2 -1
  111. package/dist/social-providers/atlassian.mjs +2 -1
  112. package/dist/social-providers/atlassian.mjs.map +1 -0
  113. package/dist/social-providers/cognito.d.mts +2 -1
  114. package/dist/social-providers/cognito.mjs +2 -1
  115. package/dist/social-providers/cognito.mjs.map +1 -0
  116. package/dist/social-providers/discord.d.mts +2 -1
  117. package/dist/social-providers/discord.mjs +2 -1
  118. package/dist/social-providers/discord.mjs.map +1 -0
  119. package/dist/social-providers/dropbox.d.mts +2 -1
  120. package/dist/social-providers/dropbox.mjs +2 -1
  121. package/dist/social-providers/dropbox.mjs.map +1 -0
  122. package/dist/social-providers/facebook.d.mts +2 -1
  123. package/dist/social-providers/facebook.mjs +5 -4
  124. package/dist/social-providers/facebook.mjs.map +1 -0
  125. package/dist/social-providers/figma.d.mts +2 -1
  126. package/dist/social-providers/figma.mjs +2 -1
  127. package/dist/social-providers/figma.mjs.map +1 -0
  128. package/dist/social-providers/github.d.mts +3 -2
  129. package/dist/social-providers/github.mjs +22 -5
  130. package/dist/social-providers/github.mjs.map +1 -0
  131. package/dist/social-providers/gitlab.d.mts +2 -1
  132. package/dist/social-providers/gitlab.mjs +2 -1
  133. package/dist/social-providers/gitlab.mjs.map +1 -0
  134. package/dist/social-providers/google.d.mts +2 -1
  135. package/dist/social-providers/google.mjs +18 -13
  136. package/dist/social-providers/google.mjs.map +1 -0
  137. package/dist/social-providers/huggingface.d.mts +2 -1
  138. package/dist/social-providers/huggingface.mjs +2 -1
  139. package/dist/social-providers/huggingface.mjs.map +1 -0
  140. package/dist/social-providers/index.d.mts +5 -3
  141. package/dist/social-providers/index.mjs +3 -2
  142. package/dist/social-providers/index.mjs.map +1 -0
  143. package/dist/social-providers/kakao.d.mts +2 -1
  144. package/dist/social-providers/kakao.mjs +2 -1
  145. package/dist/social-providers/kakao.mjs.map +1 -0
  146. package/dist/social-providers/kick.d.mts +2 -1
  147. package/dist/social-providers/kick.mjs +2 -1
  148. package/dist/social-providers/kick.mjs.map +1 -0
  149. package/dist/social-providers/line.d.mts +2 -1
  150. package/dist/social-providers/line.mjs +2 -1
  151. package/dist/social-providers/line.mjs.map +1 -0
  152. package/dist/social-providers/linear.d.mts +2 -1
  153. package/dist/social-providers/linear.mjs +2 -1
  154. package/dist/social-providers/linear.mjs.map +1 -0
  155. package/dist/social-providers/linkedin.d.mts +2 -1
  156. package/dist/social-providers/linkedin.mjs +2 -1
  157. package/dist/social-providers/linkedin.mjs.map +1 -0
  158. package/dist/social-providers/microsoft-entra-id.d.mts +4 -1
  159. package/dist/social-providers/microsoft-entra-id.mjs +36 -2
  160. package/dist/social-providers/microsoft-entra-id.mjs.map +1 -0
  161. package/dist/social-providers/naver.d.mts +2 -1
  162. package/dist/social-providers/naver.mjs +2 -1
  163. package/dist/social-providers/naver.mjs.map +1 -0
  164. package/dist/social-providers/notion.d.mts +2 -1
  165. package/dist/social-providers/notion.mjs +2 -1
  166. package/dist/social-providers/notion.mjs.map +1 -0
  167. package/dist/social-providers/paybin.d.mts +2 -1
  168. package/dist/social-providers/paybin.mjs +2 -1
  169. package/dist/social-providers/paybin.mjs.map +1 -0
  170. package/dist/social-providers/paypal.d.mts +2 -1
  171. package/dist/social-providers/paypal.mjs +2 -1
  172. package/dist/social-providers/paypal.mjs.map +1 -0
  173. package/dist/social-providers/polar.d.mts +2 -1
  174. package/dist/social-providers/polar.mjs +2 -1
  175. package/dist/social-providers/polar.mjs.map +1 -0
  176. package/dist/social-providers/reddit.d.mts +2 -1
  177. package/dist/social-providers/reddit.mjs +2 -1
  178. package/dist/social-providers/reddit.mjs.map +1 -0
  179. package/dist/social-providers/roblox.d.mts +2 -1
  180. package/dist/social-providers/roblox.mjs +2 -1
  181. package/dist/social-providers/roblox.mjs.map +1 -0
  182. package/dist/social-providers/salesforce.d.mts +2 -1
  183. package/dist/social-providers/salesforce.mjs +2 -1
  184. package/dist/social-providers/salesforce.mjs.map +1 -0
  185. package/dist/social-providers/slack.d.mts +2 -1
  186. package/dist/social-providers/slack.mjs +2 -1
  187. package/dist/social-providers/slack.mjs.map +1 -0
  188. package/dist/social-providers/spotify.d.mts +2 -1
  189. package/dist/social-providers/spotify.mjs +2 -1
  190. package/dist/social-providers/spotify.mjs.map +1 -0
  191. package/dist/social-providers/tiktok.d.mts +2 -1
  192. package/dist/social-providers/tiktok.mjs +2 -1
  193. package/dist/social-providers/tiktok.mjs.map +1 -0
  194. package/dist/social-providers/twitch.d.mts +2 -1
  195. package/dist/social-providers/twitch.mjs +2 -1
  196. package/dist/social-providers/twitch.mjs.map +1 -0
  197. package/dist/social-providers/twitter.d.mts +3 -2
  198. package/dist/social-providers/twitter.mjs +2 -1
  199. package/dist/social-providers/twitter.mjs.map +1 -0
  200. package/dist/social-providers/vercel.d.mts +2 -1
  201. package/dist/social-providers/vercel.mjs +2 -1
  202. package/dist/social-providers/vercel.mjs.map +1 -0
  203. package/dist/social-providers/vk.d.mts +2 -1
  204. package/dist/social-providers/vk.mjs +2 -1
  205. package/dist/social-providers/vk.mjs.map +1 -0
  206. package/dist/social-providers/zoom.d.mts +3 -3
  207. package/dist/social-providers/zoom.mjs +2 -1
  208. package/dist/social-providers/zoom.mjs.map +1 -0
  209. package/dist/types/context.d.mts +7 -3
  210. package/dist/types/cookie.d.mts +2 -1
  211. package/dist/types/helper.d.mts +2 -1
  212. package/dist/types/index.d.mts +1 -1
  213. package/dist/types/init-options.d.mts +36 -33
  214. package/dist/types/plugin-client.d.mts +2 -1
  215. package/dist/types/plugin.d.mts +2 -1
  216. package/dist/utils/db.d.mts +13 -0
  217. package/dist/utils/db.mjs +17 -0
  218. package/dist/utils/db.mjs.map +1 -0
  219. package/dist/utils/deprecate.d.mts +2 -1
  220. package/dist/utils/deprecate.mjs +2 -1
  221. package/dist/utils/deprecate.mjs.map +1 -0
  222. package/dist/utils/error-codes.d.mts +2 -1
  223. package/dist/utils/error-codes.mjs +2 -1
  224. package/dist/utils/error-codes.mjs.map +1 -0
  225. package/dist/utils/id.d.mts +2 -1
  226. package/dist/utils/id.mjs +2 -1
  227. package/dist/utils/id.mjs.map +1 -0
  228. package/dist/utils/index.d.mts +2 -1
  229. package/dist/utils/index.mjs +2 -1
  230. package/dist/utils/ip.d.mts +2 -1
  231. package/dist/utils/ip.mjs +2 -1
  232. package/dist/utils/ip.mjs.map +1 -0
  233. package/dist/utils/json.d.mts +2 -1
  234. package/dist/utils/json.mjs +2 -1
  235. package/dist/utils/json.mjs.map +1 -0
  236. package/dist/utils/string.d.mts +2 -1
  237. package/dist/utils/string.mjs +2 -1
  238. package/dist/utils/string.mjs.map +1 -0
  239. package/dist/utils/url.d.mts +2 -1
  240. package/dist/utils/url.mjs +2 -1
  241. package/dist/utils/url.mjs.map +1 -0
  242. package/package.json +1 -1
  243. package/src/db/adapter/factory.ts +5 -41
  244. package/src/db/adapter/index.ts +3 -0
  245. package/src/db/get-tables.ts +5 -0
  246. package/src/env/env-impl.ts +2 -2
  247. package/src/env/logger.ts +1 -1
  248. package/src/oauth2/oauth-provider.ts +1 -1
  249. package/src/oauth2/validate-authorization-code.ts +13 -26
  250. package/src/oauth2/validate-token.test.ts +241 -0
  251. package/src/social-providers/apple.ts +37 -24
  252. package/src/social-providers/facebook.ts +3 -3
  253. package/src/social-providers/github.ts +25 -3
  254. package/src/social-providers/google.ts +18 -14
  255. package/src/social-providers/microsoft-entra-id.ts +84 -1
  256. package/src/types/context.ts +6 -3
  257. package/src/types/index.ts +6 -1
  258. package/src/types/init-options.ts +44 -36
  259. package/src/utils/db.ts +20 -0
  260. package/src/utils/index.ts +1 -0
  261. package/tsdown.config.ts +3 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["path: Path | undefined","options: Opts","handler: EndpointHandler<Path, Opts, R>"],"sources":["../../src/api/index.ts"],"sourcesContent":["import type {\n\tEndpointContext,\n\tEndpointOptions,\n\tStrictEndpoint,\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 EndpointHandler<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n\tR,\n> = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;\n\nexport function createAuthEndpoint<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n\tR,\n>(\n\tpath: Path,\n\toptions: Options,\n\thandler: EndpointHandler<Path, Options, R>,\n): StrictEndpoint<Path, Options, R>;\n\nexport function createAuthEndpoint<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n\tR,\n>(\n\toptions: Options,\n\thandler: EndpointHandler<Path, Options, R>,\n): StrictEndpoint<Path, Options, R>;\n\nexport function createAuthEndpoint<\n\tPath extends string,\n\tOpts extends EndpointOptions,\n\tR,\n>(\n\tpathOrOptions: Path | Opts,\n\thandlerOrOptions: EndpointHandler<Path, Opts, R> | Opts,\n\thandlerOrNever?: any,\n) {\n\tconst path: Path | undefined =\n\t\ttypeof pathOrOptions === \"string\" ? pathOrOptions : undefined;\n\tconst options: Opts =\n\t\ttypeof handlerOrOptions === \"object\"\n\t\t\t? handlerOrOptions\n\t\t\t: (pathOrOptions as Opts);\n\tconst handler: EndpointHandler<Path, Opts, R> =\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},\n\t\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\t\tasync (ctx) => runWithEndpointContext(ctx as any, () => 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},\n\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\tasync (ctx) => runWithEndpointContext(ctx as any, () => handler(ctx)),\n\t);\n}\n\nexport type AuthEndpoint<\n\tPath extends string,\n\tOpts extends EndpointOptions,\n\tR,\n> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;\nexport type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;\n"],"mappings":";;;;;AASA,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;AA2B/B,SAAgB,mBAKf,eACA,kBACA,gBACC;CACD,MAAMA,OACL,OAAO,kBAAkB,WAAW,gBAAgB;CACrD,MAAMC,UACL,OAAO,qBAAqB,WACzB,mBACC;CACL,MAAMC,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,QAAQ,uBAAuB,WAAkB,QAAQ,IAAI,CAAC,CACrE;AAGF,QAAO,eACN;EACC,GAAG;EACH,KAAK,CAAC,GAAI,SAAS,OAAO,EAAE,EAAG,GAAG,IAAI;EACtC,EAED,OAAO,QAAQ,uBAAuB,WAAkB,QAAQ,IAAI,CAAC,CACrE"}
@@ -3,4 +3,5 @@ import { AsyncLocalStorage } from "node:async_hooks";
3
3
  //#region src/async_hooks/index.d.ts
4
4
  declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
5
  //#endregion
6
- export { type AsyncLocalStorage, getAsyncLocalStorage };
6
+ export { type AsyncLocalStorage, getAsyncLocalStorage };
7
+ //# sourceMappingURL=index.d.mts.map
@@ -18,4 +18,5 @@ async function getAsyncLocalStorage() {
18
18
  }
19
19
 
20
20
  //#endregion
21
- export { getAsyncLocalStorage };
21
+ export { getAsyncLocalStorage };
22
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null>"],"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,MAAMA,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"}
@@ -3,4 +3,5 @@ import { AsyncLocalStorage } from "node:async_hooks";
3
3
  //#region src/async_hooks/pure.index.d.ts
4
4
  declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
5
  //#endregion
6
- export { getAsyncLocalStorage };
6
+ export { getAsyncLocalStorage };
7
+ //# sourceMappingURL=pure.index.d.mts.map
@@ -31,4 +31,5 @@ async function getAsyncLocalStorage() {
31
31
  }
32
32
 
33
33
  //#endregion
34
- export { getAsyncLocalStorage };
34
+ export { getAsyncLocalStorage };
35
+ //# sourceMappingURL=pure.index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pure.index.mjs","names":["#current","AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null>"],"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;CAE1B,IAAI,OAAU,IAA4B;EACzC,MAAM,OAAO,MAAKA;AAClB,QAAKA,UAAW;EAChB,MAAM,SAAS,IAAI;AACnB,MAAI,kBAAkB,QACrB,QAAO,OAAO,cAAc;AAC3B,SAAKA,UAAW;IACf;AAEH,QAAKA,UAAW;AAChB,SAAO;;CAGR,WAA0B;AACzB,SAAO,MAAKA;;;AAId,MAAMC,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"}
@@ -16,4 +16,5 @@ declare function getCurrentAuthContextAsyncLocalStorage(): Promise<AsyncLocalSto
16
16
  declare function getCurrentAuthContext(): Promise<AuthEndpointContext>;
17
17
  declare function runWithEndpointContext<T>(context: AuthEndpointContext, fn: () => T): Promise<T>;
18
18
  //#endregion
19
- export { AuthEndpointContext, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext };
19
+ export { AuthEndpointContext, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext };
20
+ //# sourceMappingURL=endpoint-context.d.mts.map
@@ -28,4 +28,5 @@ async function runWithEndpointContext(context, fn) {
28
28
  }
29
29
 
30
30
  //#endregion
31
- export { getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext };
31
+ export { getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext };
32
+ //# sourceMappingURL=endpoint-context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-context.mjs","names":["AsyncLocalStorage"],"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> & EndpointContext<string, any>\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":";;;;AAYA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,6BAA6B;EAC1D,MAAMA,sBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,8BACxB,IAAIA,qBAAwC;;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"}
@@ -4,4 +4,5 @@ import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
4
4
 
5
5
  declare function getBetterAuthVersion(): string;
6
6
  //#endregion
7
- export { getBetterAuthVersion };
7
+ export { getBetterAuthVersion };
8
+ //# sourceMappingURL=global.d.mts.map
@@ -2,7 +2,7 @@
2
2
  const symbol = Symbol.for("better-auth:global");
3
3
  let bind = null;
4
4
  const __context = {};
5
- const __betterAuthVersion = "1.4.17";
5
+ const __betterAuthVersion = "1.4.19";
6
6
  /**
7
7
  * We store context instance in the globalThis.
8
8
  *
@@ -34,4 +34,5 @@ function getBetterAuthVersion() {
34
34
  }
35
35
 
36
36
  //#endregion
37
- export { __getBetterAuthGlobal, getBetterAuthVersion };
37
+ export { __getBetterAuthGlobal, getBetterAuthVersion };
38
+ //# sourceMappingURL=global.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.mjs","names":["bind: BetterAuthGlobal | null","__context: Record<string, AsyncLocalStorage<unknown>>","__betterAuthVersion: string"],"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,IAAIA,OAAgC;AAEpC,MAAMC,YAAwD,EAAE;AAChE,MAAMC;;;;;;;;;;;AAaN,SAAgB,wBAA0C;AACzD,KAAI,CAAE,WAAmB,SAAS;AACjC,EAAC,WAAmB,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"}
@@ -24,4 +24,5 @@ interface RequestState<T> {
24
24
  */
25
25
  declare function defineRequestState<T>(initFn: () => T | Promise<T>): RequestState<T>;
26
26
  //#endregion
27
- export { RequestState, RequestStateWeakMap, defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState };
27
+ export { RequestState, RequestStateWeakMap, defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState };
28
+ //# sourceMappingURL=request-state.d.mts.map
@@ -46,4 +46,5 @@ function defineRequestState(initFn) {
46
46
  }
47
47
 
48
48
  //#endregion
49
- export { defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState };
49
+ export { defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState };
50
+ //# sourceMappingURL=request-state.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-state.mjs","names":["AsyncLocalStorage"],"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,MAAMA,sBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,2BACxB,IAAIA,qBAAwC;;AAE9C,QAAO,iBAAiB,QACtB;;AAGH,eAAsB,mCAAmC;AACxD,QAAO,oBAAoB;;AAG5B,eAAsB,kBAAkB;AAEvC,SADY,MAAM,oBAAoB,EAC3B,UAAU,KAAK;;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"}
@@ -13,4 +13,5 @@ declare const getCurrentAdapter: (fallback: DBTransactionAdapter) => Promise<DBT
13
13
  declare const runWithAdapter: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
14
14
  declare const runWithTransaction: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
15
15
  //#endregion
16
- export { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, runWithAdapter, runWithTransaction };
16
+ export { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, runWithAdapter, runWithTransaction };
17
+ //# sourceMappingURL=transaction.d.mts.map
@@ -49,4 +49,5 @@ const runWithTransaction = async (adapter, fn) => {
49
49
  };
50
50
 
51
51
  //#endregion
52
- export { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, runWithAdapter, runWithTransaction };
52
+ export { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, runWithAdapter, runWithTransaction };
53
+ //# sourceMappingURL=transaction.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.mjs","names":["AsyncLocalStorage"],"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\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<DBTransactionAdapter>;\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\treturn als.getStore() || 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 = true;\n\treturn ensureAsyncStorage()\n\t\t.then((als) => {\n\t\t\tcalled = true;\n\t\t\treturn als.run(adapter, fn);\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((als) => {\n\t\t\tcalled = true;\n\t\t\treturn adapter.transaction(async (trx) => {\n\t\t\t\treturn als.run(trx, fn);\n\t\t\t});\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"],"mappings":";;;;AAKA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,qBAAqB;EAClD,MAAMA,sBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,sBAAsB,IAAIA,qBAAmB;;AAEvE,QAAO,iBAAiB,QACtB;;;;;;;AAQH,MAAa,uCAAuC,YAAY;AAC/D,QAAO,oBAAoB;;AAG5B,MAAa,oBAAoB,OAChC,aACmC;AACnC,QAAO,oBAAoB,CACzB,MAAM,QAAQ;AACd,SAAO,IAAI,UAAU,IAAI;GACxB,CACD,YAAY;AACZ,SAAO;GACN;;AAGJ,MAAa,iBAAiB,OAC7B,SACA,OACgB;CAChB,IAAI,SAAS;AACb,QAAO,oBAAoB,CACzB,MAAM,QAAQ;AACd,WAAS;AACT,SAAO,IAAI,IAAI,SAAS,GAAG;GAC1B,CACD,OAAO,QAAQ;AACf,MAAI,CAAC,OACJ,QAAO,IAAI;AAEZ,QAAM;GACL;;AAGJ,MAAa,qBAAqB,OACjC,SACA,OACgB;CAChB,IAAI,SAAS;AACb,QAAO,oBAAoB,CACzB,MAAM,QAAQ;AACd,WAAS;AACT,SAAO,QAAQ,YAAY,OAAO,QAAQ;AACzC,UAAO,IAAI,IAAI,KAAK,GAAG;IACtB;GACD,CACD,OAAO,QAAQ;AACf,MAAI,CAAC,OACJ,QAAO,IAAI;AAEZ,QAAM;GACL"}
@@ -24,4 +24,5 @@ declare const createAdapter: ({
24
24
  config: cfg
25
25
  }: AdapterFactoryOptions) => AdapterFactory;
26
26
  //#endregion
27
- export { AdapterFactory, createAdapter, createAdapterFactory };
27
+ export { AdapterFactory, createAdapter, createAdapterFactory };
28
+ //# sourceMappingURL=factory.d.mts.map
@@ -543,7 +543,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
543
543
  });
544
544
  return transformed;
545
545
  },
546
- findMany: async ({ model: unsafeModel, where: unsafeWhere, limit: unsafeLimit, sortBy, offset, join: unsafeJoin }) => {
546
+ findMany: async ({ model: unsafeModel, where: unsafeWhere, limit: unsafeLimit, select, sortBy, offset, join: unsafeJoin }) => {
547
547
  transactionId++;
548
548
  const thisTransactionId = transactionId;
549
549
  const limit = unsafeLimit ?? options.advanced?.database?.defaultFindManyLimit ?? 100;
@@ -557,8 +557,11 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
557
557
  let join;
558
558
  let passJoinToAdapter = true;
559
559
  if (!config.disableTransformJoin) {
560
- const result = transformJoinClause(unsafeModel, unsafeJoin, void 0);
561
- if (result) join = result.join;
560
+ const result = transformJoinClause(unsafeModel, unsafeJoin, select);
561
+ if (result) {
562
+ join = result.join;
563
+ select = result.select;
564
+ }
562
565
  if (!options.experimental?.joins && join && Object.keys(join).length > 0) passJoinToAdapter = false;
563
566
  } else join = unsafeJoin;
564
567
  debugLog({ method: "findMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`, `${formatMethod("findMany")}:`, {
@@ -573,6 +576,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
573
576
  model,
574
577
  where,
575
578
  limit,
579
+ select,
576
580
  sortBy,
577
581
  offset,
578
582
  join: passJoinToAdapter ? join : void 0
@@ -662,29 +666,6 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
662
666
  createSchema: adapterInstance.createSchema ? async (_, file) => {
663
667
  const tables = getAuthTables(options);
664
668
  if (options.secondaryStorage && !options.session?.storeSessionInDatabase) delete tables.session;
665
- if (options.rateLimit && options.rateLimit.storage === "database" && (typeof options.rateLimit.enabled === "undefined" || options.rateLimit.enabled === true)) tables.ratelimit = {
666
- modelName: options.rateLimit.modelName ?? "ratelimit",
667
- fields: {
668
- key: {
669
- type: "string",
670
- unique: true,
671
- required: true,
672
- fieldName: options.rateLimit.fields?.key ?? "key"
673
- },
674
- count: {
675
- type: "number",
676
- required: true,
677
- fieldName: options.rateLimit.fields?.count ?? "count"
678
- },
679
- lastRequest: {
680
- type: "number",
681
- required: true,
682
- bigint: true,
683
- defaultValue: () => Date.now(),
684
- fieldName: options.rateLimit.fields?.lastRequest ?? "lastRequest"
685
- }
686
- }
687
- };
688
669
  return adapterInstance.createSchema({
689
670
  file,
690
671
  tables
@@ -735,4 +716,5 @@ function formatAction(action) {
735
716
  const createAdapter = createAdapterFactory;
736
717
 
737
718
  //#endregion
738
- export { createAdapter, createAdapterFactory };
719
+ export { createAdapter, createAdapterFactory };
720
+ //# sourceMappingURL=factory.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.mjs","names":["debugLogs: { instance: string; args: any[] }[]","logger","transformedData: Record<string, any>","newFieldName: string","data","unsafe_model","select","transformedData","fieldName: string","transformedJoin: JoinConfig","from: string","to: string","requiredSelectField: string","limit: number","result: Record<string, any> | Record<string, any>[] | null","lazyLoadTransaction:\n\t\t\t| DBAdapter<BetterAuthOptions>[\"transaction\"]\n\t\t\t| null","adapter: DBAdapter<BetterAuthOptions>","join: JoinConfig | undefined","log","log: any[]","transactionId"],"sources":["../../../src/db/adapter/factory.ts"],"sourcesContent":["import { createLogger, getColorDepth, TTY_COLORS } from \"../../env\";\nimport { BetterAuthError } from \"../../error\";\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(adapter: DBAdapter<BetterAuthOptions>) =>\n\t<R>(fn: (trx: DBTransactionAdapter<BetterAuthOptions>) => Promise<R>) =>\n\t\tfn(adapter);\n\nexport type AdapterFactory = (\n\toptions: BetterAuthOptions,\n) => DBAdapter<BetterAuthOptions>;\n\nexport const createAdapterFactory =\n\t({\n\t\tadapter: customAdapter,\n\t\tconfig: cfg,\n\t}: AdapterFactoryOptions): AdapterFactory =>\n\t(options: BetterAuthOptions): DBAdapter<BetterAuthOptions> => {\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 =\n\t\t\toptions.advanced?.database?.useNumberId === true ||\n\t\t\toptions.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 =\n\t\t\t\toptions.advanced?.database?.useNumberId ||\n\t\t\t\toptions.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 =\n\t\t\t\t\toptions.advanced?.database?.useNumberId ||\n\t\t\t\t\toptions.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 =\n\t\t\t\t\toptions.advanced?.database?.useNumberId ||\n\t\t\t\t\toptions.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 (\n\t\t\t\t\tfieldAttr.type === \"boolean\" &&\n\t\t\t\t\ttypeof value === \"boolean\" &&\n\t\t\t\t\t!config.supportsBooleans\n\t\t\t\t) {\n\t\t\t\t\tnewValue = value ? 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 adapterInstance.findOne<Record<string, any>>({\n\t\t\t\t\t\tmodel: modelName,\n\t\t\t\t\t\twhere: where,\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 adapterInstance.findMany<Record<string, any>>({\n\t\t\t\t\t\tmodel: modelName,\n\t\t\t\t\t\twhere: where,\n\t\t\t\t\t\tlimit,\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:\n\t\t\t| DBAdapter<BetterAuthOptions>[\"transaction\"]\n\t\t\t| null = null;\n\t\tconst adapter: DBAdapter<BetterAuthOptions> = {\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 adapterInstance.create<T>({ data, model });\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 adapterInstance.update<T>({\n\t\t\t\t\tmodel,\n\t\t\t\t\twhere,\n\t\t\t\t\tupdate: data,\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 adapterInstance.updateMany({\n\t\t\t\t\tmodel,\n\t\t\t\t\twhere,\n\t\t\t\t\tupdate: data,\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 adapterInstance.findOne<T>({\n\t\t\t\t\tmodel,\n\t\t\t\t\twhere,\n\t\t\t\t\tselect,\n\t\t\t\t\tjoin: passJoinToAdapter ? join : undefined,\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 adapterInstance.findMany<T>({\n\t\t\t\t\tmodel,\n\t\t\t\t\twhere,\n\t\t\t\t\tlimit: limit,\n\t\t\t\t\tselect,\n\t\t\t\t\tsortBy,\n\t\t\t\t\toffset,\n\t\t\t\t\tjoin: passJoinToAdapter ? join : undefined,\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 adapterInstance.delete({\n\t\t\t\t\tmodel,\n\t\t\t\t\twhere,\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 adapterInstance.deleteMany({\n\t\t\t\t\tmodel,\n\t\t\t\t\twhere,\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 adapterInstance.count({\n\t\t\t\t\tmodel,\n\t\t\t\t\twhere,\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\n/**\n * @deprecated Use `createAdapterFactory` instead. This export will be removed in a future version.\n * @alias\n */\nexport const createAdapter = createAdapterFactory;\n"],"mappings":";;;;;;;;;;;;;;;AAoCA,IAAIA,YAAiD,EAAE;AACvD,IAAI,gBAAgB;AAEpB,MAAM,yBACJ,aACG,OACH,GAAG,QAAQ;AAMb,MAAa,wBACX,EACA,SAAS,eACT,QAAQ,WAER,YAA6D;CAC7D,MAAM,iCAAiC,KAAK,QAAQ,CAClD,SAAS,GAAG,CACZ,UAAU,GAAG,GAAG;CA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EACD,IAAI,OAAO;EAKX,GAAI,OAAO,WAAW,wBACnB,EACA,sBAAsB;GACrB,iBAAiB;AAChB,gBAAY,UAAU,QACpB,QAAQ,IAAI,aAAa,+BAC1B;;GAEF,iBAAiB;IAChB,MAAM,YAAY,IAAI,OAAO,GAAG;IAChC,MAAM,OAAO,UAAU,QACrB,UAAQC,MAAI,aAAa,+BAC1B;AACD,QAAI,KAAK,WAAW,EACnB;IAID,MAAMC,MAAa,KACjB,SAAS,CACT,KAAK,UAAQ;AACb,WAAI,KAAK,KAAK,KAAKD,MAAI,KAAK;AAC5B,YAAO,CAAC,GAAGA,MAAI,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,iBAAuB;AACnD,KAAI,eAAe,GAAG,EACrB,QAAO,IAAIE;AAEZ,QAAO,GAAG,WAAW,GAAG,QAAQ,GAAGA,kBAAgB,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;;;;;;AAOlD,MAAa,gBAAgB"}
@@ -15,4 +15,5 @@ declare const initGetDefaultFieldName: ({
15
15
  field: string;
16
16
  }) => string;
17
17
  //#endregion
18
- export { initGetDefaultFieldName };
18
+ export { initGetDefaultFieldName };
19
+ //# sourceMappingURL=get-default-field-name.d.mts.map
@@ -35,4 +35,5 @@ const initGetDefaultFieldName = ({ schema, usePlural }) => {
35
35
  };
36
36
 
37
37
  //#endregion
38
- export { initGetDefaultFieldName };
38
+ export { initGetDefaultFieldName };
39
+ //# sourceMappingURL=get-default-field-name.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-default-field-name.mjs","names":["f"],"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,GAAGA,SAAOA,IAAE,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"}
@@ -9,4 +9,5 @@ declare const initGetDefaultModelName: ({
9
9
  schema: BetterAuthDBSchema;
10
10
  }) => (model: string) => string;
11
11
  //#endregion
12
- export { initGetDefaultModelName };
12
+ export { initGetDefaultModelName };
13
+ //# sourceMappingURL=get-default-model-name.d.mts.map
@@ -29,4 +29,5 @@ const initGetDefaultModelName = ({ usePlural, schema }) => {
29
29
  };
30
30
 
31
31
  //#endregion
32
- export { initGetDefaultModelName };
32
+ export { initGetDefaultModelName };
33
+ //# sourceMappingURL=get-default-model-name.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-default-model-name.mjs","names":["m"],"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,IAAIA,MAAI,OAAO,kBAAkB,iBAAiB;AAClD,OAAI,CAACA,IACJ,OAAI,OAAO,QAAQ,OAAO,CAAC,MACzB,CAAC,GAAG,OAAO,EAAE,cAAc,eAC5B,GAAG;AAGL,OAAIA,IACH,QAAOA;;EAIT,IAAI,IAAI,OAAO,SAAS,QAAQ;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"}
@@ -26,4 +26,5 @@ declare const initGetFieldAttributes: ({
26
26
  field: string;
27
27
  }) => DBFieldAttribute<DBFieldType>;
28
28
  //#endregion
29
- export { initGetFieldAttributes };
29
+ export { initGetFieldAttributes };
30
+ //# sourceMappingURL=get-field-attributes.d.mts.map
@@ -36,4 +36,5 @@ const initGetFieldAttributes = ({ usePlural, schema, options, customIdGenerator,
36
36
  };
37
37
 
38
38
  //#endregion
39
- export { initGetFieldAttributes };
39
+ export { initGetFieldAttributes };
40
+ //# sourceMappingURL=get-field-attributes.mjs.map
@@ -0,0 +1 @@
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"}
@@ -15,4 +15,5 @@ declare const initGetFieldName: ({
15
15
  field: string;
16
16
  }) => string;
17
17
  //#endregion
18
- export { initGetFieldName };
18
+ export { initGetFieldName };
19
+ //# sourceMappingURL=get-field-name.d.mts.map
@@ -30,4 +30,5 @@ const initGetFieldName = ({ schema, usePlural }) => {
30
30
  };
31
31
 
32
32
  //#endregion
33
- export { initGetFieldName };
33
+ export { initGetFieldName };
34
+ //# sourceMappingURL=get-field-name.mjs.map
@@ -0,0 +1 @@
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"}
@@ -36,4 +36,5 @@ declare const initGetIdField: ({
36
36
  required: boolean;
37
37
  };
38
38
  //#endregion
39
- export { initGetIdField };
39
+ export { initGetIdField };
40
+ //# sourceMappingURL=get-id-field.d.mts.map
@@ -65,4 +65,5 @@ const initGetIdField = ({ usePlural, schema, disableIdGeneration, options, custo
65
65
  };
66
66
 
67
67
  //#endregion
68
- export { initGetIdField };
68
+ export { initGetIdField };
69
+ //# sourceMappingURL=get-id-field.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-id-field.mjs","names":["shouldGenerateId: boolean","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\";\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 =\n\t\t\toptions.advanced?.database?.useNumberId ||\n\t\t\toptions.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\t\t\t\t\t\t\tif (generateId === false || useNumberId) return undefined;\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\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\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\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,cACL,QAAQ,UAAU,UAAU,eAC5B,QAAQ,UAAU,UAAU,eAAe;EAC5C,MAAM,WAAW,QAAQ,UAAU,UAAU,eAAe;EAE5D,MAAMA,0BAAmC;AACxC,OAAI,oBACH,QAAO;YACG,eAAe,CAAC,aAE1B,QAAO;YACG,SAEV,QAAO,CAAC;OAER,QAAO;MAEL;EAEJ,MAAM,QAAQ,oBAAoB,mBAAmB,KAAK;AAC1D,SAAO;GACN,MAAM,cAAc,WAAW;GAC/B,UAAU,mBAAmB,OAAO;GACpC,GAAI,mBACD,EACA,eAAe;AACd,QAAI,oBAAqB,QAAO;IAChC,MAAMC,eAAa,QAAQ,UAAU,UAAU;AAC/C,QAAIA,iBAAe,SAAS,YAAa,QAAO;AAChD,QAAI,OAAOA,iBAAe,WACzB,QAAOA,aAAW,EACjB,OACA,CAAC;AAEH,QAAI,kBACH,QAAO,kBAAkB,EAAE,OAAO,CAAC;AAEpC,QAAIA,iBAAe,OAClB,QAAO,OAAO,YAAY;AAE3B,WAAOC,YAAmB;MAE3B,GACA,EAAE;GACL,WAAW;IACV,QAAQ,UAAU;AAQjB,SAAI,CAAC,MAAO,QAAO;AAEnB,SAAI,aAAa;MAChB,MAAM,cAAc,OAAO,MAAM;AAEjC,UAAI,MAAM,YAAY,CACrB;AAED,aAAO;;AAGR,SAAI,UAAU;AAEb,UAAI,oBAAoB,CAAC,aAAc,QAAO;AAC9C,UAAI,oBAAqB,QAAO;AAEhC,UAAI,cAAe,QAAO;AAE1B,UAAI,gBAAgB,OAAO,UAAU,SAGpC,KADC,6EACa,KAAK,MAAM,CACxB,QAAO;WACD;OAEN,MAAM,yBADM,IAAI,OAAO,EACL,OACf,MAAM,KAAK,CACZ,QAAQ,GAAG,MAAM,MAAM,EAAE,CACzB,KAAK,KAAK,CACV,QAAQ,UAAU,GAAG;AACvB,cAAO,KACN,sHACA,MACA;;AAIH,UAAI,OAAO,UAAU,YAAY,CAAC,cACjC,QAAO,OAAO,YAAY;AAE3B;;AAGD,YAAO;;IAER,SAAS,UAAU;AAClB,SAAI,CAAC,MAAO,QAAO;AACnB,YAAO,OAAO,MAAM;;IAErB;GACD;;AAGF,QAAO"}
@@ -9,4 +9,5 @@ declare const initGetModelName: ({
9
9
  schema: BetterAuthDBSchema;
10
10
  }) => (model: string) => string;
11
11
  //#endregion
12
- export { initGetModelName };
12
+ export { initGetModelName };
13
+ //# sourceMappingURL=get-model-name.d.mts.map
@@ -20,4 +20,5 @@ const initGetModelName = ({ usePlural, schema }) => {
20
20
  };
21
21
 
22
22
  //#endregion
23
- export { initGetModelName };
23
+ export { initGetModelName };
24
+ //# sourceMappingURL=get-model-name.mjs.map
@@ -0,0 +1 @@
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"}
@@ -373,6 +373,7 @@ type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
373
373
  model: string;
374
374
  where?: Where[] | undefined;
375
375
  limit?: number | undefined;
376
+ select?: string[] | undefined;
376
377
  sortBy?: {
377
378
  field: string;
378
379
  direction: "asc" | "desc";
@@ -457,6 +458,7 @@ interface CustomAdapter {
457
458
  model,
458
459
  where,
459
460
  limit,
461
+ select,
460
462
  sortBy,
461
463
  offset,
462
464
  join
@@ -464,6 +466,7 @@ interface CustomAdapter {
464
466
  model: string;
465
467
  where?: CleanedWhere[] | undefined;
466
468
  limit: number;
469
+ select?: string[] | undefined;
467
470
  sortBy?: {
468
471
  field: string;
469
472
  direction: "asc" | "desc";
@@ -511,4 +514,5 @@ interface DBAdapterInstance<Options extends BetterAuthOptions = BetterAuthOption
511
514
  (options: BetterAuthOptions): DBAdapter<Options>;
512
515
  }
513
516
  //#endregion
514
- export { AdapterConfig, AdapterFactory, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, JoinOption, Where, createAdapter, createAdapterFactory, deepmerge, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName, withApplyDefault };
517
+ export { AdapterConfig, AdapterFactory, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, JoinOption, Where, createAdapter, createAdapterFactory, deepmerge, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName, withApplyDefault };
518
+ //# sourceMappingURL=index.d.mts.map