Skip to content

Commit

Permalink
Changed AsyncStoreFileSystem to use new options format
Browse files Browse the repository at this point in the history
Fixed AsyncStoreFileSystem.ready() and _initialize()
Added AsyncStoreFileSystemOptions
Renamed SyncFileSystemOptions to SyncStoreFileSystemOptions
  • Loading branch information
james-pre committed Mar 7, 2024
1 parent e610aa3 commit 2f4fa80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/backends/AsyncStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ export class AsyncFile extends PreloadFile<AsyncStoreFileSystem> {
}
}

export interface AsyncStoreFileSystemOptions {
/**
* Promise that resolves to the store
*/
store: Promise<AsyncStore>;

/**
* The size of the cache. If not provided, no cache will be used
*/
cacheSize?: number;
}

/**
* An "Asynchronous key-value file system". Stores data to/retrieves data from
* an underlying asynchronous key-value store.
Expand All @@ -160,21 +172,23 @@ export class AsyncStoreFileSystem extends AsyncFileSystem {
return this._ready;
}

constructor(cacheSize: number) {
constructor({ store, cacheSize }: AsyncStoreFileSystemOptions) {
super();
if (cacheSize > 0) {
this._cache = new LRUCache(cacheSize);
}
this._ready = this._initialize(store);
}

/**
* Initializes the file system. Typically called by subclasses' async
* constructors.
*/
public async init(store: AsyncStore) {
this.store = store;
protected async _initialize(store: Promise<AsyncStore>): Promise<this> {
this.store = await store;
// INVARIANT: Ensure that the root exists.
await this.makeRootDirectory();
return this;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/backends/SyncStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class SimpleSyncRWTransaction implements SyncRWTransaction {
}
}

export interface SyncFileSystemOptions {
export interface SyncStoreFileSystemOptions {
/**
* The actual key-value store to read from/write to.
*/
Expand Down Expand Up @@ -202,7 +202,7 @@ export class SyncStoreFile extends PreloadFile<SyncStoreFileSystem> {
export class SyncStoreFileSystem extends SyncFileSystem {
protected store: SyncStore;

constructor(options: SyncFileSystemOptions) {
constructor(options: SyncStoreFileSystemOptions) {
super();
this.store = options.store;
// INVARIANT: Ensure that the root exists.
Expand Down

0 comments on commit 2f4fa80

Please sign in to comment.