mirror of
https://github.com/colanode/colanode.git
synced 2025-12-24 15:39:32 +01:00
Move id and contants in core package and use lodash-es package
This commit is contained in:
@@ -104,7 +104,6 @@
|
||||
"tailwind-merge": "^2.5.4",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"ts-pattern": "^5.5.0",
|
||||
"ulid": "^2.3.0",
|
||||
"ws": "^8.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { hashCode } from '@/lib/utils';
|
||||
import { IdType } from '@/lib/id';
|
||||
import { IdType } from '@colanode/core';
|
||||
|
||||
export const getAvatarSizeClasses = (size?: string) => {
|
||||
if (size === 'small') {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { EditorNodeTypes } from '@/lib/constants';
|
||||
import { generateId, getIdTypeFromNode } from '@/lib/id';
|
||||
import { EditorNodeTypes, generateId, getIdTypeFromNode } from '@colanode/core';
|
||||
import { generateNodeIndex } from '@/lib/nodes';
|
||||
import { compareString } from '@/lib/utils';
|
||||
import { JSONContent } from '@tiptap/core';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { generateKeyBetween } from 'fractional-indexing-jittered';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
|
||||
export const generateNodeIndex = (
|
||||
previous?: string | null,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import SQLite from 'better-sqlite3';
|
||||
import { QueryResult } from 'kysely';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export const buildSqlite = (filename: string): SQLite.Database => {
|
||||
const database = new SQLite(filename);
|
||||
@@ -17,7 +17,7 @@ export const extractTablesFromSql = (sql: string): string[] => {
|
||||
|
||||
export const resultHasChanged = <R>(
|
||||
oldResult: QueryResult<R>,
|
||||
newResult: QueryResult<R>,
|
||||
newResult: QueryResult<R>
|
||||
): boolean => {
|
||||
if (oldResult.rows.length !== newResult.rows.length) {
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { generateNodeIndex } from '@/lib/nodes';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { ChannelCreateMutationInput } from '@/operations/mutations/channel-create';
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { NodeRole, NodeTypes } from '@/lib/constants';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType, NodeTypes, NodeRoles } from '@colanode/core';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { ChatCreateMutationInput } from '@/operations/mutations/chat-create';
|
||||
import { sql } from 'kysely';
|
||||
@@ -44,8 +43,8 @@ export class ChatCreateMutationHandler
|
||||
type: 'chat',
|
||||
parentId: input.workspaceId,
|
||||
collaborators: {
|
||||
[input.userId]: NodeRole.Collaborator,
|
||||
[input.otherUserId]: NodeRole.Collaborator,
|
||||
[input.userId]: NodeRoles.Collaborator,
|
||||
[input.otherUserId]: NodeRoles.Collaborator,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { generateNodeIndex } from '@/lib/nodes';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { DatabaseCreateMutationInput } from '@/operations/mutations/database-create';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { generateNodeIndex } from '@/lib/nodes';
|
||||
import { compareString } from '@/lib/utils';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { FileCreateMutationInput } from '@/operations/mutations/file-create';
|
||||
import { fileManager } from '@/main/file-manager';
|
||||
import { FileAttributes } from '@colanode/core';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { FolderCreateMutationInput } from '@/operations/mutations/folder-create';
|
||||
import { FolderAttributes } from '@colanode/core';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { MarkNodeAsSeenMutationInput } from '@/operations/mutations/mark-node-as-seen';
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import * as Y from 'yjs';
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { EditorNodeTypes, NodeTypes } from '@/lib/constants';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType, EditorNodeTypes, NodeTypes } from '@colanode/core';
|
||||
import { MutationChange, MutationHandler, MutationResult } from '@/main/types';
|
||||
import { MessageCreateMutationInput } from '@/operations/mutations/message-create';
|
||||
import { mapContentsToBlocks } from '@/lib/editor';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { NodeAttributeDeleteMutationInput } from '@/operations/mutations/node-attribute-delete';
|
||||
import { nodeManager } from '@/main/node-manager';
|
||||
import { unset } from 'lodash';
|
||||
import { unset } from 'lodash-es';
|
||||
|
||||
export class NodeAttributeDeleteMutationHandler
|
||||
implements MutationHandler<NodeAttributeDeleteMutationInput>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { NodeAttributeSetMutationInput } from '@/operations/mutations/node-attribute-set';
|
||||
import { nodeManager } from '@/main/node-manager';
|
||||
import { set } from 'lodash';
|
||||
import { set } from 'lodash-es';
|
||||
|
||||
export class NodeAttributeSetMutationHandler
|
||||
implements MutationHandler<NodeAttributeSetMutationInput>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { NodeCollaboratorCreateMutationInput } from '@/operations/mutations/node-collaborator-create';
|
||||
import { nodeManager } from '@/main/node-manager';
|
||||
import { set } from 'lodash';
|
||||
import { set } from 'lodash-es';
|
||||
|
||||
export class NodeCollaboratorCreateMutationHandler
|
||||
implements MutationHandler<NodeCollaboratorCreateMutationInput>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { nodeManager } from '@/main/node-manager';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { NodeCollaboratorDeleteMutationInput } from '@/operations/mutations/node-collaborator-delete';
|
||||
import { unset } from 'lodash';
|
||||
import { unset } from 'lodash-es';
|
||||
|
||||
export class NodeCollaboratorDeleteMutationHandler
|
||||
implements MutationHandler<NodeCollaboratorDeleteMutationInput>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { nodeManager } from '@/main/node-manager';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { NodeCollaboratorUpdateMutationInput } from '@/operations/mutations/node-collaborator-update';
|
||||
import { set } from 'lodash';
|
||||
import { set } from 'lodash-es';
|
||||
|
||||
export class NodeCollaboratorUpdateMutationHandler
|
||||
implements MutationHandler<NodeCollaboratorUpdateMutationInput>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { fileManager } from '@/main/file-manager';
|
||||
import { MutationChange, MutationHandler, MutationResult } from '@/main/types';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { PageCreateMutationInput } from '@/operations/mutations/page-create';
|
||||
import { PageAttributes } from '@colanode/core';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { RecordCreateMutationInput } from '@/operations/mutations/record-create';
|
||||
import { RecordAttributes } from '@colanode/core';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { generateNodeIndex } from '@/lib/nodes';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { SelectOptionCreateMutationInput } from '@/operations/mutations/select-option-create';
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType, NodeRoles } from '@colanode/core';
|
||||
import { generateNodeIndex } from '@/lib/nodes';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { SpaceCreateMutationInput } from '@/operations/mutations/space-create';
|
||||
import { NodeRole } from '@/lib/constants';
|
||||
import {
|
||||
ChannelAttributes,
|
||||
PageAttributes,
|
||||
@@ -26,7 +25,7 @@ export class SpaceCreateMutationHandler
|
||||
type: 'space',
|
||||
name: input.name,
|
||||
collaborators: {
|
||||
[input.userId]: NodeRole.Admin,
|
||||
[input.userId]: NodeRoles.Admin,
|
||||
},
|
||||
parentId: input.workspaceId,
|
||||
description: input.description,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { MutationHandler, MutationResult } from '@/main/types';
|
||||
import { ViewCreateMutationInput } from '@/operations/mutations/view-create';
|
||||
import { compareString } from '@/lib/utils';
|
||||
|
||||
@@ -2,7 +2,7 @@ import { AccountListQueryInput } from '@/operations/queries/account-list';
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { Account } from '@/types/accounts';
|
||||
import { SelectAccount } from '@/main/data/app/schema';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import {
|
||||
MutationChange,
|
||||
ChangeCheckResult,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { sql } from 'kysely';
|
||||
import { SelectNode } from '@/main/data/workspace/schema';
|
||||
import { BreadcrumbNode } from '@/types/workspaces';
|
||||
import { mapNode } from '@/main/utils';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import {
|
||||
MutationChange,
|
||||
ChangeCheckResult,
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { ChatNode } from '@/types/chats';
|
||||
|
||||
export class ChatGetQueryHandler implements QueryHandler<ChatGetQueryInput> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { sha256 } from 'js-sha256';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import {
|
||||
DocumentGetQueryInput,
|
||||
DocumentGetQueryOutput,
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { FileDetails } from '@/types/files';
|
||||
|
||||
interface FileRow {
|
||||
|
||||
@@ -6,9 +6,9 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { compareString } from '@/lib/utils';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { FileNode } from '@/types/files';
|
||||
|
||||
interface FileRow {
|
||||
|
||||
@@ -7,12 +7,12 @@ import {
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { SelectNode } from '@/main/data/workspace/schema';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { MessageNode, MessageReactionCount } from '@/types/messages';
|
||||
import { mapNode } from '@/main/utils';
|
||||
import { UserNode } from '@/types/users';
|
||||
import { compareString } from '@/lib/utils';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { mapBlocksToContents } from '@/lib/editor';
|
||||
|
||||
export class MessageListQueryHandler
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
type ExtractedNodeCollaborator = {
|
||||
nodeId: string;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NodeCollaboratorSearchQueryInput } from '@/operations/queries/node-coll
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { sql } from 'kysely';
|
||||
import { SelectNode } from '@/main/data/workspace/schema';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { NodeCollaborator } from '@/types/nodes';
|
||||
import {
|
||||
MutationChange,
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class NodeCollaboratorSearchQueryHandler
|
||||
implements QueryHandler<NodeCollaboratorSearchQueryInput>
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class NodeGetQueryHandler implements QueryHandler<NodeGetQueryInput> {
|
||||
public async handleQuery(
|
||||
|
||||
@@ -28,8 +28,8 @@ import {
|
||||
} from '@colanode/core';
|
||||
import { isStringArray } from '@/lib/utils';
|
||||
import { mapNode } from '@/main/utils';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { isEqual } from 'lodash';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class RecordListQueryHandler
|
||||
implements QueryHandler<RecordListQueryInput>
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { Server } from '@/types/servers';
|
||||
|
||||
export class ServerListQueryHandler
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SidebarChatListQueryInput } from '@/operations/queries/sidebar-chat-list';
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { SelectNode } from '@/main/data/workspace/schema';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { SidebarChatNode } from '@/types/workspaces';
|
||||
import { mapNode } from '@/main/utils';
|
||||
import {
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
interface UnreadCountRow {
|
||||
node_id: string;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { SidebarSpaceListQueryInput } from '@/operations/queries/sidebar-space-l
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { sql } from 'kysely';
|
||||
import { SelectNode } from '@/main/data/workspace/schema';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { SidebarNode, SidebarSpaceNode } from '@/types/workspaces';
|
||||
import { mapNode } from '@/main/utils';
|
||||
import { Node } from '@colanode/core';
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { compareString } from '@/lib/utils';
|
||||
|
||||
interface UnreadCountRow {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { UserSearchQueryInput } from '@/operations/queries/user-search';
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { sql } from 'kysely';
|
||||
import { SelectNode } from '@/main/data/workspace/schema';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { UserNode } from '@/types/users';
|
||||
import {
|
||||
MutationChange,
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class UserSearchQueryHandler
|
||||
implements QueryHandler<UserSearchQueryInput>
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class WorkspaceListQueryHandler
|
||||
implements QueryHandler<WorkspaceListQueryInput>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { WorkspaceUserListQueryInput } from '@/operations/queries/workspace-user-list';
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { mapNode } from '@/main/utils';
|
||||
import { SelectNode } from '@/main/data/workspace/schema';
|
||||
import { UserNode } from '@colanode/core';
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
QueryHandler,
|
||||
QueryResult,
|
||||
} from '@/main/types';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class WorkspaceUserListQueryHandler
|
||||
implements QueryHandler<WorkspaceUserListQueryInput>
|
||||
|
||||
@@ -6,8 +6,7 @@ import {
|
||||
LocalCreateNodeChangeData,
|
||||
LocalUpdateNodeChangeData,
|
||||
} from '@/types/sync';
|
||||
import { generateId } from '@/lib/id';
|
||||
import { IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { databaseManager } from '@/main/data/database-manager';
|
||||
import { hasUpdateChanges } from '@/main/utils';
|
||||
import { Transaction } from 'kysely';
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
getColorForId,
|
||||
getDefaultNodeAvatar,
|
||||
} from '@/lib/avatars';
|
||||
import { getIdType, IdType } from '@/lib/id';
|
||||
import { getIdType, IdType } from '@colanode/core';
|
||||
import { getEmojiUrl } from '@/lib/emojis';
|
||||
import { getIconUrl } from '@/lib/icons';
|
||||
import { useAccount } from '@/renderer/contexts/account';
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from '@/renderer/components/ui/dropdown-menu';
|
||||
import { Button } from '@/renderer/components/ui/button';
|
||||
import { SortDirections } from '@/lib/constants';
|
||||
import { SortDirections } from '@colanode/core';
|
||||
import { useView } from '@/renderer/contexts/view';
|
||||
import { FieldIcon } from '@/renderer/components/databases/fields/field-icon';
|
||||
import { ChevronDown, Trash2 } from 'lucide-react';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import '@/renderer/styles/editor.css';
|
||||
import { debounce } from 'lodash';
|
||||
import { debounce } from 'lodash-es';
|
||||
import { useEditor, EditorContent, JSONContent } from '@tiptap/react';
|
||||
import {
|
||||
ParagraphCommand,
|
||||
@@ -85,7 +85,7 @@ export const DocumentEditor = ({
|
||||
},
|
||||
});
|
||||
}, 500),
|
||||
[mutate, documentId, workspace.userId],
|
||||
[mutate, documentId, workspace.userId]
|
||||
);
|
||||
|
||||
const editor = useEditor(
|
||||
@@ -164,7 +164,7 @@ export const DocumentEditor = ({
|
||||
}
|
||||
},
|
||||
},
|
||||
[documentId],
|
||||
[documentId]
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useInfiniteQuery } from '@/renderer/hooks/use-infinite-query';
|
||||
import { GridLayout } from '@/renderer/components/folders/grids/grid-layout';
|
||||
import { ListLayout } from '@/renderer/components/folders/lists/list-layout';
|
||||
import { GalleryLayout } from '@/renderer/components/folders/galleries/gallery-layout';
|
||||
import { getIdType, IdType } from '@/lib/id';
|
||||
import { getIdType, IdType } from '@colanode/core';
|
||||
|
||||
const FILES_PER_PAGE = 100;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Avatar } from '@/renderer/components/avatars/avatar';
|
||||
import { BreadcrumbNode } from '@/types/workspaces';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
|
||||
interface BreadcrumbNodeProps {
|
||||
node: BreadcrumbNode;
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/renderer/components/ui/dropdown-menu';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { useWorkspace } from '@/renderer/contexts/workspace';
|
||||
import { BreadcrumbItem } from '@/renderer/components/workspaces/containers/breadcrumb-item';
|
||||
import { BreadcrumbItemPopover } from '@/renderer/components/workspaces/containers/breadcrumb-item-popover';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getIdType, IdType } from '@/lib/id';
|
||||
import { getIdType, IdType } from '@colanode/core';
|
||||
import { Breadcrumb } from '@/renderer/components/workspaces/containers/breadcrumb';
|
||||
import { ChatBreadcrumb } from '@/renderer/components/workspaces/containers/chat-breadcrumb';
|
||||
import { NodeCollaboratorsPopover } from '@/renderer/components/collaborators/node-collaborators-popover';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { IdType } from '@/lib/id';
|
||||
import { getIdType } from '@/lib/id';
|
||||
import { IdType, getIdType } from '@colanode/core';
|
||||
import { match } from 'ts-pattern';
|
||||
import { ChannelSettings } from '@/renderer/components/channels/channel-settings';
|
||||
import { PageSettings } from '@/renderer/components/pages/page-settings';
|
||||
|
||||
@@ -8,7 +8,7 @@ import { RecordContainer } from '@/renderer/components/records/record-container'
|
||||
import { ChatContainer } from '@/renderer/components/chats/chat-container';
|
||||
import { FolderContainer } from '@/renderer/components/folders/folder-container';
|
||||
import { FileContainer } from '@/renderer/components/files/file-container';
|
||||
import { getIdType, IdType } from '@/lib/id';
|
||||
import { getIdType, IdType } from '@colanode/core';
|
||||
|
||||
export const Container = () => {
|
||||
const { nodeId } = useParams<{ nodeId: string }>();
|
||||
|
||||
@@ -6,7 +6,7 @@ import { RecordContainer } from '@/renderer/components/records/record-container'
|
||||
import { ChatContainer } from '@/renderer/components/chats/chat-container';
|
||||
import { FolderContainer } from '@/renderer/components/folders/folder-container';
|
||||
import { FileContainer } from '@/renderer/components/files/file-container';
|
||||
import { getIdType, IdType } from '@/lib/id';
|
||||
import { getIdType, IdType } from '@colanode/core';
|
||||
|
||||
interface ModalContentProps {
|
||||
nodeId: string;
|
||||
|
||||
@@ -18,7 +18,7 @@ import { toast } from '@/renderer/hooks/use-toast';
|
||||
import { useMutation } from '@/renderer/hooks/use-mutation';
|
||||
import { useAccount } from '@/renderer/contexts/account';
|
||||
import { Avatar } from '@/renderer/components/avatars/avatar';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Upload } from 'lucide-react';
|
||||
|
||||
@@ -122,7 +122,7 @@ export const WorkspaceForm = ({
|
||||
<div
|
||||
className={cn(
|
||||
`absolute left-0 top-0 hidden h-32 w-32 items-center justify-center overflow-hidden bg-gray-50 group-hover:inline-flex`,
|
||||
isPending ? 'inline-flex' : 'hidden',
|
||||
isPending ? 'inline-flex' : 'hidden'
|
||||
)}
|
||||
>
|
||||
{isPending ? (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EditorCommand } from '@/types/editor';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { FilePlus } from 'lucide-react';
|
||||
|
||||
export const FileCommand: EditorCommand = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EditorCommand } from '@/types/editor';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { Folder } from 'lucide-react';
|
||||
|
||||
export const FolderCommand: EditorCommand = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EditorCommand } from '@/types/editor';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { FileText } from 'lucide-react';
|
||||
|
||||
export const PageCommand: EditorCommand = {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { mergeAttributes, Node, CommandProps } from '@tiptap/core';
|
||||
import { ReactNodeViewRenderer } from '@tiptap/react';
|
||||
import { FilePlaceholderNodeView } from '@/renderer/editor/views';
|
||||
import { FileMetadata } from '@/types/files';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands<ReturnType> {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Extension } from '@tiptap/react';
|
||||
import { Plugin, PluginKey } from 'prosemirror-state';
|
||||
import { generateId, getIdTypeFromNode } from '@/lib/id';
|
||||
import { EditorNodeTypes } from '@/lib/constants';
|
||||
import { generateId, getIdTypeFromNode, EditorNodeTypes } from '@colanode/core';
|
||||
|
||||
const types = [
|
||||
EditorNodeTypes.Paragraph,
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
import { QueryInput, QueryMap } from '@/operations/queries';
|
||||
import { sha256 } from 'js-sha256';
|
||||
import { useEventBus } from '@/renderer/hooks/use-event-bus';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
|
||||
export const useInfiniteQuery = <T extends QueryInput>({
|
||||
initialPageInput,
|
||||
@@ -11,7 +11,7 @@ export const useInfiniteQuery = <T extends QueryInput>({
|
||||
initialPageInput: T;
|
||||
getNextPageInput: (
|
||||
page: number,
|
||||
pages: Array<QueryMap[T['type']]['output']>,
|
||||
pages: Array<QueryMap[T['type']]['output']>
|
||||
) => T | undefined;
|
||||
}) => {
|
||||
const eventBus = useEventBus();
|
||||
@@ -56,7 +56,7 @@ export const useInfiniteQuery = <T extends QueryInput>({
|
||||
});
|
||||
subscriberIdsRef.current.push({ queryId, subscriberId });
|
||||
},
|
||||
[eventBus],
|
||||
[eventBus]
|
||||
);
|
||||
|
||||
// Function to fetch a page
|
||||
@@ -67,7 +67,7 @@ export const useInfiniteQuery = <T extends QueryInput>({
|
||||
try {
|
||||
const result = await window.neuron.executeQueryAndSubscribe(
|
||||
queryId,
|
||||
input,
|
||||
input
|
||||
);
|
||||
|
||||
// Update pages state
|
||||
@@ -90,7 +90,7 @@ export const useInfiniteQuery = <T extends QueryInput>({
|
||||
console.error('Error executing query:', error);
|
||||
}
|
||||
},
|
||||
[pages, getNextPageInput, subscribeToQueryResult],
|
||||
[pages, getNextPageInput, subscribeToQueryResult]
|
||||
);
|
||||
|
||||
// Fetch the initial page
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
import { QueryInput, QueryMap } from '@/operations/queries';
|
||||
import { sha256 } from 'js-sha256';
|
||||
import { useEventBus } from '@/renderer/hooks/use-event-bus';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
|
||||
export const useQuery = <T extends QueryInput>(input: T) => {
|
||||
const eventBus = useEventBus();
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
"tsup": "^8.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@colanode/core": "workspace:*",
|
||||
"@colanode/crdt": "workspace:*",
|
||||
"@aws-sdk/client-s3": "^3.675.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.675.0",
|
||||
"axios": "^1.7.7",
|
||||
@@ -46,7 +48,6 @@
|
||||
"postgres": "^3.4.4",
|
||||
"redis": "^4.7.0",
|
||||
"sharp": "^0.33.5",
|
||||
"ulid": "^2.3.0",
|
||||
"ws": "^8.18.0",
|
||||
"yjs": "^13.6.20"
|
||||
}
|
||||
|
||||
@@ -1,28 +1,4 @@
|
||||
export const NodeTypes = {
|
||||
User: 'user',
|
||||
Space: 'space',
|
||||
Page: 'page',
|
||||
Channel: 'channel',
|
||||
Chat: 'chat',
|
||||
Message: 'message',
|
||||
Database: 'database',
|
||||
DatabaseReplica: 'database_replica',
|
||||
Record: 'record',
|
||||
Folder: 'folder',
|
||||
TableView: 'table_view',
|
||||
BoardView: 'board_view',
|
||||
CalendarView: 'calendar_view',
|
||||
Field: 'field',
|
||||
SelectOption: 'select_option',
|
||||
File: 'file',
|
||||
};
|
||||
|
||||
export const NodeRoles = {
|
||||
Admin: 'admin',
|
||||
Editor: 'editor',
|
||||
Collaborator: 'collaborator',
|
||||
Viewer: 'viewer',
|
||||
};
|
||||
import { NodeRoles } from '@colanode/core';
|
||||
|
||||
export const hasAdminAccess = (role: string): boolean => {
|
||||
return role === NodeRoles.Admin;
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import { monotonicFactory } from 'ulid';
|
||||
|
||||
const ulid = monotonicFactory();
|
||||
|
||||
export enum IdType {
|
||||
Account = 'ac',
|
||||
Workspace = 'wc',
|
||||
User = 'us',
|
||||
Version = 've',
|
||||
Mutation = 'mu',
|
||||
Space = 'sp',
|
||||
Page = 'pg',
|
||||
Channel = 'ch',
|
||||
Chat = 'ct',
|
||||
Node = 'nd',
|
||||
Message = 'ms',
|
||||
Subscriber = 'sb',
|
||||
Paragraph = 'pa',
|
||||
Heading1 = 'h1',
|
||||
Heading2 = 'h2',
|
||||
Heading3 = 'h3',
|
||||
Blockquote = 'bq',
|
||||
CodeBlock = 'cb',
|
||||
ListItem = 'li',
|
||||
OrderedList = 'ol',
|
||||
BulletList = 'bl',
|
||||
TaskList = 'tl',
|
||||
TaskItem = 'ti',
|
||||
HorizontalRule = 'hr',
|
||||
Database = 'db',
|
||||
DatabaseReplica = 'dr',
|
||||
Record = 'rc',
|
||||
Folder = 'fl',
|
||||
TableView = 'tv',
|
||||
BoardView = 'bv',
|
||||
CalendarView = 'cv',
|
||||
Field = 'fi',
|
||||
SelectOption = 'so',
|
||||
ViewFilter = 'vf',
|
||||
ViewSort = 'vs',
|
||||
Query = 'qu',
|
||||
Device = 'dv',
|
||||
Change = 'cd',
|
||||
Avatar = 'av',
|
||||
}
|
||||
|
||||
export const generateId = (type: IdType): string => {
|
||||
return ulid().toLowerCase() + type;
|
||||
};
|
||||
|
||||
export const isIdOfType = (id: string, type: IdType): boolean => {
|
||||
return id.endsWith(type);
|
||||
};
|
||||
|
||||
export const getIdType = (id: string): IdType => {
|
||||
return id.substring(id.length - 2) as IdType;
|
||||
};
|
||||
@@ -5,12 +5,12 @@ import {
|
||||
WorkspaceStatus,
|
||||
WorkspaceUserStatus,
|
||||
} from '@/types/workspaces';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType, NodeRoles } from '@colanode/core';
|
||||
import * as Y from 'yjs';
|
||||
import { fromUint8Array } from 'js-base64';
|
||||
import { NodeCreatedEvent } from '@/types/events';
|
||||
import { enqueueEvent } from '@/queues/events';
|
||||
import { NodeRoles } from './constants';
|
||||
import {} from './constants';
|
||||
|
||||
export const createDefaultWorkspace = async (account: SelectAccount) => {
|
||||
const createdAt = new Date();
|
||||
@@ -64,7 +64,7 @@ export const createDefaultWorkspace = async (account: SelectAccount) => {
|
||||
|
||||
const buildUserNodeCreate = (
|
||||
workspaceId: string,
|
||||
account: SelectAccount,
|
||||
account: SelectAccount
|
||||
): CreateNode => {
|
||||
const id = generateId(IdType.User);
|
||||
const versionId = generateId(IdType.Version);
|
||||
@@ -99,7 +99,7 @@ const buildUserNodeCreate = (
|
||||
|
||||
const buildSpaceNodeCreate = (
|
||||
workspaceId: string,
|
||||
userId: string,
|
||||
userId: string
|
||||
): CreateNode => {
|
||||
const id = generateId(IdType.Space);
|
||||
const versionId = generateId(IdType.Version);
|
||||
@@ -115,7 +115,7 @@ const buildSpaceNodeCreate = (
|
||||
|
||||
attributesMap.set('collaborators', new Y.Map());
|
||||
const collaboratorsMap = attributesMap.get(
|
||||
'collaborators',
|
||||
'collaborators'
|
||||
) as Y.Map<string>;
|
||||
|
||||
collaboratorsMap.set(userId, NodeRoles.Admin);
|
||||
@@ -139,7 +139,7 @@ const buildSpaceNodeCreate = (
|
||||
const buildPageNodeCreate = (
|
||||
workspaceId: string,
|
||||
spaceId: string,
|
||||
userId: string,
|
||||
userId: string
|
||||
): CreateNode => {
|
||||
const id = generateId(IdType.Page);
|
||||
const versionId = generateId(IdType.Version);
|
||||
@@ -172,7 +172,7 @@ const buildPageNodeCreate = (
|
||||
const buildChannelNodeCreate = (
|
||||
workspaceId: string,
|
||||
spaceId: string,
|
||||
userId: string,
|
||||
userId: string
|
||||
): CreateNode => {
|
||||
const id = generateId(IdType.Channel);
|
||||
const versionId = generateId(IdType.Version);
|
||||
|
||||
@@ -3,8 +3,7 @@ import { redisConfig } from '@/data/redis';
|
||||
import { CreateUserNode } from '@/data/schema';
|
||||
import { filesStorage } from '@/data/storage';
|
||||
import { BUCKET_NAMES } from '@/data/storage';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType, NodeTypes } from '@colanode/core';
|
||||
import { fetchNodeCollaborators, fetchWorkspaceUsers } from '@/lib/nodes';
|
||||
import { synapse } from '@/services/synapse';
|
||||
import {
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from '@/types/accounts';
|
||||
import axios from 'axios';
|
||||
import { ApiError, NeuronRequest, NeuronResponse } from '@/types/api';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { database } from '@/data/database';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { WorkspaceOutput, WorkspaceRole } from '@/types/workspaces';
|
||||
@@ -229,7 +229,7 @@ accountsRouter.delete(
|
||||
});
|
||||
|
||||
return res.status(200).end();
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
accountsRouter.put(
|
||||
@@ -285,7 +285,7 @@ accountsRouter.put(
|
||||
database
|
||||
.selectFrom('workspace_users')
|
||||
.select('id')
|
||||
.where('account_id', '=', req.account.id),
|
||||
.where('account_id', '=', req.account.id)
|
||||
)
|
||||
.execute();
|
||||
|
||||
@@ -301,7 +301,7 @@ accountsRouter.put(
|
||||
updated_at: new Date(),
|
||||
})
|
||||
.where('id', '=', req.account.id)
|
||||
.compile(),
|
||||
.compile()
|
||||
);
|
||||
|
||||
for (const user of users) {
|
||||
@@ -345,7 +345,7 @@ accountsRouter.put(
|
||||
server_updated_at: updatedAt,
|
||||
})
|
||||
.where('id', '=', user.id)
|
||||
.compile(),
|
||||
.compile()
|
||||
);
|
||||
|
||||
const event: NodeUpdatedEvent = {
|
||||
@@ -380,11 +380,11 @@ accountsRouter.put(
|
||||
};
|
||||
|
||||
return res.status(200).json(output);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const buildLoginOutput = async (
|
||||
account: SelectAccount,
|
||||
account: SelectAccount
|
||||
): Promise<LoginOutput> => {
|
||||
let workspaceUsers = await database
|
||||
.selectFrom('workspace_users')
|
||||
@@ -420,7 +420,7 @@ const buildLoginOutput = async (
|
||||
|
||||
for (const workspaceUser of workspaceUsers) {
|
||||
const workspace = workspaces.find(
|
||||
(w) => w.id === workspaceUser.workspace_id,
|
||||
(w) => w.id === workspaceUser.workspace_id
|
||||
);
|
||||
|
||||
if (!workspace) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { avatarStorage, BUCKET_NAMES } from '@/data/storage';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';
|
||||
import { Router } from 'express';
|
||||
import multer from 'multer';
|
||||
@@ -16,7 +16,7 @@ const upload = multer({
|
||||
fileFilter: (req, file, cb) => {
|
||||
const filetypes = /jpeg|jpg|png|webp/;
|
||||
const extname = filetypes.test(
|
||||
path.extname(file.originalname).toLowerCase(),
|
||||
path.extname(file.originalname).toLowerCase()
|
||||
);
|
||||
const mimetype = filetypes.test(file.mimetype);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
WorkspaceStatus,
|
||||
} from '@/types/workspaces';
|
||||
import { ApiError, NeuronRequest, NeuronResponse } from '@/types/api';
|
||||
import { generateId, IdType } from '@/lib/id';
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
import { database } from '@/data/database';
|
||||
import { Router } from 'express';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
SynapseNodeChangeMessage,
|
||||
SynapseUserNodeChangeMessage,
|
||||
} from '@/types/synapse';
|
||||
import { getIdType, IdType } from '@/lib/id';
|
||||
import { getIdType, IdType } from '@colanode/core';
|
||||
import { MessageInput } from '@/types/messages';
|
||||
|
||||
interface SynapseConnection {
|
||||
@@ -91,20 +91,20 @@ class SynapseService {
|
||||
const subscriber = redis.duplicate();
|
||||
await subscriber.connect();
|
||||
await subscriber.subscribe(CHANNEL_NAMES.SYNAPSE, (message) =>
|
||||
this.handleSynapseMessage(message.toString()),
|
||||
this.handleSynapseMessage(message.toString())
|
||||
);
|
||||
}
|
||||
|
||||
private sendSocketMessage(
|
||||
connection: SynapseConnection,
|
||||
message: MessageInput,
|
||||
message: MessageInput
|
||||
) {
|
||||
connection.socket.send(JSON.stringify(message));
|
||||
}
|
||||
|
||||
private async handleSocketMessage(
|
||||
connection: SynapseConnection,
|
||||
message: MessageInput,
|
||||
message: MessageInput
|
||||
) {
|
||||
if (message.type === 'local_node_sync') {
|
||||
await database
|
||||
@@ -123,7 +123,7 @@ class SynapseService {
|
||||
workspace_id: message.workspaceId,
|
||||
node_version_id: message.versionId,
|
||||
node_synced_at: new Date(),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.execute();
|
||||
} else if (message.type === 'local_user_node_sync') {
|
||||
@@ -143,7 +143,7 @@ class SynapseService {
|
||||
workspace_id: message.workspaceId,
|
||||
user_node_version_id: message.versionId,
|
||||
user_node_synced_at: new Date(),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.execute();
|
||||
} else if (message.type === 'local_node_delete') {
|
||||
@@ -154,7 +154,7 @@ class SynapseService {
|
||||
.execute();
|
||||
|
||||
const userId = connection.workspaceUsers.find(
|
||||
(wu) => wu.workspaceId === message.workspaceId,
|
||||
(wu) => wu.workspaceId === message.workspaceId
|
||||
)?.userId;
|
||||
|
||||
if (userId) {
|
||||
@@ -167,7 +167,7 @@ class SynapseService {
|
||||
database
|
||||
.selectFrom('workspace_users')
|
||||
.select('account_id')
|
||||
.where('id', '=', userId),
|
||||
.where('id', '=', userId)
|
||||
)
|
||||
.execute();
|
||||
|
||||
@@ -231,7 +231,7 @@ class SynapseService {
|
||||
.selectFrom('user_nodes')
|
||||
.selectAll()
|
||||
.where((eb) =>
|
||||
eb.and([eb('user_id', 'in', userIds), eb('node_id', '=', data.nodeId)]),
|
||||
eb.and([eb('user_id', 'in', userIds), eb('node_id', '=', data.nodeId)])
|
||||
)
|
||||
.execute();
|
||||
|
||||
@@ -317,7 +317,7 @@ class SynapseService {
|
||||
}
|
||||
|
||||
private async handleUserNodeUpdateMessage(
|
||||
data: SynapseUserNodeChangeMessage,
|
||||
data: SynapseUserNodeChangeMessage
|
||||
) {
|
||||
const userDevices = this.getWorkspaceUserDevices(data.workspaceId);
|
||||
if (!userDevices.has(data.userId)) {
|
||||
@@ -369,7 +369,7 @@ class SynapseService {
|
||||
|
||||
private async sendPendingChanges(connection: SynapseConnection) {
|
||||
const userIds = connection.workspaceUsers.map(
|
||||
(workspaceUser) => workspaceUser.userId,
|
||||
(workspaceUser) => workspaceUser.userId
|
||||
);
|
||||
|
||||
console.log('sendPendingChanges', userIds);
|
||||
@@ -384,7 +384,7 @@ class SynapseService {
|
||||
.leftJoin('device_nodes as nds', (join) =>
|
||||
join
|
||||
.onRef('nds.node_id', '=', 'nus.node_id')
|
||||
.on('nds.device_id', '=', connection.deviceId),
|
||||
.on('nds.device_id', '=', connection.deviceId)
|
||||
)
|
||||
.select([
|
||||
'n.id',
|
||||
@@ -420,7 +420,7 @@ class SynapseService {
|
||||
eb('nds.user_node_version_id', 'is', null),
|
||||
eb('nds.user_node_version_id', '!=', eb.ref('nus.version_id')),
|
||||
]),
|
||||
]),
|
||||
])
|
||||
)
|
||||
.orderBy('n.id', 'asc')
|
||||
.limit(100)
|
||||
@@ -509,7 +509,7 @@ class SynapseService {
|
||||
}
|
||||
|
||||
private async fetchWorkspaceUsers(
|
||||
connection: SynapseConnection,
|
||||
connection: SynapseConnection
|
||||
): Promise<void> {
|
||||
const workspaceUsers = await database
|
||||
.selectFrom('workspace_users')
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import { SelectWorkspaceUser } from '@/data/schema';
|
||||
import { hasAdminAccess, hasEditorAccess } from '@/lib/constants';
|
||||
import { fetchNodeRole } from '@/lib/nodes';
|
||||
import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
|
||||
import { Validator } from '@/types/validators';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class BoardViewValidator implements Validator {
|
||||
async canCreate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
if (!attributes.parentId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const role = await fetchNodeRole(attributes.parentId, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (attributes.collaborators) {
|
||||
return hasAdminAccess(role);
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canUpdate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isEqual(node.attributes.collaborators, attributes.collaborators)) {
|
||||
return hasAdminAccess(role);
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canDelete(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
import { SelectWorkspaceUser } from '@/data/schema';
|
||||
import { hasAdminAccess, hasEditorAccess } from '@/lib/constants';
|
||||
import { fetchNodeRole } from '@/lib/nodes';
|
||||
import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
|
||||
import { Validator } from '@/types/validators';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class CalendarViewValidator implements Validator {
|
||||
async canCreate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
if (!attributes.parentId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const parentId = attributes.parentId;
|
||||
const role = await fetchNodeRole(parentId, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (attributes.collaborators) {
|
||||
return hasAdminAccess(role);
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canUpdate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isEqual(node.attributes.collaborators, attributes.collaborators)) {
|
||||
return hasAdminAccess(role);
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canDelete(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
import { SelectWorkspaceUser } from '@/data/schema';
|
||||
import { hasAdminAccess, hasEditorAccess } from '@/lib/constants';
|
||||
import { fetchNodeRole } from '@/lib/nodes';
|
||||
import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
|
||||
import { Validator } from '@/types/validators';
|
||||
|
||||
export class FieldValidator implements Validator {
|
||||
async canCreate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
attributes: ServerNodeAttributes,
|
||||
): Promise<boolean> {
|
||||
if (!attributes.parentId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const role = await fetchNodeRole(attributes.parentId, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canUpdate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode,
|
||||
attributes: ServerNodeAttributes,
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canDelete(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode,
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { SelectWorkspaceUser } from '@/data/schema';
|
||||
import { hasEditorAccess, NodeTypes } from '@/lib/constants';
|
||||
import { hasEditorAccess } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { extractNodeRole, fetchNodeAncestors } from '@/lib/nodes';
|
||||
import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
|
||||
import { Validator } from '@/types/validators';
|
||||
@@ -7,7 +8,7 @@ import { Validator } from '@/types/validators';
|
||||
export class FileValidator implements Validator {
|
||||
async canCreate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
attributes: ServerNodeAttributes,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
if (!attributes.parentId) {
|
||||
return false;
|
||||
@@ -19,7 +20,7 @@ export class FileValidator implements Validator {
|
||||
}
|
||||
|
||||
const parent = ancestors.find(
|
||||
(ancestor) => ancestor.id === attributes.parentId,
|
||||
(ancestor) => ancestor.id === attributes.parentId
|
||||
);
|
||||
|
||||
if (!parent) {
|
||||
@@ -41,7 +42,7 @@ export class FileValidator implements Validator {
|
||||
async canUpdate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode,
|
||||
attributes: ServerNodeAttributes,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
if (!attributes.parentId) {
|
||||
return false;
|
||||
@@ -53,7 +54,7 @@ export class FileValidator implements Validator {
|
||||
}
|
||||
|
||||
const parent = ancestors.find(
|
||||
(ancestor) => ancestor.id === attributes.parentId,
|
||||
(ancestor) => ancestor.id === attributes.parentId
|
||||
);
|
||||
|
||||
if (!parent) {
|
||||
@@ -74,7 +75,7 @@ export class FileValidator implements Validator {
|
||||
|
||||
async canDelete(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode,
|
||||
node: ServerNode
|
||||
): Promise<boolean> {
|
||||
if (!node.parentId) {
|
||||
return false;
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from '@colanode/core';
|
||||
import { Validator } from '@/types/validators';
|
||||
import { BoardViewValidator } from '@/validators/board-view-validator';
|
||||
import { CalendarViewValidator } from '@/validators/calendar-view-validator';
|
||||
import { ChannelValidator } from '@/validators/channel-validator';
|
||||
import { ChatValidator } from '@/validators/chat-validator';
|
||||
import { DatabaseValidator } from '@/validators/database-validator';
|
||||
import { FieldValidator } from '@/validators/field-validator';
|
||||
import { FileValidator } from '@/validators/file-validator';
|
||||
import { FolderValidator } from '@/validators/folder-validator';
|
||||
import { MessageValidator } from '@/validators/message-validator';
|
||||
import { PageValidator } from '@/validators/page-validator';
|
||||
import { RecordValidator } from '@/validators/record-validator';
|
||||
import { SelectOptionValidator } from '@/validators/select-option-validator';
|
||||
import { SpaceValidator } from '@/validators/space-validator';
|
||||
import { TableViewValidator } from '@/validators/table-view-validator';
|
||||
|
||||
const validators: Record<string, Validator> = {
|
||||
[NodeTypes.BoardView]: new BoardViewValidator(),
|
||||
[NodeTypes.CalendarView]: new CalendarViewValidator(),
|
||||
[NodeTypes.Channel]: new ChannelValidator(),
|
||||
[NodeTypes.Chat]: new ChatValidator(),
|
||||
[NodeTypes.Database]: new DatabaseValidator(),
|
||||
[NodeTypes.Field]: new FieldValidator(),
|
||||
[NodeTypes.File]: new FileValidator(),
|
||||
[NodeTypes.Folder]: new FolderValidator(),
|
||||
[NodeTypes.Message]: new MessageValidator(),
|
||||
[NodeTypes.Page]: new PageValidator(),
|
||||
[NodeTypes.Record]: new RecordValidator(),
|
||||
[NodeTypes.SelectOption]: new SelectOptionValidator(),
|
||||
[NodeTypes.Space]: new SpaceValidator(),
|
||||
[NodeTypes.TableView]: new TableViewValidator(),
|
||||
};
|
||||
|
||||
export const getValidator = (type: string): Validator | undefined => {
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
import { SelectWorkspaceUser } from '@/data/schema';
|
||||
import { hasAdminAccess, hasEditorAccess } from '@/lib/constants';
|
||||
import { fetchNodeRole } from '@/lib/nodes';
|
||||
import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
|
||||
import { Validator } from '@/types/validators';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class SelectOptionValidator implements Validator {
|
||||
async canCreate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
if (!attributes.parentId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const parentId = attributes.parentId;
|
||||
const role = await fetchNodeRole(parentId, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (attributes.collaborators) {
|
||||
return hasAdminAccess(role);
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canUpdate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isEqual(node.attributes.collaborators, attributes.collaborators)) {
|
||||
return hasAdminAccess(role);
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canDelete(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
import { SelectWorkspaceUser } from '@/data/schema';
|
||||
import { hasAdminAccess, hasEditorAccess } from '@/lib/constants';
|
||||
import { fetchNodeRole } from '@/lib/nodes';
|
||||
import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
|
||||
import { Validator } from '@/types/validators';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export class TableViewValidator implements Validator {
|
||||
async canCreate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
if (!attributes.parentId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const role = await fetchNodeRole(attributes.parentId, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (attributes.collaborators) {
|
||||
return hasAdminAccess(role);
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canUpdate(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode,
|
||||
attributes: ServerNodeAttributes
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isEqual(node.attributes.collaborators, attributes.collaborators)) {
|
||||
return hasAdminAccess(role);
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
|
||||
async canDelete(
|
||||
workspaceUser: SelectWorkspaceUser,
|
||||
node: ServerNode
|
||||
): Promise<boolean> {
|
||||
const role = await fetchNodeRole(node.id, workspaceUser.id);
|
||||
if (!role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasEditorAccess(role);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@
|
||||
"references": [
|
||||
{
|
||||
"path": "../../packages/core"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/crdt"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"vitest": "^1.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ulid": "^2.3.0",
|
||||
"zod": "^3.23.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export * from './lib/constants';
|
||||
export * from './lib/id';
|
||||
export * from './registry/block';
|
||||
export * from './registry/channel';
|
||||
export * from './registry/chat';
|
||||
|
||||
@@ -36,7 +36,7 @@ export const SortDirections = {
|
||||
Descending: 'desc',
|
||||
};
|
||||
|
||||
export const NodeRole = {
|
||||
export const NodeRoles = {
|
||||
Admin: 'admin',
|
||||
Editor: 'editor',
|
||||
Collaborator: 'collaborator',
|
||||
@@ -1,5 +1,5 @@
|
||||
import { monotonicFactory } from 'ulid';
|
||||
import { NodeTypes } from '@/lib/constants';
|
||||
import { NodeTypes } from './constants';
|
||||
|
||||
const ulid = monotonicFactory();
|
||||
|
||||
@@ -43,6 +43,7 @@ export enum IdType {
|
||||
Icon = 'ic',
|
||||
File = 'fi',
|
||||
FilePlaceholder = 'fp',
|
||||
Device = 'dv',
|
||||
}
|
||||
|
||||
export const generateId = (type: IdType): string => {
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
import { NodeModel } from './core';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export const channelAttributesSchema = z.object({
|
||||
type: z.literal('channel'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
import { NodeModel } from './core';
|
||||
import { fieldAttributesSchema } from './fields';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export const viewFieldAttributesSchema = z.object({
|
||||
id: z.string(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
import { NodeModel } from './core';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export const folderAttributesSchema = z.object({
|
||||
type: z.literal('folder'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
import { NodeModel } from './core';
|
||||
import { blockSchema } from './block';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export const messageAttributesSchema = z.object({
|
||||
type: z.literal('message'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
import { NodeModel } from './core';
|
||||
import { blockSchema } from './block';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export const pageAttributesSchema = z.object({
|
||||
type: z.literal('page'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
import * as Y from 'yjs';
|
||||
import { ZodText } from '@colanode/core';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { diffChars } from 'diff';
|
||||
|
||||
export const applyCrdt = (
|
||||
|
||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
@@ -282,9 +282,6 @@ importers:
|
||||
ts-pattern:
|
||||
specifier: ^5.5.0
|
||||
version: 5.5.0
|
||||
ulid:
|
||||
specifier: ^2.3.0
|
||||
version: 2.3.0
|
||||
ws:
|
||||
specifier: ^8.18.0
|
||||
version: 8.18.0
|
||||
@@ -436,9 +433,6 @@ importers:
|
||||
sharp:
|
||||
specifier: ^0.33.5
|
||||
version: 0.33.5
|
||||
ulid:
|
||||
specifier: ^2.3.0
|
||||
version: 2.3.0
|
||||
ws:
|
||||
specifier: ^8.18.0
|
||||
version: 8.18.0
|
||||
@@ -476,6 +470,9 @@ importers:
|
||||
|
||||
packages/core:
|
||||
dependencies:
|
||||
ulid:
|
||||
specifier: ^2.3.0
|
||||
version: 2.3.0
|
||||
zod:
|
||||
specifier: ^3.23.8
|
||||
version: 3.23.8
|
||||
|
||||
Reference in New Issue
Block a user