@durable-streams/client 0.1.3 → 0.1.4

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/src/types.ts CHANGED
@@ -381,6 +381,26 @@ export interface AppendOptions {
381
381
  * AbortSignal for this operation.
382
382
  */
383
383
  signal?: AbortSignal
384
+
385
+ /**
386
+ * Producer ID for idempotent writes.
387
+ * Client-supplied stable identifier (e.g., "order-service-1").
388
+ * Must be provided together with producerEpoch and producerSeq.
389
+ */
390
+ producerId?: string
391
+
392
+ /**
393
+ * Producer epoch for idempotent writes.
394
+ * Client-declared, server-validated monotonically increasing.
395
+ * Increment on producer restart.
396
+ */
397
+ producerEpoch?: number
398
+
399
+ /**
400
+ * Producer sequence for idempotent writes.
401
+ * Monotonically increasing per epoch, per-batch.
402
+ */
403
+ producerSeq?: number
384
404
  }
385
405
 
386
406
  /**
@@ -753,3 +773,76 @@ export interface StreamResponse<TJson = unknown> {
753
773
  */
754
774
  readonly closed: Promise<void>
755
775
  }
776
+
777
+ // ============================================================================
778
+ // Idempotent Producer Types
779
+ // ============================================================================
780
+
781
+ /**
782
+ * Options for creating an IdempotentProducer.
783
+ */
784
+ export interface IdempotentProducerOptions {
785
+ /**
786
+ * Starting epoch (default: 0).
787
+ * Increment this on producer restart.
788
+ */
789
+ epoch?: number
790
+
791
+ /**
792
+ * On 403 Forbidden (stale epoch), automatically retry with epoch+1.
793
+ * Useful for serverless/ephemeral producers.
794
+ * @default false
795
+ */
796
+ autoClaim?: boolean
797
+
798
+ /**
799
+ * Maximum bytes before sending a batch.
800
+ * @default 1048576 (1MB)
801
+ */
802
+ maxBatchBytes?: number
803
+
804
+ /**
805
+ * Maximum time to wait for more messages before sending batch (ms).
806
+ * @default 5
807
+ */
808
+ lingerMs?: number
809
+
810
+ /**
811
+ * Maximum number of concurrent batches in flight.
812
+ * Higher values improve throughput at the cost of more memory.
813
+ * @default 5
814
+ */
815
+ maxInFlight?: number
816
+
817
+ /**
818
+ * Custom fetch implementation.
819
+ */
820
+ fetch?: typeof globalThis.fetch
821
+
822
+ /**
823
+ * AbortSignal for the producer lifecycle.
824
+ */
825
+ signal?: AbortSignal
826
+
827
+ /**
828
+ * Callback for batch errors in fire-and-forget mode.
829
+ * Since append() returns immediately, errors are reported via this callback.
830
+ * @param error - The error that occurred
831
+ */
832
+ onError?: (error: Error) => void
833
+ }
834
+
835
+ /**
836
+ * Result of an append operation from IdempotentProducer.
837
+ */
838
+ export interface IdempotentAppendResult {
839
+ /**
840
+ * The offset after this message was appended.
841
+ */
842
+ offset: Offset
843
+
844
+ /**
845
+ * Whether this was a duplicate (idempotent success).
846
+ */
847
+ duplicate: boolean
848
+ }