@zenfs/core 0.12.7 → 0.12.9
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/memory.js +3 -1
- package/dist/backends/port/fs.d.ts +2 -5
- package/dist/backends/store/fs.d.ts +6 -6
- package/dist/backends/store/fs.js +9 -19
- 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 +8 -2
- package/src/backends/memory.ts +3 -1
- package/src/backends/store/fs.ts +8 -22
- package/src/backends/store/simple.ts +6 -4
- package/src/backends/store/store.ts +14 -9
- package/src/filesystem.ts +11 -20
|
@@ -20,6 +20,7 @@ declare const IndexFS_base: (abstract new (...args: any[]) => {
|
|
|
20
20
|
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
21
21
|
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
22
22
|
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
23
|
+
_disableSync?: boolean | undefined;
|
|
23
24
|
ready(): Promise<void>;
|
|
24
25
|
stat(path: string, cred: Cred): Promise<Stats>;
|
|
25
26
|
statSync(path: string, cred: Cred): Stats;
|
package/dist/backends/memory.js
CHANGED
|
@@ -41,7 +41,6 @@ export declare class PortFile extends File {
|
|
|
41
41
|
type FSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<any> | FileSystemMetadata>;
|
|
42
42
|
type FSMethod = keyof FSMethods;
|
|
43
43
|
declare const PortFS_base: (abstract new (...args: any[]) => {
|
|
44
|
-
_disableSync: boolean;
|
|
45
44
|
_sync?: FileSystem | undefined;
|
|
46
45
|
queueDone(): Promise<void>;
|
|
47
46
|
metadata(): FileSystemMetadata;
|
|
@@ -56,16 +55,14 @@ declare const PortFS_base: (abstract new (...args: any[]) => {
|
|
|
56
55
|
readdirSync(path: string, cred: Cred): string[];
|
|
57
56
|
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
58
57
|
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
58
|
+
_disableSync?: boolean | undefined;
|
|
59
59
|
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
60
60
|
stat(path: string, cred: Cred): Promise<Stats>;
|
|
61
61
|
openFile(path: string, flag: string, cred: Cred): Promise<File>;
|
|
62
62
|
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
63
63
|
unlink(path: string, cred: Cred): Promise<void>;
|
|
64
64
|
rmdir(path: string, cred: Cred): Promise<void>;
|
|
65
|
-
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
66
|
-
* Constructs a new PortFS instance that connects with ZenFS running on
|
|
67
|
-
* the specified port.
|
|
68
|
-
*/
|
|
65
|
+
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
69
66
|
readdir(path: string, cred: Cred): Promise<string[]>;
|
|
70
67
|
exists(path: string, cred: Cred): Promise<boolean>;
|
|
71
68
|
existsSync(path: string, cred: Cred): boolean;
|
|
@@ -13,19 +13,19 @@ import type { Store, Transaction } from './store.js';
|
|
|
13
13
|
* @internal
|
|
14
14
|
*/
|
|
15
15
|
export declare class StoreFS<T extends Store = Store> extends FileSystem {
|
|
16
|
-
|
|
17
|
-
protected get store(): T;
|
|
18
|
-
protected _store?: T;
|
|
16
|
+
protected store: T;
|
|
19
17
|
private _initialized;
|
|
20
18
|
ready(): Promise<void>;
|
|
21
|
-
constructor(
|
|
19
|
+
constructor(store: T);
|
|
22
20
|
metadata(): FileSystemMetadata;
|
|
23
21
|
/**
|
|
24
22
|
* Delete all contents stored in the file system.
|
|
23
|
+
* @deprecated
|
|
25
24
|
*/
|
|
26
25
|
empty(): Promise<void>;
|
|
27
26
|
/**
|
|
28
27
|
* Delete all contents stored in the file system.
|
|
28
|
+
* @deprecated
|
|
29
29
|
*/
|
|
30
30
|
emptySync(): void;
|
|
31
31
|
/**
|
|
@@ -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
|
-
|
|
65
|
+
checkRoot(): Promise<void>;
|
|
66
66
|
/**
|
|
67
67
|
* Checks if the root directory exists. Creates it if it doesn't.
|
|
68
68
|
*/
|
|
69
|
-
|
|
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.
|
|
@@ -16,29 +16,17 @@ const maxInodeAllocTries = 5;
|
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
18
|
export class StoreFS extends FileSystem {
|
|
19
|
-
get store() {
|
|
20
|
-
if (!this._store) {
|
|
21
|
-
throw new ErrnoError(Errno.ENODATA, 'No store attached');
|
|
22
|
-
}
|
|
23
|
-
return this._store;
|
|
24
|
-
}
|
|
25
19
|
async ready() {
|
|
26
|
-
await super.ready();
|
|
27
20
|
if (this._initialized) {
|
|
28
21
|
return;
|
|
29
22
|
}
|
|
23
|
+
await this.checkRoot();
|
|
30
24
|
this._initialized = true;
|
|
31
|
-
this._store = await this.$store;
|
|
32
25
|
}
|
|
33
|
-
constructor(
|
|
26
|
+
constructor(store) {
|
|
34
27
|
super();
|
|
35
|
-
this
|
|
28
|
+
this.store = store;
|
|
36
29
|
this._initialized = false;
|
|
37
|
-
if (!($store instanceof Promise)) {
|
|
38
|
-
this._store = $store;
|
|
39
|
-
this._initialized = true;
|
|
40
|
-
this.makeRootDirectorySync();
|
|
41
|
-
}
|
|
42
30
|
}
|
|
43
31
|
metadata() {
|
|
44
32
|
return {
|
|
@@ -48,19 +36,21 @@ export class StoreFS extends FileSystem {
|
|
|
48
36
|
}
|
|
49
37
|
/**
|
|
50
38
|
* Delete all contents stored in the file system.
|
|
39
|
+
* @deprecated
|
|
51
40
|
*/
|
|
52
41
|
async empty() {
|
|
53
42
|
await this.store.clear();
|
|
54
43
|
// Root always exists.
|
|
55
|
-
await this.
|
|
44
|
+
await this.checkRoot();
|
|
56
45
|
}
|
|
57
46
|
/**
|
|
58
47
|
* Delete all contents stored in the file system.
|
|
48
|
+
* @deprecated
|
|
59
49
|
*/
|
|
60
50
|
emptySync() {
|
|
61
51
|
this.store.clearSync();
|
|
62
52
|
// Root always exists.
|
|
63
|
-
this.
|
|
53
|
+
this.checkRootSync();
|
|
64
54
|
}
|
|
65
55
|
/**
|
|
66
56
|
* @todo Make rename compatible with the cache.
|
|
@@ -381,7 +371,7 @@ export class StoreFS extends FileSystem {
|
|
|
381
371
|
/**
|
|
382
372
|
* Checks if the root directory exists. Creates it if it doesn't.
|
|
383
373
|
*/
|
|
384
|
-
async
|
|
374
|
+
async checkRoot() {
|
|
385
375
|
const tx = this.store.transaction();
|
|
386
376
|
if (await tx.get(rootIno)) {
|
|
387
377
|
return;
|
|
@@ -397,7 +387,7 @@ export class StoreFS extends FileSystem {
|
|
|
397
387
|
/**
|
|
398
388
|
* Checks if the root directory exists. Creates it if it doesn't.
|
|
399
389
|
*/
|
|
400
|
-
|
|
390
|
+
checkRootSync() {
|
|
401
391
|
const tx = this.store.transaction();
|
|
402
392
|
if (tx.getSync(rootIno)) {
|
|
403
393
|
return;
|
|
@@ -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
|
* An interface for simple synchronous stores that don't have special support for transactions and such.
|
|
5
5
|
*/
|
|
@@ -32,8 +32,7 @@ export declare abstract class SimpleAsyncStore implements SimpleSyncStore {
|
|
|
32
32
|
* @see SimpleSyncStore
|
|
33
33
|
* @see SimpleAsyncStore
|
|
34
34
|
*/
|
|
35
|
-
export declare class SimpleTransaction extends SyncTransaction {
|
|
36
|
-
protected store: SimpleSyncStore;
|
|
35
|
+
export declare class SimpleTransaction extends SyncTransaction<SimpleSyncStore> {
|
|
37
36
|
/**
|
|
38
37
|
* Stores data in the keys we modify prior to modifying them.
|
|
39
38
|
* Allows us to roll back commits.
|
|
@@ -43,6 +42,7 @@ export declare class SimpleTransaction extends SyncTransaction {
|
|
|
43
42
|
* List of keys modified in this transaction, if any.
|
|
44
43
|
*/
|
|
45
44
|
protected modifiedKeys: Set<Ino>;
|
|
45
|
+
protected store: SimpleSyncStore;
|
|
46
46
|
constructor(store: SimpleSyncStore);
|
|
47
47
|
getSync(ino: Ino): Uint8Array;
|
|
48
48
|
setSync(ino: Ino, data: Uint8Array): void;
|
|
@@ -44,8 +44,7 @@ export class SimpleAsyncStore {
|
|
|
44
44
|
*/
|
|
45
45
|
export class SimpleTransaction extends SyncTransaction {
|
|
46
46
|
constructor(store) {
|
|
47
|
-
super();
|
|
48
|
-
this.store = store;
|
|
47
|
+
super(store);
|
|
49
48
|
/**
|
|
50
49
|
* Stores data in the keys we modify prior to modifying them.
|
|
51
50
|
* Allows us to roll back commits.
|
|
@@ -6,7 +6,7 @@ export interface Store {
|
|
|
6
6
|
/**
|
|
7
7
|
* The name of the store.
|
|
8
8
|
*/
|
|
9
|
-
name: string;
|
|
9
|
+
readonly name: string;
|
|
10
10
|
/**
|
|
11
11
|
* Syncs the store
|
|
12
12
|
*/
|
|
@@ -25,9 +25,11 @@ export interface Store {
|
|
|
25
25
|
transaction(): Transaction;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* A transaction for a
|
|
28
|
+
* A transaction for a store.
|
|
29
29
|
*/
|
|
30
|
-
export declare abstract class Transaction {
|
|
30
|
+
export declare abstract class Transaction<T extends Store = Store> {
|
|
31
|
+
protected store: T;
|
|
32
|
+
constructor(store: T);
|
|
31
33
|
protected aborted: boolean;
|
|
32
34
|
/**
|
|
33
35
|
* Retrieves the data at the given key.
|
|
@@ -91,7 +93,7 @@ export declare abstract class Transaction {
|
|
|
91
93
|
/**
|
|
92
94
|
* Transaction that implements asynchronous operations with synchronous ones
|
|
93
95
|
*/
|
|
94
|
-
export declare abstract class SyncTransaction extends Transaction {
|
|
96
|
+
export declare abstract class SyncTransaction<T extends Store = Store> extends Transaction<T> {
|
|
95
97
|
get(ino: Ino): Promise<Uint8Array>;
|
|
96
98
|
set(ino: bigint, data: Uint8Array): Promise<void>;
|
|
97
99
|
remove(ino: Ino): Promise<void>;
|
|
@@ -100,12 +102,11 @@ export declare abstract class SyncTransaction extends Transaction {
|
|
|
100
102
|
}
|
|
101
103
|
/**
|
|
102
104
|
* Transaction that only supports asynchronous operations
|
|
103
|
-
* @todo Add caching
|
|
104
105
|
*/
|
|
105
|
-
export declare abstract class AsyncTransaction extends Transaction {
|
|
106
|
-
getSync(
|
|
107
|
-
setSync(
|
|
108
|
-
removeSync(
|
|
106
|
+
export declare abstract class AsyncTransaction<T extends Store = Store> extends Transaction<T> {
|
|
107
|
+
getSync(): Uint8Array;
|
|
108
|
+
setSync(): void;
|
|
109
|
+
removeSync(): void;
|
|
109
110
|
commitSync(): void;
|
|
110
111
|
abortSync(): void;
|
|
111
112
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ErrnoError } from '../../error.js';
|
|
2
2
|
/**
|
|
3
|
-
* A transaction for a
|
|
3
|
+
* A transaction for a store.
|
|
4
4
|
*/
|
|
5
5
|
export class Transaction {
|
|
6
|
-
constructor() {
|
|
6
|
+
constructor(store) {
|
|
7
|
+
this.store = store;
|
|
7
8
|
this.aborted = false;
|
|
8
9
|
}
|
|
9
10
|
async [Symbol.asyncDispose]() {
|
|
@@ -41,16 +42,15 @@ export class SyncTransaction extends Transaction {
|
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* Transaction that only supports asynchronous operations
|
|
44
|
-
* @todo Add caching
|
|
45
45
|
*/
|
|
46
46
|
export class AsyncTransaction extends Transaction {
|
|
47
|
-
getSync(
|
|
47
|
+
getSync() {
|
|
48
48
|
throw ErrnoError.With('ENOSYS', undefined, 'AsyncTransaction.getSync');
|
|
49
49
|
}
|
|
50
|
-
setSync(
|
|
50
|
+
setSync() {
|
|
51
51
|
throw ErrnoError.With('ENOSYS', undefined, 'AsyncTransaction.setSync');
|
|
52
52
|
}
|
|
53
|
-
removeSync(
|
|
53
|
+
removeSync() {
|
|
54
54
|
throw ErrnoError.With('ENOSYS', undefined, 'AsyncTransaction.removeSync');
|
|
55
55
|
}
|
|
56
56
|
commitSync() {
|