@utoo/web 1.2.0-rc.4 → 1.2.0-rc.6

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.
Files changed (38) hide show
  1. package/esm/{3ec3463a197b5c4bac1e.wasm → fe3ccd485f4eb7cd1a1e.wasm} +0 -0
  2. package/esm/forkedProject.d.ts +2 -1
  3. package/esm/forkedProject.js +5 -0
  4. package/esm/internalProject.d.ts +3 -3
  5. package/esm/internalProject.js +33 -20
  6. package/esm/loaderWorker.js +1 -1
  7. package/esm/project.d.ts +2 -1
  8. package/esm/project.js +6 -1
  9. package/esm/sabcom.d.ts +6 -0
  10. package/esm/sabcom.js +53 -5
  11. package/esm/serviceWorker.js +1 -0
  12. package/esm/type.d.ts +38 -0
  13. package/esm/type.js +44 -0
  14. package/esm/utoo/index.d.ts +27 -24
  15. package/esm/utoo/index.js +97 -95
  16. package/esm/utoo/index_bg.wasm +0 -0
  17. package/esm/webpackLoaders/{worker/cjs.js → cjs.js} +71 -64
  18. package/esm/webpackLoaders/loaderWorkerPool.d.ts +2 -0
  19. package/esm/{loaderWorkerPool.js → webpackLoaders/loaderWorkerPool.js} +30 -18
  20. package/esm/webpackLoaders/polyfills/fsPolyfill.d.ts +78 -0
  21. package/esm/webpackLoaders/polyfills/fsPolyfill.js +279 -0
  22. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.d.ts +26 -0
  23. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.js +112 -0
  24. package/esm/webpackLoaders/{worker/type.d.ts → type.d.ts} +1 -0
  25. package/esm/webpackLoaders/{worker/index.js → worker.js} +8 -3
  26. package/package.json +4 -3
  27. package/esm/loaderWorkerPool.d.ts +0 -3
  28. package/esm/webpackLoaders/worker/polyfills/fsPolyfill.d.ts +0 -244
  29. package/esm/webpackLoaders/worker/polyfills/fsPolyfill.js +0 -369
  30. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.d.ts +0 -9
  31. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.js +0 -9
  32. /package/esm/webpackLoaders/{worker/cjs.d.ts → cjs.d.ts} +0 -0
  33. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.d.ts +0 -0
  34. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.js +0 -0
  35. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.d.ts +0 -0
  36. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.js +0 -0
  37. /package/esm/webpackLoaders/{worker/type.js → type.js} +0 -0
  38. /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 {
@@ -104,6 +104,11 @@ export class Project {
104
104
  await __classPrivateFieldGet(this, _Project_mount, "f");
105
105
  return await this.remote.rmdir(path, options);
106
106
  }
107
+ async stat(path) {
108
+ await __classPrivateFieldGet(this, _Project_mount, "f");
109
+ const raw = (await this.remote.stat(path));
110
+ return new Stats(raw);
111
+ }
107
112
  async gzip(files) {
108
113
  await __classPrivateFieldGet(this, _Project_mount, "f");
109
114
  return await this.remote.gzip(files);
package/esm/sabcom.d.ts CHANGED
@@ -10,10 +10,13 @@ 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;
13
15
  export declare class SabComHost {
14
16
  private sab;
15
17
  private int32;
16
18
  private uint8;
19
+ statStruct: any;
17
20
  constructor(sab: SharedArrayBuffer);
18
21
  readRequest(): {
19
22
  op: number;
@@ -21,14 +24,17 @@ export declare class SabComHost {
21
24
  };
22
25
  writeResponse(data: Uint8Array | string): void;
23
26
  writeError(message: string): void;
27
+ writeStatResponse(): void;
24
28
  }
25
29
  export declare class SabComClient {
26
30
  private sab;
27
31
  private notifyHost;
28
32
  private int32;
29
33
  private uint8;
34
+ statStruct: any;
30
35
  constructor(sab: SharedArrayBuffer, notifyHost: () => void);
31
36
  call(op: number, data: string): Uint8Array<ArrayBuffer>;
37
+ callStat(path: string): any;
32
38
  }
33
39
  export interface SabFileSystem {
34
40
  read(path: string): Promise<Uint8Array>;
package/esm/sabcom.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { BigUint64, BufferBackedObject, Float64, Uint8, } from "buffer-backed-object";
1
2
  export const SAB_STATE_IDLE = 0;
2
3
  export const SAB_STATE_REQUEST = 1;
3
4
  export const SAB_STATE_RESPONSE = 2;
@@ -10,6 +11,16 @@ export const SAB_OP_RM = 5;
10
11
  export const SAB_OP_RMDIR = 6;
11
12
  export const SAB_OP_COPY_FILE = 7;
12
13
  export const SAB_OP_STAT = 8;
14
+ export const STAT_TYPE_FILE = 0;
15
+ export const STAT_TYPE_DIR = 1;
16
+ const StatDescriptor = {
17
+ type: Uint8(),
18
+ size: BigUint64(),
19
+ atimeMs: Float64(),
20
+ mtimeMs: Float64(),
21
+ ctimeMs: Float64(),
22
+ birthtimeMs: Float64(),
23
+ };
13
24
  // Layout:
14
25
  // 0: State (Int32)
15
26
  // 1: Op (Int32)
@@ -20,6 +31,9 @@ export class SabComHost {
20
31
  this.sab = sab;
21
32
  this.int32 = new Int32Array(sab);
22
33
  this.uint8 = new Uint8Array(sab);
34
+ this.statStruct = BufferBackedObject(sab, StatDescriptor, {
35
+ byteOffset: 12,
36
+ });
23
37
  }
24
38
  readRequest() {
25
39
  const op = this.int32[1];
@@ -44,6 +58,10 @@ export class SabComHost {
44
58
  Atomics.store(this.int32, 0, SAB_STATE_ERROR);
45
59
  Atomics.notify(this.int32, 0);
46
60
  }
61
+ writeStatResponse() {
62
+ Atomics.store(this.int32, 0, SAB_STATE_RESPONSE);
63
+ Atomics.notify(this.int32, 0);
64
+ }
47
65
  }
48
66
  export class SabComClient {
49
67
  constructor(sab, notifyHost) {
@@ -51,6 +69,9 @@ export class SabComClient {
51
69
  this.notifyHost = notifyHost;
52
70
  this.int32 = new Int32Array(sab);
53
71
  this.uint8 = new Uint8Array(sab);
72
+ this.statStruct = BufferBackedObject(sab, StatDescriptor, {
73
+ byteOffset: 12,
74
+ });
54
75
  }
55
76
  call(op, data) {
56
77
  const encoded = new TextEncoder().encode(data);
@@ -69,6 +90,22 @@ export class SabComClient {
69
90
  const len = this.int32[2];
70
91
  return this.uint8.slice(12, 12 + len);
71
92
  }
93
+ callStat(path) {
94
+ const encoded = new TextEncoder().encode(path);
95
+ this.int32[1] = SAB_OP_STAT;
96
+ this.int32[2] = encoded.length;
97
+ this.uint8.set(encoded, 12);
98
+ Atomics.store(this.int32, 0, SAB_STATE_REQUEST);
99
+ this.notifyHost();
100
+ Atomics.wait(this.int32, 0, SAB_STATE_REQUEST);
101
+ const state = Atomics.load(this.int32, 0);
102
+ if (state === SAB_STATE_ERROR) {
103
+ const len = this.int32[2];
104
+ const msg = new TextDecoder().decode(this.uint8.slice(12, 12 + len));
105
+ throw new Error(msg);
106
+ }
107
+ return this.statStruct;
108
+ }
72
109
  }
73
110
  export const handleSabRequest = async (sabHost, fs) => {
74
111
  const { op, data: path } = sabHost.readRequest();
@@ -82,9 +119,7 @@ export const handleSabRequest = async (sabHost, fs) => {
82
119
  sabHost.writeResponse(JSON.stringify(entries.map((e) => e.toJSON())));
83
120
  }
84
121
  else if (op === SAB_OP_WRITE_FILE) {
85
- const { content, encoding } = JSON.parse(path);
86
- const filePath = content.path;
87
- const fileContent = content.data;
122
+ const { path: filePath, data: fileContent } = JSON.parse(path);
88
123
  // TODO: handle binary content (base64?)
89
124
  await fs.writeString(filePath, fileContent);
90
125
  sabHost.writeResponse("ok");
@@ -103,7 +138,10 @@ export const handleSabRequest = async (sabHost, fs) => {
103
138
  const { path: rmPath, recursive } = JSON.parse(path);
104
139
  // Mimic internalProject.rm logic
105
140
  const metadata = await fs.metadata(rmPath);
106
- const type = metadata.toJSON().type;
141
+ const json = metadata.toJSON
142
+ ? metadata.toJSON()
143
+ : metadata;
144
+ const type = json.type;
107
145
  if (type === "file") {
108
146
  await fs.removeFile(rmPath);
109
147
  }
@@ -124,7 +162,17 @@ export const handleSabRequest = async (sabHost, fs) => {
124
162
  }
125
163
  else if (op === SAB_OP_STAT) {
126
164
  const metadata = await fs.metadata(path);
127
- sabHost.writeResponse(JSON.stringify(metadata));
165
+ const json = metadata.toJSON
166
+ ? metadata.toJSON()
167
+ : metadata;
168
+ sabHost.statStruct.type =
169
+ json.type === "directory" ? STAT_TYPE_DIR : STAT_TYPE_FILE;
170
+ sabHost.statStruct.size = BigInt(json.file_size || 0);
171
+ sabHost.statStruct.atimeMs = Number(json.atimeMs || 0);
172
+ sabHost.statStruct.mtimeMs = Number(json.mtimeMs || 0);
173
+ sabHost.statStruct.ctimeMs = Number(json.ctimeMs || 0);
174
+ sabHost.statStruct.birthtimeMs = Number(json.birthtimeMs || 0);
175
+ sabHost.writeStatResponse();
128
176
  }
129
177
  else {
130
178
  sabHost.writeError("Unknown op");
@@ -60,6 +60,7 @@ async function readFileFromProject(projectPath) {
60
60
  });
61
61
  }
62
62
  catch (e) {
63
+ console.error(`File ${projectPath} not found`);
63
64
  return new Response("Not Found", { status: 404 });
64
65
  }
65
66
  }
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;
@@ -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;