There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
refactor: workspaces -> workspaceMetaCollection
alt0ff63de2aa530
diff --git a/packages/data-center/src/datacenter.ts b/packages/data-center/src/datacenter.tsindex 8455737b5a..1efb93ca79 100644--- a/packages/data-center/src/datacenter.ts+++ b/packages/data-center/src/datacenter.ts@@ -1,5 +1,5 @@-import { Workspaces } from './workspaces';-import type { WorkspacesChangeEvent } from './workspaces';+import { WorkspaceMetaCollection } from './workspace-meta-collection.js';+import type { WorkspaceMetaCollectionChangeEvent } from './workspace-meta-collection';import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';import { BaseProvider } from './provider/base';import { LocalProvider } from './provider/local/local';@@ -15,7 +15,7 @@ import { createBlocksuiteWorkspace } from './utils/index.js';* @classdesc Data center is made for managing different providers for business*/export class DataCenter {- private readonly _workspaces = new Workspaces();+ private readonly _workspaceMetaCollection = new WorkspaceMetaCollection();private readonly _logger = getLogger('dc');private _workspaceInstances: Map<string, BlocksuiteWorkspace> = new Map();/**@@ -34,13 +34,13 @@ export class DataCenter {dc.registerProvider(new LocalProvider({logger: dc._logger,- workspaces: dc._workspaces.createScope(),+ workspaces: dc._workspaceMetaCollection.createScope(),}));dc.registerProvider(new AffineProvider({logger: dc._logger,- workspaces: dc._workspaces.createScope(),+ workspaces: dc._workspaceMetaCollection.createScope(),}));@@ -69,7 +69,7 @@ export class DataCenter {}public get workspaces() {- return this._workspaces.workspaces;+ return this._workspaceMetaCollection.workspaces;}public async refreshWorkspaces() {@@ -104,7 +104,7 @@ export class DataCenter {* @param {string} workspaceId workspace id*/public async deleteWorkspace(workspaceId: string) {- const workspaceInfo = this._workspaces.find(workspaceId);+ const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);assert(workspaceInfo, 'Workspace not found');const provider = this.providerMap.get(workspaceInfo.provider);assert(provider, `Workspace exists, but we couldn't find its provider.`);@@ -116,7 +116,7 @@ export class DataCenter {* @param {string} workspaceId workspace id*/private _getBlocksuiteWorkspace(workspaceId: string) {- const workspaceInfo = this._workspaces.find(workspaceId);+ const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);assert(workspaceInfo, 'Workspace not found');return (this._workspaceInstances.get(workspaceId) ||@@ -150,7 +150,7 @@ export class DataCenter {* @returns {Promise<BlocksuiteWorkspace>}*/public async loadWorkspace(workspaceId: string) {- const workspaceInfo = this._workspaces.find(workspaceId);+ const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);assert(workspaceInfo, 'Workspace not found');const currentProvider = this.providerMap.get(workspaceInfo.provider);if (currentProvider) {@@ -181,9 +181,9 @@ export class DataCenter {* @param {Function} callback callback function*/public async onWorkspacesChange(- callback: (workspaces: WorkspacesChangeEvent) => void+ callback: (workspaces: WorkspaceMetaCollectionChangeEvent) => void) {- this._workspaces.on('change', callback);+ this._workspaceMetaCollection.on('change', callback);}/**@@ -206,7 +206,7 @@ export class DataCenter {update.avatar = avatar;}// may run for change workspace meta- const workspaceInfo = this._workspaces.find(workspace.room);+ const workspaceInfo = this._workspaceMetaCollection.find(workspace.room);assert(workspaceInfo, 'Workspace not found');const provider = this.providerMap.get(workspaceInfo.provider);provider?.updateWorkspaceMeta(workspace.room, update);@@ -218,7 +218,7 @@ export class DataCenter {* @param id workspace id*/public async leaveWorkspace(workspaceId: string) {- const workspaceInfo = this._workspaces.find(workspaceId);+ const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);assert(workspaceInfo, 'Workspace not found');const provider = this.providerMap.get(workspaceInfo.provider);if (provider) {@@ -228,7 +228,7 @@ export class DataCenter {}public async setWorkspacePublish(workspaceId: string, isPublish: boolean) {- const workspaceInfo = this._workspaces.find(workspaceId);+ const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);assert(workspaceInfo, 'Workspace not found');const provider = this.providerMap.get(workspaceInfo.provider);if (provider) {@@ -237,7 +237,7 @@ export class DataCenter {}public async inviteMember(id: string, email: string) {- const workspaceInfo = this._workspaces.find(id);+ const workspaceInfo = this._workspaceMetaCollection.find(id);assert(workspaceInfo, 'Workspace not found');const provider = this.providerMap.get(workspaceInfo.provider);if (provider) {@@ -250,7 +250,7 @@ export class DataCenter {* @param {number} permissionId permission id*/public async removeMember(workspaceId: string, permissionId: number) {- const workspaceInfo = this._workspaces.find(workspaceId);+ const workspaceInfo = this._workspaceMetaCollection.find(workspaceId);assert(workspaceInfo, 'Workspace not found');const provider = this.providerMap.get(workspaceInfo.provider);if (provider) {@@ -281,7 +281,7 @@ export class DataCenter {providerId: string) {assert(workspace.room, 'No workspace id');- const workspaceInfo = this._workspaces.find(workspace.room);+ const workspaceInfo = this._workspaceMetaCollection.find(workspace.room);assert(workspaceInfo, 'Workspace not found');if (workspaceInfo.provider === providerId) {this._logger('Workspace provider is same');diff --git a/packages/data-center/src/provider/base.ts b/packages/data-center/src/provider/base.tsindex f7a056110c..c21939103f 100644--- a/packages/data-center/src/provider/base.ts+++ b/packages/data-center/src/provider/base.ts@@ -1,6 +1,6 @@import { Workspace as BlocksuiteWorkspace, uuidv4 } from '@blocksuite/store';import { Logger, User, WorkspaceInfo, WorkspaceMeta } from '../types';-import type { WorkspacesScope } from '../workspaces';+import type { WorkspaceMetaCollectionScope } from '../workspace-meta-collection';const defaultLogger = () => {return;@@ -8,12 +8,12 @@ const defaultLogger = () => {export interface ProviderConstructorParams {logger?: Logger;- workspaces: WorkspacesScope;+ workspaces: WorkspaceMetaCollectionScope;}export class BaseProvider {public readonly id: string = 'base';- protected _workspaces!: WorkspacesScope;+ protected _workspaces!: WorkspaceMetaCollectionScope;protected _logger!: Logger;public constructor({ logger, workspaces }: ProviderConstructorParams) {diff --git a/packages/data-center/src/workspaces/workspaces.spec.ts b/packages/data-center/src/workspace-meta-collection.spec.tssimilarity index 64%rename from packages/data-center/src/workspaces/workspaces.spec.tsrename to packages/data-center/src/workspace-meta-collection.spec.tsindex c7925fdfff..afb3eb65f5 100644--- a/packages/data-center/src/workspaces/workspaces.spec.ts+++ b/packages/data-center/src/workspace-meta-collection.spec.ts@@ -1,14 +1,14 @@import { test, expect } from '@playwright/test';-import { Workspaces } from './workspaces.js';-import type { WorkspacesChangeEvent } from './workspaces';+import { WorkspaceMetaCollection } from './workspace-meta-collection.js';+import type { WorkspaceMetaCollectionChangeEvent } from './workspace-meta-collection';-test.describe.serial('workspaces observable', () => {- const workspaces = new Workspaces();+test.describe.serial('workspace meta collection observable', () => {+ const workspaces = new WorkspaceMetaCollection();const scope = workspaces.createScope();test('add workspace', () => {- workspaces.once('change', (event: WorkspacesChangeEvent) => {+ workspaces.once('change', (event: WorkspaceMetaCollectionChangeEvent) => {expect(event.added?.id).toEqual('123');});scope.add({@@ -30,7 +30,7 @@ test.describe.serial('workspaces observable', () => {});test('update workspace', () => {- workspaces.once('change', (event: WorkspacesChangeEvent) => {+ workspaces.once('change', (event: WorkspaceMetaCollectionChangeEvent) => {expect(event.updated?.name).toEqual('demo');});scope.update('123', { name: 'demo' });@@ -42,7 +42,7 @@ test.describe.serial('workspaces observable', () => {});test('delete workspace', () => {- workspaces.once('change', (event: WorkspacesChangeEvent) => {+ workspaces.once('change', (event: WorkspaceMetaCollectionChangeEvent) => {expect(event.deleted?.id).toEqual('123');});scope.remove('123');diff --git a/packages/data-center/src/workspaces/workspaces.ts b/packages/data-center/src/workspace-meta-collection.tssimilarity index 86%rename from packages/data-center/src/workspaces/workspaces.tsrename to packages/data-center/src/workspace-meta-collection.tsindex d248951dc7..6b7ce4a350 100644--- a/packages/data-center/src/workspaces/workspaces.ts+++ b/packages/data-center/src/workspace-meta-collection.ts@@ -1,7 +1,7 @@import { Observable } from 'lib0/observable';-import type { WorkspaceInfo, WorkspaceMeta } from '../types';+import type { WorkspaceInfo, WorkspaceMeta } from './types';-export interface WorkspacesScope {+export interface WorkspaceMetaCollectionScope {get: (workspaceId: string) => WorkspaceInfo | undefined;list: () => WorkspaceInfo[];add: (workspace: WorkspaceInfo) => void;@@ -10,13 +10,13 @@ export interface WorkspacesScope {update: (workspaceId: string, workspaceMeta: Partial<WorkspaceMeta>) => void;}-export interface WorkspacesChangeEvent {+export interface WorkspaceMetaCollectionChangeEvent {added?: WorkspaceInfo;deleted?: WorkspaceInfo;updated?: WorkspaceInfo;}-export class Workspaces extends Observable<'change'> {+export class WorkspaceMetaCollection extends Observable<'change'> {private _workspacesMap = new Map<string, WorkspaceInfo>();get workspaces(): WorkspaceInfo[] {@@ -27,7 +27,7 @@ export class Workspaces extends Observable<'change'> {return this._workspacesMap.get(workspaceId);}- createScope(): WorkspacesScope {+ createScope(): WorkspaceMetaCollectionScope {const scopedWorkspaceIds = new Set<string>();const get = (workspaceId: string) => {@@ -47,7 +47,7 @@ export class Workspaces extends Observable<'change'> {this.emit('change', [{added: workspace,- } as WorkspacesChangeEvent,+ } as WorkspaceMetaCollectionChangeEvent,]);};@@ -69,7 +69,7 @@ export class Workspaces extends Observable<'change'> {this.emit('change', [{deleted: workspace,- } as WorkspacesChangeEvent,+ } as WorkspaceMetaCollectionChangeEvent,]);}return true;@@ -99,7 +99,7 @@ export class Workspaces extends Observable<'change'> {this.emit('change', [{updated: this._workspacesMap.get(workspaceId),- } as WorkspacesChangeEvent,+ } as WorkspaceMetaCollectionChangeEvent,]);};diff --git a/packages/data-center/src/workspaces/index.ts b/packages/data-center/src/workspaces/index.tsdeleted file mode 100644index a8ef316e8d..0000000000--- a/packages/data-center/src/workspaces/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export { Workspaces } from './workspaces.js';-export type { WorkspacesScope, WorkspacesChangeEvent } from './workspaces';