@capsule-run/sdk 0.7.2 → 0.8.1
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/README.md +5 -1
- package/dist/app.d.ts +7 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +7 -0
- package/dist/app.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/polyfills/fs.d.ts +81 -11
- package/dist/polyfills/fs.d.ts.map +1 -1
- package/dist/polyfills/fs.js +290 -11
- package/dist/polyfills/fs.js.map +1 -1
- package/dist/polyfills/process.d.ts +17 -4
- package/dist/polyfills/process.d.ts.map +1 -1
- package/dist/polyfills/process.js +118 -19
- package/dist/polyfills/process.js.map +1 -1
- package/dist/run.d.ts +3 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js.map +1 -1
- package/dist/task.d.ts +11 -2
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +6 -3
- package/dist/task.js.map +1 -1
- package/package.json +4 -10
- package/src/app.ts +8 -0
- package/src/index.ts +1 -2
- package/src/polyfills/fs.ts +317 -12
- package/src/polyfills/process.ts +119 -20
- package/src/run.ts +3 -0
- package/src/task.ts +32 -14
- package/dist/polyfills/buffer.d.ts +0 -8
- package/dist/polyfills/buffer.d.ts.map +0 -1
- package/dist/polyfills/buffer.js +0 -9
- package/dist/polyfills/buffer.js.map +0 -1
- package/dist/polyfills/events.d.ts +0 -8
- package/dist/polyfills/events.d.ts.map +0 -1
- package/dist/polyfills/events.js +0 -9
- package/dist/polyfills/events.js.map +0 -1
- package/dist/polyfills/path.d.ts +0 -8
- package/dist/polyfills/path.d.ts.map +0 -1
- package/dist/polyfills/path.js +0 -8
- package/dist/polyfills/path.js.map +0 -1
- package/dist/polyfills/stream-web.d.ts +0 -74
- package/dist/polyfills/stream-web.d.ts.map +0 -1
- package/dist/polyfills/stream-web.js +0 -23
- package/dist/polyfills/stream-web.js.map +0 -1
- package/dist/polyfills/stream.d.ts +0 -16
- package/dist/polyfills/stream.d.ts.map +0 -1
- package/dist/polyfills/stream.js +0 -16
- package/dist/polyfills/stream.js.map +0 -1
- package/dist/polyfills/url.d.ts +0 -47
- package/dist/polyfills/url.d.ts.map +0 -1
- package/dist/polyfills/url.js +0 -68
- package/dist/polyfills/url.js.map +0 -1
- package/src/polyfills/buffer.ts +0 -11
- package/src/polyfills/events.ts +0 -11
- package/src/polyfills/path.ts +0 -21
- package/src/polyfills/stream-web.ts +0 -24
- package/src/polyfills/stream.ts +0 -28
- package/src/polyfills/url.ts +0 -73
package/README.md
CHANGED
|
@@ -147,7 +147,9 @@ Every task returns a structured JSON envelope containing both the result and exe
|
|
|
147
147
|
"task_name": "data_processor",
|
|
148
148
|
"duration_ms": 1523,
|
|
149
149
|
"retries": 0,
|
|
150
|
-
"fuel_consumed": 45000
|
|
150
|
+
"fuel_consumed": 45000,
|
|
151
|
+
"ram_used": 1200000,
|
|
152
|
+
"host_requests": [{...}]
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
```
|
|
@@ -161,6 +163,8 @@ Every task returns a structured JSON envelope containing both the result and exe
|
|
|
161
163
|
- `duration_ms` — Execution time in milliseconds
|
|
162
164
|
- `retries` — Number of retry attempts that occurred
|
|
163
165
|
- `fuel_consumed` — CPU resources used (see [Compute Levels](#compute-levels))
|
|
166
|
+
- `ram_used` — Peak memory used in bytes
|
|
167
|
+
- `host_requests` — List of host requests made by the task
|
|
164
168
|
|
|
165
169
|
## Documentation
|
|
166
170
|
|
package/dist/app.d.ts
CHANGED
|
@@ -45,4 +45,11 @@ export declare class TaskRunner {
|
|
|
45
45
|
run(argsJson: string): Promise<string>;
|
|
46
46
|
}
|
|
47
47
|
export declare const exports: TaskRunner;
|
|
48
|
+
/**
|
|
49
|
+
* Implementation of wasi:http/incoming-handler@0.2.0.
|
|
50
|
+
* Required for some edge use cases.
|
|
51
|
+
*/
|
|
52
|
+
export declare const incomingHandler: {
|
|
53
|
+
handle(_req: unknown, _responseOut: unknown): void;
|
|
54
|
+
};
|
|
48
55
|
//# sourceMappingURL=app.d.ts.map
|
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG;IACzD,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAID;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC5D,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,UAAU,GACjB,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,GAAG,SAAS,CAE3E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAElE;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,EAAE,CAEvC;AAQD;;;;;GAKG;AACH,qBAAa,UAAU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C,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAuC7C;AAED,eAAO,MAAM,OAAO,YAAmB,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,eAAe;iBACb,OAAO,gBAAgB,OAAO,GAAG,IAAI;CACnD,CAAC"}
|
package/dist/app.js
CHANGED
|
@@ -72,4 +72,11 @@ export class TaskRunner {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
export const exports = new TaskRunner();
|
|
75
|
+
/**
|
|
76
|
+
* Implementation of wasi:http/incoming-handler@0.2.0.
|
|
77
|
+
* Required for some edge use cases.
|
|
78
|
+
*/
|
|
79
|
+
export const incomingHandler = {
|
|
80
|
+
handle(_req, _responseOut) { },
|
|
81
|
+
};
|
|
75
82
|
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;GAEG;AAkBH,MAAM,KAAK,GAA+B,IAAI,GAAG,EAAE,CAAC;AAEpD;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,IAAO,EACP,MAAkB;IAElB,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AAClC,CAAC;AAQD;;;;;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,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;aACpD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,UAAU,EAAE,CAAC;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,MAAM,CAAC,IAAa,EAAE,YAAqB,IAAS,CAAC;CACtD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -15,9 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export { task, type TaskOptions } from "./task.js";
|
|
17
17
|
export { TaskRunner, exports, type TaskConfig } from "./app.js";
|
|
18
|
-
export { default as fs } from "./polyfills/fs.js";
|
|
18
|
+
export { default as fs, promises as fsPromises } from "./polyfills/fs.js";
|
|
19
19
|
export { isWasmMode } from "./hostApi.js";
|
|
20
|
-
export { default as path } from "./polyfills/path.js";
|
|
21
20
|
export { default as os } from "./polyfills/os.js";
|
|
22
21
|
export { default as process } from "./polyfills/process.js";
|
|
23
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,9 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export { task } from "./task.js";
|
|
17
17
|
export { TaskRunner, exports } from "./app.js";
|
|
18
|
-
export { default as fs } from "./polyfills/fs.js";
|
|
18
|
+
export { default as fs, promises as fsPromises } from "./polyfills/fs.js";
|
|
19
19
|
export { isWasmMode } from "./hostApi.js";
|
|
20
|
-
export { default as path } from "./polyfills/path.js";
|
|
21
20
|
export { default as os } from "./polyfills/os.js";
|
|
22
21
|
export { default as process } from "./polyfills/process.js";
|
|
23
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAoB,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAmB,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAoB,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAmB,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/polyfills/fs.d.ts
CHANGED
|
@@ -46,9 +46,72 @@ export declare function writeFile(path: string, data: string | Uint8Array, optio
|
|
|
46
46
|
*/
|
|
47
47
|
export declare function readdir(path: string, optionsOrCallback: any | ((err: Error | null, files?: string[]) => void), callback?: (err: Error | null, files?: string[]) => void): void;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Read file contents synchronously.
|
|
50
50
|
*/
|
|
51
|
-
export declare function
|
|
51
|
+
export declare function readFileSync(path: string, options?: ReadFileOptions | Encoding): string | Uint8Array;
|
|
52
|
+
/**
|
|
53
|
+
* Write data to a file synchronously.
|
|
54
|
+
*/
|
|
55
|
+
export declare function writeFileSync(path: string, data: string | Uint8Array, _options?: WriteFileOptions | Encoding): void;
|
|
56
|
+
/**
|
|
57
|
+
* Append data to a file synchronously, creating it if it doesn't exist.
|
|
58
|
+
*/
|
|
59
|
+
export declare function appendFileSync(path: string, data: string | Uint8Array, _options?: WriteFileOptions | Encoding): void;
|
|
60
|
+
/**
|
|
61
|
+
* Read directory contents synchronously.
|
|
62
|
+
*/
|
|
63
|
+
export declare function readdirSync(path: string, _options?: any): string[];
|
|
64
|
+
export interface StatResult {
|
|
65
|
+
isFile: () => boolean;
|
|
66
|
+
isDirectory: () => boolean;
|
|
67
|
+
isSymbolicLink: () => boolean;
|
|
68
|
+
size: number;
|
|
69
|
+
mtimeMs: number;
|
|
70
|
+
atimeMs: number;
|
|
71
|
+
ctimeMs: number;
|
|
72
|
+
mode: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get file stats synchronously.
|
|
76
|
+
*/
|
|
77
|
+
export declare function statSync(path: string): StatResult;
|
|
78
|
+
/**
|
|
79
|
+
* Get file stats synchronously (no symlink follow — same as stat in WASI 0.2).
|
|
80
|
+
*/
|
|
81
|
+
export declare function lstatSync(path: string): StatResult;
|
|
82
|
+
/**
|
|
83
|
+
* Create a directory synchronously.
|
|
84
|
+
*/
|
|
85
|
+
export declare function mkdirSync(path: string, options?: MkdirOptions): void;
|
|
86
|
+
/**
|
|
87
|
+
* Remove a directory synchronously.
|
|
88
|
+
*/
|
|
89
|
+
export declare function rmdirSync(path: string, _options?: RmdirOptions): void;
|
|
90
|
+
/**
|
|
91
|
+
* Remove a file or directory synchronously.
|
|
92
|
+
*/
|
|
93
|
+
export declare function rmSync(path: string, options?: RmOptions): void;
|
|
94
|
+
/**
|
|
95
|
+
* Remove a file synchronously.
|
|
96
|
+
*/
|
|
97
|
+
export declare function unlinkSync(path: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Copy a file synchronously.
|
|
100
|
+
*/
|
|
101
|
+
export declare function copyFileSync(src: string, dest: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* Rename a file or directory synchronously.
|
|
104
|
+
*/
|
|
105
|
+
export declare function renameSync(oldPath: string, newPath: string): void;
|
|
106
|
+
/**
|
|
107
|
+
* Check file accessibility synchronously.
|
|
108
|
+
* Throws if the path does not exist.
|
|
109
|
+
*/
|
|
110
|
+
export declare function accessSync(path: string, _mode?: number): void;
|
|
111
|
+
/**
|
|
112
|
+
* Check if a path exists synchronously.
|
|
113
|
+
*/
|
|
114
|
+
export declare function existsSync(path: string): boolean;
|
|
52
115
|
/**
|
|
53
116
|
* Delete a file.
|
|
54
117
|
*/
|
|
@@ -95,10 +158,7 @@ export declare const promises: {
|
|
|
95
158
|
readdir(path: string): Promise<string[]>;
|
|
96
159
|
access(path: string): Promise<void>;
|
|
97
160
|
unlink(path: string): Promise<void>;
|
|
98
|
-
stat(path: string): Promise<
|
|
99
|
-
isFile: () => boolean;
|
|
100
|
-
isDirectory: () => boolean;
|
|
101
|
-
}>;
|
|
161
|
+
stat(path: string): Promise<StatResult>;
|
|
102
162
|
rmdir(path: string, options?: RmdirOptions): Promise<void>;
|
|
103
163
|
rm(path: string, options?: RmOptions): Promise<void>;
|
|
104
164
|
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
@@ -109,23 +169,33 @@ declare const fs: {
|
|
|
109
169
|
readFile: typeof readFile;
|
|
110
170
|
writeFile: typeof writeFile;
|
|
111
171
|
readdir: typeof readdir;
|
|
112
|
-
existsSync: typeof existsSync;
|
|
113
172
|
unlink: typeof unlink;
|
|
114
173
|
rmdir: typeof rmdir;
|
|
115
174
|
rm: typeof rm;
|
|
116
175
|
mkdir: typeof mkdir;
|
|
117
176
|
copyFile: typeof copyFile;
|
|
118
177
|
cp: typeof cp;
|
|
178
|
+
readFileSync: typeof readFileSync;
|
|
179
|
+
writeFileSync: typeof writeFileSync;
|
|
180
|
+
appendFileSync: typeof appendFileSync;
|
|
181
|
+
readdirSync: typeof readdirSync;
|
|
182
|
+
statSync: typeof statSync;
|
|
183
|
+
lstatSync: typeof lstatSync;
|
|
184
|
+
mkdirSync: typeof mkdirSync;
|
|
185
|
+
rmdirSync: typeof rmdirSync;
|
|
186
|
+
rmSync: typeof rmSync;
|
|
187
|
+
unlinkSync: typeof unlinkSync;
|
|
188
|
+
copyFileSync: typeof copyFileSync;
|
|
189
|
+
renameSync: typeof renameSync;
|
|
190
|
+
accessSync: typeof accessSync;
|
|
191
|
+
existsSync: typeof existsSync;
|
|
119
192
|
promises: {
|
|
120
193
|
readFile(path: string, options?: ReadFileOptions | Encoding): Promise<string | Uint8Array>;
|
|
121
194
|
writeFile(path: string, data: string | Uint8Array): Promise<void>;
|
|
122
195
|
readdir(path: string): Promise<string[]>;
|
|
123
196
|
access(path: string): Promise<void>;
|
|
124
197
|
unlink(path: string): Promise<void>;
|
|
125
|
-
stat(path: string): Promise<
|
|
126
|
-
isFile: () => boolean;
|
|
127
|
-
isDirectory: () => boolean;
|
|
128
|
-
}>;
|
|
198
|
+
stat(path: string): Promise<StatResult>;
|
|
129
199
|
rmdir(path: string, options?: RmdirOptions): Promise<void>;
|
|
130
200
|
rm(path: string, options?: RmOptions): Promise<void>;
|
|
131
201
|
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/polyfills/fs.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/polyfills/fs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuHH;;GAEG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG5D;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAkBjE;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5E;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB9E;AAED;;GAEG;AACH,wBAAsB,IAAI,CAAC,IAAI,GAAE,MAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA6BhE;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAe3D;AAED,KAAK,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC;AAE/D,UAAU,eAAe;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACvB;AAED,UAAU,gBAAgB;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;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C;oBAIxC,MAAM,YAAY,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;sBAI5C,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;gBAI1C,MAAM,QAAQ,MAAM,YAAY,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;;CAgC1E,CAAC;AAEF,eAAe,EAAE,CAAC"}
|
package/dist/polyfills/fs.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Node.js fs polyfill for WASI environment
|
|
3
3
|
* Provides both Node.js fs API
|
|
4
4
|
*/
|
|
5
|
+
import { getCwd } from './process.js';
|
|
5
6
|
function getFsBindings() {
|
|
6
7
|
try {
|
|
7
8
|
const types = globalThis['wasi:filesystem/types'];
|
|
@@ -34,11 +35,26 @@ function normalizePath(path) {
|
|
|
34
35
|
}
|
|
35
36
|
return path;
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Absolute paths pass through unchanged.
|
|
40
|
+
*/
|
|
41
|
+
function getEffectivePath(path) {
|
|
42
|
+
if (path.startsWith('/'))
|
|
43
|
+
return path;
|
|
44
|
+
const cwd = getCwd();
|
|
45
|
+
if (cwd === '.' || cwd === '')
|
|
46
|
+
return path;
|
|
47
|
+
if (path === '.')
|
|
48
|
+
return cwd;
|
|
49
|
+
if (path.startsWith('./'))
|
|
50
|
+
return cwd.replace(/\/+$/, '') + '/' + path.slice(2);
|
|
51
|
+
return cwd.replace(/\/+$/, '') + '/' + path;
|
|
52
|
+
}
|
|
37
53
|
function resolvePath(path) {
|
|
38
54
|
const preopens = getPreopenedDirs();
|
|
39
55
|
if (preopens.length === 0)
|
|
40
56
|
return null;
|
|
41
|
-
const normalizedPath = normalizePath(path);
|
|
57
|
+
const normalizedPath = normalizePath(getEffectivePath(path));
|
|
42
58
|
let catchAll = null;
|
|
43
59
|
for (const { descriptor, guestPath } of preopens) {
|
|
44
60
|
const normalizedGuest = normalizePath(guestPath);
|
|
@@ -205,12 +221,263 @@ export function readdir(path, optionsOrCallback, callback) {
|
|
|
205
221
|
.then((files) => cb?.(null, files))
|
|
206
222
|
.catch((err) => cb?.(err instanceof Error ? err : new Error(String(err))));
|
|
207
223
|
}
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
// Sync implementations
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
function enoent(path) {
|
|
228
|
+
return Object.assign(new Error(`ENOENT: no such file or directory, open '${path}'`), { code: 'ENOENT' });
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Read file contents synchronously.
|
|
232
|
+
*/
|
|
233
|
+
export function readFileSync(path, options) {
|
|
234
|
+
const resolved = resolvePath(path);
|
|
235
|
+
if (!resolved)
|
|
236
|
+
throw enoent(path);
|
|
237
|
+
try {
|
|
238
|
+
const fd = resolved.dir.openAt({ symlinkFollow: false }, resolved.relativePath, {}, { read: true });
|
|
239
|
+
const stat = fd.stat();
|
|
240
|
+
const [data] = fd.read(stat.size, BigInt(0));
|
|
241
|
+
const encoding = typeof options === 'string' ? options : options?.encoding;
|
|
242
|
+
return (encoding === 'utf8' || encoding === 'utf-8') ? new TextDecoder().decode(data) : data;
|
|
243
|
+
}
|
|
244
|
+
catch (e) {
|
|
245
|
+
if (e instanceof Error && e.code)
|
|
246
|
+
throw e;
|
|
247
|
+
throw Object.assign(new Error(`ENOENT: no such file or directory, open '${path}'`), { code: 'ENOENT' });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Write data to a file synchronously.
|
|
252
|
+
*/
|
|
253
|
+
export function writeFileSync(path, data, _options) {
|
|
254
|
+
const resolved = resolvePath(path);
|
|
255
|
+
if (!resolved)
|
|
256
|
+
throw enoent(path);
|
|
257
|
+
const bytes = typeof data === 'string' ? new TextEncoder().encode(data) : data;
|
|
258
|
+
try {
|
|
259
|
+
const fd = resolved.dir.openAt({ symlinkFollow: false }, resolved.relativePath, { create: true, truncate: true }, { write: true, mutateDirectory: true });
|
|
260
|
+
fd.write(bytes, BigInt(0));
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
throw new Error(`ENOENT: no such file or directory, open '${path}'`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Append data to a file synchronously, creating it if it doesn't exist.
|
|
268
|
+
*/
|
|
269
|
+
export function appendFileSync(path, data, _options) {
|
|
270
|
+
const resolved = resolvePath(path);
|
|
271
|
+
if (!resolved)
|
|
272
|
+
throw enoent(path);
|
|
273
|
+
const bytes = typeof data === 'string' ? new TextEncoder().encode(data) : data;
|
|
274
|
+
try {
|
|
275
|
+
const fd = resolved.dir.openAt({ symlinkFollow: false }, resolved.relativePath, { create: true }, { write: true, mutateDirectory: true });
|
|
276
|
+
const stat = fd.stat();
|
|
277
|
+
fd.write(bytes, stat.size);
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
throw new Error(`Failed to append to file '${path}': ${e}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Read directory contents synchronously.
|
|
285
|
+
*/
|
|
286
|
+
export function readdirSync(path, _options) {
|
|
287
|
+
const resolved = resolvePath(path);
|
|
288
|
+
if (!resolved)
|
|
289
|
+
throw enoent(path);
|
|
290
|
+
try {
|
|
291
|
+
let targetDir = resolved.dir;
|
|
292
|
+
if (resolved.relativePath !== '.') {
|
|
293
|
+
targetDir = resolved.dir.openAt({ symlinkFollow: false }, resolved.relativePath, { directory: true }, { read: true });
|
|
294
|
+
}
|
|
295
|
+
const stream = targetDir.readDirectory();
|
|
296
|
+
const entries = [];
|
|
297
|
+
let entry;
|
|
298
|
+
while ((entry = stream.readDirectoryEntry()) && entry) {
|
|
299
|
+
if (entry.name)
|
|
300
|
+
entries.push(entry.name);
|
|
301
|
+
}
|
|
302
|
+
return entries;
|
|
303
|
+
}
|
|
304
|
+
catch (e) {
|
|
305
|
+
throw Object.assign(new Error(`ENOENT: no such file or directory, scandir '${path}'`), { code: 'ENOENT' });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function makeStatResult(type, size = BigInt(0)) {
|
|
309
|
+
return {
|
|
310
|
+
isFile: () => type === 'file',
|
|
311
|
+
isDirectory: () => type === 'directory',
|
|
312
|
+
isSymbolicLink: () => false,
|
|
313
|
+
size: Number(size),
|
|
314
|
+
mtimeMs: 0,
|
|
315
|
+
atimeMs: 0,
|
|
316
|
+
ctimeMs: 0,
|
|
317
|
+
mode: type === 'directory' ? 0o40755 : 0o100644,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Get file stats synchronously.
|
|
322
|
+
*/
|
|
323
|
+
export function statSync(path) {
|
|
324
|
+
const resolved = resolvePath(path);
|
|
325
|
+
if (!resolved)
|
|
326
|
+
throw enoent(path);
|
|
327
|
+
try {
|
|
328
|
+
const fd = resolved.dir.openAt({ symlinkFollow: false }, resolved.relativePath, {}, { read: true });
|
|
329
|
+
const s = fd.stat();
|
|
330
|
+
const type = s.type === 'directory' ? 'directory' : 'file';
|
|
331
|
+
return makeStatResult(type, s.size);
|
|
332
|
+
}
|
|
333
|
+
catch (e) {
|
|
334
|
+
throw Object.assign(new Error(`ENOENT: no such file or directory, stat '${path}'`), { code: 'ENOENT' });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Get file stats synchronously (no symlink follow — same as stat in WASI 0.2).
|
|
339
|
+
*/
|
|
340
|
+
export function lstatSync(path) {
|
|
341
|
+
return statSync(path);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Create a directory synchronously.
|
|
345
|
+
*/
|
|
346
|
+
export function mkdirSync(path, options) {
|
|
347
|
+
if (options?.recursive) {
|
|
348
|
+
const normalized = normalizePath(path);
|
|
349
|
+
const parts = normalized.split('/').filter(Boolean);
|
|
350
|
+
for (let i = 1; i <= parts.length; i++) {
|
|
351
|
+
const partial = parts.slice(0, i).join('/');
|
|
352
|
+
const resolved = resolvePath(partial);
|
|
353
|
+
if (!resolved)
|
|
354
|
+
continue;
|
|
355
|
+
try {
|
|
356
|
+
resolved.dir.createDirectoryAt(resolved.relativePath);
|
|
357
|
+
}
|
|
358
|
+
catch { /* already exists */ }
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
const resolved = resolvePath(path);
|
|
363
|
+
if (!resolved)
|
|
364
|
+
throw enoent(path);
|
|
365
|
+
try {
|
|
366
|
+
resolved.dir.createDirectoryAt(resolved.relativePath);
|
|
367
|
+
}
|
|
368
|
+
catch (e) {
|
|
369
|
+
throw Object.assign(new Error(`EEXIST: file already exists, mkdir '${path}'`), { code: 'EEXIST' });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Remove a directory synchronously.
|
|
375
|
+
*/
|
|
376
|
+
export function rmdirSync(path, _options) {
|
|
377
|
+
const resolved = resolvePath(path);
|
|
378
|
+
if (!resolved)
|
|
379
|
+
throw enoent(path);
|
|
380
|
+
try {
|
|
381
|
+
resolved.dir.removeDirectoryAt(resolved.relativePath);
|
|
382
|
+
}
|
|
383
|
+
catch (e) {
|
|
384
|
+
throw Object.assign(new Error(`ENOENT: no such file or directory, rmdir '${path}'`), { code: 'ENOENT' });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
208
387
|
/**
|
|
209
|
-
*
|
|
388
|
+
* Remove a file or directory synchronously.
|
|
210
389
|
*/
|
|
211
|
-
export function
|
|
212
|
-
|
|
213
|
-
|
|
390
|
+
export function rmSync(path, options) {
|
|
391
|
+
const resolved = resolvePath(path);
|
|
392
|
+
if (!resolved) {
|
|
393
|
+
if (options?.force)
|
|
394
|
+
return;
|
|
395
|
+
throw enoent(path);
|
|
396
|
+
}
|
|
397
|
+
try {
|
|
398
|
+
const fd = resolved.dir.openAt({ symlinkFollow: false }, resolved.relativePath, {}, { read: true });
|
|
399
|
+
const s = fd.stat();
|
|
400
|
+
if (s.type === 'directory') {
|
|
401
|
+
if (!options?.recursive) {
|
|
402
|
+
throw Object.assign(new Error(`EISDIR: illegal operation on a directory, rm '${path}'`), { code: 'EISDIR' });
|
|
403
|
+
}
|
|
404
|
+
resolved.dir.removeDirectoryAt(resolved.relativePath);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
resolved.dir.unlinkFileAt(resolved.relativePath);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
catch (e) {
|
|
411
|
+
if (options?.force)
|
|
412
|
+
return;
|
|
413
|
+
if (e instanceof Error && e.code)
|
|
414
|
+
throw e;
|
|
415
|
+
throw enoent(path);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Remove a file synchronously.
|
|
420
|
+
*/
|
|
421
|
+
export function unlinkSync(path) {
|
|
422
|
+
const resolved = resolvePath(path);
|
|
423
|
+
if (!resolved)
|
|
424
|
+
throw enoent(path);
|
|
425
|
+
try {
|
|
426
|
+
resolved.dir.unlinkFileAt(resolved.relativePath);
|
|
427
|
+
}
|
|
428
|
+
catch (e) {
|
|
429
|
+
throw Object.assign(new Error(`ENOENT: no such file or directory, unlink '${path}'`), { code: 'ENOENT' });
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Copy a file synchronously.
|
|
434
|
+
*/
|
|
435
|
+
export function copyFileSync(src, dest) {
|
|
436
|
+
const data = readFileSync(src);
|
|
437
|
+
writeFileSync(dest, data);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Rename a file or directory synchronously.
|
|
441
|
+
*/
|
|
442
|
+
export function renameSync(oldPath, newPath) {
|
|
443
|
+
try {
|
|
444
|
+
const data = readFileSync(oldPath);
|
|
445
|
+
writeFileSync(newPath, data);
|
|
446
|
+
unlinkSync(oldPath);
|
|
447
|
+
}
|
|
448
|
+
catch (e) {
|
|
449
|
+
throw Object.assign(new Error(`ENOENT: no such file or directory, rename '${oldPath}' -> '${newPath}'`), { code: 'ENOENT' });
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Check file accessibility synchronously.
|
|
454
|
+
* Throws if the path does not exist.
|
|
455
|
+
*/
|
|
456
|
+
export function accessSync(path, _mode) {
|
|
457
|
+
const resolved = resolvePath(path);
|
|
458
|
+
if (!resolved)
|
|
459
|
+
throw enoent(path);
|
|
460
|
+
try {
|
|
461
|
+
resolved.dir.openAt({ symlinkFollow: false }, resolved.relativePath, {}, { read: true });
|
|
462
|
+
}
|
|
463
|
+
catch (e) {
|
|
464
|
+
throw Object.assign(new Error(`ENOENT: no such file or directory, access '${path}'`), { code: 'ENOENT' });
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Check if a path exists synchronously.
|
|
469
|
+
*/
|
|
470
|
+
export function existsSync(path) {
|
|
471
|
+
const resolved = resolvePath(path);
|
|
472
|
+
if (!resolved)
|
|
473
|
+
return false;
|
|
474
|
+
try {
|
|
475
|
+
resolved.dir.openAt({ symlinkFollow: false }, resolved.relativePath, {}, { read: true });
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
catch {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
214
481
|
}
|
|
215
482
|
/**
|
|
216
483
|
* Delete a file.
|
|
@@ -418,12 +685,9 @@ export const promises = {
|
|
|
418
685
|
async stat(path) {
|
|
419
686
|
const kind = await statPath(path);
|
|
420
687
|
if (kind === 'notfound') {
|
|
421
|
-
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
688
|
+
throw Object.assign(new Error(`ENOENT: no such file or directory, stat '${path}'`), { code: 'ENOENT' });
|
|
422
689
|
}
|
|
423
|
-
return
|
|
424
|
-
isFile: () => kind === 'file',
|
|
425
|
-
isDirectory: () => kind === 'directory',
|
|
426
|
-
};
|
|
690
|
+
return makeStatResult(kind);
|
|
427
691
|
},
|
|
428
692
|
async rmdir(path, options) {
|
|
429
693
|
await rmdir(path, options);
|
|
@@ -442,16 +706,31 @@ export const promises = {
|
|
|
442
706
|
},
|
|
443
707
|
};
|
|
444
708
|
const fs = {
|
|
709
|
+
// Async / callback
|
|
445
710
|
readFile,
|
|
446
711
|
writeFile,
|
|
447
712
|
readdir,
|
|
448
|
-
existsSync,
|
|
449
713
|
unlink,
|
|
450
714
|
rmdir,
|
|
451
715
|
rm,
|
|
452
716
|
mkdir,
|
|
453
717
|
copyFile,
|
|
454
718
|
cp,
|
|
719
|
+
readFileSync,
|
|
720
|
+
writeFileSync,
|
|
721
|
+
appendFileSync,
|
|
722
|
+
readdirSync,
|
|
723
|
+
statSync,
|
|
724
|
+
lstatSync,
|
|
725
|
+
mkdirSync,
|
|
726
|
+
rmdirSync,
|
|
727
|
+
rmSync,
|
|
728
|
+
unlinkSync,
|
|
729
|
+
copyFileSync,
|
|
730
|
+
renameSync,
|
|
731
|
+
accessSync,
|
|
732
|
+
existsSync,
|
|
733
|
+
// Promises API
|
|
455
734
|
promises,
|
|
456
735
|
};
|
|
457
736
|
export default fs;
|