appos 0.3.5-0 → 0.3.6-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/main.mjs +2 -2
- package/dist/exports/api/adapter-C2mMJKvG.mjs +1504 -0
- package/dist/exports/api/{auth-schema.mjs → auth-schema-CON4yFFY.mjs} +2 -3
- package/dist/exports/api/bun-sqlite-dialect-CPpPZa23.mjs +155 -0
- package/dist/exports/{cli/_virtual/rolldown_runtime.mjs → api/chunk-CyXqrcp_.mjs} +14 -1
- package/dist/exports/api/conditions-DjBAWfiK.mjs +116 -0
- package/dist/exports/api/dialect-CUUD24Ge.mjs +72 -0
- package/dist/exports/api/env-CwT3zhez.mjs +1 -0
- package/dist/exports/api/esm-_hkVMulx.mjs +15816 -0
- package/dist/exports/api/event-BHFSE6hY.mjs +20983 -0
- package/dist/exports/api/extract-blob-metadata-BMgUEPcW.mjs +4 -0
- package/dist/exports/api/extract-blob-metadata-_9RUEwoU.mjs +9818 -0
- package/dist/exports/api/generate-image-variant-DOIzj1wJ.mjs +4 -0
- package/dist/exports/api/generate-image-variant-DxOPoGAk.mjs +118 -0
- package/dist/exports/api/generate-preview-CvTFuq58.mjs +160 -0
- package/dist/exports/api/generate-preview-Dk3coswZ.mjs +4 -0
- package/dist/exports/api/index.d.mts +7347 -20
- package/dist/exports/api/index.mjs +146856 -18
- package/dist/exports/api/kysely-adapter-CmP2TbkS.mjs +296 -0
- package/dist/exports/api/memory-adapter-BzhRhLFK.mjs +212 -0
- package/dist/exports/api/node-sqlite-dialect-Bl5suBxl.mjs +155 -0
- package/dist/exports/api/orm-CMqufD21.mjs +153690 -0
- package/dist/exports/api/orm-DXqYuKvB.d.mts +11 -0
- package/dist/exports/api/orm.d.mts +2 -11
- package/dist/exports/api/orm.mjs +4 -42
- package/dist/exports/api/pdf-YxB2Hm1p.mjs +25822 -0
- package/dist/exports/api/purge-attachment-Cf6KH2Jv.mjs +34 -0
- package/dist/exports/api/purge-attachment-DIuil7ps.mjs +4 -0
- package/dist/exports/{cli/api/workflows/purge-audit-logs.mjs → api/purge-audit-logs-z6j_Pu47.mjs} +3 -3
- package/dist/exports/{cli/api/workflows/purge-unattached-blobs.mjs → api/purge-unattached-blobs-B0TfY5Hk.mjs} +1 -1
- package/dist/exports/api/react-BYhV5bYt.mjs +1131 -0
- package/dist/exports/api/server.node-DyVrQ6cz.mjs +19298 -0
- package/dist/exports/api/table-6bTIEqON.mjs +2636 -0
- package/dist/exports/api/{workflows/track-db-changes.mjs → track-db-changes-BysaV6nN.mjs} +14 -14
- package/dist/exports/api/{workflow.mjs → workflow-BuSWHcX-.mjs} +121 -10
- package/dist/exports/api/workflows/auth-schema-BFve3hgZ.mjs +2813 -0
- package/dist/exports/api/{_virtual/rolldown_runtime.mjs → workflows/chunk-B36mNPO4.mjs} +5 -1
- package/dist/exports/api/workflows/extract-blob-metadata-BcWKvY2K.mjs +9818 -0
- package/dist/exports/api/workflows/{generate-image-variant.mjs → generate-image-variant-BAFvL_zV.mjs} +20 -20
- package/dist/exports/{cli/api/workflows/generate-preview.mjs → api/workflows/generate-preview-BjlIVYYp.mjs} +6 -6
- package/dist/exports/api/workflows/index.d.mts +2011 -1
- package/dist/exports/api/workflows/index.mjs +2 -1
- package/dist/exports/api/workflows/pdf-DUB8zyIc.mjs +25822 -0
- package/dist/exports/{cli/api/workflows/purge-attachment.mjs → api/workflows/purge-attachment-k_sdxTPY.mjs} +3 -3
- package/dist/exports/api/workflows/{purge-audit-logs.mjs → purge-audit-logs-zCyWj4Mw.mjs} +12 -3
- package/dist/exports/api/workflows/{purge-unattached-blobs.mjs → purge-unattached-blobs-CdsuFAeW.mjs} +1 -1
- package/dist/exports/api/workflows/track-db-changes-CiKaI9gT.mjs +20943 -0
- package/dist/exports/api/workflows/track-db-changes-DEWQYryO.mjs +4 -0
- package/dist/exports/{cli/api/workflow.mjs → api/workflows/workflow-BjM2xCa6.mjs} +23 -3
- package/dist/exports/api/workflows/zod-Br0enFWK.mjs +12333 -0
- package/dist/exports/api/zod-CdrJdBtV.mjs +12571 -0
- package/dist/exports/cli/auth-schema-CNuOqPi-.mjs +2813 -0
- package/dist/exports/{api/workflows/_virtual/rolldown_runtime.mjs → cli/chunk-B36mNPO4.mjs} +5 -1
- package/dist/exports/cli/extract-blob-metadata-CV1Ke90d.mjs +9818 -0
- package/dist/exports/cli/{api/workflows/generate-image-variant.mjs → generate-image-variant-CM1BrVvZ.mjs} +20 -20
- package/dist/exports/{api/workflows/generate-preview.mjs → cli/generate-preview-DdHQ3ukz.mjs} +6 -6
- package/dist/exports/cli/index.d.mts +2142 -2
- package/dist/exports/cli/index.mjs +41 -1
- package/dist/exports/cli/pdf-CLUPEIdT.mjs +25822 -0
- package/dist/exports/{api/workflows/purge-attachment.mjs → cli/purge-attachment-Dc_J74dG.mjs} +3 -3
- package/dist/exports/cli/purge-audit-logs-DFhWh-Bx.mjs +56 -0
- package/dist/exports/cli/purge-unattached-blobs-C1MRlM_2.mjs +46 -0
- package/dist/exports/cli/track-db-changes-CfneOF2_.mjs +20943 -0
- package/dist/exports/{api/workflows/api/workflow.mjs → cli/workflow-DSbbXBMt.mjs} +23 -3
- package/dist/exports/cli/zod-7q0_Mtnn.mjs +12333 -0
- package/dist/exports/devtools/BaseTanStackRouterDevtoolsPanel-BBz1qLry-DUwdvyLv.js +2090 -0
- package/dist/exports/devtools/EIDV623S-B7f6114d.js +2497 -0
- package/dist/exports/devtools/FloatingTanStackRouterDevtools-DymJEvfG-BHuQHiRR.js +237 -0
- package/dist/exports/devtools/MIMHJGAX-Cb3wf11F.js +10903 -0
- package/dist/exports/devtools/Q7LWSL4U-BoEO3rNq.js +37 -0
- package/dist/exports/devtools/VLTTJS3N-CIyRc84e.js +44 -0
- package/dist/exports/devtools/index.js +1724 -3
- package/dist/exports/devtools/utils-YRTCpRgb.js +1670 -0
- package/dist/exports/tests/api.d.mts +7354 -5
- package/dist/exports/tests/api.mjs +79 -1
- package/dist/exports/tests/auth-schema-DUCJw-_2.mjs +1 -0
- package/dist/exports/tests/chunk-Cii4FAhs.mjs +1 -0
- package/dist/exports/tests/conditions-B0ffVJ5E.mjs +1 -0
- package/dist/exports/tests/constants-DHjjg05J.mjs +1 -0
- package/dist/exports/tests/dist-D6vgKv3t.mjs +7 -0
- package/dist/exports/tests/dist-EfrRkq5c.mjs +296 -0
- package/dist/exports/tests/extract-blob-metadata-Dv343Vcn.mjs +169 -0
- package/dist/exports/tests/generate-image-variant-cQc8q0kh.mjs +1 -0
- package/dist/exports/tests/generate-preview-HaTMd2hS.mjs +1 -0
- package/dist/exports/tests/magic-string.es-D6VRmdiF.mjs +14 -0
- package/dist/exports/tests/mock-BvkO5nlm.mjs +1 -0
- package/dist/exports/tests/mock.mjs +1 -1
- package/dist/exports/tests/pdf-BDsS3vjF.mjs +13 -0
- package/dist/exports/tests/purge-attachment-D4uOzHRi.mjs +1 -0
- package/dist/exports/tests/purge-audit-logs-DiPcc09d.mjs +1 -0
- package/dist/exports/tests/purge-unattached-blobs-CqW6tlIC.mjs +1 -0
- package/dist/exports/tests/react.mjs +6 -1
- package/dist/exports/tests/setup.d.mts +1 -1
- package/dist/exports/tests/setup.mjs +34 -1
- package/dist/exports/tests/table-CbU04119.mjs +1 -0
- package/dist/exports/tests/track-db-changes-Bd4W-P1q.mjs +1 -0
- package/dist/exports/tests/vi.2VT5v0um-Cme1b0Dl.mjs +348 -0
- package/dist/exports/tests/{api/workflow.mjs → workflow-DwZxTqdH.mjs} +1 -1
- package/dist/exports/tests/zod-DcpxsMPz.mjs +23 -0
- package/dist/exports/vendors/date.js +13236 -1
- package/dist/exports/vendors/toolkit.js +2206 -1
- package/dist/exports/vendors/zod.js +12344 -1
- package/dist/exports/vite/api-DGRU_RdM.mjs +27 -0
- package/dist/exports/vite/build-CxJAu2Bn.mjs +1 -0
- package/dist/exports/vite/build2-BMK0OFVt.mjs +16 -0
- package/dist/exports/vite/chunk-CxnlK1Zi.mjs +1 -0
- package/dist/exports/vite/chunk-PtveFMYu.mjs +1 -0
- package/dist/exports/vite/dist-Bxp8DqWh.mjs +114 -0
- package/dist/exports/vite/dist-CX51FKbX.mjs +1 -0
- package/dist/exports/vite/dist-DcyNr-KR.mjs +1 -0
- package/dist/exports/vite/dist-j3-Khlzt.mjs +1 -0
- package/dist/exports/vite/experimental-index-3KsfmUbz.mjs +1 -0
- package/dist/exports/vite/false-BNJbUKYT.mjs +1 -0
- package/dist/exports/vite/false-BvrPEDU6.mjs +1 -0
- package/dist/exports/vite/index.d.mts +1 -1
- package/dist/exports/vite/index.mjs +26 -1
- package/dist/exports/vite/internal-C5cVwRiK.mjs +1 -0
- package/dist/exports/vite/jiti-BjSPrFvg.mjs +9 -0
- package/dist/exports/vite/lexer-DQCqS3nf-C6xCDOEQ.mjs +3 -0
- package/dist/exports/vite/lib-CMv7Sfwa.mjs +1 -0
- package/dist/exports/vite/lib-D9TnS-7w.mjs +1 -0
- package/dist/exports/vite/lib-DuBRr9dH.mjs +382 -0
- package/dist/exports/vite/node-DI8AnY_i.mjs +437 -0
- package/dist/exports/vite/postcss-BtmDpj-c.mjs +32 -0
- package/dist/exports/vite/postcss-import-Bk_ZCd6c.mjs +5 -0
- package/dist/exports/vite/rolldown-build-CNW2eye_-CJNfyXdF.mjs +13 -0
- package/dist/exports/vitest/api-CPv6lnxG.mjs +27 -0
- package/dist/exports/vitest/build2-28i3OiJ3.mjs +16 -0
- package/dist/exports/vitest/chunk-_e2jlDPK.mjs +1 -0
- package/dist/exports/vitest/chunk-jwDkFoXW.mjs +1 -0
- package/dist/exports/vitest/config.mjs +77 -1
- package/dist/exports/vitest/dist-L-OpshPJ.mjs +114 -0
- package/dist/exports/vitest/index.mjs +348 -1
- package/dist/exports/vitest/jiti-eNGOyHIo.mjs +9 -0
- package/dist/exports/vitest/lexer-DQCqS3nf-TWLyIqlY.mjs +3 -0
- package/dist/exports/vitest/lib-C3G64csm.mjs +1 -0
- package/dist/exports/vitest/magic-string.es-CxM5Ubyl.mjs +14 -0
- package/dist/exports/vitest/module-runner-DsF4L04D.mjs +1 -0
- package/dist/exports/vitest/postcss-BxLp_Too.mjs +32 -0
- package/dist/exports/vitest/postcss-import-5pKj3f5q.mjs +5 -0
- package/dist/exports/web/browser-ponyfill-DxTJMXNq.js +443 -0
- package/dist/exports/web/chunk-DksrlJLg.js +49 -0
- package/dist/exports/web/index.d.ts +2546 -2
- package/dist/exports/web/index.js +9295 -6
- package/dist/exports/web/plugin-DqTFWG7p.js +250 -0
- package/package.json +1 -1
- package/dist/exports/api/app-context.d.mts +0 -115
- package/dist/exports/api/app-context.mjs +0 -24
- package/dist/exports/api/auth-schema.d.mts +0 -4248
- package/dist/exports/api/auth.d.mts +0 -402
- package/dist/exports/api/auth.mjs +0 -188
- package/dist/exports/api/cache.d.mts +0 -44
- package/dist/exports/api/cache.mjs +0 -28
- package/dist/exports/api/config.d.mts +0 -28
- package/dist/exports/api/config.mjs +0 -72
- package/dist/exports/api/constants.mjs +0 -92
- package/dist/exports/api/container.d.mts +0 -210
- package/dist/exports/api/container.mjs +0 -49
- package/dist/exports/api/database.d.mts +0 -101
- package/dist/exports/api/database.mjs +0 -219
- package/dist/exports/api/event.d.mts +0 -235
- package/dist/exports/api/event.mjs +0 -236
- package/dist/exports/api/i18n.d.mts +0 -34
- package/dist/exports/api/i18n.mjs +0 -45
- package/dist/exports/api/instrumentation.d.mts +0 -7
- package/dist/exports/api/instrumentation.mjs +0 -40
- package/dist/exports/api/logger.d.mts +0 -21
- package/dist/exports/api/logger.mjs +0 -26
- package/dist/exports/api/mailer.d.mts +0 -70
- package/dist/exports/api/mailer.mjs +0 -37
- package/dist/exports/api/middleware/request-logger.d.mts +0 -24
- package/dist/exports/api/middleware.d.mts +0 -39
- package/dist/exports/api/middleware.mjs +0 -73
- package/dist/exports/api/openapi.d.mts +0 -271
- package/dist/exports/api/openapi.mjs +0 -507
- package/dist/exports/api/otel.d.mts +0 -40
- package/dist/exports/api/otel.mjs +0 -56
- package/dist/exports/api/redis.d.mts +0 -34
- package/dist/exports/api/redis.mjs +0 -41
- package/dist/exports/api/storage-schema.d.mts +0 -707
- package/dist/exports/api/storage-schema.mjs +0 -72
- package/dist/exports/api/storage.d.mts +0 -506
- package/dist/exports/api/storage.mjs +0 -833
- package/dist/exports/api/web/auth.mjs +0 -17
- package/dist/exports/api/workflow.d.mts +0 -250
- package/dist/exports/api/workflows/api/auth-schema.mjs +0 -373
- package/dist/exports/api/workflows/api/auth.d.mts +0 -379
- package/dist/exports/api/workflows/api/cache.d.mts +0 -44
- package/dist/exports/api/workflows/api/config.d.mts +0 -18
- package/dist/exports/api/workflows/api/container.d.mts +0 -167
- package/dist/exports/api/workflows/api/database.d.mts +0 -47
- package/dist/exports/api/workflows/api/event.d.mts +0 -68
- package/dist/exports/api/workflows/api/event.mjs +0 -126
- package/dist/exports/api/workflows/api/logger.d.mts +0 -21
- package/dist/exports/api/workflows/api/mailer.d.mts +0 -70
- package/dist/exports/api/workflows/api/orm.d.mts +0 -13
- package/dist/exports/api/workflows/api/redis.mjs +0 -3
- package/dist/exports/api/workflows/api/storage-schema.d.mts +0 -699
- package/dist/exports/api/workflows/api/storage.d.mts +0 -396
- package/dist/exports/api/workflows/api/workflow.d.mts +0 -24
- package/dist/exports/api/workflows/constants.mjs +0 -23
- package/dist/exports/api/workflows/extract-blob-metadata.mjs +0 -132
- package/dist/exports/api/workflows/generate-image-variant.d.mts +0 -63
- package/dist/exports/api/workflows/track-db-changes.d.mts +0 -72
- package/dist/exports/cli/api/auth-schema.mjs +0 -373
- package/dist/exports/cli/api/auth.d.mts +0 -379
- package/dist/exports/cli/api/cache.d.mts +0 -44
- package/dist/exports/cli/api/config.d.mts +0 -18
- package/dist/exports/cli/api/container.d.mts +0 -167
- package/dist/exports/cli/api/database.d.mts +0 -47
- package/dist/exports/cli/api/event.d.mts +0 -68
- package/dist/exports/cli/api/event.mjs +0 -126
- package/dist/exports/cli/api/logger.d.mts +0 -21
- package/dist/exports/cli/api/mailer.d.mts +0 -70
- package/dist/exports/cli/api/orm.d.mts +0 -13
- package/dist/exports/cli/api/redis.mjs +0 -3
- package/dist/exports/cli/api/storage-schema.d.mts +0 -699
- package/dist/exports/cli/api/storage.d.mts +0 -396
- package/dist/exports/cli/api/workflow.d.mts +0 -2
- package/dist/exports/cli/api/workflows/extract-blob-metadata.mjs +0 -132
- package/dist/exports/cli/api/workflows/generate-image-variant.d.mts +0 -63
- package/dist/exports/cli/api/workflows/track-db-changes.mjs +0 -110
- package/dist/exports/cli/command.d.mts +0 -56
- package/dist/exports/cli/command.mjs +0 -43
- package/dist/exports/cli/constants.mjs +0 -23
- package/dist/exports/cli/context.d.mts +0 -170
- package/dist/exports/tests/_virtual/rolldown_runtime.mjs +0 -1
- package/dist/exports/tests/api/app-context.d.mts +0 -115
- package/dist/exports/tests/api/app-context.mjs +0 -1
- package/dist/exports/tests/api/auth-schema.d.mts +0 -4248
- package/dist/exports/tests/api/auth-schema.mjs +0 -1
- package/dist/exports/tests/api/auth.d.mts +0 -402
- package/dist/exports/tests/api/cache.d.mts +0 -44
- package/dist/exports/tests/api/config.d.mts +0 -28
- package/dist/exports/tests/api/container.d.mts +0 -210
- package/dist/exports/tests/api/database.d.mts +0 -101
- package/dist/exports/tests/api/database.mjs +0 -1
- package/dist/exports/tests/api/event.d.mts +0 -235
- package/dist/exports/tests/api/event.mjs +0 -1
- package/dist/exports/tests/api/i18n.d.mts +0 -34
- package/dist/exports/tests/api/index.d.mts +0 -26
- package/dist/exports/tests/api/logger.d.mts +0 -21
- package/dist/exports/tests/api/mailer.d.mts +0 -70
- package/dist/exports/tests/api/middleware/error-handler.mjs +0 -1
- package/dist/exports/tests/api/middleware/health.mjs +0 -1
- package/dist/exports/tests/api/middleware/i18n.mjs +0 -1
- package/dist/exports/tests/api/middleware/request-logger.d.mts +0 -24
- package/dist/exports/tests/api/middleware/request-logger.mjs +0 -1
- package/dist/exports/tests/api/middleware/shutdown.mjs +0 -1
- package/dist/exports/tests/api/middleware/timeout.mjs +0 -1
- package/dist/exports/tests/api/middleware.d.mts +0 -39
- package/dist/exports/tests/api/middleware.mjs +0 -1
- package/dist/exports/tests/api/openapi.d.mts +0 -271
- package/dist/exports/tests/api/openapi.mjs +0 -1
- package/dist/exports/tests/api/orm.d.mts +0 -13
- package/dist/exports/tests/api/otel.d.mts +0 -40
- package/dist/exports/tests/api/redis.d.mts +0 -34
- package/dist/exports/tests/api/redis.mjs +0 -1
- package/dist/exports/tests/api/server.mjs +0 -1
- package/dist/exports/tests/api/storage-schema.d.mts +0 -707
- package/dist/exports/tests/api/storage.d.mts +0 -506
- package/dist/exports/tests/api/workflow.d.mts +0 -250
- package/dist/exports/tests/api/workflows/extract-blob-metadata.mjs +0 -1
- package/dist/exports/tests/api/workflows/generate-image-variant.d.mts +0 -63
- package/dist/exports/tests/api/workflows/generate-image-variant.mjs +0 -1
- package/dist/exports/tests/api/workflows/generate-preview.mjs +0 -1
- package/dist/exports/tests/api/workflows/purge-attachment.mjs +0 -1
- package/dist/exports/tests/api/workflows/purge-audit-logs.mjs +0 -1
- package/dist/exports/tests/api/workflows/purge-unattached-blobs.mjs +0 -1
- package/dist/exports/tests/api/workflows/track-db-changes.mjs +0 -1
- package/dist/exports/tests/constants.mjs +0 -1
- package/dist/exports/tests/instrumentation.d.mts +0 -7
- package/dist/exports/tests/instrumentation.mjs +0 -1
- package/dist/exports/web/api/auth.d.ts +0 -125
- package/dist/exports/web/api/database.d.ts +0 -4
- package/dist/exports/web/api/logger.d.ts +0 -1
- package/dist/exports/web/auth.d.ts +0 -2388
- package/dist/exports/web/auth.js +0 -75
- package/dist/exports/web/i18n.d.ts +0 -42
- package/dist/exports/web/i18n.js +0 -45
- /package/dist/exports/tests/{api/middleware/youch-handler.mjs → youch-handler-Ch5yf6im.mjs} +0 -0
|
@@ -0,0 +1,1504 @@
|
|
|
1
|
+
//#region ../../node_modules/.bun/@better-auth+core@1.4.7+96c18005d8555383/node_modules/@better-auth/core/dist/get-tables-DeuRhD_P.mjs
|
|
2
|
+
const getAuthTables = (options) => {
|
|
3
|
+
const pluginSchema = (options.plugins ?? []).reduce((acc, plugin) => {
|
|
4
|
+
const schema = plugin.schema;
|
|
5
|
+
if (!schema) return acc;
|
|
6
|
+
for (const [key, value] of Object.entries(schema)) acc[key] = {
|
|
7
|
+
fields: {
|
|
8
|
+
...acc[key]?.fields,
|
|
9
|
+
...value.fields
|
|
10
|
+
},
|
|
11
|
+
modelName: value.modelName || key
|
|
12
|
+
};
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
const shouldAddRateLimitTable = options.rateLimit?.storage === "database";
|
|
16
|
+
const rateLimitTable = { rateLimit: {
|
|
17
|
+
modelName: options.rateLimit?.modelName || "rateLimit",
|
|
18
|
+
fields: {
|
|
19
|
+
key: {
|
|
20
|
+
type: "string",
|
|
21
|
+
fieldName: options.rateLimit?.fields?.key || "key"
|
|
22
|
+
},
|
|
23
|
+
count: {
|
|
24
|
+
type: "number",
|
|
25
|
+
fieldName: options.rateLimit?.fields?.count || "count"
|
|
26
|
+
},
|
|
27
|
+
lastRequest: {
|
|
28
|
+
type: "number",
|
|
29
|
+
bigint: true,
|
|
30
|
+
fieldName: options.rateLimit?.fields?.lastRequest || "lastRequest"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} };
|
|
34
|
+
const { user, session, account, ...pluginTables } = pluginSchema;
|
|
35
|
+
const sessionTable = { session: {
|
|
36
|
+
modelName: options.session?.modelName || "session",
|
|
37
|
+
fields: {
|
|
38
|
+
expiresAt: {
|
|
39
|
+
type: "date",
|
|
40
|
+
required: true,
|
|
41
|
+
fieldName: options.session?.fields?.expiresAt || "expiresAt"
|
|
42
|
+
},
|
|
43
|
+
token: {
|
|
44
|
+
type: "string",
|
|
45
|
+
required: true,
|
|
46
|
+
fieldName: options.session?.fields?.token || "token",
|
|
47
|
+
unique: true
|
|
48
|
+
},
|
|
49
|
+
createdAt: {
|
|
50
|
+
type: "date",
|
|
51
|
+
required: true,
|
|
52
|
+
fieldName: options.session?.fields?.createdAt || "createdAt",
|
|
53
|
+
defaultValue: () => /* @__PURE__ */ new Date()
|
|
54
|
+
},
|
|
55
|
+
updatedAt: {
|
|
56
|
+
type: "date",
|
|
57
|
+
required: true,
|
|
58
|
+
fieldName: options.session?.fields?.updatedAt || "updatedAt",
|
|
59
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
60
|
+
},
|
|
61
|
+
ipAddress: {
|
|
62
|
+
type: "string",
|
|
63
|
+
required: false,
|
|
64
|
+
fieldName: options.session?.fields?.ipAddress || "ipAddress"
|
|
65
|
+
},
|
|
66
|
+
userAgent: {
|
|
67
|
+
type: "string",
|
|
68
|
+
required: false,
|
|
69
|
+
fieldName: options.session?.fields?.userAgent || "userAgent"
|
|
70
|
+
},
|
|
71
|
+
userId: {
|
|
72
|
+
type: "string",
|
|
73
|
+
fieldName: options.session?.fields?.userId || "userId",
|
|
74
|
+
references: {
|
|
75
|
+
model: options.user?.modelName || "user",
|
|
76
|
+
field: "id",
|
|
77
|
+
onDelete: "cascade"
|
|
78
|
+
},
|
|
79
|
+
required: true,
|
|
80
|
+
index: true
|
|
81
|
+
},
|
|
82
|
+
...session?.fields,
|
|
83
|
+
...options.session?.additionalFields
|
|
84
|
+
},
|
|
85
|
+
order: 2
|
|
86
|
+
} };
|
|
87
|
+
return {
|
|
88
|
+
user: {
|
|
89
|
+
modelName: options.user?.modelName || "user",
|
|
90
|
+
fields: {
|
|
91
|
+
name: {
|
|
92
|
+
type: "string",
|
|
93
|
+
required: true,
|
|
94
|
+
fieldName: options.user?.fields?.name || "name",
|
|
95
|
+
sortable: true
|
|
96
|
+
},
|
|
97
|
+
email: {
|
|
98
|
+
type: "string",
|
|
99
|
+
unique: true,
|
|
100
|
+
required: true,
|
|
101
|
+
fieldName: options.user?.fields?.email || "email",
|
|
102
|
+
sortable: true
|
|
103
|
+
},
|
|
104
|
+
emailVerified: {
|
|
105
|
+
type: "boolean",
|
|
106
|
+
defaultValue: false,
|
|
107
|
+
required: true,
|
|
108
|
+
fieldName: options.user?.fields?.emailVerified || "emailVerified",
|
|
109
|
+
input: false
|
|
110
|
+
},
|
|
111
|
+
image: {
|
|
112
|
+
type: "string",
|
|
113
|
+
required: false,
|
|
114
|
+
fieldName: options.user?.fields?.image || "image"
|
|
115
|
+
},
|
|
116
|
+
createdAt: {
|
|
117
|
+
type: "date",
|
|
118
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
119
|
+
required: true,
|
|
120
|
+
fieldName: options.user?.fields?.createdAt || "createdAt"
|
|
121
|
+
},
|
|
122
|
+
updatedAt: {
|
|
123
|
+
type: "date",
|
|
124
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
125
|
+
onUpdate: () => /* @__PURE__ */ new Date(),
|
|
126
|
+
required: true,
|
|
127
|
+
fieldName: options.user?.fields?.updatedAt || "updatedAt"
|
|
128
|
+
},
|
|
129
|
+
...user?.fields,
|
|
130
|
+
...options.user?.additionalFields
|
|
131
|
+
},
|
|
132
|
+
order: 1
|
|
133
|
+
},
|
|
134
|
+
...!options.secondaryStorage || options.session?.storeSessionInDatabase ? sessionTable : {},
|
|
135
|
+
account: {
|
|
136
|
+
modelName: options.account?.modelName || "account",
|
|
137
|
+
fields: {
|
|
138
|
+
accountId: {
|
|
139
|
+
type: "string",
|
|
140
|
+
required: true,
|
|
141
|
+
fieldName: options.account?.fields?.accountId || "accountId"
|
|
142
|
+
},
|
|
143
|
+
providerId: {
|
|
144
|
+
type: "string",
|
|
145
|
+
required: true,
|
|
146
|
+
fieldName: options.account?.fields?.providerId || "providerId"
|
|
147
|
+
},
|
|
148
|
+
userId: {
|
|
149
|
+
type: "string",
|
|
150
|
+
references: {
|
|
151
|
+
model: options.user?.modelName || "user",
|
|
152
|
+
field: "id",
|
|
153
|
+
onDelete: "cascade"
|
|
154
|
+
},
|
|
155
|
+
required: true,
|
|
156
|
+
fieldName: options.account?.fields?.userId || "userId",
|
|
157
|
+
index: true
|
|
158
|
+
},
|
|
159
|
+
accessToken: {
|
|
160
|
+
type: "string",
|
|
161
|
+
required: false,
|
|
162
|
+
fieldName: options.account?.fields?.accessToken || "accessToken"
|
|
163
|
+
},
|
|
164
|
+
refreshToken: {
|
|
165
|
+
type: "string",
|
|
166
|
+
required: false,
|
|
167
|
+
fieldName: options.account?.fields?.refreshToken || "refreshToken"
|
|
168
|
+
},
|
|
169
|
+
idToken: {
|
|
170
|
+
type: "string",
|
|
171
|
+
required: false,
|
|
172
|
+
fieldName: options.account?.fields?.idToken || "idToken"
|
|
173
|
+
},
|
|
174
|
+
accessTokenExpiresAt: {
|
|
175
|
+
type: "date",
|
|
176
|
+
required: false,
|
|
177
|
+
fieldName: options.account?.fields?.accessTokenExpiresAt || "accessTokenExpiresAt"
|
|
178
|
+
},
|
|
179
|
+
refreshTokenExpiresAt: {
|
|
180
|
+
type: "date",
|
|
181
|
+
required: false,
|
|
182
|
+
fieldName: options.account?.fields?.refreshTokenExpiresAt || "refreshTokenExpiresAt"
|
|
183
|
+
},
|
|
184
|
+
scope: {
|
|
185
|
+
type: "string",
|
|
186
|
+
required: false,
|
|
187
|
+
fieldName: options.account?.fields?.scope || "scope"
|
|
188
|
+
},
|
|
189
|
+
password: {
|
|
190
|
+
type: "string",
|
|
191
|
+
required: false,
|
|
192
|
+
fieldName: options.account?.fields?.password || "password"
|
|
193
|
+
},
|
|
194
|
+
createdAt: {
|
|
195
|
+
type: "date",
|
|
196
|
+
required: true,
|
|
197
|
+
fieldName: options.account?.fields?.createdAt || "createdAt",
|
|
198
|
+
defaultValue: () => /* @__PURE__ */ new Date()
|
|
199
|
+
},
|
|
200
|
+
updatedAt: {
|
|
201
|
+
type: "date",
|
|
202
|
+
required: true,
|
|
203
|
+
fieldName: options.account?.fields?.updatedAt || "updatedAt",
|
|
204
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
205
|
+
},
|
|
206
|
+
...account?.fields,
|
|
207
|
+
...options.account?.additionalFields
|
|
208
|
+
},
|
|
209
|
+
order: 3
|
|
210
|
+
},
|
|
211
|
+
verification: {
|
|
212
|
+
modelName: options.verification?.modelName || "verification",
|
|
213
|
+
fields: {
|
|
214
|
+
identifier: {
|
|
215
|
+
type: "string",
|
|
216
|
+
required: true,
|
|
217
|
+
fieldName: options.verification?.fields?.identifier || "identifier",
|
|
218
|
+
index: true
|
|
219
|
+
},
|
|
220
|
+
value: {
|
|
221
|
+
type: "string",
|
|
222
|
+
required: true,
|
|
223
|
+
fieldName: options.verification?.fields?.value || "value"
|
|
224
|
+
},
|
|
225
|
+
expiresAt: {
|
|
226
|
+
type: "date",
|
|
227
|
+
required: true,
|
|
228
|
+
fieldName: options.verification?.fields?.expiresAt || "expiresAt"
|
|
229
|
+
},
|
|
230
|
+
createdAt: {
|
|
231
|
+
type: "date",
|
|
232
|
+
required: true,
|
|
233
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
234
|
+
fieldName: options.verification?.fields?.createdAt || "createdAt"
|
|
235
|
+
},
|
|
236
|
+
updatedAt: {
|
|
237
|
+
type: "date",
|
|
238
|
+
required: true,
|
|
239
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
240
|
+
onUpdate: () => /* @__PURE__ */ new Date(),
|
|
241
|
+
fieldName: options.verification?.fields?.updatedAt || "updatedAt"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
order: 4
|
|
245
|
+
},
|
|
246
|
+
...pluginTables,
|
|
247
|
+
...shouldAddRateLimitTable ? rateLimitTable : {}
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region ../../node_modules/.bun/@better-auth+core@1.4.7+96c18005d8555383/node_modules/@better-auth/core/dist/env-DbssmzoK.mjs
|
|
253
|
+
const _envShim = Object.create(null);
|
|
254
|
+
const _getEnv = (useShim) => globalThis.process?.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (useShim ? _envShim : globalThis);
|
|
255
|
+
const env = new Proxy(_envShim, {
|
|
256
|
+
get(_, prop) {
|
|
257
|
+
return _getEnv()[prop] ?? _envShim[prop];
|
|
258
|
+
},
|
|
259
|
+
has(_, prop) {
|
|
260
|
+
return prop in _getEnv() || prop in _envShim;
|
|
261
|
+
},
|
|
262
|
+
set(_, prop, value) {
|
|
263
|
+
const env$1 = _getEnv(true);
|
|
264
|
+
env$1[prop] = value;
|
|
265
|
+
return true;
|
|
266
|
+
},
|
|
267
|
+
deleteProperty(_, prop) {
|
|
268
|
+
if (!prop) return false;
|
|
269
|
+
const env$1 = _getEnv(true);
|
|
270
|
+
delete env$1[prop];
|
|
271
|
+
return true;
|
|
272
|
+
},
|
|
273
|
+
ownKeys() {
|
|
274
|
+
const env$1 = _getEnv(true);
|
|
275
|
+
return Object.keys(env$1);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
function toBoolean(val) {
|
|
279
|
+
return val ? val !== "false" : false;
|
|
280
|
+
}
|
|
281
|
+
const nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
|
|
282
|
+
/** Detect if `NODE_ENV` environment variable is `production` */
|
|
283
|
+
const isProduction = nodeENV === "production";
|
|
284
|
+
/** Detect if `NODE_ENV` environment variable is `dev` or `development` */
|
|
285
|
+
const isDevelopment = () => nodeENV === "dev" || nodeENV === "development";
|
|
286
|
+
/** Detect if `NODE_ENV` environment variable is `test` */
|
|
287
|
+
const isTest = () => nodeENV === "test" || toBoolean(env.TEST);
|
|
288
|
+
/**
|
|
289
|
+
* Get environment variable with fallback
|
|
290
|
+
*/
|
|
291
|
+
function getEnvVar(key, fallback) {
|
|
292
|
+
if (typeof process !== "undefined" && process.env) return process.env[key] ?? fallback;
|
|
293
|
+
if (typeof Deno !== "undefined") return Deno.env.get(key) ?? fallback;
|
|
294
|
+
if (typeof Bun !== "undefined") return Bun.env[key] ?? fallback;
|
|
295
|
+
return fallback;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Get boolean environment variable
|
|
299
|
+
*/
|
|
300
|
+
function getBooleanEnvVar(key, fallback = true) {
|
|
301
|
+
const value = getEnvVar(key);
|
|
302
|
+
if (!value) return fallback;
|
|
303
|
+
return value !== "0" && value.toLowerCase() !== "false" && value !== "";
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Common environment variables used in Better Auth
|
|
307
|
+
*/
|
|
308
|
+
const ENV = Object.freeze({
|
|
309
|
+
get BETTER_AUTH_SECRET() {
|
|
310
|
+
return getEnvVar("BETTER_AUTH_SECRET");
|
|
311
|
+
},
|
|
312
|
+
get AUTH_SECRET() {
|
|
313
|
+
return getEnvVar("AUTH_SECRET");
|
|
314
|
+
},
|
|
315
|
+
get BETTER_AUTH_TELEMETRY() {
|
|
316
|
+
return getEnvVar("BETTER_AUTH_TELEMETRY");
|
|
317
|
+
},
|
|
318
|
+
get BETTER_AUTH_TELEMETRY_ID() {
|
|
319
|
+
return getEnvVar("BETTER_AUTH_TELEMETRY_ID");
|
|
320
|
+
},
|
|
321
|
+
get NODE_ENV() {
|
|
322
|
+
return getEnvVar("NODE_ENV", "development");
|
|
323
|
+
},
|
|
324
|
+
get PACKAGE_VERSION() {
|
|
325
|
+
return getEnvVar("PACKAGE_VERSION", "0.0.0");
|
|
326
|
+
},
|
|
327
|
+
get BETTER_AUTH_TELEMETRY_ENDPOINT() {
|
|
328
|
+
return getEnvVar("BETTER_AUTH_TELEMETRY_ENDPOINT", "https://telemetry.better-auth.com/v1/track");
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
const COLORS_2 = 1;
|
|
332
|
+
const COLORS_16 = 4;
|
|
333
|
+
const COLORS_256 = 8;
|
|
334
|
+
const COLORS_16m = 24;
|
|
335
|
+
const TERM_ENVS = {
|
|
336
|
+
eterm: COLORS_16,
|
|
337
|
+
cons25: COLORS_16,
|
|
338
|
+
console: COLORS_16,
|
|
339
|
+
cygwin: COLORS_16,
|
|
340
|
+
dtterm: COLORS_16,
|
|
341
|
+
gnome: COLORS_16,
|
|
342
|
+
hurd: COLORS_16,
|
|
343
|
+
jfbterm: COLORS_16,
|
|
344
|
+
konsole: COLORS_16,
|
|
345
|
+
kterm: COLORS_16,
|
|
346
|
+
mlterm: COLORS_16,
|
|
347
|
+
mosh: COLORS_16m,
|
|
348
|
+
putty: COLORS_16,
|
|
349
|
+
st: COLORS_16,
|
|
350
|
+
"rxvt-unicode-24bit": COLORS_16m,
|
|
351
|
+
terminator: COLORS_16m,
|
|
352
|
+
"xterm-kitty": COLORS_16m
|
|
353
|
+
};
|
|
354
|
+
const CI_ENVS_MAP = new Map(Object.entries({
|
|
355
|
+
APPVEYOR: COLORS_256,
|
|
356
|
+
BUILDKITE: COLORS_256,
|
|
357
|
+
CIRCLECI: COLORS_16m,
|
|
358
|
+
DRONE: COLORS_256,
|
|
359
|
+
GITEA_ACTIONS: COLORS_16m,
|
|
360
|
+
GITHUB_ACTIONS: COLORS_16m,
|
|
361
|
+
GITLAB_CI: COLORS_256,
|
|
362
|
+
TRAVIS: COLORS_256
|
|
363
|
+
}));
|
|
364
|
+
const TERM_ENVS_REG_EXP = [
|
|
365
|
+
/ansi/,
|
|
366
|
+
/color/,
|
|
367
|
+
/linux/,
|
|
368
|
+
/direct/,
|
|
369
|
+
/^con[0-9]*x[0-9]/,
|
|
370
|
+
/^rxvt/,
|
|
371
|
+
/^screen/,
|
|
372
|
+
/^xterm/,
|
|
373
|
+
/^vt100/,
|
|
374
|
+
/^vt220/
|
|
375
|
+
];
|
|
376
|
+
function getColorDepth() {
|
|
377
|
+
if (getEnvVar("FORCE_COLOR") !== void 0) switch (getEnvVar("FORCE_COLOR")) {
|
|
378
|
+
case "":
|
|
379
|
+
case "1":
|
|
380
|
+
case "true": return COLORS_16;
|
|
381
|
+
case "2": return COLORS_256;
|
|
382
|
+
case "3": return COLORS_16m;
|
|
383
|
+
default: return COLORS_2;
|
|
384
|
+
}
|
|
385
|
+
if (getEnvVar("NODE_DISABLE_COLORS") !== void 0 && getEnvVar("NODE_DISABLE_COLORS") !== "" || getEnvVar("NO_COLOR") !== void 0 && getEnvVar("NO_COLOR") !== "" || getEnvVar("TERM") === "dumb") return COLORS_2;
|
|
386
|
+
if (getEnvVar("TMUX")) return COLORS_16m;
|
|
387
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) return COLORS_16;
|
|
388
|
+
if ("CI" in env) {
|
|
389
|
+
for (const { 0: envName, 1: colors } of CI_ENVS_MAP) if (envName in env) return colors;
|
|
390
|
+
if (getEnvVar("CI_NAME") === "codeship") return COLORS_256;
|
|
391
|
+
return COLORS_2;
|
|
392
|
+
}
|
|
393
|
+
if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(getEnvVar("TEAMCITY_VERSION")) !== null ? COLORS_16 : COLORS_2;
|
|
394
|
+
switch (getEnvVar("TERM_PROGRAM")) {
|
|
395
|
+
case "iTerm.app":
|
|
396
|
+
if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) return COLORS_256;
|
|
397
|
+
return COLORS_16m;
|
|
398
|
+
case "HyperTerm":
|
|
399
|
+
case "MacTerm": return COLORS_16m;
|
|
400
|
+
case "Apple_Terminal": return COLORS_256;
|
|
401
|
+
}
|
|
402
|
+
if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") return COLORS_16m;
|
|
403
|
+
if (getEnvVar("TERM")) {
|
|
404
|
+
if (/truecolor/.exec(getEnvVar("TERM")) !== null) return COLORS_16m;
|
|
405
|
+
if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) return COLORS_256;
|
|
406
|
+
const termEnv = getEnvVar("TERM").toLowerCase();
|
|
407
|
+
if (TERM_ENVS[termEnv]) return TERM_ENVS[termEnv];
|
|
408
|
+
if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) return COLORS_16;
|
|
409
|
+
}
|
|
410
|
+
if (getEnvVar("COLORTERM")) return COLORS_16;
|
|
411
|
+
return COLORS_2;
|
|
412
|
+
}
|
|
413
|
+
const TTY_COLORS = {
|
|
414
|
+
reset: "\x1B[0m",
|
|
415
|
+
bright: "\x1B[1m",
|
|
416
|
+
dim: "\x1B[2m",
|
|
417
|
+
undim: "\x1B[22m",
|
|
418
|
+
underscore: "\x1B[4m",
|
|
419
|
+
blink: "\x1B[5m",
|
|
420
|
+
reverse: "\x1B[7m",
|
|
421
|
+
hidden: "\x1B[8m",
|
|
422
|
+
fg: {
|
|
423
|
+
black: "\x1B[30m",
|
|
424
|
+
red: "\x1B[31m",
|
|
425
|
+
green: "\x1B[32m",
|
|
426
|
+
yellow: "\x1B[33m",
|
|
427
|
+
blue: "\x1B[34m",
|
|
428
|
+
magenta: "\x1B[35m",
|
|
429
|
+
cyan: "\x1B[36m",
|
|
430
|
+
white: "\x1B[37m"
|
|
431
|
+
},
|
|
432
|
+
bg: {
|
|
433
|
+
black: "\x1B[40m",
|
|
434
|
+
red: "\x1B[41m",
|
|
435
|
+
green: "\x1B[42m",
|
|
436
|
+
yellow: "\x1B[43m",
|
|
437
|
+
blue: "\x1B[44m",
|
|
438
|
+
magenta: "\x1B[45m",
|
|
439
|
+
cyan: "\x1B[46m",
|
|
440
|
+
white: "\x1B[47m"
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
const levels = [
|
|
444
|
+
"debug",
|
|
445
|
+
"info",
|
|
446
|
+
"success",
|
|
447
|
+
"warn",
|
|
448
|
+
"error"
|
|
449
|
+
];
|
|
450
|
+
function shouldPublishLog(currentLogLevel, logLevel) {
|
|
451
|
+
return levels.indexOf(logLevel) >= levels.indexOf(currentLogLevel);
|
|
452
|
+
}
|
|
453
|
+
const levelColors = {
|
|
454
|
+
info: TTY_COLORS.fg.blue,
|
|
455
|
+
success: TTY_COLORS.fg.green,
|
|
456
|
+
warn: TTY_COLORS.fg.yellow,
|
|
457
|
+
error: TTY_COLORS.fg.red,
|
|
458
|
+
debug: TTY_COLORS.fg.magenta
|
|
459
|
+
};
|
|
460
|
+
const formatMessage = (level, message, colorsEnabled) => {
|
|
461
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
462
|
+
if (colorsEnabled) return `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${levelColors[level]}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${TTY_COLORS.reset} ${message}`;
|
|
463
|
+
return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
|
|
464
|
+
};
|
|
465
|
+
const createLogger = (options) => {
|
|
466
|
+
const enabled = options?.disabled !== true;
|
|
467
|
+
const logLevel = options?.level ?? "error";
|
|
468
|
+
const colorsEnabled = options?.disableColors !== void 0 ? !options.disableColors : getColorDepth() !== 1;
|
|
469
|
+
const LogFunc = (level, message, args = []) => {
|
|
470
|
+
if (!enabled || !shouldPublishLog(logLevel, level)) return;
|
|
471
|
+
const formattedMessage = formatMessage(level, message, colorsEnabled);
|
|
472
|
+
if (!options || typeof options.log !== "function") {
|
|
473
|
+
if (level === "error") console.error(formattedMessage, ...args);
|
|
474
|
+
else if (level === "warn") console.warn(formattedMessage, ...args);
|
|
475
|
+
else console.log(formattedMessage, ...args);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
options.log(level === "success" ? "info" : level, message, ...args);
|
|
479
|
+
};
|
|
480
|
+
return {
|
|
481
|
+
...Object.fromEntries(levels.map((level) => [level, (...[message, ...args]) => LogFunc(level, message, args)])),
|
|
482
|
+
get level() {
|
|
483
|
+
return logLevel;
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
};
|
|
487
|
+
const logger = createLogger();
|
|
488
|
+
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region ../../node_modules/.bun/@better-auth+utils@0.3.0/node_modules/@better-auth/utils/dist/random.mjs
|
|
491
|
+
function expandAlphabet(alphabet) {
|
|
492
|
+
switch (alphabet) {
|
|
493
|
+
case "a-z": return "abcdefghijklmnopqrstuvwxyz";
|
|
494
|
+
case "A-Z": return "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
495
|
+
case "0-9": return "0123456789";
|
|
496
|
+
case "-_": return "-_";
|
|
497
|
+
default: throw new Error(`Unsupported alphabet: ${alphabet}`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function createRandomStringGenerator(...baseAlphabets) {
|
|
501
|
+
const baseCharSet = baseAlphabets.map(expandAlphabet).join("");
|
|
502
|
+
if (baseCharSet.length === 0) throw new Error("No valid characters provided for random string generation.");
|
|
503
|
+
const baseCharSetLength = baseCharSet.length;
|
|
504
|
+
return (length, ...alphabets) => {
|
|
505
|
+
if (length <= 0) throw new Error("Length must be a positive integer.");
|
|
506
|
+
let charSet = baseCharSet;
|
|
507
|
+
let charSetLength = baseCharSetLength;
|
|
508
|
+
if (alphabets.length > 0) {
|
|
509
|
+
charSet = alphabets.map(expandAlphabet).join("");
|
|
510
|
+
charSetLength = charSet.length;
|
|
511
|
+
}
|
|
512
|
+
const maxValid = Math.floor(256 / charSetLength) * charSetLength;
|
|
513
|
+
const buf = new Uint8Array(length * 2);
|
|
514
|
+
const bufLength = buf.length;
|
|
515
|
+
let result = "";
|
|
516
|
+
let bufIndex = bufLength;
|
|
517
|
+
let rand;
|
|
518
|
+
while (result.length < length) {
|
|
519
|
+
if (bufIndex >= bufLength) {
|
|
520
|
+
crypto.getRandomValues(buf);
|
|
521
|
+
bufIndex = 0;
|
|
522
|
+
}
|
|
523
|
+
rand = buf[bufIndex++];
|
|
524
|
+
if (rand < maxValid) result += charSet[rand % charSetLength];
|
|
525
|
+
}
|
|
526
|
+
return result;
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region ../../node_modules/.bun/@better-auth+core@1.4.7+96c18005d8555383/node_modules/@better-auth/core/dist/utils-NloIXYE0.mjs
|
|
532
|
+
function defineErrorCodes(codes) {
|
|
533
|
+
return codes;
|
|
534
|
+
}
|
|
535
|
+
const generateId = (size) => {
|
|
536
|
+
return createRandomStringGenerator("a-z", "A-Z", "0-9")(size || 32);
|
|
537
|
+
};
|
|
538
|
+
function safeJSONParse(data) {
|
|
539
|
+
function reviver(_, value) {
|
|
540
|
+
if (typeof value === "string") {
|
|
541
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/.test(value)) {
|
|
542
|
+
const date = new Date(value);
|
|
543
|
+
if (!isNaN(date.getTime())) return date;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return value;
|
|
547
|
+
}
|
|
548
|
+
try {
|
|
549
|
+
if (typeof data !== "string") return data;
|
|
550
|
+
return JSON.parse(data, reviver);
|
|
551
|
+
} catch (e) {
|
|
552
|
+
logger.error("Error parsing JSON", { error: e });
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
//#endregion
|
|
558
|
+
//#region ../../node_modules/.bun/@better-auth+core@1.4.7+96c18005d8555383/node_modules/@better-auth/core/dist/error-CzMAIrPb.mjs
|
|
559
|
+
const BASE_ERROR_CODES = defineErrorCodes({
|
|
560
|
+
USER_NOT_FOUND: "User not found",
|
|
561
|
+
FAILED_TO_CREATE_USER: "Failed to create user",
|
|
562
|
+
FAILED_TO_CREATE_SESSION: "Failed to create session",
|
|
563
|
+
FAILED_TO_UPDATE_USER: "Failed to update user",
|
|
564
|
+
FAILED_TO_GET_SESSION: "Failed to get session",
|
|
565
|
+
INVALID_PASSWORD: "Invalid password",
|
|
566
|
+
INVALID_EMAIL: "Invalid email",
|
|
567
|
+
INVALID_EMAIL_OR_PASSWORD: "Invalid email or password",
|
|
568
|
+
SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked",
|
|
569
|
+
PROVIDER_NOT_FOUND: "Provider not found",
|
|
570
|
+
INVALID_TOKEN: "Invalid token",
|
|
571
|
+
ID_TOKEN_NOT_SUPPORTED: "id_token not supported",
|
|
572
|
+
FAILED_TO_GET_USER_INFO: "Failed to get user info",
|
|
573
|
+
USER_EMAIL_NOT_FOUND: "User email not found",
|
|
574
|
+
EMAIL_NOT_VERIFIED: "Email not verified",
|
|
575
|
+
PASSWORD_TOO_SHORT: "Password too short",
|
|
576
|
+
PASSWORD_TOO_LONG: "Password too long",
|
|
577
|
+
USER_ALREADY_EXISTS: "User already exists.",
|
|
578
|
+
USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.",
|
|
579
|
+
EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated",
|
|
580
|
+
CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found",
|
|
581
|
+
SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.",
|
|
582
|
+
FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account",
|
|
583
|
+
ACCOUNT_NOT_FOUND: "Account not found",
|
|
584
|
+
USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account."
|
|
585
|
+
});
|
|
586
|
+
var BetterAuthError = class extends Error {
|
|
587
|
+
constructor(message, cause) {
|
|
588
|
+
super(message);
|
|
589
|
+
this.name = "BetterAuthError";
|
|
590
|
+
this.message = message;
|
|
591
|
+
this.cause = cause;
|
|
592
|
+
this.stack = "";
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region ../../node_modules/.bun/@better-auth+core@1.4.7+96c18005d8555383/node_modules/@better-auth/core/dist/db/adapter/index.mjs
|
|
598
|
+
const initGetDefaultModelName = ({ usePlural, schema }) => {
|
|
599
|
+
/**
|
|
600
|
+
* This function helps us get the default model name from the schema defined by devs.
|
|
601
|
+
* Often times, the user will be using the `modelName` which could had been customized by the users.
|
|
602
|
+
* This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
|
|
603
|
+
*
|
|
604
|
+
* If it's still unclear what this does:
|
|
605
|
+
*
|
|
606
|
+
* 1. User can define a custom modelName.
|
|
607
|
+
* 2. When using a custom modelName, doing something like `schema[model]` will not work.
|
|
608
|
+
* 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
|
|
609
|
+
*/
|
|
610
|
+
const getDefaultModelName = (model) => {
|
|
611
|
+
if (usePlural && model.charAt(model.length - 1) === "s") {
|
|
612
|
+
let pluralessModel = model.slice(0, -1);
|
|
613
|
+
let m$1 = schema[pluralessModel] ? pluralessModel : void 0;
|
|
614
|
+
if (!m$1) m$1 = Object.entries(schema).find(([_, f]) => f.modelName === pluralessModel)?.[0];
|
|
615
|
+
if (m$1) return m$1;
|
|
616
|
+
}
|
|
617
|
+
let m = schema[model] ? model : void 0;
|
|
618
|
+
if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === model)?.[0];
|
|
619
|
+
if (!m) throw new BetterAuthError(`Model "${model}" not found in schema`);
|
|
620
|
+
return m;
|
|
621
|
+
};
|
|
622
|
+
return getDefaultModelName;
|
|
623
|
+
};
|
|
624
|
+
const initGetDefaultFieldName = ({ schema, usePlural }) => {
|
|
625
|
+
const getDefaultModelName = initGetDefaultModelName({
|
|
626
|
+
schema,
|
|
627
|
+
usePlural
|
|
628
|
+
});
|
|
629
|
+
/**
|
|
630
|
+
* This function helps us get the default field name from the schema defined by devs.
|
|
631
|
+
* Often times, the user will be using the `fieldName` which could had been customized by the users.
|
|
632
|
+
* This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
|
|
633
|
+
*
|
|
634
|
+
* If it's still unclear what this does:
|
|
635
|
+
*
|
|
636
|
+
* 1. User can define a custom fieldName.
|
|
637
|
+
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
638
|
+
*/
|
|
639
|
+
const getDefaultFieldName = ({ field, model: unsafeModel }) => {
|
|
640
|
+
if (field === "id" || field === "_id") return "id";
|
|
641
|
+
const model = getDefaultModelName(unsafeModel);
|
|
642
|
+
let f = schema[model]?.fields[field];
|
|
643
|
+
if (!f) {
|
|
644
|
+
const result = Object.entries(schema[model].fields).find(([_, f$1]) => f$1.fieldName === field);
|
|
645
|
+
if (result) {
|
|
646
|
+
f = result[1];
|
|
647
|
+
field = result[0];
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
if (!f) throw new BetterAuthError(`Field ${field} not found in model ${model}`);
|
|
651
|
+
return field;
|
|
652
|
+
};
|
|
653
|
+
return getDefaultFieldName;
|
|
654
|
+
};
|
|
655
|
+
const initGetIdField = ({ usePlural, schema, disableIdGeneration, options, customIdGenerator, supportsUUIDs }) => {
|
|
656
|
+
const getDefaultModelName = initGetDefaultModelName({
|
|
657
|
+
usePlural,
|
|
658
|
+
schema
|
|
659
|
+
});
|
|
660
|
+
const idField = ({ customModelName, forceAllowId }) => {
|
|
661
|
+
const useNumberId = options.advanced?.database?.useNumberId || options.advanced?.database?.generateId === "serial";
|
|
662
|
+
const useUUIDs = options.advanced?.database?.generateId === "uuid";
|
|
663
|
+
let shouldGenerateId = (() => {
|
|
664
|
+
if (disableIdGeneration) return false;
|
|
665
|
+
else if (useNumberId && !forceAllowId) return false;
|
|
666
|
+
else if (useUUIDs) return !supportsUUIDs;
|
|
667
|
+
else return true;
|
|
668
|
+
})();
|
|
669
|
+
const model = getDefaultModelName(customModelName ?? "id");
|
|
670
|
+
return {
|
|
671
|
+
type: useNumberId ? "number" : "string",
|
|
672
|
+
required: shouldGenerateId ? true : false,
|
|
673
|
+
...shouldGenerateId ? { defaultValue() {
|
|
674
|
+
if (disableIdGeneration) return void 0;
|
|
675
|
+
let generateId$1 = options.advanced?.database?.generateId;
|
|
676
|
+
if (generateId$1 === false || useNumberId) return void 0;
|
|
677
|
+
if (typeof generateId$1 === "function") return generateId$1({ model });
|
|
678
|
+
if (customIdGenerator) return customIdGenerator({ model });
|
|
679
|
+
if (generateId$1 === "uuid") return crypto.randomUUID();
|
|
680
|
+
return generateId();
|
|
681
|
+
} } : {},
|
|
682
|
+
transform: {
|
|
683
|
+
input: (value) => {
|
|
684
|
+
if (!value) return void 0;
|
|
685
|
+
if (useNumberId) {
|
|
686
|
+
const numberValue = Number(value);
|
|
687
|
+
if (isNaN(numberValue)) return;
|
|
688
|
+
return numberValue;
|
|
689
|
+
}
|
|
690
|
+
if (useUUIDs) {
|
|
691
|
+
if (shouldGenerateId && !forceAllowId) return value;
|
|
692
|
+
if (disableIdGeneration) return void 0;
|
|
693
|
+
if (supportsUUIDs) return void 0;
|
|
694
|
+
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;
|
|
695
|
+
else {
|
|
696
|
+
const stack = (/* @__PURE__ */ new Error()).stack?.split("\n").filter((_, i) => i !== 1).join("\n").replace("Error:", "");
|
|
697
|
+
logger.warn("[Adapter Factory] - Invalid UUID value for field `id` provided when `forceAllowId` is true. Generating a new UUID.", stack);
|
|
698
|
+
}
|
|
699
|
+
if (typeof value !== "string" && !supportsUUIDs) return crypto.randomUUID();
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
return value;
|
|
703
|
+
},
|
|
704
|
+
output: (value) => {
|
|
705
|
+
if (!value) return void 0;
|
|
706
|
+
return String(value);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
};
|
|
711
|
+
return idField;
|
|
712
|
+
};
|
|
713
|
+
const initGetFieldAttributes = ({ usePlural, schema, options, customIdGenerator, disableIdGeneration }) => {
|
|
714
|
+
const getDefaultModelName = initGetDefaultModelName({
|
|
715
|
+
usePlural,
|
|
716
|
+
schema
|
|
717
|
+
});
|
|
718
|
+
const getDefaultFieldName = initGetDefaultFieldName({
|
|
719
|
+
usePlural,
|
|
720
|
+
schema
|
|
721
|
+
});
|
|
722
|
+
const idField = initGetIdField({
|
|
723
|
+
usePlural,
|
|
724
|
+
schema,
|
|
725
|
+
options,
|
|
726
|
+
customIdGenerator,
|
|
727
|
+
disableIdGeneration
|
|
728
|
+
});
|
|
729
|
+
const getFieldAttributes = ({ model, field }) => {
|
|
730
|
+
const defaultModelName = getDefaultModelName(model);
|
|
731
|
+
const defaultFieldName = getDefaultFieldName({
|
|
732
|
+
field,
|
|
733
|
+
model: defaultModelName
|
|
734
|
+
});
|
|
735
|
+
const fields = schema[defaultModelName].fields;
|
|
736
|
+
fields.id = idField({ customModelName: defaultModelName });
|
|
737
|
+
const fieldAttributes = fields[defaultFieldName];
|
|
738
|
+
if (!fieldAttributes) throw new BetterAuthError(`Field ${field} not found in model ${model}`);
|
|
739
|
+
return fieldAttributes;
|
|
740
|
+
};
|
|
741
|
+
return getFieldAttributes;
|
|
742
|
+
};
|
|
743
|
+
const initGetFieldName = ({ schema, usePlural }) => {
|
|
744
|
+
const getDefaultModelName = initGetDefaultModelName({
|
|
745
|
+
schema,
|
|
746
|
+
usePlural
|
|
747
|
+
});
|
|
748
|
+
const getDefaultFieldName = initGetDefaultFieldName({
|
|
749
|
+
schema,
|
|
750
|
+
usePlural
|
|
751
|
+
});
|
|
752
|
+
/**
|
|
753
|
+
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
754
|
+
*
|
|
755
|
+
* This function is useful if you need to save the field name to the database.
|
|
756
|
+
*
|
|
757
|
+
* 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.
|
|
758
|
+
*/
|
|
759
|
+
function getFieldName({ model: modelName, field: fieldName }) {
|
|
760
|
+
const model = getDefaultModelName(modelName);
|
|
761
|
+
const field = getDefaultFieldName({
|
|
762
|
+
model,
|
|
763
|
+
field: fieldName
|
|
764
|
+
});
|
|
765
|
+
return schema[model]?.fields[field]?.fieldName || field;
|
|
766
|
+
}
|
|
767
|
+
return getFieldName;
|
|
768
|
+
};
|
|
769
|
+
const initGetModelName = ({ usePlural, schema }) => {
|
|
770
|
+
const getDefaultModelName = initGetDefaultModelName({
|
|
771
|
+
schema,
|
|
772
|
+
usePlural
|
|
773
|
+
});
|
|
774
|
+
/**
|
|
775
|
+
* Users can overwrite the default model of some tables. This function helps find the correct model name.
|
|
776
|
+
* Furthermore, if the user passes `usePlural` as true in their adapter config,
|
|
777
|
+
* then we should return the model name ending with an `s`.
|
|
778
|
+
*/
|
|
779
|
+
const getModelName = (model) => {
|
|
780
|
+
const defaultModelKey = getDefaultModelName(model);
|
|
781
|
+
if (schema && schema[defaultModelKey] && schema[defaultModelKey].modelName !== model) return usePlural ? `${schema[defaultModelKey].modelName}s` : schema[defaultModelKey].modelName;
|
|
782
|
+
return usePlural ? `${model}s` : model;
|
|
783
|
+
};
|
|
784
|
+
return getModelName;
|
|
785
|
+
};
|
|
786
|
+
function withApplyDefault(value, field, action) {
|
|
787
|
+
if (action === "update") {
|
|
788
|
+
if (value === void 0 && field.onUpdate !== void 0) {
|
|
789
|
+
if (typeof field.onUpdate === "function") return field.onUpdate();
|
|
790
|
+
return field.onUpdate;
|
|
791
|
+
}
|
|
792
|
+
return value;
|
|
793
|
+
}
|
|
794
|
+
if (action === "create") {
|
|
795
|
+
if (value === void 0 || field.required === true && value === null) {
|
|
796
|
+
if (field.defaultValue !== void 0) {
|
|
797
|
+
if (typeof field.defaultValue === "function") return field.defaultValue();
|
|
798
|
+
return field.defaultValue;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return value;
|
|
803
|
+
}
|
|
804
|
+
let debugLogs = [];
|
|
805
|
+
let transactionId = -1;
|
|
806
|
+
const createAsIsTransaction = (adapter) => (fn) => fn(adapter);
|
|
807
|
+
const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (options) => {
|
|
808
|
+
const uniqueAdapterFactoryInstanceId = Math.random().toString(36).substring(2, 15);
|
|
809
|
+
const config = {
|
|
810
|
+
...cfg,
|
|
811
|
+
supportsBooleans: cfg.supportsBooleans ?? true,
|
|
812
|
+
supportsDates: cfg.supportsDates ?? true,
|
|
813
|
+
supportsJSON: cfg.supportsJSON ?? false,
|
|
814
|
+
adapterName: cfg.adapterName ?? cfg.adapterId,
|
|
815
|
+
supportsNumericIds: cfg.supportsNumericIds ?? true,
|
|
816
|
+
supportsUUIDs: cfg.supportsUUIDs ?? false,
|
|
817
|
+
supportsArrays: cfg.supportsArrays ?? false,
|
|
818
|
+
transaction: cfg.transaction ?? false,
|
|
819
|
+
disableTransformInput: cfg.disableTransformInput ?? false,
|
|
820
|
+
disableTransformOutput: cfg.disableTransformOutput ?? false,
|
|
821
|
+
disableTransformJoin: cfg.disableTransformJoin ?? false
|
|
822
|
+
};
|
|
823
|
+
if ((options.advanced?.database?.useNumberId === true || options.advanced?.database?.generateId === "serial") && config.supportsNumericIds === false) throw new BetterAuthError(`[${config.adapterName}] Your database or database adapter does not support numeric ids. Please disable "useNumberId" in your config.`);
|
|
824
|
+
const schema = getAuthTables(options);
|
|
825
|
+
const debugLog = (...args) => {
|
|
826
|
+
if (config.debugLogs === true || typeof config.debugLogs === "object") {
|
|
827
|
+
const logger$2 = createLogger({ level: "info" });
|
|
828
|
+
if (typeof config.debugLogs === "object" && "isRunningAdapterTests" in config.debugLogs) {
|
|
829
|
+
if (config.debugLogs.isRunningAdapterTests) {
|
|
830
|
+
args.shift();
|
|
831
|
+
debugLogs.push({
|
|
832
|
+
instance: uniqueAdapterFactoryInstanceId,
|
|
833
|
+
args
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
if (typeof config.debugLogs === "object" && config.debugLogs.logCondition && !config.debugLogs.logCondition?.()) return;
|
|
839
|
+
if (typeof args[0] === "object" && "method" in args[0]) {
|
|
840
|
+
const method = args.shift().method;
|
|
841
|
+
if (typeof config.debugLogs === "object") {
|
|
842
|
+
if (method === "create" && !config.debugLogs.create) return;
|
|
843
|
+
else if (method === "update" && !config.debugLogs.update) return;
|
|
844
|
+
else if (method === "updateMany" && !config.debugLogs.updateMany) return;
|
|
845
|
+
else if (method === "findOne" && !config.debugLogs.findOne) return;
|
|
846
|
+
else if (method === "findMany" && !config.debugLogs.findMany) return;
|
|
847
|
+
else if (method === "delete" && !config.debugLogs.delete) return;
|
|
848
|
+
else if (method === "deleteMany" && !config.debugLogs.deleteMany) return;
|
|
849
|
+
else if (method === "count" && !config.debugLogs.count) return;
|
|
850
|
+
}
|
|
851
|
+
logger$2.info(`[${config.adapterName}]`, ...args);
|
|
852
|
+
} else logger$2.info(`[${config.adapterName}]`, ...args);
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
const logger$1 = createLogger(options.logger);
|
|
856
|
+
const getDefaultModelName = initGetDefaultModelName({
|
|
857
|
+
usePlural: config.usePlural,
|
|
858
|
+
schema
|
|
859
|
+
});
|
|
860
|
+
const getDefaultFieldName = initGetDefaultFieldName({
|
|
861
|
+
usePlural: config.usePlural,
|
|
862
|
+
schema
|
|
863
|
+
});
|
|
864
|
+
const getModelName = initGetModelName({
|
|
865
|
+
usePlural: config.usePlural,
|
|
866
|
+
schema
|
|
867
|
+
});
|
|
868
|
+
const getFieldName = initGetFieldName({
|
|
869
|
+
schema,
|
|
870
|
+
usePlural: config.usePlural
|
|
871
|
+
});
|
|
872
|
+
const idField = initGetIdField({
|
|
873
|
+
schema,
|
|
874
|
+
options,
|
|
875
|
+
usePlural: config.usePlural,
|
|
876
|
+
disableIdGeneration: config.disableIdGeneration,
|
|
877
|
+
customIdGenerator: config.customIdGenerator,
|
|
878
|
+
supportsUUIDs: config.supportsUUIDs
|
|
879
|
+
});
|
|
880
|
+
const getFieldAttributes = initGetFieldAttributes({
|
|
881
|
+
schema,
|
|
882
|
+
options,
|
|
883
|
+
usePlural: config.usePlural,
|
|
884
|
+
disableIdGeneration: config.disableIdGeneration,
|
|
885
|
+
customIdGenerator: config.customIdGenerator
|
|
886
|
+
});
|
|
887
|
+
const transformInput = async (data, defaultModelName, action, forceAllowId) => {
|
|
888
|
+
const transformedData = {};
|
|
889
|
+
const fields = schema[defaultModelName].fields;
|
|
890
|
+
const newMappedKeys = config.mapKeysTransformInput ?? {};
|
|
891
|
+
const useNumberId = options.advanced?.database?.useNumberId || options.advanced?.database?.generateId === "serial";
|
|
892
|
+
fields.id = idField({
|
|
893
|
+
customModelName: defaultModelName,
|
|
894
|
+
forceAllowId: forceAllowId && "id" in data
|
|
895
|
+
});
|
|
896
|
+
for (const field in fields) {
|
|
897
|
+
let value = data[field];
|
|
898
|
+
const fieldAttributes = fields[field];
|
|
899
|
+
let newFieldName = newMappedKeys[field] || fields[field].fieldName || field;
|
|
900
|
+
if (value === void 0 && (fieldAttributes.defaultValue === void 0 && !fieldAttributes.transform?.input && !(action === "update" && fieldAttributes.onUpdate) || action === "update" && !fieldAttributes.onUpdate)) continue;
|
|
901
|
+
if (fieldAttributes && fieldAttributes.type === "date" && !(value instanceof Date) && typeof value === "string") try {
|
|
902
|
+
value = new Date(value);
|
|
903
|
+
} catch {
|
|
904
|
+
logger$1.error("[Adapter Factory] Failed to convert string to date", {
|
|
905
|
+
value,
|
|
906
|
+
field
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
let newValue = withApplyDefault(value, fieldAttributes, action);
|
|
910
|
+
if (fieldAttributes.transform?.input) newValue = await fieldAttributes.transform.input(newValue);
|
|
911
|
+
if (fieldAttributes.references?.field === "id" && useNumberId) if (Array.isArray(newValue)) newValue = newValue.map((x) => x !== null ? Number(x) : null);
|
|
912
|
+
else newValue = newValue !== null ? Number(newValue) : null;
|
|
913
|
+
else if (config.supportsJSON === false && typeof newValue === "object" && fieldAttributes.type === "json") newValue = JSON.stringify(newValue);
|
|
914
|
+
else if (config.supportsArrays === false && Array.isArray(newValue) && (fieldAttributes.type === "string[]" || fieldAttributes.type === "number[]")) newValue = JSON.stringify(newValue);
|
|
915
|
+
else if (config.supportsDates === false && newValue instanceof Date && fieldAttributes.type === "date") newValue = newValue.toISOString();
|
|
916
|
+
else if (config.supportsBooleans === false && typeof newValue === "boolean") newValue = newValue ? 1 : 0;
|
|
917
|
+
if (config.customTransformInput) newValue = config.customTransformInput({
|
|
918
|
+
data: newValue,
|
|
919
|
+
action,
|
|
920
|
+
field: newFieldName,
|
|
921
|
+
fieldAttributes,
|
|
922
|
+
model: getModelName(defaultModelName),
|
|
923
|
+
schema,
|
|
924
|
+
options
|
|
925
|
+
});
|
|
926
|
+
if (newValue !== void 0) transformedData[newFieldName] = newValue;
|
|
927
|
+
}
|
|
928
|
+
return transformedData;
|
|
929
|
+
};
|
|
930
|
+
const transformOutput = async (data, unsafe_model, select = [], join) => {
|
|
931
|
+
const transformSingleOutput = async (data$1, unsafe_model$1, select$1 = []) => {
|
|
932
|
+
if (!data$1) return null;
|
|
933
|
+
const newMappedKeys = config.mapKeysTransformOutput ?? {};
|
|
934
|
+
const transformedData$1 = {};
|
|
935
|
+
const tableSchema = schema[getDefaultModelName(unsafe_model$1)].fields;
|
|
936
|
+
const idKey = Object.entries(newMappedKeys).find(([_, v]) => v === "id")?.[0];
|
|
937
|
+
tableSchema[idKey ?? "id"] = { type: options.advanced?.database?.useNumberId || options.advanced?.database?.generateId === "serial" ? "number" : "string" };
|
|
938
|
+
for (const key in tableSchema) {
|
|
939
|
+
if (select$1.length && !select$1.includes(key)) continue;
|
|
940
|
+
const field = tableSchema[key];
|
|
941
|
+
if (field) {
|
|
942
|
+
const originalKey = field.fieldName || key;
|
|
943
|
+
let newValue = data$1[Object.entries(newMappedKeys).find(([_, v]) => v === originalKey)?.[0] || originalKey];
|
|
944
|
+
if (field.transform?.output) newValue = await field.transform.output(newValue);
|
|
945
|
+
let newFieldName = newMappedKeys[key] || key;
|
|
946
|
+
if (originalKey === "id" || field.references?.field === "id") {
|
|
947
|
+
if (typeof newValue !== "undefined" && newValue !== null) newValue = String(newValue);
|
|
948
|
+
} else if (config.supportsJSON === false && typeof newValue === "string" && field.type === "json") newValue = safeJSONParse(newValue);
|
|
949
|
+
else if (config.supportsArrays === false && typeof newValue === "string" && (field.type === "string[]" || field.type === "number[]")) newValue = safeJSONParse(newValue);
|
|
950
|
+
else if (config.supportsDates === false && typeof newValue === "string" && field.type === "date") newValue = new Date(newValue);
|
|
951
|
+
else if (config.supportsBooleans === false && typeof newValue === "number" && field.type === "boolean") newValue = newValue === 1;
|
|
952
|
+
if (config.customTransformOutput) newValue = config.customTransformOutput({
|
|
953
|
+
data: newValue,
|
|
954
|
+
field: newFieldName,
|
|
955
|
+
fieldAttributes: field,
|
|
956
|
+
select: select$1,
|
|
957
|
+
model: getModelName(unsafe_model$1),
|
|
958
|
+
schema,
|
|
959
|
+
options
|
|
960
|
+
});
|
|
961
|
+
transformedData$1[newFieldName] = newValue;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return transformedData$1;
|
|
965
|
+
};
|
|
966
|
+
if (!join || Object.keys(join).length === 0) return await transformSingleOutput(data, unsafe_model, select);
|
|
967
|
+
unsafe_model = getDefaultModelName(unsafe_model);
|
|
968
|
+
let transformedData = await transformSingleOutput(data, unsafe_model, select);
|
|
969
|
+
const requiredModels = Object.entries(join).map(([model, joinConfig]) => ({
|
|
970
|
+
modelName: getModelName(model),
|
|
971
|
+
defaultModelName: getDefaultModelName(model),
|
|
972
|
+
joinConfig
|
|
973
|
+
}));
|
|
974
|
+
if (!data) return null;
|
|
975
|
+
for (const { modelName, defaultModelName, joinConfig } of requiredModels) {
|
|
976
|
+
let joinedData = await (async () => {
|
|
977
|
+
if (options.experimental?.joins) return data[modelName];
|
|
978
|
+
else return await handleFallbackJoin({
|
|
979
|
+
baseModel: unsafe_model,
|
|
980
|
+
baseData: transformedData,
|
|
981
|
+
joinModel: modelName,
|
|
982
|
+
specificJoinConfig: joinConfig
|
|
983
|
+
});
|
|
984
|
+
})();
|
|
985
|
+
if (joinedData === void 0 || joinedData === null) joinedData = joinConfig.relation === "one-to-one" ? null : [];
|
|
986
|
+
if (joinConfig.relation === "one-to-many" && !Array.isArray(joinedData)) joinedData = [joinedData];
|
|
987
|
+
let transformed = [];
|
|
988
|
+
if (Array.isArray(joinedData)) for (const item of joinedData) {
|
|
989
|
+
const transformedItem = await transformSingleOutput(item, modelName, []);
|
|
990
|
+
transformed.push(transformedItem);
|
|
991
|
+
}
|
|
992
|
+
else {
|
|
993
|
+
const transformedItem = await transformSingleOutput(joinedData, modelName, []);
|
|
994
|
+
transformed.push(transformedItem);
|
|
995
|
+
}
|
|
996
|
+
transformedData[defaultModelName] = (joinConfig.relation === "one-to-one" ? transformed[0] : transformed) ?? null;
|
|
997
|
+
}
|
|
998
|
+
return transformedData;
|
|
999
|
+
};
|
|
1000
|
+
const transformWhereClause = ({ model, where }) => {
|
|
1001
|
+
if (!where) return void 0;
|
|
1002
|
+
const newMappedKeys = config.mapKeysTransformInput ?? {};
|
|
1003
|
+
return where.map((w) => {
|
|
1004
|
+
const { field: unsafe_field, value, operator = "eq", connector = "AND" } = w;
|
|
1005
|
+
if (operator === "in") {
|
|
1006
|
+
if (!Array.isArray(value)) throw new BetterAuthError("Value must be an array");
|
|
1007
|
+
}
|
|
1008
|
+
let newValue = value;
|
|
1009
|
+
const defaultModelName = getDefaultModelName(model);
|
|
1010
|
+
const defaultFieldName = getDefaultFieldName({
|
|
1011
|
+
field: unsafe_field,
|
|
1012
|
+
model
|
|
1013
|
+
});
|
|
1014
|
+
const fieldName = newMappedKeys[defaultFieldName] || getFieldName({
|
|
1015
|
+
field: defaultFieldName,
|
|
1016
|
+
model: defaultModelName
|
|
1017
|
+
});
|
|
1018
|
+
const fieldAttr = getFieldAttributes({
|
|
1019
|
+
field: defaultFieldName,
|
|
1020
|
+
model: defaultModelName
|
|
1021
|
+
});
|
|
1022
|
+
const useNumberId = options.advanced?.database?.useNumberId || options.advanced?.database?.generateId === "serial";
|
|
1023
|
+
if (defaultFieldName === "id" || fieldAttr.references?.field === "id") {
|
|
1024
|
+
if (useNumberId) if (Array.isArray(value)) newValue = value.map(Number);
|
|
1025
|
+
else newValue = Number(value);
|
|
1026
|
+
}
|
|
1027
|
+
if (fieldAttr.type === "date" && value instanceof Date && !config.supportsDates) newValue = value.toISOString();
|
|
1028
|
+
if (fieldAttr.type === "boolean" && typeof value === "boolean" && !config.supportsBooleans) newValue = value ? 1 : 0;
|
|
1029
|
+
if (fieldAttr.type === "json" && typeof value === "object" && !config.supportsJSON) try {
|
|
1030
|
+
newValue = JSON.stringify(value);
|
|
1031
|
+
} catch (error) {
|
|
1032
|
+
throw new Error(`Failed to stringify JSON value for field ${fieldName}`, { cause: error });
|
|
1033
|
+
}
|
|
1034
|
+
return {
|
|
1035
|
+
operator,
|
|
1036
|
+
connector,
|
|
1037
|
+
field: fieldName,
|
|
1038
|
+
value: newValue
|
|
1039
|
+
};
|
|
1040
|
+
});
|
|
1041
|
+
};
|
|
1042
|
+
const transformJoinClause = (baseModel, unsanitizedJoin, select) => {
|
|
1043
|
+
if (!unsanitizedJoin) return void 0;
|
|
1044
|
+
if (Object.keys(unsanitizedJoin).length === 0) return void 0;
|
|
1045
|
+
const transformedJoin = {};
|
|
1046
|
+
for (const [model, join] of Object.entries(unsanitizedJoin)) {
|
|
1047
|
+
if (!join) continue;
|
|
1048
|
+
const defaultModelName = getDefaultModelName(model);
|
|
1049
|
+
const defaultBaseModelName = getDefaultModelName(baseModel);
|
|
1050
|
+
let foreignKeys = Object.entries(schema[defaultModelName].fields).filter(([field, fieldAttributes]) => fieldAttributes.references && getDefaultModelName(fieldAttributes.references.model) === defaultBaseModelName);
|
|
1051
|
+
let isForwardJoin = true;
|
|
1052
|
+
if (!foreignKeys.length) {
|
|
1053
|
+
foreignKeys = Object.entries(schema[defaultBaseModelName].fields).filter(([field, fieldAttributes]) => fieldAttributes.references && getDefaultModelName(fieldAttributes.references.model) === defaultModelName);
|
|
1054
|
+
isForwardJoin = false;
|
|
1055
|
+
}
|
|
1056
|
+
if (!foreignKeys.length) throw new BetterAuthError(`No foreign key found for model ${model} and base model ${baseModel} while performing join operation.`);
|
|
1057
|
+
else if (foreignKeys.length > 1) throw new BetterAuthError(`Multiple foreign keys found for model ${model} and base model ${baseModel} while performing join operation. Only one foreign key is supported.`);
|
|
1058
|
+
const [foreignKey, foreignKeyAttributes] = foreignKeys[0];
|
|
1059
|
+
if (!foreignKeyAttributes.references) throw new BetterAuthError(`No references found for foreign key ${foreignKey} on model ${model} while performing join operation.`);
|
|
1060
|
+
let from;
|
|
1061
|
+
let to;
|
|
1062
|
+
let requiredSelectField;
|
|
1063
|
+
if (isForwardJoin) {
|
|
1064
|
+
requiredSelectField = foreignKeyAttributes.references.field;
|
|
1065
|
+
from = getFieldName({
|
|
1066
|
+
model: baseModel,
|
|
1067
|
+
field: requiredSelectField
|
|
1068
|
+
});
|
|
1069
|
+
to = getFieldName({
|
|
1070
|
+
model,
|
|
1071
|
+
field: foreignKey
|
|
1072
|
+
});
|
|
1073
|
+
} else {
|
|
1074
|
+
requiredSelectField = foreignKey;
|
|
1075
|
+
from = getFieldName({
|
|
1076
|
+
model: baseModel,
|
|
1077
|
+
field: requiredSelectField
|
|
1078
|
+
});
|
|
1079
|
+
to = getFieldName({
|
|
1080
|
+
model,
|
|
1081
|
+
field: foreignKeyAttributes.references.field
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
if (select && !select.includes(requiredSelectField)) select.push(requiredSelectField);
|
|
1085
|
+
const isUnique = to === "id" ? true : foreignKeyAttributes.unique ?? false;
|
|
1086
|
+
let limit = options.advanced?.database?.defaultFindManyLimit ?? 100;
|
|
1087
|
+
if (isUnique) limit = 1;
|
|
1088
|
+
else if (typeof join === "object" && typeof join.limit === "number") limit = join.limit;
|
|
1089
|
+
transformedJoin[getModelName(model)] = {
|
|
1090
|
+
on: {
|
|
1091
|
+
from,
|
|
1092
|
+
to
|
|
1093
|
+
},
|
|
1094
|
+
limit,
|
|
1095
|
+
relation: isUnique ? "one-to-one" : "one-to-many"
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
return {
|
|
1099
|
+
join: transformedJoin,
|
|
1100
|
+
select
|
|
1101
|
+
};
|
|
1102
|
+
};
|
|
1103
|
+
/**
|
|
1104
|
+
* Handle joins by making separate queries and combining results (fallback for adapters that don't support native joins).
|
|
1105
|
+
*/
|
|
1106
|
+
const handleFallbackJoin = async ({ baseModel, baseData, joinModel, specificJoinConfig: joinConfig }) => {
|
|
1107
|
+
if (!baseData) return baseData;
|
|
1108
|
+
const modelName = getModelName(joinModel);
|
|
1109
|
+
const field = joinConfig.on.to;
|
|
1110
|
+
const value = baseData[getDefaultFieldName({
|
|
1111
|
+
field: joinConfig.on.from,
|
|
1112
|
+
model: baseModel
|
|
1113
|
+
})];
|
|
1114
|
+
if (value === null || value === void 0) return joinConfig.relation === "one-to-one" ? null : [];
|
|
1115
|
+
let result;
|
|
1116
|
+
const where = transformWhereClause({
|
|
1117
|
+
model: modelName,
|
|
1118
|
+
where: [{
|
|
1119
|
+
field,
|
|
1120
|
+
value,
|
|
1121
|
+
operator: "eq",
|
|
1122
|
+
connector: "AND"
|
|
1123
|
+
}]
|
|
1124
|
+
});
|
|
1125
|
+
try {
|
|
1126
|
+
if (joinConfig.relation === "one-to-one") result = await adapterInstance.findOne({
|
|
1127
|
+
model: modelName,
|
|
1128
|
+
where
|
|
1129
|
+
});
|
|
1130
|
+
else {
|
|
1131
|
+
const limit = joinConfig.limit ?? options.advanced?.database?.defaultFindManyLimit ?? 100;
|
|
1132
|
+
result = await adapterInstance.findMany({
|
|
1133
|
+
model: modelName,
|
|
1134
|
+
where,
|
|
1135
|
+
limit
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
} catch (error) {
|
|
1139
|
+
logger$1.error(`Failed to query fallback join for model ${modelName}:`, {
|
|
1140
|
+
where,
|
|
1141
|
+
limit: joinConfig.limit
|
|
1142
|
+
});
|
|
1143
|
+
console.error(error);
|
|
1144
|
+
throw error;
|
|
1145
|
+
}
|
|
1146
|
+
return result;
|
|
1147
|
+
};
|
|
1148
|
+
const adapterInstance = customAdapter({
|
|
1149
|
+
options,
|
|
1150
|
+
schema,
|
|
1151
|
+
debugLog,
|
|
1152
|
+
getFieldName,
|
|
1153
|
+
getModelName,
|
|
1154
|
+
getDefaultModelName,
|
|
1155
|
+
getDefaultFieldName,
|
|
1156
|
+
getFieldAttributes,
|
|
1157
|
+
transformInput,
|
|
1158
|
+
transformOutput,
|
|
1159
|
+
transformWhereClause
|
|
1160
|
+
});
|
|
1161
|
+
let lazyLoadTransaction = null;
|
|
1162
|
+
const adapter = {
|
|
1163
|
+
transaction: async (cb) => {
|
|
1164
|
+
if (!lazyLoadTransaction) if (!config.transaction) lazyLoadTransaction = createAsIsTransaction(adapter);
|
|
1165
|
+
else {
|
|
1166
|
+
logger$1.debug(`[${config.adapterName}] - Using provided transaction implementation.`);
|
|
1167
|
+
lazyLoadTransaction = config.transaction;
|
|
1168
|
+
}
|
|
1169
|
+
return lazyLoadTransaction(cb);
|
|
1170
|
+
},
|
|
1171
|
+
create: async ({ data: unsafeData, model: unsafeModel, select, forceAllowId = false }) => {
|
|
1172
|
+
transactionId++;
|
|
1173
|
+
let thisTransactionId = transactionId;
|
|
1174
|
+
const model = getModelName(unsafeModel);
|
|
1175
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1176
|
+
if ("id" in unsafeData && typeof unsafeData.id !== "undefined" && !forceAllowId) {
|
|
1177
|
+
logger$1.warn(`[${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.`);
|
|
1178
|
+
const stack = (/* @__PURE__ */ new Error()).stack?.split("\n").filter((_, i) => i !== 1).join("\n").replace("Error:", "Create method with `id` being called at:");
|
|
1179
|
+
console.log(stack);
|
|
1180
|
+
unsafeData.id = void 0;
|
|
1181
|
+
}
|
|
1182
|
+
debugLog({ method: "create" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`, `${formatMethod("create")} ${formatAction("Unsafe Input")}:`, {
|
|
1183
|
+
model,
|
|
1184
|
+
data: unsafeData
|
|
1185
|
+
});
|
|
1186
|
+
let data = unsafeData;
|
|
1187
|
+
if (!config.disableTransformInput) data = await transformInput(unsafeData, unsafeModel, "create", forceAllowId);
|
|
1188
|
+
debugLog({ method: "create" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`, `${formatMethod("create")} ${formatAction("Parsed Input")}:`, {
|
|
1189
|
+
model,
|
|
1190
|
+
data
|
|
1191
|
+
});
|
|
1192
|
+
const res = await adapterInstance.create({
|
|
1193
|
+
data,
|
|
1194
|
+
model
|
|
1195
|
+
});
|
|
1196
|
+
debugLog({ method: "create" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`, `${formatMethod("create")} ${formatAction("DB Result")}:`, {
|
|
1197
|
+
model,
|
|
1198
|
+
res
|
|
1199
|
+
});
|
|
1200
|
+
let transformed = res;
|
|
1201
|
+
if (!config.disableTransformOutput) transformed = await transformOutput(res, unsafeModel, select, void 0);
|
|
1202
|
+
debugLog({ method: "create" }, `${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`, `${formatMethod("create")} ${formatAction("Parsed Result")}:`, {
|
|
1203
|
+
model,
|
|
1204
|
+
data: transformed
|
|
1205
|
+
});
|
|
1206
|
+
return transformed;
|
|
1207
|
+
},
|
|
1208
|
+
update: async ({ model: unsafeModel, where: unsafeWhere, update: unsafeData }) => {
|
|
1209
|
+
transactionId++;
|
|
1210
|
+
let thisTransactionId = transactionId;
|
|
1211
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1212
|
+
const model = getModelName(unsafeModel);
|
|
1213
|
+
const where = transformWhereClause({
|
|
1214
|
+
model: unsafeModel,
|
|
1215
|
+
where: unsafeWhere
|
|
1216
|
+
});
|
|
1217
|
+
debugLog({ method: "update" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`, `${formatMethod("update")} ${formatAction("Unsafe Input")}:`, {
|
|
1218
|
+
model,
|
|
1219
|
+
data: unsafeData
|
|
1220
|
+
});
|
|
1221
|
+
let data = unsafeData;
|
|
1222
|
+
if (!config.disableTransformInput) data = await transformInput(unsafeData, unsafeModel, "update");
|
|
1223
|
+
debugLog({ method: "update" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`, `${formatMethod("update")} ${formatAction("Parsed Input")}:`, {
|
|
1224
|
+
model,
|
|
1225
|
+
data
|
|
1226
|
+
});
|
|
1227
|
+
const res = await adapterInstance.update({
|
|
1228
|
+
model,
|
|
1229
|
+
where,
|
|
1230
|
+
update: data
|
|
1231
|
+
});
|
|
1232
|
+
debugLog({ method: "update" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`, `${formatMethod("update")} ${formatAction("DB Result")}:`, {
|
|
1233
|
+
model,
|
|
1234
|
+
data: res
|
|
1235
|
+
});
|
|
1236
|
+
let transformed = res;
|
|
1237
|
+
if (!config.disableTransformOutput) transformed = await transformOutput(res, unsafeModel, void 0, void 0);
|
|
1238
|
+
debugLog({ method: "update" }, `${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`, `${formatMethod("update")} ${formatAction("Parsed Result")}:`, {
|
|
1239
|
+
model,
|
|
1240
|
+
data: transformed
|
|
1241
|
+
});
|
|
1242
|
+
return transformed;
|
|
1243
|
+
},
|
|
1244
|
+
updateMany: async ({ model: unsafeModel, where: unsafeWhere, update: unsafeData }) => {
|
|
1245
|
+
transactionId++;
|
|
1246
|
+
let thisTransactionId = transactionId;
|
|
1247
|
+
const model = getModelName(unsafeModel);
|
|
1248
|
+
const where = transformWhereClause({
|
|
1249
|
+
model: unsafeModel,
|
|
1250
|
+
where: unsafeWhere
|
|
1251
|
+
});
|
|
1252
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1253
|
+
debugLog({ method: "updateMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`, `${formatMethod("updateMany")} ${formatAction("Unsafe Input")}:`, {
|
|
1254
|
+
model,
|
|
1255
|
+
data: unsafeData
|
|
1256
|
+
});
|
|
1257
|
+
let data = unsafeData;
|
|
1258
|
+
if (!config.disableTransformInput) data = await transformInput(unsafeData, unsafeModel, "update");
|
|
1259
|
+
debugLog({ method: "updateMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`, `${formatMethod("updateMany")} ${formatAction("Parsed Input")}:`, {
|
|
1260
|
+
model,
|
|
1261
|
+
data
|
|
1262
|
+
});
|
|
1263
|
+
const updatedCount = await adapterInstance.updateMany({
|
|
1264
|
+
model,
|
|
1265
|
+
where,
|
|
1266
|
+
update: data
|
|
1267
|
+
});
|
|
1268
|
+
debugLog({ method: "updateMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`, `${formatMethod("updateMany")} ${formatAction("DB Result")}:`, {
|
|
1269
|
+
model,
|
|
1270
|
+
data: updatedCount
|
|
1271
|
+
});
|
|
1272
|
+
debugLog({ method: "updateMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`, `${formatMethod("updateMany")} ${formatAction("Parsed Result")}:`, {
|
|
1273
|
+
model,
|
|
1274
|
+
data: updatedCount
|
|
1275
|
+
});
|
|
1276
|
+
return updatedCount;
|
|
1277
|
+
},
|
|
1278
|
+
findOne: async ({ model: unsafeModel, where: unsafeWhere, select, join: unsafeJoin }) => {
|
|
1279
|
+
transactionId++;
|
|
1280
|
+
let thisTransactionId = transactionId;
|
|
1281
|
+
const model = getModelName(unsafeModel);
|
|
1282
|
+
const where = transformWhereClause({
|
|
1283
|
+
model: unsafeModel,
|
|
1284
|
+
where: unsafeWhere
|
|
1285
|
+
});
|
|
1286
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1287
|
+
let join;
|
|
1288
|
+
let passJoinToAdapter = true;
|
|
1289
|
+
if (!config.disableTransformJoin) {
|
|
1290
|
+
const result = transformJoinClause(unsafeModel, unsafeJoin, select);
|
|
1291
|
+
if (result) {
|
|
1292
|
+
join = result.join;
|
|
1293
|
+
select = result.select;
|
|
1294
|
+
}
|
|
1295
|
+
if (!options.experimental?.joins && join && Object.keys(join).length > 0) passJoinToAdapter = false;
|
|
1296
|
+
} else join = unsafeJoin;
|
|
1297
|
+
debugLog({ method: "findOne" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`, `${formatMethod("findOne")}:`, {
|
|
1298
|
+
model,
|
|
1299
|
+
where,
|
|
1300
|
+
select,
|
|
1301
|
+
join
|
|
1302
|
+
});
|
|
1303
|
+
const res = await adapterInstance.findOne({
|
|
1304
|
+
model,
|
|
1305
|
+
where,
|
|
1306
|
+
select,
|
|
1307
|
+
join: passJoinToAdapter ? join : void 0
|
|
1308
|
+
});
|
|
1309
|
+
debugLog({ method: "findOne" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 3)}`, `${formatMethod("findOne")} ${formatAction("DB Result")}:`, {
|
|
1310
|
+
model,
|
|
1311
|
+
data: res
|
|
1312
|
+
});
|
|
1313
|
+
let transformed = res;
|
|
1314
|
+
if (!config.disableTransformOutput) transformed = await transformOutput(res, unsafeModel, select, join);
|
|
1315
|
+
debugLog({ method: "findOne" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 3)}`, `${formatMethod("findOne")} ${formatAction("Parsed Result")}:`, {
|
|
1316
|
+
model,
|
|
1317
|
+
data: transformed
|
|
1318
|
+
});
|
|
1319
|
+
return transformed;
|
|
1320
|
+
},
|
|
1321
|
+
findMany: async ({ model: unsafeModel, where: unsafeWhere, limit: unsafeLimit, sortBy, offset, join: unsafeJoin }) => {
|
|
1322
|
+
transactionId++;
|
|
1323
|
+
let thisTransactionId = transactionId;
|
|
1324
|
+
const limit = unsafeLimit ?? options.advanced?.database?.defaultFindManyLimit ?? 100;
|
|
1325
|
+
const model = getModelName(unsafeModel);
|
|
1326
|
+
const where = transformWhereClause({
|
|
1327
|
+
model: unsafeModel,
|
|
1328
|
+
where: unsafeWhere
|
|
1329
|
+
});
|
|
1330
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1331
|
+
let join;
|
|
1332
|
+
let passJoinToAdapter = true;
|
|
1333
|
+
if (!config.disableTransformJoin) {
|
|
1334
|
+
const result = transformJoinClause(unsafeModel, unsafeJoin, void 0);
|
|
1335
|
+
if (result) join = result.join;
|
|
1336
|
+
if (!options.experimental?.joins && join && Object.keys(join).length > 0) passJoinToAdapter = false;
|
|
1337
|
+
} else join = unsafeJoin;
|
|
1338
|
+
debugLog({ method: "findMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`, `${formatMethod("findMany")}:`, {
|
|
1339
|
+
model,
|
|
1340
|
+
where,
|
|
1341
|
+
limit,
|
|
1342
|
+
sortBy,
|
|
1343
|
+
offset,
|
|
1344
|
+
join
|
|
1345
|
+
});
|
|
1346
|
+
const res = await adapterInstance.findMany({
|
|
1347
|
+
model,
|
|
1348
|
+
where,
|
|
1349
|
+
limit,
|
|
1350
|
+
sortBy,
|
|
1351
|
+
offset,
|
|
1352
|
+
join: passJoinToAdapter ? join : void 0
|
|
1353
|
+
});
|
|
1354
|
+
debugLog({ method: "findMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 3)}`, `${formatMethod("findMany")} ${formatAction("DB Result")}:`, {
|
|
1355
|
+
model,
|
|
1356
|
+
data: res
|
|
1357
|
+
});
|
|
1358
|
+
let transformed = res;
|
|
1359
|
+
if (!config.disableTransformOutput) transformed = await Promise.all(res.map(async (r) => {
|
|
1360
|
+
return await transformOutput(r, unsafeModel, void 0, join);
|
|
1361
|
+
}));
|
|
1362
|
+
debugLog({ method: "findMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 3)}`, `${formatMethod("findMany")} ${formatAction("Parsed Result")}:`, {
|
|
1363
|
+
model,
|
|
1364
|
+
data: transformed
|
|
1365
|
+
});
|
|
1366
|
+
return transformed;
|
|
1367
|
+
},
|
|
1368
|
+
delete: async ({ model: unsafeModel, where: unsafeWhere }) => {
|
|
1369
|
+
transactionId++;
|
|
1370
|
+
let thisTransactionId = transactionId;
|
|
1371
|
+
const model = getModelName(unsafeModel);
|
|
1372
|
+
const where = transformWhereClause({
|
|
1373
|
+
model: unsafeModel,
|
|
1374
|
+
where: unsafeWhere
|
|
1375
|
+
});
|
|
1376
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1377
|
+
debugLog({ method: "delete" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`, `${formatMethod("delete")}:`, {
|
|
1378
|
+
model,
|
|
1379
|
+
where
|
|
1380
|
+
});
|
|
1381
|
+
await adapterInstance.delete({
|
|
1382
|
+
model,
|
|
1383
|
+
where
|
|
1384
|
+
});
|
|
1385
|
+
debugLog({ method: "delete" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`, `${formatMethod("delete")} ${formatAction("DB Result")}:`, { model });
|
|
1386
|
+
},
|
|
1387
|
+
deleteMany: async ({ model: unsafeModel, where: unsafeWhere }) => {
|
|
1388
|
+
transactionId++;
|
|
1389
|
+
let thisTransactionId = transactionId;
|
|
1390
|
+
const model = getModelName(unsafeModel);
|
|
1391
|
+
const where = transformWhereClause({
|
|
1392
|
+
model: unsafeModel,
|
|
1393
|
+
where: unsafeWhere
|
|
1394
|
+
});
|
|
1395
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1396
|
+
debugLog({ method: "deleteMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`, `${formatMethod("deleteMany")} ${formatAction("DeleteMany")}:`, {
|
|
1397
|
+
model,
|
|
1398
|
+
where
|
|
1399
|
+
});
|
|
1400
|
+
const res = await adapterInstance.deleteMany({
|
|
1401
|
+
model,
|
|
1402
|
+
where
|
|
1403
|
+
});
|
|
1404
|
+
debugLog({ method: "deleteMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`, `${formatMethod("deleteMany")} ${formatAction("DB Result")}:`, {
|
|
1405
|
+
model,
|
|
1406
|
+
data: res
|
|
1407
|
+
});
|
|
1408
|
+
return res;
|
|
1409
|
+
},
|
|
1410
|
+
count: async ({ model: unsafeModel, where: unsafeWhere }) => {
|
|
1411
|
+
transactionId++;
|
|
1412
|
+
let thisTransactionId = transactionId;
|
|
1413
|
+
const model = getModelName(unsafeModel);
|
|
1414
|
+
const where = transformWhereClause({
|
|
1415
|
+
model: unsafeModel,
|
|
1416
|
+
where: unsafeWhere
|
|
1417
|
+
});
|
|
1418
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1419
|
+
debugLog({ method: "count" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`, `${formatMethod("count")}:`, {
|
|
1420
|
+
model,
|
|
1421
|
+
where
|
|
1422
|
+
});
|
|
1423
|
+
const res = await adapterInstance.count({
|
|
1424
|
+
model,
|
|
1425
|
+
where
|
|
1426
|
+
});
|
|
1427
|
+
debugLog({ method: "count" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`, `${formatMethod("count")}:`, {
|
|
1428
|
+
model,
|
|
1429
|
+
data: res
|
|
1430
|
+
});
|
|
1431
|
+
return res;
|
|
1432
|
+
},
|
|
1433
|
+
createSchema: adapterInstance.createSchema ? async (_, file) => {
|
|
1434
|
+
const tables = getAuthTables(options);
|
|
1435
|
+
if (options.secondaryStorage && !options.session?.storeSessionInDatabase) delete tables.session;
|
|
1436
|
+
if (options.rateLimit && options.rateLimit.storage === "database" && (typeof options.rateLimit.enabled === "undefined" || options.rateLimit.enabled === true)) tables.ratelimit = {
|
|
1437
|
+
modelName: options.rateLimit.modelName ?? "ratelimit",
|
|
1438
|
+
fields: {
|
|
1439
|
+
key: {
|
|
1440
|
+
type: "string",
|
|
1441
|
+
unique: true,
|
|
1442
|
+
required: true,
|
|
1443
|
+
fieldName: options.rateLimit.fields?.key ?? "key"
|
|
1444
|
+
},
|
|
1445
|
+
count: {
|
|
1446
|
+
type: "number",
|
|
1447
|
+
required: true,
|
|
1448
|
+
fieldName: options.rateLimit.fields?.count ?? "count"
|
|
1449
|
+
},
|
|
1450
|
+
lastRequest: {
|
|
1451
|
+
type: "number",
|
|
1452
|
+
required: true,
|
|
1453
|
+
bigint: true,
|
|
1454
|
+
defaultValue: () => Date.now(),
|
|
1455
|
+
fieldName: options.rateLimit.fields?.lastRequest ?? "lastRequest"
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
return adapterInstance.createSchema({
|
|
1460
|
+
file,
|
|
1461
|
+
tables
|
|
1462
|
+
});
|
|
1463
|
+
} : void 0,
|
|
1464
|
+
options: {
|
|
1465
|
+
adapterConfig: config,
|
|
1466
|
+
...adapterInstance.options ?? {}
|
|
1467
|
+
},
|
|
1468
|
+
id: config.adapterId,
|
|
1469
|
+
...config.debugLogs?.isRunningAdapterTests ? { adapterTestDebugLogs: {
|
|
1470
|
+
resetDebugLogs() {
|
|
1471
|
+
debugLogs = debugLogs.filter((log) => log.instance !== uniqueAdapterFactoryInstanceId);
|
|
1472
|
+
},
|
|
1473
|
+
printDebugLogs() {
|
|
1474
|
+
const separator = `─`.repeat(80);
|
|
1475
|
+
const logs = debugLogs.filter((log$1) => log$1.instance === uniqueAdapterFactoryInstanceId);
|
|
1476
|
+
if (logs.length === 0) return;
|
|
1477
|
+
let log = logs.reverse().map((log$1) => {
|
|
1478
|
+
log$1.args[0] = `\n${log$1.args[0]}`;
|
|
1479
|
+
return [...log$1.args, "\n"];
|
|
1480
|
+
}).reduce((prev, curr) => {
|
|
1481
|
+
return [...curr, ...prev];
|
|
1482
|
+
}, [`\n${separator}`]);
|
|
1483
|
+
console.log(...log);
|
|
1484
|
+
}
|
|
1485
|
+
} } : {}
|
|
1486
|
+
};
|
|
1487
|
+
return adapter;
|
|
1488
|
+
};
|
|
1489
|
+
function formatTransactionId(transactionId$1) {
|
|
1490
|
+
if (getColorDepth() < 8) return `#${transactionId$1}`;
|
|
1491
|
+
return `${TTY_COLORS.fg.magenta}#${transactionId$1}${TTY_COLORS.reset}`;
|
|
1492
|
+
}
|
|
1493
|
+
function formatStep(step, total) {
|
|
1494
|
+
return `${TTY_COLORS.bg.black}${TTY_COLORS.fg.yellow}[${step}/${total}]${TTY_COLORS.reset}`;
|
|
1495
|
+
}
|
|
1496
|
+
function formatMethod(method) {
|
|
1497
|
+
return `${TTY_COLORS.bright}${method}${TTY_COLORS.reset}`;
|
|
1498
|
+
}
|
|
1499
|
+
function formatAction(action) {
|
|
1500
|
+
return `${TTY_COLORS.dim}(${action})${TTY_COLORS.reset}`;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
//#endregion
|
|
1504
|
+
export { isTest as _, BetterAuthError as a, getAuthTables as b, safeJSONParse as c, createLogger as d, env as f, isProduction as g, isDevelopment as h, BASE_ERROR_CODES as i, createRandomStringGenerator as l, getEnvVar as m, initGetFieldName as n, defineErrorCodes as o, getBooleanEnvVar as p, initGetModelName as r, generateId as s, createAdapterFactory as t, ENV as u, logger as v, shouldPublishLog as y };
|