@run0/jiki 0.1.0

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 (152) hide show
  1. package/dist/browser-bundle.d.ts +40 -0
  2. package/dist/builtins.d.ts +22 -0
  3. package/dist/code-transform.d.ts +7 -0
  4. package/dist/config/cdn.d.ts +13 -0
  5. package/dist/container.d.ts +101 -0
  6. package/dist/dev-server.d.ts +69 -0
  7. package/dist/errors.d.ts +19 -0
  8. package/dist/frameworks/code-transforms.d.ts +32 -0
  9. package/dist/frameworks/next-api-handler.d.ts +72 -0
  10. package/dist/frameworks/next-dev-server.d.ts +141 -0
  11. package/dist/frameworks/next-html-generator.d.ts +36 -0
  12. package/dist/frameworks/next-route-resolver.d.ts +19 -0
  13. package/dist/frameworks/next-shims.d.ts +78 -0
  14. package/dist/frameworks/remix-dev-server.d.ts +47 -0
  15. package/dist/frameworks/sveltekit-dev-server.d.ts +43 -0
  16. package/dist/frameworks/vite-dev-server.d.ts +50 -0
  17. package/dist/fs-errors.d.ts +36 -0
  18. package/dist/index.cjs +14916 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.ts +61 -0
  21. package/dist/index.mjs +14898 -0
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/kernel.d.ts +48 -0
  24. package/dist/memfs.d.ts +144 -0
  25. package/dist/metrics.d.ts +78 -0
  26. package/dist/module-resolver.d.ts +60 -0
  27. package/dist/network-interceptor.d.ts +71 -0
  28. package/dist/npm/cache.d.ts +76 -0
  29. package/dist/npm/index.d.ts +60 -0
  30. package/dist/npm/lockfile-reader.d.ts +32 -0
  31. package/dist/npm/pnpm.d.ts +18 -0
  32. package/dist/npm/registry.d.ts +45 -0
  33. package/dist/npm/resolver.d.ts +39 -0
  34. package/dist/npm/sync-installer.d.ts +18 -0
  35. package/dist/npm/tarball.d.ts +4 -0
  36. package/dist/npm/workspaces.d.ts +46 -0
  37. package/dist/persistence.d.ts +94 -0
  38. package/dist/plugin.d.ts +156 -0
  39. package/dist/polyfills/assert.d.ts +30 -0
  40. package/dist/polyfills/child_process.d.ts +116 -0
  41. package/dist/polyfills/chokidar.d.ts +18 -0
  42. package/dist/polyfills/crypto.d.ts +49 -0
  43. package/dist/polyfills/events.d.ts +28 -0
  44. package/dist/polyfills/fs.d.ts +82 -0
  45. package/dist/polyfills/http.d.ts +147 -0
  46. package/dist/polyfills/module.d.ts +29 -0
  47. package/dist/polyfills/net.d.ts +53 -0
  48. package/dist/polyfills/os.d.ts +91 -0
  49. package/dist/polyfills/path.d.ts +96 -0
  50. package/dist/polyfills/perf_hooks.d.ts +21 -0
  51. package/dist/polyfills/process.d.ts +99 -0
  52. package/dist/polyfills/querystring.d.ts +15 -0
  53. package/dist/polyfills/readdirp.d.ts +18 -0
  54. package/dist/polyfills/readline.d.ts +32 -0
  55. package/dist/polyfills/stream.d.ts +106 -0
  56. package/dist/polyfills/stubs.d.ts +737 -0
  57. package/dist/polyfills/tty.d.ts +25 -0
  58. package/dist/polyfills/url.d.ts +41 -0
  59. package/dist/polyfills/util.d.ts +61 -0
  60. package/dist/polyfills/v8.d.ts +43 -0
  61. package/dist/polyfills/vm.d.ts +76 -0
  62. package/dist/polyfills/worker-threads.d.ts +77 -0
  63. package/dist/polyfills/ws.d.ts +32 -0
  64. package/dist/polyfills/zlib.d.ts +87 -0
  65. package/dist/runtime-helpers.d.ts +4 -0
  66. package/dist/runtime-interface.d.ts +39 -0
  67. package/dist/sandbox.d.ts +69 -0
  68. package/dist/server-bridge.d.ts +55 -0
  69. package/dist/shell-commands.d.ts +2 -0
  70. package/dist/shell.d.ts +101 -0
  71. package/dist/transpiler.d.ts +47 -0
  72. package/dist/type-checker.d.ts +57 -0
  73. package/dist/types/package-json.d.ts +17 -0
  74. package/dist/utils/binary-encoding.d.ts +4 -0
  75. package/dist/utils/hash.d.ts +6 -0
  76. package/dist/utils/safe-path.d.ts +6 -0
  77. package/dist/worker-runtime.d.ts +34 -0
  78. package/package.json +59 -0
  79. package/src/browser-bundle.ts +498 -0
  80. package/src/builtins.ts +222 -0
  81. package/src/code-transform.ts +183 -0
  82. package/src/config/cdn.ts +17 -0
  83. package/src/container.ts +343 -0
  84. package/src/dev-server.ts +322 -0
  85. package/src/errors.ts +604 -0
  86. package/src/frameworks/code-transforms.ts +667 -0
  87. package/src/frameworks/next-api-handler.ts +366 -0
  88. package/src/frameworks/next-dev-server.ts +1252 -0
  89. package/src/frameworks/next-html-generator.ts +585 -0
  90. package/src/frameworks/next-route-resolver.ts +521 -0
  91. package/src/frameworks/next-shims.ts +1084 -0
  92. package/src/frameworks/remix-dev-server.ts +163 -0
  93. package/src/frameworks/sveltekit-dev-server.ts +197 -0
  94. package/src/frameworks/vite-dev-server.ts +370 -0
  95. package/src/fs-errors.ts +118 -0
  96. package/src/index.ts +188 -0
  97. package/src/kernel.ts +381 -0
  98. package/src/memfs.ts +1006 -0
  99. package/src/metrics.ts +140 -0
  100. package/src/module-resolver.ts +511 -0
  101. package/src/network-interceptor.ts +143 -0
  102. package/src/npm/cache.ts +172 -0
  103. package/src/npm/index.ts +377 -0
  104. package/src/npm/lockfile-reader.ts +105 -0
  105. package/src/npm/pnpm.ts +108 -0
  106. package/src/npm/registry.ts +120 -0
  107. package/src/npm/resolver.ts +339 -0
  108. package/src/npm/sync-installer.ts +217 -0
  109. package/src/npm/tarball.ts +136 -0
  110. package/src/npm/workspaces.ts +255 -0
  111. package/src/persistence.ts +235 -0
  112. package/src/plugin.ts +293 -0
  113. package/src/polyfills/assert.ts +164 -0
  114. package/src/polyfills/child_process.ts +535 -0
  115. package/src/polyfills/chokidar.ts +52 -0
  116. package/src/polyfills/crypto.ts +433 -0
  117. package/src/polyfills/events.ts +178 -0
  118. package/src/polyfills/fs.ts +297 -0
  119. package/src/polyfills/http.ts +478 -0
  120. package/src/polyfills/module.ts +97 -0
  121. package/src/polyfills/net.ts +123 -0
  122. package/src/polyfills/os.ts +108 -0
  123. package/src/polyfills/path.ts +169 -0
  124. package/src/polyfills/perf_hooks.ts +30 -0
  125. package/src/polyfills/process.ts +349 -0
  126. package/src/polyfills/querystring.ts +66 -0
  127. package/src/polyfills/readdirp.ts +72 -0
  128. package/src/polyfills/readline.ts +80 -0
  129. package/src/polyfills/stream.ts +610 -0
  130. package/src/polyfills/stubs.ts +600 -0
  131. package/src/polyfills/tty.ts +43 -0
  132. package/src/polyfills/url.ts +97 -0
  133. package/src/polyfills/util.ts +173 -0
  134. package/src/polyfills/v8.ts +62 -0
  135. package/src/polyfills/vm.ts +111 -0
  136. package/src/polyfills/worker-threads.ts +189 -0
  137. package/src/polyfills/ws.ts +73 -0
  138. package/src/polyfills/zlib.ts +244 -0
  139. package/src/runtime-helpers.ts +83 -0
  140. package/src/runtime-interface.ts +46 -0
  141. package/src/sandbox.ts +178 -0
  142. package/src/server-bridge.ts +473 -0
  143. package/src/service-worker.ts +153 -0
  144. package/src/shell-commands.ts +708 -0
  145. package/src/shell.ts +795 -0
  146. package/src/transpiler.ts +282 -0
  147. package/src/type-checker.ts +241 -0
  148. package/src/types/package-json.ts +17 -0
  149. package/src/utils/binary-encoding.ts +38 -0
  150. package/src/utils/hash.ts +24 -0
  151. package/src/utils/safe-path.ts +38 -0
  152. package/src/worker-runtime.ts +42 -0
@@ -0,0 +1,25 @@
1
+ import { Readable, Writable } from "./stream";
2
+ export declare class ReadStream extends Readable {
3
+ isTTY: boolean;
4
+ isRaw: boolean;
5
+ setRawMode(mode: boolean): this;
6
+ }
7
+ export declare class WriteStream extends Writable {
8
+ isTTY: boolean;
9
+ columns: number;
10
+ rows: number;
11
+ getColorDepth(): number;
12
+ hasColors(count?: number): boolean;
13
+ getWindowSize(): [number, number];
14
+ clearLine(_dir: number, _cb?: () => void): boolean;
15
+ clearScreenDown(_cb?: () => void): boolean;
16
+ cursorTo(_x: number, _y?: number, _cb?: () => void): boolean;
17
+ moveCursor(_dx: number, _dy: number, _cb?: () => void): boolean;
18
+ }
19
+ export declare function isatty(_fd: number): boolean;
20
+ declare const _default: {
21
+ ReadStream: typeof ReadStream;
22
+ WriteStream: typeof WriteStream;
23
+ isatty: typeof isatty;
24
+ };
25
+ export default _default;
@@ -0,0 +1,41 @@
1
+ export declare const URL: {
2
+ new (url: string | URL, base?: string | URL): URL;
3
+ prototype: URL;
4
+ canParse(url: string | URL, base?: string | URL): boolean;
5
+ createObjectURL(obj: Blob | MediaSource): string;
6
+ parse(url: string | URL, base?: string | URL): URL | null;
7
+ revokeObjectURL(url: string): void;
8
+ };
9
+ export declare const URLSearchParams: {
10
+ new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
11
+ prototype: URLSearchParams;
12
+ };
13
+ export declare function parse(urlString: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): Record<string, unknown>;
14
+ export declare function format(urlObj: Record<string, unknown>): string;
15
+ export declare function resolve(from: string, to: string): string;
16
+ export declare function fileURLToPath(url: string | URL): string;
17
+ export declare function pathToFileURL(path: string): URL;
18
+ export declare function domainToASCII(domain: string): string;
19
+ export declare function domainToUnicode(domain: string): string;
20
+ declare const _default: {
21
+ URL: {
22
+ new (url: string | URL, base?: string | URL): URL;
23
+ prototype: URL;
24
+ canParse(url: string | URL, base?: string | URL): boolean;
25
+ createObjectURL(obj: Blob | MediaSource): string;
26
+ parse(url: string | URL, base?: string | URL): URL | null;
27
+ revokeObjectURL(url: string): void;
28
+ };
29
+ URLSearchParams: {
30
+ new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
31
+ prototype: URLSearchParams;
32
+ };
33
+ parse: typeof parse;
34
+ format: typeof format;
35
+ resolve: typeof resolve;
36
+ fileURLToPath: typeof fileURLToPath;
37
+ pathToFileURL: typeof pathToFileURL;
38
+ domainToASCII: typeof domainToASCII;
39
+ domainToUnicode: typeof domainToUnicode;
40
+ };
41
+ export default _default;
@@ -0,0 +1,61 @@
1
+ export declare function format(fmt: unknown, ...args: unknown[]): string;
2
+ export declare function inspect(obj: unknown, opts?: {
3
+ depth?: number;
4
+ colors?: boolean;
5
+ }): string;
6
+ export declare namespace inspect {
7
+ var custom: symbol;
8
+ }
9
+ export declare function inherits(ctor: Function, superCtor: Function): void;
10
+ export declare function deprecate<T extends Function>(fn: T, msg: string): T;
11
+ export declare function promisify<T extends Function>(fn: T): (...args: unknown[]) => Promise<unknown>;
12
+ export declare function callbackify(fn: (...args: unknown[]) => Promise<unknown>): (...args: unknown[]) => void;
13
+ export declare function debuglog(section: string): (...args: unknown[]) => void;
14
+ export declare function isDeepStrictEqual(a: unknown, b: unknown): boolean;
15
+ export declare const types: {
16
+ isDate: (v: unknown) => v is Date;
17
+ isRegExp: (v: unknown) => v is RegExp;
18
+ isPromise: (v: unknown) => v is Promise<unknown>;
19
+ isMap: (v: unknown) => v is Map<unknown, unknown>;
20
+ isSet: (v: unknown) => v is Set<unknown>;
21
+ isTypedArray: (v: unknown) => boolean;
22
+ isUint8Array: (v: unknown) => v is Uint8Array;
23
+ isArrayBuffer: (v: unknown) => v is ArrayBuffer;
24
+ isSharedArrayBuffer: (v: unknown) => boolean;
25
+ isProxy: (_v: unknown) => boolean;
26
+ isNativeError: (v: unknown) => v is Error;
27
+ isGeneratorFunction: (v: unknown) => boolean;
28
+ isAsyncFunction: (v: unknown) => boolean;
29
+ };
30
+ export declare class TextEncoder extends globalThis.TextEncoder {
31
+ }
32
+ export declare class TextDecoder extends globalThis.TextDecoder {
33
+ }
34
+ declare const _default: {
35
+ format: typeof format;
36
+ inspect: typeof inspect;
37
+ inherits: typeof inherits;
38
+ deprecate: typeof deprecate;
39
+ promisify: typeof promisify;
40
+ callbackify: typeof callbackify;
41
+ debuglog: typeof debuglog;
42
+ isDeepStrictEqual: typeof isDeepStrictEqual;
43
+ types: {
44
+ isDate: (v: unknown) => v is Date;
45
+ isRegExp: (v: unknown) => v is RegExp;
46
+ isPromise: (v: unknown) => v is Promise<unknown>;
47
+ isMap: (v: unknown) => v is Map<unknown, unknown>;
48
+ isSet: (v: unknown) => v is Set<unknown>;
49
+ isTypedArray: (v: unknown) => boolean;
50
+ isUint8Array: (v: unknown) => v is Uint8Array;
51
+ isArrayBuffer: (v: unknown) => v is ArrayBuffer;
52
+ isSharedArrayBuffer: (v: unknown) => boolean;
53
+ isProxy: (_v: unknown) => boolean;
54
+ isNativeError: (v: unknown) => v is Error;
55
+ isGeneratorFunction: (v: unknown) => boolean;
56
+ isAsyncFunction: (v: unknown) => boolean;
57
+ };
58
+ TextEncoder: typeof TextEncoder;
59
+ TextDecoder: typeof TextDecoder;
60
+ };
61
+ export default _default;
@@ -0,0 +1,43 @@
1
+ export declare function getHeapStatistics(): Record<string, number>;
2
+ export declare function getHeapSpaceStatistics(): Record<string, unknown>[];
3
+ export declare function getHeapSnapshot(): unknown;
4
+ export declare function writeHeapSnapshot(_filename?: string): string;
5
+ export declare function setFlagsFromString(_flags: string): void;
6
+ export declare function serialize(value: unknown): Uint8Array;
7
+ export declare function deserialize(buffer: Uint8Array): unknown;
8
+ export declare const DefaultSerializer: {
9
+ new (): {
10
+ writeHeader(): void;
11
+ writeValue(_v: unknown): void;
12
+ releaseBuffer(): Uint8Array<ArrayBuffer>;
13
+ };
14
+ };
15
+ export declare const DefaultDeserializer: {
16
+ new (_buf: Uint8Array): {
17
+ readHeader(): void;
18
+ readValue(): null;
19
+ };
20
+ };
21
+ declare const _default: {
22
+ getHeapStatistics: typeof getHeapStatistics;
23
+ getHeapSpaceStatistics: typeof getHeapSpaceStatistics;
24
+ getHeapSnapshot: typeof getHeapSnapshot;
25
+ writeHeapSnapshot: typeof writeHeapSnapshot;
26
+ setFlagsFromString: typeof setFlagsFromString;
27
+ serialize: typeof serialize;
28
+ deserialize: typeof deserialize;
29
+ DefaultSerializer: {
30
+ new (): {
31
+ writeHeader(): void;
32
+ writeValue(_v: unknown): void;
33
+ releaseBuffer(): Uint8Array<ArrayBuffer>;
34
+ };
35
+ };
36
+ DefaultDeserializer: {
37
+ new (_buf: Uint8Array): {
38
+ readHeader(): void;
39
+ readValue(): null;
40
+ };
41
+ };
42
+ };
43
+ export default _default;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Browser polyfill for Node.js `vm` module.
3
+ *
4
+ * **IMPORTANT: Security Limitation**
5
+ *
6
+ * This is NOT a true sandbox. In Node.js, `vm` creates a V8 context with its own
7
+ * global object, providing isolation from the host environment. In the browser,
8
+ * this polyfill uses `new Function()` which executes code in the same JavaScript
9
+ * realm as the host page.
10
+ *
11
+ * Implications:
12
+ * - Code executed via `runInContext()` / `runInNewContext()` can access and modify
13
+ * global browser objects (window, document, etc.) through prototype chain traversal.
14
+ * - There is NO memory isolation — the executed code shares the same heap.
15
+ * - `createContext()` simply returns the sandbox object without creating an isolated context.
16
+ * - The `Script` class wraps code in `new Function()`, not a separate V8 context.
17
+ *
18
+ * This polyfill is suitable for:
19
+ * - Module evaluation (CommonJS require simulation)
20
+ * - Template rendering that expects vm-like API
21
+ * - Code that uses vm for convenience, not security
22
+ *
23
+ * This polyfill is NOT suitable for:
24
+ * - Untrusted code execution
25
+ * - Security sandboxing
26
+ * - Scenarios requiring true memory/scope isolation
27
+ *
28
+ * @module vm
29
+ */
30
+ /**
31
+ * Create a "context" from a sandbox object.
32
+ * In the browser, this simply returns the sandbox as-is since we cannot
33
+ * create a true V8 context. The returned object is used as the scope
34
+ * for `runInContext()`.
35
+ */
36
+ export declare function createContext(sandbox?: Record<string, unknown>): Record<string, unknown>;
37
+ /**
38
+ * Execute code in the given context.
39
+ * Uses `new Function()` — does NOT provide true V8 context isolation.
40
+ * @see Module-level JSDoc for security limitations.
41
+ */
42
+ export declare function runInContext(code: string, context: Record<string, unknown>): unknown;
43
+ /**
44
+ * Execute code in a new context created from the sandbox.
45
+ * Equivalent to `runInContext(code, createContext(sandbox))`.
46
+ * @see Module-level JSDoc for security limitations.
47
+ */
48
+ export declare function runInNewContext(code: string, sandbox?: Record<string, unknown>): unknown;
49
+ /**
50
+ * Execute code in the current global context via `new Function()`.
51
+ * @see Module-level JSDoc for security limitations.
52
+ */
53
+ export declare function runInThisContext(code: string): unknown;
54
+ /** Always returns true since we cannot distinguish real V8 contexts in the browser. */
55
+ export declare function isContext(_sandbox: unknown): boolean;
56
+ /**
57
+ * Wraps code in a `new Function()` call for deferred execution.
58
+ * Does NOT create a V8 Script object — no compilation caching occurs.
59
+ * @see Module-level JSDoc for security limitations.
60
+ */
61
+ export declare class Script {
62
+ private code;
63
+ constructor(code: string, _options?: unknown);
64
+ runInContext(context: Record<string, unknown>): unknown;
65
+ runInNewContext(sandbox?: Record<string, unknown>): unknown;
66
+ runInThisContext(): unknown;
67
+ }
68
+ declare const _default: {
69
+ createContext: typeof createContext;
70
+ runInContext: typeof runInContext;
71
+ runInNewContext: typeof runInNewContext;
72
+ runInThisContext: typeof runInThisContext;
73
+ isContext: typeof isContext;
74
+ Script: typeof Script;
75
+ };
76
+ export default _default;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Enhanced worker_threads polyfill.
3
+ *
4
+ * Provides a more complete implementation of Node.js worker_threads API.
5
+ * When Web Workers are available (browser), `new Worker()` spawns a real
6
+ * Web Worker for parallel execution. When unavailable (tests), it falls
7
+ * back to in-process emulation via EventEmitter pairs.
8
+ *
9
+ * Supported:
10
+ * - `Worker` class with `postMessage`/`on('message')` communication
11
+ * - `parentPort` for child-to-parent messaging
12
+ * - `workerData` for initial data transfer
13
+ * - `isMainThread` flag
14
+ * - `threadId` counter
15
+ * - `MessageChannel` / `MessagePort` pairs
16
+ */
17
+ import { EventEmitter } from "./events";
18
+ export declare class MessagePort extends EventEmitter {
19
+ private _partner;
20
+ private _started;
21
+ private _closed;
22
+ private _queue;
23
+ postMessage(value: unknown): void;
24
+ start(): void;
25
+ close(): void;
26
+ ref(): this;
27
+ unref(): this;
28
+ /** @internal Connect two ports as partners. */
29
+ static _pair(): [MessagePort, MessagePort];
30
+ }
31
+ export declare class MessageChannel {
32
+ port1: MessagePort;
33
+ port2: MessagePort;
34
+ constructor();
35
+ }
36
+ export declare class Worker extends EventEmitter {
37
+ readonly threadId: number;
38
+ private _port;
39
+ private _workerPort;
40
+ constructor(_filename: string, options?: {
41
+ workerData?: unknown;
42
+ eval?: boolean;
43
+ });
44
+ postMessage(value: unknown): void;
45
+ terminate(): Promise<number>;
46
+ ref(): this;
47
+ unref(): this;
48
+ }
49
+ /** Whether the current context is the main thread. */
50
+ export declare const isMainThread = true;
51
+ /** Thread ID of the current thread. */
52
+ export declare const threadId = 0;
53
+ /** Parent port (only available inside a worker thread). */
54
+ export declare const parentPort: MessagePort | null;
55
+ /** Data passed to the worker via `workerData` option. */
56
+ export declare const workerData: unknown;
57
+ /**
58
+ * Get the last created worker's port (for testing).
59
+ * @internal
60
+ */
61
+ export declare function _getLastWorkerPort(): MessagePort | null;
62
+ /**
63
+ * Get the last created worker's data (for testing).
64
+ * @internal
65
+ */
66
+ export declare function _getLastWorkerData(): unknown;
67
+ /** Default export matching Node.js worker_threads module shape. */
68
+ declare const _default: {
69
+ Worker: typeof Worker;
70
+ isMainThread: boolean;
71
+ parentPort: null;
72
+ workerData: unknown;
73
+ threadId: number;
74
+ MessageChannel: typeof MessageChannel;
75
+ MessagePort: typeof MessagePort;
76
+ };
77
+ export default _default;
@@ -0,0 +1,32 @@
1
+ import { EventEmitter } from "./events";
2
+ export declare class WebSocketShim extends EventEmitter {
3
+ readyState: number;
4
+ url: string;
5
+ static CONNECTING: number;
6
+ static OPEN: number;
7
+ static CLOSING: number;
8
+ static CLOSED: number;
9
+ CONNECTING: number;
10
+ OPEN: number;
11
+ CLOSING: number;
12
+ CLOSED: number;
13
+ private _ws;
14
+ constructor(url: string, _protocols?: string | string[], _options?: unknown);
15
+ send(data: unknown, _options?: unknown, cb?: (err?: Error) => void): void;
16
+ close(code?: number, reason?: string): void;
17
+ ping(_data?: unknown, _mask?: boolean, _cb?: () => void): void;
18
+ pong(_data?: unknown, _mask?: boolean, _cb?: () => void): void;
19
+ terminate(): void;
20
+ }
21
+ export declare class WebSocketServer extends EventEmitter {
22
+ clients: Set<WebSocketShim>;
23
+ constructor(_options?: unknown);
24
+ close(_cb?: () => void): void;
25
+ address(): {
26
+ port: number;
27
+ family: string;
28
+ address: string;
29
+ };
30
+ }
31
+ export { WebSocketShim as WebSocket };
32
+ export default WebSocketShim;
@@ -0,0 +1,87 @@
1
+ import pako from "pako";
2
+ import { BufferImpl, Transform } from "./stream";
3
+ export declare function gzipSync(data: string | Uint8Array): BufferImpl;
4
+ export declare function gunzipSync(data: Uint8Array): BufferImpl;
5
+ export declare function deflateSync(data: string | Uint8Array): BufferImpl;
6
+ export declare function inflateSync(data: Uint8Array): BufferImpl;
7
+ export declare function deflateRawSync(data: string | Uint8Array): BufferImpl;
8
+ export declare function inflateRawSync(data: Uint8Array): BufferImpl;
9
+ export declare function gzip(data: string | Uint8Array, cb: (err: Error | null, result?: BufferImpl) => void): void;
10
+ export declare function gunzip(data: Uint8Array, cb: (err: Error | null, result?: BufferImpl) => void): void;
11
+ export declare function deflate(data: string | Uint8Array, cb: (err: Error | null, result?: BufferImpl) => void): void;
12
+ export declare function inflate(data: Uint8Array, cb: (err: Error | null, result?: BufferImpl) => void): void;
13
+ export declare function unzipSync(data: Uint8Array): BufferImpl;
14
+ export declare function unzip(data: Uint8Array, cb: (err: Error | null, result?: BufferImpl) => void): void;
15
+ declare class ZlibTransform extends Transform {
16
+ private processor;
17
+ private _chunks;
18
+ constructor(processor: pako.Deflate | pako.Inflate);
19
+ _transform(chunk: unknown, _encoding: string, callback: (err?: Error | null, data?: unknown) => void): void;
20
+ _flush(callback: (err?: Error | null, data?: unknown) => void): void;
21
+ end(chunkOrCb?: unknown, encodingOrCb?: string | (() => void), cb?: () => void): this;
22
+ }
23
+ export declare function createGzip(): ZlibTransform;
24
+ export declare function createGunzip(): ZlibTransform;
25
+ export declare function createDeflate(): ZlibTransform;
26
+ export declare function createInflate(): ZlibTransform;
27
+ export declare function brotliCompressSync(data: string | Uint8Array): BufferImpl;
28
+ export declare function brotliDecompressSync(data: Uint8Array): BufferImpl;
29
+ export declare const constants: {
30
+ Z_NO_FLUSH: number;
31
+ Z_PARTIAL_FLUSH: number;
32
+ Z_SYNC_FLUSH: number;
33
+ Z_FULL_FLUSH: number;
34
+ Z_FINISH: number;
35
+ Z_OK: number;
36
+ Z_STREAM_END: number;
37
+ Z_NEED_DICT: number;
38
+ Z_ERRNO: number;
39
+ Z_STREAM_ERROR: number;
40
+ Z_DEFAULT_COMPRESSION: number;
41
+ Z_BEST_SPEED: number;
42
+ Z_BEST_COMPRESSION: number;
43
+ Z_NO_COMPRESSION: number;
44
+ BROTLI_OPERATION_PROCESS: number;
45
+ BROTLI_OPERATION_FLUSH: number;
46
+ BROTLI_OPERATION_FINISH: number;
47
+ };
48
+ declare const _default: {
49
+ gzip: typeof gzip;
50
+ gzipSync: typeof gzipSync;
51
+ gunzip: typeof gunzip;
52
+ gunzipSync: typeof gunzipSync;
53
+ deflate: typeof deflate;
54
+ deflateSync: typeof deflateSync;
55
+ inflate: typeof inflate;
56
+ inflateSync: typeof inflateSync;
57
+ deflateRawSync: typeof deflateRawSync;
58
+ inflateRawSync: typeof inflateRawSync;
59
+ unzip: typeof unzip;
60
+ unzipSync: typeof unzipSync;
61
+ brotliCompressSync: typeof brotliCompressSync;
62
+ brotliDecompressSync: typeof brotliDecompressSync;
63
+ createGzip: typeof createGzip;
64
+ createGunzip: typeof createGunzip;
65
+ createDeflate: typeof createDeflate;
66
+ createInflate: typeof createInflate;
67
+ constants: {
68
+ Z_NO_FLUSH: number;
69
+ Z_PARTIAL_FLUSH: number;
70
+ Z_SYNC_FLUSH: number;
71
+ Z_FULL_FLUSH: number;
72
+ Z_FINISH: number;
73
+ Z_OK: number;
74
+ Z_STREAM_END: number;
75
+ Z_NEED_DICT: number;
76
+ Z_ERRNO: number;
77
+ Z_STREAM_ERROR: number;
78
+ Z_DEFAULT_COMPRESSION: number;
79
+ Z_BEST_SPEED: number;
80
+ Z_BEST_COMPRESSION: number;
81
+ Z_NO_COMPRESSION: number;
82
+ BROTLI_OPERATION_PROCESS: number;
83
+ BROTLI_OPERATION_FLUSH: number;
84
+ BROTLI_OPERATION_FINISH: number;
85
+ };
86
+ };
87
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type { RequireFunction } from "./kernel";
2
+ export declare function wrapDynamicImport(localRequire: RequireFunction): (specifier: string) => Promise<unknown>;
3
+ export declare function buildConsoleProxy(hook?: (method: string, args: unknown[]) => void): typeof console | Record<string, (...args: unknown[]) => void>;
4
+ export declare function buildModuleWrapper(code: string, filename?: string): (exports: unknown, require: RequireFunction, mod: unknown, __filename: string, __dirname: string, process: unknown, console: unknown, import_meta: unknown, __dynamicImport: unknown) => void;
@@ -0,0 +1,39 @@
1
+ import type { MemFS } from "./memfs";
2
+ export interface IRuntimeOptions {
3
+ cwd?: string;
4
+ env?: Record<string, string>;
5
+ onConsole?: (method: string, args: unknown[]) => void;
6
+ }
7
+ export interface IModule {
8
+ id: string;
9
+ filename: string;
10
+ exports: unknown;
11
+ loaded: boolean;
12
+ children: IModule[];
13
+ paths: string[];
14
+ }
15
+ export interface IExecuteResult {
16
+ exports: unknown;
17
+ module: IModule;
18
+ }
19
+ export interface IRuntime {
20
+ execute(code: string, filename?: string): Promise<IExecuteResult>;
21
+ runFile(filename: string): Promise<IExecuteResult>;
22
+ clearCache(): void;
23
+ getVFS?(): MemFS;
24
+ terminate?(): void;
25
+ }
26
+ export interface CreateRuntimeOptions extends IRuntimeOptions {
27
+ sandbox?: string;
28
+ dangerouslyAllowSameOrigin?: boolean;
29
+ useWorker?: boolean | "auto";
30
+ }
31
+ export interface VFSSnapshot {
32
+ files: VFSFileEntry[];
33
+ }
34
+ export interface VFSFileEntry {
35
+ path: string;
36
+ type: "file" | "directory" | "symlink";
37
+ content?: string;
38
+ target?: string;
39
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Resource limits and sandboxing for jiki containers.
3
+ *
4
+ * Provides configurable limits for memory, execution time, file count,
5
+ * network access, and filesystem path boundaries. Essential for
6
+ * production deployments where untrusted code runs.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const container = boot({
11
+ * sandbox: {
12
+ * limits: { maxMemoryMB: 256, maxExecutionMs: 30000, maxFileCount: 10000 },
13
+ * network: { allowedHosts: ['registry.npmjs.org'] },
14
+ * fs: { allowedPaths: ['/app', '/node_modules'] },
15
+ * },
16
+ * });
17
+ * ```
18
+ */
19
+ export interface SandboxLimits {
20
+ /** Maximum total VFS memory in megabytes. Default: unlimited. */
21
+ maxMemoryMB?: number;
22
+ /** Maximum execution time per run/execute call in milliseconds. Default: unlimited. */
23
+ maxExecutionMs?: number;
24
+ /** Maximum number of files in the VFS. Default: unlimited. */
25
+ maxFileCount?: number;
26
+ /** Maximum single file size in megabytes. Default: unlimited. */
27
+ maxFileSizeMB?: number;
28
+ }
29
+ export interface SandboxNetwork {
30
+ /** List of allowed hostnames for network requests. */
31
+ allowedHosts?: string[];
32
+ /** Block all network requests. */
33
+ blockAll?: boolean;
34
+ }
35
+ export interface SandboxFs {
36
+ /** List of allowed path prefixes. Writes outside these paths are rejected. */
37
+ allowedPaths?: string[];
38
+ /** Make the entire VFS read-only. */
39
+ readOnly?: boolean;
40
+ }
41
+ export interface SandboxOptions {
42
+ limits?: SandboxLimits;
43
+ network?: SandboxNetwork;
44
+ fs?: SandboxFs;
45
+ }
46
+ /**
47
+ * Enforces resource limits and access controls for a container.
48
+ */
49
+ export declare class SandboxGuard {
50
+ private opts;
51
+ private fileCount;
52
+ private totalBytes;
53
+ constructor(options?: SandboxOptions);
54
+ /** Check if the sandbox has any restrictions configured. */
55
+ get isActive(): boolean;
56
+ /** Check if a file write is allowed by size and count limits. */
57
+ checkWrite(path: string, sizeBytes: number): void;
58
+ /** Track a file being added to the VFS. */
59
+ trackWrite(sizeBytes: number): void;
60
+ /** Track a file being removed from the VFS. */
61
+ trackDelete(sizeBytes: number): void;
62
+ /** Check if a network request to the given URL is allowed. */
63
+ checkNetwork(url: string): void;
64
+ /** Get the execution timeout in milliseconds, or `undefined` if unlimited. */
65
+ get executionTimeout(): number | undefined;
66
+ get currentFileCount(): number;
67
+ get currentMemoryBytes(): number;
68
+ get currentMemoryMB(): number;
69
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Server Bridge
3
+ * Connects Service Worker requests to virtual HTTP servers running in-memory.
4
+ * Provides the illusion of real HTTP by intercepting /__virtual__/{port}/* URLs.
5
+ */
6
+ import { EventEmitter } from "./polyfills/events";
7
+ import { BufferImpl as Buffer } from "./polyfills/stream";
8
+ import type { ResponseData } from "./dev-server";
9
+ export interface IVirtualServer {
10
+ handleRequest(method: string, url: string, headers: Record<string, string>, body?: Buffer | string): Promise<ResponseData>;
11
+ handleStreamingRequest?(method: string, url: string, headers: Record<string, string>, body: Buffer | undefined, onStart: (statusCode: number, statusMessage: string, headers: Record<string, string>) => void, onChunk: (chunk: string | Uint8Array) => void, onEnd: () => void): Promise<void>;
12
+ }
13
+ export interface VirtualServer {
14
+ server: IVirtualServer;
15
+ port: number;
16
+ hostname: string;
17
+ }
18
+ export interface BridgeOptions {
19
+ baseUrl?: string;
20
+ onServerReady?: (port: number, url: string) => void;
21
+ }
22
+ export interface InitServiceWorkerOptions {
23
+ swUrl?: string;
24
+ }
25
+ export declare class ServerBridge extends EventEmitter {
26
+ static DEBUG: boolean;
27
+ /** Maximum time (ms) a queued request will wait for a server to become available. */
28
+ static REQUEST_QUEUE_TIMEOUT: number;
29
+ private servers;
30
+ private baseUrl;
31
+ private options;
32
+ private messageChannel;
33
+ private serviceWorkerReady;
34
+ private keepaliveInterval;
35
+ /** Requests queued while waiting for a server to register on a given port. */
36
+ private requestQueue;
37
+ constructor(options?: BridgeOptions);
38
+ registerServer(server: IVirtualServer, port: number, hostname?: string): void;
39
+ /**
40
+ * Process any queued requests waiting for a server on the given port.
41
+ */
42
+ private drainQueue;
43
+ unregisterServer(port: number): void;
44
+ getServerUrl(port: number): string;
45
+ getServerPorts(): number[];
46
+ handleRequest(port: number, method: string, url: string, headers: Record<string, string>, body?: ArrayBuffer): Promise<ResponseData>;
47
+ initServiceWorker(options?: InitServiceWorkerOptions): Promise<void>;
48
+ private handleServiceWorkerMessage;
49
+ private handleStreamingBridge;
50
+ createFetchHandler(): (request: Request) => Promise<Response>;
51
+ private notifyServiceWorker;
52
+ dispose(): void;
53
+ }
54
+ export declare function getServerBridge(options?: BridgeOptions): ServerBridge;
55
+ export declare function resetServerBridge(): void;
@@ -0,0 +1,2 @@
1
+ import type { CommandHandler } from "./shell";
2
+ export declare function createDefaultCommands(): Map<string, CommandHandler>;