@trpc/server 11.0.0-alpha-tmp-export-from-main.218 → 11.0.0-alpha-tmp-export-from-main-nuke-core.239
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/@trpc/server/http.d.ts +7 -0
- package/dist/@trpc/server/http.d.ts.map +1 -0
- package/dist/@trpc/server/index.d.ts +69 -0
- package/dist/@trpc/server/index.d.ts.map +1 -0
- package/dist/@trpc/server/rpc.d.ts +3 -0
- package/dist/@trpc/server/rpc.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.d.ts +1 -2
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +6 -4
- package/dist/adapters/aws-lambda/index.mjs +4 -2
- package/dist/adapters/aws-lambda/utils.d.ts +2 -3
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +5 -4
- package/dist/adapters/aws-lambda/utils.mjs +3 -2
- package/dist/adapters/express.d.ts +1 -2
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +6 -3
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +4 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +6 -4
- package/dist/adapters/fetch/fetchRequestHandler.mjs +4 -2
- package/dist/adapters/fetch/types.d.ts +2 -3
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.d.ts +1 -3
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +6 -4
- package/dist/adapters/next.mjs +4 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +4 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +3 -1
- package/dist/adapters/node-http/content-type/json/index.js +4 -2
- package/dist/adapters/node-http/content-type/json/index.mjs +3 -1
- package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +6 -4
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +4 -2
- package/dist/adapters/node-http/types.d.ts +3 -4
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +1 -0
- package/dist/adapters/standalone.mjs +1 -0
- package/dist/adapters/ws.d.ts +3 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +33 -26
- package/dist/adapters/ws.mjs +8 -1
- package/dist/bundle-analysis.json +757 -0
- package/dist/http.d.ts +1 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +11 -21
- package/dist/http.mjs +6 -1
- package/dist/index.d.ts +1 -68
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -41
- package/dist/index.mjs +8 -1
- package/dist/observable/index.d.ts +5 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/dist/observable/index.js +13 -0
- package/dist/observable/index.mjs +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/observable/observable.js +126 -0
- package/dist/observable/observable.mjs +122 -0
- package/dist/observable/operators.d.ts +8 -0
- package/dist/observable/operators.d.ts.map +1 -0
- package/dist/observable/operators.js +103 -0
- package/dist/observable/operators.mjs +99 -0
- package/dist/observable/types.d.ts +26 -0
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/rpc.d.ts +1 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +6 -13
- package/dist/rpc.mjs +3 -1
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +6 -9
- package/dist/shared.mjs +4 -1
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +6 -0
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts +19 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.js +52 -0
- package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +13 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.js +67 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +63 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +33 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/formatter.js +7 -0
- package/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +31 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +24 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +32 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +30 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +29 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentType.js +54 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +52 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +51 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +48 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts +7 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +51 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +295 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +293 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts +96 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.d.ts +37 -0
- package/dist/unstable-core-do-not-import/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.js +48 -0
- package/dist/unstable-core-do-not-import/index.mjs +16 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +96 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/initTRPC.js +95 -0
- package/dist/unstable-core-do-not-import/initTRPC.mjs +93 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts +105 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/middleware.js +95 -0
- package/dist/unstable-core-do-not-import/middleware.mjs +89 -0
- package/dist/unstable-core-do-not-import/parser.d.ts +30 -0
- package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/parser.js +37 -0
- package/dist/unstable-core-do-not-import/parser.mjs +35 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts +72 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedure.js +9 -0
- package/dist/unstable-core-do-not-import/procedure.mjs +7 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +101 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.js +176 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +173 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +75 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rootConfig.js +8 -0
- package/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
- package/dist/unstable-core-do-not-import/router.d.ts +85 -0
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/router.js +156 -0
- package/dist/unstable-core-do-not-import/router.mjs +151 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +51 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/codes.js +38 -0
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +35 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +97 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +59 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +57 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts +62 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +107 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.js +107 -0
- package/dist/unstable-core-do-not-import/transformer.mjs +102 -0
- package/dist/unstable-core-do-not-import/types.d.ts +98 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.d.ts +27 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.js +44 -0
- package/dist/unstable-core-do-not-import/utils.mjs +39 -0
- package/package.json +53 -125
- package/src/@trpc/server/http.ts +26 -0
- package/src/@trpc/server/index.ts +105 -0
- package/src/@trpc/server/rpc.ts +26 -0
- package/src/adapters/aws-lambda/index.ts +4 -5
- package/src/adapters/aws-lambda/utils.ts +3 -4
- package/src/adapters/express.ts +1 -3
- package/src/adapters/fastify/fastifyRequestHandler.ts +6 -4
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -2
- package/src/adapters/fetch/fetchRequestHandler.ts +6 -4
- package/src/adapters/fetch/types.ts +2 -3
- package/src/adapters/next.ts +2 -4
- package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
- package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
- package/src/adapters/node-http/content-type/json/index.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +6 -4
- package/src/adapters/node-http/types.ts +4 -5
- package/src/adapters/standalone.ts +2 -2
- package/src/adapters/ws.ts +14 -13
- package/src/http.ts +1 -26
- package/src/index.ts +1 -105
- package/src/observable/index.ts +10 -0
- package/src/observable/observable.ts +158 -0
- package/src/observable/operators.ts +119 -0
- package/src/observable/types.ts +76 -0
- package/src/rpc.ts +1 -26
- package/src/shared.ts +1 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +9 -0
- package/src/unstable-core-do-not-import/createProxy.ts +59 -0
- package/src/unstable-core-do-not-import/error/TRPCError.ts +82 -0
- package/src/unstable-core-do-not-import/error/formatter.ts +51 -0
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +36 -0
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +29 -0
- package/src/unstable-core-do-not-import/http/contentType.ts +99 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +57 -0
- package/src/unstable-core-do-not-import/http/index.ts +23 -0
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +458 -0
- package/src/unstable-core-do-not-import/http/types.ts +111 -0
- package/src/unstable-core-do-not-import/index.ts +110 -0
- package/src/unstable-core-do-not-import/initTRPC.ts +206 -0
- package/src/unstable-core-do-not-import/middleware.ts +233 -0
- package/src/unstable-core-do-not-import/parser.ts +94 -0
- package/src/unstable-core-do-not-import/procedure.ts +108 -0
- package/src/unstable-core-do-not-import/procedureBuilder.ts +458 -0
- package/src/unstable-core-do-not-import/rootConfig.ts +90 -0
- package/src/unstable-core-do-not-import/router.ts +370 -0
- package/src/unstable-core-do-not-import/rpc/codes.ts +44 -0
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +136 -0
- package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +85 -0
- package/src/unstable-core-do-not-import/serialize.ts +122 -0
- package/src/unstable-core-do-not-import/transformer.ts +202 -0
- package/src/unstable-core-do-not-import/types.ts +151 -0
- package/src/unstable-core-do-not-import/utils.ts +59 -0
- package/unstable-core-do-not-import/index.d.ts +1 -0
- package/unstable-core-do-not-import/index.js +1 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +0 -10
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +0 -1
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/observable.d.ts +0 -3
- package/dist/observable.d.ts.map +0 -1
- package/dist/observable.js +0 -30
- package/dist/observable.mjs +0 -1
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -146
- package/src/@trpc-server/http.ts +0 -2
- package/src/observable.ts +0 -16
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { TRPCError, getTRPCErrorFromUnknown } from './error/TRPCError.mjs';
|
|
2
|
+
import { createInputMiddleware, createOutputMiddleware, middlewareMarker } from './middleware.mjs';
|
|
3
|
+
import { getParseFn } from './parser.mjs';
|
|
4
|
+
import { mergeWithoutOverrides } from './utils.mjs';
|
|
5
|
+
|
|
6
|
+
/** @internal */ const unsetMarker = Symbol('unsetMarker');
|
|
7
|
+
function createNewBuilder(def1, def2) {
|
|
8
|
+
const { middlewares =[] , inputs , meta , ...rest } = def2;
|
|
9
|
+
// TODO: maybe have a fn here to warn about calls
|
|
10
|
+
return createBuilder({
|
|
11
|
+
...mergeWithoutOverrides(def1, rest),
|
|
12
|
+
inputs: [
|
|
13
|
+
...def1.inputs,
|
|
14
|
+
...inputs ?? []
|
|
15
|
+
],
|
|
16
|
+
middlewares: [
|
|
17
|
+
...def1.middlewares,
|
|
18
|
+
...middlewares
|
|
19
|
+
],
|
|
20
|
+
meta: def1.meta && meta ? {
|
|
21
|
+
...def1.meta,
|
|
22
|
+
...meta
|
|
23
|
+
} : meta ?? def1.meta
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function createBuilder(initDef = {}) {
|
|
27
|
+
const _def = {
|
|
28
|
+
procedure: true,
|
|
29
|
+
inputs: [],
|
|
30
|
+
middlewares: [],
|
|
31
|
+
...initDef
|
|
32
|
+
};
|
|
33
|
+
const builder = {
|
|
34
|
+
_def,
|
|
35
|
+
input (input) {
|
|
36
|
+
const parser = getParseFn(input);
|
|
37
|
+
return createNewBuilder(_def, {
|
|
38
|
+
inputs: [
|
|
39
|
+
input
|
|
40
|
+
],
|
|
41
|
+
middlewares: [
|
|
42
|
+
createInputMiddleware(parser)
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
output (output) {
|
|
47
|
+
const parser = getParseFn(output);
|
|
48
|
+
return createNewBuilder(_def, {
|
|
49
|
+
output,
|
|
50
|
+
middlewares: [
|
|
51
|
+
createOutputMiddleware(parser)
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
meta (meta) {
|
|
56
|
+
return createNewBuilder(_def, {
|
|
57
|
+
meta
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
use (middlewareBuilderOrFn) {
|
|
61
|
+
// Distinguish between a middleware builder and a middleware function
|
|
62
|
+
const middlewares = '_middlewares' in middlewareBuilderOrFn ? middlewareBuilderOrFn._middlewares : [
|
|
63
|
+
middlewareBuilderOrFn
|
|
64
|
+
];
|
|
65
|
+
return createNewBuilder(_def, {
|
|
66
|
+
middlewares: middlewares
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
query (resolver) {
|
|
70
|
+
return createResolver({
|
|
71
|
+
..._def,
|
|
72
|
+
type: 'query'
|
|
73
|
+
}, resolver);
|
|
74
|
+
},
|
|
75
|
+
mutation (resolver) {
|
|
76
|
+
return createResolver({
|
|
77
|
+
..._def,
|
|
78
|
+
type: 'mutation'
|
|
79
|
+
}, resolver);
|
|
80
|
+
},
|
|
81
|
+
subscription (resolver) {
|
|
82
|
+
return createResolver({
|
|
83
|
+
..._def,
|
|
84
|
+
type: 'subscription'
|
|
85
|
+
}, resolver);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return builder;
|
|
89
|
+
}
|
|
90
|
+
function createResolver(_def, resolver) {
|
|
91
|
+
const finalBuilder = createNewBuilder(_def, {
|
|
92
|
+
resolver,
|
|
93
|
+
middlewares: [
|
|
94
|
+
async function resolveMiddleware(opts) {
|
|
95
|
+
const data = await resolver(opts);
|
|
96
|
+
return {
|
|
97
|
+
marker: middlewareMarker,
|
|
98
|
+
ok: true,
|
|
99
|
+
data,
|
|
100
|
+
ctx: opts.ctx
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
});
|
|
105
|
+
return createProcedureCaller(finalBuilder._def);
|
|
106
|
+
}
|
|
107
|
+
const codeblock = `
|
|
108
|
+
This is a client-only function.
|
|
109
|
+
If you want to call this function on the server, see https://trpc.io/docs/v11/server/server-side-calls
|
|
110
|
+
`.trim();
|
|
111
|
+
function createProcedureCaller(_def) {
|
|
112
|
+
async function procedure(opts) {
|
|
113
|
+
// is direct server-side call
|
|
114
|
+
if (!opts || !('getRawInput' in opts)) {
|
|
115
|
+
throw new Error(codeblock);
|
|
116
|
+
}
|
|
117
|
+
// run the middlewares recursively with the resolver as the last one
|
|
118
|
+
async function callRecursive(callOpts = {
|
|
119
|
+
index: 0,
|
|
120
|
+
ctx: opts.ctx
|
|
121
|
+
}) {
|
|
122
|
+
try {
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
124
|
+
const middleware = _def.middlewares[callOpts.index];
|
|
125
|
+
const result = await middleware({
|
|
126
|
+
ctx: callOpts.ctx,
|
|
127
|
+
type: opts.type,
|
|
128
|
+
path: opts.path,
|
|
129
|
+
getRawInput: callOpts.getRawInput ?? opts.getRawInput,
|
|
130
|
+
meta: _def.meta,
|
|
131
|
+
input: callOpts.input,
|
|
132
|
+
next (_nextOpts) {
|
|
133
|
+
const nextOpts = _nextOpts;
|
|
134
|
+
return callRecursive({
|
|
135
|
+
index: callOpts.index + 1,
|
|
136
|
+
ctx: nextOpts && 'ctx' in nextOpts ? {
|
|
137
|
+
...callOpts.ctx,
|
|
138
|
+
...nextOpts.ctx
|
|
139
|
+
} : callOpts.ctx,
|
|
140
|
+
input: nextOpts && 'input' in nextOpts ? nextOpts.input : callOpts.input,
|
|
141
|
+
getRawInput: nextOpts && 'getRawInput' in nextOpts ? nextOpts.getRawInput : callOpts.getRawInput
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return result;
|
|
146
|
+
} catch (cause) {
|
|
147
|
+
return {
|
|
148
|
+
ok: false,
|
|
149
|
+
error: getTRPCErrorFromUnknown(cause),
|
|
150
|
+
marker: middlewareMarker
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// there's always at least one "next" since we wrap this.resolver in a middleware
|
|
155
|
+
const result = await callRecursive();
|
|
156
|
+
if (!result) {
|
|
157
|
+
throw new TRPCError({
|
|
158
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
159
|
+
message: 'No result from middlewares - did you forget to `return next()`?'
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (!result.ok) {
|
|
163
|
+
// re-throw original error
|
|
164
|
+
throw result.error;
|
|
165
|
+
}
|
|
166
|
+
return result.data;
|
|
167
|
+
}
|
|
168
|
+
procedure._def = _def;
|
|
169
|
+
// FIXME typecast shouldn't be needed - fixittt
|
|
170
|
+
return procedure;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export { createBuilder, unsetMarker };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ErrorFormatter } from './error/formatter';
|
|
2
|
+
import type { TRPCErrorShape } from './rpc';
|
|
3
|
+
/**
|
|
4
|
+
* The initial generics that are used in the init function
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface RootConfigTypes {
|
|
8
|
+
ctx: object;
|
|
9
|
+
meta: object;
|
|
10
|
+
errorShape: unknown;
|
|
11
|
+
transformer: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The default check to see if we're in a server
|
|
15
|
+
*/
|
|
16
|
+
export declare const isServerDefault: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The runtime config that are used and actually represents real values underneath
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export interface RuntimeConfig<TTypes extends RootConfigTypes> {
|
|
22
|
+
/**
|
|
23
|
+
* Use a data transformer
|
|
24
|
+
* @link https://trpc.io/docs/v11/data-transformers
|
|
25
|
+
*/
|
|
26
|
+
transformer: TTypes['transformer'];
|
|
27
|
+
/**
|
|
28
|
+
* Use custom error formatting
|
|
29
|
+
* @link https://trpc.io/docs/v11/error-formatting
|
|
30
|
+
*/
|
|
31
|
+
errorFormatter: ErrorFormatter<TTypes['ctx'], TRPCErrorShape<number> & {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Allow `@trpc/server` to run in non-server environments
|
|
36
|
+
* @warning **Use with caution**, this should likely mainly be used within testing.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
allowOutsideOfServer: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Is this a server environment?
|
|
42
|
+
* @warning **Use with caution**, this should likely mainly be used within testing.
|
|
43
|
+
* @default typeof window === 'undefined' || 'Deno' in window || process.env.NODE_ENV === 'test'
|
|
44
|
+
*/
|
|
45
|
+
isServer: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Is this development?
|
|
48
|
+
* Will be used to decide if the API should return stack traces
|
|
49
|
+
* @default process.env.NODE_ENV !== 'production'
|
|
50
|
+
*/
|
|
51
|
+
isDev: boolean;
|
|
52
|
+
defaultMeta?: TTypes['meta'] extends object ? TTypes['meta'] : never;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export type CreateRootConfigTypes<TGenerics extends RootConfigTypes> = TGenerics;
|
|
58
|
+
/**
|
|
59
|
+
* The config that is resolved after `initTRPC.create()` has been called
|
|
60
|
+
* Combination of `InitTOptions` + `InitGenerics`
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export interface RootConfig<TGenerics extends RootConfigTypes> extends RuntimeConfig<TGenerics> {
|
|
64
|
+
$types: TGenerics;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export type AnyRootConfig = RootConfig<{
|
|
70
|
+
ctx: any;
|
|
71
|
+
meta: any;
|
|
72
|
+
errorShape: any;
|
|
73
|
+
transformer: any;
|
|
74
|
+
}>;
|
|
75
|
+
//# sourceMappingURL=rootConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rootConfig.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/rootConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,OAMmB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,SAAS,eAAe;IAC3D;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACnC;;;OAGG;IACH,cAAc,EAAE,cAAc,CAC5B,MAAM,CAAC,KAAK,CAAC,EACb,cAAc,CAAC,MAAM,CAAC,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAChD,CAAC;IACF;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;CACtE;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,SAAS,SAAS,eAAe,IACjE,SAAS,CAAC;AAEZ;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,SAAS,SAAS,eAAe,CAC3D,SAAQ,aAAa,CAAC,SAAS,CAAC;IAChC,MAAM,EAAE,SAAS,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC;IACrC,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,GAAG,CAAC;IACV,UAAU,EAAE,GAAG,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The default check to see if we're in a server
|
|
5
|
+
*/ const isServerDefault = typeof window === 'undefined' || 'Deno' in window || // eslint-disable-next-line @typescript-eslint/dot-notation
|
|
6
|
+
globalThis.process?.env?.['NODE_ENV'] === 'test' || !!globalThis.process?.env?.['JEST_WORKER_ID'] || !!globalThis.process?.env?.['VITEST_WORKER_ID'];
|
|
7
|
+
|
|
8
|
+
exports.isServerDefault = isServerDefault;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default check to see if we're in a server
|
|
3
|
+
*/ const isServerDefault = typeof window === 'undefined' || 'Deno' in window || // eslint-disable-next-line @typescript-eslint/dot-notation
|
|
4
|
+
globalThis.process?.env?.['NODE_ENV'] === 'test' || !!globalThis.process?.env?.['JEST_WORKER_ID'] || !!globalThis.process?.env?.['VITEST_WORKER_ID'];
|
|
5
|
+
|
|
6
|
+
export { isServerDefault };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { AnyProcedure, inferProcedureInput, inferTransformedProcedureOutput, ProcedureArgs } from './procedure';
|
|
2
|
+
import type { ProcedureCallOptions } from './procedureBuilder';
|
|
3
|
+
import type { AnyRootConfig } from './rootConfig';
|
|
4
|
+
import type { MaybePromise } from './types';
|
|
5
|
+
/** @internal **/
|
|
6
|
+
export type ProcedureRecord = Record<string, AnyProcedure>;
|
|
7
|
+
export interface ProcedureRouterRecord {
|
|
8
|
+
[key: string]: AnyProcedure | AnyRouter;
|
|
9
|
+
}
|
|
10
|
+
export interface RouterDef<TConfig extends AnyRootConfig, TRecord extends ProcedureRouterRecord> {
|
|
11
|
+
_config: TConfig;
|
|
12
|
+
router: true;
|
|
13
|
+
procedure?: never;
|
|
14
|
+
procedures: TRecord;
|
|
15
|
+
record: TRecord;
|
|
16
|
+
}
|
|
17
|
+
export type AnyRouterDef<TConfig extends AnyRootConfig = AnyRootConfig> = RouterDef<TConfig, any>;
|
|
18
|
+
type DecorateProcedure<TProcedure extends AnyProcedure> = (input: ProcedureArgs<TProcedure['_def']>[0]) => Promise<TProcedure['_def']['_output_out']>;
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
23
|
+
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']> : TProcedures[TKey] extends AnyProcedure ? DecorateProcedure<TProcedures[TKey]> : never;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export type RouterCaller<TDef extends AnyRouterDef> = (
|
|
29
|
+
/**
|
|
30
|
+
* @note
|
|
31
|
+
* If passing a function, we recommend it's a cached function
|
|
32
|
+
* e.g. wrapped in `React.cache` to avoid unnecessary computations
|
|
33
|
+
*/
|
|
34
|
+
ctx: TDef['_config']['$types']['ctx'] | (() => MaybePromise<TDef['_config']['$types']['ctx']>)) => DecoratedProcedureRecord<TDef['record']>;
|
|
35
|
+
export interface Router<TDef extends AnyRouterDef> {
|
|
36
|
+
_def: TDef;
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated use `t.createCallerFactory(router)` instead
|
|
39
|
+
* @link https://trpc.io/docs/v11/server/server-side-calls
|
|
40
|
+
*/
|
|
41
|
+
createCaller: RouterCaller<TDef>;
|
|
42
|
+
}
|
|
43
|
+
export type AnyRouter = Router<AnyRouterDef>;
|
|
44
|
+
type inferRouterDef<TRouter extends AnyRouter> = TRouter extends Router<infer TParams> ? TParams extends AnyRouterDef<any> ? TParams : never : never;
|
|
45
|
+
type inferRouterConfig<TRouter extends AnyRouter> = inferRouterDef<TRouter>['_config'];
|
|
46
|
+
export type inferRouterContext<TRouter extends AnyRouter> = inferRouterConfig<TRouter>['$types']['ctx'];
|
|
47
|
+
export type inferRouterError<TRouter extends AnyRouter> = inferRouterConfig<TRouter>['$types']['errorShape'];
|
|
48
|
+
export type inferRouterMeta<TRouter extends AnyRouter> = inferRouterConfig<TRouter>['$types']['meta'];
|
|
49
|
+
type GetInferenceHelpers<TType extends 'input' | 'output', TRouter extends AnyRouter> = {
|
|
50
|
+
[TKey in keyof TRouter['_def']['record']]: TRouter['_def']['record'][TKey] extends infer TRouterOrProcedure ? TRouterOrProcedure extends AnyRouter ? GetInferenceHelpers<TType, TRouterOrProcedure> : TRouterOrProcedure extends AnyProcedure ? TType extends 'input' ? inferProcedureInput<TRouterOrProcedure> : inferTransformedProcedureOutput<TRouter['_def']['_config'], TRouterOrProcedure> : never : never;
|
|
51
|
+
};
|
|
52
|
+
export type inferRouterInputs<TRouter extends AnyRouter> = GetInferenceHelpers<'input', TRouter>;
|
|
53
|
+
export type inferRouterOutputs<TRouter extends AnyRouter> = GetInferenceHelpers<'output', TRouter>;
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export type CreateRouterInner<TConfig extends AnyRootConfig, TProcRouterRecord extends ProcedureRouterRecord> = Router<RouterDef<TConfig, TProcRouterRecord>> &
|
|
58
|
+
/**
|
|
59
|
+
* This adds ability to call procedures directly but is primarily used for quick access in type inference
|
|
60
|
+
*/
|
|
61
|
+
TProcRouterRecord;
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export declare function createRouterFactory<TConfig extends AnyRootConfig>(config: TConfig): <TProcRouterRecord extends ProcedureRouterRecord>(procedures: TProcRouterRecord) => CreateRouterInner<TConfig, TProcRouterRecord>;
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export declare function callProcedure(opts: ProcedureCallOptions & {
|
|
70
|
+
procedures: ProcedureRouterRecord;
|
|
71
|
+
}): Promise<unknown>;
|
|
72
|
+
export declare function createCallerFactory<TConfig extends AnyRootConfig>(): <TRouter extends Router<AnyRouterDef<TConfig>>>(router: TRouter) => RouterCaller<TRouter["_def"]>;
|
|
73
|
+
/** @internal */
|
|
74
|
+
type MergeRouters<TRouters extends AnyRouter[], TRouterDef extends AnyRouterDef = RouterDef<TRouters[0]['_def']['_config'], {}>> = TRouters extends [
|
|
75
|
+
infer Head extends AnyRouter,
|
|
76
|
+
...infer Tail extends AnyRouter[]
|
|
77
|
+
] ? MergeRouters<Tail, {
|
|
78
|
+
_config: TRouterDef['_config'];
|
|
79
|
+
router: true;
|
|
80
|
+
procedures: Head['_def']['procedures'] & TRouterDef['procedures'];
|
|
81
|
+
record: Head['_def']['record'] & TRouterDef['record'];
|
|
82
|
+
}> : Router<TRouterDef> & TRouterDef['record'];
|
|
83
|
+
export declare function mergeRouters<TRouters extends AnyRouter[]>(...routerList: [...TRouters]): MergeRouters<TRouters>;
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/router.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,+BAA+B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,UAAU,SAAS,YAAY,GAAG,SAAS,CACzC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAE9B,EAAE,CACH,IACC,QAAQ,SAAS;IACnB,MAAM,IAAI,SAAS,SAAS;IAC5B,GAAG,MAAM,IAAI,SAAS,SAAS,EAAE;CAClC,GACG,YAAY,CACV,IAAI,EACJ;IACE,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IAC/B,MAAM,EAAE,IAAI,CAAC;IACb,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAClE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;CACvD,CACF,GACD,MAAM,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AAE9C,wBAAgB,YAAY,CAAC,QAAQ,SAAS,SAAS,EAAE,EACvD,GAAG,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,GAC3B,YAAY,CAAC,QAAQ,CAAC,CAmDxB"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var createProxy = require('./createProxy.js');
|
|
4
|
+
var formatter = require('./error/formatter.js');
|
|
5
|
+
var TRPCError = require('./error/TRPCError.js');
|
|
6
|
+
var transformer = require('./transformer.js');
|
|
7
|
+
var utils = require('./utils.js');
|
|
8
|
+
|
|
9
|
+
function isRouter(procedureOrRouter) {
|
|
10
|
+
return 'router' in procedureOrRouter._def;
|
|
11
|
+
}
|
|
12
|
+
const emptyRouter = {
|
|
13
|
+
_ctx: null,
|
|
14
|
+
_errorShape: null,
|
|
15
|
+
_meta: null,
|
|
16
|
+
queries: {},
|
|
17
|
+
mutations: {},
|
|
18
|
+
subscriptions: {},
|
|
19
|
+
errorFormatter: formatter.defaultFormatter,
|
|
20
|
+
transformer: transformer.defaultTransformer
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Reserved words that can't be used as router or procedure names
|
|
24
|
+
*/ const reservedWords = [
|
|
25
|
+
/**
|
|
26
|
+
* Then is a reserved word because otherwise we can't return a promise that returns a Proxy
|
|
27
|
+
* since JS will think that `.then` is something that exists
|
|
28
|
+
*/ 'then'
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/ function createRouterFactory(config) {
|
|
33
|
+
return function createRouterInner(procedures) {
|
|
34
|
+
const reservedWordsUsed = new Set(Object.keys(procedures).filter((v)=>reservedWords.includes(v)));
|
|
35
|
+
if (reservedWordsUsed.size > 0) {
|
|
36
|
+
throw new Error('Reserved words used in `router({})` call: ' + Array.from(reservedWordsUsed).join(', '));
|
|
37
|
+
}
|
|
38
|
+
const routerProcedures = utils.omitPrototype({});
|
|
39
|
+
function recursiveGetPaths(procedures, path = '') {
|
|
40
|
+
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})){
|
|
41
|
+
const newPath = `${path}${key}`;
|
|
42
|
+
if (isRouter(procedureOrRouter)) {
|
|
43
|
+
recursiveGetPaths(procedureOrRouter._def.procedures, `${newPath}.`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (routerProcedures[newPath]) {
|
|
47
|
+
throw new Error(`Duplicate key: ${newPath}`);
|
|
48
|
+
}
|
|
49
|
+
routerProcedures[newPath] = procedureOrRouter;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
recursiveGetPaths(procedures);
|
|
53
|
+
const _def = {
|
|
54
|
+
_config: config,
|
|
55
|
+
router: true,
|
|
56
|
+
procedures: routerProcedures,
|
|
57
|
+
...emptyRouter,
|
|
58
|
+
record: procedures
|
|
59
|
+
};
|
|
60
|
+
const router = {
|
|
61
|
+
...procedures,
|
|
62
|
+
_def,
|
|
63
|
+
createCaller (ctx) {
|
|
64
|
+
const proxy = createProxy.createRecursiveProxy(({ path , args })=>{
|
|
65
|
+
const fullPath = path.join('.');
|
|
66
|
+
const procedure = _def.procedures[fullPath];
|
|
67
|
+
return procedure({
|
|
68
|
+
path: fullPath,
|
|
69
|
+
getRawInput: async ()=>args[0],
|
|
70
|
+
ctx,
|
|
71
|
+
type: procedure._def.type
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return proxy;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return router;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function isProcedure(procedureOrRouter) {
|
|
81
|
+
return !!procedureOrRouter._def.procedure;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/ function callProcedure(opts) {
|
|
86
|
+
const { type , path } = opts;
|
|
87
|
+
const proc = opts.procedures[path];
|
|
88
|
+
if (!proc || !isProcedure(proc) || proc._def.type !== type) {
|
|
89
|
+
throw new TRPCError.TRPCError({
|
|
90
|
+
code: 'NOT_FOUND',
|
|
91
|
+
message: `No "${type}"-procedure on path "${path}"`
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return proc(opts);
|
|
95
|
+
}
|
|
96
|
+
function createCallerFactory() {
|
|
97
|
+
return function createCallerInner(router) {
|
|
98
|
+
const _def = router._def;
|
|
99
|
+
return function createCaller(maybeContext) {
|
|
100
|
+
const proxy = createProxy.createRecursiveProxy(({ path , args })=>{
|
|
101
|
+
const fullPath = path.join('.');
|
|
102
|
+
const procedure = _def.procedures[fullPath];
|
|
103
|
+
const callProc = (ctx)=>procedure({
|
|
104
|
+
path: fullPath,
|
|
105
|
+
getRawInput: async ()=>args[0],
|
|
106
|
+
ctx,
|
|
107
|
+
type: procedure._def.type
|
|
108
|
+
});
|
|
109
|
+
if (typeof maybeContext === 'function') {
|
|
110
|
+
const context = maybeContext();
|
|
111
|
+
if (context instanceof Promise) {
|
|
112
|
+
return context.then(callProc);
|
|
113
|
+
}
|
|
114
|
+
return callProc(context);
|
|
115
|
+
}
|
|
116
|
+
return callProc(maybeContext);
|
|
117
|
+
});
|
|
118
|
+
return proxy;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function mergeRouters(...routerList) {
|
|
123
|
+
const record = utils.mergeWithoutOverrides({}, ...routerList.map((r)=>r._def.record));
|
|
124
|
+
const errorFormatter = routerList.reduce((currentErrorFormatter, nextRouter)=>{
|
|
125
|
+
if (nextRouter._def._config.errorFormatter && nextRouter._def._config.errorFormatter !== formatter.defaultFormatter) {
|
|
126
|
+
if (currentErrorFormatter !== formatter.defaultFormatter && currentErrorFormatter !== nextRouter._def._config.errorFormatter) {
|
|
127
|
+
throw new Error('You seem to have several error formatters');
|
|
128
|
+
}
|
|
129
|
+
return nextRouter._def._config.errorFormatter;
|
|
130
|
+
}
|
|
131
|
+
return currentErrorFormatter;
|
|
132
|
+
}, formatter.defaultFormatter);
|
|
133
|
+
const transformer$1 = routerList.reduce((prev, current)=>{
|
|
134
|
+
if (current._def._config.transformer && current._def._config.transformer !== transformer.defaultTransformer) {
|
|
135
|
+
if (prev !== transformer.defaultTransformer && prev !== current._def._config.transformer) {
|
|
136
|
+
throw new Error('You seem to have several transformers');
|
|
137
|
+
}
|
|
138
|
+
return current._def._config.transformer;
|
|
139
|
+
}
|
|
140
|
+
return prev;
|
|
141
|
+
}, transformer.defaultTransformer);
|
|
142
|
+
const router = createRouterFactory({
|
|
143
|
+
errorFormatter,
|
|
144
|
+
transformer: transformer$1,
|
|
145
|
+
isDev: routerList.some((r)=>r._def._config.isDev),
|
|
146
|
+
allowOutsideOfServer: routerList.some((r)=>r._def._config.allowOutsideOfServer),
|
|
147
|
+
isServer: routerList.some((r)=>r._def._config.isServer),
|
|
148
|
+
$types: routerList[0]?._def._config.$types
|
|
149
|
+
})(record);
|
|
150
|
+
return router;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
exports.callProcedure = callProcedure;
|
|
154
|
+
exports.createCallerFactory = createCallerFactory;
|
|
155
|
+
exports.createRouterFactory = createRouterFactory;
|
|
156
|
+
exports.mergeRouters = mergeRouters;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { createRecursiveProxy } from './createProxy.mjs';
|
|
2
|
+
import { defaultFormatter } from './error/formatter.mjs';
|
|
3
|
+
import { TRPCError } from './error/TRPCError.mjs';
|
|
4
|
+
import { defaultTransformer } from './transformer.mjs';
|
|
5
|
+
import { mergeWithoutOverrides, omitPrototype } from './utils.mjs';
|
|
6
|
+
|
|
7
|
+
function isRouter(procedureOrRouter) {
|
|
8
|
+
return 'router' in procedureOrRouter._def;
|
|
9
|
+
}
|
|
10
|
+
const emptyRouter = {
|
|
11
|
+
_ctx: null,
|
|
12
|
+
_errorShape: null,
|
|
13
|
+
_meta: null,
|
|
14
|
+
queries: {},
|
|
15
|
+
mutations: {},
|
|
16
|
+
subscriptions: {},
|
|
17
|
+
errorFormatter: defaultFormatter,
|
|
18
|
+
transformer: defaultTransformer
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Reserved words that can't be used as router or procedure names
|
|
22
|
+
*/ const reservedWords = [
|
|
23
|
+
/**
|
|
24
|
+
* Then is a reserved word because otherwise we can't return a promise that returns a Proxy
|
|
25
|
+
* since JS will think that `.then` is something that exists
|
|
26
|
+
*/ 'then'
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/ function createRouterFactory(config) {
|
|
31
|
+
return function createRouterInner(procedures) {
|
|
32
|
+
const reservedWordsUsed = new Set(Object.keys(procedures).filter((v)=>reservedWords.includes(v)));
|
|
33
|
+
if (reservedWordsUsed.size > 0) {
|
|
34
|
+
throw new Error('Reserved words used in `router({})` call: ' + Array.from(reservedWordsUsed).join(', '));
|
|
35
|
+
}
|
|
36
|
+
const routerProcedures = omitPrototype({});
|
|
37
|
+
function recursiveGetPaths(procedures, path = '') {
|
|
38
|
+
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})){
|
|
39
|
+
const newPath = `${path}${key}`;
|
|
40
|
+
if (isRouter(procedureOrRouter)) {
|
|
41
|
+
recursiveGetPaths(procedureOrRouter._def.procedures, `${newPath}.`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (routerProcedures[newPath]) {
|
|
45
|
+
throw new Error(`Duplicate key: ${newPath}`);
|
|
46
|
+
}
|
|
47
|
+
routerProcedures[newPath] = procedureOrRouter;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
recursiveGetPaths(procedures);
|
|
51
|
+
const _def = {
|
|
52
|
+
_config: config,
|
|
53
|
+
router: true,
|
|
54
|
+
procedures: routerProcedures,
|
|
55
|
+
...emptyRouter,
|
|
56
|
+
record: procedures
|
|
57
|
+
};
|
|
58
|
+
const router = {
|
|
59
|
+
...procedures,
|
|
60
|
+
_def,
|
|
61
|
+
createCaller (ctx) {
|
|
62
|
+
const proxy = createRecursiveProxy(({ path , args })=>{
|
|
63
|
+
const fullPath = path.join('.');
|
|
64
|
+
const procedure = _def.procedures[fullPath];
|
|
65
|
+
return procedure({
|
|
66
|
+
path: fullPath,
|
|
67
|
+
getRawInput: async ()=>args[0],
|
|
68
|
+
ctx,
|
|
69
|
+
type: procedure._def.type
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
return proxy;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return router;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function isProcedure(procedureOrRouter) {
|
|
79
|
+
return !!procedureOrRouter._def.procedure;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @internal
|
|
83
|
+
*/ function callProcedure(opts) {
|
|
84
|
+
const { type , path } = opts;
|
|
85
|
+
const proc = opts.procedures[path];
|
|
86
|
+
if (!proc || !isProcedure(proc) || proc._def.type !== type) {
|
|
87
|
+
throw new TRPCError({
|
|
88
|
+
code: 'NOT_FOUND',
|
|
89
|
+
message: `No "${type}"-procedure on path "${path}"`
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return proc(opts);
|
|
93
|
+
}
|
|
94
|
+
function createCallerFactory() {
|
|
95
|
+
return function createCallerInner(router) {
|
|
96
|
+
const _def = router._def;
|
|
97
|
+
return function createCaller(maybeContext) {
|
|
98
|
+
const proxy = createRecursiveProxy(({ path , args })=>{
|
|
99
|
+
const fullPath = path.join('.');
|
|
100
|
+
const procedure = _def.procedures[fullPath];
|
|
101
|
+
const callProc = (ctx)=>procedure({
|
|
102
|
+
path: fullPath,
|
|
103
|
+
getRawInput: async ()=>args[0],
|
|
104
|
+
ctx,
|
|
105
|
+
type: procedure._def.type
|
|
106
|
+
});
|
|
107
|
+
if (typeof maybeContext === 'function') {
|
|
108
|
+
const context = maybeContext();
|
|
109
|
+
if (context instanceof Promise) {
|
|
110
|
+
return context.then(callProc);
|
|
111
|
+
}
|
|
112
|
+
return callProc(context);
|
|
113
|
+
}
|
|
114
|
+
return callProc(maybeContext);
|
|
115
|
+
});
|
|
116
|
+
return proxy;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function mergeRouters(...routerList) {
|
|
121
|
+
const record = mergeWithoutOverrides({}, ...routerList.map((r)=>r._def.record));
|
|
122
|
+
const errorFormatter = routerList.reduce((currentErrorFormatter, nextRouter)=>{
|
|
123
|
+
if (nextRouter._def._config.errorFormatter && nextRouter._def._config.errorFormatter !== defaultFormatter) {
|
|
124
|
+
if (currentErrorFormatter !== defaultFormatter && currentErrorFormatter !== nextRouter._def._config.errorFormatter) {
|
|
125
|
+
throw new Error('You seem to have several error formatters');
|
|
126
|
+
}
|
|
127
|
+
return nextRouter._def._config.errorFormatter;
|
|
128
|
+
}
|
|
129
|
+
return currentErrorFormatter;
|
|
130
|
+
}, defaultFormatter);
|
|
131
|
+
const transformer = routerList.reduce((prev, current)=>{
|
|
132
|
+
if (current._def._config.transformer && current._def._config.transformer !== defaultTransformer) {
|
|
133
|
+
if (prev !== defaultTransformer && prev !== current._def._config.transformer) {
|
|
134
|
+
throw new Error('You seem to have several transformers');
|
|
135
|
+
}
|
|
136
|
+
return current._def._config.transformer;
|
|
137
|
+
}
|
|
138
|
+
return prev;
|
|
139
|
+
}, defaultTransformer);
|
|
140
|
+
const router = createRouterFactory({
|
|
141
|
+
errorFormatter,
|
|
142
|
+
transformer,
|
|
143
|
+
isDev: routerList.some((r)=>r._def._config.isDev),
|
|
144
|
+
allowOutsideOfServer: routerList.some((r)=>r._def._config.allowOutsideOfServer),
|
|
145
|
+
isServer: routerList.some((r)=>r._def._config.isServer),
|
|
146
|
+
$types: routerList[0]?._def._config.$types
|
|
147
|
+
})(record);
|
|
148
|
+
return router;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { callProcedure, createCallerFactory, createRouterFactory, mergeRouters };
|