@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/README.md +168 -4
- package/dist/index.cjs +431 -3
- package/dist/index.d.cts +218 -1
- package/dist/index.d.ts +218 -1
- package/dist/index.js +424 -4
- package/package.json +2 -2
- package/src/constants.ts +31 -0
- package/src/idempotent-producer.ts +642 -0
- package/src/index.ts +21 -0
- package/src/stream.ts +5 -0
- package/src/types.ts +93 -0
package/dist/index.d.cts
CHANGED
|
@@ -436,6 +436,23 @@ interface AppendOptions {
|
|
|
436
436
|
* AbortSignal for this operation.
|
|
437
437
|
*/
|
|
438
438
|
signal?: AbortSignal;
|
|
439
|
+
/**
|
|
440
|
+
* Producer ID for idempotent writes.
|
|
441
|
+
* Client-supplied stable identifier (e.g., "order-service-1").
|
|
442
|
+
* Must be provided together with producerEpoch and producerSeq.
|
|
443
|
+
*/
|
|
444
|
+
producerId?: string;
|
|
445
|
+
/**
|
|
446
|
+
* Producer epoch for idempotent writes.
|
|
447
|
+
* Client-declared, server-validated monotonically increasing.
|
|
448
|
+
* Increment on producer restart.
|
|
449
|
+
*/
|
|
450
|
+
producerEpoch?: number;
|
|
451
|
+
/**
|
|
452
|
+
* Producer sequence for idempotent writes.
|
|
453
|
+
* Monotonically increasing per epoch, per-batch.
|
|
454
|
+
*/
|
|
455
|
+
producerSeq?: number;
|
|
439
456
|
}
|
|
440
457
|
/**
|
|
441
458
|
* Legacy live mode type (internal use only).
|
|
@@ -698,6 +715,65 @@ interface StreamResponse<TJson = unknown> {
|
|
|
698
715
|
* - terminal error.
|
|
699
716
|
*/
|
|
700
717
|
readonly closed: Promise<void>;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Options for creating an IdempotentProducer.
|
|
721
|
+
*/
|
|
722
|
+
interface IdempotentProducerOptions {
|
|
723
|
+
/**
|
|
724
|
+
* Starting epoch (default: 0).
|
|
725
|
+
* Increment this on producer restart.
|
|
726
|
+
*/
|
|
727
|
+
epoch?: number;
|
|
728
|
+
/**
|
|
729
|
+
* On 403 Forbidden (stale epoch), automatically retry with epoch+1.
|
|
730
|
+
* Useful for serverless/ephemeral producers.
|
|
731
|
+
* @default false
|
|
732
|
+
*/
|
|
733
|
+
autoClaim?: boolean;
|
|
734
|
+
/**
|
|
735
|
+
* Maximum bytes before sending a batch.
|
|
736
|
+
* @default 1048576 (1MB)
|
|
737
|
+
*/
|
|
738
|
+
maxBatchBytes?: number;
|
|
739
|
+
/**
|
|
740
|
+
* Maximum time to wait for more messages before sending batch (ms).
|
|
741
|
+
* @default 5
|
|
742
|
+
*/
|
|
743
|
+
lingerMs?: number;
|
|
744
|
+
/**
|
|
745
|
+
* Maximum number of concurrent batches in flight.
|
|
746
|
+
* Higher values improve throughput at the cost of more memory.
|
|
747
|
+
* @default 5
|
|
748
|
+
*/
|
|
749
|
+
maxInFlight?: number;
|
|
750
|
+
/**
|
|
751
|
+
* Custom fetch implementation.
|
|
752
|
+
*/
|
|
753
|
+
fetch?: typeof globalThis.fetch;
|
|
754
|
+
/**
|
|
755
|
+
* AbortSignal for the producer lifecycle.
|
|
756
|
+
*/
|
|
757
|
+
signal?: AbortSignal;
|
|
758
|
+
/**
|
|
759
|
+
* Callback for batch errors in fire-and-forget mode.
|
|
760
|
+
* Since append() returns immediately, errors are reported via this callback.
|
|
761
|
+
* @param error - The error that occurred
|
|
762
|
+
*/
|
|
763
|
+
onError?: (error: Error) => void;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Result of an append operation from IdempotentProducer.
|
|
767
|
+
*/
|
|
768
|
+
interface IdempotentAppendResult {
|
|
769
|
+
/**
|
|
770
|
+
* The offset after this message was appended.
|
|
771
|
+
*/
|
|
772
|
+
offset: Offset;
|
|
773
|
+
/**
|
|
774
|
+
* Whether this was a duplicate (idempotent success).
|
|
775
|
+
*/
|
|
776
|
+
duplicate: boolean;
|
|
701
777
|
} //#endregion
|
|
702
778
|
//#region src/stream-api.d.ts
|
|
703
779
|
/**
|
|
@@ -980,6 +1056,125 @@ declare function warnIfUsingHttpInBrowser(url: string | URL, warnOnHttp?: boolea
|
|
|
980
1056
|
*/
|
|
981
1057
|
declare function _resetHttpWarningForTesting(): void;
|
|
982
1058
|
|
|
1059
|
+
//#endregion
|
|
1060
|
+
//#region src/idempotent-producer.d.ts
|
|
1061
|
+
/**
|
|
1062
|
+
* Error thrown when a producer's epoch is stale (zombie fencing).
|
|
1063
|
+
*/
|
|
1064
|
+
declare class StaleEpochError extends Error {
|
|
1065
|
+
/**
|
|
1066
|
+
* The current epoch on the server.
|
|
1067
|
+
*/
|
|
1068
|
+
readonly currentEpoch: number;
|
|
1069
|
+
constructor(currentEpoch: number);
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Error thrown when an unrecoverable sequence gap is detected.
|
|
1073
|
+
*
|
|
1074
|
+
* With maxInFlight > 1, HTTP requests can arrive out of order at the server,
|
|
1075
|
+
* causing temporary 409 responses. The client automatically handles these
|
|
1076
|
+
* by waiting for earlier sequences to complete, then retrying.
|
|
1077
|
+
*
|
|
1078
|
+
* This error is only thrown when the gap cannot be resolved (e.g., the
|
|
1079
|
+
* expected sequence is >= our sequence, indicating a true protocol violation).
|
|
1080
|
+
*/
|
|
1081
|
+
declare class SequenceGapError extends Error {
|
|
1082
|
+
readonly expectedSeq: number;
|
|
1083
|
+
readonly receivedSeq: number;
|
|
1084
|
+
constructor(expectedSeq: number, receivedSeq: number);
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* An idempotent producer for exactly-once writes to a durable stream.
|
|
1088
|
+
*
|
|
1089
|
+
* Features:
|
|
1090
|
+
* - Fire-and-forget: append() returns immediately, batches in background
|
|
1091
|
+
* - Exactly-once: server deduplicates using (producerId, epoch, seq)
|
|
1092
|
+
* - Batching: multiple appends batched into single HTTP request
|
|
1093
|
+
* - Pipelining: up to maxInFlight concurrent batches
|
|
1094
|
+
* - Zombie fencing: stale producers rejected via epoch validation
|
|
1095
|
+
*
|
|
1096
|
+
* @example
|
|
1097
|
+
* ```typescript
|
|
1098
|
+
* const stream = new DurableStream({ url: "https://..." });
|
|
1099
|
+
* const producer = new IdempotentProducer(stream, "order-service-1", {
|
|
1100
|
+
* epoch: 0,
|
|
1101
|
+
* autoClaim: true,
|
|
1102
|
+
* });
|
|
1103
|
+
*
|
|
1104
|
+
* // Fire-and-forget writes (synchronous, returns immediately)
|
|
1105
|
+
* producer.append("message 1");
|
|
1106
|
+
* producer.append("message 2");
|
|
1107
|
+
*
|
|
1108
|
+
* // Ensure all messages are delivered before shutdown
|
|
1109
|
+
* await producer.flush();
|
|
1110
|
+
* await producer.close();
|
|
1111
|
+
* ```
|
|
1112
|
+
*/
|
|
1113
|
+
declare class IdempotentProducer {
|
|
1114
|
+
#private;
|
|
1115
|
+
/**
|
|
1116
|
+
* Create an idempotent producer for a stream.
|
|
1117
|
+
*
|
|
1118
|
+
* @param stream - The DurableStream to write to
|
|
1119
|
+
* @param producerId - Stable identifier for this producer (e.g., "order-service-1")
|
|
1120
|
+
* @param opts - Producer options
|
|
1121
|
+
*/
|
|
1122
|
+
constructor(stream: DurableStream, producerId: string, opts?: IdempotentProducerOptions);
|
|
1123
|
+
/**
|
|
1124
|
+
* Append data to the stream.
|
|
1125
|
+
*
|
|
1126
|
+
* This is fire-and-forget: returns immediately after adding to the batch.
|
|
1127
|
+
* The message is batched and sent when:
|
|
1128
|
+
* - maxBatchBytes is reached
|
|
1129
|
+
* - lingerMs elapses
|
|
1130
|
+
* - flush() is called
|
|
1131
|
+
*
|
|
1132
|
+
* Errors are reported via onError callback if configured. Use flush() to
|
|
1133
|
+
* wait for all pending messages to be sent.
|
|
1134
|
+
*
|
|
1135
|
+
* For JSON streams, pass native objects (which will be serialized internally).
|
|
1136
|
+
* For byte streams, pass string or Uint8Array.
|
|
1137
|
+
*
|
|
1138
|
+
* @param body - Data to append (object for JSON streams, string or Uint8Array for byte streams)
|
|
1139
|
+
*/
|
|
1140
|
+
append(body: Uint8Array | string | unknown): void;
|
|
1141
|
+
/**
|
|
1142
|
+
* Send any pending batch immediately and wait for all in-flight batches.
|
|
1143
|
+
*
|
|
1144
|
+
* Call this before shutdown to ensure all messages are delivered.
|
|
1145
|
+
*/
|
|
1146
|
+
flush(): Promise<void>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Flush pending messages and close the producer.
|
|
1149
|
+
*
|
|
1150
|
+
* After calling close(), further append() calls will throw.
|
|
1151
|
+
*/
|
|
1152
|
+
close(): Promise<void>;
|
|
1153
|
+
/**
|
|
1154
|
+
* Increment epoch and reset sequence.
|
|
1155
|
+
*
|
|
1156
|
+
* Call this when restarting the producer to establish a new session.
|
|
1157
|
+
* Flushes any pending messages first.
|
|
1158
|
+
*/
|
|
1159
|
+
restart(): Promise<void>;
|
|
1160
|
+
/**
|
|
1161
|
+
* Current epoch for this producer.
|
|
1162
|
+
*/
|
|
1163
|
+
get epoch(): number;
|
|
1164
|
+
/**
|
|
1165
|
+
* Next sequence number to be assigned.
|
|
1166
|
+
*/
|
|
1167
|
+
get nextSeq(): number;
|
|
1168
|
+
/**
|
|
1169
|
+
* Number of messages in the current pending batch.
|
|
1170
|
+
*/
|
|
1171
|
+
get pendingCount(): number;
|
|
1172
|
+
/**
|
|
1173
|
+
* Number of batches currently in flight.
|
|
1174
|
+
*/
|
|
1175
|
+
get inFlightCount(): number;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
983
1178
|
//#endregion
|
|
984
1179
|
//#region src/error.d.ts
|
|
985
1180
|
/**
|
|
@@ -1077,6 +1272,28 @@ declare const STREAM_TTL_HEADER = "Stream-TTL";
|
|
|
1077
1272
|
*/
|
|
1078
1273
|
declare const STREAM_EXPIRES_AT_HEADER = "Stream-Expires-At";
|
|
1079
1274
|
/**
|
|
1275
|
+
* Request header for producer ID (client-supplied stable identifier).
|
|
1276
|
+
*/
|
|
1277
|
+
declare const PRODUCER_ID_HEADER = "Producer-Id";
|
|
1278
|
+
/**
|
|
1279
|
+
* Request/response header for producer epoch.
|
|
1280
|
+
* Client-declared, server-validated monotonically increasing.
|
|
1281
|
+
*/
|
|
1282
|
+
declare const PRODUCER_EPOCH_HEADER = "Producer-Epoch";
|
|
1283
|
+
/**
|
|
1284
|
+
* Request header for producer sequence number.
|
|
1285
|
+
* Monotonically increasing per epoch, per-batch (not per-message).
|
|
1286
|
+
*/
|
|
1287
|
+
declare const PRODUCER_SEQ_HEADER = "Producer-Seq";
|
|
1288
|
+
/**
|
|
1289
|
+
* Response header indicating expected sequence number on 409 Conflict.
|
|
1290
|
+
*/
|
|
1291
|
+
declare const PRODUCER_EXPECTED_SEQ_HEADER = "Producer-Expected-Seq";
|
|
1292
|
+
/**
|
|
1293
|
+
* Response header indicating received sequence number on 409 Conflict.
|
|
1294
|
+
*/
|
|
1295
|
+
declare const PRODUCER_RECEIVED_SEQ_HEADER = "Producer-Received-Seq";
|
|
1296
|
+
/**
|
|
1080
1297
|
* Query parameter for starting offset.
|
|
1081
1298
|
*/
|
|
1082
1299
|
declare const OFFSET_QUERY_PARAM = "offset";
|
|
@@ -1105,4 +1322,4 @@ declare const SSE_COMPATIBLE_CONTENT_TYPES: ReadonlyArray<string>;
|
|
|
1105
1322
|
declare const DURABLE_STREAM_PROTOCOL_QUERY_PARAMS: Array<string>;
|
|
1106
1323
|
|
|
1107
1324
|
//#endregion
|
|
1108
|
-
export { AppendOptions, BackoffDefaults, BackoffOptions, ByteChunk, CURSOR_QUERY_PARAM, CreateOptions, DURABLE_STREAM_PROTOCOL_QUERY_PARAMS, DurableStream, DurableStreamError, DurableStreamErrorCode, DurableStreamOptions, FetchBackoffAbortError, FetchError, HeadResult, HeadersRecord, InvalidSignalError, JsonBatch, JsonBatchMeta, LIVE_QUERY_PARAM, LegacyLiveMode, LiveMode, MaybePromise, MissingStreamUrlError, OFFSET_QUERY_PARAM, Offset, 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, StreamErrorHandler, StreamHandleOptions, StreamOptions, StreamResponse, TextChunk, _resetHttpWarningForTesting, asAsyncIterableReadableStream, createFetchWithBackoff, createFetchWithConsumedBody, stream, warnIfUsingHttpInBrowser };
|
|
1325
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -436,6 +436,23 @@ interface AppendOptions {
|
|
|
436
436
|
* AbortSignal for this operation.
|
|
437
437
|
*/
|
|
438
438
|
signal?: AbortSignal;
|
|
439
|
+
/**
|
|
440
|
+
* Producer ID for idempotent writes.
|
|
441
|
+
* Client-supplied stable identifier (e.g., "order-service-1").
|
|
442
|
+
* Must be provided together with producerEpoch and producerSeq.
|
|
443
|
+
*/
|
|
444
|
+
producerId?: string;
|
|
445
|
+
/**
|
|
446
|
+
* Producer epoch for idempotent writes.
|
|
447
|
+
* Client-declared, server-validated monotonically increasing.
|
|
448
|
+
* Increment on producer restart.
|
|
449
|
+
*/
|
|
450
|
+
producerEpoch?: number;
|
|
451
|
+
/**
|
|
452
|
+
* Producer sequence for idempotent writes.
|
|
453
|
+
* Monotonically increasing per epoch, per-batch.
|
|
454
|
+
*/
|
|
455
|
+
producerSeq?: number;
|
|
439
456
|
}
|
|
440
457
|
/**
|
|
441
458
|
* Legacy live mode type (internal use only).
|
|
@@ -698,6 +715,65 @@ interface StreamResponse<TJson = unknown> {
|
|
|
698
715
|
* - terminal error.
|
|
699
716
|
*/
|
|
700
717
|
readonly closed: Promise<void>;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Options for creating an IdempotentProducer.
|
|
721
|
+
*/
|
|
722
|
+
interface IdempotentProducerOptions {
|
|
723
|
+
/**
|
|
724
|
+
* Starting epoch (default: 0).
|
|
725
|
+
* Increment this on producer restart.
|
|
726
|
+
*/
|
|
727
|
+
epoch?: number;
|
|
728
|
+
/**
|
|
729
|
+
* On 403 Forbidden (stale epoch), automatically retry with epoch+1.
|
|
730
|
+
* Useful for serverless/ephemeral producers.
|
|
731
|
+
* @default false
|
|
732
|
+
*/
|
|
733
|
+
autoClaim?: boolean;
|
|
734
|
+
/**
|
|
735
|
+
* Maximum bytes before sending a batch.
|
|
736
|
+
* @default 1048576 (1MB)
|
|
737
|
+
*/
|
|
738
|
+
maxBatchBytes?: number;
|
|
739
|
+
/**
|
|
740
|
+
* Maximum time to wait for more messages before sending batch (ms).
|
|
741
|
+
* @default 5
|
|
742
|
+
*/
|
|
743
|
+
lingerMs?: number;
|
|
744
|
+
/**
|
|
745
|
+
* Maximum number of concurrent batches in flight.
|
|
746
|
+
* Higher values improve throughput at the cost of more memory.
|
|
747
|
+
* @default 5
|
|
748
|
+
*/
|
|
749
|
+
maxInFlight?: number;
|
|
750
|
+
/**
|
|
751
|
+
* Custom fetch implementation.
|
|
752
|
+
*/
|
|
753
|
+
fetch?: typeof globalThis.fetch;
|
|
754
|
+
/**
|
|
755
|
+
* AbortSignal for the producer lifecycle.
|
|
756
|
+
*/
|
|
757
|
+
signal?: AbortSignal;
|
|
758
|
+
/**
|
|
759
|
+
* Callback for batch errors in fire-and-forget mode.
|
|
760
|
+
* Since append() returns immediately, errors are reported via this callback.
|
|
761
|
+
* @param error - The error that occurred
|
|
762
|
+
*/
|
|
763
|
+
onError?: (error: Error) => void;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Result of an append operation from IdempotentProducer.
|
|
767
|
+
*/
|
|
768
|
+
interface IdempotentAppendResult {
|
|
769
|
+
/**
|
|
770
|
+
* The offset after this message was appended.
|
|
771
|
+
*/
|
|
772
|
+
offset: Offset;
|
|
773
|
+
/**
|
|
774
|
+
* Whether this was a duplicate (idempotent success).
|
|
775
|
+
*/
|
|
776
|
+
duplicate: boolean;
|
|
701
777
|
} //#endregion
|
|
702
778
|
//#region src/stream-api.d.ts
|
|
703
779
|
/**
|
|
@@ -980,6 +1056,125 @@ declare function warnIfUsingHttpInBrowser(url: string | URL, warnOnHttp?: boolea
|
|
|
980
1056
|
*/
|
|
981
1057
|
declare function _resetHttpWarningForTesting(): void;
|
|
982
1058
|
|
|
1059
|
+
//#endregion
|
|
1060
|
+
//#region src/idempotent-producer.d.ts
|
|
1061
|
+
/**
|
|
1062
|
+
* Error thrown when a producer's epoch is stale (zombie fencing).
|
|
1063
|
+
*/
|
|
1064
|
+
declare class StaleEpochError extends Error {
|
|
1065
|
+
/**
|
|
1066
|
+
* The current epoch on the server.
|
|
1067
|
+
*/
|
|
1068
|
+
readonly currentEpoch: number;
|
|
1069
|
+
constructor(currentEpoch: number);
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Error thrown when an unrecoverable sequence gap is detected.
|
|
1073
|
+
*
|
|
1074
|
+
* With maxInFlight > 1, HTTP requests can arrive out of order at the server,
|
|
1075
|
+
* causing temporary 409 responses. The client automatically handles these
|
|
1076
|
+
* by waiting for earlier sequences to complete, then retrying.
|
|
1077
|
+
*
|
|
1078
|
+
* This error is only thrown when the gap cannot be resolved (e.g., the
|
|
1079
|
+
* expected sequence is >= our sequence, indicating a true protocol violation).
|
|
1080
|
+
*/
|
|
1081
|
+
declare class SequenceGapError extends Error {
|
|
1082
|
+
readonly expectedSeq: number;
|
|
1083
|
+
readonly receivedSeq: number;
|
|
1084
|
+
constructor(expectedSeq: number, receivedSeq: number);
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* An idempotent producer for exactly-once writes to a durable stream.
|
|
1088
|
+
*
|
|
1089
|
+
* Features:
|
|
1090
|
+
* - Fire-and-forget: append() returns immediately, batches in background
|
|
1091
|
+
* - Exactly-once: server deduplicates using (producerId, epoch, seq)
|
|
1092
|
+
* - Batching: multiple appends batched into single HTTP request
|
|
1093
|
+
* - Pipelining: up to maxInFlight concurrent batches
|
|
1094
|
+
* - Zombie fencing: stale producers rejected via epoch validation
|
|
1095
|
+
*
|
|
1096
|
+
* @example
|
|
1097
|
+
* ```typescript
|
|
1098
|
+
* const stream = new DurableStream({ url: "https://..." });
|
|
1099
|
+
* const producer = new IdempotentProducer(stream, "order-service-1", {
|
|
1100
|
+
* epoch: 0,
|
|
1101
|
+
* autoClaim: true,
|
|
1102
|
+
* });
|
|
1103
|
+
*
|
|
1104
|
+
* // Fire-and-forget writes (synchronous, returns immediately)
|
|
1105
|
+
* producer.append("message 1");
|
|
1106
|
+
* producer.append("message 2");
|
|
1107
|
+
*
|
|
1108
|
+
* // Ensure all messages are delivered before shutdown
|
|
1109
|
+
* await producer.flush();
|
|
1110
|
+
* await producer.close();
|
|
1111
|
+
* ```
|
|
1112
|
+
*/
|
|
1113
|
+
declare class IdempotentProducer {
|
|
1114
|
+
#private;
|
|
1115
|
+
/**
|
|
1116
|
+
* Create an idempotent producer for a stream.
|
|
1117
|
+
*
|
|
1118
|
+
* @param stream - The DurableStream to write to
|
|
1119
|
+
* @param producerId - Stable identifier for this producer (e.g., "order-service-1")
|
|
1120
|
+
* @param opts - Producer options
|
|
1121
|
+
*/
|
|
1122
|
+
constructor(stream: DurableStream, producerId: string, opts?: IdempotentProducerOptions);
|
|
1123
|
+
/**
|
|
1124
|
+
* Append data to the stream.
|
|
1125
|
+
*
|
|
1126
|
+
* This is fire-and-forget: returns immediately after adding to the batch.
|
|
1127
|
+
* The message is batched and sent when:
|
|
1128
|
+
* - maxBatchBytes is reached
|
|
1129
|
+
* - lingerMs elapses
|
|
1130
|
+
* - flush() is called
|
|
1131
|
+
*
|
|
1132
|
+
* Errors are reported via onError callback if configured. Use flush() to
|
|
1133
|
+
* wait for all pending messages to be sent.
|
|
1134
|
+
*
|
|
1135
|
+
* For JSON streams, pass native objects (which will be serialized internally).
|
|
1136
|
+
* For byte streams, pass string or Uint8Array.
|
|
1137
|
+
*
|
|
1138
|
+
* @param body - Data to append (object for JSON streams, string or Uint8Array for byte streams)
|
|
1139
|
+
*/
|
|
1140
|
+
append(body: Uint8Array | string | unknown): void;
|
|
1141
|
+
/**
|
|
1142
|
+
* Send any pending batch immediately and wait for all in-flight batches.
|
|
1143
|
+
*
|
|
1144
|
+
* Call this before shutdown to ensure all messages are delivered.
|
|
1145
|
+
*/
|
|
1146
|
+
flush(): Promise<void>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Flush pending messages and close the producer.
|
|
1149
|
+
*
|
|
1150
|
+
* After calling close(), further append() calls will throw.
|
|
1151
|
+
*/
|
|
1152
|
+
close(): Promise<void>;
|
|
1153
|
+
/**
|
|
1154
|
+
* Increment epoch and reset sequence.
|
|
1155
|
+
*
|
|
1156
|
+
* Call this when restarting the producer to establish a new session.
|
|
1157
|
+
* Flushes any pending messages first.
|
|
1158
|
+
*/
|
|
1159
|
+
restart(): Promise<void>;
|
|
1160
|
+
/**
|
|
1161
|
+
* Current epoch for this producer.
|
|
1162
|
+
*/
|
|
1163
|
+
get epoch(): number;
|
|
1164
|
+
/**
|
|
1165
|
+
* Next sequence number to be assigned.
|
|
1166
|
+
*/
|
|
1167
|
+
get nextSeq(): number;
|
|
1168
|
+
/**
|
|
1169
|
+
* Number of messages in the current pending batch.
|
|
1170
|
+
*/
|
|
1171
|
+
get pendingCount(): number;
|
|
1172
|
+
/**
|
|
1173
|
+
* Number of batches currently in flight.
|
|
1174
|
+
*/
|
|
1175
|
+
get inFlightCount(): number;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
983
1178
|
//#endregion
|
|
984
1179
|
//#region src/error.d.ts
|
|
985
1180
|
/**
|
|
@@ -1077,6 +1272,28 @@ declare const STREAM_TTL_HEADER = "Stream-TTL";
|
|
|
1077
1272
|
*/
|
|
1078
1273
|
declare const STREAM_EXPIRES_AT_HEADER = "Stream-Expires-At";
|
|
1079
1274
|
/**
|
|
1275
|
+
* Request header for producer ID (client-supplied stable identifier).
|
|
1276
|
+
*/
|
|
1277
|
+
declare const PRODUCER_ID_HEADER = "Producer-Id";
|
|
1278
|
+
/**
|
|
1279
|
+
* Request/response header for producer epoch.
|
|
1280
|
+
* Client-declared, server-validated monotonically increasing.
|
|
1281
|
+
*/
|
|
1282
|
+
declare const PRODUCER_EPOCH_HEADER = "Producer-Epoch";
|
|
1283
|
+
/**
|
|
1284
|
+
* Request header for producer sequence number.
|
|
1285
|
+
* Monotonically increasing per epoch, per-batch (not per-message).
|
|
1286
|
+
*/
|
|
1287
|
+
declare const PRODUCER_SEQ_HEADER = "Producer-Seq";
|
|
1288
|
+
/**
|
|
1289
|
+
* Response header indicating expected sequence number on 409 Conflict.
|
|
1290
|
+
*/
|
|
1291
|
+
declare const PRODUCER_EXPECTED_SEQ_HEADER = "Producer-Expected-Seq";
|
|
1292
|
+
/**
|
|
1293
|
+
* Response header indicating received sequence number on 409 Conflict.
|
|
1294
|
+
*/
|
|
1295
|
+
declare const PRODUCER_RECEIVED_SEQ_HEADER = "Producer-Received-Seq";
|
|
1296
|
+
/**
|
|
1080
1297
|
* Query parameter for starting offset.
|
|
1081
1298
|
*/
|
|
1082
1299
|
declare const OFFSET_QUERY_PARAM = "offset";
|
|
@@ -1105,4 +1322,4 @@ declare const SSE_COMPATIBLE_CONTENT_TYPES: ReadonlyArray<string>;
|
|
|
1105
1322
|
declare const DURABLE_STREAM_PROTOCOL_QUERY_PARAMS: Array<string>;
|
|
1106
1323
|
|
|
1107
1324
|
//#endregion
|
|
1108
|
-
export { AppendOptions, BackoffDefaults, BackoffOptions, ByteChunk, CURSOR_QUERY_PARAM, CreateOptions, DURABLE_STREAM_PROTOCOL_QUERY_PARAMS, DurableStream, DurableStreamError, DurableStreamErrorCode, DurableStreamOptions, FetchBackoffAbortError, FetchError, HeadResult, HeadersRecord, InvalidSignalError, JsonBatch, JsonBatchMeta, LIVE_QUERY_PARAM, LegacyLiveMode, LiveMode, MaybePromise, MissingStreamUrlError, OFFSET_QUERY_PARAM, Offset, 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, StreamErrorHandler, StreamHandleOptions, StreamOptions, StreamResponse, TextChunk, _resetHttpWarningForTesting, asAsyncIterableReadableStream, createFetchWithBackoff, createFetchWithConsumedBody, stream, warnIfUsingHttpInBrowser };
|
|
1325
|
+
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 };
|