create-croissant 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/apps/web/package.json +2 -0
- package/template/apps/web/src/components/login-form.tsx +95 -48
- package/template/apps/web/src/components/signup-form.tsx +149 -79
- package/template/apps/web/src/routes/__root.tsx +17 -12
- package/template/apps/web/src/routes/client-orpc-auth.tsx +8 -20
- package/template/apps/web/src/routes/client-orpc.tsx +203 -108
- package/template/apps/web/src/routes/ssr-orpc.tsx +169 -96
- package/template/package.json +3 -1
- package/template/apps/web/node_modules/@better-auth/core/LICENSE.md +0 -20
- package/template/apps/web/node_modules/@better-auth/core/README.md +0 -17
- package/template/apps/web/node_modules/@better-auth/core/dist/api/index.d.mts +0 -278
- package/template/apps/web/node_modules/@better-auth/core/dist/api/index.mjs +0 -56
- package/template/apps/web/node_modules/@better-auth/core/dist/async_hooks/index.d.mts +0 -6
- package/template/apps/web/node_modules/@better-auth/core/dist/async_hooks/index.mjs +0 -20
- package/template/apps/web/node_modules/@better-auth/core/dist/async_hooks/pure.index.d.mts +0 -6
- package/template/apps/web/node_modules/@better-auth/core/dist/async_hooks/pure.index.mjs +0 -33
- package/template/apps/web/node_modules/@better-auth/core/dist/context/endpoint-context.d.mts +0 -18
- package/template/apps/web/node_modules/@better-auth/core/dist/context/endpoint-context.mjs +0 -29
- package/template/apps/web/node_modules/@better-auth/core/dist/context/global.d.mts +0 -6
- package/template/apps/web/node_modules/@better-auth/core/dist/context/global.mjs +0 -36
- package/template/apps/web/node_modules/@better-auth/core/dist/context/index.d.mts +0 -5
- package/template/apps/web/node_modules/@better-auth/core/dist/context/index.mjs +0 -5
- package/template/apps/web/node_modules/@better-auth/core/dist/context/request-state.d.mts +0 -27
- package/template/apps/web/node_modules/@better-auth/core/dist/context/request-state.mjs +0 -47
- package/template/apps/web/node_modules/@better-auth/core/dist/context/transaction.d.mts +0 -24
- package/template/apps/web/node_modules/@better-auth/core/dist/context/transaction.mjs +0 -93
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/factory.d.mts +0 -17
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/factory.mjs +0 -754
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-default-field-name.d.mts +0 -18
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-default-field-name.mjs +0 -36
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-default-model-name.d.mts +0 -12
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-default-model-name.mjs +0 -30
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-field-attributes.d.mts +0 -26
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-field-attributes.mjs +0 -37
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-field-name.d.mts +0 -18
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-field-name.mjs +0 -31
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-id-field.d.mts +0 -36
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-id-field.mjs +0 -64
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-model-name.d.mts +0 -12
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/get-model-name.mjs +0 -21
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/index.d.mts +0 -525
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/index.mjs +0 -24
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/types.d.mts +0 -105
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/utils.d.mts +0 -7
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/utils.mjs +0 -37
- package/template/apps/web/node_modules/@better-auth/core/dist/db/get-tables.d.mts +0 -6
- package/template/apps/web/node_modules/@better-auth/core/dist/db/get-tables.mjs +0 -265
- package/template/apps/web/node_modules/@better-auth/core/dist/db/index.d.mts +0 -10
- package/template/apps/web/node_modules/@better-auth/core/dist/db/index.mjs +0 -8
- package/template/apps/web/node_modules/@better-auth/core/dist/db/plugin.d.mts +0 -12
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/account.d.mts +0 -28
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/account.mjs +0 -17
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/rate-limit.d.mts +0 -18
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/rate-limit.mjs +0 -9
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/session.d.mts +0 -23
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/session.mjs +0 -12
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/shared.d.mts +0 -10
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/shared.mjs +0 -9
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/user.d.mts +0 -22
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/user.mjs +0 -11
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/verification.d.mts +0 -21
- package/template/apps/web/node_modules/@better-auth/core/dist/db/schema/verification.mjs +0 -10
- package/template/apps/web/node_modules/@better-auth/core/dist/db/type.d.mts +0 -167
- package/template/apps/web/node_modules/@better-auth/core/dist/env/color-depth.d.mts +0 -4
- package/template/apps/web/node_modules/@better-auth/core/dist/env/color-depth.mjs +0 -86
- package/template/apps/web/node_modules/@better-auth/core/dist/env/env-impl.d.mts +0 -32
- package/template/apps/web/node_modules/@better-auth/core/dist/env/env-impl.mjs +0 -81
- package/template/apps/web/node_modules/@better-auth/core/dist/env/index.d.mts +0 -4
- package/template/apps/web/node_modules/@better-auth/core/dist/env/index.mjs +0 -4
- package/template/apps/web/node_modules/@better-auth/core/dist/env/logger.d.mts +0 -48
- package/template/apps/web/node_modules/@better-auth/core/dist/env/logger.mjs +0 -79
- package/template/apps/web/node_modules/@better-auth/core/dist/error/codes.d.mts +0 -68
- package/template/apps/web/node_modules/@better-auth/core/dist/error/codes.mjs +0 -54
- package/template/apps/web/node_modules/@better-auth/core/dist/error/index.d.mts +0 -19
- package/template/apps/web/node_modules/@better-auth/core/dist/error/index.mjs +0 -27
- package/template/apps/web/node_modules/@better-auth/core/dist/index.d.mts +0 -9
- package/template/apps/web/node_modules/@better-auth/core/dist/index.mjs +0 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/api.mjs +0 -12
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/attributes.d.mts +0 -11
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/attributes.mjs +0 -10
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/index.d.mts +0 -3
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/index.mjs +0 -3
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/noop.mjs +0 -42
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/pure.index.d.mts +0 -7
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/pure.index.mjs +0 -7
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/tracer.d.mts +0 -13
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/tracer.mjs +0 -53
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/client-credentials-token.d.mts +0 -56
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/client-credentials-token.mjs +0 -64
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/create-authorization-url.d.mts +0 -44
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/create-authorization-url.mjs +0 -41
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/index.d.mts +0 -8
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/index.mjs +0 -7
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/oauth-provider.d.mts +0 -192
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/refresh-access-token.d.mts +0 -54
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/refresh-access-token.mjs +0 -73
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/utils.d.mts +0 -16
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/utils.mjs +0 -37
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/validate-authorization-code.d.mts +0 -85
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/validate-authorization-code.mjs +0 -79
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/verify.d.mts +0 -42
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/verify.mjs +0 -92
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/apple.d.mts +0 -126
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/apple.mjs +0 -107
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/atlassian.d.mts +0 -70
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/atlassian.mjs +0 -80
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/cognito.d.mts +0 -85
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/cognito.mjs +0 -162
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/discord.d.mts +0 -124
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/discord.mjs +0 -62
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/dropbox.d.mts +0 -69
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/dropbox.mjs +0 -72
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/facebook.d.mts +0 -79
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/facebook.mjs +0 -124
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/figma.d.mts +0 -61
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/figma.mjs +0 -83
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/github.d.mts +0 -102
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/github.mjs +0 -92
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/gitlab.d.mts +0 -123
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/gitlab.mjs +0 -79
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/google.d.mts +0 -97
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/google.mjs +0 -109
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/huggingface.d.mts +0 -83
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/huggingface.mjs +0 -73
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/index.d.mts +0 -1834
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/index.mjs +0 -78
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/kakao.d.mts +0 -161
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/kakao.mjs +0 -70
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/kick.d.mts +0 -73
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/kick.mjs +0 -68
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/line.d.mts +0 -105
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/line.mjs +0 -110
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/linear.d.mts +0 -68
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/linear.mjs +0 -85
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/linkedin.d.mts +0 -67
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/linkedin.mjs +0 -73
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/microsoft-entra-id.d.mts +0 -174
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/microsoft-entra-id.mjs +0 -140
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/naver.d.mts +0 -92
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/naver.mjs +0 -65
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/notion.d.mts +0 -64
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/notion.mjs +0 -72
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/paybin.d.mts +0 -71
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/paybin.mjs +0 -81
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/paypal.d.mts +0 -129
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/paypal.mjs +0 -140
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/polar.d.mts +0 -74
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/polar.mjs +0 -71
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/railway.d.mts +0 -65
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/railway.mjs +0 -74
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/reddit.d.mts +0 -62
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/reddit.mjs +0 -80
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/roblox.d.mts +0 -70
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/roblox.mjs +0 -57
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/salesforce.d.mts +0 -79
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/salesforce.mjs +0 -87
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/slack.d.mts +0 -83
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/slack.mjs +0 -66
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/spotify.d.mts +0 -63
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/spotify.mjs +0 -69
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/tiktok.d.mts +0 -168
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/tiktok.mjs +0 -60
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/twitch.d.mts +0 -79
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/twitch.mjs +0 -75
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/twitter.d.mts +0 -126
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/twitter.mjs +0 -85
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/vercel.d.mts +0 -62
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/vercel.mjs +0 -58
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/vk.d.mts +0 -70
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/vk.mjs +0 -81
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/wechat.d.mts +0 -113
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/wechat.mjs +0 -81
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/zoom.d.mts +0 -163
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/zoom.mjs +0 -69
- package/template/apps/web/node_modules/@better-auth/core/dist/types/context.d.mts +0 -277
- package/template/apps/web/node_modules/@better-auth/core/dist/types/cookie.d.mts +0 -15
- package/template/apps/web/node_modules/@better-auth/core/dist/types/helper.d.mts +0 -10
- package/template/apps/web/node_modules/@better-auth/core/dist/types/index.d.mts +0 -9
- package/template/apps/web/node_modules/@better-auth/core/dist/types/init-options.d.mts +0 -1358
- package/template/apps/web/node_modules/@better-auth/core/dist/types/plugin-client.d.mts +0 -113
- package/template/apps/web/node_modules/@better-auth/core/dist/types/plugin.d.mts +0 -124
- package/template/apps/web/node_modules/@better-auth/core/dist/types/secret.d.mts +0 -11
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/async.d.mts +0 -22
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/async.mjs +0 -32
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/db.d.mts +0 -9
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/db.mjs +0 -15
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/deprecate.d.mts +0 -9
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/deprecate.mjs +0 -16
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/error-codes.d.mts +0 -13
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/error-codes.mjs +0 -10
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/fetch-metadata.d.mts +0 -4
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/fetch-metadata.mjs +0 -6
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/host.d.mts +0 -147
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/host.mjs +0 -291
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/id.d.mts +0 -4
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/id.mjs +0 -7
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/ip.d.mts +0 -54
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/ip.mjs +0 -116
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/is-api-error.d.mts +0 -6
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/is-api-error.mjs +0 -8
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/json.d.mts +0 -4
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/json.mjs +0 -41
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/string.d.mts +0 -4
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/string.mjs +0 -6
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/url.d.mts +0 -20
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/url.mjs +0 -31
- package/template/apps/web/node_modules/@better-auth/core/package.json +0 -193
- package/template/apps/web/node_modules/@better-auth/core/src/api/index.ts +0 -140
- package/template/apps/web/node_modules/@better-auth/core/src/async_hooks/index.ts +0 -40
- package/template/apps/web/node_modules/@better-auth/core/src/async_hooks/pure.index.ts +0 -46
- package/template/apps/web/node_modules/@better-auth/core/src/context/endpoint-context.ts +0 -50
- package/template/apps/web/node_modules/@better-auth/core/src/context/global.ts +0 -57
- package/template/apps/web/node_modules/@better-auth/core/src/context/index.ts +0 -23
- package/template/apps/web/node_modules/@better-auth/core/src/context/request-state.ts +0 -91
- package/template/apps/web/node_modules/@better-auth/core/src/context/transaction.ts +0 -136
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/factory.ts +0 -1440
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/get-default-field-name.ts +0 -59
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/get-default-model-name.ts +0 -51
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/get-field-attributes.ts +0 -62
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/get-field-name.ts +0 -43
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/get-id-field.ts +0 -150
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/get-model-name.ts +0 -36
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/index.ts +0 -567
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/types.ts +0 -132
- package/template/apps/web/node_modules/@better-auth/core/src/db/adapter/utils.ts +0 -61
- package/template/apps/web/node_modules/@better-auth/core/src/db/get-tables.ts +0 -296
- package/template/apps/web/node_modules/@better-auth/core/src/db/index.ts +0 -43
- package/template/apps/web/node_modules/@better-auth/core/src/db/plugin.ts +0 -11
- package/template/apps/web/node_modules/@better-auth/core/src/db/schema/account.ts +0 -47
- package/template/apps/web/node_modules/@better-auth/core/src/db/schema/rate-limit.ts +0 -36
- package/template/apps/web/node_modules/@better-auth/core/src/db/schema/session.ts +0 -29
- package/template/apps/web/node_modules/@better-auth/core/src/db/schema/shared.ts +0 -7
- package/template/apps/web/node_modules/@better-auth/core/src/db/schema/user.ts +0 -28
- package/template/apps/web/node_modules/@better-auth/core/src/db/schema/verification.ts +0 -28
- package/template/apps/web/node_modules/@better-auth/core/src/db/type.ts +0 -333
- package/template/apps/web/node_modules/@better-auth/core/src/env/color-depth.ts +0 -172
- package/template/apps/web/node_modules/@better-auth/core/src/env/env-impl.ts +0 -124
- package/template/apps/web/node_modules/@better-auth/core/src/env/index.ts +0 -23
- package/template/apps/web/node_modules/@better-auth/core/src/env/logger.ts +0 -145
- package/template/apps/web/node_modules/@better-auth/core/src/error/codes.ts +0 -71
- package/template/apps/web/node_modules/@better-auth/core/src/error/index.ts +0 -35
- package/template/apps/web/node_modules/@better-auth/core/src/index.ts +0 -1
- package/template/apps/web/node_modules/@better-auth/core/src/instrumentation/api.ts +0 -17
- package/template/apps/web/node_modules/@better-auth/core/src/instrumentation/attributes.ts +0 -22
- package/template/apps/web/node_modules/@better-auth/core/src/instrumentation/index.ts +0 -2
- package/template/apps/web/node_modules/@better-auth/core/src/instrumentation/noop.ts +0 -74
- package/template/apps/web/node_modules/@better-auth/core/src/instrumentation/pure.index.ts +0 -31
- package/template/apps/web/node_modules/@better-auth/core/src/instrumentation/tracer.ts +0 -95
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/client-credentials-token.ts +0 -126
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/create-authorization-url.ts +0 -89
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/index.ts +0 -33
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/oauth-provider.ts +0 -222
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/refresh-access-token.ts +0 -157
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/utils.ts +0 -51
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/validate-authorization-code.ts +0 -180
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/verify.ts +0 -221
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/apple.ts +0 -231
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/atlassian.ts +0 -133
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/cognito.ts +0 -281
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/discord.ts +0 -170
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/dropbox.ts +0 -112
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/facebook.ts +0 -215
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/figma.ts +0 -118
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/github.ts +0 -184
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/gitlab.ts +0 -155
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/google.ts +0 -204
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/huggingface.ts +0 -119
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/index.ts +0 -132
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/kakao.ts +0 -179
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/kick.ts +0 -109
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/line.ts +0 -169
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/linear.ts +0 -121
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/linkedin.ts +0 -110
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/microsoft-entra-id.ts +0 -352
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/naver.ts +0 -113
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/notion.ts +0 -108
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/paybin.ts +0 -118
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/paypal.ts +0 -263
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/polar.ts +0 -111
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/railway.ts +0 -100
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/reddit.ts +0 -122
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/roblox.ts +0 -112
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/salesforce.ts +0 -159
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/slack.ts +0 -112
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/spotify.ts +0 -94
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/tiktok.ts +0 -211
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/twitch.ts +0 -112
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/twitter.ts +0 -199
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/vercel.ts +0 -87
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/vk.ts +0 -125
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/wechat.ts +0 -213
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/zoom.ts +0 -230
- package/template/apps/web/node_modules/@better-auth/core/src/types/context.ts +0 -415
- package/template/apps/web/node_modules/@better-auth/core/src/types/cookie.ts +0 -10
- package/template/apps/web/node_modules/@better-auth/core/src/types/helper.ts +0 -27
- package/template/apps/web/node_modules/@better-auth/core/src/types/index.ts +0 -40
- package/template/apps/web/node_modules/@better-auth/core/src/types/init-options.ts +0 -1610
- package/template/apps/web/node_modules/@better-auth/core/src/types/plugin-client.ts +0 -129
- package/template/apps/web/node_modules/@better-auth/core/src/types/plugin.ts +0 -163
- package/template/apps/web/node_modules/@better-auth/core/src/types/secret.ts +0 -8
- package/template/apps/web/node_modules/@better-auth/core/src/utils/async.ts +0 -53
- package/template/apps/web/node_modules/@better-auth/core/src/utils/db.ts +0 -20
- package/template/apps/web/node_modules/@better-auth/core/src/utils/deprecate.ts +0 -21
- package/template/apps/web/node_modules/@better-auth/core/src/utils/error-codes.ts +0 -68
- package/template/apps/web/node_modules/@better-auth/core/src/utils/fetch-metadata.ts +0 -3
- package/template/apps/web/node_modules/@better-auth/core/src/utils/host.ts +0 -401
- package/template/apps/web/node_modules/@better-auth/core/src/utils/id.ts +0 -5
- package/template/apps/web/node_modules/@better-auth/core/src/utils/ip.ts +0 -211
- package/template/apps/web/node_modules/@better-auth/core/src/utils/is-api-error.ts +0 -10
- package/template/apps/web/node_modules/@better-auth/core/src/utils/json.ts +0 -56
- package/template/apps/web/node_modules/@better-auth/core/src/utils/string.ts +0 -3
- package/template/apps/web/node_modules/@better-auth/core/src/utils/url.ts +0 -43
- package/template/apps/web/node_modules/@better-auth/utils/README.md +0 -384
- package/template/apps/web/node_modules/@better-auth/utils/dist/base32.cjs +0 -104
- package/template/apps/web/node_modules/@better-auth/utils/dist/base32.d.cts +0 -44
- package/template/apps/web/node_modules/@better-auth/utils/dist/base32.d.mts +0 -44
- package/template/apps/web/node_modules/@better-auth/utils/dist/base32.d.ts +0 -44
- package/template/apps/web/node_modules/@better-auth/utils/dist/base32.mjs +0 -101
- package/template/apps/web/node_modules/@better-auth/utils/dist/base64.cjs +0 -80
- package/template/apps/web/node_modules/@better-auth/utils/dist/base64.d.cts +0 -16
- package/template/apps/web/node_modules/@better-auth/utils/dist/base64.d.mts +0 -16
- package/template/apps/web/node_modules/@better-auth/utils/dist/base64.d.ts +0 -16
- package/template/apps/web/node_modules/@better-auth/utils/dist/base64.mjs +0 -77
- package/template/apps/web/node_modules/@better-auth/utils/dist/binary.cjs +0 -16
- package/template/apps/web/node_modules/@better-auth/utils/dist/binary.d.cts +0 -8
- package/template/apps/web/node_modules/@better-auth/utils/dist/binary.d.mts +0 -8
- package/template/apps/web/node_modules/@better-auth/utils/dist/binary.d.ts +0 -8
- package/template/apps/web/node_modules/@better-auth/utils/dist/binary.mjs +0 -14
- package/template/apps/web/node_modules/@better-auth/utils/dist/ecdsa.cjs +0 -90
- package/template/apps/web/node_modules/@better-auth/utils/dist/ecdsa.d.cts +0 -19
- package/template/apps/web/node_modules/@better-auth/utils/dist/ecdsa.d.mts +0 -19
- package/template/apps/web/node_modules/@better-auth/utils/dist/ecdsa.d.ts +0 -19
- package/template/apps/web/node_modules/@better-auth/utils/dist/ecdsa.mjs +0 -88
- package/template/apps/web/node_modules/@better-auth/utils/dist/hash.cjs +0 -31
- package/template/apps/web/node_modules/@better-auth/utils/dist/hash.d.cts +0 -7
- package/template/apps/web/node_modules/@better-auth/utils/dist/hash.d.mts +0 -7
- package/template/apps/web/node_modules/@better-auth/utils/dist/hash.d.ts +0 -7
- package/template/apps/web/node_modules/@better-auth/utils/dist/hash.mjs +0 -29
- package/template/apps/web/node_modules/@better-auth/utils/dist/hex.cjs +0 -40
- package/template/apps/web/node_modules/@better-auth/utils/dist/hex.d.cts +0 -8
- package/template/apps/web/node_modules/@better-auth/utils/dist/hex.d.mts +0 -8
- package/template/apps/web/node_modules/@better-auth/utils/dist/hex.d.ts +0 -8
- package/template/apps/web/node_modules/@better-auth/utils/dist/hex.mjs +0 -38
- package/template/apps/web/node_modules/@better-auth/utils/dist/hmac.cjs +0 -58
- package/template/apps/web/node_modules/@better-auth/utils/dist/hmac.d.cts +0 -9
- package/template/apps/web/node_modules/@better-auth/utils/dist/hmac.d.mts +0 -9
- package/template/apps/web/node_modules/@better-auth/utils/dist/hmac.d.ts +0 -9
- package/template/apps/web/node_modules/@better-auth/utils/dist/hmac.mjs +0 -56
- package/template/apps/web/node_modules/@better-auth/utils/dist/index.cjs +0 -10
- package/template/apps/web/node_modules/@better-auth/utils/dist/index.d.cts +0 -3
- package/template/apps/web/node_modules/@better-auth/utils/dist/index.d.mts +0 -3
- package/template/apps/web/node_modules/@better-auth/utils/dist/index.d.ts +0 -3
- package/template/apps/web/node_modules/@better-auth/utils/dist/index.mjs +0 -8
- package/template/apps/web/node_modules/@better-auth/utils/dist/otp.cjs +0 -90
- package/template/apps/web/node_modules/@better-auth/utils/dist/otp.d.cts +0 -13
- package/template/apps/web/node_modules/@better-auth/utils/dist/otp.d.mts +0 -13
- package/template/apps/web/node_modules/@better-auth/utils/dist/otp.d.ts +0 -13
- package/template/apps/web/node_modules/@better-auth/utils/dist/otp.mjs +0 -88
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.cjs +0 -36
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.d.cts +0 -4
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.d.mts +0 -4
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.d.ts +0 -4
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.mjs +0 -33
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.node.cjs +0 -47
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.node.d.cts +0 -4
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.node.d.mts +0 -4
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.node.d.ts +0 -4
- package/template/apps/web/node_modules/@better-auth/utils/dist/password.node.mjs +0 -44
- package/template/apps/web/node_modules/@better-auth/utils/dist/random.cjs +0 -55
- package/template/apps/web/node_modules/@better-auth/utils/dist/random.d.cts +0 -4
- package/template/apps/web/node_modules/@better-auth/utils/dist/random.d.mts +0 -4
- package/template/apps/web/node_modules/@better-auth/utils/dist/random.d.ts +0 -4
- package/template/apps/web/node_modules/@better-auth/utils/dist/random.mjs +0 -53
- package/template/apps/web/node_modules/@better-auth/utils/dist/rsa.cjs +0 -76
- package/template/apps/web/node_modules/@better-auth/utils/dist/rsa.d.cts +0 -16
- package/template/apps/web/node_modules/@better-auth/utils/dist/rsa.d.mts +0 -16
- package/template/apps/web/node_modules/@better-auth/utils/dist/rsa.d.ts +0 -16
- package/template/apps/web/node_modules/@better-auth/utils/dist/rsa.mjs +0 -74
- package/template/apps/web/node_modules/@better-auth/utils/dist/shared/utils.ecd028f7.d.cts +0 -22
- package/template/apps/web/node_modules/@better-auth/utils/dist/shared/utils.ecd028f7.d.mts +0 -22
- package/template/apps/web/node_modules/@better-auth/utils/dist/shared/utils.ecd028f7.d.ts +0 -22
- package/template/apps/web/node_modules/@better-auth/utils/package.json +0 -95
- package/template/apps/web/node_modules/better-call/LICENSE +0 -21
- package/template/apps/web/node_modules/better-call/dist/_virtual/_rolldown/runtime.cjs +0 -29
- package/template/apps/web/node_modules/better-call/dist/adapters/node/request.cjs +0 -181
- package/template/apps/web/node_modules/better-call/dist/adapters/node/request.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/adapters/node/request.d.cts +0 -16
- package/template/apps/web/node_modules/better-call/dist/adapters/node/request.d.mts +0 -16
- package/template/apps/web/node_modules/better-call/dist/adapters/node/request.mjs +0 -178
- package/template/apps/web/node_modules/better-call/dist/adapters/node/request.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/client.cjs +0 -23
- package/template/apps/web/node_modules/better-call/dist/client.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/client.d.cts +0 -53
- package/template/apps/web/node_modules/better-call/dist/client.d.mts +0 -53
- package/template/apps/web/node_modules/better-call/dist/client.mjs +0 -14
- package/template/apps/web/node_modules/better-call/dist/client.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/context.cjs +0 -103
- package/template/apps/web/node_modules/better-call/dist/context.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/context.d.cts +0 -341
- package/template/apps/web/node_modules/better-call/dist/context.d.mts +0 -341
- package/template/apps/web/node_modules/better-call/dist/context.mjs +0 -103
- package/template/apps/web/node_modules/better-call/dist/context.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/cookies.cjs +0 -87
- package/template/apps/web/node_modules/better-call/dist/cookies.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/cookies.d.cts +0 -103
- package/template/apps/web/node_modules/better-call/dist/cookies.d.mts +0 -103
- package/template/apps/web/node_modules/better-call/dist/cookies.mjs +0 -84
- package/template/apps/web/node_modules/better-call/dist/cookies.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/crypto.cjs +0 -39
- package/template/apps/web/node_modules/better-call/dist/crypto.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/crypto.mjs +0 -36
- package/template/apps/web/node_modules/better-call/dist/crypto.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/endpoint.cjs +0 -70
- package/template/apps/web/node_modules/better-call/dist/endpoint.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/endpoint.d.cts +0 -475
- package/template/apps/web/node_modules/better-call/dist/endpoint.d.mts +0 -475
- package/template/apps/web/node_modules/better-call/dist/endpoint.mjs +0 -70
- package/template/apps/web/node_modules/better-call/dist/endpoint.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/error.cjs +0 -141
- package/template/apps/web/node_modules/better-call/dist/error.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/error.d.cts +0 -103
- package/template/apps/web/node_modules/better-call/dist/error.d.mts +0 -103
- package/template/apps/web/node_modules/better-call/dist/error.mjs +0 -133
- package/template/apps/web/node_modules/better-call/dist/error.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/helper.d.cts +0 -12
- package/template/apps/web/node_modules/better-call/dist/helper.d.mts +0 -12
- package/template/apps/web/node_modules/better-call/dist/index.cjs +0 -28
- package/template/apps/web/node_modules/better-call/dist/index.d.cts +0 -11
- package/template/apps/web/node_modules/better-call/dist/index.d.mts +0 -11
- package/template/apps/web/node_modules/better-call/dist/index.mjs +0 -10
- package/template/apps/web/node_modules/better-call/dist/middleware.cjs +0 -52
- package/template/apps/web/node_modules/better-call/dist/middleware.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/middleware.d.cts +0 -123
- package/template/apps/web/node_modules/better-call/dist/middleware.d.mts +0 -123
- package/template/apps/web/node_modules/better-call/dist/middleware.mjs +0 -52
- package/template/apps/web/node_modules/better-call/dist/middleware.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/node.cjs +0 -18
- package/template/apps/web/node_modules/better-call/dist/node.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/node.d.cts +0 -9
- package/template/apps/web/node_modules/better-call/dist/node.d.mts +0 -9
- package/template/apps/web/node_modules/better-call/dist/node.mjs +0 -15
- package/template/apps/web/node_modules/better-call/dist/node.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/openapi.cjs +0 -191
- package/template/apps/web/node_modules/better-call/dist/openapi.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/openapi.d.cts +0 -113
- package/template/apps/web/node_modules/better-call/dist/openapi.d.mts +0 -113
- package/template/apps/web/node_modules/better-call/dist/openapi.mjs +0 -189
- package/template/apps/web/node_modules/better-call/dist/openapi.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/router.cjs +0 -118
- package/template/apps/web/node_modules/better-call/dist/router.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/router.d.cts +0 -103
- package/template/apps/web/node_modules/better-call/dist/router.d.mts +0 -103
- package/template/apps/web/node_modules/better-call/dist/router.mjs +0 -117
- package/template/apps/web/node_modules/better-call/dist/router.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/standard-schema.d.cts +0 -59
- package/template/apps/web/node_modules/better-call/dist/standard-schema.d.mts +0 -59
- package/template/apps/web/node_modules/better-call/dist/to-response.cjs +0 -153
- package/template/apps/web/node_modules/better-call/dist/to-response.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/to-response.d.cts +0 -12
- package/template/apps/web/node_modules/better-call/dist/to-response.d.mts +0 -12
- package/template/apps/web/node_modules/better-call/dist/to-response.mjs +0 -153
- package/template/apps/web/node_modules/better-call/dist/to-response.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/utils.cjs +0 -86
- package/template/apps/web/node_modules/better-call/dist/utils.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/utils.mjs +0 -82
- package/template/apps/web/node_modules/better-call/dist/utils.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/validator.cjs +0 -58
- package/template/apps/web/node_modules/better-call/dist/validator.cjs.map +0 -1
- package/template/apps/web/node_modules/better-call/dist/validator.mjs +0 -57
- package/template/apps/web/node_modules/better-call/dist/validator.mjs.map +0 -1
- package/template/apps/web/node_modules/better-call/package.json +0 -96
- package/template/apps/web/node_modules/set-cookie-parser/LICENSE +0 -21
- package/template/apps/web/node_modules/set-cookie-parser/README.md +0 -169
- package/template/apps/web/node_modules/set-cookie-parser/dist/.eslintrc.cjs +0 -16
- package/template/apps/web/node_modules/set-cookie-parser/dist/set-cookie.cjs +0 -260
- package/template/apps/web/node_modules/set-cookie-parser/lib/set-cookie.d.ts +0 -119
- package/template/apps/web/node_modules/set-cookie-parser/lib/set-cookie.js +0 -265
- package/template/apps/web/node_modules/set-cookie-parser/package.json +0 -61
|
@@ -1,1440 +0,0 @@
|
|
|
1
|
-
import { createLogger, getColorDepth, TTY_COLORS } from "../../env";
|
|
2
|
-
import { BetterAuthError } from "../../error";
|
|
3
|
-
import {
|
|
4
|
-
ATTR_DB_COLLECTION_NAME,
|
|
5
|
-
ATTR_DB_OPERATION_NAME,
|
|
6
|
-
withSpan,
|
|
7
|
-
} from "../../instrumentation";
|
|
8
|
-
import type { BetterAuthOptions } from "../../types";
|
|
9
|
-
import { safeJSONParse } from "../../utils/json";
|
|
10
|
-
import { getAuthTables } from "../get-tables";
|
|
11
|
-
import { initGetDefaultFieldName } from "./get-default-field-name";
|
|
12
|
-
import { initGetDefaultModelName } from "./get-default-model-name";
|
|
13
|
-
import { initGetFieldAttributes } from "./get-field-attributes";
|
|
14
|
-
import { initGetFieldName } from "./get-field-name";
|
|
15
|
-
import { initGetIdField } from "./get-id-field";
|
|
16
|
-
import { initGetModelName } from "./get-model-name";
|
|
17
|
-
import type {
|
|
18
|
-
CleanedWhere,
|
|
19
|
-
DBAdapter,
|
|
20
|
-
DBTransactionAdapter,
|
|
21
|
-
JoinConfig,
|
|
22
|
-
JoinOption,
|
|
23
|
-
Where,
|
|
24
|
-
} from "./index";
|
|
25
|
-
import type {
|
|
26
|
-
AdapterFactoryConfig,
|
|
27
|
-
AdapterFactoryOptions,
|
|
28
|
-
AdapterTestDebugLogs,
|
|
29
|
-
} from "./types";
|
|
30
|
-
import { withApplyDefault } from "./utils";
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
initGetDefaultModelName,
|
|
34
|
-
initGetDefaultFieldName,
|
|
35
|
-
initGetModelName,
|
|
36
|
-
initGetFieldName,
|
|
37
|
-
initGetFieldAttributes,
|
|
38
|
-
initGetIdField,
|
|
39
|
-
};
|
|
40
|
-
export * from "./types";
|
|
41
|
-
|
|
42
|
-
let debugLogs: { instance: string; args: any[] }[] = [];
|
|
43
|
-
let transactionId = -1;
|
|
44
|
-
|
|
45
|
-
const createAsIsTransaction =
|
|
46
|
-
<Options extends BetterAuthOptions>(adapter: DBAdapter<Options>) =>
|
|
47
|
-
<R>(fn: (trx: DBTransactionAdapter<Options>) => Promise<R>) =>
|
|
48
|
-
fn(adapter);
|
|
49
|
-
|
|
50
|
-
export type AdapterFactory<Options extends BetterAuthOptions> = (
|
|
51
|
-
options: Options,
|
|
52
|
-
) => DBAdapter<Options>;
|
|
53
|
-
|
|
54
|
-
export const createAdapterFactory =
|
|
55
|
-
<Options extends BetterAuthOptions>({
|
|
56
|
-
adapter: customAdapter,
|
|
57
|
-
config: cfg,
|
|
58
|
-
}: AdapterFactoryOptions): AdapterFactory<Options> =>
|
|
59
|
-
(options: Options): DBAdapter<Options> => {
|
|
60
|
-
const uniqueAdapterFactoryInstanceId = Math.random()
|
|
61
|
-
.toString(36)
|
|
62
|
-
.substring(2, 15);
|
|
63
|
-
|
|
64
|
-
const config = {
|
|
65
|
-
...cfg,
|
|
66
|
-
supportsBooleans: cfg.supportsBooleans ?? true,
|
|
67
|
-
supportsDates: cfg.supportsDates ?? true,
|
|
68
|
-
supportsJSON: cfg.supportsJSON ?? false,
|
|
69
|
-
adapterName: cfg.adapterName ?? cfg.adapterId,
|
|
70
|
-
supportsNumericIds: cfg.supportsNumericIds ?? true,
|
|
71
|
-
supportsUUIDs: cfg.supportsUUIDs ?? false,
|
|
72
|
-
supportsArrays: cfg.supportsArrays ?? false,
|
|
73
|
-
transaction: cfg.transaction ?? false,
|
|
74
|
-
disableTransformInput: cfg.disableTransformInput ?? false,
|
|
75
|
-
disableTransformOutput: cfg.disableTransformOutput ?? false,
|
|
76
|
-
disableTransformJoin: cfg.disableTransformJoin ?? false,
|
|
77
|
-
} satisfies AdapterFactoryConfig;
|
|
78
|
-
|
|
79
|
-
const useNumberId = options.advanced?.database?.generateId === "serial";
|
|
80
|
-
if (useNumberId && config.supportsNumericIds === false) {
|
|
81
|
-
throw new BetterAuthError(
|
|
82
|
-
`[${config.adapterName}] Your database or database adapter does not support numeric ids. Please disable "useNumberId" in your config.`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// End-user's Better-Auth instance's schema
|
|
87
|
-
const schema = getAuthTables(options);
|
|
88
|
-
|
|
89
|
-
const debugLog = (...args: any[]) => {
|
|
90
|
-
if (config.debugLogs === true || typeof config.debugLogs === "object") {
|
|
91
|
-
const logger = createLogger({ level: "info" });
|
|
92
|
-
// If we're running adapter tests, we'll keep debug logs in memory, then print them out if a test fails.
|
|
93
|
-
if (
|
|
94
|
-
typeof config.debugLogs === "object" &&
|
|
95
|
-
"isRunningAdapterTests" in config.debugLogs
|
|
96
|
-
) {
|
|
97
|
-
if (config.debugLogs.isRunningAdapterTests) {
|
|
98
|
-
args.shift(); // Removes the {method: "..."} object from the args array.
|
|
99
|
-
debugLogs.push({ instance: uniqueAdapterFactoryInstanceId, args });
|
|
100
|
-
}
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
typeof config.debugLogs === "object" &&
|
|
106
|
-
config.debugLogs.logCondition &&
|
|
107
|
-
!config.debugLogs.logCondition?.()
|
|
108
|
-
) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (typeof args[0] === "object" && "method" in args[0]) {
|
|
113
|
-
const method = args.shift().method;
|
|
114
|
-
// Make sure the method is enabled in the config.
|
|
115
|
-
if (typeof config.debugLogs === "object") {
|
|
116
|
-
if (method === "create" && !config.debugLogs.create) {
|
|
117
|
-
return;
|
|
118
|
-
} else if (method === "update" && !config.debugLogs.update) {
|
|
119
|
-
return;
|
|
120
|
-
} else if (
|
|
121
|
-
method === "updateMany" &&
|
|
122
|
-
!config.debugLogs.updateMany
|
|
123
|
-
) {
|
|
124
|
-
return;
|
|
125
|
-
} else if (method === "findOne" && !config.debugLogs.findOne) {
|
|
126
|
-
return;
|
|
127
|
-
} else if (method === "findMany" && !config.debugLogs.findMany) {
|
|
128
|
-
return;
|
|
129
|
-
} else if (method === "delete" && !config.debugLogs.delete) {
|
|
130
|
-
return;
|
|
131
|
-
} else if (
|
|
132
|
-
method === "deleteMany" &&
|
|
133
|
-
!config.debugLogs.deleteMany
|
|
134
|
-
) {
|
|
135
|
-
return;
|
|
136
|
-
} else if (method === "count" && !config.debugLogs.count) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
logger.info(`[${config.adapterName}]`, ...args);
|
|
141
|
-
} else {
|
|
142
|
-
logger.info(`[${config.adapterName}]`, ...args);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const logger = createLogger(options.logger);
|
|
148
|
-
|
|
149
|
-
const getDefaultModelName = initGetDefaultModelName({
|
|
150
|
-
usePlural: config.usePlural,
|
|
151
|
-
schema,
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
const getDefaultFieldName = initGetDefaultFieldName({
|
|
155
|
-
usePlural: config.usePlural,
|
|
156
|
-
schema,
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
const getModelName = initGetModelName({
|
|
160
|
-
usePlural: config.usePlural,
|
|
161
|
-
schema,
|
|
162
|
-
});
|
|
163
|
-
const getFieldName = initGetFieldName({
|
|
164
|
-
schema,
|
|
165
|
-
usePlural: config.usePlural,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
const idField = initGetIdField({
|
|
169
|
-
schema,
|
|
170
|
-
options,
|
|
171
|
-
usePlural: config.usePlural,
|
|
172
|
-
disableIdGeneration: config.disableIdGeneration,
|
|
173
|
-
customIdGenerator: config.customIdGenerator,
|
|
174
|
-
supportsUUIDs: config.supportsUUIDs,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
const getFieldAttributes = initGetFieldAttributes({
|
|
178
|
-
schema,
|
|
179
|
-
options,
|
|
180
|
-
usePlural: config.usePlural,
|
|
181
|
-
disableIdGeneration: config.disableIdGeneration,
|
|
182
|
-
customIdGenerator: config.customIdGenerator,
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const transformInput = async (
|
|
186
|
-
data: Record<string, any>,
|
|
187
|
-
defaultModelName: string,
|
|
188
|
-
action: "create" | "update" | "findOne" | "findMany",
|
|
189
|
-
forceAllowId?: boolean,
|
|
190
|
-
) => {
|
|
191
|
-
const transformedData: Record<string, any> = {};
|
|
192
|
-
const fields = schema[defaultModelName]!.fields;
|
|
193
|
-
|
|
194
|
-
const newMappedKeys = config.mapKeysTransformInput ?? {};
|
|
195
|
-
const useNumberId = options.advanced?.database?.generateId === "serial";
|
|
196
|
-
fields.id = idField({
|
|
197
|
-
customModelName: defaultModelName,
|
|
198
|
-
forceAllowId: forceAllowId && "id" in data,
|
|
199
|
-
});
|
|
200
|
-
for (const field in fields) {
|
|
201
|
-
let value = data[field];
|
|
202
|
-
const fieldAttributes = fields[field];
|
|
203
|
-
|
|
204
|
-
const newFieldName: string =
|
|
205
|
-
newMappedKeys[field] || fields[field]!.fieldName || field;
|
|
206
|
-
if (
|
|
207
|
-
value === undefined &&
|
|
208
|
-
((fieldAttributes!.defaultValue === undefined &&
|
|
209
|
-
!fieldAttributes!.transform?.input &&
|
|
210
|
-
!(action === "update" && fieldAttributes!.onUpdate)) ||
|
|
211
|
-
(action === "update" && !fieldAttributes!.onUpdate))
|
|
212
|
-
) {
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// In some endpoints (like signUpEmail) where there isn't proper Zod validation,
|
|
217
|
-
// we might receive a date as a string (this is because of the client converting the Date to a string
|
|
218
|
-
// when sending to the server). Because of this, we'll convert the string to a Date.
|
|
219
|
-
if (
|
|
220
|
-
fieldAttributes &&
|
|
221
|
-
fieldAttributes.type === "date" &&
|
|
222
|
-
!(value instanceof Date) &&
|
|
223
|
-
typeof value === "string"
|
|
224
|
-
) {
|
|
225
|
-
try {
|
|
226
|
-
value = new Date(value);
|
|
227
|
-
} catch {
|
|
228
|
-
logger.error("[Adapter Factory] Failed to convert string to date", {
|
|
229
|
-
value,
|
|
230
|
-
field,
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// If the value is undefined, but the fieldAttr provides a `defaultValue`, then we'll use that.
|
|
236
|
-
let newValue = withApplyDefault(value, fieldAttributes!, action);
|
|
237
|
-
|
|
238
|
-
// If the field attr provides a custom transform input, then we'll let it handle the value transformation.
|
|
239
|
-
// Afterwards, we'll continue to apply the default transformations just to make sure it saves in the correct format.
|
|
240
|
-
if (fieldAttributes!.transform?.input) {
|
|
241
|
-
newValue = await fieldAttributes!.transform.input(newValue);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (fieldAttributes!.references?.field === "id" && useNumberId) {
|
|
245
|
-
if (Array.isArray(newValue)) {
|
|
246
|
-
newValue = newValue.map((x) => (x !== null ? Number(x) : null));
|
|
247
|
-
} else {
|
|
248
|
-
newValue = newValue !== null ? Number(newValue) : null;
|
|
249
|
-
}
|
|
250
|
-
} else if (
|
|
251
|
-
config.supportsJSON === false &&
|
|
252
|
-
typeof newValue === "object" &&
|
|
253
|
-
fieldAttributes!.type === "json"
|
|
254
|
-
) {
|
|
255
|
-
newValue = JSON.stringify(newValue);
|
|
256
|
-
} else if (
|
|
257
|
-
config.supportsArrays === false &&
|
|
258
|
-
Array.isArray(newValue) &&
|
|
259
|
-
(fieldAttributes!.type === "string[]" ||
|
|
260
|
-
fieldAttributes!.type === "number[]")
|
|
261
|
-
) {
|
|
262
|
-
newValue = JSON.stringify(newValue);
|
|
263
|
-
} else if (
|
|
264
|
-
config.supportsDates === false &&
|
|
265
|
-
newValue instanceof Date &&
|
|
266
|
-
fieldAttributes!.type === "date"
|
|
267
|
-
) {
|
|
268
|
-
newValue = newValue.toISOString();
|
|
269
|
-
} else if (
|
|
270
|
-
config.supportsBooleans === false &&
|
|
271
|
-
typeof newValue === "boolean"
|
|
272
|
-
) {
|
|
273
|
-
newValue = newValue ? 1 : 0;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (config.customTransformInput) {
|
|
277
|
-
newValue = config.customTransformInput({
|
|
278
|
-
data: newValue,
|
|
279
|
-
action,
|
|
280
|
-
field: newFieldName,
|
|
281
|
-
fieldAttributes: fieldAttributes!,
|
|
282
|
-
model: getModelName(defaultModelName),
|
|
283
|
-
schema,
|
|
284
|
-
options,
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (newValue !== undefined) {
|
|
289
|
-
transformedData[newFieldName] = newValue;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return transformedData;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
const transformOutput = async (
|
|
296
|
-
data: Record<string, any> | null,
|
|
297
|
-
unsafe_model: string,
|
|
298
|
-
select: string[] = [],
|
|
299
|
-
join: JoinConfig | undefined,
|
|
300
|
-
) => {
|
|
301
|
-
const transformSingleOutput = async (
|
|
302
|
-
data: Record<string, any> | null,
|
|
303
|
-
unsafe_model: string,
|
|
304
|
-
select: string[] = [],
|
|
305
|
-
) => {
|
|
306
|
-
if (!data) return null;
|
|
307
|
-
const newMappedKeys = config.mapKeysTransformOutput ?? {};
|
|
308
|
-
const transformedData: Record<string, any> = {};
|
|
309
|
-
const tableSchema = schema[getDefaultModelName(unsafe_model)]!.fields;
|
|
310
|
-
const idKey = Object.entries(newMappedKeys).find(
|
|
311
|
-
([_, v]) => v === "id",
|
|
312
|
-
)?.[0];
|
|
313
|
-
const useNumberId = options.advanced?.database?.generateId === "serial";
|
|
314
|
-
tableSchema[idKey ?? "id"] = {
|
|
315
|
-
type: useNumberId ? "number" : "string",
|
|
316
|
-
};
|
|
317
|
-
for (const key in tableSchema) {
|
|
318
|
-
if (select.length && !select.includes(key)) {
|
|
319
|
-
continue;
|
|
320
|
-
}
|
|
321
|
-
const field = tableSchema[key];
|
|
322
|
-
if (field) {
|
|
323
|
-
const originalKey = field.fieldName || key;
|
|
324
|
-
|
|
325
|
-
// If the field is mapped, we'll use the mapped key. Otherwise, we'll use the original key.
|
|
326
|
-
let newValue =
|
|
327
|
-
data[
|
|
328
|
-
Object.entries(newMappedKeys).find(
|
|
329
|
-
([_, v]) => v === originalKey,
|
|
330
|
-
)?.[0] || originalKey
|
|
331
|
-
];
|
|
332
|
-
|
|
333
|
-
if (field.transform?.output) {
|
|
334
|
-
newValue = await field.transform.output(newValue);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const newFieldName: string = newMappedKeys[key] || key;
|
|
338
|
-
|
|
339
|
-
if (originalKey === "id" || field.references?.field === "id") {
|
|
340
|
-
// Even if `useNumberId` is true, we must always return a string `id` output.
|
|
341
|
-
if (typeof newValue !== "undefined" && newValue !== null)
|
|
342
|
-
newValue = String(newValue);
|
|
343
|
-
} else if (
|
|
344
|
-
config.supportsJSON === false &&
|
|
345
|
-
typeof newValue === "string" &&
|
|
346
|
-
field.type === "json"
|
|
347
|
-
) {
|
|
348
|
-
newValue = safeJSONParse(newValue);
|
|
349
|
-
} else if (
|
|
350
|
-
config.supportsArrays === false &&
|
|
351
|
-
typeof newValue === "string" &&
|
|
352
|
-
(field.type === "string[]" || field.type === "number[]")
|
|
353
|
-
) {
|
|
354
|
-
newValue = safeJSONParse(newValue);
|
|
355
|
-
} else if (
|
|
356
|
-
config.supportsDates === false &&
|
|
357
|
-
typeof newValue === "string" &&
|
|
358
|
-
field.type === "date"
|
|
359
|
-
) {
|
|
360
|
-
newValue = new Date(newValue);
|
|
361
|
-
} else if (
|
|
362
|
-
config.supportsBooleans === false &&
|
|
363
|
-
typeof newValue === "number" &&
|
|
364
|
-
field.type === "boolean"
|
|
365
|
-
) {
|
|
366
|
-
newValue = newValue === 1;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if (config.customTransformOutput) {
|
|
370
|
-
newValue = config.customTransformOutput({
|
|
371
|
-
data: newValue,
|
|
372
|
-
field: newFieldName,
|
|
373
|
-
fieldAttributes: field,
|
|
374
|
-
select,
|
|
375
|
-
model: getModelName(unsafe_model),
|
|
376
|
-
schema,
|
|
377
|
-
options,
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
transformedData[newFieldName] = newValue;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return transformedData as any;
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
if (!join || Object.keys(join).length === 0) {
|
|
388
|
-
return await transformSingleOutput(data, unsafe_model, select);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
unsafe_model = getDefaultModelName(unsafe_model);
|
|
392
|
-
// for now we just transform the base model
|
|
393
|
-
// later we append the joined models to this object.
|
|
394
|
-
const transformedData: Record<string, any> = await transformSingleOutput(
|
|
395
|
-
data,
|
|
396
|
-
unsafe_model,
|
|
397
|
-
select,
|
|
398
|
-
);
|
|
399
|
-
|
|
400
|
-
// Get all the models that are required to be joined.
|
|
401
|
-
const requiredModels = Object.entries(join).map(
|
|
402
|
-
([model, joinConfig]) => ({
|
|
403
|
-
modelName: getModelName(model),
|
|
404
|
-
defaultModelName: getDefaultModelName(model),
|
|
405
|
-
joinConfig,
|
|
406
|
-
}),
|
|
407
|
-
);
|
|
408
|
-
|
|
409
|
-
if (!data) return null;
|
|
410
|
-
// Data is now the base model object directly (not wrapped under a key)
|
|
411
|
-
|
|
412
|
-
for (const {
|
|
413
|
-
modelName,
|
|
414
|
-
defaultModelName,
|
|
415
|
-
joinConfig,
|
|
416
|
-
} of requiredModels) {
|
|
417
|
-
let joinedData = await (async () => {
|
|
418
|
-
if (options.experimental?.joins) {
|
|
419
|
-
const result = data[modelName];
|
|
420
|
-
return result;
|
|
421
|
-
} else {
|
|
422
|
-
// doesn't support joins, so fallback to handleFallbackJoin
|
|
423
|
-
const result = await handleFallbackJoin({
|
|
424
|
-
baseModel: unsafe_model,
|
|
425
|
-
baseData: transformedData,
|
|
426
|
-
joinModel: modelName,
|
|
427
|
-
specificJoinConfig: joinConfig,
|
|
428
|
-
});
|
|
429
|
-
return result;
|
|
430
|
-
}
|
|
431
|
-
})();
|
|
432
|
-
|
|
433
|
-
// If joinedData is undefined, initialize it based on relationship type
|
|
434
|
-
if (joinedData === undefined || joinedData === null) {
|
|
435
|
-
joinedData = joinConfig.relation === "one-to-one" ? null : [];
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
if (
|
|
439
|
-
joinConfig.relation === "one-to-many" &&
|
|
440
|
-
!Array.isArray(joinedData)
|
|
441
|
-
) {
|
|
442
|
-
joinedData = [joinedData];
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
const transformed = [];
|
|
446
|
-
|
|
447
|
-
if (Array.isArray(joinedData)) {
|
|
448
|
-
for (const item of joinedData) {
|
|
449
|
-
const transformedItem = await transformSingleOutput(
|
|
450
|
-
item,
|
|
451
|
-
modelName,
|
|
452
|
-
[],
|
|
453
|
-
);
|
|
454
|
-
transformed.push(transformedItem);
|
|
455
|
-
}
|
|
456
|
-
} else {
|
|
457
|
-
const transformedItem = await transformSingleOutput(
|
|
458
|
-
joinedData,
|
|
459
|
-
modelName,
|
|
460
|
-
[],
|
|
461
|
-
);
|
|
462
|
-
transformed.push(transformedItem);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
const result =
|
|
466
|
-
joinConfig.relation === "one-to-one" ? transformed[0] : transformed;
|
|
467
|
-
transformedData[defaultModelName] = result ?? null;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return transformedData as any;
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
const transformWhereClause = <W extends Where[] | undefined>({
|
|
474
|
-
model,
|
|
475
|
-
where,
|
|
476
|
-
action,
|
|
477
|
-
}: {
|
|
478
|
-
where: W;
|
|
479
|
-
model: string;
|
|
480
|
-
action:
|
|
481
|
-
| "create"
|
|
482
|
-
| "update"
|
|
483
|
-
| "findOne"
|
|
484
|
-
| "findMany"
|
|
485
|
-
| "updateMany"
|
|
486
|
-
| "delete"
|
|
487
|
-
| "deleteMany"
|
|
488
|
-
| "count";
|
|
489
|
-
}): W extends undefined ? undefined : CleanedWhere[] => {
|
|
490
|
-
if (!where) return undefined as any;
|
|
491
|
-
const newMappedKeys = config.mapKeysTransformInput ?? {};
|
|
492
|
-
|
|
493
|
-
return where.map((w) => {
|
|
494
|
-
const {
|
|
495
|
-
field: unsafe_field,
|
|
496
|
-
value,
|
|
497
|
-
operator = "eq",
|
|
498
|
-
connector = "AND",
|
|
499
|
-
mode = "sensitive",
|
|
500
|
-
} = w;
|
|
501
|
-
if (operator === "in") {
|
|
502
|
-
if (!Array.isArray(value)) {
|
|
503
|
-
throw new BetterAuthError("Value must be an array");
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
let newValue = value;
|
|
508
|
-
|
|
509
|
-
const defaultModelName = getDefaultModelName(model);
|
|
510
|
-
const defaultFieldName = getDefaultFieldName({
|
|
511
|
-
field: unsafe_field,
|
|
512
|
-
model,
|
|
513
|
-
});
|
|
514
|
-
const fieldName: string =
|
|
515
|
-
newMappedKeys[defaultFieldName] ||
|
|
516
|
-
getFieldName({
|
|
517
|
-
field: defaultFieldName,
|
|
518
|
-
model: defaultModelName,
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
const fieldAttr = getFieldAttributes({
|
|
522
|
-
field: defaultFieldName,
|
|
523
|
-
model: defaultModelName,
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
const useNumberId = options.advanced?.database?.generateId === "serial";
|
|
527
|
-
|
|
528
|
-
if (
|
|
529
|
-
defaultFieldName === "id" ||
|
|
530
|
-
fieldAttr!.references?.field === "id"
|
|
531
|
-
) {
|
|
532
|
-
if (useNumberId) {
|
|
533
|
-
if (Array.isArray(value)) {
|
|
534
|
-
newValue = value.map(Number);
|
|
535
|
-
} else {
|
|
536
|
-
newValue = Number(value);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
if (
|
|
542
|
-
fieldAttr.type === "date" &&
|
|
543
|
-
value instanceof Date &&
|
|
544
|
-
!config.supportsDates
|
|
545
|
-
) {
|
|
546
|
-
newValue = value.toISOString();
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
if (fieldAttr.type === "boolean" && typeof newValue === "string") {
|
|
550
|
-
newValue = newValue === "true";
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
if (fieldAttr.type === "number") {
|
|
554
|
-
if (typeof newValue === "string" && newValue.trim() !== "") {
|
|
555
|
-
const parsed = Number(newValue);
|
|
556
|
-
if (!Number.isNaN(parsed)) {
|
|
557
|
-
newValue = parsed;
|
|
558
|
-
}
|
|
559
|
-
} else if (Array.isArray(newValue)) {
|
|
560
|
-
const parsed = newValue.map((v) =>
|
|
561
|
-
typeof v === "string" && v.trim() !== "" ? Number(v) : NaN,
|
|
562
|
-
);
|
|
563
|
-
if (parsed.every((n) => !Number.isNaN(n))) {
|
|
564
|
-
newValue = parsed;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
if (
|
|
570
|
-
fieldAttr.type === "boolean" &&
|
|
571
|
-
typeof newValue === "boolean" &&
|
|
572
|
-
!config.supportsBooleans
|
|
573
|
-
) {
|
|
574
|
-
newValue = newValue ? 1 : 0;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (
|
|
578
|
-
fieldAttr.type === "json" &&
|
|
579
|
-
typeof value === "object" &&
|
|
580
|
-
!config.supportsJSON
|
|
581
|
-
) {
|
|
582
|
-
try {
|
|
583
|
-
const stringifiedJSON = JSON.stringify(value);
|
|
584
|
-
newValue = stringifiedJSON;
|
|
585
|
-
} catch (error) {
|
|
586
|
-
throw new Error(
|
|
587
|
-
`Failed to stringify JSON value for field ${fieldName}`,
|
|
588
|
-
{ cause: error },
|
|
589
|
-
);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
if (config.customTransformInput) {
|
|
594
|
-
newValue = config.customTransformInput({
|
|
595
|
-
data: newValue,
|
|
596
|
-
fieldAttributes: fieldAttr,
|
|
597
|
-
field: fieldName,
|
|
598
|
-
model: getModelName(model),
|
|
599
|
-
schema,
|
|
600
|
-
options,
|
|
601
|
-
action,
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
return {
|
|
606
|
-
operator,
|
|
607
|
-
connector,
|
|
608
|
-
field: fieldName,
|
|
609
|
-
value: newValue,
|
|
610
|
-
mode,
|
|
611
|
-
} satisfies CleanedWhere;
|
|
612
|
-
}) as any;
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
const transformJoinClause = (
|
|
616
|
-
baseModel: string,
|
|
617
|
-
unsanitizedJoin: JoinOption | undefined,
|
|
618
|
-
select: string[] | undefined,
|
|
619
|
-
): { join: JoinConfig; select: string[] | undefined } | undefined => {
|
|
620
|
-
if (!unsanitizedJoin) return undefined;
|
|
621
|
-
if (Object.keys(unsanitizedJoin).length === 0) return undefined;
|
|
622
|
-
const transformedJoin: JoinConfig = {};
|
|
623
|
-
for (const [model, join] of Object.entries(unsanitizedJoin)) {
|
|
624
|
-
if (!join) continue;
|
|
625
|
-
const defaultModelName = getDefaultModelName(model);
|
|
626
|
-
const defaultBaseModelName = getDefaultModelName(baseModel);
|
|
627
|
-
|
|
628
|
-
// First, check if the joined model has FKs to the base model (forward join)
|
|
629
|
-
let foreignKeys = Object.entries(
|
|
630
|
-
schema[defaultModelName]!.fields,
|
|
631
|
-
).filter(
|
|
632
|
-
([field, fieldAttributes]) =>
|
|
633
|
-
fieldAttributes.references &&
|
|
634
|
-
getDefaultModelName(fieldAttributes.references.model) ===
|
|
635
|
-
defaultBaseModelName,
|
|
636
|
-
);
|
|
637
|
-
|
|
638
|
-
let isForwardJoin = true;
|
|
639
|
-
|
|
640
|
-
// If no forward join found, check backwards: does the base model have FKs to the joined model?
|
|
641
|
-
if (!foreignKeys.length) {
|
|
642
|
-
foreignKeys = Object.entries(
|
|
643
|
-
schema[defaultBaseModelName]!.fields,
|
|
644
|
-
).filter(
|
|
645
|
-
([field, fieldAttributes]) =>
|
|
646
|
-
fieldAttributes.references &&
|
|
647
|
-
getDefaultModelName(fieldAttributes.references.model) ===
|
|
648
|
-
defaultModelName,
|
|
649
|
-
);
|
|
650
|
-
isForwardJoin = false;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
if (!foreignKeys.length) {
|
|
654
|
-
throw new BetterAuthError(
|
|
655
|
-
`No foreign key found for model ${model} and base model ${baseModel} while performing join operation.`,
|
|
656
|
-
);
|
|
657
|
-
} else if (foreignKeys.length > 1) {
|
|
658
|
-
throw new BetterAuthError(
|
|
659
|
-
`Multiple foreign keys found for model ${model} and base model ${baseModel} while performing join operation. Only one foreign key is supported.`,
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
const [foreignKey, foreignKeyAttributes] = foreignKeys[0]!;
|
|
664
|
-
if (!foreignKeyAttributes.references) {
|
|
665
|
-
// this should never happen, as we filter for references in the foreign keys.
|
|
666
|
-
// it's here for typescript to be happy.
|
|
667
|
-
throw new BetterAuthError(
|
|
668
|
-
`No references found for foreign key ${foreignKey} on model ${model} while performing join operation.`,
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
let from: string;
|
|
673
|
-
let to: string;
|
|
674
|
-
let requiredSelectField: string;
|
|
675
|
-
|
|
676
|
-
if (isForwardJoin) {
|
|
677
|
-
// joined model has FK to base model
|
|
678
|
-
// The field we need in select is the referenced field in the base model
|
|
679
|
-
requiredSelectField = foreignKeyAttributes.references.field;
|
|
680
|
-
from = getFieldName({
|
|
681
|
-
model: baseModel,
|
|
682
|
-
field: requiredSelectField,
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
to = getFieldName({
|
|
686
|
-
model,
|
|
687
|
-
field: foreignKey,
|
|
688
|
-
});
|
|
689
|
-
} else {
|
|
690
|
-
// base model has FK to joined model
|
|
691
|
-
// The field we need in select is the foreign key field in the base model
|
|
692
|
-
requiredSelectField = foreignKey;
|
|
693
|
-
from = getFieldName({
|
|
694
|
-
model: baseModel,
|
|
695
|
-
field: requiredSelectField,
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
to = getFieldName({
|
|
699
|
-
model,
|
|
700
|
-
field: foreignKeyAttributes.references.field,
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
// Ensure the required field is in select if select is provided
|
|
705
|
-
if (select && !select.includes(requiredSelectField)) {
|
|
706
|
-
select.push(requiredSelectField);
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
const isUnique =
|
|
710
|
-
to === "id" ? true : (foreignKeyAttributes.unique ?? false);
|
|
711
|
-
|
|
712
|
-
let limit: number =
|
|
713
|
-
options.advanced?.database?.defaultFindManyLimit ?? 100;
|
|
714
|
-
if (isUnique) {
|
|
715
|
-
limit = 1;
|
|
716
|
-
} else if (typeof join === "object" && typeof join.limit === "number") {
|
|
717
|
-
limit = join.limit;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
transformedJoin[getModelName(model)] = {
|
|
721
|
-
on: {
|
|
722
|
-
from,
|
|
723
|
-
to,
|
|
724
|
-
},
|
|
725
|
-
limit,
|
|
726
|
-
relation: isUnique ? "one-to-one" : "one-to-many",
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
return { join: transformedJoin, select };
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
/**
|
|
733
|
-
* Handle joins by making separate queries and combining results (fallback for adapters that don't support native joins).
|
|
734
|
-
*/
|
|
735
|
-
const handleFallbackJoin = async <T extends Record<string, any> | null>({
|
|
736
|
-
baseModel,
|
|
737
|
-
baseData,
|
|
738
|
-
joinModel,
|
|
739
|
-
specificJoinConfig: joinConfig,
|
|
740
|
-
}: {
|
|
741
|
-
baseModel: string;
|
|
742
|
-
baseData: T;
|
|
743
|
-
joinModel: string;
|
|
744
|
-
specificJoinConfig: JoinConfig[number];
|
|
745
|
-
}) => {
|
|
746
|
-
if (!baseData) return baseData;
|
|
747
|
-
const modelName = getModelName(joinModel);
|
|
748
|
-
const field = joinConfig.on.to;
|
|
749
|
-
const value =
|
|
750
|
-
baseData[
|
|
751
|
-
getDefaultFieldName({ field: joinConfig.on.from, model: baseModel })
|
|
752
|
-
];
|
|
753
|
-
|
|
754
|
-
if (value === null || value === undefined) {
|
|
755
|
-
// If there is no value, it could mean that the query used a `select` clause that didn't include the field.
|
|
756
|
-
// or the query result is purely empty.
|
|
757
|
-
// In any case, we return null/empty array.
|
|
758
|
-
return joinConfig.relation === "one-to-one" ? null : [];
|
|
759
|
-
}
|
|
760
|
-
let result: Record<string, any> | Record<string, any>[] | null;
|
|
761
|
-
const where = transformWhereClause({
|
|
762
|
-
model: modelName,
|
|
763
|
-
where: [
|
|
764
|
-
{
|
|
765
|
-
field,
|
|
766
|
-
value,
|
|
767
|
-
operator: "eq",
|
|
768
|
-
connector: "AND",
|
|
769
|
-
},
|
|
770
|
-
],
|
|
771
|
-
action: "findOne",
|
|
772
|
-
});
|
|
773
|
-
try {
|
|
774
|
-
if (joinConfig.relation === "one-to-one") {
|
|
775
|
-
result = await withSpan(
|
|
776
|
-
`db findOne ${modelName}`,
|
|
777
|
-
{
|
|
778
|
-
[ATTR_DB_OPERATION_NAME]: "findOne",
|
|
779
|
-
[ATTR_DB_COLLECTION_NAME]: modelName,
|
|
780
|
-
},
|
|
781
|
-
() =>
|
|
782
|
-
adapterInstance.findOne<Record<string, any>>({
|
|
783
|
-
model: modelName,
|
|
784
|
-
where: where,
|
|
785
|
-
}),
|
|
786
|
-
);
|
|
787
|
-
} else {
|
|
788
|
-
const limit =
|
|
789
|
-
joinConfig.limit ??
|
|
790
|
-
options.advanced?.database?.defaultFindManyLimit ??
|
|
791
|
-
100;
|
|
792
|
-
result = await withSpan(
|
|
793
|
-
`db findMany ${modelName}`,
|
|
794
|
-
{
|
|
795
|
-
[ATTR_DB_OPERATION_NAME]: "findMany",
|
|
796
|
-
[ATTR_DB_COLLECTION_NAME]: modelName,
|
|
797
|
-
},
|
|
798
|
-
() =>
|
|
799
|
-
adapterInstance.findMany<Record<string, any>>({
|
|
800
|
-
model: modelName,
|
|
801
|
-
where: where,
|
|
802
|
-
limit,
|
|
803
|
-
}),
|
|
804
|
-
);
|
|
805
|
-
}
|
|
806
|
-
} catch (error) {
|
|
807
|
-
logger.error(`Failed to query fallback join for model ${modelName}:`, {
|
|
808
|
-
where,
|
|
809
|
-
limit: joinConfig.limit,
|
|
810
|
-
});
|
|
811
|
-
console.error(error);
|
|
812
|
-
throw error;
|
|
813
|
-
}
|
|
814
|
-
return result;
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
const adapterInstance = customAdapter({
|
|
818
|
-
options,
|
|
819
|
-
schema,
|
|
820
|
-
debugLog,
|
|
821
|
-
getFieldName,
|
|
822
|
-
getModelName,
|
|
823
|
-
getDefaultModelName,
|
|
824
|
-
getDefaultFieldName,
|
|
825
|
-
getFieldAttributes,
|
|
826
|
-
transformInput,
|
|
827
|
-
transformOutput,
|
|
828
|
-
transformWhereClause,
|
|
829
|
-
});
|
|
830
|
-
|
|
831
|
-
let lazyLoadTransaction: DBAdapter<Options>["transaction"] | null = null;
|
|
832
|
-
const adapter: DBAdapter<Options> = {
|
|
833
|
-
transaction: async (cb) => {
|
|
834
|
-
if (!lazyLoadTransaction) {
|
|
835
|
-
if (!config.transaction) {
|
|
836
|
-
lazyLoadTransaction = createAsIsTransaction(adapter);
|
|
837
|
-
} else {
|
|
838
|
-
logger.debug(
|
|
839
|
-
`[${config.adapterName}] - Using provided transaction implementation.`,
|
|
840
|
-
);
|
|
841
|
-
lazyLoadTransaction = config.transaction;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
return lazyLoadTransaction(cb);
|
|
845
|
-
},
|
|
846
|
-
create: async <T extends Record<string, any>, R = T>({
|
|
847
|
-
data: unsafeData,
|
|
848
|
-
model: unsafeModel,
|
|
849
|
-
select,
|
|
850
|
-
forceAllowId = false,
|
|
851
|
-
}: {
|
|
852
|
-
model: string;
|
|
853
|
-
data: T;
|
|
854
|
-
select?: string[];
|
|
855
|
-
forceAllowId?: boolean;
|
|
856
|
-
}): Promise<R> => {
|
|
857
|
-
transactionId++;
|
|
858
|
-
const thisTransactionId = transactionId;
|
|
859
|
-
const model = getModelName(unsafeModel);
|
|
860
|
-
unsafeModel = getDefaultModelName(unsafeModel);
|
|
861
|
-
if (
|
|
862
|
-
"id" in unsafeData &&
|
|
863
|
-
typeof unsafeData.id !== "undefined" &&
|
|
864
|
-
!forceAllowId
|
|
865
|
-
) {
|
|
866
|
-
// The reason why `forceAllowId` was introduced was because we used to handle
|
|
867
|
-
// id generation ourselves (eg adapter.create({ data: { id: "123" } }))
|
|
868
|
-
// This was bad as certain things (such as number ids) would not work as expected.
|
|
869
|
-
// Since then, we have introduced the `forceAllowId` parameter to allow users to
|
|
870
|
-
// bypass this check. Otherwise, we would throw a warning stating that the id will be ignored
|
|
871
|
-
logger.warn(
|
|
872
|
-
`[${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.`,
|
|
873
|
-
);
|
|
874
|
-
const err = new Error();
|
|
875
|
-
const stack = err.stack
|
|
876
|
-
?.split("\n")
|
|
877
|
-
.filter((_, i) => i !== 1)
|
|
878
|
-
.join("\n")
|
|
879
|
-
.replace("Error:", "Create method with `id` being called at:");
|
|
880
|
-
console.log(stack);
|
|
881
|
-
//@ts-expect-error
|
|
882
|
-
unsafeData.id = undefined;
|
|
883
|
-
}
|
|
884
|
-
debugLog(
|
|
885
|
-
{ method: "create" },
|
|
886
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`,
|
|
887
|
-
`${formatMethod("create")} ${formatAction("Unsafe Input")}:`,
|
|
888
|
-
{ model, data: unsafeData },
|
|
889
|
-
);
|
|
890
|
-
let data = unsafeData;
|
|
891
|
-
if (!config.disableTransformInput) {
|
|
892
|
-
data = (await transformInput(
|
|
893
|
-
unsafeData,
|
|
894
|
-
unsafeModel,
|
|
895
|
-
"create",
|
|
896
|
-
forceAllowId,
|
|
897
|
-
)) as T;
|
|
898
|
-
}
|
|
899
|
-
debugLog(
|
|
900
|
-
{ method: "create" },
|
|
901
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`,
|
|
902
|
-
`${formatMethod("create")} ${formatAction("Parsed Input")}:`,
|
|
903
|
-
{ model, data },
|
|
904
|
-
);
|
|
905
|
-
const res = await withSpan(
|
|
906
|
-
`db create ${model}`,
|
|
907
|
-
{
|
|
908
|
-
[ATTR_DB_OPERATION_NAME]: "create",
|
|
909
|
-
[ATTR_DB_COLLECTION_NAME]: model,
|
|
910
|
-
},
|
|
911
|
-
() => adapterInstance.create<T>({ data, model }),
|
|
912
|
-
);
|
|
913
|
-
debugLog(
|
|
914
|
-
{ method: "create" },
|
|
915
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`,
|
|
916
|
-
`${formatMethod("create")} ${formatAction("DB Result")}:`,
|
|
917
|
-
{ model, res },
|
|
918
|
-
);
|
|
919
|
-
let transformed = res as any;
|
|
920
|
-
if (!config.disableTransformOutput) {
|
|
921
|
-
transformed = await transformOutput(
|
|
922
|
-
res as any,
|
|
923
|
-
unsafeModel,
|
|
924
|
-
select,
|
|
925
|
-
undefined,
|
|
926
|
-
);
|
|
927
|
-
}
|
|
928
|
-
debugLog(
|
|
929
|
-
{ method: "create" },
|
|
930
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`,
|
|
931
|
-
`${formatMethod("create")} ${formatAction("Parsed Result")}:`,
|
|
932
|
-
{ model, data: transformed },
|
|
933
|
-
);
|
|
934
|
-
return transformed;
|
|
935
|
-
},
|
|
936
|
-
update: async <T>({
|
|
937
|
-
model: unsafeModel,
|
|
938
|
-
where: unsafeWhere,
|
|
939
|
-
update: unsafeData,
|
|
940
|
-
}: {
|
|
941
|
-
model: string;
|
|
942
|
-
where: Where[];
|
|
943
|
-
update: Record<string, any>;
|
|
944
|
-
}): Promise<T | null> => {
|
|
945
|
-
transactionId++;
|
|
946
|
-
const thisTransactionId = transactionId;
|
|
947
|
-
unsafeModel = getDefaultModelName(unsafeModel);
|
|
948
|
-
const model = getModelName(unsafeModel);
|
|
949
|
-
const where = transformWhereClause({
|
|
950
|
-
model: unsafeModel,
|
|
951
|
-
where: unsafeWhere,
|
|
952
|
-
action: "update",
|
|
953
|
-
});
|
|
954
|
-
debugLog(
|
|
955
|
-
{ method: "update" },
|
|
956
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`,
|
|
957
|
-
`${formatMethod("update")} ${formatAction("Unsafe Input")}:`,
|
|
958
|
-
{ model, data: unsafeData },
|
|
959
|
-
);
|
|
960
|
-
let data = unsafeData as T;
|
|
961
|
-
if (!config.disableTransformInput) {
|
|
962
|
-
data = (await transformInput(unsafeData, unsafeModel, "update")) as T;
|
|
963
|
-
}
|
|
964
|
-
debugLog(
|
|
965
|
-
{ method: "update" },
|
|
966
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`,
|
|
967
|
-
`${formatMethod("update")} ${formatAction("Parsed Input")}:`,
|
|
968
|
-
{ model, data },
|
|
969
|
-
);
|
|
970
|
-
const res = await withSpan(
|
|
971
|
-
`db update ${model}`,
|
|
972
|
-
{
|
|
973
|
-
[ATTR_DB_OPERATION_NAME]: "update",
|
|
974
|
-
[ATTR_DB_COLLECTION_NAME]: model,
|
|
975
|
-
},
|
|
976
|
-
() =>
|
|
977
|
-
adapterInstance.update<T>({
|
|
978
|
-
model,
|
|
979
|
-
where,
|
|
980
|
-
update: data,
|
|
981
|
-
}),
|
|
982
|
-
);
|
|
983
|
-
debugLog(
|
|
984
|
-
{ method: "update" },
|
|
985
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`,
|
|
986
|
-
`${formatMethod("update")} ${formatAction("DB Result")}:`,
|
|
987
|
-
{ model, data: res },
|
|
988
|
-
);
|
|
989
|
-
let transformed = res as any;
|
|
990
|
-
if (!config.disableTransformOutput) {
|
|
991
|
-
transformed = await transformOutput(
|
|
992
|
-
res as any,
|
|
993
|
-
unsafeModel,
|
|
994
|
-
undefined,
|
|
995
|
-
undefined,
|
|
996
|
-
);
|
|
997
|
-
}
|
|
998
|
-
debugLog(
|
|
999
|
-
{ method: "update" },
|
|
1000
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`,
|
|
1001
|
-
`${formatMethod("update")} ${formatAction("Parsed Result")}:`,
|
|
1002
|
-
{ model, data: transformed },
|
|
1003
|
-
);
|
|
1004
|
-
return transformed;
|
|
1005
|
-
},
|
|
1006
|
-
updateMany: async ({
|
|
1007
|
-
model: unsafeModel,
|
|
1008
|
-
where: unsafeWhere,
|
|
1009
|
-
update: unsafeData,
|
|
1010
|
-
}: {
|
|
1011
|
-
model: string;
|
|
1012
|
-
where: Where[];
|
|
1013
|
-
update: Record<string, any>;
|
|
1014
|
-
}) => {
|
|
1015
|
-
transactionId++;
|
|
1016
|
-
const thisTransactionId = transactionId;
|
|
1017
|
-
const model = getModelName(unsafeModel);
|
|
1018
|
-
const where = transformWhereClause({
|
|
1019
|
-
model: unsafeModel,
|
|
1020
|
-
where: unsafeWhere,
|
|
1021
|
-
action: "updateMany",
|
|
1022
|
-
});
|
|
1023
|
-
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1024
|
-
debugLog(
|
|
1025
|
-
{ method: "updateMany" },
|
|
1026
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`,
|
|
1027
|
-
`${formatMethod("updateMany")} ${formatAction("Unsafe Input")}:`,
|
|
1028
|
-
{ model, data: unsafeData },
|
|
1029
|
-
);
|
|
1030
|
-
let data = unsafeData;
|
|
1031
|
-
if (!config.disableTransformInput) {
|
|
1032
|
-
data = await transformInput(unsafeData, unsafeModel, "update");
|
|
1033
|
-
}
|
|
1034
|
-
debugLog(
|
|
1035
|
-
{ method: "updateMany" },
|
|
1036
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`,
|
|
1037
|
-
`${formatMethod("updateMany")} ${formatAction("Parsed Input")}:`,
|
|
1038
|
-
{ model, data },
|
|
1039
|
-
);
|
|
1040
|
-
|
|
1041
|
-
const updatedCount = await withSpan(
|
|
1042
|
-
`db updateMany ${model}`,
|
|
1043
|
-
{
|
|
1044
|
-
[ATTR_DB_OPERATION_NAME]: "updateMany",
|
|
1045
|
-
[ATTR_DB_COLLECTION_NAME]: model,
|
|
1046
|
-
},
|
|
1047
|
-
() =>
|
|
1048
|
-
adapterInstance.updateMany({
|
|
1049
|
-
model,
|
|
1050
|
-
where,
|
|
1051
|
-
update: data,
|
|
1052
|
-
}),
|
|
1053
|
-
);
|
|
1054
|
-
debugLog(
|
|
1055
|
-
{ method: "updateMany" },
|
|
1056
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`,
|
|
1057
|
-
`${formatMethod("updateMany")} ${formatAction("DB Result")}:`,
|
|
1058
|
-
{ model, data: updatedCount },
|
|
1059
|
-
);
|
|
1060
|
-
debugLog(
|
|
1061
|
-
{ method: "updateMany" },
|
|
1062
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`,
|
|
1063
|
-
`${formatMethod("updateMany")} ${formatAction("Parsed Result")}:`,
|
|
1064
|
-
{ model, data: updatedCount },
|
|
1065
|
-
);
|
|
1066
|
-
return updatedCount;
|
|
1067
|
-
},
|
|
1068
|
-
findOne: async <T extends Record<string, any>>({
|
|
1069
|
-
model: unsafeModel,
|
|
1070
|
-
where: unsafeWhere,
|
|
1071
|
-
select,
|
|
1072
|
-
join: unsafeJoin,
|
|
1073
|
-
}: {
|
|
1074
|
-
model: string;
|
|
1075
|
-
where: Where[];
|
|
1076
|
-
select?: string[];
|
|
1077
|
-
join?: JoinOption;
|
|
1078
|
-
}) => {
|
|
1079
|
-
transactionId++;
|
|
1080
|
-
const thisTransactionId = transactionId;
|
|
1081
|
-
const model = getModelName(unsafeModel);
|
|
1082
|
-
const where = transformWhereClause({
|
|
1083
|
-
model: unsafeModel,
|
|
1084
|
-
where: unsafeWhere,
|
|
1085
|
-
action: "findOne",
|
|
1086
|
-
});
|
|
1087
|
-
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1088
|
-
let join: JoinConfig | undefined;
|
|
1089
|
-
let passJoinToAdapter = true;
|
|
1090
|
-
if (!config.disableTransformJoin) {
|
|
1091
|
-
const result = transformJoinClause(unsafeModel, unsafeJoin, select);
|
|
1092
|
-
if (result) {
|
|
1093
|
-
join = result.join;
|
|
1094
|
-
select = result.select;
|
|
1095
|
-
}
|
|
1096
|
-
// If adapter doesn't support joins and we have joins, don't pass them to the adapter
|
|
1097
|
-
const experimentalJoins = options.experimental?.joins;
|
|
1098
|
-
if (!experimentalJoins && join && Object.keys(join).length > 0) {
|
|
1099
|
-
passJoinToAdapter = false;
|
|
1100
|
-
}
|
|
1101
|
-
} else {
|
|
1102
|
-
// assume it's already transformed if transformation is disabled
|
|
1103
|
-
join = unsafeJoin as never as JoinConfig;
|
|
1104
|
-
}
|
|
1105
|
-
debugLog(
|
|
1106
|
-
{ method: "findOne" },
|
|
1107
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`,
|
|
1108
|
-
`${formatMethod("findOne")}:`,
|
|
1109
|
-
{ model, where, select, join },
|
|
1110
|
-
);
|
|
1111
|
-
|
|
1112
|
-
const res = await withSpan(
|
|
1113
|
-
`db findOne ${model}`,
|
|
1114
|
-
{
|
|
1115
|
-
[ATTR_DB_OPERATION_NAME]: "findOne",
|
|
1116
|
-
[ATTR_DB_COLLECTION_NAME]: model,
|
|
1117
|
-
},
|
|
1118
|
-
() =>
|
|
1119
|
-
adapterInstance.findOne<T>({
|
|
1120
|
-
model,
|
|
1121
|
-
where,
|
|
1122
|
-
select,
|
|
1123
|
-
join: passJoinToAdapter ? join : undefined,
|
|
1124
|
-
}),
|
|
1125
|
-
);
|
|
1126
|
-
debugLog(
|
|
1127
|
-
{ method: "findOne" },
|
|
1128
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(2, 3)}`,
|
|
1129
|
-
`${formatMethod("findOne")} ${formatAction("DB Result")}:`,
|
|
1130
|
-
{ model, data: res },
|
|
1131
|
-
);
|
|
1132
|
-
|
|
1133
|
-
// Handle fallback join if adapter doesn't support joins
|
|
1134
|
-
let transformed = res as any;
|
|
1135
|
-
if (!config.disableTransformOutput) {
|
|
1136
|
-
transformed = await transformOutput(res, unsafeModel, select, join);
|
|
1137
|
-
}
|
|
1138
|
-
debugLog(
|
|
1139
|
-
{ method: "findOne" },
|
|
1140
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(3, 3)}`,
|
|
1141
|
-
`${formatMethod("findOne")} ${formatAction("Parsed Result")}:`,
|
|
1142
|
-
{ model, data: transformed },
|
|
1143
|
-
);
|
|
1144
|
-
return transformed;
|
|
1145
|
-
},
|
|
1146
|
-
findMany: async <T extends Record<string, any>>({
|
|
1147
|
-
model: unsafeModel,
|
|
1148
|
-
where: unsafeWhere,
|
|
1149
|
-
limit: unsafeLimit,
|
|
1150
|
-
select,
|
|
1151
|
-
sortBy,
|
|
1152
|
-
offset,
|
|
1153
|
-
join: unsafeJoin,
|
|
1154
|
-
}: {
|
|
1155
|
-
model: string;
|
|
1156
|
-
where?: Where[];
|
|
1157
|
-
limit?: number;
|
|
1158
|
-
select?: string[] | undefined;
|
|
1159
|
-
sortBy?: { field: string; direction: "asc" | "desc" };
|
|
1160
|
-
offset?: number;
|
|
1161
|
-
join?: JoinOption;
|
|
1162
|
-
}) => {
|
|
1163
|
-
transactionId++;
|
|
1164
|
-
const thisTransactionId = transactionId;
|
|
1165
|
-
const limit =
|
|
1166
|
-
unsafeLimit ??
|
|
1167
|
-
options.advanced?.database?.defaultFindManyLimit ??
|
|
1168
|
-
100;
|
|
1169
|
-
const model = getModelName(unsafeModel);
|
|
1170
|
-
const where = transformWhereClause({
|
|
1171
|
-
model: unsafeModel,
|
|
1172
|
-
where: unsafeWhere,
|
|
1173
|
-
action: "findMany",
|
|
1174
|
-
});
|
|
1175
|
-
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1176
|
-
let join: JoinConfig | undefined;
|
|
1177
|
-
let passJoinToAdapter = true;
|
|
1178
|
-
if (!config.disableTransformJoin) {
|
|
1179
|
-
const result = transformJoinClause(unsafeModel, unsafeJoin, select);
|
|
1180
|
-
if (result) {
|
|
1181
|
-
join = result.join;
|
|
1182
|
-
select = result.select;
|
|
1183
|
-
}
|
|
1184
|
-
// If adapter doesn't support joins and we have joins, don't pass them to the adapter
|
|
1185
|
-
const experimentalJoins = options.experimental?.joins;
|
|
1186
|
-
if (!experimentalJoins && join && Object.keys(join).length > 0) {
|
|
1187
|
-
passJoinToAdapter = false;
|
|
1188
|
-
}
|
|
1189
|
-
} else {
|
|
1190
|
-
// assume it's already transformed if transformation is disabled
|
|
1191
|
-
join = unsafeJoin as never as JoinConfig;
|
|
1192
|
-
}
|
|
1193
|
-
debugLog(
|
|
1194
|
-
{ method: "findMany" },
|
|
1195
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`,
|
|
1196
|
-
`${formatMethod("findMany")}:`,
|
|
1197
|
-
{ model, where, limit, sortBy, offset, join },
|
|
1198
|
-
);
|
|
1199
|
-
const res = await withSpan(
|
|
1200
|
-
`db findMany ${model}`,
|
|
1201
|
-
{
|
|
1202
|
-
[ATTR_DB_OPERATION_NAME]: "findMany",
|
|
1203
|
-
[ATTR_DB_COLLECTION_NAME]: model,
|
|
1204
|
-
},
|
|
1205
|
-
() =>
|
|
1206
|
-
adapterInstance.findMany<T>({
|
|
1207
|
-
model,
|
|
1208
|
-
where,
|
|
1209
|
-
limit: limit,
|
|
1210
|
-
select,
|
|
1211
|
-
sortBy,
|
|
1212
|
-
offset,
|
|
1213
|
-
join: passJoinToAdapter ? join : undefined,
|
|
1214
|
-
}),
|
|
1215
|
-
);
|
|
1216
|
-
debugLog(
|
|
1217
|
-
{ method: "findMany" },
|
|
1218
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(2, 3)}`,
|
|
1219
|
-
`${formatMethod("findMany")} ${formatAction("DB Result")}:`,
|
|
1220
|
-
{ model, data: res },
|
|
1221
|
-
);
|
|
1222
|
-
|
|
1223
|
-
let transformed = res as any;
|
|
1224
|
-
if (!config.disableTransformOutput) {
|
|
1225
|
-
transformed = await Promise.all(
|
|
1226
|
-
res.map(async (r: Record<string, any>) => {
|
|
1227
|
-
return await transformOutput(r, unsafeModel, undefined, join);
|
|
1228
|
-
}),
|
|
1229
|
-
);
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
debugLog(
|
|
1233
|
-
{ method: "findMany" },
|
|
1234
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(3, 3)}`,
|
|
1235
|
-
`${formatMethod("findMany")} ${formatAction("Parsed Result")}:`,
|
|
1236
|
-
{ model, data: transformed },
|
|
1237
|
-
);
|
|
1238
|
-
return transformed;
|
|
1239
|
-
},
|
|
1240
|
-
delete: async ({
|
|
1241
|
-
model: unsafeModel,
|
|
1242
|
-
where: unsafeWhere,
|
|
1243
|
-
}: {
|
|
1244
|
-
model: string;
|
|
1245
|
-
where: Where[];
|
|
1246
|
-
}) => {
|
|
1247
|
-
transactionId++;
|
|
1248
|
-
const thisTransactionId = transactionId;
|
|
1249
|
-
const model = getModelName(unsafeModel);
|
|
1250
|
-
const where = transformWhereClause({
|
|
1251
|
-
model: unsafeModel,
|
|
1252
|
-
where: unsafeWhere,
|
|
1253
|
-
action: "delete",
|
|
1254
|
-
});
|
|
1255
|
-
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1256
|
-
debugLog(
|
|
1257
|
-
{ method: "delete" },
|
|
1258
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`,
|
|
1259
|
-
`${formatMethod("delete")}:`,
|
|
1260
|
-
{ model, where },
|
|
1261
|
-
);
|
|
1262
|
-
await withSpan(
|
|
1263
|
-
`db delete ${model}`,
|
|
1264
|
-
{
|
|
1265
|
-
[ATTR_DB_OPERATION_NAME]: "delete",
|
|
1266
|
-
[ATTR_DB_COLLECTION_NAME]: model,
|
|
1267
|
-
},
|
|
1268
|
-
() => adapterInstance.delete({ model, where }),
|
|
1269
|
-
);
|
|
1270
|
-
debugLog(
|
|
1271
|
-
{ method: "delete" },
|
|
1272
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`,
|
|
1273
|
-
`${formatMethod("delete")} ${formatAction("DB Result")}:`,
|
|
1274
|
-
{ model },
|
|
1275
|
-
);
|
|
1276
|
-
},
|
|
1277
|
-
deleteMany: async ({
|
|
1278
|
-
model: unsafeModel,
|
|
1279
|
-
where: unsafeWhere,
|
|
1280
|
-
}: {
|
|
1281
|
-
model: string;
|
|
1282
|
-
where: Where[];
|
|
1283
|
-
}) => {
|
|
1284
|
-
transactionId++;
|
|
1285
|
-
const thisTransactionId = transactionId;
|
|
1286
|
-
const model = getModelName(unsafeModel);
|
|
1287
|
-
const where = transformWhereClause({
|
|
1288
|
-
model: unsafeModel,
|
|
1289
|
-
where: unsafeWhere,
|
|
1290
|
-
action: "deleteMany",
|
|
1291
|
-
});
|
|
1292
|
-
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1293
|
-
debugLog(
|
|
1294
|
-
{ method: "deleteMany" },
|
|
1295
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`,
|
|
1296
|
-
`${formatMethod("deleteMany")} ${formatAction("DeleteMany")}:`,
|
|
1297
|
-
{ model, where },
|
|
1298
|
-
);
|
|
1299
|
-
const res = await withSpan(
|
|
1300
|
-
`db deleteMany ${model}`,
|
|
1301
|
-
{
|
|
1302
|
-
[ATTR_DB_OPERATION_NAME]: "deleteMany",
|
|
1303
|
-
[ATTR_DB_COLLECTION_NAME]: model,
|
|
1304
|
-
},
|
|
1305
|
-
() => adapterInstance.deleteMany({ model, where }),
|
|
1306
|
-
);
|
|
1307
|
-
debugLog(
|
|
1308
|
-
{ method: "deleteMany" },
|
|
1309
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`,
|
|
1310
|
-
`${formatMethod("deleteMany")} ${formatAction("DB Result")}:`,
|
|
1311
|
-
{ model, data: res },
|
|
1312
|
-
);
|
|
1313
|
-
return res;
|
|
1314
|
-
},
|
|
1315
|
-
count: async ({
|
|
1316
|
-
model: unsafeModel,
|
|
1317
|
-
where: unsafeWhere,
|
|
1318
|
-
}: {
|
|
1319
|
-
model: string;
|
|
1320
|
-
where?: Where[];
|
|
1321
|
-
}) => {
|
|
1322
|
-
transactionId++;
|
|
1323
|
-
const thisTransactionId = transactionId;
|
|
1324
|
-
const model = getModelName(unsafeModel);
|
|
1325
|
-
const where = transformWhereClause({
|
|
1326
|
-
model: unsafeModel,
|
|
1327
|
-
where: unsafeWhere,
|
|
1328
|
-
action: "count",
|
|
1329
|
-
});
|
|
1330
|
-
unsafeModel = getDefaultModelName(unsafeModel);
|
|
1331
|
-
debugLog(
|
|
1332
|
-
{ method: "count" },
|
|
1333
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`,
|
|
1334
|
-
`${formatMethod("count")}:`,
|
|
1335
|
-
{
|
|
1336
|
-
model,
|
|
1337
|
-
where,
|
|
1338
|
-
},
|
|
1339
|
-
);
|
|
1340
|
-
const res = await withSpan(
|
|
1341
|
-
`db count ${model}`,
|
|
1342
|
-
{
|
|
1343
|
-
[ATTR_DB_OPERATION_NAME]: "count",
|
|
1344
|
-
[ATTR_DB_COLLECTION_NAME]: model,
|
|
1345
|
-
},
|
|
1346
|
-
() => adapterInstance.count({ model, where }),
|
|
1347
|
-
);
|
|
1348
|
-
debugLog(
|
|
1349
|
-
{ method: "count" },
|
|
1350
|
-
`${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`,
|
|
1351
|
-
`${formatMethod("count")}:`,
|
|
1352
|
-
{
|
|
1353
|
-
model,
|
|
1354
|
-
data: res,
|
|
1355
|
-
},
|
|
1356
|
-
);
|
|
1357
|
-
return res;
|
|
1358
|
-
},
|
|
1359
|
-
createSchema: adapterInstance.createSchema
|
|
1360
|
-
? async (_, file) => {
|
|
1361
|
-
const tables = getAuthTables(options);
|
|
1362
|
-
|
|
1363
|
-
if (
|
|
1364
|
-
options.secondaryStorage &&
|
|
1365
|
-
!options.session?.storeSessionInDatabase
|
|
1366
|
-
) {
|
|
1367
|
-
// biome-ignore lint/performance/noDelete: If the user has enabled secondaryStorage, as well as not specifying to store session table in DB, then createSchema shouldn't generate schema table.
|
|
1368
|
-
delete tables.session;
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
return adapterInstance.createSchema!({ file, tables });
|
|
1372
|
-
}
|
|
1373
|
-
: undefined,
|
|
1374
|
-
options: {
|
|
1375
|
-
adapterConfig: config,
|
|
1376
|
-
...(adapterInstance.options ?? {}),
|
|
1377
|
-
},
|
|
1378
|
-
id: config.adapterId,
|
|
1379
|
-
|
|
1380
|
-
// Secretly export values ONLY if this adapter has enabled adapter-test-debug-logs.
|
|
1381
|
-
// This would then be used during our adapter-tests to help print debug logs if a test fails.
|
|
1382
|
-
//@ts-expect-error - ^^
|
|
1383
|
-
...(config.debugLogs?.isRunningAdapterTests
|
|
1384
|
-
? {
|
|
1385
|
-
adapterTestDebugLogs: {
|
|
1386
|
-
resetDebugLogs() {
|
|
1387
|
-
debugLogs = debugLogs.filter(
|
|
1388
|
-
(log) => log.instance !== uniqueAdapterFactoryInstanceId,
|
|
1389
|
-
);
|
|
1390
|
-
},
|
|
1391
|
-
printDebugLogs() {
|
|
1392
|
-
const separator = `─`.repeat(80);
|
|
1393
|
-
const logs = debugLogs.filter(
|
|
1394
|
-
(log) => log.instance === uniqueAdapterFactoryInstanceId,
|
|
1395
|
-
);
|
|
1396
|
-
if (logs.length === 0) {
|
|
1397
|
-
return;
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
//`${colors.fg.blue}|${colors.reset} `,
|
|
1401
|
-
const log: any[] = logs
|
|
1402
|
-
.reverse()
|
|
1403
|
-
.map((log) => {
|
|
1404
|
-
log.args[0] = `\n${log.args[0]}`;
|
|
1405
|
-
return [...log.args, "\n"];
|
|
1406
|
-
})
|
|
1407
|
-
.reduce(
|
|
1408
|
-
(prev, curr) => {
|
|
1409
|
-
return [...curr, ...prev];
|
|
1410
|
-
},
|
|
1411
|
-
[`\n${separator}`],
|
|
1412
|
-
);
|
|
1413
|
-
|
|
1414
|
-
console.log(...log);
|
|
1415
|
-
},
|
|
1416
|
-
} satisfies AdapterTestDebugLogs,
|
|
1417
|
-
}
|
|
1418
|
-
: {}),
|
|
1419
|
-
};
|
|
1420
|
-
return adapter;
|
|
1421
|
-
};
|
|
1422
|
-
|
|
1423
|
-
function formatTransactionId(transactionId: number) {
|
|
1424
|
-
if (getColorDepth() < 8) {
|
|
1425
|
-
return `#${transactionId}`;
|
|
1426
|
-
}
|
|
1427
|
-
return `${TTY_COLORS.fg.magenta}#${transactionId}${TTY_COLORS.reset}`;
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
function formatStep(step: number, total: number) {
|
|
1431
|
-
return `${TTY_COLORS.bg.black}${TTY_COLORS.fg.yellow}[${step}/${total}]${TTY_COLORS.reset}`;
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
function formatMethod(method: string) {
|
|
1435
|
-
return `${TTY_COLORS.bright}${method}${TTY_COLORS.reset}`;
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
function formatAction(action: string) {
|
|
1439
|
-
return `${TTY_COLORS.dim}(${action})${TTY_COLORS.reset}`;
|
|
1440
|
-
}
|