@orpc/server 0.0.0-next.c0dd7cd → 0.0.0-next.c287818

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 (40) hide show
  1. package/README.md +9 -0
  2. package/dist/adapters/fetch/index.d.mts +41 -11
  3. package/dist/adapters/fetch/index.d.ts +41 -11
  4. package/dist/adapters/fetch/index.mjs +8 -6
  5. package/dist/adapters/hono/index.d.mts +6 -5
  6. package/dist/adapters/hono/index.d.ts +6 -5
  7. package/dist/adapters/hono/index.mjs +12 -9
  8. package/dist/adapters/next/index.d.mts +6 -5
  9. package/dist/adapters/next/index.d.ts +6 -5
  10. package/dist/adapters/next/index.mjs +12 -9
  11. package/dist/adapters/node/index.d.mts +43 -22
  12. package/dist/adapters/node/index.d.ts +43 -22
  13. package/dist/adapters/node/index.mjs +82 -24
  14. package/dist/adapters/standard/index.d.mts +6 -6
  15. package/dist/adapters/standard/index.d.ts +6 -6
  16. package/dist/adapters/standard/index.mjs +6 -4
  17. package/dist/index.d.mts +50 -36
  18. package/dist/index.d.ts +50 -36
  19. package/dist/index.mjs +32 -11
  20. package/dist/plugins/index.d.mts +108 -15
  21. package/dist/plugins/index.d.ts +108 -15
  22. package/dist/plugins/index.mjs +156 -7
  23. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  24. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  25. package/dist/shared/server.Bm0UqHzd.mjs +103 -0
  26. package/dist/shared/{server.BtxZnWJ9.mjs → server.C37gDhSZ.mjs} +19 -29
  27. package/dist/shared/server.C8NkqxHo.d.ts +17 -0
  28. package/dist/shared/server.CGCwEAt_.d.mts +10 -0
  29. package/dist/shared/server.DCQgF_JR.d.mts +17 -0
  30. package/dist/shared/{server.P4_D9lKb.d.mts → server.DFFT_EZo.d.ts} +27 -29
  31. package/dist/shared/{server.BY9sDlwl.mjs → server.DFuJLDuo.mjs} +60 -28
  32. package/dist/shared/{server.MZvbGc3n.d.mts → server.DLt5njUb.d.mts} +8 -8
  33. package/dist/shared/{server.MZvbGc3n.d.ts → server.DLt5njUb.d.ts} +8 -8
  34. package/dist/shared/{server.CPqNKiJp.d.ts → server.DOYDVeMX.d.mts} +27 -29
  35. package/dist/shared/server._2UufoXA.d.ts +10 -0
  36. package/package.json +8 -8
  37. package/dist/shared/server.BqBN5WhH.d.mts +0 -8
  38. package/dist/shared/server.Dba3Iiyp.mjs +0 -12
  39. package/dist/shared/server.Del5OmaY.mjs +0 -29
  40. package/dist/shared/server.Dm3ZuTuI.d.ts +0 -8
@@ -0,0 +1,103 @@
1
+ import { ORPCError } from '@orpc/client';
2
+ import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
3
+ import '@orpc/contract';
4
+ import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from './server.DFuJLDuo.mjs';
5
+ import '@orpc/client/standard';
6
+ import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
7
+ import { r as resolveFriendlyStandardHandleOptions } from './server.BVwwTHyO.mjs';
8
+ import '@orpc/standard-server/batch';
9
+
10
+ class BodyLimitPlugin {
11
+ maxBodySize;
12
+ constructor(options) {
13
+ this.maxBodySize = options.maxBodySize;
14
+ }
15
+ initRuntimeAdapter(options) {
16
+ options.adapterInterceptors ??= [];
17
+ options.adapterInterceptors.push(async (options2) => {
18
+ if (!options2.request.body) {
19
+ return options2.next();
20
+ }
21
+ let currentBodySize = 0;
22
+ const rawReader = options2.request.body.getReader();
23
+ const reader = new ReadableStream({
24
+ start: async (controller) => {
25
+ try {
26
+ if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
27
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
28
+ return;
29
+ }
30
+ while (true) {
31
+ const { done, value } = await rawReader.read();
32
+ if (done) {
33
+ break;
34
+ }
35
+ currentBodySize += value.length;
36
+ if (currentBodySize > this.maxBodySize) {
37
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
38
+ break;
39
+ }
40
+ controller.enqueue(value);
41
+ }
42
+ } finally {
43
+ controller.close();
44
+ }
45
+ }
46
+ });
47
+ const requestInit = { body: reader, duplex: "half" };
48
+ return options2.next({
49
+ ...options2,
50
+ request: new Request(options2.request, requestInit)
51
+ });
52
+ });
53
+ }
54
+ }
55
+
56
+ class CompositeFetchHandlerPlugin extends CompositeStandardHandlerPlugin {
57
+ initRuntimeAdapter(options) {
58
+ for (const plugin of this.plugins) {
59
+ plugin.initRuntimeAdapter?.(options);
60
+ }
61
+ }
62
+ }
63
+
64
+ class FetchHandler {
65
+ constructor(standardHandler, options = {}) {
66
+ this.standardHandler = standardHandler;
67
+ const plugin = new CompositeFetchHandlerPlugin(options.plugins);
68
+ plugin.initRuntimeAdapter(options);
69
+ this.adapterInterceptors = toArray(options.adapterInterceptors);
70
+ this.toFetchResponseOptions = options;
71
+ }
72
+ toFetchResponseOptions;
73
+ adapterInterceptors;
74
+ async handle(request, ...rest) {
75
+ return intercept(
76
+ this.adapterInterceptors,
77
+ {
78
+ ...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
79
+ request,
80
+ toFetchResponseOptions: this.toFetchResponseOptions
81
+ },
82
+ async ({ request: request2, toFetchResponseOptions, ...options }) => {
83
+ const standardRequest = toStandardLazyRequest(request2);
84
+ const result = await this.standardHandler.handle(standardRequest, options);
85
+ if (!result.matched) {
86
+ return result;
87
+ }
88
+ return {
89
+ matched: true,
90
+ response: toFetchResponse(result.response, toFetchResponseOptions)
91
+ };
92
+ }
93
+ );
94
+ }
95
+ }
96
+
97
+ class RPCHandler extends FetchHandler {
98
+ constructor(router, options = {}) {
99
+ super(new StandardRPCHandler(router, options), options);
100
+ }
101
+ }
102
+
103
+ export { BodyLimitPlugin as B, CompositeFetchHandlerPlugin as C, FetchHandler as F, RPCHandler as R };
@@ -1,6 +1,6 @@
1
1
  import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
2
2
  import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
3
- import { value, intercept, toError } from '@orpc/shared';
3
+ import { value, intercept } from '@orpc/shared';
4
4
 
5
5
  const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
6
6
  function lazy(loader, meta = {}) {
@@ -127,7 +127,7 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
127
127
  );
128
128
  } catch (e) {
129
129
  if (!(e instanceof ORPCError)) {
130
- throw toError(e);
130
+ throw e;
131
131
  }
132
132
  const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
133
133
  throw validated;
@@ -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");
@@ -367,8 +361,4 @@ function call(procedure, input, ...rest) {
367
361
  return createProcedureClient(procedure, ...rest)(input);
368
362
  }
369
363
 
370
- function toHttpPath(path) {
371
- return `/${path.map(encodeURIComponent).join("/")}`;
372
- }
373
-
374
- export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i, createORPCErrorConstructorMap as j, getLazyMeta as k, lazy as l, mergeCurrentContext as m, middlewareOutputFn as n, isStartWithMiddlewares as o, mergeMiddlewares as p, call as q, getHiddenRouterContract as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, createAccessibleLazyRouter as w, resolveContractProcedures as x, unlazyRouter as y };
364
+ export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, resolveContractProcedures as w, unlazyRouter as x };
@@ -0,0 +1,17 @@
1
+ import { C as Context, R as Router } from './server.DLt5njUb.js';
2
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
3
+ import { a as StandardHandlerOptions, b as StandardHandler } from './server.DFFT_EZo.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 { type StandardRPCHandlerOptions as S, StandardRPCHandler as a };
@@ -0,0 +1,10 @@
1
+ import { C as Context } from './server.DLt5njUb.mjs';
2
+ import { S as StandardHandleOptions } from './server.DOYDVeMX.mjs';
3
+
4
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
+ context?: T;
6
+ } : {
7
+ context: T;
8
+ });
9
+
10
+ export type { FriendlyStandardHandleOptions as F };
@@ -0,0 +1,17 @@
1
+ import { C as Context, R as Router } from './server.DLt5njUb.mjs';
2
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
3
+ import { a as StandardHandlerOptions, b as StandardHandler } from './server.DOYDVeMX.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 { type StandardRPCHandlerOptions as S, StandardRPCHandler as a };
@@ -1,8 +1,8 @@
1
- import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
+ import { Interceptor, ThrowableError } from '@orpc/shared';
3
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
4
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.MZvbGc3n.mjs';
5
- import { ORPCError } from '@orpc/client';
5
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.js';
6
6
 
7
7
  type StandardParams = Record<string, string>;
8
8
  type StandardMatchResult = {
@@ -20,13 +20,20 @@ interface StandardCodec {
20
20
  decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
21
  }
22
22
 
23
- type StandardHandleOptions<T extends Context> = {
23
+ interface StandardHandlerPlugin<TContext extends Context> {
24
+ order?: number;
25
+ init?(options: StandardHandlerOptions<TContext>): void;
26
+ }
27
+ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
28
+ protected readonly plugins: TPlugin[];
29
+ constructor(plugins?: readonly TPlugin[]);
30
+ init(options: StandardHandlerOptions<T>): void;
31
+ }
32
+
33
+ interface StandardHandleOptions<T extends Context> {
24
34
  prefix?: HTTPPath;
25
- } & (Record<never, never> extends T ? {
26
- context?: T;
27
- } : {
28
35
  context: T;
29
- });
36
+ }
30
37
  type StandardHandleResult = {
31
38
  matched: true;
32
39
  response: StandardResponse;
@@ -34,42 +41,33 @@ type StandardHandleResult = {
34
41
  matched: false;
35
42
  response: undefined;
36
43
  };
37
- type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
38
- context: T;
44
+ interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
39
45
  request: StandardLazyRequest;
40
- };
46
+ }
41
47
  interface StandardHandlerOptions<TContext extends Context> {
42
- plugins?: HandlerPlugin<TContext>[];
48
+ plugins?: StandardHandlerPlugin<TContext>[];
43
49
  /**
44
50
  * Interceptors at the request level, helpful when you want catch errors
45
51
  */
46
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
52
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
47
53
  /**
48
54
  * Interceptors at the root level, helpful when you want override the request/response
49
55
  */
50
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
56
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
51
57
  /**
52
58
  *
53
59
  * Interceptors for procedure client.
54
60
  */
55
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
61
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
56
62
  }
57
63
  declare class StandardHandler<T extends Context> {
58
64
  private readonly matcher;
59
65
  private readonly codec;
60
- private readonly options;
61
- private readonly plugin;
66
+ private readonly interceptors;
67
+ private readonly clientInterceptors;
68
+ private readonly rootInterceptors;
62
69
  constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
63
- handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
64
- }
65
-
66
- interface HandlerPlugin<TContext extends Context> {
67
- init?(options: StandardHandlerOptions<TContext>): void;
68
- }
69
- declare class CompositeHandlerPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
70
- private readonly plugins;
71
- constructor(plugins?: HandlerPlugin<TContext>[]);
72
- init(options: StandardHandlerOptions<TContext>): void;
70
+ handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
73
71
  }
74
72
 
75
- export { CompositeHandlerPlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
73
+ export { CompositeStandardHandlerPlugin as C, type StandardHandleOptions as S, type StandardHandlerOptions as a, StandardHandler as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, type StandardHandlerInterceptorOptions as h, type StandardHandlerPlugin as i };
@@ -1,51 +1,68 @@
1
+ import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
2
+ import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
3
+ import '@orpc/standard-server/batch';
1
4
  import { ORPCError, toORPCError } from '@orpc/client';
2
- import { intercept, trim, parseEmptyableJSON } from '@orpc/shared';
3
- import { C as CompositeHandlerPlugin } from './server.Dba3Iiyp.mjs';
4
- import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.BtxZnWJ9.mjs';
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
- this.options = options;
11
- this.plugin = new CompositeHandlerPlugin(options.plugins);
12
- this.plugin.init(this.options);
24
+ const plugins = new CompositeStandardHandlerPlugin(options.plugins);
25
+ plugins.init(options);
26
+ this.interceptors = toArray(options.interceptors);
27
+ this.clientInterceptors = toArray(options.clientInterceptors);
28
+ this.rootInterceptors = toArray(options.rootInterceptors);
13
29
  this.matcher.init(router);
14
30
  }
15
- plugin;
16
- handle(request, ...[options]) {
31
+ interceptors;
32
+ clientInterceptors;
33
+ rootInterceptors;
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
+ }
17
39
  return intercept(
18
- this.options.rootInterceptors ?? [],
19
- {
20
- request,
21
- ...options,
22
- context: options?.context ?? {}
23
- // context is optional only when all fields are optional so we can safely force it to have a context
24
- },
40
+ this.rootInterceptors,
41
+ { ...options, request, prefix },
25
42
  async (interceptorOptions) => {
26
43
  let isDecoding = false;
27
44
  try {
28
45
  return await intercept(
29
- this.options.interceptors ?? [],
46
+ this.interceptors,
30
47
  interceptorOptions,
31
- async (interceptorOptions2) => {
32
- const method = interceptorOptions2.request.method;
33
- const url = interceptorOptions2.request.url;
34
- const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
35
- const match = await this.matcher.match(method, pathname);
48
+ async ({ request: request2, context, prefix: prefix2 }) => {
49
+ const method = request2.method;
50
+ const url = request2.url;
51
+ const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
52
+ const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
36
53
  if (!match) {
37
54
  return { matched: false, response: void 0 };
38
55
  }
39
56
  const client = createProcedureClient(match.procedure, {
40
- context: interceptorOptions2.context,
57
+ context,
41
58
  path: match.path,
42
- interceptors: this.options.clientInterceptors
59
+ interceptors: this.clientInterceptors
43
60
  });
44
61
  isDecoding = true;
45
- const input = await this.codec.decode(request, match.params, match.procedure);
62
+ const input = await this.codec.decode(request2, match.params, match.procedure);
46
63
  isDecoding = false;
47
- const lastEventId = Array.isArray(request.headers["last-event-id"]) ? request.headers["last-event-id"].at(-1) : request.headers["last-event-id"];
48
- const output = await client(input, { signal: request.signal, lastEventId });
64
+ const lastEventId = Array.isArray(request2.headers["last-event-id"]) ? request2.headers["last-event-id"].at(-1) : request2.headers["last-event-id"];
65
+ const output = await client(input, { signal: request2.signal, lastEventId });
49
66
  const response = this.codec.encode(output, match.procedure);
50
67
  return {
51
68
  matched: true,
@@ -54,7 +71,7 @@ class StandardHandler {
54
71
  }
55
72
  );
56
73
  } catch (e) {
57
- const error = isDecoding ? new ORPCError("BAD_REQUEST", {
74
+ const error = isDecoding && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
58
75
  message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
59
76
  cause: e
60
77
  }) : toORPCError(e);
@@ -155,4 +172,19 @@ class StandardRPCMatcher {
155
172
  }
156
173
  }
157
174
 
158
- 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,8 +1,8 @@
1
- import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
1
+ import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
2
2
  import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
- import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
3
+ import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
4
4
 
5
- type Context = Record<string, any>;
5
+ type Context = Record<PropertyKey, any>;
6
6
  type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
7
7
  type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
8
8
  declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
@@ -97,9 +97,9 @@ interface MapInputMiddleware<TInput, TMappedInput> {
97
97
  declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
98
98
 
99
99
  type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
100
- interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
100
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
101
101
  context: TInitialContext;
102
- input: InferSchemaInput<TInputSchema>;
102
+ input: unknown;
103
103
  errors: ORPCErrorConstructorMap<TErrorMap>;
104
104
  path: readonly string[];
105
105
  procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
@@ -109,18 +109,18 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TIn
109
109
  /**
110
110
  * Options for creating a procedure caller with comprehensive type safety
111
111
  */
112
- type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
112
+ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
113
113
  /**
114
114
  * This is helpful for logging and analytics.
115
115
  */
116
116
  path?: readonly string[];
117
- interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
117
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
118
118
  } & (Record<never, never> extends TInitialContext ? {
119
119
  context?: Value<TInitialContext, [clientContext: TClientContext]>;
120
120
  } : {
121
121
  context: Value<TInitialContext, [clientContext: TClientContext]>;
122
122
  });
123
- declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
123
+ declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
124
124
 
125
125
  type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
126
126
  [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
@@ -1,8 +1,8 @@
1
- import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
1
+ import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
2
2
  import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
- import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
3
+ import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
4
4
 
5
- type Context = Record<string, any>;
5
+ type Context = Record<PropertyKey, any>;
6
6
  type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
7
7
  type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
8
8
  declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
@@ -97,9 +97,9 @@ interface MapInputMiddleware<TInput, TMappedInput> {
97
97
  declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
98
98
 
99
99
  type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
100
- interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
100
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
101
101
  context: TInitialContext;
102
- input: InferSchemaInput<TInputSchema>;
102
+ input: unknown;
103
103
  errors: ORPCErrorConstructorMap<TErrorMap>;
104
104
  path: readonly string[];
105
105
  procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
@@ -109,18 +109,18 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TIn
109
109
  /**
110
110
  * Options for creating a procedure caller with comprehensive type safety
111
111
  */
112
- type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
112
+ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
113
113
  /**
114
114
  * This is helpful for logging and analytics.
115
115
  */
116
116
  path?: readonly string[];
117
- interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
117
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
118
118
  } & (Record<never, never> extends TInitialContext ? {
119
119
  context?: Value<TInitialContext, [clientContext: TClientContext]>;
120
120
  } : {
121
121
  context: Value<TInitialContext, [clientContext: TClientContext]>;
122
122
  });
123
- declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
123
+ declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
124
124
 
125
125
  type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
126
126
  [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
@@ -1,8 +1,8 @@
1
- import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
+ import { Interceptor, ThrowableError } from '@orpc/shared';
3
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
4
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.MZvbGc3n.js';
5
- import { ORPCError } from '@orpc/client';
5
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.mjs';
6
6
 
7
7
  type StandardParams = Record<string, string>;
8
8
  type StandardMatchResult = {
@@ -20,13 +20,20 @@ interface StandardCodec {
20
20
  decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
21
  }
22
22
 
23
- type StandardHandleOptions<T extends Context> = {
23
+ interface StandardHandlerPlugin<TContext extends Context> {
24
+ order?: number;
25
+ init?(options: StandardHandlerOptions<TContext>): void;
26
+ }
27
+ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
28
+ protected readonly plugins: TPlugin[];
29
+ constructor(plugins?: readonly TPlugin[]);
30
+ init(options: StandardHandlerOptions<T>): void;
31
+ }
32
+
33
+ interface StandardHandleOptions<T extends Context> {
24
34
  prefix?: HTTPPath;
25
- } & (Record<never, never> extends T ? {
26
- context?: T;
27
- } : {
28
35
  context: T;
29
- });
36
+ }
30
37
  type StandardHandleResult = {
31
38
  matched: true;
32
39
  response: StandardResponse;
@@ -34,42 +41,33 @@ type StandardHandleResult = {
34
41
  matched: false;
35
42
  response: undefined;
36
43
  };
37
- type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
38
- context: T;
44
+ interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
39
45
  request: StandardLazyRequest;
40
- };
46
+ }
41
47
  interface StandardHandlerOptions<TContext extends Context> {
42
- plugins?: HandlerPlugin<TContext>[];
48
+ plugins?: StandardHandlerPlugin<TContext>[];
43
49
  /**
44
50
  * Interceptors at the request level, helpful when you want catch errors
45
51
  */
46
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
52
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
47
53
  /**
48
54
  * Interceptors at the root level, helpful when you want override the request/response
49
55
  */
50
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
56
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
51
57
  /**
52
58
  *
53
59
  * Interceptors for procedure client.
54
60
  */
55
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
61
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
56
62
  }
57
63
  declare class StandardHandler<T extends Context> {
58
64
  private readonly matcher;
59
65
  private readonly codec;
60
- private readonly options;
61
- private readonly plugin;
66
+ private readonly interceptors;
67
+ private readonly clientInterceptors;
68
+ private readonly rootInterceptors;
62
69
  constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
63
- handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
64
- }
65
-
66
- interface HandlerPlugin<TContext extends Context> {
67
- init?(options: StandardHandlerOptions<TContext>): void;
68
- }
69
- declare class CompositeHandlerPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
70
- private readonly plugins;
71
- constructor(plugins?: HandlerPlugin<TContext>[]);
72
- init(options: StandardHandlerOptions<TContext>): void;
70
+ handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
73
71
  }
74
72
 
75
- export { CompositeHandlerPlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
73
+ export { CompositeStandardHandlerPlugin as C, type StandardHandleOptions as S, type StandardHandlerOptions as a, StandardHandler as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, type StandardHandlerInterceptorOptions as h, type StandardHandlerPlugin as i };