@gjsify/utils 0.36.0 → 0.38.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.
- package/lib/types/callable.d.ts +13 -21
- package/lib/types/error.d.ts +1 -2
- package/lib/types/fs.d.ts +1 -1
- package/lib/types/gio-errors.d.ts +10 -1
- package/lib/types/gio.d.ts +3 -10
- package/lib/types/globals.d.ts +2 -2
- package/lib/types/host-os.d.ts +11 -15
- package/lib/types/host-process.d.ts +16 -23
- package/lib/types/main-loop.d.ts +17 -0
- package/lib/types/next-tick.d.ts +2 -3
- package/lib/types/structured-clone.d.ts +8 -15
- package/package.json +2 -2
package/lib/types/callable.d.ts
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Wrap an ES6 class so it supports
|
|
3
|
-
*
|
|
2
|
+
* Wrap an ES6 class so it supports `new Cls(...)`, `Cls.call(thisArg, ...)` and
|
|
3
|
+
* `Cls(...)` (no-`new`) alike.
|
|
4
4
|
*
|
|
5
5
|
* The `apply` trap has two modes:
|
|
6
6
|
*
|
|
7
|
-
* 1. **`Cls.call(thisArg, ...)`** — a
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* own property descriptors onto `thisArg`. This is how Node-era CJS
|
|
11
|
-
* consumers + `util.inherits(Sub, Cls)` chains expect to subclass our
|
|
12
|
-
* ES6 classes.
|
|
7
|
+
* 1. **`Cls.call(thisArg, ...)`** — materialise a temporary instance via
|
|
8
|
+
* `Reflect.construct` (so field initializers and constructor bodies run) and
|
|
9
|
+
* transplant its own property descriptors onto `thisArg`.
|
|
13
10
|
*
|
|
14
|
-
* 2. **`Cls(...)`**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* so consumers like `merge2` invoke `Stream.PassThrough(opts)` without
|
|
20
|
-
* `new` and rely on the result being a real instance. Without this
|
|
21
|
-
* branch the apply trap would crash with "undefined is not a non-null
|
|
22
|
-
* object" when it tried to `Object.defineProperty(thisArg, …)`.
|
|
11
|
+
* 2. **`Cls(...)`** — `thisArg` is `undefined` (strict) or `globalThis`
|
|
12
|
+
* (sloppy); construct instead. Node's stream constructors guard this
|
|
13
|
+
* explicitly (`if (!(this instanceof PassThrough)) return new PassThrough(…)`)
|
|
14
|
+
* and consumers like `merge2` rely on it. Without this branch the trap
|
|
15
|
+
* crashes on `Object.defineProperty(thisArg, …)`.
|
|
23
16
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* to the underlying class.
|
|
17
|
+
* `construct`, `get` and `getPrototypeOf` pass straight through, so
|
|
18
|
+
* `Wrapped.prototype` (consulted by `util.inherits`) and `instanceof` behave
|
|
19
|
+
* exactly as on the underlying class.
|
|
28
20
|
*/
|
|
29
21
|
export declare function makeCallable<T extends new (...args: unknown[]) => unknown>(Cls: T): T;
|
package/lib/types/error.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* this is not present in SpiderMonkey because it comes from V8
|
|
2
|
+
* Installs the V8-only static `Error.captureStackTrace` on engines that lack it.
|
|
4
3
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#static_methods
|
|
5
4
|
* @see https://nodejs.org/dist/latest-v18.x/docs/api/errors.html#errorcapturestacktracetargetobject-constructoropt
|
|
6
5
|
*/
|
package/lib/types/fs.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Gio.IOErrorEnum numeric value → Node error code.
|
|
3
|
+
*
|
|
4
|
+
* The trailing name on each row is the member that number ACTUALLY has, checked
|
|
5
|
+
* against `Gio.IOErrorEnum` on gjs 1.88.1; GLib's numbering is append-only, so it
|
|
6
|
+
* does not drift with the GIR version. Several rows pair a member with an errno that
|
|
7
|
+
* does not follow from it (12 is NO_SPACE yet maps to ELOOP, 24 is TIMED_OUT yet maps
|
|
8
|
+
* to EROFS, 31 is TOO_MANY_OPEN_FILES yet maps to ENETUNREACH): those are wrong
|
|
9
|
+
* mappings to repair, not aliases — do not "correct" the name back.
|
|
10
|
+
*/
|
|
2
11
|
export declare const GIO_ERROR_TO_NODE: Record<number, string>;
|
|
3
12
|
export interface NodeErrorDetails {
|
|
4
13
|
path?: string;
|
package/lib/types/gio.d.ts
CHANGED
|
@@ -8,16 +8,9 @@ import Gio from '@girs/gio-2.0';
|
|
|
8
8
|
export declare function gioAsync<T>(obj: any, asyncMethod: string, finishMethod: string, ...args: any[]): Promise<T>;
|
|
9
9
|
/**
|
|
10
10
|
* Promise wrapper around `Gio.InputStream.read_bytes_async` / `read_bytes_finish`.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Treats `G_IO_ERROR_PARTIAL_INPUT` as EOF: Soup3's chunked-decoding input
|
|
14
|
-
* stream surfaces this when the upstream closes the connection cleanly at a
|
|
15
|
-
* non-chunk boundary (common on the npm registry CDN). Without this, the
|
|
16
|
-
* fetch `Body.text()` path raises "Invalid response body" mid-read even
|
|
17
|
-
* though the full payload has already arrived. Bubble all other errors.
|
|
11
|
+
* `null` means end of stream; a clean-stream-end error counts as EOF (see the catch),
|
|
12
|
+
* everything else is bubbled.
|
|
18
13
|
*/
|
|
19
14
|
export declare function readBytesAsync(inputStream: Gio.InputStream, count?: number, ioPriority?: number, cancellable?: Gio.Cancellable | null): Promise<Uint8Array | null>;
|
|
20
|
-
/**
|
|
21
|
-
* Async generator that yields `Uint8Array` chunks from a `Gio.InputStream`.
|
|
22
|
-
*/
|
|
15
|
+
/** Yields `Uint8Array` chunks from a `Gio.InputStream` until EOF. */
|
|
23
16
|
export declare function inputStreamAsyncIterator(inputStream: Gio.InputStream, count?: number, ioPriority?: number, cancellable?: Gio.Cancellable | null): AsyncGenerator<Uint8Array>;
|
package/lib/types/globals.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Register
|
|
3
|
-
*
|
|
2
|
+
* Register `value` as a global only where that name is still free, so a web polyfill
|
|
3
|
+
* never displaces a host implementation that is already there.
|
|
4
4
|
*/
|
|
5
5
|
export declare function registerGlobal(name: string, value: unknown): void;
|
package/lib/types/host-os.d.ts
CHANGED
|
@@ -2,26 +2,22 @@ import type { ProcessPlatform } from './platform-names.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* The three operating systems ADR 0018 declares as the project's target set.
|
|
4
4
|
*
|
|
5
|
-
* Deliberately
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* are build-verified only and are an ARCH question, not an OS one — they live
|
|
10
|
-
* on the `gjsify.platforms` axis, which stays separate by design.
|
|
5
|
+
* Deliberately narrower than {@link ProcessPlatform} (Node's full vocabulary):
|
|
6
|
+
* `gjsify.os` keys are exactly these three and `os-axis` fails on any other key.
|
|
7
|
+
* The emulated `linux-{ppc64,s390x,riscv64}` targets are an ARCH question and
|
|
8
|
+
* live on the separate `gjsify.platforms` axis.
|
|
11
9
|
*/
|
|
12
10
|
export type TargetOs = 'linux' | 'darwin' | 'win32';
|
|
13
|
-
/** The target set as data,
|
|
11
|
+
/** The target set as data, for checks that iterate it. */
|
|
14
12
|
export declare const TARGET_OSES: readonly TargetOs[];
|
|
15
13
|
/** Is `value` one of the three declared target operating systems? */
|
|
16
14
|
export declare function isTargetOs(value: unknown): value is TargetOs;
|
|
17
15
|
/**
|
|
18
16
|
* The host's `process.platform`, or `undefined` where nothing answers.
|
|
19
17
|
*
|
|
20
|
-
* `undefined`
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* The defaulting belongs to `@gjsify/process`'s `detectPlatform()`, which has a
|
|
24
|
-
* uname probe to fall back ON; this module has none and must not pretend.
|
|
18
|
+
* Callers must treat `undefined` as "unknown", never as "not Windows". Nothing is
|
|
19
|
+
* defaulted here because this module has no uname probe to fall back on; that
|
|
20
|
+
* defaulting belongs to `@gjsify/process`'s `detectPlatform()`.
|
|
25
21
|
*/
|
|
26
22
|
export declare function hostPlatform(): ProcessPlatform | undefined;
|
|
27
23
|
/**
|
|
@@ -32,9 +28,9 @@ export declare function hostOs(): TargetOs | undefined;
|
|
|
32
28
|
/**
|
|
33
29
|
* Running on Windows?
|
|
34
30
|
*
|
|
35
|
-
* The predicate `it.failing(name, fn, reason, { when: isWin32() })`
|
|
36
|
-
* sanctioned way to
|
|
37
|
-
*
|
|
31
|
+
* The predicate for `it.failing(name, fn, reason, { when: isWin32() })` — the
|
|
32
|
+
* sanctioned way to park a POSIX-only assertion on a win32 run, instead of an
|
|
33
|
+
* `if (platform)` guard that would hide it forever.
|
|
38
34
|
*/
|
|
39
35
|
export declare function isWin32(): boolean;
|
|
40
36
|
/** Running on macOS? */
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** Does this host have a readable procfs for the current process? */
|
|
2
2
|
export declare function hasProcfs(): boolean;
|
|
3
3
|
/**
|
|
4
|
-
* This process's own pid, or `undefined` where nothing can answer.
|
|
4
|
+
* This process's own pid, or `undefined` where nothing can answer. Never `0` —
|
|
5
|
+
* that is a real pid, and returning it as "unknown" hands the caller a number
|
|
6
|
+
* that looks answered.
|
|
5
7
|
*
|
|
6
8
|
* Two readers, capability-selected:
|
|
7
9
|
*
|
|
@@ -9,12 +11,8 @@ export declare function hasProcfs(): boolean;
|
|
|
9
11
|
* subprocess.
|
|
10
12
|
* 2. `sh -c 'echo $PPID'` — the shell's PARENT is us, because
|
|
11
13
|
* `g_spawn_command_line_sync()` forks this process and execs the shell in
|
|
12
|
-
* the child
|
|
13
|
-
*
|
|
14
|
-
* has no procfs.
|
|
15
|
-
*
|
|
16
|
-
* Never `0`. `0` is a real pid, so returning it as "unknown" would hand every
|
|
17
|
-
* caller a number that looks answered.
|
|
14
|
+
* the child (same trick as `@gjsify/v8`'s darwin heap reader; portable to
|
|
15
|
+
* every POSIX host without procfs).
|
|
18
16
|
*/
|
|
19
17
|
export declare function hostPid(): number | undefined;
|
|
20
18
|
/**
|
|
@@ -30,20 +28,17 @@ export declare function hostPpid(): number | undefined;
|
|
|
30
28
|
* The absolute path of the INTERPRETER running this process — what Node calls
|
|
31
29
|
* `process.execPath` — or `undefined` where nothing can answer.
|
|
32
30
|
*
|
|
33
|
-
* NOT `imports.system.programInvocationName
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* non-executable text file through `/bin/sh` and the shell begins interpreting
|
|
38
|
-
* a bundle.
|
|
31
|
+
* NOT `imports.system.programInvocationName`: that is the SCRIPT, and reporting it
|
|
32
|
+
* as `execPath` breaks `spawn(process.execPath, […])` — the portable way to start
|
|
33
|
+
* a second copy of the runtime — with `ENOENT`, or worse, `g_spawn` retries the
|
|
34
|
+
* non-executable text file through `/bin/sh` and the shell interprets a bundle.
|
|
39
35
|
*
|
|
40
36
|
* 1. `/proc/self/exe` — a symlink to the running binary, exact by
|
|
41
37
|
* construction.
|
|
42
|
-
* 2. `g_find_program_in_path(g_get_prgname())` —
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* hardcoded `/usr/bin/gjs` — a path that does not exist on macOS at all.
|
|
38
|
+
* 2. `g_find_program_in_path(g_get_prgname())` — honest but not exact, since a
|
|
39
|
+
* host with two gjs installations can resolve the other one; hence the
|
|
40
|
+
* fallback position. Nothing defaults to a hardcoded `/usr/bin/gjs`, a path
|
|
41
|
+
* that does not exist on macOS at all.
|
|
47
42
|
*/
|
|
48
43
|
export declare function hostExecPath(): string | undefined;
|
|
49
44
|
/** The OS's view of a process's memory, in bytes. */
|
|
@@ -60,11 +55,9 @@ export interface ProcessMemory {
|
|
|
60
55
|
/**
|
|
61
56
|
* This process's memory figures, or `null` when no reader applies.
|
|
62
57
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* but it is a real difference and `@gjsify/v8` documents it in
|
|
67
|
-
* `getHeapStatistics()`'s own contract.
|
|
58
|
+
* Degraded off procfs: `ps(1)` reports only `rss` and `vsz`, so `data` and `peak`
|
|
59
|
+
* stay `0` — the same shape the Linux reader already produced for a procfs it
|
|
60
|
+
* could not parse.
|
|
68
61
|
*
|
|
69
62
|
* Both `ps` columns are in KiB on Linux and on macOS (POSIX mandates KiB for
|
|
70
63
|
* `rss`; BSD `vsz` follows), so one multiply serves both.
|
package/lib/types/main-loop.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import type GLib from '@girs/glib-2.0';
|
|
2
|
+
/**
|
|
3
|
+
* Ensure a GLib MainLoop is running for async I/O dispatch (Soup.Server,
|
|
4
|
+
* Gio.SocketService, …). No-op on Node.js. Idempotent.
|
|
5
|
+
*
|
|
6
|
+
* Called automatically by `http.Server.listen()`, `net.Server.listen()`,
|
|
7
|
+
* `dgram.Socket.bind()`. GTK apps must NOT call it — they use
|
|
8
|
+
* `Gtk.Application.runAsync()` instead.
|
|
9
|
+
*
|
|
10
|
+
* Teardown hazard: with a main-loop hook set, GJS's `eval_module` drives the
|
|
11
|
+
* hook's *blocking* `loop.run()`, so terminating from an async continuation with
|
|
12
|
+
* a bare `imports.system.exit()` DEADLOCKS — it only sets GJS's internal exit
|
|
13
|
+
* flag, never calls `loop.quit()`, so the parked `loop.run()` never returns.
|
|
14
|
+
* Microtask draining is unaffected; only the exit hangs
|
|
15
|
+
* (`docs/poc/tla-microtask-draining.md`). Exit through `process.exit()` (which
|
|
16
|
+
* idle-schedules `quitMainLoop()` + `system.exit()`) or call {@link quitMainLoop}
|
|
17
|
+
* yourself first.
|
|
18
|
+
*/
|
|
2
19
|
export declare function ensureMainLoop(): GLib.MainLoop | undefined;
|
|
3
20
|
/**
|
|
4
21
|
* Quit the MainLoop created by `ensureMainLoop()`. Idempotent, no-op on Node.js.
|
package/lib/types/next-tick.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/** @internal Test helper: reset burst state. */
|
|
2
2
|
export declare function __resetBurstStateForTests(): void;
|
|
3
3
|
/**
|
|
4
|
-
* Schedule a function on the next turn of the event loop
|
|
5
|
-
*
|
|
6
|
-
* On Node.js: uses process.nextTick → queueMicrotask → Promise.resolve().then().
|
|
4
|
+
* Schedule a function on the next turn of the event loop: the burst-yield drainer on
|
|
5
|
+
* GJS, otherwise `process.nextTick` → `queueMicrotask` → `Promise.resolve().then()`.
|
|
7
6
|
*/
|
|
8
7
|
export declare const nextTick: (fn: (...args: unknown[]) => void, ...args: unknown[]) => void;
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* structuredClone polyfill implementing the HTML structured clone algorithm.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* and arrays.
|
|
4
|
+
* Throws DataCloneError for functions, symbols, WeakMap, WeakSet, WeakRef and
|
|
5
|
+
* Promise; everything else the spec covers is cloned, circular and shared
|
|
6
|
+
* references included.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* accepted but ignored — the caller (e.g. `MessagePort.postMessage`) is
|
|
15
|
-
* responsible for handling transferable objects that aren't structured-clone
|
|
16
|
-
* primitives (`MessagePort`, `ReadableStream`, …).
|
|
17
|
-
*
|
|
18
|
-
* @param value The value to clone
|
|
19
|
-
* @param options Optional transfer list
|
|
8
|
+
* An `ArrayBuffer` in `options.transfer` is moved zero-copy via
|
|
9
|
+
* `ArrayBuffer.prototype.transfer()` and the sender's buffer becomes detached.
|
|
10
|
+
* Non-`ArrayBuffer` entries are accepted but IGNORED: transferables that are not
|
|
11
|
+
* structured-clone primitives (`MessagePort`, `ReadableStream`, …) are the caller's
|
|
12
|
+
* responsibility, e.g. `MessagePort.postMessage`.
|
|
20
13
|
*/
|
|
21
14
|
export declare function structuredClone<T>(value: T, options?: {
|
|
22
15
|
transfer?: unknown[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Utils module for gjsify",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"fs"
|
|
41
41
|
],
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@gjsify/cli": "^0.
|
|
43
|
+
"@gjsify/cli": "^0.38.0",
|
|
44
44
|
"typescript": "^6.0.3"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|