@opendaw/lib-fusion 0.0.28 → 0.0.30
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.
@@ -3,13 +3,15 @@ import { OpfsProtocol } from "./OpfsProtocol";
|
|
3
3
|
import "../types";
|
4
4
|
export declare namespace OpfsWorker {
|
5
5
|
const init: (messenger: Messenger) => Communicator.Executor<{
|
6
|
+
readonly "__#private@#locks": Map<string, Promise<void>>;
|
6
7
|
write(path: string, data: Uint8Array): Promise<void>;
|
7
8
|
read(path: string): Promise<Uint8Array>;
|
8
9
|
delete(path: string): Promise<void>;
|
9
10
|
list(path: string): Promise<ReadonlyArray<OpfsProtocol.Entry>>;
|
10
11
|
clear(): Promise<void>;
|
11
|
-
#
|
12
|
-
#
|
12
|
+
"__#private@#acquireLock"<T>(path: string, operation: () => Promise<T>): Promise<T>;
|
13
|
+
"__#private@#resolveFile"(path: string, options?: FileSystemGetDirectoryOptions): Promise<FileSystemSyncAccessHandle>;
|
14
|
+
"__#private@#resolveFolder"(segments: ReadonlyArray<string>, options?: FileSystemGetDirectoryOptions): Promise<FileSystemDirectoryHandle>;
|
13
15
|
}>;
|
14
16
|
}
|
15
17
|
//# sourceMappingURL=OpfsWorker.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"OpfsWorker.d.ts","sourceRoot":"","sources":["../../src/opfs/OpfsWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,SAAS,EAAW,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAC3C,OAAO,UAAU,CAAA;AAEjB,yBAAiB,UAAU,CAAC;IAGjB,MAAM,IAAI,GAAI,WAAW,SAAS
|
1
|
+
{"version":3,"file":"OpfsWorker.d.ts","sourceRoot":"","sources":["../../src/opfs/OpfsWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,SAAS,EAAW,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAC3C,OAAO,UAAU,CAAA;AAEjB,yBAAiB,UAAU,CAAC;IAGjB,MAAM,IAAI,GAAI,WAAW,SAAS;;oBAIf,MAAM,QAAQ,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;mBAczC,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;qBAe1B,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;mBASxB,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;iBAWrD,OAAO,CAAC,IAAI,CAAC;kCAWT,CAAC,QAAQ,MAAM,aAAa,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;wCAkBnD,MAAM,YAAY,6BAA6B,GAAG,OAAO,CAAC,0BAA0B,CAAC;8CAO/E,aAAa,CAAC,MAAM,CAAC,YACrB,6BAA6B,GAAG,OAAO,CAAC,yBAAyB,CAAC;MAKnG,CAAA;CAMT"}
|
package/dist/opfs/OpfsWorker.js
CHANGED
@@ -1,46 +1,53 @@
|
|
1
|
-
import { Arrays, asDefined } from "@opendaw/lib-std";
|
1
|
+
import { Arrays, asDefined, panic } from "@opendaw/lib-std";
|
2
2
|
import { Communicator, Promises } from "@opendaw/lib-runtime";
|
3
3
|
import "../types";
|
4
4
|
export var OpfsWorker;
|
5
5
|
(function (OpfsWorker) {
|
6
6
|
const DEBUG = true;
|
7
7
|
OpfsWorker.init = (messenger) => Communicator.executor(messenger.channel("opfs"), new class {
|
8
|
+
#locks = new Map();
|
8
9
|
async write(path, data) {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
await this.#acquireLock(path, async () => {
|
11
|
+
if (DEBUG) {
|
12
|
+
console.debug(`write ${data.length}b to ${path}`);
|
13
|
+
}
|
14
|
+
const handle = await this.#resolveFile(path, { create: true });
|
15
|
+
try {
|
16
|
+
handle.truncate(data.length);
|
17
|
+
handle.write(data.buffer, { at: 0 });
|
18
|
+
handle.flush();
|
19
|
+
}
|
20
|
+
finally {
|
21
|
+
handle.close();
|
22
|
+
}
|
23
|
+
});
|
21
24
|
}
|
22
25
|
async read(path) {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
return await this.#acquireLock(path, async () => {
|
27
|
+
if (DEBUG) {
|
28
|
+
console.debug(`read ${path}`);
|
29
|
+
}
|
30
|
+
const handle = await this.#resolveFile(path);
|
31
|
+
try {
|
32
|
+
const size = handle.getSize();
|
33
|
+
const buffer = new Uint8Array(size);
|
34
|
+
handle.read(buffer);
|
35
|
+
return buffer;
|
36
|
+
}
|
37
|
+
finally {
|
38
|
+
handle.close();
|
39
|
+
}
|
40
|
+
});
|
36
41
|
}
|
37
42
|
async delete(path) {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
await this.#acquireLock(path, async () => {
|
44
|
+
const segments = pathToSegments(path);
|
45
|
+
if (segments.length === 0) {
|
46
|
+
return this.clear();
|
47
|
+
}
|
48
|
+
return this.#resolveFolder(segments.slice(0, -1))
|
49
|
+
.then(folder => folder.removeEntry(asDefined(segments.at(-1)), { recursive: true }));
|
50
|
+
});
|
44
51
|
}
|
45
52
|
async list(path) {
|
46
53
|
const segments = pathToSegments(path);
|
@@ -65,6 +72,24 @@ export var OpfsWorker;
|
|
65
72
|
}
|
66
73
|
}
|
67
74
|
}
|
75
|
+
async #acquireLock(path, operation) {
|
76
|
+
const existingLock = this.#locks.get(path);
|
77
|
+
if (existingLock) {
|
78
|
+
await existingLock;
|
79
|
+
}
|
80
|
+
let releaseLock = () => panic("Lock not acquired");
|
81
|
+
const lockPromise = new Promise(resolve => releaseLock = resolve);
|
82
|
+
this.#locks.set(path, lockPromise);
|
83
|
+
try {
|
84
|
+
return await operation();
|
85
|
+
}
|
86
|
+
finally {
|
87
|
+
releaseLock();
|
88
|
+
if (this.#locks.get(path) === lockPromise) {
|
89
|
+
this.#locks.delete(path);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
68
93
|
async #resolveFile(path, options) {
|
69
94
|
const segments = pathToSegments(path);
|
70
95
|
const folder = await this.#resolveFolder(segments.slice(0, -1), options);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opendaw/lib-fusion",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.30",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"license": "LGPL-3.0-or-later",
|
@@ -22,13 +22,13 @@
|
|
22
22
|
"test": "echo \"No tests to run\""
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@opendaw/lib-box": "^0.0.
|
26
|
-
"@opendaw/lib-runtime": "^0.0.
|
27
|
-
"@opendaw/lib-std": "^0.0.
|
25
|
+
"@opendaw/lib-box": "^0.0.30",
|
26
|
+
"@opendaw/lib-runtime": "^0.0.30",
|
27
|
+
"@opendaw/lib-std": "^0.0.30"
|
28
28
|
},
|
29
29
|
"devDependencies": {
|
30
30
|
"@opendaw/eslint-config": "^0.0.19",
|
31
31
|
"@opendaw/typescript-config": "^0.0.20"
|
32
32
|
},
|
33
|
-
"gitHead": "
|
33
|
+
"gitHead": "2fff74bbce57bd2c3c634b1cb735cccdaff2ab15"
|
34
34
|
}
|