Skip to content

Commit a320605

Browse files
authored
feat(server): stable hibernation apis (#854)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - Refactor - Stabilized Hibernation public API by removing experimental_ prefixes. Use HibernationPlugin, HibernationEventIterator, and encodeHibernationRPCEvent. - Updated type names accordingly; no behavioral changes. - Documentation - Updated guides and examples to reflect new Hibernation API names and imports. - Tests - Adjusted imports and spies to use the stable Hibernation API names. - Chores - Aligned internal references and instanceof checks with the new stable Hibernation API. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 842d6b5 commit a320605

16 files changed

Lines changed: 35 additions & 35 deletions

File tree

apps/content/docs/plugins/hibernation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The Hibernation Plugin helps you fully leverage Hibernation APIs, making it espe
1010
## Setup
1111

1212
```ts
13-
import { experimental_HibernationPlugin as HibernationPlugin } from '@orpc/server/hibernation'
13+
import { HibernationPlugin } from '@orpc/server/hibernation'
1414

1515
const handler = new RPCHandler(router, {
1616
plugins: [
@@ -26,7 +26,7 @@ The plugin provide `HibernationEventIterator` and `encodeHibernationRPCEvent` to
2626
1. Return an `HibernationEventIterator` from your handler
2727

2828
```ts
29-
import { experimental_HibernationEventIterator as HibernationEventIterator } from '@orpc/server/hibernation'
29+
import { HibernationEventIterator } from '@orpc/server/hibernation'
3030

3131
export const onMessage = os.handler(async ({ context }) => {
3232
return new HibernationEventIterator<{ message: string }>((id) => {
@@ -39,7 +39,7 @@ The plugin provide `HibernationEventIterator` and `encodeHibernationRPCEvent` to
3939
2. Send events to clients with `encodeHibernationRPCEvent`
4040

4141
```ts
42-
import { experimental_encodeHibernationRPCEvent as encodeHibernationRPCEvent } from '@orpc/server/hibernation'
42+
import { encodeHibernationRPCEvent } from '@orpc/server/hibernation'
4343

4444
export const sendMessage = os.handler(async ({ input, context }) => {
4545
const websockets = context.getWebSockets()
@@ -70,9 +70,9 @@ This example demonstrates how to set up a chat room using [Cloudflare Durable Ob
7070
```ts [Durable Object]
7171
import { RPCHandler } from '@orpc/server/websocket'
7272
import {
73-
experimental_encodeHibernationRPCEvent as encodeHibernationRPCEvent,
74-
experimental_HibernationEventIterator as HibernationEventIterator,
75-
experimental_HibernationPlugin as HibernationPlugin,
73+
encodeHibernationRPCEvent,
74+
HibernationEventIterator,
75+
HibernationPlugin,
7676
} from '@orpc/server/hibernation'
7777
import { onError, os } from '@orpc/server'
7878
import { DurableObject } from 'cloudflare:workers'

packages/durable-event-iterator/src/durable-object/handler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { call, createProcedureClient } from '@orpc/server'
2-
import { experimental_HibernationEventIterator as HibernationEventIterator } from '@orpc/server/hibernation'
2+
import { HibernationEventIterator } from '@orpc/server/hibernation'
33
import { createCloudflareWebsocket, createDurableObjectState } from '../../tests/shared'
44
import { DURABLE_EVENT_ITERATOR_HIBERNATION_ID_KEY, DURABLE_EVENT_ITERATOR_TOKEN_PAYLOAD_KEY } from './consts'
55
import { DurableEventIteratorObjectEventStorage } from './event-storage'

packages/durable-event-iterator/src/durable-object/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { DurableObject } from 'cloudflare:workers'
33
import type { TokenAttachment } from '../object'
44
import type { DurableEventIteratorObjectWebsocketAttachment, DurableEventIteratorObjectWebsocketManager } from './websocket-manager'
55
import { implement, ORPCError } from '@orpc/server'
6-
import { experimental_HibernationEventIterator as HibernationEventIterator } from '@orpc/server/hibernation'
6+
import { HibernationEventIterator } from '@orpc/server/hibernation'
77
import { get } from '@orpc/shared'
88
import { durableEventIteratorContract } from '../client/contract'
99
import { DURABLE_EVENT_ITERATOR_HIBERNATION_ID_KEY, DURABLE_EVENT_ITERATOR_TOKEN_PAYLOAD_KEY } from './consts'

packages/durable-event-iterator/src/durable-object/object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { DurableEventIteratorTokenPayload } from '../schemas'
44
import type { DurableEventIteratorObjectEventStorageOptions } from './event-storage'
55
import type { DurableEventIteratorObjectRouterContext } from './handler'
66
import type { DurableEventIteratorObjectWebsocketAttachment, DurableEventIteratorObjectWebsocketManagerOptions } from './websocket-manager'
7-
import { experimental_HibernationPlugin as HibernationPlugin } from '@orpc/server/hibernation'
7+
import { HibernationPlugin } from '@orpc/server/hibernation'
88
import { RPCHandler } from '@orpc/server/websocket'
99
import { toArray } from '@orpc/shared'
1010
import { DurableObject } from 'cloudflare:workers'

packages/durable-event-iterator/src/durable-object/websocket-manager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DURABLE_EVENT_ITERATOR_HIBERNATION_ID_KEY, DURABLE_EVENT_ITERATOR_TOKEN
55
import { DurableEventIteratorObjectEventStorage } from './event-storage'
66
import { DurableEventIteratorObjectWebsocketManager } from './websocket-manager'
77

8-
const encodeHibernationRPCEventSpy = vi.spyOn(Hibernation, 'experimental_encodeHibernationRPCEvent')
8+
const encodeHibernationRPCEventSpy = vi.spyOn(Hibernation, 'encodeHibernationRPCEvent')
99

1010
beforeEach(() => {
1111
vi.clearAllMocks()

packages/durable-event-iterator/src/durable-object/websocket-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { StandardRPCJsonSerializerOptions } from '@orpc/client/standard'
22
import type { TokenAttachment } from '../object'
33
import type { DurableEventIteratorTokenPayload } from '../schemas'
44
import type { DurableEventIteratorObjectEventStorage } from './event-storage'
5-
import { experimental_encodeHibernationRPCEvent as encodeHibernationRPCEvent } from '@orpc/server/hibernation'
5+
import { encodeHibernationRPCEvent } from '@orpc/server/hibernation'
66
import { DURABLE_EVENT_ITERATOR_HIBERNATION_ID_KEY, DURABLE_EVENT_ITERATOR_TOKEN_PAYLOAD_KEY } from './consts'
77

88
export interface DurableEventIteratorObjectWebsocketManagerOptions extends StandardRPCJsonSerializerOptions {

packages/server/src/hibernation/event-iterator.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ORPCError } from '@orpc/client'
33
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard'
44
import { withEventMeta } from '@orpc/standard-server'
55
import { encodeResponseMessage, MessageType } from '@orpc/standard-server-peer'
6-
import { experimental_encodeHibernationRPCEvent as encodeHibernationRPCEvent } from './event-iterator'
6+
import { encodeHibernationRPCEvent } from './event-iterator'
77

88
class Planet {
99
constructor(public readonly name: string, public readonly diameter: number) {}

packages/server/src/hibernation/event-iterator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { stringifyJSON } from '@orpc/shared'
55
import { getEventMeta } from '@orpc/standard-server'
66
import { MessageType } from '@orpc/standard-server-peer'
77

8-
export interface experimental_EncodeHibernationRPCEventOptions extends StandardRPCJsonSerializerOptions {
8+
export interface EncodeHibernationRPCEventOptions extends StandardRPCJsonSerializerOptions {
99
/**
1010
* The type of event, each type corresponds a different operation
1111
*
@@ -23,10 +23,10 @@ export interface experimental_EncodeHibernationRPCEventOptions extends StandardR
2323
*
2424
* @see {@link https://orpc.unnoq.com/docs/plugins/hibernation Hibernation Plugin}
2525
*/
26-
export function experimental_encodeHibernationRPCEvent(
26+
export function encodeHibernationRPCEvent(
2727
id: string,
2828
payload: unknown,
29-
options: experimental_EncodeHibernationRPCEventOptions = {},
29+
options: EncodeHibernationRPCEventOptions = {},
3030
): string {
3131
const { event = 'message', ...rest } = options
3232

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './event-iterator'
22
export * from './plugin'
3-
export { experimental_HibernationEventIterator, type experimental_HibernationEventIteratorCallback } from '@orpc/standard-server'
3+
export { HibernationEventIterator, type HibernationEventIteratorCallback } from '@orpc/standard-server'

packages/server/src/hibernation/plugin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { experimental_HibernationEventIterator as HibernationEventIterator } from '@orpc/standard-server'
1+
import { HibernationEventIterator } from '@orpc/standard-server'
22
import { StandardRPCHandler } from '../adapters/standard'
33
import { os } from '../builder'
4-
import { experimental_HibernationPlugin as HibernationPlugin } from './plugin'
4+
import { HibernationPlugin } from './plugin'
55

66
beforeEach(() => {
77
vi.resetAllMocks()

0 commit comments

Comments
 (0)