@restatedev/restate-sdk 1.18.0 → 1.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common_api.d.cts.map +1 -1
- package/dist/common_api.d.ts.map +1 -1
- package/dist/context.d.cts +3 -0
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.ts +3 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/context_impl.cjs +8 -3
- package/dist/context_impl.js +8 -3
- package/dist/context_impl.js.map +1 -1
- package/dist/endpoint/connect/env.cjs +208 -0
- package/dist/endpoint/connect/env.js +201 -0
- package/dist/endpoint/connect/env.js.map +1 -0
- package/dist/endpoint/connect/index.cjs +113 -0
- package/dist/endpoint/connect/index.d.cts +41 -0
- package/dist/endpoint/connect/index.d.cts.map +1 -0
- package/dist/endpoint/connect/index.d.ts +41 -0
- package/dist/endpoint/connect/index.d.ts.map +1 -0
- package/dist/endpoint/connect/index.js +114 -0
- package/dist/endpoint/connect/index.js.map +1 -0
- package/dist/endpoint/connect/key.cjs +62 -0
- package/dist/endpoint/connect/key.js +62 -0
- package/dist/endpoint/connect/key.js.map +1 -0
- package/dist/endpoint/tunnel/backoff.cjs +37 -0
- package/dist/endpoint/tunnel/backoff.js +36 -0
- package/dist/endpoint/tunnel/backoff.js.map +1 -0
- package/dist/endpoint/tunnel/connection.cjs +604 -0
- package/dist/endpoint/tunnel/connection.js +600 -0
- package/dist/endpoint/tunnel/connection.js.map +1 -0
- package/dist/endpoint/tunnel/draining.cjs +40 -0
- package/dist/endpoint/tunnel/draining.js +40 -0
- package/dist/endpoint/tunnel/draining.js.map +1 -0
- package/dist/endpoint/tunnel/engine.cjs +264 -0
- package/dist/endpoint/tunnel/engine.d.cts +1 -0
- package/dist/endpoint/tunnel/engine.d.ts +1 -0
- package/dist/endpoint/tunnel/engine.js +265 -0
- package/dist/endpoint/tunnel/engine.js.map +1 -0
- package/dist/endpoint/tunnel/forwarded.cjs +34 -0
- package/dist/endpoint/tunnel/forwarded.js +34 -0
- package/dist/endpoint/tunnel/forwarded.js.map +1 -0
- package/dist/endpoint/tunnel/handshake.cjs +98 -0
- package/dist/endpoint/tunnel/handshake.js +97 -0
- package/dist/endpoint/tunnel/handshake.js.map +1 -0
- package/dist/endpoint/tunnel/index.d.cts +3 -0
- package/dist/endpoint/tunnel/index.d.ts +3 -0
- package/dist/endpoint/tunnel/options.cjs +168 -0
- package/dist/endpoint/tunnel/options.d.cts +2 -0
- package/dist/endpoint/tunnel/options.d.ts +2 -0
- package/dist/endpoint/tunnel/options.js +161 -0
- package/dist/endpoint/tunnel/options.js.map +1 -0
- package/dist/endpoint/tunnel/supervisor.cjs +180 -0
- package/dist/endpoint/tunnel/supervisor.js +181 -0
- package/dist/endpoint/tunnel/supervisor.js.map +1 -0
- package/dist/endpoint/tunnel/targets.cjs +110 -0
- package/dist/endpoint/tunnel/targets.js +107 -0
- package/dist/endpoint/tunnel/targets.js.map +1 -0
- package/dist/endpoint/tunnel/types.d.cts +269 -0
- package/dist/endpoint/tunnel/types.d.cts.map +1 -0
- package/dist/endpoint/tunnel/types.d.ts +269 -0
- package/dist/endpoint/tunnel/types.d.ts.map +1 -0
- package/dist/endpoint/tunnel/util.cjs +67 -0
- package/dist/endpoint/tunnel/util.js +65 -0
- package/dist/endpoint/tunnel/util.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/node.cjs +2 -0
- package/dist/node.d.cts +4 -1
- package/dist/node.d.cts.map +1 -1
- package/dist/node.d.ts +4 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +2 -1
- package/dist/node.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/dist/types/rpc.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { EndpointOptions } from "../types.cjs";
|
|
2
|
+
import { Duration } from "@restatedev/restate-sdk-core";
|
|
3
|
+
|
|
4
|
+
//#region src/endpoint/tunnel/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TLS options for the outbound connection.
|
|
8
|
+
*
|
|
9
|
+
* The connection always offers ALPN `h2` and requires TLS peers to negotiate
|
|
10
|
+
* it; omit these options to use the system trust store and SNI for the dialed
|
|
11
|
+
* host. There is no user-facing ALPN option because the protocol requires
|
|
12
|
+
* HTTP/2.
|
|
13
|
+
*/
|
|
14
|
+
interface ConnectTlsOptions {
|
|
15
|
+
/**
|
|
16
|
+
* CA certificate(s) (PEM) to trust. Omit to use the system trust store —
|
|
17
|
+
* the right choice for Restate Cloud's public endpoints.
|
|
18
|
+
*/
|
|
19
|
+
ca?: string | Buffer | Array<string | Buffer>;
|
|
20
|
+
/** Client certificate (PEM) for mutual TLS. */
|
|
21
|
+
cert?: string | Buffer;
|
|
22
|
+
/** Client key (PEM) for mutual TLS. */
|
|
23
|
+
key?: string | Buffer;
|
|
24
|
+
/**
|
|
25
|
+
* SNI / certificate-verification name. Defaults to the hostname being
|
|
26
|
+
* dialed (for DNS SRV discovery, the SRV target hostname).
|
|
27
|
+
*/
|
|
28
|
+
servername?: string;
|
|
29
|
+
/** Verify the server certificate. Default true. */
|
|
30
|
+
rejectUnauthorized?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reconnect retry policy, the same shape as the invocation and client retry
|
|
34
|
+
* policies: a jittered exponential backoff between attempts, reset after a
|
|
35
|
+
* connection stays up long enough to count as stable. Intervals accept a
|
|
36
|
+
* {@link Duration} or a number of milliseconds.
|
|
37
|
+
*
|
|
38
|
+
* Unlike those policies the reconnect loop is unbounded by default — a
|
|
39
|
+
* deployment keeps trying until Restate Cloud is reachable again — so
|
|
40
|
+
* {@link maxAttempts} and {@link maxDuration} default to `false`. A bound is
|
|
41
|
+
* counted per server (and for DNS discovery itself); reaching it stops the
|
|
42
|
+
* deployment only when no other connection is alive, otherwise that server
|
|
43
|
+
* is dropped until discovery brings it back.
|
|
44
|
+
*/
|
|
45
|
+
interface ReconnectRetryPolicy {
|
|
46
|
+
/**
|
|
47
|
+
* Max number of attempts (including the initial) in a row without a stable
|
|
48
|
+
* connection, before giving up. Giving up is a non-retryable stop: the
|
|
49
|
+
* connection's `ready`, `close()` and `shutdown()` reject with the reason.
|
|
50
|
+
*
|
|
51
|
+
* Defaults to `false`: no attempt bound.
|
|
52
|
+
*/
|
|
53
|
+
maxAttempts?: number | false;
|
|
54
|
+
/**
|
|
55
|
+
* Max total duration without a stable connection, measured from the first
|
|
56
|
+
* failed attempt, before giving up. If a number is provided, it is
|
|
57
|
+
* interpreted as milliseconds.
|
|
58
|
+
*
|
|
59
|
+
* Defaults to `false`: no duration bound.
|
|
60
|
+
*/
|
|
61
|
+
maxDuration?: Duration | number | false;
|
|
62
|
+
/**
|
|
63
|
+
* Initial backoff interval. If a number is provided, it is interpreted as
|
|
64
|
+
* milliseconds. Defaults to `10` milliseconds.
|
|
65
|
+
*/
|
|
66
|
+
initialInterval?: Duration | number;
|
|
67
|
+
/**
|
|
68
|
+
* Maximum backoff interval. If a number is provided, it is interpreted as
|
|
69
|
+
* milliseconds. Defaults to `120_000` milliseconds.
|
|
70
|
+
*/
|
|
71
|
+
maxInterval?: Duration | number;
|
|
72
|
+
/**
|
|
73
|
+
* Exponentiation factor to use when computing the next retry delay.
|
|
74
|
+
* Defaults to `2`.
|
|
75
|
+
*/
|
|
76
|
+
exponentiationFactor?: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Options for {@link connect}.
|
|
80
|
+
*
|
|
81
|
+
* A usual connect setup requires 3 configuration options:
|
|
82
|
+
*
|
|
83
|
+
* * The `services` to expose
|
|
84
|
+
* * The {@link name} (or env `RESTATE_CONNECT_NAME`) of the deployment, used to identify this version of the code.
|
|
85
|
+
* * The {@link key} (or `RESTATE_CONNECT_KEY`) required to connect to Restate Cloud/BYOC
|
|
86
|
+
*/
|
|
87
|
+
interface ConnectOptions extends EndpointOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Required: The deployment name, e.g. `"greeter-v1"`: the identity you register
|
|
90
|
+
* (`restate deployments register connect://<name>`). Restate Cloud/BYOC routes by
|
|
91
|
+
* `<environment>/<name>` and load-balances across every connection under
|
|
92
|
+
* it, so replicas of the same deployment share one name and distinct
|
|
93
|
+
* deployments each have their own. Letters, digits, `.`, `_` and `-`.
|
|
94
|
+
*
|
|
95
|
+
* Also configurable via env `RESTATE_CONNECT_NAME`.
|
|
96
|
+
*/
|
|
97
|
+
name?: string;
|
|
98
|
+
/**
|
|
99
|
+
* The connect key from the Cloud UI -> Development → Configure SDK.
|
|
100
|
+
*
|
|
101
|
+
* Also configurable via env `RESTATE_CONNECT_KEY`.
|
|
102
|
+
*/
|
|
103
|
+
key?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Advanced connection options.
|
|
106
|
+
*/
|
|
107
|
+
connection?: ConnectionOptions;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The {@link ConnectOptions.connection} tuning: server discovery, the worker
|
|
111
|
+
* id, reconnect and drain behaviour, HTTP/2 limits, TLS. Every option has a
|
|
112
|
+
* default that fits Restate Cloud; most deployments set none of them.
|
|
113
|
+
*/
|
|
114
|
+
interface ConnectionOptions {
|
|
115
|
+
/**
|
|
116
|
+
* A DNS SRV name to discover the servers to connect to, instead of the one
|
|
117
|
+
* the connect key stands for. For environments with a custom domain; rarely
|
|
118
|
+
* set by hand. Servers are
|
|
119
|
+
* discovered via a DNS SRV lookup expanded to every resolved address — the
|
|
120
|
+
* engine holds **one connection per resolved server** and re-resolves every
|
|
121
|
+
* {@link resolveIntervalMs}, starting connections to
|
|
122
|
+
* servers that appear and tearing down connections to servers that vanish.
|
|
123
|
+
*
|
|
124
|
+
* At most one of `serversSrv` and `servers` may be set.
|
|
125
|
+
*/
|
|
126
|
+
serversSrv?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Explicit server addresses, instead of DNS discovery. Each entry is either
|
|
129
|
+
* `"host:port"` (TLS governed by the `tls` option) or a URL
|
|
130
|
+
* `"https://host:port"` / `"http://host:port"` (scheme selects TLS/plaintext
|
|
131
|
+
* for that server). One connection per entry; the set is fixed (no
|
|
132
|
+
* re-resolution). Private networks and tests.
|
|
133
|
+
*
|
|
134
|
+
* At most one of `serversSrv` and `servers` may be set.
|
|
135
|
+
*/
|
|
136
|
+
servers?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* Stable diagnostic identifier for this SDK worker/process. Restate Cloud
|
|
139
|
+
* can include it in routing and failure logs so operators can grep
|
|
140
|
+
* server-side events against SDK-side logs. Defaults to a hostname-based
|
|
141
|
+
* id with a short random suffix that is stable for this process. Advisory
|
|
142
|
+
* only: it is sent in the handshake for diagnostics, not used for
|
|
143
|
+
* authentication.
|
|
144
|
+
*/
|
|
145
|
+
workerId?: string;
|
|
146
|
+
/**
|
|
147
|
+
* How often DNS SRV discovery re-resolves the server set. Default 30_000.
|
|
148
|
+
* (The Rust client re-resolves on DNS TTL expiry; Node does not expose
|
|
149
|
+
* record TTLs, so a fixed interval approximates it.) Ignored with explicit
|
|
150
|
+
* server addresses.
|
|
151
|
+
*/
|
|
152
|
+
resolveIntervalMs?: number;
|
|
153
|
+
/**
|
|
154
|
+
* How long a draining connection may keep serving its in-flight
|
|
155
|
+
* invocations before being torn down. Default 120_000.
|
|
156
|
+
*/
|
|
157
|
+
drainGraceMs?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Automatic graceful shutdown on process signals. **On by default**: the
|
|
160
|
+
* engine installs a one-shot handler for each signal (default `SIGTERM`)
|
|
161
|
+
* that calls `shutdown()`. If multiple connections in the same process
|
|
162
|
+
* register for a signal, the shared process-level handler waits for all of
|
|
163
|
+
* them before calling `process.exit(0)` once draining completes (or the
|
|
164
|
+
* grace elapses) — so an operator-managed deployment gets
|
|
165
|
+
* zero-dropped-invocation rollouts with no wiring. In Kubernetes, set
|
|
166
|
+
* `terminationGracePeriodSeconds` to at least the drain grace plus the
|
|
167
|
+
* handler slack you want to preserve. The handlers are removed when the
|
|
168
|
+
* connection closes.
|
|
169
|
+
*
|
|
170
|
+
* Pass `false` to opt out entirely — e.g. to manage signals and process
|
|
171
|
+
* exit yourself and call `shutdown()` by hand. Pass an object to choose the
|
|
172
|
+
* signals and grace, or `true` for the defaults.
|
|
173
|
+
*/
|
|
174
|
+
gracefulShutdown?: boolean | {
|
|
175
|
+
signals?: NodeJS.Signals[];
|
|
176
|
+
graceMs?: number;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Reconnect backoff policy: jittered exponential backoff applied between
|
|
180
|
+
* reconnect attempts (10ms → 120s by default), reset after a stable
|
|
181
|
+
* connection. See {@link ReconnectRetryPolicy}.
|
|
182
|
+
*/
|
|
183
|
+
reconnectRetryPolicy?: ReconnectRetryPolicy;
|
|
184
|
+
/**
|
|
185
|
+
* Deadline for establishing the TCP connection and completing the TLS
|
|
186
|
+
* handshake. Default 5_000. Without it, a peer that accepts the connection
|
|
187
|
+
* but never completes TLS would stall reconnection indefinitely.
|
|
188
|
+
*/
|
|
189
|
+
connectTimeoutMs?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Deadline for the handshake with Restate Cloud. Default 5_000, mirroring
|
|
192
|
+
* the server's own handshake timeout.
|
|
193
|
+
*/
|
|
194
|
+
handshakeTimeoutMs?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Liveness watchdog: send an HTTP/2 PING every this many milliseconds.
|
|
197
|
+
* Default 75_000.
|
|
198
|
+
*/
|
|
199
|
+
pingIntervalMs?: number;
|
|
200
|
+
/** Watchdog: how long to wait for a PING ack. Default 10_000. */
|
|
201
|
+
pingTimeoutMs?: number;
|
|
202
|
+
/**
|
|
203
|
+
* Watchdog: consecutive missed PINGs before the connection is declared
|
|
204
|
+
* dead and redialed. Default 2.
|
|
205
|
+
*/
|
|
206
|
+
pingMaxMissed?: number;
|
|
207
|
+
/**
|
|
208
|
+
* Maximum concurrent HTTP/2 streams (in-flight invocations) per
|
|
209
|
+
* connection. Default 4096 (Node's default of 100 is far too low for a
|
|
210
|
+
* deployment serving many concurrent invocations).
|
|
211
|
+
*/
|
|
212
|
+
maxConcurrentStreams?: number;
|
|
213
|
+
/**
|
|
214
|
+
* Per-connection HTTP/2 flow-control window in bytes. Default 16 MiB
|
|
215
|
+
* (Node's 64 KiB default throttles aggregate throughput).
|
|
216
|
+
*/
|
|
217
|
+
connectionWindowSize?: number;
|
|
218
|
+
/**
|
|
219
|
+
* Node http2 per-session memory cap in MiB. Default 256 (Node's 10 MiB
|
|
220
|
+
* default makes the session reject work under load).
|
|
221
|
+
*/
|
|
222
|
+
maxSessionMemory?: number;
|
|
223
|
+
/**
|
|
224
|
+
* TLS for the outbound connection. Default `true` (system trust, SNI =
|
|
225
|
+
* dialed host, ALPN `h2`). Pass `false` only for plaintext dev/test setups,
|
|
226
|
+
* or an object for a private CA / mTLS.
|
|
227
|
+
*/
|
|
228
|
+
tls?: boolean | ConnectTlsOptions;
|
|
229
|
+
/** Abort to stop reconnecting and close the connection (same as `close()`). */
|
|
230
|
+
signal?: AbortSignal;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Handle returned by {@link connect}: the outbound connection to Restate
|
|
234
|
+
* Cloud serving your services.
|
|
235
|
+
*/
|
|
236
|
+
interface Connection {
|
|
237
|
+
/**
|
|
238
|
+
* Resolves when the first handshake succeeds (the deployment is reachable
|
|
239
|
+
* from Restate Cloud and can be registered); rejects if the connection
|
|
240
|
+
* stops on a non-retryable failure before ever connecting. Useful for
|
|
241
|
+
* readiness checks; safe to ignore.
|
|
242
|
+
*/
|
|
243
|
+
readonly ready: Promise<void>;
|
|
244
|
+
/** The deployment name, as configured. */
|
|
245
|
+
readonly name: string;
|
|
246
|
+
/**
|
|
247
|
+
* Stop reconnecting, close the current connections, and wait for teardown.
|
|
248
|
+
* Rejects with the fatal error if the connection had already stopped on a
|
|
249
|
+
* non-retryable failure (e.g. Restate Cloud rejected the key or the name).
|
|
250
|
+
*/
|
|
251
|
+
close(): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Gracefully drain, then stop. Proactively sends HTTP/2 GOAWAY so Restate
|
|
254
|
+
* Cloud stops opening new streams, refuses any raced streams with a drain
|
|
255
|
+
* sentinel, lets in-flight invocations finish — bounded by `graceMs`
|
|
256
|
+
* (default {@link ConnectionOptions.drainGraceMs}) — and then closes the
|
|
257
|
+
* session gracefully. If the grace elapses first, the session/socket are
|
|
258
|
+
* force-closed. The default {@link ConnectionOptions.gracefulShutdown}
|
|
259
|
+
* handler wires this to `SIGTERM`; {@link close} is the abrupt alternative.
|
|
260
|
+
* Rejects like {@link close} if the connection had already stopped on a
|
|
261
|
+
* non-retryable failure.
|
|
262
|
+
*/
|
|
263
|
+
shutdown(opts?: {
|
|
264
|
+
graceMs?: number;
|
|
265
|
+
}): Promise<void>;
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
export { ConnectOptions, ConnectTlsOptions, Connection, ConnectionOptions, ReconnectRetryPolicy };
|
|
269
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../../src/endpoint/tunnel/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAwBA;;;;;;AASuB,UATN,iBAAA,CASM;EAuBN;;;;EA0BO,EAAA,CAAA,EAAA,MAAA,GArDR,MAqDQ,GArDC,KAqDD,CAAA,MAAA,GArDgB,MAqDhB,CAAA;EAiBP;EA4BA,IAAA,CAAA,EAAA,MAAA,GAhGC,MAgGgB;EA4DS;EAMlB,GAAA,CAAA,EAAA,MAAA,GAhKR,MAgKQ;EA6CP;;;AASlB;EAOkB,UAAA,CAAA,EAAA,MAAA;EAQP;EAY8B,kBAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;UA1NxB,oBAAA;;;;;;;;;;;;;;;;gBAgBD;;;;;oBAKI;;;;;gBAKJ;;;;;;;;;;;;;;;;UAiBC,cAAA,SAAuB;;;;;;;;;;;;;;;;;;;;eAoBzB;;;;;;;UAQE,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4D0B,MAAA,CAAO;;;;;;;;yBAMzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA6CP;;WAEP;;;;;;UAOM,UAAA;;;;;;;kBAOC;;;;;;;;WAQP;;;;;;;;;;;;;;MAY8B"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { EndpointOptions } from "../types.js";
|
|
2
|
+
import { Duration } from "@restatedev/restate-sdk-core";
|
|
3
|
+
|
|
4
|
+
//#region src/endpoint/tunnel/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TLS options for the outbound connection.
|
|
8
|
+
*
|
|
9
|
+
* The connection always offers ALPN `h2` and requires TLS peers to negotiate
|
|
10
|
+
* it; omit these options to use the system trust store and SNI for the dialed
|
|
11
|
+
* host. There is no user-facing ALPN option because the protocol requires
|
|
12
|
+
* HTTP/2.
|
|
13
|
+
*/
|
|
14
|
+
interface ConnectTlsOptions {
|
|
15
|
+
/**
|
|
16
|
+
* CA certificate(s) (PEM) to trust. Omit to use the system trust store —
|
|
17
|
+
* the right choice for Restate Cloud's public endpoints.
|
|
18
|
+
*/
|
|
19
|
+
ca?: string | Buffer | Array<string | Buffer>;
|
|
20
|
+
/** Client certificate (PEM) for mutual TLS. */
|
|
21
|
+
cert?: string | Buffer;
|
|
22
|
+
/** Client key (PEM) for mutual TLS. */
|
|
23
|
+
key?: string | Buffer;
|
|
24
|
+
/**
|
|
25
|
+
* SNI / certificate-verification name. Defaults to the hostname being
|
|
26
|
+
* dialed (for DNS SRV discovery, the SRV target hostname).
|
|
27
|
+
*/
|
|
28
|
+
servername?: string;
|
|
29
|
+
/** Verify the server certificate. Default true. */
|
|
30
|
+
rejectUnauthorized?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reconnect retry policy, the same shape as the invocation and client retry
|
|
34
|
+
* policies: a jittered exponential backoff between attempts, reset after a
|
|
35
|
+
* connection stays up long enough to count as stable. Intervals accept a
|
|
36
|
+
* {@link Duration} or a number of milliseconds.
|
|
37
|
+
*
|
|
38
|
+
* Unlike those policies the reconnect loop is unbounded by default — a
|
|
39
|
+
* deployment keeps trying until Restate Cloud is reachable again — so
|
|
40
|
+
* {@link maxAttempts} and {@link maxDuration} default to `false`. A bound is
|
|
41
|
+
* counted per server (and for DNS discovery itself); reaching it stops the
|
|
42
|
+
* deployment only when no other connection is alive, otherwise that server
|
|
43
|
+
* is dropped until discovery brings it back.
|
|
44
|
+
*/
|
|
45
|
+
interface ReconnectRetryPolicy {
|
|
46
|
+
/**
|
|
47
|
+
* Max number of attempts (including the initial) in a row without a stable
|
|
48
|
+
* connection, before giving up. Giving up is a non-retryable stop: the
|
|
49
|
+
* connection's `ready`, `close()` and `shutdown()` reject with the reason.
|
|
50
|
+
*
|
|
51
|
+
* Defaults to `false`: no attempt bound.
|
|
52
|
+
*/
|
|
53
|
+
maxAttempts?: number | false;
|
|
54
|
+
/**
|
|
55
|
+
* Max total duration without a stable connection, measured from the first
|
|
56
|
+
* failed attempt, before giving up. If a number is provided, it is
|
|
57
|
+
* interpreted as milliseconds.
|
|
58
|
+
*
|
|
59
|
+
* Defaults to `false`: no duration bound.
|
|
60
|
+
*/
|
|
61
|
+
maxDuration?: Duration | number | false;
|
|
62
|
+
/**
|
|
63
|
+
* Initial backoff interval. If a number is provided, it is interpreted as
|
|
64
|
+
* milliseconds. Defaults to `10` milliseconds.
|
|
65
|
+
*/
|
|
66
|
+
initialInterval?: Duration | number;
|
|
67
|
+
/**
|
|
68
|
+
* Maximum backoff interval. If a number is provided, it is interpreted as
|
|
69
|
+
* milliseconds. Defaults to `120_000` milliseconds.
|
|
70
|
+
*/
|
|
71
|
+
maxInterval?: Duration | number;
|
|
72
|
+
/**
|
|
73
|
+
* Exponentiation factor to use when computing the next retry delay.
|
|
74
|
+
* Defaults to `2`.
|
|
75
|
+
*/
|
|
76
|
+
exponentiationFactor?: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Options for {@link connect}.
|
|
80
|
+
*
|
|
81
|
+
* A usual connect setup requires 3 configuration options:
|
|
82
|
+
*
|
|
83
|
+
* * The `services` to expose
|
|
84
|
+
* * The {@link name} (or env `RESTATE_CONNECT_NAME`) of the deployment, used to identify this version of the code.
|
|
85
|
+
* * The {@link key} (or `RESTATE_CONNECT_KEY`) required to connect to Restate Cloud/BYOC
|
|
86
|
+
*/
|
|
87
|
+
interface ConnectOptions extends EndpointOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Required: The deployment name, e.g. `"greeter-v1"`: the identity you register
|
|
90
|
+
* (`restate deployments register connect://<name>`). Restate Cloud/BYOC routes by
|
|
91
|
+
* `<environment>/<name>` and load-balances across every connection under
|
|
92
|
+
* it, so replicas of the same deployment share one name and distinct
|
|
93
|
+
* deployments each have their own. Letters, digits, `.`, `_` and `-`.
|
|
94
|
+
*
|
|
95
|
+
* Also configurable via env `RESTATE_CONNECT_NAME`.
|
|
96
|
+
*/
|
|
97
|
+
name?: string;
|
|
98
|
+
/**
|
|
99
|
+
* The connect key from the Cloud UI -> Development → Configure SDK.
|
|
100
|
+
*
|
|
101
|
+
* Also configurable via env `RESTATE_CONNECT_KEY`.
|
|
102
|
+
*/
|
|
103
|
+
key?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Advanced connection options.
|
|
106
|
+
*/
|
|
107
|
+
connection?: ConnectionOptions;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The {@link ConnectOptions.connection} tuning: server discovery, the worker
|
|
111
|
+
* id, reconnect and drain behaviour, HTTP/2 limits, TLS. Every option has a
|
|
112
|
+
* default that fits Restate Cloud; most deployments set none of them.
|
|
113
|
+
*/
|
|
114
|
+
interface ConnectionOptions {
|
|
115
|
+
/**
|
|
116
|
+
* A DNS SRV name to discover the servers to connect to, instead of the one
|
|
117
|
+
* the connect key stands for. For environments with a custom domain; rarely
|
|
118
|
+
* set by hand. Servers are
|
|
119
|
+
* discovered via a DNS SRV lookup expanded to every resolved address — the
|
|
120
|
+
* engine holds **one connection per resolved server** and re-resolves every
|
|
121
|
+
* {@link resolveIntervalMs}, starting connections to
|
|
122
|
+
* servers that appear and tearing down connections to servers that vanish.
|
|
123
|
+
*
|
|
124
|
+
* At most one of `serversSrv` and `servers` may be set.
|
|
125
|
+
*/
|
|
126
|
+
serversSrv?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Explicit server addresses, instead of DNS discovery. Each entry is either
|
|
129
|
+
* `"host:port"` (TLS governed by the `tls` option) or a URL
|
|
130
|
+
* `"https://host:port"` / `"http://host:port"` (scheme selects TLS/plaintext
|
|
131
|
+
* for that server). One connection per entry; the set is fixed (no
|
|
132
|
+
* re-resolution). Private networks and tests.
|
|
133
|
+
*
|
|
134
|
+
* At most one of `serversSrv` and `servers` may be set.
|
|
135
|
+
*/
|
|
136
|
+
servers?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* Stable diagnostic identifier for this SDK worker/process. Restate Cloud
|
|
139
|
+
* can include it in routing and failure logs so operators can grep
|
|
140
|
+
* server-side events against SDK-side logs. Defaults to a hostname-based
|
|
141
|
+
* id with a short random suffix that is stable for this process. Advisory
|
|
142
|
+
* only: it is sent in the handshake for diagnostics, not used for
|
|
143
|
+
* authentication.
|
|
144
|
+
*/
|
|
145
|
+
workerId?: string;
|
|
146
|
+
/**
|
|
147
|
+
* How often DNS SRV discovery re-resolves the server set. Default 30_000.
|
|
148
|
+
* (The Rust client re-resolves on DNS TTL expiry; Node does not expose
|
|
149
|
+
* record TTLs, so a fixed interval approximates it.) Ignored with explicit
|
|
150
|
+
* server addresses.
|
|
151
|
+
*/
|
|
152
|
+
resolveIntervalMs?: number;
|
|
153
|
+
/**
|
|
154
|
+
* How long a draining connection may keep serving its in-flight
|
|
155
|
+
* invocations before being torn down. Default 120_000.
|
|
156
|
+
*/
|
|
157
|
+
drainGraceMs?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Automatic graceful shutdown on process signals. **On by default**: the
|
|
160
|
+
* engine installs a one-shot handler for each signal (default `SIGTERM`)
|
|
161
|
+
* that calls `shutdown()`. If multiple connections in the same process
|
|
162
|
+
* register for a signal, the shared process-level handler waits for all of
|
|
163
|
+
* them before calling `process.exit(0)` once draining completes (or the
|
|
164
|
+
* grace elapses) — so an operator-managed deployment gets
|
|
165
|
+
* zero-dropped-invocation rollouts with no wiring. In Kubernetes, set
|
|
166
|
+
* `terminationGracePeriodSeconds` to at least the drain grace plus the
|
|
167
|
+
* handler slack you want to preserve. The handlers are removed when the
|
|
168
|
+
* connection closes.
|
|
169
|
+
*
|
|
170
|
+
* Pass `false` to opt out entirely — e.g. to manage signals and process
|
|
171
|
+
* exit yourself and call `shutdown()` by hand. Pass an object to choose the
|
|
172
|
+
* signals and grace, or `true` for the defaults.
|
|
173
|
+
*/
|
|
174
|
+
gracefulShutdown?: boolean | {
|
|
175
|
+
signals?: NodeJS.Signals[];
|
|
176
|
+
graceMs?: number;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Reconnect backoff policy: jittered exponential backoff applied between
|
|
180
|
+
* reconnect attempts (10ms → 120s by default), reset after a stable
|
|
181
|
+
* connection. See {@link ReconnectRetryPolicy}.
|
|
182
|
+
*/
|
|
183
|
+
reconnectRetryPolicy?: ReconnectRetryPolicy;
|
|
184
|
+
/**
|
|
185
|
+
* Deadline for establishing the TCP connection and completing the TLS
|
|
186
|
+
* handshake. Default 5_000. Without it, a peer that accepts the connection
|
|
187
|
+
* but never completes TLS would stall reconnection indefinitely.
|
|
188
|
+
*/
|
|
189
|
+
connectTimeoutMs?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Deadline for the handshake with Restate Cloud. Default 5_000, mirroring
|
|
192
|
+
* the server's own handshake timeout.
|
|
193
|
+
*/
|
|
194
|
+
handshakeTimeoutMs?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Liveness watchdog: send an HTTP/2 PING every this many milliseconds.
|
|
197
|
+
* Default 75_000.
|
|
198
|
+
*/
|
|
199
|
+
pingIntervalMs?: number;
|
|
200
|
+
/** Watchdog: how long to wait for a PING ack. Default 10_000. */
|
|
201
|
+
pingTimeoutMs?: number;
|
|
202
|
+
/**
|
|
203
|
+
* Watchdog: consecutive missed PINGs before the connection is declared
|
|
204
|
+
* dead and redialed. Default 2.
|
|
205
|
+
*/
|
|
206
|
+
pingMaxMissed?: number;
|
|
207
|
+
/**
|
|
208
|
+
* Maximum concurrent HTTP/2 streams (in-flight invocations) per
|
|
209
|
+
* connection. Default 4096 (Node's default of 100 is far too low for a
|
|
210
|
+
* deployment serving many concurrent invocations).
|
|
211
|
+
*/
|
|
212
|
+
maxConcurrentStreams?: number;
|
|
213
|
+
/**
|
|
214
|
+
* Per-connection HTTP/2 flow-control window in bytes. Default 16 MiB
|
|
215
|
+
* (Node's 64 KiB default throttles aggregate throughput).
|
|
216
|
+
*/
|
|
217
|
+
connectionWindowSize?: number;
|
|
218
|
+
/**
|
|
219
|
+
* Node http2 per-session memory cap in MiB. Default 256 (Node's 10 MiB
|
|
220
|
+
* default makes the session reject work under load).
|
|
221
|
+
*/
|
|
222
|
+
maxSessionMemory?: number;
|
|
223
|
+
/**
|
|
224
|
+
* TLS for the outbound connection. Default `true` (system trust, SNI =
|
|
225
|
+
* dialed host, ALPN `h2`). Pass `false` only for plaintext dev/test setups,
|
|
226
|
+
* or an object for a private CA / mTLS.
|
|
227
|
+
*/
|
|
228
|
+
tls?: boolean | ConnectTlsOptions;
|
|
229
|
+
/** Abort to stop reconnecting and close the connection (same as `close()`). */
|
|
230
|
+
signal?: AbortSignal;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Handle returned by {@link connect}: the outbound connection to Restate
|
|
234
|
+
* Cloud serving your services.
|
|
235
|
+
*/
|
|
236
|
+
interface Connection {
|
|
237
|
+
/**
|
|
238
|
+
* Resolves when the first handshake succeeds (the deployment is reachable
|
|
239
|
+
* from Restate Cloud and can be registered); rejects if the connection
|
|
240
|
+
* stops on a non-retryable failure before ever connecting. Useful for
|
|
241
|
+
* readiness checks; safe to ignore.
|
|
242
|
+
*/
|
|
243
|
+
readonly ready: Promise<void>;
|
|
244
|
+
/** The deployment name, as configured. */
|
|
245
|
+
readonly name: string;
|
|
246
|
+
/**
|
|
247
|
+
* Stop reconnecting, close the current connections, and wait for teardown.
|
|
248
|
+
* Rejects with the fatal error if the connection had already stopped on a
|
|
249
|
+
* non-retryable failure (e.g. Restate Cloud rejected the key or the name).
|
|
250
|
+
*/
|
|
251
|
+
close(): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Gracefully drain, then stop. Proactively sends HTTP/2 GOAWAY so Restate
|
|
254
|
+
* Cloud stops opening new streams, refuses any raced streams with a drain
|
|
255
|
+
* sentinel, lets in-flight invocations finish — bounded by `graceMs`
|
|
256
|
+
* (default {@link ConnectionOptions.drainGraceMs}) — and then closes the
|
|
257
|
+
* session gracefully. If the grace elapses first, the session/socket are
|
|
258
|
+
* force-closed. The default {@link ConnectionOptions.gracefulShutdown}
|
|
259
|
+
* handler wires this to `SIGTERM`; {@link close} is the abrupt alternative.
|
|
260
|
+
* Rejects like {@link close} if the connection had already stopped on a
|
|
261
|
+
* non-retryable failure.
|
|
262
|
+
*/
|
|
263
|
+
shutdown(opts?: {
|
|
264
|
+
graceMs?: number;
|
|
265
|
+
}): Promise<void>;
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
export { ConnectOptions, ConnectTlsOptions, Connection, ConnectionOptions, ReconnectRetryPolicy };
|
|
269
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/endpoint/tunnel/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAwBA;;;;;;AASuB,UATN,iBAAA,CASM;EAuBN;;;;EA0BO,EAAA,CAAA,EAAA,MAAA,GArDR,MAqDQ,GArDC,KAqDD,CAAA,MAAA,GArDgB,MAqDhB,CAAA;EAiBP;EA4BA,IAAA,CAAA,EAAA,MAAA,GAhGC,MAgGgB;EA4DS;EAMlB,GAAA,CAAA,EAAA,MAAA,GAhKR,MAgKQ;EA6CP;;;AASlB;EAOkB,UAAA,CAAA,EAAA,MAAA;EAQP;EAY8B,kBAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;UA1NxB,oBAAA;;;;;;;;;;;;;;;;gBAgBD;;;;;oBAKI;;;;;gBAKJ;;;;;;;;;;;;;;;;UAiBC,cAAA,SAAuB;;;;;;;;;;;;;;;;;;;;eAoBzB;;;;;;;UAQE,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4D0B,MAAA,CAAO;;;;;;;;yBAMzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA6CP;;WAEP;;;;;;UAOM,UAAA;;;;;;;kBAOC;;;;;;;;WAQP;;;;;;;;;;;;;;MAY8B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/endpoint/tunnel/util.ts
|
|
3
|
+
/** Sleep that wakes early (resolving) when the signal aborts. */
|
|
4
|
+
function delay(ms, signal) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
if (signal.aborted) {
|
|
7
|
+
resolve();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const t = setTimeout(() => {
|
|
11
|
+
signal.removeEventListener("abort", onAbort);
|
|
12
|
+
resolve();
|
|
13
|
+
}, ms);
|
|
14
|
+
const onAbort = () => {
|
|
15
|
+
clearTimeout(t);
|
|
16
|
+
resolve();
|
|
17
|
+
};
|
|
18
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Race a promise against a signal: resolves `null` the moment the signal
|
|
23
|
+
* aborts, otherwise passes the promise's result through (rejections
|
|
24
|
+
* propagate). The abort listener is removed when the race settles, so
|
|
25
|
+
* repeated calls against a long-lived signal don't accumulate listeners.
|
|
26
|
+
*/
|
|
27
|
+
async function raceAbortable(promise, signal) {
|
|
28
|
+
if (signal.aborted) return null;
|
|
29
|
+
let onAbort;
|
|
30
|
+
const aborted = new Promise((resolve) => {
|
|
31
|
+
onAbort = () => resolve(null);
|
|
32
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
return await Promise.race([promise, aborted]);
|
|
36
|
+
} finally {
|
|
37
|
+
signal.removeEventListener("abort", onAbort);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** A promise whose resolve/reject are exposed and fire at most once. */
|
|
41
|
+
var Deferred = class {
|
|
42
|
+
settled = false;
|
|
43
|
+
promise;
|
|
44
|
+
resolveFn;
|
|
45
|
+
rejectFn;
|
|
46
|
+
constructor() {
|
|
47
|
+
this.promise = new Promise((resolve, reject) => {
|
|
48
|
+
this.resolveFn = resolve;
|
|
49
|
+
this.rejectFn = reject;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
resolve(value) {
|
|
53
|
+
if (this.settled) return;
|
|
54
|
+
this.settled = true;
|
|
55
|
+
this.resolveFn(value);
|
|
56
|
+
}
|
|
57
|
+
reject(err) {
|
|
58
|
+
if (this.settled) return;
|
|
59
|
+
this.settled = true;
|
|
60
|
+
this.rejectFn(err);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.Deferred = Deferred;
|
|
66
|
+
exports.delay = delay;
|
|
67
|
+
exports.raceAbortable = raceAbortable;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//#region src/endpoint/tunnel/util.ts
|
|
2
|
+
/** Sleep that wakes early (resolving) when the signal aborts. */
|
|
3
|
+
function delay(ms, signal) {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
if (signal.aborted) {
|
|
6
|
+
resolve();
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const t = setTimeout(() => {
|
|
10
|
+
signal.removeEventListener("abort", onAbort);
|
|
11
|
+
resolve();
|
|
12
|
+
}, ms);
|
|
13
|
+
const onAbort = () => {
|
|
14
|
+
clearTimeout(t);
|
|
15
|
+
resolve();
|
|
16
|
+
};
|
|
17
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Race a promise against a signal: resolves `null` the moment the signal
|
|
22
|
+
* aborts, otherwise passes the promise's result through (rejections
|
|
23
|
+
* propagate). The abort listener is removed when the race settles, so
|
|
24
|
+
* repeated calls against a long-lived signal don't accumulate listeners.
|
|
25
|
+
*/
|
|
26
|
+
async function raceAbortable(promise, signal) {
|
|
27
|
+
if (signal.aborted) return null;
|
|
28
|
+
let onAbort;
|
|
29
|
+
const aborted = new Promise((resolve) => {
|
|
30
|
+
onAbort = () => resolve(null);
|
|
31
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
32
|
+
});
|
|
33
|
+
try {
|
|
34
|
+
return await Promise.race([promise, aborted]);
|
|
35
|
+
} finally {
|
|
36
|
+
signal.removeEventListener("abort", onAbort);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** A promise whose resolve/reject are exposed and fire at most once. */
|
|
40
|
+
var Deferred = class {
|
|
41
|
+
settled = false;
|
|
42
|
+
promise;
|
|
43
|
+
resolveFn;
|
|
44
|
+
rejectFn;
|
|
45
|
+
constructor() {
|
|
46
|
+
this.promise = new Promise((resolve, reject) => {
|
|
47
|
+
this.resolveFn = resolve;
|
|
48
|
+
this.rejectFn = reject;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
resolve(value) {
|
|
52
|
+
if (this.settled) return;
|
|
53
|
+
this.settled = true;
|
|
54
|
+
this.resolveFn(value);
|
|
55
|
+
}
|
|
56
|
+
reject(err) {
|
|
57
|
+
if (this.settled) return;
|
|
58
|
+
this.settled = true;
|
|
59
|
+
this.rejectFn(err);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { Deferred, delay, raceAbortable };
|
|
65
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","names":["onAbort!: () => void"],"sources":["../../../src/endpoint/tunnel/util.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2026 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\n// Small abort-aware async utilities shared by the engine.\n\n/** Sleep that wakes early (resolving) when the signal aborts. */\nexport function delay(ms: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve) => {\n if (signal.aborted) {\n resolve();\n return;\n }\n const t = setTimeout(() => {\n signal.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(t);\n resolve();\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\n/**\n * Race a promise against a signal: resolves `null` the moment the signal\n * aborts, otherwise passes the promise's result through (rejections\n * propagate). The abort listener is removed when the race settles, so\n * repeated calls against a long-lived signal don't accumulate listeners.\n */\nexport async function raceAbortable<T>(\n promise: Promise<T>,\n signal: AbortSignal\n): Promise<T | null> {\n if (signal.aborted) return null;\n let onAbort!: () => void;\n const aborted = new Promise<null>((resolve) => {\n onAbort = () => resolve(null);\n signal.addEventListener(\"abort\", onAbort, { once: true });\n });\n try {\n return await Promise.race([promise, aborted]);\n } finally {\n signal.removeEventListener(\"abort\", onAbort);\n }\n}\n\n// TODO replace with Promise.withResolvers\n/** A promise whose resolve/reject are exposed and fire at most once. */\nexport class Deferred<T> {\n private settled = false;\n readonly promise: Promise<T>;\n private resolveFn!: (value: T) => void;\n private rejectFn!: (err: Error) => void;\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this.resolveFn = resolve;\n this.rejectFn = reject;\n });\n }\n\n resolve(value: T): void {\n if (this.settled) return;\n this.settled = true;\n this.resolveFn(value);\n }\n\n reject(err: Error): void {\n if (this.settled) return;\n this.settled = true;\n this.rejectFn(err);\n }\n}\n"],"mappings":";;AAcA,SAAgB,MAAM,IAAY,QAAoC;AACpE,QAAO,IAAI,SAAS,YAAY;AAC9B,MAAI,OAAO,SAAS;AAClB,YAAS;AACT;;EAEF,MAAM,IAAI,iBAAiB;AACzB,UAAO,oBAAoB,SAAS,QAAQ;AAC5C,YAAS;KACR,GAAG;EACN,MAAM,gBAAgB;AACpB,gBAAa,EAAE;AACf,YAAS;;AAEX,SAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;GACzD;;;;;;;;AASJ,eAAsB,cACpB,SACA,QACmB;AACnB,KAAI,OAAO,QAAS,QAAO;CAC3B,IAAIA;CACJ,MAAM,UAAU,IAAI,SAAe,YAAY;AAC7C,kBAAgB,QAAQ,KAAK;AAC7B,SAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;GACzD;AACF,KAAI;AACF,SAAO,MAAM,QAAQ,KAAK,CAAC,SAAS,QAAQ,CAAC;WACrC;AACR,SAAO,oBAAoB,SAAS,QAAQ;;;;AAMhD,IAAa,WAAb,MAAyB;CACvB,AAAQ,UAAU;CAClB,AAAS;CACT,AAAQ;CACR,AAAQ;CAER,cAAc;AACZ,OAAK,UAAU,IAAI,SAAY,SAAS,WAAW;AACjD,QAAK,YAAY;AACjB,QAAK,WAAW;IAChB;;CAGJ,QAAQ,OAAgB;AACtB,MAAI,KAAK,QAAS;AAClB,OAAK,UAAU;AACf,OAAK,UAAU,MAAM;;CAGvB,OAAO,KAAkB;AACvB,MAAI,KAAK,QAAS;AAClB,OAAK,UAAU;AACf,OAAK,SAAS,IAAI"}
|