@orpc/trpc 2.0.0-beta.47 → 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 +2 -3
- 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
|
@@ -191,15 +191,14 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
191
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>
|
|
192
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>
|
|
193
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>
|
|
194
|
-
<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>
|
|
195
195
|
</tr>
|
|
196
196
|
<tr>
|
|
197
|
-
<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>
|
|
198
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>
|
|
199
198
|
</tr>
|
|
200
199
|
</table>
|
|
201
200
|
|
|
202
|
-
With thanks to [
|
|
201
|
+
With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
203
202
|
|
|
204
203
|
## Open Source Programs
|
|
205
204
|
|
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 };
|