@orpc/trpc 1.6.6 → 1.6.8
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/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.mjs +109 -0
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
@@ -1,2 +1,20 @@
|
|
1
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
2
|
+
import { AnyProcedure, AnyRouter, inferRouterContext } from '@trpc/server';
|
3
|
+
import { inferRouterMeta } from '@trpc/server/unstable-core-do-not-import';
|
4
|
+
import * as ORPC from '@orpc/server';
|
1
5
|
|
2
|
-
|
6
|
+
interface experimental_ORPCMeta extends ORPC.Route {
|
7
|
+
}
|
8
|
+
type experimental_ToORPCOutput<T> = T extends AsyncIterable<infer TData, infer TReturn, infer TNext> ? AsyncIteratorClass<TData, TReturn, TNext> : T;
|
9
|
+
type experimental_ToORPCRouterResult<TContext extends ORPC.Context, TMeta extends ORPC.Meta, TRecord extends Record<string, any>> = {
|
10
|
+
[K in keyof TRecord]: TRecord[K] extends AnyProcedure ? ORPC.Procedure<TContext, object, ORPC.Schema<TRecord[K]['_def']['$types']['input'], unknown>, ORPC.Schema<unknown, experimental_ToORPCOutput<TRecord[K]['_def']['$types']['output']>>, object, TMeta> : TRecord[K] extends Record<string, any> ? experimental_ToORPCRouterResult<TContext, TMeta, TRecord[K]> : never;
|
11
|
+
};
|
12
|
+
/**
|
13
|
+
* Convert a tRPC router to an oRPC router.
|
14
|
+
*
|
15
|
+
* @warning You should set the `meta` type to `ORPCMeta` when creating your tRPC builder, to ensure OpenAPI features work correctly.
|
16
|
+
*/
|
17
|
+
declare function experimental_toORPCRouter<T extends AnyRouter>(router: T): experimental_ToORPCRouterResult<inferRouterContext<T>, inferRouterMeta<T>, T['_def']['record']>;
|
18
|
+
|
19
|
+
export { experimental_toORPCRouter };
|
20
|
+
export type { experimental_ORPCMeta, experimental_ToORPCOutput, experimental_ToORPCRouterResult };
|
package/dist/index.d.ts
CHANGED
@@ -1,2 +1,20 @@
|
|
1
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
2
|
+
import { AnyProcedure, AnyRouter, inferRouterContext } from '@trpc/server';
|
3
|
+
import { inferRouterMeta } from '@trpc/server/unstable-core-do-not-import';
|
4
|
+
import * as ORPC from '@orpc/server';
|
1
5
|
|
2
|
-
|
6
|
+
interface experimental_ORPCMeta extends ORPC.Route {
|
7
|
+
}
|
8
|
+
type experimental_ToORPCOutput<T> = T extends AsyncIterable<infer TData, infer TReturn, infer TNext> ? AsyncIteratorClass<TData, TReturn, TNext> : T;
|
9
|
+
type experimental_ToORPCRouterResult<TContext extends ORPC.Context, TMeta extends ORPC.Meta, TRecord extends Record<string, any>> = {
|
10
|
+
[K in keyof TRecord]: TRecord[K] extends AnyProcedure ? ORPC.Procedure<TContext, object, ORPC.Schema<TRecord[K]['_def']['$types']['input'], unknown>, ORPC.Schema<unknown, experimental_ToORPCOutput<TRecord[K]['_def']['$types']['output']>>, object, TMeta> : TRecord[K] extends Record<string, any> ? experimental_ToORPCRouterResult<TContext, TMeta, TRecord[K]> : never;
|
11
|
+
};
|
12
|
+
/**
|
13
|
+
* Convert a tRPC router to an oRPC router.
|
14
|
+
*
|
15
|
+
* @warning You should set the `meta` type to `ORPCMeta` when creating your tRPC builder, to ensure OpenAPI features work correctly.
|
16
|
+
*/
|
17
|
+
declare function experimental_toORPCRouter<T extends AnyRouter>(router: T): experimental_ToORPCRouterResult<inferRouterContext<T>, inferRouterMeta<T>, T['_def']['record']>;
|
18
|
+
|
19
|
+
export { experimental_toORPCRouter };
|
20
|
+
export type { experimental_ORPCMeta, experimental_ToORPCOutput, experimental_ToORPCRouterResult };
|
package/dist/index.mjs
CHANGED
@@ -1 +1,110 @@
|
|
1
|
+
import { mapEventIterator } from '@orpc/client';
|
2
|
+
import * as ORPC from '@orpc/server';
|
3
|
+
import { isObject, isTypescriptObject } from '@orpc/shared';
|
4
|
+
import { isTrackedEnvelope, TRPCError } from '@trpc/server';
|
5
|
+
import { isAsyncIterable, getHTTPStatusCodeFromError } from '@trpc/server/unstable-core-do-not-import';
|
1
6
|
|
7
|
+
function experimental_toORPCRouter(router) {
|
8
|
+
const result = {
|
9
|
+
...lazyToORPCRouter(router._def.lazy),
|
10
|
+
...recordToORPCRouterRecord(router._def.record)
|
11
|
+
};
|
12
|
+
return result;
|
13
|
+
}
|
14
|
+
function lazyToORPCRouter(lazies) {
|
15
|
+
const orpcRouter = {};
|
16
|
+
for (const key in lazies) {
|
17
|
+
const item = lazies[key];
|
18
|
+
orpcRouter[key] = ORPC.lazy(async () => {
|
19
|
+
const router = await item.ref();
|
20
|
+
return { default: experimental_toORPCRouter(router) };
|
21
|
+
});
|
22
|
+
}
|
23
|
+
return orpcRouter;
|
24
|
+
}
|
25
|
+
function recordToORPCRouterRecord(records) {
|
26
|
+
const orpcRouter = {};
|
27
|
+
for (const key in records) {
|
28
|
+
const item = records[key];
|
29
|
+
if (typeof item === "function") {
|
30
|
+
orpcRouter[key] = toORPCProcedure(item);
|
31
|
+
} else {
|
32
|
+
orpcRouter[key] = recordToORPCRouterRecord(item);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return orpcRouter;
|
36
|
+
}
|
37
|
+
function toORPCProcedure(procedure) {
|
38
|
+
return new ORPC.Procedure({
|
39
|
+
errorMap: {},
|
40
|
+
meta: procedure._def.meta ?? {},
|
41
|
+
inputValidationIndex: 0,
|
42
|
+
outputValidationIndex: 0,
|
43
|
+
route: procedure._def.meta ?? {},
|
44
|
+
middlewares: [],
|
45
|
+
inputSchema: toDisabledStandardSchema(procedure._def.inputs.at(-1)),
|
46
|
+
outputSchema: toDisabledStandardSchema(procedure._def.output),
|
47
|
+
handler: async ({ context, signal, path, input, lastEventId }) => {
|
48
|
+
try {
|
49
|
+
const trpcInput = lastEventId !== void 0 && (input === void 0 || isObject(input)) ? { ...input, lastEventId } : input;
|
50
|
+
const output = await procedure({
|
51
|
+
ctx: context,
|
52
|
+
signal,
|
53
|
+
path: path.join("."),
|
54
|
+
type: procedure._def.type,
|
55
|
+
input: trpcInput,
|
56
|
+
getRawInput: () => trpcInput
|
57
|
+
});
|
58
|
+
if (isAsyncIterable(output)) {
|
59
|
+
return mapEventIterator(output[Symbol.asyncIterator](), {
|
60
|
+
error: async (error) => error,
|
61
|
+
value: (value) => {
|
62
|
+
if (isTrackedEnvelope(value)) {
|
63
|
+
const [id, data] = value;
|
64
|
+
return ORPC.withEventMeta({
|
65
|
+
id,
|
66
|
+
data
|
67
|
+
}, {
|
68
|
+
id
|
69
|
+
});
|
70
|
+
}
|
71
|
+
return value;
|
72
|
+
}
|
73
|
+
});
|
74
|
+
}
|
75
|
+
return output;
|
76
|
+
} catch (cause) {
|
77
|
+
if (cause instanceof TRPCError) {
|
78
|
+
throw new ORPC.ORPCError(cause.code, {
|
79
|
+
status: getHTTPStatusCodeFromError(cause),
|
80
|
+
message: cause.message,
|
81
|
+
cause
|
82
|
+
});
|
83
|
+
}
|
84
|
+
throw cause;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
});
|
88
|
+
}
|
89
|
+
function toDisabledStandardSchema(schema) {
|
90
|
+
if (!isTypescriptObject(schema) || !("~standard" in schema) || !isTypescriptObject(schema["~standard"])) {
|
91
|
+
return void 0;
|
92
|
+
}
|
93
|
+
return new Proxy(schema, {
|
94
|
+
get: (target, prop) => {
|
95
|
+
if (prop === "~standard") {
|
96
|
+
return new Proxy(target["~standard"], {
|
97
|
+
get: (target2, prop2) => {
|
98
|
+
if (prop2 === "validate") {
|
99
|
+
return (value) => ({ value });
|
100
|
+
}
|
101
|
+
return Reflect.get(target2, prop2, target2);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
}
|
105
|
+
return Reflect.get(target, prop, target);
|
106
|
+
}
|
107
|
+
});
|
108
|
+
}
|
109
|
+
|
110
|
+
export { experimental_toORPCRouter };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/trpc",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.6.
|
4
|
+
"version": "1.6.8",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -28,9 +28,9 @@
|
|
28
28
|
"@trpc/server": ">=11.4.2"
|
29
29
|
},
|
30
30
|
"dependencies": {
|
31
|
-
"@orpc/client": "1.6.
|
32
|
-
"@orpc/server": "1.6.
|
33
|
-
"@orpc/shared": "1.6.
|
31
|
+
"@orpc/client": "1.6.8",
|
32
|
+
"@orpc/server": "1.6.8",
|
33
|
+
"@orpc/shared": "1.6.8"
|
34
34
|
},
|
35
35
|
"devDependencies": {
|
36
36
|
"@trpc/server": "^11.4.3",
|