@utoo/web 0.0.1-alpha.2 → 0.0.1-alpha.8

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 CHANGED
@@ -1,17 +1,20 @@
1
- import { ProjectEndpoint, DirEntry } from "./type";
1
+ import { Dirent, ProjectEndpoint } from "./type";
2
2
  export declare class Project implements ProjectEndpoint {
3
3
  #private;
4
4
  private cwd;
5
5
  private remote;
6
- constructor(cwd: string);
6
+ constructor(cwd: string, worker?: Worker);
7
7
  install(packageLock: string): Promise<void>;
8
8
  build(): Promise<void>;
9
- readFile(path: string): Promise<string>;
10
- writeFile(path: string, content: string): Promise<void>;
9
+ readFile(path: string, encoding?: "utf8"): Promise<any>;
10
+ writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
11
11
  copyFile(src: string, dst: string): Promise<void>;
12
- readDir(path: string): Promise<DirEntry[]>;
13
- createDir(path: string): Promise<void>;
14
- createDirAll(path: string): Promise<void>;
15
- static fork(port1: MessagePort, port2: MessagePort): ProjectEndpoint;
12
+ readdir(path: string, options?: {
13
+ recursive?: boolean;
14
+ }): Promise<Dirent[]>;
15
+ mkdir(path: string, options?: {
16
+ recursive?: boolean;
17
+ }): Promise<void>;
18
+ static fork(channel: MessageChannel): ProjectEndpoint;
16
19
  }
17
20
  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(cwd) {
19
+ constructor(cwd, worker) {
19
20
  var _a, _b;
20
21
  _Project_tunnel.set(this, void 0);
21
22
  this.cwd = cwd;
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 = new Worker(new URL("./worker", import.meta.url));
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)) {
@@ -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 readDir(path) {
58
+ async readdir(path, options) {
57
59
  await __classPrivateFieldGet(this, _Project_tunnel, "f");
58
- return await this.remote.readDir(path);
60
+ const dirEntry = (await this.remote.readdir(path, options));
61
+ return dirEntry.map((e) => new Dirent(e));
59
62
  }
60
- async createDir(path) {
63
+ async mkdir(path, options) {
61
64
  await __classPrivateFieldGet(this, _Project_tunnel, "f");
62
- return await this.remote.createDir(path);
65
+ return await this.remote.mkdir(path, options);
63
66
  }
64
- async createDirAll(path) {
65
- await __classPrivateFieldGet(this, _Project_tunnel, "f");
66
- return await this.remote.createDirAll(path);
67
- }
68
- // This should be called from different worker
69
- static fork(port1, port2) {
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 readDir(path) {
96
- return await this.endpoint.readDir(path);
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 createDirAll(path) {
102
- return await this.endpoint.createDirAll(path);
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 type { DirEntryType } from "./utoo";
2
- export interface DirEntry {
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<string>;
10
- writeFile(path: string, content: string): Promise<void>;
11
- readDir(path: string): Promise<DirEntry[]>;
12
- createDir(path: string): Promise<void>;
13
- createDirAll(path: string): 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>;
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
+ }
@@ -1,3 +1,4 @@
1
+ export function init_pack(): void;
1
2
  export class CreateSyncAccessHandleOptions {
2
3
  static __wrap(ptr: any): any;
3
4
  __destroy_into_raw(): number | undefined;
@@ -55,17 +56,28 @@ export class Project {
55
56
  * @returns {Promise<void>}
56
57
  */
57
58
  build(): Promise<void>;
59
+ /**
60
+ * @param {string} path
61
+ * @returns {Promise<Uint8Array>}
62
+ */
63
+ read(path: string): Promise<Uint8Array>;
58
64
  /**
59
65
  * @param {string} path
60
66
  * @returns {Promise<string>}
61
67
  */
62
- readFile(path: string): Promise<string>;
68
+ readToString(path: string): Promise<string>;
69
+ /**
70
+ * @param {string} path
71
+ * @param {Uint8Array} content
72
+ * @returns {Promise<void>}
73
+ */
74
+ write(path: string, content: Uint8Array): Promise<void>;
63
75
  /**
64
76
  * @param {string} path
65
77
  * @param {string} content
66
78
  * @returns {Promise<void>}
67
79
  */
68
- writeFile(path: string, content: string): Promise<void>;
80
+ writeString(path: string, content: string): Promise<void>;
69
81
  /**
70
82
  * @param {string} path
71
83
  * @returns {Promise<DirEntry[]>}
package/esm/utoo/index.js CHANGED
@@ -46,6 +46,10 @@ function takeObject(idx) {
46
46
  dropObject(idx);
47
47
  return ret;
48
48
  }
49
+ function getArrayU8FromWasm0(ptr, len) {
50
+ ptr = ptr >>> 0;
51
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
52
+ }
49
53
  let WASM_VECTOR_LEN = 0;
50
54
  const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available'); } });
51
55
  const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
@@ -98,17 +102,13 @@ function getDataViewMemory0() {
98
102
  }
99
103
  return cachedDataViewMemory0;
100
104
  }
101
- function getArrayU8FromWasm0(ptr, len) {
102
- ptr = ptr >>> 0;
103
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
104
- }
105
105
  function isLikeNone(x) {
106
106
  return x === undefined || x === null;
107
107
  }
108
108
  const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
109
109
  ? { register: () => { }, unregister: () => { } }
110
110
  : new FinalizationRegistry(state => {
111
- wasm.__wbindgen_export_3.get(state.dtor)(state.a, state.b);
111
+ wasm.__wbindgen_export_4.get(state.dtor)(state.a, state.b);
112
112
  });
113
113
  function makeMutClosure(arg0, arg1, dtor, f) {
114
114
  const state = { a: arg0, b: arg1, cnt: 1, dtor };
@@ -124,7 +124,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
124
124
  }
125
125
  finally {
126
126
  if (--state.cnt === 0) {
127
- wasm.__wbindgen_export_3.get(state.dtor)(a, state.b);
127
+ wasm.__wbindgen_export_4.get(state.dtor)(a, state.b);
128
128
  CLOSURE_DTORS.unregister(state);
129
129
  }
130
130
  else {
@@ -204,14 +204,26 @@ function debugString(val) {
204
204
  // TODO we could test for more things here, like `Set`s and `Map`s.
205
205
  return className;
206
206
  }
207
- function __wbg_adapter_28(arg0, arg1) {
207
+ function passArray8ToWasm0(arg, malloc) {
208
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
209
+ getUint8ArrayMemory0().set(arg, ptr / 1);
210
+ WASM_VECTOR_LEN = arg.length;
211
+ return ptr;
212
+ }
213
+ export function init_pack() {
214
+ wasm.init_pack();
215
+ }
216
+ function __wbg_adapter_30(arg0, arg1) {
208
217
  wasm.__wbindgen_export_5(arg0, arg1);
209
218
  }
210
- function __wbg_adapter_31(arg0, arg1, arg2) {
219
+ function __wbg_adapter_33(arg0, arg1, arg2) {
211
220
  wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2));
212
221
  }
213
- function __wbg_adapter_66(arg0, arg1, arg2, arg3) {
214
- wasm.__wbindgen_export_7(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
222
+ function __wbg_adapter_36(arg0, arg1) {
223
+ wasm.__wbindgen_export_7(arg0, arg1);
224
+ }
225
+ function __wbg_adapter_71(arg0, arg1, arg2, arg3) {
226
+ wasm.__wbindgen_export_8(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
215
227
  }
216
228
  const __wbindgen_enum_DirEntryType = ["file", "directory"];
217
229
  const __wbindgen_enum_FileSystemHandleKind = ["file", "directory"];
@@ -289,14 +301,14 @@ export class DirEntry {
289
301
  }
290
302
  finally {
291
303
  wasm.__wbindgen_add_to_stack_pointer(16);
292
- wasm.__wbindgen_export_4(deferred1_0, deferred1_1, 1);
304
+ wasm.__wbindgen_export_1(deferred1_0, deferred1_1, 1);
293
305
  }
294
306
  }
295
307
  /**
296
308
  * @param {string} arg0
297
309
  */
298
310
  set name(arg0) {
299
- const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
311
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
300
312
  const len0 = WASM_VECTOR_LEN;
301
313
  wasm.__wbg_set_direntry_name(this.__wbg_ptr, ptr0, len0);
302
314
  }
@@ -332,7 +344,7 @@ export class Project {
332
344
  * @param {string} cwd
333
345
  */
334
346
  constructor(cwd) {
335
- const ptr0 = passStringToWasm0(cwd, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
347
+ const ptr0 = passStringToWasm0(cwd, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
336
348
  const len0 = WASM_VECTOR_LEN;
337
349
  const ret = wasm.project_new(ptr0, len0);
338
350
  this.__wbg_ptr = ret >>> 0;
@@ -356,7 +368,7 @@ export class Project {
356
368
  }
357
369
  finally {
358
370
  wasm.__wbindgen_add_to_stack_pointer(16);
359
- wasm.__wbindgen_export_4(deferred1_0, deferred1_1, 1);
371
+ wasm.__wbindgen_export_1(deferred1_0, deferred1_1, 1);
360
372
  }
361
373
  }
362
374
  /**
@@ -364,7 +376,7 @@ export class Project {
364
376
  * @returns {Promise<void>}
365
377
  */
366
378
  install(package_lock) {
367
- const ptr0 = passStringToWasm0(package_lock, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
379
+ const ptr0 = passStringToWasm0(package_lock, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
368
380
  const len0 = WASM_VECTOR_LEN;
369
381
  const ret = wasm.project_install(this.__wbg_ptr, ptr0, len0);
370
382
  return takeObject(ret);
@@ -376,14 +388,37 @@ export class Project {
376
388
  const ret = wasm.project_build(this.__wbg_ptr);
377
389
  return takeObject(ret);
378
390
  }
391
+ /**
392
+ * @param {string} path
393
+ * @returns {Promise<Uint8Array>}
394
+ */
395
+ read(path) {
396
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
397
+ const len0 = WASM_VECTOR_LEN;
398
+ const ret = wasm.project_read(this.__wbg_ptr, ptr0, len0);
399
+ return takeObject(ret);
400
+ }
379
401
  /**
380
402
  * @param {string} path
381
403
  * @returns {Promise<string>}
382
404
  */
383
- readFile(path) {
384
- const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
405
+ readToString(path) {
406
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
407
+ const len0 = WASM_VECTOR_LEN;
408
+ const ret = wasm.project_readToString(this.__wbg_ptr, ptr0, len0);
409
+ return takeObject(ret);
410
+ }
411
+ /**
412
+ * @param {string} path
413
+ * @param {Uint8Array} content
414
+ * @returns {Promise<void>}
415
+ */
416
+ write(path, content) {
417
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
385
418
  const len0 = WASM_VECTOR_LEN;
386
- const ret = wasm.project_readFile(this.__wbg_ptr, ptr0, len0);
419
+ const ptr1 = passArray8ToWasm0(content, wasm.__wbindgen_export_2);
420
+ const len1 = WASM_VECTOR_LEN;
421
+ const ret = wasm.project_write(this.__wbg_ptr, ptr0, len0, ptr1, len1);
387
422
  return takeObject(ret);
388
423
  }
389
424
  /**
@@ -391,12 +426,12 @@ export class Project {
391
426
  * @param {string} content
392
427
  * @returns {Promise<void>}
393
428
  */
394
- writeFile(path, content) {
395
- const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
429
+ writeString(path, content) {
430
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
396
431
  const len0 = WASM_VECTOR_LEN;
397
- const ptr1 = passStringToWasm0(content, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
432
+ const ptr1 = passStringToWasm0(content, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
398
433
  const len1 = WASM_VECTOR_LEN;
399
- const ret = wasm.project_writeFile(this.__wbg_ptr, ptr0, len0, ptr1, len1);
434
+ const ret = wasm.project_writeString(this.__wbg_ptr, ptr0, len0, ptr1, len1);
400
435
  return takeObject(ret);
401
436
  }
402
437
  /**
@@ -404,7 +439,7 @@ export class Project {
404
439
  * @returns {Promise<DirEntry[]>}
405
440
  */
406
441
  readDir(path) {
407
- const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
442
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
408
443
  const len0 = WASM_VECTOR_LEN;
409
444
  const ret = wasm.project_readDir(this.__wbg_ptr, ptr0, len0);
410
445
  return takeObject(ret);
@@ -414,7 +449,7 @@ export class Project {
414
449
  * @returns {Promise<void>}
415
450
  */
416
451
  createDir(path) {
417
- const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
452
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
418
453
  const len0 = WASM_VECTOR_LEN;
419
454
  const ret = wasm.project_createDir(this.__wbg_ptr, ptr0, len0);
420
455
  return takeObject(ret);
@@ -424,7 +459,7 @@ export class Project {
424
459
  * @returns {Promise<void>}
425
460
  */
426
461
  createDirAll(path) {
427
- const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
462
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
428
463
  const len0 = WASM_VECTOR_LEN;
429
464
  const ret = wasm.project_createDirAll(this.__wbg_ptr, ptr0, len0);
430
465
  return takeObject(ret);
@@ -435,9 +470,9 @@ export class Project {
435
470
  * @returns {Promise<void>}
436
471
  */
437
472
  copyFile(src, dst) {
438
- const ptr0 = passStringToWasm0(src, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
473
+ const ptr0 = passStringToWasm0(src, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
439
474
  const len0 = WASM_VECTOR_LEN;
440
- const ptr1 = passStringToWasm0(dst, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
475
+ const ptr1 = passStringToWasm0(dst, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
441
476
  const len1 = WASM_VECTOR_LEN;
442
477
  const ret = wasm.project_copyFile(this.__wbg_ptr, ptr0, len0, ptr1, len1);
443
478
  return takeObject(ret);
@@ -518,6 +553,12 @@ function __wbg_get_imports() {
518
553
  const ret = CreateSyncAccessHandleOptions.__wrap(arg0);
519
554
  return addHeapObject(ret);
520
555
  };
556
+ imports.wbg.__wbg_debug_3cb59063b29f58c1 = function (arg0) {
557
+ console.debug(getObject(arg0));
558
+ };
559
+ imports.wbg.__wbg_debug_e17b51583ca6a632 = function (arg0, arg1, arg2, arg3) {
560
+ console.debug(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
561
+ };
521
562
  imports.wbg.__wbg_direntry_new = function (arg0) {
522
563
  const ret = DirEntry.__wrap(arg0);
523
564
  return addHeapObject(ret);
@@ -530,6 +571,24 @@ function __wbg_get_imports() {
530
571
  const ret = getObject(arg0).entries();
531
572
  return addHeapObject(ret);
532
573
  };
574
+ imports.wbg.__wbg_error_524f506f44df1645 = function (arg0) {
575
+ console.error(getObject(arg0));
576
+ };
577
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function (arg0, arg1) {
578
+ let deferred0_0;
579
+ let deferred0_1;
580
+ try {
581
+ deferred0_0 = arg0;
582
+ deferred0_1 = arg1;
583
+ console.error(getStringFromWasm0(arg0, arg1));
584
+ }
585
+ finally {
586
+ wasm.__wbindgen_export_1(deferred0_0, deferred0_1, 1);
587
+ }
588
+ };
589
+ imports.wbg.__wbg_error_80de38b3f7cc3c3c = function (arg0, arg1, arg2, arg3) {
590
+ console.error(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
591
+ };
533
592
  imports.wbg.__wbg_fetch_11bff8299d0ecd2b = function (arg0) {
534
593
  const ret = fetch(getObject(arg0));
535
594
  return addHeapObject(ret);
@@ -554,6 +613,11 @@ function __wbg_get_imports() {
554
613
  const ret = getObject(arg0).getFileHandle(getStringFromWasm0(arg1, arg2), getObject(arg3));
555
614
  return addHeapObject(ret);
556
615
  };
616
+ imports.wbg.__wbg_getRandomValues_21a0191e74d0e1d3 = function () {
617
+ return handleError(function (arg0, arg1) {
618
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
619
+ }, arguments);
620
+ };
557
621
  imports.wbg.__wbg_getSize_e7dbd5ffa0b43df1 = function () {
558
622
  return handleError(function (arg0) {
559
623
  const ret = getObject(arg0).getSize();
@@ -580,6 +644,12 @@ function __wbg_get_imports() {
580
644
  const ret = getObject(arg0).headers;
581
645
  return addHeapObject(ret);
582
646
  };
647
+ imports.wbg.__wbg_info_033d8b8a0838f1d3 = function (arg0, arg1, arg2, arg3) {
648
+ console.info(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
649
+ };
650
+ imports.wbg.__wbg_info_3daf2e093e091b66 = function (arg0) {
651
+ console.info(getObject(arg0));
652
+ };
583
653
  imports.wbg.__wbg_instanceof_DomException_ed1ccb7aaf39034c = function (arg0) {
584
654
  let result;
585
655
  try {
@@ -627,7 +697,7 @@ function __wbg_get_imports() {
627
697
  };
628
698
  imports.wbg.__wbg_name_f2d27098bfd843e7 = function (arg0, arg1) {
629
699
  const ret = getObject(arg1).name;
630
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
700
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
631
701
  const len1 = WASM_VECTOR_LEN;
632
702
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
633
703
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
@@ -649,7 +719,7 @@ function __wbg_get_imports() {
649
719
  const a = state0.a;
650
720
  state0.a = 0;
651
721
  try {
652
- return __wbg_adapter_66(a, state0.b, arg0, arg1);
722
+ return __wbg_adapter_71(a, state0.b, arg0, arg1);
653
723
  }
654
724
  finally {
655
725
  state0.a = a;
@@ -666,6 +736,10 @@ function __wbg_get_imports() {
666
736
  const ret = new Object();
667
737
  return addHeapObject(ret);
668
738
  };
739
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function () {
740
+ const ret = new Error();
741
+ return addHeapObject(ret);
742
+ };
669
743
  imports.wbg.__wbg_new_a12002a7f91c75be = function (arg0) {
670
744
  const ret = new Uint8Array(getObject(arg0));
671
745
  return addHeapObject(ret);
@@ -706,6 +780,14 @@ function __wbg_get_imports() {
706
780
  return addHeapObject(ret);
707
781
  }, arguments);
708
782
  };
783
+ imports.wbg.__wbg_now_e1163c67115ff874 = function (arg0) {
784
+ const ret = getObject(arg0).now();
785
+ return ret;
786
+ };
787
+ imports.wbg.__wbg_performance_7fe0928f3ab059e5 = function (arg0) {
788
+ const ret = getObject(arg0).performance;
789
+ return addHeapObject(ret);
790
+ };
709
791
  imports.wbg.__wbg_queueMicrotask_97d92b4fcc8a61c5 = function (arg0) {
710
792
  queueMicrotask(getObject(arg0));
711
793
  };
@@ -719,10 +801,20 @@ function __wbg_get_imports() {
719
801
  return ret;
720
802
  }, arguments);
721
803
  };
804
+ imports.wbg.__wbg_removeEntry_a424e90dff229b19 = function (arg0, arg1, arg2, arg3) {
805
+ const ret = getObject(arg0).removeEntry(getStringFromWasm0(arg1, arg2), getObject(arg3));
806
+ return addHeapObject(ret);
807
+ };
722
808
  imports.wbg.__wbg_resolve_4851785c9c5f573d = function (arg0) {
723
809
  const ret = Promise.resolve(getObject(arg0));
724
810
  return addHeapObject(ret);
725
811
  };
812
+ imports.wbg.__wbg_setTimeout_42370cb3051b8c2c = function () {
813
+ return handleError(function (arg0, arg1, arg2) {
814
+ const ret = getObject(arg0).setTimeout(getObject(arg1), arg2);
815
+ return addHeapObject(ret);
816
+ }, arguments);
817
+ };
726
818
  imports.wbg.__wbg_setTimeout_73ce8df12de4f2f2 = function (arg0, arg1) {
727
819
  const ret = setTimeout(getObject(arg0), arg1);
728
820
  return addHeapObject(ret);
@@ -754,6 +846,9 @@ function __wbg_get_imports() {
754
846
  imports.wbg.__wbg_setmode_5dc300b865044b65 = function (arg0, arg1) {
755
847
  getObject(arg0).mode = __wbindgen_enum_RequestMode[arg1];
756
848
  };
849
+ imports.wbg.__wbg_setrecursive_536113a081d6177a = function (arg0, arg1) {
850
+ getObject(arg0).recursive = arg1 !== 0;
851
+ };
757
852
  imports.wbg.__wbg_setsignal_75b21ef3a81de905 = function (arg0, arg1) {
758
853
  getObject(arg0).signal = getObject(arg1);
759
854
  };
@@ -761,6 +856,13 @@ function __wbg_get_imports() {
761
856
  const ret = getObject(arg0).signal;
762
857
  return addHeapObject(ret);
763
858
  };
859
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function (arg0, arg1) {
860
+ const ret = getObject(arg1).stack;
861
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
862
+ const len1 = WASM_VECTOR_LEN;
863
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
864
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
865
+ };
764
866
  imports.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function () {
765
867
  const ret = typeof global === 'undefined' ? null : global;
766
868
  return isLikeNone(ret) ? 0 : addHeapObject(ret);
@@ -810,7 +912,7 @@ function __wbg_get_imports() {
810
912
  };
811
913
  imports.wbg.__wbg_url_ae10c34ca209681d = function (arg0, arg1) {
812
914
  const ret = getObject(arg1).url;
813
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
915
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
814
916
  const len1 = WASM_VECTOR_LEN;
815
917
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
816
918
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
@@ -819,6 +921,12 @@ function __wbg_get_imports() {
819
921
  const ret = getObject(arg0).value;
820
922
  return addHeapObject(ret);
821
923
  };
924
+ imports.wbg.__wbg_warn_4ca3906c248c47c4 = function (arg0) {
925
+ console.warn(getObject(arg0));
926
+ };
927
+ imports.wbg.__wbg_warn_aaf1f4664a035bd6 = function (arg0, arg1, arg2, arg3) {
928
+ console.warn(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
929
+ };
822
930
  imports.wbg.__wbg_write_530d3c84df874f53 = function () {
823
931
  return handleError(function (arg0, arg1, arg2, arg3) {
824
932
  const ret = getObject(arg0).write(getArrayU8FromWasm0(arg1, arg2), getObject(arg3));
@@ -841,17 +949,21 @@ function __wbg_get_imports() {
841
949
  const ret = false;
842
950
  return ret;
843
951
  };
844
- imports.wbg.__wbindgen_closure_wrapper1053 = function (arg0, arg1, arg2) {
845
- const ret = makeMutClosure(arg0, arg1, 172, __wbg_adapter_28);
952
+ imports.wbg.__wbindgen_closure_wrapper220138 = function (arg0, arg1, arg2) {
953
+ const ret = makeMutClosure(arg0, arg1, 148252, __wbg_adapter_33);
846
954
  return addHeapObject(ret);
847
955
  };
848
- imports.wbg.__wbindgen_closure_wrapper1670 = function (arg0, arg1, arg2) {
849
- const ret = makeMutClosure(arg0, arg1, 443, __wbg_adapter_31);
956
+ imports.wbg.__wbindgen_closure_wrapper220295 = function (arg0, arg1, arg2) {
957
+ const ret = makeMutClosure(arg0, arg1, 148274, __wbg_adapter_36);
958
+ return addHeapObject(ret);
959
+ };
960
+ imports.wbg.__wbindgen_closure_wrapper33472 = function (arg0, arg1, arg2) {
961
+ const ret = makeMutClosure(arg0, arg1, 19113, __wbg_adapter_30);
850
962
  return addHeapObject(ret);
851
963
  };
852
964
  imports.wbg.__wbindgen_debug_string = function (arg0, arg1) {
853
965
  const ret = debugString(getObject(arg1));
854
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
966
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
855
967
  const len1 = WASM_VECTOR_LEN;
856
968
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
857
969
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
@@ -883,7 +995,7 @@ function __wbg_get_imports() {
883
995
  imports.wbg.__wbindgen_string_get = function (arg0, arg1) {
884
996
  const obj = getObject(arg1);
885
997
  const ret = typeof (obj) === 'string' ? obj : undefined;
886
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
998
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_2, wasm.__wbindgen_export_3);
887
999
  var len1 = WASM_VECTOR_LEN;
888
1000
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
889
1001
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
@@ -895,6 +1007,12 @@ function __wbg_get_imports() {
895
1007
  imports.wbg.__wbindgen_throw = function (arg0, arg1) {
896
1008
  throw new Error(getStringFromWasm0(arg0, arg1));
897
1009
  };
1010
+ imports.wbg.__wbindgen_uint8_array_new = function (arg0, arg1) {
1011
+ var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
1012
+ wasm.__wbindgen_export_1(arg0, arg1 * 1, 1);
1013
+ const ret = v0;
1014
+ return addHeapObject(ret);
1015
+ };
898
1016
  return imports;
899
1017
  }
900
1018
  function __wbg_init_memory(imports, memory) {
@@ -904,6 +1022,7 @@ function __wbg_finalize_init(instance, module) {
904
1022
  __wbg_init.__wbindgen_wasm_module = module;
905
1023
  cachedDataViewMemory0 = null;
906
1024
  cachedUint8ArrayMemory0 = null;
1025
+ wasm.__wbindgen_start();
907
1026
  return wasm;
908
1027
  }
909
1028
  function initSync(module) {
Binary file
package/esm/worker.js CHANGED
@@ -1,35 +1,71 @@
1
1
  import * as comlink from "comlink";
2
2
  import { HandShake } from "./message";
3
3
  import initWasm, { Project as ProjectInternal } from "./utoo";
4
+ const WasmInit = initWasm();
4
5
  const projectEndpoint = {
5
6
  projectInternal: undefined,
6
7
  async mount(cwd) {
7
- await initWasm();
8
+ await WasmInit;
8
9
  this.projectInternal = new ProjectInternal(cwd);
10
+ return;
9
11
  },
10
12
  async install(packageLock) {
13
+ await WasmInit;
11
14
  await this.projectInternal.install(packageLock);
15
+ return;
12
16
  },
13
17
  async build() {
14
- await this.projectInternal.build();
18
+ await WasmInit;
19
+ return await this.projectInternal.build();
15
20
  },
16
- async readFile(path) {
17
- return await this.projectInternal.readFile(path);
21
+ async readFile(path, encoding) {
22
+ await WasmInit;
23
+ let ret;
24
+ if (encoding === "utf8") {
25
+ ret = await this.projectInternal.readToString(path);
26
+ }
27
+ else {
28
+ ret = await this.projectInternal.read(path);
29
+ }
30
+ return ret;
18
31
  },
19
- async writeFile(path, content) {
20
- return await this.projectInternal.writeFile(path, content);
32
+ async writeFile(path, content, _encoding) {
33
+ await WasmInit;
34
+ if (typeof content === "string") {
35
+ return await this.projectInternal.writeString(path, content);
36
+ }
37
+ else {
38
+ return await this.projectInternal.write(path, content);
39
+ }
21
40
  },
22
41
  async copyFile(src, dst) {
42
+ await WasmInit;
23
43
  return await this.projectInternal.copyFile(src, dst);
24
44
  },
25
- async readDir(path) {
26
- return (await this.projectInternal.readDir(path)).map((e) => e.toJSON());
45
+ async readdir(path, options) {
46
+ await WasmInit;
47
+ const dirEntries = (options === null || options === void 0 ? void 0 : options.recursive)
48
+ ? await this.projectInternal.readDir(path)
49
+ : // TODO: support recursive readDirAll
50
+ await this.projectInternal.readDir(path);
51
+ const rawDirents = dirEntries.map((e) => {
52
+ const dir = e.toJSON();
53
+ return {
54
+ name: dir.name,
55
+ type: dir.type,
56
+ };
57
+ });
58
+ // WARN: This is a hack, functions can not be structurally cloned
59
+ return rawDirents;
27
60
  },
28
- async createDir(path) {
29
- return await this.projectInternal.createDir(path);
30
- },
31
- async createDirAll(path) {
32
- return await this.projectInternal.createDirAll(path);
61
+ async mkdir(path, options) {
62
+ await WasmInit;
63
+ if (options === null || options === void 0 ? void 0 : options.recursive) {
64
+ return await this.projectInternal.createDirAll(path);
65
+ }
66
+ else {
67
+ return await this.projectInternal.createDir(path);
68
+ }
33
69
  },
34
70
  };
35
71
  const ConnectedPorts = new Set();
package/package.json CHANGED
@@ -1,16 +1,21 @@
1
1
  {
2
2
  "name": "@utoo/web",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.1-alpha.8",
4
4
  "module": "esm/index.js",
5
5
  "types": "esm/index.d.ts",
6
6
  "files": [
7
7
  "esm/*"
8
8
  ],
9
9
  "scripts": {
10
- "wasmpack": "wasm-pack build ../../crates/utoo-wasm --out-dir ../../packages/utoo-web/src/utoo --out-name index --no-pack --target web",
10
+ "install-toolchain": "cargo install wasm-bindgen-cli && brew install binaryen",
11
+ "build-wasm": "cargo build -p utoo-wasm --target wasm32-unknown-unknown",
12
+ "build-wasm:pm": "cargo build -p utoo-wasm --target wasm32-unknown-unknown --no-default-features",
13
+ "bindgen-dev": "wasm-bindgen ../../target/wasm32-unknown-unknown/wasm-dev/utoo_wasm.wasm --out-dir src/utoo --out-name index --target web --debug --keep-debug --no-demangle",
14
+ "bindgen-build": "wasm-bindgen ../../target/wasm32-unknown-unknown/wasm-release/utoo_wasm.wasm --out-dir src/utoo --out-name index --target web",
11
15
  "tsx": "rm -rf esm && tsc -p ./tsconfig.json",
12
- "dev": "npm run wasmpack -- --dev && npm run tsx && cp ./src/utoo/*.wasm ./esm/utoo",
13
- "build": "npm run wasmpack -- --release && npm run tsx && cp ./src/utoo/*.wasm ./esm/utoo",
16
+ "dev": "npm run build-wasm -- --profile wasm-dev && npm run bindgen-dev && npm run tsx && cp src/utoo/index_bg.wasm esm/utoo",
17
+ "dev:pm": "npm run build-wasm:pm -- --profile wasm-dev && npm run bindgen-dev && npm run tsx && cp src/utoo/index_bg.wasm esm/utoo",
18
+ "build": "npm run build-wasm -- --profile wasm-release && npm run bindgen-build && npm run tsx && wasm-opt src/utoo/index_bg.wasm -o esm/utoo/index_bg.wasm -O4 --enable-bulk-memory --enable-nontrapping-float-to-int",
14
19
  "prepublishOnly": "npm run build"
15
20
  },
16
21
  "dependencies": {