@utoo/web 1.2.0-rc.5 → 1.2.0-rc.7
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/README.md +52 -0
- package/esm/{8df7dc7828270e8a8ece.wasm → b0afc1b3f31b4fb74f6b.wasm} +0 -0
- package/esm/forkedProject.d.ts +2 -1
- package/esm/forkedProject.js +5 -0
- package/esm/internalProject.d.ts +3 -3
- package/esm/internalProject.js +36 -20
- package/esm/loaderWorker.js +1 -1
- package/esm/project.d.ts +2 -1
- package/esm/project.js +12 -3
- package/esm/sabcom.d.ts +17 -0
- package/esm/sabcom.js +93 -26
- package/esm/serviceWorker.js +1 -0
- package/esm/type.d.ts +38 -0
- package/esm/type.js +44 -0
- package/esm/utoo/index.d.ts +27 -24
- package/esm/utoo/index.js +104 -102
- package/esm/utoo/index_bg.wasm +0 -0
- package/esm/webpackLoaders/{worker/cjs.js → cjs.js} +71 -64
- package/esm/webpackLoaders/loaderWorkerPool.d.ts +2 -0
- package/esm/{loaderWorkerPool.js → webpackLoaders/loaderWorkerPool.js} +30 -18
- package/esm/webpackLoaders/polyfills/fsPolyfill.d.ts +78 -0
- package/esm/webpackLoaders/polyfills/fsPolyfill.js +279 -0
- package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.d.ts +26 -0
- package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.js +112 -0
- package/esm/webpackLoaders/{worker/type.d.ts → type.d.ts} +1 -0
- package/esm/webpackLoaders/{worker/index.js → worker.js} +8 -3
- package/package.json +6 -6
- package/esm/loaderWorkerPool.d.ts +0 -3
- package/esm/webpackLoaders/worker/polyfills/fsPolyfill.d.ts +0 -244
- package/esm/webpackLoaders/worker/polyfills/fsPolyfill.js +0 -369
- package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.d.ts +0 -9
- package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.js +0 -9
- /package/esm/webpackLoaders/{worker/cjs.d.ts → cjs.d.ts} +0 -0
- /package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.d.ts +0 -0
- /package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.js +0 -0
- /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.d.ts +0 -0
- /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.js +0 -0
- /package/esm/webpackLoaders/{worker/type.js → type.js} +0 -0
- /package/esm/webpackLoaders/{worker/index.d.ts → worker.d.ts} +0 -0
package/esm/project.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildOutput, Dirent, PackFile, ProjectEndpoint, ProjectOptions, ServiceWorkerOptions } from "./type";
|
|
1
|
+
import { BuildOutput, Dirent, PackFile, ProjectEndpoint, ProjectOptions, ServiceWorkerOptions, Stats } from "./type";
|
|
2
2
|
export declare class Project implements ProjectEndpoint {
|
|
3
3
|
#private;
|
|
4
4
|
private options;
|
|
@@ -26,6 +26,7 @@ export declare class Project implements ProjectEndpoint {
|
|
|
26
26
|
rmdir(path: string, options?: {
|
|
27
27
|
recursive?: boolean;
|
|
28
28
|
}): Promise<void>;
|
|
29
|
+
stat(path: string): Promise<Stats>;
|
|
29
30
|
gzip(files: PackFile[]): Promise<Uint8Array>;
|
|
30
31
|
sigMd5(content: Uint8Array): Promise<string>;
|
|
31
32
|
static fork(channel: MessageChannel, eventSource?: Client | DedicatedWorkerGlobalScope): ProjectEndpoint;
|
package/esm/project.js
CHANGED
|
@@ -15,7 +15,7 @@ import * as comlink from "comlink";
|
|
|
15
15
|
import { ForkedProject } from "./forkedProject";
|
|
16
16
|
import { installServiceWorker } from "./installServiceWorker";
|
|
17
17
|
import { Fork, HandShake } from "./message";
|
|
18
|
-
import { Dirent, } from "./type";
|
|
18
|
+
import { Dirent, Stats, } from "./type";
|
|
19
19
|
let ProjectWorker;
|
|
20
20
|
const ConnectedPorts = new Set();
|
|
21
21
|
export class Project {
|
|
@@ -81,6 +81,9 @@ export class Project {
|
|
|
81
81
|
}
|
|
82
82
|
async writeFile(path, content, encoding) {
|
|
83
83
|
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
84
|
+
if (content instanceof Uint8Array) {
|
|
85
|
+
return await this.remote.writeFile(path, comlink.transfer(content, [content.buffer]), encoding);
|
|
86
|
+
}
|
|
84
87
|
return await this.remote.writeFile(path, content, encoding);
|
|
85
88
|
}
|
|
86
89
|
async copyFile(src, dst) {
|
|
@@ -104,13 +107,19 @@ export class Project {
|
|
|
104
107
|
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
105
108
|
return await this.remote.rmdir(path, options);
|
|
106
109
|
}
|
|
110
|
+
async stat(path) {
|
|
111
|
+
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
112
|
+
const raw = (await this.remote.stat(path));
|
|
113
|
+
return new Stats(raw);
|
|
114
|
+
}
|
|
107
115
|
async gzip(files) {
|
|
108
116
|
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
109
|
-
|
|
117
|
+
const buffers = files.map((f) => f.content.buffer);
|
|
118
|
+
return await this.remote.gzip(comlink.transfer(files, buffers));
|
|
110
119
|
}
|
|
111
120
|
async sigMd5(content) {
|
|
112
121
|
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
113
|
-
return await this.remote.sigMd5(content);
|
|
122
|
+
return await this.remote.sigMd5(comlink.transfer(content, [content.buffer]));
|
|
114
123
|
}
|
|
115
124
|
static fork(channel, eventSource) {
|
|
116
125
|
(eventSource || self).postMessage(Fork, {
|
package/esm/sabcom.d.ts
CHANGED
|
@@ -10,10 +10,17 @@ export declare const SAB_OP_RM = 5;
|
|
|
10
10
|
export declare const SAB_OP_RMDIR = 6;
|
|
11
11
|
export declare const SAB_OP_COPY_FILE = 7;
|
|
12
12
|
export declare const SAB_OP_STAT = 8;
|
|
13
|
+
export declare const STAT_TYPE_FILE = 0;
|
|
14
|
+
export declare const STAT_TYPE_DIR = 1;
|
|
15
|
+
export declare const SAB_INDEX_STATE = 0;
|
|
16
|
+
export declare const SAB_INDEX_OP = 1;
|
|
17
|
+
export declare const SAB_INDEX_DATA_LEN = 2;
|
|
18
|
+
export declare const SAB_DATA_OFFSET = 12;
|
|
13
19
|
export declare class SabComHost {
|
|
14
20
|
private sab;
|
|
15
21
|
private int32;
|
|
16
22
|
private uint8;
|
|
23
|
+
private dataView;
|
|
17
24
|
constructor(sab: SharedArrayBuffer);
|
|
18
25
|
readRequest(): {
|
|
19
26
|
op: number;
|
|
@@ -21,14 +28,24 @@ export declare class SabComHost {
|
|
|
21
28
|
};
|
|
22
29
|
writeResponse(data: Uint8Array | string): void;
|
|
23
30
|
writeError(message: string): void;
|
|
31
|
+
writeStat(type: number, size: bigint, atimeMs: number, mtimeMs: number, ctimeMs: number, birthtimeMs: number): void;
|
|
24
32
|
}
|
|
25
33
|
export declare class SabComClient {
|
|
26
34
|
private sab;
|
|
27
35
|
private notifyHost;
|
|
28
36
|
private int32;
|
|
29
37
|
private uint8;
|
|
38
|
+
private dataView;
|
|
30
39
|
constructor(sab: SharedArrayBuffer, notifyHost: () => void);
|
|
31
40
|
call(op: number, data: string): Uint8Array<ArrayBuffer>;
|
|
41
|
+
callStat(path: string): {
|
|
42
|
+
type: number;
|
|
43
|
+
size: bigint;
|
|
44
|
+
atimeMs: number;
|
|
45
|
+
mtimeMs: number;
|
|
46
|
+
ctimeMs: number;
|
|
47
|
+
birthtimeMs: number;
|
|
48
|
+
};
|
|
32
49
|
}
|
|
33
50
|
export interface SabFileSystem {
|
|
34
51
|
read(path: string): Promise<Uint8Array>;
|
package/esm/sabcom.js
CHANGED
|
@@ -10,6 +10,26 @@ export const SAB_OP_RM = 5;
|
|
|
10
10
|
export const SAB_OP_RMDIR = 6;
|
|
11
11
|
export const SAB_OP_COPY_FILE = 7;
|
|
12
12
|
export const SAB_OP_STAT = 8;
|
|
13
|
+
export const STAT_TYPE_FILE = 0;
|
|
14
|
+
export const STAT_TYPE_DIR = 1;
|
|
15
|
+
export const SAB_INDEX_STATE = 0;
|
|
16
|
+
export const SAB_INDEX_OP = 1;
|
|
17
|
+
export const SAB_INDEX_DATA_LEN = 2;
|
|
18
|
+
export const SAB_DATA_OFFSET = 12;
|
|
19
|
+
// Stat struct layout (starts at byte 12)
|
|
20
|
+
// type: Uint8 (1 byte) -> offset 0
|
|
21
|
+
// padding: 7 bytes
|
|
22
|
+
// size: BigUint64 (8 bytes) -> offset 8
|
|
23
|
+
// atimeMs: Float64 (8 bytes) -> offset 16
|
|
24
|
+
// mtimeMs: Float64 (8 bytes) -> offset 24
|
|
25
|
+
// ctimeMs: Float64 (8 bytes) -> offset 32
|
|
26
|
+
// birthtimeMs: Float64 (8 bytes) -> offset 40
|
|
27
|
+
const STAT_OFFSET_TYPE = 0;
|
|
28
|
+
const STAT_OFFSET_SIZE = 8;
|
|
29
|
+
const STAT_OFFSET_ATIME = 16;
|
|
30
|
+
const STAT_OFFSET_MTIME = 24;
|
|
31
|
+
const STAT_OFFSET_CTIME = 32;
|
|
32
|
+
const STAT_OFFSET_BIRTHTIME = 40;
|
|
13
33
|
// Layout:
|
|
14
34
|
// 0: State (Int32)
|
|
15
35
|
// 1: Op (Int32)
|
|
@@ -20,11 +40,12 @@ export class SabComHost {
|
|
|
20
40
|
this.sab = sab;
|
|
21
41
|
this.int32 = new Int32Array(sab);
|
|
22
42
|
this.uint8 = new Uint8Array(sab);
|
|
43
|
+
this.dataView = new DataView(sab);
|
|
23
44
|
}
|
|
24
45
|
readRequest() {
|
|
25
|
-
const op = this.int32[
|
|
26
|
-
const len = this.int32[
|
|
27
|
-
const data = new TextDecoder().decode(this.uint8.slice(
|
|
46
|
+
const op = this.int32[SAB_INDEX_OP];
|
|
47
|
+
const len = this.int32[SAB_INDEX_DATA_LEN];
|
|
48
|
+
const data = new TextDecoder().decode(this.uint8.slice(SAB_DATA_OFFSET, SAB_DATA_OFFSET + len));
|
|
28
49
|
return { op, data };
|
|
29
50
|
}
|
|
30
51
|
writeResponse(data) {
|
|
@@ -32,17 +53,28 @@ export class SabComHost {
|
|
|
32
53
|
data = new TextEncoder().encode(data);
|
|
33
54
|
}
|
|
34
55
|
// TODO: Check size overflow
|
|
35
|
-
this.int32[
|
|
36
|
-
this.uint8.set(data,
|
|
37
|
-
Atomics.store(this.int32,
|
|
38
|
-
Atomics.notify(this.int32,
|
|
56
|
+
this.int32[SAB_INDEX_DATA_LEN] = data.length;
|
|
57
|
+
this.uint8.set(data, SAB_DATA_OFFSET);
|
|
58
|
+
Atomics.store(this.int32, SAB_INDEX_STATE, SAB_STATE_RESPONSE);
|
|
59
|
+
Atomics.notify(this.int32, SAB_INDEX_STATE);
|
|
39
60
|
}
|
|
40
61
|
writeError(message) {
|
|
41
62
|
const data = new TextEncoder().encode(message);
|
|
42
|
-
this.int32[
|
|
43
|
-
this.uint8.set(data,
|
|
44
|
-
Atomics.store(this.int32,
|
|
45
|
-
Atomics.notify(this.int32,
|
|
63
|
+
this.int32[SAB_INDEX_DATA_LEN] = data.length;
|
|
64
|
+
this.uint8.set(data, SAB_DATA_OFFSET);
|
|
65
|
+
Atomics.store(this.int32, SAB_INDEX_STATE, SAB_STATE_ERROR);
|
|
66
|
+
Atomics.notify(this.int32, SAB_INDEX_STATE);
|
|
67
|
+
}
|
|
68
|
+
writeStat(type, size, atimeMs, mtimeMs, ctimeMs, birthtimeMs) {
|
|
69
|
+
const base = SAB_DATA_OFFSET;
|
|
70
|
+
this.dataView.setUint8(base + STAT_OFFSET_TYPE, type);
|
|
71
|
+
this.dataView.setBigUint64(base + STAT_OFFSET_SIZE, size, true);
|
|
72
|
+
this.dataView.setFloat64(base + STAT_OFFSET_ATIME, atimeMs, true);
|
|
73
|
+
this.dataView.setFloat64(base + STAT_OFFSET_MTIME, mtimeMs, true);
|
|
74
|
+
this.dataView.setFloat64(base + STAT_OFFSET_CTIME, ctimeMs, true);
|
|
75
|
+
this.dataView.setFloat64(base + STAT_OFFSET_BIRTHTIME, birthtimeMs, true);
|
|
76
|
+
Atomics.store(this.int32, SAB_INDEX_STATE, SAB_STATE_RESPONSE);
|
|
77
|
+
Atomics.notify(this.int32, SAB_INDEX_STATE);
|
|
46
78
|
}
|
|
47
79
|
}
|
|
48
80
|
export class SabComClient {
|
|
@@ -51,23 +83,48 @@ export class SabComClient {
|
|
|
51
83
|
this.notifyHost = notifyHost;
|
|
52
84
|
this.int32 = new Int32Array(sab);
|
|
53
85
|
this.uint8 = new Uint8Array(sab);
|
|
86
|
+
this.dataView = new DataView(sab);
|
|
54
87
|
}
|
|
55
88
|
call(op, data) {
|
|
56
89
|
const encoded = new TextEncoder().encode(data);
|
|
57
|
-
this.int32[
|
|
58
|
-
this.int32[
|
|
59
|
-
this.uint8.set(encoded,
|
|
60
|
-
Atomics.store(this.int32,
|
|
90
|
+
this.int32[SAB_INDEX_OP] = op;
|
|
91
|
+
this.int32[SAB_INDEX_DATA_LEN] = encoded.length;
|
|
92
|
+
this.uint8.set(encoded, SAB_DATA_OFFSET);
|
|
93
|
+
Atomics.store(this.int32, SAB_INDEX_STATE, SAB_STATE_REQUEST);
|
|
94
|
+
this.notifyHost();
|
|
95
|
+
Atomics.wait(this.int32, SAB_INDEX_STATE, SAB_STATE_REQUEST);
|
|
96
|
+
const state = Atomics.load(this.int32, SAB_INDEX_STATE);
|
|
97
|
+
if (state === SAB_STATE_ERROR) {
|
|
98
|
+
const len = this.int32[SAB_INDEX_DATA_LEN];
|
|
99
|
+
const msg = new TextDecoder().decode(this.uint8.slice(SAB_DATA_OFFSET, SAB_DATA_OFFSET + len));
|
|
100
|
+
throw new Error(msg);
|
|
101
|
+
}
|
|
102
|
+
const len = this.int32[SAB_INDEX_DATA_LEN];
|
|
103
|
+
return this.uint8.slice(SAB_DATA_OFFSET, SAB_DATA_OFFSET + len);
|
|
104
|
+
}
|
|
105
|
+
callStat(path) {
|
|
106
|
+
const encoded = new TextEncoder().encode(path);
|
|
107
|
+
this.int32[SAB_INDEX_OP] = SAB_OP_STAT;
|
|
108
|
+
this.int32[SAB_INDEX_DATA_LEN] = encoded.length;
|
|
109
|
+
this.uint8.set(encoded, SAB_DATA_OFFSET);
|
|
110
|
+
Atomics.store(this.int32, SAB_INDEX_STATE, SAB_STATE_REQUEST);
|
|
61
111
|
this.notifyHost();
|
|
62
|
-
Atomics.wait(this.int32,
|
|
63
|
-
const state = Atomics.load(this.int32,
|
|
112
|
+
Atomics.wait(this.int32, SAB_INDEX_STATE, SAB_STATE_REQUEST);
|
|
113
|
+
const state = Atomics.load(this.int32, SAB_INDEX_STATE);
|
|
64
114
|
if (state === SAB_STATE_ERROR) {
|
|
65
|
-
const len = this.int32[
|
|
66
|
-
const msg = new TextDecoder().decode(this.uint8.slice(
|
|
115
|
+
const len = this.int32[SAB_INDEX_DATA_LEN];
|
|
116
|
+
const msg = new TextDecoder().decode(this.uint8.slice(SAB_DATA_OFFSET, SAB_DATA_OFFSET + len));
|
|
67
117
|
throw new Error(msg);
|
|
68
118
|
}
|
|
69
|
-
const
|
|
70
|
-
return
|
|
119
|
+
const base = SAB_DATA_OFFSET;
|
|
120
|
+
return {
|
|
121
|
+
type: this.dataView.getUint8(base + STAT_OFFSET_TYPE),
|
|
122
|
+
size: this.dataView.getBigUint64(base + STAT_OFFSET_SIZE, true),
|
|
123
|
+
atimeMs: this.dataView.getFloat64(base + STAT_OFFSET_ATIME, true),
|
|
124
|
+
mtimeMs: this.dataView.getFloat64(base + STAT_OFFSET_MTIME, true),
|
|
125
|
+
ctimeMs: this.dataView.getFloat64(base + STAT_OFFSET_CTIME, true),
|
|
126
|
+
birthtimeMs: this.dataView.getFloat64(base + STAT_OFFSET_BIRTHTIME, true),
|
|
127
|
+
};
|
|
71
128
|
}
|
|
72
129
|
}
|
|
73
130
|
export const handleSabRequest = async (sabHost, fs) => {
|
|
@@ -82,9 +139,7 @@ export const handleSabRequest = async (sabHost, fs) => {
|
|
|
82
139
|
sabHost.writeResponse(JSON.stringify(entries.map((e) => e.toJSON())));
|
|
83
140
|
}
|
|
84
141
|
else if (op === SAB_OP_WRITE_FILE) {
|
|
85
|
-
const {
|
|
86
|
-
const filePath = content.path;
|
|
87
|
-
const fileContent = content.data;
|
|
142
|
+
const { path: filePath, data: fileContent } = JSON.parse(path);
|
|
88
143
|
// TODO: handle binary content (base64?)
|
|
89
144
|
await fs.writeString(filePath, fileContent);
|
|
90
145
|
sabHost.writeResponse("ok");
|
|
@@ -103,7 +158,10 @@ export const handleSabRequest = async (sabHost, fs) => {
|
|
|
103
158
|
const { path: rmPath, recursive } = JSON.parse(path);
|
|
104
159
|
// Mimic internalProject.rm logic
|
|
105
160
|
const metadata = await fs.metadata(rmPath);
|
|
106
|
-
const
|
|
161
|
+
const json = metadata.toJSON
|
|
162
|
+
? metadata.toJSON()
|
|
163
|
+
: metadata;
|
|
164
|
+
const type = json.type;
|
|
107
165
|
if (type === "file") {
|
|
108
166
|
await fs.removeFile(rmPath);
|
|
109
167
|
}
|
|
@@ -124,7 +182,16 @@ export const handleSabRequest = async (sabHost, fs) => {
|
|
|
124
182
|
}
|
|
125
183
|
else if (op === SAB_OP_STAT) {
|
|
126
184
|
const metadata = await fs.metadata(path);
|
|
127
|
-
|
|
185
|
+
const json = metadata.toJSON
|
|
186
|
+
? metadata.toJSON()
|
|
187
|
+
: metadata;
|
|
188
|
+
const type = json.type === "directory" ? STAT_TYPE_DIR : STAT_TYPE_FILE;
|
|
189
|
+
const size = BigInt(json.file_size || 0);
|
|
190
|
+
const atimeMs = Number(json.atimeMs || 0);
|
|
191
|
+
const mtimeMs = Number(json.mtimeMs || 0);
|
|
192
|
+
const ctimeMs = Number(json.ctimeMs || 0);
|
|
193
|
+
const birthtimeMs = Number(json.birthtimeMs || 0);
|
|
194
|
+
sabHost.writeStat(type, size, atimeMs, mtimeMs, ctimeMs, birthtimeMs);
|
|
128
195
|
}
|
|
129
196
|
else {
|
|
130
197
|
sabHost.writeError("Unknown op");
|
package/esm/serviceWorker.js
CHANGED
package/esm/type.d.ts
CHANGED
|
@@ -4,6 +4,43 @@ export interface RawDirent {
|
|
|
4
4
|
name: string;
|
|
5
5
|
type: DirEntryType;
|
|
6
6
|
}
|
|
7
|
+
export interface RawStats {
|
|
8
|
+
type: DirEntryType;
|
|
9
|
+
size: number;
|
|
10
|
+
atimeMs?: number;
|
|
11
|
+
mtimeMs?: number;
|
|
12
|
+
ctimeMs?: number;
|
|
13
|
+
birthtimeMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class Stats {
|
|
16
|
+
private raw;
|
|
17
|
+
dev: number;
|
|
18
|
+
ino: number;
|
|
19
|
+
mode: number;
|
|
20
|
+
nlink: number;
|
|
21
|
+
uid: number;
|
|
22
|
+
gid: number;
|
|
23
|
+
rdev: number;
|
|
24
|
+
size: number;
|
|
25
|
+
blksize: number;
|
|
26
|
+
blocks: number;
|
|
27
|
+
atimeMs: number;
|
|
28
|
+
mtimeMs: number;
|
|
29
|
+
ctimeMs: number;
|
|
30
|
+
birthtimeMs: number;
|
|
31
|
+
atime: Date;
|
|
32
|
+
mtime: Date;
|
|
33
|
+
ctime: Date;
|
|
34
|
+
birthtime: Date;
|
|
35
|
+
constructor(raw: RawStats);
|
|
36
|
+
isDirectory(): boolean;
|
|
37
|
+
isFile(): boolean;
|
|
38
|
+
isSymbolicLink(): boolean;
|
|
39
|
+
isBlockDevice(): boolean;
|
|
40
|
+
isCharacterDevice(): boolean;
|
|
41
|
+
isFIFO(): boolean;
|
|
42
|
+
isSocket(): boolean;
|
|
43
|
+
}
|
|
7
44
|
export declare class Dirent {
|
|
8
45
|
private rawDirent;
|
|
9
46
|
name: string;
|
|
@@ -37,6 +74,7 @@ export interface ProjectEndpoint {
|
|
|
37
74
|
recursive?: boolean;
|
|
38
75
|
}): Promise<void>;
|
|
39
76
|
copyFile(src: string, dst: string): Promise<void>;
|
|
77
|
+
stat(path: string): Promise<Stats>;
|
|
40
78
|
gzip: (files: PackFile[]) => Promise<Uint8Array>;
|
|
41
79
|
sigMd5: (content: Uint8Array) => Promise<string>;
|
|
42
80
|
}
|
package/esm/type.js
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
+
export class Stats {
|
|
2
|
+
constructor(raw) {
|
|
3
|
+
this.raw = raw;
|
|
4
|
+
this.dev = 0;
|
|
5
|
+
this.ino = 0;
|
|
6
|
+
this.nlink = 1;
|
|
7
|
+
this.uid = 0;
|
|
8
|
+
this.gid = 0;
|
|
9
|
+
this.rdev = 0;
|
|
10
|
+
this.blksize = 4096;
|
|
11
|
+
this.blocks = 0;
|
|
12
|
+
this.size = raw.size;
|
|
13
|
+
this.mode = raw.type === "directory" ? 16877 : 33188;
|
|
14
|
+
this.atimeMs = raw.atimeMs || 0;
|
|
15
|
+
this.mtimeMs = raw.mtimeMs || 0;
|
|
16
|
+
this.ctimeMs = raw.ctimeMs || 0;
|
|
17
|
+
this.birthtimeMs = raw.birthtimeMs || 0;
|
|
18
|
+
this.atime = new Date(this.atimeMs);
|
|
19
|
+
this.mtime = new Date(this.mtimeMs);
|
|
20
|
+
this.ctime = new Date(this.ctimeMs);
|
|
21
|
+
this.birthtime = new Date(this.birthtimeMs);
|
|
22
|
+
}
|
|
23
|
+
isDirectory() {
|
|
24
|
+
return this.raw.type === "directory";
|
|
25
|
+
}
|
|
26
|
+
isFile() {
|
|
27
|
+
return this.raw.type === "file";
|
|
28
|
+
}
|
|
29
|
+
isSymbolicLink() {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
isBlockDevice() {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
isCharacterDevice() {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
isFIFO() {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
isSocket() {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
1
45
|
export class Dirent {
|
|
2
46
|
constructor(rawDirent) {
|
|
3
47
|
this.rawDirent = rawDirent;
|
package/esm/utoo/index.d.ts
CHANGED
|
@@ -88,100 +88,103 @@ export class Metadata {
|
|
|
88
88
|
get file_size(): bigint;
|
|
89
89
|
}
|
|
90
90
|
export class Project {
|
|
91
|
-
/**
|
|
92
|
-
* @param {string} cwd
|
|
93
|
-
* @param {string} thread_url
|
|
94
|
-
*/
|
|
95
|
-
constructor(cwd: string, thread_url: string);
|
|
96
|
-
__destroy_into_raw(): number;
|
|
97
|
-
__wbg_ptr: number;
|
|
98
|
-
free(): void;
|
|
99
91
|
/**
|
|
100
92
|
* @param {string} path
|
|
101
93
|
* @returns {Promise<void>}
|
|
102
94
|
*/
|
|
103
|
-
createDir(path: string): Promise<void>;
|
|
95
|
+
static createDir(path: string): Promise<void>;
|
|
104
96
|
/**
|
|
105
97
|
* @param {string} path
|
|
106
98
|
* @param {boolean} recursive
|
|
107
99
|
* @returns {Promise<void>}
|
|
108
100
|
*/
|
|
109
|
-
removeDir(path: string, recursive: boolean): Promise<void>;
|
|
101
|
+
static removeDir(path: string, recursive: boolean): Promise<void>;
|
|
110
102
|
/**
|
|
111
103
|
* @param {string} path
|
|
112
104
|
* @returns {Promise<void>}
|
|
113
105
|
*/
|
|
114
|
-
removeFile(path: string): Promise<void>;
|
|
106
|
+
static removeFile(path: string): Promise<void>;
|
|
115
107
|
/**
|
|
116
108
|
* @param {string} path
|
|
117
109
|
* @param {string} content
|
|
118
110
|
* @returns {Promise<void>}
|
|
119
111
|
*/
|
|
120
|
-
writeString(path: string, content: string): Promise<void>;
|
|
112
|
+
static writeString(path: string, content: string): Promise<void>;
|
|
121
113
|
/**
|
|
122
114
|
* @param {string} path
|
|
123
115
|
* @returns {Promise<void>}
|
|
124
116
|
*/
|
|
125
|
-
createDirAll(path: string): Promise<void>;
|
|
117
|
+
static createDirAll(path: string): Promise<void>;
|
|
126
118
|
/**
|
|
127
119
|
* @param {string} path
|
|
128
120
|
* @returns {Promise<string>}
|
|
129
121
|
*/
|
|
130
|
-
readToString(path: string): Promise<string>;
|
|
122
|
+
static readToString(path: string): Promise<string>;
|
|
131
123
|
/**
|
|
132
124
|
* @returns {string}
|
|
133
125
|
*/
|
|
134
|
-
get cwd(): string;
|
|
126
|
+
static get cwd(): string;
|
|
135
127
|
/**
|
|
136
128
|
* Create a tar.gz archive and return bytes (no file I/O)
|
|
137
129
|
* This is useful for main thread execution without OPFS access
|
|
138
130
|
* @param {any} files
|
|
139
131
|
* @returns {Uint8Array}
|
|
140
132
|
*/
|
|
141
|
-
gzip(files: any): Uint8Array;
|
|
133
|
+
static gzip(files: any): Uint8Array;
|
|
134
|
+
/**
|
|
135
|
+
* @param {string} thread_url
|
|
136
|
+
*/
|
|
137
|
+
static init(thread_url: string): void;
|
|
142
138
|
/**
|
|
143
139
|
* @param {string} path
|
|
144
140
|
* @returns {Promise<Uint8Array>}
|
|
145
141
|
*/
|
|
146
|
-
read(path: string): Promise<Uint8Array>;
|
|
142
|
+
static read(path: string): Promise<Uint8Array>;
|
|
147
143
|
/**
|
|
148
144
|
* @returns {Promise<any>}
|
|
149
145
|
*/
|
|
150
|
-
build(): Promise<any>;
|
|
146
|
+
static build(): Promise<any>;
|
|
151
147
|
/**
|
|
152
148
|
* @param {string} path
|
|
153
149
|
* @param {Uint8Array} content
|
|
154
150
|
* @returns {Promise<void>}
|
|
155
151
|
*/
|
|
156
|
-
write(path: string, content: Uint8Array): Promise<void>;
|
|
152
|
+
static write(path: string, content: Uint8Array): Promise<void>;
|
|
157
153
|
/**
|
|
158
154
|
* @param {string} package_lock
|
|
159
155
|
* @param {number | null} [max_concurrent_downloads]
|
|
160
156
|
* @returns {Promise<void>}
|
|
161
157
|
*/
|
|
162
|
-
install(package_lock: string, max_concurrent_downloads?: number | null): Promise<void>;
|
|
158
|
+
static install(package_lock: string, max_concurrent_downloads?: number | null): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* @param {string} path
|
|
161
|
+
*/
|
|
162
|
+
static setCwd(path: string): void;
|
|
163
163
|
/**
|
|
164
164
|
* Calculate MD5 hash of byte content
|
|
165
165
|
* @param {Uint8Array} content
|
|
166
166
|
* @returns {string}
|
|
167
167
|
*/
|
|
168
|
-
sigMd5(content: Uint8Array): string;
|
|
168
|
+
static sigMd5(content: Uint8Array): string;
|
|
169
169
|
/**
|
|
170
170
|
* @param {string} path
|
|
171
171
|
* @returns {Promise<Metadata>}
|
|
172
172
|
*/
|
|
173
|
-
metadata(path: string): Promise<Metadata>;
|
|
173
|
+
static metadata(path: string): Promise<Metadata>;
|
|
174
174
|
/**
|
|
175
175
|
* @param {string} path
|
|
176
176
|
* @returns {Promise<DirEntry[]>}
|
|
177
177
|
*/
|
|
178
|
-
readDir(path: string): Promise<DirEntry[]>;
|
|
178
|
+
static readDir(path: string): Promise<DirEntry[]>;
|
|
179
179
|
/**
|
|
180
180
|
* @param {string} src
|
|
181
181
|
* @param {string} dst
|
|
182
182
|
* @returns {Promise<void>}
|
|
183
183
|
*/
|
|
184
|
-
copyFile(src: string, dst: string): Promise<void>;
|
|
184
|
+
static copyFile(src: string, dst: string): Promise<void>;
|
|
185
|
+
__destroy_into_raw(): number | undefined;
|
|
186
|
+
__wbg_ptr: number | undefined;
|
|
187
|
+
free(): void;
|
|
185
188
|
}
|
|
186
189
|
export class WasmTaskMessage {
|
|
187
190
|
static __wrap(ptr: any): any;
|