@orpc/server 0.0.0-next.3647437 → 0.0.0-next.36cf381

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +128 -13
  2. package/dist/adapters/aws-lambda/index.d.mts +7 -7
  3. package/dist/adapters/aws-lambda/index.d.ts +7 -7
  4. package/dist/adapters/aws-lambda/index.mjs +4 -6
  5. package/dist/adapters/bun-ws/index.d.mts +7 -7
  6. package/dist/adapters/bun-ws/index.d.ts +7 -7
  7. package/dist/adapters/bun-ws/index.mjs +5 -5
  8. package/dist/adapters/crossws/index.d.mts +7 -7
  9. package/dist/adapters/crossws/index.d.ts +7 -7
  10. package/dist/adapters/crossws/index.mjs +5 -5
  11. package/dist/adapters/fastify/index.d.mts +53 -0
  12. package/dist/adapters/fastify/index.d.ts +53 -0
  13. package/dist/adapters/fastify/index.mjs +52 -0
  14. package/dist/adapters/fetch/index.d.mts +10 -10
  15. package/dist/adapters/fetch/index.d.ts +10 -10
  16. package/dist/adapters/fetch/index.mjs +4 -5
  17. package/dist/adapters/message-port/index.d.mts +8 -8
  18. package/dist/adapters/message-port/index.d.ts +8 -8
  19. package/dist/adapters/message-port/index.mjs +5 -5
  20. package/dist/adapters/node/index.d.mts +11 -11
  21. package/dist/adapters/node/index.d.ts +11 -11
  22. package/dist/adapters/node/index.mjs +4 -6
  23. package/dist/adapters/standard/index.d.mts +6 -6
  24. package/dist/adapters/standard/index.d.ts +6 -6
  25. package/dist/adapters/standard/index.mjs +2 -2
  26. package/dist/adapters/standard-peer/index.d.mts +3 -3
  27. package/dist/adapters/standard-peer/index.d.ts +3 -3
  28. package/dist/adapters/standard-peer/index.mjs +21 -7
  29. package/dist/adapters/websocket/index.d.mts +8 -8
  30. package/dist/adapters/websocket/index.d.ts +8 -8
  31. package/dist/adapters/websocket/index.mjs +5 -5
  32. package/dist/adapters/ws/index.d.mts +7 -7
  33. package/dist/adapters/ws/index.d.ts +7 -7
  34. package/dist/adapters/ws/index.mjs +5 -5
  35. package/dist/hibernation/index.d.mts +4 -4
  36. package/dist/hibernation/index.d.ts +4 -4
  37. package/dist/index.d.mts +101 -101
  38. package/dist/index.d.ts +101 -101
  39. package/dist/index.mjs +28 -28
  40. package/dist/plugins/index.d.mts +43 -11
  41. package/dist/plugins/index.d.ts +43 -11
  42. package/dist/plugins/index.mjs +42 -1
  43. package/dist/shared/{server.DPIFWpxG.d.ts → server.7cEtMB30.d.ts} +1 -1
  44. package/dist/shared/{server.CVKCo60T.d.mts → server.B8gYOD5g.d.mts} +2 -2
  45. package/dist/shared/{server.DBCUJijK.d.mts → server.BqadksTP.d.mts} +1 -1
  46. package/dist/shared/{server.DzV1hr3z.d.mts → server.C8_sRzQB.d.mts} +1 -1
  47. package/dist/shared/{server.Ck-gOLzq.d.mts → server.ChUyt5-i.d.mts} +3 -3
  48. package/dist/shared/{server.Cb6yD7DZ.d.ts → server.ChyoA9XY.d.ts} +1 -1
  49. package/dist/shared/{server.Ds4HPpvH.mjs → server.DEBcqOjg.mjs} +12 -3
  50. package/dist/shared/{server.DNtJ-p60.d.ts → server.EfTOZ2Q7.d.ts} +2 -2
  51. package/dist/shared/{server.Bxx6tqNe.mjs → server.ZxHCEN1h.mjs} +8 -1
  52. package/dist/shared/{server.B4BGqy3Y.d.mts → server.qKsRrdxW.d.mts} +8 -8
  53. package/dist/shared/{server.B4BGqy3Y.d.ts → server.qKsRrdxW.d.ts} +8 -8
  54. package/dist/shared/{server.COL12UTb.d.ts → server.yoEB3Fx4.d.ts} +3 -3
  55. package/package.json +25 -18
  56. package/dist/shared/server.UVMTOWrk.mjs +0 -26
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter, fallbackContractConfig } from '@orpc/contract';
2
2
  export { ValidationError, eventIterator, type, validateORPCError } from '@orpc/contract';
3
- import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, u as unlazy, g as getRouter, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure } from './shared/server.Ds4HPpvH.mjs';
4
- export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, v as resolveContractProcedures, t as traverseContractProcedures, w as unlazyRouter } from './shared/server.Ds4HPpvH.mjs';
3
+ import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, u as unlazy, g as getRouter, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure } from './shared/server.DEBcqOjg.mjs';
4
+ export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, v as resolveContractProcedures, t as traverseContractProcedures, w as unlazyRouter } from './shared/server.DEBcqOjg.mjs';
5
5
  import { toORPCError } from '@orpc/client';
6
6
  export { ORPCError, isDefinedError, safe } from '@orpc/client';
7
7
  import { isObject, resolveMaybeOptionalOptions } from '@orpc/shared';
8
8
  export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
9
- export { getEventMeta, withEventMeta } from '@orpc/standard-server';
9
+ export { ErrorEvent, getEventMeta, withEventMeta } from '@orpc/standard-server';
10
10
 
11
11
  const DEFAULT_CONFIG = {
12
12
  initialInputValidationIndex: 0,
@@ -68,7 +68,7 @@ class DecoratedProcedure extends Procedure {
68
68
  * Adds type-safe custom errors.
69
69
  * The provided errors are spared-merged with any existing errors.
70
70
  *
71
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
71
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
72
72
  */
73
73
  errors(errors) {
74
74
  return new DecoratedProcedure({
@@ -80,7 +80,7 @@ class DecoratedProcedure extends Procedure {
80
80
  * Sets or updates the metadata.
81
81
  * The provided metadata is spared-merged with any existing metadata.
82
82
  *
83
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
83
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
84
84
  */
85
85
  meta(meta) {
86
86
  return new DecoratedProcedure({
@@ -93,8 +93,8 @@ class DecoratedProcedure extends Procedure {
93
93
  * The provided route is spared-merged with any existing route.
94
94
  * This option is typically relevant when integrating with OpenAPI.
95
95
  *
96
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
97
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
96
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
97
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
98
98
  */
99
99
  route(route) {
100
100
  return new DecoratedProcedure({
@@ -112,7 +112,7 @@ class DecoratedProcedure extends Procedure {
112
112
  /**
113
113
  * Make this procedure callable (works like a function while still being a procedure).
114
114
  *
115
- * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
115
+ * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
116
116
  */
117
117
  callable(...rest) {
118
118
  const client = createProcedureClient(this, ...rest);
@@ -128,7 +128,7 @@ class DecoratedProcedure extends Procedure {
128
128
  /**
129
129
  * Make this procedure compatible with server action.
130
130
  *
131
- * @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
131
+ * @see {@link https://orpc.dev/docs/server-action Server Action Docs}
132
132
  */
133
133
  actionable(...rest) {
134
134
  const action = createActionableClient(createProcedureClient(this, ...rest));
@@ -154,8 +154,8 @@ class Builder {
154
154
  /**
155
155
  * Sets or overrides the config.
156
156
  *
157
- * @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
158
- * @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
157
+ * @see {@link https://orpc.dev/docs/client/server-side#middlewares-order Middlewares Order Docs}
158
+ * @see {@link https://orpc.dev/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
159
159
  */
160
160
  $config(config) {
161
161
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
@@ -171,7 +171,7 @@ class Builder {
171
171
  /**
172
172
  * Set or override the initial context.
173
173
  *
174
- * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
174
+ * @see {@link https://orpc.dev/docs/context Context Docs}
175
175
  */
176
176
  $context() {
177
177
  return new Builder({
@@ -184,7 +184,7 @@ class Builder {
184
184
  /**
185
185
  * Sets or overrides the initial meta.
186
186
  *
187
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
187
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
188
188
  */
189
189
  $meta(initialMeta) {
190
190
  return new Builder({
@@ -196,8 +196,8 @@ class Builder {
196
196
  * Sets or overrides the initial route.
197
197
  * This option is typically relevant when integrating with OpenAPI.
198
198
  *
199
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
200
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
199
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
200
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
201
201
  */
202
202
  $route(initialRoute) {
203
203
  return new Builder({
@@ -208,7 +208,7 @@ class Builder {
208
208
  /**
209
209
  * Sets or overrides the initial input schema.
210
210
  *
211
- * @see {@link https://orpc.unnoq.com/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
211
+ * @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
212
212
  */
213
213
  $input(initialInputSchema) {
214
214
  return new Builder({
@@ -219,7 +219,7 @@ class Builder {
219
219
  /**
220
220
  * Creates a middleware.
221
221
  *
222
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
222
+ * @see {@link https://orpc.dev/docs/middleware Middleware Docs}
223
223
  */
224
224
  middleware(middleware) {
225
225
  return decorateMiddleware(middleware);
@@ -228,7 +228,7 @@ class Builder {
228
228
  * Adds type-safe custom errors.
229
229
  * The provided errors are spared-merged with any existing errors.
230
230
  *
231
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
231
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
232
232
  */
233
233
  errors(errors) {
234
234
  return new Builder({
@@ -247,7 +247,7 @@ class Builder {
247
247
  * Sets or updates the metadata.
248
248
  * The provided metadata is spared-merged with any existing metadata.
249
249
  *
250
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
250
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
251
251
  */
252
252
  meta(meta) {
253
253
  return new Builder({
@@ -260,8 +260,8 @@ class Builder {
260
260
  * The provided route is spared-merged with any existing route.
261
261
  * This option is typically relevant when integrating with OpenAPI.
262
262
  *
263
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
264
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
263
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
264
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
265
265
  */
266
266
  route(route) {
267
267
  return new Builder({
@@ -272,7 +272,7 @@ class Builder {
272
272
  /**
273
273
  * Defines the input validation schema.
274
274
  *
275
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
275
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
276
276
  */
277
277
  input(schema) {
278
278
  return new Builder({
@@ -284,7 +284,7 @@ class Builder {
284
284
  /**
285
285
  * Defines the output validation schema.
286
286
  *
287
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
287
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
288
288
  */
289
289
  output(schema) {
290
290
  return new Builder({
@@ -296,7 +296,7 @@ class Builder {
296
296
  /**
297
297
  * Defines the handler of the procedure.
298
298
  *
299
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
299
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
300
300
  */
301
301
  handler(handler) {
302
302
  return new DecoratedProcedure({
@@ -310,7 +310,7 @@ class Builder {
310
310
  *
311
311
  * @note This option does not affect procedures that do not define a path in their route definition.
312
312
  *
313
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
313
+ * @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
314
314
  */
315
315
  prefix(prefix) {
316
316
  return new Builder({
@@ -322,7 +322,7 @@ class Builder {
322
322
  * Adds tags to all procedures in the router.
323
323
  * This helpful when you want to group procedures together in the OpenAPI specification.
324
324
  *
325
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
325
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
326
326
  */
327
327
  tag(...tags) {
328
328
  return new Builder({
@@ -333,7 +333,7 @@ class Builder {
333
333
  /**
334
334
  * Applies all of the previously defined options to the specified router.
335
335
  *
336
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
336
+ * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
337
337
  */
338
338
  router(router) {
339
339
  return enhanceRouter(router, this["~orpc"]);
@@ -342,7 +342,7 @@ class Builder {
342
342
  * Create a lazy router
343
343
  * And applies all of the previously defined options to the specified router.
344
344
  *
345
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
345
+ * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
346
346
  */
347
347
  lazy(loader) {
348
348
  return enhanceRouter(lazy(loader), this["~orpc"]);
@@ -1,8 +1,8 @@
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
- import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.DBCUJijK.mjs';
5
- import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.B4BGqy3Y.mjs';
4
+ import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.qKsRrdxW.mjs';
5
+ import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.BqadksTP.mjs';
6
6
  import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
7
  import { ORPCError } from '@orpc/client';
8
8
 
@@ -36,7 +36,7 @@ interface BatchHandlerOptions<T extends Context> {
36
36
  * The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
37
37
  * reducing the overhead of sending each one separately.
38
38
  *
39
- * @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
39
+ * @see {@link https://orpc.dev/docs/plugins/batch-requests Batch Requests Plugin Docs}
40
40
  */
41
41
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
42
42
  private readonly maxSize;
@@ -60,7 +60,7 @@ interface CORSOptions<T extends Context> {
60
60
  /**
61
61
  * CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
62
62
  *
63
- * @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
63
+ * @see {@link https://orpc.dev/docs/plugins/cors CORS Plugin Docs}
64
64
  */
65
65
  declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
66
66
  private readonly options;
@@ -76,7 +76,7 @@ interface RequestHeadersPluginContext {
76
76
  * The Request Headers Plugin injects a `reqHeaders` instance into the context,
77
77
  * allowing access to request headers in oRPC.
78
78
  *
79
- * @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
79
+ * @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
80
80
  */
81
81
  declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
82
82
  init(options: StandardHandlerOptions<T>): void;
@@ -89,12 +89,44 @@ interface ResponseHeadersPluginContext {
89
89
  * The Response Headers Plugin allows you to set response headers in oRPC.
90
90
  * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
91
91
  *
92
- * @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
92
+ * @see {@link https://orpc.dev/docs/plugins/response-headers Response Headers Plugin Docs}
93
93
  */
94
94
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
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.
@@ -131,7 +163,7 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
131
163
  * It helps ensure that requests to your procedures originate from JavaScript code,
132
164
  * not from other sources like standard HTML forms or direct browser navigation.
133
165
  *
134
- * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
166
+ * @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
135
167
  */
136
168
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
137
169
  private readonly headerName;
@@ -156,7 +188,7 @@ interface StrictGetMethodPluginOptions {
156
188
  * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
157
189
  * Cross-Site Request Forgery (CSRF) attacks.
158
190
  *
159
- * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
191
+ * @see {@link https://orpc.dev/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
160
192
  */
161
193
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
162
194
  private readonly error;
@@ -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,8 +1,8 @@
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
- import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.DPIFWpxG.js';
5
- import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.B4BGqy3Y.js';
4
+ import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.qKsRrdxW.js';
5
+ import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.7cEtMB30.js';
6
6
  import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
7
  import { ORPCError } from '@orpc/client';
8
8
 
@@ -36,7 +36,7 @@ interface BatchHandlerOptions<T extends Context> {
36
36
  * The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
37
37
  * reducing the overhead of sending each one separately.
38
38
  *
39
- * @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
39
+ * @see {@link https://orpc.dev/docs/plugins/batch-requests Batch Requests Plugin Docs}
40
40
  */
41
41
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
42
42
  private readonly maxSize;
@@ -60,7 +60,7 @@ interface CORSOptions<T extends Context> {
60
60
  /**
61
61
  * CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
62
62
  *
63
- * @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
63
+ * @see {@link https://orpc.dev/docs/plugins/cors CORS Plugin Docs}
64
64
  */
65
65
  declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
66
66
  private readonly options;
@@ -76,7 +76,7 @@ interface RequestHeadersPluginContext {
76
76
  * The Request Headers Plugin injects a `reqHeaders` instance into the context,
77
77
  * allowing access to request headers in oRPC.
78
78
  *
79
- * @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
79
+ * @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
80
80
  */
81
81
  declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
82
82
  init(options: StandardHandlerOptions<T>): void;
@@ -89,12 +89,44 @@ interface ResponseHeadersPluginContext {
89
89
  * The Response Headers Plugin allows you to set response headers in oRPC.
90
90
  * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
91
91
  *
92
- * @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
92
+ * @see {@link https://orpc.dev/docs/plugins/response-headers Response Headers Plugin Docs}
93
93
  */
94
94
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
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.
@@ -131,7 +163,7 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
131
163
  * It helps ensure that requests to your procedures originate from JavaScript code,
132
164
  * not from other sources like standard HTML forms or direct browser navigation.
133
165
  *
134
- * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
166
+ * @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
135
167
  */
136
168
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
137
169
  private readonly headerName;
@@ -156,7 +188,7 @@ interface StrictGetMethodPluginOptions {
156
188
  * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
157
189
  * Cross-Site Request Forgery (CSRF) attacks.
158
190
  *
159
- * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
191
+ * @see {@link https://orpc.dev/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
160
192
  */
161
193
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
162
194
  private readonly error;
@@ -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 };
@@ -2,7 +2,7 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta } from '@orpc/contract';
3
3
  import { Interceptor } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.B4BGqy3Y.js';
5
+ import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.qKsRrdxW.js';
6
6
 
7
7
  interface StandardHandlerPlugin<T extends Context> {
8
8
  order?: number;
@@ -1,5 +1,5 @@
1
- import { C as Context } from './server.B4BGqy3Y.mjs';
2
- import { b as StandardHandleOptions } from './server.DBCUJijK.mjs';
1
+ import { C as Context } from './server.qKsRrdxW.mjs';
2
+ import { b as StandardHandleOptions } from './server.BqadksTP.mjs';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;
@@ -2,7 +2,7 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta } from '@orpc/contract';
3
3
  import { Interceptor } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.B4BGqy3Y.mjs';
5
+ import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.qKsRrdxW.mjs';
6
6
 
7
7
  interface StandardHandlerPlugin<T extends Context> {
8
8
  order?: number;
@@ -1,5 +1,5 @@
1
1
  import { ErrorMap, EnhanceRouteOptions, MergedErrorMap, AnyContractRouter, AnyContractProcedure } from '@orpc/contract';
2
- import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.B4BGqy3Y.mjs';
2
+ import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.qKsRrdxW.mjs';
3
3
 
4
4
  declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
5
5
  type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
@@ -1,9 +1,9 @@
1
1
  import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
- import { b as AnyRouter, C as Context, R as Router } from './server.B4BGqy3Y.mjs';
3
- import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.DBCUJijK.mjs';
2
+ import { b as AnyRouter, C as Context, R as Router } from './server.qKsRrdxW.mjs';
3
+ import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.BqadksTP.mjs';
4
4
  import { HTTPPath } from '@orpc/client';
5
5
  import { Value } from '@orpc/shared';
6
- import { T as TraverseContractProcedureCallbackOptions } from './server.DzV1hr3z.mjs';
6
+ import { T as TraverseContractProcedureCallbackOptions } from './server.C8_sRzQB.mjs';
7
7
 
8
8
  interface StandardRPCMatcherOptions {
9
9
  /**
@@ -1,5 +1,5 @@
1
1
  import { ErrorMap, EnhanceRouteOptions, MergedErrorMap, AnyContractRouter, AnyContractProcedure } from '@orpc/contract';
2
- import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.B4BGqy3Y.js';
2
+ import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.qKsRrdxW.js';
3
3
 
4
4
  declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
5
5
  type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
@@ -1,5 +1,5 @@
1
1
  import { isContractProcedure, validateORPCError, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
2
- import { resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@orpc/shared';
2
+ import { resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan, isTypescriptObject } from '@orpc/shared';
3
3
  import { ORPCError, mapEventIterator } from '@orpc/client';
4
4
  import { HibernationEventIterator } from '@orpc/standard-server';
5
5
 
@@ -263,6 +263,9 @@ function getRouter(router, path) {
263
263
  if (isProcedure(current)) {
264
264
  return void 0;
265
265
  }
266
+ if (!isTypescriptObject(current)) {
267
+ return void 0;
268
+ }
266
269
  if (!isLazy(current)) {
267
270
  current = current[segment];
268
271
  continue;
@@ -317,6 +320,9 @@ function enhanceRouter(router, options) {
317
320
  });
318
321
  return enhanced2;
319
322
  }
323
+ if (typeof router !== "object" || router === null) {
324
+ return router;
325
+ }
320
326
  const enhanced = {};
321
327
  for (const key in router) {
322
328
  enhanced[key] = enhanceRouter(router[key], options);
@@ -325,7 +331,7 @@ function enhanceRouter(router, options) {
325
331
  }
326
332
  function traverseContractProcedures(options, callback, lazyOptions = []) {
327
333
  let currentRouter = options.router;
328
- const hiddenContract = getHiddenRouterContract(options.router);
334
+ const hiddenContract = isTypescriptObject(options.router) ? getHiddenRouterContract(options.router) : void 0;
329
335
  if (hiddenContract !== void 0) {
330
336
  currentRouter = hiddenContract;
331
337
  }
@@ -339,7 +345,7 @@ function traverseContractProcedures(options, callback, lazyOptions = []) {
339
345
  contract: currentRouter,
340
346
  path: options.path
341
347
  });
342
- } else {
348
+ } else if (typeof currentRouter === "object" && currentRouter !== null) {
343
349
  for (const key in currentRouter) {
344
350
  traverseContractProcedures(
345
351
  {
@@ -370,6 +376,9 @@ async function unlazyRouter(router) {
370
376
  if (isProcedure(router)) {
371
377
  return router;
372
378
  }
379
+ if (typeof router !== "object" || router === null) {
380
+ return router;
381
+ }
373
382
  const unlazied = {};
374
383
  for (const key in router) {
375
384
  const item = router[key];
@@ -1,5 +1,5 @@
1
- import { C as Context } from './server.B4BGqy3Y.js';
2
- import { b as StandardHandleOptions } from './server.DPIFWpxG.js';
1
+ import { C as Context } from './server.qKsRrdxW.js';
2
+ import { b as StandardHandleOptions } from './server.7cEtMB30.js';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;
@@ -2,7 +2,7 @@ import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@o
2
2
  import { ORPCError, toORPCError } from '@orpc/client';
3
3
  import { toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, parseEmptyableJSON, NullProtoObj, value } from '@orpc/shared';
4
4
  import { flattenHeader } from '@orpc/standard-server';
5
- import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.Ds4HPpvH.mjs';
5
+ import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.DEBcqOjg.mjs';
6
6
 
7
7
  class CompositeStandardHandlerPlugin {
8
8
  plugins;
@@ -121,6 +121,13 @@ class StandardRPCCodec {
121
121
  return this.serializer.deserialize(serialized);
122
122
  }
123
123
  encode(output, _procedure) {
124
+ if (output instanceof ReadableStream) {
125
+ return {
126
+ status: 200,
127
+ headers: {},
128
+ body: output
129
+ };
130
+ }
124
131
  return {
125
132
  status: 200,
126
133
  headers: {},