@procedures/client 0.2.3 → 0.3.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/CHANGELOG.md +65 -0
- package/README.md +61 -38
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters/http/client/transport.d.ts.map +1 -1
- package/dist/adapters/http/client/transport.js +35 -3
- package/dist/adapters/http/client/transport.js.map +1 -1
- package/dist/adapters/http/client/types.d.ts +3 -2
- package/dist/adapters/http/client/types.d.ts.map +1 -1
- package/dist/adapters/http/server/transport.d.ts +2 -2
- package/dist/adapters/http/server/transport.d.ts.map +1 -1
- package/dist/adapters/http/server/transport.js +53 -20
- package/dist/adapters/http/server/transport.js.map +1 -1
- package/dist/adapters/http/shared/headers.d.ts +1 -1
- package/dist/adapters/http/shared/headers.d.ts.map +1 -1
- package/dist/adapters/http/shared/headers.js +7 -6
- package/dist/adapters/http/shared/headers.js.map +1 -1
- package/dist/adapters/local/client/transport.d.ts +3 -0
- package/dist/adapters/local/client/transport.d.ts.map +1 -1
- package/dist/adapters/local/client/transport.js +63 -4
- package/dist/adapters/local/client/transport.js.map +1 -1
- package/dist/adapters/local/client/types.d.ts +15 -0
- package/dist/adapters/local/client/types.d.ts.map +1 -1
- package/dist/adapters/local/client/types.js.map +1 -1
- package/dist/adapters/mock/client/transport.d.ts +3 -2
- package/dist/adapters/mock/client/transport.d.ts.map +1 -1
- package/dist/adapters/mock/client/transport.js +8 -5
- package/dist/adapters/mock/client/transport.js.map +1 -1
- package/dist/adapters/mock/client/types.d.ts +7 -6
- package/dist/adapters/mock/client/types.d.ts.map +1 -1
- package/dist/adapters/port/transport.d.ts +62 -0
- package/dist/adapters/port/transport.d.ts.map +1 -0
- package/dist/adapters/port/transport.js +94 -0
- package/dist/adapters/port/transport.js.map +1 -0
- package/dist/adapters/websocket/client/index.d.ts +1 -1
- package/dist/adapters/websocket/client/index.d.ts.map +1 -1
- package/dist/adapters/websocket/client/index.js.map +1 -1
- package/dist/adapters/websocket/client/transport.d.ts +47 -7
- package/dist/adapters/websocket/client/transport.d.ts.map +1 -1
- package/dist/adapters/websocket/client/transport.js +213 -67
- package/dist/adapters/websocket/client/transport.js.map +1 -1
- package/dist/adapters/websocket/client/types.d.ts +70 -21
- package/dist/adapters/websocket/client/types.d.ts.map +1 -1
- package/dist/adapters/websocket/client/types.js.map +1 -1
- package/dist/adapters/websocket/server/transport.d.ts +65 -24
- package/dist/adapters/websocket/server/transport.d.ts.map +1 -1
- package/dist/adapters/websocket/server/transport.js +192 -263
- package/dist/adapters/websocket/server/transport.js.map +1 -1
- package/dist/adapters/websocket/server/types.d.ts +20 -1
- package/dist/adapters/websocket/server/types.d.ts.map +1 -1
- package/dist/adapters/websocket/shared/rpc.d.ts +129 -0
- package/dist/adapters/websocket/shared/rpc.d.ts.map +1 -0
- package/dist/adapters/websocket/shared/rpc.js +425 -0
- package/dist/adapters/websocket/shared/rpc.js.map +1 -0
- package/dist/browser.d.ts +29 -7
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +26 -3
- package/dist/browser.js.map +1 -1
- package/dist/client/call-types.d.ts +10 -10
- package/dist/client/call-types.d.ts.map +1 -1
- package/dist/client/call-types.js +1 -6
- package/dist/client/call-types.js.map +1 -1
- package/dist/client/client.d.ts +6 -1
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +23 -9
- package/dist/client/client.js.map +1 -1
- package/dist/client/deadline.d.ts +38 -0
- package/dist/client/deadline.d.ts.map +1 -0
- package/dist/client/deadline.js +60 -0
- package/dist/client/deadline.js.map +1 -0
- package/dist/client/errors/factory.d.ts.map +1 -1
- package/dist/client/errors/factory.js +11 -7
- package/dist/client/errors/factory.js.map +1 -1
- package/dist/client/index.d.ts +9 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +8 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/middleware/cache.d.ts +19 -5
- package/dist/client/middleware/cache.d.ts.map +1 -1
- package/dist/client/middleware/cache.js +106 -18
- package/dist/client/middleware/cache.js.map +1 -1
- package/dist/client/middleware/circuit-breaker.d.ts +28 -10
- package/dist/client/middleware/circuit-breaker.d.ts.map +1 -1
- package/dist/client/middleware/circuit-breaker.js +35 -24
- package/dist/client/middleware/circuit-breaker.js.map +1 -1
- package/dist/client/middleware/contexts.d.ts +16 -10
- package/dist/client/middleware/contexts.d.ts.map +1 -1
- package/dist/client/middleware/contexts.js.map +1 -1
- package/dist/client/middleware/items.d.ts +31 -2
- package/dist/client/middleware/items.d.ts.map +1 -1
- package/dist/client/middleware/items.js +86 -6
- package/dist/client/middleware/items.js.map +1 -1
- package/dist/client/middleware/lru.d.ts +2 -0
- package/dist/client/middleware/lru.d.ts.map +1 -1
- package/dist/client/middleware/lru.js +11 -0
- package/dist/client/middleware/lru.js.map +1 -1
- package/dist/client/middleware/rate-limit.d.ts +7 -6
- package/dist/client/middleware/rate-limit.d.ts.map +1 -1
- package/dist/client/middleware/rate-limit.js +9 -6
- package/dist/client/middleware/rate-limit.js.map +1 -1
- package/dist/client/middleware/resilience.d.ts +61 -0
- package/dist/client/middleware/resilience.d.ts.map +1 -0
- package/dist/client/middleware/resilience.js +59 -0
- package/dist/client/middleware/resilience.js.map +1 -0
- package/dist/client/middleware/retry.d.ts +45 -11
- package/dist/client/middleware/retry.d.ts.map +1 -1
- package/dist/client/middleware/retry.js +102 -22
- package/dist/client/middleware/retry.js.map +1 -1
- package/dist/client/middleware/timeout.d.ts +15 -12
- package/dist/client/middleware/timeout.d.ts.map +1 -1
- package/dist/client/middleware/timeout.js +46 -37
- package/dist/client/middleware/timeout.js.map +1 -1
- package/dist/client/middleware/tracing.d.ts.map +1 -1
- package/dist/client/middleware/tracing.js +11 -3
- package/dist/client/middleware/tracing.js.map +1 -1
- package/dist/client/types.d.ts +9 -1
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/clock.d.ts +19 -0
- package/dist/clock.d.ts.map +1 -0
- package/dist/clock.js +18 -0
- package/dist/clock.js.map +1 -0
- package/dist/duration.d.ts +37 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/duration.js +44 -0
- package/dist/duration.js.map +1 -0
- package/dist/machines.d.ts +90 -0
- package/dist/machines.d.ts.map +1 -0
- package/dist/machines.js +127 -0
- package/dist/machines.js.map +1 -0
- package/dist/procedures/capability.d.ts +3 -6
- package/dist/procedures/capability.d.ts.map +1 -1
- package/dist/procedures/capability.js +7 -8
- package/dist/procedures/capability.js.map +1 -1
- package/dist/procedures/collection/index.d.ts +3 -3
- package/dist/procedures/collection/index.d.ts.map +1 -1
- package/dist/procedures/collection/index.js +1 -1
- package/dist/procedures/collection/index.js.map +1 -1
- package/dist/procedures/collection/procedures.d.ts.map +1 -1
- package/dist/procedures/collection/procedures.js +49 -1
- package/dist/procedures/collection/procedures.js.map +1 -1
- package/dist/procedures/collection/schemas.d.ts +33 -0
- package/dist/procedures/collection/schemas.d.ts.map +1 -1
- package/dist/procedures/collection/schemas.js +68 -0
- package/dist/procedures/collection/schemas.js.map +1 -1
- package/dist/procedures/collection/storage.d.ts +37 -0
- package/dist/procedures/collection/storage.d.ts.map +1 -1
- package/dist/procedures/core/array.d.ts.map +1 -1
- package/dist/procedures/core/array.js +26 -15
- package/dist/procedures/core/array.js.map +1 -1
- package/dist/procedures/core/index.d.ts.map +1 -1
- package/dist/procedures/core/index.js +8 -0
- package/dist/procedures/core/index.js.map +1 -1
- package/dist/procedures/core/meta.d.ts.map +1 -1
- package/dist/procedures/core/meta.js +2 -1
- package/dist/procedures/core/meta.js.map +1 -1
- package/dist/procedures/core/object.d.ts.map +1 -1
- package/dist/procedures/core/object.js +42 -13
- package/dist/procedures/core/object.js.map +1 -1
- package/dist/procedures/core/operands.d.ts.map +1 -1
- package/dist/procedures/core/operands.js +6 -1
- package/dist/procedures/core/operands.js.map +1 -1
- package/dist/procedures/core/string.d.ts.map +1 -1
- package/dist/procedures/core/string.js +4 -2
- package/dist/procedures/core/string.js.map +1 -1
- package/dist/procedures/define-procedure.d.ts +19 -7
- package/dist/procedures/define-procedure.d.ts.map +1 -1
- package/dist/procedures/define-procedure.js +57 -17
- package/dist/procedures/define-procedure.js.map +1 -1
- package/dist/procedures/effects.d.ts +16 -0
- package/dist/procedures/effects.d.ts.map +1 -1
- package/dist/procedures/effects.js +33 -0
- package/dist/procedures/effects.js.map +1 -1
- package/dist/procedures/idempotency.d.ts +73 -0
- package/dist/procedures/idempotency.d.ts.map +1 -0
- package/dist/procedures/idempotency.js +131 -0
- package/dist/procedures/idempotency.js.map +1 -0
- package/dist/procedures/index.d.ts +7 -3
- package/dist/procedures/index.d.ts.map +1 -1
- package/dist/procedures/index.js +6 -2
- package/dist/procedures/index.js.map +1 -1
- package/dist/procedures/interceptors.d.ts +17 -4
- package/dist/procedures/interceptors.d.ts.map +1 -1
- package/dist/procedures/interceptors.js +18 -7
- package/dist/procedures/interceptors.js.map +1 -1
- package/dist/procedures/invoke.d.ts +15 -3
- package/dist/procedures/invoke.d.ts.map +1 -1
- package/dist/procedures/invoke.js +8 -3
- package/dist/procedures/invoke.js.map +1 -1
- package/dist/procedures/manifest.d.ts +83 -0
- package/dist/procedures/manifest.d.ts.map +1 -0
- package/dist/procedures/manifest.js +90 -0
- package/dist/procedures/manifest.js.map +1 -0
- package/dist/procedures/runtime-programs.d.ts +19 -0
- package/dist/procedures/runtime-programs.d.ts.map +1 -0
- package/dist/procedures/runtime-programs.js +24 -0
- package/dist/procedures/runtime-programs.js.map +1 -0
- package/dist/procedures/types.d.ts +16 -0
- package/dist/procedures/types.d.ts.map +1 -1
- package/dist/procedures/types.js.map +1 -1
- package/dist/protocol.d.ts +40 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +58 -0
- package/dist/protocol.js.map +1 -0
- package/dist/server/host-policy.d.ts +4 -3
- package/dist/server/host-policy.d.ts.map +1 -1
- package/dist/server/host-policy.js +6 -3
- package/dist/server/host-policy.js.map +1 -1
- package/dist/server/host-procedures.d.ts +31 -0
- package/dist/server/host-procedures.d.ts.map +1 -0
- package/dist/server/host-procedures.js +75 -0
- package/dist/server/host-procedures.js.map +1 -0
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/procedure-server.d.ts +110 -4
- package/dist/server/procedure-server.d.ts.map +1 -1
- package/dist/server/procedure-server.js +269 -17
- package/dist/server/procedure-server.js.map +1 -1
- package/dist/server/request-auth.d.ts +19 -0
- package/dist/server/request-auth.d.ts.map +1 -0
- package/dist/server/request-auth.js +32 -0
- package/dist/server/request-auth.js.map +1 -0
- package/dist/server/types.d.ts +32 -0
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js.map +1 -1
- package/dist/timers.d.ts +60 -0
- package/dist/timers.d.ts.map +1 -0
- package/dist/timers.js +33 -0
- package/dist/timers.js.map +1 -0
- package/dist/tracing/traceparent.d.ts +26 -0
- package/dist/tracing/traceparent.d.ts.map +1 -0
- package/dist/tracing/traceparent.js +53 -0
- package/dist/tracing/traceparent.js.map +1 -0
- package/package.json +7 -1
- package/src/adapters/http/client/transport.ts +31 -3
- package/src/adapters/http/client/types.ts +3 -2
- package/src/adapters/http/server/transport.ts +60 -24
- package/src/adapters/http/shared/headers.ts +7 -6
- package/src/adapters/local/client/transport.ts +70 -5
- package/src/adapters/local/client/types.ts +18 -0
- package/src/adapters/mock/client/transport.ts +9 -6
- package/src/adapters/mock/client/types.ts +7 -6
- package/src/adapters/port/transport.ts +124 -0
- package/src/adapters/websocket/client/index.ts +1 -0
- package/src/adapters/websocket/client/transport.ts +232 -73
- package/src/adapters/websocket/client/types.ts +80 -21
- package/src/adapters/websocket/server/transport.ts +199 -301
- package/src/adapters/websocket/server/types.ts +20 -1
- package/src/adapters/websocket/shared/rpc.ts +453 -0
- package/src/browser.ts +51 -3
- package/src/client/call-types.ts +10 -14
- package/src/client/client.ts +28 -9
- package/src/client/deadline.ts +64 -0
- package/src/client/errors/factory.ts +12 -8
- package/src/client/index.ts +21 -3
- package/src/client/middleware/cache.ts +120 -23
- package/src/client/middleware/circuit-breaker.ts +65 -35
- package/src/client/middleware/contexts.ts +17 -10
- package/src/client/middleware/items.ts +101 -6
- package/src/client/middleware/lru.ts +12 -0
- package/src/client/middleware/rate-limit.ts +9 -7
- package/src/client/middleware/resilience.ts +81 -0
- package/src/client/middleware/retry.ts +146 -34
- package/src/client/middleware/timeout.ts +55 -46
- package/src/client/middleware/tracing.ts +13 -4
- package/src/client/types.ts +9 -1
- package/src/clock.ts +21 -0
- package/src/duration.ts +56 -0
- package/src/machines.ts +186 -0
- package/src/procedures/capability.ts +7 -8
- package/src/procedures/collection/index.ts +9 -1
- package/src/procedures/collection/procedures.ts +57 -0
- package/src/procedures/collection/schemas.ts +110 -0
- package/src/procedures/collection/storage.ts +38 -0
- package/src/procedures/core/array.ts +27 -16
- package/src/procedures/core/index.ts +8 -0
- package/src/procedures/core/meta.ts +2 -1
- package/src/procedures/core/object.ts +48 -14
- package/src/procedures/core/operands.ts +7 -0
- package/src/procedures/core/string.ts +4 -2
- package/src/procedures/define-procedure.ts +73 -20
- package/src/procedures/effects.ts +35 -0
- package/src/procedures/idempotency.ts +152 -0
- package/src/procedures/index.ts +18 -2
- package/src/procedures/interceptors.ts +28 -11
- package/src/procedures/invoke.ts +19 -5
- package/src/procedures/manifest.ts +158 -0
- package/src/procedures/runtime-programs.ts +27 -0
- package/src/procedures/types.ts +16 -0
- package/src/protocol.ts +97 -0
- package/src/server/host-policy.ts +8 -5
- package/src/server/host-procedures.ts +102 -0
- package/src/server/index.ts +5 -2
- package/src/server/procedure-server.ts +324 -10
- package/src/server/request-auth.ts +35 -0
- package/src/server/types.ts +37 -0
- package/src/timers.ts +82 -0
- package/src/tracing/traceparent.ts +61 -0
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
* Protocol-agnostic timeout handling with per-request and overall timeouts.
|
|
5
5
|
* Works with any transport!
|
|
6
6
|
*/
|
|
7
|
-
import { ABORTED_FIRST, errorItem, nextOrAbort } from "./items.js";
|
|
7
|
+
import { ABORTED_FIRST, abortedItem, errorItem, nextOrAbort, withDelivery } from "./items.js";
|
|
8
|
+
import { deadlineOf, narrowDeadline, restoreDeadline } from "../deadline.js";
|
|
9
|
+
import { resilience } from "./resilience.js";
|
|
10
|
+
import { optionalMs } from "../../duration.js";
|
|
8
11
|
/**
|
|
9
12
|
* Compose multiple AbortSignals into one.
|
|
10
13
|
*
|
|
@@ -55,15 +58,16 @@ function composeAbortSignals(...signals) {
|
|
|
55
58
|
// Fall through to manual composition if AbortSignal.any() fails
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
|
-
// Fallback: Manual composition for older environments
|
|
61
|
+
// Fallback: Manual composition for older environments. The composed signal keeps the reason of
|
|
62
|
+
// the signal that aborted, as with AbortSignal.any() (before, it got a new AbortError).
|
|
59
63
|
const controller = new AbortController();
|
|
60
64
|
const abortListeners = [];
|
|
61
65
|
for (const signal of validSignals) {
|
|
62
66
|
if (signal.aborted) {
|
|
63
|
-
controller.abort();
|
|
67
|
+
controller.abort(signal.reason);
|
|
64
68
|
break;
|
|
65
69
|
}
|
|
66
|
-
const listener = () => controller.abort();
|
|
70
|
+
const listener = () => controller.abort(signal.reason);
|
|
67
71
|
signal.addEventListener("abort", listener, { once: true });
|
|
68
72
|
abortListeners.push(() => signal.removeEventListener("abort", listener));
|
|
69
73
|
}
|
|
@@ -77,7 +81,8 @@ function composeAbortSignals(...signals) {
|
|
|
77
81
|
/**
|
|
78
82
|
* Run `next` with a timeout. When the time runs out, the request's signal aborts, and the
|
|
79
83
|
* reader gets one TIMEOUT error item in place of the transport's ABORTED item or thrown error.
|
|
80
|
-
* The middleware does not wait for a transport that ignores the signal
|
|
84
|
+
* The middleware does not wait for a transport that ignores the signal: not after the timeout,
|
|
85
|
+
* and not after an abort of the caller, which gives an ABORTED item.
|
|
81
86
|
*
|
|
82
87
|
* Before, the middleware waited for a thrown error, but the transports yield error items: the
|
|
83
88
|
* reader got "ABORTED" (not retryable), so a per-attempt timeout with retry never retried, and
|
|
@@ -86,23 +91,31 @@ function composeAbortSignals(...signals) {
|
|
|
86
91
|
async function* runWithTimeout(next, context, ms, message, retryable) {
|
|
87
92
|
const timeoutController = new AbortController();
|
|
88
93
|
const timeoutId = setTimeout(() => timeoutController.abort(), ms);
|
|
94
|
+
// The overall timeout is the deadline of the call: the transport sends its remaining time to
|
|
95
|
+
// the server (roadmap R10). The timeout of one try is not: the server keeps a keyed write
|
|
96
|
+
// until the next try can get its result, and the request signal stops another call.
|
|
97
|
+
const deadlineBefore = retryable ? deadlineOf(context.message.metadata) : narrowDeadline(context.message.metadata, Date.now() + ms);
|
|
89
98
|
// Compose with existing signal
|
|
90
99
|
const originalSignal = context.message.signal;
|
|
91
100
|
const { controller: composedController, cleanup } = composeAbortSignals(originalSignal, timeoutController.signal);
|
|
92
101
|
context.message.signal = composedController.signal;
|
|
93
102
|
const timedOut = () => timeoutController.signal.aborted && !originalSignal?.aborted;
|
|
94
|
-
|
|
103
|
+
// The request left before the time ran out: the server can still run it (R1)
|
|
104
|
+
const timeoutItem = () => withDelivery(errorItem(context.message.id, "TIMEOUT", message, retryable), "indeterminate");
|
|
95
105
|
const iterator = next(context)[Symbol.asyncIterator]();
|
|
96
106
|
// "running": a next() may be pending; "done": the iterator ended; "abandoned": the timeout won
|
|
97
107
|
let phase = "running";
|
|
98
108
|
try {
|
|
99
109
|
for (;;) {
|
|
100
|
-
|
|
110
|
+
// The timeout and the abort of the caller both end the wait (roadmap R30: before, the wait
|
|
111
|
+
// ignored the abort of the caller, so a transport that ignored the signal kept the caller
|
|
112
|
+
// waiting until the timeout, and the caller got TIMEOUT for its own abort)
|
|
113
|
+
const result = await nextOrAbort(iterator, composedController.signal);
|
|
101
114
|
if (result === ABORTED_FIRST) {
|
|
102
115
|
phase = "abandoned";
|
|
103
|
-
// The transport did not stop in time: end it in the background, and give the timeout
|
|
116
|
+
// The transport did not stop in time: end it in the background, and give the timeout or the abort
|
|
104
117
|
void Promise.resolve(iterator.return?.()).catch(() => undefined);
|
|
105
|
-
yield timeoutItem();
|
|
118
|
+
yield timedOut() ? timeoutItem() : abortedItem(context.message.id);
|
|
106
119
|
return;
|
|
107
120
|
}
|
|
108
121
|
if (result.done) {
|
|
@@ -127,6 +140,7 @@ async function* runWithTimeout(next, context, ms, message, retryable) {
|
|
|
127
140
|
}
|
|
128
141
|
finally {
|
|
129
142
|
clearTimeout(timeoutId);
|
|
143
|
+
restoreDeadline(context.message.metadata, deadlineBefore);
|
|
130
144
|
cleanup();
|
|
131
145
|
// Restore the caller's original signal; we only swapped in the composed signal for this
|
|
132
146
|
// attempt. Leaving the (possibly aborted) composed signal in place poisons subsequent
|
|
@@ -156,21 +170,22 @@ async function* runWithTimeout(next, context, ms, message, retryable) {
|
|
|
156
170
|
* @example
|
|
157
171
|
* ```typescript
|
|
158
172
|
* // Create middleware with default timeout
|
|
159
|
-
* client.use(createOverallTimeoutMiddleware({ overall:
|
|
173
|
+
* client.use(createOverallTimeoutMiddleware({ overall: seconds(5) }));
|
|
160
174
|
*
|
|
161
175
|
* // Override per-call via context
|
|
162
176
|
* await client.call(method, payload, {
|
|
163
|
-
* context: { timeout: { overall:
|
|
177
|
+
* context: { timeout: { overall: seconds(10) } }
|
|
164
178
|
* });
|
|
165
179
|
* ```
|
|
166
180
|
*/
|
|
167
181
|
export function createOverallTimeoutMiddleware(options) {
|
|
168
|
-
const {
|
|
182
|
+
const { message = "Overall request timeout" } = options;
|
|
183
|
+
const defaultOverall = optionalMs(options.overall, "overall");
|
|
169
184
|
return (next) => {
|
|
170
185
|
return async function* (context) {
|
|
171
186
|
// Read from metadata first (user-provided context), then fall back to options
|
|
172
|
-
const overall = context.message.metadata.timeout?.overall
|
|
173
|
-
|
|
187
|
+
const overall = optionalMs(context.message.metadata.timeout?.overall, "timeout.overall") ??
|
|
188
|
+
defaultOverall;
|
|
174
189
|
if (!overall) {
|
|
175
190
|
// No timeout - passthrough
|
|
176
191
|
yield* next(context);
|
|
@@ -195,59 +210,53 @@ export function createOverallTimeoutMiddleware(options) {
|
|
|
195
210
|
* @example
|
|
196
211
|
* ```typescript
|
|
197
212
|
* // Create middleware with default timeout
|
|
198
|
-
* client.use(createTimeoutMiddleware({ perAttempt:
|
|
213
|
+
* client.use(createTimeoutMiddleware({ perAttempt: seconds(1) }));
|
|
199
214
|
*
|
|
200
215
|
* // Override per-call via context
|
|
201
216
|
* await client.call(method, payload, {
|
|
202
|
-
* context: { timeout: { perAttempt:
|
|
217
|
+
* context: { timeout: { perAttempt: seconds(2) } }
|
|
203
218
|
* });
|
|
204
219
|
* ```
|
|
205
220
|
*/
|
|
206
221
|
export function createTimeoutMiddleware(options) {
|
|
207
|
-
const {
|
|
222
|
+
const { message = "Request timeout" } = options;
|
|
223
|
+
const defaultPerAttempt = optionalMs(options.perAttempt, "perAttempt");
|
|
208
224
|
return (next) => {
|
|
209
225
|
return async function* (context) {
|
|
210
226
|
// Read from metadata first (user-provided context), then fall back to options
|
|
211
|
-
const perAttempt = context.message.metadata.timeout?.perAttempt
|
|
212
|
-
|
|
227
|
+
const perAttempt = optionalMs(context.message.metadata.timeout?.perAttempt, "timeout.perAttempt") ??
|
|
228
|
+
defaultPerAttempt;
|
|
213
229
|
if (!perAttempt) {
|
|
214
230
|
// No timeout - passthrough
|
|
215
231
|
yield* next(context);
|
|
216
232
|
return;
|
|
217
233
|
}
|
|
234
|
+
// The limit of one try is at most the remaining time of the call (roadmap R10)
|
|
235
|
+
const deadline = deadlineOf(context.message.metadata);
|
|
236
|
+
const limit = deadline === undefined ? perAttempt : Math.max(0, Math.min(perAttempt, deadline - Date.now()));
|
|
218
237
|
// A retry middleware outside this one can start a new attempt
|
|
219
|
-
yield* runWithTimeout(next, context,
|
|
238
|
+
yield* runWithTimeout(next, context, limit, message, true);
|
|
220
239
|
};
|
|
221
240
|
};
|
|
222
241
|
}
|
|
223
242
|
/**
|
|
224
243
|
* Create combined timeout middleware with both overall and per-attempt timeouts.
|
|
225
244
|
*
|
|
245
|
+
* @deprecated Use `resilience({ overall, perAttempt, retry })`. This function puts the two
|
|
246
|
+
* timeouts in one slot, so a retry middleware that you add with another `use()` cannot sit
|
|
247
|
+
* between them: the retry is outside both, or inside both. `resilience` puts the retry between
|
|
248
|
+
* them (roadmap R10).
|
|
249
|
+
*
|
|
226
250
|
* @param options - Timeout configuration
|
|
227
251
|
* @returns Middleware function
|
|
228
252
|
*
|
|
229
253
|
* @example
|
|
230
254
|
* ```typescript
|
|
231
|
-
* client.use(
|
|
232
|
-
* overall: 5000, // 5 seconds total
|
|
233
|
-
* perAttempt: 1000 // 1 second per attempt
|
|
234
|
-
* }));
|
|
255
|
+
* client.use(resilience({ overall: seconds(5), perAttempt: seconds(1), retry: { maxRetries: 2 } }));
|
|
235
256
|
* ```
|
|
236
257
|
*/
|
|
237
258
|
export function createCombinedTimeoutMiddleware(options) {
|
|
238
259
|
const { overall, perAttempt, message = "Request timeout" } = options;
|
|
239
|
-
return (
|
|
240
|
-
// Compose both timeout middlewares
|
|
241
|
-
let composed = next;
|
|
242
|
-
if (perAttempt) {
|
|
243
|
-
const perAttemptMiddleware = createTimeoutMiddleware({ perAttempt, message: `${message} (per-attempt)` });
|
|
244
|
-
composed = perAttemptMiddleware(composed);
|
|
245
|
-
}
|
|
246
|
-
if (overall) {
|
|
247
|
-
const overallMiddleware = createOverallTimeoutMiddleware({ overall, message: `${message} (overall)` });
|
|
248
|
-
composed = overallMiddleware(composed);
|
|
249
|
-
}
|
|
250
|
-
return composed;
|
|
251
|
-
};
|
|
260
|
+
return resilience({ overall, perAttempt, message });
|
|
252
261
|
}
|
|
253
262
|
//# sourceMappingURL=timeout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../../src/client/middleware/timeout.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WA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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../../src/client/middleware/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../../src/client/middleware/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,MAAM,CAAC;IAE/B,qDAAqD;IACrD,cAAc,CAAC,EAAE,MAAM,MAAM,CAAC;IAE9B,iEAAiE;IACjE,eAAe,CAAC,EAAE,MAAM;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAEnE,+BAA+B;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,cAAmB,GAC3B,qBAAqB,CAAC,cAAc,EAAE,EAAE,CAAC,CA8C3C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,IAAI,qBAAqB,CAAC,cAAc,EAAE,EAAE,CAAC,CAWzF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CAWP"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Compatible with OpenTelemetry, Jaeger, and custom tracing systems.
|
|
13
13
|
*/
|
|
14
|
+
import { TRACEPARENT_METADATA_KEY, formatTraceparent, isW3cIds, newSpanId, newTraceId, parseTraceparent } from "../../tracing/traceparent.js";
|
|
14
15
|
/**
|
|
15
16
|
* Generate a simple unique ID (UUID v4 subset)
|
|
16
17
|
*/
|
|
@@ -74,12 +75,14 @@ function generateId() {
|
|
|
74
75
|
* ```
|
|
75
76
|
*/
|
|
76
77
|
export function createTracingMiddleware(options = {}) {
|
|
77
|
-
|
|
78
|
+
// W3C ids by default, so the server continues the trace (roadmap R16)
|
|
79
|
+
const { generateTraceId = newTraceId, generateSpanId = newSpanId, getCurrentTrace, serviceName, } = options;
|
|
78
80
|
return (next) => async function* (context) {
|
|
79
81
|
// Check if there's already tracing metadata
|
|
80
82
|
if (!context.message.metadata.tracing) {
|
|
81
|
-
// Try to get current trace context
|
|
82
|
-
|
|
83
|
+
// Try to get current trace context: the function of the options, or the trace context of
|
|
84
|
+
// the caller (a call that a handler makes on a server carries the span of that handler)
|
|
85
|
+
const currentTrace = getCurrentTrace?.() ?? parseTraceparent(context.message.metadata[TRACEPARENT_METADATA_KEY]) ?? null;
|
|
83
86
|
if (currentTrace) {
|
|
84
87
|
// Continue existing trace (create child span)
|
|
85
88
|
context.message.metadata.tracing = {
|
|
@@ -100,6 +103,11 @@ export function createTracingMiddleware(options = {}) {
|
|
|
100
103
|
context.message.metadata["serviceName"] = serviceName;
|
|
101
104
|
}
|
|
102
105
|
}
|
|
106
|
+
// The W3C trace context of the call: the server continues this trace (R16)
|
|
107
|
+
const tracing = context.message.metadata.tracing;
|
|
108
|
+
if (tracing && isW3cIds(tracing.traceId, tracing.spanId)) {
|
|
109
|
+
context.message.metadata[TRACEPARENT_METADATA_KEY] = formatTraceparent(tracing.traceId, tracing.spanId);
|
|
110
|
+
}
|
|
103
111
|
// Continue middleware chain
|
|
104
112
|
yield* next(context);
|
|
105
113
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../../src/client/middleware/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../../src/client/middleware/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAmB9I;;GAEG;AACH,SAAS,UAAU;IACjB,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AACjF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAO,GAAmB,EAAE;IAE5B,sEAAsE;IACtE,MAAM,EACJ,eAAe,GAAG,UAAU,EAC5B,cAAc,GAAG,SAAS,EAC1B,eAAe,EACf,WAAW,GACZ,GAAG,OAAO,CAAC;IAEZ,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,SAAS,CAAC,EAAE,OAAO;QACvC,4CAA4C;QAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACtC,yFAAyF;YACzF,wFAAwF;YACxF,MAAM,YAAY,GAAG,eAAe,EAAE,EAAE,IAAI,gBAAgB,CAAC,OAAO,CAAC,OAAO,C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AAC,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE;YAC3B,CAAC,CAAC,UAAU;QACd,cAAc,EAAE,aAAa;YAC3B,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE;YAC3B,CAAC,CAAC,UAAU;KACf,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAiC;IAKlE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,OAAO,QAAQ,CAAC,SAAS,CAAC,KAAK,QAAQ,EAAE,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAA4B,CAAC;IAC/D,OAAO;QACL,GAAG,CAAC,OAAO,OAAO,CAAC,SAAS,CAAC,KAAK,QAAQ,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9E,GAAG,CAAC,OAAO,OAAO,CAAC,QAAQ,CAAC,KAAK,QAAQ,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3E,GAAG,CAAC,OAAO,OAAO,CAAC,cAAc,CAAC,KAAK,QAAQ,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;KAC9F,CAAC;AACJ,CAAC"}
|
package/dist/client/types.d.ts
CHANGED
|
@@ -22,7 +22,13 @@ export interface Method {
|
|
|
22
22
|
service: string;
|
|
23
23
|
/** Operation name (e.g., "get", "create", "update", "delete", "watch") */
|
|
24
24
|
operation: string;
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Optional version (e.g., "v1", "v2").
|
|
27
|
+
*
|
|
28
|
+
* @deprecated The wire protocol (v1, roadmap R25) has no version of a procedure: the server
|
|
29
|
+
* ignores this field. A URL strategy can put it in the path. Use a new path for a procedure
|
|
30
|
+
* that changes in a way that is not compatible.
|
|
31
|
+
*/
|
|
26
32
|
version?: string;
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
@@ -58,6 +64,8 @@ export interface Metadata {
|
|
|
58
64
|
retry?: {
|
|
59
65
|
attempt: number;
|
|
60
66
|
maxAttempts: number;
|
|
67
|
+
/** True: a second run of the call changes nothing more, so a retry is safe */
|
|
68
|
+
idempotent?: boolean;
|
|
61
69
|
};
|
|
62
70
|
/** Extensible for custom fields */
|
|
63
71
|
[key: string]: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,WAAW,MAAM;IACrB,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAEhB,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;IAElB
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,WAAW,MAAM;IACrB,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAEhB,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AAE1D;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;aAElB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC;aAC1C,UAAU,EAAE,MAAM;IAFpC,YACkB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,EAC1C,UAAU,EAAE,MAAM,EAInC;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;CACF;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,+BAA+B;IAC/B,SAAS,EAAE,SAAS,CAAC;IAErB,+CAA+C;IAC/C,eAAe,CAAC,EAAE,QAAQ,CAAC;IAE3B,0DAA0D;IAC1D,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;OAGG;IACH,YAAY,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAEtC;;;;OAIG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC"}
|
package/dist/client/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA+TH;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAElB,MAAM;IACN,UAAU;IAF5B,YACkB,MAA0C,EAC1C,UAAkB;QAElC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;sBAHN,MAAM;0BACN,UAAU;QAG1B,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/clock.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The clock of the core (roadmap R35). The retry, the circuit breaker and the WebSocket client
|
|
3
|
+
* read the time and start their timers only through a clock. Thus a test gives a fake clock, and
|
|
4
|
+
* the timing is exact and repeatable.
|
|
5
|
+
*
|
|
6
|
+
* The clock comes from `@mark1russell7/service/clock` (roadmap R37). The entry imports nothing
|
|
7
|
+
* else, and it has 228 bytes of gzip. The `fakeClock` of `@mark1russell7/service/testing` fits here.
|
|
8
|
+
* A `Cancel` of the platform also has `unref`. The circuit breaker uses it for its reset: a breaker
|
|
9
|
+
* must not keep a process alive for its reset time (BUGS-2026-07 M4).
|
|
10
|
+
*/
|
|
11
|
+
import { type Cancel, type Clock } from "@mark1russell7/service/clock";
|
|
12
|
+
export type { Cancel, Clock };
|
|
13
|
+
/**
|
|
14
|
+
* The clock of the platform: `performance.now()` and `setTimeout`. Its timers keep a Node process
|
|
15
|
+
* alive, as `setTimeout` does: a script that waits for a retry does not end during the wait. The
|
|
16
|
+
* `realClock` of the service package is different: its timers do not keep a process alive.
|
|
17
|
+
*/
|
|
18
|
+
export declare const realClock: Clock;
|
|
19
|
+
//# sourceMappingURL=clock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../src/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAiB,KAAK,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAEtF,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAE9B;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,KAAuB,CAAC"}
|
package/dist/clock.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The clock of the core (roadmap R35). The retry, the circuit breaker and the WebSocket client
|
|
3
|
+
* read the time and start their timers only through a clock. Thus a test gives a fake clock, and
|
|
4
|
+
* the timing is exact and repeatable.
|
|
5
|
+
*
|
|
6
|
+
* The clock comes from `@mark1russell7/service/clock` (roadmap R37). The entry imports nothing
|
|
7
|
+
* else, and it has 228 bytes of gzip. The `fakeClock` of `@mark1russell7/service/testing` fits here.
|
|
8
|
+
* A `Cancel` of the platform also has `unref`. The circuit breaker uses it for its reset: a breaker
|
|
9
|
+
* must not keep a process alive for its reset time (BUGS-2026-07 M4).
|
|
10
|
+
*/
|
|
11
|
+
import { platformClock } from "@mark1russell7/service/clock";
|
|
12
|
+
/**
|
|
13
|
+
* The clock of the platform: `performance.now()` and `setTimeout`. Its timers keep a Node process
|
|
14
|
+
* alive, as `setTimeout` does: a script that waits for a retry does not end during the wait. The
|
|
15
|
+
* `realClock` of the service package is different: its timers do not keep a process alive.
|
|
16
|
+
*/
|
|
17
|
+
export const realClock = platformClock();
|
|
18
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../src/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAA2B,MAAM,8BAA8B,CAAC;AAItF;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAU,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed durations (roadmap R11).
|
|
3
|
+
*
|
|
4
|
+
* Each public option of this package that is a time takes a `Duration`: a quantity of
|
|
5
|
+
* `@mark1russell7/quantity` with a time unit. A plain number is a type error, so `timeout: 5`
|
|
6
|
+
* cannot mean five milliseconds in one place and five seconds in another. The wire keeps
|
|
7
|
+
* milliseconds (`procedure-timeout`), and the internals convert each duration one time, when an
|
|
8
|
+
* option is read.
|
|
9
|
+
*
|
|
10
|
+
* `@mark1russell7/quantity` has no `Duration` type yet. This alias narrows its `Quantity` to the
|
|
11
|
+
* time units, so the type also refuses `{ value: 5, unit: "kg" }`.
|
|
12
|
+
*/
|
|
13
|
+
import { type Quantity } from "@mark1russell7/quantity";
|
|
14
|
+
/** The canonical time units of `@mark1russell7/quantity` that a duration of this package uses. */
|
|
15
|
+
export type TimeUnit = "ns" | "us" | "ms" | "s" | "min" | "h" | "d";
|
|
16
|
+
/** A time: a quantity with a time unit. */
|
|
17
|
+
export type Duration = Quantity & {
|
|
18
|
+
readonly unit: TimeUnit;
|
|
19
|
+
};
|
|
20
|
+
/** This function makes a duration of milliseconds. */
|
|
21
|
+
export declare const ms: (value: number) => Duration;
|
|
22
|
+
/** This function makes a duration of seconds. */
|
|
23
|
+
export declare const seconds: (value: number) => Duration;
|
|
24
|
+
/** This function makes a duration of minutes. */
|
|
25
|
+
export declare const minutes: (value: number) => Duration;
|
|
26
|
+
/** This function makes a duration of hours. */
|
|
27
|
+
export declare const hours: (value: number) => Duration;
|
|
28
|
+
/** True when a value is a duration: a finite number with a time unit. */
|
|
29
|
+
export declare function isDuration(value: unknown): value is Duration;
|
|
30
|
+
/**
|
|
31
|
+
* The number of milliseconds of a duration. A value that is not a duration (a plain number, or
|
|
32
|
+
* a quantity of another kind) throws a `TypeError` that names the option.
|
|
33
|
+
*/
|
|
34
|
+
export declare function toMs(duration: Duration, option?: string): number;
|
|
35
|
+
/** The milliseconds of an optional duration, or undefined. */
|
|
36
|
+
export declare function optionalMs(duration: Duration | undefined, option?: string): number | undefined;
|
|
37
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAE3E,kGAAkG;AAClG,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;AAEpE,2CAA2C;AAC3C,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAI9D,sDAAsD;AACtD,eAAO,MAAM,EAAE,UAAW,MAAM,KAAG,QAA6C,CAAC;AACjF,iDAAiD;AACjD,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,QAA4C,CAAC;AACrF,iDAAiD;AACjD,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,QAA8C,CAAC;AACvF,+CAA+C;AAC/C,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,QAA4C,CAAC;AAEnF,yEAAyE;AACzE,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAI5D;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAa,GAAG,MAAM,CAOpE;AAED,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE9F"}
|
package/dist/duration.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed durations (roadmap R11).
|
|
3
|
+
*
|
|
4
|
+
* Each public option of this package that is a time takes a `Duration`: a quantity of
|
|
5
|
+
* `@mark1russell7/quantity` with a time unit. A plain number is a type error, so `timeout: 5`
|
|
6
|
+
* cannot mean five milliseconds in one place and five seconds in another. The wire keeps
|
|
7
|
+
* milliseconds (`procedure-timeout`), and the internals convert each duration one time, when an
|
|
8
|
+
* option is read.
|
|
9
|
+
*
|
|
10
|
+
* `@mark1russell7/quantity` has no `Duration` type yet. This alias narrows its `Quantity` to the
|
|
11
|
+
* time units, so the type also refuses `{ value: 5, unit: "kg" }`.
|
|
12
|
+
*/
|
|
13
|
+
import { quantity, valueIn } from "@mark1russell7/quantity";
|
|
14
|
+
const TIME_UNITS = new Set(["ns", "us", "ms", "s", "min", "h", "d"]);
|
|
15
|
+
/** This function makes a duration of milliseconds. */
|
|
16
|
+
export const ms = (value) => quantity(value, "ms");
|
|
17
|
+
/** This function makes a duration of seconds. */
|
|
18
|
+
export const seconds = (value) => quantity(value, "s");
|
|
19
|
+
/** This function makes a duration of minutes. */
|
|
20
|
+
export const minutes = (value) => quantity(value, "min");
|
|
21
|
+
/** This function makes a duration of hours. */
|
|
22
|
+
export const hours = (value) => quantity(value, "h");
|
|
23
|
+
/** True when a value is a duration: a finite number with a time unit. */
|
|
24
|
+
export function isDuration(value) {
|
|
25
|
+
if (value === null || typeof value !== "object")
|
|
26
|
+
return false;
|
|
27
|
+
const { value: amount, unit } = value;
|
|
28
|
+
return typeof amount === "number" && Number.isFinite(amount) && typeof unit === "string" && TIME_UNITS.has(unit);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The number of milliseconds of a duration. A value that is not a duration (a plain number, or
|
|
32
|
+
* a quantity of another kind) throws a `TypeError` that names the option.
|
|
33
|
+
*/
|
|
34
|
+
export function toMs(duration, option = "duration") {
|
|
35
|
+
if (!isDuration(duration)) {
|
|
36
|
+
throw new TypeError(`${option} must be a duration such as ms(500) or seconds(2), got ${JSON.stringify(duration)}. Plain numbers are not durations (roadmap R11).`);
|
|
37
|
+
}
|
|
38
|
+
return valueIn(duration, "ms");
|
|
39
|
+
}
|
|
40
|
+
/** The milliseconds of an optional duration, or undefined. */
|
|
41
|
+
export function optionalMs(duration, option) {
|
|
42
|
+
return duration === undefined ? undefined : toMs(duration, option);
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1 @@
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AC,QAAkB,EAAE,MAAM,GAAG,UAAU;IAC1D,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,SAAS,CACjB,GAAG,MAAM,0DAA0D,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,kDAAkD,CAC9I,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,UAAU,CAAC,QAA8B,EAAE,MAAe;IACxE,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state machines of the core as data (roadmap R35): the connection of the WebSocket client
|
|
3
|
+
* and the circuit breaker. The documents have the format `mark1russell7.machine/1` of
|
|
4
|
+
* `@mark1russell7/algebra`. They are the specification, and the code implements them. Their knobs
|
|
5
|
+
* are the default times of the core (`TIMER_DEFAULTS`), and their timers say which knob gives each
|
|
6
|
+
* wait.
|
|
7
|
+
*
|
|
8
|
+
* The code reports each change of its state as a `MachineTransition` (the option `onTransition`).
|
|
9
|
+
* `replayTransitions()` replays the reports of a run against a document, so a test finds each
|
|
10
|
+
* change that the document does not allow. It uses `replay` of `@mark1russell7/algebra/replay`
|
|
11
|
+
* (roadmap R37). That entry imports nothing else, and it has 418 bytes of gzip.
|
|
12
|
+
*/
|
|
13
|
+
/** A change of state that the code reports. It has the fields of a lifecycle event of `@mark1russell7/service`. */
|
|
14
|
+
export interface MachineTransition {
|
|
15
|
+
/** The id of the document. */
|
|
16
|
+
readonly machine: string;
|
|
17
|
+
/** The instance: one connection, one breaker. */
|
|
18
|
+
readonly instance: string;
|
|
19
|
+
readonly from: string;
|
|
20
|
+
readonly on: string;
|
|
21
|
+
readonly to: string;
|
|
22
|
+
/** The time of the clock of the instance, in milliseconds. */
|
|
23
|
+
readonly at: number;
|
|
24
|
+
}
|
|
25
|
+
/** A time of a timer: one knob, in a unit. */
|
|
26
|
+
export interface MachineDuration {
|
|
27
|
+
readonly knob: string;
|
|
28
|
+
readonly unit: string;
|
|
29
|
+
}
|
|
30
|
+
/** A timer of a document: the events that start and stop it, and the event that it gives. */
|
|
31
|
+
export interface MachineTimer {
|
|
32
|
+
readonly duration: MachineDuration;
|
|
33
|
+
readonly arms: readonly string[];
|
|
34
|
+
readonly cancels?: readonly string[] | undefined;
|
|
35
|
+
readonly fires: string;
|
|
36
|
+
/** A timer that starts again after it fires, with a longer wait each time. */
|
|
37
|
+
readonly backoff?: {
|
|
38
|
+
readonly resets: readonly string[];
|
|
39
|
+
} | undefined;
|
|
40
|
+
readonly note?: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
/** A transition of a document. */
|
|
43
|
+
export interface MachineTransitionDef {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly from: string | readonly string[];
|
|
46
|
+
readonly on: string | readonly string[];
|
|
47
|
+
readonly to: string;
|
|
48
|
+
readonly timer?: string | undefined;
|
|
49
|
+
readonly note?: string | undefined;
|
|
50
|
+
}
|
|
51
|
+
/** A machine document: the subset of `mark1russell7.machine/1` that the core uses. */
|
|
52
|
+
export interface MachineDocument {
|
|
53
|
+
readonly format: "mark1russell7.machine/1";
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly title: string;
|
|
56
|
+
readonly layer: "self";
|
|
57
|
+
readonly version: string;
|
|
58
|
+
readonly sources: ReadonlyArray<{
|
|
59
|
+
readonly ref: string;
|
|
60
|
+
readonly rung: "implemented";
|
|
61
|
+
}>;
|
|
62
|
+
readonly states: Readonly<Record<string, {
|
|
63
|
+
readonly initial?: boolean;
|
|
64
|
+
readonly final?: boolean;
|
|
65
|
+
readonly note?: string;
|
|
66
|
+
}>>;
|
|
67
|
+
readonly events: Readonly<Record<string, {
|
|
68
|
+
readonly kind: "rx" | "tx" | "app" | "timer" | "local";
|
|
69
|
+
readonly note?: string;
|
|
70
|
+
}>>;
|
|
71
|
+
readonly knobs: Readonly<Record<string, {
|
|
72
|
+
readonly key: string;
|
|
73
|
+
readonly scope: string;
|
|
74
|
+
readonly unit: string | null;
|
|
75
|
+
readonly default: number | null;
|
|
76
|
+
}>>;
|
|
77
|
+
readonly timers: Readonly<Record<string, MachineTimer>>;
|
|
78
|
+
readonly transitions: readonly MachineTransitionDef[];
|
|
79
|
+
}
|
|
80
|
+
/** The connection of the WebSocket client (`WebSocketTransport`). */
|
|
81
|
+
export declare const WEBSOCKET_CONNECTION_MACHINE: MachineDocument;
|
|
82
|
+
/** The circuit breaker (`createCircuitBreakerMiddleware`). */
|
|
83
|
+
export declare const CIRCUIT_BREAKER_MACHINE: MachineDocument;
|
|
84
|
+
/**
|
|
85
|
+
* This function replays the reported transitions of one document. Each instance starts in the
|
|
86
|
+
* state that its first transition leaves. Each transition must leave the state where the replay
|
|
87
|
+
* is, and the document must allow it. The function gives each disagreement.
|
|
88
|
+
*/
|
|
89
|
+
export declare function replayTransitions(machine: MachineDocument, events: readonly MachineTransition[]): string[];
|
|
90
|
+
//# sourceMappingURL=machines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machines.d.ts","sourceRoot":"","sources":["../src/machines.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,mHAAmH;AACnH,MAAM,WAAW,iBAAiB;IAChC,8BAA8B;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iDAAiD;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;C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