@restatedev/restate-sdk-integration-client 0.0.0-placeholder → 1.18.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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +133 -0
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/api.d.cts +219 -0
  5. package/dist/api.d.cts.map +1 -0
  6. package/dist/api.d.ts +219 -0
  7. package/dist/api.d.ts.map +1 -0
  8. package/dist/client.cjs +101 -0
  9. package/dist/client.d.cts +26 -0
  10. package/dist/client.d.cts.map +1 -0
  11. package/dist/client.d.ts +26 -0
  12. package/dist/client.d.ts.map +1 -0
  13. package/dist/client.js +99 -0
  14. package/dist/client.js.map +1 -0
  15. package/dist/errors.cjs +52 -0
  16. package/dist/errors.d.cts +42 -0
  17. package/dist/errors.d.cts.map +1 -0
  18. package/dist/errors.d.ts +42 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +51 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/generated/dev/restate/ingress/ingestion/v1/ingestion_svc_pb.cjs +137 -0
  23. package/dist/generated/dev/restate/ingress/ingestion/v1/ingestion_svc_pb.d.cts +1 -0
  24. package/dist/generated/dev/restate/ingress/ingestion/v1/ingestion_svc_pb.d.ts +2 -0
  25. package/dist/generated/dev/restate/ingress/ingestion/v1/ingestion_svc_pb.js +131 -0
  26. package/dist/generated/dev/restate/ingress/ingestion/v1/ingestion_svc_pb.js.map +1 -0
  27. package/dist/index.cjs +5 -0
  28. package/dist/index.d.cts +4 -0
  29. package/dist/index.d.ts +4 -0
  30. package/dist/index.js +4 -0
  31. package/dist/package.cjs +11 -0
  32. package/dist/package.js +6 -0
  33. package/dist/package.js.map +1 -0
  34. package/dist/producer.cjs +245 -0
  35. package/dist/producer.js +244 -0
  36. package/dist/producer.js.map +1 -0
  37. package/dist/proto.cjs +37 -0
  38. package/dist/proto.js +35 -0
  39. package/dist/proto.js.map +1 -0
  40. package/dist/queue.cjs +40 -0
  41. package/dist/queue.js +40 -0
  42. package/dist/queue.js.map +1 -0
  43. package/package.json +64 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # @restatedev/restate-sdk-integration-client
2
+
3
+ Turn any source of events into Restate invocations through the Restate ingestion API.
4
+
5
+ > **Experimental.** The ingestion API is not yet part of a released Restate version.
6
+
7
+ Node-only (uses `node:http2`). Node ≥ 22.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @restatedev/restate-sdk-integration-client
13
+ ```
14
+
15
+ ## Create a client
16
+
17
+ Create one client for your Restate ingress URL and close it when your integration shuts down:
18
+
19
+ ```ts
20
+ import { connect } from "@restatedev/restate-sdk-integration-client";
21
+
22
+ const client = connect({ url: "http://localhost:8080" });
23
+ // Use the client
24
+ await client.close();
25
+ ```
26
+
27
+ Pass `authToken` to send a bearer token.
28
+
29
+ ## Simple producer
30
+
31
+ Use `producer()` when your source does not provide stable offsets that you can replay.
32
+ Call `close()` (or `flush()`) to wait until Restate has durably committed everything you sent:
33
+
34
+ ```ts
35
+ const producer = client.producer();
36
+ for (const record of records) {
37
+ await producer.send({
38
+ service: "OrderService",
39
+ handler: "ingest",
40
+ headers: { "content-type": "application/json" },
41
+ body: record.payload,
42
+ });
43
+ }
44
+ await producer.close();
45
+ ```
46
+
47
+ `send()` resolves once the producer accepted the record into its buffer, not once Restate committed it.
48
+ When the buffer is full (`bufferBytes`, 32 MiB by default) `send()` waits, so **always await `send()`**:
49
+ calls that are not awaited keep waiting for buffer space without any bound.
50
+
51
+ To wait a single individual record to be committed instead, pass `waitCommitted`:
52
+
53
+ ```ts
54
+ const offset = await producer.send(record, { waitCommitted: true });
55
+ ```
56
+
57
+ ## Exactly-once producer
58
+
59
+ Use `exactlyOnceProducer()` when your source provides stable, strictly increasing offsets.
60
+ Restate deduplicates records on `(producerId, offset)`, across streams and restarts,
61
+ so choose a producer id that remains stable across restarts and is unique to that offset sequence.
62
+
63
+ Checkpoint the committed offset in your source with `onCommitted`, or with the value returned by `flush()`.
64
+ After a restart, resume from the checkpoint: Restate drops the records it already committed.
65
+
66
+ ```ts
67
+ const producer = client.exactlyOnceProducer("orders/partition-0", {
68
+ // Optional, you can use this to add a hook to your source checkpointing
69
+ onCommitted: (offset) => checkpoints.save("orders/partition-0", offset),
70
+ });
71
+ for (const record of sourceRecords) {
72
+ await producer.send({
73
+ offset: record.offset,
74
+ service: "OrderService",
75
+ handler: "ingest",
76
+ body: record.payload,
77
+ });
78
+ }
79
+ // Waits all previous records to be durably committed
80
+ const committedOffset = await producer.flush();
81
+ ```
82
+
83
+ ## Producer defaults
84
+
85
+ Producers accept `defaults` when every invocation shares fields such as the target service, handler, or headers.
86
+ Defaults are sent once, when the stream is opened, instead of with every invocation.
87
+ Fields set on an individual invocation override the defaults.
88
+
89
+ ```ts
90
+ const producer = client.producer({
91
+ defaults: {
92
+ service: "OrderService",
93
+ handler: "ingest",
94
+ headers: { "content-type": "application/json" },
95
+ },
96
+ });
97
+ for (const record of records) {
98
+ await producer.send({ body: record.payload });
99
+ }
100
+ ```
101
+
102
+ ## Piping a source
103
+
104
+ `producer.writable` is a `WritableStream` view of the producer: writing sends the record,
105
+ closing the stream closes the producer, and the producer buffer applies backpressure to the source.
106
+
107
+ ```ts
108
+ await ReadableStream.from(records)
109
+ .pipeThrough(
110
+ new TransformStream({
111
+ transform: (record, controller) =>
112
+ controller.enqueue({ body: record.payload }),
113
+ })
114
+ )
115
+ .pipeTo(producer.writable);
116
+ ```
117
+
118
+ With Node streams, convert it with `Writable.fromWeb`:
119
+
120
+ ```ts
121
+ import { Writable } from "node:stream";
122
+ import { pipeline } from "node:stream/promises";
123
+
124
+ await pipeline(
125
+ source,
126
+ async function* (records) {
127
+ for await (const record of records) yield { body: record.payload };
128
+ },
129
+ Writable.fromWeb(producer.writable, { objectMode: true })
130
+ );
131
+ ```
132
+
133
+
@@ -0,0 +1,25 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ exports.__toESM = __toESM;
package/dist/api.d.cts ADDED
@@ -0,0 +1,219 @@
1
+ import { Transport } from "@connectrpc/connect";
2
+
3
+ //#region src/api.d.ts
4
+
5
+ /**
6
+ * Options for {@link connect}.
7
+ *
8
+ * @experimental
9
+ */
10
+ interface IntegrationClientOptions {
11
+ /**
12
+ * Restate ingress URL, e.g. `http://localhost:8080`. `https` selects TLS.
13
+ */
14
+ url: string;
15
+ /**
16
+ * Bearer token, sent as the `authorization` header of every ingestion stream.
17
+ */
18
+ authToken?: string;
19
+ /**
20
+ * Identifies the integration to Restate, as `name/version`. Restate records it on
21
+ * traces and metrics. Longer than 64 bytes, it is truncated.
22
+ *
23
+ * Defaults to this client's own identity, `restate-integration-client-ts/<version>`.
24
+ */
25
+ integration?: {
26
+ name: string;
27
+ version: string;
28
+ };
29
+ /**
30
+ * Connect transport to use instead of opening a new HTTP/2 connection to
31
+ * {@link IntegrationClientOptions.url}.
32
+ * The transport remains owned by the caller and {@link IntegrationClient.close} does not
33
+ * close it.
34
+ */
35
+ transport?: Transport;
36
+ }
37
+ /**
38
+ * Entry point for producing invocations to Restate through the ingestion API.
39
+ *
40
+ * @experimental
41
+ */
42
+ interface IntegrationClient {
43
+ /**
44
+ * Creates an at-least-once {@link Producer}. Offsets are assigned automatically, and
45
+ * records resent on a new stream are not deduplicated: set {@link Invocation.idempotencyKey}
46
+ * when handler-level deduplication is required.
47
+ */
48
+ producer(opts?: ProducerOptions): Producer;
49
+ /**
50
+ * Creates an {@link ExactlyOnceProducer}. Restate deduplicates on `(producerId, offset)`, so
51
+ * choose a producer id that is stable across restarts and distinct per independent offset
52
+ * sequence, e.g. a Kafka `groupId/topic/partition`.
53
+ *
54
+ * @param producerId - stable identity of the producer, non-empty and at most 256 bytes.
55
+ */
56
+ exactlyOnceProducer(producerId: string, opts?: ProducerOptions): ExactlyOnceProducer;
57
+ /**
58
+ * Closes the HTTP/2 connection opened by this client. Close (or flush) the producers
59
+ * first when their records must be durably committed.
60
+ */
61
+ close(): Promise<void>;
62
+ }
63
+ /**
64
+ * Invocation fields shared by every record of a producer, see {@link ProducerOptions.defaults}.
65
+ *
66
+ * @experimental
67
+ */
68
+ interface InvocationDefaults {
69
+ /** Target service name. */
70
+ service?: string;
71
+ /** Target handler name. */
72
+ handler?: string;
73
+ /** Target key, required when the target is a Virtual Object or a Workflow. */
74
+ key?: string;
75
+ /** Invocation scope. */
76
+ scope?: string;
77
+ /** Concurrency/rate limit key. */
78
+ limitKey?: string;
79
+ /** Headers. A record's own headers are added to these, overriding the same keys. */
80
+ headers?: Record<string, string>;
81
+ }
82
+ /**
83
+ * A record to send through a {@link Producer}. Fields set here override the producer
84
+ * {@link ProducerOptions.defaults}.
85
+ *
86
+ * @experimental
87
+ */
88
+ interface Invocation extends InvocationDefaults {
89
+ /** Invocation payload. Strings are encoded as UTF-8. */
90
+ body?: Uint8Array | string;
91
+ /** Idempotency key used by Restate to deduplicate the invocation. */
92
+ idempotencyKey?: string;
93
+ /** Schedule the invocation at this time. */
94
+ invokeAt?: Date;
95
+ /** W3C `traceparent`. */
96
+ traceparent?: string;
97
+ /** W3C `tracestate`. */
98
+ tracestate?: string;
99
+ }
100
+ /**
101
+ * A record to send through an {@link ExactlyOnceProducer}.
102
+ *
103
+ * @experimental
104
+ */
105
+ interface ExactlyOnceInvocation extends Invocation {
106
+ /**
107
+ * Position of this record in the source, e.g. a Kafka offset. Must be strictly greater than
108
+ * the offset of the previous record sent by this producer, and at most
109
+ * `Number.MAX_SAFE_INTEGER`. Gaps are allowed.
110
+ */
111
+ offset: number;
112
+ }
113
+ /**
114
+ * Options for {@link IntegrationClient.producer} and {@link IntegrationClient.exactlyOnceProducer}.
115
+ *
116
+ * @experimental
117
+ */
118
+ interface ProducerOptions {
119
+ /**
120
+ * Fields applied to every record unless the record sets them itself. They are sent
121
+ * once, when the stream is opened.
122
+ */
123
+ defaults?: InvocationDefaults;
124
+ /**
125
+ * Maximum combined serialized size of the records waiting to be written to the stream.
126
+ * While the buffer is full, {@link ProducerBase.send} waits. Zero disables the buffer:
127
+ * `send` then waits until the record can be written to the stream directly.
128
+ *
129
+ * Defaults to 32 MiB.
130
+ */
131
+ bufferBytes?: number;
132
+ /**
133
+ * Called with the commit watermark every time it advances: every record with an offset up
134
+ * to and including it is durably committed by Restate. Use it to checkpoint an
135
+ * exactly-once source.
136
+ *
137
+ * If the callback throws, the producer is aborted with the thrown error.
138
+ */
139
+ onCommitted?: (offset: number) => void;
140
+ }
141
+ /**
142
+ * Options for {@link ProducerBase.send}.
143
+ *
144
+ * @experimental
145
+ */
146
+ interface SendOptions {
147
+ /**
148
+ * Wait until the record is durably committed by Restate, instead of only until it is
149
+ * accepted by the producer.
150
+ */
151
+ waitCommitted?: boolean;
152
+ }
153
+ /**
154
+ * Operations shared by {@link Producer} and {@link ExactlyOnceProducer}.
155
+ *
156
+ * A producer owns one ingestion stream. Errors are terminal: once the stream fails, every
157
+ * pending and later operation rejects with the same error, and a new producer is needed.
158
+ *
159
+ * @experimental
160
+ */
161
+ interface ProducerBase<R extends Invocation> {
162
+ /**
163
+ * Sends a record.
164
+ *
165
+ * The returned promise resolves with the record offset once the producer has accepted the
166
+ * record into its buffer (or, with `bufferBytes: 0`, written it to the stream), waiting
167
+ * while the buffer is full. With `waitCommitted`, it resolves once Restate has durably
168
+ * committed the record instead.
169
+ *
170
+ * Always await `send`: calls that are not awaited keep waiting for buffer space without
171
+ * any bound. Records are sent in call order, so concurrent calls, e.g. with `Promise.all`,
172
+ * are safe. Note that a record rejected by validation (an oversized record, or a
173
+ * non-increasing exactly-once offset) rejects only its own call, while the others are
174
+ * still sent: with an exactly-once producer, validate records before sending them
175
+ * concurrently, or the commit watermark can move past the rejected offset.
176
+ */
177
+ send(record: R, opts?: SendOptions): Promise<number>;
178
+ /**
179
+ * Waits until every record sent so far is durably committed.
180
+ *
181
+ * @returns the commit watermark, or -1 if nothing was sent.
182
+ */
183
+ flush(): Promise<number>;
184
+ /**
185
+ * Flushes the producer, then closes its stream.
186
+ */
187
+ close(): Promise<void>;
188
+ /**
189
+ * Closes the producer immediately, without flushing. Every pending operation rejects
190
+ * with `reason`.
191
+ */
192
+ abort(reason?: unknown): void;
193
+ /**
194
+ * A `WritableStream` view of this producer, to pipe a source into it, e.g. with
195
+ * `ReadableStream.pipeTo` or Node's `stream/promises` `pipeline`. Writing sends the
196
+ * record, closing the stream closes the producer and aborting it aborts the producer.
197
+ */
198
+ readonly writable: WritableStream<R>;
199
+ }
200
+ /**
201
+ * Sends invocations to Restate with at-least-once delivery.
202
+ *
203
+ * @experimental
204
+ */
205
+ type Producer = ProducerBase<Invocation>;
206
+ /**
207
+ * Sends invocations to Restate with exactly-once delivery: Restate deduplicates records on
208
+ * `(producerId, offset)`, across streams and restarts. After a restart, resend from the
209
+ * last checkpointed offset and Restate drops the records it already committed.
210
+ *
211
+ * @experimental
212
+ */
213
+ interface ExactlyOnceProducer extends ProducerBase<ExactlyOnceInvocation> {
214
+ /** Stable identity of this producer. */
215
+ readonly producerId: string;
216
+ }
217
+ //#endregion
218
+ export { ExactlyOnceInvocation, ExactlyOnceProducer, IntegrationClient, IntegrationClientOptions, Invocation, InvocationDefaults, Producer, ProducerBase, ProducerOptions, SendOptions };
219
+ //# sourceMappingURL=api.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.cts","names":[],"sources":["../src/api.ts"],"sourcesContent":[],"mappings":";;;;;;AAkBA;AAiCA;;AAMoC,UAvCnB,wBAAA,CAuCmB;EAWzB;;;EAOO,GAAA,EAAA,MAAA;EAQD;AAqBjB;;EAMa,SAAA,CAAA,EAAA,MAAA;EANuB;;AAkBpC;AAcA;AA+BA;AAgBA;EAAwC,WAAA,CAAA,EAAA;IAgBzB,IAAA,EAAA,MAAA;IAAU,OAAA,EAAA,MAAA;EAAc,CAAA;EAO5B;;;;;AA0BX;EASiB,SAAA,CAAA,EAtMH,SAsMG;;;;;;;UA9LA,iBAAA;;;;;;kBAMC,kBAAkB;;;;;;;;iDAWzB,kBACN;;;;;WAMM;;;;;;;UAQM,kBAAA;;;;;;;;;;;;YAYL;;;;;;;;UASK,UAAA,SAAmB;;SAE3B;;;;aAII;;;;;;;;;;;UAYI,qBAAA,SAA8B;;;;;;;;;;;;;UAc9B,eAAA;;;;;aAKJ;;;;;;;;;;;;;;;;;;;;;;;UA0BI,WAAA;;;;;;;;;;;;;;;UAgBA,uBAAuB;;;;;;;;;;;;;;;;eAgBzB,UAAU,cAAc;;;;;;WAO5B;;;;WAKA;;;;;;;;;;;qBAaU,eAAe;;;;;;;KAQxB,QAAA,GAAW,aAAa;;;;;;;;UASnB,mBAAA,SAA4B,aAAa"}
package/dist/api.d.ts ADDED
@@ -0,0 +1,219 @@
1
+ import { Transport } from "@connectrpc/connect";
2
+
3
+ //#region src/api.d.ts
4
+
5
+ /**
6
+ * Options for {@link connect}.
7
+ *
8
+ * @experimental
9
+ */
10
+ interface IntegrationClientOptions {
11
+ /**
12
+ * Restate ingress URL, e.g. `http://localhost:8080`. `https` selects TLS.
13
+ */
14
+ url: string;
15
+ /**
16
+ * Bearer token, sent as the `authorization` header of every ingestion stream.
17
+ */
18
+ authToken?: string;
19
+ /**
20
+ * Identifies the integration to Restate, as `name/version`. Restate records it on
21
+ * traces and metrics. Longer than 64 bytes, it is truncated.
22
+ *
23
+ * Defaults to this client's own identity, `restate-integration-client-ts/<version>`.
24
+ */
25
+ integration?: {
26
+ name: string;
27
+ version: string;
28
+ };
29
+ /**
30
+ * Connect transport to use instead of opening a new HTTP/2 connection to
31
+ * {@link IntegrationClientOptions.url}.
32
+ * The transport remains owned by the caller and {@link IntegrationClient.close} does not
33
+ * close it.
34
+ */
35
+ transport?: Transport;
36
+ }
37
+ /**
38
+ * Entry point for producing invocations to Restate through the ingestion API.
39
+ *
40
+ * @experimental
41
+ */
42
+ interface IntegrationClient {
43
+ /**
44
+ * Creates an at-least-once {@link Producer}. Offsets are assigned automatically, and
45
+ * records resent on a new stream are not deduplicated: set {@link Invocation.idempotencyKey}
46
+ * when handler-level deduplication is required.
47
+ */
48
+ producer(opts?: ProducerOptions): Producer;
49
+ /**
50
+ * Creates an {@link ExactlyOnceProducer}. Restate deduplicates on `(producerId, offset)`, so
51
+ * choose a producer id that is stable across restarts and distinct per independent offset
52
+ * sequence, e.g. a Kafka `groupId/topic/partition`.
53
+ *
54
+ * @param producerId - stable identity of the producer, non-empty and at most 256 bytes.
55
+ */
56
+ exactlyOnceProducer(producerId: string, opts?: ProducerOptions): ExactlyOnceProducer;
57
+ /**
58
+ * Closes the HTTP/2 connection opened by this client. Close (or flush) the producers
59
+ * first when their records must be durably committed.
60
+ */
61
+ close(): Promise<void>;
62
+ }
63
+ /**
64
+ * Invocation fields shared by every record of a producer, see {@link ProducerOptions.defaults}.
65
+ *
66
+ * @experimental
67
+ */
68
+ interface InvocationDefaults {
69
+ /** Target service name. */
70
+ service?: string;
71
+ /** Target handler name. */
72
+ handler?: string;
73
+ /** Target key, required when the target is a Virtual Object or a Workflow. */
74
+ key?: string;
75
+ /** Invocation scope. */
76
+ scope?: string;
77
+ /** Concurrency/rate limit key. */
78
+ limitKey?: string;
79
+ /** Headers. A record's own headers are added to these, overriding the same keys. */
80
+ headers?: Record<string, string>;
81
+ }
82
+ /**
83
+ * A record to send through a {@link Producer}. Fields set here override the producer
84
+ * {@link ProducerOptions.defaults}.
85
+ *
86
+ * @experimental
87
+ */
88
+ interface Invocation extends InvocationDefaults {
89
+ /** Invocation payload. Strings are encoded as UTF-8. */
90
+ body?: Uint8Array | string;
91
+ /** Idempotency key used by Restate to deduplicate the invocation. */
92
+ idempotencyKey?: string;
93
+ /** Schedule the invocation at this time. */
94
+ invokeAt?: Date;
95
+ /** W3C `traceparent`. */
96
+ traceparent?: string;
97
+ /** W3C `tracestate`. */
98
+ tracestate?: string;
99
+ }
100
+ /**
101
+ * A record to send through an {@link ExactlyOnceProducer}.
102
+ *
103
+ * @experimental
104
+ */
105
+ interface ExactlyOnceInvocation extends Invocation {
106
+ /**
107
+ * Position of this record in the source, e.g. a Kafka offset. Must be strictly greater than
108
+ * the offset of the previous record sent by this producer, and at most
109
+ * `Number.MAX_SAFE_INTEGER`. Gaps are allowed.
110
+ */
111
+ offset: number;
112
+ }
113
+ /**
114
+ * Options for {@link IntegrationClient.producer} and {@link IntegrationClient.exactlyOnceProducer}.
115
+ *
116
+ * @experimental
117
+ */
118
+ interface ProducerOptions {
119
+ /**
120
+ * Fields applied to every record unless the record sets them itself. They are sent
121
+ * once, when the stream is opened.
122
+ */
123
+ defaults?: InvocationDefaults;
124
+ /**
125
+ * Maximum combined serialized size of the records waiting to be written to the stream.
126
+ * While the buffer is full, {@link ProducerBase.send} waits. Zero disables the buffer:
127
+ * `send` then waits until the record can be written to the stream directly.
128
+ *
129
+ * Defaults to 32 MiB.
130
+ */
131
+ bufferBytes?: number;
132
+ /**
133
+ * Called with the commit watermark every time it advances: every record with an offset up
134
+ * to and including it is durably committed by Restate. Use it to checkpoint an
135
+ * exactly-once source.
136
+ *
137
+ * If the callback throws, the producer is aborted with the thrown error.
138
+ */
139
+ onCommitted?: (offset: number) => void;
140
+ }
141
+ /**
142
+ * Options for {@link ProducerBase.send}.
143
+ *
144
+ * @experimental
145
+ */
146
+ interface SendOptions {
147
+ /**
148
+ * Wait until the record is durably committed by Restate, instead of only until it is
149
+ * accepted by the producer.
150
+ */
151
+ waitCommitted?: boolean;
152
+ }
153
+ /**
154
+ * Operations shared by {@link Producer} and {@link ExactlyOnceProducer}.
155
+ *
156
+ * A producer owns one ingestion stream. Errors are terminal: once the stream fails, every
157
+ * pending and later operation rejects with the same error, and a new producer is needed.
158
+ *
159
+ * @experimental
160
+ */
161
+ interface ProducerBase<R extends Invocation> {
162
+ /**
163
+ * Sends a record.
164
+ *
165
+ * The returned promise resolves with the record offset once the producer has accepted the
166
+ * record into its buffer (or, with `bufferBytes: 0`, written it to the stream), waiting
167
+ * while the buffer is full. With `waitCommitted`, it resolves once Restate has durably
168
+ * committed the record instead.
169
+ *
170
+ * Always await `send`: calls that are not awaited keep waiting for buffer space without
171
+ * any bound. Records are sent in call order, so concurrent calls, e.g. with `Promise.all`,
172
+ * are safe. Note that a record rejected by validation (an oversized record, or a
173
+ * non-increasing exactly-once offset) rejects only its own call, while the others are
174
+ * still sent: with an exactly-once producer, validate records before sending them
175
+ * concurrently, or the commit watermark can move past the rejected offset.
176
+ */
177
+ send(record: R, opts?: SendOptions): Promise<number>;
178
+ /**
179
+ * Waits until every record sent so far is durably committed.
180
+ *
181
+ * @returns the commit watermark, or -1 if nothing was sent.
182
+ */
183
+ flush(): Promise<number>;
184
+ /**
185
+ * Flushes the producer, then closes its stream.
186
+ */
187
+ close(): Promise<void>;
188
+ /**
189
+ * Closes the producer immediately, without flushing. Every pending operation rejects
190
+ * with `reason`.
191
+ */
192
+ abort(reason?: unknown): void;
193
+ /**
194
+ * A `WritableStream` view of this producer, to pipe a source into it, e.g. with
195
+ * `ReadableStream.pipeTo` or Node's `stream/promises` `pipeline`. Writing sends the
196
+ * record, closing the stream closes the producer and aborting it aborts the producer.
197
+ */
198
+ readonly writable: WritableStream<R>;
199
+ }
200
+ /**
201
+ * Sends invocations to Restate with at-least-once delivery.
202
+ *
203
+ * @experimental
204
+ */
205
+ type Producer = ProducerBase<Invocation>;
206
+ /**
207
+ * Sends invocations to Restate with exactly-once delivery: Restate deduplicates records on
208
+ * `(producerId, offset)`, across streams and restarts. After a restart, resend from the
209
+ * last checkpointed offset and Restate drops the records it already committed.
210
+ *
211
+ * @experimental
212
+ */
213
+ interface ExactlyOnceProducer extends ProducerBase<ExactlyOnceInvocation> {
214
+ /** Stable identity of this producer. */
215
+ readonly producerId: string;
216
+ }
217
+ //#endregion
218
+ export { ExactlyOnceInvocation, ExactlyOnceProducer, IntegrationClient, IntegrationClientOptions, Invocation, InvocationDefaults, Producer, ProducerBase, ProducerOptions, SendOptions };
219
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","names":[],"sources":["../src/api.ts"],"sourcesContent":[],"mappings":";;;;;;AAkBA;AAiCA;;AAMoC,UAvCnB,wBAAA,CAuCmB;EAWzB;;;EAOO,GAAA,EAAA,MAAA;EAQD;AAqBjB;;EAMa,SAAA,CAAA,EAAA,MAAA;EANuB;;AAkBpC;AAcA;AA+BA;AAgBA;EAAwC,WAAA,CAAA,EAAA;IAgBzB,IAAA,EAAA,MAAA;IAAU,OAAA,EAAA,MAAA;EAAc,CAAA;EAO5B;;;;;AA0BX;EASiB,SAAA,CAAA,EAtMH,SAsMG;;;;;;;UA9LA,iBAAA;;;;;;kBAMC,kBAAkB;;;;;;;;iDAWzB,kBACN;;;;;WAMM;;;;;;;UAQM,kBAAA;;;;;;;;;;;;YAYL;;;;;;;;UASK,UAAA,SAAmB;;SAE3B;;;;aAII;;;;;;;;;;;UAYI,qBAAA,SAA8B;;;;;;;;;;;;;UAc9B,eAAA;;;;;aAKJ;;;;;;;;;;;;;;;;;;;;;;;UA0BI,WAAA;;;;;;;;;;;;;;;UAgBA,uBAAuB;;;;;;;;;;;;;;;;eAgBzB,UAAU,cAAc;;;;;;WAO5B;;;;WAKA;;;;;;;;;;;qBAaU,eAAe;;;;;;;KAQxB,QAAA,GAAW,aAAa;;;;;;;;UASnB,mBAAA,SAA4B,aAAa"}