@orpc/server 2.0.0-beta.49 → 2.0.0-beta.50
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/adapters/aws-lambda/handler.d.ts +17 -15
- package/dist/adapters/aws-lambda/handler.js +23 -23
- package/dist/adapters/aws-lambda/index.d.ts +4 -16
- package/dist/adapters/aws-lambda/index.js +2 -2
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +9 -9
- package/dist/adapters/aws-lambda/rpc-handler.js +20 -17
- package/dist/adapters/crossws/handler.d.ts +44 -42
- package/dist/adapters/crossws/handler.js +53 -60
- package/dist/adapters/crossws/index.d.ts +3 -2
- package/dist/adapters/crossws/index.js +2 -2
- package/dist/adapters/crossws/rpc-handler.d.ts +10 -10
- package/dist/adapters/crossws/rpc-handler.js +17 -14
- package/dist/adapters/fastify/handler.d.ts +17 -15
- package/dist/adapters/fastify/handler.js +20 -20
- package/dist/adapters/fastify/index.d.ts +3 -2
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/fastify/rpc-handler.d.ts +9 -9
- package/dist/adapters/fastify/rpc-handler.js +16 -13
- package/dist/adapters/fetch/handler.d.ts +19 -17
- package/dist/adapters/fetch/handler.js +22 -22
- package/dist/adapters/fetch/index.d.ts +4 -7
- package/dist/adapters/fetch/index.js +3 -7
- package/dist/adapters/fetch/rpc-handler.d.ts +9 -9
- package/dist/adapters/fetch/rpc-handler.js +18 -15
- package/dist/adapters/message-port/handler.d.ts +58 -60
- package/dist/adapters/message-port/handler.js +72 -86
- package/dist/adapters/message-port/index.d.ts +3 -2
- package/dist/adapters/message-port/index.js +2 -2
- package/dist/adapters/message-port/rpc-handler.d.ts +9 -9
- package/dist/adapters/message-port/rpc-handler.js +17 -14
- package/dist/adapters/node/handler.d.ts +17 -15
- package/dist/adapters/node/handler.js +20 -20
- package/dist/adapters/node/index.d.ts +4 -7
- package/dist/adapters/node/index.js +3 -7
- package/dist/adapters/node/rpc-handler.d.ts +9 -9
- package/dist/adapters/node/rpc-handler.js +17 -14
- package/dist/adapters/standard/codec.d.ts +13 -13
- package/dist/adapters/standard/handler.d.ts +49 -49
- package/dist/adapters/standard/handler.js +205 -205
- package/dist/adapters/standard/index.d.ts +7 -6
- package/dist/adapters/standard/index.js +4 -5
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-handler-codec.d.ts +39 -43
- package/dist/adapters/standard/rpc-handler-codec.js +50 -51
- package/dist/adapters/standard/rpc-matcher.d.ts +40 -40
- package/dist/adapters/standard/rpc-matcher.js +103 -149
- package/dist/adapters/standard/utils.d.ts +8 -8
- package/dist/adapters/standard/utils.js +7 -5
- package/dist/adapters/standard-peer/index.d.ts +2 -1
- package/dist/adapters/standard-peer/index.js +1 -1
- package/dist/adapters/standard-peer/utils.d.ts +6 -4
- package/dist/adapters/standard-peer/utils.js +12 -6
- package/dist/adapters/websocket/handler.d.ts +52 -50
- package/dist/adapters/websocket/handler.js +75 -85
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-handler.d.ts +9 -9
- package/dist/adapters/websocket/rpc-handler.js +17 -14
- package/dist/builder-variants.d.ts +195 -195
- package/dist/builder.d.ts +103 -104
- package/dist/builder.js +198 -224
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +4 -2
- package/dist/context.d.ts +3 -3
- package/dist/extensions/callable.d.ts +11 -11
- package/dist/extensions/callable.js +6 -5
- package/dist/helpers/base64url.d.ts +1 -1
- package/dist/helpers/base64url.js +44 -49
- package/dist/helpers/cookie.d.ts +10 -11
- package/dist/helpers/cookie.js +56 -63
- package/dist/helpers/encryption.d.ts +1 -1
- package/dist/helpers/encryption.js +80 -70
- package/dist/helpers/index.d.ts +5 -4
- package/dist/helpers/index.js +4 -4
- package/dist/helpers/signing.d.ts +1 -1
- package/dist/helpers/signing.js +72 -82
- package/dist/implementer-procedure.d.ts +12 -13
- package/dist/implementer-procedure.js +37 -44
- package/dist/implementer-router.d.ts +30 -36
- package/dist/implementer-router.js +92 -111
- package/dist/implementer.d.ts +8 -8
- package/dist/implementer.js +28 -35
- package/dist/index.d.ts +22 -61
- package/dist/index.js +16 -48
- package/dist/lazy.d.ts +14 -14
- package/dist/lazy.js +19 -30
- package/dist/middleware-decorated.d.ts +8 -9
- package/dist/middleware-decorated.js +66 -70
- package/dist/middleware.d.ts +34 -34
- package/dist/plugins/batch.d.ts +75 -75
- package/dist/plugins/batch.js +345 -379
- package/dist/plugins/cors.d.ts +60 -64
- package/dist/plugins/cors.js +118 -111
- package/dist/plugins/get-method-csrf-protection.d.ts +8 -6
- package/dist/plugins/get-method-csrf-protection.js +47 -63
- package/dist/plugins/head-method.d.ts +11 -9
- package/dist/plugins/head-method.js +97 -94
- package/dist/plugins/index.d.ts +15 -39
- package/dist/plugins/index.js +14 -29
- package/dist/plugins/method-override.d.ts +30 -28
- package/dist/plugins/method-override.js +53 -49
- package/dist/plugins/request-compression.d.ts +11 -9
- package/dist/plugins/request-compression.js +52 -79
- package/dist/plugins/request-headers.d.ts +10 -8
- package/dist/plugins/request-headers.js +27 -29
- package/dist/plugins/request-limit.d.ts +21 -19
- package/dist/plugins/request-limit.js +60 -67
- package/dist/plugins/response-compression.d.ts +42 -39
- package/dist/plugins/response-compression.js +150 -202
- package/dist/plugins/response-headers.d.ts +15 -13
- package/dist/plugins/response-headers.js +43 -46
- package/dist/plugins/rethrow.d.ts +25 -23
- package/dist/plugins/rethrow.js +46 -58
- package/dist/plugins/signal-sync.d.ts +7 -5
- package/dist/plugins/signal-sync.js +71 -86
- package/dist/plugins/timeout.d.ts +29 -27
- package/dist/plugins/timeout.js +61 -58
- package/dist/procedure-client.d.ts +14 -15
- package/dist/procedure-client.js +149 -166
- package/dist/procedure-decorated.d.ts +9 -9
- package/dist/procedure-decorated.js +36 -44
- package/dist/procedure-utils.d.ts +10 -30
- package/dist/procedure-utils.js +39 -40
- package/dist/procedure.d.ts +60 -60
- package/dist/procedure.js +18 -24
- package/dist/router-client.d.ts +9 -11
- package/dist/router-client.js +33 -41
- package/dist/router-hidden.js +10 -12
- package/dist/router-utils.d.ts +13 -30
- package/dist/router-utils.js +146 -191
- package/dist/router.d.ts +12 -26
- package/package.json +10 -10
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/builder-variants.js +0 -1
- package/dist/context.js +0 -1
- package/dist/middleware.js +0 -1
- package/dist/router-hidden.d.ts +0 -5
- package/dist/router.js +0 -1
package/dist/router-utils.js
CHANGED
|
@@ -1,202 +1,157 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
setOwn(enhanced, key, augmentRouter(child, options));
|
|
46
|
-
}
|
|
47
|
-
return enhanced;
|
|
1
|
+
import { Lazy, unlazy } from "./lazy.js";
|
|
2
|
+
import { Procedure } from "./procedure.js";
|
|
3
|
+
import { createContractProcedure } from "./procedure-utils.js";
|
|
4
|
+
import { getHiddenRouterContract } from "./router-hidden.js";
|
|
5
|
+
import { ProcedureContract, mergeErrorMap, resolveMetaPlugins } from "@orpc/contract";
|
|
6
|
+
import { getOwn, isNonPrimitive, omit, setOwn } from "@orpc/shared";
|
|
7
|
+
// src/router-utils.ts
|
|
8
|
+
function augmentRouter(router, options) {
|
|
9
|
+
if (router instanceof Lazy) {
|
|
10
|
+
const [meta, metaPlugins] = resolveMetaPlugins(options.meta, options.metaPlugins, router["~orpc"].metaPlugins);
|
|
11
|
+
return new Lazy({
|
|
12
|
+
meta,
|
|
13
|
+
metaPlugins,
|
|
14
|
+
async loader() {
|
|
15
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
|
16
|
+
const enhanced = augmentRouter(unlaziedRouter, options);
|
|
17
|
+
return unlazy(enhanced);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (router instanceof Procedure) {
|
|
22
|
+
const [meta, metaPlugins] = resolveMetaPlugins(options.meta, options.metaPlugins, router["~orpc"].metaPlugins);
|
|
23
|
+
return new Procedure({
|
|
24
|
+
...omit(options, [
|
|
25
|
+
"middlewares",
|
|
26
|
+
"errorMap",
|
|
27
|
+
"meta",
|
|
28
|
+
"metaPlugins"
|
|
29
|
+
]),
|
|
30
|
+
...router["~orpc"],
|
|
31
|
+
meta,
|
|
32
|
+
metaPlugins,
|
|
33
|
+
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
34
|
+
orderedMiddlewares: [...options.middlewares.map((middleware) => ({
|
|
35
|
+
middleware,
|
|
36
|
+
inputSchemasLengthAtUse: 0,
|
|
37
|
+
outputSchemasLengthAtUse: 0
|
|
38
|
+
})), ...router["~orpc"].orderedMiddlewares]
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (!isNonPrimitive(router)) return router;
|
|
42
|
+
const enhanced = {};
|
|
43
|
+
for (const [key, child] of Object.entries(router)) setOwn(enhanced, key, augmentRouter(child, options));
|
|
44
|
+
return enhanced;
|
|
48
45
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
...router['~orpc'].orderedMiddlewares,
|
|
72
|
-
],
|
|
73
|
-
});
|
|
74
|
-
return enhanced;
|
|
75
|
-
}
|
|
76
|
-
if (!isNonPrimitive(router)) {
|
|
77
|
-
return router;
|
|
78
|
-
}
|
|
79
|
-
const enhanced = {};
|
|
80
|
-
for (const [key, child] of Object.entries(router)) {
|
|
81
|
-
setOwn(enhanced, key, augmentImplementedRouter(child, options));
|
|
82
|
-
}
|
|
83
|
-
return enhanced;
|
|
46
|
+
function augmentImplementedRouter(router, options) {
|
|
47
|
+
if (router instanceof Lazy) return new Lazy({
|
|
48
|
+
...router["~orpc"],
|
|
49
|
+
async loader() {
|
|
50
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
|
51
|
+
const enhanced = augmentImplementedRouter(unlaziedRouter, options);
|
|
52
|
+
return unlazy(enhanced);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (router instanceof Procedure) return new Procedure({
|
|
56
|
+
...omit(options, ["middlewares"]),
|
|
57
|
+
...router["~orpc"],
|
|
58
|
+
orderedMiddlewares: [...options.middlewares.map((middleware) => ({
|
|
59
|
+
middleware,
|
|
60
|
+
inputSchemasLengthAtUse: 0,
|
|
61
|
+
outputSchemasLengthAtUse: 0
|
|
62
|
+
})), ...router["~orpc"].orderedMiddlewares]
|
|
63
|
+
});
|
|
64
|
+
if (!isNonPrimitive(router)) return router;
|
|
65
|
+
const enhanced = {};
|
|
66
|
+
for (const [key, child] of Object.entries(router)) setOwn(enhanced, key, augmentImplementedRouter(child, options));
|
|
67
|
+
return enhanced;
|
|
84
68
|
}
|
|
85
69
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (!(maybeProcedure instanceof Procedure)) {
|
|
97
|
-
throw new TypeError(`[Contract-First] Missing or invalid implementation for procedure at path: "${path.join('.')}". ` +
|
|
98
|
-
`Ensure the procedure is correctly implemented and matches its contract.`);
|
|
99
|
-
}
|
|
100
|
-
return createContractProcedure(maybeProcedure, contract);
|
|
70
|
+
* Resolves the procedure of a contract walked from a router: the procedure itself,
|
|
71
|
+
* or the implementation of a contract-first procedure, looked up by its path.
|
|
72
|
+
*
|
|
73
|
+
* @throws {TypeError} If a contract-first procedure has no valid implementation.
|
|
74
|
+
*/
|
|
75
|
+
async function resolveContractProcedure(router, contract, path) {
|
|
76
|
+
if (contract instanceof Procedure) return contract;
|
|
77
|
+
const { default: maybeProcedure } = await unlazy(getRouter(router, path));
|
|
78
|
+
if (!(maybeProcedure instanceof Procedure)) throw new TypeError(`[Contract-First] Missing or invalid implementation for procedure at path: "${path.join(".")}". Ensure the procedure is correctly implemented and matches its contract.`);
|
|
79
|
+
return createContractProcedure(maybeProcedure, contract);
|
|
101
80
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
if (!isNonPrimitive(current)) {
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
return current;
|
|
81
|
+
function getRouter(router, path) {
|
|
82
|
+
let current = router;
|
|
83
|
+
for (let i = 0; i < path.length; i++) {
|
|
84
|
+
const segment = path[i];
|
|
85
|
+
if (!isNonPrimitive(current)) return;
|
|
86
|
+
if (current instanceof Procedure) return;
|
|
87
|
+
if (!(current instanceof Lazy)) {
|
|
88
|
+
current = getOwn(current, segment);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const lazied = current;
|
|
92
|
+
const rest = path.slice(i);
|
|
93
|
+
return new Lazy({
|
|
94
|
+
...lazied["~orpc"],
|
|
95
|
+
async loader() {
|
|
96
|
+
const next = getRouter((await unlazy(lazied)).default, rest);
|
|
97
|
+
return await unlazy(next);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (!isNonPrimitive(current)) return;
|
|
102
|
+
return current;
|
|
131
103
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
104
|
+
function walkProcedureContractsSync(router, callback, path = []) {
|
|
105
|
+
const lazyResults = [];
|
|
106
|
+
walkProcedureContractsSyncInternal(router, callback, path.slice(), lazyResults);
|
|
107
|
+
return lazyResults;
|
|
136
108
|
}
|
|
137
109
|
function walkProcedureContractsSyncInternal(router, callback, path, lazyResults) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
else {
|
|
155
|
-
walkProcedureContractsSyncInternal(value, callback, path, lazyResults);
|
|
156
|
-
}
|
|
157
|
-
path.pop();
|
|
158
|
-
}
|
|
110
|
+
const hiddenContract = getHiddenRouterContract(router);
|
|
111
|
+
if (hiddenContract !== void 0) router = hiddenContract;
|
|
112
|
+
if (router instanceof ProcedureContract) {
|
|
113
|
+
callback(router, path.slice());
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!isNonPrimitive(router)) return;
|
|
117
|
+
for (const [key, value] of Object.entries(router)) {
|
|
118
|
+
path.push(key);
|
|
119
|
+
if (value instanceof Lazy) lazyResults.push({
|
|
120
|
+
router: value,
|
|
121
|
+
path: path.slice()
|
|
122
|
+
});
|
|
123
|
+
else walkProcedureContractsSyncInternal(value, callback, path, lazyResults);
|
|
124
|
+
path.pop();
|
|
125
|
+
}
|
|
159
126
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
for (const [key, value] of Object.entries(router)) {
|
|
173
|
-
if (value instanceof Lazy) {
|
|
174
|
-
const { default: router } = await unlazy(value);
|
|
175
|
-
await walkProcedureContractsAsync(router, callback, [...path, key]);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
await walkProcedureContractsAsync(value, callback, [...path, key]);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
127
|
+
async function walkProcedureContractsAsync(router, callback, path = []) {
|
|
128
|
+
const hiddenContract = getHiddenRouterContract(router);
|
|
129
|
+
if (hiddenContract !== void 0) router = hiddenContract;
|
|
130
|
+
if (router instanceof ProcedureContract) {
|
|
131
|
+
await callback(router, path);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!isNonPrimitive(router)) return;
|
|
135
|
+
for (const [key, value] of Object.entries(router)) if (value instanceof Lazy) {
|
|
136
|
+
const { default: router } = await unlazy(value);
|
|
137
|
+
await walkProcedureContractsAsync(router, callback, [...path, key]);
|
|
138
|
+
} else await walkProcedureContractsAsync(value, callback, [...path, key]);
|
|
181
139
|
}
|
|
182
140
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const { default: unlaziedRouter } = await unlazy(item);
|
|
199
|
-
setOwn(unlazied, key, await unlazyRouter(unlaziedRouter));
|
|
200
|
-
}
|
|
201
|
-
return unlazied;
|
|
141
|
+
* Fully resolves all lazy routers inside a router, returning a plain router.
|
|
142
|
+
* Useful for making a router with lazy parts contract-compatible.
|
|
143
|
+
*
|
|
144
|
+
* @see {@link https://orpc.dev/docs/contract/router#router-to-contract | Router Contract - Router to Contract}
|
|
145
|
+
*/
|
|
146
|
+
async function unlazyRouter(router) {
|
|
147
|
+
if (router instanceof Procedure) return router;
|
|
148
|
+
if (!isNonPrimitive(router)) return router;
|
|
149
|
+
const unlazied = {};
|
|
150
|
+
for (const key of Object.keys(router)) {
|
|
151
|
+
const item = router[key];
|
|
152
|
+
const { default: unlaziedRouter } = await unlazy(item);
|
|
153
|
+
setOwn(unlazied, key, await unlazyRouter(unlaziedRouter));
|
|
154
|
+
}
|
|
155
|
+
return unlazied;
|
|
202
156
|
}
|
|
157
|
+
export { augmentImplementedRouter, augmentRouter, getRouter, resolveContractProcedure, unlazyRouter, walkProcedureContractsAsync, walkProcedureContractsSync };
|
package/dist/router.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { Context, MergedContext } from "./context.js";
|
|
2
|
+
import { Lazyable } from "./lazy.js";
|
|
3
|
+
import { Procedure } from "./procedure.js";
|
|
4
|
+
import { InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap, ProcedureContract, RouterContract, ThrowableError } from "@orpc/contract";
|
|
5
5
|
export type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any> | {
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap> : {
|
|
9
|
-
[K in keyof T]: T[K] extends RouterContract ? Lazyable<ContractedRouter<T[K], TInitialContext>> : never;
|
|
6
|
+
[k: string]: Lazyable<Router<TInitialContext>>;
|
|
10
7
|
};
|
|
8
|
+
export type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap> : { [K in keyof T]: T[K] extends RouterContract ? Lazyable<ContractedRouter<T[K], TInitialContext>> : never; };
|
|
11
9
|
export type AnyRouter = Router<any>;
|
|
12
10
|
export type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $> ? $ : never;
|
|
13
11
|
/**
|
|
@@ -18,9 +16,7 @@ export type InferRouterInitialContext<T extends AnyRouter> = T extends Router<in
|
|
|
18
16
|
*
|
|
19
17
|
* @see {@link https://orpc.dev/docs/router#infer-router-initial-contexts | Router - Infer Router Initial Contexts}
|
|
20
18
|
*/
|
|
21
|
-
export type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
|
|
22
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
23
|
-
};
|
|
19
|
+
export type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never; };
|
|
24
20
|
/**
|
|
25
21
|
* Infer all current context of the router.
|
|
26
22
|
*
|
|
@@ -29,9 +25,7 @@ export type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedur
|
|
|
29
25
|
*
|
|
30
26
|
* @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts}
|
|
31
27
|
*/
|
|
32
|
-
export type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
|
|
33
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never;
|
|
34
|
-
};
|
|
28
|
+
export type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never; };
|
|
35
29
|
/**
|
|
36
30
|
* Infer all router inputs.
|
|
37
31
|
*
|
|
@@ -40,9 +34,7 @@ export type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<
|
|
|
40
34
|
*
|
|
41
35
|
* @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs}
|
|
42
36
|
*/
|
|
43
|
-
export type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
44
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
45
|
-
};
|
|
37
|
+
export type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never; };
|
|
46
38
|
/**
|
|
47
39
|
* Infer all router outputs.
|
|
48
40
|
*
|
|
@@ -51,22 +43,16 @@ export type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, an
|
|
|
51
43
|
*
|
|
52
44
|
* @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs}
|
|
53
45
|
*/
|
|
54
|
-
export type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
55
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
56
|
-
};
|
|
46
|
+
export type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never; };
|
|
57
47
|
/**
|
|
58
48
|
* Infer the union of throwable errors for entire router.
|
|
59
49
|
*
|
|
60
50
|
* @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error}
|
|
61
51
|
*/
|
|
62
|
-
export type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
63
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never;
|
|
64
|
-
}[keyof T];
|
|
52
|
+
export type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never; }[keyof T];
|
|
65
53
|
/**
|
|
66
54
|
* Infer throwable errors for each procedure, preserving the router shape.
|
|
67
55
|
*
|
|
68
56
|
* @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors}
|
|
69
57
|
*/
|
|
70
|
-
export type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
71
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never;
|
|
72
|
-
};
|
|
58
|
+
export type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : { [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never; };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/server",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.50",
|
|
4
4
|
"description": "Build typesafe APIs with oRPC: RPC and OpenAPI support, middleware, and adapters for Node.js, Bun, Deno, Fetch, Fastify, WebSocket, AWS Lambda, and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -105,15 +105,15 @@
|
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
|
-
"@orpc/client": "2.0.0-beta.
|
|
109
|
-
"@orpc/contract": "2.0.0-beta.
|
|
110
|
-
"@orpc/shared": "2.0.0-beta.
|
|
111
|
-
"@standard-server/aws-lambda": "~0.
|
|
112
|
-
"@standard-server/core": "~0.
|
|
113
|
-
"@standard-server/fastify": "~0.
|
|
114
|
-
"@standard-server/fetch": "~0.
|
|
115
|
-
"@standard-server/node": "~0.
|
|
116
|
-
"@standard-server/peer": "~0.
|
|
108
|
+
"@orpc/client": "2.0.0-beta.50",
|
|
109
|
+
"@orpc/contract": "2.0.0-beta.50",
|
|
110
|
+
"@orpc/shared": "2.0.0-beta.50",
|
|
111
|
+
"@standard-server/aws-lambda": "~0.16.0",
|
|
112
|
+
"@standard-server/core": "~0.16.0",
|
|
113
|
+
"@standard-server/fastify": "~0.16.0",
|
|
114
|
+
"@standard-server/fetch": "~0.16.0",
|
|
115
|
+
"@standard-server/node": "~0.16.0",
|
|
116
|
+
"@standard-server/peer": "~0.16.0",
|
|
117
117
|
"cookie": "^2.0.1"
|
|
118
118
|
},
|
|
119
119
|
"devDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/builder-variants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/context.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/middleware.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/router-hidden.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { RouterContract } from '@orpc/contract';
|
|
2
|
-
import type { Lazyable } from './lazy.ts';
|
|
3
|
-
import type { AnyRouter } from './router.ts';
|
|
4
|
-
export declare function withHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: RouterContract): T;
|
|
5
|
-
export declare function getHiddenRouterContract(router: Lazyable<AnyRouter | RouterContract>): RouterContract | undefined;
|
package/dist/router.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|