@orpc/server 2.0.0-beta.3 → 2.0.0-beta.31

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 (56) hide show
  1. package/README.md +71 -101
  2. package/dist/adapters/aws-lambda/index.d.mts +93 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +93 -0
  4. package/dist/adapters/aws-lambda/index.mjs +66 -0
  5. package/dist/adapters/crossws/index.d.mts +17 -8
  6. package/dist/adapters/crossws/index.d.ts +17 -8
  7. package/dist/adapters/crossws/index.mjs +10 -7
  8. package/dist/adapters/fastify/index.d.mts +85 -0
  9. package/dist/adapters/fastify/index.d.ts +85 -0
  10. package/dist/adapters/fastify/index.mjs +66 -0
  11. package/dist/adapters/fetch/index.d.mts +16 -67
  12. package/dist/adapters/fetch/index.d.ts +16 -67
  13. package/dist/adapters/fetch/index.mjs +8 -144
  14. package/dist/adapters/message-port/index.d.mts +19 -16
  15. package/dist/adapters/message-port/index.d.ts +19 -16
  16. package/dist/adapters/message-port/index.mjs +28 -32
  17. package/dist/adapters/node/index.d.mts +15 -49
  18. package/dist/adapters/node/index.d.ts +15 -49
  19. package/dist/adapters/node/index.mjs +9 -120
  20. package/dist/adapters/standard/index.d.mts +6 -6
  21. package/dist/adapters/standard/index.d.ts +6 -6
  22. package/dist/adapters/standard/index.mjs +3 -3
  23. package/dist/adapters/standard-peer/index.d.mts +2 -2
  24. package/dist/adapters/standard-peer/index.d.ts +2 -2
  25. package/dist/adapters/websocket/index.d.mts +42 -26
  26. package/dist/adapters/websocket/index.d.ts +42 -26
  27. package/dist/adapters/websocket/index.mjs +33 -25
  28. package/dist/extensions/callable.d.mts +2 -2
  29. package/dist/extensions/callable.d.ts +2 -2
  30. package/dist/extensions/callable.mjs +2 -2
  31. package/dist/helpers/index.d.mts +23 -6
  32. package/dist/helpers/index.d.ts +23 -6
  33. package/dist/helpers/index.mjs +13 -5
  34. package/dist/index.d.mts +311 -16
  35. package/dist/index.d.ts +311 -16
  36. package/dist/index.mjs +126 -34
  37. package/dist/plugins/index.d.mts +241 -32
  38. package/dist/plugins/index.d.ts +241 -32
  39. package/dist/plugins/index.mjs +479 -15
  40. package/dist/shared/server.BhHrioCw.d.ts +34 -0
  41. package/dist/shared/{server.T9F3bzZx.d.ts → server.C2n16pp0.d.ts} +34 -9
  42. package/dist/shared/server.Cd4Z1hpV.mjs +69 -0
  43. package/dist/shared/{server.CrlKQucM.mjs → server.CkButhNT.mjs} +21 -38
  44. package/dist/shared/{server.B_U9y00a.d.mts → server.CkNnZ5F-.d.mts} +34 -9
  45. package/dist/shared/{server.BL22TloH.d.mts → server.CwrYlF72.d.mts} +31 -41
  46. package/dist/shared/{server.BL22TloH.d.ts → server.CwrYlF72.d.ts} +31 -41
  47. package/dist/shared/server.D0Ipbmdv.d.mts +34 -0
  48. package/dist/shared/{server.BwHnWUuN.mjs → server.Dh77P3ii.mjs} +17 -10
  49. package/dist/shared/{server.Pa0F03f_.d.ts → server.Dm0os-OP.d.mts} +24 -12
  50. package/dist/shared/{server.GDpX6Df8.mjs → server.DpUGXBi2.mjs} +84 -51
  51. package/dist/shared/{server.EOHJ3NJr.d.ts → server.DrN1Pj1-.d.ts} +3 -3
  52. package/dist/shared/{server.BsNNjG5J.d.mts → server.DtfwuV6U.d.ts} +24 -12
  53. package/dist/shared/{server.BB_Ik9Ph.d.mts → server.JbCIPL4P.d.mts} +3 -3
  54. package/dist/shared/{server.CjOb6ItT.mjs → server.eCTV8Vpp.mjs} +1 -1
  55. package/package.json +46 -12
  56. package/dist/shared/server.D_QauotT.mjs +0 -30
@@ -1,11 +1,21 @@
1
1
  import { RPCSerializer, AnyORPCError } from '@orpc/client';
2
2
  import { Value, Promisable } from '@orpc/shared';
3
3
  import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standardserver/core';
4
- import { A as AnyProcedure, C as Context } from './server.BL22TloH.js';
5
- import { A as AnyRouter } from './server.Pa0F03f_.js';
4
+ import { A as AnyProcedure, C as Context } from './server.CwrYlF72.js';
5
+ import { A as AnyRouter } from './server.DtfwuV6U.js';
6
6
  import { AnyProcedureContract } from '@orpc/contract';
7
- import { b as StandardHandlerHandleOptions, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure } from './server.EOHJ3NJr.js';
7
+ import { c as StandardHandlerHandleOptions, d as StandardHandlerCodec, e as StandardHandlerCodecResolvedProcedure } from './server.DrN1Pj1-.js';
8
8
 
9
+ /**
10
+ * Methods that can invoke procedures by default. Browsers cannot trigger them
11
+ * cross-site without a CORS preflight or an HTML form, unlike `GET`, which a plain
12
+ * `<a>` click or redirect can trigger with `SameSite=Lax` cookies attached. Other
13
+ * methods (`HEAD`, `OPTIONS`, `QUERY`, ...) have safe semantics that should not
14
+ * invoke a procedure that can modify data.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
17
+ */
18
+ declare const RPC_DEFAULT_ALLOW_METHODS: readonly StandardMethod[];
9
19
  interface RPCMatcherOptions {
10
20
  /**
11
21
  * Filter which procedures are exposed for matching. Return `false` to exclude.
@@ -13,20 +23,34 @@ interface RPCMatcherOptions {
13
23
  * @default true
14
24
  */
15
25
  filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
26
+ /**
27
+ * Restricts which HTTP methods can invoke procedures, either with a list of allowed
28
+ * methods or decided per request via a function. Requests using a disallowed method
29
+ * are treated as unmatched. `GET` is excluded by default because it is exposed to
30
+ * Cross-Site Request Forgery (CSRF) attacks.
31
+ *
32
+ * @default RPC_DEFAULT_ALLOW_METHODS (['POST', 'PUT', 'PATCH', 'DELETE'])
33
+ * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
34
+ */
35
+ allowMethods?: readonly StandardMethod[] | ((method: StandardMethod, procedure: AnyProcedure, path: string[]) => boolean);
16
36
  }
17
37
  declare class RPCMatcher {
18
38
  private readonly filter;
39
+ private readonly allowMethodsSet;
40
+ private readonly allowMethodsFn;
19
41
  private readonly rootRouter;
20
42
  private readonly tree;
21
- private pendingLazyRouters;
43
+ private readonly pendingLazyRouters;
22
44
  constructor(router: AnyRouter, options?: RPCMatcherOptions);
23
45
  private index;
24
- match(_method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
46
+ match(method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
25
47
  path: string[];
26
48
  procedure: AnyProcedure;
27
49
  } | undefined>;
28
- private matchPathname;
29
50
  private resolvePendingLazyRouters;
51
+ private loadPendingLazyRouters;
52
+ private loadPendingLazyRouter;
53
+ private indexPendingLazyRouter;
30
54
  private resolveProcedure;
31
55
  }
32
56
 
@@ -38,14 +62,15 @@ interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
38
62
  /**
39
63
  * Resolve HTTP status for encoded successful outputs.
40
64
  *
41
- * Value should be in range `200-299`
65
+ * Value should be in the `2xx` range and must be less than `400`.
42
66
  * Return `undefined` or `null` to fallback to default
43
67
  *
44
- * @default DEFAULT_ERROR_STATUS, DEFAULT_ERROR_STATUS
68
+ * @default DEFAULT_SUCCESS_STATUS (200)
45
69
  */
46
70
  outputStatus?: Value<number | undefined | null, [output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>]>;
47
71
  /**
48
72
  * Mapping ORPCError Code -> HTTP Status Code
73
+ * The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
49
74
  *
50
75
  * @default COMMON_ERROR_STATUS_MAP
51
76
  */
@@ -62,5 +87,5 @@ declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec
62
87
  encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
63
88
  }
64
89
 
65
- export { RPCHandlerCodec as a, RPCMatcher as b };
90
+ export { RPCHandlerCodec as a, RPCMatcher as b, RPC_DEFAULT_ALLOW_METHODS as d };
66
91
  export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
@@ -0,0 +1,69 @@
1
+ import { ORPCError } from '@orpc/client';
2
+ import { toArray } from '@orpc/shared';
3
+ import { flattenStandardHeader } from '@standardserver/core';
4
+ import { toFetchHeaders, toStandardBody } from '@standardserver/fetch';
5
+
6
+ class RequestLimitHandlerPlugin {
7
+ name = "~request-limit";
8
+ /**
9
+ * Should limit the original batch request body instead of sub-requests.
10
+ */
11
+ after = ["~batch"];
12
+ /**
13
+ * Should limit the final body size instead of the compressed one.
14
+ */
15
+ before = ["~request-compression"];
16
+ maxBodySize;
17
+ constructor(options) {
18
+ this.maxBodySize = options.maxBodySize;
19
+ }
20
+ init(options) {
21
+ const maxBodySize = this.maxBodySize;
22
+ const routingInterceptor = async ({ next, ...interceptorOptions }) => {
23
+ return next({
24
+ ...interceptorOptions,
25
+ request: {
26
+ ...interceptorOptions.request,
27
+ async resolveBody(hint) {
28
+ const contentLength = Number(
29
+ flattenStandardHeader(interceptorOptions.request.headers["content-length"])
30
+ );
31
+ if (Number.isFinite(contentLength) && contentLength > maxBodySize) {
32
+ throw new ORPCError("PAYLOAD_TOO_LARGE");
33
+ }
34
+ const stream = await interceptorOptions.request.resolveBody("octet-stream");
35
+ if (!(stream instanceof ReadableStream)) {
36
+ return stream;
37
+ }
38
+ let currentBodySize = 0;
39
+ const limitedStream = stream.pipeThrough(
40
+ new TransformStream({
41
+ transform(chunk, controller) {
42
+ currentBodySize += chunk.byteLength;
43
+ if (currentBodySize > maxBodySize) {
44
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
45
+ return;
46
+ }
47
+ controller.enqueue(chunk);
48
+ }
49
+ })
50
+ );
51
+ const response = new Response(limitedStream, {
52
+ headers: toFetchHeaders(interceptorOptions.request.headers)
53
+ });
54
+ return toStandardBody(response, { hint });
55
+ }
56
+ }
57
+ });
58
+ };
59
+ return {
60
+ ...options,
61
+ routingInterceptors: [
62
+ routingInterceptor,
63
+ ...toArray(options.routingInterceptors)
64
+ ]
65
+ };
66
+ }
67
+ }
68
+
69
+ export { RequestLimitHandlerPlugin as R };
@@ -1,32 +1,6 @@
1
- import { ORPCError, wrapEventIteratorPreservingMeta, cloneORPCError } from '@orpc/client';
2
- import { reconcileORPCError, ValidationError, ProcedureContract } from '@orpc/contract';
3
- import { getOrBind, resolveMaybeOptionalOptions, getConstructor, isTypescriptObject, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, override, traceAsyncIterator, traceReadableStream } from '@orpc/shared';
4
-
5
- function createORPCErrorConstructorMap(errorMap) {
6
- const proxy = new Proxy(errorMap, {
7
- get(target, code) {
8
- if (typeof code !== "string") {
9
- return getOrBind(target, code);
10
- }
11
- const item = (...rest) => {
12
- const options = resolveMaybeOptionalOptions(rest);
13
- const config = errorMap[code];
14
- const error = new ORPCError(code, {
15
- message: options.message ?? config?.message,
16
- data: options.data,
17
- cause: options.cause
18
- });
19
- if (config) {
20
- error.defined = true;
21
- error.inferable = true;
22
- }
23
- return error;
24
- };
25
- return item;
26
- }
27
- });
28
- return proxy;
29
- }
1
+ import { wrapAsyncIteratorPreservingEventMeta, ORPCError, cloneORPCError } from '@orpc/client';
2
+ import { createORPCErrorConstructorMap, reconcileORPCError, ValidationError, ProcedureContract } from '@orpc/contract';
3
+ import { getConstructor, isTypescriptObject, resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, override, traceAsyncIterator, traceReadableStream, isPlainObject, mergeTwoLevels } from '@orpc/shared';
30
4
 
31
5
  class Lazy {
32
6
  "~orpc";
@@ -34,7 +8,7 @@ class Lazy {
34
8
  this["~orpc"] = def;
35
9
  }
36
10
  /**
37
- * Checks if the given instance satisfies the {@see Lazy} class/interface.
11
+ * Checks if the given instance satisfies the {@link Lazy} class/interface.
38
12
  */
39
13
  static [Symbol.hasInstance](instance) {
40
14
  if (this !== Lazy) {
@@ -84,8 +58,8 @@ function createProcedureClient(lazyableProcedure, ...rest) {
84
58
  );
85
59
  });
86
60
  if (isAsyncIteratorObject(output)) {
87
- return override(output, wrapEventIteratorPreservingMeta(
88
- traceAsyncIterator("consume_event_iterator_output", output),
61
+ return override(output, wrapAsyncIteratorPreservingEventMeta(
62
+ traceAsyncIterator("consume_async_iterator_object_output", output),
89
63
  { mapError: reconcileError }
90
64
  ));
91
65
  }
@@ -151,8 +125,15 @@ async function executeProcedureInternal(procedure, options) {
151
125
  let currentInput = input;
152
126
  const startInputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].inputSchemasLengthAtUse ?? 0;
153
127
  const endInputIndex = midIndex === orderedMiddlewares.length ? inputSchemas.length : orderedMiddlewares[midIndex].inputSchemasLengthAtUse ?? 0;
154
- for (let i = startInputIndex; i < endInputIndex; i++) {
155
- currentInput = await validateInput(i, inputSchemas[i], currentInput);
128
+ if (!procedure["~orpc"].disableInputValidation) {
129
+ for (let i = startInputIndex; i < endInputIndex; i++) {
130
+ const validated = await validateInput(
131
+ i,
132
+ inputSchemas[i],
133
+ inputSchemas.length > 1 && isPlainObject(currentInput) ? options.input : currentInput
134
+ );
135
+ currentInput = i !== 0 ? mergeTwoLevels(currentInput, validated) : validated;
136
+ }
156
137
  }
157
138
  let currentOutput;
158
139
  let currentContext = context;
@@ -201,8 +182,10 @@ async function executeProcedureInternal(procedure, options) {
201
182
  }
202
183
  const startOutputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].outputSchemasLengthAtUse ?? 0;
203
184
  const endOutputIndex = midIndex === orderedMiddlewares.length ? outputSchemas.length : orderedMiddlewares[midIndex].outputSchemasLengthAtUse ?? 0;
204
- for (let i = endOutputIndex - 1; i >= startOutputIndex; i--) {
205
- currentOutput = await validateOutput(i, outputSchemas[i], currentOutput);
185
+ if (!procedure["~orpc"].disableOutputValidation) {
186
+ for (let i = endOutputIndex - 1; i >= startOutputIndex; i--) {
187
+ currentOutput = await validateOutput(i, outputSchemas[i], currentOutput);
188
+ }
206
189
  }
207
190
  return { output: currentOutput, context: currentContext };
208
191
  };
@@ -216,7 +199,7 @@ class Procedure {
216
199
  this["~orpc"] = def;
217
200
  }
218
201
  /**
219
- * Checks if the given instance satisfies the {@see Procedure} class/interface.
202
+ * Checks if the given instance satisfies the {@link Procedure} class/interface.
220
203
  */
221
204
  static [Symbol.hasInstance](instance) {
222
205
  if (this !== Procedure) {
@@ -230,4 +213,4 @@ class Procedure {
230
213
  }
231
214
  }
232
215
 
233
- export { Lazy as L, Procedure as P, createORPCErrorConstructorMap as a, createProcedureClient as c, unlazy as u };
216
+ export { Lazy as L, Procedure as P, createProcedureClient as c, unlazy as u };
@@ -1,11 +1,21 @@
1
1
  import { RPCSerializer, AnyORPCError } from '@orpc/client';
2
2
  import { Value, Promisable } from '@orpc/shared';
3
3
  import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standardserver/core';
4
- import { A as AnyProcedure, C as Context } from './server.BL22TloH.mjs';
5
- import { A as AnyRouter } from './server.BsNNjG5J.mjs';
4
+ import { A as AnyProcedure, C as Context } from './server.CwrYlF72.mjs';
5
+ import { A as AnyRouter } from './server.Dm0os-OP.mjs';
6
6
  import { AnyProcedureContract } from '@orpc/contract';
7
- import { b as StandardHandlerHandleOptions, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure } from './server.BB_Ik9Ph.mjs';
7
+ import { c as StandardHandlerHandleOptions, d as StandardHandlerCodec, e as StandardHandlerCodecResolvedProcedure } from './server.JbCIPL4P.mjs';
8
8
 
9
+ /**
10
+ * Methods that can invoke procedures by default. Browsers cannot trigger them
11
+ * cross-site without a CORS preflight or an HTML form, unlike `GET`, which a plain
12
+ * `<a>` click or redirect can trigger with `SameSite=Lax` cookies attached. Other
13
+ * methods (`HEAD`, `OPTIONS`, `QUERY`, ...) have safe semantics that should not
14
+ * invoke a procedure that can modify data.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
17
+ */
18
+ declare const RPC_DEFAULT_ALLOW_METHODS: readonly StandardMethod[];
9
19
  interface RPCMatcherOptions {
10
20
  /**
11
21
  * Filter which procedures are exposed for matching. Return `false` to exclude.
@@ -13,20 +23,34 @@ interface RPCMatcherOptions {
13
23
  * @default true
14
24
  */
15
25
  filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
26
+ /**
27
+ * Restricts which HTTP methods can invoke procedures, either with a list of allowed
28
+ * methods or decided per request via a function. Requests using a disallowed method
29
+ * are treated as unmatched. `GET` is excluded by default because it is exposed to
30
+ * Cross-Site Request Forgery (CSRF) attacks.
31
+ *
32
+ * @default RPC_DEFAULT_ALLOW_METHODS (['POST', 'PUT', 'PATCH', 'DELETE'])
33
+ * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
34
+ */
35
+ allowMethods?: readonly StandardMethod[] | ((method: StandardMethod, procedure: AnyProcedure, path: string[]) => boolean);
16
36
  }
17
37
  declare class RPCMatcher {
18
38
  private readonly filter;
39
+ private readonly allowMethodsSet;
40
+ private readonly allowMethodsFn;
19
41
  private readonly rootRouter;
20
42
  private readonly tree;
21
- private pendingLazyRouters;
43
+ private readonly pendingLazyRouters;
22
44
  constructor(router: AnyRouter, options?: RPCMatcherOptions);
23
45
  private index;
24
- match(_method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
46
+ match(method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
25
47
  path: string[];
26
48
  procedure: AnyProcedure;
27
49
  } | undefined>;
28
- private matchPathname;
29
50
  private resolvePendingLazyRouters;
51
+ private loadPendingLazyRouters;
52
+ private loadPendingLazyRouter;
53
+ private indexPendingLazyRouter;
30
54
  private resolveProcedure;
31
55
  }
32
56
 
@@ -38,14 +62,15 @@ interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
38
62
  /**
39
63
  * Resolve HTTP status for encoded successful outputs.
40
64
  *
41
- * Value should be in range `200-299`
65
+ * Value should be in the `2xx` range and must be less than `400`.
42
66
  * Return `undefined` or `null` to fallback to default
43
67
  *
44
- * @default DEFAULT_ERROR_STATUS, DEFAULT_ERROR_STATUS
68
+ * @default DEFAULT_SUCCESS_STATUS (200)
45
69
  */
46
70
  outputStatus?: Value<number | undefined | null, [output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>]>;
47
71
  /**
48
72
  * Mapping ORPCError Code -> HTTP Status Code
73
+ * The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
49
74
  *
50
75
  * @default COMMON_ERROR_STATUS_MAP
51
76
  */
@@ -62,5 +87,5 @@ declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec
62
87
  encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
63
88
  }
64
89
 
65
- export { RPCHandlerCodec as a, RPCMatcher as b };
90
+ export { RPCHandlerCodec as a, RPCMatcher as b, RPC_DEFAULT_ALLOW_METHODS as d };
66
91
  export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
@@ -1,5 +1,5 @@
1
- import { ORPCErrorCode, ORPCErrorOptions, ORPCError, AnyORPCError, ClientContext, Client } from '@orpc/client';
2
- import { ErrorMap, ErrorMapItem, InferSchemaInput, AnyMetaPlugin, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
1
+ import { AnyORPCError, ClientContext, Client } from '@orpc/client';
2
+ import { ErrorMap, AnyMetaPlugin, ORPCErrorConstructorMap, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap, InferSchemaInput } from '@orpc/contract';
3
3
  import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
4
4
 
5
5
  interface Context {
@@ -8,40 +8,6 @@ interface Context {
8
8
  type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & Omit<TInContext, keyof TInitial | keyof TOutContext>;
9
9
  type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : Omit<TCurrent, keyof TOutContext> & TOutContext;
10
10
 
11
- type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
12
- interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
13
- (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
14
- }
15
- type ORPCErrorConstructorMap<T extends ErrorMap> = {
16
- [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
17
- };
18
- /**
19
- * Creates a map of ORPC error constructors.
20
- *
21
- * The returned object is a `Proxy` that allows access to arbitrary error codes:
22
- * - If the code exists in the provided `errorMap`, the corresponding constructor
23
- * will create a **defined** `ORPCError`.
24
- * - If the code does not exist, a fallback `ORPCError` constructor is returned.
25
- *
26
- * The `in` operator can be used to check whether an error code is explicitly
27
- * defined in the map.
28
- *
29
- * @example
30
- * ```ts
31
- * const errorMap = createORPCErrorConstructorMap({
32
- * NOT_FOUND: {
33
- * status: 404,
34
- * message: 'Not Found',
35
- * },
36
- * })
37
- *
38
- * if ('NOT_FOUND' in errorMap) {
39
- * const error = errorMap.NOT_FOUND()
40
- * }
41
- * ```
42
- */
43
- declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
44
-
45
11
  type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
46
12
  output: TOutput;
47
13
  context: TOutContext;
@@ -119,7 +85,31 @@ interface OrderedMiddleware {
119
85
  outputSchemasLengthAtUse?: number | undefined;
120
86
  middleware: AnyMiddleware;
121
87
  }
122
- interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap> {
88
+ interface ProcedureConfig {
89
+ /**
90
+ * When enabled, input schemas are not validated at runtime.
91
+ * Schemas are still used for type inference and OpenAPI generation.
92
+ *
93
+ * @remarks
94
+ * **Warning**: Do not disable validation for schemas that transform values.
95
+ *
96
+ * @default false
97
+ */
98
+ disableInputValidation?: boolean | undefined;
99
+ /**
100
+ * When enabled, output schemas are not validated at runtime.
101
+ * Schemas are still used for type inference and OpenAPI generation.
102
+ *
103
+ * Useful when output schemas exist only for specification generation.
104
+ *
105
+ * @remarks
106
+ * **Warning**: Do not disable validation for schemas that transform values.
107
+ *
108
+ * @default false
109
+ */
110
+ disableOutputValidation?: boolean | undefined;
111
+ }
112
+ interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>, ProcedureConfig {
123
113
  __TInitialContext?: (type: TInitialContext) => unknown;
124
114
  __TInjectedContext?: (type: TInjectedContext) => unknown;
125
115
  __TReturnedError?: () => TReturnedError;
@@ -140,7 +130,7 @@ declare class Procedure<TInitialContext extends Context, TInjectedContext extend
140
130
  '~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
141
131
  constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>);
142
132
  /**
143
- * Checks if the given instance satisfies the {@see Procedure} class/interface.
133
+ * Checks if the given instance satisfies the {@link Procedure} class/interface.
144
134
  */
145
135
  static [Symbol.hasInstance](instance: unknown): boolean;
146
136
  }
@@ -157,7 +147,7 @@ declare class Lazy<T> {
157
147
  '~orpc': LazyDefinition<T>;
158
148
  constructor(def: LazyDefinition<T>);
159
149
  /**
160
- * Checks if the given instance satisfies the {@see Lazy} class/interface.
150
+ * Checks if the given instance satisfies the {@link Lazy} class/interface.
161
151
  */
162
152
  static [Symbol.hasInstance](instance: unknown): boolean;
163
153
  }
@@ -180,5 +170,5 @@ type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema exten
180
170
  });
181
171
  declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
182
172
 
183
- export { Procedure as a, Lazy as g, createORPCErrorConstructorMap as w, createProcedureClient as x, unlazy as y };
184
- export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, ORPCErrorConstructorMap as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, AnyMiddleware as f, ProcedureHandler as h, OrderedMiddleware as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ORPCErrorConstructorMapItem as r, ORPCErrorConstructorMapItemOptions as s, ProcedureClientInterceptorOptions as t, ProcedureDefinition as u, ProcedureHandlerOptions as v };
173
+ export { Procedure as a, Lazy as h, createProcedureClient as u, unlazy as v };
174
+ export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, OrderedMiddleware as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ProcedureClientInterceptorOptions as r, ProcedureDefinition as s, ProcedureHandlerOptions as t };
@@ -1,5 +1,5 @@
1
- import { ORPCErrorCode, ORPCErrorOptions, ORPCError, AnyORPCError, ClientContext, Client } from '@orpc/client';
2
- import { ErrorMap, ErrorMapItem, InferSchemaInput, AnyMetaPlugin, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
1
+ import { AnyORPCError, ClientContext, Client } from '@orpc/client';
2
+ import { ErrorMap, AnyMetaPlugin, ORPCErrorConstructorMap, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap, InferSchemaInput } from '@orpc/contract';
3
3
  import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
4
4
 
5
5
  interface Context {
@@ -8,40 +8,6 @@ interface Context {
8
8
  type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & Omit<TInContext, keyof TInitial | keyof TOutContext>;
9
9
  type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : Omit<TCurrent, keyof TOutContext> & TOutContext;
10
10
 
11
- type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
12
- interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
13
- (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
14
- }
15
- type ORPCErrorConstructorMap<T extends ErrorMap> = {
16
- [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
17
- };
18
- /**
19
- * Creates a map of ORPC error constructors.
20
- *
21
- * The returned object is a `Proxy` that allows access to arbitrary error codes:
22
- * - If the code exists in the provided `errorMap`, the corresponding constructor
23
- * will create a **defined** `ORPCError`.
24
- * - If the code does not exist, a fallback `ORPCError` constructor is returned.
25
- *
26
- * The `in` operator can be used to check whether an error code is explicitly
27
- * defined in the map.
28
- *
29
- * @example
30
- * ```ts
31
- * const errorMap = createORPCErrorConstructorMap({
32
- * NOT_FOUND: {
33
- * status: 404,
34
- * message: 'Not Found',
35
- * },
36
- * })
37
- *
38
- * if ('NOT_FOUND' in errorMap) {
39
- * const error = errorMap.NOT_FOUND()
40
- * }
41
- * ```
42
- */
43
- declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
44
-
45
11
  type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
46
12
  output: TOutput;
47
13
  context: TOutContext;
@@ -119,7 +85,31 @@ interface OrderedMiddleware {
119
85
  outputSchemasLengthAtUse?: number | undefined;
120
86
  middleware: AnyMiddleware;
121
87
  }
122
- interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap> {
88
+ interface ProcedureConfig {
89
+ /**
90
+ * When enabled, input schemas are not validated at runtime.
91
+ * Schemas are still used for type inference and OpenAPI generation.
92
+ *
93
+ * @remarks
94
+ * **Warning**: Do not disable validation for schemas that transform values.
95
+ *
96
+ * @default false
97
+ */
98
+ disableInputValidation?: boolean | undefined;
99
+ /**
100
+ * When enabled, output schemas are not validated at runtime.
101
+ * Schemas are still used for type inference and OpenAPI generation.
102
+ *
103
+ * Useful when output schemas exist only for specification generation.
104
+ *
105
+ * @remarks
106
+ * **Warning**: Do not disable validation for schemas that transform values.
107
+ *
108
+ * @default false
109
+ */
110
+ disableOutputValidation?: boolean | undefined;
111
+ }
112
+ interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>, ProcedureConfig {
123
113
  __TInitialContext?: (type: TInitialContext) => unknown;
124
114
  __TInjectedContext?: (type: TInjectedContext) => unknown;
125
115
  __TReturnedError?: () => TReturnedError;
@@ -140,7 +130,7 @@ declare class Procedure<TInitialContext extends Context, TInjectedContext extend
140
130
  '~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
141
131
  constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>);
142
132
  /**
143
- * Checks if the given instance satisfies the {@see Procedure} class/interface.
133
+ * Checks if the given instance satisfies the {@link Procedure} class/interface.
144
134
  */
145
135
  static [Symbol.hasInstance](instance: unknown): boolean;
146
136
  }
@@ -157,7 +147,7 @@ declare class Lazy<T> {
157
147
  '~orpc': LazyDefinition<T>;
158
148
  constructor(def: LazyDefinition<T>);
159
149
  /**
160
- * Checks if the given instance satisfies the {@see Lazy} class/interface.
150
+ * Checks if the given instance satisfies the {@link Lazy} class/interface.
161
151
  */
162
152
  static [Symbol.hasInstance](instance: unknown): boolean;
163
153
  }
@@ -180,5 +170,5 @@ type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema exten
180
170
  });
181
171
  declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
182
172
 
183
- export { Procedure as a, Lazy as g, createORPCErrorConstructorMap as w, createProcedureClient as x, unlazy as y };
184
- export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, ORPCErrorConstructorMap as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, AnyMiddleware as f, ProcedureHandler as h, OrderedMiddleware as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ORPCErrorConstructorMapItem as r, ORPCErrorConstructorMapItemOptions as s, ProcedureClientInterceptorOptions as t, ProcedureDefinition as u, ProcedureHandlerOptions as v };
173
+ export { Procedure as a, Lazy as h, createProcedureClient as u, unlazy as v };
174
+ export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, OrderedMiddleware as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ProcedureClientInterceptorOptions as r, ProcedureDefinition as s, ProcedureHandlerOptions as t };
@@ -0,0 +1,34 @@
1
+ import { C as Context } from './server.CwrYlF72.mjs';
2
+ import { S as StandardHandlerPlugin, a as StandardHandlerOptions } from './server.JbCIPL4P.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 };