@durable-streams/client 0.1.5 → 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 +772 -718
- package/dist/index.d.cts +63 -25
- package/dist/index.d.ts +63 -25
- package/dist/index.js +772 -718
- package/package.json +2 -2
- package/src/idempotent-producer.ts +51 -38
- package/src/response.ts +69 -18
- package/src/sse.ts +17 -4
- package/src/stream-api.ts +17 -10
- package/src/stream.ts +77 -56
- package/src/types.ts +24 -12
package/src/types.ts
CHANGED
|
@@ -62,11 +62,11 @@ export type ParamsRecord = {
|
|
|
62
62
|
/**
|
|
63
63
|
* Live mode for reading from a stream.
|
|
64
64
|
* - false: Catch-up only, stop at first `upToDate`
|
|
65
|
-
* -
|
|
65
|
+
* - true: Auto-select best mode (SSE for JSON streams, long-poll for binary)
|
|
66
66
|
* - "long-poll": Explicit long-poll mode for live updates
|
|
67
67
|
* - "sse": Explicit server-sent events for live updates
|
|
68
68
|
*/
|
|
69
|
-
export type LiveMode =
|
|
69
|
+
export type LiveMode = boolean | `long-poll` | `sse`
|
|
70
70
|
|
|
71
71
|
// ============================================================================
|
|
72
72
|
// Stream Options (Read API)
|
|
@@ -136,7 +136,7 @@ export interface StreamOptions {
|
|
|
136
136
|
/**
|
|
137
137
|
* Live mode behavior:
|
|
138
138
|
* - false: Catch-up only, stop at first `upToDate`
|
|
139
|
-
* -
|
|
139
|
+
* - true (default): Auto-select best mode (SSE for JSON, long-poll for binary)
|
|
140
140
|
* - "long-poll": Explicit long-poll mode for live updates
|
|
141
141
|
* - "sse": Explicit server-sent events for live updates
|
|
142
142
|
*/
|
|
@@ -518,6 +518,7 @@ export type DurableStreamErrorCode =
|
|
|
518
518
|
| `RATE_LIMITED`
|
|
519
519
|
| `ALREADY_CONSUMED`
|
|
520
520
|
| `ALREADY_CLOSED`
|
|
521
|
+
| `PARSE_ERROR`
|
|
521
522
|
| `UNKNOWN`
|
|
522
523
|
|
|
523
524
|
/**
|
|
@@ -659,21 +660,21 @@ export interface StreamResponse<TJson = unknown> {
|
|
|
659
660
|
*
|
|
660
661
|
* Use this for resuming reads after a disconnect or saving checkpoints.
|
|
661
662
|
*/
|
|
662
|
-
offset: Offset
|
|
663
|
+
readonly offset: Offset
|
|
663
664
|
|
|
664
665
|
/**
|
|
665
666
|
* Stream cursor for CDN collapsing (stream-cursor header).
|
|
666
667
|
*
|
|
667
668
|
* Updated after each chunk is delivered to the consumer.
|
|
668
669
|
*/
|
|
669
|
-
cursor?: string
|
|
670
|
+
readonly cursor?: string
|
|
670
671
|
|
|
671
672
|
/**
|
|
672
673
|
* Whether we've reached the current end of the stream (stream-up-to-date header).
|
|
673
674
|
*
|
|
674
675
|
* Updated after each chunk is delivered to the consumer.
|
|
675
676
|
*/
|
|
676
|
-
upToDate: boolean
|
|
677
|
+
readonly upToDate: boolean
|
|
677
678
|
|
|
678
679
|
// =================================
|
|
679
680
|
// 1) Accumulating helpers (Promise)
|
|
@@ -682,20 +683,20 @@ export interface StreamResponse<TJson = unknown> {
|
|
|
682
683
|
|
|
683
684
|
/**
|
|
684
685
|
* Accumulate raw bytes until first `upToDate` batch, then resolve.
|
|
685
|
-
* When used with `live:
|
|
686
|
+
* When used with `live: true`, signals the session to stop after upToDate.
|
|
686
687
|
*/
|
|
687
688
|
body: () => Promise<Uint8Array>
|
|
688
689
|
|
|
689
690
|
/**
|
|
690
691
|
* Accumulate JSON *items* across batches into a single array, resolve at `upToDate`.
|
|
691
692
|
* Only valid in JSON-mode; throws otherwise.
|
|
692
|
-
* When used with `live:
|
|
693
|
+
* When used with `live: true`, signals the session to stop after upToDate.
|
|
693
694
|
*/
|
|
694
695
|
json: <T = TJson>() => Promise<Array<T>>
|
|
695
696
|
|
|
696
697
|
/**
|
|
697
698
|
* Accumulate text chunks into a single string, resolve at `upToDate`.
|
|
698
|
-
* When used with `live:
|
|
699
|
+
* When used with `live: true`, signals the session to stop after upToDate.
|
|
699
700
|
*/
|
|
700
701
|
text: () => Promise<string>
|
|
701
702
|
|
|
@@ -737,24 +738,35 @@ export interface StreamResponse<TJson = unknown> {
|
|
|
737
738
|
/**
|
|
738
739
|
* Subscribe to JSON batches as they arrive.
|
|
739
740
|
* Returns unsubscribe function.
|
|
741
|
+
*
|
|
742
|
+
* The subscriber can be sync or async. If async, backpressure is applied
|
|
743
|
+
* (the next batch waits for the previous callback to complete).
|
|
740
744
|
*/
|
|
741
745
|
subscribeJson: <T = TJson>(
|
|
742
|
-
subscriber: (batch: JsonBatch<T>) => Promise<void>
|
|
746
|
+
subscriber: (batch: JsonBatch<T>) => void | Promise<void>
|
|
743
747
|
) => () => void
|
|
744
748
|
|
|
745
749
|
/**
|
|
746
750
|
* Subscribe to raw byte chunks as they arrive.
|
|
747
751
|
* Returns unsubscribe function.
|
|
752
|
+
*
|
|
753
|
+
* The subscriber can be sync or async. If async, backpressure is applied
|
|
754
|
+
* (the next chunk waits for the previous callback to complete).
|
|
748
755
|
*/
|
|
749
756
|
subscribeBytes: (
|
|
750
|
-
subscriber: (chunk: ByteChunk) => Promise<void>
|
|
757
|
+
subscriber: (chunk: ByteChunk) => void | Promise<void>
|
|
751
758
|
) => () => void
|
|
752
759
|
|
|
753
760
|
/**
|
|
754
761
|
* Subscribe to text chunks as they arrive.
|
|
755
762
|
* Returns unsubscribe function.
|
|
763
|
+
*
|
|
764
|
+
* The subscriber can be sync or async. If async, backpressure is applied
|
|
765
|
+
* (the next chunk waits for the previous callback to complete).
|
|
756
766
|
*/
|
|
757
|
-
subscribeText: (
|
|
767
|
+
subscribeText: (
|
|
768
|
+
subscriber: (chunk: TextChunk) => void | Promise<void>
|
|
769
|
+
) => () => void
|
|
758
770
|
|
|
759
771
|
// =====================
|
|
760
772
|
// 4) Lifecycle
|