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
Move some types into registry
Hakan Shehue8d0e9fb0800
diff --git a/desktop/src/lib/databases.ts b/desktop/src/lib/databases.tsindex 65d27347..8b193601 100644--- a/desktop/src/lib/databases.ts+++ b/desktop/src/lib/databases.ts@@ -4,8 +4,8 @@ import {ViewFieldFilterAttributes,ViewFilterAttributes,ViewFieldAttributes,+ RecordNode,} from '@/registry';-import { RecordNode } from '@/types/nodes';import { compareString, isStringArray } from '@/lib/utils';import { generateNodeIndex } from './nodes';diff --git a/desktop/src/lib/nodes.ts b/desktop/src/lib/nodes.tsindex 90c7df49..2551f086 100644--- a/desktop/src/lib/nodes.ts+++ b/desktop/src/lib/nodes.ts@@ -1,5 +1,5 @@import { SelectNode } from '@/main/data/workspace/schema';-import { LocalNode } from '@/types/nodes';+import { Node } from '@/registry';import { generateKeyBetween } from 'fractional-indexing-jittered';import { NodeTypes } from '@/lib/constants';@@ -13,14 +13,13 @@ export const generateNodeIndex = (return generateKeyBetween(lower, upper);};-export const mapNode = (row: SelectNode): LocalNode => {+export const mapNode = (row: SelectNode): Node => {return {id: row.id,type: row.type as any,index: row.index,parentId: row.parent_id,attributes: JSON.parse(row.attributes),- state: row.state,createdAt: row.created_at,createdBy: row.created_by,updatedAt: row.updated_at,diff --git a/desktop/src/main/handlers/mutations/message-create.ts b/desktop/src/main/handlers/mutations/message-create.tsindex ea8329bf..d8f71765 100644--- a/desktop/src/main/handlers/mutations/message-create.ts+++ b/desktop/src/main/handlers/mutations/message-create.ts@@ -11,7 +11,7 @@ import { MessageCreateMutationInput } from '@/operations/mutations/message-creatimport { mapContentsToBlocks } from '@/lib/editor';import { fileManager } from '@/main/file-manager';import { CreateDownload, CreateUpload } from '@/main/data/workspace/schema';-import { LocalNodeAttributes } from '@/types/nodes';+import { NodeAttributes } from '@/registry';import { Block, FileAttributes, MessageAttributes } from '@/registry';import { nodeManager } from '@/main/node-manager';@@ -25,7 +25,7 @@ export class MessageCreateMutationHandlerinput.userId,);- const nodeAttributes: LocalNodeAttributes[] = [];+ const nodeAttributes: NodeAttributes[] = [];const downloadsToCreate: CreateDownload[] = [];const uploadsToCreate: CreateUpload[] = [];diff --git a/desktop/src/main/handlers/queries/document-get.ts b/desktop/src/main/handlers/queries/document-get.tsindex 499455d5..77e61223 100644--- a/desktop/src/main/handlers/queries/document-get.ts+++ b/desktop/src/main/handlers/queries/document-get.ts@@ -13,7 +13,7 @@ import {import { SelectNode } from '@/main/data/workspace/schema';import { MutationChange } from '@/operations/mutations';-import { LocalNodeAttributes } from '@/types/nodes';+import { NodeAttributes } from '@/registry';import { mapBlocksToContents } from '@/lib/editor';export class DocumentGetQueryHandler@@ -91,7 +91,7 @@ export class DocumentGetQueryHandler};}- const attributes = JSON.parse(document.attributes) as LocalNodeAttributes;+ const attributes = JSON.parse(document.attributes) as NodeAttributes;if (attributes.type !== 'page' && attributes.type !== 'record') {return {content: null,diff --git a/desktop/src/main/handlers/queries/node-collaborator-list.ts b/desktop/src/main/handlers/queries/node-collaborator-list.tsindex 0c6c5f75..c3a21507 100644--- a/desktop/src/main/handlers/queries/node-collaborator-list.ts+++ b/desktop/src/main/handlers/queries/node-collaborator-list.ts@@ -7,10 +7,10 @@ import {} from '@/operations/queries';import {InheritNodeCollaboratorsGroup,- LocalNodeAttributes,NodeCollaboratorsWrapper,NodeCollaborator,} from '@/types/nodes';+import { NodeAttributes } from '@/registry';import { MutationChange } from '@/operations/mutations';import { isEqual } from 'lodash';@@ -138,7 +138,7 @@ export class NodeCollaboratorListQueryHandlerconst map: Map<string, ExtractedNodeCollaborator> = new Map();for (const node of nodes) {- const attributes = JSON.parse(node.attributes) as LocalNodeAttributes;+ const attributes = JSON.parse(node.attributes) as NodeAttributes;if (attributes.type !== 'space' &&diff --git a/desktop/src/main/handlers/queries/record-list.ts b/desktop/src/main/handlers/queries/record-list.tsindex 469042e1..ed612cfc 100644--- a/desktop/src/main/handlers/queries/record-list.ts+++ b/desktop/src/main/handlers/queries/record-list.ts@@ -23,12 +23,13 @@ import {ViewFieldFilterAttributes,ViewFilterAttributes,ViewSortAttributes,+ DatabaseNode,+ RecordNode,} from '@/registry';import { isStringArray } from '@/lib/utils';import { mapNode } from '@/lib/nodes';import { NodeTypes } from '@/lib/constants';import { isEqual } from 'lodash';-import { DatabaseNode, RecordNode } from '@/types/nodes';export class RecordListQueryHandlerimplements QueryHandler<RecordListQueryInput>diff --git a/desktop/src/main/handlers/queries/sidebar-space-list.ts b/desktop/src/main/handlers/queries/sidebar-space-list.tsindex a2c7d355..c7353318 100644--- a/desktop/src/main/handlers/queries/sidebar-space-list.ts+++ b/desktop/src/main/handlers/queries/sidebar-space-list.ts@@ -10,7 +10,7 @@ import { SelectNode } from '@/main/data/workspace/schema';import { NodeTypes } from '@/lib/constants';import { SidebarNode, SidebarSpaceNode } from '@/types/workspaces';import { mapNode } from '@/lib/nodes';-import { LocalNode } from '@/types/nodes';+import { Node } from '@/registry';import { MutationChange } from '@/operations/mutations';import { isEqual } from 'lodash';import { compareString } from '@/lib/utils';@@ -140,7 +140,7 @@ export class SidebarSpaceListQueryHandlerrows: SelectNode[],unreadCounts: UnreadCountRow[],): SidebarSpaceNode[] => {- const nodes: LocalNode[] = rows.map(mapNode);+ const nodes: Node[] = rows.map(mapNode);const spaces: SidebarSpaceNode[] = [];for (const node of nodes) {@@ -162,8 +162,8 @@ export class SidebarSpaceListQueryHandler};private buildSpaceNode = (- node: LocalNode,- children: LocalNode[],+ node: Node,+ children: Node[],unreadCounts: UnreadCountRow[],): SidebarSpaceNode | null => {if (node.type !== 'space') {@@ -190,7 +190,7 @@ export class SidebarSpaceListQueryHandler};private buildSidearNode = (- node: LocalNode,+ node: Node,unreadCounts: UnreadCountRow[],): SidebarNode | null => {const unreadCountRow = unreadCounts.find((r) => r.node_id === node.id);diff --git a/desktop/src/main/handlers/queries/workspace-user-list.ts b/desktop/src/main/handlers/queries/workspace-user-list.tsindex b2cc3dfb..bd2e387d 100644--- a/desktop/src/main/handlers/queries/workspace-user-list.ts+++ b/desktop/src/main/handlers/queries/workspace-user-list.ts@@ -8,7 +8,7 @@ import {import { NodeTypes } from '@/lib/constants';import { mapNode } from '@/lib/nodes';import { SelectNode } from '@/main/data/workspace/schema';-import { LocalNode, UserNode } from '@/types/nodes';+import { UserNode } from '@/registry';import { MutationChange } from '@/operations/mutations';import { isEqual } from 'lodash';diff --git a/desktop/src/main/node-manager.ts b/desktop/src/main/node-manager.tsindex bda6b259..f8cdb177 100644--- a/desktop/src/main/node-manager.ts+++ b/desktop/src/main/node-manager.ts@@ -1,5 +1,5 @@import * as Y from 'yjs';-import { LocalNodeAttributes } from '@/types/nodes';+import { NodeAttributes } from '@/registry';import { fromUint8Array, toUint8Array } from 'js-base64';import { applyCrdt } from '@/main/crdt';import {@@ -19,7 +19,7 @@ class NodeManager {transaction: Transaction<WorkspaceDatabaseSchema>,userId: string,id: string,- attributes: LocalNodeAttributes,+ attributes: NodeAttributes,) {const doc = new Y.Doc({guid: id,@@ -71,7 +71,7 @@ class NodeManager {async updateNode(userId: string,id: string,- updater: (attributes: LocalNodeAttributes) => LocalNodeAttributes,+ updater: (attributes: NodeAttributes) => NodeAttributes,) {const workspaceDatabase =await databaseManager.getWorkspaceDatabase(userId);@@ -101,7 +101,7 @@ class NodeManager {updates.push(fromUint8Array(update));});- const attributes = JSON.parse(node.attributes) as LocalNodeAttributes;+ const attributes = JSON.parse(node.attributes) as NodeAttributes;const updatedAttributes = updater(attributes);const attributesMap = doc.getMap('attributes');diff --git a/desktop/src/main/utils.ts b/desktop/src/main/utils.tsindex 932d7689..9dfc380b 100644--- a/desktop/src/main/utils.ts+++ b/desktop/src/main/utils.ts@@ -1,12 +1,6 @@import { app } from 'electron';import { DeleteResult, InsertResult, UpdateResult } from 'kysely';import path from 'path';-import * as Y from 'yjs';-import { databaseManager } from '@/main/data/database-manager';-import { LocalNodeAttributes } from '@/types/nodes';-import { generateId, IdType } from '@/lib/id';-import { fromUint8Array, toUint8Array } from 'js-base64';-import { LocalUpdateNodeChangeData } from '@/types/sync';export const appPath = app.getPath('userData');diff --git a/desktop/src/operations/queries/node-get.ts b/desktop/src/operations/queries/node-get.tsindex 0625b936..c969ebe6 100644--- a/desktop/src/operations/queries/node-get.ts+++ b/desktop/src/operations/queries/node-get.ts@@ -1,4 +1,4 @@-import { LocalNode } from '@/types/nodes';+import { Node } from '@/registry';export type NodeGetQueryInput = {type: 'node_get';@@ -10,7 +10,7 @@ declare module '@/operations/queries' {interface QueryMap {node_get: {input: NodeGetQueryInput;- output: LocalNode | null;+ output: Node | null;};}}diff --git a/desktop/src/operations/queries/record-list.ts b/desktop/src/operations/queries/record-list.tsindex 63010695..8ed2b34f 100644--- a/desktop/src/operations/queries/record-list.ts+++ b/desktop/src/operations/queries/record-list.ts@@ -1,4 +1,4 @@-import { RecordNode } from '@/types/nodes';+import { RecordNode } from '@/registry';import { ViewFilterAttributes, ViewSortAttributes } from '@/registry';export type RecordListQueryInput = {diff --git a/desktop/src/operations/queries/workspace-user-list.ts b/desktop/src/operations/queries/workspace-user-list.tsindex 2501880d..44ce28fa 100644--- a/desktop/src/operations/queries/workspace-user-list.ts+++ b/desktop/src/operations/queries/workspace-user-list.ts@@ -1,4 +1,4 @@-import { UserNode } from '@/types/nodes';+import { UserNode } from '@/registry';export type WorkspaceUserListQueryInput = {type: 'workspace_user_list';diff --git a/desktop/src/registry/index.ts b/desktop/src/registry/index.tsindex b660d46a..1f4b0400 100644--- a/desktop/src/registry/index.ts+++ b/desktop/src/registry/index.ts@@ -1,14 +1,14 @@-import { ChannelRegistry } from '@/registry/channel';+import { ChannelAttributes, ChannelRegistry } from '@/registry/channel';import { NodeRegistry } from '@/registry/core';-import { PageRegistry } from '@/registry/page';-import { ChatRegistry } from '@/registry/chat';-import { SpaceRegistry } from '@/registry/space';-import { UserRegistry } from '@/registry/user';-import { MessageRegistry } from '@/registry/message';-import { DatabaseRegistry } from '@/registry/database';-import { FileRegistry } from '@/registry/file';-import { FolderRegistry } from '@/registry/folder';-import { RecordRegistry } from '@/registry/record';+import { PageAttributes, PageRegistry } from '@/registry/page';+import { ChatAttributes, ChatRegistry } from '@/registry/chat';+import { SpaceAttributes, SpaceRegistry } from '@/registry/space';+import { UserAttributes, UserRegistry } from '@/registry/user';+import { MessageAttributes, MessageRegistry } from '@/registry/message';+import { DatabaseAttributes, DatabaseRegistry } from '@/registry/database';+import { FileAttributes, FileRegistry } from '@/registry/file';+import { FolderAttributes, FolderRegistry } from '@/registry/folder';+import { RecordAttributes, RecordRegistry } from '@/registry/record';export * from '@/registry/channel';export * from '@/registry/core';@@ -36,3 +36,91 @@ export const registryMap: Record<string, NodeRegistry> = {space: SpaceRegistry,user: UserRegistry,};++type NodeBase = {+ id: string;+ parentId: string | null;+ index: string | null;+ createdAt: string;+ createdBy: string;+ updatedAt: string | null;+ updatedBy: string | null;+ versionId: string;+ serverCreatedAt: string | null;+ serverUpdatedAt: string | null;+ serverVersionId: string | null;+};++export type ChannelNode = NodeBase & {+ type: 'channel';+ attributes: ChannelAttributes;+};++export type ChatNode = NodeBase & {+ type: 'chat';+ attributes: ChatAttributes;+};++export type DatabaseNode = NodeBase & {+ type: 'database';+ attributes: DatabaseAttributes;+};++export type FileNode = NodeBase & {+ type: 'file';+ attributes: FileAttributes;+};++export type FolderNode = NodeBase & {+ type: 'folder';+ attributes: FolderAttributes;+};++export type MessageNode = NodeBase & {+ type: 'message';+ attributes: MessageAttributes;+};++export type PageNode = NodeBase & {+ type: 'page';+ attributes: PageAttributes;+};++export type RecordNode = NodeBase & {+ type: 'record';+ attributes: RecordAttributes;+};++export type SpaceNode = NodeBase & {+ type: 'space';+ attributes: SpaceAttributes;+};++export type UserNode = NodeBase & {+ type: 'user';+ attributes: UserAttributes;+};++export type Node =+ | ChannelNode+ | ChatNode+ | DatabaseNode+ | FileNode+ | FolderNode+ | MessageNode+ | PageNode+ | RecordNode+ | SpaceNode+ | UserNode;++export type NodeAttributes =+ | UserAttributes+ | SpaceAttributes+ | DatabaseAttributes+ | ChannelAttributes+ | ChatAttributes+ | FileAttributes+ | FolderAttributes+ | MessageAttributes+ | PageAttributes+ | RecordAttributes;diff --git a/desktop/src/renderer/components/databases/boards/board-view-card.tsx b/desktop/src/renderer/components/databases/boards/board-view-card.tsxindex b24bf547..d0ca677d 100644--- a/desktop/src/renderer/components/databases/boards/board-view-card.tsx+++ b/desktop/src/renderer/components/databases/boards/board-view-card.tsx@@ -1,7 +1,7 @@import React from 'react';import { useWorkspace } from '@/renderer/contexts/workspace';import { useMutation } from '@/renderer/hooks/use-mutation';-import { RecordNode } from '@/types/nodes';+import { RecordNode } from '@/registry';import { SelectFieldAttributes, SelectOptionAttributes } from '@/registry';import { useDrag } from 'react-dnd';import { cn } from '@/lib/utils';diff --git a/desktop/src/renderer/components/databases/calendars/calendar-view-card.tsx b/desktop/src/renderer/components/databases/calendars/calendar-view-card.tsxindex d2d10d3f..2f918cad 100644--- a/desktop/src/renderer/components/databases/calendars/calendar-view-card.tsx+++ b/desktop/src/renderer/components/databases/calendars/calendar-view-card.tsx@@ -1,6 +1,6 @@import React from 'react';import { useWorkspace } from '@/renderer/contexts/workspace';-import { RecordNode } from '@/types/nodes';+import { RecordNode } from '@/registry';import { cn } from '@/lib/utils';interface CalendarViewCardProps {diff --git a/desktop/src/renderer/components/databases/calendars/calendar-view-day.tsx b/desktop/src/renderer/components/databases/calendars/calendar-view-day.tsxindex a3d931bb..38840eb4 100644--- a/desktop/src/renderer/components/databases/calendars/calendar-view-day.tsx+++ b/desktop/src/renderer/components/databases/calendars/calendar-view-day.tsx@@ -1,6 +1,6 @@import React from 'react';import { cn, isSameDay } from '@/lib/utils';-import { RecordNode } from '@/types/nodes';+import { RecordNode } from '@/registry';import { CalendarViewCard } from '@/renderer/components/databases/calendars/calendar-view-card';import { Plus } from 'lucide-react';diff --git a/desktop/src/renderer/components/databases/tables/table-view-field-cell.tsx b/desktop/src/renderer/components/databases/tables/table-view-field-cell.tsxindex f8f9cb20..b9c63f93 100644--- a/desktop/src/renderer/components/databases/tables/table-view-field-cell.tsx+++ b/desktop/src/renderer/components/databases/tables/table-view-field-cell.tsx@@ -1,5 +1,5 @@import React from 'react';-import { RecordNode } from '@/types/nodes';+import { RecordNode } from '@/registry';import { FieldAttributes } from '@/registry';import { TableViewTextCell } from '@/renderer/components/databases/tables/cells/table-view-text-cell';import { TableViewNumberCell } from '@/renderer/components/databases/tables/cells/table-view-number-cell';diff --git a/desktop/src/renderer/components/databases/tables/table-view-name-cell.tsx b/desktop/src/renderer/components/databases/tables/table-view-name-cell.tsxindex 4b34cb1a..0466bf5e 100644--- a/desktop/src/renderer/components/databases/tables/table-view-name-cell.tsx+++ b/desktop/src/renderer/components/databases/tables/table-view-name-cell.tsx@@ -2,7 +2,7 @@ import React from 'react';import isHotkey from 'is-hotkey';import { useWorkspace } from '@/renderer/contexts/workspace';import { Spinner } from '@/renderer/components/ui/spinner';-import { RecordNode } from '@/types/nodes';+import { RecordNode } from '@/registry';import { useMutation } from '@/renderer/hooks/use-mutation';import { Maximize2 } from 'lucide-react';diff --git a/desktop/src/renderer/components/databases/tables/table-view-row.tsx b/desktop/src/renderer/components/databases/tables/table-view-row.tsxindex ce5b318f..74b107b1 100644--- a/desktop/src/renderer/components/databases/tables/table-view-row.tsx+++ b/desktop/src/renderer/components/databases/tables/table-view-row.tsx@@ -1,9 +1,9 @@import React from 'react';import { TableViewNameCell } from '@/renderer/components/databases/tables/table-view-name-cell';import { TableViewFieldCell } from '@/renderer/components/databases/tables/table-view-field-cell';-import { RecordNode } from '@/types/nodes';+import { RecordNode } from '@/registry';import { useView } from '@/renderer/contexts/view';-import { RecordProvider } from '../../records/record-provider';+import { RecordProvider } from '@/renderer/components/records/record-provider';interface TableViewRowProps {index: number;diff --git a/desktop/src/renderer/components/records/record-provider.tsx b/desktop/src/renderer/components/records/record-provider.tsxindex 186ab30f..61b41d71 100644--- a/desktop/src/renderer/components/records/record-provider.tsx+++ b/desktop/src/renderer/components/records/record-provider.tsx@@ -1,6 +1,6 @@import React from 'react';import { RecordContext } from '@/renderer/contexts/record';-import { RecordNode } from '@/types/nodes';+import { RecordNode } from '@/registry';import { useDatabase } from '@/renderer/contexts/database';import { useWorkspace } from '@/renderer/contexts/workspace';import { useMutation } from '@/renderer/hooks/use-mutation';diff --git a/desktop/src/types/nodes.ts b/desktop/src/types/nodes.tsindex 4e81cbc4..76273ae0 100644--- a/desktop/src/types/nodes.ts+++ b/desktop/src/types/nodes.ts@@ -1,111 +1,11 @@-import {- ChannelAttributes,- ChatAttributes,- DatabaseAttributes,- FileAttributes,- FolderAttributes,- MessageAttributes,- PageAttributes,- RecordAttributes,- SpaceAttributes,- UserAttributes,-} from '@/registry';--type LocalNodeBase = {- id: string;- parentId: string | null;- index: string | null;- state: string;- createdAt: string;- createdBy: string;- updatedAt: string | null;- updatedBy: string | null;- versionId: string;- serverCreatedAt: string | null;- serverUpdatedAt: string | null;- serverVersionId: string | null;-};--export type ChannelNode = LocalNodeBase & {- type: 'channel';- attributes: ChannelAttributes;-};--export type ChatNode = LocalNodeBase & {- type: 'chat';- attributes: ChatAttributes;-};--export type DatabaseNode = LocalNodeBase & {- type: 'database';- attributes: DatabaseAttributes;-};--export type FileNode = LocalNodeBase & {- type: 'file';- attributes: FileAttributes;-};--export type FolderNode = LocalNodeBase & {- type: 'folder';- attributes: FolderAttributes;-};--export type MessageNode = LocalNodeBase & {- type: 'message';- attributes: MessageAttributes;-};--export type PageNode = LocalNodeBase & {- type: 'page';- attributes: PageAttributes;-};--export type RecordNode = LocalNodeBase & {- type: 'record';- attributes: RecordAttributes;-};--export type SpaceNode = LocalNodeBase & {- type: 'space';- attributes: SpaceAttributes;-};--export type UserNode = LocalNodeBase & {- type: 'user';- attributes: UserAttributes;-};--export type LocalNode =- | ChannelNode- | ChatNode- | DatabaseNode- | FileNode- | FolderNode- | MessageNode- | PageNode- | RecordNode- | SpaceNode- | UserNode;--export type LocalNodeAttributes =- | UserAttributes- | SpaceAttributes- | DatabaseAttributes- | ChannelAttributes- | ChatAttributes- | FileAttributes- | FolderAttributes- | MessageAttributes- | PageAttributes- | RecordAttributes;+import { NodeAttributes } from '@/registry';export type ServerNode = {id: string;parentId: string | null;type: string;index: string | null;- attributes: LocalNodeAttributes;+ attributes: NodeAttributes;state: string;createdAt: string;createdBy: string;