refactor(workspace): split workspace interface and implementation (#5463)
@affine/workspace -> (@affine/workspace, @affine/workspace-impl)
This commit is contained in:
77 files changed
+325
-163
No files matched your search
+6
-1
@@ -32,7 +32,12 @@ mod:plugin-cli:
|
||||
mod:workspace:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- 'packages/frontend/workspace/**/*'
|
||||
- 'packages/common/workspace/**/*'
|
||||
|
||||
mod:workspace-impl:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- 'packages/frontend/workspace-impl/**/*'
|
||||
|
||||
mod:i18n:
|
||||
- changed-files:
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "@affine/workspace",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@blocksuite/blocks": "*",
|
||||
"@blocksuite/global": "*",
|
||||
"@blocksuite/store": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"@affine/debug": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@toeverything/infra": "workspace:*",
|
||||
"lodash-es": "^4.17.21",
|
||||
"yjs": "^13.6.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitest": "1.1.0"
|
||||
},
|
||||
"version": "0.11.0"
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,7 @@
|
||||
export * from './engine';
|
||||
export * from './factory';
|
||||
export * from './global-schema';
|
||||
export * from './list';
|
||||
export * from './manager';
|
||||
export * from './metadata';
|
||||
export * from './workspace';
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -7,7 +7,6 @@ import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
||||
|
||||
import type { BlobStorage } from '.';
|
||||
import type { WorkspaceFactory } from './factory';
|
||||
import { LOCAL_WORKSPACE_LOCAL_STORAGE_KEY } from './impl/local/consts';
|
||||
import type { WorkspaceList } from './list';
|
||||
import type { WorkspaceMetadata } from './metadata';
|
||||
import { WorkspacePool } from './pool';
|
||||
@@ -151,21 +150,6 @@ export class WorkspaceManager {
|
||||
return factory.getWorkspaceBlob(metadata.id, blobKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* a hack for directly add local workspace to workspace list
|
||||
* Used after copying sqlite database file to appdata folder
|
||||
*/
|
||||
_addLocalWorkspace(id: string) {
|
||||
const allWorkspaceIDs: string[] = JSON.parse(
|
||||
localStorage.getItem(LOCAL_WORKSPACE_LOCAL_STORAGE_KEY) ?? '[]'
|
||||
);
|
||||
allWorkspaceIDs.push(id);
|
||||
localStorage.setItem(
|
||||
LOCAL_WORKSPACE_LOCAL_STORAGE_KEY,
|
||||
JSON.stringify(allWorkspaceIDs)
|
||||
);
|
||||
}
|
||||
|
||||
private open(metadata: WorkspaceMetadata) {
|
||||
logger.info(`open workspace [${metadata.flavour}] ${metadata.id} `);
|
||||
const factory = this.factories.find(x => x.name === metadata.flavour);
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -14,7 +14,7 @@
|
||||
{
|
||||
"path": "../../frontend/electron-api"
|
||||
},
|
||||
{ "path": "../../frontend/workspace" },
|
||||
{ "path": "../../common/workspace" },
|
||||
{
|
||||
"path": "../../common/debug"
|
||||
},
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
"@affine/i18n": "workspace:*",
|
||||
"@affine/templates": "workspace:*",
|
||||
"@affine/workspace": "workspace:*",
|
||||
"@affine/workspace-impl": "workspace:*",
|
||||
"@blocksuite/block-std": "0.11.0-nightly-202312220916-e3abcbb",
|
||||
"@blocksuite/blocks": "0.11.0-nightly-202312220916-e3abcbb",
|
||||
"@blocksuite/global": "0.11.0-nightly-202312220916-e3abcbb",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { DEFAULT_WORKSPACE_NAME } from '@affine/env/constant';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { workspaceManager } from '@affine/workspace';
|
||||
import { workspaceManager } from '@affine/workspace-impl';
|
||||
import { getCurrentStore } from '@toeverything/infra/atom';
|
||||
import {
|
||||
buildShowcaseWorkspace,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { DebugLogger } from '@affine/debug';
|
||||
import { apis } from '@affine/electron-api';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { _addLocalWorkspace } from '@affine/workspace-impl';
|
||||
import { getCurrentStore } from '@toeverything/infra/atom';
|
||||
import {
|
||||
buildShowcaseWorkspace,
|
||||
@@ -119,7 +120,7 @@ export const CreateWorkspaceModal = ({
|
||||
setStep(undefined);
|
||||
const result = await apis.dialog.loadDBFile();
|
||||
if (result.workspaceId && !canceled) {
|
||||
workspaceManager._addLocalWorkspace(result.workspaceId);
|
||||
_addLocalWorkspace(result.workspaceId);
|
||||
onCreate(result.workspaceId);
|
||||
} else if (result.error || result.canceled) {
|
||||
if (result.error) {
|
||||
|
||||
@@ -7,10 +7,8 @@ import {
|
||||
listHistoryQuery,
|
||||
recoverDocMutation,
|
||||
} from '@affine/graphql';
|
||||
import {
|
||||
createAffineCloudBlobStorage,
|
||||
globalBlockSuiteSchema,
|
||||
} from '@affine/workspace';
|
||||
import { globalBlockSuiteSchema } from '@affine/workspace';
|
||||
import { createAffineCloudBlobStorage } from '@affine/workspace-impl';
|
||||
import { assertEquals } from '@blocksuite/global/utils';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import { revertUpdate } from '@toeverything/y-indexeddb';
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import {
|
||||
type Workspace,
|
||||
workspaceManager,
|
||||
type WorkspaceMetadata,
|
||||
} from '@affine/workspace';
|
||||
import type { Workspace, WorkspaceMetadata } from '@affine/workspace';
|
||||
import { workspaceManager } from '@affine/workspace-impl';
|
||||
import { atom } from 'jotai';
|
||||
import { atomWithObservable } from 'jotai/utils';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { MainContainer } from '@affine/component/workspace';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { fetchWithTraceReport } from '@affine/graphql';
|
||||
import { globalBlockSuiteSchema } from '@affine/workspace';
|
||||
import {
|
||||
createAffineCloudBlobStorage,
|
||||
createStaticBlobStorage,
|
||||
globalBlockSuiteSchema,
|
||||
} from '@affine/workspace';
|
||||
} from '@affine/workspace-impl';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { type Page, Workspace } from '@blocksuite/store';
|
||||
import { noop } from 'foxact/noop';
|
||||
|
||||
@@ -2,7 +2,7 @@ import { pushNotificationAtom } from '@affine/component/notification-center';
|
||||
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
|
||||
import { affine } from '@affine/electron-api';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { CLOUD_WORKSPACE_CHANGED_BROADCAST_CHANNEL_KEY } from '@affine/workspace';
|
||||
import { CLOUD_WORKSPACE_CHANGED_BROADCAST_CHANNEL_KEY } from '@affine/workspace-impl';
|
||||
import { useAtom, useSetAtom } from 'jotai';
|
||||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||
import { SessionProvider, useSession } from 'next-auth/react';
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
TRACE_ID_BYTES,
|
||||
traceReporter,
|
||||
} from '@affine/graphql';
|
||||
import { CLOUD_WORKSPACE_CHANGED_BROADCAST_CHANNEL_KEY } from '@affine/workspace';
|
||||
import { CLOUD_WORKSPACE_CHANGED_BROADCAST_CHANNEL_KEY } from '@affine/workspace-impl';
|
||||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||
import { signIn, signOut } from 'next-auth/react';
|
||||
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
"path": "../../frontend/i18n"
|
||||
},
|
||||
{
|
||||
"path": "../../frontend/workspace"
|
||||
"path": "../../common/workspace"
|
||||
},
|
||||
{
|
||||
"path": "../../frontend/workspace-impl"
|
||||
},
|
||||
{
|
||||
"path": "../../frontend/electron-api"
|
||||
|
||||
@@ -27,10 +27,12 @@ type ClientHandler = {
|
||||
} & HelperHandlers;
|
||||
type ClientEvents = MainEvents & HelperEvents;
|
||||
|
||||
export const appInfo = (window as any).appInfo as typeof exposedAppInfo | null;
|
||||
export const apis = (window as any).apis as ClientHandler | null;
|
||||
export const events = (window as any).events as ClientEvents | null;
|
||||
export const affine = (window as any).affine as
|
||||
export const appInfo = (globalThis as any).appInfo as
|
||||
| typeof exposedAppInfo
|
||||
| null;
|
||||
export const apis = (globalThis as any).apis as ClientHandler | null;
|
||||
export const events = (globalThis as any).events as ClientEvents | null;
|
||||
export const affine = (globalThis as any).affine as
|
||||
| typeof exposedAffineGlobal
|
||||
| null;
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
lib
|
||||
+5
-20
@@ -1,10 +1,9 @@
|
||||
{
|
||||
"name": "@affine/workspace",
|
||||
"name": "@affine/workspace-impl",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./atom": "./src/atom.ts",
|
||||
"./affine/*": "./src/affine/*.ts"
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@blocksuite/blocks": "*",
|
||||
@@ -12,37 +11,23 @@
|
||||
"@blocksuite/store": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine/debug": "workspace:*",
|
||||
"@affine/electron-api": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/graphql": "workspace:*",
|
||||
"@affine/workspace": "workspace:*",
|
||||
"@toeverything/infra": "workspace:*",
|
||||
"async-call-rpc": "^6.3.1",
|
||||
"idb": "^8.0.0",
|
||||
"idb-keyval": "^6.2.1",
|
||||
"is-svg": "^5.0.0",
|
||||
"jotai": "^2.5.1",
|
||||
"js-base64": "^3.7.5",
|
||||
"ky": "^1.0.1",
|
||||
"lib0": "^0.2.87",
|
||||
"lodash-es": "^4.17.21",
|
||||
"nanoid": "^5.0.3",
|
||||
"next-auth": "^4.24.5",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"rxjs": "^7.8.1",
|
||||
"socket.io-client": "^4.7.2",
|
||||
"swr": "2.2.4",
|
||||
"valtio": "^1.11.2",
|
||||
"y-protocols": "^1.0.6",
|
||||
"y-provider": "workspace:*",
|
||||
"yjs": "^13.6.10",
|
||||
"zod": "^3.22.4"
|
||||
"yjs": "^13.6.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/react": "^14.0.0",
|
||||
"@types/ws": "^8.5.7",
|
||||
"fake-indexeddb": "^5.0.0",
|
||||
"vitest": "1.1.1",
|
||||
"ws": "^8.14.2"
|
||||
+3
-3
@@ -1,4 +1,5 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { AwarenessProvider } from '@affine/workspace';
|
||||
import {
|
||||
applyAwarenessUpdate,
|
||||
type Awareness,
|
||||
@@ -6,9 +7,8 @@ import {
|
||||
removeAwarenessStates,
|
||||
} from 'y-protocols/awareness';
|
||||
|
||||
import type { AwarenessProvider } from '../../engine/awareness';
|
||||
import { getIoManager } from '../../utils/affine-io';
|
||||
import { base64ToUint8Array, uint8ArrayToBase64 } from '../../utils/base64';
|
||||
import { getIoManager } from '../utils/affine-io';
|
||||
import { base64ToUint8Array, uint8ArrayToBase64 } from '../utils/base64';
|
||||
|
||||
const logger = new DebugLogger('affine:awareness:socketio');
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@ import {
|
||||
setBlobMutation,
|
||||
} from '@affine/graphql';
|
||||
import { fetcher } from '@affine/graphql';
|
||||
import type { BlobStorage } from '@affine/workspace';
|
||||
|
||||
import type { BlobStorage } from '../../engine/blob';
|
||||
import { bufferToBlob } from '../../utils/buffer-to-blob';
|
||||
import { bufferToBlob } from '../utils/buffer-to-blob';
|
||||
|
||||
export const createAffineCloudBlobStorage = (
|
||||
workspaceId: string
|
||||
File renamed without changes.
File renamed without changes.
+2
-2
@@ -5,13 +5,13 @@ import {
|
||||
getWorkspacesQuery,
|
||||
} from '@affine/graphql';
|
||||
import { fetcher } from '@affine/graphql';
|
||||
import type { WorkspaceListProvider } from '@affine/workspace';
|
||||
import { globalBlockSuiteSchema } from '@affine/workspace';
|
||||
import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import { difference } from 'lodash-es';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
||||
|
||||
import { globalBlockSuiteSchema } from '../../global-schema';
|
||||
import type { WorkspaceListProvider } from '../../list';
|
||||
import { createLocalBlobStorage } from '../local/blob';
|
||||
import { createLocalStorage } from '../local/sync';
|
||||
import { CLOUD_WORKSPACE_CHANGED_BROADCAST_CHANNEL_KEY } from './consts';
|
||||
File renamed without changes.
+3
-3
@@ -1,9 +1,9 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { fetchWithTraceReport } from '@affine/graphql';
|
||||
import type { SyncStorage } from '@affine/workspace';
|
||||
|
||||
import type { SyncStorage } from '../../../engine/sync';
|
||||
import { getIoManager } from '../../../utils/affine-io';
|
||||
import { base64ToUint8Array, uint8ArrayToBase64 } from '../../../utils/base64';
|
||||
import { getIoManager } from '../../utils/affine-io';
|
||||
import { base64ToUint8Array, uint8ArrayToBase64 } from '../../utils/base64';
|
||||
import { MultipleBatchSyncSender } from './batch-sync-sender';
|
||||
|
||||
const logger = new DebugLogger('affine:storage:socketio');
|
||||
+4
-4
@@ -1,11 +1,11 @@
|
||||
import { setupEditorFlags } from '@affine/env/global';
|
||||
import type { WorkspaceFactory } from '@affine/workspace';
|
||||
import { BlobEngine, SyncEngine, WorkspaceEngine } from '@affine/workspace';
|
||||
import { globalBlockSuiteSchema } from '@affine/workspace';
|
||||
import { Workspace } from '@affine/workspace';
|
||||
import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
import { BlobEngine, SyncEngine, WorkspaceEngine } from '../../engine';
|
||||
import type { WorkspaceFactory } from '../../factory';
|
||||
import { globalBlockSuiteSchema } from '../../global-schema';
|
||||
import { Workspace } from '../../workspace';
|
||||
import { createBroadcastChannelAwarenessProvider } from '../local/awareness';
|
||||
import { createLocalBlobStorage } from '../local/blob';
|
||||
import { createStaticBlobStorage } from '../local/blob-static';
|
||||
@@ -0,0 +1,41 @@
|
||||
import { WorkspaceList, WorkspaceManager } from '@affine/workspace';
|
||||
|
||||
import {
|
||||
cloudWorkspaceFactory,
|
||||
createCloudWorkspaceListProvider,
|
||||
} from './cloud';
|
||||
import {
|
||||
createLocalWorkspaceListProvider,
|
||||
LOCAL_WORKSPACE_LOCAL_STORAGE_KEY,
|
||||
localWorkspaceFactory,
|
||||
} from './local';
|
||||
|
||||
const list = new WorkspaceList([
|
||||
createLocalWorkspaceListProvider(),
|
||||
createCloudWorkspaceListProvider(),
|
||||
]);
|
||||
|
||||
export const workspaceManager = new WorkspaceManager(list, [
|
||||
localWorkspaceFactory,
|
||||
cloudWorkspaceFactory,
|
||||
]);
|
||||
|
||||
(window as any).workspaceManager = workspaceManager;
|
||||
|
||||
export * from './cloud';
|
||||
export * from './local';
|
||||
|
||||
/**
|
||||
* a hack for directly add local workspace to workspace list
|
||||
* Used after copying sqlite database file to appdata folder
|
||||
*/
|
||||
export function _addLocalWorkspace(id: string) {
|
||||
const allWorkspaceIDs: string[] = JSON.parse(
|
||||
localStorage.getItem(LOCAL_WORKSPACE_LOCAL_STORAGE_KEY) ?? '[]'
|
||||
);
|
||||
allWorkspaceIDs.push(id);
|
||||
localStorage.setItem(
|
||||
LOCAL_WORKSPACE_LOCAL_STORAGE_KEY,
|
||||
JSON.stringify(allWorkspaceIDs)
|
||||
);
|
||||
}
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import { SyncEngine, SyncEngineStep, SyncPeerStep } from '@affine/workspace';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import { Schema, Workspace } from '@blocksuite/store';
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
import { Doc } from 'yjs';
|
||||
|
||||
import { createIndexedDBStorage } from '../../../impl/local/sync-indexeddb';
|
||||
import { SyncEngine, SyncEngineStep, SyncPeerStep } from '../';
|
||||
import { createIndexedDBStorage } from '..';
|
||||
import { createTestStorage } from './test-storage';
|
||||
|
||||
const schema = new Schema();
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import { SyncPeer, SyncPeerStep } from '@affine/workspace';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import { Schema, Workspace } from '@blocksuite/store';
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { createIndexedDBStorage } from '../../../impl/local/sync-indexeddb';
|
||||
import { SyncPeer, SyncPeerStep } from '../';
|
||||
import { createIndexedDBStorage } from '..';
|
||||
|
||||
const schema = new Schema();
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import type { SyncStorage } from '..';
|
||||
import type { SyncStorage } from '@affine/workspace';
|
||||
|
||||
export function createTestStorage(origin: SyncStorage) {
|
||||
const controler = {
|
||||
+1
-2
@@ -1,11 +1,10 @@
|
||||
import type { AwarenessProvider } from '@affine/workspace';
|
||||
import type { Awareness } from 'y-protocols/awareness.js';
|
||||
import {
|
||||
applyAwarenessUpdate,
|
||||
encodeAwarenessUpdate,
|
||||
} from 'y-protocols/awareness.js';
|
||||
|
||||
import type { AwarenessProvider } from '../../engine/awareness';
|
||||
|
||||
type AwarenessChanges = Record<'added' | 'updated' | 'removed', number[]>;
|
||||
|
||||
type ChannelMessage =
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import type { BlobStorage } from '@affine/workspace';
|
||||
import { createStore, del, get, keys, set } from 'idb-keyval';
|
||||
|
||||
import type { BlobStorage } from '../../engine/blob';
|
||||
import { bufferToBlob } from '../../utils/buffer-to-blob';
|
||||
import { bufferToBlob } from '../utils/buffer-to-blob';
|
||||
|
||||
export const createIndexeddbBlobStorage = (
|
||||
workspaceId: string
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { apis } from '@affine/electron-api';
|
||||
import type { BlobStorage } from '@affine/workspace';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
|
||||
import type { BlobStorage } from '../../engine/blob';
|
||||
import { bufferToBlob } from '../../utils/buffer-to-blob';
|
||||
import { bufferToBlob } from '../utils/buffer-to-blob';
|
||||
|
||||
export const createSQLiteBlobStorage = (workspaceId: string): BlobStorage => {
|
||||
assertExists(apis);
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import type { BlobStorage } from '../../engine/blob';
|
||||
import type { BlobStorage } from '@affine/workspace';
|
||||
|
||||
export const predefinedStaticFiles = [
|
||||
'029uztLz2CzJezK7UUhrbGiWUdZ0J7NVs_qR6RDsvb8=',
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-2
@@ -1,12 +1,12 @@
|
||||
import { apis } from '@affine/electron-api';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import type { WorkspaceListProvider } from '@affine/workspace';
|
||||
import { globalBlockSuiteSchema } from '@affine/workspace';
|
||||
import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import { difference } from 'lodash-es';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
||||
|
||||
import { globalBlockSuiteSchema } from '../../global-schema';
|
||||
import type { WorkspaceListProvider } from '../../list';
|
||||
import { createLocalBlobStorage } from './blob';
|
||||
import {
|
||||
LOCAL_WORKSPACE_CREATED_BROADCAST_CHANNEL_KEY,
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import type { SyncStorage } from '@affine/workspace';
|
||||
import { type DBSchema, type IDBPDatabase, openDB } from 'idb';
|
||||
import { diffUpdate, encodeStateVectorFromUpdate } from 'yjs';
|
||||
|
||||
import type { SyncStorage } from '../../engine/sync';
|
||||
import { mergeUpdates } from '../../utils/merge-updates';
|
||||
import { mergeUpdates } from '../utils/merge-updates';
|
||||
|
||||
export const dbVersion = 1;
|
||||
export const DEFAULT_DB_NAME = 'affine-local';
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
import { apis } from '@affine/electron-api';
|
||||
import type { SyncStorage } from '@affine/workspace';
|
||||
import { encodeStateVectorFromUpdate } from 'yjs';
|
||||
|
||||
import type { SyncStorage } from '../../engine/sync';
|
||||
|
||||
export function createSQLiteStorage(workspaceId: string): SyncStorage {
|
||||
if (!apis?.db) {
|
||||
throw new Error('sqlite datasource is not available');
|
||||
File renamed without changes.
+6
-6
@@ -1,13 +1,13 @@
|
||||
import { setupEditorFlags } from '@affine/env/global';
|
||||
import type { WorkspaceFactory } from '@affine/workspace';
|
||||
import { WorkspaceEngine } from '@affine/workspace';
|
||||
import { BlobEngine } from '@affine/workspace';
|
||||
import { SyncEngine } from '@affine/workspace';
|
||||
import { globalBlockSuiteSchema } from '@affine/workspace';
|
||||
import { Workspace } from '@affine/workspace';
|
||||
import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
import { WorkspaceEngine } from '../../engine';
|
||||
import { BlobEngine } from '../../engine/blob';
|
||||
import { SyncEngine } from '../../engine/sync';
|
||||
import type { WorkspaceFactory } from '../../factory';
|
||||
import { globalBlockSuiteSchema } from '../../global-schema';
|
||||
import { Workspace } from '../../workspace';
|
||||
import { createBroadcastChannelAwarenessProvider } from './awareness';
|
||||
import { createLocalBlobStorage } from './blob';
|
||||
import { createStaticBlobStorage } from './blob-static';
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,17 @@
|
||||
import { applyUpdate, Doc, encodeStateAsUpdate } from 'yjs';
|
||||
|
||||
export function mergeUpdates(updates: Uint8Array[]) {
|
||||
if (updates.length === 0) {
|
||||
return new Uint8Array();
|
||||
}
|
||||
if (updates.length === 1) {
|
||||
return updates[0];
|
||||
}
|
||||
const doc = new Doc();
|
||||
doc.transact(() => {
|
||||
updates.forEach(update => {
|
||||
applyUpdate(doc, update);
|
||||
});
|
||||
});
|
||||
return encodeStateAsUpdate(doc);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"include": ["./src"],
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../../../tests/fixtures" },
|
||||
{ "path": "../../common/env" },
|
||||
{ "path": "../../common/debug" },
|
||||
{ "path": "../../common/infra" },
|
||||
{ "path": "../../frontend/graphql" },
|
||||
{ "path": "../../frontend/electron-api" }
|
||||
]
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './cloud';
|
||||
export * from './local';
|
||||
@@ -1,29 +0,0 @@
|
||||
import {
|
||||
cloudWorkspaceFactory,
|
||||
createCloudWorkspaceListProvider,
|
||||
createLocalWorkspaceListProvider,
|
||||
localWorkspaceFactory,
|
||||
} from './impl';
|
||||
import { WorkspaceList } from './list';
|
||||
import { WorkspaceManager } from './manager';
|
||||
|
||||
const list = new WorkspaceList([
|
||||
createLocalWorkspaceListProvider(),
|
||||
createCloudWorkspaceListProvider(),
|
||||
]);
|
||||
|
||||
export const workspaceManager = new WorkspaceManager(list, [
|
||||
localWorkspaceFactory,
|
||||
cloudWorkspaceFactory,
|
||||
]);
|
||||
|
||||
(window as any).workspaceManager = workspaceManager;
|
||||
|
||||
export * from './engine';
|
||||
export * from './factory';
|
||||
export * from './global-schema';
|
||||
export * from './impl';
|
||||
export * from './list';
|
||||
export * from './manager';
|
||||
export * from './metadata';
|
||||
export * from './workspace';
|
||||
@@ -8,7 +8,7 @@ import MockSessionContext, {
|
||||
import { ThemeProvider, useTheme } from 'next-themes';
|
||||
import { useDarkMode } from 'storybook-dark-mode';
|
||||
import { AffineContext } from '@affine/component/context';
|
||||
import { workspaceManager } from '@affine/workspace';
|
||||
import { workspaceManager } from '@affine/workspace-impl';
|
||||
import useSWR from 'swr';
|
||||
import type { Decorator } from '@storybook/react';
|
||||
import { createStore } from 'jotai/vanilla';
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"path": "../../packages/common/infra"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/frontend/workspace"
|
||||
"path": "../../packages/common/workspace"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
|
||||
+6
-2
@@ -60,7 +60,8 @@
|
||||
"@affine/debug": ["./packages/common/debug"],
|
||||
"@affine/env": ["./packages/common/env/src"],
|
||||
"@affine/env/*": ["./packages/common/env/src/*"],
|
||||
"@affine/workspace/*": ["./packages/frontend/workspace/src/*"],
|
||||
"@affine/workspace/*": ["./packages/common/workspace/src/*"],
|
||||
"@affine/workspace-impl/*": ["./packages/frontend/workspace-impl/src/*"],
|
||||
"@affine/graphql": ["./packages/frontend/graphql/src"],
|
||||
"@affine/electron/scripts/*": ["./packages/frontend/electron/scripts/*"],
|
||||
"@affine-test/kit/*": ["./tests/kit/*"],
|
||||
@@ -100,7 +101,10 @@
|
||||
"path": "./packages/frontend/i18n"
|
||||
},
|
||||
{
|
||||
"path": "./packages/frontend/workspace"
|
||||
"path": "./packages/common/workspace"
|
||||
},
|
||||
{
|
||||
"path": "./packages/frontend/workspace-impl"
|
||||
},
|
||||
// Common
|
||||
{
|
||||
|
||||
@@ -316,6 +316,7 @@ __metadata:
|
||||
"@affine/i18n": "workspace:*"
|
||||
"@affine/templates": "workspace:*"
|
||||
"@affine/workspace": "workspace:*"
|
||||
"@affine/workspace-impl": "workspace:*"
|
||||
"@aws-sdk/client-s3": "npm:3.484.0"
|
||||
"@blocksuite/block-std": "npm:0.11.0-nightly-202312220916-e3abcbb"
|
||||
"@blocksuite/blocks": "npm:0.11.0-nightly-202312220916-e3abcbb"
|
||||
@@ -791,42 +792,45 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@affine/workspace@workspace:*, @affine/workspace@workspace:packages/frontend/workspace":
|
||||
"@affine/workspace-impl@workspace:*, @affine/workspace-impl@workspace:packages/frontend/workspace-impl":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@affine/workspace@workspace:packages/frontend/workspace"
|
||||
resolution: "@affine/workspace-impl@workspace:packages/frontend/workspace-impl"
|
||||
dependencies:
|
||||
"@affine-test/fixtures": "workspace:*"
|
||||
"@affine/debug": "workspace:*"
|
||||
"@affine/electron-api": "workspace:*"
|
||||
"@affine/env": "workspace:*"
|
||||
"@affine/graphql": "workspace:*"
|
||||
"@testing-library/react": "npm:^14.0.0"
|
||||
"@affine/workspace": "workspace:*"
|
||||
"@toeverything/infra": "workspace:*"
|
||||
"@types/ws": "npm:^8.5.7"
|
||||
async-call-rpc: "npm:^6.3.1"
|
||||
fake-indexeddb: "npm:^5.0.0"
|
||||
idb: "npm:^8.0.0"
|
||||
idb-keyval: "npm:^6.2.1"
|
||||
is-svg: "npm:^5.0.0"
|
||||
jotai: "npm:^2.5.1"
|
||||
js-base64: "npm:^3.7.5"
|
||||
ky: "npm:^1.0.1"
|
||||
lib0: "npm:^0.2.87"
|
||||
lodash-es: "npm:^4.17.21"
|
||||
nanoid: "npm:^5.0.3"
|
||||
next-auth: "npm:^4.24.5"
|
||||
react: "npm:18.2.0"
|
||||
react-dom: "npm:18.2.0"
|
||||
rxjs: "npm:^7.8.1"
|
||||
socket.io-client: "npm:^4.7.2"
|
||||
swr: "npm:2.2.4"
|
||||
valtio: "npm:^1.11.2"
|
||||
vitest: "npm:1.1.1"
|
||||
ws: "npm:^8.14.2"
|
||||
y-protocols: "npm:^1.0.6"
|
||||
y-provider: "workspace:*"
|
||||
yjs: "npm:^13.6.10"
|
||||
zod: "npm:^3.22.4"
|
||||
peerDependencies:
|
||||
"@blocksuite/blocks": "*"
|
||||
"@blocksuite/global": "*"
|
||||
"@blocksuite/store": "*"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@affine/workspace@workspace:*, @affine/workspace@workspace:packages/common/workspace":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@affine/workspace@workspace:packages/common/workspace"
|
||||
dependencies:
|
||||
"@affine/debug": "workspace:*"
|
||||
"@affine/env": "workspace:*"
|
||||
"@toeverything/infra": "workspace:*"
|
||||
lodash-es: "npm:^4.17.21"
|
||||
vitest: "npm:1.1.0"
|
||||
yjs: "npm:^13.6.10"
|
||||
peerDependencies:
|
||||
"@blocksuite/blocks": "*"
|
||||
"@blocksuite/global": "*"
|
||||
@@ -14428,7 +14432,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/ws@npm:^8.0.0, @types/ws@npm:^8.5.10, @types/ws@npm:^8.5.5, @types/ws@npm:^8.5.7":
|
||||
"@types/ws@npm:^8.0.0, @types/ws@npm:^8.5.10, @types/ws@npm:^8.5.5":
|
||||
version: 8.5.10
|
||||
resolution: "@types/ws@npm:8.5.10"
|
||||
dependencies:
|
||||
@@ -14774,6 +14778,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/expect@npm:1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "@vitest/expect@npm:1.1.0"
|
||||
dependencies:
|
||||
"@vitest/spy": "npm:1.1.0"
|
||||
"@vitest/utils": "npm:1.1.0"
|
||||
chai: "npm:^4.3.10"
|
||||
checksum: 08d1ea192cf638da4b6f19e67642ea6a181593bca3c21ca8cb741d8d0792f95876281414b9cce0c0583701489a1ebbbdc4a83eec3012874bba3282d15664eaaa
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/expect@npm:1.1.1":
|
||||
version: 1.1.1
|
||||
resolution: "@vitest/expect@npm:1.1.1"
|
||||
@@ -14785,6 +14800,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/runner@npm:1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "@vitest/runner@npm:1.1.0"
|
||||
dependencies:
|
||||
"@vitest/utils": "npm:1.1.0"
|
||||
p-limit: "npm:^5.0.0"
|
||||
pathe: "npm:^1.1.1"
|
||||
checksum: f21c503ea944cdafcf33160913759ae686739ccde7b36d060128a4f7387245019ab4508d825ddf51268aea6e72bc8afd4806ca6ba88f564274d5265229c8e91f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/runner@npm:1.1.1":
|
||||
version: 1.1.1
|
||||
resolution: "@vitest/runner@npm:1.1.1"
|
||||
@@ -14796,6 +14822,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/snapshot@npm:1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "@vitest/snapshot@npm:1.1.0"
|
||||
dependencies:
|
||||
magic-string: "npm:^0.30.5"
|
||||
pathe: "npm:^1.1.1"
|
||||
pretty-format: "npm:^29.7.0"
|
||||
checksum: e4db6344019aae10fe880cecf0a058e22e4952172cc9bb2a8ea9fc41d3e32a3dc3e99520676cffd4d870ba77108e24f2d8ab1e391da423d21c2533e1933def5e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/snapshot@npm:1.1.1":
|
||||
version: 1.1.1
|
||||
resolution: "@vitest/snapshot@npm:1.1.1"
|
||||
@@ -14807,6 +14844,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/spy@npm:1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "@vitest/spy@npm:1.1.0"
|
||||
dependencies:
|
||||
tinyspy: "npm:^2.2.0"
|
||||
checksum: 99d507df9e0f4224fa21b841721af2ed03d7538e534fb55627d5e8ba684b8659b79a1d46cfaa87d24121ce14fd0a93a04c01099e0758ba40fbdd6efebc4278d1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/spy@npm:1.1.1":
|
||||
version: 1.1.1
|
||||
resolution: "@vitest/spy@npm:1.1.1"
|
||||
@@ -14833,6 +14879,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/utils@npm:1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "@vitest/utils@npm:1.1.0"
|
||||
dependencies:
|
||||
diff-sequences: "npm:^29.6.3"
|
||||
loupe: "npm:^2.3.7"
|
||||
pretty-format: "npm:^29.7.0"
|
||||
checksum: d1e5443b366664f244d8cbce8a36fcc74a5c784a97aeabd93511afc86c04acdd57414c16d97151656466626af9553cf10074618c16722fff88bbb7545186eeb8
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/utils@npm:1.1.1":
|
||||
version: 1.1.1
|
||||
resolution: "@vitest/utils@npm:1.1.1"
|
||||
@@ -24700,13 +24757,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"js-base64@npm:^3.7.5":
|
||||
version: 3.7.5
|
||||
resolution: "js-base64@npm:3.7.5"
|
||||
checksum: 97642fdef112cb99aed25a092156029e2f44cef0e4e3bf64dba0b6f8d85b9f4ee80b65ab8fa11a051dfcd09133bcd96c130167afdf90e4e4b21933632157a4f9
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"js-levenshtein@npm:^1.1.6":
|
||||
version: 1.1.6
|
||||
resolution: "js-levenshtein@npm:1.1.6"
|
||||
@@ -25059,13 +25109,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ky@npm:^1.0.1":
|
||||
version: 1.1.3
|
||||
resolution: "ky@npm:1.1.3"
|
||||
checksum: 0545fd228d7e21aa51adc1b317559da317cdd3131d5af86480dcd323231d5e5831987dbb1d1a61317a9a7d615a9d822faff827fd22956f14cd345bf764da95fe
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"launch-editor@npm:^2.6.0":
|
||||
version: 2.6.1
|
||||
resolution: "launch-editor@npm:2.6.1"
|
||||
@@ -34719,6 +34762,21 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"vite-node@npm:1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "vite-node@npm:1.1.0"
|
||||
dependencies:
|
||||
cac: "npm:^6.7.14"
|
||||
debug: "npm:^4.3.4"
|
||||
pathe: "npm:^1.1.1"
|
||||
picocolors: "npm:^1.0.0"
|
||||
vite: "npm:^5.0.0"
|
||||
bin:
|
||||
vite-node: vite-node.mjs
|
||||
checksum: 2978b2fa7091233c234a86d60be6d6b407748471ae7b0e10a93ccd707ed2c888f04bc1c0e0737fa243f85e8477c18d6ed998b5bf67fd42cdd8778cc9cd40868c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"vite-node@npm:1.1.1":
|
||||
version: 1.1.1
|
||||
resolution: "vite-node@npm:1.1.1"
|
||||
@@ -34880,6 +34938,57 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"vitest@npm:1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "vitest@npm:1.1.0"
|
||||
dependencies:
|
||||
"@vitest/expect": "npm:1.1.0"
|
||||
"@vitest/runner": "npm:1.1.0"
|
||||
"@vitest/snapshot": "npm:1.1.0"
|
||||
"@vitest/spy": "npm:1.1.0"
|
||||
"@vitest/utils": "npm:1.1.0"
|
||||
acorn-walk: "npm:^8.3.0"
|
||||
cac: "npm:^6.7.14"
|
||||
chai: "npm:^4.3.10"
|
||||
debug: "npm:^4.3.4"
|
||||
execa: "npm:^8.0.1"
|
||||
local-pkg: "npm:^0.5.0"
|
||||
magic-string: "npm:^0.30.5"
|
||||
pathe: "npm:^1.1.1"
|
||||
picocolors: "npm:^1.0.0"
|
||||
std-env: "npm:^3.5.0"
|
||||
strip-literal: "npm:^1.3.0"
|
||||
tinybench: "npm:^2.5.1"
|
||||
tinypool: "npm:^0.8.1"
|
||||
vite: "npm:^5.0.0"
|
||||
vite-node: "npm:1.1.0"
|
||||
why-is-node-running: "npm:^2.2.2"
|
||||
peerDependencies:
|
||||
"@edge-runtime/vm": "*"
|
||||
"@types/node": ^18.0.0 || >=20.0.0
|
||||
"@vitest/browser": ^1.0.0
|
||||
"@vitest/ui": ^1.0.0
|
||||
happy-dom: "*"
|
||||
jsdom: "*"
|
||||
peerDependenciesMeta:
|
||||
"@edge-runtime/vm":
|
||||
optional: true
|
||||
"@types/node":
|
||||
optional: true
|
||||
"@vitest/browser":
|
||||
optional: true
|
||||
"@vitest/ui":
|
||||
optional: true
|
||||
happy-dom:
|
||||
optional: true
|
||||
jsdom:
|
||||
optional: true
|
||||
bin:
|
||||
vitest: vitest.mjs
|
||||
checksum: 5e4ac0231b2dc9cf51892e0414c7ab092e70bf5eacdb9c4a8cdd941bdd325544eb4ffe8eb89586aa6e399f9a34739f330482c64c13300bf1b7c5b130101d7e7c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"vitest@npm:1.1.1":
|
||||
version: 1.1.1
|
||||
resolution: "vitest@npm:1.1.1"
|
||||
|
||||
Reference in new issue
Block a user