Merge remote-tracking branch 'refs/remotes/origin/feat/poc'

Conflicts:
	package.json
	packages/data-center/package.json
	pnpm-lock.yaml
This commit is contained in:
linonetwo
2023-01-09 14:59:34 +08:00
132 changed files with 2338 additions and 3219 deletions

View File

@@ -10,8 +10,8 @@
".": "./dist/src/index.js"
},
"scripts": {
"build": "tsc --project ./tsconfig.json",
"test": "playwright test"
"dev": "tsc --project ./tsconfig.json -w",
"build": "tsc --project ./tsconfig.json"
},
"keywords": [],
"author": "",
@@ -27,8 +27,8 @@
},
"dependencies": {
"@tauri-apps/api": "^1.2.0",
"@blocksuite/blocks": "=0.3.1-20230106060050-1aad55d",
"@blocksuite/store": "=0.3.1-20230106060050-1aad55d",
"@blocksuite/blocks": "^0.3.1-20230109032243-37ad3ba",
"@blocksuite/store": "^0.3.1-20230109032243-37ad3ba",
"debug": "^4.3.4",
"encoding": "^0.1.13",
"firebase": "^9.15.0",
@@ -37,6 +37,7 @@
"ky-universal": "^0.11.0",
"lib0": "^0.2.58",
"swr": "^2.0.0",
"vitest": "^0.26.3",
"y-protocols": "^1.0.5",
"yjs": "^13.5.44"
}

View File

@@ -1,25 +0,0 @@
import type { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
testDir: './tests',
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000,
},
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
use: {
actionTimeout: 0,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
};
export default config;

View File

@@ -2,11 +2,13 @@ import { describe, test, expect } from 'vitest';
import { Workspaces } from '../../workspaces';
import { LocalProvider } from './local';
import 'fake-indexeddb/auto';
import { BlobStorage } from '@blocksuite/store';
describe('local provider', () => {
const workspaces = new Workspaces();
const provider = new LocalProvider({
workspaces: workspaces.createScope(),
blobs: new BlobStorage(),
});
const workspaceName = 'workspace-test';
@@ -27,6 +29,7 @@ describe('local provider', () => {
const workspaces1 = new Workspaces();
const provider1 = new LocalProvider({
workspaces: workspaces1.createScope(),
blobs: new BlobStorage(),
});
await provider1.loadWorkspaces();
expect(workspaces1.workspaces.length).toEqual(1);

View File

@@ -1,63 +0,0 @@
import assert from 'assert';
import { LocalProvider } from '../local/index.js';
import { WebsocketProvider } from './sync.js';
export class SelfHostedProvider extends LocalProvider {
static id = 'selfhosted';
private _ws?: WebsocketProvider;
constructor() {
super();
}
async destroy() {
this._ws?.disconnect();
}
async initData() {
const databases = await indexedDB.databases();
await super.initData(
// set locally to true if exists a same name db
databases
.map(db => db.name)
.filter(v => v)
.includes(this._workspace.room)
);
const workspace = this._workspace;
const doc = workspace.doc;
if (workspace.room) {
try {
// Wait for ws synchronization to complete, otherwise the data will be modified in reverse, which can be optimized later
this._ws = new WebsocketProvider(this.host, workspace.room, doc);
await new Promise<void>((resolve, reject) => {
// TODO: synced will also be triggered on reconnection after losing sync
// There needs to be an event mechanism to emit the synchronization state to the upper layer
assert(this._ws);
this._ws.once('synced', () => resolve());
this._ws.once('lost-connection', () => resolve());
this._ws.once('connection-error', () => reject());
});
this._signals.listAdd.emit({
workspace: workspace.room,
provider: this.id,
locally: true,
});
} catch (e) {
this._logger('Failed to init cloud workspace', e);
}
}
// if after update, the space:meta is empty
// then we need to get map with doc
// just a workaround for yjs
doc.getMap('space:meta');
}
private get host() {
const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
return `${protocol}//${location.host}/collaboration/`;
}
}

View File

@@ -0,0 +1,63 @@
// import assert from 'assert';
// import { LocalProvider } from '../local/index.js';
// import { WebsocketProvider } from './sync.js';
// export class SelfHostedProvider extends LocalProvider {
// static id = 'selfhosted';
// private _ws?: WebsocketProvider;
// constructor() {
// super();
// }
// async destroy() {
// this._ws?.disconnect();
// }
// async initData() {
// const databases = await indexedDB.databases();
// await super.initData(
// // set locally to true if exists a same name db
// databases
// .map(db => db.name)
// .filter(v => v)
// .includes(this._workspace.room)
// );
// const workspace = this._workspace;
// const doc = workspace.doc;
// if (workspace.room) {
// try {
// // Wait for ws synchronization to complete, otherwise the data will be modified in reverse, which can be optimized later
// this._ws = new WebsocketProvider(this.host, workspace.room, doc);
// await new Promise<void>((resolve, reject) => {
// // TODO: synced will also be triggered on reconnection after losing sync
// // There needs to be an event mechanism to emit the synchronization state to the upper layer
// assert(this._ws);
// this._ws.once('synced', () => resolve());
// this._ws.once('lost-connection', () => resolve());
// this._ws.once('connection-error', () => reject());
// });
// this._signals.listAdd.emit({
// workspace: workspace.room,
// provider: this.id,
// locally: true,
// });
// } catch (e) {
// this._logger('Failed to init cloud workspace', e);
// }
// }
// // if after update, the space:meta is empty
// // then we need to get map with doc
// // just a workaround for yjs
// doc.getMap('space:meta');
// }
// private get host() {
// const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
// return `${protocol}//${location.host}/collaboration/`;
// }
// }