@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,13 +1,12 @@
|
|
|
1
|
-
import "./core
|
|
1
|
+
import "./core.js";
|
|
2
2
|
/**
|
|
3
3
|
* A judge reads the bytes that the server sent so far. It gives null for a good answer, an error for
|
|
4
4
|
* a bad answer, or "more" when it must wait for more bytes.
|
|
5
5
|
*/
|
|
6
|
-
type Judge = (received: Buffer) => Error | null | "more";
|
|
6
|
+
export type Judge = (received: Buffer) => Error | null | "more";
|
|
7
7
|
/**
|
|
8
8
|
* This function makes a judge of the status line of an HTTP/1.1 answer. The judge waits for the end
|
|
9
9
|
* of the line, in the first 8 KiB. Then `accept` reads the status code, and gives null for a good status or an error.
|
|
10
10
|
* The HTTP client accepts each status. The WebSocket client accepts only 101.
|
|
11
11
|
*/
|
|
12
|
-
declare const statusLineJudge: (accept: (status: number, line: string) => Error | null) => Judge;
|
|
13
|
-
export { statusLineJudge as n, Judge as t };
|
|
12
|
+
export declare const statusLineJudge: (accept: (status: number, line: string) => Error | null) => Judge;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { connect } from "node:net";
|
|
2
|
+
// src/client/dial.ts
|
|
3
|
+
/**
|
|
4
|
+
* This function makes a dial function. The dial opens a TCP connection, sends `hello`, and reads the
|
|
5
|
+
* answer until `judge` decides. An abort, an error of the socket, and a close before the decision fail the dial.
|
|
6
|
+
* The dial destroys its socket at its end.
|
|
7
|
+
*/
|
|
8
|
+
const helloDial = (hello, judge) => (host, port, signal) => new Promise((resolve, reject) => {
|
|
9
|
+
if (signal.aborted) {
|
|
10
|
+
reject(/* @__PURE__ */ new Error("the dial was aborted"));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const socket = connect({
|
|
14
|
+
host,
|
|
15
|
+
port
|
|
16
|
+
});
|
|
17
|
+
let received = Buffer.alloc(0);
|
|
18
|
+
const end = (error) => {
|
|
19
|
+
signal.removeEventListener("abort", onAbort);
|
|
20
|
+
socket.destroy();
|
|
21
|
+
if (error === void 0) resolve();
|
|
22
|
+
else reject(error);
|
|
23
|
+
};
|
|
24
|
+
const onAbort = () => end(/* @__PURE__ */ new Error("the dial was aborted"));
|
|
25
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
26
|
+
socket.once("connect", () => socket.write(hello));
|
|
27
|
+
socket.on("data", (chunk) => {
|
|
28
|
+
received = Buffer.concat([received, chunk]);
|
|
29
|
+
const verdict = judge(received);
|
|
30
|
+
if (verdict === "more") return;
|
|
31
|
+
end(verdict ?? void 0);
|
|
32
|
+
});
|
|
33
|
+
socket.once("error", (error) => end(error));
|
|
34
|
+
socket.once("close", () => end(/* @__PURE__ */ new Error("the server closed the dial")));
|
|
35
|
+
});
|
|
36
|
+
/** This function gives the authority of a host and a port for a Host header. An IPv6 address goes in brackets. */
|
|
37
|
+
const authority = (host, port) => `${host.includes(":") ? `[${host}]` : host}:${port}`;
|
|
38
|
+
/**
|
|
39
|
+
* This function makes a judge of the status line of an HTTP/1.1 answer. The judge waits for the end
|
|
40
|
+
* of the line, in the first 8 KiB. Then `accept` reads the status code, and gives null for a good status or an error.
|
|
41
|
+
* The HTTP client accepts each status. The WebSocket client accepts only 101.
|
|
42
|
+
*/
|
|
43
|
+
const statusLineJudge = (accept) => (received) => {
|
|
44
|
+
const end = received.indexOf("\r\n");
|
|
45
|
+
if (end < 0) return received.length > 8192 ? /* @__PURE__ */ new Error("the answer has no status line in its first 8 KiB") : "more";
|
|
46
|
+
const line = received.toString("latin1", 0, end);
|
|
47
|
+
const status = /^HTTP\/1\.[01] (\d{3})/.exec(line);
|
|
48
|
+
return status === null ? /* @__PURE__ */ new Error(`the answer ${JSON.stringify(line)} is not an HTTP/1.1 status line`) : accept(Number(status[1]), line);
|
|
49
|
+
};
|
|
50
|
+
export { authority, helloDial, statusLineJudge };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=dial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dial.js","names":["dialTcp"],"sources":["../../src/client/dial.ts"],"sourcesContent":["// The dial of a client: a new TCP connection that sends the first bytes of its protocol and reads\n// the answer. Each driver gives its bytes and its rule for the answer. The core keeps node:net out\n// of `core.ts`, thus only an entry that gives a dial loads it.\n\nimport { connect as dialTcp } from \"node:net\";\nimport type { DialFn } from \"./core.ts\";\n\n/**\n * A judge reads the bytes that the server sent so far. It gives null for a good answer, an error for\n * a bad answer, or \"more\" when it must wait for more bytes.\n */\nexport type Judge = (received: Buffer) => Error | null | \"more\";\n\n/**\n * This function makes a dial function. The dial opens a TCP connection, sends `hello`, and reads the\n * answer until `judge` decides. An abort, an error of the socket, and a close before the decision fail the dial.\n * The dial destroys its socket at its end.\n */\nexport const helloDial =\n (hello: string | Uint8Array, judge: Judge): DialFn =>\n (host, port, signal) =>\n new Promise((resolve, reject) => {\n if (signal.aborted) {\n reject(new Error(\"the dial was aborted\"));\n return;\n }\n const socket = dialTcp({ host, port });\n let received = Buffer.alloc(0);\n const end = (error?: Error): void => {\n signal.removeEventListener(\"abort\", onAbort);\n socket.destroy();\n if (error === undefined) resolve();\n else reject(error);\n };\n const onAbort = (): void => end(new Error(\"the dial was aborted\"));\n signal.addEventListener(\"abort\", onAbort, { once: true });\n socket.once(\"connect\", () => socket.write(hello));\n socket.on(\"data\", (chunk: Buffer) => {\n received = Buffer.concat([received, chunk]);\n const verdict = judge(received);\n if (verdict === \"more\") return;\n end(verdict ?? undefined);\n });\n socket.once(\"error\", (error) => end(error));\n socket.once(\"close\", () => end(new Error(\"the server closed the dial\")));\n });\n\n/** This function gives the authority of a host and a port for a Host header. An IPv6 address goes in brackets. */\nexport const authority = (host: string, port: number): string => `${host.includes(\":\") ? `[${host}]` : host}:${port}`;\n\n/**\n * This function makes a judge of the status line of an HTTP/1.1 answer. The judge waits for the end\n * of the line, in the first 8 KiB. Then `accept` reads the status code, and gives null for a good status or an error.\n * The HTTP client accepts each status. The WebSocket client accepts only 101.\n */\nexport const statusLineJudge =\n (accept: (status: number, line: string) => Error | null): Judge =>\n (received) => {\n const end = received.indexOf(\"\\r\\n\");\n if (end < 0) return received.length > 8192 ? new Error(\"the answer has no status line in its first 8 KiB\") : \"more\";\n const line = received.toString(\"latin1\", 0, end);\n const status = /^HTTP\\/1\\.[01] (\\d{3})/.exec(line);\n return status === null ? new Error(`the answer ${JSON.stringify(line)} is not an HTTP/1.1 status line`) : accept(Number(status[1]), line);\n };\n"],"mappings":";;;;;;;AAkBA,MAAa,aACV,OAA4B,WAC5B,MAAM,MAAM,WACX,IAAI,SAAS,SAAS,WAAW;CAC/B,IAAI,OAAO,SAAS;EAClB,uBAAO,IAAI,MAAM,sBAAsB,CAAC;EACxC;CACF;CACA,MAAM,SAASA,QAAQ;EAAE;EAAM;CAAK,CAAC;CACrC,IAAI,WAAW,OAAO,MAAM,CAAC;CAC7B,MAAM,OAAO,UAAwB;EACnC,OAAO,oBAAoB,SAAS,OAAO;EAC3C,OAAO,QAAQ;EACf,IAAI,UAAU,KAAA,GAAW,QAAQ;OAC5B,OAAO,KAAK;CACnB;CACA,MAAM,gBAAsB,oBAAI,IAAI,MAAM,sBAAsB,CAAC;CACjE,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;CACxD,OAAO,KAAK,iBAAiB,OAAO,MAAM,KAAK,CAAC;CAChD,OAAO,GAAG,SAAS,UAAkB;EACnC,WAAW,OAAO,OAAO,CAAC,UAAU,KAAK,CAAC;EAC1C,MAAM,UAAU,MAAM,QAAQ;EAC9B,IAAI,YAAY,QAAQ;EACxB,IAAI,WAAW,KAAA,CAAS;CAC1B,CAAC;CACD,OAAO,KAAK,UAAU,UAAU,IAAI,KAAK,CAAC;CAC1C,OAAO,KAAK,eAAe,oBAAI,IAAI,MAAM,4BAA4B,CAAC,CAAC;AACzE,CAAC;;AAGL,MAAa,aAAa,MAAc,SAAyB,GAAG,KAAK,SAAS,GAAG,IAAI,IAAI,KAAK,KAAK,KAAK,GAAG;;;;;;AAO/G,MAAa,mBACV,YACA,aAAa;CACZ,MAAM,MAAM,SAAS,QAAQ,MAAM;CACnC,IAAI,MAAM,GAAG,OAAO,SAAS,SAAS,uBAAO,IAAI,MAAM,kDAAkD,IAAI;CAC7G,MAAM,OAAO,SAAS,SAAS,UAAU,GAAG,GAAG;CAC/C,MAAM,SAAS,yBAAyB,KAAK,IAAI;CACjD,OAAO,WAAW,uBAAO,IAAI,MAAM,cAAc,KAAK,UAAU,IAAI,EAAE,gCAAgC,IAAI,OAAO,OAAO,OAAO,EAAE,GAAG,IAAI;AAC1I"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/client/machine.ts
|
|
2
|
+
/** This function gives one transition of a machine document. */
|
|
3
|
+
const transition = (id, from, on, to, extra = {}) => ({
|
|
4
|
+
id,
|
|
5
|
+
from,
|
|
6
|
+
on,
|
|
7
|
+
to,
|
|
8
|
+
...extra
|
|
9
|
+
});
|
|
10
|
+
/** This function gives a knob of a client in a machine document, by the option of the driver that it sets. */
|
|
11
|
+
const clientKnob = (key) => ({
|
|
12
|
+
key,
|
|
13
|
+
scope: "client",
|
|
14
|
+
unit: "s",
|
|
15
|
+
default: null
|
|
16
|
+
});
|
|
17
|
+
/** This timer is the bound of the close. The close request arms it, and the end cancels it. At its end, the driver destroys each socket. */
|
|
18
|
+
const closeTimer = () => ({
|
|
19
|
+
duration: {
|
|
20
|
+
knob: "close_bound",
|
|
21
|
+
unit: "s"
|
|
22
|
+
},
|
|
23
|
+
arms: ["close.request"],
|
|
24
|
+
cancels: ["status.end"],
|
|
25
|
+
fires: "close.bound"
|
|
26
|
+
});
|
|
27
|
+
export { clientKnob, closeTimer, transition };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine.js","names":[],"sources":["../../src/client/machine.ts"],"sourcesContent":["// The parts of the machine document of a client that each client has. Each client entry writes its\n// own states and transitions, because the states are the states of its driver. The helpers, the\n// knob shape, the timer of the bounded close and the events that the core records are the same.\n\nimport type { TransitionDef } from \"@mark1russell7/algebra\";\n\n/** This function gives one transition of a machine document. */\nexport const transition = (\n id: string,\n from: string | readonly string[],\n on: string | readonly string[],\n to: string,\n extra: Partial<TransitionDef> = {},\n): TransitionDef => ({\n id,\n from,\n on,\n to,\n ...extra,\n});\n\n/** A client knob is a knob of a client in a machine document: a time in seconds, with no default. */\nexport interface ClientKnob {\n readonly key: string;\n readonly scope: \"client\";\n readonly unit: \"s\";\n readonly default: null;\n}\n\n/** This function gives a knob of a client in a machine document, by the option of the driver that it sets. */\nexport const clientKnob = (key: string): ClientKnob => ({ key, scope: \"client\", unit: \"s\", default: null });\n\n/** A close timer is the timer of the bounded close in a machine document. */\nexport interface CloseTimer {\n readonly duration: { readonly knob: \"close_bound\"; readonly unit: \"s\" };\n readonly arms: readonly [\"close.request\"];\n readonly cancels: readonly [\"status.end\"];\n readonly fires: \"close.bound\";\n}\n\n/** This timer is the bound of the close. The close request arms it, and the end cancels it. At its end, the driver destroys each socket. */\nexport const closeTimer = (): CloseTimer => ({\n duration: { knob: \"close_bound\", unit: \"s\" },\n arms: [\"close.request\"],\n cancels: [\"status.end\"],\n fires: \"close.bound\",\n});\n\n/**\n * These are the events that each machine document of a client declares. The core and the shared\n * parts of each client record them: a second try, a failed connect, and the steps of the bounded close.\n */\nexport const CLIENT_EVENTS = [\"status.connecting\", \"connect.failed\", \"command.reissue\", \"close.request\", \"close.bound\", \"close.destroy\", \"status.end\"] as const;\n"],"mappings":";;AAOA,MAAa,cACX,IACA,MACA,IACA,IACA,QAAgC,CAAC,OACd;CACnB;CACA;CACA;CACA;CACA,GAAG;AACL;;AAWA,MAAa,cAAc,SAA6B;CAAE;CAAK,OAAO;CAAU,MAAM;CAAK,SAAS;AAAK;;AAWzG,MAAa,oBAAgC;CAC3C,UAAU;EAAE,MAAM;EAAe,MAAM;CAAI;CAC3C,MAAM,CAAC,eAAe;CACtB,SAAS,CAAC,YAAY;CACtB,OAAO;AACT"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Extent } from "@mark1russell7/quantity";
|
|
2
|
+
/** A situation is what the connection did when the failure started: a command in flight, or idle. */
|
|
3
|
+
export type Situation = "in flight" | "idle";
|
|
4
|
+
/** A detector is a mechanism that finds a failure, and the most time that it takes. */
|
|
5
|
+
export interface Detector {
|
|
6
|
+
/** This name identifies the mechanism: a knob of the declaration, or the kernel. */
|
|
7
|
+
readonly by: string;
|
|
8
|
+
/** This time is the most that the detector takes, after the failure starts. "infinite" tells that it does not find the failure. */
|
|
9
|
+
readonly within: Extent;
|
|
10
|
+
readonly situation: Situation;
|
|
11
|
+
/** This text tells what the detector does, for example that it fails a command without a change of state. */
|
|
12
|
+
readonly effect: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A meeting is a manifestation that the client can meet, and its detectors (E9). The names of the
|
|
16
|
+
* manifestations are the names of the vocabulary of the harness and the corpus. `app-stall` is a
|
|
17
|
+
* server whose process is alive and does not answer, a proposal of the vocabulary.
|
|
18
|
+
*/
|
|
19
|
+
export interface Meeting {
|
|
20
|
+
readonly manifestation: string;
|
|
21
|
+
/** This text tells the failure in words. */
|
|
22
|
+
readonly what: string;
|
|
23
|
+
readonly detectors: readonly Detector[];
|
|
24
|
+
}
|
|
25
|
+
/** These are the manifestations that each client gives a meeting for, in this sequence. */
|
|
26
|
+
export declare const MANIFESTATIONS: readonly ["rst", "fin", "blackhole", "freeze-host", "freeze-process", "app-stall"];
|
|
27
|
+
/** A manifestation is one name of `MANIFESTATIONS`. */
|
|
28
|
+
export type Manifestation = (typeof MANIFESTATIONS)[number];
|
|
29
|
+
/** This function gives the first detector of a manifestation in a situation, or null when no detector has an end (C3). */
|
|
30
|
+
export declare const firstDetector: (meeting: Meeting, situation: Situation) => Detector | null;
|
|
31
|
+
/** This function gives each manifestation and situation that no detector of the client finds: the standing rule, as a query (C3, E9). */
|
|
32
|
+
export declare const unwatched: (meets: readonly Meeting[]) => Array<{
|
|
33
|
+
readonly manifestation: string;
|
|
34
|
+
readonly situation: Situation;
|
|
35
|
+
}>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { quantity, valueIn } from "@mark1russell7/quantity";
|
|
2
|
+
// src/client/meets.ts
|
|
3
|
+
/** These are the manifestations that each client gives a meeting for, in this sequence. */
|
|
4
|
+
const MANIFESTATIONS = [
|
|
5
|
+
"rst",
|
|
6
|
+
"fin",
|
|
7
|
+
"blackhole",
|
|
8
|
+
"freeze-host",
|
|
9
|
+
"freeze-process",
|
|
10
|
+
"app-stall"
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* These words tell each manifestation that does not depend on the driver. The words of `app-stall`
|
|
14
|
+
* name an example, and the example is a fact of each server, thus each client gives them.
|
|
15
|
+
*/
|
|
16
|
+
const WHAT = {
|
|
17
|
+
rst: "the server answers each segment with a reset, and refuses each new connection",
|
|
18
|
+
fin: "the process of the server ends, and its kernel closes the connection",
|
|
19
|
+
blackhole: "the network drops each segment in the two directions",
|
|
20
|
+
"freeze-host": "the host of the server stops, without a close: the death without a close",
|
|
21
|
+
"freeze-process": "the process of the server stops, and its kernel stays up"
|
|
22
|
+
};
|
|
23
|
+
/** This amount is a detector that does not find the failure. */
|
|
24
|
+
const NEVER = {
|
|
25
|
+
value: "infinite",
|
|
26
|
+
unit: "s"
|
|
27
|
+
};
|
|
28
|
+
const s = (value) => quantity(Math.round(value * 1e6) / 1e6, "s");
|
|
29
|
+
const seconds = (amount) => amount.value === "infinite" ? Number.POSITIVE_INFINITY : valueIn(amount, "s");
|
|
30
|
+
/** This function gives the time at which Node's TCP keepalive gives up a silent peer: the idle time, then 10 probes 1 s apart. */
|
|
31
|
+
const keepaliveGiveUp = (idle) => idle.value === "infinite" ? NEVER : s(seconds(idle) + 10);
|
|
32
|
+
/** This detector is a segment that arrives at once: a reset or a FIN. */
|
|
33
|
+
const immediate = (situation, effect) => ({
|
|
34
|
+
by: "the next segment",
|
|
35
|
+
within: s(0),
|
|
36
|
+
situation,
|
|
37
|
+
effect
|
|
38
|
+
});
|
|
39
|
+
/** This detector is TCP keepalive on a silent peer. It gives up after its probes, and the socket closes. */
|
|
40
|
+
const keepaliveSilent = (idle) => ({
|
|
41
|
+
by: "keepalive_idle",
|
|
42
|
+
within: keepaliveGiveUp(idle),
|
|
43
|
+
situation: "idle",
|
|
44
|
+
effect: "TCP keepalive gives up, and the socket closes"
|
|
45
|
+
});
|
|
46
|
+
/** This detector is TCP keepalive on a peer whose kernel stays up. That kernel answers each probe, thus keepalive does not find the failure. */
|
|
47
|
+
const keepaliveAnswered = () => ({
|
|
48
|
+
by: "keepalive_idle",
|
|
49
|
+
within: NEVER,
|
|
50
|
+
situation: "idle",
|
|
51
|
+
effect: "the kernel of the server answers each probe"
|
|
52
|
+
});
|
|
53
|
+
/** This detector is TCP keepalive on a peer that resets: the first probe gets the reset. */
|
|
54
|
+
const keepaliveReset = (idle) => ({
|
|
55
|
+
by: "keepalive_idle",
|
|
56
|
+
within: idle.value === "infinite" ? NEVER : idle,
|
|
57
|
+
situation: "idle",
|
|
58
|
+
effect: "the first probe gets a reset"
|
|
59
|
+
});
|
|
60
|
+
/** This detector is the kernel, which gives up the retransmissions of a segment in flight. A driver can add what follows. */
|
|
61
|
+
const kernelGiveUp = (within, after) => ({
|
|
62
|
+
by: "retrans_giveup_time",
|
|
63
|
+
within,
|
|
64
|
+
situation: "in flight",
|
|
65
|
+
effect: `the kernel gives up the retransmissions and closes the socket${after === void 0 ? "" : `, and ${after}`}`
|
|
66
|
+
});
|
|
67
|
+
/** This function gives the first detector of a manifestation in a situation, or null when no detector has an end (C3). */
|
|
68
|
+
const firstDetector = (meeting, situation) => {
|
|
69
|
+
return meeting.detectors.filter((detector) => detector.situation === situation && detector.within.value !== "infinite").sort((a, b) => seconds(a.within) - seconds(b.within))[0] ?? null;
|
|
70
|
+
};
|
|
71
|
+
/** This function gives each manifestation and situation that no detector of the client finds: the standing rule, as a query (C3, E9). */
|
|
72
|
+
const unwatched = (meets) => meets.flatMap((meeting) => ["in flight", "idle"].flatMap((situation) => firstDetector(meeting, situation) === null ? [{
|
|
73
|
+
manifestation: meeting.manifestation,
|
|
74
|
+
situation
|
|
75
|
+
}] : []));
|
|
76
|
+
export { MANIFESTATIONS, NEVER, WHAT, firstDetector, immediate, keepaliveAnswered, keepaliveGiveUp, keepaliveReset, keepaliveSilent, kernelGiveUp, unwatched };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=meets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meets.js","names":[],"sources":["../../src/client/meets.ts"],"sourcesContent":["// The manifestations that a client can meet, and their detectors (E9). The shapes, the two queries,\n// the detectors of the kernel and the words of each manifestation are the same for each client.\n// Each client entry gives its own list of meetings, because the timers of each driver differ.\n\nimport type { Extent, Quantity } from \"@mark1russell7/quantity\";\nimport { quantity, valueIn } from \"@mark1russell7/quantity\";\n\n/** A situation is what the connection did when the failure started: a command in flight, or idle. */\nexport type Situation = \"in flight\" | \"idle\";\n\n/** A detector is a mechanism that finds a failure, and the most time that it takes. */\nexport interface Detector {\n /** This name identifies the mechanism: a knob of the declaration, or the kernel. */\n readonly by: string;\n /** This time is the most that the detector takes, after the failure starts. \"infinite\" tells that it does not find the failure. */\n readonly within: Extent;\n readonly situation: Situation;\n /** This text tells what the detector does, for example that it fails a command without a change of state. */\n readonly effect: string;\n}\n\n/**\n * A meeting is a manifestation that the client can meet, and its detectors (E9). The names of the\n * manifestations are the names of the vocabulary of the harness and the corpus. `app-stall` is a\n * server whose process is alive and does not answer, a proposal of the vocabulary.\n */\nexport interface Meeting {\n readonly manifestation: string;\n /** This text tells the failure in words. */\n readonly what: string;\n readonly detectors: readonly Detector[];\n}\n\n/** These are the manifestations that each client gives a meeting for, in this sequence. */\nexport const MANIFESTATIONS = [\"rst\", \"fin\", \"blackhole\", \"freeze-host\", \"freeze-process\", \"app-stall\"] as const;\n\n/** A manifestation is one name of `MANIFESTATIONS`. */\nexport type Manifestation = (typeof MANIFESTATIONS)[number];\n\n/**\n * These words tell each manifestation that does not depend on the driver. The words of `app-stall`\n * name an example, and the example is a fact of each server, thus each client gives them.\n */\nexport const WHAT: Readonly<Record<Exclude<Manifestation, \"app-stall\">, string>> = {\n rst: \"the server answers each segment with a reset, and refuses each new connection\",\n fin: \"the process of the server ends, and its kernel closes the connection\",\n blackhole: \"the network drops each segment in the two directions\",\n \"freeze-host\": \"the host of the server stops, without a close: the death without a close\",\n \"freeze-process\": \"the process of the server stops, and its kernel stays up\",\n};\n\n/** This amount is a detector that does not find the failure. */\nexport const NEVER: Extent = { value: \"infinite\", unit: \"s\" };\n\nconst s = (value: number): Quantity => quantity(Math.round(value * 1e6) / 1e6, \"s\");\nconst seconds = (amount: Extent): number =>\n amount.value === \"infinite\" ? Number.POSITIVE_INFINITY : valueIn(amount as Quantity, \"s\");\n\n/** Node gives keepalive 10 probes, 1 s apart, after its idle time: a silent peer is found 10 s after the idle time. */\nconst NODE_PROBES = 10;\nconst NODE_INTERVAL = 1;\n\n/** This function gives the time at which Node's TCP keepalive gives up a silent peer: the idle time, then 10 probes 1 s apart. */\nexport const keepaliveGiveUp = (idle: Extent): Extent => (idle.value === \"infinite\" ? NEVER : s(seconds(idle) + NODE_PROBES * NODE_INTERVAL));\n\n/** This detector is a segment that arrives at once: a reset or a FIN. */\nexport const immediate = (situation: Situation, effect: string): Detector => ({ by: \"the next segment\", within: s(0), situation, effect });\n\n/** This detector is TCP keepalive on a silent peer. It gives up after its probes, and the socket closes. */\nexport const keepaliveSilent = (idle: Extent): Detector => ({\n by: \"keepalive_idle\",\n within: keepaliveGiveUp(idle),\n situation: \"idle\",\n effect: \"TCP keepalive gives up, and the socket closes\",\n});\n\n/** This detector is TCP keepalive on a peer whose kernel stays up. That kernel answers each probe, thus keepalive does not find the failure. */\nexport const keepaliveAnswered = (): Detector => ({\n by: \"keepalive_idle\",\n within: NEVER,\n situation: \"idle\",\n effect: \"the kernel of the server answers each probe\",\n});\n\n/** This detector is TCP keepalive on a peer that resets: the first probe gets the reset. */\nexport const keepaliveReset = (idle: Extent): Detector => ({\n by: \"keepalive_idle\",\n within: idle.value === \"infinite\" ? NEVER : idle,\n situation: \"idle\",\n effect: \"the first probe gets a reset\",\n});\n\n/** This detector is the kernel, which gives up the retransmissions of a segment in flight. A driver can add what follows. */\nexport const kernelGiveUp = (within: Extent, after?: string): Detector => ({\n by: \"retrans_giveup_time\",\n within,\n situation: \"in flight\",\n effect: `the kernel gives up the retransmissions and closes the socket${after === undefined ? \"\" : `, and ${after}`}`,\n});\n\n/** This function gives the first detector of a manifestation in a situation, or null when no detector has an end (C3). */\nexport const firstDetector = (meeting: Meeting, situation: Situation): Detector | null => {\n const ranked = meeting.detectors\n .filter((detector) => detector.situation === situation && detector.within.value !== \"infinite\")\n .sort((a, b) => seconds(a.within) - seconds(b.within));\n return ranked[0] ?? null;\n};\n\n/** This function gives each manifestation and situation that no detector of the client finds: the standing rule, as a query (C3, E9). */\nexport const unwatched = (meets: readonly Meeting[]): Array<{ readonly manifestation: string; readonly situation: Situation }> =>\n meets.flatMap((meeting) =>\n ([\"in flight\", \"idle\"] as const).flatMap((situation) =>\n firstDetector(meeting, situation) === null ? [{ manifestation: meeting.manifestation, situation }] : [],\n ),\n );\n"],"mappings":";;;AAkCA,MAAa,iBAAiB;CAAC;CAAO;CAAO;CAAa;CAAe;CAAkB;AAAW;;;;;AAStG,MAAa,OAAsE;CACjF,KAAK;CACL,KAAK;CACL,WAAW;CACX,eAAe;CACf,kBAAkB;AACpB;;AAGA,MAAa,QAAgB;CAAE,OAAO;CAAY,MAAM;AAAI;AAE5D,MAAM,KAAK,UAA4B,SAAS,KAAK,MAAM,QAAQ,GAAG,IAAI,KAAK,GAAG;AAClF,MAAM,WAAW,WACf,OAAO,UAAU,aAAa,OAAO,oBAAoB,QAAQ,QAAoB,GAAG;;AAO1F,MAAa,mBAAmB,SAA0B,KAAK,UAAU,aAAa,QAAQ,EAAE,QAAQ,IAAI,IAAI,EAA2B;;AAG3I,MAAa,aAAa,WAAsB,YAA8B;CAAE,IAAI;CAAoB,QAAQ,EAAE,CAAC;CAAG;CAAW;AAAO;;AAGxI,MAAa,mBAAmB,UAA4B;CAC1D,IAAI;CACJ,QAAQ,gBAAgB,IAAI;CAC5B,WAAW;CACX,QAAQ;AACV;;AAGA,MAAa,2BAAqC;CAChD,IAAI;CACJ,QAAQ;CACR,WAAW;CACX,QAAQ;AACV;;AAGA,MAAa,kBAAkB,UAA4B;CACzD,IAAI;CACJ,QAAQ,KAAK,UAAU,aAAa,QAAQ;CAC5C,WAAW;CACX,QAAQ;AACV;;AAGA,MAAa,gBAAgB,QAAgB,WAA8B;CACzE,IAAI;CACJ;CACA,WAAW;CACX,QAAQ,gEAAgE,UAAU,KAAA,IAAY,KAAK,SAAS;AAC9G;;AAGA,MAAa,iBAAiB,SAAkB,cAA0C;CAIxF,OAHe,QAAQ,UACpB,QAAQ,aAAa,SAAS,cAAc,aAAa,SAAS,OAAO,UAAU,UAAU,CAAC,CAC9F,MAAM,GAAG,MAAM,QAAQ,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,CAC1C,CAAC,CAAC,MAAM;AACtB;;AAGA,MAAa,aAAa,UACxB,MAAM,SAAS,YACZ,CAAC,aAAa,MAAM,CAAC,CAAW,SAAS,cACxC,cAAc,SAAS,SAAS,MAAM,OAAO,CAAC;CAAE,eAAe,QAAQ;CAAe;AAAU,CAAC,IAAI,CAAC,CACxG,CACF"}
|
package/build/clock.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cancel, Clock, PlatformClockOptions, platformClock, realClock } from "@mark1russell7/algebra/clock";
|
|
2
2
|
export { type Cancel, type Clock, type PlatformClockOptions, platformClock, realClock };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Clock } from "./clock.js";
|
|
2
|
+
import { ContractCase } from "./contract.js";
|
|
3
|
+
import { Lifecycle, TransportImpl } from "./lifecycle.js";
|
|
4
|
+
import { RequestEnd, RequestFn } from "./requests.js";
|
|
5
|
+
/** A held work is one unit of work that stays in flight until the test releases it. */
|
|
6
|
+
export interface HeldWork {
|
|
7
|
+
/** This method lets the work end. Its promise ends when the caller of the work has its answer, or its error. */
|
|
8
|
+
release(): Promise<void>;
|
|
9
|
+
/** This flag tells if the work got the cooperative abort of the drain. */
|
|
10
|
+
readonly aborted: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A transport subject is a transport and the client side of its work. The kit offers work through
|
|
14
|
+
* it, holds work in flight through it, and reads the count of the transport.
|
|
15
|
+
*/
|
|
16
|
+
export interface TransportSubject {
|
|
17
|
+
readonly impl: TransportImpl;
|
|
18
|
+
/** This lifecycle goes to `start()`. Without it, the kit gives a detached lifecycle. */
|
|
19
|
+
readonly life?: Lifecycle | undefined;
|
|
20
|
+
/** This method offers one unit of new work. It gives true when the transport took it, and false when it refused it. */
|
|
21
|
+
offer(): Promise<boolean>;
|
|
22
|
+
/** This method starts one unit of work that stays in flight until its release. The promise ends when the transport has it. */
|
|
23
|
+
hold(): Promise<HeldWork>;
|
|
24
|
+
/**
|
|
25
|
+
* This method sends one call through the transport, for the stream cases (option `streams`). The
|
|
26
|
+
* handler of the call gives `call.work` to `life.request(call.controller, call.route, ...)` of the
|
|
27
|
+
* lifecycle of the start, and writes its stream to the caller. It gives what the caller sees.
|
|
28
|
+
*/
|
|
29
|
+
call?(call: StreamCall): CallerView | Promise<CallerView>;
|
|
30
|
+
/** This method frees what the subject holds outside the transport: its clients and their sockets. */
|
|
31
|
+
dispose?(): Promise<void> | void;
|
|
32
|
+
}
|
|
33
|
+
/** A stream call is one request of the stream cases. The kit gives its work, and the subject sends it. */
|
|
34
|
+
export interface StreamCall {
|
|
35
|
+
/** This name is the controller of the request in the lifecycle of the kit. */
|
|
36
|
+
readonly controller: string;
|
|
37
|
+
/** This name is the route of the request in the lifecycle of the kit. */
|
|
38
|
+
readonly route: string;
|
|
39
|
+
/** This function is the work of the request: one value, or a stream of values. */
|
|
40
|
+
readonly work: RequestFn<unknown>;
|
|
41
|
+
/** True tells that the answer is a stream of items. False tells that the answer is unary: one status and one value. */
|
|
42
|
+
readonly stream: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** A seen end is the end of a call, as its caller read it. */
|
|
45
|
+
export interface SeenEnd {
|
|
46
|
+
readonly kind: RequestEnd["kind"];
|
|
47
|
+
/**
|
|
48
|
+
* True tells that the end came in the body of the answer, after its status, for example as the
|
|
49
|
+
* last line of a stream. False tells that the end came as the status of the answer.
|
|
50
|
+
*/
|
|
51
|
+
readonly inBand: boolean;
|
|
52
|
+
}
|
|
53
|
+
/** A caller view is what the caller of a call has read so far. The kit reads it again until it changes. */
|
|
54
|
+
export interface CallerView {
|
|
55
|
+
/** These values are the items that the caller read, in their sequence. */
|
|
56
|
+
readonly items: readonly unknown[];
|
|
57
|
+
/** This end is the end that the caller read, or null while the call is open. */
|
|
58
|
+
readonly end: SeenEnd | null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* This function gives a detached lifecycle: a lifecycle with no service, for the start of a
|
|
62
|
+
* transport in a test. Its state is `running`, it keeps each connection, and nothing is in flight. Each request
|
|
63
|
+
* and each use of its health throws, because no service declares a route.
|
|
64
|
+
*/
|
|
65
|
+
export declare const detachedLifecycle: () => Lifecycle;
|
|
66
|
+
/** A subject factory makes a new subject for each case, on the clock of the case. */
|
|
67
|
+
export type SubjectFactory = (clock: Clock) => TransportSubject | Promise<TransportSubject>;
|
|
68
|
+
/** A conformance record is one measurement of a case, for the raw records of a run in CI. */
|
|
69
|
+
export interface ConformanceRecord {
|
|
70
|
+
readonly case: string;
|
|
71
|
+
readonly what: string;
|
|
72
|
+
/** This time is the limit of the contract, in milliseconds. */
|
|
73
|
+
readonly expected: number;
|
|
74
|
+
/** This time is what the case measured, in milliseconds of the real clock. */
|
|
75
|
+
readonly measured: number;
|
|
76
|
+
}
|
|
77
|
+
/** These options tune the conformance kit. */
|
|
78
|
+
export interface ConformanceOptions {
|
|
79
|
+
/** This name goes before the name of each case. */
|
|
80
|
+
readonly name?: string | undefined;
|
|
81
|
+
/** This clock moves the cases: `fake` gives exact and fast cases, and `real` measures the timing. The default is `fake`. */
|
|
82
|
+
readonly clock?: "fake" | "real" | undefined;
|
|
83
|
+
/** This time is the cap of each drain of the cases, in milliseconds. The default is 1000. */
|
|
84
|
+
readonly cap?: number | undefined;
|
|
85
|
+
/** This time is the most that a close can take, in milliseconds of the real clock. The default is 1000. */
|
|
86
|
+
readonly closeBound?: number | undefined;
|
|
87
|
+
/** This time is the most that an event can take to reach the transport, in real milliseconds. The default is 100. */
|
|
88
|
+
readonly slack?: number | undefined;
|
|
89
|
+
/** False tells that the work of the transport cannot see the cooperative abort. The default is true. */
|
|
90
|
+
readonly cooperative?: boolean | undefined;
|
|
91
|
+
/** This count is the number of works that the count case holds. The default is 3. */
|
|
92
|
+
readonly holds?: number | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* True adds the stream cases (S6 D4). Then the subject gives `call`, and the kit gives the
|
|
95
|
+
* transport a lifecycle with request tracking. The default is false.
|
|
96
|
+
*/
|
|
97
|
+
readonly streams?: boolean | undefined;
|
|
98
|
+
/** This function receives each measurement, for the raw records of a run. */
|
|
99
|
+
readonly record?: ((record: ConformanceRecord) => void) | undefined;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* This function generates the conformance cases of a transport (S6 A9). `make` gives a new subject
|
|
103
|
+
* for each case. Each case throws on a failure, and its message names the part of the contract.
|
|
104
|
+
* - The start: nothing is in flight, and the transport takes work.
|
|
105
|
+
* - The count: it follows each work from its events, with no move of the clock.
|
|
106
|
+
* - `stopIntake` refuses new work, keeps the work in flight, and a second stop has no effect.
|
|
107
|
+
* - `drain` ends at once with no work, ends with the last work, and holds to its deadline and not
|
|
108
|
+
* past it. It gives the cooperative abort to the work, and it does not throw.
|
|
109
|
+
* - `close` ends the work in flight in its bound, and a second close has no effect.
|
|
110
|
+
* - The stages in their sequence, as the lifecycle does them.
|
|
111
|
+
*
|
|
112
|
+
* The option `streams` adds the cases of the streams (S6 D4). Each request is a stream, and a
|
|
113
|
+
* unary call is a stream of one item. The kit gives the transport a lifecycle with request
|
|
114
|
+
* tracking. It also does the stages of the shutdown on the tracker, as the lifecycle does them.
|
|
115
|
+
* - A unary call gives one value, and its end comes as the status of the answer.
|
|
116
|
+
* - A stream stays in flight until its end, not until its first item.
|
|
117
|
+
* - A failure after the first item ends the stream with an error line in the body, not a status.
|
|
118
|
+
* A failure before the first item gets a status.
|
|
119
|
+
* - `drain` waits for an open stream. The cooperative abort ends the stream, and its caller gets the end.
|
|
120
|
+
* - At the deadline of the drain, the cut ends an open stream, and its caller gets the end.
|
|
121
|
+
*/
|
|
122
|
+
export declare const transportConformance: (make: SubjectFactory, options?: ConformanceOptions) => ContractCase[];
|