@mark1russell7/service 0.8.19 → 0.8.20
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/build/backoff.d.ts +44 -2
- package/build/{builder-zO48Vgoj.d.ts → builder.d.ts} +14 -101
- package/build/builder.js +499 -0
- package/build/builder.js.map +1 -0
- package/build/{call-context-DDhcVvn5.d.ts → call-context.d.ts} +3 -4
- package/build/channel.d.ts +1 -1
- package/build/{core-BSzt4RI2.d.ts → client/core.d.ts} +32 -61
- package/build/{machine-BhVeHr_m.js → client/core.js} +4 -153
- package/build/client/core.js.map +1 -0
- package/build/{dial-ChwIcvd4.d.ts → client/dial.d.ts} +3 -4
- package/build/client/dial.js +52 -0
- package/build/client/dial.js.map +1 -0
- package/build/client/machine.js +29 -0
- package/build/client/machine.js.map +1 -0
- package/build/client/meets.d.ts +35 -0
- package/build/client/meets.js +78 -0
- package/build/client/meets.js.map +1 -0
- package/build/clock.d.ts +1 -1
- package/build/conformance.d.ts +122 -0
- package/build/conformance.js +470 -0
- package/build/conformance.js.map +1 -0
- package/build/contract.d.ts +28 -0
- package/build/contract.js +184 -0
- package/build/contract.js.map +1 -0
- package/build/description.d.ts +161 -0
- package/build/description.js +11 -0
- package/build/description.js.map +1 -0
- package/build/drains.js +35 -0
- package/build/drains.js.map +1 -0
- package/build/events.d.ts +25 -0
- package/build/fakes.d.ts +43 -0
- package/build/fakes.js +93 -0
- package/build/fakes.js.map +1 -0
- package/build/grpc/client.d.ts +153 -0
- package/build/grpc/client.js +474 -0
- package/build/grpc/client.js.map +1 -0
- package/build/grpc/connection.d.ts +97 -0
- package/build/grpc/connection.js +59 -0
- package/build/grpc/connection.js.map +1 -0
- package/build/grpc/machine.d.ts +12 -0
- package/build/grpc/machine.js +149 -0
- package/build/grpc/machine.js.map +1 -0
- package/build/grpc/meets.d.ts +14 -0
- package/build/grpc/meets.js +105 -0
- package/build/grpc/meets.js.map +1 -0
- package/build/grpc/starting.d.ts +33 -0
- package/build/grpc/starting.js +89 -0
- package/build/grpc/starting.js.map +1 -0
- package/build/grpc.d.ts +9 -303
- package/build/grpc.js +7 -854
- package/build/health.d.ts +93 -0
- package/build/health.js +223 -0
- package/build/health.js.map +1 -0
- package/build/heartbeat.d.ts +1 -1
- package/build/host/discovery.d.ts +61 -0
- package/build/host/discovery.js +113 -0
- package/build/host/discovery.js.map +1 -0
- package/build/host/env.d.ts +14 -0
- package/build/host/env.js +57 -0
- package/build/host/env.js.map +1 -0
- package/build/host/fakes.d.ts +82 -0
- package/build/host/fakes.js +239 -0
- package/build/host/fakes.js.map +1 -0
- package/build/host/group.d.ts +142 -0
- package/build/host/group.js +517 -0
- package/build/host/group.js.map +1 -0
- package/build/host/install.d.ts +96 -0
- package/build/host/install.js +330 -0
- package/build/host/install.js.map +1 -0
- package/build/host/lock.d.ts +78 -0
- package/build/host/lock.js +190 -0
- package/build/host/lock.js.map +1 -0
- package/build/host/logs.d.ts +26 -0
- package/build/host/logs.js +48 -0
- package/build/host/logs.js.map +1 -0
- package/build/host/node.d.ts +14 -0
- package/build/host/node.js +309 -0
- package/build/host/node.js.map +1 -0
- package/build/{ports-B1ayTL-j.d.ts → host/ports.d.ts} +15 -16
- package/build/host/ports.js +17 -0
- package/build/host/ports.js.map +1 -0
- package/build/host/probes.d.ts +51 -0
- package/build/host/probes.js +139 -0
- package/build/host/probes.js.map +1 -0
- package/build/host/processes.d.ts +32 -0
- package/build/host/processes.js +63 -0
- package/build/host/processes.js.map +1 -0
- package/build/host/render.d.ts +84 -0
- package/build/host/render.js +235 -0
- package/build/host/render.js.map +1 -0
- package/build/host/watch.d.ts +90 -0
- package/build/host/watch.js +165 -0
- package/build/host/watch.js.map +1 -0
- package/build/host.d.ts +13 -671
- package/build/host.js +12 -2126
- package/build/http/answers.js +29 -0
- package/build/http/answers.js.map +1 -0
- package/build/http/fake-server.js +61 -0
- package/build/http/fake-server.js.map +1 -0
- package/build/http/outcome.d.ts +115 -0
- package/build/http/outcome.js +325 -0
- package/build/http/outcome.js.map +1 -0
- package/build/http/probes.d.ts +83 -0
- package/build/http/probes.js +232 -0
- package/build/http/probes.js.map +1 -0
- package/build/http/transport.d.ts +165 -0
- package/build/http/transport.js +517 -0
- package/build/http/transport.js.map +1 -0
- package/build/http-client/client.d.ts +121 -0
- package/build/http-client/client.js +330 -0
- package/build/http-client/client.js.map +1 -0
- package/build/http-client/connection.d.ts +78 -0
- package/build/http-client/connection.js +54 -0
- package/build/http-client/connection.js.map +1 -0
- package/build/http-client/machine.d.ts +14 -0
- package/build/http-client/machine.js +109 -0
- package/build/http-client/machine.js.map +1 -0
- package/build/http-client/meets.d.ts +11 -0
- package/build/http-client/meets.js +74 -0
- package/build/http-client/meets.js.map +1 -0
- package/build/http-client/session.d.ts +87 -0
- package/build/http-client/session.js +99 -0
- package/build/http-client/session.js.map +1 -0
- package/build/http-client/starting.d.ts +25 -0
- package/build/http-client/starting.js +65 -0
- package/build/http-client/starting.js.map +1 -0
- package/build/http-client.d.ts +9 -330
- package/build/http-client.js +8 -707
- package/build/http.d.ts +5 -353
- package/build/http.js +3 -1086
- package/build/identity.d.ts +16 -0
- package/build/identity.js +44 -0
- package/build/identity.js.map +1 -0
- package/build/index.d.ts +35 -412
- package/build/index.js +24 -3277
- package/build/knobs.d.ts +1 -0
- package/build/{knobs-BJcz6m01.js → knobs.js} +2 -34
- package/build/knobs.js.map +1 -0
- package/build/latch.d.ts +29 -0
- package/build/latch.js +122 -0
- package/build/latch.js.map +1 -0
- package/build/{rules-HyFCBStQ.d.ts → law.d.ts} +19 -37
- package/build/law.js +149 -0
- package/build/law.js.map +1 -0
- package/build/lifecycle.d.ts +144 -0
- package/build/lifecycle.js +411 -0
- package/build/lifecycle.js.map +1 -0
- package/build/limiter/machine.d.ts +40 -0
- package/build/limiter/machine.js +279 -0
- package/build/limiter/machine.js.map +1 -0
- package/build/{policy-CBcK2XGg.d.ts → limiter/policy.d.ts} +28 -29
- package/build/{policy-UYALkqVq.js → limiter/policy.js} +10 -9
- package/build/limiter/policy.js.map +1 -0
- package/build/{limiter-BNKnwzeY.d.ts → limiter/quota.d.ts} +32 -74
- package/build/{limiter-DrM0PQV9.js → limiter/quota.js} +3 -418
- package/build/limiter/quota.js.map +1 -0
- package/build/{store-DFwFKrsB.d.ts → limiter/store.d.ts} +10 -11
- package/build/limiter/store.js +145 -0
- package/build/limiter/store.js.map +1 -0
- package/build/limiter.d.ts +4 -3
- package/build/limiter.js +4 -2
- package/build/lint.d.ts +152 -0
- package/build/lint.js +576 -0
- package/build/lint.js.map +1 -0
- package/build/logger.d.ts +71 -0
- package/build/logger.js +183 -0
- package/build/logger.js.map +1 -0
- package/build/machines.d.ts +41 -0
- package/build/machines.js +451 -0
- package/build/machines.js.map +1 -0
- package/build/metrics.d.ts +53 -0
- package/build/metrics.js +111 -0
- package/build/metrics.js.map +1 -0
- package/build/mongodb/client.d.ts +131 -0
- package/build/mongodb/client.js +388 -0
- package/build/mongodb/client.js.map +1 -0
- package/build/mongodb/connection.d.ts +112 -0
- package/build/mongodb/connection.js +12 -0
- package/build/mongodb/connection.js.map +1 -0
- package/build/mongodb/machine.d.ts +14 -0
- package/build/mongodb/machine.js +122 -0
- package/build/mongodb/machine.js.map +1 -0
- package/build/mongodb/meets.d.ts +15 -0
- package/build/mongodb/meets.js +103 -0
- package/build/mongodb/meets.js.map +1 -0
- package/build/mongodb/starting.d.ts +29 -0
- package/build/mongodb/starting.js +77 -0
- package/build/mongodb/starting.js.map +1 -0
- package/build/mongodb.d.ts +8 -296
- package/build/mongodb.js +7 -682
- package/build/operation.d.ts +27 -0
- package/build/{operation-DF73RZOI.js → operation.js} +2 -2
- package/build/operation.js.map +1 -0
- package/build/otel.d.ts +2 -2
- package/build/pg/client.d.ts +96 -0
- package/build/pg/client.js +277 -0
- package/build/pg/client.js.map +1 -0
- package/build/pg/connection.d.ts +75 -0
- package/build/pg/connection.js +11 -0
- package/build/pg/connection.js.map +1 -0
- package/build/pg/machine.d.ts +13 -0
- package/build/pg/machine.js +111 -0
- package/build/pg/machine.js.map +1 -0
- package/build/pg/meets.d.ts +14 -0
- package/build/pg/meets.js +83 -0
- package/build/pg/meets.js.map +1 -0
- package/build/pg/starting.d.ts +26 -0
- package/build/pg/starting.js +62 -0
- package/build/pg/starting.js.map +1 -0
- package/build/pg.d.ts +8 -219
- package/build/pg.js +7 -525
- package/build/poller.d.ts +9 -0
- package/build/poller.js +152 -0
- package/build/poller.js.map +1 -0
- package/build/process.d.ts +114 -0
- package/build/process.js +170 -0
- package/build/process.js.map +1 -0
- package/build/profiles.d.ts +68 -0
- package/build/profiles.js +120 -0
- package/build/profiles.js.map +1 -0
- package/build/{queue-DXdw1vLO.d.ts → queue.d.ts} +16 -29
- package/build/queue.js +279 -0
- package/build/queue.js.map +1 -0
- package/build/rabbitmq/client.d.ts +144 -0
- package/build/rabbitmq/client.js +426 -0
- package/build/rabbitmq/client.js.map +1 -0
- package/build/rabbitmq/connection.d.ts +91 -0
- package/build/rabbitmq/connection.js +15 -0
- package/build/rabbitmq/connection.js.map +1 -0
- package/build/rabbitmq/machine.d.ts +13 -0
- package/build/rabbitmq/machine.js +159 -0
- package/build/rabbitmq/machine.js.map +1 -0
- package/build/rabbitmq/meets.d.ts +12 -0
- package/build/rabbitmq/meets.js +96 -0
- package/build/rabbitmq/meets.js.map +1 -0
- package/build/rabbitmq/starting.d.ts +27 -0
- package/build/rabbitmq/starting.js +67 -0
- package/build/rabbitmq/starting.js.map +1 -0
- package/build/rabbitmq.d.ts +8 -283
- package/build/rabbitmq.js +7 -742
- package/build/redis/client.d.ts +86 -0
- package/build/redis/client.js +285 -0
- package/build/redis/client.js.map +1 -0
- package/build/redis/connection.d.ts +57 -0
- package/build/redis/connection.js +11 -0
- package/build/redis/connection.js.map +1 -0
- package/build/redis/limiter.d.ts +43 -0
- package/build/redis/limiter.js +164 -0
- package/build/redis/limiter.js.map +1 -0
- package/build/redis/machine.d.ts +12 -0
- package/build/redis/machine.js +144 -0
- package/build/redis/machine.js.map +1 -0
- package/build/redis/meets.d.ts +11 -0
- package/build/redis/meets.js +75 -0
- package/build/redis/meets.js.map +1 -0
- package/build/redis/operations.d.ts +5 -0
- package/build/redis/operations.js +114 -0
- package/build/redis/operations.js.map +1 -0
- package/build/redis.d.ts +10 -207
- package/build/redis.js +9 -771
- package/build/requests.d.ts +66 -0
- package/build/requests.js +279 -0
- package/build/requests.js.map +1 -0
- package/build/retrier.d.ts +62 -0
- package/build/{retrier-Dnjhvxol.js → retrier.js} +2 -2
- package/build/retrier.js.map +1 -0
- package/build/routes.d.ts +35 -0
- package/build/routes.js +77 -0
- package/build/routes.js.map +1 -0
- package/build/rules.d.ts +19 -2
- package/build/stops.d.ts +51 -0
- package/build/stops.js +86 -0
- package/build/stops.js.map +1 -0
- package/build/testing.d.ts +8 -270
- package/build/testing.js +4 -1027
- package/build/testing.js.map +1 -1
- package/build/timing.d.ts +63 -0
- package/build/{timing-DZl36uXs.js → timing.js} +2 -2
- package/build/timing.js.map +1 -0
- package/build/units.d.ts +17 -0
- package/build/units.js +236 -0
- package/build/units.js.map +1 -0
- package/build/watchdog.d.ts +34 -0
- package/build/watchdog.js +53 -0
- package/build/watchdog.js.map +1 -0
- package/build/websocket/client.d.ts +136 -0
- package/build/websocket/client.js +422 -0
- package/build/websocket/client.js.map +1 -0
- package/build/websocket/connection.d.ts +83 -0
- package/build/websocket/connection.js +57 -0
- package/build/websocket/connection.js.map +1 -0
- package/build/websocket/machine.d.ts +12 -0
- package/build/websocket/machine.js +155 -0
- package/build/websocket/machine.js.map +1 -0
- package/build/websocket/meets.d.ts +14 -0
- package/build/websocket/meets.js +92 -0
- package/build/websocket/meets.js.map +1 -0
- package/build/websocket/starting.d.ts +25 -0
- package/build/websocket/starting.js +69 -0
- package/build/websocket/starting.js.map +1 -0
- package/build/websocket.d.ts +9 -264
- package/build/websocket.js +8 -774
- package/build/worker.d.ts +92 -0
- package/build/worker.js +153 -0
- package/build/worker.js.map +1 -0
- package/package.json +4 -3
- package/build/backoff-QTRGfkEK.d.ts +0 -45
- package/build/clock-DpVgpY4h.d.ts +0 -2
- package/build/grpc.js.map +0 -1
- package/build/host.js.map +0 -1
- package/build/http-client.js.map +0 -1
- package/build/http.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/knobs-BJcz6m01.js.map +0 -1
- package/build/lifecycle-D0J-zwZF.d.ts +0 -374
- package/build/limiter-DrM0PQV9.js.map +0 -1
- package/build/logger-B6drv9w0.d.ts +0 -488
- package/build/machine-BhVeHr_m.js.map +0 -1
- package/build/mongodb.js.map +0 -1
- package/build/operation-DF73RZOI.js.map +0 -1
- package/build/pg.js.map +0 -1
- package/build/policy-UYALkqVq.js.map +0 -1
- package/build/process-7R9M29wN.js +0 -437
- package/build/process-7R9M29wN.js.map +0 -1
- package/build/rabbitmq.js.map +0 -1
- package/build/redis.js.map +0 -1
- package/build/requests-DD2ALv0_.js +0 -583
- package/build/requests-DD2ALv0_.js.map +0 -1
- package/build/retrier-Dnjhvxol.js.map +0 -1
- package/build/timing-DZl36uXs.js.map +0 -1
- package/build/websocket.js.map +0 -1
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import { valueIn } from "@mark1russell7/quantity";
|
|
2
|
-
// src/latch.ts
|
|
3
|
-
const ms = (amount) => valueIn(amount, "ms");
|
|
4
|
-
/**
|
|
5
|
-
* This function makes a latch. `tripped` is its state at the start: a readiness latch starts
|
|
6
|
-
* tripped, and a liveness latch starts released. The latch starts `changed` each time it trips or
|
|
7
|
-
* releases, and it gives each transition to `trace`. A debounce has the states `released` and
|
|
8
|
-
* `tripped`. A window also has the states `failing` and `recovering`, while one of its timers runs.
|
|
9
|
-
*/
|
|
10
|
-
const latch = (timing, clock, tripped, changed, trace) => {
|
|
11
|
-
let state = tripped;
|
|
12
|
-
let since = clock.now();
|
|
13
|
-
let streak = 0;
|
|
14
|
-
let fails = 0;
|
|
15
|
-
let passes = 0;
|
|
16
|
-
let failingSince = null;
|
|
17
|
-
let passingSince = null;
|
|
18
|
-
let failTimer = null;
|
|
19
|
-
let passTimer = null;
|
|
20
|
-
/** This function gives the name of the state, as the machine documents name it. */
|
|
21
|
-
const named = () => state ? passingSince === null ? "tripped" : "recovering" : failingSince === null ? "released" : "failing";
|
|
22
|
-
/** This function does one step of the machine, and gives its transition to the trace. */
|
|
23
|
-
const step = (on, change) => {
|
|
24
|
-
const from = named();
|
|
25
|
-
change();
|
|
26
|
-
trace?.(from, named(), on);
|
|
27
|
-
};
|
|
28
|
-
const set = (next) => {
|
|
29
|
-
if (next === state) return;
|
|
30
|
-
state = next;
|
|
31
|
-
since = clock.now();
|
|
32
|
-
changed();
|
|
33
|
-
};
|
|
34
|
-
const stopFail = () => {
|
|
35
|
-
failTimer?.();
|
|
36
|
-
failTimer = null;
|
|
37
|
-
failingSince = null;
|
|
38
|
-
};
|
|
39
|
-
const stopPass = () => {
|
|
40
|
-
passTimer?.();
|
|
41
|
-
passTimer = null;
|
|
42
|
-
passingSince = null;
|
|
43
|
-
};
|
|
44
|
-
const debounce = (result) => {
|
|
45
|
-
if (timing.type !== "debounce") return;
|
|
46
|
-
if (result.outcome === "ok") {
|
|
47
|
-
passes += 1;
|
|
48
|
-
fails = 0;
|
|
49
|
-
if (state && passes >= timing.recoverAfter) set(false);
|
|
50
|
-
} else {
|
|
51
|
-
fails += 1;
|
|
52
|
-
passes = 0;
|
|
53
|
-
if (!state && fails >= timing.failAfter) set(true);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const windowed = (result) => {
|
|
57
|
-
if (timing.type !== "window") return;
|
|
58
|
-
if (result.outcome === "ok") {
|
|
59
|
-
stopFail();
|
|
60
|
-
if (!state) return;
|
|
61
|
-
if (timing.recoverAfter === void 0) {
|
|
62
|
-
set(false);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (passingSince !== null) return;
|
|
66
|
-
const wait = ms(timing.recoverAfter);
|
|
67
|
-
if (wait <= 0) {
|
|
68
|
-
stopPass();
|
|
69
|
-
set(false);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
passingSince = result.at;
|
|
73
|
-
passTimer = clock.after(wait, () => step("window.recovered", () => {
|
|
74
|
-
passTimer = null;
|
|
75
|
-
passingSince = null;
|
|
76
|
-
set(false);
|
|
77
|
-
}));
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
stopPass();
|
|
81
|
-
if (state || failingSince !== null) return;
|
|
82
|
-
const wait = ms(timing.failAfter);
|
|
83
|
-
if (wait <= 0) {
|
|
84
|
-
stopFail();
|
|
85
|
-
set(true);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
failingSince = result.at;
|
|
89
|
-
failTimer = clock.after(wait, () => step("window.failed", () => {
|
|
90
|
-
failTimer = null;
|
|
91
|
-
failingSince = null;
|
|
92
|
-
set(true);
|
|
93
|
-
}));
|
|
94
|
-
};
|
|
95
|
-
return {
|
|
96
|
-
get tripped() {
|
|
97
|
-
return state;
|
|
98
|
-
},
|
|
99
|
-
get since() {
|
|
100
|
-
return since;
|
|
101
|
-
},
|
|
102
|
-
get streak() {
|
|
103
|
-
return streak;
|
|
104
|
-
},
|
|
105
|
-
record(result) {
|
|
106
|
-
if (result.outcome === "indeterminate") return;
|
|
107
|
-
const pass = result.outcome === "ok";
|
|
108
|
-
step(pass ? "poll.ok" : "poll.fail", () => {
|
|
109
|
-
streak = pass ? Math.max(0, streak) + 1 : Math.min(0, streak) - 1;
|
|
110
|
-
debounce(result);
|
|
111
|
-
windowed(result);
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
stop() {
|
|
115
|
-
stopFail();
|
|
116
|
-
stopPass();
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
// src/poller.ts
|
|
121
|
-
const message = (error) => error instanceof Error ? error.message : String(error);
|
|
122
|
-
/**
|
|
123
|
-
* This function makes a poller. The loop is on a fixed delay from the start of each poll. Thus the
|
|
124
|
-
* next poll starts one interval after the current poll starts, with the jitter (±20 % is 0.2).
|
|
125
|
-
* The timing algebra of the declaration uses this model.
|
|
126
|
-
*
|
|
127
|
-
* Each poll makes a new measurement. While a use of the check is pending, the poller does not
|
|
128
|
-
* start the check again. Such a poll fails at once with the same cause, and the sequence of
|
|
129
|
-
* failures continues.
|
|
130
|
-
*/
|
|
131
|
-
const poller = (options) => {
|
|
132
|
-
const { clock, poll, run } = options;
|
|
133
|
-
const interval = valueIn(poll.interval, "ms");
|
|
134
|
-
const timeout = valueIn(poll.timeout, "ms");
|
|
135
|
-
let last = null;
|
|
136
|
-
let next = null;
|
|
137
|
-
let stopped = false;
|
|
138
|
-
let looping = false;
|
|
139
|
-
let pending = null;
|
|
140
|
-
const active = /* @__PURE__ */ new Set();
|
|
141
|
-
/** This function gives the name of the state, as the machine document of the poller names it. */
|
|
142
|
-
const named = () => stopped ? "stopped" : pending !== null ? pending.late ? "hung" : "calling" : looping ? "waiting" : "idle";
|
|
143
|
-
const step = (on, change) => {
|
|
144
|
-
const from = named();
|
|
145
|
-
change();
|
|
146
|
-
options.trace?.(from, named(), on);
|
|
147
|
-
};
|
|
148
|
-
const result = (outcome, started, fields = {}) => ({
|
|
149
|
-
outcome,
|
|
150
|
-
at: clock.now(),
|
|
151
|
-
took: clock.now() - started,
|
|
152
|
-
cause: fields.cause ?? null,
|
|
153
|
-
timedOut: fields.timedOut ?? false,
|
|
154
|
-
thrown: fields.thrown ?? false,
|
|
155
|
-
forced: fields.forced ?? false
|
|
156
|
-
});
|
|
157
|
-
const once = () => {
|
|
158
|
-
const started = clock.now();
|
|
159
|
-
if (options.forced()) return Promise.resolve(result("error", started, {
|
|
160
|
-
cause: "the force-fail list names it",
|
|
161
|
-
forced: true
|
|
162
|
-
}));
|
|
163
|
-
if (pending !== null) {
|
|
164
|
-
const cause = `its call of ${Math.round(started - pending.since)} ms ago is still pending`;
|
|
165
|
-
return Promise.resolve(result("error", started, { cause }));
|
|
166
|
-
}
|
|
167
|
-
const controller = new AbortController();
|
|
168
|
-
return new Promise((resolve) => {
|
|
169
|
-
let done = false;
|
|
170
|
-
const finish = (value) => {
|
|
171
|
-
if (done) return;
|
|
172
|
-
done = true;
|
|
173
|
-
active.delete(abandon);
|
|
174
|
-
cancel();
|
|
175
|
-
resolve(value);
|
|
176
|
-
};
|
|
177
|
-
const abandon = () => {
|
|
178
|
-
controller.abort();
|
|
179
|
-
finish(result("error", started, { cause: "the runtime stopped" }));
|
|
180
|
-
};
|
|
181
|
-
active.add(abandon);
|
|
182
|
-
const call = {
|
|
183
|
-
since: started,
|
|
184
|
-
late: false
|
|
185
|
-
};
|
|
186
|
-
pending = call;
|
|
187
|
-
const cancel = clock.after(timeout, () => {
|
|
188
|
-
controller.abort();
|
|
189
|
-
step("timeout", () => {
|
|
190
|
-
if (pending === call) call.late = true;
|
|
191
|
-
});
|
|
192
|
-
finish(result("error", started, {
|
|
193
|
-
cause: `no answer in ${timeout} ms`,
|
|
194
|
-
timedOut: true
|
|
195
|
-
}));
|
|
196
|
-
});
|
|
197
|
-
const settled = () => {
|
|
198
|
-
if (pending !== call) return;
|
|
199
|
-
step(call.late ? "late-answer" : "answer", () => {
|
|
200
|
-
pending = null;
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
let answer;
|
|
204
|
-
try {
|
|
205
|
-
answer = Promise.resolve(run(controller.signal));
|
|
206
|
-
} catch (error) {
|
|
207
|
-
answer = Promise.reject(error);
|
|
208
|
-
}
|
|
209
|
-
answer.then((value) => {
|
|
210
|
-
settled();
|
|
211
|
-
const outcome = value ?? "ok";
|
|
212
|
-
finish(result(outcome, started, outcome === "ok" ? {} : { cause: `the check gave ${outcome}` }));
|
|
213
|
-
}, (error) => {
|
|
214
|
-
settled();
|
|
215
|
-
finish(result("error", started, {
|
|
216
|
-
cause: message(error),
|
|
217
|
-
thrown: true
|
|
218
|
-
}));
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
const handle = (value) => {
|
|
223
|
-
last = value;
|
|
224
|
-
if (!stopped) options.record(value);
|
|
225
|
-
return value;
|
|
226
|
-
};
|
|
227
|
-
const jittered = () => interval * (1 + poll.jitter * (2 * options.random() - 1));
|
|
228
|
-
const tick = () => {
|
|
229
|
-
next = null;
|
|
230
|
-
if (stopped) return;
|
|
231
|
-
let polled;
|
|
232
|
-
step("tick", () => {
|
|
233
|
-
next = clock.after(jittered(), tick);
|
|
234
|
-
polled = once();
|
|
235
|
-
});
|
|
236
|
-
polled.then(handle);
|
|
237
|
-
};
|
|
238
|
-
return {
|
|
239
|
-
get last() {
|
|
240
|
-
return last;
|
|
241
|
-
},
|
|
242
|
-
pollNow: () => {
|
|
243
|
-
let polled;
|
|
244
|
-
step("sweep", () => {
|
|
245
|
-
polled = once();
|
|
246
|
-
});
|
|
247
|
-
return polled.then(handle);
|
|
248
|
-
},
|
|
249
|
-
start(delay) {
|
|
250
|
-
if (stopped || next !== null) return;
|
|
251
|
-
step("start", () => {
|
|
252
|
-
looping = true;
|
|
253
|
-
next = clock.after(Math.max(0, delay), tick);
|
|
254
|
-
});
|
|
255
|
-
},
|
|
256
|
-
jittered,
|
|
257
|
-
stop() {
|
|
258
|
-
if (stopped) return;
|
|
259
|
-
step("stop", () => {
|
|
260
|
-
stopped = true;
|
|
261
|
-
next?.();
|
|
262
|
-
next = null;
|
|
263
|
-
});
|
|
264
|
-
for (const abandon of [...active]) abandon();
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
// src/process.ts
|
|
269
|
-
/** These are the signals that the runtime handles. */
|
|
270
|
-
const EXIT_SIGNALS = [
|
|
271
|
-
"SIGINT",
|
|
272
|
-
"SIGTERM",
|
|
273
|
-
"SIGQUIT"
|
|
274
|
-
];
|
|
275
|
-
/** These are the process triggers that a declaration can opt in to. */
|
|
276
|
-
const PROCESS_TRIGGERS = [
|
|
277
|
-
"stdin-close",
|
|
278
|
-
"ipc-close",
|
|
279
|
-
"ipc-message"
|
|
280
|
-
];
|
|
281
|
-
/** These are the origins of the errors that the option `uncaught` of `run()` receives. */
|
|
282
|
-
const UNCAUGHT_ORIGINS = ["uncaughtException", "unhandledRejection"];
|
|
283
|
-
/** This function tells if a number is an exit code of a process: a whole number from 0 to 255. */
|
|
284
|
-
const isExitCode = (code) => Number.isInteger(code) && code >= 0 && code <= 255;
|
|
285
|
-
/** This function tells if a trigger is an exit signal. A repeat signal obeys `onRepeatSignal`. */
|
|
286
|
-
const isExitSignal = (trigger) => EXIT_SIGNALS.includes(trigger);
|
|
287
|
-
/** This function tells if a value is a message shape: a value of JSON, with no function and no undefined. */
|
|
288
|
-
const isMessageShape = (value) => {
|
|
289
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
290
|
-
if (typeof value === "number") return Number.isFinite(value);
|
|
291
|
-
if (Array.isArray(value)) return value.every(isMessageShape);
|
|
292
|
-
if (typeof value !== "object") return false;
|
|
293
|
-
const prototype = Object.getPrototypeOf(value);
|
|
294
|
-
return (prototype === Object.prototype || prototype === null) && Object.values(value).every(isMessageShape);
|
|
295
|
-
};
|
|
296
|
-
/** This function tells if a message of the IPC channel matches a shape. */
|
|
297
|
-
const matchesMessage = (shape, message) => {
|
|
298
|
-
if (shape === null || typeof shape !== "object") return Object.is(shape, message);
|
|
299
|
-
if (Array.isArray(shape)) {
|
|
300
|
-
const items = shape;
|
|
301
|
-
return Array.isArray(message) && message.length === items.length && items.every((item, at) => matchesMessage(item, message[at]));
|
|
302
|
-
}
|
|
303
|
-
if (message === null || typeof message !== "object" || Array.isArray(message)) return false;
|
|
304
|
-
const fields = message;
|
|
305
|
-
return Object.entries(shape).every(([field, value]) => Object.hasOwn(fields, field) && matchesMessage(value, fields[field]));
|
|
306
|
-
};
|
|
307
|
-
/** This time is the interval of the timer of a hold, the most that a timer of Node accepts. */
|
|
308
|
-
const HOLD_INTERVAL = 2147483647;
|
|
309
|
-
/** This function adds a handler to some events of an emitter. The handler operates one time at most. */
|
|
310
|
-
const once = (emitter, events, handler) => {
|
|
311
|
-
let called = false;
|
|
312
|
-
const fire = () => {
|
|
313
|
-
if (called) return;
|
|
314
|
-
called = true;
|
|
315
|
-
handler();
|
|
316
|
-
};
|
|
317
|
-
for (const event of events) emitter.on(event, fire);
|
|
318
|
-
return () => {
|
|
319
|
-
for (const event of events) emitter.off(event, fire);
|
|
320
|
-
};
|
|
321
|
-
};
|
|
322
|
-
/** This function gives a promise that ends when the data before it in a stream is written. */
|
|
323
|
-
const written = (stream) => new Promise((resolve) => {
|
|
324
|
-
if (stream === void 0 || stream.destroyed === true || stream.writable === false) {
|
|
325
|
-
resolve();
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
try {
|
|
329
|
-
stream.write("", () => resolve());
|
|
330
|
-
} catch {
|
|
331
|
-
resolve();
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
/**
|
|
335
|
-
* This function makes a process port on a host. `find` gives the host at each use, or undefined
|
|
336
|
-
* when the platform has no process. Then the use throws.
|
|
337
|
-
*/
|
|
338
|
-
const processPortOf = (find) => {
|
|
339
|
-
const hostProcess = () => {
|
|
340
|
-
const host = find();
|
|
341
|
-
if (host === void 0) throw new Error("no process: give the runtime a process port");
|
|
342
|
-
return host;
|
|
343
|
-
};
|
|
344
|
-
return {
|
|
345
|
-
on(trigger, handler) {
|
|
346
|
-
const host = hostProcess();
|
|
347
|
-
if (trigger === "stdin-close") {
|
|
348
|
-
const input = host.stdin;
|
|
349
|
-
if (input === void 0) return () => {};
|
|
350
|
-
if (input.readableEnded === true) {
|
|
351
|
-
let live = true;
|
|
352
|
-
queueMicrotask(() => {
|
|
353
|
-
if (live) handler();
|
|
354
|
-
});
|
|
355
|
-
return () => {
|
|
356
|
-
live = false;
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
return once(input, ["end", "close"], handler);
|
|
360
|
-
}
|
|
361
|
-
if (trigger === "ipc-close") return once(host, ["disconnect"], handler);
|
|
362
|
-
if (trigger === "ipc-message") {
|
|
363
|
-
const receive = (message) => handler(message);
|
|
364
|
-
host.on("message", receive);
|
|
365
|
-
return () => {
|
|
366
|
-
host.off("message", receive);
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
host.on(trigger, handler);
|
|
370
|
-
return () => {
|
|
371
|
-
host.off(trigger, handler);
|
|
372
|
-
};
|
|
373
|
-
},
|
|
374
|
-
onUncaught(handler) {
|
|
375
|
-
const host = hostProcess();
|
|
376
|
-
const offs = UNCAUGHT_ORIGINS.map((origin) => {
|
|
377
|
-
const receive = (error) => handler(error, origin);
|
|
378
|
-
host.on(origin, receive);
|
|
379
|
-
return () => {
|
|
380
|
-
host.off(origin, receive);
|
|
381
|
-
};
|
|
382
|
-
});
|
|
383
|
-
return () => {
|
|
384
|
-
for (const off of offs) off();
|
|
385
|
-
};
|
|
386
|
-
},
|
|
387
|
-
async flush() {
|
|
388
|
-
const host = hostProcess();
|
|
389
|
-
await Promise.all([written(host.stdout), written(host.stderr)]);
|
|
390
|
-
},
|
|
391
|
-
hold() {
|
|
392
|
-
hostProcess();
|
|
393
|
-
const timer = setInterval(() => {}, HOLD_INTERVAL);
|
|
394
|
-
let held = true;
|
|
395
|
-
return () => {
|
|
396
|
-
if (!held) return;
|
|
397
|
-
held = false;
|
|
398
|
-
clearInterval(timer);
|
|
399
|
-
};
|
|
400
|
-
},
|
|
401
|
-
exit(code) {
|
|
402
|
-
hostProcess().exit(code);
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
};
|
|
406
|
-
/** This port is the process of Node. */
|
|
407
|
-
const nodeProcess = processPortOf(() => globalThis.process);
|
|
408
|
-
/**
|
|
409
|
-
* This function gives a process port for a lifecycle in a process that another part owns. That
|
|
410
|
-
* part is a script, a test of an application, or a library entry. The port adds no handler of a signal or of
|
|
411
|
-
* a trigger, it does not hold the process, and its `exit` only records the code. The caller stops
|
|
412
|
-
* the lifecycle with `life.shutdown()`. A process with a service of its own gives its parts to
|
|
413
|
-
* that service, and does not use this port.
|
|
414
|
-
*/
|
|
415
|
-
const embeddedProcess = () => {
|
|
416
|
-
let code = null;
|
|
417
|
-
let resolve = () => {};
|
|
418
|
-
return {
|
|
419
|
-
on() {
|
|
420
|
-
return () => {};
|
|
421
|
-
},
|
|
422
|
-
exit(requested) {
|
|
423
|
-
if (code !== null) return;
|
|
424
|
-
code = requested;
|
|
425
|
-
resolve(requested);
|
|
426
|
-
},
|
|
427
|
-
get exitCode() {
|
|
428
|
-
return code;
|
|
429
|
-
},
|
|
430
|
-
exited: new Promise((done) => {
|
|
431
|
-
resolve = done;
|
|
432
|
-
})
|
|
433
|
-
};
|
|
434
|
-
};
|
|
435
|
-
export { isExitCode as a, matchesMessage as c, poller as d, latch as f, embeddedProcess as i, nodeProcess as l, PROCESS_TRIGGERS as n, isExitSignal as o, UNCAUGHT_ORIGINS as r, isMessageShape as s, EXIT_SIGNALS as t, processPortOf as u };
|
|
436
|
-
|
|
437
|
-
//# sourceMappingURL=process-7R9M29wN.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process-7R9M29wN.js","names":[],"sources":["../src/latch.ts","../src/poller.ts","../src/process.ts"],"sourcesContent":["import { valueIn } from \"@mark1russell7/quantity\";\nimport type { Cancel, Clock } from \"./clock.ts\";\nimport type { Timing } from \"./timing.ts\";\n\n/**\n * An outcome is the result of one poll of a check. Only `\"ok\"` passes. An `\"indeterminate\"`\n * outcome measured nothing: it does not pass, and it does not fail.\n */\nexport type Outcome = \"ok\" | \"error\" | \"indeterminate\";\n\n/** A result is one poll of a check, as the runtime records it. */\nexport interface Result {\n readonly outcome: Outcome;\n /** This time is when the result came, on the monotonic clock, in milliseconds. */\n readonly at: number;\n /** This time is how long the poll took, in milliseconds. */\n readonly took: number;\n /** This text tells why the poll did not pass, or it is null. */\n readonly cause: string | null;\n /** This flag tells if the poll failed at its timeout. */\n readonly timedOut: boolean;\n /** This flag tells if the check threw. A throw is an error with a flag. */\n readonly thrown: boolean;\n /** This flag tells if the force-fail list made the poll fail. */\n readonly forced: boolean;\n}\n\n/**\n * A latch turns the results of one check into a verdict, by the timing of its policy. A debounce\n * counts polls in sequence. A window measures time on the monotonic clock from the first failure\n * of a sequence. A tripped latch fails its policy.\n */\nexport interface Latch {\n readonly tripped: boolean;\n /** This time is when the latch last tripped or released. */\n readonly since: number;\n /** This count is the sequence of the latest results: above zero for passes, below zero for failures. */\n readonly streak: number;\n record(result: Result): void;\n /** This method stops the timers of a window. */\n stop(): void;\n}\n\n/**\n * A trace receives each transition of a machine of the runtime: the state before, the state after,\n * and the event. The machine documents of the lifecycle name the same states and events, thus a\n * test can replay a trace against its document.\n */\nexport type Trace = (from: string, to: string, on: string) => void;\n\nconst ms = (amount: { readonly value: number; readonly unit: string }): number =>\n valueIn(amount, \"ms\");\n\n/**\n * This function makes a latch. `tripped` is its state at the start: a readiness latch starts\n * tripped, and a liveness latch starts released. The latch starts `changed` each time it trips or\n * releases, and it gives each transition to `trace`. A debounce has the states `released` and\n * `tripped`. A window also has the states `failing` and `recovering`, while one of its timers runs.\n */\nexport const latch = (\n timing: Timing,\n clock: Clock,\n tripped: boolean,\n changed: () => void,\n trace?: Trace,\n): Latch => {\n let state = tripped;\n let since = clock.now();\n let streak = 0;\n let fails = 0;\n let passes = 0;\n // the timers of a window: the time that a sequence of failures or passes started, and its timer\n let failingSince: number | null = null;\n let passingSince: number | null = null;\n let failTimer: Cancel | null = null;\n let passTimer: Cancel | null = null;\n\n /** This function gives the name of the state, as the machine documents name it. */\n const named = (): string =>\n state\n ? passingSince === null\n ? \"tripped\"\n : \"recovering\"\n : failingSince === null\n ? \"released\"\n : \"failing\";\n /** This function does one step of the machine, and gives its transition to the trace. */\n const step = (on: string, change: () => void): void => {\n const from = named();\n change();\n trace?.(from, named(), on);\n };\n\n const set = (next: boolean): void => {\n if (next === state) return;\n state = next;\n since = clock.now();\n changed();\n };\n const stopFail = (): void => {\n failTimer?.();\n failTimer = null;\n failingSince = null;\n };\n const stopPass = (): void => {\n passTimer?.();\n passTimer = null;\n passingSince = null;\n };\n\n const debounce = (result: Result): void => {\n if (timing.type !== \"debounce\") return;\n if (result.outcome === \"ok\") {\n passes += 1;\n fails = 0;\n if (state && passes >= timing.recoverAfter) set(false);\n } else {\n fails += 1;\n passes = 0;\n if (!state && fails >= timing.failAfter) set(true);\n }\n };\n\n const windowed = (result: Result): void => {\n if (timing.type !== \"window\") return;\n if (result.outcome === \"ok\") {\n stopFail();\n if (!state) return;\n if (timing.recoverAfter === undefined) {\n set(false);\n return;\n }\n if (passingSince !== null) return;\n const wait = ms(timing.recoverAfter);\n if (wait <= 0) {\n stopPass();\n set(false);\n return;\n }\n passingSince = result.at;\n passTimer = clock.after(wait, () =>\n step(\"window.recovered\", () => {\n passTimer = null;\n passingSince = null;\n set(false);\n }),\n );\n return;\n }\n stopPass();\n if (state || failingSince !== null) return;\n const wait = ms(timing.failAfter);\n if (wait <= 0) {\n stopFail();\n set(true);\n return;\n }\n failingSince = result.at;\n failTimer = clock.after(wait, () =>\n step(\"window.failed\", () => {\n failTimer = null;\n failingSince = null;\n set(true);\n }),\n );\n };\n\n return {\n get tripped() {\n return state;\n },\n get since() {\n return since;\n },\n get streak() {\n return streak;\n },\n record(result) {\n // an indeterminate poll measured nothing: it moves no sequence and no streak\n if (result.outcome === \"indeterminate\") return;\n const pass = result.outcome === \"ok\";\n step(pass ? \"poll.ok\" : \"poll.fail\", () => {\n streak = pass ? Math.max(0, streak) + 1 : Math.min(0, streak) - 1;\n debounce(result);\n windowed(result);\n });\n },\n stop() {\n stopFail();\n stopPass();\n },\n };\n};\n","import { valueIn } from \"@mark1russell7/quantity\";\nimport type { Cancel, Clock } from \"./clock.ts\";\nimport type { Outcome, Result, Trace } from \"./latch.ts\";\nimport type { Poll } from \"./timing.ts\";\n\n/**\n * A check function measures one step of a connection. It ends with nothing or `\"ok\"` for a pass,\n * or with `\"error\"` or `\"indeterminate\"`. A throw is an error with a flag. The runtime aborts the\n * signal at the timeout of the poll.\n */\nexport type CheckFn = (signal: AbortSignal) => Outcome | void | Promise<Outcome | void>;\n\n/** A poller starts one check on its own loop, and gives each result to `record`. */\nexport interface Poller {\n /** This result is the latest one, or null before the first poll. */\n readonly last: Result | null;\n /** This method polls one time at once, outside the loop, and gives the result. */\n pollNow(): Promise<Result>;\n /** This method starts the loop. The first poll of the loop comes after `delay` milliseconds. */\n start(delay: number): void;\n /** This method gives the next delay of the loop: the interval, with the jitter. */\n jittered(): number;\n stop(): void;\n}\n\nexport interface PollerOptions {\n readonly name: string;\n readonly poll: Poll;\n readonly run: CheckFn;\n readonly clock: Clock;\n readonly random: () => number;\n /** This function tells if the force-fail list names the check at this time. */\n readonly forced: () => boolean;\n readonly record: (result: Result) => void;\n /**\n * This function receives each transition of the poller. Its states are `idle`, `waiting`,\n * `calling`, `hung` (a call that outlived its timeout) and `stopped`.\n */\n readonly trace?: Trace | undefined;\n}\n\nconst message = (error: unknown): string =>\n error instanceof Error ? error.message : String(error);\n\n/**\n * This function makes a poller. The loop is on a fixed delay from the start of each poll. Thus the\n * next poll starts one interval after the current poll starts, with the jitter (±20 % is 0.2).\n * The timing algebra of the declaration uses this model.\n *\n * Each poll makes a new measurement. While a use of the check is pending, the poller does not\n * start the check again. Such a poll fails at once with the same cause, and the sequence of\n * failures continues.\n */\nexport const poller = (options: PollerOptions): Poller => {\n const { clock, poll, run } = options;\n const interval = valueIn(poll.interval, \"ms\");\n const timeout = valueIn(poll.timeout, \"ms\");\n let last: Result | null = null;\n let next: Cancel | null = null;\n let stopped = false;\n let looping = false;\n // the call that has not ended, and when it started; `late` once the call outlived its timeout\n let pending: { readonly since: number; late: boolean } | null = null;\n // the polls in flight: stop() ends each one, and its timer\n const active = new Set<() => void>();\n\n /** This function gives the name of the state, as the machine document of the poller names it. */\n const named = (): string =>\n stopped\n ? \"stopped\"\n : pending !== null\n ? pending.late\n ? \"hung\"\n : \"calling\"\n : looping\n ? \"waiting\"\n : \"idle\";\n const step = (on: string, change: () => void): void => {\n const from = named();\n change();\n options.trace?.(from, named(), on);\n };\n\n const result = (\n outcome: Outcome,\n started: number,\n fields: Partial<Pick<Result, \"cause\" | \"timedOut\" | \"thrown\" | \"forced\">> = {},\n ): Result => ({\n outcome,\n at: clock.now(),\n took: clock.now() - started,\n cause: fields.cause ?? null,\n timedOut: fields.timedOut ?? false,\n thrown: fields.thrown ?? false,\n forced: fields.forced ?? false,\n });\n\n const once = (): Promise<Result> => {\n const started = clock.now();\n if (options.forced())\n return Promise.resolve(result(\"error\", started, { cause: \"the force-fail list names it\", forced: true }));\n if (pending !== null) {\n const cause = `its call of ${Math.round(started - pending.since)} ms ago is still pending`;\n return Promise.resolve(result(\"error\", started, { cause }));\n }\n const controller = new AbortController();\n return new Promise<Result>((resolve) => {\n let done = false;\n const finish = (value: Result): void => {\n if (done) return;\n done = true;\n active.delete(abandon);\n cancel();\n resolve(value);\n };\n const abandon = (): void => {\n controller.abort();\n finish(result(\"error\", started, { cause: \"the runtime stopped\" }));\n };\n active.add(abandon);\n const call = { since: started, late: false };\n pending = call;\n const cancel = clock.after(timeout, () => {\n controller.abort();\n // the poll fails at its timeout. The call stays pending until it settles\n step(\"timeout\", () => {\n if (pending === call) call.late = true;\n });\n finish(result(\"error\", started, { cause: `no answer in ${timeout} ms`, timedOut: true }));\n });\n const settled = (): void => {\n if (pending !== call) return;\n step(call.late ? \"late-answer\" : \"answer\", () => {\n pending = null;\n });\n };\n let answer: Promise<Outcome | void>;\n try {\n answer = Promise.resolve(run(controller.signal));\n } catch (error) {\n answer = Promise.reject(error);\n }\n answer.then(\n (value) => {\n settled();\n const outcome = value ?? \"ok\";\n finish(result(outcome, started, outcome === \"ok\" ? {} : { cause: `the check gave ${outcome}` }));\n },\n (error: unknown) => {\n settled();\n finish(result(\"error\", started, { cause: message(error), thrown: true }));\n },\n );\n });\n };\n\n const handle = (value: Result): Result => {\n last = value;\n if (!stopped) options.record(value);\n return value;\n };\n\n const jittered = (): number => interval * (1 + poll.jitter * (2 * options.random() - 1));\n\n const tick = (): void => {\n next = null;\n if (stopped) return;\n let polled: Promise<Result> | undefined;\n step(\"tick\", () => {\n next = clock.after(jittered(), tick);\n polled = once();\n });\n void polled!.then(handle);\n };\n\n return {\n get last() {\n return last;\n },\n pollNow: () => {\n let polled: Promise<Result> | undefined;\n step(\"sweep\", () => {\n polled = once();\n });\n return polled!.then(handle);\n },\n start(delay) {\n if (stopped || next !== null) return;\n step(\"start\", () => {\n looping = true;\n next = clock.after(Math.max(0, delay), tick);\n });\n },\n jittered,\n stop() {\n if (stopped) return;\n step(\"stop\", () => {\n stopped = true;\n next?.();\n next = null;\n });\n for (const abandon of [...active]) abandon();\n },\n };\n};\n","/** An exit signal is a signal that asks the process to stop: each one starts the shutdown. */\nexport type ExitSignal = \"SIGINT\" | \"SIGTERM\" | \"SIGQUIT\";\n\n/** These are the signals that the runtime handles. */\nexport const EXIT_SIGNALS: readonly ExitSignal[] = [\"SIGINT\", \"SIGTERM\", \"SIGQUIT\"];\n\n/**\n * A process trigger is an event of the process, other than a signal, that starts the shutdown. A\n * declaration opts in to each one (`svc.trigger`):\n * - `stdin-close`: the standard input ends or closes, as when the parent of a stdio child goes away.\n * The process must read its input, as a stdio transport does, or Node does not see the end.\n * - `ipc-close`: the IPC channel to the parent process closes.\n * - `ipc-message`: a message on the IPC channel matches a declared shape. Windows cannot give a\n * child a SIGTERM that the child can catch, thus a parent sends a message.\n */\nexport type ProcessTrigger = \"stdin-close\" | \"ipc-close\" | \"ipc-message\";\n\n/** These are the process triggers that a declaration can opt in to. */\nexport const PROCESS_TRIGGERS: readonly ProcessTrigger[] = [\"stdin-close\", \"ipc-close\", \"ipc-message\"];\n\n/** An exit trigger is an event that starts the shutdown: an exit signal, or a declared process trigger. */\nexport type ExitTrigger = ExitSignal | ProcessTrigger;\n\n/**\n * An uncaught origin tells how an error that no code caught came to the process. It is an exception\n * that no code caught, or a rejection of a promise that no code handled.\n */\nexport type UncaughtOrigin = \"uncaughtException\" | \"unhandledRejection\";\n\n/** These are the origins of the errors that the option `uncaught` of `run()` receives. */\nexport const UNCAUGHT_ORIGINS: readonly UncaughtOrigin[] = [\"uncaughtException\", \"unhandledRejection\"];\n\n/** This function tells if a number is an exit code of a process: a whole number from 0 to 255. */\nexport const isExitCode = (code: number): boolean => Number.isInteger(code) && code >= 0 && code <= 255;\n\n/** This function tells if a trigger is an exit signal. A repeat signal obeys `onRepeatSignal`. */\nexport const isExitSignal = (trigger: string): trigger is ExitSignal =>\n (EXIT_SIGNALS as readonly string[]).includes(trigger);\n\n/**\n * A message shape is a value of JSON that a message of the IPC channel can match. A string, a\n * number, a boolean or null matches an equal message. An object matches a message that has each of\n * its fields, and each value of the field matches. An array matches an array of the same length, item by item.\n */\nexport type MessageShape = string | number | boolean | null | readonly MessageShape[] | { readonly [field: string]: MessageShape };\n\n/** This function tells if a value is a message shape: a value of JSON, with no function and no undefined. */\nexport const isMessageShape = (value: unknown): value is MessageShape => {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n if (typeof value === \"number\") return Number.isFinite(value);\n if (Array.isArray(value)) return value.every(isMessageShape);\n if (typeof value !== \"object\") return false;\n const prototype = Object.getPrototypeOf(value) as unknown;\n return (prototype === Object.prototype || prototype === null) && Object.values(value).every(isMessageShape);\n};\n\n/** This function tells if a message of the IPC channel matches a shape. */\nexport const matchesMessage = (shape: MessageShape, message: unknown): boolean => {\n if (shape === null || typeof shape !== \"object\") return Object.is(shape, message);\n if (Array.isArray(shape)) {\n const items: readonly MessageShape[] = shape;\n return Array.isArray(message) && message.length === items.length && items.every((item, at) => matchesMessage(item, message[at]));\n }\n if (message === null || typeof message !== \"object\" || Array.isArray(message)) return false;\n const fields = message as Readonly<Record<string, unknown>>;\n return Object.entries(shape).every(([field, value]) => Object.hasOwn(fields, field) && matchesMessage(value, fields[field]));\n};\n\n/**\n * A process port is the part of the process that the runtime uses: its exit triggers, its output\n * and its exit. The runtime owns the handlers, because Node as PID 1 without a handler ignores\n * SIGTERM. Only the runtime ends the process, and library code does not. A test gives a fake port,\n * sends triggers, and reads the exit code.\n */\nexport interface ProcessPort {\n /**\n * This method adds a handler for a trigger, and gives the function that removes it. The runtime\n * asks for a process trigger only when the declaration opts in to it. For `ipc-message`, the\n * handler gets each message of the IPC channel, and the runtime matches it.\n */\n on(trigger: ExitTrigger, handler: (message?: unknown) => void): () => void;\n /**\n * This method adds a handler for each error that no code caught, and gives the function that\n * removes it. The runtime asks for it only when `run()` gets the option `uncaught`. A port without\n * this method gets no handler, as the embedded port.\n */\n onUncaught?(handler: (error: unknown, origin: UncaughtOrigin) => void): () => void;\n /**\n * This method writes each buffered line of the output, and its promise ends when the output is\n * written. The stage `flush the output` uses it, in the cap of that stage.\n */\n flush?(): Promise<void> | void;\n /**\n * This method keeps the process alive, and gives the function that releases it. The lifecycle\n * holds its process from its start to its exit, as a listening socket does. Thus a process whose\n * timers do not keep it alive does not end in the middle of its work. It keeps its teardown and its exit code.\n */\n hold?(): () => void;\n /** This method ends the process with a code: the code of the exit request, 1 after an error, or 0. */\n exit(code: number): void;\n}\n\n/** A host stream is the part of a stream of Node that the port uses. */\nexport interface HostStream {\n readonly writable?: boolean;\n readonly destroyed?: boolean;\n readonly readableEnded?: boolean;\n write(chunk: string, done: (error?: unknown) => void): boolean;\n on(event: string, handler: () => void): unknown;\n off(event: string, handler: () => void): unknown;\n}\n\n/** A process host is the part of the process of Node that the port uses. Its event `message` gives the message of the IPC channel. */\nexport interface ProcessHost {\n on(signal: string, handler: (message?: unknown) => void): unknown;\n off(signal: string, handler: (message?: unknown) => void): unknown;\n exit(code: number): unknown;\n readonly stdin?: HostStream | undefined;\n readonly stdout?: HostStream | undefined;\n readonly stderr?: HostStream | undefined;\n}\n\n/** This time is the interval of the timer of a hold, the most that a timer of Node accepts. */\nconst HOLD_INTERVAL = 0x7fffffff;\n\n/** This function adds a handler to some events of an emitter. The handler operates one time at most. */\nconst once = (emitter: HostStream | ProcessHost, events: readonly string[], handler: () => void): (() => void) => {\n let called = false;\n const fire = (): void => {\n if (called) return;\n called = true;\n handler();\n };\n for (const event of events) emitter.on(event, fire);\n return () => {\n for (const event of events) emitter.off(event, fire);\n };\n};\n\n/** This function gives a promise that ends when the data before it in a stream is written. */\nconst written = (stream: HostStream | undefined): Promise<void> =>\n new Promise<void>((resolve) => {\n if (stream === undefined || stream.destroyed === true || stream.writable === false) {\n resolve();\n return;\n }\n try {\n // the callback of an empty write comes after each write before it\n stream.write(\"\", () => resolve());\n } catch {\n resolve();\n }\n });\n\n/**\n * This function makes a process port on a host. `find` gives the host at each use, or undefined\n * when the platform has no process. Then the use throws.\n */\nexport const processPortOf = (find: () => ProcessHost | undefined): ProcessPort => {\n const hostProcess = (): ProcessHost => {\n const host = find();\n if (host === undefined) throw new Error(\"no process: give the runtime a process port\");\n return host;\n };\n return {\n on(trigger, handler) {\n const host = hostProcess();\n if (trigger === \"stdin-close\") {\n const input = host.stdin;\n if (input === undefined) return () => {};\n // an input that ended before the handler was added still starts the shutdown\n if (input.readableEnded === true) {\n let live = true;\n queueMicrotask(() => {\n if (live) handler();\n });\n return () => {\n live = false;\n };\n }\n return once(input, [\"end\", \"close\"], handler);\n }\n if (trigger === \"ipc-close\") return once(host, [\"disconnect\"], handler);\n if (trigger === \"ipc-message\") {\n // each message goes to the runtime, which matches it with the declared shapes\n const receive = (message?: unknown): void => handler(message);\n host.on(\"message\", receive);\n return () => {\n host.off(\"message\", receive);\n };\n }\n host.on(trigger, handler);\n return () => {\n host.off(trigger, handler);\n };\n },\n onUncaught(handler) {\n const host = hostProcess();\n // a handler of each origin: Node then does not end the process, and the runtime does the shutdown\n const offs = UNCAUGHT_ORIGINS.map((origin) => {\n const receive = (error?: unknown): void => handler(error, origin);\n host.on(origin, receive);\n return () => {\n host.off(origin, receive);\n };\n });\n return () => {\n for (const off of offs) off();\n };\n },\n async flush() {\n const host = hostProcess();\n await Promise.all([written(host.stdout), written(host.stderr)]);\n },\n hold() {\n hostProcess();\n // one interval that keeps the event loop alive: its timer does nothing, and the release stops it\n const timer = setInterval(() => {}, HOLD_INTERVAL);\n let held = true;\n return () => {\n if (!held) return;\n held = false;\n clearInterval(timer);\n };\n },\n exit(code) {\n hostProcess().exit(code);\n },\n };\n};\n\n/** This port is the process of Node. */\nexport const nodeProcess: ProcessPort = processPortOf(() => (globalThis as { process?: ProcessHost }).process);\n\n/** An embedded process port records the exit code of a lifecycle that does not own its process. */\nexport interface EmbeddedProcess extends ProcessPort {\n /** This code is the code of the exit request of the lifecycle, or null before that request. */\n readonly exitCode: number | null;\n /** This promise ends with the exit code when the lifecycle asks for its exit. */\n readonly exited: Promise<number>;\n}\n\n/**\n * This function gives a process port for a lifecycle in a process that another part owns. That\n * part is a script, a test of an application, or a library entry. The port adds no handler of a signal or of\n * a trigger, it does not hold the process, and its `exit` only records the code. The caller stops\n * the lifecycle with `life.shutdown()`. A process with a service of its own gives its parts to\n * that service, and does not use this port.\n */\nexport const embeddedProcess = (): EmbeddedProcess => {\n let code: number | null = null;\n let resolve: (code: number) => void = () => {};\n const exited = new Promise<number>((done) => {\n resolve = done;\n });\n return {\n on() {\n // the owner of the process keeps its signals and triggers\n return () => {};\n },\n exit(requested) {\n if (code !== null) return;\n code = requested;\n resolve(requested);\n },\n get exitCode() {\n return code;\n },\n exited,\n };\n};\n"],"mappings":";;AAkDA,MAAM,MAAM,WACV,QAAQ,QAAQ,IAAI;;;;;;;AAQtB,MAAa,SACX,QACA,OACA,SACA,SACA,UACU;CACV,IAAI,QAAQ;CACZ,IAAI,QAAQ,MAAM,IAAI;CACtB,IAAI,SAAS;CACb,IAAI,QAAQ;CACZ,IAAI,SAAS;CAEb,IAAI,eAA8B;CAClC,IAAI,eAA8B;CAClC,IAAI,YAA2B;CAC/B,IAAI,YAA2B;;CAG/B,MAAM,cACJ,QACI,iBAAiB,OACf,YACA,eACF,iBAAiB,OACf,aACA;;CAER,MAAM,QAAQ,IAAY,WAA6B;EACrD,MAAM,OAAO,MAAM;EACnB,OAAO;EACP,QAAQ,MAAM,MAAM,GAAG,EAAE;CAC3B;C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