@orpc/server 1.14.5 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +75 -136
  2. package/dist/adapters/crossws/index.d.mts +42 -21
  3. package/dist/adapters/crossws/index.d.ts +42 -21
  4. package/dist/adapters/crossws/index.mjs +37 -18
  5. package/dist/adapters/fetch/index.d.mts +83 -67
  6. package/dist/adapters/fetch/index.d.ts +83 -67
  7. package/dist/adapters/fetch/index.mjs +131 -106
  8. package/dist/adapters/message-port/index.d.mts +51 -34
  9. package/dist/adapters/message-port/index.d.ts +51 -34
  10. package/dist/adapters/message-port/index.mjs +73 -38
  11. package/dist/adapters/node/index.d.mts +82 -60
  12. package/dist/adapters/node/index.d.ts +82 -60
  13. package/dist/adapters/node/index.mjs +127 -98
  14. package/dist/adapters/standard/index.d.mts +16 -18
  15. package/dist/adapters/standard/index.d.ts +16 -18
  16. package/dist/adapters/standard/index.mjs +5 -5
  17. package/dist/adapters/standard-peer/index.d.mts +12 -14
  18. package/dist/adapters/standard-peer/index.d.ts +12 -14
  19. package/dist/adapters/standard-peer/index.mjs +2 -21
  20. package/dist/adapters/websocket/index.d.mts +39 -34
  21. package/dist/adapters/websocket/index.d.ts +39 -34
  22. package/dist/adapters/websocket/index.mjs +42 -33
  23. package/dist/extensions/callable.d.mts +10 -0
  24. package/dist/extensions/callable.d.ts +10 -0
  25. package/dist/extensions/callable.mjs +11 -0
  26. package/dist/helpers/index.d.mts +2 -2
  27. package/dist/helpers/index.d.ts +2 -2
  28. package/dist/helpers/index.mjs +1 -1
  29. package/dist/index.d.mts +163 -770
  30. package/dist/index.d.ts +163 -770
  31. package/dist/index.mjs +296 -403
  32. package/dist/plugins/index.d.mts +105 -143
  33. package/dist/plugins/index.d.ts +105 -143
  34. package/dist/plugins/index.mjs +232 -255
  35. package/dist/shared/server.BB_Ik9Ph.d.mts +104 -0
  36. package/dist/shared/server.BL22TloH.d.mts +184 -0
  37. package/dist/shared/server.BL22TloH.d.ts +184 -0
  38. package/dist/shared/server.B_U9y00a.d.mts +66 -0
  39. package/dist/shared/server.BsNNjG5J.d.mts +61 -0
  40. package/dist/shared/server.BwHnWUuN.mjs +222 -0
  41. package/dist/shared/server.CX4vUnDk.mjs +11 -0
  42. package/dist/shared/server.CjOb6ItT.mjs +41 -0
  43. package/dist/shared/server.CrlKQucM.mjs +233 -0
  44. package/dist/shared/server.D_QauotT.mjs +30 -0
  45. package/dist/shared/server.EOHJ3NJr.d.ts +104 -0
  46. package/dist/shared/server.GDpX6Df8.mjs +271 -0
  47. package/dist/shared/server.Pa0F03f_.d.ts +61 -0
  48. package/dist/shared/server.T9F3bzZx.d.ts +66 -0
  49. package/dist/shared/{server.DZ5BIITo.mjs → server.W91HSRkE.mjs} +2 -2
  50. package/package.json +26 -55
  51. package/dist/adapters/aws-lambda/index.d.mts +0 -46
  52. package/dist/adapters/aws-lambda/index.d.ts +0 -46
  53. package/dist/adapters/aws-lambda/index.mjs +0 -40
  54. package/dist/adapters/bun-ws/index.d.mts +0 -36
  55. package/dist/adapters/bun-ws/index.d.ts +0 -36
  56. package/dist/adapters/bun-ws/index.mjs +0 -47
  57. package/dist/adapters/fastify/index.d.mts +0 -53
  58. package/dist/adapters/fastify/index.d.ts +0 -53
  59. package/dist/adapters/fastify/index.mjs +0 -52
  60. package/dist/adapters/ws/index.d.mts +0 -31
  61. package/dist/adapters/ws/index.d.ts +0 -31
  62. package/dist/adapters/ws/index.mjs +0 -37
  63. package/dist/hibernation/index.d.mts +0 -44
  64. package/dist/hibernation/index.d.ts +0 -44
  65. package/dist/hibernation/index.mjs +0 -65
  66. package/dist/shared/server.7cEtMB30.d.ts +0 -74
  67. package/dist/shared/server.B8gYOD5g.d.mts +0 -12
  68. package/dist/shared/server.BqadksTP.d.mts +0 -74
  69. package/dist/shared/server.C8_sRzQB.d.mts +0 -42
  70. package/dist/shared/server.ChUyt5-i.d.mts +0 -32
  71. package/dist/shared/server.ChyoA9XY.d.ts +0 -42
  72. package/dist/shared/server.DEBcqOjg.mjs +0 -418
  73. package/dist/shared/server.EfTOZ2Q7.d.ts +0 -12
  74. package/dist/shared/server.TEVCLCFC.mjs +0 -39
  75. package/dist/shared/server.ZxHCEN1h.mjs +0 -226
  76. package/dist/shared/server.qKsRrdxW.d.mts +0 -193
  77. package/dist/shared/server.qKsRrdxW.d.ts +0 -193
  78. package/dist/shared/server.yoEB3Fx4.d.ts +0 -32
package/README.md CHANGED
@@ -1,8 +1,4 @@
1
- <div align="center">
2
- <image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
3
- </div>
4
-
5
- <h1></h1>
1
+ <h1 align="center">oRPC - Typesafe APIs Made Simple 🪄</h1>
6
2
 
7
3
  <div align="center">
8
4
  <a href="https://codecov.io/gh/middleapi/orpc">
@@ -22,105 +18,46 @@
22
18
  </a>
23
19
  </div>
24
20
 
25
- <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
21
+ ## Documentation
22
+
23
+ You can read the documentation [here](https://orpc.dev).
26
24
 
27
- **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
25
+ ## Packages
28
26
 
29
- ---
27
+ **Core**
30
28
 
31
- ## Highlights
29
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Define type-safe contracts for your API.
30
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Implement your API or contract on the server.
31
+ - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API from the client with full type safety.
32
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Bring OpenAPI compatibility to your APIs.
32
33
 
33
- - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
34
- - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
35
- - **📝 Contract-First Development**: Optionally define your API contract before implementation.
36
- - **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
37
- - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
38
- - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
39
- - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
40
- - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
41
- - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
42
- - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
43
- - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
44
- - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
34
+ **Schema validation**
45
35
 
46
- ## Documentation
36
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): Integrate with [Zod](https://zod.dev/).
37
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): Integrate with [Valibot](https://valibot.dev/).
38
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): Integrate with [ArkType](https://arktype.io/).
47
39
 
48
- You can find the full documentation [here](https://orpc.dev).
40
+ **Framework & ecosystem integrations**
49
41
 
50
- ## Packages
42
+ - [@orpc/next](https://www.npmjs.com/package/@orpc/react): Use oRPC with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
43
+ - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
44
+ - [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
45
+
46
+ **Built-in features**
47
+
48
+ - [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher): Pub/Sub.
49
+ - [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting.
50
+ - [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
51
51
 
52
- - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
53
- - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
54
- - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
55
- - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
56
- - [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
57
- - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
58
- - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
59
- - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
60
- - [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
61
- - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
62
- - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
63
- - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
64
- - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
65
- - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
66
-
67
- ## `@orpc/server`
68
-
69
- Build your API or implement API contract. Read the [documentation](https://orpc.dev/docs/getting-started) for more information.
70
-
71
- ```ts
72
- import type { IncomingHttpHeaders } from 'node:http'
73
- import { ORPCError, os } from '@orpc/server'
74
- import * as z from 'zod'
75
-
76
- const PlanetSchema = z.object({
77
- id: z.number().int().min(1),
78
- name: z.string(),
79
- description: z.string().optional(),
80
- })
81
-
82
- export const listPlanet = os
83
- .input(
84
- z.object({
85
- limit: z.number().int().min(1).max(100).optional(),
86
- cursor: z.number().int().min(0).default(0),
87
- }),
88
- )
89
- .handler(async ({ input }) => {
90
- // your list code here
91
- return [{ id: 1, name: 'name' }]
92
- })
93
-
94
- export const findPlanet = os
95
- .input(PlanetSchema.pick({ id: true }))
96
- .handler(async ({ input }) => {
97
- // your find code here
98
- return { id: 1, name: 'name' }
99
- })
100
-
101
- export const createPlanet = os
102
- .$context<{ headers: IncomingHttpHeaders }>()
103
- .use(({ context, next }) => {
104
- const user = parseJWT(context.headers.authorization?.split(' ')[1])
105
-
106
- if (user) {
107
- return next({ context: { user } })
108
- }
109
-
110
- throw new ORPCError('UNAUTHORIZED')
111
- })
112
- .input(PlanetSchema.omit({ id: true }))
113
- .handler(async ({ input, context }) => {
114
- // your create code here
115
- return { id: 1, name: 'name' }
116
- })
117
-
118
- export const router = { planet: { list: listPlanet, find: findPlanet, create: createPlanet } }
119
- ```
52
+ **Observability**
53
+
54
+ - [@orpc/opentelemetry](https://www.npmjs.com/package/@orpc/opentelemetry): Instrument your API with [OpenTelemetry](https://opentelemetry.io/).
55
+ - [@orpc/pino](https://www.npmjs.com/package/@orpc/pino): Log with [Pino](https://getpino.io/).
56
+ - [@orpc/evlog](https://www.npmjs.com/package/@orpc/evlog): Log with [Evlog](https://evlog.dev/).
120
57
 
121
58
  ## Sponsors
122
59
 
123
- If you find oRPC valuable and would like to support its development, you can do so here: [GitHub Sponsors](https://github.com/sponsors/dinwwwh).
60
+ Like what we build over at [middleapi](https://github.com/middleapi)? You can help keep it going here: [GitHub Sponsors](https://github.com/sponsors/dinwwwh). Every bit helps! 🚀
124
61
 
125
62
  ### 🏆 Platinum Sponsor
126
63
 
@@ -138,19 +75,11 @@ If you find oRPC valuable and would like to support its development, you can do
138
75
  </tr>
139
76
  </table>
140
77
 
141
- ### 🥉 Bronze Sponsor
142
-
143
- <table>
144
- <tr>
145
- <td align="center"><a href="https://plancraft.com/?ref=orpc" target="_blank" rel="noopener" title="plancraft"><img src="https://avatars.githubusercontent.com/u/46482287?v=4" width="167" alt="plancraft"/><br />plancraft</a></td>
146
- </tr>
147
- </table>
148
-
149
78
  ### Generous Sponsors
150
79
 
151
80
  <table>
152
81
  <tr>
153
- <td align="center"><a href="https://github.com/ln-markets?ref=orpc" target="_blank" rel="noopener" title="LN Markets"><img src="https://avatars.githubusercontent.com/u/70597625?v=4" width="139" alt="LN Markets"/><br />LN Markets</a></td>
82
+ <td align="center"><a href="https://github.com/ln-markets?ref=orpc" target="_blank" rel="noopener" title="LN Markets"><img src="https://avatars.githubusercontent.com/u/70597625?v=4" width="167" alt="LN Markets"/><br />LN Markets</a></td>
154
83
  </tr>
155
84
  </table>
156
85
 
@@ -158,27 +87,26 @@ If you find oRPC valuable and would like to support its development, you can do
158
87
 
159
88
  <table>
160
89
  <tr>
161
- <td align="center"><a href="https://github.com/hrmcdonald?ref=orpc" target="_blank" rel="noopener" title="Reece McDonald"><img src="https://avatars.githubusercontent.com/u/39349270?v=4" width="119" alt="Reece McDonald"/><br />Reece McDonald</a></td>
162
- <td align="center"><a href="https://github.com/nicognaW?ref=orpc" target="_blank" rel="noopener" title="nk"><img src="https://avatars.githubusercontent.com/u/66731869?u=4699bda3a9092d3ec34fbd959450767bcc8b8b6d&amp;v=4" width="119" alt="nk"/><br />nk</a></td>
163
- <td align="center"><a href="https://github.com/supastarter?ref=orpc" target="_blank" rel="noopener" title="supastarter"><img src="https://avatars.githubusercontent.com/u/110960143?v=4" width="119" alt="supastarter"/><br />supastarter</a></td>
164
- <td align="center"><a href="https://github.com/divmgl?ref=orpc" target="_blank" rel="noopener" title="Dexter Miguel"><img src="https://avatars.githubusercontent.com/u/5452298?u=645993204be8696c085ecf0d228c3062efe2ed65&amp;v=4" width="119" alt="Dexter Miguel"/><br />Dexter Miguel</a></td>
165
- <td align="center"><a href="https://github.com/herrfugbaum?ref=orpc" target="_blank" rel="noopener" title="herrfugbaum"><img src="https://avatars.githubusercontent.com/u/12859776?u=644dc1666d0220bc0468eb0de3c56b919f635b16&amp;v=4" width="119" alt="herrfugbaum"/><br />herrfugbaum</a></td>
166
- <td align="center"><a href="https://github.com/ryota-murakami?ref=orpc" target="_blank" rel="noopener" title="Ryota Murakami"><img src="https://avatars.githubusercontent.com/u/5501268?u=599389e03340734325726ca3f8f423c021d47d7f&amp;v=4" width="119" alt="Ryota Murakami"/><br />Ryota Murakami</a></td>
167
- <td align="center"><a href="https://github.com/dcramer?ref=orpc" target="_blank" rel="noopener" title="David Cramer"><img src="https://avatars.githubusercontent.com/u/23610?v=4" width="119" alt="David Cramer"/><br />David Cramer</a></td>
90
+ <td align="center"><a href="https://github.com/hrmcdonald?ref=orpc" target="_blank" rel="noopener" title="Reece McDonald"><img src="https://avatars.githubusercontent.com/u/39349270?v=4" width="139" alt="Reece McDonald"/><br />Reece McDonald</a></td>
91
+ <td align="center"><a href="https://github.com/nicognaW?ref=orpc" target="_blank" rel="noopener" title="nk"><img src="https://avatars.githubusercontent.com/u/66731869?u=4699bda3a9092d3ec34fbd959450767bcc8b8b6d&amp;v=4" width="139" alt="nk"/><br />nk</a></td>
92
+ <td align="center"><a href="https://github.com/supastarter?ref=orpc" target="_blank" rel="noopener" title="supastarter"><img src="https://avatars.githubusercontent.com/u/110960143?v=4" width="139" alt="supastarter"/><br />supastarter</a></td>
93
+ <td align="center"><a href="https://github.com/divmgl?ref=orpc" target="_blank" rel="noopener" title="Dexter Miguel"><img src="https://avatars.githubusercontent.com/u/5452298?u=645993204be8696c085ecf0d228c3062efe2ed65&amp;v=4" width="139" alt="Dexter Miguel"/><br />Dexter Miguel</a></td>
94
+ <td align="center"><a href="https://github.com/herrfugbaum?ref=orpc" target="_blank" rel="noopener" title="herrfugbaum"><img src="https://avatars.githubusercontent.com/u/12859776?u=644dc1666d0220bc0468eb0de3c56b919f635b16&amp;v=4" width="139" alt="herrfugbaum"/><br />herrfugbaum</a></td>
95
+ <td align="center"><a href="https://github.com/ryota-murakami?ref=orpc" target="_blank" rel="noopener" title="Ryota Murakami"><img src="https://avatars.githubusercontent.com/u/5501268?u=599389e03340734325726ca3f8f423c021d47d7f&amp;v=4" width="139" alt="Ryota Murakami"/><br />Ryota Murakami</a></td>
168
96
  </tr>
169
97
  <tr>
170
- <td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&amp;v=4" width="119" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
171
- <td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&amp;v=4" width="119" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
172
- <td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&amp;v=4" width="119" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
173
- <td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="119" alt="Andrew Peters"/><br />Andrew Peters</a></td>
174
- <td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&amp;v=4" width="119" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
175
- <td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="119" alt="christ12938"/><br />christ12938</a></td>
176
- <td align="center"><a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&amp;v=4" width="119" alt="Peter Adam"/><br />Peter Adam</a></td>
98
+ <td align="center"><a href="https://github.com/dcramer?ref=orpc" target="_blank" rel="noopener" title="David Cramer"><img src="https://avatars.githubusercontent.com/u/23610?v=4" width="139" alt="David Cramer"/><br />David Cramer</a></td>
99
+ <td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&amp;v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
100
+ <td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&amp;v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
101
+ <td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&amp;v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
102
+ <td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="139" alt="Andrew Peters"/><br />Andrew Peters</a></td>
103
+ <td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&amp;v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
177
104
  </tr>
178
105
  <tr>
179
- <td align="center"><a href="https://github.com/yukimotochern?ref=orpc" target="_blank" rel="noopener" title="Chen, Zhi-Yuan"><img src="https://avatars.githubusercontent.com/u/20896173?u=945c33fc21725e4d566a0d02afc54b136ca1d67a&amp;v=4" width="119" alt="Chen, Zhi-Yuan"/><br />Chen, Zhi-Yuan</a></td>
180
- <td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="119" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
181
- <td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&amp;v=4" width="119" alt="shota"/><br />shota</a></td>
106
+ <td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
107
+ <td align="center"><a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&amp;v=4" width="139" alt="Peter Adam"/><br />Peter Adam</a></td>
108
+ <td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
109
+ <td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&amp;v=4" width="139" alt="shota"/><br />shota</a></td>
182
110
  </tr>
183
111
  </table>
184
112
 
@@ -186,27 +114,27 @@ If you find oRPC valuable and would like to support its development, you can do
186
114
 
187
115
  <table>
188
116
  <tr>
189
- <td align="center"><a href="https://github.com/rhinodavid?ref=orpc" target="_blank" rel="noopener" title="David Walsh"><img src="https://avatars.githubusercontent.com/u/5778036?u=b5521f07d2f88c3db2a0dae62b5f2f8357214af0&amp;v=4" width="104" alt="David Walsh"/><br />David Walsh</a></td>
190
- <td align="center"><a href="https://github.com/ChromeGG?ref=orpc" target="_blank" rel="noopener" title="Adam Tkaczyk"><img src="https://avatars.githubusercontent.com/u/39050595?u=a58ca6042a6950e94e6e92442db76ef584279bc0&amp;v=4" width="104" alt="Adam Tkaczyk"/><br />Adam Tkaczyk</a></td>
191
- <td align="center"><a href="https://github.com/Robbe95?ref=orpc" target="_blank" rel="noopener" title="Robbe Vaes"><img src="https://avatars.githubusercontent.com/u/44748019?u=e0232402c045ad4eac7cbd217f1f47e083103b89&amp;v=4" width="104" alt="Robbe Vaes"/><br />Robbe Vaes</a></td>
192
- <td align="center"><a href="https://github.com/aidansunbury?ref=orpc" target="_blank" rel="noopener" title="Aidan Sunbury"><img src="https://avatars.githubusercontent.com/u/64103161?v=4" width="104" alt="Aidan Sunbury"/><br />Aidan Sunbury</a></td>
193
- <td align="center"><a href="https://github.com/soonoo?ref=orpc" target="_blank" rel="noopener" title="soonoo"><img src="https://avatars.githubusercontent.com/u/5436405?u=5d0b4aa955c87e30e6bda7f0cccae5402da99528&amp;v=4" width="104" alt="soonoo"/><br />soonoo</a></td>
194
- <td align="center"><a href="https://github.com/kporten?ref=orpc" target="_blank" rel="noopener" title="Kevin Porten"><img src="https://avatars.githubusercontent.com/u/1839345?u=dc2263d5cfe0d927ce1a0be04a1d55dd6b55405c&amp;v=4" width="104" alt="Kevin Porten"/><br />Kevin Porten</a></td>
195
- <td align="center"><a href="https://github.com/pumpkinlink?ref=orpc" target="_blank" rel="noopener" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&amp;v=4" width="104" alt="Denis"/><br />Denis</a></td>
196
- <td align="center"><a href="https://github.com/christopher-kapic?ref=orpc" target="_blank" rel="noopener" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&amp;v=4" width="104" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
117
+ <td align="center"><a href="https://github.com/rhinodavid?ref=orpc" target="_blank" rel="noopener" title="David Walsh"><img src="https://avatars.githubusercontent.com/u/5778036?u=b5521f07d2f88c3db2a0dae62b5f2f8357214af0&amp;v=4" width="119" alt="David Walsh"/><br />David Walsh</a></td>
118
+ <td align="center"><a href="https://github.com/Robbe95?ref=orpc" target="_blank" rel="noopener" title="Robbe Vaes"><img src="https://avatars.githubusercontent.com/u/44748019?u=e0232402c045ad4eac7cbd217f1f47e083103b89&amp;v=4" width="119" alt="Robbe Vaes"/><br />Robbe Vaes</a></td>
119
+ <td align="center"><a href="https://github.com/aidansunbury?ref=orpc" target="_blank" rel="noopener" title="Aidan Sunbury"><img src="https://avatars.githubusercontent.com/u/64103161?v=4" width="119" alt="Aidan Sunbury"/><br />Aidan Sunbury</a></td>
120
+ <td align="center"><a href="https://github.com/soonoo?ref=orpc" target="_blank" rel="noopener" title="soonoo"><img src="https://avatars.githubusercontent.com/u/5436405?u=5d0b4aa955c87e30e6bda7f0cccae5402da99528&amp;v=4" width="119" alt="soonoo"/><br />soonoo</a></td>
121
+ <td align="center"><a href="https://github.com/kporten?ref=orpc" target="_blank" rel="noopener" title="Kevin Porten"><img src="https://avatars.githubusercontent.com/u/1839345?u=dc2263d5cfe0d927ce1a0be04a1d55dd6b55405c&amp;v=4" width="119" alt="Kevin Porten"/><br />Kevin Porten</a></td>
122
+ <td align="center"><a href="https://github.com/pumpkinlink?ref=orpc" target="_blank" rel="noopener" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&amp;v=4" width="119" alt="Denis"/><br />Denis</a></td>
123
+ <td align="center"><a href="https://github.com/christopher-kapic?ref=orpc" target="_blank" rel="noopener" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&amp;v=4" width="119" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
197
124
  </tr>
198
125
  <tr>
199
- <td align="center"><a href="https://github.com/thomasballinger?ref=orpc" target="_blank" rel="noopener" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&amp;v=4" width="104" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
200
- <td align="center"><a href="https://github.com/SSam0419?ref=orpc" target="_blank" rel="noopener" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&amp;v=4" width="104" alt="Sam"/><br />Sam</a></td>
201
- <td align="center"><a href="https://github.com/Titoine?ref=orpc" target="_blank" rel="noopener" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&amp;v=4" width="104" alt="Titoine"/><br />Titoine</a></td>
202
- <td align="center"><a href="https://github.com/Mnigos?ref=orpc" target="_blank" rel="noopener" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&amp;v=4" width="104" alt="Igor Makowski"/><br />Igor Makowski</a></td>
203
- <td align="center"><a href="https://github.com/steelbrain?ref=orpc" target="_blank" rel="noopener" title="Anees Iqbal"><img src="https://avatars.githubusercontent.com/u/4278113?u=22b80b5399eed68ac76cd58b02961b0481f1db11&amp;v=4" width="104" alt="Anees Iqbal"/><br />Anees Iqbal</a></td>
204
- <td align="center"><a href="https://github.com/hanayashiki?ref=orpc" target="_blank" rel="noopener" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&amp;v=4" width="104" alt="hanayashiki"/><br />hanayashiki</a></td>
205
- <td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="104" alt="Alex"/><br />Alex</a></td>
206
- <td align="center"><a href="https://github.com/nattstack?ref=orpc" target="_blank" rel="noopener" title="nattstack"><img src="https://avatars.githubusercontent.com/u/31426677?u=fa9dbb8b3e66eb0ea3c88db5dc07f31c8c5418fe&amp;v=4" width="104" alt="nattstack"/><br />nattstack</a></td>
126
+ <td align="center"><a href="https://github.com/thomasballinger?ref=orpc" target="_blank" rel="noopener" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&amp;v=4" width="119" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
127
+ <td align="center"><a href="https://github.com/SSam0419?ref=orpc" target="_blank" rel="noopener" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&amp;v=4" width="119" alt="Sam"/><br />Sam</a></td>
128
+ <td align="center"><a href="https://github.com/Titoine?ref=orpc" target="_blank" rel="noopener" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&amp;v=4" width="119" alt="Titoine"/><br />Titoine</a></td>
129
+ <td align="center"><a href="https://github.com/Mnigos?ref=orpc" target="_blank" rel="noopener" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&amp;v=4" width="119" alt="Igor Makowski"/><br />Igor Makowski</a></td>
130
+ <td align="center"><a href="https://github.com/hanayashiki?ref=orpc" target="_blank" rel="noopener" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&amp;v=4" width="119" alt="hanayashiki"/><br />hanayashiki</a></td>
131
+ <td align="center"><a href="https://github.com/ldub?ref=orpc" target="_blank" rel="noopener" title="Lev Dubinets"><img src="https://avatars.githubusercontent.com/u/3114081?u=f547f5d5012cab54851f1b1ad72d10e537f78fc2&amp;v=4" width="119" alt="Lev Dubinets"/><br />Lev Dubinets</a></td>
132
+ <td align="center"><a href="https://github.com/mr-kelly?ref=orpc" target="_blank" rel="noopener" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&amp;v=4" width="119" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
207
133
  </tr>
208
134
  <tr>
209
- <td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=29e91400dbd4a9c217048a8f59562c4f740498e6&amp;v=4" width="104" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
135
+ <td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="119" alt="Alex"/><br />Alex</a></td>
136
+ <td align="center"><a href="https://github.com/nattstack?ref=orpc" target="_blank" rel="noopener" title="nattstack"><img src="https://avatars.githubusercontent.com/u/31426677?u=fa9dbb8b3e66eb0ea3c88db5dc07f31c8c5418fe&amp;v=4" width="119" alt="nattstack"/><br />nattstack</a></td>
137
+ <td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=29e91400dbd4a9c217048a8f59562c4f740498e6&amp;v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
210
138
  </tr>
211
139
  </table>
212
140
 
@@ -240,10 +168,21 @@ If you find oRPC valuable and would like to support its development, you can do
240
168
  <a href="https://github.com/FabworksHQ?ref=orpc" target="_blank" rel="noopener" title="Fabworks"><img src="https://avatars.githubusercontent.com/u/160179500?v=4" width="32" height="32" alt="Fabworks" /></a>
241
169
  <a href="https://github.com/NovakAnton?ref=orpc" target="_blank" rel="noopener" title="Novak Antonijevic"><img src="https://avatars.githubusercontent.com/u/157126729?u=ae49fa22292d55c0434ff0ca008206155b18663b&amp;v=4" width="32" height="32" alt="Novak Antonijevic" /></a>
242
170
  <a href="https://github.com/laduniestu?ref=orpc" target="_blank" rel="noopener" title="Laduni Estu Syalwa"><img src="https://avatars.githubusercontent.com/u/44757637?u=a2fc1ea8f7d827a96721176f79d30592d1c48059&amp;v=4" width="32" height="32" alt="Laduni Estu Syalwa" /></a>
171
+ <a href="https://github.com/yukimotochern?ref=orpc" target="_blank" rel="noopener" title="Chen, Zhi-Yuan"><img src="https://avatars.githubusercontent.com/u/20896173?u=945c33fc21725e4d566a0d02afc54b136ca1d67a&amp;v=4" width="32" height="32" alt="Chen, Zhi-Yuan" /></a>
243
172
  <a href="https://github.com/illarionvk?ref=orpc" target="_blank" rel="noopener" title="Illarion Koperski"><img src="https://avatars.githubusercontent.com/u/5012724?u=7cfa13652f7ac5fb3c56d880e3eb3fbe40c3ea34&amp;v=4" width="32" height="32" alt="Illarion Koperski" /></a>
173
+ <a href="https://github.com/steelbrain?ref=orpc" target="_blank" rel="noopener" title="Anees Iqbal"><img src="https://avatars.githubusercontent.com/u/4278113?u=22b80b5399eed68ac76cd58b02961b0481f1db11&amp;v=4" width="32" height="32" alt="Anees Iqbal" /></a>
244
174
  <a href="https://github.com/Scrumplex?ref=orpc" target="_blank" rel="noopener" title="Sefa Eyeoglu"><img src="https://avatars.githubusercontent.com/u/11587657?u=ab503582165c0bbff0cca47ce31c9450bb1553c9&amp;v=4" width="32" height="32" alt="Sefa Eyeoglu" /></a>
175
+ <a href="https://github.com/ChromeGG?ref=orpc" target="_blank" rel="noopener" title="Adam Tkaczyk"><img src="https://avatars.githubusercontent.com/u/39050595?u=a58ca6042a6950e94e6e92442db76ef584279bc0&amp;v=4" width="32" height="32" alt="Adam Tkaczyk" /></a>
176
+ <a href="https://github.com/plancraft?ref=orpc" target="_blank" rel="noopener" title="plancraft"><img src="https://avatars.githubusercontent.com/u/46482287?v=4" width="32" height="32" alt="plancraft" /></a>
245
177
  </p>
246
178
 
179
+ ## References
180
+
181
+ oRPC is inspired by existing solutions that prioritize type safety and developer experience. Special acknowledgments to:
182
+
183
+ - [tRPC](https://trpc.io): For pioneering the concept of end-to-end type-safe RPC and influencing the development of type-safe APIs.
184
+ - [ts-rest](https://ts-rest.com): For its emphasis on contract-first development and OpenAPI integration, which have greatly inspired oRPC's feature set.
185
+
247
186
  ## License
248
187
 
249
188
  Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/main/LICENSE) for more information.
@@ -1,33 +1,54 @@
1
1
  import { MaybeOptionalOptions } from '@orpc/shared';
2
- import { Peer, Message } from 'crossws';
3
- import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.mjs';
4
- import { f as StandardHandler } from '../../shared/server.BqadksTP.mjs';
5
- import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.mjs';
6
- import { S as StandardRPCHandlerOptions } from '../../shared/server.ChUyt5-i.mjs';
2
+ import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
3
+ import { Message, Peer } from 'crossws';
4
+ import { C as Context } from '../../shared/server.BL22TloH.mjs';
5
+ import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.BB_Ik9Ph.mjs';
6
+ import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
7
+ import { R as Router } from '../../shared/server.BsNNjG5J.mjs';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.B_U9y00a.mjs';
7
9
  import '@orpc/client';
8
10
  import '@orpc/contract';
9
- import '@orpc/standard-server';
10
- import '@orpc/standard-server-peer';
11
- import '../../shared/server.B8gYOD5g.mjs';
12
- import '@orpc/client/standard';
13
- import '../../shared/server.C8_sRzQB.mjs';
11
+ import '@standardserver/core';
14
12
 
13
+ type CrosswsPeerLike = Pick<Peer, 'send'>;
14
+ type CrosswsMessageLike = Pick<Message, 'rawData' | 'uint8Array'>;
15
+ interface experimental_CrosswsHandlerOptions<_T extends Context> {
16
+ /**
17
+ * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
18
+ */
19
+ encodePeerMessage?: EncodePeerMessageOptions | undefined;
20
+ /**
21
+ * Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
22
+ */
23
+ decodePeerMessage?: DecodePeerMessageOptions | undefined;
24
+ }
15
25
  declare class experimental_CrosswsHandler<T extends Context> {
16
- private readonly standardHandler;
26
+ private readonly handler;
17
27
  private readonly peers;
18
- constructor(standardHandler: StandardHandler<T>);
19
- message(ws: Pick<Peer, 'send'>, message: Pick<Message, 'rawData' | 'uint8Array'>, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
20
- close(ws: Pick<Peer, 'send'>): void;
28
+ private readonly encodePeerMessageOptions;
29
+ private readonly decodePeerMessageOptions;
30
+ constructor(handler: StandardHandler<T>, options?: NoInfer<experimental_CrosswsHandlerOptions<T>>);
31
+ /**
32
+ * Handles a single message received from a crossws Peer.
33
+ *
34
+ * @param ws The crossws Peer instance, require consistent instance across messages for proper peer management
35
+ */
36
+ message(ws: CrosswsPeerLike, message: CrosswsMessageLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
37
+ matched: boolean;
38
+ }>;
39
+ /**
40
+ * Closes the peer connection and cleans up associated resources.
41
+ *
42
+ * @param ws The crossws Peer instance to close, require consistent instance for proper peer management
43
+ */
44
+ close(ws: CrosswsPeerLike): Promise<void>;
21
45
  }
22
46
 
23
- /**
24
- * RPC Handler for Crossws adapter
25
- *
26
- * @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
27
- * @see {@link https://orpc.dev/docs/adapters/websocket Websocket Adapter Docs}
28
- */
47
+ interface experimental_RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, experimental_CrosswsHandlerOptions<T> {
48
+ }
29
49
  declare class experimental_RPCHandler<T extends Context> extends experimental_CrosswsHandler<T> {
30
- constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
50
+ constructor(router: Router<T>, options?: NoInfer<experimental_RPCHandlerOptions<T>>);
31
51
  }
32
52
 
33
53
  export { experimental_CrosswsHandler, experimental_RPCHandler };
54
+ export type { CrosswsMessageLike, CrosswsPeerLike, experimental_CrosswsHandlerOptions, experimental_RPCHandlerOptions };
@@ -1,33 +1,54 @@
1
1
  import { MaybeOptionalOptions } from '@orpc/shared';
2
- import { Peer, Message } from 'crossws';
3
- import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.js';
4
- import { f as StandardHandler } from '../../shared/server.7cEtMB30.js';
5
- import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.js';
6
- import { S as StandardRPCHandlerOptions } from '../../shared/server.yoEB3Fx4.js';
2
+ import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
3
+ import { Message, Peer } from 'crossws';
4
+ import { C as Context } from '../../shared/server.BL22TloH.js';
5
+ import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.EOHJ3NJr.js';
6
+ import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
7
+ import { R as Router } from '../../shared/server.Pa0F03f_.js';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.T9F3bzZx.js';
7
9
  import '@orpc/client';
8
10
  import '@orpc/contract';
9
- import '@orpc/standard-server';
10
- import '@orpc/standard-server-peer';
11
- import '../../shared/server.EfTOZ2Q7.js';
12
- import '@orpc/client/standard';
13
- import '../../shared/server.ChyoA9XY.js';
11
+ import '@standardserver/core';
14
12
 
13
+ type CrosswsPeerLike = Pick<Peer, 'send'>;
14
+ type CrosswsMessageLike = Pick<Message, 'rawData' | 'uint8Array'>;
15
+ interface experimental_CrosswsHandlerOptions<_T extends Context> {
16
+ /**
17
+ * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
18
+ */
19
+ encodePeerMessage?: EncodePeerMessageOptions | undefined;
20
+ /**
21
+ * Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
22
+ */
23
+ decodePeerMessage?: DecodePeerMessageOptions | undefined;
24
+ }
15
25
  declare class experimental_CrosswsHandler<T extends Context> {
16
- private readonly standardHandler;
26
+ private readonly handler;
17
27
  private readonly peers;
18
- constructor(standardHandler: StandardHandler<T>);
19
- message(ws: Pick<Peer, 'send'>, message: Pick<Message, 'rawData' | 'uint8Array'>, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
20
- close(ws: Pick<Peer, 'send'>): void;
28
+ private readonly encodePeerMessageOptions;
29
+ private readonly decodePeerMessageOptions;
30
+ constructor(handler: StandardHandler<T>, options?: NoInfer<experimental_CrosswsHandlerOptions<T>>);
31
+ /**
32
+ * Handles a single message received from a crossws Peer.
33
+ *
34
+ * @param ws The crossws Peer instance, require consistent instance across messages for proper peer management
35
+ */
36
+ message(ws: CrosswsPeerLike, message: CrosswsMessageLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
37
+ matched: boolean;
38
+ }>;
39
+ /**
40
+ * Closes the peer connection and cleans up associated resources.
41
+ *
42
+ * @param ws The crossws Peer instance to close, require consistent instance for proper peer management
43
+ */
44
+ close(ws: CrosswsPeerLike): Promise<void>;
21
45
  }
22
46
 
23
- /**
24
- * RPC Handler for Crossws adapter
25
- *
26
- * @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
27
- * @see {@link https://orpc.dev/docs/adapters/websocket Websocket Adapter Docs}
28
- */
47
+ interface experimental_RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, experimental_CrosswsHandlerOptions<T> {
48
+ }
29
49
  declare class experimental_RPCHandler<T extends Context> extends experimental_CrosswsHandler<T> {
30
- constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
50
+ constructor(router: Router<T>, options?: NoInfer<experimental_RPCHandlerOptions<T>>);
31
51
  }
32
52
 
33
53
  export { experimental_CrosswsHandler, experimental_RPCHandler };
54
+ export type { CrosswsMessageLike, CrosswsPeerLike, experimental_CrosswsHandlerOptions, experimental_RPCHandlerOptions };
@@ -1,36 +1,53 @@
1
1
  import { resolveMaybeOptionalOptions } from '@orpc/shared';
2
- import { ServerPeer } from '@orpc/standard-server-peer';
3
- import { createServerPeerHandleRequestFn } from '../standard-peer/index.mjs';
4
- import { b as StandardRPCHandler } from '../../shared/server.ZxHCEN1h.mjs';
5
- import '../../shared/server.DZ5BIITo.mjs';
6
- import '@orpc/client/standard';
2
+ import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@standardserver/peer';
3
+ import { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.GDpX6Df8.mjs';
7
5
  import '@orpc/client';
8
- import '@orpc/standard-server';
9
- import '../../shared/server.DEBcqOjg.mjs';
6
+ import '@standardserver/core';
7
+ import '../../shared/server.CrlKQucM.mjs';
10
8
  import '@orpc/contract';
9
+ import '../../shared/server.BwHnWUuN.mjs';
11
10
 
12
11
  class experimental_CrosswsHandler {
13
- constructor(standardHandler) {
14
- this.standardHandler = standardHandler;
12
+ constructor(handler, options = {}) {
13
+ this.handler = handler;
14
+ this.encodePeerMessageOptions = options.encodePeerMessage;
15
+ this.decodePeerMessageOptions = options.decodePeerMessage;
15
16
  }
16
17
  peers = /* @__PURE__ */ new WeakMap();
18
+ encodePeerMessageOptions;
19
+ decodePeerMessageOptions;
20
+ /**
21
+ * Handles a single message received from a crossws Peer.
22
+ *
23
+ * @param ws The crossws Peer instance, require consistent instance across messages for proper peer management
24
+ */
17
25
  async message(ws, message, ...rest) {
18
26
  let peer = this.peers.get(ws);
19
27
  if (!peer) {
20
- this.peers.set(ws, peer = new ServerPeer((message2) => {
21
- ws.send(message2);
28
+ this.peers.set(ws, peer = new ServerPeer(async (message2) => {
29
+ ws.send(await encodePeerMessage(message2, this.encodePeerMessageOptions));
22
30
  }));
23
31
  }
24
32
  const encodedMessage = typeof message.rawData === "string" ? message.rawData : message.uint8Array();
25
- await peer.message(
26
- encodedMessage,
27
- createServerPeerHandleRequestFn(this.standardHandler, resolveMaybeOptionalOptions(rest))
28
- );
33
+ const result = decodePeerMessage(encodedMessage, this.decodePeerMessageOptions);
34
+ if (result.matched && isClientPeerSendMessage(result.message)) {
35
+ await peer.message(
36
+ result.message,
37
+ createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
38
+ );
39
+ }
40
+ return result;
29
41
  }
30
- close(ws) {
42
+ /**
43
+ * Closes the peer connection and cleans up associated resources.
44
+ *
45
+ * @param ws The crossws Peer instance to close, require consistent instance for proper peer management
46
+ */
47
+ async close(ws) {
31
48
  const server = this.peers.get(ws);
32
49
  if (server) {
33
- server.close();
50
+ await server.close();
34
51
  this.peers.delete(ws);
35
52
  }
36
53
  }
@@ -38,7 +55,9 @@ class experimental_CrosswsHandler {
38
55
 
39
56
  class experimental_RPCHandler extends experimental_CrosswsHandler {
40
57
  constructor(router, options = {}) {
41
- super(new StandardRPCHandler(router, options));
58
+ const codec = new RPCHandlerCodec(router, options);
59
+ const handler = new StandardHandler(codec, options);
60
+ super(handler, options);
42
61
  }
43
62
  }
44
63