feat(nbstore): add nbstore worker (#9185)

This commit is contained in:
EYHN
2024-12-20 08:01:23 +00:00
parent 30200ff86d
commit cbaf35df0b
51 changed files with 1144 additions and 501 deletions
@@ -1,8 +1,8 @@
import { share } from '../../connection';
import { type BlobRecord, BlobStorage } from '../../storage';
import { type BlobRecord, BlobStorageBase } from '../../storage';
import { NativeDBConnection } from './db';
export class SqliteBlobStorage extends BlobStorage {
export class SqliteBlobStorage extends BlobStorageBase {
override connection = share(
new NativeDBConnection(this.peer, this.spaceType, this.spaceId)
);
@@ -1,6 +1,6 @@
import { apis } from '@affine/electron-api';
import { Connection } from '../../connection';
import { AutoReconnectConnection } from '../../connection';
import { type SpaceType, universalId } from '../../storage';
type NativeDBApis = NonNullable<typeof apis>['nbstore'] extends infer APIs
@@ -13,7 +13,7 @@ type NativeDBApis = NonNullable<typeof apis>['nbstore'] extends infer APIs
}
: never;
export class NativeDBConnection extends Connection<void> {
export class NativeDBConnection extends AutoReconnectConnection<void> {
readonly apis: NativeDBApis;
constructor(
@@ -1,8 +1,8 @@
import { share } from '../../connection';
import { type DocClock, DocStorage, type DocUpdate } from '../../storage';
import { type DocClock, DocStorageBase, type DocUpdate } from '../../storage';
import { NativeDBConnection } from './db';
export class SqliteDocStorage extends DocStorage {
export class SqliteDocStorage extends DocStorageBase {
override connection = share(
new NativeDBConnection(this.peer, this.spaceType, this.spaceId)
);
@@ -1,8 +1,8 @@
import { share } from '../../connection';
import { type DocClock, SyncStorage } from '../../storage';
import { BasicSyncStorage, type DocClock } from '../../storage';
import { NativeDBConnection } from './db';
export class SqliteSyncStorage extends SyncStorage {
export class SqliteSyncStorage extends BasicSyncStorage {
override connection = share(
new NativeDBConnection(this.peer, this.spaceType, this.spaceId)
);
@@ -1,13 +1,13 @@
import { apis } from '@affine/electron-api';
import { DummyConnection, share } from '../../../connection';
import { BlobStorage } from '../../../storage';
import { DummyConnection } from '../../../connection';
import { BlobStorageBase } from '../../../storage';
/**
* @deprecated readonly
*/
export class SqliteV1BlobStorage extends BlobStorage {
override connection = share(new DummyConnection());
export class SqliteV1BlobStorage extends BlobStorageBase {
override connection = new DummyConnection();
get db() {
if (!apis) {
@@ -1,13 +1,17 @@
import { apis } from '@affine/electron-api';
import { DummyConnection, share } from '../../../connection';
import { type DocRecord, DocStorage, type DocUpdate } from '../../../storage';
import { DummyConnection } from '../../../connection';
import {
type DocRecord,
DocStorageBase,
type DocUpdate,
} from '../../../storage';
/**
* @deprecated readonly
*/
export class SqliteV1DocStorage extends DocStorage {
override connection = share(new DummyConnection());
export class SqliteV1DocStorage extends DocStorageBase {
override connection = new DummyConnection();
get db() {
if (!apis) {