@orpc/server 0.52.0 → 0.54.0

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 (36) hide show
  1. package/dist/adapters/fetch/index.d.mts +13 -8
  2. package/dist/adapters/fetch/index.d.ts +13 -8
  3. package/dist/adapters/fetch/index.mjs +104 -8
  4. package/dist/adapters/node/index.d.mts +13 -8
  5. package/dist/adapters/node/index.d.ts +13 -8
  6. package/dist/adapters/node/index.mjs +17 -12
  7. package/dist/adapters/standard/index.d.mts +4 -4
  8. package/dist/adapters/standard/index.d.ts +4 -4
  9. package/dist/adapters/standard/index.mjs +6 -4
  10. package/dist/index.d.mts +7 -6
  11. package/dist/index.d.ts +7 -6
  12. package/dist/index.mjs +7 -7
  13. package/dist/plugins/index.d.mts +101 -6
  14. package/dist/plugins/index.d.ts +101 -6
  15. package/dist/plugins/index.mjs +147 -2
  16. package/dist/shared/{server.CzxlqYZL.d.mts → server.B1oIHH_j.d.mts} +13 -5
  17. package/dist/shared/{server.DLt5njUb.d.mts → server.BVHsfJ99.d.mts} +3 -2
  18. package/dist/shared/{server.DLt5njUb.d.ts → server.BVHsfJ99.d.ts} +3 -2
  19. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  20. package/dist/shared/server.BuLPHTX1.d.mts +18 -0
  21. package/dist/shared/{server.e3W6AG3-.mjs → server.C37gDhSZ.mjs} +16 -22
  22. package/dist/shared/{server.BHlRCrf_.d.ts → server.CaWivVk3.d.ts} +13 -5
  23. package/dist/shared/{server.Dfx1jV-K.mjs → server.DFuJLDuo.mjs} +43 -14
  24. package/dist/shared/{server.Cud5qk0c.d.ts → server.DMhSfHk1.d.ts} +2 -2
  25. package/dist/shared/server.D_vpYits.d.ts +18 -0
  26. package/dist/shared/{server.DGnN7q3R.d.mts → server.Dwnm6cSk.d.mts} +2 -2
  27. package/package.json +8 -22
  28. package/dist/adapters/hono/index.d.mts +0 -22
  29. package/dist/adapters/hono/index.d.ts +0 -22
  30. package/dist/adapters/hono/index.mjs +0 -32
  31. package/dist/adapters/next/index.d.mts +0 -29
  32. package/dist/adapters/next/index.d.ts +0 -29
  33. package/dist/adapters/next/index.mjs +0 -29
  34. package/dist/shared/server.B77ImKAP.d.mts +0 -8
  35. package/dist/shared/server.DUF89eb-.d.ts +0 -8
  36. package/dist/shared/server.T5WmDoWQ.mjs +0 -98
@@ -1,9 +1,46 @@
1
- import { b as StandardHandlerInterceptorOptions, c as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.BHlRCrf_.js';
2
1
  import { Value } from '@orpc/shared';
3
- import { C as Context } from '../shared/server.DLt5njUb.js';
4
- import '@orpc/client';
5
- import '@orpc/contract';
6
- import '@orpc/standard-server';
2
+ import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
+ import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CaWivVk3.js';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.BVHsfJ99.js';
6
+ import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
+ import { ORPCError } from '@orpc/client';
8
+
9
+ interface BatchHandlerOptions<T extends Context> {
10
+ /**
11
+ * The max size of the batch allowed.
12
+ *
13
+ * @default 10
14
+ */
15
+ maxSize?: Value<number, [StandardHandlerInterceptorOptions<T>]>;
16
+ /**
17
+ * Map the request before processing it.
18
+ *
19
+ * @default merged back batch request headers into the request
20
+ */
21
+ mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
22
+ /**
23
+ * Success batch response status code.
24
+ *
25
+ * @default 207
26
+ */
27
+ successStatus?: Value<number, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
28
+ /**
29
+ * success batch response headers.
30
+ *
31
+ * @default {}
32
+ */
33
+ headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
34
+ }
35
+ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
+ private readonly maxSize;
37
+ private readonly mapRequestItem;
38
+ private readonly successStatus;
39
+ private readonly headers;
40
+ order: number;
41
+ constructor(options?: BatchHandlerOptions<T>);
42
+ init(options: StandardHandlerOptions<T>): void;
43
+ }
7
44
 
8
45
  interface CORSOptions<T extends Context> {
9
46
  origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
@@ -16,6 +53,7 @@ interface CORSOptions<T extends Context> {
16
53
  }
17
54
  declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
18
55
  private readonly options;
56
+ order: number;
19
57
  constructor(options?: CORSOptions<T>);
20
58
  init(options: StandardHandlerOptions<T>): void;
21
59
  }
@@ -27,4 +65,61 @@ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> impl
27
65
  init(options: StandardHandlerOptions<T>): void;
28
66
  }
29
67
 
30
- export { type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
68
+ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
69
+ /**
70
+ * The name of the header to check.
71
+ *
72
+ * @default 'x-csrf-token'
73
+ */
74
+ headerName?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
75
+ /**
76
+ * The value of the header to check.
77
+ *
78
+ * @default 'orpc'
79
+ *
80
+ */
81
+ headerValue?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
82
+ /**
83
+ * Exclude a procedure from the plugin.
84
+ *
85
+ * @default false
86
+ *
87
+ */
88
+ exclude?: Value<boolean, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
89
+ /**
90
+ * The error thrown when the CSRF token is invalid.
91
+ *
92
+ * @default new ORPCError('CSRF_TOKEN_MISMATCH', {
93
+ * status: 403,
94
+ * message: 'Invalid CSRF token',
95
+ * })
96
+ */
97
+ error?: InstanceType<typeof ORPCError>;
98
+ }
99
+ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
100
+ private readonly headerName;
101
+ private readonly headerValue;
102
+ private readonly exclude;
103
+ private readonly error;
104
+ constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
105
+ order: number;
106
+ init(options: StandardHandlerOptions<T>): void;
107
+ }
108
+
109
+ interface StrictGetMethodPluginOptions {
110
+ /**
111
+ * The error thrown when a GET request is made to a procedure that doesn't allow GET.
112
+ *
113
+ * @default new ORPCError('METHOD_NOT_SUPPORTED')
114
+ */
115
+ error?: InstanceType<typeof ORPCError$1>;
116
+ }
117
+ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
118
+ private readonly error;
119
+ order: number;
120
+ constructor(options?: StrictGetMethodPluginOptions);
121
+ init(options: StandardHandlerOptions<T>): void;
122
+ }
123
+
124
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
125
+ export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
@@ -1,7 +1,109 @@
1
- import { value } from '@orpc/shared';
1
+ import { value, isAsyncIteratorObject } from '@orpc/shared';
2
+ import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
3
+ import { ORPCError } from '@orpc/client';
4
+ export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
5
+ import '@orpc/contract';
6
+
7
+ class BatchHandlerPlugin {
8
+ maxSize;
9
+ mapRequestItem;
10
+ successStatus;
11
+ headers;
12
+ order = 5e6;
13
+ constructor(options = {}) {
14
+ this.maxSize = options.maxSize ?? 10;
15
+ this.mapRequestItem = options.mapRequestItem ?? ((request, { request: batchRequest }) => ({
16
+ ...request,
17
+ headers: {
18
+ ...batchRequest.headers,
19
+ ...request.headers
20
+ }
21
+ }));
22
+ this.successStatus = options.successStatus ?? 207;
23
+ this.headers = options.headers ?? {};
24
+ }
25
+ init(options) {
26
+ options.rootInterceptors ??= [];
27
+ options.rootInterceptors.unshift(async (options2) => {
28
+ if (options2.request.headers["x-orpc-batch"] !== "1") {
29
+ return options2.next();
30
+ }
31
+ let isParsing = false;
32
+ try {
33
+ isParsing = true;
34
+ const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
35
+ isParsing = false;
36
+ const maxSize = await value(this.maxSize, options2);
37
+ if (parsed.length > maxSize) {
38
+ return {
39
+ matched: true,
40
+ response: {
41
+ status: 413,
42
+ headers: {},
43
+ body: "Batch request size exceeds the maximum allowed size"
44
+ }
45
+ };
46
+ }
47
+ const responses = parsed.map(
48
+ (request, index) => {
49
+ const mapped = this.mapRequestItem(request, options2);
50
+ return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
51
+ if (matched) {
52
+ if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
53
+ return {
54
+ index,
55
+ status: 500,
56
+ headers: {},
57
+ body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
58
+ };
59
+ }
60
+ return { ...response2, index };
61
+ }
62
+ return { index, status: 404, headers: {}, body: "No procedure matched" };
63
+ }).catch(() => {
64
+ return { index, status: 500, headers: {}, body: "Internal server error" };
65
+ });
66
+ }
67
+ );
68
+ await Promise.race(responses);
69
+ const status = await value(this.successStatus, responses, options2);
70
+ const headers = await value(this.headers, responses, options2);
71
+ const response = toBatchResponse({
72
+ status,
73
+ headers,
74
+ body: async function* () {
75
+ const promises = [...responses];
76
+ while (true) {
77
+ const handling = promises.filter((p) => p !== void 0);
78
+ if (handling.length === 0) {
79
+ return;
80
+ }
81
+ const result = await Promise.race(handling);
82
+ promises[result.index] = void 0;
83
+ yield result;
84
+ }
85
+ }()
86
+ });
87
+ return {
88
+ matched: true,
89
+ response
90
+ };
91
+ } catch (cause) {
92
+ if (isParsing) {
93
+ return {
94
+ matched: true,
95
+ response: { status: 400, headers: {}, body: "Invalid batch request, this could be caused by a malformed request body or a missing header" }
96
+ };
97
+ }
98
+ throw cause;
99
+ }
100
+ });
101
+ }
102
+ }
2
103
 
3
104
  class CORSPlugin {
4
105
  options;
106
+ order = 9e6;
5
107
  constructor(options = {}) {
6
108
  const defaults = {
7
109
  origin: (origin) => origin,
@@ -104,4 +206,47 @@ class ResponseHeadersPlugin {
104
206
  }
105
207
  }
106
208
 
107
- export { CORSPlugin, ResponseHeadersPlugin };
209
+ const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
210
+ class SimpleCsrfProtectionHandlerPlugin {
211
+ headerName;
212
+ headerValue;
213
+ exclude;
214
+ error;
215
+ constructor(options = {}) {
216
+ this.headerName = options.headerName ?? "x-csrf-token";
217
+ this.headerValue = options.headerValue ?? "orpc";
218
+ this.exclude = options.exclude ?? false;
219
+ this.error = options.error ?? new ORPCError("CSRF_TOKEN_MISMATCH", {
220
+ status: 403,
221
+ message: "Invalid CSRF token"
222
+ });
223
+ }
224
+ order = 8e6;
225
+ init(options) {
226
+ options.rootInterceptors ??= [];
227
+ options.clientInterceptors ??= [];
228
+ options.rootInterceptors.unshift(async (options2) => {
229
+ const headerName = await value(this.headerName, options2);
230
+ const headerValue = await value(this.headerValue, options2);
231
+ return options2.next({
232
+ ...options2,
233
+ context: {
234
+ ...options2.context,
235
+ [SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers[headerName] === headerValue
236
+ }
237
+ });
238
+ });
239
+ options.clientInterceptors.unshift(async (options2) => {
240
+ if (typeof options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL] !== "boolean") {
241
+ throw new TypeError("[SimpleCsrfProtectionHandlerPlugin] CSRF protection context has been corrupted or modified by another plugin or interceptor");
242
+ }
243
+ const excluded = await value(this.exclude, options2);
244
+ if (!excluded && !options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]) {
245
+ throw this.error;
246
+ }
247
+ return options2.next();
248
+ });
249
+ }
250
+ }
251
+
252
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
@@ -2,7 +2,17 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
3
  import { Interceptor, ThrowableError } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.mjs';
5
+ import { C as Context, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions, R as Router } from './server.BVHsfJ99.mjs';
6
+
7
+ interface StandardHandlerPlugin<TContext extends Context> {
8
+ order?: number;
9
+ init?(options: StandardHandlerOptions<TContext>): void;
10
+ }
11
+ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
12
+ protected readonly plugins: TPlugin[];
13
+ constructor(plugins?: readonly TPlugin[]);
14
+ init(options: StandardHandlerOptions<T>): void;
15
+ }
6
16
 
7
17
  type StandardParams = Record<string, string>;
8
18
  type StandardMatchResult = {
@@ -31,9 +41,6 @@ type StandardHandleResult = {
31
41
  matched: false;
32
42
  response: undefined;
33
43
  };
34
- interface StandardHandlerPlugin<TContext extends Context> {
35
- init?(options: StandardHandlerOptions<TContext>): void;
36
- }
37
44
  interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
38
45
  request: StandardLazyRequest;
39
46
  }
@@ -63,4 +70,5 @@ declare class StandardHandler<T extends Context> {
63
70
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
64
71
  }
65
72
 
66
- export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardHandlerPlugin as c, type StandardCodec as d, type StandardParams as e, type StandardMatcher as f, type StandardMatchResult as g, type StandardHandleResult as h, StandardHandler as i };
73
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as i };
74
+ export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardCodec as c, StandardParams as d, StandardMatcher as e, StandardMatchResult as f, StandardHandleOptions as g, StandardHandleResult as h };
@@ -1,6 +1,6 @@
1
1
  import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
2
- import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
2
  import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
3
+ import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
4
4
 
5
5
  type Context = Record<PropertyKey, any>;
6
6
  type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
@@ -140,4 +140,5 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
140
140
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
141
  };
142
142
 
143
- export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
143
+ export { isProcedure as E, createProcedureClient as G, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, validateORPCError as v, middlewareOutputFn as z };
144
+ export type { AnyMiddleware as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, ProcedureClientInterceptorOptions as F, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, Middleware as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, MergedInitialContext as a, MergedCurrentContext as b, MapInputMiddleware as c, CreateProcedureClientOptions as d, ProcedureClient as e, AnyRouter as f, Lazy as g, AnyProcedure as h, ProcedureHandler as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
@@ -1,6 +1,6 @@
1
1
  import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
2
- import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
2
  import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
3
+ import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
4
4
 
5
5
  type Context = Record<PropertyKey, any>;
6
6
  type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
@@ -140,4 +140,5 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
140
140
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
141
  };
142
142
 
143
- export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
143
+ export { isProcedure as E, createProcedureClient as G, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, validateORPCError as v, middlewareOutputFn as z };
144
+ export type { AnyMiddleware as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, ProcedureClientInterceptorOptions as F, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, Middleware as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, MergedInitialContext as a, MergedCurrentContext as b, MapInputMiddleware as c, CreateProcedureClientOptions as d, ProcedureClient as e, AnyRouter as f, Lazy as g, AnyProcedure as h, ProcedureHandler as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
@@ -0,0 +1,36 @@
1
+ import { ORPCError, fallbackContractConfig } from '@orpc/contract';
2
+
3
+ const STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL = Symbol("STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT");
4
+ class StrictGetMethodPlugin {
5
+ error;
6
+ order = 7e6;
7
+ constructor(options = {}) {
8
+ this.error = options.error ?? new ORPCError("METHOD_NOT_SUPPORTED");
9
+ }
10
+ init(options) {
11
+ options.rootInterceptors ??= [];
12
+ options.clientInterceptors ??= [];
13
+ options.rootInterceptors.unshift((options2) => {
14
+ const isGetMethod = options2.request.method === "GET";
15
+ return options2.next({
16
+ ...options2,
17
+ context: {
18
+ ...options2.context,
19
+ [STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL]: isGetMethod
20
+ }
21
+ });
22
+ });
23
+ options.clientInterceptors.unshift((options2) => {
24
+ if (typeof options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] !== "boolean") {
25
+ throw new TypeError("[StrictGetMethodPlugin] strict GET method context has been corrupted or modified by another plugin or interceptor");
26
+ }
27
+ const procedureMethod = fallbackContractConfig("defaultMethod", options2.procedure["~orpc"].route.method);
28
+ if (options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] && procedureMethod !== "GET") {
29
+ throw this.error;
30
+ }
31
+ return options2.next();
32
+ });
33
+ }
34
+ }
35
+
36
+ export { StrictGetMethodPlugin as S };
@@ -0,0 +1,18 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { C as Context, R as Router } from './server.BVHsfJ99.mjs';
3
+ import { b as StandardHandlerOptions, i as StandardHandler } from './server.B1oIHH_j.mjs';
4
+
5
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
+ /**
7
+ * Enables or disables the StrictGetMethodPlugin.
8
+ *
9
+ * @default true
10
+ */
11
+ strictGetMethodPluginEnabled?: boolean;
12
+ }
13
+ declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
14
+ constructor(router: Router<any, T>, options: StandardRPCHandlerOptions<T>);
15
+ }
16
+
17
+ export { StandardRPCHandler as a };
18
+ export type { StandardRPCHandlerOptions as S };
@@ -169,35 +169,29 @@ async function executeProcedureInternal(procedure, options) {
169
169
  const middlewares = procedure["~orpc"].middlewares;
170
170
  const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
171
171
  const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
172
- let currentIndex = 0;
173
- let currentContext = options.context;
174
- let currentInput = options.input;
175
- const next = async (...[nextOptions]) => {
176
- const index = currentIndex;
177
- const midContext = nextOptions?.context ?? {};
178
- currentIndex += 1;
179
- currentContext = mergeCurrentContext(currentContext, midContext);
172
+ const next = async (index, context, input) => {
173
+ let currentInput = input;
180
174
  if (index === inputValidationIndex) {
181
175
  currentInput = await validateInput(procedure, currentInput);
182
176
  }
183
177
  const mid = middlewares[index];
184
- const result = mid ? {
185
- context: midContext,
186
- output: (await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn)).output
187
- } : {
188
- context: midContext,
189
- output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput })
190
- };
178
+ const output = mid ? (await mid({
179
+ ...options,
180
+ context,
181
+ next: async (...[nextOptions]) => {
182
+ const nextContext = nextOptions?.context ?? {};
183
+ return {
184
+ output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
185
+ context: nextContext
186
+ };
187
+ }
188
+ }, currentInput, middlewareOutputFn)).output : await procedure["~orpc"].handler({ ...options, context, input: currentInput });
191
189
  if (index === outputValidationIndex) {
192
- const validatedOutput = await validateOutput(procedure, result.output);
193
- return {
194
- context: result.context,
195
- output: validatedOutput
196
- };
190
+ return await validateOutput(procedure, output);
197
191
  }
198
- return result;
192
+ return output;
199
193
  };
200
- return (await next()).output;
194
+ return next(0, options.context, options.input);
201
195
  }
202
196
 
203
197
  const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
@@ -2,7 +2,17 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
3
  import { Interceptor, ThrowableError } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.js';
5
+ import { C as Context, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions, R as Router } from './server.BVHsfJ99.js';
6
+
7
+ interface StandardHandlerPlugin<TContext extends Context> {
8
+ order?: number;
9
+ init?(options: StandardHandlerOptions<TContext>): void;
10
+ }
11
+ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
12
+ protected readonly plugins: TPlugin[];
13
+ constructor(plugins?: readonly TPlugin[]);
14
+ init(options: StandardHandlerOptions<T>): void;
15
+ }
6
16
 
7
17
  type StandardParams = Record<string, string>;
8
18
  type StandardMatchResult = {
@@ -31,9 +41,6 @@ type StandardHandleResult = {
31
41
  matched: false;
32
42
  response: undefined;
33
43
  };
34
- interface StandardHandlerPlugin<TContext extends Context> {
35
- init?(options: StandardHandlerOptions<TContext>): void;
36
- }
37
44
  interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
38
45
  request: StandardLazyRequest;
39
46
  }
@@ -63,4 +70,5 @@ declare class StandardHandler<T extends Context> {
63
70
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
64
71
  }
65
72
 
66
- export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardHandlerPlugin as c, type StandardCodec as d, type StandardParams as e, type StandardMatcher as f, type StandardMatchResult as g, type StandardHandleResult as h, StandardHandler as i };
73
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as i };
74
+ export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardCodec as c, StandardParams as d, StandardMatcher as e, StandardMatchResult as f, StandardHandleOptions as g, StandardHandleResult as h };
@@ -1,15 +1,28 @@
1
- import { ORPCError, toORPCError } from '@orpc/client';
1
+ import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
2
2
  import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
3
- import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.e3W6AG3-.mjs';
4
- import { toHttpPath } from '@orpc/client/standard';
3
+ import '@orpc/standard-server/batch';
4
+ import { ORPCError, toORPCError } from '@orpc/client';
5
+ import { S as StrictGetMethodPlugin } from './server.BW-nUGgA.mjs';
6
+ import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.C37gDhSZ.mjs';
7
+
8
+ class CompositeStandardHandlerPlugin {
9
+ plugins;
10
+ constructor(plugins = []) {
11
+ this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
12
+ }
13
+ init(options) {
14
+ for (const plugin of this.plugins) {
15
+ plugin.init?.(options);
16
+ }
17
+ }
18
+ }
5
19
 
6
20
  class StandardHandler {
7
21
  constructor(router, matcher, codec, options) {
8
22
  this.matcher = matcher;
9
23
  this.codec = codec;
10
- for (const plugin of toArray(options.plugins)) {
11
- plugin.init?.(options);
12
- }
24
+ const plugins = new CompositeStandardHandlerPlugin(options.plugins);
25
+ plugins.init(options);
13
26
  this.interceptors = toArray(options.interceptors);
14
27
  this.clientInterceptors = toArray(options.clientInterceptors);
15
28
  this.rootInterceptors = toArray(options.rootInterceptors);
@@ -18,23 +31,24 @@ class StandardHandler {
18
31
  interceptors;
19
32
  clientInterceptors;
20
33
  rootInterceptors;
21
- handle(request, options) {
34
+ async handle(request, options) {
35
+ const prefix = options.prefix?.replace(/\/$/, "") || void 0;
36
+ if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
37
+ return { matched: false, response: void 0 };
38
+ }
22
39
  return intercept(
23
40
  this.rootInterceptors,
24
- { ...options, request },
41
+ { ...options, request, prefix },
25
42
  async (interceptorOptions) => {
26
43
  let isDecoding = false;
27
44
  try {
28
45
  return await intercept(
29
46
  this.interceptors,
30
47
  interceptorOptions,
31
- async ({ request: request2, context, prefix }) => {
48
+ async ({ request: request2, context, prefix: prefix2 }) => {
32
49
  const method = request2.method;
33
50
  const url = request2.url;
34
- if (prefix && !url.pathname.startsWith(prefix)) {
35
- return { matched: false, response: void 0 };
36
- }
37
- const pathname = prefix ? url.pathname.replace(prefix, "") : url.pathname;
51
+ const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
38
52
  const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
39
53
  if (!match) {
40
54
  return { matched: false, response: void 0 };
@@ -158,4 +172,19 @@ class StandardRPCMatcher {
158
172
  }
159
173
  }
160
174
 
161
- export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
175
+ class StandardRPCHandler extends StandardHandler {
176
+ constructor(router, options) {
177
+ options.plugins ??= [];
178
+ const strictGetMethodPluginEnabled = options.strictGetMethodPluginEnabled ?? true;
179
+ if (strictGetMethodPluginEnabled) {
180
+ options.plugins.push(new StrictGetMethodPlugin());
181
+ }
182
+ const jsonSerializer = new StandardRPCJsonSerializer(options);
183
+ const serializer = new StandardRPCSerializer(jsonSerializer);
184
+ const matcher = new StandardRPCMatcher();
185
+ const codec = new StandardRPCCodec(serializer);
186
+ super(router, matcher, codec, options);
187
+ }
188
+ }
189
+
190
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardRPCCodec as a, StandardRPCHandler as b, StandardRPCMatcher as c };
@@ -1,5 +1,5 @@
1
- import { C as Context } from './server.DLt5njUb.js';
2
- import { S as StandardHandleOptions } from './server.BHlRCrf_.js';
1
+ import { C as Context } from './server.BVHsfJ99.js';
2
+ import { g as StandardHandleOptions } from './server.CaWivVk3.js';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;
@@ -0,0 +1,18 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { C as Context, R as Router } from './server.BVHsfJ99.js';
3
+ import { b as StandardHandlerOptions, i as StandardHandler } from './server.CaWivVk3.js';
4
+
5
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
+ /**
7
+ * Enables or disables the StrictGetMethodPlugin.
8
+ *
9
+ * @default true
10
+ */
11
+ strictGetMethodPluginEnabled?: boolean;
12
+ }
13
+ declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
14
+ constructor(router: Router<any, T>, options: StandardRPCHandlerOptions<T>);
15
+ }
16
+
17
+ export { StandardRPCHandler as a };
18
+ export type { StandardRPCHandlerOptions as S };
@@ -1,5 +1,5 @@
1
- import { C as Context } from './server.DLt5njUb.mjs';
2
- import { S as StandardHandleOptions } from './server.CzxlqYZL.mjs';
1
+ import { C as Context } from './server.BVHsfJ99.mjs';
2
+ import { g as StandardHandleOptions } from './server.B1oIHH_j.mjs';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;