Skip to content

Releases: middleapi/orpc

v1.9.1

26 Sep 10:23

Choose a tag to compare

Tip

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

ย ย ย ๐Ÿš€ Features

ย ย ย ย View changes on GitHub

v1.9.0

23 Sep 11:53

Choose a tag to compare

Durable Iterator docs

Durable Iterator is a complete rewrite of the old Durable Event Iterator. It builds on Event Iterator by offloading streaming to a dedicated service that delivers durable event streams with automatic reconnections and event recovery.

Note

While not limited to Cloudflare Durable Objects, it's currently the only supported implementation.

Durable Object

import { DurableIteratorObject } from '@orpc/experimental-durable-iterator/durable-object'

export class ChatRoom extends DurableIteratorObject<{ message: string }> {
  constructor(ctx: DurableObjectState, env: Env) {
    super(ctx, env, {
      signingKey: 'secret-key', // Replace with your actual signing key
      interceptors: [
        onError(e => console.error(e)), // log error thrown from rpc calls
      ],
      onSubscribed: (websocket, lastEventId) => {
        console.log(`WebSocket Ready id=${websocket['~orpc'].deserializeId()}`)
      }
    })
  }

  someMethod() {
    // publishEvent method inherited from DurableIteratorObject
    this.publishEvent({ message: 'Hello, world!' })
  }
}

Server Side

import { DurableEventIterator } from '@orpc/experimental-durable-iterator'

export const router = {
  onMessage: base.handler(({ context }) => {
    return new DurableEventIterator<ChatRoom>('some-room', {
      tags: ['tag1', 'tag2'],
      signingKey: 'secret-key', // Replace with your actual signing key
    })
  }),

  sendMessage: base
    .input(z.object({ message: z.string() }))
    .handler(async ({ context, input }) => {
      const id = context.env.CHAT_ROOM.idFromName('some-room')
      const stub = context.env.CHAT_ROOM.get(id)

      await stub.publishEvent(input)
    }),
}

Client Side

const iterator = await client.onMessage()

for await (const { message } of iterator) {
  console.log('Received message:', message)
}

await client.sendMessage({ message: 'Hello, world!' })

experimental_streamedOptions is removed in old tanstack query

If you depend on this, please try NEW Tanstack Query Interagration


Tip

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

ย ย ย ๐Ÿš€ Features

ย ย ย ย View changes on GitHub

v1.8.9

15 Sep 13:20

Choose a tag to compare

Request Validation Plugin docs

The Request Validation Plugin ensures that only valid requests are sent to your server. This is especially valuable for applications that depend on server-side validation.

You can simplify your frontend by removing heavy form validation libraries and relying on oRPC's validation errors instead, since input validation runs directly in the browser and is highly performant.

export function ContactForm() {
  const [error, setError] = useState()

  const handleSubmit = async (form: FormData) => {
    try {
      const output = await client.someProcedure(parseFormData(form))
      console.log(output)
    }
    catch (error) {
      setError(error)
    }
  }

  return (
    <form action={handleSubmit}>
      <input name="user[name]" type="text" />
      <span>{getIssueMessage(error, 'user[name]')}</span>

      <input name="user[emails][]" type="email" />
      <span>{getIssueMessage(error, 'user[emails][]')}</span>

      <button type="submit">Submit</button>
    </form>
  )
}

Note

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

ย ย ย ๐Ÿš€ Features

ย ย ย ๐Ÿž Bug Fixes

  • contract: Cannot be named without a reference AsyncIteratorClass ย -ย  by @dinwwwh (c68ce)
ย ย ย ย View changes on GitHub

v1.8.8

11 Sep 12:03

Choose a tag to compare

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 @dinwwwh in #974 (06aad)
    • Optimize withEventMeta to avoid unnecessary proxies event iterator data ย -ย  by @dinwwwh in #979 (cedbd)
ย ย ย ย View changes on GitHub

v1.8.7

08 Sep 12:40

Choose a tag to compare

ย ย ย ๐Ÿš€ Features

  • client: Support ORPCError instanceof checks across different dependency graph ย -ย  by @dinwwwh in #972 (85c0f)
  • contract: Improve eventIterator schema output type ย -ย  by @dinwwwh in #970 (c79fd)
ย ย ย ย View changes on GitHub

v1.8.6

01 Sep 12:07

Choose a tag to compare

Response Validation Plugin docs

The Response Validation Plugin validates server responses against your contract schema, ensuring that data returned from your server matches the expected types defined in your contract.

import { RPCLink } from '@orpc/client/fetch'
import { ResponseValidationPlugin } from '@orpc/contract/plugins'

const link = new RPCLink({
  url: 'http://localhost:3000/rpc',
  plugins: [
    new ResponseValidationPlugin(contract),
  ],
})

const client: ContractRouterClient<typeof contract> = createORPCClient(link)

Tip

Beyond response validation, this plugin also serves special purposes such as Expanding Type Support for OpenAPI Link.

Support fetch headers in link header option

 import { RPCLink } from '@orpc/client/fetch'
 const link = new RPCLink({
   url: `${typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000'}/rpc`,
   headers: async () => {
     if (typeof window !== 'undefined') {
       return {}
     }

    const { headers } = await import('next/headers')
-    return Object.fromEntries(await headers())
+    return await headers()
   },
 })

ย ย ย ๐Ÿš€ Features

ย ย ย ย View changes on GitHub

v1.8.5

25 Aug 09:02

Choose a tag to compare

ย ย ย ๐Ÿž Bug Fixes

  • Make signal in EventPublisherSubscribeIteratorOptions AbortSignal | undefined ย -ย  by @boredland in #928 (117b5)
  • server: Compression Plugin (fetch) response invalid status ย -ย  by @dinwwwh in #929 (117b5)
ย ย ย ย View changes on GitHub

v1.8.4

23 Aug 13:19

Choose a tag to compare

ย ย ย ๐Ÿž Bug Fixes

  • client: DedupeRequestsPlugin not working well with Event Iterator ย -ย  by @dinwwwh in #921 (b38be)
  • openapi: Spec generator in case commonSchemas + GET + compact + no params ย -ย  by @dinwwwh in #920 (d7c47)
ย ย ย ย View changes on GitHub

v1.8.3

22 Aug 07:34

Choose a tag to compare

ย ย ย ๐Ÿš€ Features

  • client: Adapter interceptor ย -ย  by @dinwwwh in #899 (b5e32)
  • nest: Add async configuration support for ORPCModule ย -ย  by @dinwwwh in #916 (1e104)
  • openapi: Add Swagger UI support to OpenAPI Reference Plugin ย -ย  by @Copilot in #904 (4f28b)
ย ย ย ย View changes on GitHub

v1.8.2

20 Aug 03:29

Choose a tag to compare

React SWR Integration docs

import useSWR from 'swr'

const { data, error, isLoading } = useSWR(
  orpc.planet.find.key({ input: { id: 123 } }),
  orpc.planet.find.fetcher(),
)

ย ย ย ๐Ÿš€ Features

ย ย ย ๐Ÿž Bug Fixes

  • client: Prevent unintended procedure calls when awaiting client ย -ย  by @dinwwwh in #887 (54654)
  • server: Apply error validation to event iterator ย -ย  by @dinwwwh in #893 (03fed)
ย ย ย ย View changes on GitHub