@orpc/trpc 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 -48
- package/dist/index.d.mts +34 -10
- package/dist/index.d.ts +34 -10
- package/dist/index.mjs +42 -39
- package/package.json +7 -6
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/trpc">
|
|
12
8
|
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Ftrpc?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,55 +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
|
-
|
|
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.
|
|
70
67
|
|
|
71
68
|
## Sponsors
|
|
72
69
|
|
|
73
|
-
|
|
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! 🚀
|
|
74
71
|
|
|
75
72
|
### 🏆 Platinum Sponsor
|
|
76
73
|
|
|
@@ -112,11 +109,10 @@ If you find oRPC valuable and would like to support its development, you can do
|
|
|
112
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>
|
|
113
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>
|
|
114
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>
|
|
115
|
-
<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>
|
|
116
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>
|
|
117
114
|
</tr>
|
|
118
115
|
<tr>
|
|
119
|
-
<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>
|
|
120
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>
|
|
121
117
|
</tr>
|
|
122
118
|
</table>
|
|
@@ -176,6 +172,7 @@ If you find oRPC valuable and would like to support its development, you can do
|
|
|
176
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>
|
|
177
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>
|
|
178
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>
|
|
179
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>
|
|
180
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>
|
|
181
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>
|
|
@@ -190,6 +187,13 @@ If you find oRPC valuable and would like to support its development, you can do
|
|
|
190
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>
|
|
191
188
|
</p>
|
|
192
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
|
+
|
|
193
197
|
## License
|
|
194
198
|
|
|
195
|
-
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.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,45 @@
|
|
|
1
1
|
import { AsyncIteratorClass } from '@orpc/shared';
|
|
2
2
|
import { AnyProcedure, AnyRouter, inferRouterContext } from '@trpc/server';
|
|
3
|
-
import { inferRouterMeta } from '@trpc/server/unstable-core-do-not-import';
|
|
4
3
|
import * as ORPC from '@orpc/server';
|
|
4
|
+
import { AnyMetaPlugin } from '@orpc/contract';
|
|
5
5
|
|
|
6
|
-
interface ORPCMeta {
|
|
7
|
-
route?: ORPC.Route;
|
|
8
|
-
}
|
|
9
6
|
type ToORPCOutput<T> = T extends AsyncIterable<infer TData, infer TReturn, infer TNext> ? AsyncIteratorClass<TData, TReturn, TNext> : T;
|
|
10
|
-
type ToORPCRouterResult<TContext extends ORPC.Context,
|
|
11
|
-
[K in keyof TRecord]: TRecord[K] extends AnyProcedure ? ORPC.Procedure<TContext, object, ORPC.Schema<TRecord[K]['_def']['$types']['input'], unknown>, ORPC.Schema<unknown, ToORPCOutput<TRecord[K]['_def']['$types']['output']>>, object,
|
|
7
|
+
type ToORPCRouterResult<TContext extends ORPC.Context, TRecord extends Record<string, any>> = {
|
|
8
|
+
[K in keyof TRecord]: TRecord[K] extends AnyProcedure ? ORPC.Procedure<TContext, object, ORPC.Schema<TRecord[K]['_def']['$types']['input'], unknown>, ORPC.Schema<unknown, ToORPCOutput<TRecord[K]['_def']['$types']['output']>>, object, never> : TRecord[K] extends Record<string, any> ? ToORPCRouterResult<TContext, TRecord[K]> : never;
|
|
12
9
|
};
|
|
13
10
|
/**
|
|
14
11
|
* Convert a tRPC router to an oRPC router.
|
|
12
|
+
*/
|
|
13
|
+
declare function toORPCRouter<T extends AnyRouter>(router: T): ToORPCRouterResult<inferRouterContext<T>, T['_def']['record']>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolve oRPC meta plugins into a plain meta object usable as tRPC meta.
|
|
17
|
+
*
|
|
18
|
+
* This simulates how oRPC builders apply meta plugins, so well-known plugins
|
|
19
|
+
* like `openapi` from `@orpc/openapi` can be used with tRPC builders.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const example = t.procedure
|
|
24
|
+
* .meta(toTRPCMeta(openapi({ path: '/hello' })))
|
|
25
|
+
* .query(() => 'Hello, World!')
|
|
26
|
+
*
|
|
27
|
+
* const merged = t.procedure
|
|
28
|
+
* .meta({
|
|
29
|
+
* ...toTRPCMeta(
|
|
30
|
+
* openapi({ path: '/hello' }),
|
|
31
|
+
* openapi({ method: 'POST' }),
|
|
32
|
+
* ),
|
|
33
|
+
* other: 'value',
|
|
34
|
+
* })
|
|
35
|
+
* .mutation(() => 'Hello, World!')
|
|
36
|
+
* ```
|
|
15
37
|
*
|
|
16
|
-
* @warning
|
|
38
|
+
* @warning Chained tRPC `.meta` calls merge shallowly, so oRPC metadata merge logic
|
|
39
|
+
* (e.g. accumulating openapi `tags`) only works within a single `toTRPCMeta`
|
|
40
|
+
* call.
|
|
17
41
|
*/
|
|
18
|
-
declare function
|
|
42
|
+
declare function toTRPCMeta(...plugins: AnyMetaPlugin[]): Record<string, any>;
|
|
19
43
|
|
|
20
|
-
export { toORPCRouter };
|
|
21
|
-
export type {
|
|
44
|
+
export { toORPCRouter, toTRPCMeta };
|
|
45
|
+
export type { ToORPCOutput, ToORPCRouterResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,45 @@
|
|
|
1
1
|
import { AsyncIteratorClass } from '@orpc/shared';
|
|
2
2
|
import { AnyProcedure, AnyRouter, inferRouterContext } from '@trpc/server';
|
|
3
|
-
import { inferRouterMeta } from '@trpc/server/unstable-core-do-not-import';
|
|
4
3
|
import * as ORPC from '@orpc/server';
|
|
4
|
+
import { AnyMetaPlugin } from '@orpc/contract';
|
|
5
5
|
|
|
6
|
-
interface ORPCMeta {
|
|
7
|
-
route?: ORPC.Route;
|
|
8
|
-
}
|
|
9
6
|
type ToORPCOutput<T> = T extends AsyncIterable<infer TData, infer TReturn, infer TNext> ? AsyncIteratorClass<TData, TReturn, TNext> : T;
|
|
10
|
-
type ToORPCRouterResult<TContext extends ORPC.Context,
|
|
11
|
-
[K in keyof TRecord]: TRecord[K] extends AnyProcedure ? ORPC.Procedure<TContext, object, ORPC.Schema<TRecord[K]['_def']['$types']['input'], unknown>, ORPC.Schema<unknown, ToORPCOutput<TRecord[K]['_def']['$types']['output']>>, object,
|
|
7
|
+
type ToORPCRouterResult<TContext extends ORPC.Context, TRecord extends Record<string, any>> = {
|
|
8
|
+
[K in keyof TRecord]: TRecord[K] extends AnyProcedure ? ORPC.Procedure<TContext, object, ORPC.Schema<TRecord[K]['_def']['$types']['input'], unknown>, ORPC.Schema<unknown, ToORPCOutput<TRecord[K]['_def']['$types']['output']>>, object, never> : TRecord[K] extends Record<string, any> ? ToORPCRouterResult<TContext, TRecord[K]> : never;
|
|
12
9
|
};
|
|
13
10
|
/**
|
|
14
11
|
* Convert a tRPC router to an oRPC router.
|
|
12
|
+
*/
|
|
13
|
+
declare function toORPCRouter<T extends AnyRouter>(router: T): ToORPCRouterResult<inferRouterContext<T>, T['_def']['record']>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolve oRPC meta plugins into a plain meta object usable as tRPC meta.
|
|
17
|
+
*
|
|
18
|
+
* This simulates how oRPC builders apply meta plugins, so well-known plugins
|
|
19
|
+
* like `openapi` from `@orpc/openapi` can be used with tRPC builders.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const example = t.procedure
|
|
24
|
+
* .meta(toTRPCMeta(openapi({ path: '/hello' })))
|
|
25
|
+
* .query(() => 'Hello, World!')
|
|
26
|
+
*
|
|
27
|
+
* const merged = t.procedure
|
|
28
|
+
* .meta({
|
|
29
|
+
* ...toTRPCMeta(
|
|
30
|
+
* openapi({ path: '/hello' }),
|
|
31
|
+
* openapi({ method: 'POST' }),
|
|
32
|
+
* ),
|
|
33
|
+
* other: 'value',
|
|
34
|
+
* })
|
|
35
|
+
* .mutation(() => 'Hello, World!')
|
|
36
|
+
* ```
|
|
15
37
|
*
|
|
16
|
-
* @warning
|
|
38
|
+
* @warning Chained tRPC `.meta` calls merge shallowly, so oRPC metadata merge logic
|
|
39
|
+
* (e.g. accumulating openapi `tags`) only works within a single `toTRPCMeta`
|
|
40
|
+
* call.
|
|
17
41
|
*/
|
|
18
|
-
declare function
|
|
42
|
+
declare function toTRPCMeta(...plugins: AnyMetaPlugin[]): Record<string, any>;
|
|
19
43
|
|
|
20
|
-
export { toORPCRouter };
|
|
21
|
-
export type {
|
|
44
|
+
export { toORPCRouter, toTRPCMeta };
|
|
45
|
+
export type { ToORPCOutput, ToORPCRouterResult };
|
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import { mapEventIterator } from '@orpc/client';
|
|
2
1
|
import * as ORPC from '@orpc/server';
|
|
3
|
-
import {
|
|
2
|
+
import { set, wrapAsyncIterator, isTypescriptObject } from '@orpc/shared';
|
|
4
3
|
import { isTrackedEnvelope, TRPCError } from '@trpc/server';
|
|
5
|
-
import {
|
|
4
|
+
import { isObject, isAsyncIterable } from '@trpc/server/unstable-core-do-not-import';
|
|
5
|
+
import { resolveMetaPlugins } from '@orpc/contract';
|
|
6
6
|
|
|
7
7
|
function toORPCRouter(router) {
|
|
8
|
-
const result =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const item = lazies[key];
|
|
18
|
-
orpcRouter[key] = ORPC.createAccessibleLazyRouter(ORPC.lazy(async () => {
|
|
19
|
-
const router = await item.ref();
|
|
20
|
-
return { default: toORPCRouter(router) };
|
|
8
|
+
const result = recordToORPCRouterRecord(router._def.record);
|
|
9
|
+
for (const key in router._def.lazy) {
|
|
10
|
+
const item = router._def.lazy[key];
|
|
11
|
+
set(result, key.split("."), new ORPC.Lazy({
|
|
12
|
+
meta: {},
|
|
13
|
+
loader: async () => {
|
|
14
|
+
const router2 = await item.ref();
|
|
15
|
+
return { default: toORPCRouter(router2) };
|
|
16
|
+
}
|
|
21
17
|
}));
|
|
22
18
|
}
|
|
23
|
-
return
|
|
19
|
+
return result;
|
|
24
20
|
}
|
|
25
21
|
function recordToORPCRouterRecord(records) {
|
|
26
22
|
const orpcRouter = {};
|
|
@@ -35,17 +31,18 @@ function recordToORPCRouterRecord(records) {
|
|
|
35
31
|
return orpcRouter;
|
|
36
32
|
}
|
|
37
33
|
function toORPCProcedure(procedure) {
|
|
34
|
+
const inputSchema = toStandardSchema(procedure._def.inputs.at(-1));
|
|
35
|
+
const outputSchema = toStandardSchema(procedure._def.output);
|
|
38
36
|
return new ORPC.Procedure({
|
|
39
37
|
errorMap: {},
|
|
40
38
|
meta: procedure._def.meta ?? {},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// disable output validation
|
|
39
|
+
orderedMiddlewares: [],
|
|
40
|
+
inputSchemas: inputSchema ? [inputSchema] : void 0,
|
|
41
|
+
outputSchemas: outputSchema ? [outputSchema] : void 0,
|
|
42
|
+
// tRPC procedure calling already validates the input/output
|
|
43
|
+
disableInputValidation: true,
|
|
44
|
+
disableOutputValidation: true,
|
|
45
|
+
opaqueReturnedErrors: true,
|
|
49
46
|
handler: async ({ context, signal, path, input, lastEventId }) => {
|
|
50
47
|
try {
|
|
51
48
|
const trpcInput = lastEventId !== void 0 && (input === void 0 || isObject(input)) ? { ...input, lastEventId } : input;
|
|
@@ -60,19 +57,21 @@ function toORPCProcedure(procedure) {
|
|
|
60
57
|
batchIndex: 0
|
|
61
58
|
});
|
|
62
59
|
if (isAsyncIterable(output)) {
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
return wrapAsyncIterator(output[Symbol.asyncIterator](), {
|
|
61
|
+
mapResult: (result) => {
|
|
62
|
+
if (isTrackedEnvelope(result.value)) {
|
|
63
|
+
const [id, data] = result.value;
|
|
64
|
+
return {
|
|
65
|
+
done: result.done,
|
|
66
|
+
value: ORPC.withEventMeta({
|
|
67
|
+
id,
|
|
68
|
+
data
|
|
69
|
+
}, {
|
|
70
|
+
id
|
|
71
|
+
})
|
|
72
|
+
};
|
|
74
73
|
}
|
|
75
|
-
return
|
|
74
|
+
return result;
|
|
76
75
|
}
|
|
77
76
|
});
|
|
78
77
|
}
|
|
@@ -80,7 +79,6 @@ function toORPCProcedure(procedure) {
|
|
|
80
79
|
} catch (cause) {
|
|
81
80
|
if (cause instanceof TRPCError) {
|
|
82
81
|
throw new ORPC.ORPCError(cause.code, {
|
|
83
|
-
status: getHTTPStatusCodeFromError(cause),
|
|
84
82
|
message: cause.message,
|
|
85
83
|
cause
|
|
86
84
|
});
|
|
@@ -97,4 +95,9 @@ function toStandardSchema(schema) {
|
|
|
97
95
|
return schema;
|
|
98
96
|
}
|
|
99
97
|
|
|
100
|
-
|
|
98
|
+
function toTRPCMeta(...plugins) {
|
|
99
|
+
const [meta] = resolveMetaPlugins({}, void 0, plugins);
|
|
100
|
+
return meta;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { toORPCRouter, toTRPCMeta };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/trpc",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.14.
|
|
4
|
+
"version": "1.14.11",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"exports": {
|
|
18
|
+
"./package.json": "./package.json",
|
|
18
19
|
".": {
|
|
19
20
|
"types": "./dist/index.d.mts",
|
|
20
21
|
"import": "./dist/index.mjs",
|
|
@@ -28,17 +29,17 @@
|
|
|
28
29
|
"@trpc/server": ">=11.4.2"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@orpc/
|
|
32
|
-
"@orpc/
|
|
33
|
-
"@orpc/
|
|
32
|
+
"@orpc/contract": "1.14.11",
|
|
33
|
+
"@orpc/server": "1.14.11",
|
|
34
|
+
"@orpc/shared": "1.14.11"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@trpc/server": "^11.12.0",
|
|
37
|
-
"zod": "^4.3
|
|
38
|
+
"zod": "^4.4.3",
|
|
39
|
+
"@orpc/openapi": "1.14.11"
|
|
38
40
|
},
|
|
39
41
|
"scripts": {
|
|
40
42
|
"build": "unbuild",
|
|
41
|
-
"build:watch": "pnpm run build --watch",
|
|
42
43
|
"type:check": "tsc -b"
|
|
43
44
|
}
|
|
44
45
|
}
|