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