@better-auth/core 1.4.12-beta.2 → 1.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/.turbo/turbo-build.log +172 -35
  2. package/dist/api/index.d.mts +178 -1
  3. package/dist/api/index.mjs +2 -1
  4. package/dist/context/endpoint-context.d.mts +19 -0
  5. package/dist/context/endpoint-context.mjs +31 -0
  6. package/dist/context/global.d.mts +7 -0
  7. package/dist/context/global.mjs +37 -0
  8. package/dist/context/index.d.mts +5 -53
  9. package/dist/context/index.mjs +5 -2
  10. package/dist/context/request-state.d.mts +27 -0
  11. package/dist/context/request-state.mjs +49 -0
  12. package/dist/context/transaction.d.mts +16 -0
  13. package/dist/context/transaction.mjs +52 -0
  14. package/dist/db/adapter/factory.d.mts +27 -0
  15. package/dist/db/adapter/factory.mjs +738 -0
  16. package/dist/db/adapter/get-default-field-name.d.mts +18 -0
  17. package/dist/db/adapter/get-default-field-name.mjs +38 -0
  18. package/dist/db/adapter/get-default-model-name.d.mts +12 -0
  19. package/dist/db/adapter/get-default-model-name.mjs +32 -0
  20. package/dist/db/adapter/get-field-attributes.d.mts +29 -0
  21. package/dist/db/adapter/get-field-attributes.mjs +39 -0
  22. package/dist/db/adapter/get-field-name.d.mts +18 -0
  23. package/dist/db/adapter/get-field-name.mjs +33 -0
  24. package/dist/db/adapter/get-id-field.d.mts +39 -0
  25. package/dist/db/adapter/get-id-field.mjs +68 -0
  26. package/dist/db/adapter/get-model-name.d.mts +12 -0
  27. package/dist/db/adapter/get-model-name.mjs +23 -0
  28. package/dist/db/adapter/index.d.mts +513 -1
  29. package/dist/db/adapter/index.mjs +8 -970
  30. package/dist/db/adapter/types.d.mts +139 -0
  31. package/dist/db/adapter/utils.d.mts +7 -0
  32. package/dist/db/adapter/utils.mjs +38 -0
  33. package/dist/db/get-tables.d.mts +8 -0
  34. package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +1 -1
  35. package/dist/db/index.d.mts +10 -2
  36. package/dist/db/index.mjs +7 -60
  37. package/dist/db/plugin.d.mts +12 -0
  38. package/dist/db/schema/account.d.mts +26 -0
  39. package/dist/db/schema/account.mjs +19 -0
  40. package/dist/db/schema/rate-limit.d.mts +14 -0
  41. package/dist/db/schema/rate-limit.mjs +11 -0
  42. package/dist/db/schema/session.d.mts +21 -0
  43. package/dist/db/schema/session.mjs +14 -0
  44. package/dist/db/schema/shared.d.mts +10 -0
  45. package/dist/db/schema/shared.mjs +11 -0
  46. package/dist/db/schema/user.d.mts +20 -0
  47. package/dist/db/schema/user.mjs +13 -0
  48. package/dist/db/schema/verification.d.mts +19 -0
  49. package/dist/db/schema/verification.mjs +12 -0
  50. package/dist/db/type.d.mts +143 -0
  51. package/dist/env/color-depth.d.mts +4 -0
  52. package/dist/env/color-depth.mjs +88 -0
  53. package/dist/env/env-impl.d.mts +32 -0
  54. package/dist/env/env-impl.mjs +82 -0
  55. package/dist/env/index.d.mts +4 -2
  56. package/dist/env/index.mjs +3 -1
  57. package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
  58. package/dist/env/logger.mjs +81 -0
  59. package/dist/error/codes.d.mts +48 -0
  60. package/dist/{error-DP1xOn7P.mjs → error/codes.mjs} +3 -14
  61. package/dist/error/index.d.mts +5 -48
  62. package/dist/error/index.mjs +12 -3
  63. package/dist/index.d.mts +8 -2
  64. package/dist/oauth2/client-credentials-token.d.mts +36 -0
  65. package/dist/oauth2/client-credentials-token.mjs +54 -0
  66. package/dist/oauth2/create-authorization-url.d.mts +45 -0
  67. package/dist/oauth2/create-authorization-url.mjs +42 -0
  68. package/dist/oauth2/index.d.mts +8 -2
  69. package/dist/oauth2/index.mjs +6 -2
  70. package/dist/oauth2/oauth-provider.d.mts +194 -0
  71. package/dist/oauth2/refresh-access-token.d.mts +36 -0
  72. package/dist/oauth2/refresh-access-token.mjs +58 -0
  73. package/dist/oauth2/utils.d.mts +7 -0
  74. package/dist/oauth2/utils.mjs +27 -0
  75. package/dist/oauth2/validate-authorization-code.d.mts +55 -0
  76. package/dist/oauth2/validate-authorization-code.mjs +71 -0
  77. package/dist/oauth2/verify.d.mts +49 -0
  78. package/dist/oauth2/verify.mjs +95 -0
  79. package/dist/social-providers/apple.d.mts +119 -0
  80. package/dist/social-providers/apple.mjs +102 -0
  81. package/dist/social-providers/atlassian.d.mts +72 -0
  82. package/dist/social-providers/atlassian.mjs +83 -0
  83. package/dist/social-providers/cognito.d.mts +87 -0
  84. package/dist/social-providers/cognito.mjs +166 -0
  85. package/dist/social-providers/discord.d.mts +126 -0
  86. package/dist/social-providers/discord.mjs +64 -0
  87. package/dist/social-providers/dropbox.d.mts +71 -0
  88. package/dist/social-providers/dropbox.mjs +75 -0
  89. package/dist/social-providers/facebook.d.mts +81 -0
  90. package/dist/social-providers/facebook.mjs +120 -0
  91. package/dist/social-providers/figma.d.mts +63 -0
  92. package/dist/social-providers/figma.mjs +84 -0
  93. package/dist/social-providers/github.d.mts +104 -0
  94. package/dist/social-providers/github.mjs +80 -0
  95. package/dist/social-providers/gitlab.d.mts +125 -0
  96. package/dist/social-providers/gitlab.mjs +82 -0
  97. package/dist/social-providers/google.d.mts +99 -0
  98. package/dist/social-providers/google.mjs +109 -0
  99. package/dist/social-providers/huggingface.d.mts +85 -0
  100. package/dist/social-providers/huggingface.mjs +75 -0
  101. package/dist/social-providers/index.d.mts +1723 -1
  102. package/dist/social-providers/index.mjs +33 -2570
  103. package/dist/social-providers/kakao.d.mts +163 -0
  104. package/dist/social-providers/kakao.mjs +72 -0
  105. package/dist/social-providers/kick.d.mts +75 -0
  106. package/dist/social-providers/kick.mjs +71 -0
  107. package/dist/social-providers/line.d.mts +107 -0
  108. package/dist/social-providers/line.mjs +113 -0
  109. package/dist/social-providers/linear.d.mts +70 -0
  110. package/dist/social-providers/linear.mjs +88 -0
  111. package/dist/social-providers/linkedin.d.mts +69 -0
  112. package/dist/social-providers/linkedin.mjs +76 -0
  113. package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
  114. package/dist/social-providers/microsoft-entra-id.mjs +106 -0
  115. package/dist/social-providers/naver.d.mts +104 -0
  116. package/dist/social-providers/naver.mjs +67 -0
  117. package/dist/social-providers/notion.d.mts +66 -0
  118. package/dist/social-providers/notion.mjs +75 -0
  119. package/dist/social-providers/paybin.d.mts +73 -0
  120. package/dist/social-providers/paybin.mjs +85 -0
  121. package/dist/social-providers/paypal.d.mts +131 -0
  122. package/dist/social-providers/paypal.mjs +144 -0
  123. package/dist/social-providers/polar.d.mts +76 -0
  124. package/dist/social-providers/polar.mjs +73 -0
  125. package/dist/social-providers/reddit.d.mts +64 -0
  126. package/dist/social-providers/reddit.mjs +83 -0
  127. package/dist/social-providers/roblox.d.mts +72 -0
  128. package/dist/social-providers/roblox.mjs +59 -0
  129. package/dist/social-providers/salesforce.d.mts +81 -0
  130. package/dist/social-providers/salesforce.mjs +91 -0
  131. package/dist/social-providers/slack.d.mts +85 -0
  132. package/dist/social-providers/slack.mjs +68 -0
  133. package/dist/social-providers/spotify.d.mts +65 -0
  134. package/dist/social-providers/spotify.mjs +71 -0
  135. package/dist/social-providers/tiktok.d.mts +171 -0
  136. package/dist/social-providers/tiktok.mjs +62 -0
  137. package/dist/social-providers/twitch.d.mts +81 -0
  138. package/dist/social-providers/twitch.mjs +78 -0
  139. package/dist/social-providers/twitter.d.mts +140 -0
  140. package/dist/social-providers/twitter.mjs +87 -0
  141. package/dist/social-providers/vercel.d.mts +64 -0
  142. package/dist/social-providers/vercel.mjs +61 -0
  143. package/dist/social-providers/vk.d.mts +72 -0
  144. package/dist/social-providers/vk.mjs +83 -0
  145. package/dist/social-providers/zoom.d.mts +173 -0
  146. package/dist/social-providers/zoom.mjs +72 -0
  147. package/dist/types/context.d.mts +215 -0
  148. package/dist/types/cookie.d.mts +15 -0
  149. package/dist/types/helper.d.mts +8 -0
  150. package/dist/types/index.d.mts +8 -0
  151. package/dist/types/init-options.d.mts +1266 -0
  152. package/dist/types/plugin-client.d.mts +103 -0
  153. package/dist/types/plugin.d.mts +121 -0
  154. package/dist/utils/deprecate.d.mts +10 -0
  155. package/dist/utils/deprecate.mjs +17 -0
  156. package/dist/utils/error-codes.d.mts +9 -0
  157. package/dist/utils/error-codes.mjs +7 -0
  158. package/dist/utils/id.d.mts +4 -0
  159. package/dist/utils/id.mjs +9 -0
  160. package/dist/utils/index.d.mts +5 -26
  161. package/dist/utils/index.mjs +5 -2
  162. package/dist/utils/json.d.mts +4 -0
  163. package/dist/utils/json.mjs +25 -0
  164. package/dist/utils/string.d.mts +4 -0
  165. package/dist/utils/string.mjs +7 -0
  166. package/package.json +1 -1
  167. package/src/context/endpoint-context.ts +7 -15
  168. package/src/context/global.ts +57 -0
  169. package/src/context/index.ts +1 -0
  170. package/src/context/request-state.ts +7 -12
  171. package/src/context/transaction.ts +7 -16
  172. package/src/db/adapter/factory.ts +13 -13
  173. package/src/db/adapter/get-default-model-name.ts +1 -1
  174. package/src/db/adapter/get-id-field.ts +2 -2
  175. package/src/error/index.ts +2 -3
  176. package/src/social-providers/gitlab.ts +1 -1
  177. package/src/types/context.ts +137 -131
  178. package/src/types/cookie.ts +6 -4
  179. package/src/types/index.ts +2 -1
  180. package/tsdown.config.ts +9 -0
  181. package/dist/context-BGZ8V6DD.mjs +0 -126
  182. package/dist/env-DbssmzoK.mjs +0 -245
  183. package/dist/index-zgYuzZ7O.d.mts +0 -8020
  184. package/dist/oauth2-COJkghlT.mjs +0 -326
  185. package/dist/utils-U2L7n92V.mjs +0 -59
@@ -0,0 +1,18 @@
1
+ import { BetterAuthDBSchema } from "../type.mjs";
2
+
3
+ //#region src/db/adapter/get-default-field-name.d.ts
4
+ declare const initGetDefaultFieldName: ({
5
+ schema,
6
+ usePlural
7
+ }: {
8
+ schema: BetterAuthDBSchema;
9
+ usePlural: boolean | undefined;
10
+ }) => ({
11
+ field,
12
+ model: unsafeModel
13
+ }: {
14
+ model: string;
15
+ field: string;
16
+ }) => string;
17
+ //#endregion
18
+ export { initGetDefaultFieldName };
@@ -0,0 +1,38 @@
1
+ import { BetterAuthError } from "../../error/index.mjs";
2
+ import { initGetDefaultModelName } from "./get-default-model-name.mjs";
3
+
4
+ //#region src/db/adapter/get-default-field-name.ts
5
+ const initGetDefaultFieldName = ({ schema, usePlural }) => {
6
+ const getDefaultModelName = initGetDefaultModelName({
7
+ schema,
8
+ usePlural
9
+ });
10
+ /**
11
+ * This function helps us get the default field name from the schema defined by devs.
12
+ * Often times, the user will be using the `fieldName` which could had been customized by the users.
13
+ * This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
14
+ *
15
+ * If it's still unclear what this does:
16
+ *
17
+ * 1. User can define a custom fieldName.
18
+ * 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
19
+ */
20
+ const getDefaultFieldName = ({ field, model: unsafeModel }) => {
21
+ if (field === "id" || field === "_id") return "id";
22
+ const model = getDefaultModelName(unsafeModel);
23
+ let f = schema[model]?.fields[field];
24
+ if (!f) {
25
+ const result = Object.entries(schema[model].fields).find(([_, f$1]) => f$1.fieldName === field);
26
+ if (result) {
27
+ f = result[1];
28
+ field = result[0];
29
+ }
30
+ }
31
+ if (!f) throw new BetterAuthError(`Field ${field} not found in model ${model}`);
32
+ return field;
33
+ };
34
+ return getDefaultFieldName;
35
+ };
36
+
37
+ //#endregion
38
+ export { initGetDefaultFieldName };
@@ -0,0 +1,12 @@
1
+ import { BetterAuthDBSchema } from "../type.mjs";
2
+
3
+ //#region src/db/adapter/get-default-model-name.d.ts
4
+ declare const initGetDefaultModelName: ({
5
+ usePlural,
6
+ schema
7
+ }: {
8
+ usePlural: boolean | undefined;
9
+ schema: BetterAuthDBSchema;
10
+ }) => (model: string) => string;
11
+ //#endregion
12
+ export { initGetDefaultModelName };
@@ -0,0 +1,32 @@
1
+ import { BetterAuthError } from "../../error/index.mjs";
2
+
3
+ //#region src/db/adapter/get-default-model-name.ts
4
+ const initGetDefaultModelName = ({ usePlural, schema }) => {
5
+ /**
6
+ * This function helps us get the default model name from the schema defined by devs.
7
+ * Often times, the user will be using the `modelName` which could had been customized by the users.
8
+ * This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
9
+ *
10
+ * If it's still unclear what this does:
11
+ *
12
+ * 1. User can define a custom modelName.
13
+ * 2. When using a custom modelName, doing something like `schema[model]` will not work.
14
+ * 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
15
+ */
16
+ const getDefaultModelName = (model) => {
17
+ if (usePlural && model.charAt(model.length - 1) === "s") {
18
+ const pluralessModel = model.slice(0, -1);
19
+ let m$1 = schema[pluralessModel] ? pluralessModel : void 0;
20
+ if (!m$1) m$1 = Object.entries(schema).find(([_, f]) => f.modelName === pluralessModel)?.[0];
21
+ if (m$1) return m$1;
22
+ }
23
+ let m = schema[model] ? model : void 0;
24
+ if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === model)?.[0];
25
+ if (!m) throw new BetterAuthError(`Model "${model}" not found in schema`);
26
+ return m;
27
+ };
28
+ return getDefaultModelName;
29
+ };
30
+
31
+ //#endregion
32
+ export { initGetDefaultModelName };
@@ -0,0 +1,29 @@
1
+ import { BetterAuthDBSchema, DBFieldAttribute, DBFieldType } from "../type.mjs";
2
+ import "../index.mjs";
3
+ import { BetterAuthOptions } from "../../types/init-options.mjs";
4
+ import "../../types/index.mjs";
5
+
6
+ //#region src/db/adapter/get-field-attributes.d.ts
7
+ declare const initGetFieldAttributes: ({
8
+ usePlural,
9
+ schema,
10
+ options,
11
+ customIdGenerator,
12
+ disableIdGeneration
13
+ }: {
14
+ usePlural?: boolean;
15
+ schema: BetterAuthDBSchema;
16
+ options: BetterAuthOptions;
17
+ disableIdGeneration?: boolean;
18
+ customIdGenerator?: ((props: {
19
+ model: string;
20
+ }) => string) | undefined;
21
+ }) => ({
22
+ model,
23
+ field
24
+ }: {
25
+ model: string;
26
+ field: string;
27
+ }) => DBFieldAttribute<DBFieldType>;
28
+ //#endregion
29
+ export { initGetFieldAttributes };
@@ -0,0 +1,39 @@
1
+ import { BetterAuthError } from "../../error/index.mjs";
2
+ import { initGetDefaultModelName } from "./get-default-model-name.mjs";
3
+ import { initGetDefaultFieldName } from "./get-default-field-name.mjs";
4
+ import { initGetIdField } from "./get-id-field.mjs";
5
+
6
+ //#region src/db/adapter/get-field-attributes.ts
7
+ const initGetFieldAttributes = ({ usePlural, schema, options, customIdGenerator, disableIdGeneration }) => {
8
+ const getDefaultModelName = initGetDefaultModelName({
9
+ usePlural,
10
+ schema
11
+ });
12
+ const getDefaultFieldName = initGetDefaultFieldName({
13
+ usePlural,
14
+ schema
15
+ });
16
+ const idField = initGetIdField({
17
+ usePlural,
18
+ schema,
19
+ options,
20
+ customIdGenerator,
21
+ disableIdGeneration
22
+ });
23
+ const getFieldAttributes = ({ model, field }) => {
24
+ const defaultModelName = getDefaultModelName(model);
25
+ const defaultFieldName = getDefaultFieldName({
26
+ field,
27
+ model: defaultModelName
28
+ });
29
+ const fields = schema[defaultModelName].fields;
30
+ fields.id = idField({ customModelName: defaultModelName });
31
+ const fieldAttributes = fields[defaultFieldName];
32
+ if (!fieldAttributes) throw new BetterAuthError(`Field ${field} not found in model ${model}`);
33
+ return fieldAttributes;
34
+ };
35
+ return getFieldAttributes;
36
+ };
37
+
38
+ //#endregion
39
+ export { initGetFieldAttributes };
@@ -0,0 +1,18 @@
1
+ import { BetterAuthDBSchema } from "../type.mjs";
2
+
3
+ //#region src/db/adapter/get-field-name.d.ts
4
+ declare const initGetFieldName: ({
5
+ schema,
6
+ usePlural
7
+ }: {
8
+ schema: BetterAuthDBSchema;
9
+ usePlural: boolean | undefined;
10
+ }) => ({
11
+ model: modelName,
12
+ field: fieldName
13
+ }: {
14
+ model: string;
15
+ field: string;
16
+ }) => string;
17
+ //#endregion
18
+ export { initGetFieldName };
@@ -0,0 +1,33 @@
1
+ import { initGetDefaultModelName } from "./get-default-model-name.mjs";
2
+ import { initGetDefaultFieldName } from "./get-default-field-name.mjs";
3
+
4
+ //#region src/db/adapter/get-field-name.ts
5
+ const initGetFieldName = ({ schema, usePlural }) => {
6
+ const getDefaultModelName = initGetDefaultModelName({
7
+ schema,
8
+ usePlural
9
+ });
10
+ const getDefaultFieldName = initGetDefaultFieldName({
11
+ schema,
12
+ usePlural
13
+ });
14
+ /**
15
+ * Get the field name which is expected to be saved in the database based on the user's schema.
16
+ *
17
+ * This function is useful if you need to save the field name to the database.
18
+ *
19
+ * 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.
20
+ */
21
+ function getFieldName({ model: modelName, field: fieldName }) {
22
+ const model = getDefaultModelName(modelName);
23
+ const field = getDefaultFieldName({
24
+ model,
25
+ field: fieldName
26
+ });
27
+ return schema[model]?.fields[field]?.fieldName || field;
28
+ }
29
+ return getFieldName;
30
+ };
31
+
32
+ //#endregion
33
+ export { initGetFieldName };
@@ -0,0 +1,39 @@
1
+ import { BetterAuthDBSchema, DBPrimitive } from "../type.mjs";
2
+ import "../index.mjs";
3
+ import { BetterAuthOptions } from "../../types/init-options.mjs";
4
+ import "../../types/index.mjs";
5
+
6
+ //#region src/db/adapter/get-id-field.d.ts
7
+ declare const initGetIdField: ({
8
+ usePlural,
9
+ schema,
10
+ disableIdGeneration,
11
+ options,
12
+ customIdGenerator,
13
+ supportsUUIDs
14
+ }: {
15
+ usePlural?: boolean;
16
+ schema: BetterAuthDBSchema;
17
+ options: BetterAuthOptions;
18
+ disableIdGeneration?: boolean;
19
+ customIdGenerator?: ((props: {
20
+ model: string;
21
+ }) => string) | undefined;
22
+ supportsUUIDs?: boolean;
23
+ }) => ({
24
+ customModelName,
25
+ forceAllowId
26
+ }: {
27
+ customModelName?: string;
28
+ forceAllowId?: boolean;
29
+ }) => {
30
+ transform: {
31
+ input: (value: DBPrimitive) => string | number | true | unknown[] | Date | Record<string, unknown> | undefined;
32
+ output: (value: DBPrimitive) => string | undefined;
33
+ };
34
+ defaultValue?: (() => string | false | undefined) | undefined;
35
+ type: "string" | "number";
36
+ required: boolean;
37
+ };
38
+ //#endregion
39
+ export { initGetIdField };
@@ -0,0 +1,68 @@
1
+ import { logger } from "../../env/logger.mjs";
2
+ import "../../env/index.mjs";
3
+ import { generateId } from "../../utils/id.mjs";
4
+ import "../../utils/index.mjs";
5
+ import { initGetDefaultModelName } from "./get-default-model-name.mjs";
6
+
7
+ //#region src/db/adapter/get-id-field.ts
8
+ const initGetIdField = ({ usePlural, schema, disableIdGeneration, options, customIdGenerator, supportsUUIDs }) => {
9
+ const getDefaultModelName = initGetDefaultModelName({
10
+ usePlural,
11
+ schema
12
+ });
13
+ const idField = ({ customModelName, forceAllowId }) => {
14
+ const useNumberId = options.advanced?.database?.useNumberId || options.advanced?.database?.generateId === "serial";
15
+ const useUUIDs = options.advanced?.database?.generateId === "uuid";
16
+ const shouldGenerateId = (() => {
17
+ if (disableIdGeneration) return false;
18
+ else if (useNumberId && !forceAllowId) return false;
19
+ else if (useUUIDs) return !supportsUUIDs;
20
+ else return true;
21
+ })();
22
+ const model = getDefaultModelName(customModelName ?? "id");
23
+ return {
24
+ type: useNumberId ? "number" : "string",
25
+ required: shouldGenerateId ? true : false,
26
+ ...shouldGenerateId ? { defaultValue() {
27
+ if (disableIdGeneration) return void 0;
28
+ const generateId$1 = options.advanced?.database?.generateId;
29
+ if (generateId$1 === false || useNumberId) return void 0;
30
+ if (typeof generateId$1 === "function") return generateId$1({ model });
31
+ if (customIdGenerator) return customIdGenerator({ model });
32
+ if (generateId$1 === "uuid") return crypto.randomUUID();
33
+ return generateId();
34
+ } } : {},
35
+ transform: {
36
+ input: (value) => {
37
+ if (!value) return void 0;
38
+ if (useNumberId) {
39
+ const numberValue = Number(value);
40
+ if (isNaN(numberValue)) return;
41
+ return numberValue;
42
+ }
43
+ if (useUUIDs) {
44
+ if (shouldGenerateId && !forceAllowId) return value;
45
+ if (disableIdGeneration) return void 0;
46
+ if (supportsUUIDs) return void 0;
47
+ if (forceAllowId && typeof value === "string") if (/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)) return value;
48
+ else {
49
+ const stack = (/* @__PURE__ */ new Error()).stack?.split("\n").filter((_, i) => i !== 1).join("\n").replace("Error:", "");
50
+ logger.warn("[Adapter Factory] - Invalid UUID value for field `id` provided when `forceAllowId` is true. Generating a new UUID.", stack);
51
+ }
52
+ if (typeof value !== "string" && !supportsUUIDs) return crypto.randomUUID();
53
+ return;
54
+ }
55
+ return value;
56
+ },
57
+ output: (value) => {
58
+ if (!value) return void 0;
59
+ return String(value);
60
+ }
61
+ }
62
+ };
63
+ };
64
+ return idField;
65
+ };
66
+
67
+ //#endregion
68
+ export { initGetIdField };
@@ -0,0 +1,12 @@
1
+ import { BetterAuthDBSchema } from "../type.mjs";
2
+
3
+ //#region src/db/adapter/get-model-name.d.ts
4
+ declare const initGetModelName: ({
5
+ usePlural,
6
+ schema
7
+ }: {
8
+ usePlural: boolean | undefined;
9
+ schema: BetterAuthDBSchema;
10
+ }) => (model: string) => string;
11
+ //#endregion
12
+ export { initGetModelName };
@@ -0,0 +1,23 @@
1
+ import { initGetDefaultModelName } from "./get-default-model-name.mjs";
2
+
3
+ //#region src/db/adapter/get-model-name.ts
4
+ const initGetModelName = ({ usePlural, schema }) => {
5
+ const getDefaultModelName = initGetDefaultModelName({
6
+ schema,
7
+ usePlural
8
+ });
9
+ /**
10
+ * Users can overwrite the default model of some tables. This function helps find the correct model name.
11
+ * Furthermore, if the user passes `usePlural` as true in their adapter config,
12
+ * then we should return the model name ending with an `s`.
13
+ */
14
+ const getModelName = (model) => {
15
+ const defaultModelKey = getDefaultModelName(model);
16
+ if (schema && schema[defaultModelKey] && schema[defaultModelKey].modelName !== model) return usePlural ? `${schema[defaultModelKey].modelName}s` : schema[defaultModelKey].modelName;
17
+ return usePlural ? `${model}s` : model;
18
+ };
19
+ return getModelName;
20
+ };
21
+
22
+ //#endregion
23
+ export { initGetModelName };