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
Rename 'transactions' to 'entry_transactions' for clarity
Hakan Shehue52ccf168152
diff --git a/apps/desktop/src/main/data/workspace/migrations.ts b/apps/desktop/src/main/data/workspace/migrations.tsindex a682cd9d..b6a3d9ac 100644--- a/apps/desktop/src/main/data/workspace/migrations.ts+++ b/apps/desktop/src/main/data/workspace/migrations.ts@@ -57,10 +57,10 @@ const createEntriesTable: Migration = {},};-const createTransactionsTable: Migration = {+const createEntryTransactionsTable: Migration = {up: async (db) => {await db.schema- .createTable('transactions')+ .createTable('entry_transactions').addColumn('id', 'text', (col) => col.notNull().primaryKey()).addColumn('entry_id', 'text', (col) => col.notNull()).addColumn('root_id', 'text', (col) => col.notNull())@@ -73,7 +73,7 @@ const createTransactionsTable: Migration = {.execute();},down: async (db) => {- await db.schema.dropTable('transactions').execute();+ await db.schema.dropTable('entry_transactions').execute();},};@@ -363,7 +363,7 @@ export const workspaceDatabaseMigrations: Record<string, Migration> = {'00001_create_users_table': createUsersTable,'00002_create_entries_table': createEntriesTable,'00003_create_entry_interactions_table': createEntryInteractionsTable,- '00004_create_transactions_table': createTransactionsTable,+ '00004_create_entry_transactions_table': createEntryTransactionsTable,'00005_create_collaborations_table': createCollaborationsTable,'00006_create_messages_table': createMessagesTable,'00007_create_message_reactions_table': createMessageReactionsTable,diff --git a/apps/desktop/src/main/data/workspace/schema.ts b/apps/desktop/src/main/data/workspace/schema.tsindex 9089e596..dbf37604 100644--- a/apps/desktop/src/main/data/workspace/schema.ts+++ b/apps/desktop/src/main/data/workspace/schema.ts@@ -53,7 +53,7 @@ interface EntryPathTable {export type SelectEntryPath = Selectable<EntryPathTable>;-interface TransactionTable {+interface EntryTransactionTable {id: ColumnType<string, string, never>;entry_id: ColumnType<string, string, never>;root_id: ColumnType<string, string, never>;@@ -65,9 +65,9 @@ interface TransactionTable {version: ColumnType<bigint, bigint, bigint>;}-export type SelectTransaction = Selectable<TransactionTable>;-export type CreateTransaction = Insertable<TransactionTable>;-export type UpdateTransaction = Updateable<TransactionTable>;+export type SelectEntryTransaction = Selectable<EntryTransactionTable>;+export type CreateEntryTransaction = Insertable<EntryTransactionTable>;+export type UpdateEntryTransaction = Updateable<EntryTransactionTable>;interface EntryInteractionTable {entry_id: ColumnType<string, string, never>;@@ -230,7 +230,7 @@ export interface WorkspaceDatabaseSchema {users: UserTable;entries: EntryTable;entry_interactions: EntryInteractionTable;- transactions: TransactionTable;+ entry_transactions: EntryTransactionTable;entry_paths: EntryPathTable;collaborations: CollaborationTable;messages: MessageTable;diff --git a/apps/desktop/src/main/services/collaboration-service.ts b/apps/desktop/src/main/services/collaboration-service.tsindex bfe7fd51..5e98e574 100644--- a/apps/desktop/src/main/services/collaboration-service.ts+++ b/apps/desktop/src/main/services/collaboration-service.ts@@ -49,7 +49,7 @@ class CollaborationService {.execute();await tx- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('entry_id', '=', collaboration.entryId).execute();});diff --git a/apps/desktop/src/main/services/entry-service.ts b/apps/desktop/src/main/services/entry-service.tsindex f9026ea5..6f3f455f 100644--- a/apps/desktop/src/main/services/entry-service.ts+++ b/apps/desktop/src/main/services/entry-service.ts@@ -8,11 +8,11 @@ import {EntryAttributes,EntryMutationContext,registry,- SyncCreateTransactionData,- SyncDeleteTransactionData,- SyncTransactionData,- SyncUpdateTransactionData,+ SyncCreateEntryTransactionData,+ SyncDeleteEntryTransactionData,SyncEntryInteractionData,+ SyncEntryTransactionData,+ SyncUpdateEntryTransactionData,} from '@colanode/core';import { decodeState, YDoc } from '@colanode/crdt';@@ -22,13 +22,13 @@ import { databaseService } from '@/main/data/database-service';import {SelectMutation,SelectEntry,- SelectTransaction,+ SelectEntryTransaction,} from '@/main/data/workspace/schema';import {fetchEntryAncestors,mapEntry,mapEntryInteraction,- mapTransaction,+ mapEntryTransaction,} from '@/main/utils';import { eventBus } from '@/shared/lib/event-bus';@@ -142,7 +142,7 @@ class EntryService {createdEntries.push(createdEntry);const createdTransaction = await transaction- .insertInto('transactions')+ .insertInto('entry_transactions').returningAll().values({id: transactionId,@@ -167,7 +167,7 @@ class EntryService {id: generateId(IdType.Mutation),node_id: inputItem.id,type: 'apply_create_transaction',- data: JSON.stringify(mapTransaction(createdTransaction)),+ data: JSON.stringify(mapEntryTransaction(createdTransaction)),created_at: createdAt,retries: 0,})@@ -273,7 +273,7 @@ class EntryService {const ydoc = new YDoc();const previousTransactions = await workspaceDatabase- .selectFrom('transactions')+ .selectFrom('entry_transactions').where('entry_id', '=', entryId).selectAll().execute();@@ -309,7 +309,7 @@ class EntryService {return { updatedEntry: undefined };}const createdTransaction = await trx- .insertInto('transactions')+ .insertInto('entry_transactions').returningAll().values({id: transactionId,@@ -334,7 +334,7 @@ class EntryService {id: generateId(IdType.Mutation),node_id: entryId,type: 'apply_update_transaction',- data: JSON.stringify(mapTransaction(createdTransaction)),+ data: JSON.stringify(mapEntryTransaction(createdTransaction)),created_at: updatedAt,retries: 0,})@@ -433,7 +433,7 @@ class EntryService {}await trx- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('entry_id', '=', entryId).execute();@@ -445,7 +445,7 @@ class EntryService {await trx.deleteFrom('texts').where('id', '=', entryId).execute();const createdTransaction = await trx- .insertInto('transactions')+ .insertInto('entry_transactions').returningAll().values({id: generateId(IdType.Transaction),@@ -470,7 +470,7 @@ class EntryService {id: generateId(IdType.Mutation),node_id: entryId,type: 'apply_delete_transaction',- data: JSON.stringify(mapTransaction(createdTransaction)),+ data: JSON.stringify(mapEntryTransaction(createdTransaction)),created_at: new Date().toISOString(),retries: 0,})@@ -507,7 +507,7 @@ class EntryService {public async applyServerTransaction(userId: string,- transaction: SyncTransactionData+ transaction: SyncEntryTransactionData) {if (transaction.operation === 'create') {await this.applyServerCreateTransaction(userId, transaction);@@ -521,7 +521,7 @@ class EntryService {public async replaceTransactions(userId: string,entryId: string,- transactions: SyncTransactionData[],+ transactions: SyncEntryTransactionData[],transactionCursor: bigint): Promise<boolean> {for (let count = 0; count < UPDATE_RETRIES_LIMIT; count++) {@@ -543,7 +543,7 @@ class EntryService {public async tryReplaceTransactions(userId: string,entryId: string,- transactions: SyncTransactionData[],+ transactions: SyncEntryTransactionData[],transactionCursor: bigint): Promise<boolean | null> {const workspaceDatabase =@@ -616,12 +616,12 @@ class EntryService {}await trx- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('entry_id', '=', entryId).execute();await trx- .insertInto('transactions')+ .insertInto('entry_transactions').values(transactions.map((t) => ({id: t.id,@@ -697,12 +697,12 @@ class EntryService {}await trx- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('entry_id', '=', entryId).execute();await trx- .insertInto('transactions')+ .insertInto('entry_transactions').values(transactions.map((t) => ({id: t.id,@@ -748,7 +748,7 @@ class EntryService {private async applyServerCreateTransaction(userId: string,- transaction: SyncCreateTransactionData+ transaction: SyncCreateEntryTransactionData) {this.debug(`Applying server create transaction ${transaction.id} for entry ${transaction.entryId}`@@ -759,7 +759,7 @@ class EntryService {const version = BigInt(transaction.version);const existingTransaction = await workspaceDatabase- .selectFrom('transactions')+ .selectFrom('entry_transactions').select(['id', 'version', 'server_created_at']).where('id', '=', transaction.id).executeTakeFirst();@@ -776,7 +776,7 @@ class EntryService {}await workspaceDatabase- .updateTable('transactions')+ .updateTable('entry_transactions').set({version,server_created_at: transaction.serverCreatedAt,@@ -818,7 +818,7 @@ class EntryService {.executeTakeFirst();await trx- .insertInto('transactions')+ .insertInto('entry_transactions').values({id: transaction.id,entry_id: transaction.entryId,@@ -866,14 +866,14 @@ class EntryService {private async applyServerUpdateTransaction(userId: string,- transaction: SyncUpdateTransactionData+ transaction: SyncUpdateEntryTransactionData) {const workspaceDatabase =await databaseService.getWorkspaceDatabase(userId);const version = BigInt(transaction.version);const existingTransaction = await workspaceDatabase- .selectFrom('transactions')+ .selectFrom('entry_transactions').select(['id', 'version', 'server_created_at']).where('id', '=', transaction.id).executeTakeFirst();@@ -890,7 +890,7 @@ class EntryService {}await workspaceDatabase- .updateTable('transactions')+ .updateTable('entry_transactions').set({version,server_created_at: transaction.serverCreatedAt,@@ -910,7 +910,7 @@ class EntryService {}const previousTransactions = await workspaceDatabase- .selectFrom('transactions')+ .selectFrom('entry_transactions').selectAll().where('entry_id', '=', transaction.entryId).orderBy('id', 'asc')@@ -944,7 +944,7 @@ class EntryService {.executeTakeFirst();await trx- .insertInto('transactions')+ .insertInto('entry_transactions').values({id: transaction.id,entry_id: transaction.entryId,@@ -999,7 +999,7 @@ class EntryService {private async applyServerDeleteTransaction(userId: string,- transaction: SyncDeleteTransactionData+ transaction: SyncDeleteEntryTransactionData) {this.debug(`Applying server delete transaction ${transaction.id} for entry ${transaction.entryId}`@@ -1024,7 +1024,7 @@ class EntryService {.where('id', '=', transaction.entryId).execute();await trx- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('entry_id', '=', transaction.entryId).execute();@@ -1068,7 +1068,7 @@ class EntryService {}const transactionRow = await workspaceDatabase- .selectFrom('transactions')+ .selectFrom('entry_transactions').selectAll().where('id', '=', transaction.id).executeTakeFirst();@@ -1084,7 +1084,7 @@ class EntryService {.execute();await tx- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('id', '=', transaction.id).execute();@@ -1132,7 +1132,7 @@ class EntryService {}const transactionRow = await workspaceDatabase- .selectFrom('transactions')+ .selectFrom('entry_transactions').selectAll().where('id', '=', transaction.id).executeTakeFirst();@@ -1142,7 +1142,7 @@ class EntryService {}const previousTransactions = await workspaceDatabase- .selectFrom('transactions')+ .selectFrom('entry_transactions').selectAll().where('entry_id', '=', transaction.entryId).orderBy('id', 'asc')@@ -1155,7 +1155,7 @@ class EntryService {const ydoc = new YDoc();- let lastTransaction: SelectTransaction | undefined;+ let lastTransaction: SelectEntryTransaction | undefined;for (const previousTransaction of previousTransactions) {if (previousTransaction.id === transaction.id) {continue;@@ -1193,7 +1193,7 @@ class EntryService {}await trx- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('id', '=', transaction.id).execute();});@@ -1219,7 +1219,7 @@ class EntryService {await databaseService.getWorkspaceDatabase(userId);const transactionRow = await workspaceDatabase- .selectFrom('transactions')+ .selectFrom('entry_transactions').selectAll().where('id', '=', transaction.id).executeTakeFirst();@@ -1229,7 +1229,7 @@ class EntryService {}await workspaceDatabase- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('id', '=', transaction.id).execute();}diff --git a/apps/desktop/src/main/services/sync-service.ts b/apps/desktop/src/main/services/sync-service.tsindex af641e55..3ef79c93 100644--- a/apps/desktop/src/main/services/sync-service.ts+++ b/apps/desktop/src/main/services/sync-service.ts@@ -7,7 +7,7 @@ import { createDebugger } from '@/main/debugger';import { UserSynchronizer } from '@/main/synchronizers/users';import { WorkspaceDatabaseSchema } from '@/main/data/workspace/schema';import { CollaborationSynchronizer } from '@/main/synchronizers/collaborations';-import { TransactionSynchronizer } from '@/main/synchronizers/transactions';+import { EntryTransactionSynchronizer } from '@/main/synchronizers/entry-transactions';import { MessageSynchronizer } from '@/main/synchronizers/messages';import { MessageReactionSynchronizer } from '@/main/synchronizers/message-reactions';import { FileSynchronizer } from '@/main/synchronizers/files';@@ -171,8 +171,8 @@ class SyncService {);}- if (input.type === 'transactions') {- return new TransactionSynchronizer(+ if (input.type === 'entry_transactions') {+ return new EntryTransactionSynchronizer(userId,accountId,input,@@ -217,7 +217,7 @@ class SyncService {workspaceDatabase: Kysely<WorkspaceDatabaseSchema>) {await this.initSynchronizer(userId, accountId, workspaceDatabase, {- type: 'transactions',+ type: 'entry_transactions',rootId,});@@ -262,7 +262,7 @@ class SyncService {}if (- synchronizer.input.type === 'transactions' &&+ synchronizer.input.type === 'entry_transactions' &&synchronizer.input.rootId === rootId) {this.synchronizers.delete(key);diff --git a/apps/desktop/src/main/synchronizers/entry-transactions.ts b/apps/desktop/src/main/synchronizers/entry-transactions.tsnew file mode 100644index 00000000..449b5faf--- /dev/null+++ b/apps/desktop/src/main/synchronizers/entry-transactions.ts@@ -0,0 +1,17 @@+import {+ SyncEntryTransactionData,+ SyncEntryTransactionsInput,+} from '@colanode/core';++import { BaseSynchronizer } from '@/main/synchronizers/base';+import { entryService } from '@/main/services/entry-service';++export class EntryTransactionSynchronizer extends BaseSynchronizer<SyncEntryTransactionsInput> {+ protected async process(data: SyncEntryTransactionData): Promise<void> {+ await entryService.applyServerTransaction(this.userId, data);+ }++ protected get cursorKey(): string {+ return `entry_transactions:${this.input.rootId}`;+ }+}diff --git a/apps/desktop/src/main/synchronizers/transactions.ts b/apps/desktop/src/main/synchronizers/transactions.tsdeleted file mode 100644index a87e1af1..00000000--- a/apps/desktop/src/main/synchronizers/transactions.ts+++ /dev/null@@ -1,14 +0,0 @@-import { SyncTransactionData, SyncTransactionsInput } from '@colanode/core';--import { BaseSynchronizer } from '@/main/synchronizers/base';-import { entryService } from '@/main/services/entry-service';--export class TransactionSynchronizer extends BaseSynchronizer<SyncTransactionsInput> {- protected async process(data: SyncTransactionData): Promise<void> {- await entryService.applyServerTransaction(this.userId, data);- }-- protected get cursorKey(): string {- return `transactions:${this.input.rootId}`;- }-}diff --git a/apps/desktop/src/main/utils.ts b/apps/desktop/src/main/utils.tsindex 049d5d26..ac08338c 100644--- a/apps/desktop/src/main/utils.ts+++ b/apps/desktop/src/main/utils.ts@@ -25,7 +25,7 @@ import {SelectMessageReaction,SelectMutation,SelectEntry,- SelectTransaction,+ SelectEntryTransaction,SelectUser,WorkspaceDatabaseSchema,SelectMessageInteraction,@@ -201,7 +201,9 @@ export const mapWorkspace = (row: SelectWorkspace): Workspace => {};};-export const mapTransaction = (row: SelectTransaction): LocalTransaction => {+export const mapEntryTransaction = (+ row: SelectEntryTransaction+): LocalTransaction => {if (row.operation === 'create' && row.data) {return {id: row.id,diff --git a/apps/server/src/data/migrations.ts b/apps/server/src/data/migrations.tsindex 6165405c..1d2bc63b 100644--- a/apps/server/src/data/migrations.ts+++ b/apps/server/src/data/migrations.ts@@ -158,10 +158,10 @@ const createEntriesTable: Migration = {},};-const createTransactionsTable: Migration = {+const createEntryTransactionsTable: Migration = {up: async (db) => {await sql`- CREATE SEQUENCE IF NOT EXISTS transactions_version_sequence+ CREATE SEQUENCE IF NOT EXISTS entry_transactions_version_sequenceSTART WITH 1000000000INCREMENT BY 1NO MINVALUE@@ -170,7 +170,7 @@ const createTransactionsTable: Migration = {`.execute(db);await db.schema- .createTable('transactions')+ .createTable('entry_transactions').addColumn('id', 'varchar(30)', (col) => col.notNull().primaryKey()).addColumn('entry_id', 'varchar(30)', (col) => col.notNull()).addColumn('root_id', 'varchar(30)', (col) => col.notNull())@@ -181,13 +181,15 @@ const createTransactionsTable: Migration = {.addColumn('created_by', 'varchar(30)', (col) => col.notNull()).addColumn('server_created_at', 'timestamptz', (col) => col.notNull()).addColumn('version', 'bigint', (col) =>- col.notNull().defaultTo(sql`nextval('transactions_version_sequence')`)+ col+ .notNull()+ .defaultTo(sql`nextval('entry_transactions_version_sequence')`)).execute();},down: async (db) => {- await db.schema.dropTable('transactions').execute();- await sql`DROP SEQUENCE IF EXISTS transactions_version_sequence`.execute(+ await db.schema.dropTable('entry_transactions').execute();+ await sql`DROP SEQUENCE IF EXISTS entry_transactions_version_sequence`.execute(db);},@@ -679,7 +681,7 @@ export const databaseMigrations: Record<string, Migration> = {'00003_create_workspaces_table': createWorkspacesTable,'00004_create_users_table': createUsersTable,'00005_create_entries_table': createEntriesTable,- '00006_create_transactions_table': createTransactionsTable,+ '00006_create_entry_transactions_table': createEntryTransactionsTable,'00007_create_entry_interactions_table': createEntryInteractionsTable,'00008_create_messages_table': createMessagesTable,'00009_create_message_reactions_table': createMessageReactionsTable,diff --git a/apps/server/src/data/schema.ts b/apps/server/src/data/schema.tsindex 48ac0857..6f123f61 100644--- a/apps/server/src/data/schema.ts+++ b/apps/server/src/data/schema.ts@@ -129,7 +129,7 @@ export type SelectCollaboration = Selectable<CollaborationTable>;export type CreateCollaboration = Insertable<CollaborationTable>;export type UpdateCollaboration = Updateable<CollaborationTable>;-interface TransactionTable {+interface EntryTransactionTable {id: ColumnType<string, string, never>;entry_id: ColumnType<string, string, never>;root_id: ColumnType<string, string, never>;@@ -142,9 +142,9 @@ interface TransactionTable {version: ColumnType<bigint, never, never>;}-export type SelectTransaction = Selectable<TransactionTable>;-export type CreateTransaction = Insertable<TransactionTable>;-export type UpdateTransaction = Updateable<TransactionTable>;+export type SelectEntryTransaction = Selectable<EntryTransactionTable>;+export type CreateEntryTransaction = Insertable<EntryTransactionTable>;+export type UpdateEntryTransaction = Updateable<EntryTransactionTable>;interface EntryInteractionTable {entry_id: ColumnType<string, string, never>;@@ -272,7 +272,7 @@ export interface DatabaseSchema {workspaces: WorkspaceTable;users: UserTable;entries: EntryTable;- transactions: TransactionTable;+ entry_transactions: EntryTransactionTable;entry_interactions: EntryInteractionTable;collaborations: CollaborationTable;messages: MessageTable;diff --git a/apps/server/src/jobs/clean-entry-data.ts b/apps/server/src/jobs/clean-entry-data.tsindex ef91dde2..b4e07392 100644--- a/apps/server/src/jobs/clean-entry-data.ts+++ b/apps/server/src/jobs/clean-entry-data.ts@@ -2,7 +2,7 @@ import { generateId, IdType } from '@colanode/core';// import { DeleteObjectCommand } from '@aws-sdk/client-s3';import { database } from '@/data/database';-import { CreateTransaction } from '@/data/schema';+import { CreateEntryTransaction } from '@/data/schema';import { JobHandler } from '@/types/jobs';// import { filesStorage, BUCKET_NAMES } from '@/data/storage';import { eventBus } from '@/lib/event-bus';@@ -32,7 +32,7 @@ export const cleanEntryDataHandler: JobHandler<CleanEntryDataInput> = async (logger.trace(`Cleaning entry data for ${input.entryId}`);const deleteTransactions = await database- .selectFrom('transactions')+ .selectFrom('entry_transactions').selectAll().where('entry_id', '=', input.entryId).execute();@@ -101,7 +101,7 @@ const deleteChildren = async (// : [];const entryIds: string[] = descendants.map((d) => d.id);- const transactionsToCreate: CreateTransaction[] = descendants.map(+ const transactionsToCreate: CreateEntryTransaction[] = descendants.map((descendant) => ({id: generateId(IdType.Transaction),entry_id: descendant.id,@@ -117,12 +117,12 @@ const deleteChildren = async (await database.transaction().execute(async (trx) => {await trx- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('entry_id', 'in', entryIds).execute();const createdTransactions = await trx- .insertInto('transactions')+ .insertInto('entry_transactions').returningAll().values(transactionsToCreate).execute();diff --git a/apps/server/src/services/entry-service.ts b/apps/server/src/services/entry-service.tsindex d7e4e73f..3ffaa5d0 100644--- a/apps/server/src/services/entry-service.ts+++ b/apps/server/src/services/entry-service.ts@@ -20,7 +20,7 @@ import { database } from '@/data/database';import {CreateEntry,CreateCollaboration,- CreateTransaction,+ CreateEntryTransaction,DatabaseSchema,SelectUser,SelectCollaboration,@@ -79,7 +79,7 @@ class EntryService {transaction_id: transactionId,};- const createTransaction: CreateTransaction = {+ const createTransaction: CreateEntryTransaction = {id: transactionId,root_id: input.rootId,entry_id: input.entryId,@@ -156,7 +156,7 @@ class EntryService {}const previousTransactions = await database- .selectFrom('transactions')+ .selectFrom('entry_transactions').selectAll().where('entry_id', '=', input.entryId).orderBy('id', 'asc')@@ -216,7 +216,7 @@ class EntryService {}const createdTransaction = await trx- .insertInto('transactions')+ .insertInto('entry_transactions').returningAll().values({id: transactionId,@@ -331,7 +331,7 @@ class EntryService {transaction_id: input.id,};- const createTransaction: CreateTransaction = {+ const createTransaction: CreateEntryTransaction = {id: input.id,entry_id: input.entryId,root_id: input.rootId,@@ -411,7 +411,7 @@ class EntryService {}const previousTransactions = await database- .selectFrom('transactions')+ .selectFrom('entry_transactions').selectAll().where('entry_id', '=', input.entryId).orderBy('version', 'asc')@@ -477,7 +477,7 @@ class EntryService {}const createdTransaction = await trx- .insertInto('transactions')+ .insertInto('entry_transactions').returningAll().values({id: input.id,@@ -592,12 +592,12 @@ class EntryService {}await trx- .deleteFrom('transactions')+ .deleteFrom('entry_transactions').where('entry_id', '=', input.entryId).execute();const createdTransaction = await trx- .insertInto('transactions')+ .insertInto('entry_transactions').returningAll().values({id: input.id,@@ -826,7 +826,7 @@ class EntryService {private async applyDatabaseCreateTransaction(attributes: EntryAttributes,entry: CreateEntry,- transaction: CreateTransaction+ transaction: CreateEntryTransaction) {const collaborationsToCreate: CreateCollaboration[] = Object.entries(extractEntryCollaborators(attributes)@@ -851,7 +851,7 @@ class EntryService {}const createdTransaction = await trx- .insertInto('transactions')+ .insertInto('entry_transactions').returningAll().values(transaction).executeTakeFirst();diff --git a/apps/server/src/services/socket-connection.ts b/apps/server/src/services/socket-connection.tsindex 8cb12d72..5ffecbbe 100644--- a/apps/server/src/services/socket-connection.ts+++ b/apps/server/src/services/socket-connection.ts@@ -24,7 +24,7 @@ import { CollaborationSynchronizer } from '@/synchronizers/collaborations';import { FileSynchronizer } from '@/synchronizers/files';import { MessageSynchronizer } from '@/synchronizers/messages';import { MessageReactionSynchronizer } from '@/synchronizers/message-reactions';-import { TransactionSynchronizer } from '@/synchronizers/transactions';+import { EntryTransactionSynchronizer } from '@/synchronizers/entry-transactions';import { MessageInteractionSynchronizer } from '@/synchronizers/message-interactions';import { EntryInteractionSynchronizer } from '@/synchronizers/entry-interactions';import { FileInteractionSynchronizer } from '@/synchronizers/file-interactions';@@ -164,8 +164,8 @@ export class SocketConnection {message.input,cursor);- } else if (message.input.type === 'transactions') {- return new TransactionSynchronizer(+ } else if (message.input.type === 'entry_transactions') {+ return new EntryTransactionSynchronizer(message.id,user.user,message.input,diff --git a/apps/server/src/synchronizers/transactions.ts b/apps/server/src/synchronizers/entry-transactions.tssimilarity index 80%rename from apps/server/src/synchronizers/transactions.tsrename to apps/server/src/synchronizers/entry-transactions.tsindex 6d080b2e..fa87c4fc 100644--- a/apps/server/src/synchronizers/transactions.ts+++ b/apps/server/src/synchronizers/entry-transactions.ts@@ -1,17 +1,17 @@import {SynchronizerOutputMessage,- SyncTransactionsInput,- SyncTransactionData,+ SyncEntryTransactionsInput,+ SyncEntryTransactionData,} from '@colanode/core';import { encodeState } from '@colanode/crdt';import { BaseSynchronizer } from '@/synchronizers/base';import { Event } from '@/types/events';import { database } from '@/data/database';-import { SelectTransaction } from '@/data/schema';+import { SelectEntryTransaction } from '@/data/schema';-export class TransactionSynchronizer extends BaseSynchronizer<SyncTransactionsInput> {- public async fetchData(): Promise<SynchronizerOutputMessage<SyncTransactionsInput> | null> {+export class EntryTransactionSynchronizer extends BaseSynchronizer<SyncEntryTransactionsInput> {+ public async fetchData(): Promise<SynchronizerOutputMessage<SyncEntryTransactionsInput> | null> {const transactions = await this.fetchTransactions();if (transactions.length === 0) {return null;@@ -22,7 +22,7 @@ export class TransactionSynchronizer extends BaseSynchronizer<SyncTransactionsInpublic async fetchDataFromEvent(event: Event- ): Promise<SynchronizerOutputMessage<SyncTransactionsInput> | null> {+ ): Promise<SynchronizerOutputMessage<SyncEntryTransactionsInput> | null> {if (!this.shouldFetch(event)) {return null;}@@ -42,7 +42,7 @@ export class TransactionSynchronizer extends BaseSynchronizer<SyncTransactionsInthis.status = 'fetching';const transactions = await database- .selectFrom('transactions')+ .selectFrom('entry_transactions').selectAll().where('root_id', '=', this.input.rootId).where('version', '>', this.cursor)@@ -55,9 +55,9 @@ export class TransactionSynchronizer extends BaseSynchronizer<SyncTransactionsIn}private buildMessage(- unsyncedTransactions: SelectTransaction[]- ): SynchronizerOutputMessage<SyncTransactionsInput> {- const items: SyncTransactionData[] = unsyncedTransactions.map(+ unsyncedTransactions: SelectEntryTransaction[]+ ): SynchronizerOutputMessage<SyncEntryTransactionsInput> {+ const items: SyncEntryTransactionData[] = unsyncedTransactions.map((transaction) => {if (transaction.operation === 'create' && transaction.data) {return {@@ -119,24 +119,15 @@ export class TransactionSynchronizer extends BaseSynchronizer<SyncTransactionsIn}private shouldFetch(event: Event) {- if (- event.type === 'message_created' &&- event.rootId === this.input.rootId- ) {+ if (event.type === 'entry_created' && event.rootId === this.input.rootId) {return true;}- if (- event.type === 'message_updated' &&- event.rootId === this.input.rootId- ) {+ if (event.type === 'entry_updated' && event.rootId === this.input.rootId) {return true;}- if (- event.type === 'message_deleted' &&- event.rootId === this.input.rootId- ) {+ if (event.type === 'entry_deleted' && event.rootId === this.input.rootId) {return true;}diff --git a/apps/server/src/types/entries.ts b/apps/server/src/types/entries.tsindex 5dae443e..db132d17 100644--- a/apps/server/src/types/entries.ts+++ b/apps/server/src/types/entries.ts@@ -1,6 +1,6 @@import { Entry, EntryAttributes } from '@colanode/core';-import { SelectEntry, SelectTransaction } from '@/data/schema';+import { SelectEntry, SelectEntryTransaction } from '@/data/schema';export type EntryCollaborator = {entryId: string;@@ -19,7 +19,7 @@ export type CreateEntryInput = {export type CreateEntryOutput = {entry: SelectEntry;- transaction: SelectTransaction;+ transaction: SelectEntryTransaction;};export type UpdateEntryInput = {@@ -31,7 +31,7 @@ export type UpdateEntryInput = {export type UpdateEntryOutput = {entry: SelectEntry;- transaction: SelectTransaction;+ transaction: SelectEntryTransaction;};export type ApplyCreateTransactionInput = {@@ -44,7 +44,7 @@ export type ApplyCreateTransactionInput = {export type ApplyCreateTransactionOutput = {entry: SelectEntry;- transaction: SelectTransaction;+ transaction: SelectEntryTransaction;};export type ApplyUpdateTransactionInput = {@@ -58,7 +58,7 @@ export type ApplyUpdateTransactionInput = {export type ApplyUpdateTransactionOutput = {entry: SelectEntry;- transaction: SelectTransaction;+ transaction: SelectEntryTransaction;};export type ApplyDeleteTransactionInput = {@@ -70,5 +70,5 @@ export type ApplyDeleteTransactionInput = {export type ApplyDeleteTransactionOutput = {entry: SelectEntry;- transaction: SelectTransaction;+ transaction: SelectEntryTransaction;};diff --git a/packages/core/src/synchronizers/transactions.ts b/packages/core/src/synchronizers/entry-transactions.tssimilarity index 60%rename from packages/core/src/synchronizers/transactions.tsrename to packages/core/src/synchronizers/entry-transactions.tsindex 28ac7c67..14fda5fb 100644--- a/packages/core/src/synchronizers/transactions.ts+++ b/packages/core/src/synchronizers/entry-transactions.ts@@ -1,9 +1,9 @@-export type SyncTransactionsInput = {- type: 'transactions';+export type SyncEntryTransactionsInput = {+ type: 'entry_transactions';rootId: string;};-export type SyncCreateTransactionData = {+export type SyncCreateEntryTransactionData = {id: string;operation: 'create';entryId: string;@@ -16,7 +16,7 @@ export type SyncCreateTransactionData = {version: string;};-export type SyncUpdateTransactionData = {+export type SyncUpdateEntryTransactionData = {id: string;operation: 'update';entryId: string;@@ -29,7 +29,7 @@ export type SyncUpdateTransactionData = {version: string;};-export type SyncDeleteTransactionData = {+export type SyncDeleteEntryTransactionData = {id: string;operation: 'delete';entryId: string;@@ -41,16 +41,16 @@ export type SyncDeleteTransactionData = {version: string;};-export type SyncTransactionData =- | SyncCreateTransactionData- | SyncUpdateTransactionData- | SyncDeleteTransactionData;+export type SyncEntryTransactionData =+ | SyncCreateEntryTransactionData+ | SyncUpdateEntryTransactionData+ | SyncDeleteEntryTransactionData;declare module '@colanode/core' {interface SynchronizerMap {- transactions: {- input: SyncTransactionsInput;- data: SyncTransactionData;+ entry_transactions: {+ input: SyncEntryTransactionsInput;+ data: SyncEntryTransactionData;};}}diff --git a/packages/core/src/synchronizers/index.ts b/packages/core/src/synchronizers/index.tsindex ef13ec1c..d44b58bb 100644--- a/packages/core/src/synchronizers/index.ts+++ b/packages/core/src/synchronizers/index.ts@@ -1,5 +1,5 @@export * from './messages';-export * from './transactions';+export * from './entry-transactions';export * from './users';export * from './files';export * from './message-reactions';