@orpc/trpc 2.0.0-beta.49 → 2.0.0-beta.51
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 +10 -8
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -2
- package/dist/to-orpc-router.d.ts +5 -7
- package/dist/to-orpc-router.js +96 -111
- package/dist/to-trpc-meta.d.ts +2 -2
- package/dist/to-trpc-meta.js +34 -32
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -78,13 +78,14 @@ Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [
|
|
|
78
78
|
|
|
79
79
|
**Built-in features**
|
|
80
80
|
|
|
81
|
-
| Package
|
|
82
|
-
|
|
|
83
|
-
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher)
|
|
84
|
-
| [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit)
|
|
85
|
-
| [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock)
|
|
86
|
-
| [@orpc/
|
|
87
|
-
| [@orpc/
|
|
81
|
+
| Package | Purpose | Docs |
|
|
82
|
+
| ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
83
|
+
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
|
|
84
|
+
| [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit) | Rate limiting with memory, Redis, and Upstash adapters. | [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
|
|
85
|
+
| [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock) | Locking with memory, Redis, and Upstash adapters. | [Lock](https://orpc.dev/docs/helpers/lock) |
|
|
86
|
+
| [@orpc/experimental-openapi-inference](https://www.npmjs.com/package/@orpc/experimental-openapi-inference) | Generate OpenAPI specs from TypeScript types, no output schemas required. | [Type Inference](https://orpc.dev/docs/openapi/specification#type-inference) |
|
|
87
|
+
| [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation) | Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api). | [Hibernation](https://orpc.dev/docs/integrations/hibernation) |
|
|
88
|
+
| [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema) | Smart coercion for OpenAPI requests. | [Smart Coercion](https://orpc.dev/docs/plugins/smart-coercion) |
|
|
88
89
|
|
|
89
90
|
**Framework & ecosystem integrations**
|
|
90
91
|
|
|
@@ -192,9 +193,10 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
192
193
|
<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>
|
|
193
194
|
<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>
|
|
194
195
|
<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>
|
|
195
|
-
<td align="center"><a href="https://
|
|
196
|
+
<td align="center"><a href="https://usagerail.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="UsageRail"><img src="https://avatars.githubusercontent.com/u/347653714?v=4" width="139" alt="UsageRail"/><br />UsageRail</a></td>
|
|
196
197
|
</tr>
|
|
197
198
|
<tr>
|
|
199
|
+
<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
200
|
<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
201
|
</tr>
|
|
200
202
|
</table>
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ToORPCOutput, ToORPCRouterResult, toORPCRouter } from "./to-orpc-router.js";
|
|
2
|
+
import { toTRPCMeta } from "./to-trpc-meta.js";
|
|
3
|
+
export { ToORPCOutput, ToORPCRouterResult, toORPCRouter, toTRPCMeta };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { toORPCRouter } from "./to-orpc-router.js";
|
|
2
|
+
export { toTRPCMeta } from "./to-trpc-meta.js";
|
package/dist/to-orpc-router.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import * as ORPC from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import * as ORPC from "@orpc/server";
|
|
2
|
+
import { AsyncIteratorClass } from "@orpc/shared";
|
|
3
|
+
import { AnyProcedure, AnyRouter, inferRouterContext } from "@trpc/server";
|
|
4
4
|
export type ToORPCOutput<T> = T extends AsyncIterable<infer TData, infer TReturn, infer TNext> ? AsyncIteratorClass<TData, TReturn, TNext> : T;
|
|
5
|
-
export type ToORPCRouterResult<TContext extends ORPC.Context, TRecord extends Record<string, any>> = {
|
|
6
|
-
[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;
|
|
7
|
-
};
|
|
5
|
+
export type ToORPCRouterResult<TContext extends ORPC.Context, TRecord extends Record<string, any>> = { [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; };
|
|
8
6
|
/**
|
|
9
7
|
* Converts a tRPC router into an oRPC router that works with any oRPC feature.
|
|
10
8
|
*
|
|
@@ -13,4 +11,4 @@ export type ToORPCRouterResult<TContext extends ORPC.Context, TRecord extends Re
|
|
|
13
11
|
*
|
|
14
12
|
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
15
13
|
*/
|
|
16
|
-
export declare function toORPCRouter<T extends AnyRouter>(router: T): ToORPCRouterResult<inferRouterContext<T>, T[
|
|
14
|
+
export declare function toORPCRouter<T extends AnyRouter>(router: T): ToORPCRouterResult<inferRouterContext<T>, T["_def"]["record"]>;
|
package/dist/to-orpc-router.js
CHANGED
|
@@ -1,125 +1,110 @@
|
|
|
1
|
-
import * as ORPC from
|
|
2
|
-
import { isNonPrimitive, set, wrapAsyncIterator } from
|
|
3
|
-
import {
|
|
4
|
-
import { isAsyncIterable, isObject } from
|
|
1
|
+
import * as ORPC from "@orpc/server";
|
|
2
|
+
import { isNonPrimitive, set, wrapAsyncIterator } from "@orpc/shared";
|
|
3
|
+
import { TRPCError, isTrackedEnvelope } from "@trpc/server";
|
|
4
|
+
import { isAsyncIterable, isObject } from "@trpc/server/unstable-core-do-not-import";
|
|
5
|
+
// src/to-orpc-router.ts
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
7
|
+
* Converts a tRPC router into an oRPC router that works with any oRPC feature.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* **Note**: tRPC Error Formatting is not supported — errors thrown by tRPC are wrapped in `ORPCError`.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
13
|
+
*/
|
|
14
|
+
function toORPCRouter(router) {
|
|
15
|
+
const result = recordToORPCRouterRecord(router._def.record);
|
|
16
|
+
for (const [key, item] of Object.entries(router._def.lazy)) set(result, key.split("."), new ORPC.Lazy({
|
|
17
|
+
meta: {},
|
|
18
|
+
loader: async () => {
|
|
19
|
+
return { default: toORPCRouter(await item.ref()) };
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
return result;
|
|
25
23
|
}
|
|
26
24
|
function recordToORPCRouterRecord(records) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
orpcRouter[key] = recordToORPCRouterRecord(item);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return orpcRouter;
|
|
25
|
+
const orpcRouter = {};
|
|
26
|
+
for (const key of Object.keys(records)) {
|
|
27
|
+
const item = records[key];
|
|
28
|
+
if (typeof item === "function") orpcRouter[key] = toORPCProcedure(item);
|
|
29
|
+
else orpcRouter[key] = recordToORPCRouterRecord(item);
|
|
30
|
+
}
|
|
31
|
+
return orpcRouter;
|
|
38
32
|
}
|
|
39
33
|
function toORPCProcedure(procedure) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return output;
|
|
91
|
-
}
|
|
92
|
-
catch (cause) {
|
|
93
|
-
throw toORPCError(cause);
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
});
|
|
34
|
+
const inputSchema = toStandardSchema(procedure._def.inputs.at(-1));
|
|
35
|
+
const outputSchema = toStandardSchema(procedure._def.output);
|
|
36
|
+
const meta = procedure._def.meta ?? {};
|
|
37
|
+
return new ORPC.Procedure({
|
|
38
|
+
errorMap: {},
|
|
39
|
+
meta,
|
|
40
|
+
metaPlugins: [toTRPCMetaPlugin(meta)],
|
|
41
|
+
orderedMiddlewares: [],
|
|
42
|
+
inputSchemas: inputSchema ? [inputSchema] : void 0,
|
|
43
|
+
outputSchemas: outputSchema ? [outputSchema] : void 0,
|
|
44
|
+
disableInputValidation: true,
|
|
45
|
+
disableOutputValidation: true,
|
|
46
|
+
handler: async ({ context, signal, path, input, lastEventId }) => {
|
|
47
|
+
try {
|
|
48
|
+
const trpcInput = lastEventId !== void 0 && (input === void 0 || isObject(input)) ? {
|
|
49
|
+
...input,
|
|
50
|
+
lastEventId
|
|
51
|
+
} : input;
|
|
52
|
+
const output = await procedure({
|
|
53
|
+
ctx: context,
|
|
54
|
+
signal,
|
|
55
|
+
path: path.join("."),
|
|
56
|
+
type: procedure._def.type,
|
|
57
|
+
getRawInput: async () => trpcInput,
|
|
58
|
+
batchIndex: 0
|
|
59
|
+
});
|
|
60
|
+
if (isAsyncIterable(output)) 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
|
+
return output;
|
|
77
|
+
} catch (cause) {
|
|
78
|
+
throw toORPCError(cause);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
97
82
|
}
|
|
98
83
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
84
|
+
* Re-applies tRPC meta on top of the incoming meta, shallow merged like tRPC `.meta` calls.
|
|
85
|
+
*/
|
|
101
86
|
function toTRPCMetaPlugin(trpcMeta) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
87
|
+
return {
|
|
88
|
+
name: "~trpc",
|
|
89
|
+
init: (meta) => ({
|
|
90
|
+
...meta,
|
|
91
|
+
...trpcMeta
|
|
92
|
+
})
|
|
93
|
+
};
|
|
106
94
|
}
|
|
107
95
|
function toORPCError(error) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
return error;
|
|
96
|
+
if (error instanceof TRPCError) return new ORPC.ORPCError(error.code, {
|
|
97
|
+
message: error.message,
|
|
98
|
+
cause: error
|
|
99
|
+
});
|
|
100
|
+
return error;
|
|
115
101
|
}
|
|
116
102
|
/**
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
103
|
+
* Ensures the parser is a standard schema before exposing it to oRPC,
|
|
104
|
+
* so schemas remain usable for type inference and OpenAPI generation.
|
|
105
|
+
*/
|
|
120
106
|
function toStandardSchema(schema) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
return schema;
|
|
107
|
+
if (!isNonPrimitive(schema) || !("~standard" in schema) || !isNonPrimitive(schema["~standard"])) return;
|
|
108
|
+
return schema;
|
|
125
109
|
}
|
|
110
|
+
export { toORPCRouter };
|
package/dist/to-trpc-meta.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AnyMetaPlugin } from "@orpc/contract";
|
|
2
2
|
/**
|
|
3
3
|
* Resolve oRPC meta plugins into a plain meta object usable as tRPC meta.
|
|
4
4
|
*
|
|
@@ -28,4 +28,4 @@ import type { AnyMetaPlugin } from '@orpc/contract';
|
|
|
28
28
|
*
|
|
29
29
|
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
30
30
|
*/
|
|
31
|
-
export declare function toTRPCMeta(...plugins: AnyMetaPlugin[]): Record<string, any>;
|
|
31
|
+
export declare function toTRPCMeta(...plugins: AnyMetaPlugin[]): Record<string, any>;
|
package/dist/to-trpc-meta.js
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
|
-
import { resolveMetaPlugins } from
|
|
1
|
+
import { resolveMetaPlugins } from "@orpc/contract";
|
|
2
|
+
// src/to-trpc-meta.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
4
|
+
* Resolve oRPC meta plugins into a plain meta object usable as tRPC meta.
|
|
5
|
+
*
|
|
6
|
+
* This simulates how oRPC builders apply meta plugins, so well-known plugins
|
|
7
|
+
* like `openapi` from `@orpc/openapi` can be used with tRPC builders.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* **Warning**: Chained tRPC `.meta` calls merge shallowly, so oRPC metadata merge logic
|
|
11
|
+
* (e.g. accumulating openapi `tags`) only works within a single `toTRPCMeta` call.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const example = t.procedure
|
|
16
|
+
* .meta(toTRPCMeta(openapi({ path: '/hello' })))
|
|
17
|
+
* .query(() => 'Hello, World!')
|
|
18
|
+
*
|
|
19
|
+
* const merged = t.procedure
|
|
20
|
+
* .meta({
|
|
21
|
+
* ...toTRPCMeta(
|
|
22
|
+
* openapi({ path: '/hello' }),
|
|
23
|
+
* openapi({ method: 'POST' }),
|
|
24
|
+
* ),
|
|
25
|
+
* other: 'value',
|
|
26
|
+
* })
|
|
27
|
+
* .mutation(() => 'Hello, World!')
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://orpc.dev/docs/integrations/trpc | tRPC Integration}
|
|
31
|
+
*/
|
|
32
|
+
function toTRPCMeta(...plugins) {
|
|
33
|
+
const [meta] = resolveMetaPlugins({}, void 0, plugins);
|
|
34
|
+
return meta;
|
|
34
35
|
}
|
|
36
|
+
export { toTRPCMeta };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/trpc",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.51",
|
|
4
4
|
"description": "tRPC interop for oRPC: reuse existing tRPC routers with oRPC clients and OpenAPI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"interop",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@orpc/contract": "2.0.0-beta.
|
|
41
|
-
"@orpc/server": "2.0.0-beta.
|
|
42
|
-
"@orpc/shared": "2.0.0-beta.
|
|
40
|
+
"@orpc/contract": "2.0.0-beta.51",
|
|
41
|
+
"@orpc/server": "2.0.0-beta.51",
|
|
42
|
+
"@orpc/shared": "2.0.0-beta.51"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@orpc/openapi": "2.0.0-beta.
|
|
45
|
+
"@orpc/openapi": "2.0.0-beta.51",
|
|
46
46
|
"@trpc/server": "^11.23.0",
|
|
47
47
|
"zod": "^4.6.7"
|
|
48
48
|
},
|