@orpc/server 2.0.0-beta.23 → 2.0.0-beta.25

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 (55) hide show
  1. package/README.md +4 -1
  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 +10 -4
  6. package/dist/adapters/crossws/index.d.ts +10 -4
  7. package/dist/adapters/crossws/index.mjs +3 -3
  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 +13 -16
  12. package/dist/adapters/fetch/index.d.ts +13 -16
  13. package/dist/adapters/fetch/index.mjs +6 -12
  14. package/dist/adapters/message-port/index.d.mts +12 -7
  15. package/dist/adapters/message-port/index.d.ts +12 -7
  16. package/dist/adapters/message-port/index.mjs +3 -3
  17. package/dist/adapters/node/index.d.mts +12 -16
  18. package/dist/adapters/node/index.d.ts +12 -16
  19. package/dist/adapters/node/index.mjs +7 -12
  20. package/dist/adapters/standard/index.d.mts +5 -5
  21. package/dist/adapters/standard/index.d.ts +5 -5
  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 +10 -4
  26. package/dist/adapters/websocket/index.d.ts +10 -4
  27. package/dist/adapters/websocket/index.mjs +3 -3
  28. package/dist/extensions/callable.d.mts +1 -1
  29. package/dist/extensions/callable.d.ts +1 -1
  30. package/dist/extensions/callable.mjs +2 -2
  31. package/dist/helpers/index.d.mts +20 -3
  32. package/dist/helpers/index.d.ts +20 -3
  33. package/dist/index.d.mts +39 -7
  34. package/dist/index.d.ts +39 -7
  35. package/dist/index.mjs +23 -18
  36. package/dist/plugins/index.d.mts +59 -48
  37. package/dist/plugins/index.d.ts +59 -48
  38. package/dist/plugins/index.mjs +34 -67
  39. package/dist/shared/{server.DofEOwf-.mjs → server.7T18Khvf.mjs} +6 -32
  40. package/dist/shared/{server.DBs0rrf9.mjs → server.B2pXdfpL.mjs} +1 -1
  41. package/dist/shared/server.BhHrioCw.d.ts +34 -0
  42. package/dist/shared/{server.DG9aQpJK.d.ts → server.C2n16pp0.d.ts} +27 -5
  43. package/dist/shared/{server.A8J9H8OE.mjs → server.Cbv46U7N.mjs} +21 -5
  44. package/dist/shared/server.Cd4Z1hpV.mjs +69 -0
  45. package/dist/shared/{server.omY4cUs0.d.mts → server.CkNnZ5F-.d.mts} +27 -5
  46. package/dist/shared/{server.CcR4kgje.d.ts → server.CwrYlF72.d.mts} +10 -42
  47. package/dist/shared/{server.CcR4kgje.d.mts → server.CwrYlF72.d.ts} +10 -42
  48. package/dist/shared/server.D0Ipbmdv.d.mts +34 -0
  49. package/dist/shared/{server.D4cnq66J.mjs → server.DgunZU0v.mjs} +3 -3
  50. package/dist/shared/{server.m3szVJGU.d.ts → server.Dm0os-OP.d.mts} +24 -12
  51. package/dist/shared/{server.BhsVw7m7.d.ts → server.DrN1Pj1-.d.ts} +3 -3
  52. package/dist/shared/{server.15O7oC1p.d.mts → server.DtfwuV6U.d.ts} +24 -12
  53. package/dist/shared/{server.DDFizwfU.d.mts → server.JbCIPL4P.d.mts} +3 -3
  54. package/package.json +26 -9
  55. 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.CcR4kgje.mjs';
5
- import { A as AnyRouter } from './server.15O7oC1p.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.DDFizwfU.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,15 +23,27 @@ 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
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>;
@@ -65,5 +87,5 @@ declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec
65
87
  encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
66
88
  }
67
89
 
68
- export { RPCHandlerCodec as a, RPCMatcher as b };
90
+ export { RPCHandlerCodec as a, RPCMatcher as b, RPC_DEFAULT_ALLOW_METHODS as d };
69
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;
@@ -124,7 +90,8 @@ interface ProcedureConfig {
124
90
  * When enabled, input schemas are not validated at runtime.
125
91
  * Schemas are still used for type inference and OpenAPI generation.
126
92
  *
127
- * @warning Do not disable validation for schemas that transform values.
93
+ * @remarks
94
+ * **Warning**: Do not disable validation for schemas that transform values.
128
95
  *
129
96
  * @default false
130
97
  */
@@ -135,7 +102,8 @@ interface ProcedureConfig {
135
102
  *
136
103
  * Useful when output schemas exist only for specification generation.
137
104
  *
138
- * @warning Do not disable validation for schemas that transform values.
105
+ * @remarks
106
+ * **Warning**: Do not disable validation for schemas that transform values.
139
107
  *
140
108
  * @default false
141
109
  */
@@ -162,7 +130,7 @@ declare class Procedure<TInitialContext extends Context, TInjectedContext extend
162
130
  '~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
163
131
  constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>);
164
132
  /**
165
- * Checks if the given instance satisfies the {@see Procedure} class/interface.
133
+ * Checks if the given instance satisfies the {@link Procedure} class/interface.
166
134
  */
167
135
  static [Symbol.hasInstance](instance: unknown): boolean;
168
136
  }
@@ -179,7 +147,7 @@ declare class Lazy<T> {
179
147
  '~orpc': LazyDefinition<T>;
180
148
  constructor(def: LazyDefinition<T>);
181
149
  /**
182
- * Checks if the given instance satisfies the {@see Lazy} class/interface.
150
+ * Checks if the given instance satisfies the {@link Lazy} class/interface.
183
151
  */
184
152
  static [Symbol.hasInstance](instance: unknown): boolean;
185
153
  }
@@ -202,5 +170,5 @@ type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema exten
202
170
  });
203
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>;
204
172
 
205
- export { Procedure as a, Lazy as h, createORPCErrorConstructorMap as x, createProcedureClient as y, unlazy as z };
206
- 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, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, OrderedMiddleware as j, LazyDefinition as k, MiddlewareDefinition as l, MiddlewareDone as m, MiddlewareDoneOptions as n, MiddlewareNext as o, MiddlewareNextOptions as p, MiddlewareOptions as q, MiddlewareResult as r, ORPCErrorConstructorMapItem as s, ORPCErrorConstructorMapItemOptions as t, ProcedureClientInterceptorOptions as u, ProcedureDefinition as v, ProcedureHandlerOptions as w };
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;
@@ -124,7 +90,8 @@ interface ProcedureConfig {
124
90
  * When enabled, input schemas are not validated at runtime.
125
91
  * Schemas are still used for type inference and OpenAPI generation.
126
92
  *
127
- * @warning Do not disable validation for schemas that transform values.
93
+ * @remarks
94
+ * **Warning**: Do not disable validation for schemas that transform values.
128
95
  *
129
96
  * @default false
130
97
  */
@@ -135,7 +102,8 @@ interface ProcedureConfig {
135
102
  *
136
103
  * Useful when output schemas exist only for specification generation.
137
104
  *
138
- * @warning Do not disable validation for schemas that transform values.
105
+ * @remarks
106
+ * **Warning**: Do not disable validation for schemas that transform values.
139
107
  *
140
108
  * @default false
141
109
  */
@@ -162,7 +130,7 @@ declare class Procedure<TInitialContext extends Context, TInjectedContext extend
162
130
  '~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
163
131
  constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>);
164
132
  /**
165
- * Checks if the given instance satisfies the {@see Procedure} class/interface.
133
+ * Checks if the given instance satisfies the {@link Procedure} class/interface.
166
134
  */
167
135
  static [Symbol.hasInstance](instance: unknown): boolean;
168
136
  }
@@ -179,7 +147,7 @@ declare class Lazy<T> {
179
147
  '~orpc': LazyDefinition<T>;
180
148
  constructor(def: LazyDefinition<T>);
181
149
  /**
182
- * Checks if the given instance satisfies the {@see Lazy} class/interface.
150
+ * Checks if the given instance satisfies the {@link Lazy} class/interface.
183
151
  */
184
152
  static [Symbol.hasInstance](instance: unknown): boolean;
185
153
  }
@@ -202,5 +170,5 @@ type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema exten
202
170
  });
203
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>;
204
172
 
205
- export { Procedure as a, Lazy as h, createORPCErrorConstructorMap as x, createProcedureClient as y, unlazy as z };
206
- 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, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, OrderedMiddleware as j, LazyDefinition as k, MiddlewareDefinition as l, MiddlewareDone as m, MiddlewareDoneOptions as n, MiddlewareNext as o, MiddlewareNextOptions as p, MiddlewareOptions as q, MiddlewareResult as r, ORPCErrorConstructorMapItem as s, ORPCErrorConstructorMapItemOptions as t, ProcedureClientInterceptorOptions as u, ProcedureDefinition as v, ProcedureHandlerOptions as w };
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 };
@@ -1,6 +1,6 @@
1
- import { c as createProcedureClient, P as Procedure, L as Lazy, u as unlazy } from './server.DofEOwf-.mjs';
1
+ import { c as createProcedureClient, P as Procedure, L as Lazy, u as unlazy } from './server.7T18Khvf.mjs';
2
2
  import { resolveMetaPlugins, mergeErrorMap, ProcedureContract } from '@orpc/contract';
3
- import { getOrBind, omit, 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
  }
@@ -1,5 +1,5 @@
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.CcR4kgje.js';
2
+ import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.CwrYlF72.mjs';
3
3
 
4
4
  type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any, any> | {
5
5
  [k: string]: Lazyable<Router<TInitialContext>>;
@@ -12,8 +12,10 @@ 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
20
  type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
19
21
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
@@ -21,41 +23,51 @@ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer
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
31
  type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, 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
42
  type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, 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
53
  type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, 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
61
  type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | 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
69
  type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | 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 };
@@ -1,7 +1,7 @@
1
1
  import { AnyORPCError } from '@orpc/client';
2
2
  import { OrderablePlugin, Interceptor, Promisable } from '@orpc/shared';
3
3
  import { StandardLazyRequest, StandardResponse } from '@standardserver/core';
4
- import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.CcR4kgje.js';
4
+ import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.CwrYlF72.js';
5
5
  import { Schema, ErrorMap } from '@orpc/contract';
6
6
 
7
7
  interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
@@ -100,5 +100,5 @@ interface StandardHandlerCodec<T extends Context> {
100
100
  encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
101
101
  }
102
102
 
103
- export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, StandardHandler as S };
104
- export type { StandardHandlerOptions as a, StandardHandlerHandleOptions as b, StandardHandlerCodec as c, StandardHandlerCodecResolvedProcedure as d, StandardHandlerPlugin as e, StandardHandlerRoutingInterceptorOptions as f, StandardHandlerInterceptorOptions as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
103
+ export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, StandardHandler as b };
104
+ export type { StandardHandlerPlugin as S, StandardHandlerOptions as a, StandardHandlerHandleOptions as c, StandardHandlerCodec as d, StandardHandlerCodecResolvedProcedure as e, StandardHandlerRoutingInterceptorOptions as f, StandardHandlerInterceptorOptions as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
@@ -1,5 +1,5 @@
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.CcR4kgje.mjs';
2
+ import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.CwrYlF72.js';
3
3
 
4
4
  type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any, any> | {
5
5
  [k: string]: Lazyable<Router<TInitialContext>>;
@@ -12,8 +12,10 @@ 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
20
  type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
19
21
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
@@ -21,41 +23,51 @@ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer
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
31
  type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, 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
42
  type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, 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
53
  type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, 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
61
  type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | 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
69
  type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | 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 };
@@ -1,7 +1,7 @@
1
1
  import { AnyORPCError } from '@orpc/client';
2
2
  import { OrderablePlugin, Interceptor, Promisable } from '@orpc/shared';
3
3
  import { StandardLazyRequest, StandardResponse } from '@standardserver/core';
4
- import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.CcR4kgje.mjs';
4
+ import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.CwrYlF72.mjs';
5
5
  import { Schema, ErrorMap } from '@orpc/contract';
6
6
 
7
7
  interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
@@ -100,5 +100,5 @@ interface StandardHandlerCodec<T extends Context> {
100
100
  encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
101
101
  }
102
102
 
103
- export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, StandardHandler as S };
104
- export type { StandardHandlerOptions as a, StandardHandlerHandleOptions as b, StandardHandlerCodec as c, StandardHandlerCodecResolvedProcedure as d, StandardHandlerPlugin as e, StandardHandlerRoutingInterceptorOptions as f, StandardHandlerInterceptorOptions as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
103
+ export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, StandardHandler as b };
104
+ export type { StandardHandlerPlugin as S, StandardHandlerOptions as a, StandardHandlerHandleOptions as c, StandardHandlerCodec as d, StandardHandlerCodecResolvedProcedure as e, StandardHandlerRoutingInterceptorOptions as f, StandardHandlerInterceptorOptions as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.23",
4
+ "version": "2.0.0-beta.25",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.dev",
7
7
  "repository": {
@@ -52,6 +52,16 @@
52
52
  "import": "./dist/adapters/node/index.mjs",
53
53
  "default": "./dist/adapters/node/index.mjs"
54
54
  },
55
+ "./aws-lambda": {
56
+ "types": "./dist/adapters/aws-lambda/index.d.mts",
57
+ "import": "./dist/adapters/aws-lambda/index.mjs",
58
+ "default": "./dist/adapters/aws-lambda/index.mjs"
59
+ },
60
+ "./fastify": {
61
+ "types": "./dist/adapters/fastify/index.d.mts",
62
+ "import": "./dist/adapters/fastify/index.mjs",
63
+ "default": "./dist/adapters/fastify/index.mjs"
64
+ },
55
65
  "./websocket": {
56
66
  "types": "./dist/adapters/websocket/index.d.mts",
57
67
  "import": "./dist/adapters/websocket/index.mjs",
@@ -77,25 +87,32 @@
77
87
  "dist"
78
88
  ],
79
89
  "peerDependencies": {
80
- "crossws": ">=0.3.4"
90
+ "crossws": ">=0.3.4",
91
+ "fastify": ">=5.6.1"
81
92
  },
82
93
  "peerDependenciesMeta": {
83
94
  "crossws": {
84
95
  "optional": true
96
+ },
97
+ "fastify": {
98
+ "optional": true
85
99
  }
86
100
  },
87
101
  "dependencies": {
88
- "@standardserver/core": "^0.6.0",
89
- "@standardserver/fetch": "^0.6.0",
90
- "@standardserver/node": "^0.6.0",
91
- "@standardserver/peer": "^0.6.0",
102
+ "@standardserver/aws-lambda": "^0.7.1",
103
+ "@standardserver/core": "^0.7.1",
104
+ "@standardserver/fastify": "^0.7.1",
105
+ "@standardserver/fetch": "^0.7.1",
106
+ "@standardserver/node": "^0.7.1",
107
+ "@standardserver/peer": "^0.7.1",
92
108
  "cookie": "^2.0.1",
93
- "@orpc/client": "2.0.0-beta.23",
94
- "@orpc/shared": "2.0.0-beta.23",
95
- "@orpc/contract": "2.0.0-beta.23"
109
+ "@orpc/client": "2.0.0-beta.25",
110
+ "@orpc/contract": "2.0.0-beta.25",
111
+ "@orpc/shared": "2.0.0-beta.25"
96
112
  },
97
113
  "devDependencies": {
98
114
  "crossws": "^0.4.6",
115
+ "fastify": "^5.11.0",
99
116
  "supertest": "^7.2.2",
100
117
  "zod": "^4.4.3"
101
118
  },
@@ -1,30 +0,0 @@
1
- import { ORPCError } from '@orpc/client';
2
- import { toArray } from '@orpc/shared';
3
- import { flattenStandardHeader } from '@standardserver/core';
4
-
5
- class CSRFGuardHandlerPlugin {
6
- name = "~csrf-guard";
7
- init(options) {
8
- const interceptor = async (interceptorOptions) => {
9
- const mode = flattenStandardHeader(
10
- interceptorOptions.request.headers["sec-fetch-mode"]
11
- )?.toLowerCase();
12
- if (mode === void 0) {
13
- return interceptorOptions.next();
14
- }
15
- if (mode === "cors" || mode === "same-origin") {
16
- return interceptorOptions.next();
17
- }
18
- throw new ORPCError("FORBIDDEN", {
19
- message: "Request blocked by CSRF protection."
20
- });
21
- };
22
- return {
23
- ...options,
24
- // appended last so user's interceptors can catch ORPCError
25
- interceptors: [...toArray(options.interceptors), interceptor]
26
- };
27
- }
28
- }
29
-
30
- export { CSRFGuardHandlerPlugin as C };