@orpc/server 2.0.0-beta.4 → 2.0.0-beta.40

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 (60) hide show
  1. package/README.md +97 -94
  2. package/dist/adapters/aws-lambda/index.d.mts +50 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +50 -0
  4. package/dist/adapters/aws-lambda/index.mjs +39 -0
  5. package/dist/adapters/crossws/index.d.mts +21 -12
  6. package/dist/adapters/crossws/index.d.ts +21 -12
  7. package/dist/adapters/crossws/index.mjs +14 -10
  8. package/dist/adapters/fastify/index.d.mts +42 -0
  9. package/dist/adapters/fastify/index.d.ts +42 -0
  10. package/dist/adapters/fastify/index.mjs +39 -0
  11. package/dist/adapters/fetch/index.d.mts +21 -114
  12. package/dist/adapters/fetch/index.d.ts +21 -114
  13. package/dist/adapters/fetch/index.mjs +20 -182
  14. package/dist/adapters/message-port/index.d.mts +23 -20
  15. package/dist/adapters/message-port/index.d.ts +23 -20
  16. package/dist/adapters/message-port/index.mjs +31 -34
  17. package/dist/adapters/node/index.d.mts +19 -96
  18. package/dist/adapters/node/index.d.ts +19 -96
  19. package/dist/adapters/node/index.mjs +19 -157
  20. package/dist/adapters/standard/index.d.mts +91 -17
  21. package/dist/adapters/standard/index.d.ts +91 -17
  22. package/dist/adapters/standard/index.mjs +4 -4
  23. package/dist/adapters/standard-peer/index.d.mts +6 -11
  24. package/dist/adapters/standard-peer/index.d.ts +6 -11
  25. package/dist/adapters/standard-peer/index.mjs +10 -2
  26. package/dist/adapters/websocket/index.d.mts +45 -29
  27. package/dist/adapters/websocket/index.d.ts +45 -29
  28. package/dist/adapters/websocket/index.mjs +37 -28
  29. package/dist/extensions/callable.d.mts +5 -5
  30. package/dist/extensions/callable.d.ts +5 -5
  31. package/dist/extensions/callable.mjs +2 -2
  32. package/dist/helpers/index.d.mts +23 -6
  33. package/dist/helpers/index.d.ts +23 -6
  34. package/dist/helpers/index.mjs +13 -5
  35. package/dist/index.d.mts +332 -37
  36. package/dist/index.d.ts +332 -37
  37. package/dist/index.mjs +131 -49
  38. package/dist/plugins/index.d.mts +243 -31
  39. package/dist/plugins/index.d.ts +243 -31
  40. package/dist/plugins/index.mjs +527 -30
  41. package/dist/shared/server.1ExWFMze.mjs +69 -0
  42. package/dist/shared/{server.CjOb6ItT.mjs → server.24nXyhbl.mjs} +1 -1
  43. package/dist/shared/{server.DBANIheG.d.ts → server.B5K1CViq.d.mts} +24 -13
  44. package/dist/shared/{server.BsNNjG5J.d.mts → server.BpmUhems.d.mts} +32 -20
  45. package/dist/shared/{server.BL22TloH.d.mts → server.BsujoJoF.d.mts} +38 -59
  46. package/dist/shared/{server.BL22TloH.d.ts → server.BsujoJoF.d.ts} +38 -59
  47. package/dist/shared/{server.BwHnWUuN.mjs → server.BynNaBBA.mjs} +24 -19
  48. package/dist/shared/{server.GDpX6Df8.mjs → server.C0lFtoHU.mjs} +162 -68
  49. package/dist/shared/server.C7xllBNN.d.mts +34 -0
  50. package/dist/shared/server.CFqSIFnT.d.mts +14 -0
  51. package/dist/shared/{server.Pa0F03f_.d.ts → server.CRwPbhLO.d.ts} +32 -20
  52. package/dist/shared/{server.DJIkub_t.d.mts → server.Cxranw-8.d.ts} +24 -13
  53. package/dist/shared/server.D0dr-F8u.d.ts +34 -0
  54. package/dist/shared/{server.CrlKQucM.mjs → server.Djb_ebJT.mjs} +25 -53
  55. package/dist/shared/server.RRVK1xTV.d.ts +14 -0
  56. package/package.json +47 -14
  57. package/dist/shared/server.CX4vUnDk.mjs +0 -11
  58. package/dist/shared/server.Cj5lgPuG.d.mts +0 -66
  59. package/dist/shared/server.D_QauotT.mjs +0 -30
  60. package/dist/shared/server.d_2NS3g5.d.ts +0 -66
@@ -1,6 +1,6 @@
1
- import { c as createProcedureClient, P as Procedure, L as Lazy, u as unlazy } from './server.CrlKQucM.mjs';
1
+ import { c as createProcedureClient, P as Procedure, L as Lazy, u as unlazy } from './server.Djb_ebJT.mjs';
2
2
  import { resolveMetaPlugins, mergeErrorMap, ProcedureContract } from '@orpc/contract';
3
- import { getOrBind, isTypescriptObject } from '@orpc/shared';
3
+ import { omit, isTypescriptObject } from '@orpc/shared';
4
4
 
5
5
  const DEFAULT_SUCCESS_STATUS = 200;
6
6
  const DEFAULT_ERROR_STATUS = 500;
@@ -44,7 +44,7 @@ function withHiddenRouterContract(router, contract) {
44
44
  if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
45
45
  return contract;
46
46
  }
47
- return getOrBind(target, key);
47
+ return Reflect.get(target, key);
48
48
  }
49
49
  });
50
50
  }
@@ -77,6 +77,7 @@ function augmentRouter(router, options) {
77
77
  router["~orpc"].metaPlugins
78
78
  );
79
79
  const enhanced2 = new Procedure({
80
+ ...omit(options, ["middlewares", "errorMap", "meta", "metaPlugins"]),
80
81
  ...router["~orpc"],
81
82
  meta,
82
83
  metaPlugins,
@@ -92,8 +93,8 @@ function augmentRouter(router, options) {
92
93
  return router;
93
94
  }
94
95
  const enhanced = {};
95
- for (const key in router) {
96
- enhanced[key] = augmentRouter(router[key], options);
96
+ for (const [key, child] of Object.entries(router)) {
97
+ enhanced[key] = augmentRouter(child, options);
97
98
  }
98
99
  return enhanced;
99
100
  }
@@ -111,6 +112,7 @@ function augmentImplementedRouter(router, options) {
111
112
  }
112
113
  if (router instanceof Procedure) {
113
114
  const enhanced2 = new Procedure({
115
+ ...omit(options, ["middlewares"]),
114
116
  ...router["~orpc"],
115
117
  orderedMiddlewares: [
116
118
  ...options.middlewares.map((middleware) => ({ middleware, inputSchemasLengthAtUse: 0, outputSchemasLengthAtUse: 0 })),
@@ -123,8 +125,8 @@ function augmentImplementedRouter(router, options) {
123
125
  return router;
124
126
  }
125
127
  const enhanced = {};
126
- for (const key in router) {
127
- enhanced[key] = augmentImplementedRouter(router[key], options);
128
+ for (const [key, child] of Object.entries(router)) {
129
+ enhanced[key] = augmentImplementedRouter(child, options);
128
130
  }
129
131
  return enhanced;
130
132
  }
@@ -159,27 +161,31 @@ function getRouter(router, path) {
159
161
  return current;
160
162
  }
161
163
  function walkProcedureContractsSync(router, callback, path = []) {
164
+ const lazyResults = [];
165
+ walkProcedureContractsSyncInternal(router, callback, path.slice(), lazyResults);
166
+ return lazyResults;
167
+ }
168
+ function walkProcedureContractsSyncInternal(router, callback, path, lazyResults) {
162
169
  const hiddenContract = getHiddenRouterContract(router);
163
170
  if (hiddenContract !== void 0) {
164
171
  router = hiddenContract;
165
172
  }
166
173
  if (router instanceof ProcedureContract) {
167
- callback(router, path);
168
- return [];
174
+ callback(router, path.slice());
175
+ return;
169
176
  }
170
177
  if (!isTypescriptObject(router)) {
171
- return [];
178
+ return;
172
179
  }
173
- const lazyResults = [];
174
- for (const key in router) {
175
- const value = router[key];
180
+ for (const [key, value] of Object.entries(router)) {
181
+ path.push(key);
176
182
  if (value instanceof Lazy) {
177
- lazyResults.push({ router: value, path: [...path, key] });
183
+ lazyResults.push({ router: value, path: path.slice() });
178
184
  } else {
179
- lazyResults.push(...walkProcedureContractsSync(value, callback, [...path, key]));
185
+ walkProcedureContractsSyncInternal(value, callback, path, lazyResults);
180
186
  }
187
+ path.pop();
181
188
  }
182
- return lazyResults;
183
189
  }
184
190
  async function walkProcedureContractsAsync(router, callback, path = []) {
185
191
  const hiddenContract = getHiddenRouterContract(router);
@@ -193,8 +199,7 @@ async function walkProcedureContractsAsync(router, callback, path = []) {
193
199
  if (!isTypescriptObject(router)) {
194
200
  return;
195
201
  }
196
- for (const key in router) {
197
- const value = router[key];
202
+ for (const [key, value] of Object.entries(router)) {
198
203
  if (value instanceof Lazy) {
199
204
  const { default: router2 } = await unlazy(value);
200
205
  await walkProcedureContractsAsync(router2, callback, [...path, key]);
@@ -211,7 +216,7 @@ async function unlazyRouter(router) {
211
216
  return router;
212
217
  }
213
218
  const unlazied = {};
214
- for (const key in router) {
219
+ for (const key of Object.keys(router)) {
215
220
  const item = router[key];
216
221
  const { default: unlaziedRouter } = await unlazy(item);
217
222
  unlazied[key] = await unlazyRouter(unlaziedRouter);
@@ -1,8 +1,8 @@
1
1
  import { ORPCError, toORPCError, RPCSerializer, COMMON_ERROR_STATUS_MAP } from '@orpc/client';
2
- import { sortPlugins, getOpenTelemetryConfig, runWithSpan, toArray, matchesHttpPathPrefix, intercept, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, recordSpanError, pathToHttpPath, normalizeHttpPath, value, parseEmptyableJSON } from '@orpc/shared';
3
- import { flattenStandardHeader, parseStandardUrl } from '@standardserver/core';
4
- import { c as createProcedureClient, u as unlazy, P as Procedure } from './server.CrlKQucM.mjs';
5
- import { w as walkProcedureContractsSync, g as getRouter, c as createContractProcedure, D as DEFAULT_SUCCESS_STATUS, a as DEFAULT_ERROR_STATUS } from './server.BwHnWUuN.mjs';
2
+ import { sortPlugins, toArray, matchesHttpPathPrefix, value, intercept, getTracer, runWithSpan, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, traceReadableStream, recordSpanError, wrapAsyncIterator, toTracingException, wrapReadableStream, pathToHttpPath, normalizeHttpPath, parseEmptyableJSON, getOwn } from '@orpc/shared';
3
+ import { flattenStandardHeader, parseStandardUrl, ErrorEvent } from '@standard-server/core';
4
+ import { c as createProcedureClient, u as unlazy, P as Procedure } from './server.Djb_ebJT.mjs';
5
+ import { w as walkProcedureContractsSync, g as getRouter, c as createContractProcedure, D as DEFAULT_SUCCESS_STATUS, a as DEFAULT_ERROR_STATUS } from './server.BynNaBBA.mjs';
6
6
 
7
7
  class CompositeStandardHandlerPlugin {
8
8
  name = "~composite";
@@ -24,8 +24,8 @@ class StandardHandler {
24
24
  constructor(codec, options) {
25
25
  this.codec = codec;
26
26
  options = new CompositeStandardHandlerPlugin([
27
- new OtelHandlerPlugin(),
28
- ...toArray(options.plugins)
27
+ ...toArray(options.plugins),
28
+ new TracingHandlerPlugin()
29
29
  ]).init(options);
30
30
  this.routingInterceptors = options.routingInterceptors;
31
31
  this.interceptors = options.interceptors;
@@ -34,15 +34,17 @@ class StandardHandler {
34
34
  routingInterceptors;
35
35
  interceptors;
36
36
  clientInterceptors;
37
- async handle(request, { context, prefix }) {
37
+ async handle(request, options) {
38
+ const { prefix } = options;
38
39
  if (prefix && !matchesHttpPathPrefix(request.url, prefix)) {
39
40
  return { matched: false, response: void 0 };
40
41
  }
42
+ const context = await value(options.context, request);
41
43
  return intercept(
42
44
  this.routingInterceptors,
43
45
  { context, prefix, request },
44
46
  async ({ context: context2, prefix: prefix2, request: request2 }) => {
45
- const span = getOpenTelemetryConfig()?.trace.getActiveSpan();
47
+ const span = getTracer()?.getActiveSpan();
46
48
  let step;
47
49
  const matchedOrNot = await runWithSpan("find_procedure", () => this.codec.resolveProcedure(request2, { context: context2, prefix: prefix2 }));
48
50
  if (!matchedOrNot) {
@@ -63,8 +65,10 @@ class StandardHandler {
63
65
  step = "decode_input";
64
66
  let input = await runWithSpan("decode_input", decodeInput2);
65
67
  step = void 0;
66
- if (isAsyncIteratorObject(input)) {
67
- input = override(input, traceAsyncIterator("consume_event_iterator_input", input));
68
+ if (getTracer() && isAsyncIteratorObject(input)) {
69
+ input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
70
+ } else if (getTracer() && input instanceof ReadableStream) {
71
+ input = override(input, traceReadableStream("consume_octet_stream_input", input));
68
72
  }
69
73
  const client = createProcedureClient(procedure2, {
70
74
  context: context3,
@@ -97,23 +101,80 @@ class StandardHandler {
97
101
  );
98
102
  }
99
103
  }
100
- class OtelHandlerPlugin {
101
- name = "~opentelemetry";
104
+ class TracingHandlerPlugin {
105
+ name = "~tracing";
102
106
  init(options) {
103
107
  return {
104
108
  ...options,
105
109
  routingInterceptors: [
106
- // Should be placed before user-provided interceptors to help them access the current active context.
110
+ // Should be placed before user-provided interceptors to help them access the current active span.
107
111
  async ({ next, request }) => {
108
- const otelConfig = getOpenTelemetryConfig();
109
- let propagationContext;
110
- if (otelConfig?.propagation) {
111
- propagationContext = otelConfig.propagation.extract(otelConfig.context.active(), request.headers);
112
+ const tracer = getTracer();
113
+ if (!tracer) {
114
+ return next();
112
115
  }
113
- return runWithSpan(
114
- { name: `${request.method} ${request.url}`, context: propagationContext },
115
- () => next()
116
- );
116
+ const parent = tracer.extract?.(request.headers);
117
+ const [pathname] = parseStandardUrl(request.url);
118
+ return tracer.startActiveSpan(`${request.method} ${pathname}`, parent, async (span) => {
119
+ try {
120
+ const result = await next();
121
+ if (!result.matched) {
122
+ span.end();
123
+ return result;
124
+ }
125
+ const body = result.response.body;
126
+ if (isAsyncIteratorObject(body)) {
127
+ return {
128
+ ...result,
129
+ response: {
130
+ ...result.response,
131
+ /**
132
+ * @remarks
133
+ * **Warning**: Remember use `override` for remaining special properties
134
+ */
135
+ body: override(body, wrapAsyncIterator(body, {
136
+ runWith: (fn) => tracer.withActiveSpan(span, fn),
137
+ onError(error) {
138
+ if (!(error instanceof ErrorEvent)) {
139
+ span.recordException("error", toTracingException(error));
140
+ }
141
+ },
142
+ onFinish() {
143
+ span.end();
144
+ }
145
+ }))
146
+ }
147
+ };
148
+ }
149
+ if (body instanceof ReadableStream) {
150
+ return {
151
+ ...result,
152
+ response: {
153
+ ...result.response,
154
+ /**
155
+ * @remarks
156
+ * **Warning**: Remember use `override` for remaining special properties
157
+ */
158
+ body: override(body, wrapReadableStream(body, {
159
+ runWith: (fn) => tracer.withActiveSpan(span, fn),
160
+ onError(error) {
161
+ span.recordException("error", toTracingException(error));
162
+ },
163
+ onFinish() {
164
+ span.end();
165
+ }
166
+ }))
167
+ }
168
+ };
169
+ }
170
+ span.end();
171
+ return result;
172
+ } catch (e) {
173
+ span.recordException("error", toTracingException(e));
174
+ span.end();
175
+ throw e;
176
+ }
177
+ });
117
178
  },
118
179
  ...toArray(options.routingInterceptors)
119
180
  ]
@@ -121,13 +182,22 @@ class OtelHandlerPlugin {
121
182
  }
122
183
  }
123
184
 
185
+ const RPC_DEFAULT_ALLOW_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
124
186
  class RPCMatcher {
125
187
  filter;
188
+ allowMethodsSet;
189
+ allowMethodsFn;
126
190
  rootRouter;
127
191
  tree = /* @__PURE__ */ new Map();
128
- pendingLazyRouters = [];
192
+ pendingLazyRouters = /* @__PURE__ */ new Map();
129
193
  constructor(router, options = {}) {
130
194
  this.filter = options.filter ?? true;
195
+ const allowMethods = options.allowMethods ?? RPC_DEFAULT_ALLOW_METHODS;
196
+ if (typeof allowMethods !== "function") {
197
+ this.allowMethodsSet = new Set(allowMethods);
198
+ } else {
199
+ this.allowMethodsFn = allowMethods;
200
+ }
131
201
  this.rootRouter = router;
132
202
  this.index(router);
133
203
  }
@@ -136,28 +206,21 @@ class RPCMatcher {
136
206
  if (!value(this.filter, procedure, procedurePath)) {
137
207
  return;
138
208
  }
139
- const httpPath = pathToHttpPath(procedurePath);
140
- if (procedure instanceof Procedure) {
141
- this.tree.set(httpPath, {
142
- path: procedurePath,
143
- contract: procedure,
144
- procedure
145
- });
146
- } else {
147
- this.tree.set(httpPath, {
148
- path: procedurePath,
149
- contract: procedure
150
- });
151
- }
209
+ this.tree.set(pathToHttpPath(procedurePath), {
210
+ path: procedurePath,
211
+ contract: procedure,
212
+ // contract-first entries have no implementation yet, resolveProcedure fills it in on demand
213
+ procedure: procedure instanceof Procedure ? procedure : void 0
214
+ });
152
215
  }, path);
153
- this.pendingLazyRouters.push(
154
- ...lazyResults.map((result) => ({
155
- ...result,
156
- httpPathPrefix: pathToHttpPath(result.path)
157
- }))
158
- );
216
+ for (const result of lazyResults) {
217
+ this.pendingLazyRouters.set(pathToHttpPath(result.path), result);
218
+ }
159
219
  }
160
- async match(_method, pathname, prefix) {
220
+ async match(method, pathname, prefix) {
221
+ if (this.allowMethodsSet && !this.allowMethodsSet.has(method)) {
222
+ return void 0;
223
+ }
161
224
  if (pathname.length > 1 && pathname.endsWith("/")) {
162
225
  pathname = pathname.slice(0, -1);
163
226
  }
@@ -176,40 +239,71 @@ class RPCMatcher {
176
239
  return void 0;
177
240
  }
178
241
  }
179
- const result = await this.matchPathname(pathname);
180
- if (!result && pathname.includes("%")) {
181
- return this.matchPathname(normalizeHttpPath(pathname));
242
+ const loading = this.resolvePendingLazyRouters(pathname);
243
+ if (loading !== void 0) {
244
+ await loading;
182
245
  }
183
- return result;
184
- }
185
- async matchPathname(pathname) {
186
- await this.resolvePendingLazyRouters(pathname);
187
- const entry = this.tree.get(pathname);
188
- if (!entry) {
246
+ let entry = this.tree.get(pathname);
247
+ if (entry === void 0 && pathname.includes("%")) {
248
+ const normalizedPathname = normalizeHttpPath(pathname);
249
+ const normalizedLoading = this.resolvePendingLazyRouters(normalizedPathname);
250
+ if (normalizedLoading !== void 0) {
251
+ await normalizedLoading;
252
+ }
253
+ entry = this.tree.get(normalizedPathname);
254
+ }
255
+ if (entry === void 0) {
256
+ return void 0;
257
+ }
258
+ const procedure = entry.procedure ?? await this.resolveProcedure(entry);
259
+ if (this.allowMethodsFn && !this.allowMethodsFn(method, procedure, entry.path)) {
189
260
  return void 0;
190
261
  }
191
- const procedure = await this.resolveProcedure(entry);
192
- return { path: entry.path, procedure };
262
+ return {
263
+ path: entry.path,
264
+ procedure
265
+ };
193
266
  }
194
- async resolvePendingLazyRouters(pathname) {
195
- if (!this.pendingLazyRouters.length) {
267
+ resolvePendingLazyRouters(pathname) {
268
+ if (this.pendingLazyRouters.size === 0) {
196
269
  return;
197
270
  }
198
- const stillPending = [];
199
- for (const pending of this.pendingLazyRouters) {
200
- if (pathname.startsWith(pending.httpPathPrefix)) {
201
- const { default: router } = await unlazy(pending.router);
202
- this.index(router, pending.path);
203
- } else {
204
- stillPending.push(pending);
271
+ let slashIndex = 0;
272
+ while (slashIndex !== -1) {
273
+ const nextSlashIndex = pathname.indexOf("/", slashIndex + 1);
274
+ const httpPathPrefix = nextSlashIndex === -1 ? pathname : pathname.slice(0, nextSlashIndex);
275
+ if (this.pendingLazyRouters.has(httpPathPrefix)) {
276
+ return this.loadPendingLazyRouters(pathname, slashIndex);
205
277
  }
278
+ slashIndex = nextSlashIndex;
206
279
  }
207
- this.pendingLazyRouters = stillPending;
208
280
  }
209
- async resolveProcedure(entry) {
210
- if (entry.procedure) {
211
- return entry.procedure;
281
+ async loadPendingLazyRouters(pathname, slashIndex) {
282
+ while (slashIndex !== -1) {
283
+ const nextSlashIndex = pathname.indexOf("/", slashIndex + 1);
284
+ const httpPathPrefix = nextSlashIndex === -1 ? pathname : pathname.slice(0, nextSlashIndex);
285
+ const pending = this.pendingLazyRouters.get(httpPathPrefix);
286
+ if (pending !== void 0) {
287
+ await this.loadPendingLazyRouter(httpPathPrefix, pending);
288
+ }
289
+ slashIndex = nextSlashIndex;
290
+ }
291
+ }
292
+ loadPendingLazyRouter(httpPathPrefix, pending) {
293
+ if (pending.loading === void 0) {
294
+ pending.loading = this.indexPendingLazyRouter(httpPathPrefix, pending).catch((error) => {
295
+ pending.loading = void 0;
296
+ throw error;
297
+ });
212
298
  }
299
+ return pending.loading;
300
+ }
301
+ async indexPendingLazyRouter(httpPathPrefix, pending) {
302
+ const { default: router } = await unlazy(pending.router);
303
+ this.index(router, pending.path);
304
+ this.pendingLazyRouters.delete(httpPathPrefix);
305
+ }
306
+ async resolveProcedure(entry) {
213
307
  const { default: maybeProcedure } = await unlazy(getRouter(this.rootRouter, entry.path));
214
308
  if (!(maybeProcedure instanceof Procedure)) {
215
309
  throw new TypeError(
@@ -259,7 +353,7 @@ class RPCHandlerCodec {
259
353
  };
260
354
  }
261
355
  encodeError(error, _procedure, _path, _options) {
262
- const status = this.errorStatusMap[error.code] ?? DEFAULT_ERROR_STATUS;
356
+ const status = getOwn(this.errorStatusMap, error.code) ?? DEFAULT_ERROR_STATUS;
263
357
  return {
264
358
  headers: {},
265
359
  status,
@@ -268,4 +362,4 @@ class RPCHandlerCodec {
268
362
  }
269
363
  }
270
364
 
271
- export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, RPCHandlerCodec as R, StandardHandler as S, RPCMatcher as a };
365
+ export { CompositeStandardHandlerPlugin as C, RPCHandlerCodec as R, StandardHandler as S, TracingHandlerPlugin as T, RPCMatcher as a, RPC_DEFAULT_ALLOW_METHODS as b };
@@ -0,0 +1,34 @@
1
+ import { C as Context } from './server.BsujoJoF.mjs';
2
+ import { b as StandardHandlerPlugin, c as StandardHandlerOptions } from './server.B5K1CViq.mjs';
3
+
4
+ interface RequestLimitHandlerPluginOptions {
5
+ /**
6
+ * The maximum allowed request body size in bytes.
7
+ */
8
+ maxBodySize: number;
9
+ }
10
+ /**
11
+ * Rejects requests whose body exceeds `maxBodySize`.
12
+ *
13
+ * When used with the request compression plugin, the limit applies to the
14
+ * decompressed payload rather than the compressed wire size.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/plugins/request-limit | Request Limit Plugin}
17
+ */
18
+ declare class RequestLimitHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
19
+ name: string;
20
+ /**
21
+ * Should limit the original batch request body instead of sub-requests.
22
+ */
23
+ after: string[];
24
+ /**
25
+ * Should limit the final body size instead of the compressed one.
26
+ */
27
+ before: string[];
28
+ private readonly maxBodySize;
29
+ constructor(options: RequestLimitHandlerPluginOptions);
30
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
31
+ }
32
+
33
+ export { RequestLimitHandlerPlugin as R };
34
+ export type { RequestLimitHandlerPluginOptions as a };
@@ -0,0 +1,14 @@
1
+ import { Value, Promisable } from '@orpc/shared';
2
+ import { StandardLazyRequest } from '@standard-server/core';
3
+ import { C as Context } from './server.BsujoJoF.mjs';
4
+ import { a as StandardHandlerHandleOptions } from './server.B5K1CViq.mjs';
5
+
6
+ type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
7
+ context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
8
+ } : {
9
+ context: Value<Promisable<T>, [request: StandardLazyRequest]>;
10
+ });
11
+ declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
12
+
13
+ export { resolveFriendlyStandardHandlerHandleOptions as r };
14
+ export type { FriendlyStandardHandlerHandleOptions as F };
@@ -1,10 +1,10 @@
1
1
  import { RouterContract, ProcedureContract, ORPCErrorFromErrorMap, ThrowableError, InferSchemaInput, InferSchemaOutput } from '@orpc/contract';
2
- import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.BL22TloH.js';
2
+ import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.BsujoJoF.js';
3
3
 
4
- type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any, any> | {
4
+ type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any> | {
5
5
  [k: string]: Lazyable<Router<TInitialContext>>;
6
6
  };
7
- type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap, never> : {
7
+ type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap> : {
8
8
  [K in keyof T]: T[K] extends RouterContract ? Lazyable<ContractedRouter<T[K], TInitialContext>> : never;
9
9
  };
10
10
  type AnyRouter = Router<any>;
@@ -12,50 +12,62 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $>
12
12
  /**
13
13
  * Infer all initial context of the router.
14
14
  *
15
- * @info A procedure is a router too.
16
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
15
+ * @remarks
16
+ * **Note**: A procedure is a router too.
17
+ *
18
+ * @see {@link https://orpc.dev/docs/router#infer-router-initial-contexts | Router - Infer Router Initial Contexts}
17
19
  */
18
- type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
20
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
19
21
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
20
22
  };
21
23
  /**
22
24
  * Infer all current context of the router.
23
25
  *
24
- * @info A procedure is a router too.
25
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
26
+ * @remarks
27
+ * **Note**: A procedure is a router too.
28
+ *
29
+ * @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts}
26
30
  */
27
- type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
31
+ type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
28
32
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never;
29
33
  };
30
34
  /**
31
- * Infer all router inputs
35
+ * Infer all router inputs.
36
+ *
37
+ * @remarks
38
+ * **Note**: A procedure is a router too.
32
39
  *
33
- * @info A procedure is a router too.
34
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
40
+ * @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs}
35
41
  */
36
- type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
42
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
37
43
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
38
44
  };
39
45
  /**
40
- * Infer all router outputs
46
+ * Infer all router outputs.
41
47
  *
42
- * @info A procedure is a router too.
43
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
48
+ * @remarks
49
+ * **Note**: A procedure is a router too.
50
+ *
51
+ * @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs}
44
52
  */
45
- type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
53
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
46
54
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
47
55
  };
48
56
  /**
49
57
  * Infer the union of throwable errors for entire router.
58
+ *
59
+ * @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error}
50
60
  */
51
- type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | ThrowableError : {
61
+ type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
52
62
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never;
53
63
  }[keyof T];
54
64
  /**
55
65
  * Infer throwable errors for each procedure, preserving the router shape.
66
+ *
67
+ * @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors}
56
68
  */
57
- type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | ThrowableError : {
69
+ type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
58
70
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never;
59
71
  };
60
72
 
61
- export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterError as a, InferRouterErrors as b, InferRouterFinalContexts as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
73
+ export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterFinalContexts as a, InferRouterError as b, InferRouterErrors as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };