mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Move id and contants in core package and use lodash-es package
This commit is contained in:
@@ -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';
|
||||
|
||||
44
packages/core/src/lib/constants.ts
Normal file
44
packages/core/src/lib/constants.ts
Normal 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',
|
||||
};
|
||||
84
packages/core/src/lib/id.ts
Normal file
84
packages/core/src/lib/id.ts
Normal 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;
|
||||
}
|
||||
};
|
||||
@@ -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 = (
|
||||
|
||||
Reference in New Issue
Block a user