Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions apps/content/docs/helpers/publisher.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ while (true) {

## Available Adapters

| Name | Resume Support | Description |
| ----------------------- | -------------- | ---------------------------------------------------------------- |
| `MemoryPublisher` | ✅ | A simple in-memory publisher |
| `IORedisPublisher` | ✅ | Adapter for [ioredis](https://github.com/redis/ioredis) |
| `UpstashRedisPublisher` | ✅ | Adapter for [Upstash Redis](https://github.com/upstash/redis-js) |
| Name | Resume Support | Description |
| ------------------------ | -------------- | -------------------------------------------------------------------------------------------- |
| `MemoryPublisher` | ✅ | A simple in-memory publisher |
| `IORedisPublisher` | ✅ | Adapter for [ioredis](https://github.com/redis/ioredis) |
| `UpstashRedisPublisher` | ✅ | Adapter for [Upstash Redis](https://github.com/upstash/redis-js) |
| `PublisherDurableObject` | ✅ | Adapter for [Cloudflare Durable Objects](https://developers.cloudflare.com/durable-objects/) |

::: info
If you'd like to add a new publisher adapter, please open an issue.
Expand Down Expand Up @@ -191,6 +192,7 @@ const publisher = new IORedisPublisher<{
subscriber: new Redis(), // For subscribing to events
resumeRetentionSeconds: 60 * 2, // Retain events for 2 minutes to support resume
prefix: 'orpc:publisher:', // avoid conflict with other keys
customJsonSerializers: [] // optional custom serializers
})
```

Expand All @@ -215,9 +217,56 @@ const publisher = new UpstashRedisPublisher<{
}>(redis, {
resumeRetentionSeconds: 60 * 2, // Retain events for 2 minutes to support resume
prefix: 'orpc:publisher:', // avoid conflict with other keys
customJsonSerializers: [] // optional custom serializers
})
```

::: info
Resume support is disabled by default in `UpstashRedisPublisher`. Enable it by setting `resumeRetentionSeconds` to an appropriate value.
:::

### Cloudflare Durable Object

```ts
import { DurablePublisher, PublisherDurableObject } from '@orpc/experimental-publisher-durable-object'

export class PublisherDO extends PublisherDurableObject {
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env, {
resume: {
retentionSeconds: 60 * 2, // Retain events for 2 minutes to support resume
},
})
}
}

export default {
async fetch(request, env) {
const publisher = new DurablePublisher<{
'something-updated': {
id: string
}
}>(env.PUBLISHER_DO, {
prefix: 'publisher1', // avoid conflict with other keys
customJsonSerializers: [] // optional custom serializers
})
Comment thread
dinwwwh marked this conversation as resolved.
},
}
Comment thread
dinwwwh marked this conversation as resolved.
```

::: warning
You must enable the [`enable_request_signal`](https://developers.cloudflare.com/workers/configuration/compatibility-flags/#enable-requestsignal-for-incoming-requests) compatibility flag in your workers to support request abort signals, which are necessary for properly cleaning up subscriptions.

```json
{
"compatibility_flags": [
"enable_request_signal"
]
}
```

:::

::: info
Resume support is disabled by default in `PublisherDurableObject`. Enable it by setting `resume.retentionSeconds` to an appropriate value.
:::
Comment thread
dinwwwh marked this conversation as resolved.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"devDependencies": {
"@antfu/eslint-config": "^6.2.0",
"@cloudflare/vitest-pool-workers": "^0.10.10",
"@solidjs/testing-library": "^0.8.10",
"@sveltejs/vite-plugin-svelte": "^6.2.1",
"@testing-library/jest-dom": "^6.9.1",
Expand Down
26 changes: 26 additions & 0 deletions packages/publisher-durable-object/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Hidden folders and files
.*
!.gitignore
!.*.example

# Common generated folders
logs/
node_modules/
out/
dist/
dist-ssr/
build/
coverage/
temp/

# Common generated files
*.log
*.log.*
*.tsbuildinfo
*.vitest-temp.json
vite.config.ts.timestamp-*
vitest.config.ts.timestamp-*

# Common manual ignore files
*.local
*.pem
81 changes: 81 additions & 0 deletions packages/publisher-durable-object/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<div align="center">
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
Comment thread
dinwwwh marked this conversation as resolved.
</div>

<h1></h1>
Comment thread
dinwwwh marked this conversation as resolved.

<div align="center">
<a href="https://codecov.io/gh/unnoq/orpc">
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
</a>
<a href="https://www.npmjs.com/package/@orpc/experimental-publisher-durable-object">
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fexperimental-publisher-durable-object?logo=npm" />
</a>
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
</a>
<a href="https://discord.gg/TXEbwRBvQn">
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
</a>
<a href="https://deepwiki.com/unnoq/orpc">
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
</a>
</div>

<h3 align="center">Typesafe APIs Made Simple 🪄</h3>

**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards

---

## Highlights

- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.

## Documentation

You can find the full documentation [here](https://orpc.unnoq.com).
Comment thread
dinwwwh marked this conversation as resolved.

## Packages

- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).

## `@orpc/experimental-publisher-durable-object`

Publisher adapter for [Durable Objects](https://developers.cloudflare.com/durable-objects/)

## Sponsors

<p align="center">
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
Comment thread
dinwwwh marked this conversation as resolved.
</a>
</p>

## License

Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
7 changes: 7 additions & 0 deletions packages/publisher-durable-object/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
externals: [
'cloudflare:workers',
],
})
48 changes: 48 additions & 0 deletions packages/publisher-durable-object/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@orpc/experimental-publisher-durable-object",
"type": "module",
"version": "0.0.1",
"license": "MIT",
"homepage": "https://orpc.unnoq.com",
"repository": {
"type": "git",
"url": "git+https://github.com/unnoq/orpc.git",
"directory": "packages/publisher-durable-object"
},
"keywords": [
"unnoq",
"orpc"
],
"publishConfig": {
"exports": {
".": {
"types": "./dist/index.d.mts",
"import": "./dist/index.mjs",
"default": "./dist/index.mjs"
}
}
},
"exports": {
".": "./src/index.ts"
},
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"build:watch": "pnpm run build --watch",
"type:check": "tsc -b",
"type:check:test": "tsc -p tsconfig.test.json --noEmit"
},
"dependencies": {
"@orpc/client": "workspace:*",
"@orpc/experimental-publisher": "workspace:*",
"@orpc/shared": "workspace:*",
"@orpc/standard-server": "workspace:*"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20251118.0",
"@orpc/standard-server-peer": "workspace:*",
"@types/node": "^22.15.30"
}
}
Loading
Loading