@utoo/web 1.2.0-rc.1 → 1.2.0-rc.11

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 (58) hide show
  1. package/README.md +55 -0
  2. package/esm/{aa0ad15d2a587c43406f.wasm → 7a09b7ab69b3abceced7.wasm} +0 -0
  3. package/esm/index.d.ts +3 -2
  4. package/esm/index.js +3 -2
  5. package/esm/loaderWorker.js +1 -1
  6. package/esm/loaderWorker.js.LICENSE.txt +0 -21
  7. package/esm/{forkedProject.d.ts → project/ForkedProject.d.ts} +5 -3
  8. package/esm/{forkedProject.js → project/ForkedProject.js} +8 -0
  9. package/esm/{internalProject.d.ts → project/InternalProject.d.ts} +5 -4
  10. package/esm/project/InternalProject.js +134 -0
  11. package/esm/{project.d.ts → project/Project.d.ts} +3 -1
  12. package/esm/{project.js → project/Project.js} +19 -6
  13. package/esm/serviceWorker.js +4 -3
  14. package/esm/{type.d.ts → types.d.ts} +43 -0
  15. package/esm/types.js +56 -0
  16. package/esm/utils/sabcom.d.ts +61 -0
  17. package/esm/utils/sabcom.js +203 -0
  18. package/esm/utoo/index.d.ts +73 -38
  19. package/esm/utoo/index.js +167 -143
  20. package/esm/utoo/index_bg.wasm +0 -0
  21. package/esm/webpackLoaders/{worker/cjs.js → cjs.js} +65 -41
  22. package/esm/webpackLoaders/loaderWorkerPool.d.ts +2 -0
  23. package/esm/webpackLoaders/loaderWorkerPool.js +90 -0
  24. package/esm/webpackLoaders/polyfills/fsPolyfill.d.ts +78 -0
  25. package/esm/webpackLoaders/{worker/polyfills → polyfills}/fsPolyfill.js +154 -191
  26. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.d.ts +26 -0
  27. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.js +112 -0
  28. package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.d.ts +0 -2
  29. package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.js +4 -3
  30. package/esm/webpackLoaders/{worker/type.d.ts → types.d.ts} +1 -0
  31. package/esm/webpackLoaders/{worker/index.js → worker.js} +8 -3
  32. package/esm/worker.js +2 -2
  33. package/package.json +14 -13
  34. package/esm/internalProject.js +0 -110
  35. package/esm/loaderWorkerPool.d.ts +0 -3
  36. package/esm/loaderWorkerPool.js +0 -125
  37. package/esm/sabcom.d.ts +0 -31
  38. package/esm/sabcom.js +0 -71
  39. package/esm/type.js +0 -12
  40. package/esm/webpackLoaders/loaders/less-loader/index.d.ts +0 -3
  41. package/esm/webpackLoaders/loaders/less-loader/index.js +0 -103
  42. package/esm/webpackLoaders/loaders/less-loader/options.json +0 -67
  43. package/esm/webpackLoaders/loaders/less-loader/utils.d.ts +0 -14
  44. package/esm/webpackLoaders/loaders/less-loader/utils.js +0 -217
  45. package/esm/webpackLoaders/worker/polyfills/fastGlobPolyfill.d.ts +0 -2
  46. package/esm/webpackLoaders/worker/polyfills/fastGlobPolyfill.js +0 -48
  47. package/esm/webpackLoaders/worker/polyfills/fsPolyfill.d.ts +0 -124
  48. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.d.ts +0 -9
  49. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.js +0 -9
  50. /package/esm/{installServiceWorker.d.ts → utils/installServiceWorker.d.ts} +0 -0
  51. /package/esm/{installServiceWorker.js → utils/installServiceWorker.js} +0 -0
  52. /package/esm/{message.d.ts → utils/message.d.ts} +0 -0
  53. /package/esm/{message.js → utils/message.js} +0 -0
  54. /package/esm/webpackLoaders/{worker/cjs.d.ts → cjs.d.ts} +0 -0
  55. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.d.ts +0 -0
  56. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.js +0 -0
  57. /package/esm/webpackLoaders/{worker/type.js → types.js} +0 -0
  58. /package/esm/webpackLoaders/{worker/index.d.ts → worker.d.ts} +0 -0
@@ -16,27 +16,6 @@
16
16
  * @license MIT
17
17
  */
18
18
 
19
- /*!
20
- * fill-range <https://github.com/jonschlinkert/fill-range>
21
- *
22
- * Copyright (c) 2014-present, Jon Schlinkert.
23
- * Licensed under the MIT License.
24
- */
25
-
26
- /*!
27
- * is-number <https://github.com/jonschlinkert/is-number>
28
- *
29
- * Copyright (c) 2014-present, Jon Schlinkert.
30
- * Released under the MIT License.
31
- */
32
-
33
- /*!
34
- * to-regex-range <https://github.com/micromatch/to-regex-range>
35
- *
36
- * Copyright (c) 2015-present, Jon Schlinkert.
37
- * Released under the MIT License.
38
- */
39
-
40
19
  /*! https://mths.be/punycode v1.4.1 by @mathias */
41
20
 
42
21
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -1,15 +1,16 @@
1
- import { PackFile, ProjectEndpoint } from "./type";
1
+ import { DepsOptions, PackFile, ProjectEndpoint, Stats } from "../types";
2
2
  export declare class ForkedProject implements ProjectEndpoint {
3
3
  private endpoint;
4
4
  constructor(port: MessagePort);
5
+ deps(options?: DepsOptions): Promise<string>;
5
6
  install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
6
- build(): Promise<import("./type").BuildOutput>;
7
+ build(): Promise<import("..").BuildOutput>;
7
8
  readFile(path: string, encoding?: "utf8"): Promise<any>;
8
9
  writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
9
10
  copyFile(src: string, dst: string): Promise<void>;
10
11
  readdir(path: string, options?: {
11
12
  recursive?: boolean;
12
- }): Promise<import("./type").Dirent[]>;
13
+ }): Promise<import("..").Dirent[]>;
13
14
  mkdir(path: string, options?: {
14
15
  recursive?: boolean;
15
16
  }): Promise<void>;
@@ -19,6 +20,7 @@ export declare class ForkedProject implements ProjectEndpoint {
19
20
  rmdir(path: string, options?: {
20
21
  recursive?: boolean;
21
22
  }): Promise<void>;
23
+ stat(path: string): Promise<Stats>;
22
24
  gzip(files: PackFile[]): Promise<Uint8Array>;
23
25
  sigMd5(content: Uint8Array): Promise<string>;
24
26
  }
@@ -1,9 +1,13 @@
1
1
  import * as comlink from "comlink";
2
+ import { Stats, } from "../types";
2
3
  export class ForkedProject {
3
4
  constructor(port) {
4
5
  var _a;
5
6
  (_a = this.endpoint) !== null && _a !== void 0 ? _a : (this.endpoint = comlink.wrap(port));
6
7
  }
8
+ async deps(options) {
9
+ return await this.endpoint.deps(options);
10
+ }
7
11
  async install(packageLock, maxConcurrentDownloads) {
8
12
  return await this.endpoint.install(packageLock, maxConcurrentDownloads);
9
13
  }
@@ -31,6 +35,10 @@ export class ForkedProject {
31
35
  async rmdir(path, options) {
32
36
  return await this.endpoint.rmdir(path, options);
33
37
  }
38
+ async stat(path) {
39
+ const raw = (await this.endpoint.stat(path));
40
+ return new Stats(raw);
41
+ }
34
42
  async gzip(files) {
35
43
  return await this.endpoint.gzip(files);
36
44
  }
@@ -1,16 +1,17 @@
1
- import { PackFile, ProjectEndpoint, ProjectOptions } from "./type";
2
- import initWasm, { Project as ProjectInternal } from "./utoo";
1
+ import { DepsOptions, PackFile, ProjectEndpoint, ProjectOptions, Stats } from "../types";
2
+ import initWasm from "../utoo";
3
3
  declare class InternalEndpoint implements ProjectEndpoint {
4
- projectInternal?: ProjectInternal;
5
4
  wasmInit?: ReturnType<typeof initWasm>;
6
5
  options?: Omit<ProjectOptions, "workerUrl" | "serviceWorker">;
7
6
  loaderWorkerPoolInitialized: boolean;
8
7
  mount(opt: Omit<ProjectOptions, "workerUrl" | "serviceWorker">): Promise<void>;
8
+ deps(options?: DepsOptions): Promise<string>;
9
9
  install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
10
10
  build(): Promise<any>;
11
11
  readFile(path: string, encoding?: "utf8"): Promise<any>;
12
12
  writeFile(path: string, content: string | Uint8Array, _encoding?: "utf8"): Promise<void>;
13
13
  copyFile(src: string, dst: string): Promise<void>;
14
+ stat(path: string): Promise<Stats>;
14
15
  readdir(path: string, options?: {
15
16
  recursive?: boolean;
16
17
  }): Promise<any>;
@@ -23,7 +24,7 @@ declare class InternalEndpoint implements ProjectEndpoint {
23
24
  rmdir(path: string, options?: {
24
25
  recursive?: boolean;
25
26
  }): Promise<void>;
26
- gzip(files: PackFile[]): Promise<Uint8Array<ArrayBufferLike>>;
27
+ gzip(files: PackFile[]): Promise<Uint8Array<ArrayBuffer>>;
27
28
  sigMd5(content: Uint8Array): Promise<string>;
28
29
  }
29
30
  declare const internalEndpoint: InternalEndpoint;
@@ -0,0 +1,134 @@
1
+ import * as comlink from "comlink";
2
+ import initWasm, { initLogFilter, Project as ProjectInternal, } from "../utoo";
3
+ import { runLoaderWorkerPool } from "../webpackLoaders/loaderWorkerPool";
4
+ class InternalEndpoint {
5
+ constructor() {
6
+ this.loaderWorkerPoolInitialized = false;
7
+ }
8
+ // This should be called only once
9
+ async mount(opt) {
10
+ var _a;
11
+ this.options = opt;
12
+ const { cwd, wasmUrl, threadWorkerUrl, logFilter } = opt;
13
+ (_a = this.wasmInit) !== null && _a !== void 0 ? _a : (this.wasmInit = initWasm(wasmUrl));
14
+ await this.wasmInit;
15
+ // Initialize log filter after wasm init
16
+ const filter = logFilter ||
17
+ "pack_core=info,pack_api=info,utoo_wasm=info,utoo_ruborist=info";
18
+ initLogFilter(filter);
19
+ const absoluteCwd = cwd.startsWith("/") ? cwd : "/" + cwd;
20
+ ProjectInternal.init(threadWorkerUrl || "");
21
+ ProjectInternal.setCwd(absoluteCwd);
22
+ return;
23
+ }
24
+ async deps(options) {
25
+ var _a, _b;
26
+ await this.wasmInit;
27
+ return await ProjectInternal.deps((_a = options === null || options === void 0 ? void 0 : options.registry) !== null && _a !== void 0 ? _a : undefined, (_b = options === null || options === void 0 ? void 0 : options.concurrency) !== null && _b !== void 0 ? _b : undefined);
28
+ }
29
+ async install(packageLock, maxConcurrentDownloads) {
30
+ await this.wasmInit;
31
+ await ProjectInternal.install(packageLock, maxConcurrentDownloads);
32
+ return;
33
+ }
34
+ async build() {
35
+ var _a, _b;
36
+ const binding = await this.wasmInit;
37
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.loaderWorkerUrl) && !this.loaderWorkerPoolInitialized) {
38
+ runLoaderWorkerPool(binding, this.options.cwd, this.options.loaderWorkerUrl, (_b = this.options) === null || _b === void 0 ? void 0 : _b.loadersImportMap);
39
+ this.loaderWorkerPoolInitialized = true;
40
+ }
41
+ return await ProjectInternal.build();
42
+ }
43
+ async readFile(path, encoding) {
44
+ await this.wasmInit;
45
+ let ret;
46
+ if (encoding === "utf8") {
47
+ ret = await ProjectInternal.readToString(path);
48
+ }
49
+ else {
50
+ ret = await ProjectInternal.read(path);
51
+ const copied = ret.slice(0);
52
+ return comlink.transfer(copied, [copied.buffer]);
53
+ }
54
+ return ret;
55
+ }
56
+ async writeFile(path, content, _encoding) {
57
+ await this.wasmInit;
58
+ if (typeof content === "string") {
59
+ return await ProjectInternal.writeString(path, content);
60
+ }
61
+ else {
62
+ return await ProjectInternal.write(path, content);
63
+ }
64
+ }
65
+ async copyFile(src, dst) {
66
+ await this.wasmInit;
67
+ return await ProjectInternal.copyFile(src, dst);
68
+ }
69
+ async stat(path) {
70
+ await this.wasmInit;
71
+ const metadata = await ProjectInternal.metadata(path);
72
+ const json = metadata.toJSON();
73
+ const raw = {
74
+ type: json.type,
75
+ size: Number(json.file_size),
76
+ };
77
+ // WARN: This is a hack, functions can not be structurally cloned
78
+ return raw;
79
+ }
80
+ async readdir(path, options) {
81
+ await this.wasmInit;
82
+ const dirEntries = (options === null || options === void 0 ? void 0 : options.recursive)
83
+ ? await ProjectInternal.readDir(path)
84
+ : // TODO: support recursive readDirAll
85
+ await ProjectInternal.readDir(path);
86
+ const rawDirents = dirEntries.map((e) => {
87
+ const dir = e.toJSON();
88
+ return {
89
+ name: dir.name,
90
+ type: dir.type,
91
+ };
92
+ });
93
+ // WARN: This is a hack, functions can not be structurally cloned
94
+ return rawDirents;
95
+ }
96
+ async mkdir(path, options) {
97
+ await this.wasmInit;
98
+ if (options === null || options === void 0 ? void 0 : options.recursive) {
99
+ return await ProjectInternal.createDirAll(path);
100
+ }
101
+ else {
102
+ return await ProjectInternal.createDir(path);
103
+ }
104
+ }
105
+ async rm(path, options) {
106
+ await this.wasmInit;
107
+ let metadata = (await ProjectInternal.metadata(path)).toJSON();
108
+ switch (metadata.type) {
109
+ case "file":
110
+ return await ProjectInternal.removeFile(path);
111
+ case "directory":
112
+ return await ProjectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
113
+ default:
114
+ // nothing to remove now
115
+ break;
116
+ }
117
+ }
118
+ async rmdir(path, options) {
119
+ await this.wasmInit;
120
+ return await ProjectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
121
+ }
122
+ async gzip(files) {
123
+ await this.wasmInit;
124
+ const ret = await ProjectInternal.gzip(files);
125
+ const copied = ret.slice(0);
126
+ return comlink.transfer(copied, [copied.buffer]);
127
+ }
128
+ async sigMd5(content) {
129
+ await this.wasmInit;
130
+ return await ProjectInternal.sigMd5(content);
131
+ }
132
+ }
133
+ const internalEndpoint = new InternalEndpoint();
134
+ export { internalEndpoint };
@@ -1,4 +1,4 @@
1
- import { BuildOutput, Dirent, PackFile, ProjectEndpoint, ProjectOptions, ServiceWorkerOptions } from "./type";
1
+ import { BuildOutput, DepsOptions, Dirent, PackFile, ProjectEndpoint, ProjectOptions, ServiceWorkerOptions, Stats } from "../types";
2
2
  export declare class Project implements ProjectEndpoint {
3
3
  #private;
4
4
  private options;
@@ -9,6 +9,7 @@ export declare class Project implements ProjectEndpoint {
9
9
  private connectWorker;
10
10
  installServiceWorker(): Promise<void>;
11
11
  mount(): Promise<void>;
12
+ deps(options?: DepsOptions): Promise<string>;
12
13
  install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
13
14
  build(): Promise<BuildOutput>;
14
15
  readFile(path: string, encoding?: "utf8"): Promise<any>;
@@ -26,6 +27,7 @@ export declare class Project implements ProjectEndpoint {
26
27
  rmdir(path: string, options?: {
27
28
  recursive?: boolean;
28
29
  }): Promise<void>;
30
+ stat(path: string): Promise<Stats>;
29
31
  gzip(files: PackFile[]): Promise<Uint8Array>;
30
32
  sigMd5(content: Uint8Array): Promise<string>;
31
33
  static fork(channel: MessageChannel, eventSource?: Client | DedicatedWorkerGlobalScope): ProjectEndpoint;
@@ -12,10 +12,10 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
12
12
  var _Project_mount;
13
13
  import { handleIssues } from "@utoo/pack-shared";
14
14
  import * as comlink from "comlink";
15
- import { ForkedProject } from "./forkedProject";
16
- import { installServiceWorker } from "./installServiceWorker";
17
- import { Fork, HandShake } from "./message";
18
- import { Dirent, } from "./type";
15
+ import { Dirent, Stats, } from "../types";
16
+ import { installServiceWorker } from "../utils/installServiceWorker";
17
+ import { Fork, HandShake } from "../utils/message";
18
+ import { ForkedProject } from "./ForkedProject";
19
19
  let ProjectWorker;
20
20
  const ConnectedPorts = new Set();
21
21
  export class Project {
@@ -65,6 +65,10 @@ export class Project {
65
65
  async mount() {
66
66
  return await __classPrivateFieldGet(this, _Project_mount, "f");
67
67
  }
68
+ async deps(options) {
69
+ await __classPrivateFieldGet(this, _Project_mount, "f");
70
+ return await this.remote.deps(options);
71
+ }
68
72
  async install(packageLock, maxConcurrentDownloads) {
69
73
  await __classPrivateFieldGet(this, _Project_mount, "f");
70
74
  return await this.remote.install(packageLock, maxConcurrentDownloads);
@@ -81,6 +85,9 @@ export class Project {
81
85
  }
82
86
  async writeFile(path, content, encoding) {
83
87
  await __classPrivateFieldGet(this, _Project_mount, "f");
88
+ if (content instanceof Uint8Array) {
89
+ return await this.remote.writeFile(path, comlink.transfer(content, [content.buffer]), encoding);
90
+ }
84
91
  return await this.remote.writeFile(path, content, encoding);
85
92
  }
86
93
  async copyFile(src, dst) {
@@ -104,13 +111,19 @@ export class Project {
104
111
  await __classPrivateFieldGet(this, _Project_mount, "f");
105
112
  return await this.remote.rmdir(path, options);
106
113
  }
114
+ async stat(path) {
115
+ await __classPrivateFieldGet(this, _Project_mount, "f");
116
+ const raw = (await this.remote.stat(path));
117
+ return new Stats(raw);
118
+ }
107
119
  async gzip(files) {
108
120
  await __classPrivateFieldGet(this, _Project_mount, "f");
109
- return await this.remote.gzip(files);
121
+ const buffers = files.map((f) => f.content.buffer);
122
+ return await this.remote.gzip(comlink.transfer(files, buffers));
110
123
  }
111
124
  async sigMd5(content) {
112
125
  await __classPrivateFieldGet(this, _Project_mount, "f");
113
- return await this.remote.sigMd5(content);
126
+ return await this.remote.sigMd5(comlink.transfer(content, [content.buffer]));
114
127
  }
115
128
  static fork(channel, eventSource) {
116
129
  (eventSource || self).postMessage(Fork, {
@@ -1,5 +1,5 @@
1
- import { Project } from ".";
2
- import { ServiceWorkerHandShake } from "./message";
1
+ import { Project } from "./project/Project";
2
+ import { ServiceWorkerHandShake } from "./utils/message";
3
3
  let _resolve;
4
4
  let _promise = new Promise((resolve) => {
5
5
  _resolve = resolve;
@@ -54,12 +54,13 @@ async function readFileFromProject(projectPath) {
54
54
  headers: {
55
55
  "Content-Type": mimeType,
56
56
  ...(mimeType === "text/html"
57
- ? { "Cross-Origin-Embedder-Policy": "require-corp" }
57
+ ? { "Cross-Origin-Embedder-Policy": "credentialless" }
58
58
  : {}),
59
59
  },
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
  }
@@ -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;
@@ -18,7 +55,12 @@ export interface PackFile {
18
55
  path: string;
19
56
  content: Uint8Array;
20
57
  }
58
+ export interface DepsOptions {
59
+ registry?: string | null;
60
+ concurrency?: number | null;
61
+ }
21
62
  export interface ProjectEndpoint {
63
+ deps: (options?: DepsOptions) => Promise<string>;
22
64
  install: (packageLock: string, maxConcurrentDownloads?: number) => Promise<void>;
23
65
  build: () => Promise<BuildOutput>;
24
66
  readFile(path: string): Promise<Uint8Array>;
@@ -37,6 +79,7 @@ export interface ProjectEndpoint {
37
79
  recursive?: boolean;
38
80
  }): Promise<void>;
39
81
  copyFile(src: string, dst: string): Promise<void>;
82
+ stat(path: string): Promise<Stats>;
40
83
  gzip: (files: PackFile[]) => Promise<Uint8Array>;
41
84
  sigMd5: (content: Uint8Array) => Promise<string>;
42
85
  }
package/esm/types.js ADDED
@@ -0,0 +1,56 @@
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
+ }
45
+ export class Dirent {
46
+ constructor(rawDirent) {
47
+ this.rawDirent = rawDirent;
48
+ this.name = this.rawDirent.name;
49
+ }
50
+ isDirectory() {
51
+ return this.rawDirent.type === "directory";
52
+ }
53
+ isFile() {
54
+ return this.rawDirent.type === "file";
55
+ }
56
+ }
@@ -0,0 +1,61 @@
1
+ export declare const SAB_STATE_IDLE = 0;
2
+ export declare const SAB_STATE_REQUEST = 1;
3
+ export declare const SAB_STATE_RESPONSE = 2;
4
+ export declare const SAB_STATE_ERROR = 3;
5
+ export declare const SAB_OP_READ_FILE = 1;
6
+ export declare const SAB_OP_READ_DIR = 2;
7
+ export declare const SAB_OP_WRITE_FILE = 3;
8
+ export declare const SAB_OP_MKDIR = 4;
9
+ export declare const SAB_OP_RM = 5;
10
+ export declare const SAB_OP_RMDIR = 6;
11
+ export declare const SAB_OP_COPY_FILE = 7;
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;
19
+ export declare class SabComHost {
20
+ private sab;
21
+ private int32;
22
+ private uint8;
23
+ private dataView;
24
+ constructor(sab: SharedArrayBuffer);
25
+ readRequest(): {
26
+ op: number;
27
+ data: string;
28
+ };
29
+ writeResponse(data: Uint8Array | string): void;
30
+ writeError(message: string): void;
31
+ writeStat(type: number, size: bigint, atimeMs: number, mtimeMs: number, ctimeMs: number, birthtimeMs: number): void;
32
+ }
33
+ export declare class SabComClient {
34
+ private sab;
35
+ private notifyHost;
36
+ private int32;
37
+ private uint8;
38
+ private dataView;
39
+ constructor(sab: SharedArrayBuffer, notifyHost: () => void);
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
+ };
49
+ }
50
+ export interface SabFileSystem {
51
+ read(path: string): Promise<Uint8Array>;
52
+ readDir(path: string): Promise<any[]>;
53
+ writeString(path: string, content: string): Promise<void>;
54
+ createDirAll(path: string): Promise<void>;
55
+ createDir(path: string): Promise<void>;
56
+ metadata(path: string): Promise<any>;
57
+ removeFile(path: string): Promise<void>;
58
+ removeDir(path: string, recursive: boolean): Promise<void>;
59
+ copyFile(src: string, dst: string): Promise<void>;
60
+ }
61
+ export declare const handleSabRequest: (sabHost: SabComHost, fs: SabFileSystem) => Promise<void>;