@grovemotorco/manifold 0.0.0-stage → 0.0.1

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.
@@ -0,0 +1,530 @@
1
+ import { Ft as RequestStatus, Pt as RequestRecord, a as LOCAL_ID_PREFIX, an as TargetLabel, d as isLocalId, dt as LocalId, h as newLocalId, lt as LocalAttemptKind } from "./ids-Ced7gYBp.js";
2
+ import * as Schema from "effect/Schema";
3
+ import * as Option from "effect/Option";
4
+ import * as Data from "effect/Data";
5
+ /** The protocol version in `hello` and `ready`. */
6
+ export declare const LISTEN_PROTOCOL = 1;
7
+ export declare const LISTEN_LIMITS: {
8
+ /** Open sessions per source; the next upgrade answers `409`. */
9
+ readonly listenersPerSource: 10;
10
+ /** Largest frame either side sends, UTF-8 bytes. */
11
+ readonly frameBytes: number;
12
+ /** Requests per replay (frame or `send-local`) and per resume. */
13
+ readonly replayMax: 500;
14
+ /** Bodies up to this size travel in the frame (base64); larger ones are fetched from the raw-body endpoint. */
15
+ readonly inlineBodyBytes: number;
16
+ /** Globs in a `hello`. */
17
+ readonly eventTypes: 20;
18
+ /** `result.error`, characters. */
19
+ readonly resultErrorChars: 300;
20
+ /** `local_attempts` rows older than this are removed by hourly maintenance. */
21
+ readonly localAttemptsRetentionMs: number;
22
+ /** `local_attempts` keeps at most this many rows per source (oldest removed first). */
23
+ readonly localAttemptsMaxRows: 2000;
24
+ /** `RequestDetail.localAttempts` lists at most this many, newest first. */
25
+ readonly localAttemptsPerRequest: 100;
26
+ };
27
+ export declare const LISTEN_TIMINGS: {
28
+ /** The client must send `hello` this soon after the socket opens. */
29
+ readonly helloTimeoutMs: 10000;
30
+ /** The client sends `LISTEN_PING` this often. */
31
+ readonly keepAliveMs: 30000;
32
+ /** The client reconnects with exponential backoff from this… */
33
+ readonly reconnectMinMs: 1000;
34
+ /** …to this, jittered, forever (docs/LOCAL-RELAY.md §6.2). */
35
+ readonly reconnectMaxMs: 30000;
36
+ };
37
+ /** The keep-alive request. Answered by the platform with `LISTEN_PONG`, without waking the object. */
38
+ export declare const LISTEN_PING = "{\"type\":\"ping\"}";
39
+ export declare const LISTEN_PONG = "{\"type\":\"pong\"}";
40
+ /**
41
+ * Headers the Worker sets on the upgrade request it passes to the SourceDO,
42
+ * after removing every inbound `manifold-*` header (so a client cannot set
43
+ * them). Values are plain strings.
44
+ */
45
+ export declare const LISTEN_UPGRADE_HEADERS: {
46
+ /** The audit actor: `listen:<tokenId>`, `token` or `access:<email>` (`actorLabel`). */
47
+ readonly actor: "manifold-listen-actor";
48
+ /** The listen token's id (`ltk_…`); absent for the admin token and Access. */
49
+ readonly tokenId: "manifold-listen-token-id";
50
+ };
51
+ /**
52
+ * Close codes. `1000`–`1011` are the standard ones; `4000`–`4099` are ours,
53
+ * one per `bye` reason so a client that missed the `bye` frame still knows.
54
+ */
55
+ export declare const LISTEN_CLOSE: {
56
+ /** Either side ended the session normally (CLI `Ctrl-C`). */
57
+ readonly normal: 1000;
58
+ /** The server is restarting or the object is being evicted. Reconnect. */
59
+ readonly goingAway: 1001;
60
+ /** A malformed frame of a known type, or a second `hello`. */
61
+ readonly protocolError: 1002;
62
+ /** A frame over `LISTEN_LIMITS.frameBytes`. */
63
+ readonly tooBig: 1009;
64
+ readonly internalError: 1011;
65
+ readonly replaced: 4000;
66
+ readonly revoked: 4001;
67
+ readonly sourceDeleted: 4002;
68
+ readonly tooManyListeners: 4003;
69
+ readonly disconnected: 4004;
70
+ readonly listenersOff: 4005;
71
+ readonly unsupportedProtocol: 4006;
72
+ readonly badHello: 4007;
73
+ readonly helloTimeout: 4008;
74
+ /** The client read too slowly and its send buffer passed the limit (§7 of LOCAL-RELAY.md). Reconnect with resume. */
75
+ readonly slowConsumer: 4009;
76
+ /** `live: false` and the replay is done. */
77
+ readonly done: 4010;
78
+ };
79
+ export type ListenCloseCode = (typeof LISTEN_CLOSE)[keyof typeof LISTEN_CLOSE];
80
+ /**
81
+ * `bye` reasons the server sends. `reason` is decoded as any string so a
82
+ * newer server's reasons reach an older CLI; these are the known ones:
83
+ *
84
+ * - `replaced`: a new session with the same name and the same credential
85
+ * took over. Do not reconnect.
86
+ * - `revoked`: the listen token was revoked or expired. Do not reconnect.
87
+ * - `source_deleted`. Do not reconnect.
88
+ * - `too_many_listeners`: a race past the `409` check. Retry later.
89
+ * - `disconnected`: an operator disconnected it (`DELETE …/listeners/{id}`). Do not reconnect.
90
+ * - `listeners_off`: the source's `listeners` was set to `off`. Do not reconnect.
91
+ * - `unsupported_protocol`: `hello.protocol` is not `LISTEN_PROTOCOL`. Upgrade the CLI.
92
+ * - `bad_hello`: the hello was invalid (unknown `likeRoute`, both `resumeAfter` and `replay`, …).
93
+ * - `slow_consumer`: see `LISTEN_CLOSE.slowConsumer`. Reconnect with resume.
94
+ * - `done`: `live: false` and the replay is finished.
95
+ */
96
+ export declare const ByeReason: Schema.Literals<readonly ["replaced", "revoked", "source_deleted", "too_many_listeners", "disconnected", "listeners_off", "unsupported_protocol", "bad_hello", "slow_consumer", "done"]>;
97
+ export type ByeReason = typeof ByeReason.Type;
98
+ /** The close code that follows a `bye` with this reason. */
99
+ export declare const byeCloseCode: (reason: ByeReason) => ListenCloseCode;
100
+ /**
101
+ * True when the CLI must not reconnect after this close code. Every other
102
+ * code (network loss `1006`, `1001`, `1011`, `4003`, `4008`, `4009`, unknown
103
+ * codes) is retried with the reconnect schedule and `resumeAfter`.
104
+ */
105
+ export declare const isFinalClose: (code: number) => boolean;
106
+ /**
107
+ * `notice` codes the server sends. `code` is decoded as any string, so a
108
+ * notice with an unknown code is still delivered (and can be printed); these
109
+ * are the known ones:
110
+ *
111
+ * - `gap`: a resume found more than `LISTEN_LIMITS.replayMax` requests after
112
+ * the cursor (`count` of them were skipped), or the cursor is older than
113
+ * the source's retention. Sent before the resume's requests, which are the
114
+ * newest `replayMax`.
115
+ * - `resume_done`: the resume's requests were all sent (`count`).
116
+ * - `replay_done`: a replay (hello `replay`, a `replay` frame with its `ref`, or
117
+ * a `send-local`) was all sent (`count`).
118
+ * - `limit`: a request could not be sent because its frame would pass
119
+ * `LISTEN_LIMITS.frameBytes` even without its body, or a replay was cut at
120
+ * `replayMax`. `message` names the request id.
121
+ */
122
+ export declare const NoticeCode: Schema.Literals<readonly ["gap", "resume_done", "replay_done", "limit"]>;
123
+ export type NoticeCode = typeof NoticeCode.Type;
124
+ /** `--last <n>`: the newest `n` matching stored requests. `--since`: those received at or after `since`. */
125
+ export declare const HelloReplay: Schema.Union<readonly [Schema.Struct<{
126
+ readonly last: Schema.Int;
127
+ }>, Schema.Struct<{
128
+ readonly since: Schema.Int;
129
+ }>]>;
130
+ export type HelloReplay = typeof HelloReplay.Type;
131
+ /**
132
+ * Opens the session. Filter: `eventTypes` globs, or `likeRoute` (a route of
133
+ * this source) whose filter is copied; with `likeRoute` set, `eventTypes` is
134
+ * ignored and should be `["*"]` (see `effectiveEventTypes`). A hello replay
135
+ * (`replay`) and resume (`resumeAfter`, the newest live or resume request id
136
+ * the CLI saw) are both filtered and both leave out `duplicate` requests;
137
+ * at most one of them may be set.
138
+ */
139
+ export declare const HelloFrame: Schema.Struct<{
140
+ readonly type: Schema.Literal<"hello">;
141
+ /** `LISTEN_PROTOCOL`. Any integer decodes, so a newer client can be refused with `bye: unsupported_protocol`. */
142
+ readonly protocol: Schema.Int;
143
+ readonly name: Schema.String;
144
+ readonly eventTypes: Schema.NonEmptyArray<Schema.String>;
145
+ readonly likeRoute: Schema.optionalKey<Schema.String>;
146
+ readonly resumeAfter: Schema.optionalKey<Schema.String>;
147
+ readonly replay: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
148
+ readonly last: Schema.Int;
149
+ }>, Schema.Struct<{
150
+ readonly since: Schema.Int;
151
+ }>]>>;
152
+ /** False for `--no-live`: replay, then `bye: done`. */
153
+ readonly live: Schema.Boolean;
154
+ }>;
155
+ export type HelloFrame = typeof HelloFrame.Type;
156
+ /**
157
+ * The outcome of one attempt to forward one `request` frame to one local
158
+ * target. `statusCode` when a response arrived (any status, `3xx` included:
159
+ * redirects are not followed), `error` otherwise; exactly one of them.
160
+ */
161
+ export declare const ResultFrame: Schema.Struct<{
162
+ readonly type: Schema.Literal<"result">;
163
+ readonly localId: Schema.String;
164
+ readonly requestId: Schema.String;
165
+ /** The `kind` of the `request` frame. */
166
+ readonly kind: Schema.Literals<readonly ["live", "replay", "resume"]>;
167
+ /** `targetLabel(url)`, never the full URL. */
168
+ readonly target: Schema.String;
169
+ readonly attempt: Schema.Int;
170
+ readonly durationMs: Schema.Int;
171
+ readonly statusCode: Schema.optionalKey<Schema.Int>;
172
+ readonly error: Schema.optionalKey<Schema.String>;
173
+ }>;
174
+ export type ResultFrame = typeof ResultFrame.Type;
175
+ /**
176
+ * Asks for stored requests on this socket, as `request` frames of kind
177
+ * `replay`, then `notice: replay_done` with the same `ref`. By ids
178
+ * (`requestIds`) or by a range; not both. The session's filter does not
179
+ * apply: what is asked for is sent.
180
+ */
181
+ export declare const ReplayFrame: Schema.Struct<{
182
+ readonly since: Schema.optionalKey<Schema.Int>;
183
+ readonly until: Schema.optionalKey<Schema.Int>;
184
+ readonly eventType: Schema.optionalKey<Schema.String>;
185
+ readonly status: Schema.optionalKey<Schema.Literals<readonly ["accepted", "duplicate", "unrouted"]>>;
186
+ readonly limit: Schema.optionalKey<Schema.Int>;
187
+ readonly type: Schema.Literal<"replay">;
188
+ /** Echoed in the `replay_done` notice. */
189
+ readonly ref: Schema.optionalKey<Schema.String>;
190
+ readonly requestIds: Schema.optionalKey<Schema.NonEmptyArray<Schema.String>>;
191
+ }>;
192
+ export type ReplayFrame = typeof ReplayFrame.Type;
193
+ /** `LISTEN_PING` as a frame. Normally answered by the platform, never seen by the object. */
194
+ export declare const PingFrame: Schema.Struct<{
195
+ readonly type: Schema.Literal<"ping">;
196
+ }>;
197
+ export type PingFrame = typeof PingFrame.Type;
198
+ export declare const ClientFrame: Schema.Union<readonly [Schema.Struct<{
199
+ readonly type: Schema.Literal<"hello">;
200
+ /** `LISTEN_PROTOCOL`. Any integer decodes, so a newer client can be refused with `bye: unsupported_protocol`. */
201
+ readonly protocol: Schema.Int;
202
+ readonly name: Schema.String;
203
+ readonly eventTypes: Schema.NonEmptyArray<Schema.String>;
204
+ readonly likeRoute: Schema.optionalKey<Schema.String>;
205
+ readonly resumeAfter: Schema.optionalKey<Schema.String>;
206
+ readonly replay: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
207
+ readonly last: Schema.Int;
208
+ }>, Schema.Struct<{
209
+ readonly since: Schema.Int;
210
+ }>]>>;
211
+ /** False for `--no-live`: replay, then `bye: done`. */
212
+ readonly live: Schema.Boolean;
213
+ }>, Schema.Struct<{
214
+ readonly type: Schema.Literal<"result">;
215
+ readonly localId: Schema.String;
216
+ readonly requestId: Schema.String;
217
+ /** The `kind` of the `request` frame. */
218
+ readonly kind: Schema.Literals<readonly ["live", "replay", "resume"]>;
219
+ /** `targetLabel(url)`, never the full URL. */
220
+ readonly target: Schema.String;
221
+ readonly attempt: Schema.Int;
222
+ readonly durationMs: Schema.Int;
223
+ readonly statusCode: Schema.optionalKey<Schema.Int>;
224
+ readonly error: Schema.optionalKey<Schema.String>;
225
+ }>, Schema.Struct<{
226
+ readonly since: Schema.optionalKey<Schema.Int>;
227
+ readonly until: Schema.optionalKey<Schema.Int>;
228
+ readonly eventType: Schema.optionalKey<Schema.String>;
229
+ readonly status: Schema.optionalKey<Schema.Literals<readonly ["accepted", "duplicate", "unrouted"]>>;
230
+ readonly limit: Schema.optionalKey<Schema.Int>;
231
+ readonly type: Schema.Literal<"replay">;
232
+ /** Echoed in the `replay_done` notice. */
233
+ readonly ref: Schema.optionalKey<Schema.String>;
234
+ readonly requestIds: Schema.optionalKey<Schema.NonEmptyArray<Schema.String>>;
235
+ }>, Schema.Struct<{
236
+ readonly type: Schema.Literal<"ping">;
237
+ }>]>;
238
+ export type ClientFrame = typeof ClientFrame.Type;
239
+ /**
240
+ * Sent once, after a valid `hello`. `source` and `preset` are plain strings
241
+ * so a newer server's preset ids decode in an older CLI.
242
+ */
243
+ export declare const ReadyFrame: Schema.Struct<{
244
+ readonly type: Schema.Literal<"ready">;
245
+ readonly protocol: Schema.Int;
246
+ readonly sessionId: Schema.String;
247
+ readonly source: Schema.String;
248
+ readonly preset: Schema.String;
249
+ /** The effective filter (`effectiveEventTypes`). */
250
+ readonly eventTypes: Schema.$Array<Schema.String>;
251
+ /**
252
+ * The source's resolved `redactHeaders`, which `buildOutboundRequest`
253
+ * needs to build what a relay would receive (a listen token cannot read
254
+ * the source config).
255
+ */
256
+ readonly redactHeaders: Schema.$Array<Schema.String>;
257
+ readonly limits: Schema.Struct<{
258
+ readonly listenersPerSource: Schema.Int;
259
+ readonly frameBytes: Schema.Int;
260
+ readonly inlineBodyBytes: Schema.Int;
261
+ readonly replayMax: Schema.Int;
262
+ }>;
263
+ readonly serverTime: Schema.Int;
264
+ }>;
265
+ export type ReadyFrame = typeof ReadyFrame.Type;
266
+ /**
267
+ * How a `request` frame carries the body: `inline` (base64 of the raw bytes,
268
+ * for bodies up to `LISTEN_LIMITS.inlineBodyBytes` whose frame fits), or
269
+ * `fetch` (read it from `GET /api/v1/sources/{key}/requests/{id}/body`,
270
+ * which a listen token may call for its source).
271
+ */
272
+ export declare const FrameBody: Schema.Union<readonly [Schema.Struct<{
273
+ readonly inline: Schema.String;
274
+ }>, Schema.Struct<{
275
+ readonly fetch: Schema.Literal<true>;
276
+ readonly size: Schema.Int;
277
+ }>]>;
278
+ export type FrameBody = typeof FrameBody.Type;
279
+ /**
280
+ * One stored request for the listener. `request` is the stored record, as
281
+ * the admin API returns it (headers as stored, credentials redacted).
282
+ * `localId` is minted by the server per frame (`newLocalId`): the CLI sends it
283
+ * as `manifold-delivery-id` to every target and on every retry.
284
+ * `duplicate` requests are never sent live or on resume.
285
+ */
286
+ export declare const RequestFrame: Schema.Struct<{
287
+ readonly type: Schema.Literal<"request">;
288
+ readonly localId: Schema.String;
289
+ readonly kind: Schema.Literals<readonly ["live", "replay", "resume"]>;
290
+ readonly request: Schema.Struct<{
291
+ readonly id: Schema.String;
292
+ readonly sourceKey: Schema.String;
293
+ readonly receivedAt: Schema.Int;
294
+ readonly status: Schema.Literals<readonly ["accepted", "duplicate", "unrouted"]>;
295
+ readonly method: Schema.String;
296
+ readonly path: Schema.String;
297
+ readonly query: Schema.String;
298
+ readonly headers: Schema.$Record<Schema.String, Schema.String>;
299
+ readonly bodySize: Schema.Int;
300
+ readonly bodySha256: Schema.String;
301
+ readonly bodyStorage: Schema.Literals<readonly ["inline", "r2"]>;
302
+ readonly contentType: Schema.NullOr<Schema.String>;
303
+ readonly eventType: Schema.NullOr<Schema.String>;
304
+ readonly idempotencyKey: Schema.NullOr<Schema.String>;
305
+ readonly principal: Schema.NullOr<Schema.Struct<{
306
+ readonly kind: Schema.Literal<"jwt">;
307
+ readonly iss: Schema.String;
308
+ readonly sub: Schema.NullOr<Schema.String>;
309
+ readonly email: Schema.NullOr<Schema.String>;
310
+ readonly aud: Schema.NullOr<Schema.String>;
311
+ }>>;
312
+ readonly duplicateOf: Schema.NullOr<Schema.String>;
313
+ readonly conflict: Schema.Boolean;
314
+ readonly remoteIp: Schema.NullOr<Schema.String>;
315
+ readonly userAgent: Schema.NullOr<Schema.String>;
316
+ }>;
317
+ readonly body: Schema.Union<readonly [Schema.Struct<{
318
+ readonly inline: Schema.String;
319
+ }>, Schema.Struct<{
320
+ readonly fetch: Schema.Literal<true>;
321
+ readonly size: Schema.Int;
322
+ }>]>;
323
+ }>;
324
+ export type RequestFrame = typeof RequestFrame.Type;
325
+ export declare const NoticeFrame: Schema.Struct<{
326
+ readonly type: Schema.Literal<"notice">;
327
+ /** A `NoticeCode`, or a newer one. */
328
+ readonly code: Schema.String;
329
+ readonly message: Schema.String;
330
+ /** The `ref` of the `replay` frame this answers. */
331
+ readonly ref: Schema.optionalKey<Schema.String>;
332
+ readonly count: Schema.optionalKey<Schema.Int>;
333
+ }>;
334
+ export type NoticeFrame = typeof NoticeFrame.Type;
335
+ export declare const ByeFrame: Schema.Struct<{
336
+ readonly type: Schema.Literal<"bye">;
337
+ /** A `ByeReason`, or a newer one. */
338
+ readonly reason: Schema.String;
339
+ readonly message: Schema.optionalKey<Schema.String>;
340
+ }>;
341
+ export type ByeFrame = typeof ByeFrame.Type;
342
+ /** `LISTEN_PONG` as a frame. */
343
+ export declare const PongFrame: Schema.Struct<{
344
+ readonly type: Schema.Literal<"pong">;
345
+ }>;
346
+ export type PongFrame = typeof PongFrame.Type;
347
+ export declare const ServerFrame: Schema.Union<readonly [Schema.Struct<{
348
+ readonly type: Schema.Literal<"ready">;
349
+ readonly protocol: Schema.Int;
350
+ readonly sessionId: Schema.String;
351
+ readonly source: Schema.String;
352
+ readonly preset: Schema.String;
353
+ /** The effective filter (`effectiveEventTypes`). */
354
+ readonly eventTypes: Schema.$Array<Schema.String>;
355
+ /**
356
+ * The source's resolved `redactHeaders`, which `buildOutboundRequest`
357
+ * needs to build what a relay would receive (a listen token cannot read
358
+ * the source config).
359
+ */
360
+ readonly redactHeaders: Schema.$Array<Schema.String>;
361
+ readonly limits: Schema.Struct<{
362
+ readonly listenersPerSource: Schema.Int;
363
+ readonly frameBytes: Schema.Int;
364
+ readonly inlineBodyBytes: Schema.Int;
365
+ readonly replayMax: Schema.Int;
366
+ }>;
367
+ readonly serverTime: Schema.Int;
368
+ }>, Schema.Struct<{
369
+ readonly type: Schema.Literal<"request">;
370
+ readonly localId: Schema.String;
371
+ readonly kind: Schema.Literals<readonly ["live", "replay", "resume"]>;
372
+ readonly request: Schema.Struct<{
373
+ readonly id: Schema.String;
374
+ readonly sourceKey: Schema.String;
375
+ readonly receivedAt: Schema.Int;
376
+ readonly status: Schema.Literals<readonly ["accepted", "duplicate", "unrouted"]>;
377
+ readonly method: Schema.String;
378
+ readonly path: Schema.String;
379
+ readonly query: Schema.String;
380
+ readonly headers: Schema.$Record<Schema.String, Schema.String>;
381
+ readonly bodySize: Schema.Int;
382
+ readonly bodySha256: Schema.String;
383
+ readonly bodyStorage: Schema.Literals<readonly ["inline", "r2"]>;
384
+ readonly contentType: Schema.NullOr<Schema.String>;
385
+ readonly eventType: Schema.NullOr<Schema.String>;
386
+ readonly idempotencyKey: Schema.NullOr<Schema.String>;
387
+ readonly principal: Schema.NullOr<Schema.Struct<{
388
+ readonly kind: Schema.Literal<"jwt">;
389
+ readonly iss: Schema.String;
390
+ readonly sub: Schema.NullOr<Schema.String>;
391
+ readonly email: Schema.NullOr<Schema.String>;
392
+ readonly aud: Schema.NullOr<Schema.String>;
393
+ }>>;
394
+ readonly duplicateOf: Schema.NullOr<Schema.String>;
395
+ readonly conflict: Schema.Boolean;
396
+ readonly remoteIp: Schema.NullOr<Schema.String>;
397
+ readonly userAgent: Schema.NullOr<Schema.String>;
398
+ }>;
399
+ readonly body: Schema.Union<readonly [Schema.Struct<{
400
+ readonly inline: Schema.String;
401
+ }>, Schema.Struct<{
402
+ readonly fetch: Schema.Literal<true>;
403
+ readonly size: Schema.Int;
404
+ }>]>;
405
+ }>, Schema.Struct<{
406
+ readonly type: Schema.Literal<"notice">;
407
+ /** A `NoticeCode`, or a newer one. */
408
+ readonly code: Schema.String;
409
+ readonly message: Schema.String;
410
+ /** The `ref` of the `replay` frame this answers. */
411
+ readonly ref: Schema.optionalKey<Schema.String>;
412
+ readonly count: Schema.optionalKey<Schema.Int>;
413
+ }>, Schema.Struct<{
414
+ readonly type: Schema.Literal<"bye">;
415
+ /** A `ByeReason`, or a newer one. */
416
+ readonly reason: Schema.String;
417
+ readonly message: Schema.optionalKey<Schema.String>;
418
+ }>, Schema.Struct<{
419
+ readonly type: Schema.Literal<"pong">;
420
+ }>]>;
421
+ export type ServerFrame = typeof ServerFrame.Type;
422
+ export type ClientFrameType = ClientFrame["type"];
423
+ export type ServerFrameType = ServerFrame["type"];
424
+ /** The UTF-8 size of an encoded frame. */
425
+ export declare const frameBytes: (text: string) => number;
426
+ /**
427
+ * The outcome of reading one frame. `Unknown` (a `type` this side does not
428
+ * know) is to be ignored; `Malformed` (not JSON, no `type`, too large, or a
429
+ * known type that does not decode) carries a short reason for logs.
430
+ */
431
+ export type ParsedFrame<F> = Data.TaggedEnum<{
432
+ Frame: {
433
+ readonly frame: F;
434
+ };
435
+ Unknown: {
436
+ readonly type: string;
437
+ };
438
+ Malformed: {
439
+ readonly type: string | null;
440
+ readonly reason: string;
441
+ };
442
+ }>;
443
+ interface ParsedFrameDefinition extends Data.TaggedEnum.WithGenerics<1> {
444
+ readonly taggedEnum: ParsedFrame<this["A"]>;
445
+ }
446
+ export declare const ParsedFrame: Data.TaggedEnum.GenericConstructor<ParsedFrameDefinition>;
447
+ /** Reads a frame the CLI sent. Never throws. */
448
+ export declare const parseClientFrame: (data: string | Uint8Array | ArrayBuffer) => ParsedFrame<ClientFrame>;
449
+ /** Reads a frame the server sent. Never throws. */
450
+ export declare const parseServerFrame: (data: string | Uint8Array | ArrayBuffer) => ParsedFrame<ServerFrame>;
451
+ /** A client frame, or none when it is of an unknown type or malformed. Never throws. */
452
+ export declare const decodeClientFrame: (data: string | Uint8Array | ArrayBuffer) => Option.Option<ClientFrame>;
453
+ /** A server frame, or none when it is of an unknown type or malformed. Never throws. */
454
+ export declare const decodeServerFrame: (data: string | Uint8Array | ArrayBuffer) => Option.Option<ServerFrame>;
455
+ /** The JSON text of a client frame. Throws on a value that does not satisfy its schema (a programming error). */
456
+ export declare const encodeClientFrame: (frame: ClientFrame) => string;
457
+ /** The JSON text of a server frame. Throws on a value that does not satisfy its schema (a programming error). */
458
+ export declare const encodeServerFrame: (frame: ServerFrame) => string;
459
+ /**
460
+ * Builds and encodes a `request` frame, choosing how the body travels: inline
461
+ * when `body` is given, at most `LISTEN_LIMITS.inlineBodyBytes`, and the frame
462
+ * fits `LISTEN_LIMITS.frameBytes`; otherwise `fetch`. `body` is `null` when it
463
+ * is stored in R2. Answers `undefined` when even the `fetch` frame is too
464
+ * large (very large headers): send a `limit` notice instead.
465
+ */
466
+ export declare const encodeRequestFrame: (input: {
467
+ readonly localId: string;
468
+ readonly kind: LocalAttemptKind;
469
+ readonly request: RequestRecord;
470
+ readonly body: Uint8Array | null;
471
+ }) => {
472
+ readonly frame: RequestFrame;
473
+ readonly text: string;
474
+ } | undefined;
475
+ /** The body of a `request` frame when it is inline; `undefined` when it must be fetched (or is not valid base64). */
476
+ export declare const inlineBody: (frame: RequestFrame) => Uint8Array | undefined;
477
+ /**
478
+ * The globs a session filters live and resume requests with: the hello's
479
+ * `eventTypes`, or, with `likeRoute`, a copy of that route's filter as it is
480
+ * in the current snapshot. `undefined` when `likeRoute` names no route of
481
+ * this source (answer `bye: bad_hello` at hello time; send nothing later if
482
+ * the route was deleted since).
483
+ */
484
+ export declare const effectiveEventTypes: (filter: {
485
+ readonly eventTypes: ReadonlyArray<string>;
486
+ readonly likeRoute?: string | null | undefined;
487
+ }, routes: ReadonlyArray<{
488
+ readonly id: string;
489
+ readonly eventTypes: ReadonlyArray<string>;
490
+ }>) => ReadonlyArray<string> | undefined;
491
+ /**
492
+ * True when a live or resume request goes to a session with these globs:
493
+ * never a `duplicate`; `accepted` and `unrouted` ones when a glob matches
494
+ * the event type (`*` also matches a request without one), exactly as route
495
+ * filters match (src/core/filter.ts). Rejections are never sent.
496
+ */
497
+ export declare const listenerWants: (eventTypes: ReadonlyArray<string>, request: {
498
+ readonly status: RequestStatus;
499
+ readonly eventType: string | null;
500
+ }) => boolean;
501
+ /** The WebSocket path for a source, under `API_PREFIX`. */
502
+ export declare const listenPath: (sourceKey: string) => string;
503
+ /**
504
+ * The source key when `pathname` is exactly a listen path
505
+ * (`/api/v1/sources/{key}/listen`), else `undefined`. For the Worker's router.
506
+ */
507
+ export declare const listenPathKey: (pathname: string) => string | undefined;
508
+ /**
509
+ * The `ws:` / `wss:` URL of a source's listen endpoint. `baseUrl` is the
510
+ * service origin as the CLI is configured with it (`http`, `https`, `ws` or
511
+ * `wss`; a path prefix is kept, as the typed client keeps it). Throws a
512
+ * `TypeError` for another protocol or an invalid source key.
513
+ */
514
+ export declare const listenUrl: (baseUrl: string | URL, sourceKey: string) => string;
515
+ /**
516
+ * The label a `result` frame reports for a local target: `:{port}{path}` for
517
+ * a loopback host (`:3000/webhooks/github`), `{host}{path}` otherwise. No
518
+ * scheme, query or credentials. At most 200 characters.
519
+ */
520
+ export declare const targetLabel: (target: string | URL) => string;
521
+ export declare const LISTEN_TOKEN_PREFIX = "mfl_";
522
+ /** A new listen token: `mfl_` and 32 random bytes in base64url (43 characters). */
523
+ export declare const generateListenToken: () => string;
524
+ /** True when the value has the shape of a listen token. Says nothing about whether it is valid. */
525
+ export declare const isListenToken: (value: string) => boolean;
526
+ /** What is stored and compared: SHA-256 of the token's UTF-8 bytes, 64 lowercase hex characters. */
527
+ export declare const hashListenToken: (token: string) => Promise<string>;
528
+ /** The token's fingerprint (§5.5): the first 8 hex characters of its hash. */
529
+ export declare const listenTokenFingerprint: (hash: string) => string;
530
+ export { LOCAL_ID_PREFIX, LocalAttemptKind, LocalId, TargetLabel, isLocalId, newLocalId };