Skip to content

v0.5.0

Choose a tag to compare

@github-actions github-actions released this 23 Oct 10:24
· 28 commits to main since this release
2d57ad1
  • @streamsy/core@0.5.0
  • @streamsy/projection@0.5.0
  • @streamsy/serve@0.5.0
  • @streamsy/storage@0.5.0

Durable State control messages (93fb11f)

Breaking change: the item type of a State address now includes control messages. Code that reads type, key or headers.operation from a State item must narrow the item first.

A State stream can now hold the control messages of the Durable State protocol: snapshot-start, snapshot-end and reset. Before this release, StreamAddress.state failed to decode a stored control. Streams.decode then failed the whole batch with a DecodeFault, and a follow or projection on that address stopped.

  • StreamAddress.state decodes and encodes controls. The items of a StateAddress, a Streamsy.state route and Serve.state have the new type StreamAddress.CollectionsEvent<C>. That type is CollectionsChange<C> | StateControl. It was CollectionsChange<C>.
  • StreamAddress.isControl and StreamAddress.isChange narrow an item. StreamAddress.reset(), StreamAddress.snapshotStart() and StreamAddress.snapshotEnd() make a control. Each one takes an optional { offset }.
  • StreamAddress.stateControl is the codec for one control. StreamAddress.stateChange stays the codec for the changes of one collection.
  • DurableState.changes and projection outputs accept DurableState.Entry<C>, which is a row change or a control. A control is written unchanged. With an offset, a control that has no offset gets that offset.
  • Serve.state serves stored controls as they are. It still refuses the x-streamsy-state-reset: snapshot request header.

To migrate a reader that folds State items, skip controls or handle them:

if (StreamAddress.isControl(item)) {
  if (item.headers.control === "reset") rows.clear();
} else if ("value" in item) rows.set(item.key, item.value);
else rows.delete(item.key);