@durable-streams/client 0.2.0 → 0.2.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.
- package/README.md +201 -8
- package/dist/index.cjs +331 -38
- package/dist/index.d.cts +139 -9
- package/dist/index.d.ts +139 -9
- package/dist/index.js +329 -39
- package/package.json +2 -2
- package/src/constants.ts +19 -2
- package/src/error.ts +20 -0
- package/src/idempotent-producer.ts +144 -5
- package/src/index.ts +7 -0
- package/src/response.ts +176 -17
- package/src/sse.ts +10 -1
- package/src/stream-api.ts +13 -0
- package/src/stream.ts +147 -26
- package/src/types.ts +73 -0
- package/src/utils.ts +10 -1
package/dist/index.d.cts
CHANGED
|
@@ -306,6 +306,11 @@ interface JsonBatchMeta {
|
|
|
306
306
|
* Last Stream-Cursor / streamCursor, if present.
|
|
307
307
|
*/
|
|
308
308
|
cursor?: string;
|
|
309
|
+
/**
|
|
310
|
+
* Whether the stream is closed and this batch contains the final data.
|
|
311
|
+
* When true, no more data will ever be appended to the stream.
|
|
312
|
+
*/
|
|
313
|
+
streamClosed: boolean;
|
|
309
314
|
}
|
|
310
315
|
/**
|
|
311
316
|
* A batch of parsed JSON items with metadata.
|
|
@@ -415,6 +420,17 @@ interface CreateOptions extends StreamHandleOptions {
|
|
|
415
420
|
* @default true
|
|
416
421
|
*/
|
|
417
422
|
batching?: boolean;
|
|
423
|
+
/**
|
|
424
|
+
* If true, create the stream in the closed state.
|
|
425
|
+
* Any body provided becomes the complete and final content.
|
|
426
|
+
*
|
|
427
|
+
* Useful for:
|
|
428
|
+
* - Cached responses
|
|
429
|
+
* - Placeholder errors
|
|
430
|
+
* - Pre-computed results
|
|
431
|
+
* - Single-message streams that are immediately complete
|
|
432
|
+
*/
|
|
433
|
+
closed?: boolean;
|
|
418
434
|
}
|
|
419
435
|
/**
|
|
420
436
|
* Options for appending data to a stream.
|
|
@@ -455,6 +471,37 @@ interface AppendOptions {
|
|
|
455
471
|
producerSeq?: number;
|
|
456
472
|
}
|
|
457
473
|
/**
|
|
474
|
+
* Result of a close operation.
|
|
475
|
+
*/
|
|
476
|
+
interface CloseResult {
|
|
477
|
+
/**
|
|
478
|
+
* The final offset of the stream.
|
|
479
|
+
* This is the offset after the last byte (including any final message).
|
|
480
|
+
* Returned via the `Stream-Next-Offset` header.
|
|
481
|
+
*/
|
|
482
|
+
finalOffset: Offset;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Options for closing a stream.
|
|
486
|
+
*/
|
|
487
|
+
interface CloseOptions {
|
|
488
|
+
/**
|
|
489
|
+
* Optional final message to append atomically with close.
|
|
490
|
+
* For JSON streams, pass a pre-serialized JSON string.
|
|
491
|
+
* Strings are UTF-8 encoded.
|
|
492
|
+
*/
|
|
493
|
+
body?: Uint8Array | string;
|
|
494
|
+
/**
|
|
495
|
+
* Content type for the final message.
|
|
496
|
+
* Defaults to the stream's content type. Must match if provided.
|
|
497
|
+
*/
|
|
498
|
+
contentType?: string;
|
|
499
|
+
/**
|
|
500
|
+
* AbortSignal for this operation.
|
|
501
|
+
*/
|
|
502
|
+
signal?: AbortSignal;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
458
505
|
* Legacy live mode type (internal use only).
|
|
459
506
|
* @internal
|
|
460
507
|
*/
|
|
@@ -512,6 +559,11 @@ interface HeadResult {
|
|
|
512
559
|
* Cache-Control header value.
|
|
513
560
|
*/
|
|
514
561
|
cacheControl?: string;
|
|
562
|
+
/**
|
|
563
|
+
* Whether the stream is closed.
|
|
564
|
+
* When true, no further appends are permitted.
|
|
565
|
+
*/
|
|
566
|
+
streamClosed: boolean;
|
|
515
567
|
}
|
|
516
568
|
/**
|
|
517
569
|
* Metadata extracted from a stream response.
|
|
@@ -521,7 +573,7 @@ interface HeadResult {
|
|
|
521
573
|
/**
|
|
522
574
|
* Error codes for DurableStreamError.
|
|
523
575
|
*/
|
|
524
|
-
type DurableStreamErrorCode = `NOT_FOUND` | `CONFLICT_SEQ` | `CONFLICT_EXISTS` | `BAD_REQUEST` | `BUSY` | `SSE_NOT_SUPPORTED` | `UNAUTHORIZED` | `FORBIDDEN` | `RATE_LIMITED` | `ALREADY_CONSUMED` | `ALREADY_CLOSED` | `PARSE_ERROR` | `UNKNOWN`;
|
|
576
|
+
type DurableStreamErrorCode = `NOT_FOUND` | `CONFLICT_SEQ` | `CONFLICT_EXISTS` | `BAD_REQUEST` | `BUSY` | `SSE_NOT_SUPPORTED` | `UNAUTHORIZED` | `FORBIDDEN` | `RATE_LIMITED` | `ALREADY_CONSUMED` | `ALREADY_CLOSED` | `PARSE_ERROR` | `STREAM_CLOSED` | `UNKNOWN`;
|
|
525
577
|
/**
|
|
526
578
|
* Options returned from onError handler to retry with modified params/headers.
|
|
527
579
|
* Following the Electric client pattern.
|
|
@@ -652,6 +704,18 @@ interface StreamResponse<TJson = unknown> {
|
|
|
652
704
|
*/
|
|
653
705
|
readonly upToDate: boolean;
|
|
654
706
|
/**
|
|
707
|
+
* Whether the stream is closed (EOF).
|
|
708
|
+
*
|
|
709
|
+
* When true, no more data will ever be appended to the stream.
|
|
710
|
+
* This is updated after each chunk is delivered to the consumer.
|
|
711
|
+
*
|
|
712
|
+
* In live mode, when streamClosed becomes true:
|
|
713
|
+
* - Long-poll requests return immediately (no waiting)
|
|
714
|
+
* - SSE connections are closed by the server
|
|
715
|
+
* - Clients stop reconnecting automatically
|
|
716
|
+
*/
|
|
717
|
+
readonly streamClosed: boolean;
|
|
718
|
+
/**
|
|
655
719
|
* Accumulate raw bytes until first `upToDate` batch, then resolve.
|
|
656
720
|
* When used with `live: true`, signals the session to stop after upToDate.
|
|
657
721
|
*/
|
|
@@ -934,6 +998,28 @@ declare class DurableStream {
|
|
|
934
998
|
signal?: AbortSignal;
|
|
935
999
|
}): Promise<void>;
|
|
936
1000
|
/**
|
|
1001
|
+
* Close the stream, optionally with a final message.
|
|
1002
|
+
*
|
|
1003
|
+
* After closing:
|
|
1004
|
+
* - No further appends are permitted (server returns 409)
|
|
1005
|
+
* - Readers can observe the closed state and treat it as EOF
|
|
1006
|
+
* - The stream's data remains fully readable
|
|
1007
|
+
*
|
|
1008
|
+
* Closing is:
|
|
1009
|
+
* - **Durable**: The closed state is persisted
|
|
1010
|
+
* - **Monotonic**: Once closed, a stream cannot be reopened
|
|
1011
|
+
*
|
|
1012
|
+
* **Idempotency:**
|
|
1013
|
+
* - `close()` without body: Idempotent — safe to call multiple times
|
|
1014
|
+
* - `close({ body })` with body: NOT idempotent — throws `StreamClosedError`
|
|
1015
|
+
* if stream is already closed (use `IdempotentProducer.close()` for
|
|
1016
|
+
* idempotent close-with-body semantics)
|
|
1017
|
+
*
|
|
1018
|
+
* @returns CloseResult with the final offset
|
|
1019
|
+
* @throws StreamClosedError if called with body on an already-closed stream
|
|
1020
|
+
*/
|
|
1021
|
+
close(opts?: CloseOptions): Promise<CloseResult>;
|
|
1022
|
+
/**
|
|
937
1023
|
* Append a single payload to the stream.
|
|
938
1024
|
*
|
|
939
1025
|
* When batching is enabled (default), multiple append() calls made while
|
|
@@ -1183,11 +1269,33 @@ declare class IdempotentProducer {
|
|
|
1183
1269
|
*/
|
|
1184
1270
|
flush(): Promise<void>;
|
|
1185
1271
|
/**
|
|
1186
|
-
*
|
|
1272
|
+
* Stop the producer without closing the underlying stream.
|
|
1273
|
+
*
|
|
1274
|
+
* Use this when you want to:
|
|
1275
|
+
* - Hand off writing to another producer
|
|
1276
|
+
* - Keep the stream open for future writes
|
|
1277
|
+
* - Stop this producer but not signal EOF to readers
|
|
1187
1278
|
*
|
|
1188
|
-
*
|
|
1279
|
+
* Flushes any pending messages before detaching.
|
|
1280
|
+
* After calling detach(), further append() calls will throw.
|
|
1189
1281
|
*/
|
|
1190
|
-
|
|
1282
|
+
detach(): Promise<void>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Flush pending messages and close the underlying stream (EOF).
|
|
1285
|
+
*
|
|
1286
|
+
* This is the typical way to end a producer session. It:
|
|
1287
|
+
* 1. Flushes all pending messages
|
|
1288
|
+
* 2. Optionally appends a final message
|
|
1289
|
+
* 3. Closes the stream (no further appends permitted)
|
|
1290
|
+
*
|
|
1291
|
+
* **Idempotent**: Unlike `DurableStream.close({ body })`, this method is
|
|
1292
|
+
* idempotent even with a final message because it uses producer headers
|
|
1293
|
+
* for deduplication. Safe to retry on network failures.
|
|
1294
|
+
*
|
|
1295
|
+
* @param finalMessage - Optional final message to append atomically with close
|
|
1296
|
+
* @returns CloseResult with the final offset
|
|
1297
|
+
*/
|
|
1298
|
+
close(finalMessage?: Uint8Array | string): Promise<CloseResult>;
|
|
1191
1299
|
/**
|
|
1192
1300
|
* Increment epoch and reset sequence.
|
|
1193
1301
|
*
|
|
@@ -1268,6 +1376,19 @@ declare class MissingStreamUrlError extends Error {
|
|
|
1268
1376
|
constructor();
|
|
1269
1377
|
}
|
|
1270
1378
|
/**
|
|
1379
|
+
* Error thrown when attempting to append to a closed stream.
|
|
1380
|
+
*/
|
|
1381
|
+
declare class StreamClosedError extends DurableStreamError {
|
|
1382
|
+
readonly code: "STREAM_CLOSED";
|
|
1383
|
+
readonly status = 409;
|
|
1384
|
+
readonly streamClosed: true;
|
|
1385
|
+
/**
|
|
1386
|
+
* The final offset of the stream, if available from the response.
|
|
1387
|
+
*/
|
|
1388
|
+
readonly finalOffset?: string;
|
|
1389
|
+
constructor(url?: string, finalOffset?: string);
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1271
1392
|
* Error thrown when signal option is invalid.
|
|
1272
1393
|
*/
|
|
1273
1394
|
declare class InvalidSignalError extends Error {
|
|
@@ -1297,6 +1418,11 @@ declare const STREAM_CURSOR_HEADER = "Stream-Cursor";
|
|
|
1297
1418
|
*/
|
|
1298
1419
|
declare const STREAM_UP_TO_DATE_HEADER = "Stream-Up-To-Date";
|
|
1299
1420
|
/**
|
|
1421
|
+
* Response/request header indicating stream is closed (EOF).
|
|
1422
|
+
* When present with value "true", the stream is permanently closed.
|
|
1423
|
+
*/
|
|
1424
|
+
declare const STREAM_CLOSED_HEADER = "Stream-Closed";
|
|
1425
|
+
/**
|
|
1300
1426
|
* Request header for writer coordination sequence.
|
|
1301
1427
|
* Monotonic, lexicographic. If lower than last appended seq -> 409 Conflict.
|
|
1302
1428
|
*/
|
|
@@ -1345,13 +1471,17 @@ declare const LIVE_QUERY_PARAM = "live";
|
|
|
1345
1471
|
*/
|
|
1346
1472
|
declare const CURSOR_QUERY_PARAM = "cursor";
|
|
1347
1473
|
/**
|
|
1348
|
-
* SSE
|
|
1349
|
-
* Note: Different from HTTP header name (camelCase vs Header-Case).
|
|
1474
|
+
* Response header indicating SSE data encoding (e.g., base64 for binary streams).
|
|
1350
1475
|
*/
|
|
1351
1476
|
|
|
1352
1477
|
/**
|
|
1353
|
-
*
|
|
1354
|
-
*
|
|
1478
|
+
* SSE control event field for stream closed state.
|
|
1479
|
+
* Note: Different from HTTP header name (camelCase vs Header-Case).
|
|
1480
|
+
*/
|
|
1481
|
+
declare const SSE_CLOSED_FIELD = "streamClosed";
|
|
1482
|
+
/**
|
|
1483
|
+
* Content types that are natively compatible with SSE (UTF-8 text).
|
|
1484
|
+
* Binary content types are also supported via automatic base64 encoding.
|
|
1355
1485
|
*/
|
|
1356
1486
|
declare const SSE_COMPATIBLE_CONTENT_TYPES: ReadonlyArray<string>;
|
|
1357
1487
|
/**
|
|
@@ -1360,4 +1490,4 @@ declare const SSE_COMPATIBLE_CONTENT_TYPES: ReadonlyArray<string>;
|
|
|
1360
1490
|
declare const DURABLE_STREAM_PROTOCOL_QUERY_PARAMS: Array<string>;
|
|
1361
1491
|
|
|
1362
1492
|
//#endregion
|
|
1363
|
-
export { AppendOptions, BackoffDefaults, BackoffOptions, ByteChunk, CURSOR_QUERY_PARAM, CreateOptions, DURABLE_STREAM_PROTOCOL_QUERY_PARAMS, DurableStream, DurableStreamError, DurableStreamErrorCode, DurableStreamOptions, FetchBackoffAbortError, FetchError, HeadResult, HeadersRecord, IdempotentAppendResult, IdempotentProducer, IdempotentProducerOptions, InvalidSignalError, JsonBatch, JsonBatchMeta, LIVE_QUERY_PARAM, LegacyLiveMode, LiveMode, MaybePromise, MissingStreamUrlError, OFFSET_QUERY_PARAM, Offset, PRODUCER_EPOCH_HEADER, PRODUCER_EXPECTED_SEQ_HEADER, PRODUCER_ID_HEADER, PRODUCER_RECEIVED_SEQ_HEADER, PRODUCER_SEQ_HEADER, ParamsRecord, ReadOptions, ReadableStreamAsyncIterable, RetryOpts, SSEResilienceOptions, SSE_COMPATIBLE_CONTENT_TYPES, STREAM_CURSOR_HEADER, STREAM_EXPIRES_AT_HEADER, STREAM_OFFSET_HEADER, STREAM_SEQ_HEADER, STREAM_TTL_HEADER, STREAM_UP_TO_DATE_HEADER, SequenceGapError, StaleEpochError, StreamErrorHandler, StreamHandleOptions, StreamOptions, StreamResponse, TextChunk, _resetHttpWarningForTesting, asAsyncIterableReadableStream, createFetchWithBackoff, createFetchWithConsumedBody, stream, warnIfUsingHttpInBrowser };
|
|
1493
|
+
export { AppendOptions, BackoffDefaults, BackoffOptions, ByteChunk, CURSOR_QUERY_PARAM, CloseOptions, CloseResult, CreateOptions, DURABLE_STREAM_PROTOCOL_QUERY_PARAMS, DurableStream, DurableStreamError, DurableStreamErrorCode, DurableStreamOptions, FetchBackoffAbortError, FetchError, HeadResult, HeadersRecord, IdempotentAppendResult, IdempotentProducer, IdempotentProducerOptions, InvalidSignalError, JsonBatch, JsonBatchMeta, LIVE_QUERY_PARAM, LegacyLiveMode, LiveMode, MaybePromise, MissingStreamUrlError, OFFSET_QUERY_PARAM, Offset, PRODUCER_EPOCH_HEADER, PRODUCER_EXPECTED_SEQ_HEADER, PRODUCER_ID_HEADER, PRODUCER_RECEIVED_SEQ_HEADER, PRODUCER_SEQ_HEADER, ParamsRecord, ReadOptions, ReadableStreamAsyncIterable, RetryOpts, SSEResilienceOptions, SSE_CLOSED_FIELD, SSE_COMPATIBLE_CONTENT_TYPES, STREAM_CLOSED_HEADER, STREAM_CURSOR_HEADER, STREAM_EXPIRES_AT_HEADER, STREAM_OFFSET_HEADER, STREAM_SEQ_HEADER, STREAM_TTL_HEADER, STREAM_UP_TO_DATE_HEADER, SequenceGapError, StaleEpochError, StreamClosedError, StreamErrorHandler, StreamHandleOptions, StreamOptions, StreamResponse, TextChunk, _resetHttpWarningForTesting, asAsyncIterableReadableStream, createFetchWithBackoff, createFetchWithConsumedBody, stream, warnIfUsingHttpInBrowser };
|
package/dist/index.d.ts
CHANGED
|
@@ -306,6 +306,11 @@ interface JsonBatchMeta {
|
|
|
306
306
|
* Last Stream-Cursor / streamCursor, if present.
|
|
307
307
|
*/
|
|
308
308
|
cursor?: string;
|
|
309
|
+
/**
|
|
310
|
+
* Whether the stream is closed and this batch contains the final data.
|
|
311
|
+
* When true, no more data will ever be appended to the stream.
|
|
312
|
+
*/
|
|
313
|
+
streamClosed: boolean;
|
|
309
314
|
}
|
|
310
315
|
/**
|
|
311
316
|
* A batch of parsed JSON items with metadata.
|
|
@@ -415,6 +420,17 @@ interface CreateOptions extends StreamHandleOptions {
|
|
|
415
420
|
* @default true
|
|
416
421
|
*/
|
|
417
422
|
batching?: boolean;
|
|
423
|
+
/**
|
|
424
|
+
* If true, create the stream in the closed state.
|
|
425
|
+
* Any body provided becomes the complete and final content.
|
|
426
|
+
*
|
|
427
|
+
* Useful for:
|
|
428
|
+
* - Cached responses
|
|
429
|
+
* - Placeholder errors
|
|
430
|
+
* - Pre-computed results
|
|
431
|
+
* - Single-message streams that are immediately complete
|
|
432
|
+
*/
|
|
433
|
+
closed?: boolean;
|
|
418
434
|
}
|
|
419
435
|
/**
|
|
420
436
|
* Options for appending data to a stream.
|
|
@@ -455,6 +471,37 @@ interface AppendOptions {
|
|
|
455
471
|
producerSeq?: number;
|
|
456
472
|
}
|
|
457
473
|
/**
|
|
474
|
+
* Result of a close operation.
|
|
475
|
+
*/
|
|
476
|
+
interface CloseResult {
|
|
477
|
+
/**
|
|
478
|
+
* The final offset of the stream.
|
|
479
|
+
* This is the offset after the last byte (including any final message).
|
|
480
|
+
* Returned via the `Stream-Next-Offset` header.
|
|
481
|
+
*/
|
|
482
|
+
finalOffset: Offset;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Options for closing a stream.
|
|
486
|
+
*/
|
|
487
|
+
interface CloseOptions {
|
|
488
|
+
/**
|
|
489
|
+
* Optional final message to append atomically with close.
|
|
490
|
+
* For JSON streams, pass a pre-serialized JSON string.
|
|
491
|
+
* Strings are UTF-8 encoded.
|
|
492
|
+
*/
|
|
493
|
+
body?: Uint8Array | string;
|
|
494
|
+
/**
|
|
495
|
+
* Content type for the final message.
|
|
496
|
+
* Defaults to the stream's content type. Must match if provided.
|
|
497
|
+
*/
|
|
498
|
+
contentType?: string;
|
|
499
|
+
/**
|
|
500
|
+
* AbortSignal for this operation.
|
|
501
|
+
*/
|
|
502
|
+
signal?: AbortSignal;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
458
505
|
* Legacy live mode type (internal use only).
|
|
459
506
|
* @internal
|
|
460
507
|
*/
|
|
@@ -512,6 +559,11 @@ interface HeadResult {
|
|
|
512
559
|
* Cache-Control header value.
|
|
513
560
|
*/
|
|
514
561
|
cacheControl?: string;
|
|
562
|
+
/**
|
|
563
|
+
* Whether the stream is closed.
|
|
564
|
+
* When true, no further appends are permitted.
|
|
565
|
+
*/
|
|
566
|
+
streamClosed: boolean;
|
|
515
567
|
}
|
|
516
568
|
/**
|
|
517
569
|
* Metadata extracted from a stream response.
|
|
@@ -521,7 +573,7 @@ interface HeadResult {
|
|
|
521
573
|
/**
|
|
522
574
|
* Error codes for DurableStreamError.
|
|
523
575
|
*/
|
|
524
|
-
type DurableStreamErrorCode = `NOT_FOUND` | `CONFLICT_SEQ` | `CONFLICT_EXISTS` | `BAD_REQUEST` | `BUSY` | `SSE_NOT_SUPPORTED` | `UNAUTHORIZED` | `FORBIDDEN` | `RATE_LIMITED` | `ALREADY_CONSUMED` | `ALREADY_CLOSED` | `PARSE_ERROR` | `UNKNOWN`;
|
|
576
|
+
type DurableStreamErrorCode = `NOT_FOUND` | `CONFLICT_SEQ` | `CONFLICT_EXISTS` | `BAD_REQUEST` | `BUSY` | `SSE_NOT_SUPPORTED` | `UNAUTHORIZED` | `FORBIDDEN` | `RATE_LIMITED` | `ALREADY_CONSUMED` | `ALREADY_CLOSED` | `PARSE_ERROR` | `STREAM_CLOSED` | `UNKNOWN`;
|
|
525
577
|
/**
|
|
526
578
|
* Options returned from onError handler to retry with modified params/headers.
|
|
527
579
|
* Following the Electric client pattern.
|
|
@@ -652,6 +704,18 @@ interface StreamResponse<TJson = unknown> {
|
|
|
652
704
|
*/
|
|
653
705
|
readonly upToDate: boolean;
|
|
654
706
|
/**
|
|
707
|
+
* Whether the stream is closed (EOF).
|
|
708
|
+
*
|
|
709
|
+
* When true, no more data will ever be appended to the stream.
|
|
710
|
+
* This is updated after each chunk is delivered to the consumer.
|
|
711
|
+
*
|
|
712
|
+
* In live mode, when streamClosed becomes true:
|
|
713
|
+
* - Long-poll requests return immediately (no waiting)
|
|
714
|
+
* - SSE connections are closed by the server
|
|
715
|
+
* - Clients stop reconnecting automatically
|
|
716
|
+
*/
|
|
717
|
+
readonly streamClosed: boolean;
|
|
718
|
+
/**
|
|
655
719
|
* Accumulate raw bytes until first `upToDate` batch, then resolve.
|
|
656
720
|
* When used with `live: true`, signals the session to stop after upToDate.
|
|
657
721
|
*/
|
|
@@ -934,6 +998,28 @@ declare class DurableStream {
|
|
|
934
998
|
signal?: AbortSignal;
|
|
935
999
|
}): Promise<void>;
|
|
936
1000
|
/**
|
|
1001
|
+
* Close the stream, optionally with a final message.
|
|
1002
|
+
*
|
|
1003
|
+
* After closing:
|
|
1004
|
+
* - No further appends are permitted (server returns 409)
|
|
1005
|
+
* - Readers can observe the closed state and treat it as EOF
|
|
1006
|
+
* - The stream's data remains fully readable
|
|
1007
|
+
*
|
|
1008
|
+
* Closing is:
|
|
1009
|
+
* - **Durable**: The closed state is persisted
|
|
1010
|
+
* - **Monotonic**: Once closed, a stream cannot be reopened
|
|
1011
|
+
*
|
|
1012
|
+
* **Idempotency:**
|
|
1013
|
+
* - `close()` without body: Idempotent — safe to call multiple times
|
|
1014
|
+
* - `close({ body })` with body: NOT idempotent — throws `StreamClosedError`
|
|
1015
|
+
* if stream is already closed (use `IdempotentProducer.close()` for
|
|
1016
|
+
* idempotent close-with-body semantics)
|
|
1017
|
+
*
|
|
1018
|
+
* @returns CloseResult with the final offset
|
|
1019
|
+
* @throws StreamClosedError if called with body on an already-closed stream
|
|
1020
|
+
*/
|
|
1021
|
+
close(opts?: CloseOptions): Promise<CloseResult>;
|
|
1022
|
+
/**
|
|
937
1023
|
* Append a single payload to the stream.
|
|
938
1024
|
*
|
|
939
1025
|
* When batching is enabled (default), multiple append() calls made while
|
|
@@ -1183,11 +1269,33 @@ declare class IdempotentProducer {
|
|
|
1183
1269
|
*/
|
|
1184
1270
|
flush(): Promise<void>;
|
|
1185
1271
|
/**
|
|
1186
|
-
*
|
|
1272
|
+
* Stop the producer without closing the underlying stream.
|
|
1273
|
+
*
|
|
1274
|
+
* Use this when you want to:
|
|
1275
|
+
* - Hand off writing to another producer
|
|
1276
|
+
* - Keep the stream open for future writes
|
|
1277
|
+
* - Stop this producer but not signal EOF to readers
|
|
1187
1278
|
*
|
|
1188
|
-
*
|
|
1279
|
+
* Flushes any pending messages before detaching.
|
|
1280
|
+
* After calling detach(), further append() calls will throw.
|
|
1189
1281
|
*/
|
|
1190
|
-
|
|
1282
|
+
detach(): Promise<void>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Flush pending messages and close the underlying stream (EOF).
|
|
1285
|
+
*
|
|
1286
|
+
* This is the typical way to end a producer session. It:
|
|
1287
|
+
* 1. Flushes all pending messages
|
|
1288
|
+
* 2. Optionally appends a final message
|
|
1289
|
+
* 3. Closes the stream (no further appends permitted)
|
|
1290
|
+
*
|
|
1291
|
+
* **Idempotent**: Unlike `DurableStream.close({ body })`, this method is
|
|
1292
|
+
* idempotent even with a final message because it uses producer headers
|
|
1293
|
+
* for deduplication. Safe to retry on network failures.
|
|
1294
|
+
*
|
|
1295
|
+
* @param finalMessage - Optional final message to append atomically with close
|
|
1296
|
+
* @returns CloseResult with the final offset
|
|
1297
|
+
*/
|
|
1298
|
+
close(finalMessage?: Uint8Array | string): Promise<CloseResult>;
|
|
1191
1299
|
/**
|
|
1192
1300
|
* Increment epoch and reset sequence.
|
|
1193
1301
|
*
|
|
@@ -1268,6 +1376,19 @@ declare class MissingStreamUrlError extends Error {
|
|
|
1268
1376
|
constructor();
|
|
1269
1377
|
}
|
|
1270
1378
|
/**
|
|
1379
|
+
* Error thrown when attempting to append to a closed stream.
|
|
1380
|
+
*/
|
|
1381
|
+
declare class StreamClosedError extends DurableStreamError {
|
|
1382
|
+
readonly code: "STREAM_CLOSED";
|
|
1383
|
+
readonly status = 409;
|
|
1384
|
+
readonly streamClosed: true;
|
|
1385
|
+
/**
|
|
1386
|
+
* The final offset of the stream, if available from the response.
|
|
1387
|
+
*/
|
|
1388
|
+
readonly finalOffset?: string;
|
|
1389
|
+
constructor(url?: string, finalOffset?: string);
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1271
1392
|
* Error thrown when signal option is invalid.
|
|
1272
1393
|
*/
|
|
1273
1394
|
declare class InvalidSignalError extends Error {
|
|
@@ -1297,6 +1418,11 @@ declare const STREAM_CURSOR_HEADER = "Stream-Cursor";
|
|
|
1297
1418
|
*/
|
|
1298
1419
|
declare const STREAM_UP_TO_DATE_HEADER = "Stream-Up-To-Date";
|
|
1299
1420
|
/**
|
|
1421
|
+
* Response/request header indicating stream is closed (EOF).
|
|
1422
|
+
* When present with value "true", the stream is permanently closed.
|
|
1423
|
+
*/
|
|
1424
|
+
declare const STREAM_CLOSED_HEADER = "Stream-Closed";
|
|
1425
|
+
/**
|
|
1300
1426
|
* Request header for writer coordination sequence.
|
|
1301
1427
|
* Monotonic, lexicographic. If lower than last appended seq -> 409 Conflict.
|
|
1302
1428
|
*/
|
|
@@ -1345,13 +1471,17 @@ declare const LIVE_QUERY_PARAM = "live";
|
|
|
1345
1471
|
*/
|
|
1346
1472
|
declare const CURSOR_QUERY_PARAM = "cursor";
|
|
1347
1473
|
/**
|
|
1348
|
-
* SSE
|
|
1349
|
-
* Note: Different from HTTP header name (camelCase vs Header-Case).
|
|
1474
|
+
* Response header indicating SSE data encoding (e.g., base64 for binary streams).
|
|
1350
1475
|
*/
|
|
1351
1476
|
|
|
1352
1477
|
/**
|
|
1353
|
-
*
|
|
1354
|
-
*
|
|
1478
|
+
* SSE control event field for stream closed state.
|
|
1479
|
+
* Note: Different from HTTP header name (camelCase vs Header-Case).
|
|
1480
|
+
*/
|
|
1481
|
+
declare const SSE_CLOSED_FIELD = "streamClosed";
|
|
1482
|
+
/**
|
|
1483
|
+
* Content types that are natively compatible with SSE (UTF-8 text).
|
|
1484
|
+
* Binary content types are also supported via automatic base64 encoding.
|
|
1355
1485
|
*/
|
|
1356
1486
|
declare const SSE_COMPATIBLE_CONTENT_TYPES: ReadonlyArray<string>;
|
|
1357
1487
|
/**
|
|
@@ -1360,4 +1490,4 @@ declare const SSE_COMPATIBLE_CONTENT_TYPES: ReadonlyArray<string>;
|
|
|
1360
1490
|
declare const DURABLE_STREAM_PROTOCOL_QUERY_PARAMS: Array<string>;
|
|
1361
1491
|
|
|
1362
1492
|
//#endregion
|
|
1363
|
-
export { AppendOptions, BackoffDefaults, BackoffOptions, ByteChunk, CURSOR_QUERY_PARAM, CreateOptions, DURABLE_STREAM_PROTOCOL_QUERY_PARAMS, DurableStream, DurableStreamError, DurableStreamErrorCode, DurableStreamOptions, FetchBackoffAbortError, FetchError, HeadResult, HeadersRecord, IdempotentAppendResult, IdempotentProducer, IdempotentProducerOptions, InvalidSignalError, JsonBatch, JsonBatchMeta, LIVE_QUERY_PARAM, LegacyLiveMode, LiveMode, MaybePromise, MissingStreamUrlError, OFFSET_QUERY_PARAM, Offset, PRODUCER_EPOCH_HEADER, PRODUCER_EXPECTED_SEQ_HEADER, PRODUCER_ID_HEADER, PRODUCER_RECEIVED_SEQ_HEADER, PRODUCER_SEQ_HEADER, ParamsRecord, ReadOptions, ReadableStreamAsyncIterable, RetryOpts, SSEResilienceOptions, SSE_COMPATIBLE_CONTENT_TYPES, STREAM_CURSOR_HEADER, STREAM_EXPIRES_AT_HEADER, STREAM_OFFSET_HEADER, STREAM_SEQ_HEADER, STREAM_TTL_HEADER, STREAM_UP_TO_DATE_HEADER, SequenceGapError, StaleEpochError, StreamErrorHandler, StreamHandleOptions, StreamOptions, StreamResponse, TextChunk, _resetHttpWarningForTesting, asAsyncIterableReadableStream, createFetchWithBackoff, createFetchWithConsumedBody, stream, warnIfUsingHttpInBrowser };
|
|
1493
|
+
export { AppendOptions, BackoffDefaults, BackoffOptions, ByteChunk, CURSOR_QUERY_PARAM, CloseOptions, CloseResult, CreateOptions, DURABLE_STREAM_PROTOCOL_QUERY_PARAMS, DurableStream, DurableStreamError, DurableStreamErrorCode, DurableStreamOptions, FetchBackoffAbortError, FetchError, HeadResult, HeadersRecord, IdempotentAppendResult, IdempotentProducer, IdempotentProducerOptions, InvalidSignalError, JsonBatch, JsonBatchMeta, LIVE_QUERY_PARAM, LegacyLiveMode, LiveMode, MaybePromise, MissingStreamUrlError, OFFSET_QUERY_PARAM, Offset, PRODUCER_EPOCH_HEADER, PRODUCER_EXPECTED_SEQ_HEADER, PRODUCER_ID_HEADER, PRODUCER_RECEIVED_SEQ_HEADER, PRODUCER_SEQ_HEADER, ParamsRecord, ReadOptions, ReadableStreamAsyncIterable, RetryOpts, SSEResilienceOptions, SSE_CLOSED_FIELD, SSE_COMPATIBLE_CONTENT_TYPES, STREAM_CLOSED_HEADER, STREAM_CURSOR_HEADER, STREAM_EXPIRES_AT_HEADER, STREAM_OFFSET_HEADER, STREAM_SEQ_HEADER, STREAM_TTL_HEADER, STREAM_UP_TO_DATE_HEADER, SequenceGapError, StaleEpochError, StreamClosedError, StreamErrorHandler, StreamHandleOptions, StreamOptions, StreamResponse, TextChunk, _resetHttpWarningForTesting, asAsyncIterableReadableStream, createFetchWithBackoff, createFetchWithConsumedBody, stream, warnIfUsingHttpInBrowser };
|