Move id and contants in core package and use lodash-es package

This commit is contained in:
Hakan Shehu
2024-11-09 12:20:01 +01:00
parent 56a16ba9b3
commit 372fe62fa8
88 changed files with 140 additions and 512 deletions

View File

@@ -24,6 +24,7 @@
"vitest": "^1.6.0"
},
"dependencies": {
"ulid": "^2.3.0",
"zod": "^3.23.8"
}
}

View File

@@ -1,3 +1,5 @@
export * from './lib/constants';
export * from './lib/id';
export * from './registry/block';
export * from './registry/channel';
export * from './registry/chat';

View File

@@ -0,0 +1,44 @@
export const NodeTypes = {
User: 'user',
Space: 'space',
Page: 'page',
Channel: 'channel',
Chat: 'chat',
Message: 'message',
Database: 'database',
DatabaseReplica: 'databaseReplica',
Record: 'record',
Folder: 'folder',
File: 'file',
};
export const EditorNodeTypes = {
Paragraph: 'paragraph',
Heading1: 'heading1',
Heading2: 'heading2',
Heading3: 'heading3',
Blockquote: 'blockquote',
BulletList: 'bulletList',
CodeBlock: 'codeBlock',
ListItem: 'listItem',
OrderedList: 'orderedList',
TaskList: 'taskList',
TaskItem: 'taskItem',
HorizontalRule: 'horizontalRule',
Page: 'page',
File: 'file',
Folder: 'folder',
FilePlaceholder: 'filePlaceholder',
};
export const SortDirections = {
Ascending: 'asc',
Descending: 'desc',
};
export const NodeRoles = {
Admin: 'admin',
Editor: 'editor',
Collaborator: 'collaborator',
Viewer: 'viewer',
};

View File

@@ -0,0 +1,84 @@
import { monotonicFactory } from 'ulid';
import { NodeTypes } from './constants';
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',
View = 'vw',
Field = 'fi',
SelectOption = 'so',
ViewFilter = 'vf',
ViewSort = 'vs',
Query = 'qu',
Emoji = 'em',
Avatar = 'av',
Icon = 'ic',
File = 'fi',
FilePlaceholder = 'fp',
Device = 'dv',
}
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;
};
export const getIdTypeFromNode = (nodeType: string): IdType => {
switch (nodeType) {
case NodeTypes.User:
return IdType.User;
case NodeTypes.Space:
return IdType.Space;
case NodeTypes.Page:
return IdType.Page;
case NodeTypes.Channel:
return IdType.Channel;
case NodeTypes.Message:
return IdType.Message;
case NodeTypes.Database:
return IdType.Database;
case NodeTypes.DatabaseReplica:
return IdType.DatabaseReplica;
case NodeTypes.Record:
return IdType.Record;
case NodeTypes.Folder:
return IdType.Folder;
default:
return IdType.Node;
}
};

View File

@@ -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'),

View File

@@ -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(),

View File

@@ -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'),

View File

@@ -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'),

View File

@@ -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'),

View File

@@ -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 = (