@mark1russell7/service 0.8.19 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- 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/channel.js.map +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 +2 -2
- package/build/clock.js +1 -1
- package/build/conformance.d.ts +122 -0
- package/build/conformance.js +469 -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 +225 -0
- package/build/health.js.map +1 -0
- package/build/heartbeat.d.ts +6 -2
- package/build/heartbeat.js.map +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 +524 -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 +518 -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 +25 -3278
- 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 +154 -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 +38 -0
- package/build/watchdog.js +57 -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 +5 -4
- 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
package/build/builder.js
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import { FORMAT } from "./description.js";
|
|
2
|
+
import { realClock, unrefClock } from "./clock.js";
|
|
3
|
+
import { limiterProblems } from "./limiter/policy.js";
|
|
4
|
+
import { healthRuntime } from "./health.js";
|
|
5
|
+
import { logEvents } from "./logger.js";
|
|
6
|
+
import { STAGES, lifecycle, lifecycleProblems, stageRank, uncaughtProblems } from "./lifecycle.js";
|
|
7
|
+
import { operationProblems } from "./operation.js";
|
|
8
|
+
import { EXIT_SIGNALS, PROCESS_TRIGGERS, isExitCode, isExitSignal, isMessageShape } from "./process.js";
|
|
9
|
+
import { routePatternProblems } from "./routes.js";
|
|
10
|
+
import { watchdog } from "./watchdog.js";
|
|
11
|
+
import { convertible, valueIn } from "@mark1russell7/quantity";
|
|
12
|
+
// src/builder.ts
|
|
13
|
+
const isTime = (amount) => convertible(amount.unit, "s");
|
|
14
|
+
const above = (amount) => amount.value === "infinite" || isTime(amount) && valueIn(amount, "s") > 0;
|
|
15
|
+
const whole = (count) => Number.isInteger(count) && count >= 1;
|
|
16
|
+
/** This function copies a check, with its poll and the loops that mark it. */
|
|
17
|
+
const copyCheck = (check) => ({
|
|
18
|
+
...check,
|
|
19
|
+
poll: { ...check.poll },
|
|
20
|
+
...check.marks === void 0 ? {} : { marks: {
|
|
21
|
+
loops: [...check.marks.loops],
|
|
22
|
+
stall: { ...check.marks.stall }
|
|
23
|
+
} }
|
|
24
|
+
});
|
|
25
|
+
/** This function gives the problems of the loops that mark a check. `lint()` compares the stall time with the loops. */
|
|
26
|
+
const marksProblems = (check) => {
|
|
27
|
+
const marks = check.marks;
|
|
28
|
+
if (marks === void 0) return [];
|
|
29
|
+
const problems = [];
|
|
30
|
+
if (check.step !== "progress") problems.push(`check ${check.name} names the loops that mark it, but its step is ${check.step}, not progress`);
|
|
31
|
+
if (marks.loops.length === 0) problems.push(`check ${check.name} names no loop that marks it`);
|
|
32
|
+
if (typeof marks.stall.value !== "number" || !above(marks.stall)) problems.push(`check ${check.name} has a stall time that is not a time above zero`);
|
|
33
|
+
return problems;
|
|
34
|
+
};
|
|
35
|
+
/** This function gives the problems of a timing: a zero interval or count fails decoding. */
|
|
36
|
+
const timingProblems = (policy, timing) => {
|
|
37
|
+
if (timing.type === "debounce") {
|
|
38
|
+
const problems = [];
|
|
39
|
+
if (!above(timing.interval)) problems.push(`the ${policy} debounce polls at an interval that is not above zero`);
|
|
40
|
+
if (!whole(timing.failAfter)) problems.push(`the ${policy} debounce fails after ${timing.failAfter} polls, not a whole number above zero`);
|
|
41
|
+
if (!whole(timing.recoverAfter)) problems.push(`the ${policy} debounce recovers after ${timing.recoverAfter} polls, not a whole number above zero`);
|
|
42
|
+
return problems;
|
|
43
|
+
}
|
|
44
|
+
const negative = (amount) => amount !== void 0 && (!isTime(amount) || valueIn(amount, "s") < 0);
|
|
45
|
+
return negative(timing.failAfter) || negative(timing.recoverAfter) ? [`the ${policy} window is not a time of zero or more`] : [];
|
|
46
|
+
};
|
|
47
|
+
/** This function gives the problems of the rules of the shutdown: an unknown name, or an exit code that a process cannot give. */
|
|
48
|
+
const shutdownProblems = (floor, repeat, triggers, exitCodes, messages) => {
|
|
49
|
+
const problems = [];
|
|
50
|
+
if (floor !== void 0 && floor !== "half" && floor !== "none") problems.push(`the cooperative floor ${String(floor)} is not "half" or "none"`);
|
|
51
|
+
if (repeat !== void 0 && repeat !== "ignore" && repeat !== "exit") problems.push(`the policy of a repeat signal ${String(repeat)} is not "ignore" or "exit"`);
|
|
52
|
+
for (const trigger of triggers) if (!PROCESS_TRIGGERS.includes(trigger)) problems.push(`the trigger ${String(trigger)} is not a process trigger (${PROCESS_TRIGGERS.join(", ")})`);
|
|
53
|
+
if (triggers.includes("ipc-message") && messages.length === 0) problems.push(`the trigger ipc-message has no message to match: declare it with svc.trigger("ipc-message", { match })`);
|
|
54
|
+
for (const message of messages) {
|
|
55
|
+
if (!isMessageShape(message.match)) problems.push(`the match of a message trigger is not a value of JSON: ${String(message.match)}`);
|
|
56
|
+
if (message.as !== void 0 && !isExitSignal(message.as)) problems.push(`a message trigger stands for ${String(message.as)}, not an exit signal (${EXIT_SIGNALS.join(", ")})`);
|
|
57
|
+
}
|
|
58
|
+
for (const [trigger, code] of Object.entries(exitCodes)) {
|
|
59
|
+
if (!(EXIT_SIGNALS.includes(trigger) || triggers.includes(trigger))) problems.push(`the exit code of ${trigger} names no exit signal and no declared trigger`);
|
|
60
|
+
if (code === void 0 || !isExitCode(code)) problems.push(`the exit code of ${trigger} is ${String(code)}, not a whole number from 0 to 255`);
|
|
61
|
+
}
|
|
62
|
+
return problems;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* This function gives the options with one recorder for the recorder and the logger of the options.
|
|
66
|
+
* Without a logger, it gives the same options.
|
|
67
|
+
*/
|
|
68
|
+
const withLogger = (options, description) => {
|
|
69
|
+
if (options.logger === void 0) return options;
|
|
70
|
+
const given = options.record;
|
|
71
|
+
const log = logEvents(options.logger, description);
|
|
72
|
+
return {
|
|
73
|
+
...options,
|
|
74
|
+
record: (event) => {
|
|
75
|
+
given?.(event);
|
|
76
|
+
log(event);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
/** This function starts the composition of a service. */
|
|
81
|
+
const service = (name) => {
|
|
82
|
+
if (name.trim().length === 0) throw new Error("a service needs a name");
|
|
83
|
+
const transports = [];
|
|
84
|
+
const dependencies = [];
|
|
85
|
+
const controllers = [];
|
|
86
|
+
const choices = /* @__PURE__ */ new Map();
|
|
87
|
+
const checks = [];
|
|
88
|
+
const runs = /* @__PURE__ */ new Map();
|
|
89
|
+
const limiters = [];
|
|
90
|
+
const couplings = [];
|
|
91
|
+
const phases = [];
|
|
92
|
+
let readiness;
|
|
93
|
+
let liveness;
|
|
94
|
+
let startup;
|
|
95
|
+
let cooperative;
|
|
96
|
+
let floor;
|
|
97
|
+
let repeat;
|
|
98
|
+
const triggers = [];
|
|
99
|
+
const messages = [];
|
|
100
|
+
const exitCodes = {};
|
|
101
|
+
let started = false;
|
|
102
|
+
let partial = false;
|
|
103
|
+
let runtime;
|
|
104
|
+
let live;
|
|
105
|
+
let running;
|
|
106
|
+
let life;
|
|
107
|
+
const transportImpls = /* @__PURE__ */ new Map();
|
|
108
|
+
const handles = /* @__PURE__ */ new Map();
|
|
109
|
+
const phaseWork = /* @__PURE__ */ new Map();
|
|
110
|
+
const watchdogs = [];
|
|
111
|
+
let probes = null;
|
|
112
|
+
/** This function stops a change to the shape of the service after the start. */
|
|
113
|
+
const composing = (what) => {
|
|
114
|
+
if (started) throw new Error(`${name} has started: ${what} is declared before svc.start()`);
|
|
115
|
+
};
|
|
116
|
+
const once = (list, entry, what) => {
|
|
117
|
+
if (list.some((held) => held.name === entry)) throw new Error(`${name} already has a ${what} named ${entry}`);
|
|
118
|
+
};
|
|
119
|
+
const transport = (kind) => (entry, knobs, impl) => {
|
|
120
|
+
composing(`a ${kind}`);
|
|
121
|
+
once(transports, entry, "transport");
|
|
122
|
+
transports.push({
|
|
123
|
+
name: entry,
|
|
124
|
+
kind,
|
|
125
|
+
knobs: { ...knobs }
|
|
126
|
+
});
|
|
127
|
+
if (impl !== void 0) transportImpls.set(entry, impl);
|
|
128
|
+
return builder;
|
|
129
|
+
};
|
|
130
|
+
/** This function makes the runtime of the declaration: its checks, and a watchdog for each spec. */
|
|
131
|
+
const makeRuntime = (given) => {
|
|
132
|
+
const description = builder.describe();
|
|
133
|
+
const options = withLogger(given, description);
|
|
134
|
+
const clock = options.clock ?? realClock;
|
|
135
|
+
const dogs = [];
|
|
136
|
+
const all = new Map(runs);
|
|
137
|
+
for (const spec of watchdogs) {
|
|
138
|
+
const dog = watchdog(unrefClock(clock), spec, (from, to, on) => options.record?.({
|
|
139
|
+
at: clock.now(),
|
|
140
|
+
machine: "watchdog",
|
|
141
|
+
instance: spec.name,
|
|
142
|
+
from,
|
|
143
|
+
to,
|
|
144
|
+
on
|
|
145
|
+
}));
|
|
146
|
+
dogs.push(dog);
|
|
147
|
+
all.set(spec.name, () => dog.check());
|
|
148
|
+
}
|
|
149
|
+
const stopPollers = () => {
|
|
150
|
+
for (const dog of dogs) dog.stop();
|
|
151
|
+
};
|
|
152
|
+
let made;
|
|
153
|
+
try {
|
|
154
|
+
made = healthRuntime(description, all, options);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
stopPollers();
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
runtime: {
|
|
161
|
+
...made,
|
|
162
|
+
stop: () => {
|
|
163
|
+
made.stop();
|
|
164
|
+
stopPollers();
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
description,
|
|
168
|
+
stopPollers,
|
|
169
|
+
options
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
const builder = {
|
|
173
|
+
name,
|
|
174
|
+
get health() {
|
|
175
|
+
return live ?? null;
|
|
176
|
+
},
|
|
177
|
+
get lifecycle() {
|
|
178
|
+
return life ?? null;
|
|
179
|
+
},
|
|
180
|
+
dependency(entry, spec, handle) {
|
|
181
|
+
once(dependencies, entry, "dependency");
|
|
182
|
+
if (handle !== void 0 && !started) handles.set(entry, handle);
|
|
183
|
+
dependencies.push({
|
|
184
|
+
name: entry,
|
|
185
|
+
...spec,
|
|
186
|
+
knobs: { ...spec.knobs },
|
|
187
|
+
operations: { ...spec.operations }
|
|
188
|
+
});
|
|
189
|
+
if (started) {
|
|
190
|
+
partial = true;
|
|
191
|
+
live?.addDependency(entry);
|
|
192
|
+
}
|
|
193
|
+
return builder;
|
|
194
|
+
},
|
|
195
|
+
server: transport("server"),
|
|
196
|
+
consumer: transport("consumer"),
|
|
197
|
+
worker: transport("worker"),
|
|
198
|
+
controller(entry) {
|
|
199
|
+
composing("a controller");
|
|
200
|
+
once(controllers, entry, "controller");
|
|
201
|
+
const held = {
|
|
202
|
+
name: entry,
|
|
203
|
+
requires: [],
|
|
204
|
+
routes: {},
|
|
205
|
+
patterns: []
|
|
206
|
+
};
|
|
207
|
+
controllers.push(held);
|
|
208
|
+
const handle = {
|
|
209
|
+
requires(...needed) {
|
|
210
|
+
composing(`what ${entry} requires`);
|
|
211
|
+
held.requires.push(...needed);
|
|
212
|
+
return handle;
|
|
213
|
+
},
|
|
214
|
+
route(served, operation) {
|
|
215
|
+
composing(`${entry}'s routes`);
|
|
216
|
+
if (held.routes[served] !== void 0) throw new Error(`${entry} already serves ${served}`);
|
|
217
|
+
held.routes[served] = { ...operation };
|
|
218
|
+
return handle;
|
|
219
|
+
},
|
|
220
|
+
pattern(pattern, operations, operationOf) {
|
|
221
|
+
composing(`${entry}'s route patterns`);
|
|
222
|
+
if (held.patterns.some((each) => each.pattern === pattern)) throw new Error(`${entry} already has the route pattern ${pattern}`);
|
|
223
|
+
if (operationOf === void 0 && Object.keys(operations).length > 1) throw new Error(`${entry}'s pattern ${pattern} has ${Object.keys(operations).length} operations, thus it needs the function that picks one`);
|
|
224
|
+
held.patterns.push({
|
|
225
|
+
pattern,
|
|
226
|
+
operations: Object.fromEntries(Object.entries(operations).map(([name, operation]) => [name, { ...operation }]))
|
|
227
|
+
});
|
|
228
|
+
if (operationOf !== void 0) {
|
|
229
|
+
const mine = choices.get(entry) ?? /* @__PURE__ */ new Map();
|
|
230
|
+
mine.set(pattern, operationOf);
|
|
231
|
+
choices.set(entry, mine);
|
|
232
|
+
}
|
|
233
|
+
return handle;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
return handle;
|
|
237
|
+
},
|
|
238
|
+
check(check, run) {
|
|
239
|
+
once(checks, check.name, "check");
|
|
240
|
+
if (started && run === void 0) throw new Error(`check ${check.name} joins after the start, thus it needs its function`);
|
|
241
|
+
checks.push(copyCheck(check));
|
|
242
|
+
if (run !== void 0) runs.set(check.name, run);
|
|
243
|
+
if (started) {
|
|
244
|
+
partial = true;
|
|
245
|
+
live?.addCheck(copyCheck(check), run);
|
|
246
|
+
}
|
|
247
|
+
return builder;
|
|
248
|
+
},
|
|
249
|
+
limiter(entry, spec) {
|
|
250
|
+
composing(`the limiter ${entry}`);
|
|
251
|
+
once(limiters, entry, "limiter");
|
|
252
|
+
const given = spec ?? {};
|
|
253
|
+
limiters.push({
|
|
254
|
+
name: entry,
|
|
255
|
+
...given,
|
|
256
|
+
...given.policy === void 0 ? {} : { policy: { ...given.policy } },
|
|
257
|
+
...given.store === void 0 ? {} : { store: { ...given.store } },
|
|
258
|
+
...given.evict === void 0 ? {} : { evict: { ...given.evict } }
|
|
259
|
+
});
|
|
260
|
+
return builder;
|
|
261
|
+
},
|
|
262
|
+
healthServer(server) {
|
|
263
|
+
composing("the health server");
|
|
264
|
+
if (probes !== null) throw new Error(`${name} already has a health server`);
|
|
265
|
+
probes = server;
|
|
266
|
+
return builder;
|
|
267
|
+
},
|
|
268
|
+
onPhase(phase, work) {
|
|
269
|
+
composing(`work for the phase ${phase}`);
|
|
270
|
+
phaseWork.set(phase, [...phaseWork.get(phase) ?? [], work]);
|
|
271
|
+
return builder;
|
|
272
|
+
},
|
|
273
|
+
watchdog(spec) {
|
|
274
|
+
composing(`the watchdog ${spec.name}`);
|
|
275
|
+
once(checks, spec.name, "check");
|
|
276
|
+
checks.push({
|
|
277
|
+
name: spec.name,
|
|
278
|
+
dependency: null,
|
|
279
|
+
step: "local-state",
|
|
280
|
+
ownConnection: true,
|
|
281
|
+
gates: spec.gates,
|
|
282
|
+
poll: { ...spec.poll }
|
|
283
|
+
});
|
|
284
|
+
watchdogs.push(spec);
|
|
285
|
+
return builder;
|
|
286
|
+
},
|
|
287
|
+
readiness(timing) {
|
|
288
|
+
composing("readiness");
|
|
289
|
+
readiness = timing;
|
|
290
|
+
return builder;
|
|
291
|
+
},
|
|
292
|
+
liveness(timing) {
|
|
293
|
+
composing("liveness");
|
|
294
|
+
liveness = timing;
|
|
295
|
+
return builder;
|
|
296
|
+
},
|
|
297
|
+
startup(budget) {
|
|
298
|
+
composing("the startup budget");
|
|
299
|
+
startup = budget;
|
|
300
|
+
return builder;
|
|
301
|
+
},
|
|
302
|
+
couple(coupling) {
|
|
303
|
+
composing("a coupling");
|
|
304
|
+
couplings.push({ ...coupling });
|
|
305
|
+
return builder;
|
|
306
|
+
},
|
|
307
|
+
phase(entry, cap) {
|
|
308
|
+
composing("a shutdown phase");
|
|
309
|
+
once(phases, entry, "shutdown phase");
|
|
310
|
+
phases.push({
|
|
311
|
+
name: entry,
|
|
312
|
+
cap
|
|
313
|
+
});
|
|
314
|
+
return builder;
|
|
315
|
+
},
|
|
316
|
+
cooperativeWindow(window) {
|
|
317
|
+
composing("the cooperative window");
|
|
318
|
+
cooperative = window;
|
|
319
|
+
return builder;
|
|
320
|
+
},
|
|
321
|
+
cooperativeFloor(given) {
|
|
322
|
+
composing("the cooperative floor");
|
|
323
|
+
floor = given;
|
|
324
|
+
return builder;
|
|
325
|
+
},
|
|
326
|
+
onRepeatSignal(policy) {
|
|
327
|
+
composing("the policy of a repeat signal");
|
|
328
|
+
repeat = policy;
|
|
329
|
+
return builder;
|
|
330
|
+
},
|
|
331
|
+
trigger(...given) {
|
|
332
|
+
composing("a trigger");
|
|
333
|
+
const [first, message] = given;
|
|
334
|
+
if (first === "ipc-message" && typeof message === "object" && message !== null) {
|
|
335
|
+
if (!triggers.includes("ipc-message")) triggers.push("ipc-message");
|
|
336
|
+
messages.push({ ...message });
|
|
337
|
+
return builder;
|
|
338
|
+
}
|
|
339
|
+
for (const each of given) if (typeof each === "string" && !triggers.includes(each)) triggers.push(each);
|
|
340
|
+
return builder;
|
|
341
|
+
},
|
|
342
|
+
exitCode(trigger, code) {
|
|
343
|
+
composing(`the exit code of ${trigger}`);
|
|
344
|
+
exitCodes[trigger] = code;
|
|
345
|
+
return builder;
|
|
346
|
+
},
|
|
347
|
+
profile(given) {
|
|
348
|
+
composing("a profile");
|
|
349
|
+
if (given.readiness !== void 0) builder.readiness(given.readiness);
|
|
350
|
+
if (given.liveness !== void 0) builder.liveness(given.liveness);
|
|
351
|
+
if (given.startup !== void 0) builder.startup(given.startup);
|
|
352
|
+
for (const coupling of given.couplings ?? []) builder.couple(coupling);
|
|
353
|
+
for (const each of given.phases ?? []) builder.phase(each.name, each.cap);
|
|
354
|
+
if (given.cooperativeWindow !== void 0) builder.cooperativeWindow(given.cooperativeWindow);
|
|
355
|
+
if (given.cooperativeFloor !== void 0) builder.cooperativeFloor(given.cooperativeFloor);
|
|
356
|
+
if (given.onRepeatSignal !== void 0) builder.onRepeatSignal(given.onRepeatSignal);
|
|
357
|
+
if (given.triggers !== void 0) builder.trigger(...given.triggers);
|
|
358
|
+
for (const message of given.messages ?? []) builder.trigger("ipc-message", message);
|
|
359
|
+
for (const [trigger, code] of Object.entries(given.exitCodes ?? {})) if (code !== void 0) builder.exitCode(trigger, code);
|
|
360
|
+
return builder;
|
|
361
|
+
},
|
|
362
|
+
describe() {
|
|
363
|
+
const missing = [];
|
|
364
|
+
if (readiness === void 0) missing.push("readiness (svc.readiness)");
|
|
365
|
+
if (liveness === void 0) missing.push("liveness (svc.liveness)");
|
|
366
|
+
if (startup === void 0) missing.push("a startup budget (svc.startup)");
|
|
367
|
+
if (phases.length === 0) missing.push("its shutdown phases (svc.phase)");
|
|
368
|
+
if (cooperative === void 0) missing.push("a cooperative window, or no bound (svc.cooperativeWindow)");
|
|
369
|
+
if (repeat === void 0) missing.push(`what a repeat signal does, "ignore" or "exit" (svc.onRepeatSignal)`);
|
|
370
|
+
if (missing.length > 0) throw new Error(`${name} does not declare ${missing.join("; ")}: the runtime has no defaults`);
|
|
371
|
+
const known = new Set(dependencies.map((entry) => entry.name));
|
|
372
|
+
const problems = [];
|
|
373
|
+
const policies = {
|
|
374
|
+
readiness,
|
|
375
|
+
liveness
|
|
376
|
+
};
|
|
377
|
+
for (const gate of ["readiness", "liveness"]) problems.push(...timingProblems(gate, policies[gate]));
|
|
378
|
+
for (const check of checks) {
|
|
379
|
+
if (check.dependency !== null && !known.has(check.dependency)) problems.push(`check ${check.name} exercises ${check.dependency}, which is not a dependency`);
|
|
380
|
+
if (!isTime(check.poll.interval) || !isTime(check.poll.timeout)) problems.push(`check ${check.name} polls in a unit that is not a time`);
|
|
381
|
+
else if (!above(check.poll.interval) || !above(check.poll.timeout)) problems.push(`check ${check.name} polls with an interval or a timeout that is not above zero`);
|
|
382
|
+
if (!(check.poll.jitter >= 0 && check.poll.jitter < 1)) problems.push(`check ${check.name} has a jitter of ${check.poll.jitter}, not a fraction below 1`);
|
|
383
|
+
problems.push(...marksProblems(check));
|
|
384
|
+
const timing = check.gates === null ? null : policies[check.gates];
|
|
385
|
+
if (timing?.type === "debounce" && isTime(check.poll.interval) && above(timing.interval) && valueIn(check.poll.interval, "s") !== valueIn(timing.interval, "s")) problems.push(`check ${check.name} polls every ${valueIn(check.poll.interval, "s")} s, but the ${check.gates} debounce counts polls every ${valueIn(timing.interval, "s")} s`);
|
|
386
|
+
}
|
|
387
|
+
for (const controller of controllers) {
|
|
388
|
+
for (const needed of controller.requires) if (!known.has(needed)) problems.push(`controller ${controller.name} requires ${needed}, which is not a dependency`);
|
|
389
|
+
for (const [route, operation] of Object.entries(controller.routes)) problems.push(...operationProblems(`controller ${controller.name}`, route, operation));
|
|
390
|
+
for (const declared of controller.patterns) problems.push(...routePatternProblems(`controller ${controller.name}`, declared));
|
|
391
|
+
}
|
|
392
|
+
for (const limiter of limiters) {
|
|
393
|
+
const { name: entry, ...spec } = limiter;
|
|
394
|
+
problems.push(...limiterProblems(entry, spec));
|
|
395
|
+
if (limiter.store?.kind === "shared" && typeof limiter.store.dependency === "string" && !known.has(limiter.store.dependency)) problems.push(`limiter ${entry} keeps its counts in ${limiter.store.dependency}, which is not a dependency`);
|
|
396
|
+
}
|
|
397
|
+
for (const dependency of dependencies) for (const [name, operation] of Object.entries(dependency.operations)) problems.push(...operationProblems(`dependency ${dependency.name}`, name, operation));
|
|
398
|
+
for (const phase of phases) if (!isTime(phase.cap)) problems.push(`phase ${phase.name}'s cap is not a time`);
|
|
399
|
+
problems.push(...shutdownProblems(floor, repeat, triggers, exitCodes, messages));
|
|
400
|
+
const ranked = phases.map((phase) => phase.name).filter((each) => stageRank(each) >= 0);
|
|
401
|
+
for (let at = 1; at < ranked.length; at += 1) if (stageRank(ranked[at]) < stageRank(ranked[at - 1])) problems.push(`the phase "${ranked[at]}" comes after "${ranked[at - 1]}", but the stages go ${STAGES.join(", ")}`);
|
|
402
|
+
if (problems.length > 0) throw new Error(`${name}: ${problems.join("; ")}`);
|
|
403
|
+
const controllersOut = controllers.map((entry) => ({
|
|
404
|
+
name: entry.name,
|
|
405
|
+
requires: [...entry.requires],
|
|
406
|
+
routes: { ...entry.routes },
|
|
407
|
+
...entry.patterns.length === 0 ? {} : { patterns: entry.patterns.map((each) => ({
|
|
408
|
+
pattern: each.pattern,
|
|
409
|
+
operations: { ...each.operations }
|
|
410
|
+
})) }
|
|
411
|
+
}));
|
|
412
|
+
return {
|
|
413
|
+
format: FORMAT,
|
|
414
|
+
name,
|
|
415
|
+
partial,
|
|
416
|
+
transports: transports.map((entry) => ({
|
|
417
|
+
...entry,
|
|
418
|
+
knobs: { ...entry.knobs }
|
|
419
|
+
})),
|
|
420
|
+
dependencies: dependencies.map((entry) => ({
|
|
421
|
+
...entry,
|
|
422
|
+
knobs: { ...entry.knobs },
|
|
423
|
+
operations: { ...entry.operations }
|
|
424
|
+
})),
|
|
425
|
+
controllers: controllersOut,
|
|
426
|
+
checks: checks.map(copyCheck),
|
|
427
|
+
...limiters.length === 0 ? {} : { limiters: limiters.map((entry) => ({
|
|
428
|
+
...entry,
|
|
429
|
+
policy: { ...entry.policy },
|
|
430
|
+
store: { ...entry.store },
|
|
431
|
+
evict: { maxKeys: { ...entry.evict.maxKeys } }
|
|
432
|
+
})) },
|
|
433
|
+
policies: {
|
|
434
|
+
readiness,
|
|
435
|
+
liveness,
|
|
436
|
+
startup
|
|
437
|
+
},
|
|
438
|
+
couplings: couplings.map((entry) => ({ ...entry })),
|
|
439
|
+
shutdown: {
|
|
440
|
+
phases: phases.map((entry) => ({ ...entry })),
|
|
441
|
+
cooperativeWindow: cooperative,
|
|
442
|
+
...floor === void 0 ? {} : { cooperativeFloor: floor },
|
|
443
|
+
onRepeatSignal: repeat,
|
|
444
|
+
...triggers.length === 0 ? {} : { triggers: [...triggers] },
|
|
445
|
+
...messages.length === 0 ? {} : { messages: messages.map((each) => ({ ...each })) },
|
|
446
|
+
...Object.keys(exitCodes).length === 0 ? {} : { exitCodes: { ...exitCodes } }
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
},
|
|
450
|
+
start(options = {}) {
|
|
451
|
+
if (runtime !== void 0) return runtime;
|
|
452
|
+
if (running !== void 0) return Promise.reject(/* @__PURE__ */ new Error(`${name} runs its lifecycle: use its health`));
|
|
453
|
+
let made;
|
|
454
|
+
try {
|
|
455
|
+
made = makeRuntime(options).runtime;
|
|
456
|
+
} catch (error) {
|
|
457
|
+
return Promise.reject(error);
|
|
458
|
+
}
|
|
459
|
+
started = true;
|
|
460
|
+
live = made;
|
|
461
|
+
runtime = made.warmUp().then(() => made);
|
|
462
|
+
return runtime;
|
|
463
|
+
},
|
|
464
|
+
run(options = {}) {
|
|
465
|
+
if (running !== void 0) return running;
|
|
466
|
+
if (runtime !== void 0) return Promise.reject(/* @__PURE__ */ new Error(`${name} started its health only: run() starts the whole lifecycle`));
|
|
467
|
+
try {
|
|
468
|
+
const description = builder.describe();
|
|
469
|
+
const components = {
|
|
470
|
+
transports: transportImpls,
|
|
471
|
+
dependencies: handles,
|
|
472
|
+
healthServer: probes,
|
|
473
|
+
phaseWork,
|
|
474
|
+
choices,
|
|
475
|
+
stopPollers: () => {}
|
|
476
|
+
};
|
|
477
|
+
const problems = [...lifecycleProblems(description, components), ...uncaughtProblems(options.uncaught)];
|
|
478
|
+
if (problems.length > 0) throw new Error(`${name}: ${problems.join("; ")}`);
|
|
479
|
+
const made = makeRuntime(options);
|
|
480
|
+
started = true;
|
|
481
|
+
live = made.runtime;
|
|
482
|
+
const ran = lifecycle(made.description, made.runtime, {
|
|
483
|
+
...components,
|
|
484
|
+
stopPollers: made.stopPollers
|
|
485
|
+
}, made.options, (given) => {
|
|
486
|
+
life = given;
|
|
487
|
+
});
|
|
488
|
+
running = ran.started.then(() => ran);
|
|
489
|
+
} catch (error) {
|
|
490
|
+
return Promise.reject(error);
|
|
491
|
+
}
|
|
492
|
+
return running;
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
return builder;
|
|
496
|
+
};
|
|
497
|
+
export { service };
|
|
498
|
+
|
|
499
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import type { Extent, Quantity } from \"@mark1russell7/quantity\";\nimport { convertible, valueIn } from \"@mark1russell7/quantity\";\nimport type {\n Check,\n Controller,\n CooperativeFloor,\n Coupling,\n Dependency,\n ExitCodes,\n Gate,\n MessageTrigger,\n Phase,\n RepeatSignal,\n ServiceDescription,\n Transport,\n} from \"./description.ts\";\nimport { FORMAT } from \"./description.ts\";\nimport { realClock, unrefClock } from \"./clock.ts\";\nimport type { Health, Runtime, StartOptions } from \"./health.ts\";\nimport type { Limiter, LimiterSpec } from \"./limiter/policy.ts\";\nimport { limiterProblems } from \"./limiter/policy.ts\";\nimport { healthRuntime } from \"./health.ts\";\nimport { logEvents } from \"./logger.ts\";\nimport type {\n Components,\n DependencyHandle,\n HealthServer,\n Lifecycle,\n PhaseWork,\n RunOptions,\n TransportImpl,\n} from \"./lifecycle.ts\";\nimport { STAGES, lifecycle, lifecycleProblems, stageRank, uncaughtProblems } from \"./lifecycle.ts\";\nimport type { Operation } from \"./operation.ts\";\nimport { operationProblems } from \"./operation.ts\";\nimport type { CheckFn } from \"./poller.ts\";\nimport type { ExitTrigger, ProcessTrigger } from \"./process.ts\";\nimport { EXIT_SIGNALS, PROCESS_TRIGGERS, isExitCode, isExitSignal, isMessageShape } from \"./process.ts\";\nimport type { Profile } from \"./profiles.ts\";\nimport type { OperationOf, RoutePattern } from \"./routes.ts\";\nimport { routePatternProblems } from \"./routes.ts\";\nimport type { Timing } from \"./timing.ts\";\nimport type { Watchdog, WatchdogSpec } from \"./watchdog.ts\";\nimport { watchdog } from \"./watchdog.ts\";\n\n/**\n * The caller composes a service with plain method uses before it starts. The builder is imperative, and\n * it holds static knowledge. The service does not use an `init` function that gives registrations.\n *\n * const svc = service(\"app\");\n * svc.dependency(\"weather\", {\n * system: null,\n * knobs: { request_timeout },\n * operations: { \"GET /v1/forecast\": { idempotent: true } },\n * });\n * svc.controller(\"forecast\").requires(\"weather\").route(\"GET /api/forecast\", { idempotent: true });\n * svc.check({ name: \"weather.round-trip\", dependency: \"weather\", … }, roundTrip);\n * svc.describe(); // the whole graph as data, with nothing started\n * const health = await svc.start();\n *\n * The graph has one source, thus its parts cannot disagree. A dependency or a check can join\n * after the start. It starts tripped, and the export is partial. The runtime has no defaults of\n * its own. Thus `describe()` refuses a service that does not declare a policy, its startup budget\n * or its shutdown, and it tells which. The shutdown includes what a repeat signal does.\n *\n * `start()` starts only the health runtime. `run()` starts the whole lifecycle: the startup in its\n * sequence, the exit signals, the capped phases of the shutdown, and the exit of the process.\n */\nexport interface ControllerBuilder {\n /** This method declares the dependencies that its routes need. The controller is ready only while they are ready. */\n requires(...dependencies: string[]): ControllerBuilder;\n /** This method declares a route that the controller serves, and if its callers can send it again. */\n route(route: string, operation: Operation): ControllerBuilder;\n /**\n * This method declares a route pattern, the operations that its requests can be, and the function\n * that picks the operation of each request. A pattern with one operation needs no function.\n */\n pattern(pattern: string, operations: Readonly<Record<string, Operation>>, operationOf?: OperationOf): ControllerBuilder;\n}\n\n/** A service builder composes a service, gives it as data, and starts it. */\nexport interface ServiceBuilder {\n readonly name: string;\n /** This method declares a dependency, and the handle that connects to it and closes it, if it has one. */\n dependency(name: string, spec: Omit<Dependency, \"name\">, handle?: DependencyHandle): ServiceBuilder;\n /** This method declares a server, and its implementation. `run()` needs the implementation. */\n server(name: string, knobs: Readonly<Record<string, Extent>>, impl?: TransportImpl): ServiceBuilder;\n consumer(name: string, knobs: Readonly<Record<string, Extent>>, impl?: TransportImpl): ServiceBuilder;\n worker(name: string, knobs: Readonly<Record<string, Extent>>, impl?: TransportImpl): ServiceBuilder;\n /** This method gives the server of the probes. It starts first and closes last. */\n healthServer(server: HealthServer): ServiceBuilder;\n /** This method adds work to a declared phase of the shutdown: the owner of the work registers it. */\n onPhase(phase: string, work: PhaseWork): ServiceBuilder;\n /** This method declares a watchdog of the event loop, as a check on the state of the process. */\n watchdog(spec: WatchdogSpec): ServiceBuilder;\n controller(name: string): ControllerBuilder;\n /** This method declares a check, and the function that measures its step. `start()` needs the function. */\n check(check: Check, run?: CheckFn): ServiceBuilder;\n /**\n * This method declares a keyed limiter as data: its key, its policy, its store and the bound on its\n * keys. `describe()` shows it and refuses a part that is absent, because a limiter has no defaults.\n * `keyedLimiter(name, spec, store)` makes its runtime from the same spec.\n */\n limiter(name: string, spec: LimiterSpec): ServiceBuilder;\n readiness(timing: Timing): ServiceBuilder;\n liveness(timing: Timing): ServiceBuilder;\n startup(budget: Quantity): ServiceBuilder;\n couple(coupling: Coupling): ServiceBuilder;\n phase(name: string, cap: Quantity): ServiceBuilder;\n cooperativeWindow(window: Extent): ServiceBuilder;\n /** This method declares the earliest time of the cooperative abort: half the cap of the drain, or no floor. */\n cooperativeFloor(floor: CooperativeFloor): ServiceBuilder;\n /** This method declares what an exit signal does while the shutdown runs: nothing, or an exit at once. */\n onRepeatSignal(policy: RepeatSignal): ServiceBuilder;\n /** This method declares process triggers that start the shutdown, in addition to the exit signals. */\n trigger(...triggers: ProcessTrigger[]): ServiceBuilder;\n /**\n * This method declares a message of the IPC channel that starts the shutdown, as data. With `as`,\n * the message is that exit signal: `svc.trigger(\"ipc-message\", { match: \"shutdown\", as: \"SIGTERM\" })`.\n */\n trigger(trigger: \"ipc-message\", message: MessageTrigger): ServiceBuilder;\n /** This method declares the exit code of a clean shutdown that a trigger starts, in place of 0. */\n exitCode(trigger: ExitTrigger, code: number): ServiceBuilder;\n /** This method declares each field of a profile, as the method of that field does. */\n profile(profile: Profile): ServiceBuilder;\n /** This method gives the service as data, and it starts nothing. */\n describe(): ServiceDescription;\n /**\n * This method closes the composition, starts the health runtime, and gives it after one warm-up\n * sweep of each check. A part that joins after it starts tripped, and it makes the export\n * partial. A second use gives the same runtime.\n */\n start(options?: StartOptions): Promise<Health>;\n /**\n * This method starts the whole lifecycle and gives it when its startup ends: the service operates,\n * or its startup failed and it shuts down. It refuses a declaration that it cannot start: a transport\n * without its implementation, or a stage with work and no declared phase.\n */\n run(options?: RunOptions): Promise<Lifecycle>;\n /**\n * This value is the health runtime from the time that `start()` begins, or null before. Thus the\n * probes can answer during the warm-up sweep: the startup probe fails until the sweep ends.\n */\n readonly health: Health | null;\n /**\n * This value is the lifecycle from the time that `run()` begins, or null before. Its request\n * tracking operates while the transports start, before `run()` gives it.\n */\n readonly lifecycle: Lifecycle | null;\n}\n\nconst isTime = (amount: Extent): boolean => convertible(amount.unit, \"s\");\nconst above = (amount: Extent): boolean =>\n amount.value === \"infinite\" || (isTime(amount) && valueIn(amount as Quantity, \"s\") > 0);\nconst whole = (count: number): boolean => Number.isInteger(count) && count >= 1;\n/** This function copies a check, with its poll and the loops that mark it. */\nconst copyCheck = (check: Check): Check => ({\n ...check,\n poll: { ...check.poll },\n ...(check.marks === undefined ? {} : { marks: { loops: [...check.marks.loops], stall: { ...check.marks.stall } } }),\n});\n/** This function gives the problems of the loops that mark a check. `lint()` compares the stall time with the loops. */\nconst marksProblems = (check: Check): string[] => {\n const marks = check.marks;\n if (marks === undefined) return [];\n const problems: string[] = [];\n if (check.step !== \"progress\")\n problems.push(`check ${check.name} names the loops that mark it, but its step is ${check.step}, not progress`);\n if (marks.loops.length === 0) problems.push(`check ${check.name} names no loop that marks it`);\n // a description from JSON can give a stall time without a bound, which is not a stall time\n if (typeof marks.stall.value !== \"number\" || !above(marks.stall))\n problems.push(`check ${check.name} has a stall time that is not a time above zero`);\n return problems;\n};\n\n/** This function gives the problems of a timing: a zero interval or count fails decoding. */\nconst timingProblems = (policy: Gate, timing: Timing): string[] => {\n if (timing.type === \"debounce\") {\n const problems: string[] = [];\n if (!above(timing.interval)) problems.push(`the ${policy} debounce polls at an interval that is not above zero`);\n if (!whole(timing.failAfter)) problems.push(`the ${policy} debounce fails after ${timing.failAfter} polls, not a whole number above zero`);\n if (!whole(timing.recoverAfter)) problems.push(`the ${policy} debounce recovers after ${timing.recoverAfter} polls, not a whole number above zero`);\n return problems;\n }\n const negative = (amount: Quantity | undefined): boolean =>\n amount !== undefined && (!isTime(amount) || valueIn(amount, \"s\") < 0);\n return negative(timing.failAfter) || negative(timing.recoverAfter)\n ? [`the ${policy} window is not a time of zero or more`]\n : [];\n};\n\n/** This function gives the problems of the rules of the shutdown: an unknown name, or an exit code that a process cannot give. */\nconst shutdownProblems = (\n floor: CooperativeFloor | undefined,\n repeat: RepeatSignal | undefined,\n triggers: readonly ProcessTrigger[],\n exitCodes: ExitCodes,\n messages: readonly MessageTrigger[],\n): string[] => {\n const problems: string[] = [];\n if (floor !== undefined && floor !== \"half\" && floor !== \"none\")\n problems.push(`the cooperative floor ${String(floor)} is not \"half\" or \"none\"`);\n if (repeat !== undefined && repeat !== \"ignore\" && repeat !== \"exit\")\n problems.push(`the policy of a repeat signal ${String(repeat)} is not \"ignore\" or \"exit\"`);\n for (const trigger of triggers)\n if (!PROCESS_TRIGGERS.includes(trigger))\n problems.push(`the trigger ${String(trigger)} is not a process trigger (${PROCESS_TRIGGERS.join(\", \")})`);\n if (triggers.includes(\"ipc-message\") && messages.length === 0)\n problems.push(`the trigger ipc-message has no message to match: declare it with svc.trigger(\"ipc-message\", { match })`);\n for (const message of messages) {\n if (!isMessageShape(message.match))\n problems.push(`the match of a message trigger is not a value of JSON: ${String(message.match)}`);\n if (message.as !== undefined && !isExitSignal(message.as))\n problems.push(`a message trigger stands for ${String(message.as)}, not an exit signal (${EXIT_SIGNALS.join(\", \")})`);\n }\n for (const [trigger, code] of Object.entries(exitCodes)) {\n const known = (EXIT_SIGNALS as readonly string[]).includes(trigger) || triggers.includes(trigger as ProcessTrigger);\n if (!known) problems.push(`the exit code of ${trigger} names no exit signal and no declared trigger`);\n if (code === undefined || !isExitCode(code))\n problems.push(`the exit code of ${trigger} is ${String(code)}, not a whole number from 0 to 255`);\n }\n return problems;\n};\n\n/**\n * This function gives the options with one recorder for the recorder and the logger of the options.\n * Without a logger, it gives the same options.\n */\nconst withLogger = <O extends StartOptions>(options: O, description: ServiceDescription): O => {\n if (options.logger === undefined) return options;\n const given = options.record;\n const log = logEvents(options.logger, description);\n return {\n ...options,\n record: (event) => {\n given?.(event);\n log(event);\n },\n };\n};\n\n/** This function starts the composition of a service. */\nexport const service = (name: string): ServiceBuilder => {\n if (name.trim().length === 0) throw new Error(\"a service needs a name\");\n const transports: Transport[] = [];\n const dependencies: Dependency[] = [];\n const controllers: Array<{\n name: string;\n requires: string[];\n routes: Record<string, Operation>;\n patterns: RoutePattern[];\n }> = [];\n // the function of each route pattern, by controller and by pattern\n const choices = new Map<string, Map<string, OperationOf>>();\n const checks: Check[] = [];\n const runs = new Map<string, CheckFn>();\n const limiters: Limiter[] = [];\n const couplings: Coupling[] = [];\n const phases: Phase[] = [];\n let readiness: Timing | undefined;\n let liveness: Timing | undefined;\n let startup: Quantity | undefined;\n let cooperative: Extent | undefined;\n let floor: CooperativeFloor | undefined;\n let repeat: RepeatSignal | undefined;\n const triggers: ProcessTrigger[] = [];\n const messages: MessageTrigger[] = [];\n const exitCodes: Partial<Record<ExitTrigger, number>> = {};\n let started = false;\n let partial = false;\n let runtime: Promise<Health> | undefined;\n let live: Runtime | undefined;\n let running: Promise<Lifecycle> | undefined;\n let life: Lifecycle | undefined;\n const transportImpls = new Map<string, TransportImpl>();\n const handles = new Map<string, DependencyHandle>();\n const phaseWork = new Map<string, PhaseWork[]>();\n const watchdogs: WatchdogSpec[] = [];\n let probes: HealthServer | null = null;\n\n /** This function stops a change to the shape of the service after the start. */\n const composing = (what: string): void => {\n if (started) throw new Error(`${name} has started: ${what} is declared before svc.start()`);\n };\n const once = (list: ReadonlyArray<{ name: string }>, entry: string, what: string): void => {\n if (list.some((held) => held.name === entry))\n throw new Error(`${name} already has a ${what} named ${entry}`);\n };\n const transport =\n (kind: Transport[\"kind\"]) =>\n (entry: string, knobs: Readonly<Record<string, Extent>>, impl?: TransportImpl) => {\n composing(`a ${kind}`);\n once(transports, entry, \"transport\");\n transports.push({ name: entry, kind, knobs: { ...knobs } });\n if (impl !== undefined) transportImpls.set(entry, impl);\n return builder;\n };\n\n /** This function makes the runtime of the declaration: its checks, and a watchdog for each spec. */\n const makeRuntime = <O extends StartOptions>(\n given: O,\n ): { runtime: Runtime; description: ServiceDescription; stopPollers: () => void; options: O } => {\n const description = builder.describe();\n // the logger is one sink of the stream of the recorder: each machine writes to both\n const options = withLogger(given, description);\n const clock = options.clock ?? realClock;\n const dogs: Watchdog[] = [];\n const all = new Map(runs);\n for (const spec of watchdogs) {\n // the tick only watches the event loop: the work of the service keeps the process alive (SYS-126)\n const dog = watchdog(unrefClock(clock), spec, (from, to, on) =>\n options.record?.({ at: clock.now(), machine: \"watchdog\", instance: spec.name, from, to, on }),\n );\n dogs.push(dog);\n all.set(spec.name, () => dog.check());\n }\n const stopPollers = (): void => {\n for (const dog of dogs) dog.stop();\n };\n let made: Runtime;\n try {\n made = healthRuntime(description, all, options);\n } catch (error) {\n stopPollers();\n throw error;\n }\n // the stop of the health runtime also stops the watchdogs\n const runtime: Runtime = {\n ...made,\n stop: () => {\n made.stop();\n stopPollers();\n },\n };\n return { runtime, description, stopPollers, options };\n };\n\n const builder: ServiceBuilder = {\n name,\n get health() {\n return live ?? null;\n },\n get lifecycle() {\n return life ?? null;\n },\n dependency(entry, spec, handle) {\n once(dependencies, entry, \"dependency\");\n // a dependency that joins after the start has no connection that the lifecycle opens\n if (handle !== undefined && !started) handles.set(entry, handle);\n dependencies.push({\n name: entry,\n ...spec,\n knobs: { ...spec.knobs },\n operations: { ...spec.operations },\n });\n if (started) {\n partial = true;\n live?.addDependency(entry);\n }\n return builder;\n },\n server: transport(\"server\"),\n consumer: transport(\"consumer\"),\n worker: transport(\"worker\"),\n controller(entry) {\n composing(\"a controller\");\n once(controllers, entry, \"controller\");\n const held = {\n name: entry,\n requires: [] as string[],\n routes: {} as Record<string, Operation>,\n patterns: [] as RoutePattern[],\n };\n controllers.push(held);\n const handle: ControllerBuilder = {\n requires(...needed) {\n composing(`what ${entry} requires`);\n held.requires.push(...needed);\n return handle;\n },\n route(served, operation) {\n composing(`${entry}'s routes`);\n if (held.routes[served] !== undefined)\n throw new Error(`${entry} already serves ${served}`);\n held.routes[served] = { ...operation };\n return handle;\n },\n pattern(pattern, operations, operationOf) {\n composing(`${entry}'s route patterns`);\n if (held.patterns.some((each) => each.pattern === pattern))\n throw new Error(`${entry} already has the route pattern ${pattern}`);\n // the function is not data, thus the builder checks it here, and describe() checks the rest\n if (operationOf === undefined && Object.keys(operations).length > 1)\n throw new Error(`${entry}'s pattern ${pattern} has ${Object.keys(operations).length} operations, thus it needs the function that picks one`);\n held.patterns.push({\n pattern,\n operations: Object.fromEntries(Object.entries(operations).map(([name, operation]) => [name, { ...operation }])),\n });\n if (operationOf !== undefined) {\n const mine = choices.get(entry) ?? new Map<string, OperationOf>();\n mine.set(pattern, operationOf);\n choices.set(entry, mine);\n }\n return handle;\n },\n };\n return handle;\n },\n check(check, run) {\n once(checks, check.name, \"check\");\n if (started && run === undefined)\n throw new Error(`check ${check.name} joins after the start, thus it needs its function`);\n checks.push(copyCheck(check));\n if (run !== undefined) runs.set(check.name, run);\n if (started) {\n partial = true;\n live?.addCheck(copyCheck(check), run!);\n }\n return builder;\n },\n limiter(entry, spec) {\n composing(`the limiter ${entry}`);\n once(limiters, entry, \"limiter\");\n // the spec is data: the builder keeps a copy, and describe() checks each part\n const given = (spec ?? {}) as Partial<LimiterSpec>;\n limiters.push({\n name: entry,\n ...given,\n ...(given.policy === undefined ? {} : { policy: { ...given.policy } }),\n ...(given.store === undefined ? {} : { store: { ...given.store } }),\n ...(given.evict === undefined ? {} : { evict: { ...given.evict } }),\n } as Limiter);\n return builder;\n },\n healthServer(server) {\n composing(\"the health server\");\n if (probes !== null) throw new Error(`${name} already has a health server`);\n probes = server;\n return builder;\n },\n onPhase(phase, work) {\n composing(`work for the phase ${phase}`);\n phaseWork.set(phase, [...(phaseWork.get(phase) ?? []), work]);\n return builder;\n },\n watchdog(spec) {\n composing(`the watchdog ${spec.name}`);\n once(checks, spec.name, \"check\");\n // the watchdog is a check on the state of the process itself, on its own connection\n checks.push({\n name: spec.name,\n dependency: null,\n step: \"local-state\",\n ownConnection: true,\n gates: spec.gates,\n poll: { ...spec.poll },\n });\n watchdogs.push(spec);\n return builder;\n },\n readiness(timing) {\n composing(\"readiness\");\n readiness = timing;\n return builder;\n },\n liveness(timing) {\n composing(\"liveness\");\n liveness = timing;\n return builder;\n },\n startup(budget) {\n composing(\"the startup budget\");\n startup = budget;\n return builder;\n },\n couple(coupling) {\n composing(\"a coupling\");\n couplings.push({ ...coupling });\n return builder;\n },\n phase(entry, cap) {\n composing(\"a shutdown phase\");\n once(phases, entry, \"shutdown phase\");\n phases.push({ name: entry, cap });\n return builder;\n },\n cooperativeWindow(window) {\n composing(\"the cooperative window\");\n cooperative = window;\n return builder;\n },\n cooperativeFloor(given) {\n composing(\"the cooperative floor\");\n floor = given;\n return builder;\n },\n onRepeatSignal(policy) {\n composing(\"the policy of a repeat signal\");\n repeat = policy;\n return builder;\n },\n trigger(...given: ReadonlyArray<ProcessTrigger | MessageTrigger>) {\n composing(\"a trigger\");\n const [first, message] = given;\n if (first === \"ipc-message\" && typeof message === \"object\" && message !== null) {\n if (!triggers.includes(\"ipc-message\")) triggers.push(\"ipc-message\");\n messages.push({ ...message });\n return builder;\n }\n for (const each of given) if (typeof each === \"string\" && !triggers.includes(each)) triggers.push(each);\n return builder;\n },\n exitCode(trigger, code) {\n composing(`the exit code of ${trigger}`);\n exitCodes[trigger] = code;\n return builder;\n },\n profile(given) {\n composing(\"a profile\");\n if (given.readiness !== undefined) builder.readiness(given.readiness);\n if (given.liveness !== undefined) builder.liveness(given.liveness);\n if (given.startup !== undefined) builder.startup(given.startup);\n for (const coupling of given.couplings ?? []) builder.couple(coupling);\n for (const each of given.phases ?? []) builder.phase(each.name, each.cap);\n if (given.cooperativeWindow !== undefined) builder.cooperativeWindow(given.cooperativeWindow);\n if (given.cooperativeFloor !== undefined) builder.cooperativeFloor(given.cooperativeFloor);\n if (given.onRepeatSignal !== undefined) builder.onRepeatSignal(given.onRepeatSignal);\n if (given.triggers !== undefined) builder.trigger(...given.triggers);\n for (const message of given.messages ?? []) builder.trigger(\"ipc-message\", message);\n for (const [trigger, code] of Object.entries(given.exitCodes ?? {}))\n if (code !== undefined) builder.exitCode(trigger as ExitTrigger, code);\n return builder;\n },\n describe() {\n const missing: string[] = [];\n if (readiness === undefined) missing.push(\"readiness (svc.readiness)\");\n if (liveness === undefined) missing.push(\"liveness (svc.liveness)\");\n if (startup === undefined) missing.push(\"a startup budget (svc.startup)\");\n if (phases.length === 0) missing.push(\"its shutdown phases (svc.phase)\");\n if (cooperative === undefined)\n missing.push(\"a cooperative window, or no bound (svc.cooperativeWindow)\");\n if (repeat === undefined)\n missing.push(`what a repeat signal does, \"ignore\" or \"exit\" (svc.onRepeatSignal)`);\n if (missing.length > 0)\n throw new Error(\n `${name} does not declare ${missing.join(\"; \")}: the runtime has no defaults`,\n );\n const known = new Set(dependencies.map((entry) => entry.name));\n const problems: string[] = [];\n const policies: Record<Gate, Timing> = { readiness: readiness!, liveness: liveness! };\n for (const gate of [\"readiness\", \"liveness\"] as const)\n problems.push(...timingProblems(gate, policies[gate]));\n for (const check of checks) {\n if (check.dependency !== null && !known.has(check.dependency)) {\n problems.push(\n `check ${check.name} exercises ${check.dependency}, which is not a dependency`,\n );\n }\n if (!isTime(check.poll.interval) || !isTime(check.poll.timeout)) {\n problems.push(`check ${check.name} polls in a unit that is not a time`);\n } else if (!above(check.poll.interval) || !above(check.poll.timeout)) {\n problems.push(`check ${check.name} polls with an interval or a timeout that is not above zero`);\n }\n if (!(check.poll.jitter >= 0 && check.poll.jitter < 1))\n problems.push(`check ${check.name} has a jitter of ${check.poll.jitter}, not a fraction below 1`);\n problems.push(...marksProblems(check));\n // a debounce counts the polls of each check that it gates, thus they poll at its interval\n const timing = check.gates === null ? null : policies[check.gates];\n if (\n timing?.type === \"debounce\" &&\n isTime(check.poll.interval) &&\n above(timing.interval) &&\n valueIn(check.poll.interval, \"s\") !== valueIn(timing.interval, \"s\")\n )\n problems.push(\n `check ${check.name} polls every ${valueIn(check.poll.interval, \"s\")} s, but the ${check.gates} debounce counts polls every ${valueIn(timing.interval, \"s\")} s`,\n );\n }\n for (const controller of controllers) {\n for (const needed of controller.requires) {\n if (!known.has(needed))\n problems.push(\n `controller ${controller.name} requires ${needed}, which is not a dependency`,\n );\n }\n for (const [route, operation] of Object.entries(controller.routes))\n problems.push(...operationProblems(`controller ${controller.name}`, route, operation));\n for (const declared of controller.patterns)\n problems.push(...routePatternProblems(`controller ${controller.name}`, declared));\n }\n for (const limiter of limiters) {\n const { name: entry, ...spec } = limiter;\n problems.push(...limiterProblems(entry, spec));\n if (limiter.store?.kind === \"shared\" && typeof limiter.store.dependency === \"string\" && !known.has(limiter.store.dependency))\n problems.push(`limiter ${entry} keeps its counts in ${limiter.store.dependency}, which is not a dependency`);\n }\n for (const dependency of dependencies)\n for (const [name, operation] of Object.entries(dependency.operations))\n problems.push(...operationProblems(`dependency ${dependency.name}`, name, operation));\n for (const phase of phases)\n if (!isTime(phase.cap)) problems.push(`phase ${phase.name}'s cap is not a time`);\n problems.push(...shutdownProblems(floor, repeat, triggers, exitCodes, messages));\n // the stages of the shutdown keep their sequence: readiness fails first, the health server closes last\n const ranked = phases.map((phase) => phase.name).filter((each) => stageRank(each) >= 0);\n for (let at = 1; at < ranked.length; at += 1)\n if (stageRank(ranked[at]!) < stageRank(ranked[at - 1]!))\n problems.push(\n `the phase \"${ranked[at]!}\" comes after \"${ranked[at - 1]!}\", but the stages go ${STAGES.join(\", \")}`,\n );\n if (problems.length > 0) throw new Error(`${name}: ${problems.join(\"; \")}`);\n const controllersOut: Controller[] = controllers.map((entry) => ({\n name: entry.name,\n requires: [...entry.requires],\n routes: { ...entry.routes },\n ...(entry.patterns.length === 0\n ? {}\n : { patterns: entry.patterns.map((each) => ({ pattern: each.pattern, operations: { ...each.operations } })) }),\n }));\n return {\n format: FORMAT,\n name,\n partial,\n transports: transports.map((entry) => ({ ...entry, knobs: { ...entry.knobs } })),\n dependencies: dependencies.map((entry) => ({\n ...entry,\n knobs: { ...entry.knobs },\n operations: { ...entry.operations },\n })),\n controllers: controllersOut,\n checks: checks.map(copyCheck),\n ...(limiters.length === 0\n ? {}\n : {\n limiters: limiters.map((entry) => ({\n ...entry,\n policy: { ...entry.policy },\n store: { ...entry.store },\n evict: { maxKeys: { ...entry.evict.maxKeys } },\n })),\n }),\n policies: { readiness: readiness!, liveness: liveness!, startup: startup! },\n couplings: couplings.map((entry) => ({ ...entry })),\n shutdown: {\n phases: phases.map((entry) => ({ ...entry })),\n cooperativeWindow: cooperative!,\n ...(floor === undefined ? {} : { cooperativeFloor: floor }),\n onRepeatSignal: repeat!,\n ...(triggers.length === 0 ? {} : { triggers: [...triggers] }),\n ...(messages.length === 0 ? {} : { messages: messages.map((each) => ({ ...each })) }),\n ...(Object.keys(exitCodes).length === 0 ? {} : { exitCodes: { ...exitCodes } }),\n },\n };\n },\n start(options = {}) {\n // the start needs the whole graph: describe() is the check, and the runtime reads it\n if (runtime !== undefined) return runtime;\n if (running !== undefined) return Promise.reject(new Error(`${name} runs its lifecycle: use its health`));\n let made: Runtime;\n try {\n made = makeRuntime(options).runtime;\n } catch (error) {\n return Promise.reject(error);\n }\n started = true;\n live = made;\n runtime = made.warmUp().then(() => made);\n return runtime;\n },\n run(options = {}) {\n if (running !== undefined) return running;\n if (runtime !== undefined) return Promise.reject(new Error(`${name} started its health only: run() starts the whole lifecycle`));\n try {\n const description = builder.describe();\n const components: Components = {\n transports: transportImpls,\n dependencies: handles,\n healthServer: probes,\n phaseWork,\n choices,\n stopPollers: () => {},\n };\n const problems = [...lifecycleProblems(description, components), ...uncaughtProblems(options.uncaught)];\n if (problems.length > 0) throw new Error(`${name}: ${problems.join(\"; \")}`);\n const made = makeRuntime(options);\n started = true;\n live = made.runtime;\n // the builder holds the lifecycle before the first transport starts\n const ran = lifecycle(made.description, made.runtime, { ...components, stopPollers: made.stopPollers }, made.options, (given) => {\n life = given;\n });\n running = ran.started.then(() => ran);\n } catch (error) {\n return Promise.reject(error);\n }\n return running;\n },\n };\n return builder;\n};\n"],"mappings":";;;;;;;;;;;;AAuJA,MAAM,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ACA,MAAM,WAAW,CAAC,GAAG,kBAAkB,aAAa,UAAU,GAAG,GAAG,iBAAiB,QAAQ,QAAQ,CAAC;IACtG,IAAI,SAAS,SAAS,GAAG,MAAM,IAAI,MAAM,GAAG,KAAK,IAAI,SAAS,KAAK,IAAI,GAAG;IAC1E,MAAM,OAAO,YAAY,OAAO;IAChC,UAAU;IACV,OAAO,KAAK;IAEZ,MAAM,MAAM,UAAU,KAAK,aAAa,KAAK,SAAS;KAAE,GAAG;KAAY,aAAa,KAAK;IAAY,GAAG,KAAK,UAAU,UAAU;KAC/H,OAAO;IACT,CAAC;IACD,UAAU,IAAI,QAAQ,WAAW,GAAG;GACtC,SAAS,OAAO;IACd,OAAO,QAAQ,OAAO,KAAK;GAC7B;GACA,OAAO;EACT;CACF;CACA,OAAO;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** These are the headers of an incoming call, as `node:http` gives them: the names are in lower case. */
|
|
2
|
-
type IncomingHeaders = Readonly<Record<string, string | readonly string[] | undefined>>;
|
|
2
|
+
export type IncomingHeaders = Readonly<Record<string, string | readonly string[] | undefined>>;
|
|
3
3
|
/** A call context reads the context of an incoming call, and writes the context of an outgoing call. */
|
|
4
|
-
interface CallContext {
|
|
4
|
+
export interface CallContext {
|
|
5
5
|
/**
|
|
6
6
|
* This function runs `fn` in the context of the headers of an incoming call. The context has the
|
|
7
7
|
* trace of `traceparent`. It has the baggage only when `trusted` is true. A call that is not trusted
|
|
@@ -10,5 +10,4 @@ interface CallContext {
|
|
|
10
10
|
run<T>(headers: IncomingHeaders, trusted: boolean, fn: () => T): T;
|
|
11
11
|
/** This function gives the headers of the active context for an outgoing call, for example `traceparent`. */
|
|
12
12
|
headers(): Record<string, string>;
|
|
13
|
-
}
|
|
14
|
-
export { IncomingHeaders as n, CallContext as t };
|
|
13
|
+
}
|
package/build/channel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Clock } from "./clock.js";
|
|
2
2
|
/** This function gets a failure of the work that a function of this entry started. */
|
|
3
3
|
export type ErrorHandler = (error: unknown) => void;
|
|
4
4
|
/** These options are for a function that starts work and gives an output channel. */
|