@di-framework/cli-plugin-platform 6.0.3 → 6.0.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.
- package/README.md +196 -21
- package/dist/args.d.ts +2 -1
- package/dist/args.js +9 -5
- package/dist/assets/http-adapter.js +111 -2
- package/dist/assets/platform/README.md +22 -6
- package/dist/assets/sqlite/BUILD-INFO.txt +1 -1
- package/dist/assets/wit/deps/wasi-clocks-0.2.12/package.wit +43 -0
- package/dist/assets/wit/deps/wasi-filesystem-0.2.12/package.wit +196 -0
- package/dist/assets/wit/deps/wasi-io-0.2.12/package.wit +66 -0
- package/dist/assets/wit/deps/wasi-logging/package.wit +36 -0
- package/dist/build.d.ts +3 -1
- package/dist/build.js +4 -2
- package/dist/command.js +31 -13
- package/dist/console/auth.d.ts +20 -0
- package/dist/console/auth.js +82 -0
- package/dist/console/catalog.d.ts +196 -0
- package/dist/console/catalog.js +821 -0
- package/dist/console/cluster.d.ts +30 -0
- package/dist/console/cluster.js +299 -0
- package/dist/console/errors.d.ts +10 -0
- package/dist/console/errors.js +32 -0
- package/dist/console/run.d.ts +18 -0
- package/dist/console/run.js +102 -0
- package/dist/console/server.d.ts +25 -0
- package/dist/console/server.js +668 -0
- package/dist/console/services.d.ts +47 -0
- package/dist/console/services.js +111 -0
- package/dist/console-ui/app.css +1 -0
- package/dist/console-ui/app.js +260 -0
- package/dist/console-ui/di-framework-mark.png +0 -0
- package/dist/console-ui/index.html +13 -0
- package/dist/deps.d.ts +2 -0
- package/dist/deps.js +5 -3
- package/dist/dev.js +10 -5
- package/dist/egress.d.ts +40 -0
- package/dist/egress.js +214 -0
- package/dist/host-interface.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/manifest.d.ts +7 -0
- package/dist/manifest.js +35 -8
- package/dist/node-compat/console.d.ts +18 -0
- package/dist/node-compat/console.js +42 -0
- package/dist/node-compat/env.js +6 -0
- package/dist/node-compat/events.d.ts +20 -0
- package/dist/node-compat/events.js +55 -0
- package/dist/node-compat/fetch-runtime.d.ts +39 -0
- package/dist/node-compat/fetch-runtime.js +106 -2
- package/dist/node-compat/fs-promises.d.ts +30 -0
- package/dist/node-compat/fs-promises.js +3 -0
- package/dist/node-compat/fs.d.ts +79 -0
- package/dist/node-compat/fs.js +112 -5
- package/dist/node-compat/net.d.ts +2 -1
- package/dist/node-compat/net.js +3 -1
- package/dist/node-compat/storage.d.ts +87 -0
- package/dist/node-compat/storage.js +244 -0
- package/dist/node-compat/stream.d.ts +24 -0
- package/dist/node-compat/stream.js +70 -0
- package/dist/platform.js +2 -4
- package/dist/project.d.ts +5 -0
- package/dist/project.js +4 -0
- package/dist/service.d.ts +21 -2
- package/dist/service.js +71 -5
- package/dist/target.js +6 -1
- package/dist/wit.d.ts +8 -0
- package/dist/wit.js +28 -0
- package/dist/workload.d.ts +45 -0
- package/dist/workload.js +98 -26
- package/package.json +14 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// unenv's EventEmitter is an ES class, so the function-style subclassing that npm
|
|
2
|
+
// packages copied from Node (`EE.call(this)` plus `util.inherits`, as in
|
|
3
|
+
// readable-stream's legacy Stream) throws "class constructors must be invoked with
|
|
4
|
+
// 'new'". This wrapper keeps unenv's implementation and adds Node's call behavior.
|
|
5
|
+
import { EventEmitter as UnenvEventEmitter } from 'unenv/node/events';
|
|
6
|
+
export * from 'unenv/node/events';
|
|
7
|
+
const kCapture = Symbol.for('kCapture');
|
|
8
|
+
const kShapeMode = Symbol.for('shapeMode');
|
|
9
|
+
/** Node's `EventEmitter.init`: the constructor body for an existing `this`. */
|
|
10
|
+
function initialize(target, options) {
|
|
11
|
+
const prototype = Object.getPrototypeOf(target);
|
|
12
|
+
if (target._events === undefined || target._events === prototype?._events) {
|
|
13
|
+
target._events = Object.create(null);
|
|
14
|
+
target._eventsCount = 0;
|
|
15
|
+
target[kShapeMode] = false;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
target[kShapeMode] = true;
|
|
19
|
+
}
|
|
20
|
+
target._maxListeners = target._maxListeners || undefined;
|
|
21
|
+
target[kCapture] = Boolean(options?.captureRejections);
|
|
22
|
+
}
|
|
23
|
+
function EventEmitterConstructor(options) {
|
|
24
|
+
// `new` and `super()` from an ES subclass construct unenv's class for new.target.
|
|
25
|
+
if (new.target)
|
|
26
|
+
return Reflect.construct(UnenvEventEmitter, [options], new.target);
|
|
27
|
+
initialize(this, options);
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
/** `EventEmitter.init.call(this)`, the older spelling of `EventEmitter.call(this)`. */
|
|
31
|
+
export function init(options) {
|
|
32
|
+
initialize(this, options);
|
|
33
|
+
}
|
|
34
|
+
const emitterPrototype = UnenvEventEmitter.prototype;
|
|
35
|
+
// Node aliases these; unenv's `on` calls `this.addListener`, which recurses forever when a
|
|
36
|
+
// subclass points addListener back at its own `on` (readable-stream's Readable does).
|
|
37
|
+
emitterPrototype.on = emitterPrototype.addListener;
|
|
38
|
+
emitterPrototype.off = emitterPrototype.removeListener;
|
|
39
|
+
Object.setPrototypeOf(EventEmitterConstructor, UnenvEventEmitter);
|
|
40
|
+
EventEmitterConstructor.prototype = emitterPrototype;
|
|
41
|
+
Object.defineProperty(emitterPrototype, 'constructor', {
|
|
42
|
+
value: EventEmitterConstructor,
|
|
43
|
+
writable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperties(EventEmitterConstructor, {
|
|
47
|
+
name: { value: 'EventEmitter' },
|
|
48
|
+
EventEmitter: { value: EventEmitterConstructor, writable: true, configurable: true },
|
|
49
|
+
init: { value: init, writable: true, configurable: true },
|
|
50
|
+
});
|
|
51
|
+
export const EventEmitter = EventEmitterConstructor;
|
|
52
|
+
// unenv exports these as "not implemented"; the class statics already work.
|
|
53
|
+
export const setMaxListeners = (...args) => UnenvEventEmitter.setMaxListeners(...args);
|
|
54
|
+
export const listenerCount = (emitter, type) => emitter.listenerCount(type);
|
|
55
|
+
export default EventEmitter;
|
|
@@ -16,12 +16,20 @@ export declare class TextDecoderPolyfill {
|
|
|
16
16
|
export declare class URLSearchParamsPolyfill {
|
|
17
17
|
#private;
|
|
18
18
|
constructor(init?: string | URLSearchParamsPolyfill | Record<string, string>);
|
|
19
|
+
/** Lets `URL` refresh `search` and `href` after `set`, `append`, or `delete`. */
|
|
20
|
+
bind(onChange: () => void): void;
|
|
19
21
|
get(name: string): string | null;
|
|
22
|
+
getAll(name: string): string[];
|
|
23
|
+
has(name: string): boolean;
|
|
24
|
+
append(name: string, value: string): void;
|
|
25
|
+
set(name: string, value: string): void;
|
|
26
|
+
delete(name: string): void;
|
|
20
27
|
entries(): IterableIterator<[string, string]>;
|
|
21
28
|
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
22
29
|
toString(): string;
|
|
23
30
|
}
|
|
24
31
|
export declare class URLPolyfill {
|
|
32
|
+
#private;
|
|
25
33
|
href: string;
|
|
26
34
|
protocol: string;
|
|
27
35
|
hostname: string;
|
|
@@ -76,5 +84,36 @@ export declare class ResponsePolyfill {
|
|
|
76
84
|
text(): Promise<string>;
|
|
77
85
|
json(): Promise<unknown>;
|
|
78
86
|
}
|
|
87
|
+
export declare class AbortSignalPolyfill {
|
|
88
|
+
#private;
|
|
89
|
+
aborted: boolean;
|
|
90
|
+
reason: unknown;
|
|
91
|
+
onabort: ((event: {
|
|
92
|
+
type: 'abort';
|
|
93
|
+
}) => void) | null;
|
|
94
|
+
addEventListener(type: string, listener: (event: {
|
|
95
|
+
type: 'abort';
|
|
96
|
+
}) => void): void;
|
|
97
|
+
removeEventListener(type: string, listener: (event: {
|
|
98
|
+
type: 'abort';
|
|
99
|
+
}) => void): void;
|
|
100
|
+
dispatchEvent(event: {
|
|
101
|
+
type: 'abort';
|
|
102
|
+
}): boolean;
|
|
103
|
+
throwIfAborted(): void;
|
|
104
|
+
}
|
|
105
|
+
export declare class AbortControllerPolyfill {
|
|
106
|
+
readonly signal: AbortSignalPolyfill;
|
|
107
|
+
abort(reason?: unknown): void;
|
|
108
|
+
}
|
|
109
|
+
type BlobPart = string | ArrayBuffer | ArrayBufferView;
|
|
110
|
+
/** QuickJS has no Blob. unenv's File extends it while Node streams load. */
|
|
111
|
+
export declare class BlobPolyfill {
|
|
112
|
+
readonly size: number;
|
|
113
|
+
readonly type: string;
|
|
114
|
+
constructor(parts?: BlobPart[], options?: {
|
|
115
|
+
type?: string;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
79
118
|
export declare function installFetchRuntime(force?: boolean): void;
|
|
80
119
|
export {};
|
|
@@ -31,14 +31,16 @@ export class TextDecoderPolyfill {
|
|
|
31
31
|
}
|
|
32
32
|
export class URLSearchParamsPolyfill {
|
|
33
33
|
#pairs = [];
|
|
34
|
+
#onChange;
|
|
34
35
|
constructor(init) {
|
|
35
36
|
if (typeof init === 'string') {
|
|
36
37
|
const query = init.startsWith('?') ? init.slice(1) : init;
|
|
37
38
|
if (query !== '') {
|
|
38
39
|
for (const part of query.split('&')) {
|
|
39
40
|
const eq = part.indexOf('=');
|
|
40
|
-
const
|
|
41
|
-
const
|
|
41
|
+
const decode = (text) => decodeURIComponent(text.replaceAll('+', ' '));
|
|
42
|
+
const name = decode(eq === -1 ? part : part.slice(0, eq));
|
|
43
|
+
const value = decode(eq === -1 ? '' : part.slice(eq + 1));
|
|
42
44
|
this.#pairs.push([name, value]);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -51,10 +53,44 @@ export class URLSearchParamsPolyfill {
|
|
|
51
53
|
this.#pairs.push([name, String(value)]);
|
|
52
54
|
}
|
|
53
55
|
}
|
|
56
|
+
/** Lets `URL` refresh `search` and `href` after `set`, `append`, or `delete`. */
|
|
57
|
+
bind(onChange) {
|
|
58
|
+
this.#onChange = onChange;
|
|
59
|
+
}
|
|
54
60
|
get(name) {
|
|
55
61
|
const found = this.#pairs.find(([key]) => key === name);
|
|
56
62
|
return found ? found[1] : null;
|
|
57
63
|
}
|
|
64
|
+
getAll(name) {
|
|
65
|
+
return this.#pairs.filter(([key]) => key === name).map(([, value]) => value);
|
|
66
|
+
}
|
|
67
|
+
has(name) {
|
|
68
|
+
return this.#pairs.some(([key]) => key === name);
|
|
69
|
+
}
|
|
70
|
+
append(name, value) {
|
|
71
|
+
this.#pairs.push([name, String(value)]);
|
|
72
|
+
this.#onChange?.();
|
|
73
|
+
}
|
|
74
|
+
set(name, value) {
|
|
75
|
+
const next = [];
|
|
76
|
+
let placed = false;
|
|
77
|
+
for (const pair of this.#pairs) {
|
|
78
|
+
if (pair[0] !== name)
|
|
79
|
+
next.push(pair);
|
|
80
|
+
else if (!placed) {
|
|
81
|
+
next.push([name, String(value)]);
|
|
82
|
+
placed = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!placed)
|
|
86
|
+
next.push([name, String(value)]);
|
|
87
|
+
this.#pairs = next;
|
|
88
|
+
this.#onChange?.();
|
|
89
|
+
}
|
|
90
|
+
delete(name) {
|
|
91
|
+
this.#pairs = this.#pairs.filter(([key]) => key !== name);
|
|
92
|
+
this.#onChange?.();
|
|
93
|
+
}
|
|
58
94
|
*entries() {
|
|
59
95
|
yield* this.#pairs;
|
|
60
96
|
}
|
|
@@ -92,6 +128,12 @@ export class URLPolyfill {
|
|
|
92
128
|
this.origin = `${this.protocol}//${this.host}`;
|
|
93
129
|
this.href = resolved;
|
|
94
130
|
this.searchParams = new URLSearchParamsPolyfill(this.search);
|
|
131
|
+
this.searchParams.bind(() => this.#sync());
|
|
132
|
+
}
|
|
133
|
+
#sync() {
|
|
134
|
+
const query = this.searchParams.toString();
|
|
135
|
+
this.search = query === '' ? '' : `?${query}`;
|
|
136
|
+
this.href = `${this.origin}${this.pathname}${this.search}${this.hash}`;
|
|
95
137
|
}
|
|
96
138
|
toString() {
|
|
97
139
|
return this.href;
|
|
@@ -283,6 +325,58 @@ export class ResponsePolyfill {
|
|
|
283
325
|
return JSON.parse(await this.text());
|
|
284
326
|
}
|
|
285
327
|
}
|
|
328
|
+
export class AbortSignalPolyfill {
|
|
329
|
+
aborted = false;
|
|
330
|
+
reason = undefined;
|
|
331
|
+
onabort = null;
|
|
332
|
+
#listeners = [];
|
|
333
|
+
addEventListener(type, listener) {
|
|
334
|
+
if (type === 'abort')
|
|
335
|
+
this.#listeners.push(listener);
|
|
336
|
+
}
|
|
337
|
+
removeEventListener(type, listener) {
|
|
338
|
+
if (type !== 'abort')
|
|
339
|
+
return;
|
|
340
|
+
this.#listeners = this.#listeners.filter((item) => item !== listener);
|
|
341
|
+
}
|
|
342
|
+
dispatchEvent(event) {
|
|
343
|
+
for (const listener of this.#listeners)
|
|
344
|
+
listener(event);
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
throwIfAborted() {
|
|
348
|
+
if (this.aborted)
|
|
349
|
+
throw this.reason instanceof Error ? this.reason : new Error('This operation was aborted');
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
export class AbortControllerPolyfill {
|
|
353
|
+
signal = new AbortSignalPolyfill();
|
|
354
|
+
abort(reason) {
|
|
355
|
+
if (this.signal.aborted)
|
|
356
|
+
return;
|
|
357
|
+
this.signal.aborted = true;
|
|
358
|
+
this.signal.reason = reason ?? new Error('This operation was aborted');
|
|
359
|
+
const event = { type: 'abort' };
|
|
360
|
+
this.signal.onabort?.(event);
|
|
361
|
+
this.signal.dispatchEvent(event);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/** QuickJS has no Blob. unenv's File extends it while Node streams load. */
|
|
365
|
+
export class BlobPolyfill {
|
|
366
|
+
size;
|
|
367
|
+
type;
|
|
368
|
+
constructor(parts = [], options) {
|
|
369
|
+
let size = 0;
|
|
370
|
+
for (const part of parts) {
|
|
371
|
+
if (typeof part === 'string')
|
|
372
|
+
size += new TextEncoder().encode(part).length;
|
|
373
|
+
else
|
|
374
|
+
size += part.byteLength;
|
|
375
|
+
}
|
|
376
|
+
this.size = size;
|
|
377
|
+
this.type = options?.type ?? '';
|
|
378
|
+
}
|
|
379
|
+
}
|
|
286
380
|
const noopConsole = {
|
|
287
381
|
log() { },
|
|
288
382
|
info() { },
|
|
@@ -307,6 +401,16 @@ export function installFetchRuntime(force = false) {
|
|
|
307
401
|
global.Request = RequestPolyfill;
|
|
308
402
|
if (force || typeof global.Response !== 'function')
|
|
309
403
|
global.Response = ResponsePolyfill;
|
|
404
|
+
if (force || typeof global.Blob !== 'function')
|
|
405
|
+
global.Blob = BlobPolyfill;
|
|
406
|
+
if (force || typeof global.AbortSignal !== 'function')
|
|
407
|
+
global.AbortSignal = AbortSignalPolyfill;
|
|
408
|
+
if (force || typeof global.AbortController !== 'function') {
|
|
409
|
+
global.AbortController = AbortControllerPolyfill;
|
|
410
|
+
}
|
|
411
|
+
// mqtt's browser abort-controller reads AbortController from self or window.
|
|
412
|
+
if (force || typeof global.self !== 'object' || global.self === null)
|
|
413
|
+
global.self = globalThis;
|
|
310
414
|
if (force || typeof global.console !== 'object' || global.console === null) {
|
|
311
415
|
global.console = noopConsole;
|
|
312
416
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { promises } from './fs.js';
|
|
2
|
+
export declare const access: (path: string, mode?: number) => Promise<void>, appendFile: (path: string, data: string | Uint8Array, encoding?: string | {
|
|
3
|
+
encoding?: string | null;
|
|
4
|
+
}) => Promise<void>, lstat: (path: string) => Promise<{
|
|
5
|
+
isFile(): boolean;
|
|
6
|
+
isDirectory(): boolean;
|
|
7
|
+
size: number;
|
|
8
|
+
mtimeMs: number;
|
|
9
|
+
}>, mkdir: (path: string, options?: {
|
|
10
|
+
recursive?: boolean;
|
|
11
|
+
} | number) => Promise<string | undefined>, readFile: (path: string, encoding?: string | {
|
|
12
|
+
encoding?: string | null;
|
|
13
|
+
}) => Promise<string | Uint8Array<ArrayBufferLike>>, readdir: (path: string, options?: {
|
|
14
|
+
withFileTypes?: boolean;
|
|
15
|
+
} | string | null) => Promise<string[] | {
|
|
16
|
+
name: string;
|
|
17
|
+
isFile(): boolean;
|
|
18
|
+
isDirectory(): boolean;
|
|
19
|
+
}[]>, rename: (from: string, to: string) => Promise<void>, rm: (path: string, options?: {
|
|
20
|
+
recursive?: boolean;
|
|
21
|
+
force?: boolean;
|
|
22
|
+
}) => Promise<void>, stat: (path: string) => Promise<{
|
|
23
|
+
isFile(): boolean;
|
|
24
|
+
isDirectory(): boolean;
|
|
25
|
+
size: number;
|
|
26
|
+
mtimeMs: number;
|
|
27
|
+
}>, unlink: (path: string) => Promise<void>, writeFile: (path: string, data: string | Uint8Array, encoding?: string | {
|
|
28
|
+
encoding?: string | null;
|
|
29
|
+
}) => Promise<void>;
|
|
30
|
+
export default promises;
|
package/dist/node-compat/fs.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { type Storage } from './storage.js';
|
|
2
|
+
/** Swap the storage backend (tests run several workload members in one process). */
|
|
3
|
+
export declare function useStorage(next: Storage): Storage;
|
|
1
4
|
export declare function normalizeFsPath(path: string, cwd?: string): string;
|
|
2
5
|
export declare function readFileSync(path: string, encoding?: string | {
|
|
3
6
|
encoding?: string | null;
|
|
@@ -5,6 +8,9 @@ export declare function readFileSync(path: string, encoding?: string | {
|
|
|
5
8
|
export declare function writeFileSync(path: string, data: string | Uint8Array, _encoding?: string | {
|
|
6
9
|
encoding?: string | null;
|
|
7
10
|
}): void;
|
|
11
|
+
export declare function appendFileSync(path: string, data: string | Uint8Array, _encoding?: string | {
|
|
12
|
+
encoding?: string | null;
|
|
13
|
+
}): void;
|
|
8
14
|
export declare function existsSync(path: string): boolean;
|
|
9
15
|
export declare function mkdirSync(path: string, options?: {
|
|
10
16
|
recursive?: boolean;
|
|
@@ -56,8 +62,47 @@ export declare const constants: {
|
|
|
56
62
|
X_OK: number;
|
|
57
63
|
};
|
|
58
64
|
export declare function accessSync(path: string, _mode?: number): void;
|
|
65
|
+
type Encoding = string | {
|
|
66
|
+
encoding?: string | null;
|
|
67
|
+
};
|
|
68
|
+
/** `fs/promises`: the synchronous operations above, settled as promises. */
|
|
69
|
+
export declare const promises: {
|
|
70
|
+
access: (path: string, mode?: number) => Promise<void>;
|
|
71
|
+
appendFile: (path: string, data: string | Uint8Array, encoding?: Encoding) => Promise<void>;
|
|
72
|
+
mkdir: (path: string, options?: {
|
|
73
|
+
recursive?: boolean;
|
|
74
|
+
} | number) => Promise<string | undefined>;
|
|
75
|
+
readFile: (path: string, encoding?: Encoding) => Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
76
|
+
readdir: (path: string, options?: {
|
|
77
|
+
withFileTypes?: boolean;
|
|
78
|
+
} | string | null) => Promise<string[] | {
|
|
79
|
+
name: string;
|
|
80
|
+
isFile(): boolean;
|
|
81
|
+
isDirectory(): boolean;
|
|
82
|
+
}[]>;
|
|
83
|
+
rename: (from: string, to: string) => Promise<void>;
|
|
84
|
+
rm: (path: string, options?: {
|
|
85
|
+
recursive?: boolean;
|
|
86
|
+
force?: boolean;
|
|
87
|
+
}) => Promise<void>;
|
|
88
|
+
stat: (path: string) => Promise<{
|
|
89
|
+
isFile(): boolean;
|
|
90
|
+
isDirectory(): boolean;
|
|
91
|
+
size: number;
|
|
92
|
+
mtimeMs: number;
|
|
93
|
+
}>;
|
|
94
|
+
lstat: (path: string) => Promise<{
|
|
95
|
+
isFile(): boolean;
|
|
96
|
+
isDirectory(): boolean;
|
|
97
|
+
size: number;
|
|
98
|
+
mtimeMs: number;
|
|
99
|
+
}>;
|
|
100
|
+
unlink: (path: string) => Promise<void>;
|
|
101
|
+
writeFile: (path: string, data: string | Uint8Array, encoding?: Encoding) => Promise<void>;
|
|
102
|
+
};
|
|
59
103
|
declare const _default: {
|
|
60
104
|
accessSync: typeof accessSync;
|
|
105
|
+
appendFileSync: typeof appendFileSync;
|
|
61
106
|
closeSync: typeof closeSync;
|
|
62
107
|
constants: {
|
|
63
108
|
F_OK: number;
|
|
@@ -80,5 +125,39 @@ declare const _default: {
|
|
|
80
125
|
unlinkSync: typeof unlinkSync;
|
|
81
126
|
writeFileSync: typeof writeFileSync;
|
|
82
127
|
writeSync: typeof writeSync;
|
|
128
|
+
promises: {
|
|
129
|
+
access: (path: string, mode?: number) => Promise<void>;
|
|
130
|
+
appendFile: (path: string, data: string | Uint8Array, encoding?: Encoding) => Promise<void>;
|
|
131
|
+
mkdir: (path: string, options?: {
|
|
132
|
+
recursive?: boolean;
|
|
133
|
+
} | number) => Promise<string | undefined>;
|
|
134
|
+
readFile: (path: string, encoding?: Encoding) => Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
135
|
+
readdir: (path: string, options?: {
|
|
136
|
+
withFileTypes?: boolean;
|
|
137
|
+
} | string | null) => Promise<string[] | {
|
|
138
|
+
name: string;
|
|
139
|
+
isFile(): boolean;
|
|
140
|
+
isDirectory(): boolean;
|
|
141
|
+
}[]>;
|
|
142
|
+
rename: (from: string, to: string) => Promise<void>;
|
|
143
|
+
rm: (path: string, options?: {
|
|
144
|
+
recursive?: boolean;
|
|
145
|
+
force?: boolean;
|
|
146
|
+
}) => Promise<void>;
|
|
147
|
+
stat: (path: string) => Promise<{
|
|
148
|
+
isFile(): boolean;
|
|
149
|
+
isDirectory(): boolean;
|
|
150
|
+
size: number;
|
|
151
|
+
mtimeMs: number;
|
|
152
|
+
}>;
|
|
153
|
+
lstat: (path: string) => Promise<{
|
|
154
|
+
isFile(): boolean;
|
|
155
|
+
isDirectory(): boolean;
|
|
156
|
+
size: number;
|
|
157
|
+
mtimeMs: number;
|
|
158
|
+
}>;
|
|
159
|
+
unlink: (path: string) => Promise<void>;
|
|
160
|
+
writeFile: (path: string, data: string | Uint8Array, encoding?: Encoding) => Promise<void>;
|
|
161
|
+
};
|
|
83
162
|
};
|
|
84
163
|
export default _default;
|
package/dist/node-compat/fs.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { nodeCompatSeed } from './seed-virtual.js';
|
|
2
|
+
import { storage as wasiStorage } from './storage.js';
|
|
3
|
+
/** Host-mounted storage; paths outside it stay in the in-memory filesystem below. */
|
|
4
|
+
let storage = wasiStorage;
|
|
5
|
+
/** Swap the storage backend (tests run several workload members in one process). */
|
|
6
|
+
export function useStorage(next) {
|
|
7
|
+
const previous = storage;
|
|
8
|
+
storage = next;
|
|
9
|
+
return previous;
|
|
10
|
+
}
|
|
11
|
+
function stored(path) {
|
|
12
|
+
return storage.owns(path);
|
|
13
|
+
}
|
|
14
|
+
function asBuffer(bytes) {
|
|
15
|
+
return typeof Buffer === 'undefined' ? bytes : Buffer.from(bytes);
|
|
16
|
+
}
|
|
2
17
|
function errno(code, syscall, path, errnoValue) {
|
|
3
18
|
const error = new Error(`${code}: no such file or directory, ${syscall} '${path}'`);
|
|
4
19
|
error.code = code;
|
|
@@ -37,6 +52,10 @@ function asBytes(data) {
|
|
|
37
52
|
}
|
|
38
53
|
export function readFileSync(path, encoding) {
|
|
39
54
|
const normalized = normalizeFsPath(String(path));
|
|
55
|
+
if (stored(normalized)) {
|
|
56
|
+
const bytes = storage.readFile(normalized);
|
|
57
|
+
return encodingName(encoding) !== undefined ? new TextDecoder().decode(bytes) : asBuffer(bytes);
|
|
58
|
+
}
|
|
40
59
|
const content = nodeCompatSeed.files[normalized];
|
|
41
60
|
if (content === undefined) {
|
|
42
61
|
throw errno('ENOENT', 'open', normalized, -2);
|
|
@@ -44,10 +63,23 @@ export function readFileSync(path, encoding) {
|
|
|
44
63
|
if (encodingName(encoding) !== undefined)
|
|
45
64
|
return content;
|
|
46
65
|
const bytes = new TextEncoder().encode(content);
|
|
47
|
-
return
|
|
66
|
+
return asBuffer(bytes);
|
|
48
67
|
}
|
|
49
68
|
export function writeFileSync(path, data, _encoding) {
|
|
50
|
-
|
|
69
|
+
const normalized = normalizeFsPath(String(path));
|
|
70
|
+
if (stored(normalized)) {
|
|
71
|
+
storage.writeFile(normalized, asBytes(data));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
nodeCompatSeed.files[normalized] = asText(data);
|
|
75
|
+
}
|
|
76
|
+
export function appendFileSync(path, data, _encoding) {
|
|
77
|
+
const normalized = normalizeFsPath(String(path));
|
|
78
|
+
if (stored(normalized)) {
|
|
79
|
+
storage.appendFile(normalized, asBytes(data));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
nodeCompatSeed.files[normalized] = (nodeCompatSeed.files[normalized] ?? '') + asText(data);
|
|
51
83
|
}
|
|
52
84
|
function directoryKey(path) {
|
|
53
85
|
const normalized = normalizeFsPath(path).replace(/\/$/, '');
|
|
@@ -55,11 +87,17 @@ function directoryKey(path) {
|
|
|
55
87
|
}
|
|
56
88
|
export function existsSync(path) {
|
|
57
89
|
const normalized = normalizeFsPath(String(path));
|
|
90
|
+
if (stored(normalized))
|
|
91
|
+
return storage.exists(normalized);
|
|
58
92
|
return normalized in nodeCompatSeed.files || directoryKey(normalized) in nodeCompatSeed.files;
|
|
59
93
|
}
|
|
60
94
|
export function mkdirSync(path, options) {
|
|
61
95
|
const normalized = normalizeFsPath(String(path)).replace(/\/$/, '') || '/';
|
|
62
96
|
const recursive = typeof options === 'object' && options?.recursive === true;
|
|
97
|
+
if (stored(normalized)) {
|
|
98
|
+
storage.mkdir(normalized, recursive);
|
|
99
|
+
return recursive ? normalized : undefined;
|
|
100
|
+
}
|
|
63
101
|
if (normalized in nodeCompatSeed.files || directoryKey(normalized) in nodeCompatSeed.files) {
|
|
64
102
|
if (recursive)
|
|
65
103
|
return undefined;
|
|
@@ -82,6 +120,17 @@ export function mkdirSync(path, options) {
|
|
|
82
120
|
}
|
|
83
121
|
export function readdirSync(path, options) {
|
|
84
122
|
const normalized = normalizeFsPath(String(path)).replace(/\/$/, '') || '/';
|
|
123
|
+
const withFileTypes = options !== null && typeof options === 'object' && options.withFileTypes === true;
|
|
124
|
+
if (stored(normalized)) {
|
|
125
|
+
const entries = storage.readdir(normalized);
|
|
126
|
+
if (!withFileTypes)
|
|
127
|
+
return entries.map((entry) => entry.name);
|
|
128
|
+
return entries.map((entry) => ({
|
|
129
|
+
name: entry.name,
|
|
130
|
+
isFile: () => !entry.directory,
|
|
131
|
+
isDirectory: () => entry.directory,
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
85
134
|
const prefix = normalized === '/' ? '/' : `${normalized}/`;
|
|
86
135
|
const names = new Set();
|
|
87
136
|
for (const key of Object.keys(nodeCompatSeed.files)) {
|
|
@@ -93,7 +142,6 @@ export function readdirSync(path, options) {
|
|
|
93
142
|
names.add(name.replace(/\/$/, ''));
|
|
94
143
|
}
|
|
95
144
|
const list = [...names].sort();
|
|
96
|
-
const withFileTypes = options !== null && typeof options === 'object' && options.withFileTypes === true;
|
|
97
145
|
if (!withFileTypes)
|
|
98
146
|
return list;
|
|
99
147
|
return list.map((name) => {
|
|
@@ -108,6 +156,15 @@ export function readdirSync(path, options) {
|
|
|
108
156
|
}
|
|
109
157
|
export function statSync(path) {
|
|
110
158
|
const normalized = normalizeFsPath(String(path));
|
|
159
|
+
if (stored(normalized)) {
|
|
160
|
+
const result = storage.stat(normalized);
|
|
161
|
+
return {
|
|
162
|
+
isFile: () => !result.directory,
|
|
163
|
+
isDirectory: () => result.directory,
|
|
164
|
+
size: result.size,
|
|
165
|
+
mtimeMs: result.mtimeMs,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
111
168
|
const content = nodeCompatSeed.files[normalized];
|
|
112
169
|
if (content !== undefined) {
|
|
113
170
|
return {
|
|
@@ -142,6 +199,17 @@ export function openSync(path, flags = 'r', _mode) {
|
|
|
142
199
|
const normalized = normalizeFsPath(String(path));
|
|
143
200
|
const flag = typeof flags === 'string' ? flags : 'r';
|
|
144
201
|
const writing = flag.includes('w') || flag.includes('a') || flag.includes('+');
|
|
202
|
+
if (stored(normalized)) {
|
|
203
|
+
if (flag.includes('w'))
|
|
204
|
+
storage.truncate(normalized);
|
|
205
|
+
else if (writing && !storage.exists(normalized))
|
|
206
|
+
storage.writeFile(normalized, new Uint8Array());
|
|
207
|
+
else if (!writing)
|
|
208
|
+
storage.stat(normalized);
|
|
209
|
+
const fd = nextFd++;
|
|
210
|
+
openHandles.set(fd, { path: normalized, position: 0, flags: flag, stored: true });
|
|
211
|
+
return fd;
|
|
212
|
+
}
|
|
145
213
|
if (!(normalized in nodeCompatSeed.files) && !writing) {
|
|
146
214
|
throw errno('ENOENT', 'open', normalized, -2);
|
|
147
215
|
}
|
|
@@ -153,6 +221,7 @@ export function openSync(path, flags = 'r', _mode) {
|
|
|
153
221
|
path: normalized,
|
|
154
222
|
position: flag.includes('a') ? Number.MAX_SAFE_INTEGER : 0,
|
|
155
223
|
flags: flag,
|
|
224
|
+
stored: false,
|
|
156
225
|
});
|
|
157
226
|
return fd;
|
|
158
227
|
}
|
|
@@ -164,9 +233,10 @@ export function readSync(fd, buffer, offset = 0, length = buffer.byteLength - of
|
|
|
164
233
|
const handle = openHandles.get(fd);
|
|
165
234
|
if (handle === undefined)
|
|
166
235
|
throw errno('EBADF', 'read', String(fd), -9);
|
|
167
|
-
const content = asBytes(nodeCompatSeed.files[handle.path] ?? '');
|
|
168
236
|
const start = position === null ? handle.position : position;
|
|
169
|
-
const slice =
|
|
237
|
+
const slice = handle.stored
|
|
238
|
+
? storage.readAt(handle.path, length, start)
|
|
239
|
+
: asBytes(nodeCompatSeed.files[handle.path] ?? '').subarray(start, start + length);
|
|
170
240
|
buffer.set(slice, offset);
|
|
171
241
|
if (position === null)
|
|
172
242
|
handle.position = start + slice.byteLength;
|
|
@@ -177,6 +247,13 @@ export function writeSync(fd, data, offset, length, position) {
|
|
|
177
247
|
if (handle === undefined)
|
|
178
248
|
throw errno('EBADF', 'write', String(fd), -9);
|
|
179
249
|
const bytes = asBytes(data).subarray(offset ?? 0, (offset ?? 0) + (length ?? asBytes(data).byteLength));
|
|
250
|
+
if (handle.stored) {
|
|
251
|
+
const target = position ?? (handle.flags.includes('a') ? 'end' : handle.position);
|
|
252
|
+
const end = storage.writeAt(handle.path, bytes, target);
|
|
253
|
+
if (position == null)
|
|
254
|
+
handle.position = end;
|
|
255
|
+
return bytes.byteLength;
|
|
256
|
+
}
|
|
180
257
|
const existing = asBytes(nodeCompatSeed.files[handle.path] ?? '');
|
|
181
258
|
const start = position == null
|
|
182
259
|
? handle.flags.includes('a')
|
|
@@ -221,6 +298,12 @@ export function createReadStream(path) {
|
|
|
221
298
|
}
|
|
222
299
|
export function rmSync(path, options) {
|
|
223
300
|
const normalized = normalizeFsPath(String(path));
|
|
301
|
+
if (stored(normalized)) {
|
|
302
|
+
if (options?.force && !storage.exists(normalized))
|
|
303
|
+
return;
|
|
304
|
+
storage.remove(normalized, options?.recursive === true);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
224
307
|
const prefix = normalized === '/' ? '/' : `${normalized}/`;
|
|
225
308
|
const keys = Object.keys(nodeCompatSeed.files).filter((key) => key === normalized || key === directoryKey(normalized) || key.startsWith(prefix));
|
|
226
309
|
if (keys.length === 0) {
|
|
@@ -233,6 +316,10 @@ export function rmSync(path, options) {
|
|
|
233
316
|
}
|
|
234
317
|
export function unlinkSync(path) {
|
|
235
318
|
const normalized = normalizeFsPath(String(path));
|
|
319
|
+
if (stored(normalized)) {
|
|
320
|
+
storage.unlink(normalized);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
236
323
|
if (!(normalized in nodeCompatSeed.files))
|
|
237
324
|
throw errno('ENOENT', 'unlink', normalized, -2);
|
|
238
325
|
delete nodeCompatSeed.files[normalized];
|
|
@@ -240,6 +327,10 @@ export function unlinkSync(path) {
|
|
|
240
327
|
export function renameSync(from, to) {
|
|
241
328
|
const source = normalizeFsPath(String(from));
|
|
242
329
|
const target = normalizeFsPath(String(to));
|
|
330
|
+
if (stored(source) || stored(target)) {
|
|
331
|
+
storage.rename(source, target);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
243
334
|
if (!(source in nodeCompatSeed.files) && !(directoryKey(source) in nodeCompatSeed.files)) {
|
|
244
335
|
throw errno('ENOENT', 'rename', source, -2);
|
|
245
336
|
}
|
|
@@ -263,8 +354,23 @@ export function accessSync(path, _mode) {
|
|
|
263
354
|
if (!existsSync(path))
|
|
264
355
|
throw errno('ENOENT', 'access', normalizeFsPath(String(path)), -2);
|
|
265
356
|
}
|
|
357
|
+
/** `fs/promises`: the synchronous operations above, settled as promises. */
|
|
358
|
+
export const promises = {
|
|
359
|
+
access: async (path, mode) => accessSync(path, mode),
|
|
360
|
+
appendFile: async (path, data, encoding) => appendFileSync(path, data, encoding),
|
|
361
|
+
mkdir: async (path, options) => mkdirSync(path, options),
|
|
362
|
+
readFile: async (path, encoding) => readFileSync(path, encoding),
|
|
363
|
+
readdir: async (path, options) => readdirSync(path, options),
|
|
364
|
+
rename: async (from, to) => renameSync(from, to),
|
|
365
|
+
rm: async (path, options) => rmSync(path, options),
|
|
366
|
+
stat: async (path) => statSync(path),
|
|
367
|
+
lstat: async (path) => lstatSync(path),
|
|
368
|
+
unlink: async (path) => unlinkSync(path),
|
|
369
|
+
writeFile: async (path, data, encoding) => writeFileSync(path, data, encoding),
|
|
370
|
+
};
|
|
266
371
|
export default {
|
|
267
372
|
accessSync,
|
|
373
|
+
appendFileSync,
|
|
268
374
|
closeSync,
|
|
269
375
|
constants,
|
|
270
376
|
createReadStream,
|
|
@@ -282,4 +388,5 @@ export default {
|
|
|
282
388
|
unlinkSync,
|
|
283
389
|
writeFileSync,
|
|
284
390
|
writeSync,
|
|
391
|
+
promises,
|
|
285
392
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { Stream } from 'node:stream';
|
|
2
3
|
import { type IpAddressFamily, type IpSocketAddress, isIP, isIPv4, isIPv6 } from './socket-address.js';
|
|
3
4
|
import { type WasiTcpSocket } from './wasi-sockets.js';
|
|
4
5
|
export { isIP, isIPv4, isIPv6 };
|
|
@@ -14,7 +15,7 @@ type PushStream = {
|
|
|
14
15
|
close(): void;
|
|
15
16
|
};
|
|
16
17
|
export declare function createPushStream(): PushStream;
|
|
17
|
-
export declare class Socket extends
|
|
18
|
+
export declare class Socket extends Stream {
|
|
18
19
|
connecting: boolean;
|
|
19
20
|
pending: boolean;
|
|
20
21
|
destroyed: boolean;
|
package/dist/node-compat/net.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { Stream } from 'node:stream';
|
|
2
3
|
import { familyFromHost, formatIpSocketAddress, ipSocketAddress, isIP, isIPv4, isIPv6, } from './socket-address.js';
|
|
3
4
|
import { asAsyncIterable, createTcpSocket, firstOfTuple, readSocketAddress, resolveSocketAddress, socketError, toBytes, toNodeBuffer, unwrapAsync, unwrapResult, } from './wasi-sockets.js';
|
|
4
5
|
export { isIP, isIPv4, isIPv6 };
|
|
@@ -42,7 +43,8 @@ function emitSocketError(emitter, error) {
|
|
|
42
43
|
return;
|
|
43
44
|
emitter.emit('error', error);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
// Node's Socket is a stream; the legacy Stream base gives it `pipe` (mqtt pipes the socket).
|
|
47
|
+
export class Socket extends Stream {
|
|
46
48
|
connecting = false;
|
|
47
49
|
pending = true;
|
|
48
50
|
destroyed = false;
|