@utoo/web 0.0.1-alpha.3 → 0.0.1-alpha.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/esm/index.d.ts +14 -9
- package/esm/index.js +29 -31
- package/esm/type.d.ts +20 -7
- package/esm/type.js +12 -1
- package/esm/utoo/index.d.ts +21 -34
- package/esm/utoo/index.js +452 -174
- package/esm/utoo/index_bg.wasm +0 -0
- package/esm/worker.d.ts +4 -1
- package/esm/worker.js +52 -14
- package/package.json +11 -5
package/esm/index.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dirent, ProjectEndpoint } from "./type";
|
|
2
|
+
import { MountOpt } from "./worker";
|
|
2
3
|
export declare class Project implements ProjectEndpoint {
|
|
3
4
|
#private;
|
|
4
|
-
private cwd;
|
|
5
5
|
private remote;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(opt: MountOpt & {
|
|
7
|
+
worker?: Worker;
|
|
8
|
+
});
|
|
7
9
|
install(packageLock: string): Promise<void>;
|
|
8
10
|
build(): Promise<void>;
|
|
9
|
-
readFile(path: string): Promise<
|
|
10
|
-
writeFile(path: string, content: string): Promise<void>;
|
|
11
|
+
readFile(path: string, encoding?: "utf8"): Promise<any>;
|
|
12
|
+
writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
|
|
11
13
|
copyFile(src: string, dst: string): Promise<void>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
readdir(path: string, options?: {
|
|
15
|
+
recursive?: boolean;
|
|
16
|
+
}): Promise<Dirent[]>;
|
|
17
|
+
mkdir(path: string, options?: {
|
|
18
|
+
recursive?: boolean;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
static fork(channel: MessageChannel): ProjectEndpoint;
|
|
16
21
|
}
|
|
17
22
|
export * from "./type";
|
package/esm/index.js
CHANGED
|
@@ -12,17 +12,19 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
12
12
|
var _Project_tunnel;
|
|
13
13
|
import * as comlink from "comlink";
|
|
14
14
|
import { Fork, HandShake } from "./message";
|
|
15
|
+
import { Dirent } from "./type";
|
|
15
16
|
let ProjectWorker;
|
|
16
17
|
const ConnectedPorts = new Set();
|
|
17
18
|
export class Project {
|
|
18
|
-
constructor(
|
|
19
|
+
constructor(opt) {
|
|
19
20
|
var _a, _b;
|
|
20
21
|
_Project_tunnel.set(this, void 0);
|
|
21
|
-
|
|
22
|
+
const { cwd, worker, wasmUrl } = opt;
|
|
22
23
|
const { port1, port2 } = new MessageChannel();
|
|
23
24
|
(_a = this.remote) !== null && _a !== void 0 ? _a : (this.remote = comlink.wrap(port1));
|
|
24
25
|
if (!ProjectWorker) {
|
|
25
|
-
ProjectWorker =
|
|
26
|
+
ProjectWorker =
|
|
27
|
+
worker || new Worker(new URL("./worker", import.meta.url));
|
|
26
28
|
self.addEventListener("message", (e) => {
|
|
27
29
|
const port = e.ports[0];
|
|
28
30
|
if (e.data === Fork && !ConnectedPorts.has(port)) {
|
|
@@ -31,7 +33,7 @@ export class Project {
|
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
ProjectWorker.postMessage(HandShake, [port2]);
|
|
34
|
-
__classPrivateFieldSet(this, _Project_tunnel, (_b = __classPrivateFieldGet(this, _Project_tunnel, "f")) !== null && _b !== void 0 ? _b : this.remote.mount(
|
|
36
|
+
__classPrivateFieldSet(this, _Project_tunnel, (_b = __classPrivateFieldGet(this, _Project_tunnel, "f")) !== null && _b !== void 0 ? _b : this.remote.mount({ cwd, wasmUrl }), "f");
|
|
35
37
|
}
|
|
36
38
|
async install(packageLock) {
|
|
37
39
|
await __classPrivateFieldGet(this, _Project_tunnel, "f");
|
|
@@ -41,34 +43,33 @@ export class Project {
|
|
|
41
43
|
await __classPrivateFieldGet(this, _Project_tunnel, "f");
|
|
42
44
|
return await this.remote.build();
|
|
43
45
|
}
|
|
44
|
-
async readFile(path) {
|
|
46
|
+
async readFile(path, encoding) {
|
|
45
47
|
await __classPrivateFieldGet(this, _Project_tunnel, "f");
|
|
46
|
-
return await this.remote.readFile(path);
|
|
48
|
+
return (await this.remote.readFile(path, encoding));
|
|
47
49
|
}
|
|
48
|
-
async writeFile(path, content) {
|
|
50
|
+
async writeFile(path, content, encoding) {
|
|
49
51
|
await __classPrivateFieldGet(this, _Project_tunnel, "f");
|
|
50
|
-
return await this.remote.writeFile(path, content);
|
|
52
|
+
return await this.remote.writeFile(path, content, encoding);
|
|
51
53
|
}
|
|
52
54
|
async copyFile(src, dst) {
|
|
53
55
|
await __classPrivateFieldGet(this, _Project_tunnel, "f");
|
|
54
56
|
return await this.remote.copyFile(src, dst);
|
|
55
57
|
}
|
|
56
|
-
async
|
|
58
|
+
async readdir(path, options) {
|
|
57
59
|
await __classPrivateFieldGet(this, _Project_tunnel, "f");
|
|
58
|
-
|
|
60
|
+
const dirEntry = (await this.remote.readdir(path, options));
|
|
61
|
+
return dirEntry.map((e) => new Dirent(e));
|
|
59
62
|
}
|
|
60
|
-
async
|
|
63
|
+
async mkdir(path, options) {
|
|
61
64
|
await __classPrivateFieldGet(this, _Project_tunnel, "f");
|
|
62
|
-
return await this.remote.
|
|
65
|
+
return await this.remote.mkdir(path, options);
|
|
63
66
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
self.postMessage(Fork, [port2]);
|
|
71
|
-
return new ForkedProject(port1);
|
|
67
|
+
static fork(channel) {
|
|
68
|
+
self.postMessage(Fork, {
|
|
69
|
+
targetOrigin: "*",
|
|
70
|
+
transfer: [channel.port2],
|
|
71
|
+
});
|
|
72
|
+
return new ForkedProject(channel.port1);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
_Project_tunnel = new WeakMap();
|
|
@@ -83,23 +84,20 @@ class ForkedProject {
|
|
|
83
84
|
async build() {
|
|
84
85
|
return await this.endpoint.build();
|
|
85
86
|
}
|
|
86
|
-
async readFile(path) {
|
|
87
|
-
return await this.endpoint.readFile(path);
|
|
87
|
+
async readFile(path, encoding) {
|
|
88
|
+
return (await this.endpoint.readFile(path, encoding));
|
|
88
89
|
}
|
|
89
|
-
async writeFile(path, content) {
|
|
90
|
-
return await this.endpoint.writeFile(path, content);
|
|
90
|
+
async writeFile(path, content, encoding) {
|
|
91
|
+
return await this.endpoint.writeFile(path, content, encoding);
|
|
91
92
|
}
|
|
92
93
|
async copyFile(src, dst) {
|
|
93
94
|
return await this.endpoint.copyFile(src, dst);
|
|
94
95
|
}
|
|
95
|
-
async
|
|
96
|
-
return await this.endpoint.
|
|
97
|
-
}
|
|
98
|
-
async createDir(path) {
|
|
99
|
-
return await this.endpoint.createDir(path);
|
|
96
|
+
async readdir(path, options) {
|
|
97
|
+
return await this.endpoint.readdir(path, options);
|
|
100
98
|
}
|
|
101
|
-
async
|
|
102
|
-
return await this.endpoint.
|
|
99
|
+
async mkdir(path, options) {
|
|
100
|
+
return await this.endpoint.mkdir(path, options);
|
|
103
101
|
}
|
|
104
102
|
}
|
|
105
103
|
export * from "./type";
|
package/esm/type.d.ts
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
export interface
|
|
1
|
+
import { DirEntryType } from "./utoo";
|
|
2
|
+
export interface RawDirent {
|
|
3
3
|
name: string;
|
|
4
4
|
type: DirEntryType;
|
|
5
5
|
}
|
|
6
|
+
export declare class Dirent {
|
|
7
|
+
private rawDirent;
|
|
8
|
+
name: string;
|
|
9
|
+
constructor(rawDirent: RawDirent);
|
|
10
|
+
isDirectory(): boolean;
|
|
11
|
+
isFile(): boolean;
|
|
12
|
+
}
|
|
6
13
|
export interface ProjectEndpoint {
|
|
7
14
|
install: (packageLock: string) => Promise<void>;
|
|
8
15
|
build: () => Promise<void>;
|
|
9
|
-
readFile(path: string): Promise<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
17
|
+
readFile(path: string, encoding?: "utf8"): Promise<string>;
|
|
18
|
+
writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
|
|
19
|
+
readdir(path: string, options?: {
|
|
20
|
+
recursive?: boolean;
|
|
21
|
+
}): Promise<Dirent[]>;
|
|
22
|
+
mkdir(path: string, options?: {
|
|
23
|
+
recursive?: boolean;
|
|
24
|
+
}): Promise<void>;
|
|
14
25
|
copyFile(src: string, dst: string): Promise<void>;
|
|
15
26
|
}
|
|
27
|
+
export interface ProjectEndpoint {
|
|
28
|
+
}
|
package/esm/type.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export class Dirent {
|
|
2
|
+
constructor(rawDirent) {
|
|
3
|
+
this.rawDirent = rawDirent;
|
|
4
|
+
this.name = this.rawDirent.name;
|
|
5
|
+
}
|
|
6
|
+
isDirectory() {
|
|
7
|
+
return this.rawDirent.type === "directory";
|
|
8
|
+
}
|
|
9
|
+
isFile() {
|
|
10
|
+
return this.rawDirent.type === "file";
|
|
11
|
+
}
|
|
12
|
+
}
|
package/esm/utoo/index.d.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
+
export function init_pack(): void;
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @
|
|
3
|
+
* Entry point for web workers
|
|
4
|
+
* @param {number} ptr
|
|
4
5
|
*/
|
|
5
|
-
export function
|
|
6
|
-
export function init_pack(): void;
|
|
6
|
+
export function wasm_thread_entry_point(ptr: number): void;
|
|
7
7
|
export class CreateSyncAccessHandleOptions {
|
|
8
8
|
static __wrap(ptr: any): any;
|
|
9
9
|
__destroy_into_raw(): number | undefined;
|
|
10
10
|
__wbg_ptr: number | undefined;
|
|
11
11
|
free(): void;
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Directory entry with name and type information
|
|
15
|
-
*/
|
|
16
13
|
export class DirEntry {
|
|
17
14
|
static __wrap(ptr: any): any;
|
|
18
15
|
toJSON(): {
|
|
@@ -40,27 +37,6 @@ export class DirEntry {
|
|
|
40
37
|
*/
|
|
41
38
|
get type(): DirEntryType;
|
|
42
39
|
}
|
|
43
|
-
export class PartialProjectOptions {
|
|
44
|
-
__destroy_into_raw(): number | undefined;
|
|
45
|
-
__wbg_ptr: number | undefined;
|
|
46
|
-
free(): void;
|
|
47
|
-
/**
|
|
48
|
-
* @param {string} arg0
|
|
49
|
-
*/
|
|
50
|
-
set project_path(arg0: string);
|
|
51
|
-
/**
|
|
52
|
-
* @returns {string}
|
|
53
|
-
*/
|
|
54
|
-
get project_path(): string;
|
|
55
|
-
/**
|
|
56
|
-
* @param {string | null} [arg0]
|
|
57
|
-
*/
|
|
58
|
-
set config(arg0: string | null);
|
|
59
|
-
/**
|
|
60
|
-
* @returns {string | undefined}
|
|
61
|
-
*/
|
|
62
|
-
get config(): string | undefined;
|
|
63
|
-
}
|
|
64
40
|
export class Project {
|
|
65
41
|
/**
|
|
66
42
|
* @param {string} cwd
|
|
@@ -79,20 +55,31 @@ export class Project {
|
|
|
79
55
|
*/
|
|
80
56
|
install(package_lock: string): Promise<void>;
|
|
81
57
|
/**
|
|
82
|
-
* @returns {Promise<
|
|
58
|
+
* @returns {Promise<any>}
|
|
83
59
|
*/
|
|
84
|
-
build(): Promise<
|
|
60
|
+
build(): Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} path
|
|
63
|
+
* @returns {Promise<Uint8Array>}
|
|
64
|
+
*/
|
|
65
|
+
read(path: string): Promise<Uint8Array>;
|
|
85
66
|
/**
|
|
86
67
|
* @param {string} path
|
|
87
68
|
* @returns {Promise<string>}
|
|
88
69
|
*/
|
|
89
|
-
|
|
70
|
+
readToString(path: string): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* @param {string} path
|
|
73
|
+
* @param {Uint8Array} content
|
|
74
|
+
* @returns {Promise<void>}
|
|
75
|
+
*/
|
|
76
|
+
write(path: string, content: Uint8Array): Promise<void>;
|
|
90
77
|
/**
|
|
91
78
|
* @param {string} path
|
|
92
79
|
* @param {string} content
|
|
93
80
|
* @returns {Promise<void>}
|
|
94
81
|
*/
|
|
95
|
-
|
|
82
|
+
writeString(path: string, content: string): Promise<void>;
|
|
96
83
|
/**
|
|
97
84
|
* @param {string} path
|
|
98
85
|
* @returns {Promise<DirEntry[]>}
|
|
@@ -116,5 +103,5 @@ export class Project {
|
|
|
116
103
|
copyFile(src: string, dst: string): Promise<void>;
|
|
117
104
|
}
|
|
118
105
|
export default __wbg_init;
|
|
119
|
-
export function initSync(module: any): any;
|
|
120
|
-
declare function __wbg_init(module_or_path: any): Promise<any>;
|
|
106
|
+
export function initSync(module: any, memory: any): any;
|
|
107
|
+
declare function __wbg_init(module_or_path: any, memory: any): Promise<any>;
|