@orpc/trpc 2.0.0-beta.46 → 2.0.0-beta.48
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 +6 -4
- package/dist/index.d.mts +2 -52
- package/dist/index.mjs +2 -105
- package/dist/to-orpc-router.d.mts +17 -0
- package/dist/to-orpc-router.mjs +99 -0
- package/dist/to-trpc-meta.d.mts +31 -0
- package/dist/to-trpc-meta.mjs +6 -0
- package/package.json +6 -6
- package/dist/index.d.ts +0 -52
package/README.md
CHANGED
|
@@ -156,10 +156,11 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
156
156
|
<td align="center"><a href="https://github.com/christ12938?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="167" alt="christ12938"/><br />christ12938</a></td>
|
|
157
157
|
<td align="center"><a href="https://github.com/Ryanjso?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="167" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
158
158
|
<td align="center"><a href="https://github.com/itigoore01?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="167" alt="shota"/><br />shota</a></td>
|
|
159
|
+
<td align="center"><a href="https://github.com/Nic13Gamer?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Nicholas"><img src="https://avatars.githubusercontent.com/u/54724556?u=56a7ab430ce7a80d648ab6eba051d454a818ed0b&v=4" width="167" alt="Nicholas"/><br />Nicholas</a></td>
|
|
159
160
|
<td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="167" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
160
|
-
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
161
161
|
</tr>
|
|
162
162
|
<tr>
|
|
163
|
+
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
163
164
|
<td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="167" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
|
|
164
165
|
<td align="center"><a href="https://automatio.ai/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Stefan Smiljkovic"><img src="https://avatars.githubusercontent.com/u/1984909?u=b7bf5bc40ed49df3c22f69d2da7b8d78709c49ed&v=4" width="167" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
|
|
165
166
|
</tr>
|
|
@@ -190,10 +191,9 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
190
191
|
<td align="center"><a href="https://kellychan.im/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
191
192
|
<td align="center"><a href="https://guyariely.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
192
193
|
<td align="center"><a href="https://paulsenon.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
|
|
193
|
-
<td align="center"><a href="https://
|
|
194
|
+
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
194
195
|
</tr>
|
|
195
196
|
<tr>
|
|
196
|
-
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
197
197
|
<td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
198
198
|
</tr>
|
|
199
199
|
</table>
|
|
@@ -206,7 +206,9 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
|
|
|
206
206
|
|
|
207
207
|
<table>
|
|
208
208
|
<tr>
|
|
209
|
-
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude
|
|
209
|
+
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude</a></td>
|
|
210
|
+
<td align="center"><a href="https://pullfrog.com/for-oss" target="_blank" rel="noopener" title="Pullfrog for OSS"><img src="https://avatars.githubusercontent.com/in/1768019?s=128&v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
|
|
211
|
+
<td align="center"><a href="https://macroscope.com/open-source" target="_blank" rel="noopener" title="Macroscope for Open Source"><img src="https://avatars.githubusercontent.com/in/900172?s=128&v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
|
|
210
212
|
</tr>
|
|
211
213
|
</table>
|
|
212
214
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,52 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import * as ORPC from '@orpc/server';
|
|
4
|
-
import { AnyMetaPlugin } from '@orpc/contract';
|
|
5
|
-
|
|
6
|
-
type ToORPCOutput<T> = T extends AsyncIterable<infer TData, infer TReturn, infer TNext> ? AsyncIteratorClass<TData, TReturn, TNext> : T;
|
|
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> : TRecord[K] extends Record<string, any> ? ToORPCRouterResult<TContext, TRecord[K]> : never;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Converts a tRPC router into an oRPC router that works with any oRPC feature.
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
14
|
-
* **Note**: tRPC Error Formatting is not supported — errors thrown by tRPC are wrapped in `ORPCError`.
|
|
15
|
-
*
|
|
16
|
-
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
17
|
-
*/
|
|
18
|
-
declare function toORPCRouter<T extends AnyRouter>(router: T): ToORPCRouterResult<inferRouterContext<T>, T['_def']['record']>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Resolve oRPC meta plugins into a plain meta object usable as tRPC meta.
|
|
22
|
-
*
|
|
23
|
-
* This simulates how oRPC builders apply meta plugins, so well-known plugins
|
|
24
|
-
* like `openapi` from `@orpc/openapi` can be used with tRPC builders.
|
|
25
|
-
*
|
|
26
|
-
* @remarks
|
|
27
|
-
* **Warning**: Chained tRPC `.meta` calls merge shallowly, so oRPC metadata merge logic
|
|
28
|
-
* (e.g. accumulating openapi `tags`) only works within a single `toTRPCMeta` call.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* const example = t.procedure
|
|
33
|
-
* .meta(toTRPCMeta(openapi({ path: '/hello' })))
|
|
34
|
-
* .query(() => 'Hello, World!')
|
|
35
|
-
*
|
|
36
|
-
* const merged = t.procedure
|
|
37
|
-
* .meta({
|
|
38
|
-
* ...toTRPCMeta(
|
|
39
|
-
* openapi({ path: '/hello' }),
|
|
40
|
-
* openapi({ method: 'POST' }),
|
|
41
|
-
* ),
|
|
42
|
-
* other: 'value',
|
|
43
|
-
* })
|
|
44
|
-
* .mutation(() => 'Hello, World!')
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
48
|
-
*/
|
|
49
|
-
declare function toTRPCMeta(...plugins: AnyMetaPlugin[]): Record<string, any>;
|
|
50
|
-
|
|
51
|
-
export { toORPCRouter, toTRPCMeta };
|
|
52
|
-
export type { ToORPCOutput, ToORPCRouterResult };
|
|
1
|
+
export * from "./to-orpc-router.mjs";
|
|
2
|
+
export * from "./to-trpc-meta.mjs";
|
package/dist/index.mjs
CHANGED
|
@@ -1,105 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { isTrackedEnvelope, TRPCError } from '@trpc/server';
|
|
4
|
-
import { isObject, isAsyncIterable } from '@trpc/server/unstable-core-do-not-import';
|
|
5
|
-
import { resolveMetaPlugins } from '@orpc/contract';
|
|
6
|
-
|
|
7
|
-
function toORPCRouter(router) {
|
|
8
|
-
const result = recordToORPCRouterRecord(router._def.record);
|
|
9
|
-
for (const [key, item] of Object.entries(router._def.lazy)) {
|
|
10
|
-
set(result, key.split("."), new ORPC.Lazy({
|
|
11
|
-
meta: {},
|
|
12
|
-
loader: async () => {
|
|
13
|
-
const router2 = await item.ref();
|
|
14
|
-
return { default: toORPCRouter(router2) };
|
|
15
|
-
}
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
function recordToORPCRouterRecord(records) {
|
|
21
|
-
const orpcRouter = {};
|
|
22
|
-
for (const key of Object.keys(records)) {
|
|
23
|
-
const item = records[key];
|
|
24
|
-
if (typeof item === "function") {
|
|
25
|
-
orpcRouter[key] = toORPCProcedure(item);
|
|
26
|
-
} else {
|
|
27
|
-
orpcRouter[key] = recordToORPCRouterRecord(item);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return orpcRouter;
|
|
31
|
-
}
|
|
32
|
-
function toORPCProcedure(procedure) {
|
|
33
|
-
const inputSchema = toStandardSchema(procedure._def.inputs.at(-1));
|
|
34
|
-
const outputSchema = toStandardSchema(procedure._def.output);
|
|
35
|
-
return new ORPC.Procedure({
|
|
36
|
-
errorMap: {},
|
|
37
|
-
meta: procedure._def.meta ?? {},
|
|
38
|
-
orderedMiddlewares: [],
|
|
39
|
-
inputSchemas: inputSchema ? [inputSchema] : void 0,
|
|
40
|
-
outputSchemas: outputSchema ? [outputSchema] : void 0,
|
|
41
|
-
// tRPC procedure calling already validates the input/output
|
|
42
|
-
disableInputValidation: true,
|
|
43
|
-
disableOutputValidation: true,
|
|
44
|
-
handler: async ({ context, signal, path, input, lastEventId }) => {
|
|
45
|
-
try {
|
|
46
|
-
const trpcInput = lastEventId !== void 0 && (input === void 0 || isObject(input)) ? { ...input, lastEventId } : input;
|
|
47
|
-
const output = await procedure({
|
|
48
|
-
ctx: context,
|
|
49
|
-
signal,
|
|
50
|
-
path: path.join("."),
|
|
51
|
-
type: procedure._def.type,
|
|
52
|
-
// Only the raw input: tRPC merges `input` into the parsed input, so passing it would keep keys the schema strips
|
|
53
|
-
getRawInput: async () => trpcInput,
|
|
54
|
-
// TODO: this should infer from context when using oRPC Batch Plugin
|
|
55
|
-
batchIndex: 0
|
|
56
|
-
});
|
|
57
|
-
if (isAsyncIterable(output)) {
|
|
58
|
-
return wrapAsyncIterator(output[Symbol.asyncIterator](), {
|
|
59
|
-
mapResult: (result) => {
|
|
60
|
-
if (isTrackedEnvelope(result.value)) {
|
|
61
|
-
const [id, data] = result.value;
|
|
62
|
-
return {
|
|
63
|
-
done: result.done,
|
|
64
|
-
value: ORPC.withEventMeta({
|
|
65
|
-
id,
|
|
66
|
-
data
|
|
67
|
-
}, {
|
|
68
|
-
id
|
|
69
|
-
})
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
},
|
|
74
|
-
mapError: toORPCError
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return output;
|
|
78
|
-
} catch (cause) {
|
|
79
|
-
throw toORPCError(cause);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function toORPCError(error) {
|
|
85
|
-
if (error instanceof TRPCError) {
|
|
86
|
-
return new ORPC.ORPCError(error.code, {
|
|
87
|
-
message: error.message,
|
|
88
|
-
cause: error
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return error;
|
|
92
|
-
}
|
|
93
|
-
function toStandardSchema(schema) {
|
|
94
|
-
if (!isTypescriptObject(schema) || !("~standard" in schema) || !isTypescriptObject(schema["~standard"])) {
|
|
95
|
-
return void 0;
|
|
96
|
-
}
|
|
97
|
-
return schema;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function toTRPCMeta(...plugins) {
|
|
101
|
-
const [meta] = resolveMetaPlugins({}, void 0, plugins);
|
|
102
|
-
return meta;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export { toORPCRouter, toTRPCMeta };
|
|
1
|
+
export * from "./to-orpc-router.mjs";
|
|
2
|
+
export * from "./to-trpc-meta.mjs";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AsyncIteratorClass } from "@orpc/shared";
|
|
2
|
+
import type { AnyProcedure, AnyRouter, inferRouterContext } from "@trpc/server";
|
|
3
|
+
import * as ORPC from "@orpc/server";
|
|
4
|
+
export type ToORPCOutput<T> = T extends AsyncIterable<infer TData, infer TReturn, infer TNext> ? AsyncIteratorClass<TData, TReturn, TNext> : T;
|
|
5
|
+
export type ToORPCRouterResult<
|
|
6
|
+
TContext extends ORPC.Context,
|
|
7
|
+
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> : TRecord[K] extends Record<string, any> ? ToORPCRouterResult<TContext, TRecord[K]> : never };
|
|
9
|
+
/**
|
|
10
|
+
* Converts a tRPC router into an oRPC router that works with any oRPC feature.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* **Note**: tRPC Error Formatting is not supported — errors thrown by tRPC are wrapped in `ORPCError`.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
16
|
+
*/
|
|
17
|
+
export declare function toORPCRouter<T extends AnyRouter>(router: T): ToORPCRouterResult<inferRouterContext<T>, T["_def"]["record"]>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as ORPC from "@orpc/server";
|
|
2
|
+
import { isTypescriptObject, set, wrapAsyncIterator } from "@orpc/shared";
|
|
3
|
+
import { isTrackedEnvelope, TRPCError } from "@trpc/server";
|
|
4
|
+
import { isAsyncIterable, isObject } from "@trpc/server/unstable-core-do-not-import";
|
|
5
|
+
|
|
6
|
+
export function toORPCRouter(router) {
|
|
7
|
+
const result = recordToORPCRouterRecord(router._def.record);
|
|
8
|
+
for (const [key, item] of Object.entries(router._def.lazy)) {
|
|
9
|
+
set(result, key.split("."), new ORPC.Lazy({
|
|
10
|
+
meta: {},
|
|
11
|
+
loader: async () => {
|
|
12
|
+
const router = await item.ref();
|
|
13
|
+
return { default: toORPCRouter(router) };
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
function recordToORPCRouterRecord(records) {
|
|
20
|
+
const orpcRouter = {};
|
|
21
|
+
for (const key of Object.keys(records)) {
|
|
22
|
+
const item = records[key];
|
|
23
|
+
if (typeof item === "function") {
|
|
24
|
+
orpcRouter[key] = toORPCProcedure(item);
|
|
25
|
+
} else {
|
|
26
|
+
orpcRouter[key] = recordToORPCRouterRecord(item);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return orpcRouter;
|
|
30
|
+
}
|
|
31
|
+
function toORPCProcedure(procedure) {
|
|
32
|
+
const inputSchema = toStandardSchema(procedure._def.inputs.at(-1));
|
|
33
|
+
const outputSchema = toStandardSchema(procedure._def.output);
|
|
34
|
+
return new ORPC.Procedure({
|
|
35
|
+
errorMap: {},
|
|
36
|
+
meta: procedure._def.meta ?? {},
|
|
37
|
+
orderedMiddlewares: [],
|
|
38
|
+
inputSchemas: inputSchema ? [inputSchema] : undefined,
|
|
39
|
+
outputSchemas: outputSchema ? [outputSchema] : undefined,
|
|
40
|
+
|
|
41
|
+
disableInputValidation: true,
|
|
42
|
+
disableOutputValidation: true,
|
|
43
|
+
handler: async ({ context, signal, path, input, lastEventId }) => {
|
|
44
|
+
try {
|
|
45
|
+
const trpcInput = lastEventId !== undefined && (input === undefined || isObject(input)) ? {
|
|
46
|
+
...input,
|
|
47
|
+
lastEventId
|
|
48
|
+
} : input;
|
|
49
|
+
const output = await procedure({
|
|
50
|
+
ctx: context,
|
|
51
|
+
signal,
|
|
52
|
+
path: path.join("."),
|
|
53
|
+
type: procedure._def.type,
|
|
54
|
+
|
|
55
|
+
getRawInput: async () => trpcInput,
|
|
56
|
+
|
|
57
|
+
batchIndex: 0
|
|
58
|
+
});
|
|
59
|
+
if (isAsyncIterable(output)) {
|
|
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
|
+
}, { id })
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
},
|
|
74
|
+
mapError: toORPCError
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return output;
|
|
78
|
+
} catch (cause) {
|
|
79
|
+
throw toORPCError(cause);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function toORPCError(error) {
|
|
85
|
+
if (error instanceof TRPCError) {
|
|
86
|
+
return new ORPC.ORPCError(error.code, {
|
|
87
|
+
message: error.message,
|
|
88
|
+
cause: error
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return error;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function toStandardSchema(schema) {
|
|
95
|
+
if (!isTypescriptObject(schema) || !("~standard" in schema) || !isTypescriptObject(schema["~standard"])) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return schema;
|
|
99
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AnyMetaPlugin } from "@orpc/contract";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve oRPC meta plugins into a plain meta object usable as tRPC meta.
|
|
4
|
+
*
|
|
5
|
+
* This simulates how oRPC builders apply meta plugins, so well-known plugins
|
|
6
|
+
* like `openapi` from `@orpc/openapi` can be used with tRPC builders.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* **Warning**: Chained tRPC `.meta` calls merge shallowly, so oRPC metadata merge logic
|
|
10
|
+
* (e.g. accumulating openapi `tags`) only works within a single `toTRPCMeta` call.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const example = t.procedure
|
|
15
|
+
* .meta(toTRPCMeta(openapi({ path: '/hello' })))
|
|
16
|
+
* .query(() => 'Hello, World!')
|
|
17
|
+
*
|
|
18
|
+
* const merged = t.procedure
|
|
19
|
+
* .meta({
|
|
20
|
+
* ...toTRPCMeta(
|
|
21
|
+
* openapi({ path: '/hello' }),
|
|
22
|
+
* openapi({ method: 'POST' }),
|
|
23
|
+
* ),
|
|
24
|
+
* other: 'value',
|
|
25
|
+
* })
|
|
26
|
+
* .mutation(() => 'Hello, World!')
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
30
|
+
*/
|
|
31
|
+
export declare function toTRPCMeta(...plugins: AnyMetaPlugin[]): Record<string, any>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/trpc",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.48",
|
|
5
5
|
"description": "tRPC interop for oRPC: reuse existing tRPC routers with oRPC clients and OpenAPI",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"@trpc/server": ">=11.4.2"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@orpc/contract": "2.0.0-beta.
|
|
44
|
-
"@orpc/server": "2.0.0-beta.
|
|
45
|
-
"@orpc/shared": "2.0.0-beta.
|
|
43
|
+
"@orpc/contract": "2.0.0-beta.48",
|
|
44
|
+
"@orpc/server": "2.0.0-beta.48",
|
|
45
|
+
"@orpc/shared": "2.0.0-beta.48"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@orpc/openapi": "2.0.0-beta.
|
|
49
|
-
"@trpc/server": "^11.
|
|
48
|
+
"@orpc/openapi": "2.0.0-beta.48",
|
|
49
|
+
"@trpc/server": "^11.22.1",
|
|
50
50
|
"zod": "^4.6.7"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
package/dist/index.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { AsyncIteratorClass } from '@orpc/shared';
|
|
2
|
-
import { AnyProcedure, AnyRouter, inferRouterContext } from '@trpc/server';
|
|
3
|
-
import * as ORPC from '@orpc/server';
|
|
4
|
-
import { AnyMetaPlugin } from '@orpc/contract';
|
|
5
|
-
|
|
6
|
-
type ToORPCOutput<T> = T extends AsyncIterable<infer TData, infer TReturn, infer TNext> ? AsyncIteratorClass<TData, TReturn, TNext> : T;
|
|
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> : TRecord[K] extends Record<string, any> ? ToORPCRouterResult<TContext, TRecord[K]> : never;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Converts a tRPC router into an oRPC router that works with any oRPC feature.
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
14
|
-
* **Note**: tRPC Error Formatting is not supported — errors thrown by tRPC are wrapped in `ORPCError`.
|
|
15
|
-
*
|
|
16
|
-
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
17
|
-
*/
|
|
18
|
-
declare function toORPCRouter<T extends AnyRouter>(router: T): ToORPCRouterResult<inferRouterContext<T>, T['_def']['record']>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Resolve oRPC meta plugins into a plain meta object usable as tRPC meta.
|
|
22
|
-
*
|
|
23
|
-
* This simulates how oRPC builders apply meta plugins, so well-known plugins
|
|
24
|
-
* like `openapi` from `@orpc/openapi` can be used with tRPC builders.
|
|
25
|
-
*
|
|
26
|
-
* @remarks
|
|
27
|
-
* **Warning**: Chained tRPC `.meta` calls merge shallowly, so oRPC metadata merge logic
|
|
28
|
-
* (e.g. accumulating openapi `tags`) only works within a single `toTRPCMeta` call.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* const example = t.procedure
|
|
33
|
-
* .meta(toTRPCMeta(openapi({ path: '/hello' })))
|
|
34
|
-
* .query(() => 'Hello, World!')
|
|
35
|
-
*
|
|
36
|
-
* const merged = t.procedure
|
|
37
|
-
* .meta({
|
|
38
|
-
* ...toTRPCMeta(
|
|
39
|
-
* openapi({ path: '/hello' }),
|
|
40
|
-
* openapi({ method: 'POST' }),
|
|
41
|
-
* ),
|
|
42
|
-
* other: 'value',
|
|
43
|
-
* })
|
|
44
|
-
* .mutation(() => 'Hello, World!')
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
48
|
-
*/
|
|
49
|
-
declare function toTRPCMeta(...plugins: AnyMetaPlugin[]): Record<string, any>;
|
|
50
|
-
|
|
51
|
-
export { toORPCRouter, toTRPCMeta };
|
|
52
|
-
export type { ToORPCOutput, ToORPCRouterResult };
|