@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.
Files changed (139) hide show
  1. package/dist/adapters/aws-lambda/handler.d.ts +17 -15
  2. package/dist/adapters/aws-lambda/handler.js +23 -23
  3. package/dist/adapters/aws-lambda/index.d.ts +4 -16
  4. package/dist/adapters/aws-lambda/index.js +2 -2
  5. package/dist/adapters/aws-lambda/rpc-handler.d.ts +9 -9
  6. package/dist/adapters/aws-lambda/rpc-handler.js +20 -17
  7. package/dist/adapters/crossws/handler.d.ts +44 -42
  8. package/dist/adapters/crossws/handler.js +53 -60
  9. package/dist/adapters/crossws/index.d.ts +3 -2
  10. package/dist/adapters/crossws/index.js +2 -2
  11. package/dist/adapters/crossws/rpc-handler.d.ts +10 -10
  12. package/dist/adapters/crossws/rpc-handler.js +17 -14
  13. package/dist/adapters/fastify/handler.d.ts +17 -15
  14. package/dist/adapters/fastify/handler.js +20 -20
  15. package/dist/adapters/fastify/index.d.ts +3 -2
  16. package/dist/adapters/fastify/index.js +2 -2
  17. package/dist/adapters/fastify/rpc-handler.d.ts +9 -9
  18. package/dist/adapters/fastify/rpc-handler.js +16 -13
  19. package/dist/adapters/fetch/handler.d.ts +19 -17
  20. package/dist/adapters/fetch/handler.js +22 -22
  21. package/dist/adapters/fetch/index.d.ts +4 -7
  22. package/dist/adapters/fetch/index.js +3 -7
  23. package/dist/adapters/fetch/rpc-handler.d.ts +9 -9
  24. package/dist/adapters/fetch/rpc-handler.js +18 -15
  25. package/dist/adapters/message-port/handler.d.ts +58 -60
  26. package/dist/adapters/message-port/handler.js +72 -86
  27. package/dist/adapters/message-port/index.d.ts +3 -2
  28. package/dist/adapters/message-port/index.js +2 -2
  29. package/dist/adapters/message-port/rpc-handler.d.ts +9 -9
  30. package/dist/adapters/message-port/rpc-handler.js +17 -14
  31. package/dist/adapters/node/handler.d.ts +17 -15
  32. package/dist/adapters/node/handler.js +20 -20
  33. package/dist/adapters/node/index.d.ts +4 -7
  34. package/dist/adapters/node/index.js +3 -7
  35. package/dist/adapters/node/rpc-handler.d.ts +9 -9
  36. package/dist/adapters/node/rpc-handler.js +17 -14
  37. package/dist/adapters/standard/codec.d.ts +13 -13
  38. package/dist/adapters/standard/handler.d.ts +49 -49
  39. package/dist/adapters/standard/handler.js +205 -205
  40. package/dist/adapters/standard/index.d.ts +7 -6
  41. package/dist/adapters/standard/index.js +4 -5
  42. package/dist/adapters/standard/plugin.d.ts +25 -31
  43. package/dist/adapters/standard/plugin.js +14 -16
  44. package/dist/adapters/standard/rpc-handler-codec.d.ts +39 -43
  45. package/dist/adapters/standard/rpc-handler-codec.js +50 -51
  46. package/dist/adapters/standard/rpc-matcher.d.ts +40 -40
  47. package/dist/adapters/standard/rpc-matcher.js +103 -149
  48. package/dist/adapters/standard/utils.d.ts +8 -8
  49. package/dist/adapters/standard/utils.js +7 -5
  50. package/dist/adapters/standard-peer/index.d.ts +2 -1
  51. package/dist/adapters/standard-peer/index.js +1 -1
  52. package/dist/adapters/standard-peer/utils.d.ts +6 -4
  53. package/dist/adapters/standard-peer/utils.js +12 -6
  54. package/dist/adapters/websocket/handler.d.ts +52 -50
  55. package/dist/adapters/websocket/handler.js +75 -85
  56. package/dist/adapters/websocket/index.d.ts +3 -2
  57. package/dist/adapters/websocket/index.js +2 -2
  58. package/dist/adapters/websocket/rpc-handler.d.ts +9 -9
  59. package/dist/adapters/websocket/rpc-handler.js +17 -14
  60. package/dist/builder-variants.d.ts +195 -195
  61. package/dist/builder.d.ts +103 -104
  62. package/dist/builder.js +198 -224
  63. package/dist/constants.d.ts +1 -1
  64. package/dist/constants.js +4 -2
  65. package/dist/context.d.ts +3 -3
  66. package/dist/extensions/callable.d.ts +11 -11
  67. package/dist/extensions/callable.js +6 -5
  68. package/dist/helpers/base64url.d.ts +1 -1
  69. package/dist/helpers/base64url.js +44 -49
  70. package/dist/helpers/cookie.d.ts +10 -11
  71. package/dist/helpers/cookie.js +56 -63
  72. package/dist/helpers/encryption.d.ts +1 -1
  73. package/dist/helpers/encryption.js +80 -70
  74. package/dist/helpers/index.d.ts +5 -4
  75. package/dist/helpers/index.js +4 -4
  76. package/dist/helpers/signing.d.ts +1 -1
  77. package/dist/helpers/signing.js +72 -82
  78. package/dist/implementer-procedure.d.ts +12 -13
  79. package/dist/implementer-procedure.js +37 -44
  80. package/dist/implementer-router.d.ts +30 -36
  81. package/dist/implementer-router.js +92 -111
  82. package/dist/implementer.d.ts +8 -8
  83. package/dist/implementer.js +28 -35
  84. package/dist/index.d.ts +22 -61
  85. package/dist/index.js +16 -48
  86. package/dist/lazy.d.ts +14 -14
  87. package/dist/lazy.js +19 -30
  88. package/dist/middleware-decorated.d.ts +8 -9
  89. package/dist/middleware-decorated.js +66 -70
  90. package/dist/middleware.d.ts +34 -34
  91. package/dist/plugins/batch.d.ts +75 -75
  92. package/dist/plugins/batch.js +345 -379
  93. package/dist/plugins/cors.d.ts +60 -64
  94. package/dist/plugins/cors.js +118 -111
  95. package/dist/plugins/get-method-csrf-protection.d.ts +8 -6
  96. package/dist/plugins/get-method-csrf-protection.js +47 -63
  97. package/dist/plugins/head-method.d.ts +11 -9
  98. package/dist/plugins/head-method.js +97 -94
  99. package/dist/plugins/index.d.ts +15 -39
  100. package/dist/plugins/index.js +14 -29
  101. package/dist/plugins/method-override.d.ts +30 -28
  102. package/dist/plugins/method-override.js +53 -49
  103. package/dist/plugins/request-compression.d.ts +11 -9
  104. package/dist/plugins/request-compression.js +52 -79
  105. package/dist/plugins/request-headers.d.ts +10 -8
  106. package/dist/plugins/request-headers.js +27 -29
  107. package/dist/plugins/request-limit.d.ts +21 -19
  108. package/dist/plugins/request-limit.js +60 -67
  109. package/dist/plugins/response-compression.d.ts +42 -39
  110. package/dist/plugins/response-compression.js +150 -202
  111. package/dist/plugins/response-headers.d.ts +15 -13
  112. package/dist/plugins/response-headers.js +43 -46
  113. package/dist/plugins/rethrow.d.ts +25 -23
  114. package/dist/plugins/rethrow.js +46 -58
  115. package/dist/plugins/signal-sync.d.ts +7 -5
  116. package/dist/plugins/signal-sync.js +71 -86
  117. package/dist/plugins/timeout.d.ts +29 -27
  118. package/dist/plugins/timeout.js +61 -58
  119. package/dist/procedure-client.d.ts +14 -15
  120. package/dist/procedure-client.js +149 -166
  121. package/dist/procedure-decorated.d.ts +9 -9
  122. package/dist/procedure-decorated.js +36 -44
  123. package/dist/procedure-utils.d.ts +10 -30
  124. package/dist/procedure-utils.js +39 -40
  125. package/dist/procedure.d.ts +60 -60
  126. package/dist/procedure.js +18 -24
  127. package/dist/router-client.d.ts +9 -11
  128. package/dist/router-client.js +33 -41
  129. package/dist/router-hidden.js +10 -12
  130. package/dist/router-utils.d.ts +13 -30
  131. package/dist/router-utils.js +146 -191
  132. package/dist/router.d.ts +12 -26
  133. package/package.json +10 -10
  134. package/dist/adapters/standard/codec.js +0 -1
  135. package/dist/builder-variants.js +0 -1
  136. package/dist/context.js +0 -1
  137. package/dist/middleware.js +0 -1
  138. package/dist/router-hidden.d.ts +0 -5
  139. package/dist/router.js +0 -1
@@ -1,202 +1,157 @@
1
- import { mergeErrorMap, ProcedureContract, resolveMetaPlugins } from '@orpc/contract';
2
- import { getOwn, isNonPrimitive, omit, setOwn } from '@orpc/shared';
3
- import { Lazy, unlazy } from './lazy.js';
4
- import { createContractProcedure } from './procedure-utils.js';
5
- import { Procedure } from './procedure.js';
6
- import { getHiddenRouterContract } from './router-hidden.js';
7
- export function augmentRouter(router, options) {
8
- if (router instanceof Lazy) {
9
- const [meta, metaPlugins] = resolveMetaPlugins(options.meta, options.metaPlugins, router['~orpc'].metaPlugins);
10
- const enhanced = new Lazy({
11
- meta,
12
- metaPlugins,
13
- async loader() {
14
- const { default: unlaziedRouter } = await unlazy(router);
15
- const enhanced = augmentRouter(unlaziedRouter, options);
16
- return unlazy(enhanced);
17
- },
18
- });
19
- return enhanced;
20
- }
21
- if (router instanceof Procedure) {
22
- const [meta, metaPlugins] = resolveMetaPlugins(options.meta, options.metaPlugins, router['~orpc'].metaPlugins);
23
- const enhanced = new Procedure({
24
- ...omit(options, ['middlewares', 'errorMap', 'meta', 'metaPlugins']),
25
- ...router['~orpc'],
26
- meta,
27
- metaPlugins,
28
- errorMap: mergeErrorMap(options.errorMap, router['~orpc'].errorMap),
29
- orderedMiddlewares: [
30
- ...options.middlewares.map((middleware) => ({
31
- middleware,
32
- inputSchemasLengthAtUse: 0,
33
- outputSchemasLengthAtUse: 0,
34
- })),
35
- ...router['~orpc'].orderedMiddlewares,
36
- ],
37
- });
38
- return enhanced;
39
- }
40
- if (!isNonPrimitive(router)) {
41
- return router;
42
- }
43
- const enhanced = {};
44
- for (const [key, child] of Object.entries(router)) {
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
- export function augmentImplementedRouter(router, options) {
50
- if (router instanceof Lazy) {
51
- const enhanced = new Lazy({
52
- ...router['~orpc'],
53
- async loader() {
54
- const { default: unlaziedRouter } = await unlazy(router);
55
- const enhanced = augmentImplementedRouter(unlaziedRouter, options);
56
- return unlazy(enhanced);
57
- },
58
- });
59
- return enhanced;
60
- }
61
- if (router instanceof Procedure) {
62
- const enhanced = new Procedure({
63
- ...omit(options, ['middlewares']),
64
- ...router['~orpc'],
65
- orderedMiddlewares: [
66
- ...options.middlewares.map((middleware) => ({
67
- middleware,
68
- inputSchemasLengthAtUse: 0,
69
- outputSchemasLengthAtUse: 0,
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
- * Resolves the procedure of a contract walked from a router: the procedure itself,
87
- * or the implementation of a contract-first procedure, looked up by its path.
88
- *
89
- * @throws {TypeError} If a contract-first procedure has no valid implementation.
90
- */
91
- export async function resolveContractProcedure(router, contract, path) {
92
- if (contract instanceof Procedure) {
93
- return contract;
94
- }
95
- const { default: maybeProcedure } = await unlazy(getRouter(router, path));
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
- export function getRouter(router, path) {
103
- let current = router;
104
- for (let i = 0; i < path.length; i++) {
105
- const segment = path[i];
106
- if (!isNonPrimitive(current)) {
107
- return undefined;
108
- }
109
- if (current instanceof Procedure) {
110
- return undefined;
111
- }
112
- if (!(current instanceof Lazy)) {
113
- current = getOwn(current, segment);
114
- continue;
115
- }
116
- const lazied = current;
117
- const rest = path.slice(i);
118
- return new Lazy({
119
- ...lazied['~orpc'],
120
- async loader() {
121
- const unwrapped = await unlazy(lazied);
122
- const next = getRouter(unwrapped.default, rest);
123
- return await unlazy(next);
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
- export function walkProcedureContractsSync(router, callback, path = []) {
133
- const lazyResults = [];
134
- walkProcedureContractsSyncInternal(router, callback, path.slice(), lazyResults);
135
- return lazyResults;
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
- const hiddenContract = getHiddenRouterContract(router);
139
- if (hiddenContract !== undefined) {
140
- router = hiddenContract;
141
- }
142
- if (router instanceof ProcedureContract) {
143
- callback(router, path.slice());
144
- return;
145
- }
146
- if (!isNonPrimitive(router)) {
147
- return;
148
- }
149
- for (const [key, value] of Object.entries(router)) {
150
- path.push(key);
151
- if (value instanceof Lazy) {
152
- lazyResults.push({ router: value, path: path.slice() });
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
- export async function walkProcedureContractsAsync(router, callback, path = []) {
161
- const hiddenContract = getHiddenRouterContract(router);
162
- if (hiddenContract !== undefined) {
163
- router = hiddenContract;
164
- }
165
- if (router instanceof ProcedureContract) {
166
- await callback(router, path);
167
- return;
168
- }
169
- if (!isNonPrimitive(router)) {
170
- return;
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
- * Fully resolves all lazy routers inside a router, returning a plain router.
184
- * Useful for making a router with lazy parts contract-compatible.
185
- *
186
- * @see {@link https://orpc.dev/docs/contract/router#router-to-contract | Router Contract - Router to Contract}
187
- */
188
- export async function unlazyRouter(router) {
189
- if (router instanceof Procedure) {
190
- return router;
191
- }
192
- if (!isNonPrimitive(router)) {
193
- return router;
194
- }
195
- const unlazied = {};
196
- for (const key of Object.keys(router)) {
197
- const item = router[key];
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 type { InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap, ProcedureContract, RouterContract, ThrowableError } from '@orpc/contract';
2
- import type { Context, MergedContext } from './context.ts';
3
- import type { Lazyable } from './lazy.ts';
4
- import type { Procedure } from './procedure.ts';
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
- [k: string]: Lazyable<Router<TInitialContext>>;
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.49",
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.49",
109
- "@orpc/contract": "2.0.0-beta.49",
110
- "@orpc/shared": "2.0.0-beta.49",
111
- "@standard-server/aws-lambda": "~0.15.0",
112
- "@standard-server/core": "~0.15.0",
113
- "@standard-server/fastify": "~0.15.0",
114
- "@standard-server/fetch": "~0.15.0",
115
- "@standard-server/node": "~0.15.0",
116
- "@standard-server/peer": "~0.15.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 {};
@@ -1 +0,0 @@
1
- export {};
package/dist/context.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -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 {};