@maligator/cli 0.1.0-alpha.27 → 0.1.0-alpha.28
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 +26 -195
- package/application-api.d.ts +23 -0
- package/index.d.ts +85 -16
- package/package.json +8 -5
- package/platform-api.d.ts +3 -0
- package/process-api.d.ts +28 -25
- package/test-api.d.ts +32 -0
- package/workers-api.d.ts +445 -0
- package/workers-host-api.d.ts +135 -0
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ maligator run -- first-argument "two words"
|
|
|
38
38
|
|
|
39
39
|
`maligator init` creates `maligator.build.ts`. If it cannot find an existing entry
|
|
40
40
|
point, it also creates `src/index.ts`. `doctor` checks the native build toolchain,
|
|
41
|
-
`build` produces a development executable, and `run`
|
|
41
|
+
`build` produces a development executable, and `run` compiles a development image and executes it while
|
|
42
42
|
forwarding everything after `--` to the application.
|
|
43
43
|
|
|
44
44
|
Useful commands:
|
|
@@ -64,200 +64,31 @@ native toolchain. `dev` retains compiler identities between edits and restarts a
|
|
|
64
64
|
application VM after every successful rebuild. Build failures keep the watcher alive
|
|
65
65
|
for recovery on the next edit.
|
|
66
66
|
|
|
67
|
-
##
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
await expect(router.match("/users/nope")).rejects.toThrow(RouteError);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
By default, discovery includes `*.test.js`, `*.test.mjs`, `*.test.ts`,
|
|
98
|
-
`*.test.mts`, and the corresponding `*.spec.*` names. Pass files, directories,
|
|
99
|
-
or both:
|
|
100
|
-
|
|
101
|
-
```shell
|
|
102
|
-
maligator test
|
|
103
|
-
maligator test src/router
|
|
104
|
-
maligator test src/router/router.test.ts
|
|
105
|
-
maligator test --run "router > parameters"
|
|
106
|
-
maligator test --shuffle
|
|
107
|
-
maligator test --shuffle 18492
|
|
108
|
-
maligator test --repeat 10
|
|
109
|
-
maligator test --bail
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
`--run` filters hierarchical suite and test names. `--shuffle [seed]` changes
|
|
113
|
-
execution order reproducibly and always prints the seed. `--repeat` executes the
|
|
114
|
-
selected tests again while reusing unchanged compilation artifacts. The default
|
|
115
|
-
policy completes the selected suite; `--bail` stops scheduling after the first
|
|
116
|
-
failure.
|
|
117
|
-
|
|
118
|
-
The authoring API includes nested `describe` suites, `beforeAll`, `afterAll`,
|
|
119
|
-
`beforeEach`, `afterEach`, synchronous and promise-returning callbacks,
|
|
120
|
-
`test.skip`, `test.todo`, `test.only`, and `test.each`. A committed `.only`
|
|
121
|
-
focuses execution and prints a warning. Matchers include identity, structural
|
|
122
|
-
equality, truthiness, containment, length, string/regular-expression matching,
|
|
123
|
-
partial-object matching, throwing, `.not`, `.resolves`, `.rejects`, and the
|
|
124
|
-
`expect.any`, `expect.anything`, `expect.stringMatching`,
|
|
125
|
-
`expect.objectContaining`, and `expect.arrayContaining` asymmetric helpers.
|
|
126
|
-
Maligator owns this API and does not claim Jest, Vitest, or `node:test`
|
|
127
|
-
compatibility.
|
|
128
|
-
|
|
129
|
-
Test files currently execute serially in one Realm. Registration and lifecycle
|
|
130
|
-
state are separated by test file, but globals, prototypes, imported module
|
|
131
|
-
singletons, host state, and asynchronous work left running by a test can be
|
|
132
|
-
shared. Do not rely on process-per-file isolation.
|
|
133
|
-
|
|
134
|
-
Frontend bytecode is content-addressed by source, transitive dependencies,
|
|
135
|
-
resolved module identities, relevant build configuration, and compiler/runtime
|
|
136
|
-
format versions. A warm run restores a shared base plus independently cached
|
|
137
|
-
test-file registration fragments. Test results are never cached: every selected
|
|
138
|
-
test executes on every invocation.
|
|
139
|
-
|
|
140
|
-
The package ships documented declarations for `maligator:test`. Projects whose
|
|
141
|
-
TypeScript configuration does not include `maligator.build.ts` should load the
|
|
142
|
-
package declarations explicitly:
|
|
143
|
-
|
|
144
|
-
```json
|
|
145
|
-
{
|
|
146
|
-
"compilerOptions": {
|
|
147
|
-
"types": ["@maligator/cli"]
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Build cache
|
|
153
|
-
|
|
154
|
-
Normal `maligator build`, `maligator run`, and `maligator test` commands share a
|
|
155
|
-
content-addressed portable VM definition store. On a valid hit, Maligator skips
|
|
156
|
-
parsing, module-graph construction, semantic analysis, optimization, register
|
|
157
|
-
allocation, and VM lowering. For supported Intl-disabled development profiles, `run`
|
|
158
|
-
executes the restored definition with a matching compile-time-specialized runtime
|
|
159
|
-
embedded in the platform CLI; it does not generate C or invoke a native toolchain.
|
|
160
|
-
Normal and production `build` commands emit
|
|
161
|
-
native translation units from the same restored definition. Those units and the native driver are
|
|
162
|
-
compiled into independently content-addressed objects, so unchanged objects can
|
|
163
|
-
be relinked without repeating C compilation. The final link still runs, and
|
|
164
|
-
native runtime and Rust archives remain separately content-addressed. Runtime C
|
|
165
|
-
objects use their preprocessed input as the feature projection, while distinct
|
|
166
|
-
Rust feature archives share Cargo dependency work. Output executables remain
|
|
167
|
-
statically linked and self-contained.
|
|
168
|
-
|
|
169
|
-
Build cache invalidation includes source and transitive dependency content,
|
|
170
|
-
package-resolution metadata, relevant configuration, the TypeScript erasure
|
|
171
|
-
frontend, and compiler/wire versions. Generated-object identity additionally
|
|
172
|
-
includes the exact C source, source identity, native headers/runtime artifact,
|
|
173
|
-
compiler/toolchain, target, flags, and build environment. Compiler diagnostic
|
|
174
|
-
dump flags deliberately recompile the frontend because they require live
|
|
175
|
-
semantic and IR objects.
|
|
176
|
-
|
|
177
|
-
## Production builds
|
|
178
|
-
|
|
179
|
-
Use production mode for a deployable binary:
|
|
180
|
-
|
|
181
|
-
```shell
|
|
182
|
-
maligator build --production
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
Production builds use optimized native compilation, add LTO when the toolchain
|
|
186
|
-
supports it, and strip native symbols when possible. To create a self-contained
|
|
187
|
-
artifact directory with a manifest, license, checksum, and binary:
|
|
188
|
-
|
|
189
|
-
```shell
|
|
190
|
-
maligator build --production --artifact dist/my-application
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
The artifact destination must be absent or empty. Launch the reported binary
|
|
194
|
-
directly; neither Node.js nor the Maligator CLI is needed at runtime.
|
|
195
|
-
|
|
196
|
-
## Configuration
|
|
197
|
-
|
|
198
|
-
`maligator.build.ts` is trusted TypeScript configuration. A small configuration
|
|
199
|
-
looks like this:
|
|
200
|
-
|
|
201
|
-
```typescript
|
|
202
|
-
import { defineBuild } from "@maligator/cli";
|
|
203
|
-
|
|
204
|
-
export default defineBuild({
|
|
205
|
-
entry: "src/index.ts",
|
|
206
|
-
outputName: "my-application",
|
|
207
|
-
engine: {
|
|
208
|
-
eval: false,
|
|
209
|
-
intl: { enabled: false },
|
|
210
|
-
},
|
|
211
|
-
surface: {
|
|
212
|
-
webPlatform: false,
|
|
213
|
-
node: false,
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
All fields are optional. Maligator excludes optional engine and host surfaces unless
|
|
219
|
-
the configuration requests them. See the
|
|
220
|
-
[full configuration reference](https://github.com/dirkdev98/maligator#configuration)
|
|
221
|
-
for assets, Intl features, Node compatibility, web-platform support, and target
|
|
222
|
-
selection.
|
|
223
|
-
|
|
224
|
-
## TypeScript
|
|
225
|
-
|
|
226
|
-
The package includes declarations for `maligator.build.ts` and Maligator's runtime
|
|
227
|
-
globals. Keeping the generated build file inside your TypeScript project makes the
|
|
228
|
-
types available automatically:
|
|
229
|
-
|
|
230
|
-
```typescript
|
|
231
|
-
const path = mal.assets.materialize("templates", {
|
|
232
|
-
baseDirectory: ".cache/my-application",
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
const server = Mal.serve({
|
|
236
|
-
hostname: "127.0.0.1",
|
|
237
|
-
port: 3000,
|
|
238
|
-
async fetch(request) {
|
|
239
|
-
return new Response(`Hello from ${request.url}`);
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
console.log(path, server.port);
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
`mal` is present when `surface.maligator` is enabled. `Mal` and `Mal.serve` are
|
|
247
|
-
present when `surface.webPlatform` is enabled. The declarations describe both
|
|
248
|
-
optional surfaces, while `maligator.build.ts` controls which globals exist in the
|
|
249
|
-
compiled application.
|
|
250
|
-
|
|
251
|
-
If your `tsconfig.json` excludes `maligator.build.ts`, load the declarations
|
|
252
|
-
explicitly:
|
|
253
|
-
|
|
254
|
-
```json
|
|
255
|
-
{
|
|
256
|
-
"compilerOptions": {
|
|
257
|
-
"types": ["@maligator/cli"]
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
```
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
Use the [guides](https://maligator.ddv.tools/guides) for application workflows and
|
|
70
|
+
the [API reference](https://maligator.ddv.tools/api) for exact contracts.
|
|
71
|
+
|
|
72
|
+
- [Getting started](https://maligator.ddv.tools/guides/getting-started)
|
|
73
|
+
- [Development](https://maligator.ddv.tools/guides/development) and
|
|
74
|
+
[TypeScript](https://maligator.ddv.tools/guides/typescript)
|
|
75
|
+
- [Application testing](https://maligator.ddv.tools/guides/testing)
|
|
76
|
+
- [Workers](https://maligator.ddv.tools/guides/workers)
|
|
77
|
+
- [Build configuration](https://maligator.ddv.tools/guides/build-configuration)
|
|
78
|
+
- [Embedded files](https://maligator.ddv.tools/guides/assets) and
|
|
79
|
+
[HTTP](https://maligator.ddv.tools/guides/http)
|
|
80
|
+
- [Production](https://maligator.ddv.tools/guides/production) and
|
|
81
|
+
[profiling](https://maligator.ddv.tools/guides/profiling)
|
|
82
|
+
- [CLI commands and flags](https://maligator.ddv.tools/api/cli)
|
|
83
|
+
|
|
84
|
+
The package ships types for configuration, runtime globals, and public `maligator:`
|
|
85
|
+
modules. Include `@maligator/cli` in `compilerOptions.types` when your TypeScript
|
|
86
|
+
project excludes the build file. Declarations do not enable optional runtime surfaces;
|
|
87
|
+
choose those in `maligator.build.ts`.
|
|
88
|
+
|
|
89
|
+
Every page has a Markdown counterpart. The
|
|
90
|
+
[public symbol index](https://maligator.ddv.tools/reference.json) provides signatures,
|
|
91
|
+
defaults, availability, and direct links.
|
|
261
92
|
|
|
262
93
|
## Build toolchain
|
|
263
94
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Generated from src/platform/catalog.ts; edit the catalog and regenerate.
|
|
2
|
+
/**
|
|
3
|
+
* Runtime lifecycle notifications for supervised applications. Module evaluation and
|
|
4
|
+
* application readiness are separate events; readiness means the application has
|
|
5
|
+
* finished its own startup work.
|
|
6
|
+
*/
|
|
7
|
+
declare module "maligator:application" {
|
|
8
|
+
/**
|
|
9
|
+
* Notify the development supervisor that this application is ready. Repeated calls
|
|
10
|
+
* are harmless. Returns true in a supervised application and false in a standalone
|
|
11
|
+
* application or ordinary worker. Call after resources such as a server listener are
|
|
12
|
+
* accepting work; this does not reserve ports or transfer traffic.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { ready } from "maligator:application";
|
|
16
|
+
* import { createServer } from "node:http";
|
|
17
|
+
*
|
|
18
|
+
* createServer((_request, response) => response.end("hello")).listen(3000, () => ready());
|
|
19
|
+
*
|
|
20
|
+
* @see https://maligator.ddv.tools/api/application#ready
|
|
21
|
+
*/
|
|
22
|
+
export const ready: () => boolean;
|
|
23
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import "./platform-api.d.ts";
|
|
4
4
|
|
|
5
|
+
/** Service selections used when Intl is enabled; an empty list includes every service. */
|
|
5
6
|
export type MaligatorIntlFeature =
|
|
6
7
|
| "collator"
|
|
7
8
|
| "number-format"
|
|
@@ -13,56 +14,106 @@ export type MaligatorIntlFeature =
|
|
|
13
14
|
| "relative-time-format"
|
|
14
15
|
| "duration-format";
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Capture a regular file or a directory tree at build time. Paths are relative to
|
|
19
|
+
* the project root. Directory patterns support *, ?, and whole-segment **;
|
|
20
|
+
* every pattern must match a regular file. Symlinks are rejected.
|
|
21
|
+
* @see https://maligator.ddv.tools/api/build#AssetInclusion
|
|
22
|
+
*/
|
|
16
23
|
export type AssetInclusion =
|
|
17
24
|
| { type: "file"; path: string }
|
|
18
25
|
| { type: "directory"; path: string; include: Array<string> };
|
|
19
26
|
|
|
27
|
+
/** Trusted, strictly validated configuration evaluated for each CLI invocation.
|
|
28
|
+
* @see https://maligator.ddv.tools/guides/build-configuration
|
|
29
|
+
*/
|
|
20
30
|
export interface MaligatorBuildConfig {
|
|
31
|
+
/** Project-root-relative entry; an explicit CLI entry takes precedence. */
|
|
21
32
|
entry?: string;
|
|
33
|
+
/** Binary name; otherwise inferred from the unscoped package name or project directory. */
|
|
22
34
|
outputName?: string;
|
|
35
|
+
/** Named build-time snapshots. Requires surface.maligator; portable serialized images cannot carry these filesystem resources. */
|
|
23
36
|
assets?: Record<string, AssetInclusion>;
|
|
24
37
|
modules?: {
|
|
25
|
-
/** Exact specifier replacements applied before module resolution. */
|
|
38
|
+
/** Exact specifier replacements applied before module resolution. Defaults to an empty map. */
|
|
26
39
|
aliases?: Record<string, string>;
|
|
27
40
|
};
|
|
28
41
|
engine?: {
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* mutable is intended for conformance suites and compatibility experiments.
|
|
42
|
+
/** Lock built-in objects for the entire build. Mutable is intended for compatibility experiments.
|
|
43
|
+
* @default "locked"
|
|
32
44
|
*/
|
|
33
45
|
primordials?: "locked" | "mutable";
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
46
|
+
/** Control dynamic compilation. false leaves eval/Function present but makes calls throw;
|
|
47
|
+
* true embeds the compiler; compile-check also rejects statically visible calls at build time.
|
|
48
|
+
* @default false
|
|
49
|
+
* @see https://maligator.ddv.tools/api/build#engine.eval
|
|
38
50
|
*/
|
|
39
51
|
eval?: boolean | "compile-check";
|
|
52
|
+
/** Include Realm support.
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
40
55
|
realms?: boolean;
|
|
56
|
+
/** Include RegExp; disabling it trades compatibility for binary size.
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
41
59
|
regexp?: boolean;
|
|
42
|
-
/** Include
|
|
60
|
+
/** Include Temporal and its calendar/time-zone data.
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
43
63
|
temporal?: boolean;
|
|
44
64
|
intl?: {
|
|
65
|
+
/** Include internationalization services and their native data.
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
45
68
|
enabled?: boolean;
|
|
69
|
+
/** Select services. An empty list includes all services when enabled.
|
|
70
|
+
* @default []
|
|
71
|
+
*/
|
|
46
72
|
features?: Array<MaligatorIntlFeature>;
|
|
73
|
+
/** Locale-data filtering is not implemented; only an empty list is accepted.
|
|
74
|
+
* @default []
|
|
75
|
+
*/
|
|
47
76
|
languages?: Array<string>;
|
|
48
77
|
};
|
|
49
78
|
};
|
|
50
79
|
surface?: {
|
|
80
|
+
/** Include Web APIs and Mal.serve. Declarations alone do not enable them.
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
51
83
|
webPlatform?: boolean;
|
|
84
|
+
/** Include supported node: modules; see the compatibility table for coverage.
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
52
87
|
node?: boolean;
|
|
88
|
+
/** Include the mal namespace. Required for configured assets.
|
|
89
|
+
* @default true
|
|
90
|
+
*/
|
|
53
91
|
maligator?: boolean;
|
|
54
92
|
};
|
|
55
93
|
}
|
|
56
94
|
|
|
95
|
+
/** Preserve the inferred config type. Validation happens when the CLI loads the config.
|
|
96
|
+
* @example
|
|
97
|
+
* import { defineBuild } from "@maligator/cli";
|
|
98
|
+
* export default defineBuild({ entry: "src/index.ts" });
|
|
99
|
+
* @see https://maligator.ddv.tools/api/build#defineBuild
|
|
100
|
+
*/
|
|
57
101
|
export declare function defineBuild<const Config extends MaligatorBuildConfig>(
|
|
58
102
|
config: Config,
|
|
59
103
|
): Config;
|
|
60
104
|
|
|
61
105
|
export interface MaligatorMaterializeOptions {
|
|
106
|
+
/** Parent directory for the content-addressed materialization. Defaults to the OS temporary directory. */
|
|
62
107
|
baseDirectory?: string;
|
|
63
108
|
}
|
|
64
109
|
|
|
65
110
|
export interface MaligatorAssets {
|
|
111
|
+
/**
|
|
112
|
+
* Atomically write a named snapshot and return its absolute file/directory path.
|
|
113
|
+
* Completed materializations are reused by content identity. Unknown names,
|
|
114
|
+
* invalid options, and filesystem failures throw synchronously.
|
|
115
|
+
* @see https://maligator.ddv.tools/api/runtime#mal.assets.materialize
|
|
116
|
+
*/
|
|
66
117
|
materialize(name: string, options?: MaligatorMaterializeOptions): string;
|
|
67
118
|
}
|
|
68
119
|
|
|
@@ -71,29 +122,47 @@ export interface MaligatorRuntime {
|
|
|
71
122
|
}
|
|
72
123
|
|
|
73
124
|
export interface MaligatorServeOptions {
|
|
125
|
+
/** Bind address. Defaults to 0.0.0.0; use 127.0.0.1 for a local-only listener. */
|
|
74
126
|
hostname?: string;
|
|
127
|
+
/** TCP port, 0 through 65535. Defaults to 0, which asks the OS to choose a port. */
|
|
75
128
|
port?: number;
|
|
129
|
+
/** Handle a request with a Response or an awaited response. */
|
|
76
130
|
fetch(request: Request): Response | PromiseLike<Response>;
|
|
131
|
+
/** Header deadline in milliseconds; 0 also selects the default. Integer 0..2147483647.
|
|
132
|
+
* @default 60000 */
|
|
133
|
+
headersTimeout?: number;
|
|
134
|
+
/** Request deadline in milliseconds; 0 also selects the default. Integer 0..2147483647.
|
|
135
|
+
* @default 300000 */
|
|
136
|
+
requestTimeout?: number;
|
|
137
|
+
/** Idle keep-alive deadline in milliseconds; 0 also selects the default. Integer 0..2147483647.
|
|
138
|
+
* @default 5000 */
|
|
139
|
+
keepAliveTimeout?: number;
|
|
140
|
+
/** Concurrent connection limit; 0 also selects the default. Integer 0..2147483647.
|
|
141
|
+
* @default 1024 */
|
|
142
|
+
maxConnections?: number;
|
|
77
143
|
}
|
|
78
144
|
|
|
79
145
|
export interface MaligatorServer {
|
|
146
|
+
/** Actual bound port, including an OS-selected port when the requested port was 0. */
|
|
80
147
|
readonly port: number;
|
|
81
148
|
}
|
|
82
149
|
|
|
83
150
|
export interface MaligatorWebRuntime {
|
|
151
|
+
/**
|
|
152
|
+
* Start an HTTP listener. Requires surface.webPlatform. The current handle exposes
|
|
153
|
+
* its bound port; it has no public stop method. Invalid timeout/connection limits throw.
|
|
154
|
+
* @see https://maligator.ddv.tools/api/runtime#Mal.serve
|
|
155
|
+
*/
|
|
84
156
|
serve(options: MaligatorServeOptions): MaligatorServer;
|
|
85
157
|
}
|
|
86
158
|
|
|
87
159
|
declare global {
|
|
88
|
-
/**
|
|
89
|
-
*
|
|
90
|
-
* `surface.maligator` is enabled.
|
|
160
|
+
/** Core namespace, available when surface.maligator is enabled.
|
|
161
|
+
* @see https://maligator.ddv.tools/api/runtime#mal
|
|
91
162
|
*/
|
|
92
163
|
var mal: MaligatorRuntime;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
* Maligator's web-host extension namespace. Present when
|
|
96
|
-
* `surface.webPlatform` is enabled.
|
|
164
|
+
/** Web host namespace, available when surface.webPlatform is enabled.
|
|
165
|
+
* @see https://maligator.ddv.tools/api/runtime#Mal
|
|
97
166
|
*/
|
|
98
167
|
var Mal: MaligatorWebRuntime;
|
|
99
168
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maligator/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.28",
|
|
4
4
|
"description": "Ahead-of-time JavaScript compiler and native runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/dirkdev98/maligator#readme",
|
|
@@ -31,8 +31,11 @@
|
|
|
31
31
|
"index.js",
|
|
32
32
|
"index.d.ts",
|
|
33
33
|
"platform-api.d.ts",
|
|
34
|
+
"application-api.d.ts",
|
|
34
35
|
"process-api.d.ts",
|
|
35
36
|
"test-api.d.ts",
|
|
37
|
+
"workers-api.d.ts",
|
|
38
|
+
"workers-host-api.d.ts",
|
|
36
39
|
"README.md",
|
|
37
40
|
"LICENSE"
|
|
38
41
|
],
|
|
@@ -47,9 +50,9 @@
|
|
|
47
50
|
}
|
|
48
51
|
},
|
|
49
52
|
"optionalDependencies": {
|
|
50
|
-
"@maligator/cli-darwin-arm64": "0.1.0-alpha.
|
|
51
|
-
"@maligator/cli-darwin-x64": "0.1.0-alpha.
|
|
52
|
-
"@maligator/cli-linux-arm64": "0.1.0-alpha.
|
|
53
|
-
"@maligator/cli-linux-x64": "0.1.0-alpha.
|
|
53
|
+
"@maligator/cli-darwin-arm64": "0.1.0-alpha.28",
|
|
54
|
+
"@maligator/cli-darwin-x64": "0.1.0-alpha.28",
|
|
55
|
+
"@maligator/cli-linux-arm64": "0.1.0-alpha.28",
|
|
56
|
+
"@maligator/cli-linux-x64": "0.1.0-alpha.28"
|
|
54
57
|
}
|
|
55
58
|
}
|
package/platform-api.d.ts
CHANGED
package/process-api.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
// Generated from src/platform/catalog.ts; edit the catalog and regenerate.
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* directory, and PID are runtime concerns outside execution.
|
|
3
|
+
* Read the compile-time command, target, and resolved application configuration. No
|
|
4
|
+
* surface flag is required. Runtime arguments, environment, working directory, and
|
|
5
|
+
* PID are separate process values.
|
|
7
6
|
*/
|
|
8
7
|
declare module "maligator:process" {
|
|
9
8
|
/**
|
|
10
9
|
* Profiling instrumentation: none by default; sampling for --profile; compiler for
|
|
11
10
|
* --profile=compiler. Both profiling modes select full optimization without
|
|
12
11
|
* selecting production application behavior.
|
|
12
|
+
*
|
|
13
|
+
* @see https://maligator.ddv.tools/api/process#ExecutionProfile
|
|
13
14
|
*/
|
|
14
15
|
export type ExecutionProfile = "none" | "sampling" | "compiler";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* The fixed platform contract of the application image.
|
|
19
|
+
*
|
|
20
|
+
* @see https://maligator.ddv.tools/api/process#ExecutionTarget
|
|
18
21
|
*/
|
|
19
22
|
export type ExecutionTarget = {
|
|
20
23
|
/**
|
|
@@ -36,6 +39,8 @@ declare module "maligator:process" {
|
|
|
36
39
|
/**
|
|
37
40
|
* Options shared by build, run, and dev. Output paths, verbosity, and compiler
|
|
38
41
|
* scheduling are tool settings and are not exposed.
|
|
42
|
+
*
|
|
43
|
+
* @see https://maligator.ddv.tools/api/process#ExecutionOptions
|
|
39
44
|
*/
|
|
40
45
|
export type ExecutionOptions = {
|
|
41
46
|
/**
|
|
@@ -48,6 +53,8 @@ declare module "maligator:process" {
|
|
|
48
53
|
/**
|
|
49
54
|
* Normalized test settings, fixed for the application image. Changing these values
|
|
50
55
|
* invalidates specialized test artifacts.
|
|
56
|
+
*
|
|
57
|
+
* @see https://maligator.ddv.tools/api/process#TestExecutionOptions
|
|
51
58
|
*/
|
|
52
59
|
export type TestExecutionOptions = {
|
|
53
60
|
/**
|
|
@@ -70,8 +77,7 @@ declare module "maligator:process" {
|
|
|
70
77
|
*/
|
|
71
78
|
readonly bail: boolean;
|
|
72
79
|
/**
|
|
73
|
-
*
|
|
74
|
-
* test APIs can select a different timeout.
|
|
80
|
+
* Test callback timeout in milliseconds from --timeout. Defaults to 5000.
|
|
75
81
|
*/
|
|
76
82
|
readonly timeoutMs: number;
|
|
77
83
|
/**
|
|
@@ -85,6 +91,8 @@ declare module "maligator:process" {
|
|
|
85
91
|
/**
|
|
86
92
|
* Resolved engine policies. These describe build inputs, never post-DCE native
|
|
87
93
|
* feature inclusion.
|
|
94
|
+
*
|
|
95
|
+
* @see https://maligator.ddv.tools/api/process#ExecutionEngineConfig
|
|
88
96
|
*/
|
|
89
97
|
export type ExecutionEngineConfig = {
|
|
90
98
|
/**
|
|
@@ -133,9 +141,10 @@ declare module "maligator:process" {
|
|
|
133
141
|
};
|
|
134
142
|
|
|
135
143
|
/**
|
|
136
|
-
*
|
|
137
|
-
* build-host paths, asset declarations, output controls
|
|
138
|
-
*
|
|
144
|
+
* Resolved application engine, Web/Node surface, and module policies. Excludes
|
|
145
|
+
* build-host paths, asset declarations, and output controls.
|
|
146
|
+
*
|
|
147
|
+
* @see https://maligator.ddv.tools/api/process#ExecutionConfig
|
|
139
148
|
*/
|
|
140
149
|
export type ExecutionConfig = {
|
|
141
150
|
/**
|
|
@@ -173,6 +182,8 @@ declare module "maligator:process" {
|
|
|
173
182
|
/**
|
|
174
183
|
* Fields shared by every execution workflow. All nested objects and arrays are
|
|
175
184
|
* deeply frozen at runtime.
|
|
185
|
+
*
|
|
186
|
+
* @see https://maligator.ddv.tools/api/process#ExecutionCommon
|
|
176
187
|
*/
|
|
177
188
|
export type ExecutionCommon = {
|
|
178
189
|
/**
|
|
@@ -208,6 +219,8 @@ declare module "maligator:process" {
|
|
|
208
219
|
/**
|
|
209
220
|
* An immutable application-image description, discriminated by command. The command
|
|
210
221
|
* describes the workflow that prepared the image, not a transient process phase.
|
|
222
|
+
*
|
|
223
|
+
* @see https://maligator.ddv.tools/api/process#Execution
|
|
211
224
|
*/
|
|
212
225
|
export type Execution = ExecutionCommon &
|
|
213
226
|
(
|
|
@@ -249,16 +262,11 @@ declare module "maligator:process" {
|
|
|
249
262
|
);
|
|
250
263
|
|
|
251
264
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
* stable identity within an application context and deeply frozen own data
|
|
258
|
-
* properties; reflection sees the complete shape. Static and dynamic imports return
|
|
259
|
-
* the same export. A different command, option, configuration, target, or backend
|
|
260
|
-
* creates a different compilation context. Profiling does not change production
|
|
261
|
-
* intent. Importing the module does not keep unused native code alive.
|
|
265
|
+
* An immutable snapshot of the workflow, target, and resolved configuration, fixed
|
|
266
|
+
* before compilation. Known property reads can specialize application branches.
|
|
267
|
+
* Runtime arguments, environment, working directory, and PID are outside this
|
|
268
|
+
* snapshot. Profiling does not change production intent. Static and dynamic imports
|
|
269
|
+
* share its identity, and reflection sees the complete deeply frozen shape.
|
|
262
270
|
*
|
|
263
271
|
* @example
|
|
264
272
|
* import { execution } from "maligator:process";
|
|
@@ -267,12 +275,7 @@ declare module "maligator:process" {
|
|
|
267
275
|
* console.log("native production application");
|
|
268
276
|
* }
|
|
269
277
|
*
|
|
270
|
-
* @
|
|
271
|
-
* import { execution } from "maligator:process";
|
|
272
|
-
*
|
|
273
|
-
* if (execution.command === "test") {
|
|
274
|
-
* console.log(execution.options.repeat);
|
|
275
|
-
* }
|
|
278
|
+
* @see https://maligator.ddv.tools/api/process#execution
|
|
276
279
|
*/
|
|
277
280
|
export const execution: Execution;
|
|
278
281
|
}
|
package/test-api.d.ts
CHANGED
|
@@ -9,16 +9,22 @@ declare module "maligator:test" {
|
|
|
9
9
|
/**
|
|
10
10
|
* A test or hook body. Maligator waits for a returned promise or thenable before
|
|
11
11
|
* advancing the lifecycle.
|
|
12
|
+
*
|
|
13
|
+
* @see https://maligator.ddv.tools/api/test#TestCallback
|
|
12
14
|
*/
|
|
13
15
|
export type TestCallback = () => unknown;
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* A lifecycle hook body, with the same async completion contract as a test.
|
|
19
|
+
*
|
|
20
|
+
* @see https://maligator.ddv.tools/api/test#HookCallback
|
|
17
21
|
*/
|
|
18
22
|
export type HookCallback = TestCallback;
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* A constructable value accepted by {@link expect.any}.
|
|
26
|
+
*
|
|
27
|
+
* @see https://maligator.ddv.tools/api/test#Constructor
|
|
22
28
|
*/
|
|
23
29
|
export type Constructor = abstract new (...args: Array<never>) => unknown;
|
|
24
30
|
|
|
@@ -26,6 +32,8 @@ declare module "maligator:test" {
|
|
|
26
32
|
* Opaque partial-match value produced by helpers such as {@link
|
|
27
33
|
* expect.objectContaining}. It may be nested inside `toEqual`, `toStrictEqual`, and
|
|
28
34
|
* `toMatchObject` expectations.
|
|
35
|
+
*
|
|
36
|
+
* @see https://maligator.ddv.tools/api/test#AsymmetricMatcher
|
|
29
37
|
*/
|
|
30
38
|
export type AsymmetricMatcher = {
|
|
31
39
|
readonly __maligator_asymmetric__: string;
|
|
@@ -33,6 +41,8 @@ declare module "maligator:test" {
|
|
|
33
41
|
|
|
34
42
|
/**
|
|
35
43
|
* Matchers for a synchronously received value.
|
|
44
|
+
*
|
|
45
|
+
* @see https://maligator.ddv.tools/api/test#Matchers
|
|
36
46
|
*/
|
|
37
47
|
export type Matchers = {
|
|
38
48
|
/** Negate the following matcher. */
|
|
@@ -86,6 +96,8 @@ declare module "maligator:test" {
|
|
|
86
96
|
* Promise-returning matcher surface exposed by {@link Matchers.resolves} and {@link
|
|
87
97
|
* Matchers.rejects}. Await these calls so the test cannot finish before the
|
|
88
98
|
* assertion.
|
|
99
|
+
*
|
|
100
|
+
* @see https://maligator.ddv.tools/api/test#AsyncMatchers
|
|
89
101
|
*/
|
|
90
102
|
export type AsyncMatchers = {
|
|
91
103
|
/** Negate the following asynchronous matcher. */
|
|
@@ -113,6 +125,8 @@ declare module "maligator:test" {
|
|
|
113
125
|
|
|
114
126
|
/**
|
|
115
127
|
* Assertion entrypoint and Maligator-owned asymmetric matcher factories.
|
|
128
|
+
*
|
|
129
|
+
* @see https://maligator.ddv.tools/api/test#ExpectFunction
|
|
116
130
|
*/
|
|
117
131
|
export type ExpectFunction = {
|
|
118
132
|
/** Create matchers for `received`. The assertion position is captured here. */
|
|
@@ -131,6 +145,8 @@ declare module "maligator:test" {
|
|
|
131
145
|
|
|
132
146
|
/**
|
|
133
147
|
* Register tests in the current suite during module evaluation.
|
|
148
|
+
*
|
|
149
|
+
* @see https://maligator.ddv.tools/api/test#TestFunction
|
|
134
150
|
*/
|
|
135
151
|
export type TestFunction = {
|
|
136
152
|
/** Register a test. Returned promises are awaited by the runner. */
|
|
@@ -155,6 +171,8 @@ declare module "maligator:test" {
|
|
|
155
171
|
|
|
156
172
|
/**
|
|
157
173
|
* Register nested suites synchronously during module evaluation.
|
|
174
|
+
*
|
|
175
|
+
* @see https://maligator.ddv.tools/api/test#DescribeFunction
|
|
158
176
|
*/
|
|
159
177
|
export type DescribeFunction = {
|
|
160
178
|
/** Register a suite. Suite callbacks must not return a promise. */
|
|
@@ -167,32 +185,46 @@ declare module "maligator:test" {
|
|
|
167
185
|
|
|
168
186
|
/**
|
|
169
187
|
* Register a test in the current suite.
|
|
188
|
+
*
|
|
189
|
+
* @see https://maligator.ddv.tools/api/test#test
|
|
170
190
|
*/
|
|
171
191
|
export const test: TestFunction;
|
|
172
192
|
/**
|
|
173
193
|
* Register a nested suite in the current suite.
|
|
194
|
+
*
|
|
195
|
+
* @see https://maligator.ddv.tools/api/test#describe
|
|
174
196
|
*/
|
|
175
197
|
export const describe: DescribeFunction;
|
|
176
198
|
/**
|
|
177
199
|
* Create fluent matchers for a received value.
|
|
200
|
+
*
|
|
201
|
+
* @see https://maligator.ddv.tools/api/test#expect
|
|
178
202
|
*/
|
|
179
203
|
export const expect: ExpectFunction;
|
|
180
204
|
/**
|
|
181
205
|
* Run once before tests in the current suite.
|
|
206
|
+
*
|
|
207
|
+
* @see https://maligator.ddv.tools/api/test#beforeAll
|
|
182
208
|
*/
|
|
183
209
|
export const beforeAll: (callback: HookCallback) => void;
|
|
184
210
|
/**
|
|
185
211
|
* Run once after tests in the current suite, including after test failures.
|
|
212
|
+
*
|
|
213
|
+
* @see https://maligator.ddv.tools/api/test#afterAll
|
|
186
214
|
*/
|
|
187
215
|
export const afterAll: (callback: HookCallback) => void;
|
|
188
216
|
/**
|
|
189
217
|
* Run before every selected descendant test. Ancestor hooks run before hooks
|
|
190
218
|
* declared by a nested suite.
|
|
219
|
+
*
|
|
220
|
+
* @see https://maligator.ddv.tools/api/test#beforeEach
|
|
191
221
|
*/
|
|
192
222
|
export const beforeEach: (callback: HookCallback) => void;
|
|
193
223
|
/**
|
|
194
224
|
* Run after every selected descendant test. Nested-suite hooks run before ancestor
|
|
195
225
|
* hooks.
|
|
226
|
+
*
|
|
227
|
+
* @see https://maligator.ddv.tools/api/test#afterEach
|
|
196
228
|
*/
|
|
197
229
|
export const afterEach: (callback: HookCallback) => void;
|
|
198
230
|
}
|
package/workers-api.d.ts
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
// Generated from src/platform/catalog.ts; edit the catalog and regenerate.
|
|
2
|
+
/**
|
|
3
|
+
* Parallel computation and isolated event loops. Declared entries are bundled into
|
|
4
|
+
* the application image; workers do not compile or load source files at runtime.
|
|
5
|
+
* Native executors and GC helpers are shared across JavaScript isolates.
|
|
6
|
+
*/
|
|
7
|
+
declare module "maligator:workers" {
|
|
8
|
+
/**
|
|
9
|
+
* An immutable image-local worker entry declaration. The compiler resolves the
|
|
10
|
+
* declaration independently of how libraries pass the descriptor or its href onward.
|
|
11
|
+
* Erased module types express the caller's assertion; runtime entry identity is
|
|
12
|
+
* validated.
|
|
13
|
+
*
|
|
14
|
+
* @see https://maligator.ddv.tools/api/workers#WorkerUrl
|
|
15
|
+
*/
|
|
16
|
+
export type WorkerUrl<Module = unknown> = {
|
|
17
|
+
readonly href: string;
|
|
18
|
+
readonly __workerModule?: Module;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* ArrayBuffer stores move at admission. MessagePort endpoints transfer ownership.
|
|
23
|
+
* SharedArrayBuffer is cloned by sharing its backing and cannot be transferred.
|
|
24
|
+
*
|
|
25
|
+
* @see https://maligator.ddv.tools/api/workers#Transferable
|
|
26
|
+
*/
|
|
27
|
+
export type Transferable = ArrayBuffer | MessagePort;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Cancellation is cooperative while a pool task runs. The worker remains occupied
|
|
31
|
+
* until the task's returned promise settles.
|
|
32
|
+
*
|
|
33
|
+
* @see https://maligator.ddv.tools/api/workers#TaskContext
|
|
34
|
+
*/
|
|
35
|
+
export type TaskContext = {
|
|
36
|
+
/** Worker-local cancellation signal. Cancellation does not preempt JavaScript. */
|
|
37
|
+
readonly signal: AbortSignal;
|
|
38
|
+
/** Throws if cancelled. Check between bounded pieces of work. */
|
|
39
|
+
throwIfCancelled(): void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* An opaque result envelope. Constructing it does not detach buffers; publication
|
|
44
|
+
* commits transfers.
|
|
45
|
+
*
|
|
46
|
+
* @see https://maligator.ddv.tools/api/workers#TransferResult
|
|
47
|
+
*/
|
|
48
|
+
export type TransferResult<Value> = {
|
|
49
|
+
readonly value: Value;
|
|
50
|
+
readonly __transferResult: unique symbol;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Names of context-first exported task functions.
|
|
55
|
+
*
|
|
56
|
+
* @see https://maligator.ddv.tools/api/workers#TaskNames
|
|
57
|
+
*/
|
|
58
|
+
export type TaskNames<Module> = {
|
|
59
|
+
[Key in keyof Module]-?: Module[Key] extends (
|
|
60
|
+
context: TaskContext,
|
|
61
|
+
...args: infer Args
|
|
62
|
+
) => unknown
|
|
63
|
+
? Key
|
|
64
|
+
: never;
|
|
65
|
+
}[keyof Module] &
|
|
66
|
+
string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The task's argument tuple, excluding its local cancellation context.
|
|
70
|
+
*
|
|
71
|
+
* @see https://maligator.ddv.tools/api/workers#TaskArgs
|
|
72
|
+
*/
|
|
73
|
+
export type TaskArgs<Function> = Function extends (
|
|
74
|
+
context: TaskContext,
|
|
75
|
+
...args: infer Args
|
|
76
|
+
) => unknown
|
|
77
|
+
? Args
|
|
78
|
+
: never;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The settled task result after unwrapping an explicit transfer envelope.
|
|
82
|
+
*
|
|
83
|
+
* @see https://maligator.ddv.tools/api/workers#TaskValue
|
|
84
|
+
*/
|
|
85
|
+
export type TaskValue<Function> = Function extends (
|
|
86
|
+
...args: Array<never>
|
|
87
|
+
) => infer Result
|
|
88
|
+
? Awaited<Result> extends TransferResult<infer Value>
|
|
89
|
+
? Value
|
|
90
|
+
: Awaited<Result>
|
|
91
|
+
: never;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Fixed persistent worker count and admission bounds. Every worker has independent
|
|
95
|
+
* module state. A size-one pool dispatches admitted tasks serially.
|
|
96
|
+
*
|
|
97
|
+
* @see https://maligator.ddv.tools/api/workers#PoolOptions
|
|
98
|
+
*/
|
|
99
|
+
export type PoolOptions = {
|
|
100
|
+
/** Positive safe integer; defaults to host parallelism, falling back to 1. */
|
|
101
|
+
size?: number;
|
|
102
|
+
/** Nonnegative safe integer; defaults to four times size. Zero disables the waiting queue. */
|
|
103
|
+
maxQueuedTasks?: number;
|
|
104
|
+
/** Positive safe integer in bytes; defaults to 67108864 (64 MiB). */
|
|
105
|
+
maxQueuedBytes?: number;
|
|
106
|
+
/** Positive safe integer in bytes; defaults to maxQueuedBytes. */
|
|
107
|
+
maxMessageBytes?: number;
|
|
108
|
+
/** Worker name prefix; each worker receives a one-based suffix. */
|
|
109
|
+
name?: string;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The transfer list commits synchronously when run returns normally. Validation,
|
|
114
|
+
* saturation, closed pools and already-aborted signals throw before admission.
|
|
115
|
+
*
|
|
116
|
+
* @see https://maligator.ddv.tools/api/workers#RunOptions
|
|
117
|
+
*/
|
|
118
|
+
export type RunOptions = {
|
|
119
|
+
/** Already-aborted signals throw before admission. Running cancellation is cooperative. */
|
|
120
|
+
signal?: AbortSignal;
|
|
121
|
+
/** Ownership moves synchronously on successful admission; rejection leaves values unchanged. */
|
|
122
|
+
transfer?: ReadonlyArray<Transferable>;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The window bounds pulled inputs and buffered results together. Results are yielded
|
|
127
|
+
* in input order; iterator return cancels this map's work and closes its input.
|
|
128
|
+
*
|
|
129
|
+
* @see https://maligator.ddv.tools/api/workers#MapOptions
|
|
130
|
+
*/
|
|
131
|
+
export type MapOptions<Args> = {
|
|
132
|
+
/** Cancels only work owned by this map; running tasks must cooperate. */
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
/** Positive safe integer; defaults to pool size. Bounds pulled inputs and buffered results together. */
|
|
135
|
+
window?: number;
|
|
136
|
+
/** Called for each input before admission to choose values whose ownership moves. */
|
|
137
|
+
transfer?: (args: Args, index: number) => ReadonlyArray<Transferable>;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A snapshot of this pool's scheduling and settled operations.
|
|
142
|
+
*
|
|
143
|
+
* @see https://maligator.ddv.tools/api/workers#PoolStats
|
|
144
|
+
*/
|
|
145
|
+
export type PoolStats = {
|
|
146
|
+
readonly size: number;
|
|
147
|
+
readonly active: number;
|
|
148
|
+
readonly queued: number;
|
|
149
|
+
readonly completed: number;
|
|
150
|
+
readonly failed: number;
|
|
151
|
+
readonly cancelled: number;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* A bounded task scheduler over isolated persistent workers. Each worker executes
|
|
156
|
+
* one task through asynchronous settlement. No accepted task is replayed after
|
|
157
|
+
* worker failure.
|
|
158
|
+
*
|
|
159
|
+
* @see https://maligator.ddv.tools/api/workers#WorkerPool
|
|
160
|
+
*/
|
|
161
|
+
export type WorkerPool<Module> = {
|
|
162
|
+
/** Resolves after every worker evaluates the entry; rejects on startup failure. */
|
|
163
|
+
readonly ready: Promise<void>;
|
|
164
|
+
/** Throws on failed admission; returns a promise for the accepted task's result or failure. */
|
|
165
|
+
run<Key extends TaskNames<Module>>(
|
|
166
|
+
name: Key,
|
|
167
|
+
args: TaskArgs<Module[Key]>,
|
|
168
|
+
options?: RunOptions,
|
|
169
|
+
): Promise<TaskValue<Module[Key]>>;
|
|
170
|
+
/** Yields in input order. Returning from the iterator cancels its work and closes its input. */
|
|
171
|
+
map<Key extends TaskNames<Module>>(
|
|
172
|
+
name: Key,
|
|
173
|
+
args: Iterable<TaskArgs<Module[Key]>> | AsyncIterable<TaskArgs<Module[Key]>>,
|
|
174
|
+
options?: MapOptions<TaskArgs<Module[Key]>>,
|
|
175
|
+
): AsyncIterable<TaskValue<Module[Key]>>;
|
|
176
|
+
/** Stops admission, drains accepted tasks, then joins every worker. Idempotent. */
|
|
177
|
+
close(): Promise<void>;
|
|
178
|
+
/** Rejects outstanding tasks with AbortError; joins workers after running tasks cooperate and settle. */
|
|
179
|
+
terminate(): Promise<void>;
|
|
180
|
+
/** Returns a scheduling snapshot; counts are not a subscription. */
|
|
181
|
+
stats(): PoolStats;
|
|
182
|
+
/** Keeps the process alive while pool workers exist; returns this pool. */
|
|
183
|
+
ref(): WorkerPool<Module>;
|
|
184
|
+
/** Allows the process to exit without waiting for this pool; returns this pool. */
|
|
185
|
+
unref(): WorkerPool<Module>;
|
|
186
|
+
/** Reports whether this pool currently keeps the process alive. */
|
|
187
|
+
hasRef(): boolean;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* A terminal record published only after the native worker is joined and its slot is
|
|
192
|
+
* released.
|
|
193
|
+
*
|
|
194
|
+
* @see https://maligator.ddv.tools/api/workers#WorkerExit
|
|
195
|
+
*/
|
|
196
|
+
export type WorkerExit = {
|
|
197
|
+
readonly id: number;
|
|
198
|
+
readonly code: number;
|
|
199
|
+
readonly reason: "completed" | "terminated" | "error";
|
|
200
|
+
readonly error?: unknown;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Worker data is snapshotted before startup. The native host bounds live workers and
|
|
205
|
+
* message admission process-wide.
|
|
206
|
+
*
|
|
207
|
+
* @see https://maligator.ddv.tools/api/workers#WorkerOptions
|
|
208
|
+
*/
|
|
209
|
+
export type WorkerOptions = {
|
|
210
|
+
name?: string;
|
|
211
|
+
/** Cloned into workerData before startup; later caller mutations are not shared. */
|
|
212
|
+
data?: unknown;
|
|
213
|
+
/** Values moved as part of startup-data admission. */
|
|
214
|
+
transfer?: ReadonlyArray<Transferable>;
|
|
215
|
+
/** Positive safe integer, at most 4294967295; defaults to 4096 messages per endpoint. */
|
|
216
|
+
maxQueuedMessages?: number;
|
|
217
|
+
/** Positive safe integer in bytes; defaults to 67108864 (64 MiB) per endpoint. */
|
|
218
|
+
maxQueuedBytes?: number;
|
|
219
|
+
/** Positive safe integer in bytes; defaults to 16777216 (16 MiB) per message. */
|
|
220
|
+
maxMessageBytes?: number;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Each endpoint bounds its pending message count and bytes. Rejection leaves the
|
|
225
|
+
* sender's transferables unchanged.
|
|
226
|
+
*
|
|
227
|
+
* @see https://maligator.ddv.tools/api/workers#MessageChannelOptions
|
|
228
|
+
*/
|
|
229
|
+
export type MessageChannelOptions = {
|
|
230
|
+
/** Positive safe integer, at most 4294967295; defaults to 4096 messages per endpoint. */
|
|
231
|
+
maxQueuedMessages?: number;
|
|
232
|
+
/** Positive safe integer in bytes; defaults to 67108864 (64 MiB) per endpoint. */
|
|
233
|
+
maxQueuedBytes?: number;
|
|
234
|
+
/** Positive safe integer in bytes; defaults to 16777216 (16 MiB) per message. */
|
|
235
|
+
maxMessageBytes?: number;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* An ordered bidirectional endpoint with transactional transfer and bounded queues.
|
|
240
|
+
* Message listeners and values are owned by the receiving isolate.
|
|
241
|
+
*
|
|
242
|
+
* @see https://maligator.ddv.tools/api/workers#MessagePort.type
|
|
243
|
+
*/
|
|
244
|
+
export interface MessagePort<Send = unknown, Receive = unknown> extends EventTarget {
|
|
245
|
+
/** Clones and admits a message synchronously. Transfer commits only after successful validation/admission. */
|
|
246
|
+
postMessage(value: Send, transfer?: ReadonlyArray<Transferable>): void;
|
|
247
|
+
/** Setting this handler starts delivery. addEventListener listeners need start(). */
|
|
248
|
+
onmessage: ((event: MessageEvent<Receive>) => void) | null;
|
|
249
|
+
/** Receives message decoding failures in the receiving isolate. */
|
|
250
|
+
onmessageerror: ((event: MessageEvent<unknown>) => void) | null;
|
|
251
|
+
/** Enables delivery to event listeners; repeated calls are harmless. */
|
|
252
|
+
start(): void;
|
|
253
|
+
/** Discards queued messages and closes this endpoint. */
|
|
254
|
+
close(): void;
|
|
255
|
+
/** Keeps the receiving isolate alive; returns this port. */
|
|
256
|
+
ref(): MessagePort<Send, Receive>;
|
|
257
|
+
/** Allows the receiving isolate to exit; returns this port. */
|
|
258
|
+
unref(): MessagePort<Send, Receive>;
|
|
259
|
+
hasRef(): boolean;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* A standalone channel whose endpoints may be transferred to workers.
|
|
264
|
+
*
|
|
265
|
+
* @see https://maligator.ddv.tools/api/workers#MessageChannel.type
|
|
266
|
+
*/
|
|
267
|
+
export type MessageChannel = {
|
|
268
|
+
readonly port1: MessagePort;
|
|
269
|
+
readonly port2: MessagePort;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* A long-lived isolated module and its parent communication port. Startup completes
|
|
274
|
+
* after module evaluation; shutdown completes after native thread reaping.
|
|
275
|
+
*
|
|
276
|
+
* @see https://maligator.ddv.tools/api/workers#Worker.type
|
|
277
|
+
*/
|
|
278
|
+
export type Worker<Send = unknown, Receive = unknown> = EventTarget & {
|
|
279
|
+
readonly id: number;
|
|
280
|
+
/** Resolves after entry evaluation; rejects on startup failure. */
|
|
281
|
+
readonly ready: Promise<void>;
|
|
282
|
+
/** Resolves with a terminal record after the native thread is joined and its slot released. */
|
|
283
|
+
readonly closed: Promise<WorkerExit>;
|
|
284
|
+
readonly port: MessagePort<Send, Receive>;
|
|
285
|
+
/** Requests shutdown and resolves after thread reaping. */
|
|
286
|
+
terminate(): Promise<WorkerExit>;
|
|
287
|
+
ref(): Worker<Send, Receive>;
|
|
288
|
+
unref(): Worker<Send, Receive>;
|
|
289
|
+
hasRef(): boolean;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Declare an entry using a static string literal and explicit import.meta.url base.
|
|
294
|
+
* The immutable href projection can be passed to existing worker libraries.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* // declaration.ts
|
|
298
|
+
* import { createWorkerUrl } from "maligator:workers";
|
|
299
|
+
*
|
|
300
|
+
* export const tasks = createWorkerUrl<typeof import("./sum.ts")>(
|
|
301
|
+
* "./sum.ts",
|
|
302
|
+
* import.meta.url,
|
|
303
|
+
* );
|
|
304
|
+
*
|
|
305
|
+
* console.log(Object.isFrozen(tasks), tasks.href.startsWith("file:"));
|
|
306
|
+
*
|
|
307
|
+
* @see https://maligator.ddv.tools/api/workers#createWorkerUrl
|
|
308
|
+
*/
|
|
309
|
+
export const createWorkerUrl: <Module = unknown>(
|
|
310
|
+
specifier: string,
|
|
311
|
+
base: string,
|
|
312
|
+
) => WorkerUrl<Module>;
|
|
313
|
+
/**
|
|
314
|
+
* Create a bounded pool of persistent workers for a declared entry. Submission
|
|
315
|
+
* failures throw synchronously; admitted tasks settle asynchronously. Await ready
|
|
316
|
+
* before submitting startup-dependent work and close the pool when finished. Throws
|
|
317
|
+
* NotSupportedError without threads and RangeError for invalid bounds.
|
|
318
|
+
*
|
|
319
|
+
* @see https://maligator.ddv.tools/api/workers#createPool
|
|
320
|
+
*/
|
|
321
|
+
export const createPool: <Module>(
|
|
322
|
+
entry: WorkerUrl<Module>,
|
|
323
|
+
options?: PoolOptions,
|
|
324
|
+
) => WorkerPool<Module>;
|
|
325
|
+
/**
|
|
326
|
+
* Wrap a result for transfer when the worker publishes it.
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* // transfer-task.ts
|
|
330
|
+
* import { transfer } from "maligator:workers";
|
|
331
|
+
* import type { TaskContext } from "maligator:workers";
|
|
332
|
+
*
|
|
333
|
+
* export function reverse(context: TaskContext, buffer: ArrayBuffer) {
|
|
334
|
+
* context.throwIfCancelled();
|
|
335
|
+
* new Uint8Array(buffer).reverse();
|
|
336
|
+
* return transfer(buffer, [buffer]);
|
|
337
|
+
* }
|
|
338
|
+
*
|
|
339
|
+
* @see https://maligator.ddv.tools/api/workers#transfer
|
|
340
|
+
*/
|
|
341
|
+
export const transfer: <Value>(
|
|
342
|
+
value: Value,
|
|
343
|
+
transfer: ReadonlyArray<Transferable>,
|
|
344
|
+
) => TransferResult<Value>;
|
|
345
|
+
/**
|
|
346
|
+
* Start a declared isolated module and expose its ordered port and complete
|
|
347
|
+
* lifecycle.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* // echo.ts
|
|
351
|
+
* import { parentPort } from "maligator:workers";
|
|
352
|
+
*
|
|
353
|
+
* if (parentPort === null) throw new Error("Run this module as a worker");
|
|
354
|
+
* const port = parentPort;
|
|
355
|
+
* port.onmessage = (event) => {
|
|
356
|
+
* port.postMessage(String(event.data));
|
|
357
|
+
* };
|
|
358
|
+
* port.start();
|
|
359
|
+
*
|
|
360
|
+
* @see https://maligator.ddv.tools/api/workers#Worker
|
|
361
|
+
*/
|
|
362
|
+
export const Worker: {
|
|
363
|
+
new <Send = unknown, Receive = unknown>(
|
|
364
|
+
entry: WorkerUrl,
|
|
365
|
+
options?: WorkerOptions,
|
|
366
|
+
): Worker<Send, Receive>;
|
|
367
|
+
};
|
|
368
|
+
/**
|
|
369
|
+
* Create two transferable endpoints independently of worker startup.
|
|
370
|
+
*
|
|
371
|
+
* @see https://maligator.ddv.tools/api/workers#MessageChannel
|
|
372
|
+
*/
|
|
373
|
+
export const MessageChannel: { new (options?: MessageChannelOptions): MessageChannel };
|
|
374
|
+
/**
|
|
375
|
+
* The port prototype for type and identity checks. Ports are created by channels and
|
|
376
|
+
* workers.
|
|
377
|
+
*
|
|
378
|
+
* @see https://maligator.ddv.tools/api/workers#MessagePort
|
|
379
|
+
*/
|
|
380
|
+
export const MessagePort: { readonly prototype: MessagePort };
|
|
381
|
+
/**
|
|
382
|
+
* Synchronously dequeue one pending message without running unrelated callbacks.
|
|
383
|
+
*
|
|
384
|
+
* @see https://maligator.ddv.tools/api/workers#receiveMessageOnPort
|
|
385
|
+
*/
|
|
386
|
+
export const receiveMessageOnPort: <Receive>(
|
|
387
|
+
port: MessagePort<unknown, Receive>,
|
|
388
|
+
) => { message: Receive } | undefined;
|
|
389
|
+
/**
|
|
390
|
+
* Report the running host's worker facilities and capacity.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* // capabilities.ts
|
|
394
|
+
* import { capabilities } from "maligator:workers";
|
|
395
|
+
*
|
|
396
|
+
* const host = capabilities();
|
|
397
|
+
* console.log(host.threads, host.sharedMemory);
|
|
398
|
+
* console.log(host.parallelism >= 1, host.maxWorkers >= 1);
|
|
399
|
+
*
|
|
400
|
+
* @see https://maligator.ddv.tools/api/workers#capabilities
|
|
401
|
+
*/
|
|
402
|
+
export const capabilities: () => {
|
|
403
|
+
readonly threads: boolean;
|
|
404
|
+
readonly sharedMemory: boolean;
|
|
405
|
+
readonly parallelism: number;
|
|
406
|
+
readonly maxWorkers: number;
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* The worker's parent endpoint; null in the main isolate.
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* // echo.ts
|
|
413
|
+
* import { parentPort } from "maligator:workers";
|
|
414
|
+
*
|
|
415
|
+
* if (parentPort === null) throw new Error("Run this module as a worker");
|
|
416
|
+
* const port = parentPort;
|
|
417
|
+
* port.onmessage = (event) => {
|
|
418
|
+
* port.postMessage(String(event.data));
|
|
419
|
+
* };
|
|
420
|
+
* port.start();
|
|
421
|
+
*
|
|
422
|
+
* @see https://maligator.ddv.tools/api/workers#parentPort
|
|
423
|
+
*/
|
|
424
|
+
export const parentPort: MessagePort | null;
|
|
425
|
+
/**
|
|
426
|
+
* The worker-owned clone of startup data.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* // configuration.ts
|
|
430
|
+
* import { createWorkerUrl, Worker } from "maligator:workers";
|
|
431
|
+
*
|
|
432
|
+
* const entry = createWorkerUrl("./worker-data.ts", import.meta.url);
|
|
433
|
+
* const worker = new Worker(entry, { data: { label: "thumbnail" } });
|
|
434
|
+
* try {
|
|
435
|
+
* await worker.ready;
|
|
436
|
+
* const exit = await worker.closed;
|
|
437
|
+
* if (exit.code !== 0) throw new Error("Worker failed");
|
|
438
|
+
* } finally {
|
|
439
|
+
* await worker.terminate();
|
|
440
|
+
* }
|
|
441
|
+
*
|
|
442
|
+
* @see https://maligator.ddv.tools/api/workers#workerData
|
|
443
|
+
*/
|
|
444
|
+
export const workerData: unknown;
|
|
445
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Generated from src/platform/catalog.ts; edit the catalog and regenerate.
|
|
2
|
+
/**
|
|
3
|
+
* Toolchain-owned worker substrate used by the public source API and Node
|
|
4
|
+
* compatibility personality.
|
|
5
|
+
*/
|
|
6
|
+
declare module "maligator:internal/workers" {
|
|
7
|
+
import type * as Workers from "maligator:workers";
|
|
8
|
+
/**
|
|
9
|
+
* Values whose ownership moves when a message is admitted.
|
|
10
|
+
*/
|
|
11
|
+
export type Transferable = Workers.Transferable;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A terminal record. The error is the uncaught value as thrown.
|
|
15
|
+
*/
|
|
16
|
+
export type WorkerExit = {
|
|
17
|
+
readonly id: number;
|
|
18
|
+
readonly code: number;
|
|
19
|
+
readonly reason: "completed" | "terminated" | "error";
|
|
20
|
+
readonly error?: unknown;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A worker's uncaught value as thrown and its own string message, or the empty
|
|
25
|
+
* string.
|
|
26
|
+
*/
|
|
27
|
+
export type WorkerErrorEvent = Event & {
|
|
28
|
+
readonly error: unknown;
|
|
29
|
+
readonly message: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A transactional endpoint. postMessage returns the admission ticket, or undefined
|
|
34
|
+
* when nothing was queued; _discard drops a posted message the peer has not
|
|
35
|
+
* received.
|
|
36
|
+
*/
|
|
37
|
+
export type MessagePort<Send = unknown, Receive = unknown> = {
|
|
38
|
+
postMessage(value: Send, transfer?: ReadonlyArray<Transferable>): number | undefined;
|
|
39
|
+
_discard(ticket: number): boolean;
|
|
40
|
+
addEventListener(
|
|
41
|
+
type: "message",
|
|
42
|
+
listener: (event: MessageEvent<Receive>) => void | Promise<void>,
|
|
43
|
+
options?: AddEventListenerOptions | boolean,
|
|
44
|
+
): void;
|
|
45
|
+
onmessage: ((event: MessageEvent<Receive>) => void) | null;
|
|
46
|
+
onmessageerror: ((event: MessageEvent<unknown>) => void) | null;
|
|
47
|
+
start(): void;
|
|
48
|
+
close(): void;
|
|
49
|
+
ref(): MessagePort<Send, Receive>;
|
|
50
|
+
unref(): MessagePort<Send, Receive>;
|
|
51
|
+
hasRef(): boolean;
|
|
52
|
+
} & EventTarget;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A channel whose first port sends Forward messages and receives Backward messages.
|
|
56
|
+
*/
|
|
57
|
+
export type MessageChannel<Forward = unknown, Backward = unknown> = {
|
|
58
|
+
readonly port1: MessagePort<Forward, Backward>;
|
|
59
|
+
readonly port2: MessagePort<Backward, Forward>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A source-API worker handle over a transactional parent port.
|
|
64
|
+
*/
|
|
65
|
+
export type Worker<Send = unknown, Receive = unknown> = {
|
|
66
|
+
readonly id: number;
|
|
67
|
+
readonly ready: Promise<void>;
|
|
68
|
+
readonly closed: Promise<WorkerExit>;
|
|
69
|
+
readonly port: MessagePort<Send, Receive>;
|
|
70
|
+
addEventListener(
|
|
71
|
+
type: "error",
|
|
72
|
+
listener: (event: WorkerErrorEvent) => void,
|
|
73
|
+
options?: AddEventListenerOptions | boolean,
|
|
74
|
+
): void;
|
|
75
|
+
terminate(): Promise<WorkerExit>;
|
|
76
|
+
ref(): Worker<Send, Receive>;
|
|
77
|
+
unref(): Worker<Send, Receive>;
|
|
78
|
+
hasRef(): boolean;
|
|
79
|
+
} & EventTarget;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Start a declared isolated module with a transactional parent port.
|
|
83
|
+
*/
|
|
84
|
+
export const Worker: {
|
|
85
|
+
new <Send = unknown, Receive = unknown>(
|
|
86
|
+
entry: { readonly href: string },
|
|
87
|
+
options?: Workers.WorkerOptions,
|
|
88
|
+
): Worker<Send, Receive>;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Create two transactional endpoints.
|
|
92
|
+
*/
|
|
93
|
+
export const MessageChannel: {
|
|
94
|
+
new <Forward = unknown, Backward = unknown>(
|
|
95
|
+
options?: Workers.MessageChannelOptions,
|
|
96
|
+
): MessageChannel<Forward, Backward>;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The transactional port prototype.
|
|
100
|
+
*/
|
|
101
|
+
export const MessagePort: { readonly prototype: MessagePort };
|
|
102
|
+
/**
|
|
103
|
+
* Synchronously dequeue one pending message without running unrelated callbacks.
|
|
104
|
+
*/
|
|
105
|
+
export const receiveMessageOnPort: <Receive>(
|
|
106
|
+
port: MessagePort<unknown, Receive>,
|
|
107
|
+
) => { readonly message: Receive } | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Report the running host's worker facilities and capacity.
|
|
110
|
+
*/
|
|
111
|
+
export const capabilities: typeof Workers.capabilities;
|
|
112
|
+
/**
|
|
113
|
+
* Fail the current worker after its outcome cannot be published.
|
|
114
|
+
*/
|
|
115
|
+
export const failCurrent: () => void;
|
|
116
|
+
/**
|
|
117
|
+
* Internal static entry declaration.
|
|
118
|
+
*/
|
|
119
|
+
export const createWorkerUrl: (
|
|
120
|
+
specifier: string,
|
|
121
|
+
base: string,
|
|
122
|
+
) => { readonly href: string };
|
|
123
|
+
/**
|
|
124
|
+
* Isolate-owned worker state.
|
|
125
|
+
*/
|
|
126
|
+
export const parentPort: MessagePort | null;
|
|
127
|
+
/**
|
|
128
|
+
* Isolate-owned worker state.
|
|
129
|
+
*/
|
|
130
|
+
export const workerData: unknown;
|
|
131
|
+
/**
|
|
132
|
+
* The task-pool bootstrap entry.
|
|
133
|
+
*/
|
|
134
|
+
export const poolEntry: { readonly href: string };
|
|
135
|
+
}
|