@orpc/server 1.12.2 → 1.13.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.
@@ -1,4 +1,4 @@
1
- import { Value, Promisable } from '@orpc/shared';
1
+ import { Value, Promisable, ThrowableError } from '@orpc/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
3
  import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
4
  import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.BqadksTP.mjs';
@@ -95,6 +95,38 @@ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> impl
95
95
  init(options: StandardHandlerOptions<T>): void;
96
96
  }
97
97
 
98
+ interface experimental_RethrowHandlerPluginOptions<T extends Context> {
99
+ /**
100
+ * Decide which errors should be rethrown.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const rethrowPlugin = new RethrowHandlerPlugin({
105
+ * filter: (error) => {
106
+ * // Rethrow all non-ORPCError errors
107
+ * return !(error instanceof ORPCError)
108
+ * }
109
+ * })
110
+ * ```
111
+ */
112
+ filter: Value<boolean, [error: ThrowableError, options: StandardHandlerInterceptorOptions<T>]>;
113
+ }
114
+ /**
115
+ * The plugin allows you to catch and rethrow specific errors that occur during request handling.
116
+ * This is particularly useful when your framework has its own error handling mechanism
117
+ * (e.g., global exception filters in NestJS, error middleware in Express)
118
+ * and you want certain errors to be processed by that mechanism instead of being handled by the
119
+ * oRPC error handling flow.
120
+ *
121
+ * @see {@link https://orpc.dev/docs/plugins/rethrow-handler Rethrow Handler Plugin Docs}
122
+ */
123
+ declare class experimental_RethrowHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
124
+ private readonly filter;
125
+ CONTEXT_SYMBOL: symbol;
126
+ constructor(options: experimental_RethrowHandlerPluginOptions<T>);
127
+ init(options: StandardHandlerOptions<T>): void;
128
+ }
129
+
98
130
  interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
99
131
  /**
100
132
  * The name of the header to check.
@@ -168,5 +200,5 @@ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandle
168
200
  init(options: StandardHandlerOptions<T>): void;
169
201
  }
170
202
 
171
- export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
172
- export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
203
+ export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin, experimental_RethrowHandlerPlugin };
204
+ export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions, experimental_RethrowHandlerPluginOptions };
@@ -1,4 +1,4 @@
1
- import { Value, Promisable } from '@orpc/shared';
1
+ import { Value, Promisable, ThrowableError } from '@orpc/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
3
  import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
4
  import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.7cEtMB30.js';
@@ -95,6 +95,38 @@ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> impl
95
95
  init(options: StandardHandlerOptions<T>): void;
96
96
  }
97
97
 
98
+ interface experimental_RethrowHandlerPluginOptions<T extends Context> {
99
+ /**
100
+ * Decide which errors should be rethrown.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const rethrowPlugin = new RethrowHandlerPlugin({
105
+ * filter: (error) => {
106
+ * // Rethrow all non-ORPCError errors
107
+ * return !(error instanceof ORPCError)
108
+ * }
109
+ * })
110
+ * ```
111
+ */
112
+ filter: Value<boolean, [error: ThrowableError, options: StandardHandlerInterceptorOptions<T>]>;
113
+ }
114
+ /**
115
+ * The plugin allows you to catch and rethrow specific errors that occur during request handling.
116
+ * This is particularly useful when your framework has its own error handling mechanism
117
+ * (e.g., global exception filters in NestJS, error middleware in Express)
118
+ * and you want certain errors to be processed by that mechanism instead of being handled by the
119
+ * oRPC error handling flow.
120
+ *
121
+ * @see {@link https://orpc.dev/docs/plugins/rethrow-handler Rethrow Handler Plugin Docs}
122
+ */
123
+ declare class experimental_RethrowHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
124
+ private readonly filter;
125
+ CONTEXT_SYMBOL: symbol;
126
+ constructor(options: experimental_RethrowHandlerPluginOptions<T>);
127
+ init(options: StandardHandlerOptions<T>): void;
128
+ }
129
+
98
130
  interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
99
131
  /**
100
132
  * The name of the header to check.
@@ -168,5 +200,5 @@ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandle
168
200
  init(options: StandardHandlerOptions<T>): void;
169
201
  }
170
202
 
171
- export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
172
- export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
203
+ export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin, experimental_RethrowHandlerPlugin };
204
+ export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions, experimental_RethrowHandlerPluginOptions };
@@ -241,6 +241,47 @@ class ResponseHeadersPlugin {
241
241
  }
242
242
  }
243
243
 
244
+ class experimental_RethrowHandlerPlugin {
245
+ filter;
246
+ CONTEXT_SYMBOL = Symbol("ORPC_RETHROW_HANDLER_PLUGIN_CONTEXT");
247
+ constructor(options) {
248
+ this.filter = options.filter;
249
+ }
250
+ init(options) {
251
+ options.rootInterceptors ??= [];
252
+ options.interceptors ??= [];
253
+ options.rootInterceptors.push(async (options2) => {
254
+ const pluginContext = {};
255
+ const result = await options2.next({
256
+ ...options2,
257
+ context: {
258
+ ...options2.context,
259
+ [this.CONTEXT_SYMBOL]: pluginContext
260
+ }
261
+ });
262
+ if (pluginContext.error) {
263
+ throw pluginContext.error.value;
264
+ }
265
+ return result;
266
+ });
267
+ options.interceptors.unshift(async (options2) => {
268
+ const pluginContext = options2.context[this.CONTEXT_SYMBOL];
269
+ if (!pluginContext) {
270
+ throw new TypeError("[RethrowHandlerPlugin] Rethrow handler context has been corrupted or modified by another plugin or interceptor");
271
+ }
272
+ try {
273
+ return await options2.next();
274
+ } catch (error) {
275
+ if (value(this.filter, error, options2)) {
276
+ pluginContext.error = { value: error };
277
+ return { matched: false, response: void 0 };
278
+ }
279
+ throw error;
280
+ }
281
+ });
282
+ }
283
+ }
284
+
244
285
  const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
245
286
  class SimpleCsrfProtectionHandlerPlugin {
246
287
  headerName;
@@ -284,4 +325,4 @@ class SimpleCsrfProtectionHandlerPlugin {
284
325
  }
285
326
  }
286
327
 
287
- export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
328
+ export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, experimental_RethrowHandlerPlugin };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "1.12.2",
4
+ "version": "1.13.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.dev",
7
7
  "repository": {
@@ -107,23 +107,23 @@
107
107
  },
108
108
  "dependencies": {
109
109
  "cookie": "^1.0.2",
110
- "@orpc/client": "1.12.2",
111
- "@orpc/contract": "1.12.2",
112
- "@orpc/standard-server": "1.12.2",
113
- "@orpc/shared": "1.12.2",
114
- "@orpc/standard-server-aws-lambda": "1.12.2",
115
- "@orpc/standard-server-fastify": "1.12.2",
116
- "@orpc/interop": "1.12.2",
117
- "@orpc/standard-server-node": "1.12.2",
118
- "@orpc/standard-server-peer": "1.12.2",
119
- "@orpc/standard-server-fetch": "1.12.2"
110
+ "@orpc/interop": "1.13.0",
111
+ "@orpc/client": "1.13.0",
112
+ "@orpc/contract": "1.13.0",
113
+ "@orpc/standard-server": "1.13.0",
114
+ "@orpc/shared": "1.13.0",
115
+ "@orpc/standard-server-fastify": "1.13.0",
116
+ "@orpc/standard-server-aws-lambda": "1.13.0",
117
+ "@orpc/standard-server-node": "1.13.0",
118
+ "@orpc/standard-server-peer": "1.13.0",
119
+ "@orpc/standard-server-fetch": "1.13.0"
120
120
  },
121
121
  "devDependencies": {
122
- "@tanstack/router-core": "^1.139.1",
122
+ "@tanstack/router-core": "^1.139.12",
123
123
  "@types/ws": "^8.18.1",
124
124
  "crossws": "^0.4.1",
125
125
  "fastify": "^5.6.2",
126
- "next": "^16.0.3",
126
+ "next": "^16.0.7",
127
127
  "supertest": "^7.1.4",
128
128
  "ws": "^8.18.3",
129
129
  "zod": "^4.1.12"