@orkestrel/worker 0.0.3 → 0.0.4
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/dist/src/core/index.cjs +16 -13
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +9 -7
- package/dist/src/core/index.d.ts +9 -7
- package/dist/src/core/index.js +16 -13
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +258 -138
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +5 -8
- package/dist/src/server/index.d.ts +5 -8
- package/dist/src/server/index.js +259 -139
- package/dist/src/server/index.js.map +1 -1
- package/package.json +21 -18
package/dist/src/server/index.js
CHANGED
|
@@ -1,8 +1,219 @@
|
|
|
1
1
|
import { Worker, parentPort } from "node:worker_threads";
|
|
2
|
-
import { isRecord } from "@orkestrel/contract";
|
|
3
|
-
import { createWorker } from "../core/index.js";
|
|
2
|
+
import { attempt, isRecord } from "@orkestrel/contract";
|
|
4
3
|
import { createJSONDriver } from "@orkestrel/database/server";
|
|
5
4
|
import { createDatabaseQueueStore } from "@orkestrel/queue";
|
|
5
|
+
import { createWorker } from "../core/index.js";
|
|
6
|
+
//#region src/server/Thread.ts
|
|
7
|
+
/**
|
|
8
|
+
* Internal mutable implementation of the readonly {@link NodeThread} observation contract.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Liveness and the first terminal error live behind runtime-private fields. Consumers observe
|
|
12
|
+
* their current values through readonly getters, while the worker lifecycle records transitions
|
|
13
|
+
* through bound instance methods without exposing writable contract properties.
|
|
14
|
+
*/
|
|
15
|
+
var Thread = class {
|
|
16
|
+
#worker;
|
|
17
|
+
#promise;
|
|
18
|
+
#resolve;
|
|
19
|
+
#reject;
|
|
20
|
+
#recordErrorHandler;
|
|
21
|
+
#recordExitHandler;
|
|
22
|
+
#onlineHandler;
|
|
23
|
+
#spawnErrorHandler;
|
|
24
|
+
#spawnExitHandler;
|
|
25
|
+
#alive = true;
|
|
26
|
+
#death;
|
|
27
|
+
constructor(script, workerData) {
|
|
28
|
+
this.#worker = new Worker(script, { ...workerData !== void 0 ? { workerData } : {} });
|
|
29
|
+
const readiness = Promise.withResolvers();
|
|
30
|
+
this.#promise = readiness.promise;
|
|
31
|
+
this.#resolve = readiness.resolve;
|
|
32
|
+
this.#reject = readiness.reject;
|
|
33
|
+
this.#recordErrorHandler = this.#recordError.bind(this);
|
|
34
|
+
this.#recordExitHandler = this.#recordExit.bind(this);
|
|
35
|
+
this.#onlineHandler = this.#online.bind(this);
|
|
36
|
+
this.#spawnErrorHandler = this.#spawnError.bind(this);
|
|
37
|
+
this.#spawnExitHandler = this.#spawnExit.bind(this);
|
|
38
|
+
this.#worker.on("error", this.#recordErrorHandler);
|
|
39
|
+
this.#worker.on("exit", this.#recordExitHandler);
|
|
40
|
+
this.#worker.once("online", this.#onlineHandler);
|
|
41
|
+
this.#worker.once("error", this.#spawnErrorHandler);
|
|
42
|
+
this.#worker.once("exit", this.#spawnExitHandler);
|
|
43
|
+
}
|
|
44
|
+
get worker() {
|
|
45
|
+
return this.#worker;
|
|
46
|
+
}
|
|
47
|
+
get alive() {
|
|
48
|
+
return this.#alive;
|
|
49
|
+
}
|
|
50
|
+
get death() {
|
|
51
|
+
return this.#death;
|
|
52
|
+
}
|
|
53
|
+
get promise() {
|
|
54
|
+
return this.#promise;
|
|
55
|
+
}
|
|
56
|
+
evict() {
|
|
57
|
+
this.#alive = false;
|
|
58
|
+
}
|
|
59
|
+
#recordError(error) {
|
|
60
|
+
this.#alive = false;
|
|
61
|
+
if (this.#death === void 0) this.#death = error;
|
|
62
|
+
}
|
|
63
|
+
#recordExit(code) {
|
|
64
|
+
this.#alive = false;
|
|
65
|
+
if (this.#death === void 0) this.#death = /* @__PURE__ */ new Error(`worker thread exited (code ${String(code)})`);
|
|
66
|
+
}
|
|
67
|
+
#online() {
|
|
68
|
+
this.#worker.off("error", this.#spawnErrorHandler);
|
|
69
|
+
this.#worker.off("exit", this.#spawnExitHandler);
|
|
70
|
+
this.#resolve(this);
|
|
71
|
+
}
|
|
72
|
+
#spawnError(error) {
|
|
73
|
+
this.#worker.off("online", this.#onlineHandler);
|
|
74
|
+
this.#worker.off("exit", this.#spawnExitHandler);
|
|
75
|
+
this.#reject(error);
|
|
76
|
+
}
|
|
77
|
+
#spawnExit(code) {
|
|
78
|
+
this.#worker.off("online", this.#onlineHandler);
|
|
79
|
+
this.#worker.off("error", this.#spawnErrorHandler);
|
|
80
|
+
this.#reject(/* @__PURE__ */ new Error(`worker thread exited before coming online (code ${String(code)})`));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/server/validators.ts
|
|
85
|
+
/**
|
|
86
|
+
* Narrow an inbound `message` to a {@link Reply} for a given job `id` — no assertion.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* A total predicate: a record whose `id` matches and whose `ok` discriminant is well-formed.
|
|
90
|
+
* Anything else is rejected so a dispatch listener can ignore foreign or malformed messages.
|
|
91
|
+
*
|
|
92
|
+
* @param value - The inbound message to narrow
|
|
93
|
+
* @param id - The job id a matching reply must carry
|
|
94
|
+
* @returns `true` when the value is this job's well-formed reply
|
|
95
|
+
*/
|
|
96
|
+
function isReply(value, id) {
|
|
97
|
+
const outcome = attempt(() => {
|
|
98
|
+
if (!isRecord(value)) return false;
|
|
99
|
+
if (value.id !== id) return false;
|
|
100
|
+
if (value.ok === true) return "value" in value;
|
|
101
|
+
return value.ok === false && typeof value.error === "string";
|
|
102
|
+
});
|
|
103
|
+
return outcome.success && outcome.value;
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/server/Dispatch.ts
|
|
107
|
+
/**
|
|
108
|
+
* Internal lifecycle entity for one dispatched worker-thread job.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* Owns the stable listener identities, settlement guard, cleanup, result narrowing, and abort
|
|
112
|
+
* eviction for one dispatch. The public {@link dispatch} helper constructs this entity and returns
|
|
113
|
+
* its promise.
|
|
114
|
+
*/
|
|
115
|
+
var Dispatch = class {
|
|
116
|
+
#thread;
|
|
117
|
+
#worker;
|
|
118
|
+
#input;
|
|
119
|
+
#execution;
|
|
120
|
+
#result;
|
|
121
|
+
#id = crypto.randomUUID();
|
|
122
|
+
#promise;
|
|
123
|
+
#fulfill;
|
|
124
|
+
#reject;
|
|
125
|
+
#messageHandler;
|
|
126
|
+
#errorHandler;
|
|
127
|
+
#exitHandler;
|
|
128
|
+
#abortHandler;
|
|
129
|
+
#settled = false;
|
|
130
|
+
constructor(thread, input, execution, result) {
|
|
131
|
+
this.#thread = thread;
|
|
132
|
+
this.#worker = thread.worker;
|
|
133
|
+
this.#input = input;
|
|
134
|
+
this.#execution = execution;
|
|
135
|
+
this.#result = result;
|
|
136
|
+
const settlement = Promise.withResolvers();
|
|
137
|
+
this.#promise = settlement.promise;
|
|
138
|
+
this.#fulfill = settlement.resolve;
|
|
139
|
+
this.#reject = settlement.reject;
|
|
140
|
+
this.#messageHandler = this.#message.bind(this);
|
|
141
|
+
this.#errorHandler = this.#error.bind(this);
|
|
142
|
+
this.#exitHandler = this.#exit.bind(this);
|
|
143
|
+
this.#abortHandler = this.#abort.bind(this);
|
|
144
|
+
this.#start();
|
|
145
|
+
}
|
|
146
|
+
get promise() {
|
|
147
|
+
return this.#promise;
|
|
148
|
+
}
|
|
149
|
+
#start() {
|
|
150
|
+
if (this.#thread.death !== void 0 || !this.#thread.alive) {
|
|
151
|
+
this.#fail(this.#thread.death ?? /* @__PURE__ */ new Error("worker thread is dead"));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
this.#worker.on("message", this.#messageHandler);
|
|
155
|
+
this.#worker.on("error", this.#errorHandler);
|
|
156
|
+
this.#worker.on("exit", this.#exitHandler);
|
|
157
|
+
if (this.#execution.signal.aborted) {
|
|
158
|
+
this.#abort();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.#execution.signal.addEventListener("abort", this.#abortHandler, { once: true });
|
|
162
|
+
try {
|
|
163
|
+
this.#worker.postMessage({
|
|
164
|
+
id: this.#id,
|
|
165
|
+
command: "run",
|
|
166
|
+
input: this.#input
|
|
167
|
+
});
|
|
168
|
+
} catch (error) {
|
|
169
|
+
this.#fail(error instanceof Error ? error : new Error(String(error)));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
#message(value) {
|
|
173
|
+
if (!isReply(value, this.#id)) return;
|
|
174
|
+
if (value.ok) {
|
|
175
|
+
const reply = value.value;
|
|
176
|
+
if (this.#result(reply)) this.#succeed(reply);
|
|
177
|
+
else this.#fail(/* @__PURE__ */ new Error("reply did not satisfy result guard"));
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.#fail(new Error(value.error));
|
|
181
|
+
}
|
|
182
|
+
#error(error) {
|
|
183
|
+
this.#fail(error);
|
|
184
|
+
}
|
|
185
|
+
#exit() {
|
|
186
|
+
this.#fail(/* @__PURE__ */ new Error("worker thread exited"));
|
|
187
|
+
}
|
|
188
|
+
#abort() {
|
|
189
|
+
this.#worker.postMessage({
|
|
190
|
+
id: this.#id,
|
|
191
|
+
command: "abort"
|
|
192
|
+
});
|
|
193
|
+
if (this.#thread instanceof Thread) this.#thread.evict();
|
|
194
|
+
this.#worker.terminate();
|
|
195
|
+
this.#fail(/* @__PURE__ */ new Error("job aborted"));
|
|
196
|
+
}
|
|
197
|
+
#succeed(value) {
|
|
198
|
+
if (this.#settled) return;
|
|
199
|
+
this.#settled = true;
|
|
200
|
+
this.#detach();
|
|
201
|
+
this.#fulfill(value);
|
|
202
|
+
}
|
|
203
|
+
#fail(error) {
|
|
204
|
+
if (this.#settled) return;
|
|
205
|
+
this.#settled = true;
|
|
206
|
+
this.#detach();
|
|
207
|
+
this.#reject(error);
|
|
208
|
+
}
|
|
209
|
+
#detach() {
|
|
210
|
+
this.#worker.off("message", this.#messageHandler);
|
|
211
|
+
this.#worker.off("error", this.#errorHandler);
|
|
212
|
+
this.#worker.off("exit", this.#exitHandler);
|
|
213
|
+
this.#execution.signal.removeEventListener("abort", this.#abortHandler);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
//#endregion
|
|
6
217
|
//#region src/server/helpers.ts
|
|
7
218
|
/**
|
|
8
219
|
* Spawn one worker thread and resolve a live {@link NodeThread} once it comes online.
|
|
@@ -26,60 +237,7 @@ import { createDatabaseQueueStore } from "@orkestrel/queue";
|
|
|
26
237
|
* @returns A promise resolving the online {@link NodeThread}
|
|
27
238
|
*/
|
|
28
239
|
function spawnThread(script, workerData) {
|
|
29
|
-
|
|
30
|
-
const thread = {
|
|
31
|
-
worker,
|
|
32
|
-
alive: true,
|
|
33
|
-
death: void 0
|
|
34
|
-
};
|
|
35
|
-
worker.on("error", (error) => {
|
|
36
|
-
thread.alive = false;
|
|
37
|
-
if (thread.death === void 0) thread.death = error;
|
|
38
|
-
});
|
|
39
|
-
worker.on("exit", (code) => {
|
|
40
|
-
thread.alive = false;
|
|
41
|
-
if (thread.death === void 0) thread.death = /* @__PURE__ */ new Error(`worker thread exited (code ${code})`);
|
|
42
|
-
});
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
const onOnline = () => {
|
|
45
|
-
worker.off("error", onError);
|
|
46
|
-
worker.off("exit", onExit);
|
|
47
|
-
resolve(thread);
|
|
48
|
-
};
|
|
49
|
-
const onError = (error) => {
|
|
50
|
-
worker.off("online", onOnline);
|
|
51
|
-
worker.off("exit", onExit);
|
|
52
|
-
reject(error);
|
|
53
|
-
};
|
|
54
|
-
const onExit = (code) => {
|
|
55
|
-
worker.off("online", onOnline);
|
|
56
|
-
worker.off("error", onError);
|
|
57
|
-
reject(/* @__PURE__ */ new Error(`worker thread exited before coming online (code ${code})`));
|
|
58
|
-
};
|
|
59
|
-
worker.once("online", onOnline);
|
|
60
|
-
worker.once("error", onError);
|
|
61
|
-
worker.once("exit", onExit);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Narrow an inbound `message` to a {@link Reply} for a given job `id` — no assertion.
|
|
66
|
-
*
|
|
67
|
-
* @remarks
|
|
68
|
-
* A total {@link Guard}-style predicate (never throws): a record whose `id` matches and
|
|
69
|
-
* whose `ok` discriminant is well-formed (a `true` carries any `value`; a `false` carries a
|
|
70
|
-
* string `error`). Anything else — another job's reply, a malformed payload — is `false`, so
|
|
71
|
-
* a {@link dispatch} listener ignores it (a thread that chatters on the channel can't corrupt
|
|
72
|
-
* a job).
|
|
73
|
-
*
|
|
74
|
-
* @param value - The inbound message to narrow
|
|
75
|
-
* @param id - The job id a matching reply must carry
|
|
76
|
-
* @returns `true` (narrowing `value` to {@link Reply}) when it is this job's well-formed reply
|
|
77
|
-
*/
|
|
78
|
-
function isReply(value, id) {
|
|
79
|
-
if (!isRecord(value)) return false;
|
|
80
|
-
if (value.id !== id) return false;
|
|
81
|
-
if (value.ok === true) return true;
|
|
82
|
-
return value.ok === false && typeof value.error === "string";
|
|
240
|
+
return new Thread(script, workerData).promise;
|
|
83
241
|
}
|
|
84
242
|
/**
|
|
85
243
|
* Dispatch one job to a leased {@link NodeThread} and await its narrowed reply.
|
|
@@ -107,73 +265,7 @@ function isReply(value, id) {
|
|
|
107
265
|
* @returns A promise resolving the narrowed `TResult`, or rejecting on error / abort
|
|
108
266
|
*/
|
|
109
267
|
function dispatch(thread, input, execution, result) {
|
|
110
|
-
|
|
111
|
-
const worker = thread.worker;
|
|
112
|
-
return new Promise((resolve, reject) => {
|
|
113
|
-
if (thread.death !== void 0 || !thread.alive) {
|
|
114
|
-
reject(thread.death ?? /* @__PURE__ */ new Error("worker thread is dead"));
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
let settled = false;
|
|
118
|
-
let detach = () => {};
|
|
119
|
-
const settle = (action) => {
|
|
120
|
-
if (settled) return;
|
|
121
|
-
settled = true;
|
|
122
|
-
detach();
|
|
123
|
-
action();
|
|
124
|
-
};
|
|
125
|
-
const onMessage = (value) => {
|
|
126
|
-
if (!isReply(value, id)) return;
|
|
127
|
-
if (value.ok) {
|
|
128
|
-
const reply = value.value;
|
|
129
|
-
if (result(reply)) settle(() => resolve(reply));
|
|
130
|
-
else settle(() => reject(/* @__PURE__ */ new Error("reply did not satisfy result guard")));
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const message = value.error;
|
|
134
|
-
settle(() => reject(new Error(message)));
|
|
135
|
-
};
|
|
136
|
-
const onError = (error) => {
|
|
137
|
-
thread.alive = false;
|
|
138
|
-
settle(() => reject(error));
|
|
139
|
-
};
|
|
140
|
-
const onExit = () => {
|
|
141
|
-
thread.alive = false;
|
|
142
|
-
settle(() => reject(/* @__PURE__ */ new Error("worker thread exited")));
|
|
143
|
-
};
|
|
144
|
-
const onAbort = () => {
|
|
145
|
-
worker.postMessage({
|
|
146
|
-
id,
|
|
147
|
-
command: "abort"
|
|
148
|
-
});
|
|
149
|
-
thread.alive = false;
|
|
150
|
-
worker.terminate();
|
|
151
|
-
settle(() => reject(/* @__PURE__ */ new Error("job aborted")));
|
|
152
|
-
};
|
|
153
|
-
detach = () => {
|
|
154
|
-
worker.off("message", onMessage);
|
|
155
|
-
worker.off("error", onError);
|
|
156
|
-
worker.off("exit", onExit);
|
|
157
|
-
execution.signal.removeEventListener("abort", onAbort);
|
|
158
|
-
};
|
|
159
|
-
worker.on("message", onMessage);
|
|
160
|
-
worker.on("error", onError);
|
|
161
|
-
worker.on("exit", onExit);
|
|
162
|
-
if (execution.signal.aborted) {
|
|
163
|
-
onAbort();
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
execution.signal.addEventListener("abort", onAbort, { once: true });
|
|
167
|
-
try {
|
|
168
|
-
worker.postMessage({
|
|
169
|
-
id,
|
|
170
|
-
command: "run",
|
|
171
|
-
input
|
|
172
|
-
});
|
|
173
|
-
} catch (error) {
|
|
174
|
-
settle(() => reject(error instanceof Error ? error : new Error(String(error))));
|
|
175
|
-
}
|
|
176
|
-
});
|
|
268
|
+
return new Dispatch(thread, input, execution, result).promise;
|
|
177
269
|
}
|
|
178
270
|
//#endregion
|
|
179
271
|
//#region src/server/serve.ts
|
|
@@ -255,6 +347,49 @@ function serveWorker(options) {
|
|
|
255
347
|
});
|
|
256
348
|
}
|
|
257
349
|
//#endregion
|
|
350
|
+
//#region src/server/NodeWorker.ts
|
|
351
|
+
/**
|
|
352
|
+
* Internal composition entity backing {@link createNodeWorker}.
|
|
353
|
+
*
|
|
354
|
+
* @remarks
|
|
355
|
+
* Supplies bound Pool and Queue operations without nested function assignments. The resulting
|
|
356
|
+
* public entity remains the plain core {@link WorkerInterface}.
|
|
357
|
+
*/
|
|
358
|
+
var NodeWorker = class {
|
|
359
|
+
#options;
|
|
360
|
+
constructor(options) {
|
|
361
|
+
this.#options = options;
|
|
362
|
+
}
|
|
363
|
+
build() {
|
|
364
|
+
return createWorker({
|
|
365
|
+
pool: {
|
|
366
|
+
create: this.#create.bind(this),
|
|
367
|
+
destroy: this.#destroy.bind(this),
|
|
368
|
+
validate: this.#validate.bind(this),
|
|
369
|
+
...this.#options.concurrency !== void 0 ? { max: this.#options.concurrency } : {}
|
|
370
|
+
},
|
|
371
|
+
handler: this.#handle.bind(this),
|
|
372
|
+
...this.#options.concurrency !== void 0 ? { concurrency: this.#options.concurrency } : {},
|
|
373
|
+
...this.#options.retries !== void 0 ? { retries: this.#options.retries } : {},
|
|
374
|
+
...this.#options.timeout !== void 0 ? { timeout: this.#options.timeout } : {},
|
|
375
|
+
...this.#options.store !== void 0 ? { store: this.#options.store } : {}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
#create() {
|
|
379
|
+
return spawnThread(this.#options.script, this.#options.workerData);
|
|
380
|
+
}
|
|
381
|
+
async #destroy(thread) {
|
|
382
|
+
await thread.worker.terminate();
|
|
383
|
+
}
|
|
384
|
+
#validate(thread) {
|
|
385
|
+
return thread.alive && thread.worker.threadId > 0;
|
|
386
|
+
}
|
|
387
|
+
#handle(input, thread, execution) {
|
|
388
|
+
if (!this.#options.input(input)) return Promise.reject(/* @__PURE__ */ new Error("input did not satisfy input guard"));
|
|
389
|
+
return dispatch(thread, input, execution, this.#options.result);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
//#endregion
|
|
258
393
|
//#region src/server/factories.ts
|
|
259
394
|
/**
|
|
260
395
|
* Create a persistent JSON-file {@link QueueStoreInterface} — the core
|
|
@@ -331,22 +466,7 @@ function createJSONQueueStore(path, input) {
|
|
|
331
466
|
* ```
|
|
332
467
|
*/
|
|
333
468
|
function createNodeWorker(options) {
|
|
334
|
-
return
|
|
335
|
-
pool: {
|
|
336
|
-
create: () => spawnThread(options.script, options.workerData),
|
|
337
|
-
destroy: (thread) => thread.worker.terminate().then(() => {}),
|
|
338
|
-
validate: (thread) => thread.alive && thread.worker.threadId > 0,
|
|
339
|
-
max: options.concurrency
|
|
340
|
-
},
|
|
341
|
-
handler: (input, thread, execution) => {
|
|
342
|
-
if (!options.input(input)) return Promise.reject(/* @__PURE__ */ new Error("input did not satisfy input guard"));
|
|
343
|
-
return dispatch(thread, input, execution, options.result);
|
|
344
|
-
},
|
|
345
|
-
concurrency: options.concurrency,
|
|
346
|
-
retries: options.retries,
|
|
347
|
-
timeout: options.timeout,
|
|
348
|
-
store: options.store
|
|
349
|
-
});
|
|
469
|
+
return new NodeWorker(options).build();
|
|
350
470
|
}
|
|
351
471
|
//#endregion
|
|
352
472
|
export { createJSONQueueStore, createNodeWorker, dispatch, isReply, serveWorker, spawnThread };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/server/helpers.ts","../../../src/server/serve.ts","../../../src/server/factories.ts"],"sourcesContent":["import type { QueueExecution } from '@orkestrel/queue'\nimport type { Guard, NodeThread, Reply } from './types.js'\nimport { Worker as ThreadWorker } from 'node:worker_threads'\nimport { isRecord } from '@orkestrel/contract'\n\n// === The wire protocol (main ↔ thread)\n//\n// The main-side half of the run/abort/reply protocol `serveWorker` answers — spawning a\n// pooled thread, narrowing its replies, and dispatching one job at a time. The envelope\n// types ({@link Reply}, {@link NodeThread}) live in `./types.js` (AGENTS §5); the public\n// bridge across the structured-clone boundary is the `input` / `result` `Guard`s, which\n// narrow the envelopes' opaque `unknown` payloads with no assertion (AGENTS §14).\n\n/**\n * Spawn one worker thread and resolve a live {@link NodeThread} once it comes online.\n *\n * @remarks\n * Constructs the thread with the `script` module and the cloned `workerData`, then\n * resolves on the thread's `online` event (rejecting on an early `error` OR an `exit`\n * that arrives before `online`, so the spawn promise is total — it can never dangle on a\n * thread that died without erroring). The wrapper attaches persistent `error` / `exit`\n * listeners that flip `alive` to `false` AND latch the first terminal event on\n * {@link NodeThread.death}: a crash is observable to an in-flight {@link dispatch} (via\n * its own listeners), to the pool's `validate` (via `alive`), and — crucially — to a\n * dispatch that attaches AFTER the death (via the latch). The latch closes a real race:\n * under event-loop pressure a dead thread's `online` + `error` + `exit` are delivered in\n * ONE synchronous exit-drain batch, so every death event fires before the microtask chain\n * resolving this spawn can hand the thread to `dispatch` — without the latch that job\n * would await events that already fired, forever. The pool's `create` hook calls this.\n *\n * @param script - The worker module each thread runs (must call `serveWorker`)\n * @param workerData - Opaque, structured-cloneable data handed to the thread at spawn\n * @returns A promise resolving the online {@link NodeThread}\n */\nexport function spawnThread(script: string | URL, workerData: unknown): Promise<NodeThread> {\n\tconst worker = new ThreadWorker(script, { workerData })\n\tconst thread: NodeThread = { worker, alive: true, death: undefined }\n\t// The persistent death latch — attached BEFORE any once-listener, so the first terminal\n\t// event records its cause on the record even when it fires inside a batched exit drain.\n\tworker.on('error', (error: Error) => {\n\t\tthread.alive = false\n\t\tif (thread.death === undefined) thread.death = error\n\t})\n\tworker.on('exit', (code: number) => {\n\t\tthread.alive = false\n\t\tif (thread.death === undefined) thread.death = new Error(`worker thread exited (code ${code})`)\n\t})\n\treturn new Promise<NodeThread>((resolve, reject) => {\n\t\tconst onOnline = (): void => {\n\t\t\tworker.off('error', onError)\n\t\t\tworker.off('exit', onExit)\n\t\t\tresolve(thread)\n\t\t}\n\t\tconst onError = (error: Error): void => {\n\t\t\tworker.off('online', onOnline)\n\t\t\tworker.off('exit', onExit)\n\t\t\treject(error)\n\t\t}\n\t\tconst onExit = (code: number): void => {\n\t\t\tworker.off('online', onOnline)\n\t\t\tworker.off('error', onError)\n\t\t\treject(new Error(`worker thread exited before coming online (code ${code})`))\n\t\t}\n\t\tworker.once('online', onOnline)\n\t\tworker.once('error', onError)\n\t\tworker.once('exit', onExit)\n\t})\n}\n\n/**\n * Narrow an inbound `message` to a {@link Reply} for a given job `id` — no assertion.\n *\n * @remarks\n * A total {@link Guard}-style predicate (never throws): a record whose `id` matches and\n * whose `ok` discriminant is well-formed (a `true` carries any `value`; a `false` carries a\n * string `error`). Anything else — another job's reply, a malformed payload — is `false`, so\n * a {@link dispatch} listener ignores it (a thread that chatters on the channel can't corrupt\n * a job).\n *\n * @param value - The inbound message to narrow\n * @param id - The job id a matching reply must carry\n * @returns `true` (narrowing `value` to {@link Reply}) when it is this job's well-formed reply\n */\nexport function isReply(value: unknown, id: string): value is Reply {\n\tif (!isRecord(value)) return false\n\tif (value.id !== id) return false\n\tif (value.ok === true) return true\n\treturn value.ok === false && typeof value.error === 'string'\n}\n\n/**\n * Dispatch one job to a leased {@link NodeThread} and await its narrowed reply.\n *\n * @remarks\n * Mints a fresh `id`, posts a `run` envelope, and resolves when the thread replies for\n * that id: a success `value` is narrowed through `result` (a value that fails the guard\n * rejects — the zero-`as` type bridge), a failure rejects with the thread's error string.\n * A thread that ALREADY died rejects synchronously at entry from the latched\n * {@link NodeThread.death} — its death events fired before this dispatch existed (under\n * load they arrive in one batched exit drain) and will never fire again, so waiting on\n * the listeners below would dangle forever; the latch makes the death total across every\n * event ordering. If the thread `error`s / `exit`s mid-flight it is marked dead and the\n * job rejects. On `execution.signal` abort it posts an `abort` envelope (cooperative) AND\n * evicts the thread — `alive = false` + `terminate()` — because CPU-bound work cannot\n * honour the signal; the freed pool slot then gets a fresh thread. Every listener (the\n * thread's `message` / `error` / `exit` and the signal's `abort`) is removed on settle,\n * and a `settled` guard prevents a double-settle.\n *\n * @typeParam TResult - The reply type the `result` guard narrows to\n * @param thread - The leased thread to run the job on\n * @param input - The work payload (structured-cloned to the thread)\n * @param execution - The per-attempt handle; its `signal` aborts → terminate + evict\n * @param result - The {@link Guard} narrowing the reply value with no assertion\n * @returns A promise resolving the narrowed `TResult`, or rejecting on error / abort\n */\nexport function dispatch<TResult>(\n\tthread: NodeThread,\n\tinput: unknown,\n\texecution: QueueExecution,\n\tresult: Guard<TResult>,\n): Promise<TResult> {\n\tconst id = crypto.randomUUID()\n\tconst worker = thread.worker\n\treturn new Promise<TResult>((resolve, reject) => {\n\t\t// The latched-death entry check: a thread that died BEFORE this dispatch attached has\n\t\t// already emitted its `error` / `exit` (a batched exit drain delivers them before this\n\t\t// microtask runs) — no listener below will ever fire, and a `postMessage` to it is a\n\t\t// silent no-op. Reject NOW from the latch; this check + the attaches are synchronous,\n\t\t// so there is no gap a death can slip through.\n\t\tif (thread.death !== undefined || !thread.alive) {\n\t\t\treject(thread.death ?? new Error('worker thread is dead'))\n\t\t\treturn\n\t\t}\n\t\tlet settled = false\n\t\tlet detach = (): void => {}\n\t\tconst settle = (action: () => void): void => {\n\t\t\tif (settled) return\n\t\t\tsettled = true\n\t\t\tdetach()\n\t\t\taction()\n\t\t}\n\t\tconst onMessage = (value: unknown): void => {\n\t\t\tif (!isReply(value, id)) return\n\t\t\tif (value.ok) {\n\t\t\t\tconst reply = value.value\n\t\t\t\tif (result(reply)) settle(() => resolve(reply))\n\t\t\t\telse settle(() => reject(new Error('reply did not satisfy result guard')))\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst message = value.error\n\t\t\tsettle(() => reject(new Error(message)))\n\t\t}\n\t\tconst onError = (error: Error): void => {\n\t\t\tthread.alive = false\n\t\t\tsettle(() => reject(error))\n\t\t}\n\t\tconst onExit = (): void => {\n\t\t\tthread.alive = false\n\t\t\tsettle(() => reject(new Error('worker thread exited')))\n\t\t}\n\t\t// Cooperative abort first, then EVICT: CPU-bound work won't honour the signal, so\n\t\t// terminate the thread and mark it dead — the pool replaces it on the next acquire.\n\t\t// NOTE: this `terminate()` may run TWICE — once here, and again when the pool's\n\t\t// `destroy` hook (`thread.worker.terminate()`) tears down the now-dead thread its\n\t\t// `validate` evicts. A second `terminate()` on an already-terminated Node thread is a\n\t\t// safe, idempotent no-op (it resolves with the prior exit code), so do NOT \"dedupe\" it\n\t\t// by gating on `alive` — that would skip the pool's eviction and reuse a tainted thread.\n\t\tconst onAbort = (): void => {\n\t\t\tworker.postMessage({ id, command: 'abort' })\n\t\t\tthread.alive = false\n\t\t\tvoid worker.terminate()\n\t\t\tsettle(() => reject(new Error('job aborted')))\n\t\t}\n\t\tdetach = (): void => {\n\t\t\tworker.off('message', onMessage)\n\t\t\tworker.off('error', onError)\n\t\t\tworker.off('exit', onExit)\n\t\t\texecution.signal.removeEventListener('abort', onAbort)\n\t\t}\n\t\tworker.on('message', onMessage)\n\t\tworker.on('error', onError)\n\t\tworker.on('exit', onExit)\n\t\tif (execution.signal.aborted) {\n\t\t\tonAbort()\n\t\t\treturn\n\t\t}\n\t\texecution.signal.addEventListener('abort', onAbort, { once: true })\n\t\t// `postMessage` structured-clones `input`; a non-cloneable payload throws here —\n\t\t// settle-reject so the listeners detach (no leak) rather than escaping the executor.\n\t\ttry {\n\t\t\tworker.postMessage({ id, command: 'run', input })\n\t\t} catch (error: unknown) {\n\t\t\tsettle(() => reject(error instanceof Error ? error : new Error(String(error))))\n\t\t}\n\t})\n}\n","import type { ServeWorkerOptions } from './types.js'\nimport { parentPort } from 'node:worker_threads'\n\n// The worker-side entry. SELF-CONTAINED by necessity: this module loads as RAW `.ts`\n// inside a spawned thread (Node ≥ 23.6 type-stripping), so it imports ONLY\n// `node:worker_threads` at runtime — no `@src/*`, no `.js`-relative value imports (the\n// only non-node import is the type-only `ServeWorkerOptions`, fully erased at runtime).\n// Its guards are inlined for the same reason. A worker script that needs the cloned\n// `workerData` reads it directly from `node:worker_threads` (it is in a thread already).\n\n// Inlined record guard (do NOT import `isRecord` from `@src/core` — see above). Total:\n// adversarial input returns `false`, never throws (AGENTS §14).\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n// Narrow an inbound message to a `run` envelope (a string `id` + a `'run'` command + an\n// `input` payload) — no assertion.\nfunction isRun(value: unknown): value is { readonly id: string; readonly input: unknown } {\n\treturn (\n\t\tisRecord(value) && typeof value.id === 'string' && value.command === 'run' && 'input' in value\n\t)\n}\n\n// Narrow an inbound message to an `abort` envelope (a string `id` + an `'abort'` command).\nfunction isAbort(value: unknown): value is { readonly id: string } {\n\treturn isRecord(value) && typeof value.id === 'string' && value.command === 'abort'\n}\n\n/**\n * Register a worker-thread handler — the worker-side half of {@link createNodeWorker}.\n *\n * @remarks\n * Must be the spawned thread's module entry. It listens on the parent port for the\n * run/abort protocol: a `run` message narrows its `input` through `options.input` (an\n * invalid payload replies with an error envelope, never running the handler), then runs\n * `options.handler(input, { signal })` and replies `{ id, ok: true, value }` on success or\n * `{ id, ok: false, error }` on throw. Each in-flight job has its own `AbortController`,\n * so an `abort` message for that id fires the handler's `signal` (cooperative — the main\n * side ALSO terminates the thread, so a handler that ignores its signal is still stopped).\n * Every inbound message is narrowed with the inlined guards — no `as`. On the main thread\n * (`parentPort === null`) it is a no-op.\n *\n * @typeParam TInput - The work payload (inferred from `options.input`)\n * @typeParam TResult - The value the handler resolves (the reply payload)\n * @param options - The `input` guard and the `handler` (see {@link ServeWorkerOptions})\n *\n * @example\n * ```ts\n * // double.ts — a worker script\n * import { serveWorker } from '@src/server'\n *\n * serveWorker<number, number>({\n * \tinput: (value): value is number => typeof value === 'number',\n * \thandler: (value) => value * 2,\n * })\n * ```\n */\nexport function serveWorker<TInput, TResult>(options: ServeWorkerOptions<TInput, TResult>): void {\n\tconst port = parentPort\n\tif (port === null) return\n\tconst controllers = new Map<string, AbortController>()\n\tport.on('message', (raw: unknown) => {\n\t\tif (isAbort(raw)) {\n\t\t\tcontrollers.get(raw.id)?.abort()\n\t\t\treturn\n\t\t}\n\t\tif (!isRun(raw)) return\n\t\tconst id = raw.id\n\t\tif (!options.input(raw.input)) {\n\t\t\tport.postMessage({ id, ok: false, error: 'input did not satisfy input guard' })\n\t\t\treturn\n\t\t}\n\t\tconst input = raw.input\n\t\tconst controller = new AbortController()\n\t\tcontrollers.set(id, controller)\n\t\t// Defer the handler call into the `then` so a SYNCHRONOUS throw becomes a rejection\n\t\t// (not an uncaught thread exception) and is reported as an error reply.\n\t\tPromise.resolve()\n\t\t\t.then(() => options.handler(input, { signal: controller.signal }))\n\t\t\t.then(\n\t\t\t\t(value) => {\n\t\t\t\t\tcontrollers.delete(id)\n\t\t\t\t\tport.postMessage({ id, ok: true, value })\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tcontrollers.delete(id)\n\t\t\t\t\tport.postMessage({\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tok: false,\n\t\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t)\n\t})\n}\n","import type { WorkerInterface } from '@src/core'\nimport type { ContractShape, Infer } from '@orkestrel/contract'\nimport type { QueueStoreInterface } from '@orkestrel/queue'\nimport type { NodeThread, NodeWorkerOptions } from './types.js'\nimport { createWorker } from '@src/core'\nimport { createJSONDriver } from '@orkestrel/database/server'\nimport { createDatabaseQueueStore } from '@orkestrel/queue'\nimport { dispatch, spawnThread } from './helpers.js'\n\n/**\n * Create a persistent JSON-file {@link QueueStoreInterface} — the core\n * `createDatabaseQueueStore` over a server {@link createJSONDriver}.\n *\n * @remarks\n * A queue's durable state is just a database table, so JSON persistence reuses the\n * existing JSON-file driver rather than a bespoke store: the entries are written to\n * (and reloaded from) the file at `path`, surviving a process restart. There is no new\n * class — the store engine ({@link createDatabaseQueueStore}) is shared, and only the\n * driver changes where the bytes live. The `input` shape must be JSON-serializable\n * (the JSON driver round-trips it as JSON). Build a second store over the SAME `path` to\n * resume the outstanding entries a prior store persisted.\n *\n * @typeParam TInput - The contract shape of each entry's `input` payload\n * @param path - The JSON file the entries are loaded from and flushed to\n * @param input - The {@link ContractShape} for the work payload (the `input` column)\n * @returns A JSON-file-backed {@link QueueStoreInterface}, typed by `input`\n *\n * @example\n * ```ts\n * import { stringShape } from '@src/core'\n * import { createJSONQueueStore } from '@src/server'\n *\n * const store = createJSONQueueStore('data/queue.json', stringShape())\n * await store.save({ id: 'job-1', input: 'https://example.com', attempts: 0 })\n * // A later process resumes the outstanding work:\n * const resumed = createJSONQueueStore('data/queue.json', stringShape())\n * const outstanding = await resumed.load()\n * ```\n */\nexport function createJSONQueueStore<TInput extends ContractShape>(\n\tpath: string,\n\tinput: TInput,\n): QueueStoreInterface<Infer<TInput>> {\n\treturn createDatabaseQueueStore(input, createJSONDriver(path))\n}\n\n/**\n * Create a CPU-parallel worker over `node:worker_threads` — a thin specialization of the\n * core `createWorker` whose pooled resource is a worker THREAD.\n *\n * @remarks\n * Composition, not reimplementation: all concurrency, retries, per-attempt timeout,\n * lifecycle, and durability are the core `Worker`'s (a `Queue` ⨉ `Pool`). This factory\n * supplies only the thread pairing — the pool `create`s a thread (via `spawnThread`),\n * `destroy`s it with `terminate()`, and `validate`s it by `alive && threadId > 0` (so an\n * evicted / crashed thread is dropped and replaced) — and an internal handler that\n * narrows the input through `options.input` (fail-fast before the structured-clone\n * boundary) then `dispatch`es the job to the leased thread, narrowing the reply through\n * `options.result`. Both generics INFER from the `input` / `result` guards, so call sites\n * need no explicit type arguments. The boundary is crossed with ZERO `as`: the guards\n * reconstruct `TInput` / `TResult` by validation (AGENTS §14). An `abort` / `timeout`\n * TERMINATES the in-flight thread (CPU-bound work can't honour a signal) and evicts it; a\n * subsequent job spawns a fresh thread. The worker script's module must call\n * `serveWorker`. Returns the plain {@link WorkerInterface} — its methods are the Worker's.\n *\n * @typeParam TInput - The work payload each job carries (inferred from `input`)\n * @typeParam TResult - The value a thread resolves for a job (inferred from `result`)\n * @param options - The `script` plus the `input` / `result` guards and optional\n * `workerData` / `concurrency` / `retries` / `timeout` / `store`\n * (see {@link NodeWorkerOptions})\n * @returns A working {@link WorkerInterface} backed by a thread pool\n *\n * @example\n * ```ts\n * import { createNodeWorker } from '@src/server'\n *\n * const worker = createNodeWorker({\n * \tscript: new URL('./double.js', import.meta.url),\n * \tinput: (value): value is number => typeof value === 'number',\n * \tresult: (value): value is number => typeof value === 'number',\n * \tconcurrency: 4,\n * })\n *\n * const doubled = await worker.enqueue(21) // 42, computed on a worker thread\n * worker.destroy() // terminates every thread\n * ```\n */\nexport function createNodeWorker<TInput, TResult>(\n\toptions: NodeWorkerOptions<TInput, TResult>,\n): WorkerInterface<TInput, TResult> {\n\treturn createWorker<TInput, NodeThread, TResult>({\n\t\tpool: {\n\t\t\tcreate: () => spawnThread(options.script, options.workerData),\n\t\t\tdestroy: (thread) => thread.worker.terminate().then(() => {}),\n\t\t\tvalidate: (thread) => thread.alive && thread.worker.threadId > 0,\n\t\t\tmax: options.concurrency,\n\t\t},\n\t\thandler: (input, thread, execution) => {\n\t\t\tif (!options.input(input)) {\n\t\t\t\treturn Promise.reject(new Error('input did not satisfy input guard'))\n\t\t\t}\n\t\t\treturn dispatch(thread, input, execution, options.result)\n\t\t},\n\t\tconcurrency: options.concurrency,\n\t\tretries: options.retries,\n\t\ttimeout: options.timeout,\n\t\tstore: options.store,\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,YAAY,QAAsB,YAA0C;CAC3F,MAAM,SAAS,IAAI,OAAa,QAAQ,EAAE,WAAW,CAAC;CACtD,MAAM,SAAqB;EAAE;EAAQ,OAAO;EAAM,OAAO,KAAA;CAAU;CAGnE,OAAO,GAAG,UAAU,UAAiB;EACpC,OAAO,QAAQ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AM,UAAU,OAAO,KAAK;GAC7D,CAAC;EACF,CACD;CACF,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACxDA,SAAgB,qBACf,MACA,OACqC;CACrC,OAAO,yBAAyB,OAAO,iBAAiB,IAAI,CAAC;AAC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,iBACf,SACmC;CACnC,OAAO,aAA0C;EAChD,MAAM;GACL,cAAc,YAAY,QAAQ,QAAQ,QAAQ,UAAU;GAC5D,UAAU,WAAW,OAAO,OAAO,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC;GAC5D,WAAW,WAAW,OAAO,SAAS,OAAO,OAAO,WAAW;GAC/D,KAAK,QAAQ;EACd;EACA,UAAU,OAAO,QAAQ,cAAc;GACtC,IAAI,CAAC,QAAQ,MAAM,KAAK,GACvB,OAAO,QAAQ,uBAAO,IAAI,MAAM,mCAAmC,CAAC;GAErE,OAAO,SAAS,QAAQ,OAAO,WAAW,QAAQ,MAAM;EACzD;EACA,aAAa,QAAQ;EACrB,SAAS,QAAQ;EACjB,SAAS,QAAQ;EACjB,OAAO,QAAQ;CAChB,CAAC;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["#worker","#promise","#resolve","#reject","#recordErrorHandler","#recordExitHandler","#onlineHandler","#spawnErrorHandler","#spawnExitHandler","#recordError","#recordExit","#online","#spawnError","#spawnExit","#alive","#death","#thread","#worker","#input","#execution","#result","#id","#promise","#fulfill","#reject","#messageHandler","#errorHandler","#exitHandler","#abortHandler","#message","#error","#exit","#abort","#start","#fail","#succeed","#settled","#detach","#options","#create","#destroy","#validate","#handle"],"sources":["../../../src/server/Thread.ts","../../../src/server/validators.ts","../../../src/server/Dispatch.ts","../../../src/server/helpers.ts","../../../src/server/serve.ts","../../../src/server/NodeWorker.ts","../../../src/server/factories.ts"],"sourcesContent":["import type { NodeThread } from './types.js'\nimport { Worker as ThreadWorker } from 'node:worker_threads'\n\n/**\n * Internal mutable implementation of the readonly {@link NodeThread} observation contract.\n *\n * @remarks\n * Liveness and the first terminal error live behind runtime-private fields. Consumers observe\n * their current values through readonly getters, while the worker lifecycle records transitions\n * through bound instance methods without exposing writable contract properties.\n */\nexport class Thread implements NodeThread {\n\treadonly #worker: ThreadWorker\n\treadonly #promise: Promise<NodeThread>\n\treadonly #resolve: (value: NodeThread | PromiseLike<NodeThread>) => void\n\treadonly #reject: (reason?: unknown) => void\n\treadonly #recordErrorHandler: (error: Error) => void\n\treadonly #recordExitHandler: (code: number) => void\n\treadonly #onlineHandler: () => void\n\treadonly #spawnErrorHandler: (error: Error) => void\n\treadonly #spawnExitHandler: (code: number) => void\n\t#alive = true\n\t#death: Error | undefined\n\n\tconstructor(script: string | URL, workerData: unknown) {\n\t\tthis.#worker = new ThreadWorker(script, {\n\t\t\t...(workerData !== undefined ? { workerData } : {}),\n\t\t})\n\t\tconst readiness = Promise.withResolvers<NodeThread>()\n\t\tthis.#promise = readiness.promise\n\t\tthis.#resolve = readiness.resolve\n\t\tthis.#reject = readiness.reject\n\t\tthis.#recordErrorHandler = this.#recordError.bind(this)\n\t\tthis.#recordExitHandler = this.#recordExit.bind(this)\n\t\tthis.#onlineHandler = this.#online.bind(this)\n\t\tthis.#spawnErrorHandler = this.#spawnError.bind(this)\n\t\tthis.#spawnExitHandler = this.#spawnExit.bind(this)\n\n\t\tthis.#worker.on('error', this.#recordErrorHandler)\n\t\tthis.#worker.on('exit', this.#recordExitHandler)\n\t\tthis.#worker.once('online', this.#onlineHandler)\n\t\tthis.#worker.once('error', this.#spawnErrorHandler)\n\t\tthis.#worker.once('exit', this.#spawnExitHandler)\n\t}\n\n\tget worker(): ThreadWorker {\n\t\treturn this.#worker\n\t}\n\n\tget alive(): boolean {\n\t\treturn this.#alive\n\t}\n\n\tget death(): Error | undefined {\n\t\treturn this.#death\n\t}\n\n\tget promise(): Promise<NodeThread> {\n\t\treturn this.#promise\n\t}\n\n\tevict(): void {\n\t\tthis.#alive = false\n\t}\n\n\t#recordError(error: Error): void {\n\t\tthis.#alive = false\n\t\tif (this.#death === undefined) this.#death = error\n\t}\n\n\t#recordExit(code: number): void {\n\t\tthis.#alive = false\n\t\tif (this.#death === undefined) {\n\t\t\tthis.#death = new Error(`worker thread exited (code ${String(code)})`)\n\t\t}\n\t}\n\n\t#online(): void {\n\t\tthis.#worker.off('error', this.#spawnErrorHandler)\n\t\tthis.#worker.off('exit', this.#spawnExitHandler)\n\t\tthis.#resolve(this)\n\t}\n\n\t#spawnError(error: Error): void {\n\t\tthis.#worker.off('online', this.#onlineHandler)\n\t\tthis.#worker.off('exit', this.#spawnExitHandler)\n\t\tthis.#reject(error)\n\t}\n\n\t#spawnExit(code: number): void {\n\t\tthis.#worker.off('online', this.#onlineHandler)\n\t\tthis.#worker.off('error', this.#spawnErrorHandler)\n\t\tthis.#reject(new Error(`worker thread exited before coming online (code ${String(code)})`))\n\t}\n}\n","import type { Reply } from './types.js'\nimport { attempt, isRecord } from '@orkestrel/contract'\n\n/**\n * Narrow an inbound `message` to a {@link Reply} for a given job `id` — no assertion.\n *\n * @remarks\n * A total predicate: a record whose `id` matches and whose `ok` discriminant is well-formed.\n * Anything else is rejected so a dispatch listener can ignore foreign or malformed messages.\n *\n * @param value - The inbound message to narrow\n * @param id - The job id a matching reply must carry\n * @returns `true` when the value is this job's well-formed reply\n */\nexport function isReply(value: unknown, id: string): value is Reply {\n\tconst outcome = attempt(() => {\n\t\tif (!isRecord(value)) return false\n\t\tif (value.id !== id) return false\n\t\tif (value.ok === true) return 'value' in value\n\t\treturn value.ok === false && typeof value.error === 'string'\n\t})\n\treturn outcome.success && outcome.value\n}\n","import type { QueueExecution } from '@orkestrel/queue'\nimport type { Guard, NodeThread } from './types.js'\nimport type { Worker as ThreadWorker } from 'node:worker_threads'\nimport { Thread } from './Thread.js'\nimport { isReply } from './validators.js'\n\n/**\n * Internal lifecycle entity for one dispatched worker-thread job.\n *\n * @remarks\n * Owns the stable listener identities, settlement guard, cleanup, result narrowing, and abort\n * eviction for one dispatch. The public {@link dispatch} helper constructs this entity and returns\n * its promise.\n */\nexport class Dispatch<TResult> {\n\treadonly #thread: NodeThread\n\treadonly #worker: ThreadWorker\n\treadonly #input: unknown\n\treadonly #execution: QueueExecution\n\treadonly #result: Guard<TResult>\n\treadonly #id = crypto.randomUUID()\n\treadonly #promise: Promise<TResult>\n\treadonly #fulfill: (value: TResult | PromiseLike<TResult>) => void\n\treadonly #reject: (reason?: unknown) => void\n\treadonly #messageHandler: (value: unknown) => void\n\treadonly #errorHandler: (error: Error) => void\n\treadonly #exitHandler: () => void\n\treadonly #abortHandler: () => void\n\t#settled = false\n\n\tconstructor(\n\t\tthread: NodeThread,\n\t\tinput: unknown,\n\t\texecution: QueueExecution,\n\t\tresult: Guard<TResult>,\n\t) {\n\t\tthis.#thread = thread\n\t\tthis.#worker = thread.worker\n\t\tthis.#input = input\n\t\tthis.#execution = execution\n\t\tthis.#result = result\n\t\tconst settlement = Promise.withResolvers<TResult>()\n\t\tthis.#promise = settlement.promise\n\t\tthis.#fulfill = settlement.resolve\n\t\tthis.#reject = settlement.reject\n\t\tthis.#messageHandler = this.#message.bind(this)\n\t\tthis.#errorHandler = this.#error.bind(this)\n\t\tthis.#exitHandler = this.#exit.bind(this)\n\t\tthis.#abortHandler = this.#abort.bind(this)\n\t\tthis.#start()\n\t}\n\n\tget promise(): Promise<TResult> {\n\t\treturn this.#promise\n\t}\n\n\t#start(): void {\n\t\tif (this.#thread.death !== undefined || !this.#thread.alive) {\n\t\t\tthis.#fail(this.#thread.death ?? new Error('worker thread is dead'))\n\t\t\treturn\n\t\t}\n\t\tthis.#worker.on('message', this.#messageHandler)\n\t\tthis.#worker.on('error', this.#errorHandler)\n\t\tthis.#worker.on('exit', this.#exitHandler)\n\t\tif (this.#execution.signal.aborted) {\n\t\t\tthis.#abort()\n\t\t\treturn\n\t\t}\n\t\tthis.#execution.signal.addEventListener('abort', this.#abortHandler, { once: true })\n\t\ttry {\n\t\t\tthis.#worker.postMessage({ id: this.#id, command: 'run', input: this.#input })\n\t\t} catch (error: unknown) {\n\t\t\tthis.#fail(error instanceof Error ? error : new Error(String(error)))\n\t\t}\n\t}\n\n\t#message(value: unknown): void {\n\t\tif (!isReply(value, this.#id)) return\n\t\tif (value.ok) {\n\t\t\tconst reply = value.value\n\t\t\tif (this.#result(reply)) this.#succeed(reply)\n\t\t\telse this.#fail(new Error('reply did not satisfy result guard'))\n\t\t\treturn\n\t\t}\n\t\tthis.#fail(new Error(value.error))\n\t}\n\n\t#error(error: Error): void {\n\t\tthis.#fail(error)\n\t}\n\n\t#exit(): void {\n\t\tthis.#fail(new Error('worker thread exited'))\n\t}\n\n\t#abort(): void {\n\t\tthis.#worker.postMessage({ id: this.#id, command: 'abort' })\n\t\tif (this.#thread instanceof Thread) this.#thread.evict()\n\t\tvoid this.#worker.terminate()\n\t\tthis.#fail(new Error('job aborted'))\n\t}\n\n\t#succeed(value: TResult): void {\n\t\tif (this.#settled) return\n\t\tthis.#settled = true\n\t\tthis.#detach()\n\t\tthis.#fulfill(value)\n\t}\n\n\t#fail(error: unknown): void {\n\t\tif (this.#settled) return\n\t\tthis.#settled = true\n\t\tthis.#detach()\n\t\tthis.#reject(error)\n\t}\n\n\t#detach(): void {\n\t\tthis.#worker.off('message', this.#messageHandler)\n\t\tthis.#worker.off('error', this.#errorHandler)\n\t\tthis.#worker.off('exit', this.#exitHandler)\n\t\tthis.#execution.signal.removeEventListener('abort', this.#abortHandler)\n\t}\n}\n","import type { QueueExecution } from '@orkestrel/queue'\nimport type { Guard, NodeThread } from './types.js'\nimport { Dispatch } from './Dispatch.js'\nimport { Thread } from './Thread.js'\n\n// === The wire protocol (main ↔ thread)\n//\n// The main-side half of the run/abort/reply protocol `serveWorker` answers — spawning a\n// pooled thread, narrowing its replies, and dispatching one job at a time. The envelope\n// types ({@link Reply}, {@link NodeThread}) live in `./types.js` (AGENTS §5); the public\n// bridge across the structured-clone boundary is the `input` / `result` `Guard`s, which\n// narrow the envelopes' opaque `unknown` payloads with no assertion (AGENTS §14).\n\n/**\n * Spawn one worker thread and resolve a live {@link NodeThread} once it comes online.\n *\n * @remarks\n * Constructs the thread with the `script` module and the cloned `workerData`, then\n * resolves on the thread's `online` event (rejecting on an early `error` OR an `exit`\n * that arrives before `online`, so the spawn promise is total — it can never dangle on a\n * thread that died without erroring). The wrapper attaches persistent `error` / `exit`\n * listeners that flip `alive` to `false` AND latch the first terminal event on\n * {@link NodeThread.death}: a crash is observable to an in-flight {@link dispatch} (via\n * its own listeners), to the pool's `validate` (via `alive`), and — crucially — to a\n * dispatch that attaches AFTER the death (via the latch). The latch closes a real race:\n * under event-loop pressure a dead thread's `online` + `error` + `exit` are delivered in\n * ONE synchronous exit-drain batch, so every death event fires before the microtask chain\n * resolving this spawn can hand the thread to `dispatch` — without the latch that job\n * would await events that already fired, forever. The pool's `create` hook calls this.\n *\n * @param script - The worker module each thread runs (must call `serveWorker`)\n * @param workerData - Opaque, structured-cloneable data handed to the thread at spawn\n * @returns A promise resolving the online {@link NodeThread}\n */\nexport function spawnThread(script: string | URL, workerData: unknown): Promise<NodeThread> {\n\treturn new Thread(script, workerData).promise\n}\n\n/**\n * Dispatch one job to a leased {@link NodeThread} and await its narrowed reply.\n *\n * @remarks\n * Mints a fresh `id`, posts a `run` envelope, and resolves when the thread replies for\n * that id: a success `value` is narrowed through `result` (a value that fails the guard\n * rejects — the zero-`as` type bridge), a failure rejects with the thread's error string.\n * A thread that ALREADY died rejects synchronously at entry from the latched\n * {@link NodeThread.death} — its death events fired before this dispatch existed (under\n * load they arrive in one batched exit drain) and will never fire again, so waiting on\n * the listeners below would dangle forever; the latch makes the death total across every\n * event ordering. If the thread `error`s / `exit`s mid-flight it is marked dead and the\n * job rejects. On `execution.signal` abort it posts an `abort` envelope (cooperative) AND\n * evicts the thread — `alive = false` + `terminate()` — because CPU-bound work cannot\n * honour the signal; the freed pool slot then gets a fresh thread. Every listener (the\n * thread's `message` / `error` / `exit` and the signal's `abort`) is removed on settle,\n * and a `settled` guard prevents a double-settle.\n *\n * @typeParam TResult - The reply type the `result` guard narrows to\n * @param thread - The leased thread to run the job on\n * @param input - The work payload (structured-cloned to the thread)\n * @param execution - The per-attempt handle; its `signal` aborts → terminate + evict\n * @param result - The {@link Guard} narrowing the reply value with no assertion\n * @returns A promise resolving the narrowed `TResult`, or rejecting on error / abort\n */\nexport function dispatch<TResult>(\n\tthread: NodeThread,\n\tinput: unknown,\n\texecution: QueueExecution,\n\tresult: Guard<TResult>,\n): Promise<TResult> {\n\treturn new Dispatch(thread, input, execution, result).promise\n}\n","import type { ServeWorkerOptions } from './types.js'\nimport { parentPort } from 'node:worker_threads'\n\n// The worker-side entry. SELF-CONTAINED by necessity: this module loads as RAW `.ts`\n// inside a spawned thread (Node ≥ 23.6 type-stripping), so it imports ONLY\n// `node:worker_threads` at runtime — no `@src/*`, no `.js`-relative value imports (the\n// only non-node import is the type-only `ServeWorkerOptions`, fully erased at runtime).\n// Its guards are inlined for the same reason. A worker script that needs the cloned\n// `workerData` reads it directly from `node:worker_threads` (it is in a thread already).\n\n// Inlined record guard (do NOT import `isRecord` from `@src/core` — see above). Total:\n// adversarial input returns `false`, never throws (AGENTS §14).\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n// Narrow an inbound message to a `run` envelope (a string `id` + a `'run'` command + an\n// `input` payload) — no assertion.\nfunction isRun(value: unknown): value is { readonly id: string; readonly input: unknown } {\n\treturn (\n\t\tisRecord(value) && typeof value.id === 'string' && value.command === 'run' && 'input' in value\n\t)\n}\n\n// Narrow an inbound message to an `abort` envelope (a string `id` + an `'abort'` command).\nfunction isAbort(value: unknown): value is { readonly id: string } {\n\treturn isRecord(value) && typeof value.id === 'string' && value.command === 'abort'\n}\n\n/**\n * Register a worker-thread handler — the worker-side half of {@link createNodeWorker}.\n *\n * @remarks\n * Must be the spawned thread's module entry. It listens on the parent port for the\n * run/abort protocol: a `run` message narrows its `input` through `options.input` (an\n * invalid payload replies with an error envelope, never running the handler), then runs\n * `options.handler(input, { signal })` and replies `{ id, ok: true, value }` on success or\n * `{ id, ok: false, error }` on throw. Each in-flight job has its own `AbortController`,\n * so an `abort` message for that id fires the handler's `signal` (cooperative — the main\n * side ALSO terminates the thread, so a handler that ignores its signal is still stopped).\n * Every inbound message is narrowed with the inlined guards — no `as`. On the main thread\n * (`parentPort === null`) it is a no-op.\n *\n * @typeParam TInput - The work payload (inferred from `options.input`)\n * @typeParam TResult - The value the handler resolves (the reply payload)\n * @param options - The `input` guard and the `handler` (see {@link ServeWorkerOptions})\n *\n * @example\n * ```ts\n * // double.ts — a worker script\n * import { serveWorker } from '@src/server'\n *\n * serveWorker<number, number>({\n * \tinput: (value): value is number => typeof value === 'number',\n * \thandler: (value) => value * 2,\n * })\n * ```\n */\nexport function serveWorker<TInput, TResult>(options: ServeWorkerOptions<TInput, TResult>): void {\n\tconst port = parentPort\n\tif (port === null) return\n\tconst controllers = new Map<string, AbortController>()\n\tport.on('message', (raw: unknown) => {\n\t\tif (isAbort(raw)) {\n\t\t\tcontrollers.get(raw.id)?.abort()\n\t\t\treturn\n\t\t}\n\t\tif (!isRun(raw)) return\n\t\tconst id = raw.id\n\t\tif (!options.input(raw.input)) {\n\t\t\tport.postMessage({ id, ok: false, error: 'input did not satisfy input guard' })\n\t\t\treturn\n\t\t}\n\t\tconst input = raw.input\n\t\tconst controller = new AbortController()\n\t\tcontrollers.set(id, controller)\n\t\t// Defer the handler call into the `then` so a SYNCHRONOUS throw becomes a rejection\n\t\t// (not an uncaught thread exception) and is reported as an error reply.\n\t\tPromise.resolve()\n\t\t\t.then(() => options.handler(input, { signal: controller.signal }))\n\t\t\t.then(\n\t\t\t\t(value) => {\n\t\t\t\t\tcontrollers.delete(id)\n\t\t\t\t\tport.postMessage({ id, ok: true, value })\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tcontrollers.delete(id)\n\t\t\t\t\tport.postMessage({\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tok: false,\n\t\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t)\n\t})\n}\n","import type { WorkerInterface } from '@src/core'\nimport type { QueueExecution } from '@orkestrel/queue'\nimport type { NodeThread, NodeWorkerOptions } from './types.js'\nimport { createWorker } from '@src/core'\nimport { dispatch, spawnThread } from './helpers.js'\n\n/**\n * Internal composition entity backing {@link createNodeWorker}.\n *\n * @remarks\n * Supplies bound Pool and Queue operations without nested function assignments. The resulting\n * public entity remains the plain core {@link WorkerInterface}.\n */\nexport class NodeWorker<TInput, TResult> {\n\treadonly #options: NodeWorkerOptions<TInput, TResult>\n\n\tconstructor(options: NodeWorkerOptions<TInput, TResult>) {\n\t\tthis.#options = options\n\t}\n\n\tbuild(): WorkerInterface<TInput, TResult> {\n\t\treturn createWorker<TInput, NodeThread, TResult>({\n\t\t\tpool: {\n\t\t\t\tcreate: this.#create.bind(this),\n\t\t\t\tdestroy: this.#destroy.bind(this),\n\t\t\t\tvalidate: this.#validate.bind(this),\n\t\t\t\t...(this.#options.concurrency !== undefined ? { max: this.#options.concurrency } : {}),\n\t\t\t},\n\t\t\thandler: this.#handle.bind(this),\n\t\t\t...(this.#options.concurrency !== undefined\n\t\t\t\t? { concurrency: this.#options.concurrency }\n\t\t\t\t: {}),\n\t\t\t...(this.#options.retries !== undefined ? { retries: this.#options.retries } : {}),\n\t\t\t...(this.#options.timeout !== undefined ? { timeout: this.#options.timeout } : {}),\n\t\t\t...(this.#options.store !== undefined ? { store: this.#options.store } : {}),\n\t\t})\n\t}\n\n\t#create(): Promise<NodeThread> {\n\t\treturn spawnThread(this.#options.script, this.#options.workerData)\n\t}\n\n\tasync #destroy(thread: NodeThread): Promise<void> {\n\t\tawait thread.worker.terminate()\n\t}\n\n\t#validate(thread: NodeThread): boolean {\n\t\treturn thread.alive && thread.worker.threadId > 0\n\t}\n\n\t#handle(input: TInput, thread: NodeThread, execution: QueueExecution): Promise<TResult> {\n\t\tif (!this.#options.input(input)) {\n\t\t\treturn Promise.reject(new Error('input did not satisfy input guard'))\n\t\t}\n\t\treturn dispatch(thread, input, execution, this.#options.result)\n\t}\n}\n","import type { WorkerInterface } from '@src/core'\nimport type { ContractShape, Infer } from '@orkestrel/contract'\nimport type { QueueStoreInterface } from '@orkestrel/queue'\nimport type { NodeWorkerOptions } from './types.js'\nimport { createJSONDriver } from '@orkestrel/database/server'\nimport { createDatabaseQueueStore } from '@orkestrel/queue'\nimport { NodeWorker } from './NodeWorker.js'\n\n/**\n * Create a persistent JSON-file {@link QueueStoreInterface} — the core\n * `createDatabaseQueueStore` over a server {@link createJSONDriver}.\n *\n * @remarks\n * A queue's durable state is just a database table, so JSON persistence reuses the\n * existing JSON-file driver rather than a bespoke store: the entries are written to\n * (and reloaded from) the file at `path`, surviving a process restart. There is no new\n * class — the store engine ({@link createDatabaseQueueStore}) is shared, and only the\n * driver changes where the bytes live. The `input` shape must be JSON-serializable\n * (the JSON driver round-trips it as JSON). Build a second store over the SAME `path` to\n * resume the outstanding entries a prior store persisted.\n *\n * @typeParam TInput - The contract shape of each entry's `input` payload\n * @param path - The JSON file the entries are loaded from and flushed to\n * @param input - The {@link ContractShape} for the work payload (the `input` column)\n * @returns A JSON-file-backed {@link QueueStoreInterface}, typed by `input`\n *\n * @example\n * ```ts\n * import { stringShape } from '@src/core'\n * import { createJSONQueueStore } from '@src/server'\n *\n * const store = createJSONQueueStore('data/queue.json', stringShape())\n * await store.save({ id: 'job-1', input: 'https://example.com', attempts: 0 })\n * // A later process resumes the outstanding work:\n * const resumed = createJSONQueueStore('data/queue.json', stringShape())\n * const outstanding = await resumed.load()\n * ```\n */\nexport function createJSONQueueStore<TInput extends ContractShape>(\n\tpath: string,\n\tinput: TInput,\n): QueueStoreInterface<Infer<TInput>> {\n\treturn createDatabaseQueueStore(input, createJSONDriver(path))\n}\n\n/**\n * Create a CPU-parallel worker over `node:worker_threads` — a thin specialization of the\n * core `createWorker` whose pooled resource is a worker THREAD.\n *\n * @remarks\n * Composition, not reimplementation: all concurrency, retries, per-attempt timeout,\n * lifecycle, and durability are the core `Worker`'s (a `Queue` ⨉ `Pool`). This factory\n * supplies only the thread pairing — the pool `create`s a thread (via `spawnThread`),\n * `destroy`s it with `terminate()`, and `validate`s it by `alive && threadId > 0` (so an\n * evicted / crashed thread is dropped and replaced) — and an internal handler that\n * narrows the input through `options.input` (fail-fast before the structured-clone\n * boundary) then `dispatch`es the job to the leased thread, narrowing the reply through\n * `options.result`. Both generics INFER from the `input` / `result` guards, so call sites\n * need no explicit type arguments. The boundary is crossed with ZERO `as`: the guards\n * reconstruct `TInput` / `TResult` by validation (AGENTS §14). An `abort` / `timeout`\n * TERMINATES the in-flight thread (CPU-bound work can't honour a signal) and evicts it; a\n * subsequent job spawns a fresh thread. The worker script's module must call\n * `serveWorker`. Returns the plain {@link WorkerInterface} — its methods are the Worker's.\n *\n * @typeParam TInput - The work payload each job carries (inferred from `input`)\n * @typeParam TResult - The value a thread resolves for a job (inferred from `result`)\n * @param options - The `script` plus the `input` / `result` guards and optional\n * `workerData` / `concurrency` / `retries` / `timeout` / `store`\n * (see {@link NodeWorkerOptions})\n * @returns A working {@link WorkerInterface} backed by a thread pool\n *\n * @example\n * ```ts\n * import { createNodeWorker } from '@src/server'\n *\n * const worker = createNodeWorker({\n * \tscript: new URL('./double.js', import.meta.url),\n * \tinput: (value): value is number => typeof value === 'number',\n * \tresult: (value): value is number => typeof value === 'number',\n * \tconcurrency: 4,\n * })\n *\n * const doubled = await worker.enqueue(21) // 42, computed on a worker thread\n * worker.destroy() // terminates every thread\n * ```\n */\nexport function createNodeWorker<TInput, TResult>(\n\toptions: NodeWorkerOptions<TInput, TResult>,\n): WorkerInterface<TInput, TResult> {\n\treturn new NodeWorker(options).build()\n}\n"],"mappings":";;;;;;;;;;;;;;AAWA,IAAa,SAAb,MAA0C;CACzC;CACA;CACA;CACA;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
4
|
"description": "A typed, resource-backed job worker for the @orkestrel line — a Queue paired with a Pool over an execution seam, plus a node:worker_threads server surface for CPU-parallel jobs. Part of the @orkestrel line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"async",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"url": "git+https://github.com/orkestrel/worker.git"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"dist",
|
|
22
|
+
"dist/src",
|
|
23
23
|
"README.md"
|
|
24
24
|
],
|
|
25
25
|
"type": "module",
|
|
@@ -53,21 +53,22 @@
|
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
|
-
"clean": "node -e \"
|
|
56
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
57
57
|
"copy": "node -e \"const fs=require('node:fs'),p=require('node:path'),a=process.argv[1],b=process.argv[2];fs.mkdirSync(p.dirname(b),{recursive:true});fs.cpSync(a,b,{force:true});console.log('Copied: '+a+' to '+b)\"",
|
|
58
|
-
"
|
|
59
|
-
"lint": "oxlint --config .oxlintrc.json --fix .",
|
|
58
|
+
"scaffold": "scaffold",
|
|
59
|
+
"lint": "oxlint --config .oxlintrc.json --fix --deny-warnings .",
|
|
60
60
|
"check": "tsc --noEmit --project tsconfig.json && npm run check:src",
|
|
61
61
|
"check:src": "npm run check:src:core && npm run check:src:server",
|
|
62
62
|
"check:src:core": "tsc --noEmit -p configs/src/tsconfig.core.json",
|
|
63
63
|
"check:src:server": "tsc --noEmit -p configs/src/tsconfig.server.json",
|
|
64
64
|
"format": "oxfmt --config .oxfmtrc.json --write .",
|
|
65
65
|
"format:check": "oxfmt --config .oxfmtrc.json --check .",
|
|
66
|
-
"lint:check": "oxlint --config .oxlintrc.json .",
|
|
67
|
-
"test": "npm run test:src && npm run test:guides",
|
|
66
|
+
"lint:check": "oxlint --config .oxlintrc.json --deny-warnings .",
|
|
67
|
+
"test": "npm run test:src && npm run test:policy && npm run test:guides",
|
|
68
68
|
"test:src": "vitest run --config vite.config.ts --no-cache --reporter=dot --project src:core --project src:server",
|
|
69
69
|
"test:src:core": "vitest run --config vite.config.ts --no-cache --reporter=dot --project src:core",
|
|
70
70
|
"test:src:server": "vitest run --config vite.config.ts --no-cache --reporter=dot --project src:server",
|
|
71
|
+
"test:policy": "vitest run --config vite.config.ts --no-cache --reporter=dot --project policy",
|
|
71
72
|
"test:guides": "vitest run --config vite.config.ts --reporter=dot --project guides",
|
|
72
73
|
"build": "npm run clean && npm run build:src",
|
|
73
74
|
"build:src": "npm run build:src:core && npm run build:src:server",
|
|
@@ -76,24 +77,26 @@
|
|
|
76
77
|
"prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run build && npm test"
|
|
77
78
|
},
|
|
78
79
|
"dependencies": {
|
|
79
|
-
"@orkestrel/contract": "^0.0.
|
|
80
|
-
"@orkestrel/database": "^0.0.
|
|
81
|
-
"@orkestrel/emitter": "^0.0.
|
|
82
|
-
"@orkestrel/pool": "^0.0.
|
|
83
|
-
"@orkestrel/queue": "^0.0.
|
|
80
|
+
"@orkestrel/contract": "^0.0.8",
|
|
81
|
+
"@orkestrel/database": "^0.0.6",
|
|
82
|
+
"@orkestrel/emitter": "^0.0.4",
|
|
83
|
+
"@orkestrel/pool": "^0.0.4",
|
|
84
|
+
"@orkestrel/queue": "^0.0.4"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
|
-
"@microsoft/api-extractor": "^7.58.
|
|
87
|
-
"@orkestrel/guide": "^0.0.
|
|
88
|
-
"@
|
|
89
|
-
"
|
|
90
|
-
"
|
|
87
|
+
"@microsoft/api-extractor": "^7.58.12",
|
|
88
|
+
"@orkestrel/guide": "^0.0.7",
|
|
89
|
+
"@orkestrel/scaffold": "^0.0.7",
|
|
90
|
+
"@types/node": "^26.1.2",
|
|
91
|
+
"@vitest/browser-playwright": "^4.1.10",
|
|
92
|
+
"oxfmt": "^0.61.0",
|
|
93
|
+
"oxlint": "^1.76.0",
|
|
91
94
|
"typescript": "^6.0.3",
|
|
92
95
|
"vite": "^8.1.5",
|
|
93
96
|
"vite-plugin-dts": "^5.0.3",
|
|
94
97
|
"vitest": "^4.1.10"
|
|
95
98
|
},
|
|
96
99
|
"engines": {
|
|
97
|
-
"node": ">=22"
|
|
100
|
+
"node": ">=22.12.0"
|
|
98
101
|
}
|
|
99
102
|
}
|