-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,481 additions
and
785 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# @affine/doc-storage | ||
|
||
## Storages | ||
|
||
### StorageNode | ||
|
||
```ts | ||
import { StorageManager } from '@affine/doc-storage'; | ||
|
||
class CloudStorageManager extends StorageManager { | ||
private readonly socket = io('http://endpoint'); | ||
|
||
constructor(options: StorageOptions) { | ||
super(options); | ||
this.add( | ||
'doc', | ||
new CloudDocStorage({ | ||
...this.options, | ||
socket: this.socket, | ||
}) | ||
); | ||
this.add( | ||
'blob', | ||
new CloudBlobStorage({ | ||
...this.options, | ||
socket: this.socket, | ||
}) | ||
); | ||
} | ||
|
||
override async doConnect() { | ||
await this.socket.connect(); | ||
} | ||
|
||
override async doDisconnect() { | ||
await this.socket.close(); | ||
} | ||
} | ||
``` | ||
|
||
### StorageEdgeNode | ||
|
||
```ts | ||
interface SqliteStorageOptions extends StorageOptions { | ||
dbPath: string; | ||
} | ||
|
||
class SqliteStorage extends CloudStorageManager<SqliteStorageOptions> { | ||
constructor(options: StorageOptions) { | ||
super(options); | ||
this.db = new Sqlite(this.options.dbPath); | ||
|
||
this.add('doc', new SqliteDocStorage({ ...this.options, db: this.db })); | ||
this.add('blob', new SqliteBlobStorage({ ...this.options, db: this.db })); | ||
this.add('sync', new SqliteSyncStorage({ ...this.options, db: this.db })); | ||
} | ||
|
||
override async doConnect() { | ||
await this.db.connect(); | ||
} | ||
|
||
override async doDisconnect() { | ||
await this.db.close(); | ||
} | ||
} | ||
``` | ||
|
||
## Compose storages | ||
|
||
```ts | ||
interface SqliteStorageOptions extends StorageOptions { | ||
dbPath: string; | ||
} | ||
|
||
class SqliteStorage extends CloudStorageManager<SqliteStorageOptions> { | ||
idb!: SpaceIDB | null = null; | ||
|
||
constructor(options: StorageOptions) { | ||
super(options); | ||
this.db = new Sqlite(this.options.dbPath); | ||
|
||
this.add('doc', new SqliteDocStorage({ ...this.options, db: this.db })); | ||
} | ||
|
||
override async doConnect() { | ||
await this.db.connect(); | ||
this.idb = await IDBProtocol.open(`${this.spaceType}:${this.spaceId}`); | ||
this.add('blob', new IDBBlobStorage({ ...this.options, idb: this.idb })); | ||
} | ||
|
||
override async doDisconnect() { | ||
await this.db.close(); | ||
await this.idb?.close(); | ||
this.remove('blob'); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './blob'; | ||
export * from './doc'; |
Oops, something went wrong.