@di-framework/cli-plugin-platform 6.0.3 → 6.0.5

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 (69) hide show
  1. package/README.md +196 -21
  2. package/dist/args.d.ts +2 -1
  3. package/dist/args.js +9 -5
  4. package/dist/assets/http-adapter.js +63 -0
  5. package/dist/assets/platform/README.md +22 -6
  6. package/dist/assets/sqlite/BUILD-INFO.txt +1 -1
  7. package/dist/assets/wit/deps/wasi-clocks-0.2.12/package.wit +43 -0
  8. package/dist/assets/wit/deps/wasi-filesystem-0.2.12/package.wit +196 -0
  9. package/dist/assets/wit/deps/wasi-io-0.2.12/package.wit +66 -0
  10. package/dist/assets/wit/deps/wasi-logging/package.wit +36 -0
  11. package/dist/build.d.ts +3 -1
  12. package/dist/build.js +4 -2
  13. package/dist/command.js +31 -13
  14. package/dist/console/auth.d.ts +20 -0
  15. package/dist/console/auth.js +82 -0
  16. package/dist/console/catalog.d.ts +196 -0
  17. package/dist/console/catalog.js +821 -0
  18. package/dist/console/cluster.d.ts +30 -0
  19. package/dist/console/cluster.js +299 -0
  20. package/dist/console/errors.d.ts +10 -0
  21. package/dist/console/errors.js +32 -0
  22. package/dist/console/run.d.ts +18 -0
  23. package/dist/console/run.js +102 -0
  24. package/dist/console/server.d.ts +25 -0
  25. package/dist/console/server.js +668 -0
  26. package/dist/console/services.d.ts +47 -0
  27. package/dist/console/services.js +111 -0
  28. package/dist/console-ui/app.css +1 -0
  29. package/dist/console-ui/app.js +260 -0
  30. package/dist/console-ui/di-framework-mark.png +0 -0
  31. package/dist/console-ui/index.html +13 -0
  32. package/dist/deps.d.ts +2 -0
  33. package/dist/deps.js +5 -3
  34. package/dist/dev.js +10 -5
  35. package/dist/egress.d.ts +40 -0
  36. package/dist/egress.js +214 -0
  37. package/dist/host-interface.js +2 -1
  38. package/dist/index.d.ts +1 -0
  39. package/dist/index.js +1 -0
  40. package/dist/manifest.d.ts +7 -0
  41. package/dist/manifest.js +35 -8
  42. package/dist/node-compat/console.d.ts +18 -0
  43. package/dist/node-compat/console.js +42 -0
  44. package/dist/node-compat/env.js +6 -0
  45. package/dist/node-compat/events.d.ts +20 -0
  46. package/dist/node-compat/events.js +55 -0
  47. package/dist/node-compat/fetch-runtime.d.ts +31 -0
  48. package/dist/node-compat/fetch-runtime.js +62 -0
  49. package/dist/node-compat/fs-promises.d.ts +30 -0
  50. package/dist/node-compat/fs-promises.js +3 -0
  51. package/dist/node-compat/fs.d.ts +79 -0
  52. package/dist/node-compat/fs.js +112 -5
  53. package/dist/node-compat/net.d.ts +2 -1
  54. package/dist/node-compat/net.js +3 -1
  55. package/dist/node-compat/storage.d.ts +87 -0
  56. package/dist/node-compat/storage.js +244 -0
  57. package/dist/node-compat/stream.d.ts +24 -0
  58. package/dist/node-compat/stream.js +70 -0
  59. package/dist/platform.js +2 -4
  60. package/dist/project.d.ts +5 -0
  61. package/dist/project.js +4 -0
  62. package/dist/service.d.ts +21 -2
  63. package/dist/service.js +71 -5
  64. package/dist/target.js +6 -1
  65. package/dist/wit.d.ts +8 -0
  66. package/dist/wit.js +28 -0
  67. package/dist/workload.d.ts +45 -0
  68. package/dist/workload.js +98 -26
  69. 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;
@@ -76,5 +76,36 @@ export declare class ResponsePolyfill {
76
76
  text(): Promise<string>;
77
77
  json(): Promise<unknown>;
78
78
  }
79
+ export declare class AbortSignalPolyfill {
80
+ #private;
81
+ aborted: boolean;
82
+ reason: unknown;
83
+ onabort: ((event: {
84
+ type: 'abort';
85
+ }) => void) | null;
86
+ addEventListener(type: string, listener: (event: {
87
+ type: 'abort';
88
+ }) => void): void;
89
+ removeEventListener(type: string, listener: (event: {
90
+ type: 'abort';
91
+ }) => void): void;
92
+ dispatchEvent(event: {
93
+ type: 'abort';
94
+ }): boolean;
95
+ throwIfAborted(): void;
96
+ }
97
+ export declare class AbortControllerPolyfill {
98
+ readonly signal: AbortSignalPolyfill;
99
+ abort(reason?: unknown): void;
100
+ }
101
+ type BlobPart = string | ArrayBuffer | ArrayBufferView;
102
+ /** QuickJS has no Blob. unenv's File extends it while Node streams load. */
103
+ export declare class BlobPolyfill {
104
+ readonly size: number;
105
+ readonly type: string;
106
+ constructor(parts?: BlobPart[], options?: {
107
+ type?: string;
108
+ });
109
+ }
79
110
  export declare function installFetchRuntime(force?: boolean): void;
80
111
  export {};
@@ -283,6 +283,58 @@ export class ResponsePolyfill {
283
283
  return JSON.parse(await this.text());
284
284
  }
285
285
  }
286
+ export class AbortSignalPolyfill {
287
+ aborted = false;
288
+ reason = undefined;
289
+ onabort = null;
290
+ #listeners = [];
291
+ addEventListener(type, listener) {
292
+ if (type === 'abort')
293
+ this.#listeners.push(listener);
294
+ }
295
+ removeEventListener(type, listener) {
296
+ if (type !== 'abort')
297
+ return;
298
+ this.#listeners = this.#listeners.filter((item) => item !== listener);
299
+ }
300
+ dispatchEvent(event) {
301
+ for (const listener of this.#listeners)
302
+ listener(event);
303
+ return true;
304
+ }
305
+ throwIfAborted() {
306
+ if (this.aborted)
307
+ throw this.reason instanceof Error ? this.reason : new Error('This operation was aborted');
308
+ }
309
+ }
310
+ export class AbortControllerPolyfill {
311
+ signal = new AbortSignalPolyfill();
312
+ abort(reason) {
313
+ if (this.signal.aborted)
314
+ return;
315
+ this.signal.aborted = true;
316
+ this.signal.reason = reason ?? new Error('This operation was aborted');
317
+ const event = { type: 'abort' };
318
+ this.signal.onabort?.(event);
319
+ this.signal.dispatchEvent(event);
320
+ }
321
+ }
322
+ /** QuickJS has no Blob. unenv's File extends it while Node streams load. */
323
+ export class BlobPolyfill {
324
+ size;
325
+ type;
326
+ constructor(parts = [], options) {
327
+ let size = 0;
328
+ for (const part of parts) {
329
+ if (typeof part === 'string')
330
+ size += new TextEncoder().encode(part).length;
331
+ else
332
+ size += part.byteLength;
333
+ }
334
+ this.size = size;
335
+ this.type = options?.type ?? '';
336
+ }
337
+ }
286
338
  const noopConsole = {
287
339
  log() { },
288
340
  info() { },
@@ -307,6 +359,16 @@ export function installFetchRuntime(force = false) {
307
359
  global.Request = RequestPolyfill;
308
360
  if (force || typeof global.Response !== 'function')
309
361
  global.Response = ResponsePolyfill;
362
+ if (force || typeof global.Blob !== 'function')
363
+ global.Blob = BlobPolyfill;
364
+ if (force || typeof global.AbortSignal !== 'function')
365
+ global.AbortSignal = AbortSignalPolyfill;
366
+ if (force || typeof global.AbortController !== 'function') {
367
+ global.AbortController = AbortControllerPolyfill;
368
+ }
369
+ // mqtt's browser abort-controller reads AbortController from self or window.
370
+ if (force || typeof global.self !== 'object' || global.self === null)
371
+ global.self = globalThis;
310
372
  if (force || typeof global.console !== 'object' || global.console === null) {
311
373
  global.console = noopConsole;
312
374
  }
@@ -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;
@@ -0,0 +1,3 @@
1
+ import { promises } from './fs.js';
2
+ export const { access, appendFile, lstat, mkdir, readFile, readdir, rename, rm, stat, unlink, writeFile, } = promises;
3
+ export default promises;
@@ -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;
@@ -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 typeof Buffer === 'undefined' ? bytes : Buffer.from(bytes);
66
+ return asBuffer(bytes);
48
67
  }
49
68
  export function writeFileSync(path, data, _encoding) {
50
- nodeCompatSeed.files[normalizeFsPath(String(path))] = asText(data);
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 = content.subarray(start, start + length);
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 EventEmitter {
18
+ export declare class Socket extends Stream {
18
19
  connecting: boolean;
19
20
  pending: boolean;
20
21
  destroyed: boolean;
@@ -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
- export class Socket extends EventEmitter {
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;
@@ -0,0 +1,87 @@
1
+ /** The wasi:filesystem@0.2.12 descriptor methods the storage backend calls. */
2
+ export type WasiDescriptor = {
3
+ openAt(pathFlags: {
4
+ symlinkFollow?: boolean;
5
+ }, path: string, openFlags: {
6
+ create?: boolean;
7
+ directory?: boolean;
8
+ exclusive?: boolean;
9
+ truncate?: boolean;
10
+ }, flags: {
11
+ read?: boolean;
12
+ write?: boolean;
13
+ mutateDirectory?: boolean;
14
+ }): WasiDescriptor;
15
+ read(length: number, offset: number): [Uint8Array | number[], boolean];
16
+ write(buffer: Uint8Array, offset: number): number;
17
+ setSize(size: number): void;
18
+ stat(): WasiStat;
19
+ statAt(pathFlags: {
20
+ symlinkFollow?: boolean;
21
+ }, path: string): WasiStat;
22
+ createDirectoryAt(path: string): void;
23
+ readDirectory(): {
24
+ readDirectoryEntry(): {
25
+ type: string;
26
+ name: string;
27
+ } | null;
28
+ };
29
+ removeDirectoryAt(path: string): void;
30
+ renameAt(oldPath: string, newDescriptor: WasiDescriptor, newPath: string): void;
31
+ unlinkFileAt(path: string): void;
32
+ };
33
+ type WasiStat = {
34
+ type: string;
35
+ size: number | bigint;
36
+ dataModificationTimestamp?: {
37
+ seconds: number | bigint;
38
+ nanoseconds: number;
39
+ } | null;
40
+ };
41
+ export type Preopen = [WasiDescriptor, string];
42
+ export type StorageStat = {
43
+ directory: boolean;
44
+ size: number;
45
+ mtimeMs: number;
46
+ };
47
+ export type StorageEntry = {
48
+ name: string;
49
+ directory: boolean;
50
+ };
51
+ export type StorageError = Error & {
52
+ code: string;
53
+ errno: number;
54
+ syscall: string;
55
+ path: string;
56
+ };
57
+ /** Map a thrown wasi:filesystem error-code to a Node.js-shaped error. */
58
+ export declare function storageError(error: unknown, syscall: string, path: string): StorageError;
59
+ /** Storage mounts the deploy manifest can request: `/data`, or `DI_STORAGE_DIR` when set. */
60
+ declare function defaultPrefixes(): string[];
61
+ /**
62
+ * Paths under a host-mounted directory (the platform's `/data` preopen) live in
63
+ * wasi:filesystem so every workload member sees them. Only absolute, non-root preopens
64
+ * qualify; every other path stays in the guest's in-memory filesystem. Preopens are
65
+ * read on the first storage path, never at module initialization: only paths under a
66
+ * storage prefix consult them.
67
+ */
68
+ export declare function createStorage(preopens: () => Preopen[], prefixes?: typeof defaultPrefixes): {
69
+ owns(path: string): boolean;
70
+ readFile(path: string): Uint8Array;
71
+ writeFile(path: string, bytes: Uint8Array): void;
72
+ appendFile(path: string, bytes: Uint8Array): void;
73
+ readAt(path: string, length: number, offset: number): Uint8Array;
74
+ writeAt(path: string, bytes: Uint8Array, offset: number | "end"): number;
75
+ truncate(path: string): void;
76
+ stat: (path: string) => StorageStat;
77
+ exists: (path: string) => boolean;
78
+ readdir: (path: string) => StorageEntry[];
79
+ mkdir: (path: string, recursive: boolean) => void;
80
+ remove: (path: string, recursive: boolean) => void;
81
+ unlink(path: string): void;
82
+ rename(from: string, to: string): void;
83
+ };
84
+ export type Storage = ReturnType<typeof createStorage>;
85
+ /** The guest's storage, backed by the host's preopened directories. */
86
+ export declare const storage: Storage;
87
+ export {};