@orpc/server 1.14.10 → 1.14.11
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.
- package/README.md +52 -98
- package/dist/adapters/crossws/index.d.mts +45 -21
- package/dist/adapters/crossws/index.d.ts +45 -21
- package/dist/adapters/crossws/index.mjs +40 -18
- package/dist/adapters/fetch/index.d.mts +64 -96
- package/dist/adapters/fetch/index.d.ts +64 -96
- package/dist/adapters/fetch/index.mjs +34 -139
- package/dist/adapters/message-port/index.d.mts +49 -34
- package/dist/adapters/message-port/index.d.ts +49 -34
- package/dist/adapters/message-port/index.mjs +68 -37
- package/dist/adapters/node/index.d.mts +63 -71
- package/dist/adapters/node/index.d.ts +63 -71
- package/dist/adapters/node/index.mjs +36 -113
- package/dist/adapters/standard/index.d.mts +16 -18
- package/dist/adapters/standard/index.d.ts +16 -18
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/standard-peer/index.d.mts +12 -14
- package/dist/adapters/standard-peer/index.d.ts +12 -14
- package/dist/adapters/standard-peer/index.mjs +2 -21
- package/dist/adapters/websocket/index.d.mts +53 -38
- package/dist/adapters/websocket/index.d.ts +53 -38
- package/dist/adapters/websocket/index.mjs +59 -42
- package/dist/extensions/callable.d.mts +10 -0
- package/dist/extensions/callable.d.ts +10 -0
- package/dist/extensions/callable.mjs +11 -0
- package/dist/helpers/index.d.mts +4 -4
- package/dist/helpers/index.d.ts +4 -4
- package/dist/helpers/index.mjs +13 -5
- package/dist/index.d.mts +166 -770
- package/dist/index.d.ts +166 -770
- package/dist/index.mjs +306 -399
- package/dist/plugins/index.d.mts +214 -121
- package/dist/plugins/index.d.ts +214 -121
- package/dist/plugins/index.mjs +576 -214
- package/dist/shared/server.15O7oC1p.d.mts +61 -0
- package/dist/shared/server.B4BnEWWm.d.mts +67 -0
- package/dist/shared/server.BhsVw7m7.d.ts +104 -0
- package/dist/shared/server.BoiFpNT7.mjs +224 -0
- package/dist/shared/server.COPVXhDG.mjs +271 -0
- package/dist/shared/server.CX4vUnDk.mjs +11 -0
- package/dist/shared/server.CcR4kgje.d.mts +206 -0
- package/dist/shared/server.CcR4kgje.d.ts +206 -0
- package/dist/shared/server.CnN50DHH.d.ts +67 -0
- package/dist/shared/server.DBs0rrf9.mjs +41 -0
- package/dist/shared/server.DDFizwfU.d.mts +104 -0
- package/dist/shared/server.D_QauotT.mjs +30 -0
- package/dist/shared/server.DofEOwf-.mjs +237 -0
- package/dist/shared/{server.DZ5BIITo.mjs → server.W91HSRkE.mjs} +2 -2
- package/dist/shared/server.m3szVJGU.d.ts +61 -0
- package/package.json +26 -56
- package/dist/adapters/aws-lambda/index.d.mts +0 -46
- package/dist/adapters/aws-lambda/index.d.ts +0 -46
- package/dist/adapters/aws-lambda/index.mjs +0 -40
- package/dist/adapters/bun-ws/index.d.mts +0 -36
- package/dist/adapters/bun-ws/index.d.ts +0 -36
- package/dist/adapters/bun-ws/index.mjs +0 -47
- package/dist/adapters/fastify/index.d.mts +0 -53
- package/dist/adapters/fastify/index.d.ts +0 -53
- package/dist/adapters/fastify/index.mjs +0 -52
- package/dist/adapters/ws/index.d.mts +0 -31
- package/dist/adapters/ws/index.d.ts +0 -31
- package/dist/adapters/ws/index.mjs +0 -41
- package/dist/hibernation/index.d.mts +0 -44
- package/dist/hibernation/index.d.ts +0 -44
- package/dist/hibernation/index.mjs +0 -65
- package/dist/shared/server.7cEtMB30.d.ts +0 -74
- package/dist/shared/server.B8gYOD5g.d.mts +0 -12
- package/dist/shared/server.BqadksTP.d.mts +0 -74
- package/dist/shared/server.C8_sRzQB.d.mts +0 -42
- package/dist/shared/server.ChUyt5-i.d.mts +0 -32
- package/dist/shared/server.ChyoA9XY.d.ts +0 -42
- package/dist/shared/server.DEBcqOjg.mjs +0 -418
- package/dist/shared/server.EfTOZ2Q7.d.ts +0 -12
- package/dist/shared/server.TEVCLCFC.mjs +0 -39
- package/dist/shared/server.ZxHCEN1h.mjs +0 -226
- package/dist/shared/server.qKsRrdxW.d.mts +0 -193
- package/dist/shared/server.qKsRrdxW.d.ts +0 -193
- package/dist/shared/server.yoEB3Fx4.d.ts +0 -32
package/README.md
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
<
|
|
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">
|
|
9
|
-
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/
|
|
5
|
+
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
|
|
10
6
|
</a>
|
|
11
7
|
<a href="https://www.npmjs.com/package/@orpc/server">
|
|
12
8
|
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fserver?logo=npm" />
|
|
13
9
|
</a>
|
|
14
|
-
<a href="https://
|
|
10
|
+
<a href="https://app.codspeed.io/middleapi/orpc?utm_source=badge">
|
|
11
|
+
<img alt="CodSpeed" src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://github.com/middleapi/orpc/blob/main/LICENSE">
|
|
15
14
|
<img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" />
|
|
16
15
|
</a>
|
|
17
16
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
@@ -22,105 +21,53 @@
|
|
|
22
21
|
</a>
|
|
23
22
|
</div>
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
## Documentation
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
You can read the documentation [here](https://orpc.dev).
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
## Packages
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
**Core**
|
|
32
31
|
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
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.
|
|
32
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Define API contract as the single source of truth.
|
|
33
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build APIs or implement contracts.
|
|
34
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume APIs with end-to-end type safety.
|
|
35
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Add OpenAPI compatibility to APIs.
|
|
45
36
|
|
|
46
|
-
|
|
37
|
+
**Schema validation**
|
|
47
38
|
|
|
48
|
-
|
|
39
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): Integrate with [Zod](https://zod.dev/).
|
|
40
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): Integrate with [Valibot](https://valibot.dev/).
|
|
41
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): Integrate with [ArkType](https://arktype.io/).
|
|
49
42
|
|
|
50
|
-
|
|
43
|
+
**Built-in features**
|
|
44
|
+
|
|
45
|
+
- [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher): Pub/Sub with memory, Redis, and Upstash adapters.
|
|
46
|
+
- [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters.
|
|
47
|
+
- [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
- [@orpc/
|
|
55
|
-
- [@orpc/
|
|
56
|
-
- [@orpc/
|
|
57
|
-
- [@orpc/
|
|
58
|
-
- [@orpc/
|
|
59
|
-
- [@orpc/
|
|
60
|
-
- [@orpc/
|
|
61
|
-
- [@orpc/
|
|
62
|
-
- [@orpc/
|
|
63
|
-
- [@orpc/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
```
|
|
49
|
+
**Framework & ecosystem integrations**
|
|
50
|
+
|
|
51
|
+
- [@orpc/next](https://www.npmjs.com/package/@orpc/next): Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
|
|
52
|
+
- [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk): Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
|
|
53
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
54
|
+
- [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada): Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
55
|
+
- [@orpc/swr](https://www.npmjs.com/package/@orpc/swr): Integrate with [SWR](https://swr.vercel.app/).
|
|
56
|
+
- [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
|
|
57
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
|
|
58
|
+
- [@orpc/bun](https://www.npmjs.com/package/@orpc/bun): Adapters for [Bun's Redis](https://bun.sh/).
|
|
59
|
+
- [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare): Adapters for [Cloudflare's RateLimit and Durable Objects](https://developers.cloudflare.com/workers/).
|
|
60
|
+
- [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc): Reuse existing [tRPC](https://trpc.io/) routers within oRPC.
|
|
61
|
+
|
|
62
|
+
**Observability**
|
|
63
|
+
|
|
64
|
+
- [@orpc/opentelemetry](https://www.npmjs.com/package/@orpc/opentelemetry): Integrate with [OpenTelemetry](https://opentelemetry.io/) for distributed tracing.
|
|
65
|
+
- [@orpc/pino](https://www.npmjs.com/package/@orpc/pino): Integrate with [Pino](https://getpino.io/) for logging.
|
|
66
|
+
- [@orpc/evlog](https://www.npmjs.com/package/@orpc/evlog): Integrate with [Evlog](https://evlog.dev/) for logging.
|
|
120
67
|
|
|
121
68
|
## Sponsors
|
|
122
69
|
|
|
123
|
-
|
|
70
|
+
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
71
|
|
|
125
72
|
### 🏆 Platinum Sponsor
|
|
126
73
|
|
|
@@ -162,11 +109,10 @@ If you find oRPC valuable and would like to support its development, you can do
|
|
|
162
109
|
<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&v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
|
|
163
110
|
<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&v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
|
|
164
111
|
<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&v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
|
|
165
|
-
<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&v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
|
|
166
112
|
<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>
|
|
113
|
+
<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&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
167
114
|
</tr>
|
|
168
115
|
<tr>
|
|
169
|
-
<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&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
170
116
|
<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&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
171
117
|
</tr>
|
|
172
118
|
</table>
|
|
@@ -226,6 +172,7 @@ If you find oRPC valuable and would like to support its development, you can do
|
|
|
226
172
|
<a href="https://github.com/nguyenlc1993?ref=orpc" target="_blank" rel="noopener" title="Lê Cao Nguyên"><img src="https://avatars.githubusercontent.com/u/13871971?u=83c8b69d9e35b589c4e1f066cc113b1d9461386f&v=4" width="32" height="32" alt="Lê Cao Nguyên" /></a>
|
|
227
173
|
<a href="https://github.com/wobsoriano?ref=orpc" target="_blank" rel="noopener" title="Robert Soriano"><img src="https://avatars.githubusercontent.com/u/13049130?u=6d72104182e7c9ed25934815313fb69107332111&v=4" width="32" height="32" alt="Robert Soriano" /></a>
|
|
228
174
|
<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="32" height="32" alt="Andrew Peters" /></a>
|
|
175
|
+
<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&v=4" width="32" height="32" alt="Ryan Vogel" /></a>
|
|
229
176
|
<a href="https://github.com/SKostyukovich?ref=orpc" target="_blank" rel="noopener" title="SKostyukovich"><img src="https://avatars.githubusercontent.com/u/10700067?v=4" width="32" height="32" alt="SKostyukovich" /></a>
|
|
230
177
|
<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&v=4" width="32" height="32" alt="Peter Adam" /></a>
|
|
231
178
|
<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>
|
|
@@ -240,6 +187,13 @@ If you find oRPC valuable and would like to support its development, you can do
|
|
|
240
187
|
<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>
|
|
241
188
|
</p>
|
|
242
189
|
|
|
190
|
+
## References
|
|
191
|
+
|
|
192
|
+
oRPC is inspired by existing solutions that prioritize type safety and developer experience. Special acknowledgments to:
|
|
193
|
+
|
|
194
|
+
- [tRPC](https://trpc.io): For pioneering the concept of end-to-end type-safe RPC and influencing the development of type-safe APIs.
|
|
195
|
+
- [ts-rest](https://ts-rest.com): For its emphasis on contract-first development and OpenAPI integration, which have greatly inspired oRPC's feature set.
|
|
196
|
+
|
|
243
197
|
## License
|
|
244
198
|
|
|
245
|
-
Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/
|
|
199
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/main/LICENSE) for more information.
|
|
@@ -1,33 +1,57 @@
|
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
3
|
+
import { Message, Peer } from 'crossws';
|
|
4
|
+
import { C as Context } from '../../shared/server.CcR4kgje.mjs';
|
|
5
|
+
import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DDFizwfU.mjs';
|
|
6
|
+
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
|
|
7
|
+
import { R as Router } from '../../shared/server.15O7oC1p.mjs';
|
|
8
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.B4BnEWWm.mjs';
|
|
7
9
|
import '@orpc/client';
|
|
8
10
|
import '@orpc/contract';
|
|
9
|
-
import '@
|
|
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
|
|
26
|
+
private readonly handler;
|
|
17
27
|
private readonly peers;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
private readonly encodePeerMessageOptions;
|
|
29
|
+
private readonly decodePeerMessageOptions;
|
|
30
|
+
constructor(handler: StandardHandler<T>, options?: NoInfer<experimental_CrosswsHandlerOptions<T>>);
|
|
31
|
+
/**
|
|
32
|
+
* Handles a single WebSocket message.
|
|
33
|
+
*
|
|
34
|
+
* Message order matters. Call this immediately after receiving a message,
|
|
35
|
+
* before any other async work, to preserve ordering.
|
|
36
|
+
*
|
|
37
|
+
* @param ws The crossws peer instance. Use the same instance for all messages.
|
|
38
|
+
*/
|
|
39
|
+
message(ws: CrosswsPeerLike, message: CrosswsMessageLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
|
|
40
|
+
matched: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Cleans up peer state for a closed WebSocket.
|
|
44
|
+
*
|
|
45
|
+
* @param ws The same crossws peer instance passed to `.message()`.
|
|
46
|
+
*/
|
|
47
|
+
close(ws: CrosswsPeerLike): Promise<void>;
|
|
21
48
|
}
|
|
22
49
|
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
*/
|
|
50
|
+
interface experimental_RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, experimental_CrosswsHandlerOptions<T> {
|
|
51
|
+
}
|
|
29
52
|
declare class experimental_RPCHandler<T extends Context> extends experimental_CrosswsHandler<T> {
|
|
30
|
-
constructor(router: Router<
|
|
53
|
+
constructor(router: Router<T>, options?: NoInfer<experimental_RPCHandlerOptions<T>>);
|
|
31
54
|
}
|
|
32
55
|
|
|
33
56
|
export { experimental_CrosswsHandler, experimental_RPCHandler };
|
|
57
|
+
export type { CrosswsMessageLike, CrosswsPeerLike, experimental_CrosswsHandlerOptions, experimental_RPCHandlerOptions };
|
|
@@ -1,33 +1,57 @@
|
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
3
|
+
import { Message, Peer } from 'crossws';
|
|
4
|
+
import { C as Context } from '../../shared/server.CcR4kgje.js';
|
|
5
|
+
import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.BhsVw7m7.js';
|
|
6
|
+
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
|
|
7
|
+
import { R as Router } from '../../shared/server.m3szVJGU.js';
|
|
8
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.CnN50DHH.js';
|
|
7
9
|
import '@orpc/client';
|
|
8
10
|
import '@orpc/contract';
|
|
9
|
-
import '@
|
|
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
|
|
26
|
+
private readonly handler;
|
|
17
27
|
private readonly peers;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
private readonly encodePeerMessageOptions;
|
|
29
|
+
private readonly decodePeerMessageOptions;
|
|
30
|
+
constructor(handler: StandardHandler<T>, options?: NoInfer<experimental_CrosswsHandlerOptions<T>>);
|
|
31
|
+
/**
|
|
32
|
+
* Handles a single WebSocket message.
|
|
33
|
+
*
|
|
34
|
+
* Message order matters. Call this immediately after receiving a message,
|
|
35
|
+
* before any other async work, to preserve ordering.
|
|
36
|
+
*
|
|
37
|
+
* @param ws The crossws peer instance. Use the same instance for all messages.
|
|
38
|
+
*/
|
|
39
|
+
message(ws: CrosswsPeerLike, message: CrosswsMessageLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
|
|
40
|
+
matched: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Cleans up peer state for a closed WebSocket.
|
|
44
|
+
*
|
|
45
|
+
* @param ws The same crossws peer instance passed to `.message()`.
|
|
46
|
+
*/
|
|
47
|
+
close(ws: CrosswsPeerLike): Promise<void>;
|
|
21
48
|
}
|
|
22
49
|
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
*/
|
|
50
|
+
interface experimental_RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, experimental_CrosswsHandlerOptions<T> {
|
|
51
|
+
}
|
|
29
52
|
declare class experimental_RPCHandler<T extends Context> extends experimental_CrosswsHandler<T> {
|
|
30
|
-
constructor(router: Router<
|
|
53
|
+
constructor(router: Router<T>, options?: NoInfer<experimental_RPCHandlerOptions<T>>);
|
|
31
54
|
}
|
|
32
55
|
|
|
33
56
|
export { experimental_CrosswsHandler, experimental_RPCHandler };
|
|
57
|
+
export type { CrosswsMessageLike, CrosswsPeerLike, experimental_CrosswsHandlerOptions, experimental_RPCHandlerOptions };
|
|
@@ -1,36 +1,56 @@
|
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { ServerPeer } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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.COPVXhDG.mjs';
|
|
7
5
|
import '@orpc/client';
|
|
8
|
-
import '@
|
|
9
|
-
import '../../shared/server.
|
|
6
|
+
import '@standardserver/core';
|
|
7
|
+
import '../../shared/server.DofEOwf-.mjs';
|
|
10
8
|
import '@orpc/contract';
|
|
9
|
+
import '../../shared/server.BoiFpNT7.mjs';
|
|
11
10
|
|
|
12
11
|
class experimental_CrosswsHandler {
|
|
13
|
-
constructor(
|
|
14
|
-
this.
|
|
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 WebSocket message.
|
|
22
|
+
*
|
|
23
|
+
* Message order matters. Call this immediately after receiving a message,
|
|
24
|
+
* before any other async work, to preserve ordering.
|
|
25
|
+
*
|
|
26
|
+
* @param ws The crossws peer instance. Use the same instance for all messages.
|
|
27
|
+
*/
|
|
17
28
|
async message(ws, message, ...rest) {
|
|
18
29
|
let peer = this.peers.get(ws);
|
|
19
30
|
if (!peer) {
|
|
20
|
-
this.peers.set(ws, peer = new ServerPeer((message2) => {
|
|
21
|
-
ws.send(message2);
|
|
31
|
+
this.peers.set(ws, peer = new ServerPeer(async (message2) => {
|
|
32
|
+
ws.send(await encodePeerMessage(message2, this.encodePeerMessageOptions));
|
|
22
33
|
}));
|
|
23
34
|
}
|
|
24
35
|
const encodedMessage = typeof message.rawData === "string" ? message.rawData : message.uint8Array();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
const result = decodePeerMessage(encodedMessage, this.decodePeerMessageOptions);
|
|
37
|
+
if (result.matched && isClientPeerSendMessage(result.message)) {
|
|
38
|
+
await peer.message(
|
|
39
|
+
result.message,
|
|
40
|
+
createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
29
44
|
}
|
|
30
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Cleans up peer state for a closed WebSocket.
|
|
47
|
+
*
|
|
48
|
+
* @param ws The same crossws peer instance passed to `.message()`.
|
|
49
|
+
*/
|
|
50
|
+
async close(ws) {
|
|
31
51
|
const server = this.peers.get(ws);
|
|
32
52
|
if (server) {
|
|
33
|
-
server.close();
|
|
53
|
+
await server.close();
|
|
34
54
|
this.peers.delete(ws);
|
|
35
55
|
}
|
|
36
56
|
}
|
|
@@ -38,7 +58,9 @@ class experimental_CrosswsHandler {
|
|
|
38
58
|
|
|
39
59
|
class experimental_RPCHandler extends experimental_CrosswsHandler {
|
|
40
60
|
constructor(router, options = {}) {
|
|
41
|
-
|
|
61
|
+
const codec = new RPCHandlerCodec(router, options);
|
|
62
|
+
const handler = new StandardHandler(codec, options);
|
|
63
|
+
super(handler, options);
|
|
42
64
|
}
|
|
43
65
|
}
|
|
44
66
|
|