@zenfs/core 0.12.7 → 0.12.8
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.
- package/dist/backends/index/fs.d.ts +1 -0
- package/dist/backends/port/fs.d.ts +2 -5
- package/dist/backends/store/fs.d.ts +4 -4
- package/dist/backends/store/fs.js +7 -13
- package/dist/backends/store/simple.d.ts +3 -3
- package/dist/backends/store/simple.js +1 -2
- package/dist/backends/store/store.d.ts +10 -9
- package/dist/backends/store/store.js +6 -6
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +3 -3
- package/dist/filesystem.d.ts +8 -9
- package/dist/filesystem.js +2 -9
- package/package.json +1 -1
- package/src/backends/store/fs.ts +6 -16
- package/src/backends/store/simple.ts +6 -4
- package/src/backends/store/store.ts +14 -9
- package/src/filesystem.ts +11 -20
package/dist/filesystem.d.ts
CHANGED
|
@@ -64,6 +64,12 @@ export declare abstract class FileSystem {
|
|
|
64
64
|
* Get metadata about the current file system
|
|
65
65
|
*/
|
|
66
66
|
metadata(): FileSystemMetadata;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the sync cache should be disabled.
|
|
69
|
+
* Only affects async things.
|
|
70
|
+
* @internal @protected
|
|
71
|
+
*/
|
|
72
|
+
_disableSync?: boolean;
|
|
67
73
|
constructor();
|
|
68
74
|
ready(): Promise<void>;
|
|
69
75
|
/**
|
|
@@ -186,18 +192,11 @@ declare abstract class SyncFS extends FileSystem {
|
|
|
186
192
|
export declare function Sync<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => SyncFS) & T;
|
|
187
193
|
/**
|
|
188
194
|
* @internal
|
|
189
|
-
* Note: `_*` should be treated like protected.
|
|
190
|
-
* Protected can't be used because of TS quirks however.
|
|
191
195
|
*/
|
|
192
196
|
declare abstract class AsyncFS extends FileSystem {
|
|
193
197
|
/**
|
|
194
|
-
*
|
|
195
|
-
* @hidden
|
|
196
|
-
*/
|
|
197
|
-
_disableSync: boolean;
|
|
198
|
-
/**
|
|
199
|
-
* @access protected
|
|
200
|
-
* @hidden
|
|
198
|
+
* protected can't be used because of TS quirks.
|
|
199
|
+
* @hidden @protected
|
|
201
200
|
*/
|
|
202
201
|
abstract _sync?: FileSystem;
|
|
203
202
|
queueDone(): Promise<void>;
|
package/dist/filesystem.js
CHANGED
|
@@ -16,12 +16,12 @@ export class FileSystem {
|
|
|
16
16
|
*/
|
|
17
17
|
metadata() {
|
|
18
18
|
return {
|
|
19
|
-
name: this.constructor.name,
|
|
19
|
+
name: this.constructor.name.toLowerCase(),
|
|
20
20
|
readonly: false,
|
|
21
21
|
totalSpace: 0,
|
|
22
22
|
freeSpace: 0,
|
|
23
23
|
noResizableBuffers: false,
|
|
24
|
-
noAsyncCache: false,
|
|
24
|
+
noAsyncCache: this._disableSync ?? false,
|
|
25
25
|
type: ZenFsType,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -114,7 +114,6 @@ export function Async(FS) {
|
|
|
114
114
|
*/
|
|
115
115
|
this._queue = [];
|
|
116
116
|
this._isInitialized = false;
|
|
117
|
-
this._disableSync = false;
|
|
118
117
|
}
|
|
119
118
|
get _queueRunning() {
|
|
120
119
|
return !!this._queue.length;
|
|
@@ -141,12 +140,6 @@ export function Async(FS) {
|
|
|
141
140
|
throw e;
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
|
-
metadata() {
|
|
145
|
-
return {
|
|
146
|
-
...super.metadata(),
|
|
147
|
-
noAsyncCache: this._disableSync,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
143
|
checkSync(path, syscall) {
|
|
151
144
|
if (this._disableSync) {
|
|
152
145
|
throw new ErrnoError(Errno.ENOTSUP, 'Sync caching has been disabled for this async file system', path, syscall);
|
package/package.json
CHANGED
package/src/backends/store/fs.ts
CHANGED
|
@@ -20,33 +20,21 @@ const maxInodeAllocTries = 5;
|
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
22
|
export class StoreFS<T extends Store = Store> extends FileSystem {
|
|
23
|
-
protected get store(): T {
|
|
24
|
-
if (!this._store) {
|
|
25
|
-
throw new ErrnoError(Errno.ENODATA, 'No store attached');
|
|
26
|
-
}
|
|
27
|
-
return this._store;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected _store?: T;
|
|
31
|
-
|
|
32
23
|
private _initialized: boolean = false;
|
|
33
24
|
|
|
34
25
|
public async ready(): Promise<void> {
|
|
35
|
-
await super.ready();
|
|
36
26
|
if (this._initialized) {
|
|
37
27
|
return;
|
|
38
28
|
}
|
|
29
|
+
await this.makeRootDirectory();
|
|
39
30
|
this._initialized = true;
|
|
40
|
-
this._store = await this.$store;
|
|
41
31
|
}
|
|
42
32
|
|
|
43
|
-
constructor(
|
|
33
|
+
constructor(protected store: T) {
|
|
44
34
|
super();
|
|
45
|
-
|
|
46
|
-
if (!($store instanceof Promise)) {
|
|
47
|
-
this._store = $store;
|
|
48
|
-
this._initialized = true;
|
|
35
|
+
if (!this._disableSync) {
|
|
49
36
|
this.makeRootDirectorySync();
|
|
37
|
+
this._initialized = true;
|
|
50
38
|
}
|
|
51
39
|
}
|
|
52
40
|
|
|
@@ -59,6 +47,7 @@ export class StoreFS<T extends Store = Store> extends FileSystem {
|
|
|
59
47
|
|
|
60
48
|
/**
|
|
61
49
|
* Delete all contents stored in the file system.
|
|
50
|
+
* @deprecated
|
|
62
51
|
*/
|
|
63
52
|
public async empty(): Promise<void> {
|
|
64
53
|
await this.store.clear();
|
|
@@ -68,6 +57,7 @@ export class StoreFS<T extends Store = Store> extends FileSystem {
|
|
|
68
57
|
|
|
69
58
|
/**
|
|
70
59
|
* Delete all contents stored in the file system.
|
|
60
|
+
* @deprecated
|
|
71
61
|
*/
|
|
72
62
|
public emptySync(): void {
|
|
73
63
|
this.store.clearSync();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Ino } from '../../inode.js';
|
|
2
|
-
import { type Store
|
|
2
|
+
import { SyncTransaction, type Store } from './store.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* An interface for simple synchronous stores that don't have special support for transactions and such.
|
|
@@ -69,7 +69,7 @@ export abstract class SimpleAsyncStore implements SimpleSyncStore {
|
|
|
69
69
|
* @see SimpleSyncStore
|
|
70
70
|
* @see SimpleAsyncStore
|
|
71
71
|
*/
|
|
72
|
-
export class SimpleTransaction extends SyncTransaction {
|
|
72
|
+
export class SimpleTransaction extends SyncTransaction<SimpleSyncStore> {
|
|
73
73
|
/**
|
|
74
74
|
* Stores data in the keys we modify prior to modifying them.
|
|
75
75
|
* Allows us to roll back commits.
|
|
@@ -80,8 +80,10 @@ export class SimpleTransaction extends SyncTransaction {
|
|
|
80
80
|
*/
|
|
81
81
|
protected modifiedKeys: Set<Ino> = new Set();
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
protected declare store: SimpleSyncStore;
|
|
84
|
+
|
|
85
|
+
constructor(store: SimpleSyncStore) {
|
|
86
|
+
super(store);
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
public getSync(ino: Ino): Uint8Array {
|
|
@@ -8,7 +8,7 @@ export interface Store {
|
|
|
8
8
|
/**
|
|
9
9
|
* The name of the store.
|
|
10
10
|
*/
|
|
11
|
-
name: string;
|
|
11
|
+
readonly name: string;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Syncs the store
|
|
@@ -32,9 +32,11 @@ export interface Store {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* A transaction for a
|
|
35
|
+
* A transaction for a store.
|
|
36
36
|
*/
|
|
37
|
-
export abstract class Transaction {
|
|
37
|
+
export abstract class Transaction<T extends Store = Store> {
|
|
38
|
+
constructor(protected store: T) {}
|
|
39
|
+
|
|
38
40
|
protected aborted: boolean = false;
|
|
39
41
|
|
|
40
42
|
/**
|
|
@@ -123,7 +125,7 @@ export abstract class Transaction {
|
|
|
123
125
|
/**
|
|
124
126
|
* Transaction that implements asynchronous operations with synchronous ones
|
|
125
127
|
*/
|
|
126
|
-
export abstract class SyncTransaction extends Transaction {
|
|
128
|
+
export abstract class SyncTransaction<T extends Store = Store> extends Transaction<T> {
|
|
127
129
|
public async get(ino: Ino): Promise<Uint8Array> {
|
|
128
130
|
return this.getSync(ino);
|
|
129
131
|
}
|
|
@@ -143,21 +145,24 @@ export abstract class SyncTransaction extends Transaction {
|
|
|
143
145
|
|
|
144
146
|
/**
|
|
145
147
|
* Transaction that only supports asynchronous operations
|
|
146
|
-
* @todo Add caching
|
|
147
148
|
*/
|
|
148
|
-
export abstract class AsyncTransaction extends Transaction {
|
|
149
|
-
public getSync(
|
|
149
|
+
export abstract class AsyncTransaction<T extends Store = Store> extends Transaction<T> {
|
|
150
|
+
public getSync(): Uint8Array {
|
|
150
151
|
throw ErrnoError.With('ENOSYS', undefined, 'AsyncTransaction.getSync');
|
|
151
152
|
}
|
|
152
|
-
|
|
153
|
+
|
|
154
|
+
public setSync(): void {
|
|
153
155
|
throw ErrnoError.With('ENOSYS', undefined, 'AsyncTransaction.setSync');
|
|
154
156
|
}
|
|
155
|
-
|
|
157
|
+
|
|
158
|
+
public removeSync(): void {
|
|
156
159
|
throw ErrnoError.With('ENOSYS', undefined, 'AsyncTransaction.removeSync');
|
|
157
160
|
}
|
|
161
|
+
|
|
158
162
|
public commitSync(): void {
|
|
159
163
|
throw ErrnoError.With('ENOSYS', undefined, 'AsyncTransaction.commitSync');
|
|
160
164
|
}
|
|
165
|
+
|
|
161
166
|
public abortSync(): void {
|
|
162
167
|
throw ErrnoError.With('ENOSYS', undefined, 'AsyncTransaction.abortSync');
|
|
163
168
|
}
|
package/src/filesystem.ts
CHANGED
|
@@ -80,16 +80,23 @@ export abstract class FileSystem {
|
|
|
80
80
|
*/
|
|
81
81
|
public metadata(): FileSystemMetadata {
|
|
82
82
|
return {
|
|
83
|
-
name: this.constructor.name,
|
|
83
|
+
name: this.constructor.name.toLowerCase(),
|
|
84
84
|
readonly: false,
|
|
85
85
|
totalSpace: 0,
|
|
86
86
|
freeSpace: 0,
|
|
87
87
|
noResizableBuffers: false,
|
|
88
|
-
noAsyncCache: false,
|
|
88
|
+
noAsyncCache: this._disableSync ?? false,
|
|
89
89
|
type: ZenFsType,
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Whether the sync cache should be disabled.
|
|
95
|
+
* Only affects async things.
|
|
96
|
+
* @internal @protected
|
|
97
|
+
*/
|
|
98
|
+
_disableSync?: boolean;
|
|
99
|
+
|
|
93
100
|
public constructor() {}
|
|
94
101
|
|
|
95
102
|
public async ready(): Promise<void> {}
|
|
@@ -293,18 +300,11 @@ export function Sync<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
293
300
|
|
|
294
301
|
/**
|
|
295
302
|
* @internal
|
|
296
|
-
* Note: `_*` should be treated like protected.
|
|
297
|
-
* Protected can't be used because of TS quirks however.
|
|
298
303
|
*/
|
|
299
304
|
declare abstract class AsyncFS extends FileSystem {
|
|
300
305
|
/**
|
|
301
|
-
*
|
|
302
|
-
* @hidden
|
|
303
|
-
*/
|
|
304
|
-
_disableSync: boolean;
|
|
305
|
-
/**
|
|
306
|
-
* @access protected
|
|
307
|
-
* @hidden
|
|
306
|
+
* protected can't be used because of TS quirks.
|
|
307
|
+
* @hidden @protected
|
|
308
308
|
*/
|
|
309
309
|
abstract _sync?: FileSystem;
|
|
310
310
|
public queueDone(): Promise<void>;
|
|
@@ -362,8 +362,6 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
362
362
|
|
|
363
363
|
private _isInitialized: boolean = false;
|
|
364
364
|
|
|
365
|
-
_disableSync: boolean = false;
|
|
366
|
-
|
|
367
365
|
abstract _sync?: FileSystem;
|
|
368
366
|
|
|
369
367
|
public async ready(): Promise<void> {
|
|
@@ -384,13 +382,6 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
384
382
|
}
|
|
385
383
|
}
|
|
386
384
|
|
|
387
|
-
public metadata(): FileSystemMetadata {
|
|
388
|
-
return {
|
|
389
|
-
...super.metadata(),
|
|
390
|
-
noAsyncCache: this._disableSync,
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
|
|
394
385
|
protected checkSync(path?: string, syscall?: string): asserts this is { _sync: FileSystem } {
|
|
395
386
|
if (this._disableSync) {
|
|
396
387
|
throw new ErrnoError(Errno.ENOTSUP, 'Sync caching has been disabled for this async file system', path, syscall);
|