@rolder/kit 3.0.0-alpha.11 → 3.0.0-alpha.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/index.d.ts +2 -0
- package/dist/ai/index.js +2 -0
- package/dist/ai/ui/chat/Root.d.ts +55 -0
- package/dist/ai/ui/chat/Root.js +18 -0
- package/dist/ai/ui/chat/chatInput/File.js +71 -0
- package/dist/ai/ui/chat/chatInput/FileIcon.js +43 -0
- package/dist/ai/ui/chat/chatInput/Root.d.ts +9 -0
- package/dist/ai/ui/chat/chatInput/Root.js +24 -0
- package/dist/ai/ui/chat/chatInput/Submit.js +23 -0
- package/dist/ai/ui/{promptInput → chat/chatInput}/Textarea.js +8 -7
- package/dist/ai/ui/{promptInput → chat/chatInput}/index.d.ts +2 -3
- package/dist/ai/ui/{promptInput → chat/chatInput}/index.js +2 -2
- package/dist/ai/ui/chat/chatInput/store/file.d.ts +8 -0
- package/dist/ai/ui/chat/chatInput/store/file.js +32 -0
- package/dist/ai/ui/chat/chatInput/store/fileErrorNotificaton.d.ts +2 -0
- package/dist/ai/ui/chat/chatInput/store/fileErrorNotificaton.js +21 -0
- package/dist/ai/ui/chat/chatInput/store/index.d.ts +2 -0
- package/dist/ai/ui/chat/chatInput/store/index.js +2 -0
- package/dist/ai/ui/chat/chatInput/store/input.d.ts +13 -0
- package/dist/ai/ui/chat/chatInput/store/input.js +81 -0
- package/dist/ai/ui/chat/chatInput/store/parseFile.d.ts +2 -0
- package/dist/ai/ui/chat/chatInput/store/parseFile.js +23 -0
- package/dist/ai/ui/chat/index.d.ts +12 -0
- package/dist/ai/ui/chat/index.js +15 -0
- package/dist/ai/ui/chat/messages/Empty.d.ts +4 -0
- package/dist/ai/ui/chat/messages/Empty.js +11 -0
- package/dist/ai/ui/chat/messages/Loader.d.ts +5 -0
- package/dist/ai/ui/chat/messages/Loader.js +12 -0
- package/dist/ai/ui/chat/messages/Message.d.ts +8 -0
- package/dist/ai/ui/chat/messages/Message.js +22 -0
- package/dist/ai/ui/chat/messages/Messages.d.ts +3 -0
- package/dist/ai/ui/chat/messages/Messages.js +40 -0
- package/dist/ai/ui/chat/messages/index.d.ts +2 -0
- package/dist/ai/ui/chat/messages/index.js +2 -0
- package/dist/ai/ui/chat/parts/File.d.ts +6 -0
- package/dist/ai/ui/{conversation → chat/parts}/File.js +10 -10
- package/dist/ai/ui/chat/parts/FileIcon.js +43 -0
- package/dist/ai/ui/chat/parts/PartPaper.d.ts +8 -0
- package/dist/ai/ui/chat/parts/PartPaper.js +14 -0
- package/dist/ai/ui/chat/parts/TextPart.d.ts +6 -0
- package/dist/ai/ui/chat/parts/TextPart.js +15 -0
- package/dist/ai/ui/chat/parts/ToolExecution.d.ts +7 -0
- package/dist/ai/ui/chat/parts/ToolExecution.js +56 -0
- package/dist/ai/ui/chat/parts/ToolPart.d.ts +10 -0
- package/dist/ai/ui/chat/parts/ToolPart.js +24 -0
- package/dist/ai/ui/chat/parts/index.d.ts +3 -0
- package/dist/ai/ui/chat/parts/index.js +3 -0
- package/dist/ai/ui/chat/store/index.d.ts +4 -0
- package/dist/ai/ui/chat/store/index.js +4 -0
- package/dist/ai/ui/chat/store/messages.d.ts +12 -0
- package/dist/ai/ui/chat/store/messages.js +40 -0
- package/dist/ai/ui/chat/store/send.d.ts +14 -0
- package/dist/ai/ui/chat/store/send.js +16 -0
- package/dist/ai/ui/chat/store/states.d.ts +11 -0
- package/dist/ai/ui/chat/store/states.js +20 -0
- package/dist/ai/ui/chat/store/useInitChat.d.ts +3 -0
- package/dist/ai/ui/chat/store/useInitChat.js +40 -0
- package/dist/ai/ui/index.d.ts +1 -0
- package/dist/ai/ui/index.js +1 -0
- package/dist/ai/utils/index.d.ts +2 -0
- package/dist/ai/utils/index.js +2 -0
- package/dist/app/AppDefaults.js +1 -1
- package/dist/app/DefaultApp.js +1 -1
- package/dist/app/cookieColorSchemeManager.js +1 -1
- package/dist/app/defaultTheme.d.ts +7 -7
- package/dist/app/index.d.ts +3 -0
- package/dist/app/index.js +3 -0
- package/dist/betterAuth/client/getAuthClient.d.ts +3050 -0
- package/dist/betterAuth/client/getAuthClient.js +18 -0
- package/dist/betterAuth/client/index.d.ts +1 -0
- package/dist/betterAuth/client/index.js +1 -0
- package/dist/betterAuth/index.d.ts +3 -0
- package/dist/betterAuth/index.js +3 -0
- package/dist/betterAuth/server/defaultAuthServerConfig.d.ts +452 -0
- package/dist/betterAuth/server/defaultAuthServerConfig.js +49 -0
- package/dist/betterAuth/server/env.d.ts +1 -0
- package/dist/betterAuth/server/env.js +8 -0
- package/dist/betterAuth/server/getDBSession.d.ts +2 -0
- package/dist/betterAuth/server/getDBSession.js +85 -0
- package/dist/betterAuth/server/getSessionToken.d.ts +1 -0
- package/dist/betterAuth/server/getSessionToken.js +14 -0
- package/dist/betterAuth/server/getSessionUser.d.ts +1 -0
- package/dist/betterAuth/server/getSessionUser.js +22 -0
- package/dist/betterAuth/server/index.d.ts +10 -0
- package/dist/betterAuth/server/index.js +11 -0
- package/dist/betterAuth/server/surrealDbAdapter/adapter.d.ts +8 -0
- package/dist/betterAuth/server/surrealDbAdapter/adapter.js +64 -0
- package/dist/betterAuth/server/surrealDbAdapter/adapter.test.d.ts +1 -0
- package/dist/betterAuth/server/surrealDbAdapter/adapter.test.js +84 -0
- package/dist/betterAuth/server/surrealDbAdapter/db/getDB.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/db/getDB.js +26 -0
- package/dist/betterAuth/server/surrealDbAdapter/db/index.d.ts +1 -0
- package/dist/betterAuth/server/surrealDbAdapter/db/index.js +1 -0
- package/dist/betterAuth/server/surrealDbAdapter/db/schema.d.ts +1 -0
- package/dist/betterAuth/server/surrealDbAdapter/db/schema.js +97 -0
- package/dist/betterAuth/server/surrealDbAdapter/index.d.ts +1 -0
- package/dist/betterAuth/server/surrealDbAdapter/index.js +1 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/count.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/count.js +17 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/create.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/create.js +21 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/delete.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/delete.js +18 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/deleteMany.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/deleteMany.js +19 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/findMany.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/findMany.js +51 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/findOne.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/findOne.js +42 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/index.d.ts +8 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/index.js +8 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/types.d.ts +56 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/update.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/update.js +25 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/updateMany.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/methods/updateMany.js +21 -0
- package/dist/betterAuth/server/surrealDbAdapter/types.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/applyJoinMappings.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/applyJoinMappings.js +31 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/buildExpression.d.ts +3 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/buildExpression.js +58 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/buildJoinPlan.d.ts +9 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/buildJoinPlan.js +46 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/buildSelectFields.d.ts +1 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/buildSelectFields.js +5 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/index.d.ts +6 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/index.js +6 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/normalizeOutputRecordIds.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/normalizeOutputRecordIds.js +43 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/normalizeRecordIds.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/normalizeRecordIds.js +38 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/normalizeWhereValue.d.ts +2 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/normalizeWhereValue.js +33 -0
- package/dist/betterAuth/server/surrealDbAdapter/utils/types.d.ts +34 -0
- package/dist/betterAuth/server/types.d.ts +8 -0
- package/dist/betterAuth/useSessionUser.d.ts +1 -0
- package/dist/betterAuth/useSessionUser.js +8 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/styles.css +3 -8
- package/dist/surrealDB/deafaultCrud.d.ts +2 -0
- package/dist/{surreal → surrealDB}/deafaultCrud.js +6 -5
- package/dist/surrealDB/getDBInstance.d.ts +3 -0
- package/dist/surrealDB/getDBInstance.js +34 -0
- package/dist/surrealDB/getDBInstanceTanstack.d.ts +3 -0
- package/dist/{surreal/connection.js → surrealDB/getDBInstanceTanstack.js} +2 -2
- package/dist/surrealDB/index.d.ts +6 -0
- package/dist/surrealDB/index.js +6 -0
- package/dist/{surreal/connection.d.ts → surrealDB/types.d.ts} +3 -3
- package/dist/surrealDB/types.js +0 -0
- package/dist/tanstack/cookie/index.d.ts +3 -0
- package/dist/tanstack/cookie/index.js +4 -0
- package/dist/{functions → tanstack/cookie}/setCookie.d.ts +1 -1
- package/dist/tanstack/index.d.ts +3 -0
- package/dist/tanstack/index.js +3 -0
- package/dist/tanstack/middlewares/index.d.ts +6 -0
- package/dist/tanstack/middlewares/index.js +5 -0
- package/dist/tanstack/middlewares/locale.d.ts +4 -0
- package/dist/{app/defaultRequestMiddlewares.js → tanstack/middlewares/locale.js} +2 -5
- package/dist/tanstack/s3/getS3Client.d.ts +2 -0
- package/dist/tanstack/s3/getS3Client.js +18 -0
- package/dist/tanstack/s3/getSignedFileUrlFn.d.ts +4 -0
- package/dist/tanstack/s3/getSignedFileUrlFn.js +21 -0
- package/dist/tanstack/s3/index.d.ts +2 -0
- package/dist/tanstack/s3/index.js +2 -0
- package/dist/tanstack/s3/uploadRequest.d.ts +3 -0
- package/dist/tanstack/s3/uploadRequest.js +21 -0
- package/dist/ui/AnimatedChevron.d.ts +3 -4
- package/dist/ui/AnimatedChevron.js +6 -25
- package/dist/ui/JsonInput.d.ts +1 -1
- package/dist/ui/JsonInput.js +1 -1
- package/dist/ui/editor/Content.d.ts +2 -2
- package/dist/ui/editor/Content.js +2 -2
- package/dist/ui/editor/Root.d.ts +7 -1
- package/dist/ui/editor/Root.js +42 -5
- package/dist/ui/editor/Toolbar.d.ts +3 -2
- package/dist/ui/editor/Toolbar.js +7 -25
- package/dist/ui/editor/index.d.ts +5 -9
- package/dist/ui/editor/index.js +3 -4
- package/dist/ui/editor/store.d.ts +6 -0
- package/dist/ui/editor/store.js +10 -0
- package/dist/ui/error/DefaultError.d.ts +1 -1
- package/dist/ui/error/DefaultNotFound.d.ts +1 -1
- package/dist/ui/error/Forbidden.d.ts +1 -1
- package/dist/ui/form/buttons/CancelButton.d.ts +2 -2
- package/dist/ui/form/buttons/CancelButton.js +4 -26
- package/dist/ui/form/buttons/SubmitButton.d.ts +2 -2
- package/dist/ui/form/buttons/SubmitButton.js +4 -29
- package/dist/ui/form/buttons/SubscribeActionIcon.d.ts +2 -2
- package/dist/ui/form/buttons/SubscribeButton.d.ts +2 -2
- package/dist/ui/form/context.d.ts +55 -55
- package/dist/ui/form/context.js +3 -3
- package/dist/ui/form/fields/JsonField.d.ts +1 -1
- package/dist/ui/form/fields/MultiSelectField.d.ts +1 -1
- package/dist/ui/form/fields/NumberField.d.ts +1 -1
- package/dist/ui/form/fields/PasswordField.d.ts +2 -0
- package/dist/ui/form/fields/{PassowrdField.js → PasswordField.js} +2 -2
- package/dist/ui/form/fields/SelectField.d.ts +1 -1
- package/dist/ui/form/fields/SwitchField.d.ts +1 -1
- package/dist/ui/form/fields/TextField.d.ts +1 -1
- package/dist/ui/form/fields/TextPasswordField.d.ts +2 -0
- package/dist/ui/form/fields/TextPasswordField.js +29 -0
- package/dist/ui/form/fields/TextareaField.d.ts +1 -1
- package/dist/ui/form/fields/index.d.ts +2 -2
- package/dist/ui/form/fields/index.js +2 -2
- package/dist/ui/form/index.d.ts +0 -1
- package/dist/ui/form/index.js +1 -2
- package/dist/ui/index.d.ts +9 -0
- package/dist/ui/index.js +9 -0
- package/dist/ui/saveInput/JsonInput.d.ts +2 -2
- package/dist/ui/saveInput/NumberInput.d.ts +2 -2
- package/dist/ui/saveInput/SaveInput.d.ts +14 -14
- package/dist/ui/saveInput/Select.d.ts +2 -2
- package/dist/ui/saveInput/Switch.d.ts +2 -2
- package/dist/ui/saveInput/TextInput.d.ts +2 -2
- package/dist/ui/saveInput/Textarea.d.ts +2 -2
- package/dist/ui/scrollArea/Root.d.ts +7 -0
- package/dist/ui/scrollArea/Root.js +42 -0
- package/dist/ui/scrollArea/ScrollButton.d.ts +7 -0
- package/dist/ui/scrollArea/ScrollButton.js +30 -0
- package/dist/ui/scrollArea/index.d.ts +6 -3
- package/dist/ui/scrollArea/index.js +7 -3
- package/dist/ui/scrollArea/methods.d.ts +4 -0
- package/dist/ui/scrollArea/methods.js +32 -0
- package/dist/ui/scrollArea/store.d.ts +12 -0
- package/dist/ui/scrollArea/store.js +25 -0
- package/dist/{ui/form/fieldsSchema.d.ts → zodSchemas.d.ts} +1 -1
- package/dist/{ui/form/fieldsSchema.js → zodSchemas.js} +2 -2
- package/package.json +103 -71
- package/dist/ai/ui/conversation/ConversationContext.d.ts +0 -7
- package/dist/ai/ui/conversation/ConversationContext.js +0 -8
- package/dist/ai/ui/conversation/ConversationProvider.d.ts +0 -2
- package/dist/ai/ui/conversation/ConversationProvider.js +0 -14
- package/dist/ai/ui/conversation/Empty.d.ts +0 -1
- package/dist/ai/ui/conversation/Empty.js +0 -21
- package/dist/ai/ui/conversation/File.d.ts +0 -4
- package/dist/ai/ui/conversation/FileIcon.js +0 -225
- package/dist/ai/ui/conversation/Loader.d.ts +0 -2
- package/dist/ai/ui/conversation/Loader.js +0 -12
- package/dist/ai/ui/conversation/Message.d.ts +0 -4
- package/dist/ai/ui/conversation/Message.js +0 -25
- package/dist/ai/ui/conversation/Root.d.ts +0 -2
- package/dist/ai/ui/conversation/Root.js +0 -26
- package/dist/ai/ui/conversation/index.d.ts +0 -13
- package/dist/ai/ui/conversation/index.js +0 -14
- package/dist/ai/ui/conversation/types.d.ts +0 -7
- package/dist/ai/ui/conversation/useChatMessage.d.ts +0 -2
- package/dist/ai/ui/conversation/useChatMessage.js +0 -12
- package/dist/ai/ui/promptInput/File.js +0 -117
- package/dist/ai/ui/promptInput/FileIcon.js +0 -225
- package/dist/ai/ui/promptInput/PromptInputContext.d.ts +0 -12
- package/dist/ai/ui/promptInput/PromptInputContext.js +0 -8
- package/dist/ai/ui/promptInput/PromptInputProvider.d.ts +0 -2
- package/dist/ai/ui/promptInput/PromptInputProvider.js +0 -50
- package/dist/ai/ui/promptInput/Root.d.ts +0 -3
- package/dist/ai/ui/promptInput/Root.js +0 -17
- package/dist/ai/ui/promptInput/Submit.js +0 -40
- package/dist/ai/ui/promptInput/types.d.ts +0 -11
- package/dist/app/defaultRequestMiddlewares.d.ts +0 -4
- package/dist/index.d.ts +0 -26
- package/dist/index.js +0 -26
- package/dist/surreal/deafaultCrud.d.ts +0 -2
- package/dist/ui/editor/Provider.d.ts +0 -17
- package/dist/ui/editor/Provider.js +0 -80
- package/dist/ui/editor/types.d.ts +0 -7
- package/dist/ui/form/fields/PassowrdField.d.ts +0 -2
- package/dist/ui/form/fields/TextPassowrdField.d.ts +0 -2
- package/dist/ui/form/fields/TextPassowrdField.js +0 -51
- package/dist/ui/scrollArea/ScrollArea.d.ts +0 -62
- package/dist/ui/scrollArea/ScrollArea.js +0 -30
- package/dist/ui/scrollArea/ScrollAreaButton.d.ts +0 -5
- package/dist/ui/scrollArea/ScrollAreaButton.js +0 -51
- package/dist/ui/scrollArea/ScrollAreaContent.d.ts +0 -6
- package/dist/ui/scrollArea/ScrollAreaContent.js +0 -29
- package/dist/ui/scrollArea/context.d.ts +0 -28
- package/dist/ui/scrollArea/context.js +0 -10
- package/dist/ui/scrollArea/types.d.ts +0 -65
- package/dist/ui/scrollArea/useScrollArea.d.ts +0 -9
- package/dist/ui/scrollArea/useScrollArea.js +0 -146
- /package/dist/ai/ui/{promptInput → chat/chatInput}/File.d.ts +0 -0
- /package/dist/ai/ui/{conversation → chat/chatInput}/FileIcon.d.ts +0 -0
- /package/dist/ai/ui/{promptInput → chat/chatInput}/Footer.d.ts +0 -0
- /package/dist/ai/ui/{promptInput → chat/chatInput}/Footer.js +0 -0
- /package/dist/ai/ui/{promptInput → chat/chatInput}/Submit.d.ts +0 -0
- /package/dist/ai/ui/{promptInput → chat/chatInput}/Textarea.d.ts +0 -0
- /package/dist/ai/ui/{promptInput → chat/parts}/FileIcon.d.ts +0 -0
- /package/dist/{ai/ui/conversation → betterAuth/server/surrealDbAdapter/methods}/types.js +0 -0
- /package/dist/{ai/ui/promptInput → betterAuth/server/surrealDbAdapter}/types.js +0 -0
- /package/dist/{ui/editor → betterAuth/server/surrealDbAdapter/utils}/types.js +0 -0
- /package/dist/{ui/scrollArea → betterAuth/server}/types.js +0 -0
- /package/dist/{surreal → surrealDB}/deserialize.d.ts +0 -0
- /package/dist/{surreal → surrealDB}/deserialize.js +0 -0
- /package/dist/{surreal → surrealDB}/encryption.d.ts +0 -0
- /package/dist/{surreal → surrealDB}/encryption.js +0 -0
- /package/dist/{functions → tanstack/cookie}/getCookie.d.ts +0 -0
- /package/dist/{functions → tanstack/cookie}/getCookie.js +0 -0
- /package/dist/{functions → tanstack/cookie}/setCookie.js +0 -0
- /package/dist/{functions → tanstack/cookie}/setCookies.d.ts +0 -0
- /package/dist/{functions → tanstack/cookie}/setCookies.js +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
2
|
+
import { getRequestHeaders } from "@tanstack/react-start/server";
|
|
3
|
+
import { baseUrl } from "./env.js";
|
|
4
|
+
const getSessionUserFn = createServerFn().handler(async ()=>{
|
|
5
|
+
try {
|
|
6
|
+
const headers = getRequestHeaders();
|
|
7
|
+
const sessionResponse = await fetch(`${baseUrl}/api/auth/get-session`, {
|
|
8
|
+
headers: {
|
|
9
|
+
cookie: headers.get('cookie') || ''
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
if (!sessionResponse.ok) throw new Error('Failed to get auth session');
|
|
13
|
+
const session = await sessionResponse.json();
|
|
14
|
+
return session?.user;
|
|
15
|
+
} catch (_) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
async function getSessionUser() {
|
|
20
|
+
return await getSessionUserFn();
|
|
21
|
+
}
|
|
22
|
+
export { getSessionUser };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from 'better-auth/client/plugins';
|
|
2
|
+
export { betterAuth as betterAuthServer } from 'better-auth/minimal';
|
|
3
|
+
export * from 'better-auth/plugins';
|
|
4
|
+
export * from 'better-auth/plugins/admin/access';
|
|
5
|
+
export * from 'better-auth/react';
|
|
6
|
+
export { tanstackStartCookies } from 'better-auth/tanstack-start';
|
|
7
|
+
export * from './defaultAuthServerConfig';
|
|
8
|
+
export * from './getDBSession';
|
|
9
|
+
export * from './getSessionUser';
|
|
10
|
+
export * from './types';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { betterAuth } from "better-auth/minimal";
|
|
2
|
+
import { tanstackStartCookies } from "better-auth/tanstack-start";
|
|
3
|
+
export * from "better-auth/client/plugins";
|
|
4
|
+
export * from "better-auth/plugins";
|
|
5
|
+
export * from "better-auth/plugins/admin/access";
|
|
6
|
+
export * from "better-auth/react";
|
|
7
|
+
export * from "./defaultAuthServerConfig.js";
|
|
8
|
+
export * from "./getDBSession.js";
|
|
9
|
+
export * from "./getSessionUser.js";
|
|
10
|
+
export * from "./types.js";
|
|
11
|
+
export { betterAuth as betterAuthServer, tanstackStartCookies };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type DBAdapterDebugLogOption } from 'better-auth/adapters';
|
|
2
|
+
import type { SurrealDBProps } from '../../../surrealDB/types';
|
|
3
|
+
type SurrealAdapterConfig = {
|
|
4
|
+
surrealDbProps?: SurrealDBProps;
|
|
5
|
+
debugLogs?: DBAdapterDebugLogOption | boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const surrealDbAdapter: ({ surrealDbProps, debugLogs, }?: SurrealAdapterConfig | undefined) => (options: Parameters<import("better-auth/adapters").AdapterFactory>[0]) => import("better-auth").DBAdapter<import("better-auth").BetterAuthOptions>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createAdapterFactory } from "better-auth/adapters";
|
|
2
|
+
import { count, create, deleteFn, deleteMany, findMany, findOne, update, updateMany } from "./methods/index.js";
|
|
3
|
+
const surrealDbAdapter = ({ surrealDbProps, debugLogs } = {})=>{
|
|
4
|
+
const adapterCreator = createAdapterFactory({
|
|
5
|
+
config: {
|
|
6
|
+
adapterId: 'surrealdb',
|
|
7
|
+
adapterName: 'SurrealDB Adapter',
|
|
8
|
+
usePlural: false,
|
|
9
|
+
supportsJSON: true,
|
|
10
|
+
supportsArrays: true,
|
|
11
|
+
supportsDates: true,
|
|
12
|
+
supportsBooleans: true,
|
|
13
|
+
supportsUUIDs: true,
|
|
14
|
+
debugLogs: debugLogs ?? false
|
|
15
|
+
},
|
|
16
|
+
adapter: (a)=>({
|
|
17
|
+
create: (p)=>create({
|
|
18
|
+
...p,
|
|
19
|
+
...a,
|
|
20
|
+
surrealDbProps
|
|
21
|
+
}),
|
|
22
|
+
update: (p)=>update({
|
|
23
|
+
...p,
|
|
24
|
+
...a,
|
|
25
|
+
surrealDbProps
|
|
26
|
+
}),
|
|
27
|
+
updateMany: (p)=>updateMany({
|
|
28
|
+
...p,
|
|
29
|
+
...a,
|
|
30
|
+
surrealDbProps
|
|
31
|
+
}),
|
|
32
|
+
findOne: (p)=>findOne({
|
|
33
|
+
...p,
|
|
34
|
+
...a,
|
|
35
|
+
surrealDbProps
|
|
36
|
+
}),
|
|
37
|
+
findMany: (p)=>findMany({
|
|
38
|
+
...p,
|
|
39
|
+
...a,
|
|
40
|
+
surrealDbProps
|
|
41
|
+
}),
|
|
42
|
+
delete: (p)=>deleteFn({
|
|
43
|
+
...p,
|
|
44
|
+
...a,
|
|
45
|
+
surrealDbProps
|
|
46
|
+
}),
|
|
47
|
+
deleteMany: (p)=>deleteMany({
|
|
48
|
+
...p,
|
|
49
|
+
...a,
|
|
50
|
+
surrealDbProps
|
|
51
|
+
}),
|
|
52
|
+
count: (p)=>count({
|
|
53
|
+
...p,
|
|
54
|
+
...a,
|
|
55
|
+
surrealDbProps
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
return (options)=>{
|
|
60
|
+
const safeOptions = options ?? {};
|
|
61
|
+
return adapterCreator(safeOptions);
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export { surrealDbAdapter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { runAdapterTest } from "better-auth/adapters/test";
|
|
4
|
+
import { Table, surql } from "surrealdb";
|
|
5
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
6
|
+
import { getDBInstance } from "../../../surrealDB/index.js";
|
|
7
|
+
import { surrealDbAdapter } from "./adapter.js";
|
|
8
|
+
const hasDbEnv = ()=>Boolean(process.env.SURREALDB_URL && process.env.SURREALDB_NAMESPACE && process.env.SURREALDB_USERNAME && process.env.SURREALDB_PASSWORD);
|
|
9
|
+
afterAll(async ()=>{
|
|
10
|
+
const db = await getDBInstance({
|
|
11
|
+
database: 'test'
|
|
12
|
+
});
|
|
13
|
+
await db.query(surql`DELETE ${new Table('session')}`).collect();
|
|
14
|
+
await db.query(surql`DELETE ${new Table('account')}`).collect();
|
|
15
|
+
await db.query(surql`DELETE ${new Table('verification')}`).collect();
|
|
16
|
+
await db.query(surql`DELETE ${new Table('user')}`).collect();
|
|
17
|
+
await db.close();
|
|
18
|
+
});
|
|
19
|
+
describe.skipIf(!hasDbEnv())('surrealdb adapter', ()=>{
|
|
20
|
+
beforeAll(async ()=>{
|
|
21
|
+
const db = await getDBInstance({
|
|
22
|
+
database: 'test'
|
|
23
|
+
});
|
|
24
|
+
const schemaPath = node_path.resolve('src/back/auth/surrealdb/schema.surql');
|
|
25
|
+
const schema = await readFile(schemaPath, 'utf8');
|
|
26
|
+
await db.query(schema).collect();
|
|
27
|
+
await db.query(surql`DELETE ${new Table('session')}`).collect();
|
|
28
|
+
await db.query(surql`DELETE ${new Table('account')}`).collect();
|
|
29
|
+
await db.query(surql`DELETE ${new Table('verification')}`).collect();
|
|
30
|
+
await db.query(surql`DELETE ${new Table('user')}`).collect();
|
|
31
|
+
});
|
|
32
|
+
runAdapterTest({
|
|
33
|
+
testPrefix: 'surrealdb',
|
|
34
|
+
getAdapter: async (options)=>surrealDbAdapter()(options ?? {})
|
|
35
|
+
});
|
|
36
|
+
it('supports experimental joins via computed fields', async ()=>{
|
|
37
|
+
const adapter = surrealDbAdapter()({
|
|
38
|
+
experimental: {
|
|
39
|
+
joins: true
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const user = await adapter.create({
|
|
43
|
+
model: 'user',
|
|
44
|
+
data: {
|
|
45
|
+
name: 'Join User',
|
|
46
|
+
email: `join-${Date.now()}@example.com`,
|
|
47
|
+
emailVerified: true,
|
|
48
|
+
createdAt: new Date(),
|
|
49
|
+
updatedAt: new Date()
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const account = await adapter.create({
|
|
53
|
+
model: 'account',
|
|
54
|
+
data: {
|
|
55
|
+
userId: user.id,
|
|
56
|
+
accountId: `join-${Date.now()}`,
|
|
57
|
+
providerId: 'credential',
|
|
58
|
+
createdAt: new Date(),
|
|
59
|
+
updatedAt: new Date()
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const joined = await adapter.findOne({
|
|
63
|
+
model: 'user',
|
|
64
|
+
where: [
|
|
65
|
+
{
|
|
66
|
+
field: 'id',
|
|
67
|
+
value: user.id
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
join: {
|
|
71
|
+
account: true
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
expect(joined?.account).toBeTruthy();
|
|
75
|
+
expect(Array.isArray(joined?.account)).toBe(true);
|
|
76
|
+
expect(joined?.account?.length).toBe(1);
|
|
77
|
+
expect(joined?.account?.[0]?.id).toBe(account.id);
|
|
78
|
+
const db = await getDBInstance({
|
|
79
|
+
database: 'test'
|
|
80
|
+
});
|
|
81
|
+
await db.query(surql`DELETE ${new Table('account')} WHERE id = ${account.id}`).collect();
|
|
82
|
+
await db.query(surql`DELETE ${new Table('user')} WHERE id = ${user.id}`).collect();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createServerOnlyFn } from "@tanstack/react-start";
|
|
2
|
+
import { getDBInstance } from "../../../../surrealDB/index.js";
|
|
3
|
+
import { baseUrl } from "../../env.js";
|
|
4
|
+
import { schema } from "./schema.js";
|
|
5
|
+
let schemaApplied = false;
|
|
6
|
+
let schemaApplying = false;
|
|
7
|
+
const ensureAuthSchema = async (props = {})=>{
|
|
8
|
+
if (schemaApplied) return;
|
|
9
|
+
if (!schemaApplying) try {
|
|
10
|
+
schemaApplying = true;
|
|
11
|
+
const db = await getDBInstance(props);
|
|
12
|
+
const betterAuthJwksUrl = `${baseUrl}/api/auth/jwks`;
|
|
13
|
+
await db.query(schema, {
|
|
14
|
+
BETTER_AUTH_JWKS_URL: betterAuthJwksUrl
|
|
15
|
+
});
|
|
16
|
+
schemaApplied = true;
|
|
17
|
+
} finally{
|
|
18
|
+
schemaApplying = false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const getDb = createServerOnlyFn(async (props = {})=>{
|
|
22
|
+
const db = await getDBInstance(props);
|
|
23
|
+
await ensureAuthSchema(props);
|
|
24
|
+
return db;
|
|
25
|
+
});
|
|
26
|
+
export { getDb };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getDB';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./getDB.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const schema = "\n-- Better Auth JWT Access\n-- URL \u043F\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044F \u0447\u0435\u0440\u0435\u0437 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440 $BETTER_AUTH_JWKS_URL \u043F\u0440\u0438 \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u0438 \u0441\u0445\u0435\u043C\u044B\nDEFINE ACCESS IF NOT EXISTS better_auth_jwt\n ON DATABASE\n TYPE JWT\n URL $BETTER_AUTH_JWKS_URL\n;\n\n// User\nDEFINE TABLE IF NOT EXISTS user TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS name ON user TYPE string;\nDEFINE FIELD OVERWRITE email ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);\nDEFINE FIELD OVERWRITE email_address ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);\nDEFINE INDEX IF NOT EXISTS userUserUnique ON user COLUMNS email UNIQUE;\nDEFINE FIELD IF NOT EXISTS emailVerified ON user TYPE bool;\nDEFINE FIELD IF NOT EXISTS image ON user TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS createdAt ON user TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON user TYPE option<datetime> DEFAULT time::now();\n-- Admin plugin\nDEFINE FIELD IF NOT EXISTS role ON user TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS banned ON user TYPE option<bool>;\nDEFINE FIELD IF NOT EXISTS banReason ON user TYPE option<string> | NULL;\nDEFINE FIELD IF NOT EXISTS banExpires ON user TYPE option<datetime> | NULL;\n-- Username plugin\nDEFINE FIELD OVERWRITE username ON user TYPE option<string>;\nDEFINE FIELD OVERWRITE displayUsername ON user TYPE option<string>;\n-- Custom\nDEFINE FIELD IF NOT EXISTS accounts ON user COMPUTED <~account;\nDEFINE FIELD IF NOT EXISTS sessions ON user COMPUTED <~session;\n\n-- // Session\nDEFINE TABLE IF NOT EXISTS session TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS expiresAt ON session TYPE datetime;\nDEFINE FIELD IF NOT EXISTS token ON session TYPE string;\nDEFINE INDEX IF NOT EXISTS sessionSessionUnique ON session COLUMNS token UNIQUE;\nDEFINE FIELD IF NOT EXISTS createdAt ON session TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON session TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS ipAddress ON session TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS userAgent ON session TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS userId ON session TYPE record<user> REFERENCE ON DELETE IGNORE;\n-- Admin plugin\nDEFINE FIELD IF NOT EXISTS impersonatedBy ON user TYPE option<record<user>>;\n\n-- // Account\nDEFINE TABLE IF NOT EXISTS account TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS accountId ON account TYPE string;\nDEFINE FIELD IF NOT EXISTS providerId ON account TYPE string;\nDEFINE FIELD IF NOT EXISTS accessToken ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS refreshToken ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS idToken ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS accessTokenExpiresAt ON account TYPE option<datetime>;\nDEFINE FIELD IF NOT EXISTS refreshTokenExpiresAt ON account TYPE option<datetime>;\nDEFINE FIELD IF NOT EXISTS scope ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS password ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS createdAt ON account TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON account TYPE option<datetime> DEFAULT time::now();\n-- Custom\nDEFINE FIELD IF NOT EXISTS userId ON account TYPE record<user> REFERENCE ON DELETE IGNORE;\n\n// Verification\nDEFINE TABLE IF NOT EXISTS verification TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS identifier ON verification TYPE string;\nDEFINE FIELD IF NOT EXISTS value ON verification TYPE string;\nDEFINE FIELD IF NOT EXISTS expiresAt ON verification TYPE datetime;\nDEFINE FIELD IF NOT EXISTS createdAt ON verification TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON verification TYPE option<datetime> DEFAULT time::now();\n\n// JWKS\nDEFINE TABLE IF NOT EXISTS jwks TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS publicKey ON jwks TYPE string;\nDEFINE FIELD IF NOT EXISTS privateKey ON jwks TYPE string;\nDEFINE FIELD IF NOT EXISTS createdAt ON jwks TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON jwks TYPE option<datetime> DEFAULT time::now();\n\n// Root auth user\nIF !user:root.* {\n CREATE user:root CONTENT {\n \tname: '\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u0430\u044F \u0443\u0447\u0435\u0442\u043D\u0430\u044F \u0437\u0430\u043F\u0438\u0441\u044C',\n \trole: 'admin',\n \tusername: 'root',\n \tdisplayUsername: 'Root',\n \temail: 'mail@rolder.dev',\n \temailVerified: true,\n \tbanned: false,\n };\n};\n\nIF !account:root.* {\n CREATE account:root CONTENT {\n \taccountId: 'root',\n \tuserId: user:root,\n \tpassword: '52c2da6bc1a525ee0f6a298e228a1314:c7ba714b9467d4582c5848947c2536340ff9f85ff6ca6c9ee022f68cd5eb60e227ba0cbadd3d46e9316c4562cef9d7551c957192809bf2a4b27f2a2b1365a08e',\n providerId: 'credential',\n };\n};";
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const schema = `
|
|
2
|
+
-- Better Auth JWT Access
|
|
3
|
+
-- URL передается через параметр $BETTER_AUTH_JWKS_URL при выполнении схемы
|
|
4
|
+
DEFINE ACCESS IF NOT EXISTS better_auth_jwt
|
|
5
|
+
ON DATABASE
|
|
6
|
+
TYPE JWT
|
|
7
|
+
URL $BETTER_AUTH_JWKS_URL
|
|
8
|
+
;
|
|
9
|
+
|
|
10
|
+
// User
|
|
11
|
+
DEFINE TABLE IF NOT EXISTS user TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
|
|
12
|
+
DEFINE FIELD IF NOT EXISTS name ON user TYPE string;
|
|
13
|
+
DEFINE FIELD OVERWRITE email ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);
|
|
14
|
+
DEFINE FIELD OVERWRITE email_address ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);
|
|
15
|
+
DEFINE INDEX IF NOT EXISTS userUserUnique ON user COLUMNS email UNIQUE;
|
|
16
|
+
DEFINE FIELD IF NOT EXISTS emailVerified ON user TYPE bool;
|
|
17
|
+
DEFINE FIELD IF NOT EXISTS image ON user TYPE option<string>;
|
|
18
|
+
DEFINE FIELD IF NOT EXISTS createdAt ON user TYPE option<datetime> DEFAULT time::now();
|
|
19
|
+
DEFINE FIELD IF NOT EXISTS updatedAt ON user TYPE option<datetime> DEFAULT time::now();
|
|
20
|
+
-- Admin plugin
|
|
21
|
+
DEFINE FIELD IF NOT EXISTS role ON user TYPE option<string>;
|
|
22
|
+
DEFINE FIELD IF NOT EXISTS banned ON user TYPE option<bool>;
|
|
23
|
+
DEFINE FIELD IF NOT EXISTS banReason ON user TYPE option<string> | NULL;
|
|
24
|
+
DEFINE FIELD IF NOT EXISTS banExpires ON user TYPE option<datetime> | NULL;
|
|
25
|
+
-- Username plugin
|
|
26
|
+
DEFINE FIELD OVERWRITE username ON user TYPE option<string>;
|
|
27
|
+
DEFINE FIELD OVERWRITE displayUsername ON user TYPE option<string>;
|
|
28
|
+
-- Custom
|
|
29
|
+
DEFINE FIELD IF NOT EXISTS accounts ON user COMPUTED <~account;
|
|
30
|
+
DEFINE FIELD IF NOT EXISTS sessions ON user COMPUTED <~session;
|
|
31
|
+
|
|
32
|
+
-- // Session
|
|
33
|
+
DEFINE TABLE IF NOT EXISTS session TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
|
|
34
|
+
DEFINE FIELD IF NOT EXISTS expiresAt ON session TYPE datetime;
|
|
35
|
+
DEFINE FIELD IF NOT EXISTS token ON session TYPE string;
|
|
36
|
+
DEFINE INDEX IF NOT EXISTS sessionSessionUnique ON session COLUMNS token UNIQUE;
|
|
37
|
+
DEFINE FIELD IF NOT EXISTS createdAt ON session TYPE option<datetime> DEFAULT time::now();
|
|
38
|
+
DEFINE FIELD IF NOT EXISTS updatedAt ON session TYPE option<datetime> DEFAULT time::now();
|
|
39
|
+
DEFINE FIELD IF NOT EXISTS ipAddress ON session TYPE option<string>;
|
|
40
|
+
DEFINE FIELD IF NOT EXISTS userAgent ON session TYPE option<string>;
|
|
41
|
+
DEFINE FIELD IF NOT EXISTS userId ON session TYPE record<user> REFERENCE ON DELETE IGNORE;
|
|
42
|
+
-- Admin plugin
|
|
43
|
+
DEFINE FIELD IF NOT EXISTS impersonatedBy ON user TYPE option<record<user>>;
|
|
44
|
+
|
|
45
|
+
-- // Account
|
|
46
|
+
DEFINE TABLE IF NOT EXISTS account TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
|
|
47
|
+
DEFINE FIELD IF NOT EXISTS accountId ON account TYPE string;
|
|
48
|
+
DEFINE FIELD IF NOT EXISTS providerId ON account TYPE string;
|
|
49
|
+
DEFINE FIELD IF NOT EXISTS accessToken ON account TYPE option<string>;
|
|
50
|
+
DEFINE FIELD IF NOT EXISTS refreshToken ON account TYPE option<string>;
|
|
51
|
+
DEFINE FIELD IF NOT EXISTS idToken ON account TYPE option<string>;
|
|
52
|
+
DEFINE FIELD IF NOT EXISTS accessTokenExpiresAt ON account TYPE option<datetime>;
|
|
53
|
+
DEFINE FIELD IF NOT EXISTS refreshTokenExpiresAt ON account TYPE option<datetime>;
|
|
54
|
+
DEFINE FIELD IF NOT EXISTS scope ON account TYPE option<string>;
|
|
55
|
+
DEFINE FIELD IF NOT EXISTS password ON account TYPE option<string>;
|
|
56
|
+
DEFINE FIELD IF NOT EXISTS createdAt ON account TYPE option<datetime> DEFAULT time::now();
|
|
57
|
+
DEFINE FIELD IF NOT EXISTS updatedAt ON account TYPE option<datetime> DEFAULT time::now();
|
|
58
|
+
-- Custom
|
|
59
|
+
DEFINE FIELD IF NOT EXISTS userId ON account TYPE record<user> REFERENCE ON DELETE IGNORE;
|
|
60
|
+
|
|
61
|
+
// Verification
|
|
62
|
+
DEFINE TABLE IF NOT EXISTS verification TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
|
|
63
|
+
DEFINE FIELD IF NOT EXISTS identifier ON verification TYPE string;
|
|
64
|
+
DEFINE FIELD IF NOT EXISTS value ON verification TYPE string;
|
|
65
|
+
DEFINE FIELD IF NOT EXISTS expiresAt ON verification TYPE datetime;
|
|
66
|
+
DEFINE FIELD IF NOT EXISTS createdAt ON verification TYPE option<datetime> DEFAULT time::now();
|
|
67
|
+
DEFINE FIELD IF NOT EXISTS updatedAt ON verification TYPE option<datetime> DEFAULT time::now();
|
|
68
|
+
|
|
69
|
+
// JWKS
|
|
70
|
+
DEFINE TABLE IF NOT EXISTS jwks TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
|
|
71
|
+
DEFINE FIELD IF NOT EXISTS publicKey ON jwks TYPE string;
|
|
72
|
+
DEFINE FIELD IF NOT EXISTS privateKey ON jwks TYPE string;
|
|
73
|
+
DEFINE FIELD IF NOT EXISTS createdAt ON jwks TYPE option<datetime> DEFAULT time::now();
|
|
74
|
+
DEFINE FIELD IF NOT EXISTS updatedAt ON jwks TYPE option<datetime> DEFAULT time::now();
|
|
75
|
+
|
|
76
|
+
// Root auth user
|
|
77
|
+
IF !user:root.* {
|
|
78
|
+
CREATE user:root CONTENT {
|
|
79
|
+
name: 'Системная учетная запись',
|
|
80
|
+
role: 'admin',
|
|
81
|
+
username: 'root',
|
|
82
|
+
displayUsername: 'Root',
|
|
83
|
+
email: 'mail@rolder.dev',
|
|
84
|
+
emailVerified: true,
|
|
85
|
+
banned: false,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
IF !account:root.* {
|
|
90
|
+
CREATE account:root CONTENT {
|
|
91
|
+
accountId: 'root',
|
|
92
|
+
userId: user:root,
|
|
93
|
+
password: '52c2da6bc1a525ee0f6a298e228a1314:c7ba714b9467d4582c5848947c2536340ff9f85ff6ca6c9ee022f68cd5eb60e227ba0cbadd3d46e9316c4562cef9d7551c957192809bf2a4b27f2a2b1365a08e',
|
|
94
|
+
providerId: 'credential',
|
|
95
|
+
};
|
|
96
|
+
};`;
|
|
97
|
+
export { schema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './adapter';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./adapter.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Table, surql } from "surrealdb";
|
|
2
|
+
import { getDb } from "../db/index.js";
|
|
3
|
+
import { buildExpression } from "../utils/index.js";
|
|
4
|
+
const count = async ({ model, where, surrealDbProps, ...args })=>{
|
|
5
|
+
const db = await getDb(surrealDbProps);
|
|
6
|
+
const table = new Table(model);
|
|
7
|
+
const expression = buildExpression({
|
|
8
|
+
model,
|
|
9
|
+
where,
|
|
10
|
+
...args
|
|
11
|
+
});
|
|
12
|
+
const query = surql`SELECT count() AS count FROM ${table}`;
|
|
13
|
+
if (expression) query.append(surql` WHERE ${expression}`);
|
|
14
|
+
const [rows] = await db.query(query).json().collect();
|
|
15
|
+
return rows?.[0]?.count ?? 0;
|
|
16
|
+
};
|
|
17
|
+
export { count };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RecordId, Table, surql } from "surrealdb";
|
|
2
|
+
import { getDb } from "../db/index.js";
|
|
3
|
+
import { normalizeOutputRecordIds, normalizeRecordIds } from "../utils/index.js";
|
|
4
|
+
const create = async ({ model, data, surrealDbProps, ...args })=>{
|
|
5
|
+
const db = await getDb(surrealDbProps);
|
|
6
|
+
const { id, ...content } = data;
|
|
7
|
+
const normalized = normalizeRecordIds({
|
|
8
|
+
model,
|
|
9
|
+
data: content,
|
|
10
|
+
...args
|
|
11
|
+
});
|
|
12
|
+
const hasId = null != id;
|
|
13
|
+
const target = hasId ? new RecordId(model, String(id)) : new Table(model);
|
|
14
|
+
const [rows] = await db.query(surql`CREATE ${target} CONTENT ${normalized} RETURN AFTER`).json().collect();
|
|
15
|
+
return normalizeOutputRecordIds({
|
|
16
|
+
model,
|
|
17
|
+
data: rows?.[0] ?? null,
|
|
18
|
+
...args
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export { create };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Table, surql } from "surrealdb";
|
|
2
|
+
import { getDb } from "../db/index.js";
|
|
3
|
+
import { buildExpression } from "../utils/index.js";
|
|
4
|
+
const deleteFn = async ({ model, where, surrealDbProps, ...args })=>{
|
|
5
|
+
if (!where || 0 === where.length) throw new Error('Delete requires a where clause');
|
|
6
|
+
const db = await getDb(surrealDbProps);
|
|
7
|
+
const table = new Table(model);
|
|
8
|
+
const expression = buildExpression({
|
|
9
|
+
model,
|
|
10
|
+
where,
|
|
11
|
+
...args
|
|
12
|
+
});
|
|
13
|
+
const query = surql`DELETE FROM ${table}`;
|
|
14
|
+
if (expression) query.append(surql` WHERE ${expression}`);
|
|
15
|
+
query.append(surql` RETURN BEFORE`);
|
|
16
|
+
await db.query(query);
|
|
17
|
+
};
|
|
18
|
+
export { deleteFn };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Table, surql } from "surrealdb";
|
|
2
|
+
import { getDb } from "../db/index.js";
|
|
3
|
+
import { buildExpression } from "../utils/index.js";
|
|
4
|
+
const deleteMany = async ({ model, where, surrealDbProps, ...args })=>{
|
|
5
|
+
if (!where || 0 === where.length) throw new Error('DeleteMany requires a where clause');
|
|
6
|
+
const db = await getDb(surrealDbProps);
|
|
7
|
+
const table = new Table(model);
|
|
8
|
+
const expression = buildExpression({
|
|
9
|
+
model,
|
|
10
|
+
where,
|
|
11
|
+
...args
|
|
12
|
+
});
|
|
13
|
+
const query = surql`DELETE FROM ${table}`;
|
|
14
|
+
if (expression) query.append(surql` WHERE ${expression}`);
|
|
15
|
+
query.append(surql` RETURN BEFORE`);
|
|
16
|
+
const [rows] = await db.query(query).json().collect();
|
|
17
|
+
return rows?.length ?? 0;
|
|
18
|
+
};
|
|
19
|
+
export { deleteMany };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Table, raw, surql } from "surrealdb";
|
|
2
|
+
import { getDb } from "../db/index.js";
|
|
3
|
+
import { applyJoinMappings, buildExpression, buildJoinPlan, buildSelectFields, normalizeOutputRecordIds } from "../utils/index.js";
|
|
4
|
+
const findMany = async ({ model, where, limit, offset, sortBy, join, surrealDbProps, ...args })=>{
|
|
5
|
+
const db = await getDb(surrealDbProps);
|
|
6
|
+
const table = new Table(model);
|
|
7
|
+
const expression = buildExpression({
|
|
8
|
+
model,
|
|
9
|
+
where,
|
|
10
|
+
...args
|
|
11
|
+
});
|
|
12
|
+
const joinPlan = buildJoinPlan({
|
|
13
|
+
model,
|
|
14
|
+
join,
|
|
15
|
+
...args
|
|
16
|
+
});
|
|
17
|
+
const fields = buildSelectFields(void 0, (field)=>args.getFieldName({
|
|
18
|
+
model,
|
|
19
|
+
field
|
|
20
|
+
}));
|
|
21
|
+
const baseFields = fields.split(', ');
|
|
22
|
+
const joinFields = joinPlan.selectFields.filter((field)=>!baseFields.includes(field));
|
|
23
|
+
const finalFields = [
|
|
24
|
+
...baseFields,
|
|
25
|
+
...joinFields
|
|
26
|
+
].join(', ');
|
|
27
|
+
const query = surql`SELECT ${raw(finalFields)} FROM ${table}`;
|
|
28
|
+
if (expression) query.append(surql` WHERE ${expression}`);
|
|
29
|
+
if (sortBy) {
|
|
30
|
+
const orderField = args.getFieldName({
|
|
31
|
+
model,
|
|
32
|
+
field: sortBy.field
|
|
33
|
+
});
|
|
34
|
+
const direction = sortBy.direction.toUpperCase();
|
|
35
|
+
query.append(surql` ORDER BY ${raw(orderField)} ${raw(direction)}`);
|
|
36
|
+
}
|
|
37
|
+
if ('number' == typeof offset) query.append(surql` START ${offset}`);
|
|
38
|
+
query.append(surql` LIMIT ${limit}`);
|
|
39
|
+
if (joinPlan.fetchFields.size > 0) query.append(surql` FETCH ${raw(Array.from(joinPlan.fetchFields).join(', '))}`);
|
|
40
|
+
const [rows] = await db.query(query).json().collect();
|
|
41
|
+
return (rows ?? []).map((row)=>normalizeOutputRecordIds({
|
|
42
|
+
model,
|
|
43
|
+
data: applyJoinMappings({
|
|
44
|
+
row,
|
|
45
|
+
mappings: joinPlan.mappings,
|
|
46
|
+
...args
|
|
47
|
+
}),
|
|
48
|
+
...args
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
export { findMany };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Table, raw, surql } from "surrealdb";
|
|
2
|
+
import { getDb } from "../db/index.js";
|
|
3
|
+
import { applyJoinMappings, buildExpression, buildJoinPlan, buildSelectFields, normalizeOutputRecordIds } from "../utils/index.js";
|
|
4
|
+
const findOne = async ({ model, where, select, join, surrealDbProps, ...args })=>{
|
|
5
|
+
const db = await getDb(surrealDbProps);
|
|
6
|
+
const table = new Table(model);
|
|
7
|
+
const expression = buildExpression({
|
|
8
|
+
model,
|
|
9
|
+
where,
|
|
10
|
+
...args
|
|
11
|
+
});
|
|
12
|
+
const joinPlan = buildJoinPlan({
|
|
13
|
+
model,
|
|
14
|
+
join,
|
|
15
|
+
...args
|
|
16
|
+
});
|
|
17
|
+
const fields = buildSelectFields(select, (field)=>args.getFieldName({
|
|
18
|
+
model,
|
|
19
|
+
field
|
|
20
|
+
}));
|
|
21
|
+
const baseFields = fields.split(', ');
|
|
22
|
+
const joinFields = joinPlan.selectFields.filter((field)=>!baseFields.includes(field));
|
|
23
|
+
const finalFields = [
|
|
24
|
+
...baseFields,
|
|
25
|
+
...joinFields
|
|
26
|
+
].join(', ');
|
|
27
|
+
const query = surql`SELECT ${raw(finalFields)} FROM ${table}`;
|
|
28
|
+
if (expression) query.append(surql` WHERE ${expression}`);
|
|
29
|
+
query.append(surql` LIMIT ${1}`);
|
|
30
|
+
if (joinPlan.fetchFields.size > 0) query.append(surql` FETCH ${raw(Array.from(joinPlan.fetchFields).join(', '))}`);
|
|
31
|
+
const [rows] = await db.query(query).json().collect();
|
|
32
|
+
return normalizeOutputRecordIds({
|
|
33
|
+
model,
|
|
34
|
+
data: applyJoinMappings({
|
|
35
|
+
row: rows?.[0] ?? null,
|
|
36
|
+
mappings: joinPlan.mappings,
|
|
37
|
+
...args
|
|
38
|
+
}),
|
|
39
|
+
...args
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
export { findOne };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AdapterFactoryCustomizeAdapterCreator, JoinConfig, Where } from 'better-auth/adapters';
|
|
2
|
+
import type { SurrealDBProps } from '../../../../surrealDB/types';
|
|
3
|
+
type Args = Parameters<AdapterFactoryCustomizeAdapterCreator>[0];
|
|
4
|
+
export type Create<T> = Args & {
|
|
5
|
+
model: string;
|
|
6
|
+
data: T;
|
|
7
|
+
surrealDbProps?: SurrealDBProps;
|
|
8
|
+
};
|
|
9
|
+
export type FindOne = Args & {
|
|
10
|
+
model: string;
|
|
11
|
+
where: Required<Where>[];
|
|
12
|
+
select?: string[];
|
|
13
|
+
join?: JoinConfig;
|
|
14
|
+
surrealDbProps?: SurrealDBProps;
|
|
15
|
+
};
|
|
16
|
+
export type SortBy = {
|
|
17
|
+
field: string;
|
|
18
|
+
direction: 'asc' | 'desc';
|
|
19
|
+
};
|
|
20
|
+
export type FindMany = Args & {
|
|
21
|
+
model: string;
|
|
22
|
+
where?: Required<Where>[];
|
|
23
|
+
limit: number;
|
|
24
|
+
offset?: number;
|
|
25
|
+
sortBy?: SortBy;
|
|
26
|
+
join?: JoinConfig;
|
|
27
|
+
surrealDbProps?: SurrealDBProps;
|
|
28
|
+
};
|
|
29
|
+
export type Update<T> = Args & {
|
|
30
|
+
model: string;
|
|
31
|
+
where: Required<Where>[];
|
|
32
|
+
update: T;
|
|
33
|
+
surrealDbProps?: SurrealDBProps;
|
|
34
|
+
};
|
|
35
|
+
export type UpdateMany = Args & {
|
|
36
|
+
model: string;
|
|
37
|
+
where: Required<Where>[];
|
|
38
|
+
update: Record<string, unknown>;
|
|
39
|
+
surrealDbProps?: SurrealDBProps;
|
|
40
|
+
};
|
|
41
|
+
export type Delete = Args & {
|
|
42
|
+
model: string;
|
|
43
|
+
where: Required<Where>[];
|
|
44
|
+
surrealDbProps?: SurrealDBProps;
|
|
45
|
+
};
|
|
46
|
+
export type DeleteMany = Args & {
|
|
47
|
+
model: string;
|
|
48
|
+
where: Required<Where>[];
|
|
49
|
+
surrealDbProps?: SurrealDBProps;
|
|
50
|
+
};
|
|
51
|
+
export type Count = Args & {
|
|
52
|
+
model: string;
|
|
53
|
+
where?: Required<Where>[];
|
|
54
|
+
surrealDbProps?: SurrealDBProps;
|
|
55
|
+
};
|
|
56
|
+
export {};
|