<a id="streamsclient"></a>

### Streams Client

StreamsClient publishes to and reads from durable topics. Unlike
`runs.subscribeToStream`, topics are stored, independent of any run, and
readers can resume from a cursor.

#### Methods

<a id="events"></a>

##### `events()`

Yields topic's messages after options.cursor, or from the oldest retained
(or, once the topic is reset, after the reset).
If the connection drops, it resubscribes from the last message yielded, so
nothing is skipped or repeated. Ends when the server hangs up an idle
subscription, options.signal aborts, or the caller stops iterating; throws
on errors a retry can't fix, such as an expired cursor.

Parameters

Parameter, Type, Description

`topic`, `string`, the topic to read from
`options?`, [`StreamCallOptions`](#streamcalloptions), optional namespace override, resume cursor, and abort signal

Returns

`AsyncIterable`\<`StreamEvent`\>

<a id="publish"></a>

##### `publish()`

Resolves once the message is stored. A client's messages to a topic are
delivered in the order publish() was called. Publishes to a topic share
requests: everything queued while one is in flight goes out in the next,
and `batchTimeoutMs` holds a message up to that long for more to join it.

Parameters

Parameter, Type, Description

`topic`, `string`, the topic to publish to
`message`, `string` \, `Uint8Array`\<`ArrayBufferLike`\>, the message payload
`options?`, [`StreamCallOptions`](#streamcalloptions), optional namespace override and batch timeout

Returns

`Promise`\<`void`\>

<a id="reset"></a>

##### `reset()`

Makes events() calls without a cursor start after options.cursor, or the
topic's latest message. Readers already iterating, and any call with a
cursor, are unaffected.

Parameters

Parameter, Type, Description

`topic`, `string`, the topic to reset
`options?`, `Pick`\<[`StreamCallOptions`](#streamcalloptions), `"namespace"` \, `"cursor"`\>, optional namespace override and cursor to reset to

Returns

`Promise`\<`void`\>

<a id="topicmetadata"></a>

##### `topicMetadata()`

Describes topic's retained messages. Rejects with a NOT_FOUND gRPC error
for a topic nothing was published to.

Parameters

Parameter, Type, Description

`topic`, `string`, the topic to describe
`options?`, `Pick`\<[`StreamCallOptions`](#streamcalloptions), `"namespace"`\>, optional namespace override

Returns

`Promise`\<[`StreamTopicMetadata`](#streamtopicmetadata)\>

## Type Aliases

<a id="streamcalloptions"></a>

### StreamCallOptions

```ts
type StreamCallOptions = object;
```

Per-call options of the durable stream calls; the same shape on the core and Node clients.

Properties

Property, Type, Description

<a id="batchtimeoutms"></a> `batchTimeoutMs?`, `number`, For `publish`: how long the message may wait for later publishes to the same topic to share its request, bounding the latency batching adds. 0, the default, sends it as soon as no other request to the topic is in flight.
<a id="cursor"></a> `cursor?`, `string`, Resumes an `events()` iteration right after this message.
<a id="namespace"></a> `namespace?`, `string`, The topic's namespace; the empty namespace when omitted.
<a id="signal"></a> `signal?`, `AbortSignal`, Ends an `events()` iteration cleanly, without throwing; aborts a unary call.

---

<a id="streamtopicmetadata"></a>

### StreamTopicMetadata

```ts
type StreamTopicMetadata = object;
```

What a durable stream topic retains; counts and the latest message cover the tenant's retention.

Properties

Property, Type, Description

<a id="lastpublishedat"></a> `lastPublishedAt?`, `Date`, When the newest retained message was stored; undefined when none is retained.
<a id="latestcursor"></a> `latestCursor?`, `string`, Resumes `events()` after the newest retained message; undefined when none is retained.
