Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Implement message handlers
Hakan Shehu2210306d32c2
diff --git a/desktop/src/main/mediator.ts b/desktop/src/main/mediator.tsindex c257f889..1bed5251 100644--- a/desktop/src/main/mediator.ts+++ b/desktop/src/main/mediator.ts@@ -13,6 +13,8 @@ import {} from '@/types/queries';import { queryHandlerMap } from '@/main/queries';import { eventBus } from '@/lib/event-bus';+import { MessageHandler, MessageInput } from '@/operations/messages';+import { messageHandlerMap } from '@/main/messages';class Mediator {private readonly subscribedQueries: Map<string, SubscribedQuery<QueryInput>> =@@ -24,8 +26,8 @@ class Mediator {const handler = mutationHandlerMap[input.type] as MutationHandler<T>;const result = await handler.handleMutation(input);- if (result.changedTables) {- await this.checkForQueryChanges(result.changedTables);+ if (result.changes) {+ await this.checkForQueryChanges(result.changes);}return result.output;@@ -52,6 +54,11 @@ class Mediator {return result.output;}+ public async executeMessage<T extends MessageInput>(input: T): Promise<void> {+ const handler = messageHandlerMap[input.type] as MessageHandler<T>;+ await handler.handleMessage(input);+ }+public unsubscribeQuery(id: string) {this.subscribedQueries.delete(id);}diff --git a/desktop/src/main/messages/index.ts b/desktop/src/main/messages/index.tsnew file mode 100644index 00000000..53239b29--- /dev/null+++ b/desktop/src/main/messages/index.ts@@ -0,0 +1,10 @@+import { MessageHandler, MessageMap } from '@/operations/messages';+import { ServerMutationMessageHandler } from '@/main/messages/server-mutation';++type MessageHandlerMap = {+ [K in keyof MessageMap]: MessageHandler<MessageMap[K]>;+};++export const messageHandlerMap: MessageHandlerMap = {+ server_mutation: new ServerMutationMessageHandler(),+};diff --git a/desktop/src/main/messages/server-mutation.ts b/desktop/src/main/messages/server-mutation.tsnew file mode 100644index 00000000..7dc9f649--- /dev/null+++ b/desktop/src/main/messages/server-mutation.ts@@ -0,0 +1,47 @@+import { MessageHandler } from '@/operations/messages';+import { ServerMutationMessageInput } from '@/operations/messages/server-mutation';+import { mediator } from '@/main/mediator';++export class ServerMutationMessageHandler+ implements MessageHandler<ServerMutationMessageInput>+{+ public async handleMessage(input: ServerMutationMessageInput): Promise<void> {+ if (input.mutation.table === 'nodes' && input.mutation.workspaceId) {+ await mediator.executeMutation({+ type: 'node_sync',+ id: input.mutation.id,+ accountId: input.accountId,+ workspaceId: input.mutation.workspaceId,+ action: input.mutation.action,+ after: input.mutation.after,+ before: input.mutation.before,+ });+ } else if (+ input.mutation.table === 'node_reactions' &&+ input.mutation.workspaceId+ ) {+ await mediator.executeMutation({+ type: 'node_reaction_sync',+ id: input.mutation.id,+ accountId: input.accountId,+ workspaceId: input.mutation.workspaceId,+ action: input.mutation.action,+ after: input.mutation.after,+ before: input.mutation.before,+ });+ } else if (+ input.mutation.table === 'node_collaborator' &&+ input.mutation.workspaceId+ ) {+ await mediator.executeMutation({+ type: 'node_collaborator_sync',+ id: input.mutation.id,+ accountId: input.accountId,+ workspaceId: input.mutation.workspaceId,+ action: input.mutation.action,+ after: input.mutation.after,+ before: input.mutation.before,+ });+ }+ }+}diff --git a/desktop/src/main/mutations/board-view-create.ts b/desktop/src/main/mutations/board-view-create.tsindex 36e6b147..f47ced81 100644--- a/desktop/src/main/mutations/board-view-create.ts+++ b/desktop/src/main/mutations/board-view-create.ts@@ -16,10 +16,6 @@ export class BoardViewCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const siblings = await workspaceDatabase.selectFrom('nodes').where((eb) =>@@ -60,7 +56,7 @@ export class BoardViewCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/calendar-view-create.ts b/desktop/src/main/mutations/calendar-view-create.tsindex b41dba08..779a85c0 100644--- a/desktop/src/main/mutations/calendar-view-create.ts+++ b/desktop/src/main/mutations/calendar-view-create.ts@@ -16,10 +16,6 @@ export class CalendarViewCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const siblings = await workspaceDatabase.selectFrom('nodes').where((eb) =>@@ -60,7 +56,7 @@ export class CalendarViewCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/channel-create.ts b/desktop/src/main/mutations/channel-create.tsindex 3bdb9df1..2713436e 100644--- a/desktop/src/main/mutations/channel-create.ts+++ b/desktop/src/main/mutations/channel-create.ts@@ -16,10 +16,6 @@ export class ChannelCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const siblings = await workspaceDatabase.selectFrom('nodes').selectAll()@@ -55,7 +51,7 @@ export class ChannelCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/chat-create.ts b/desktop/src/main/mutations/chat-create.tsindex 08603ba1..2510da1c 100644--- a/desktop/src/main/mutations/chat-create.ts+++ b/desktop/src/main/mutations/chat-create.ts@@ -8,17 +8,13 @@ import { ChatCreateMutationInput } from '@/types/mutations/chat-create';export class ChatCreateMutationHandlerimplements MutationHandler<ChatCreateMutationInput>{- async handleMutation(+ public async handleMutation(input: ChatCreateMutationInput,): Promise<MutationResult<ChatCreateMutationInput>> {const workspaceDatabase = await databaseContext.getWorkspaceDatabase(input.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const existingChats = await workspaceDatabase.selectFrom('nodes').selectAll()@@ -88,7 +84,7 @@ export class ChatCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/database-create.ts b/desktop/src/main/mutations/database-create.tsindex a3d9d3d7..e3243990 100644--- a/desktop/src/main/mutations/database-create.ts+++ b/desktop/src/main/mutations/database-create.ts@@ -16,10 +16,6 @@ export class DatabaseCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const siblings = await workspaceDatabase.selectFrom('nodes').selectAll()@@ -84,7 +80,7 @@ export class DatabaseCreateMutationHandleroutput: {id: databaseId,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/email-login.ts b/desktop/src/main/mutations/email-login.tsindex 86ce2b82..4faf013d 100644--- a/desktop/src/main/mutations/email-login.ts+++ b/desktop/src/main/mutations/email-login.ts@@ -88,7 +88,7 @@ export class EmailLoginMutationHandleroutput: {success: true,},- changedTables: changedTables,+ changes: changedTables,};}}diff --git a/desktop/src/main/mutations/email-register.ts b/desktop/src/main/mutations/email-register.tsindex dc1a14b6..1c0a4182 100644--- a/desktop/src/main/mutations/email-register.ts+++ b/desktop/src/main/mutations/email-register.ts@@ -90,7 +90,7 @@ export class EmailRegisterMutationHandleroutput: {success: true,},- changedTables: changedTables,+ changes: changedTables,};};}diff --git a/desktop/src/main/mutations/field-create.ts b/desktop/src/main/mutations/field-create.tsindex 83fc03b2..a7888976 100644--- a/desktop/src/main/mutations/field-create.ts+++ b/desktop/src/main/mutations/field-create.ts@@ -16,10 +16,6 @@ export class FieldCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const siblings = await workspaceDatabase.selectFrom('nodes').where((eb) =>@@ -62,7 +58,7 @@ export class FieldCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/index.ts b/desktop/src/main/mutations/index.tsindex 6add8ee3..fe76c833 100644--- a/desktop/src/main/mutations/index.ts+++ b/desktop/src/main/mutations/index.ts@@ -26,6 +26,9 @@ import { WorkspaceAccountRoleUpdateMutationHandler } from '@/main/mutations/workimport { WorkspaceAccountsInviteMutationHandler } from '@/main/mutations/workspace-accounts-invite';import { WorkspaceCreateMutationHandler } from '@/main/mutations/workspace-create';import { WorkspaceUpdateMutationHandler } from '@/main/mutations/workspace-update';+import { NodeSyncMutationHandler } from '@/main/mutations/node-sync';+import { NodeReactionSyncMutationHandler } from '@/main/mutations/node-reaction-sync';+import { NodeCollaboratorSyncMutationHandler } from '@/main/mutations/node-collaborator-sync';type MutationHandlerMap = {[K in keyof MutationMap]: MutationHandler<MutationMap[K]['input']>;@@ -60,4 +63,7 @@ export const mutationHandlerMap: MutationHandlerMap = {workspace_accounts_invite: new WorkspaceAccountsInviteMutationHandler(),workspace_create: new WorkspaceCreateMutationHandler(),workspace_update: new WorkspaceUpdateMutationHandler(),+ node_sync: new NodeSyncMutationHandler(),+ node_reaction_sync: new NodeReactionSyncMutationHandler(),+ node_collaborator_sync: new NodeCollaboratorSyncMutationHandler(),};diff --git a/desktop/src/main/mutations/message-create.ts b/desktop/src/main/mutations/message-create.tsindex 4f13a9dd..ef2663e8 100644--- a/desktop/src/main/mutations/message-create.ts+++ b/desktop/src/main/mutations/message-create.ts@@ -18,10 +18,6 @@ export class MessageCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const id = NeuronId.generate(NeuronId.Type.Message);const editorNodes = mapContentsToEditorNodes(input.content.content,@@ -60,7 +56,7 @@ export class MessageCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/node-attribute-delete.ts b/desktop/src/main/mutations/node-attribute-delete.tsindex 1f10d2cd..8347aa65 100644--- a/desktop/src/main/mutations/node-attribute-delete.ts+++ b/desktop/src/main/mutations/node-attribute-delete.ts@@ -15,10 +15,6 @@ export class NodeAttributeDeleteMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const node = await workspaceDatabase.selectFrom('nodes').where('id', '=', input.nodeId)@@ -64,7 +60,7 @@ export class NodeAttributeDeleteMutationHandleroutput: {success: true,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/node-attribute-set.ts b/desktop/src/main/mutations/node-attribute-set.tsindex ca583b09..b5705737 100644--- a/desktop/src/main/mutations/node-attribute-set.ts+++ b/desktop/src/main/mutations/node-attribute-set.ts@@ -15,10 +15,6 @@ export class NodeAttributeSetMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const node = await workspaceDatabase.selectFrom('nodes').where('id', '=', input.nodeId)@@ -57,7 +53,7 @@ export class NodeAttributeSetMutationHandleroutput: {success: true,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/node-collaborator-create.ts b/desktop/src/main/mutations/node-collaborator-create.tsindex ac853145..91ef13b2 100644--- a/desktop/src/main/mutations/node-collaborator-create.ts+++ b/desktop/src/main/mutations/node-collaborator-create.ts@@ -13,10 +13,6 @@ export class NodeCollaboratorCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-await workspaceDatabase.insertInto('node_collaborators').values([@@ -38,7 +34,7 @@ export class NodeCollaboratorCreateMutationHandleroutput: {success: true,},- changedTables: [+ changes: [{type: 'workspace',table: 'node_collaborators',diff --git a/desktop/src/main/mutations/node-collaborator-delete.ts b/desktop/src/main/mutations/node-collaborator-delete.tsindex 89a7530a..83c920b3 100644--- a/desktop/src/main/mutations/node-collaborator-delete.ts+++ b/desktop/src/main/mutations/node-collaborator-delete.ts@@ -12,10 +12,6 @@ export class NodeCollaboratorDeleteMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-await workspaceDatabase.deleteFrom('node_collaborators').where((eb) =>@@ -30,7 +26,7 @@ export class NodeCollaboratorDeleteMutationHandleroutput: {success: true,},- changedTables: [+ changes: [{type: 'workspace',table: 'node_collaborators',diff --git a/desktop/src/main/mutations/node-collaborator-sync.ts b/desktop/src/main/mutations/node-collaborator-sync.tsnew file mode 100644index 00000000..c1fde91e--- /dev/null+++ b/desktop/src/main/mutations/node-collaborator-sync.ts@@ -0,0 +1,160 @@+import { databaseContext } from '@/main/data/database-context';+import { MutationHandler, MutationResult } from '@/types/mutations';+import { NodeCollaboratorSyncMutationInput } from '@/types/mutations/node-collaborator-sync';+import { ServerNodeCollaborator, ServerNodeReaction } from '@/types/nodes';++export class NodeCollaboratorSyncMutationHandler+ implements MutationHandler<NodeCollaboratorSyncMutationInput>+{+ public async handleMutation(+ input: NodeCollaboratorSyncMutationInput,+ ): Promise<MutationResult<NodeCollaboratorSyncMutationInput>> {+ const workspace = await databaseContext.appDatabase+ .selectFrom('workspaces')+ .selectAll()+ .where((eb) =>+ eb.and([+ eb('account_id', '=', input.accountId),+ eb('workspace_id', '=', input.workspaceId),+ ]),+ )+ .executeTakeFirst();++ if (!workspace) {+ return {+ output: {+ success: false,+ },+ };+ }++ const userId = workspace.user_id;+ if (input.action === 'insert' && input.after) {+ await this.insertNodeCollaborator(userId, input.after);+ } else if (input.action === 'update' && input.after) {+ await this.updateNodeCollaborator(userId, input.after);+ } else if (input.action === 'delete' && input.before) {+ await this.deleteNodeReaction(userId, input.before);+ }++ return {+ output: {+ success: true,+ },+ changes: [+ {+ type: 'workspace',+ table: 'node_collaborators',+ userId: userId,+ },+ ],+ };+ }++ private async insertNodeCollaborator(+ userId: string,+ nodeCollaborator: ServerNodeCollaborator,+ ): Promise<void> {+ const workspaceDatabase =+ await databaseContext.getWorkspaceDatabase(userId);++ await workspaceDatabase+ .insertInto('node_collaborators')+ .values({+ node_id: nodeCollaborator.nodeId,+ collaborator_id: nodeCollaborator.collaboratorId,+ role: nodeCollaborator.role,+ created_at: nodeCollaborator.createdAt,+ created_by: nodeCollaborator.createdBy,+ updated_by: nodeCollaborator.updatedBy,+ updated_at: nodeCollaborator.updatedAt,+ version_id: nodeCollaborator.versionId,+ server_created_at: nodeCollaborator.serverCreatedAt,+ server_updated_at: nodeCollaborator.serverUpdatedAt,+ server_version_id: nodeCollaborator.versionId,+ })+ .onConflict((cb) =>+ cb+ .doUpdateSet({+ server_created_at: nodeCollaborator.serverCreatedAt,+ server_updated_at: nodeCollaborator.serverUpdatedAt,+ server_version_id: nodeCollaborator.versionId,+ })+ .where('version_id', '=', nodeCollaborator.versionId),+ )+ .execute();+ }++ private async updateNodeCollaborator(+ userId: string,+ nodeCollaborator: ServerNodeCollaborator,+ ): Promise<void> {+ const workspaceDatabase =+ await databaseContext.getWorkspaceDatabase(userId);++ const existingNodeCollaborator = await workspaceDatabase+ .selectFrom('node_collaborators')+ .selectAll()+ .where((eb) =>+ eb.and([+ eb('node_id', '=', nodeCollaborator.nodeId),+ eb('collaborator_id', '=', nodeCollaborator.collaboratorId),+ ]),+ )+ .executeTakeFirst();++ if (+ existingNodeCollaborator.server_version_id === nodeCollaborator.versionId+ ) {+ return;+ }++ if (existingNodeCollaborator.updated_at) {+ if (!nodeCollaborator.updatedAt) {+ return;+ }+ const localUpdatedAt = new Date(existingNodeCollaborator.updated_at);+ const serverUpdatedAt = new Date(nodeCollaborator.updatedAt);+ if (localUpdatedAt > serverUpdatedAt) {+ return;+ }+ }++ await workspaceDatabase+ .updateTable('node_collaborators')+ .set({+ role: nodeCollaborator.role,+ updated_at: nodeCollaborator.updatedAt,+ updated_by: nodeCollaborator.updatedBy,+ version_id: nodeCollaborator.versionId,+ server_created_at: nodeCollaborator.serverCreatedAt,+ server_updated_at: nodeCollaborator.serverUpdatedAt,+ server_version_id: nodeCollaborator.versionId,+ })+ .where((eb) =>+ eb.and([+ eb('node_id', '=', nodeCollaborator.nodeId),+ eb('collaborator_id', '=', nodeCollaborator.collaboratorId),+ ]),+ )+ .execute();+ }++ private async deleteNodeReaction(+ userId: string,+ nodeCollaborator: ServerNodeCollaborator,+ ): Promise<void> {+ const workspaceDatabase =+ await databaseContext.getWorkspaceDatabase(userId);++ await workspaceDatabase+ .deleteFrom('node_collaborators')+ .where((eb) =>+ eb.and([+ eb('node_id', '=', nodeCollaborator.nodeId),+ eb('collaborator_id', '=', nodeCollaborator.collaboratorId),+ ]),+ )+ .execute();+ }+}diff --git a/desktop/src/main/mutations/node-collaborator-update.ts b/desktop/src/main/mutations/node-collaborator-update.tsindex 1bc1f2af..63c43c9b 100644--- a/desktop/src/main/mutations/node-collaborator-update.ts+++ b/desktop/src/main/mutations/node-collaborator-update.ts@@ -13,10 +13,6 @@ export class NodeCollaboratorUpdateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-await workspaceDatabase.updateTable('node_collaborators').set({@@ -37,7 +33,7 @@ export class NodeCollaboratorUpdateMutationHandleroutput: {success: true,},- changedTables: [+ changes: [{type: 'workspace',table: 'node_collaborators',diff --git a/desktop/src/main/mutations/node-delete.ts b/desktop/src/main/mutations/node-delete.tsindex ddd888aa..93d1d9ca 100644--- a/desktop/src/main/mutations/node-delete.ts+++ b/desktop/src/main/mutations/node-delete.ts@@ -12,10 +12,6 @@ export class NodeDeleteMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-await workspaceDatabase.deleteFrom('nodes').where('id', '=', input.nodeId)@@ -25,7 +21,7 @@ export class NodeDeleteMutationHandleroutput: {success: true,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/node-reaction-create.ts b/desktop/src/main/mutations/node-reaction-create.tsindex b1233e64..ebbd144b 100644--- a/desktop/src/main/mutations/node-reaction-create.ts+++ b/desktop/src/main/mutations/node-reaction-create.ts@@ -13,10 +13,6 @@ export class NodeReactionCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-await workspaceDatabase.insertInto('node_reactions').values({@@ -32,7 +28,7 @@ export class NodeReactionCreateMutationHandleroutput: {success: true,},- changedTables: [+ changes: [{type: 'workspace',table: 'node_reactions',diff --git a/desktop/src/main/mutations/node-reaction-delete.ts b/desktop/src/main/mutations/node-reaction-delete.tsindex 2f9f5eec..c0b37100 100644--- a/desktop/src/main/mutations/node-reaction-delete.ts+++ b/desktop/src/main/mutations/node-reaction-delete.ts@@ -12,10 +12,6 @@ export class NodeReactionDeleteMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-await workspaceDatabase.deleteFrom('node_reactions').where((eb) =>@@ -31,7 +27,7 @@ export class NodeReactionDeleteMutationHandleroutput: {success: true,},- changedTables: [+ changes: [{type: 'workspace',table: 'node_reactions',diff --git a/desktop/src/main/mutations/node-reaction-sync.ts b/desktop/src/main/mutations/node-reaction-sync.tsnew file mode 100644index 00000000..7453d5f2--- /dev/null+++ b/desktop/src/main/mutations/node-reaction-sync.ts@@ -0,0 +1,94 @@+import { databaseContext } from '@/main/data/database-context';+import { MutationHandler, MutationResult } from '@/types/mutations';+import { NodeReactionSyncMutationInput } from '@/types/mutations/node-reaction-sync';+import { ServerNodeReaction } from '@/types/nodes';++export class NodeReactionSyncMutationHandler+ implements MutationHandler<NodeReactionSyncMutationInput>+{+ public async handleMutation(+ input: NodeReactionSyncMutationInput,+ ): Promise<MutationResult<NodeReactionSyncMutationInput>> {+ const workspace = await databaseContext.appDatabase+ .selectFrom('workspaces')+ .selectAll()+ .where((eb) =>+ eb.and([+ eb('account_id', '=', input.accountId),+ eb('workspace_id', '=', input.workspaceId),+ ]),+ )+ .executeTakeFirst();++ if (!workspace) {+ return {+ output: {+ success: false,+ },+ };+ }++ const userId = workspace.user_id;+ if (input.action === 'insert' && input.after) {+ await this.insertNodeReaction(userId, input.after);+ } else if (input.action === 'delete' && input.before) {+ await this.deleteNodeReaction(userId, input.before);+ }++ return {+ output: {+ success: true,+ },+ changes: [+ {+ type: 'workspace',+ table: 'node_reactions',+ userId: userId,+ },+ ],+ };+ }++ private async insertNodeReaction(+ userId: string,+ nodeReaction: ServerNodeReaction,+ ): Promise<void> {+ const workspaceDatabase =+ await databaseContext.getWorkspaceDatabase(userId);++ await workspaceDatabase+ .insertInto('node_reactions')+ .values({+ node_id: nodeReaction.nodeId,+ actor_id: nodeReaction.actorId,+ reaction: nodeReaction.reaction,+ created_at: nodeReaction.createdAt,+ server_created_at: nodeReaction.serverCreatedAt,+ })+ .onConflict((ob) =>+ ob.doUpdateSet({+ server_created_at: nodeReaction.serverCreatedAt,+ }),+ )+ .execute();+ }++ private async deleteNodeReaction(+ userId: string,+ nodeReaction: ServerNodeReaction,+ ): Promise<void> {+ const workspaceDatabase =+ await databaseContext.getWorkspaceDatabase(userId);++ await workspaceDatabase+ .deleteFrom('node_reactions')+ .where((eb) =>+ eb.and([+ eb('node_id', '=', nodeReaction.nodeId),+ eb('actor_id', '=', nodeReaction.actorId),+ eb('reaction', '=', nodeReaction.reaction),+ ]),+ )+ .execute();+ }+}diff --git a/desktop/src/main/mutations/node-sync.ts b/desktop/src/main/mutations/node-sync.tsnew file mode 100644index 00000000..608f1e16--- /dev/null+++ b/desktop/src/main/mutations/node-sync.ts@@ -0,0 +1,137 @@+import { databaseContext } from '@/main/data/database-context';+import { MutationHandler, MutationResult } from '@/types/mutations';+import { NodeSyncMutationInput } from '@/types/mutations/node-sync';+import { ServerNode } from '@/types/nodes';+import { fromUint8Array, toUint8Array } from 'js-base64';+import * as Y from 'yjs';++export class NodeSyncMutationHandler+ implements MutationHandler<NodeSyncMutationInput>+{+ public async handleMutation(+ input: NodeSyncMutationInput,+ ): Promise<MutationResult<NodeSyncMutationInput>> {+ const workspace = await databaseContext.appDatabase+ .selectFrom('workspaces')+ .selectAll()+ .where((eb) =>+ eb.and([+ eb('account_id', '=', input.accountId),+ eb('workspace_id', '=', input.workspaceId),+ ]),+ )+ .executeTakeFirst();++ if (!workspace) {+ return {+ output: {+ success: false,+ },+ };+ }++ const userId = workspace.user_id;+ if (input.action === 'insert' && input.after) {+ await this.insertNode(userId, input.after);+ } else if (input.action === 'update' && input.after) {+ await this.updateNode(userId, input.after);+ } else if (input.action === 'delete' && input.before) {+ await this.deleteNode(userId, input.before);+ }++ return {+ output: {+ success: true,+ },+ changes: [+ {+ type: 'workspace',+ table: 'nodes',+ userId: userId,+ },+ ],+ };+ }++ private async insertNode(userId: string, node: ServerNode): Promise<void> {+ const workspaceDatabase =+ await databaseContext.getWorkspaceDatabase(userId);++ await workspaceDatabase+ .insertInto('nodes')+ .values({+ id: node.id,+ attributes: JSON.stringify(node.attributes),+ state: node.state,+ created_at: node.createdAt,+ created_by: node.createdBy,+ updated_by: node.updatedBy,+ updated_at: node.updatedAt,+ version_id: node.versionId,+ server_created_at: node.serverCreatedAt,+ server_updated_at: node.serverUpdatedAt,+ server_version_id: node.versionId,+ })+ .onConflict((cb) =>+ cb+ .doUpdateSet({+ server_created_at: node.serverCreatedAt,+ server_updated_at: node.serverUpdatedAt,+ server_version_id: node.versionId,+ })+ .where('version_id', '=', node.versionId),+ )+ .execute();+ }++ private async updateNode(userId: string, node: ServerNode): Promise<void> {+ const workspaceDatabase =+ await databaseContext.getWorkspaceDatabase(userId);++ const existingNode = await workspaceDatabase+ .selectFrom('nodes')+ .selectAll()+ .where('id', '=', node.id)+ .executeTakeFirst();++ if (existingNode.version_id === node.versionId) {+ return;+ }++ const doc = new Y.Doc({+ guid: node.id,+ });++ Y.applyUpdate(doc, toUint8Array(existingNode.state));+ Y.applyUpdate(doc, toUint8Array(node.state));++ const attributesMap = doc.getMap('attributes');+ const attributes = JSON.stringify(attributesMap.toJSON());+ const encodedState = fromUint8Array(Y.encodeStateAsUpdate(doc));++ await workspaceDatabase+ .updateTable('nodes')+ .set({+ attributes: attributes,+ state: encodedState,+ updated_at: node.updatedAt,+ updated_by: node.updatedBy,+ version_id: node.versionId,+ server_created_at: node.serverCreatedAt,+ server_updated_at: node.serverUpdatedAt,+ server_version_id: node.versionId,+ })+ .where('id', '=', node.id)+ .execute();+ }++ private async deleteNode(userId: string, node: ServerNode): Promise<void> {+ const workspaceDatabase =+ await databaseContext.getWorkspaceDatabase(userId);++ await workspaceDatabase+ .deleteFrom('nodes')+ .where('id', '=', node.id)+ .execute();+ }+}diff --git a/desktop/src/main/mutations/page-create.ts b/desktop/src/main/mutations/page-create.tsindex 0d7291b2..e17a33d2 100644--- a/desktop/src/main/mutations/page-create.ts+++ b/desktop/src/main/mutations/page-create.ts@@ -16,10 +16,6 @@ export class PageCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const siblings = await workspaceDatabase.selectFrom('nodes').selectAll()@@ -55,7 +51,7 @@ export class PageCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/record-create.ts b/desktop/src/main/mutations/record-create.tsindex fc68e9cd..1fcaf868 100644--- a/desktop/src/main/mutations/record-create.ts+++ b/desktop/src/main/mutations/record-create.ts@@ -15,10 +15,6 @@ export class RecordCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const lastChild = await workspaceDatabase.selectFrom('nodes').selectAll()@@ -56,7 +52,7 @@ export class RecordCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/select-option-create.ts b/desktop/src/main/mutations/select-option-create.tsindex 1240c42d..1c5e67da 100644--- a/desktop/src/main/mutations/select-option-create.ts+++ b/desktop/src/main/mutations/select-option-create.ts@@ -15,10 +15,6 @@ export class SelectOptionCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const lastChild = await workspaceDatabase.selectFrom('nodes').selectAll()@@ -57,7 +53,7 @@ export class SelectOptionCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/server-create.ts b/desktop/src/main/mutations/server-create.tsindex a22ec93c..71acb73c 100644--- a/desktop/src/main/mutations/server-create.ts+++ b/desktop/src/main/mutations/server-create.ts@@ -30,7 +30,7 @@ export class ServerCreateMutationHandleroutput: {success: true,},- changedTables: [+ changes: [{type: 'app',table: 'servers',diff --git a/desktop/src/main/mutations/space-create.ts b/desktop/src/main/mutations/space-create.tsindex 1155b154..98048492 100644--- a/desktop/src/main/mutations/space-create.ts+++ b/desktop/src/main/mutations/space-create.ts@@ -15,10 +15,6 @@ export class SpaceCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const spaceId = NeuronId.generate(NeuronId.Type.Space);const pageId = NeuronId.generate(NeuronId.Type.Page);const channelId = NeuronId.generate(NeuronId.Type.Channel);@@ -71,7 +67,7 @@ export class SpaceCreateMutationHandleroutput: {id: spaceId,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/table-view-create.ts b/desktop/src/main/mutations/table-view-create.tsindex cb38f76a..b2a6c440 100644--- a/desktop/src/main/mutations/table-view-create.ts+++ b/desktop/src/main/mutations/table-view-create.ts@@ -16,10 +16,6 @@ export class TableViewCreateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const siblings = await workspaceDatabase.selectFrom('nodes').where((eb) =>@@ -60,7 +56,7 @@ export class TableViewCreateMutationHandleroutput: {id: id,},- changedTables: [+ changes: [{type: 'workspace',table: 'nodes',diff --git a/desktop/src/main/mutations/workspace-account-role-update.ts b/desktop/src/main/mutations/workspace-account-role-update.tsindex bdd433f7..54a07ff0 100644--- a/desktop/src/main/mutations/workspace-account-role-update.ts+++ b/desktop/src/main/mutations/workspace-account-role-update.ts@@ -74,10 +74,6 @@ export class WorkspaceAccountRoleUpdateMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-await workspaceDatabase.updateTable('nodes').set({@@ -103,7 +99,7 @@ export class WorkspaceAccountRoleUpdateMutationHandleroutput: {success: true,},- changedTables: changedTables,+ changes: changedTables,};}}diff --git a/desktop/src/main/mutations/workspace-accounts-invite.ts b/desktop/src/main/mutations/workspace-accounts-invite.tsindex 59dab2e6..af6d6da3 100644--- a/desktop/src/main/mutations/workspace-accounts-invite.ts+++ b/desktop/src/main/mutations/workspace-accounts-invite.ts@@ -75,10 +75,6 @@ export class WorkspaceAccountsInviteMutationHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const usersToCreate: CreateNode[] = data.users.map((user) => {return {id: user.id,@@ -113,7 +109,7 @@ export class WorkspaceAccountsInviteMutationHandleroutput: {success: true,},- changedTables: changedTables,+ changes: changedTables,};}}diff --git a/desktop/src/main/mutations/workspace-create.ts b/desktop/src/main/mutations/workspace-create.tsindex 01a78e5e..37bc3f99 100644--- a/desktop/src/main/mutations/workspace-create.ts+++ b/desktop/src/main/mutations/workspace-create.ts@@ -76,7 +76,7 @@ export class WorkspaceCreateMutationHandleroutput: {id: data.id,},- changedTables: changedTables,+ changes: changedTables,};}}diff --git a/desktop/src/main/mutations/workspace-update.ts b/desktop/src/main/mutations/workspace-update.tsindex d307bee2..3129a8ef 100644--- a/desktop/src/main/mutations/workspace-update.ts+++ b/desktop/src/main/mutations/workspace-update.ts@@ -72,7 +72,7 @@ export class WorkspaceUpdateMutationHandleroutput: {success: true,},- changedTables: changedTables,+ changes: changedTables,};}}diff --git a/desktop/src/main/queries/breadcrumb-list.ts b/desktop/src/main/queries/breadcrumb-list.tsindex 89a8fcbb..16b3ebce 100644--- a/desktop/src/main/queries/breadcrumb-list.ts+++ b/desktop/src/main/queries/breadcrumb-list.ts@@ -66,10 +66,6 @@ export class BreadcrumbListQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const query = sql<SelectNode>`WITH RECURSIVE breadcrumb_nodes AS (SELECT *diff --git a/desktop/src/main/queries/database-get.ts b/desktop/src/main/queries/database-get.tsindex a2423a94..a00c6f0a 100644--- a/desktop/src/main/queries/database-get.ts+++ b/desktop/src/main/queries/database-get.ts@@ -73,10 +73,6 @@ export class DatabaseGetQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const query = sql<SelectNode>`WITH database_node AS (SELECT *diff --git a/desktop/src/main/queries/database-view-list.ts b/desktop/src/main/queries/database-view-list.tsindex fe44ecd2..1f452781 100644--- a/desktop/src/main/queries/database-view-list.ts+++ b/desktop/src/main/queries/database-view-list.ts@@ -72,10 +72,6 @@ export class DatabaseViewListQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const rows = await workspaceDatabase.selectFrom('nodes').selectAll()diff --git a/desktop/src/main/queries/document-get.ts b/desktop/src/main/queries/document-get.tsindex f97e9623..e2e8cb89 100644--- a/desktop/src/main/queries/document-get.ts+++ b/desktop/src/main/queries/document-get.ts@@ -71,10 +71,6 @@ export class DocumentGetQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const query = sql<SelectNode>`WITH RECURSIVE document_nodes AS (SELECT *diff --git a/desktop/src/main/queries/message-list.ts b/desktop/src/main/queries/message-list.tsindex 54ee95b6..77173804 100644--- a/desktop/src/main/queries/message-list.ts+++ b/desktop/src/main/queries/message-list.ts@@ -75,10 +75,6 @@ export class MessageListQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const offset = input.page * input.count;const query = sql<MessageRow>`WITH message_nodes AS (diff --git a/desktop/src/main/queries/node-collaborator-list.tsx b/desktop/src/main/queries/node-collaborator-list.tsxindex 0404238a..1f0d2af4 100644--- a/desktop/src/main/queries/node-collaborator-list.tsx+++ b/desktop/src/main/queries/node-collaborator-list.tsx@@ -79,10 +79,6 @@ export class NodeCollaboratorListQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const query = sql<NodeCollaboratorRow>`WITH RECURSIVE ancestors(id, parent_id, level) AS (SELECT id, parent_id, 0 AS leveldiff --git a/desktop/src/main/queries/node-collaborator-search.ts b/desktop/src/main/queries/node-collaborator-search.tsindex 0ef9fe3e..498538a8 100644--- a/desktop/src/main/queries/node-collaborator-search.ts+++ b/desktop/src/main/queries/node-collaborator-search.ts@@ -66,10 +66,6 @@ export class NodeCollaboratorSearchQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const query = sql<SelectNode>`SELECT n.*FROM nodes ndiff --git a/desktop/src/main/queries/node-get.ts b/desktop/src/main/queries/node-get.tsindex df78e1d8..d9716a94 100644--- a/desktop/src/main/queries/node-get.ts+++ b/desktop/src/main/queries/node-get.ts@@ -60,10 +60,6 @@ export class NodeGetQueryHandler implements QueryHandler<NodeGetQueryInput> {input.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const row = await workspaceDatabase.selectFrom('nodes').selectAll()diff --git a/desktop/src/main/queries/record-get.ts b/desktop/src/main/queries/record-get.tsindex 8a02d4c5..bf3d2703 100644--- a/desktop/src/main/queries/record-get.ts+++ b/desktop/src/main/queries/record-get.ts@@ -65,10 +65,6 @@ export class RecordGetQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const query = sql<SelectNode>`WITH record_node AS (SELECT *diff --git a/desktop/src/main/queries/record-list.ts b/desktop/src/main/queries/record-list.tsindex 13c52b88..5b4f2015 100644--- a/desktop/src/main/queries/record-list.ts+++ b/desktop/src/main/queries/record-list.ts@@ -88,10 +88,6 @@ export class RecordListQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const database = await this.fetchDatabase(input.userId, input.databaseId);const filterQuery = this.buildFiltersQuery(input.filters, database.fields);const orderByQuery = `ORDER BY ${input.sorts.length > 0 ? this.buildSortOrdersQuery(input.sorts, database.fields) : 'n."index" ASC'}`;diff --git a/desktop/src/main/queries/sidebar-chat-list.ts b/desktop/src/main/queries/sidebar-chat-list.tsindex 791cb7b0..ea2bfed8 100644--- a/desktop/src/main/queries/sidebar-chat-list.ts+++ b/desktop/src/main/queries/sidebar-chat-list.ts@@ -71,10 +71,6 @@ export class SidebarChatListQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const query = sql<ChatRow>`WITH chat_nodes AS (SELECT *diff --git a/desktop/src/main/queries/sidebar-space-list.ts b/desktop/src/main/queries/sidebar-space-list.tsindex c1c4dd63..b1e67fdd 100644--- a/desktop/src/main/queries/sidebar-space-list.ts+++ b/desktop/src/main/queries/sidebar-space-list.ts@@ -68,10 +68,6 @@ export class SidebarSpaceListQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const query = sql<SelectNode>`WITH space_nodes AS (SELECT *diff --git a/desktop/src/main/queries/user-search.ts b/desktop/src/main/queries/user-search.tsindex f7f8672e..38872c30 100644--- a/desktop/src/main/queries/user-search.ts+++ b/desktop/src/main/queries/user-search.ts@@ -73,10 +73,6 @@ export class UserSearchQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const query = sql<SelectNode>`SELECT n.*FROM nodes ndiff --git a/desktop/src/main/queries/workspace-user-list.ts b/desktop/src/main/queries/workspace-user-list.tsindex 7e151ea7..048fcedb 100644--- a/desktop/src/main/queries/workspace-user-list.ts+++ b/desktop/src/main/queries/workspace-user-list.ts@@ -66,10 +66,6 @@ export class WorkspaceUserListQueryHandlerinput.userId,);- if (workspaceDatabase === null) {- throw new Error('Workspace database not found.');- }-const offset = input.page * input.count;const rows = await workspaceDatabase.selectFrom('nodes')diff --git a/desktop/src/main/sockets/socket-connection.ts b/desktop/src/main/sockets/socket-connection.tsindex b110c516..0ee9204a 100644--- a/desktop/src/main/sockets/socket-connection.ts+++ b/desktop/src/main/sockets/socket-connection.ts@@ -3,18 +3,14 @@ import { Account } from '@/types/accounts';import { Server } from '@/types/servers';import { buildSynapseUrl } from '@/lib/servers';import { BackoffCalculator } from '@/lib/backoff-calculator';--export type SocketMessage = {- type: string;- payload: any;-};+import { MessageInput } from '@/operations/messages';+import { mediator } from '@/main/mediator';export class SocketConnection {private readonly server: Server;private readonly account: Account;private socket: WebSocket | null;private backoffCalculator: BackoffCalculator;- private listeners: Map<string, ((payload: any) => void)[]>;private closingCount: number;constructor(server: Server, account: Account) {@@ -22,7 +18,6 @@ export class SocketConnection {this.account = account;this.socket = null;this.backoffCalculator = new BackoffCalculator();- this.listeners = new Map();this.closingCount = 0;}@@ -39,7 +34,7 @@ export class SocketConnection {buildSynapseUrl(this.server, this.account.deviceId),);- this.socket.onmessage = (event) => {+ this.socket.onmessage = async (event) => {let data: string;if (typeof event.data === 'string') {@@ -51,11 +46,8 @@ export class SocketConnection {return;}- const message: SocketMessage = JSON.parse(data);- const listeners = this.listeners.get(message.type) || [];- for (const listener of listeners) {- listener(message.payload);- }+ const message: MessageInput = JSON.parse(data);+ await mediator.executeMessage(message);};this.socket.onopen = () => {@@ -104,16 +96,4 @@ export class SocketConnection {}}}-- public send(message: SocketMessage): void {- if (this.isConnected()) {- this.socket?.send(JSON.stringify(message));- }- }-- public on(type: string, listener: (payload: any) => void): void {- const listeners = this.listeners.get(type) || [];- listeners.push(listener);- this.listeners.set(type, listeners);- }}diff --git a/desktop/src/main/synchronizer.ts b/desktop/src/main/synchronizer.tsnew file mode 100644index 00000000..57369212--- /dev/null+++ b/desktop/src/main/synchronizer.ts@@ -0,0 +1,7 @@+class Synchronizer {+ public init() {+ console.log('init synchronizer');+ }+}++export const synchronizer = new Synchronizer();diff --git a/desktop/src/operations/messages/index.ts b/desktop/src/operations/messages/index.tsnew file mode 100644index 00000000..5374a880--- /dev/null+++ b/desktop/src/operations/messages/index.ts@@ -0,0 +1,7 @@+export interface MessageMap {}++export type MessageInput = MessageMap[keyof MessageMap];++export interface MessageHandler<T extends MessageInput> {+ handleMessage: (input: T) => Promise<void>;+}diff --git a/desktop/src/operations/messages/server-mutation.ts b/desktop/src/operations/messages/server-mutation.tsnew file mode 100644index 00000000..2509b116--- /dev/null+++ b/desktop/src/operations/messages/server-mutation.ts@@ -0,0 +1,13 @@+import { ServerMutation } from '@/types/mutations';++export type ServerMutationMessageInput = {+ type: 'server_mutation';+ accountId: string;+ mutation: ServerMutation;+};++declare module '@/operations/messages' {+ interface MessageMap {+ server_mutation: ServerMutationMessageInput;+ }+}diff --git a/desktop/src/types/mutations/index.ts b/desktop/src/types/mutations/index.tsindex 6f13ecfa..1a5b83de 100644--- a/desktop/src/types/mutations/index.ts+++ b/desktop/src/types/mutations/index.ts@@ -11,7 +11,7 @@ export interface MutationHandler<T extends MutationInput> {export type MutationResult<T extends MutationInput> = {output: MutationMap[T['type']]['output'];- changedTables?: MutationChange[];+ changes?: MutationChange[];};export type MutationChange = AppMutationChange | WorkspaceMutationChange;@@ -31,7 +31,7 @@ export type ServerMutation = {id: string;table: string;action: string;- workspaceId: string;+ workspaceId: string | null;before: any | null;after: any | null;};diff --git a/desktop/src/types/mutations/node-collaborator-sync.ts b/desktop/src/types/mutations/node-collaborator-sync.tsnew file mode 100644index 00000000..df6859cf--- /dev/null+++ b/desktop/src/types/mutations/node-collaborator-sync.ts@@ -0,0 +1,22 @@+export type NodeCollaboratorSyncMutationInput = {+ type: 'node_collaborator_sync';+ accountId: string;+ workspaceId: string;+ id: string;+ action: string;+ before: any;+ after: any;+};++export type NodeCollaboratorSyncMutationOutput = {+ success: boolean;+};++declare module '@/types/mutations' {+ interface MutationMap {+ node_collaborator_sync: {+ input: NodeCollaboratorSyncMutationInput;+ output: NodeCollaboratorSyncMutationOutput;+ };+ }+}diff --git a/desktop/src/types/mutations/node-reaction-sync.ts b/desktop/src/types/mutations/node-reaction-sync.tsnew file mode 100644index 00000000..fae0275f--- /dev/null+++ b/desktop/src/types/mutations/node-reaction-sync.ts@@ -0,0 +1,22 @@+export type NodeReactionSyncMutationInput = {+ type: 'node_reaction_sync';+ accountId: string;+ workspaceId: string;+ id: string;+ action: string;+ before: any;+ after: any;+};++export type NodeReactionSyncMutationOutput = {+ success: boolean;+};++declare module '@/types/mutations' {+ interface MutationMap {+ node_reaction_sync: {+ input: NodeReactionSyncMutationInput;+ output: NodeReactionSyncMutationOutput;+ };+ }+}diff --git a/desktop/src/types/mutations/node-sync.ts b/desktop/src/types/mutations/node-sync.tsnew file mode 100644index 00000000..1ff8f884--- /dev/null+++ b/desktop/src/types/mutations/node-sync.ts@@ -0,0 +1,22 @@+export type NodeSyncMutationInput = {+ type: 'node_sync';+ accountId: string;+ workspaceId: string;+ id: string;+ action: string;+ before: any;+ after: any;+};++export type NodeSyncMutationOutput = {+ success: boolean;+};++declare module '@/types/mutations' {+ interface MutationMap {+ node_sync: {+ input: NodeSyncMutationInput;+ output: NodeSyncMutationOutput;+ };+ }+}