@zenfs/core 0.12.8 → 0.12.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,15 @@ export type OptionsConfig<T> = {
26
26
  validator?(opt: T[K]): void | Promise<void>;
27
27
  };
28
28
  };
29
+ /**
30
+ * Configuration options shared by backends and `Configuration`
31
+ */
32
+ export interface SharedConfig {
33
+ /**
34
+ * If set, disables the sync cache and sync operations on async file systems.
35
+ */
36
+ disableAsyncCache: boolean;
37
+ }
29
38
  /**
30
39
  * A backend
31
40
  */
@@ -33,7 +42,7 @@ export interface Backend<FS extends FileSystem = FileSystem, TOptions extends ob
33
42
  /**
34
43
  * Create a new instance of the backend
35
44
  */
36
- create(options: TOptions): FS | Promise<FS>;
45
+ create(options: TOptions & Partial<SharedConfig>): FS | Promise<FS>;
37
46
  /**
38
47
  * A name to identify the backend.
39
48
  */
@@ -81,9 +90,8 @@ export declare function checkOptions<T extends Backend>(backend: T, opts: Record
81
90
  *
82
91
  * The option object for each file system corresponds to that file system's option object passed to its `Create()` method.
83
92
  */
84
- export type BackendConfiguration<T extends Backend> = OptionsOf<T> & {
93
+ export type BackendConfiguration<T extends Backend> = OptionsOf<T> & Partial<SharedConfig> & {
85
94
  backend: T;
86
- disableAsyncCache?: boolean;
87
95
  };
88
96
  /**
89
97
  * @internal
@@ -33,6 +33,8 @@ export const InMemory = {
33
33
  },
34
34
  },
35
35
  create({ name }) {
36
- return new StoreFS(new InMemoryStore(name));
36
+ const fs = new StoreFS(new InMemoryStore(name));
37
+ fs.checkRootSync();
38
+ return fs;
37
39
  },
38
40
  };
@@ -62,11 +62,11 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
62
62
  /**
63
63
  * Checks if the root directory exists. Creates it if it doesn't.
64
64
  */
65
- private makeRootDirectory;
65
+ checkRoot(): Promise<void>;
66
66
  /**
67
67
  * Checks if the root directory exists. Creates it if it doesn't.
68
68
  */
69
- protected makeRootDirectorySync(): void;
69
+ checkRootSync(): void;
70
70
  /**
71
71
  * Helper function for findINode.
72
72
  * @param parent The parent directory of the file we are attempting to find.
@@ -20,17 +20,13 @@ export class StoreFS extends FileSystem {
20
20
  if (this._initialized) {
21
21
  return;
22
22
  }
23
- await this.makeRootDirectory();
23
+ await this.checkRoot();
24
24
  this._initialized = true;
25
25
  }
26
26
  constructor(store) {
27
27
  super();
28
28
  this.store = store;
29
29
  this._initialized = false;
30
- if (!this._disableSync) {
31
- this.makeRootDirectorySync();
32
- this._initialized = true;
33
- }
34
30
  }
35
31
  metadata() {
36
32
  return {
@@ -45,7 +41,7 @@ export class StoreFS extends FileSystem {
45
41
  async empty() {
46
42
  await this.store.clear();
47
43
  // Root always exists.
48
- await this.makeRootDirectory();
44
+ await this.checkRoot();
49
45
  }
50
46
  /**
51
47
  * Delete all contents stored in the file system.
@@ -54,7 +50,7 @@ export class StoreFS extends FileSystem {
54
50
  emptySync() {
55
51
  this.store.clearSync();
56
52
  // Root always exists.
57
- this.makeRootDirectorySync();
53
+ this.checkRootSync();
58
54
  }
59
55
  /**
60
56
  * @todo Make rename compatible with the cache.
@@ -375,7 +371,7 @@ export class StoreFS extends FileSystem {
375
371
  /**
376
372
  * Checks if the root directory exists. Creates it if it doesn't.
377
373
  */
378
- async makeRootDirectory() {
374
+ async checkRoot() {
379
375
  const tx = this.store.transaction();
380
376
  if (await tx.get(rootIno)) {
381
377
  return;
@@ -391,7 +387,7 @@ export class StoreFS extends FileSystem {
391
387
  /**
392
388
  * Checks if the root directory exists. Creates it if it doesn't.
393
389
  */
394
- makeRootDirectorySync() {
390
+ checkRootSync() {
395
391
  const tx = this.store.transaction();
396
392
  if (tx.getSync(rootIno)) {
397
393
  return;