github unnoq/orpc v1.8.8

4 hours ago

consumeEventIterator utility docs

oRPC provides a utility function consumeEventIterator to consume an event iterator with lifecycle callbacks.

import { consumeEventIterator } from '@orpc/client'

const cancel = consumeEventIterator(client.streaming(), {
  onEvent: (event) => {
    console.log(event.message)
  },
  onError: (error) => {
    console.error(error)
  },
  onSuccess: (value) => {
    console.log(value)
  },
  onFinish: (state) => {
    console.log(state)
  },
})

setTimeout(async () => {
  // Stop the stream after 1 second
  await cancel()
}, 1000)

optimize withEventMeta to avoid unnecessary proxies event iterator data

This prevents structuredClone from failing on proxy event iterator data, which the AI SDKdepends on.

const { messages, sendMessage, status } = useChat({
  transport: {
    async sendMessages(options) {
      return eventIteratorToStream(await client.chat({
        chatId: options.chatId,
        messages: options.messages,
      }, { signal: options.abortSignal }))
    },
    reconnectToStream(options) {
      throw new Error('Unsupported')
    },
  },
})

Note

If you find oRPC valuable and would like to support its development, you can do so here.

   🚀 Features

   🐞 Bug Fixes

  • standard-server:
    • Throw error for waiting operation if event iterator cancelled  -  by @unnoq in #974 (06aad)
    • Optimize withEventMeta to avoid unnecessary proxies event iterator data  -  by @unnoq in #979 (cedbd)
    View changes on GitHub

Don't miss a new orpc release

NewReleases is sending notifications on new releases.