@durable-streams/client 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -10
- package/dist/index.cjs +954 -795
- package/dist/index.d.cts +63 -25
- package/dist/index.d.ts +63 -25
- package/dist/index.js +954 -795
- package/package.json +2 -2
- package/src/idempotent-producer.ts +51 -38
- package/src/response.ts +258 -23
- package/src/sse.ts +17 -4
- package/src/stream-api.ts +22 -9
- package/src/stream.ts +77 -56
- package/src/types.ts +24 -12
package/dist/index.d.cts
CHANGED
|
@@ -168,11 +168,11 @@ type ParamsRecord = {
|
|
|
168
168
|
/**
|
|
169
169
|
* Live mode for reading from a stream.
|
|
170
170
|
* - false: Catch-up only, stop at first `upToDate`
|
|
171
|
-
* -
|
|
171
|
+
* - true: Auto-select best mode (SSE for JSON streams, long-poll for binary)
|
|
172
172
|
* - "long-poll": Explicit long-poll mode for live updates
|
|
173
173
|
* - "sse": Explicit server-sent events for live updates
|
|
174
174
|
*/
|
|
175
|
-
type LiveMode =
|
|
175
|
+
type LiveMode = boolean | `long-poll` | `sse`;
|
|
176
176
|
/**
|
|
177
177
|
* Options for the stream() function (read-only API).
|
|
178
178
|
*/
|
|
@@ -230,7 +230,7 @@ interface StreamOptions {
|
|
|
230
230
|
/**
|
|
231
231
|
* Live mode behavior:
|
|
232
232
|
* - false: Catch-up only, stop at first `upToDate`
|
|
233
|
-
* -
|
|
233
|
+
* - true (default): Auto-select best mode (SSE for JSON, long-poll for binary)
|
|
234
234
|
* - "long-poll": Explicit long-poll mode for live updates
|
|
235
235
|
* - "sse": Explicit server-sent events for live updates
|
|
236
236
|
*/
|
|
@@ -521,7 +521,7 @@ interface HeadResult {
|
|
|
521
521
|
/**
|
|
522
522
|
* Error codes for DurableStreamError.
|
|
523
523
|
*/
|
|
524
|
-
type DurableStreamErrorCode = `NOT_FOUND` | `CONFLICT_SEQ` | `CONFLICT_EXISTS` | `BAD_REQUEST` | `BUSY` | `SSE_NOT_SUPPORTED` | `UNAUTHORIZED` | `FORBIDDEN` | `RATE_LIMITED` | `ALREADY_CONSUMED` | `ALREADY_CLOSED` | `UNKNOWN`;
|
|
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`;
|
|
525
525
|
/**
|
|
526
526
|
* Options returned from onError handler to retry with modified params/headers.
|
|
527
527
|
* Following the Electric client pattern.
|
|
@@ -638,33 +638,33 @@ interface StreamResponse<TJson = unknown> {
|
|
|
638
638
|
*
|
|
639
639
|
* Use this for resuming reads after a disconnect or saving checkpoints.
|
|
640
640
|
*/
|
|
641
|
-
offset: Offset;
|
|
641
|
+
readonly offset: Offset;
|
|
642
642
|
/**
|
|
643
643
|
* Stream cursor for CDN collapsing (stream-cursor header).
|
|
644
644
|
*
|
|
645
645
|
* Updated after each chunk is delivered to the consumer.
|
|
646
646
|
*/
|
|
647
|
-
cursor?: string;
|
|
647
|
+
readonly cursor?: string;
|
|
648
648
|
/**
|
|
649
649
|
* Whether we've reached the current end of the stream (stream-up-to-date header).
|
|
650
650
|
*
|
|
651
651
|
* Updated after each chunk is delivered to the consumer.
|
|
652
652
|
*/
|
|
653
|
-
upToDate: boolean;
|
|
653
|
+
readonly upToDate: boolean;
|
|
654
654
|
/**
|
|
655
655
|
* Accumulate raw bytes until first `upToDate` batch, then resolve.
|
|
656
|
-
* When used with `live:
|
|
656
|
+
* When used with `live: true`, signals the session to stop after upToDate.
|
|
657
657
|
*/
|
|
658
658
|
body: () => Promise<Uint8Array>;
|
|
659
659
|
/**
|
|
660
660
|
* Accumulate JSON *items* across batches into a single array, resolve at `upToDate`.
|
|
661
661
|
* Only valid in JSON-mode; throws otherwise.
|
|
662
|
-
* When used with `live:
|
|
662
|
+
* When used with `live: true`, signals the session to stop after upToDate.
|
|
663
663
|
*/
|
|
664
664
|
json: <T = TJson>() => Promise<Array<T>>;
|
|
665
665
|
/**
|
|
666
666
|
* Accumulate text chunks into a single string, resolve at `upToDate`.
|
|
667
|
-
* When used with `live:
|
|
667
|
+
* When used with `live: true`, signals the session to stop after upToDate.
|
|
668
668
|
*/
|
|
669
669
|
text: () => Promise<string>;
|
|
670
670
|
/**
|
|
@@ -692,18 +692,27 @@ interface StreamResponse<TJson = unknown> {
|
|
|
692
692
|
/**
|
|
693
693
|
* Subscribe to JSON batches as they arrive.
|
|
694
694
|
* Returns unsubscribe function.
|
|
695
|
+
*
|
|
696
|
+
* The subscriber can be sync or async. If async, backpressure is applied
|
|
697
|
+
* (the next batch waits for the previous callback to complete).
|
|
695
698
|
*/
|
|
696
|
-
subscribeJson: <T = TJson>(subscriber: (batch: JsonBatch<T>) => Promise<void>) => () => void;
|
|
699
|
+
subscribeJson: <T = TJson>(subscriber: (batch: JsonBatch<T>) => void | Promise<void>) => () => void;
|
|
697
700
|
/**
|
|
698
701
|
* Subscribe to raw byte chunks as they arrive.
|
|
699
702
|
* Returns unsubscribe function.
|
|
703
|
+
*
|
|
704
|
+
* The subscriber can be sync or async. If async, backpressure is applied
|
|
705
|
+
* (the next chunk waits for the previous callback to complete).
|
|
700
706
|
*/
|
|
701
|
-
subscribeBytes: (subscriber: (chunk: ByteChunk) => Promise<void>) => () => void;
|
|
707
|
+
subscribeBytes: (subscriber: (chunk: ByteChunk) => void | Promise<void>) => () => void;
|
|
702
708
|
/**
|
|
703
709
|
* Subscribe to text chunks as they arrive.
|
|
704
710
|
* Returns unsubscribe function.
|
|
711
|
+
*
|
|
712
|
+
* The subscriber can be sync or async. If async, backpressure is applied
|
|
713
|
+
* (the next chunk waits for the previous callback to complete).
|
|
705
714
|
*/
|
|
706
|
-
subscribeText: (subscriber: (chunk: TextChunk) => Promise<void>) => () => void;
|
|
715
|
+
subscribeText: (subscriber: (chunk: TextChunk) => void | Promise<void>) => () => void;
|
|
707
716
|
/**
|
|
708
717
|
* Cancel the underlying session (abort HTTP, close SSE, stop long-polls).
|
|
709
718
|
*/
|
|
@@ -800,7 +809,7 @@ interface IdempotentAppendResult {
|
|
|
800
809
|
* url,
|
|
801
810
|
* auth,
|
|
802
811
|
* offset: savedOffset,
|
|
803
|
-
* live:
|
|
812
|
+
* live: true,
|
|
804
813
|
* })
|
|
805
814
|
* live.subscribeJson(async (batch) => {
|
|
806
815
|
* for (const item of batch.items) {
|
|
@@ -853,7 +862,7 @@ interface DurableStreamOptions extends StreamHandleOptions {
|
|
|
853
862
|
* });
|
|
854
863
|
*
|
|
855
864
|
* // Write data
|
|
856
|
-
* await stream.append({ message: "hello" });
|
|
865
|
+
* await stream.append(JSON.stringify({ message: "hello" }));
|
|
857
866
|
*
|
|
858
867
|
* // Read with the new API
|
|
859
868
|
* const res = await stream.stream<{ message: string }>();
|
|
@@ -931,22 +940,26 @@ declare class DurableStream {
|
|
|
931
940
|
* a POST is in-flight will be batched together into a single request.
|
|
932
941
|
* This significantly improves throughput for high-frequency writes.
|
|
933
942
|
*
|
|
934
|
-
* - `body`
|
|
935
|
-
* -
|
|
943
|
+
* - `body` must be string or Uint8Array.
|
|
944
|
+
* - For JSON streams, pass pre-serialized JSON strings.
|
|
945
|
+
* - `body` may also be a Promise that resolves to string or Uint8Array.
|
|
936
946
|
* - Strings are encoded as UTF-8.
|
|
937
947
|
* - `seq` (if provided) is sent as stream-seq (writer coordination).
|
|
938
948
|
*
|
|
939
949
|
* @example
|
|
940
950
|
* ```typescript
|
|
941
|
-
* //
|
|
942
|
-
* await stream.append({ message: "hello" });
|
|
951
|
+
* // JSON stream - pass pre-serialized JSON
|
|
952
|
+
* await stream.append(JSON.stringify({ message: "hello" }));
|
|
953
|
+
*
|
|
954
|
+
* // Byte stream
|
|
955
|
+
* await stream.append("raw text data");
|
|
956
|
+
* await stream.append(new Uint8Array([1, 2, 3]));
|
|
943
957
|
*
|
|
944
958
|
* // Promise value - awaited before buffering
|
|
945
959
|
* await stream.append(fetchData());
|
|
946
|
-
* await stream.append(Promise.all([a, b, c]));
|
|
947
960
|
* ```
|
|
948
961
|
*/
|
|
949
|
-
append(body:
|
|
962
|
+
append(body: Uint8Array | string | Promise<Uint8Array | string>, opts?: AppendOptions): Promise<void>;
|
|
950
963
|
/**
|
|
951
964
|
* Append a streaming body to the stream.
|
|
952
965
|
*
|
|
@@ -986,6 +999,11 @@ declare class DurableStream {
|
|
|
986
999
|
* Returns a WritableStream that can be used with `pipeTo()` or
|
|
987
1000
|
* `pipeThrough()` from any ReadableStream source.
|
|
988
1001
|
*
|
|
1002
|
+
* Uses IdempotentProducer internally for:
|
|
1003
|
+
* - Automatic batching (controlled by lingerMs, maxBatchBytes)
|
|
1004
|
+
* - Exactly-once delivery semantics
|
|
1005
|
+
* - Streaming writes (doesn't buffer entire content in memory)
|
|
1006
|
+
*
|
|
989
1007
|
* @example
|
|
990
1008
|
* ```typescript
|
|
991
1009
|
* // Pipe from fetch response
|
|
@@ -995,9 +1013,19 @@ declare class DurableStream {
|
|
|
995
1013
|
* // Pipe through a transform
|
|
996
1014
|
* const readable = someStream.pipeThrough(new TextEncoderStream());
|
|
997
1015
|
* await readable.pipeTo(stream.writable());
|
|
1016
|
+
*
|
|
1017
|
+
* // With custom producer options
|
|
1018
|
+
* await source.pipeTo(stream.writable({
|
|
1019
|
+
* producerId: "my-producer",
|
|
1020
|
+
* lingerMs: 10,
|
|
1021
|
+
* maxBatchBytes: 64 * 1024,
|
|
1022
|
+
* }));
|
|
998
1023
|
* ```
|
|
999
1024
|
*/
|
|
1000
|
-
writable(opts?:
|
|
1025
|
+
writable(opts?: Pick<IdempotentProducerOptions, `lingerMs` | `maxBatchBytes` | `onError`> & {
|
|
1026
|
+
producerId?: string;
|
|
1027
|
+
signal?: AbortSignal;
|
|
1028
|
+
}): WritableStream<Uint8Array | string>;
|
|
1001
1029
|
/**
|
|
1002
1030
|
* Start a fetch-like streaming session against this handle's URL/headers/params.
|
|
1003
1031
|
* The first request is made inside this method; it resolves when we have
|
|
@@ -1132,12 +1160,22 @@ declare class IdempotentProducer {
|
|
|
1132
1160
|
* Errors are reported via onError callback if configured. Use flush() to
|
|
1133
1161
|
* wait for all pending messages to be sent.
|
|
1134
1162
|
*
|
|
1135
|
-
* For JSON streams, pass
|
|
1163
|
+
* For JSON streams, pass pre-serialized JSON strings.
|
|
1136
1164
|
* For byte streams, pass string or Uint8Array.
|
|
1137
1165
|
*
|
|
1138
|
-
* @param body - Data to append (
|
|
1166
|
+
* @param body - Data to append (string or Uint8Array)
|
|
1167
|
+
*
|
|
1168
|
+
* @example
|
|
1169
|
+
* ```typescript
|
|
1170
|
+
* // JSON stream
|
|
1171
|
+
* producer.append(JSON.stringify({ message: "hello" }));
|
|
1172
|
+
*
|
|
1173
|
+
* // Byte stream
|
|
1174
|
+
* producer.append("raw text data");
|
|
1175
|
+
* producer.append(new Uint8Array([1, 2, 3]));
|
|
1176
|
+
* ```
|
|
1139
1177
|
*/
|
|
1140
|
-
append(body: Uint8Array | string
|
|
1178
|
+
append(body: Uint8Array | string): void;
|
|
1141
1179
|
/**
|
|
1142
1180
|
* Send any pending batch immediately and wait for all in-flight batches.
|
|
1143
1181
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -168,11 +168,11 @@ type ParamsRecord = {
|
|
|
168
168
|
/**
|
|
169
169
|
* Live mode for reading from a stream.
|
|
170
170
|
* - false: Catch-up only, stop at first `upToDate`
|
|
171
|
-
* -
|
|
171
|
+
* - true: Auto-select best mode (SSE for JSON streams, long-poll for binary)
|
|
172
172
|
* - "long-poll": Explicit long-poll mode for live updates
|
|
173
173
|
* - "sse": Explicit server-sent events for live updates
|
|
174
174
|
*/
|
|
175
|
-
type LiveMode =
|
|
175
|
+
type LiveMode = boolean | `long-poll` | `sse`;
|
|
176
176
|
/**
|
|
177
177
|
* Options for the stream() function (read-only API).
|
|
178
178
|
*/
|
|
@@ -230,7 +230,7 @@ interface StreamOptions {
|
|
|
230
230
|
/**
|
|
231
231
|
* Live mode behavior:
|
|
232
232
|
* - false: Catch-up only, stop at first `upToDate`
|
|
233
|
-
* -
|
|
233
|
+
* - true (default): Auto-select best mode (SSE for JSON, long-poll for binary)
|
|
234
234
|
* - "long-poll": Explicit long-poll mode for live updates
|
|
235
235
|
* - "sse": Explicit server-sent events for live updates
|
|
236
236
|
*/
|
|
@@ -521,7 +521,7 @@ interface HeadResult {
|
|
|
521
521
|
/**
|
|
522
522
|
* Error codes for DurableStreamError.
|
|
523
523
|
*/
|
|
524
|
-
type DurableStreamErrorCode = `NOT_FOUND` | `CONFLICT_SEQ` | `CONFLICT_EXISTS` | `BAD_REQUEST` | `BUSY` | `SSE_NOT_SUPPORTED` | `UNAUTHORIZED` | `FORBIDDEN` | `RATE_LIMITED` | `ALREADY_CONSUMED` | `ALREADY_CLOSED` | `UNKNOWN`;
|
|
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`;
|
|
525
525
|
/**
|
|
526
526
|
* Options returned from onError handler to retry with modified params/headers.
|
|
527
527
|
* Following the Electric client pattern.
|
|
@@ -638,33 +638,33 @@ interface StreamResponse<TJson = unknown> {
|
|
|
638
638
|
*
|
|
639
639
|
* Use this for resuming reads after a disconnect or saving checkpoints.
|
|
640
640
|
*/
|
|
641
|
-
offset: Offset;
|
|
641
|
+
readonly offset: Offset;
|
|
642
642
|
/**
|
|
643
643
|
* Stream cursor for CDN collapsing (stream-cursor header).
|
|
644
644
|
*
|
|
645
645
|
* Updated after each chunk is delivered to the consumer.
|
|
646
646
|
*/
|
|
647
|
-
cursor?: string;
|
|
647
|
+
readonly cursor?: string;
|
|
648
648
|
/**
|
|
649
649
|
* Whether we've reached the current end of the stream (stream-up-to-date header).
|
|
650
650
|
*
|
|
651
651
|
* Updated after each chunk is delivered to the consumer.
|
|
652
652
|
*/
|
|
653
|
-
upToDate: boolean;
|
|
653
|
+
readonly upToDate: boolean;
|
|
654
654
|
/**
|
|
655
655
|
* Accumulate raw bytes until first `upToDate` batch, then resolve.
|
|
656
|
-
* When used with `live:
|
|
656
|
+
* When used with `live: true`, signals the session to stop after upToDate.
|
|
657
657
|
*/
|
|
658
658
|
body: () => Promise<Uint8Array>;
|
|
659
659
|
/**
|
|
660
660
|
* Accumulate JSON *items* across batches into a single array, resolve at `upToDate`.
|
|
661
661
|
* Only valid in JSON-mode; throws otherwise.
|
|
662
|
-
* When used with `live:
|
|
662
|
+
* When used with `live: true`, signals the session to stop after upToDate.
|
|
663
663
|
*/
|
|
664
664
|
json: <T = TJson>() => Promise<Array<T>>;
|
|
665
665
|
/**
|
|
666
666
|
* Accumulate text chunks into a single string, resolve at `upToDate`.
|
|
667
|
-
* When used with `live:
|
|
667
|
+
* When used with `live: true`, signals the session to stop after upToDate.
|
|
668
668
|
*/
|
|
669
669
|
text: () => Promise<string>;
|
|
670
670
|
/**
|
|
@@ -692,18 +692,27 @@ interface StreamResponse<TJson = unknown> {
|
|
|
692
692
|
/**
|
|
693
693
|
* Subscribe to JSON batches as they arrive.
|
|
694
694
|
* Returns unsubscribe function.
|
|
695
|
+
*
|
|
696
|
+
* The subscriber can be sync or async. If async, backpressure is applied
|
|
697
|
+
* (the next batch waits for the previous callback to complete).
|
|
695
698
|
*/
|
|
696
|
-
subscribeJson: <T = TJson>(subscriber: (batch: JsonBatch<T>) => Promise<void>) => () => void;
|
|
699
|
+
subscribeJson: <T = TJson>(subscriber: (batch: JsonBatch<T>) => void | Promise<void>) => () => void;
|
|
697
700
|
/**
|
|
698
701
|
* Subscribe to raw byte chunks as they arrive.
|
|
699
702
|
* Returns unsubscribe function.
|
|
703
|
+
*
|
|
704
|
+
* The subscriber can be sync or async. If async, backpressure is applied
|
|
705
|
+
* (the next chunk waits for the previous callback to complete).
|
|
700
706
|
*/
|
|
701
|
-
subscribeBytes: (subscriber: (chunk: ByteChunk) => Promise<void>) => () => void;
|
|
707
|
+
subscribeBytes: (subscriber: (chunk: ByteChunk) => void | Promise<void>) => () => void;
|
|
702
708
|
/**
|
|
703
709
|
* Subscribe to text chunks as they arrive.
|
|
704
710
|
* Returns unsubscribe function.
|
|
711
|
+
*
|
|
712
|
+
* The subscriber can be sync or async. If async, backpressure is applied
|
|
713
|
+
* (the next chunk waits for the previous callback to complete).
|
|
705
714
|
*/
|
|
706
|
-
subscribeText: (subscriber: (chunk: TextChunk) => Promise<void>) => () => void;
|
|
715
|
+
subscribeText: (subscriber: (chunk: TextChunk) => void | Promise<void>) => () => void;
|
|
707
716
|
/**
|
|
708
717
|
* Cancel the underlying session (abort HTTP, close SSE, stop long-polls).
|
|
709
718
|
*/
|
|
@@ -800,7 +809,7 @@ interface IdempotentAppendResult {
|
|
|
800
809
|
* url,
|
|
801
810
|
* auth,
|
|
802
811
|
* offset: savedOffset,
|
|
803
|
-
* live:
|
|
812
|
+
* live: true,
|
|
804
813
|
* })
|
|
805
814
|
* live.subscribeJson(async (batch) => {
|
|
806
815
|
* for (const item of batch.items) {
|
|
@@ -853,7 +862,7 @@ interface DurableStreamOptions extends StreamHandleOptions {
|
|
|
853
862
|
* });
|
|
854
863
|
*
|
|
855
864
|
* // Write data
|
|
856
|
-
* await stream.append({ message: "hello" });
|
|
865
|
+
* await stream.append(JSON.stringify({ message: "hello" }));
|
|
857
866
|
*
|
|
858
867
|
* // Read with the new API
|
|
859
868
|
* const res = await stream.stream<{ message: string }>();
|
|
@@ -931,22 +940,26 @@ declare class DurableStream {
|
|
|
931
940
|
* a POST is in-flight will be batched together into a single request.
|
|
932
941
|
* This significantly improves throughput for high-frequency writes.
|
|
933
942
|
*
|
|
934
|
-
* - `body`
|
|
935
|
-
* -
|
|
943
|
+
* - `body` must be string or Uint8Array.
|
|
944
|
+
* - For JSON streams, pass pre-serialized JSON strings.
|
|
945
|
+
* - `body` may also be a Promise that resolves to string or Uint8Array.
|
|
936
946
|
* - Strings are encoded as UTF-8.
|
|
937
947
|
* - `seq` (if provided) is sent as stream-seq (writer coordination).
|
|
938
948
|
*
|
|
939
949
|
* @example
|
|
940
950
|
* ```typescript
|
|
941
|
-
* //
|
|
942
|
-
* await stream.append({ message: "hello" });
|
|
951
|
+
* // JSON stream - pass pre-serialized JSON
|
|
952
|
+
* await stream.append(JSON.stringify({ message: "hello" }));
|
|
953
|
+
*
|
|
954
|
+
* // Byte stream
|
|
955
|
+
* await stream.append("raw text data");
|
|
956
|
+
* await stream.append(new Uint8Array([1, 2, 3]));
|
|
943
957
|
*
|
|
944
958
|
* // Promise value - awaited before buffering
|
|
945
959
|
* await stream.append(fetchData());
|
|
946
|
-
* await stream.append(Promise.all([a, b, c]));
|
|
947
960
|
* ```
|
|
948
961
|
*/
|
|
949
|
-
append(body:
|
|
962
|
+
append(body: Uint8Array | string | Promise<Uint8Array | string>, opts?: AppendOptions): Promise<void>;
|
|
950
963
|
/**
|
|
951
964
|
* Append a streaming body to the stream.
|
|
952
965
|
*
|
|
@@ -986,6 +999,11 @@ declare class DurableStream {
|
|
|
986
999
|
* Returns a WritableStream that can be used with `pipeTo()` or
|
|
987
1000
|
* `pipeThrough()` from any ReadableStream source.
|
|
988
1001
|
*
|
|
1002
|
+
* Uses IdempotentProducer internally for:
|
|
1003
|
+
* - Automatic batching (controlled by lingerMs, maxBatchBytes)
|
|
1004
|
+
* - Exactly-once delivery semantics
|
|
1005
|
+
* - Streaming writes (doesn't buffer entire content in memory)
|
|
1006
|
+
*
|
|
989
1007
|
* @example
|
|
990
1008
|
* ```typescript
|
|
991
1009
|
* // Pipe from fetch response
|
|
@@ -995,9 +1013,19 @@ declare class DurableStream {
|
|
|
995
1013
|
* // Pipe through a transform
|
|
996
1014
|
* const readable = someStream.pipeThrough(new TextEncoderStream());
|
|
997
1015
|
* await readable.pipeTo(stream.writable());
|
|
1016
|
+
*
|
|
1017
|
+
* // With custom producer options
|
|
1018
|
+
* await source.pipeTo(stream.writable({
|
|
1019
|
+
* producerId: "my-producer",
|
|
1020
|
+
* lingerMs: 10,
|
|
1021
|
+
* maxBatchBytes: 64 * 1024,
|
|
1022
|
+
* }));
|
|
998
1023
|
* ```
|
|
999
1024
|
*/
|
|
1000
|
-
writable(opts?:
|
|
1025
|
+
writable(opts?: Pick<IdempotentProducerOptions, `lingerMs` | `maxBatchBytes` | `onError`> & {
|
|
1026
|
+
producerId?: string;
|
|
1027
|
+
signal?: AbortSignal;
|
|
1028
|
+
}): WritableStream<Uint8Array | string>;
|
|
1001
1029
|
/**
|
|
1002
1030
|
* Start a fetch-like streaming session against this handle's URL/headers/params.
|
|
1003
1031
|
* The first request is made inside this method; it resolves when we have
|
|
@@ -1132,12 +1160,22 @@ declare class IdempotentProducer {
|
|
|
1132
1160
|
* Errors are reported via onError callback if configured. Use flush() to
|
|
1133
1161
|
* wait for all pending messages to be sent.
|
|
1134
1162
|
*
|
|
1135
|
-
* For JSON streams, pass
|
|
1163
|
+
* For JSON streams, pass pre-serialized JSON strings.
|
|
1136
1164
|
* For byte streams, pass string or Uint8Array.
|
|
1137
1165
|
*
|
|
1138
|
-
* @param body - Data to append (
|
|
1166
|
+
* @param body - Data to append (string or Uint8Array)
|
|
1167
|
+
*
|
|
1168
|
+
* @example
|
|
1169
|
+
* ```typescript
|
|
1170
|
+
* // JSON stream
|
|
1171
|
+
* producer.append(JSON.stringify({ message: "hello" }));
|
|
1172
|
+
*
|
|
1173
|
+
* // Byte stream
|
|
1174
|
+
* producer.append("raw text data");
|
|
1175
|
+
* producer.append(new Uint8Array([1, 2, 3]));
|
|
1176
|
+
* ```
|
|
1139
1177
|
*/
|
|
1140
|
-
append(body: Uint8Array | string
|
|
1178
|
+
append(body: Uint8Array | string): void;
|
|
1141
1179
|
/**
|
|
1142
1180
|
* Send any pending batch immediately and wait for all in-flight batches.
|
|
1143
1181
|
*
|