@orpc/server 0.0.0-next.e82d760 → 0.0.0-next.e8416db

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 (65) hide show
  1. package/README.md +11 -6
  2. package/dist/adapters/aws-lambda/index.d.mts +9 -8
  3. package/dist/adapters/aws-lambda/index.d.ts +9 -8
  4. package/dist/adapters/aws-lambda/index.mjs +6 -5
  5. package/dist/adapters/bun-ws/index.d.mts +14 -13
  6. package/dist/adapters/bun-ws/index.d.ts +14 -13
  7. package/dist/adapters/bun-ws/index.mjs +17 -16
  8. package/dist/adapters/crossws/index.d.mts +10 -7
  9. package/dist/adapters/crossws/index.d.ts +10 -7
  10. package/dist/adapters/crossws/index.mjs +9 -10
  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 +54 -0
  14. package/dist/adapters/fetch/index.d.mts +57 -11
  15. package/dist/adapters/fetch/index.d.ts +57 -11
  16. package/dist/adapters/fetch/index.mjs +74 -4
  17. package/dist/adapters/message-port/index.d.mts +42 -13
  18. package/dist/adapters/message-port/index.d.ts +42 -13
  19. package/dist/adapters/message-port/index.mjs +32 -18
  20. package/dist/adapters/node/index.d.mts +34 -12
  21. package/dist/adapters/node/index.d.ts +34 -12
  22. package/dist/adapters/node/index.mjs +70 -13
  23. package/dist/adapters/standard/index.d.mts +8 -13
  24. package/dist/adapters/standard/index.d.ts +8 -13
  25. package/dist/adapters/standard/index.mjs +3 -2
  26. package/dist/adapters/standard-peer/index.d.mts +18 -0
  27. package/dist/adapters/standard-peer/index.d.ts +18 -0
  28. package/dist/adapters/standard-peer/index.mjs +7 -0
  29. package/dist/adapters/websocket/index.d.mts +20 -15
  30. package/dist/adapters/websocket/index.d.ts +20 -15
  31. package/dist/adapters/websocket/index.mjs +13 -15
  32. package/dist/adapters/ws/index.d.mts +13 -10
  33. package/dist/adapters/ws/index.d.ts +13 -10
  34. package/dist/adapters/ws/index.mjs +13 -15
  35. package/dist/helpers/index.d.mts +149 -0
  36. package/dist/helpers/index.d.ts +149 -0
  37. package/dist/helpers/index.mjs +198 -0
  38. package/dist/hibernation/index.d.mts +13 -13
  39. package/dist/hibernation/index.d.ts +13 -13
  40. package/dist/hibernation/index.mjs +8 -8
  41. package/dist/index.d.mts +105 -136
  42. package/dist/index.d.ts +105 -136
  43. package/dist/index.mjs +37 -33
  44. package/dist/plugins/index.d.mts +25 -9
  45. package/dist/plugins/index.d.ts +25 -9
  46. package/dist/plugins/index.mjs +86 -58
  47. package/dist/shared/{server.-ACo36I0.d.ts → server.7cEtMB30.d.ts} +3 -3
  48. package/dist/shared/server.B8gYOD5g.d.mts +12 -0
  49. package/dist/shared/{server.Dq8xr7PQ.d.mts → server.BqadksTP.d.mts} +3 -3
  50. package/dist/shared/{server.CB8Snncu.mjs → server.Bxx6tqNe.mjs} +74 -41
  51. package/dist/shared/server.C8_sRzQB.d.mts +42 -0
  52. package/dist/shared/server.ChUyt5-i.d.mts +32 -0
  53. package/dist/shared/server.ChyoA9XY.d.ts +42 -0
  54. package/dist/shared/{server.DLJzqnSX.mjs → server.Ds4HPpvH.mjs} +114 -73
  55. package/dist/shared/server.EfTOZ2Q7.d.ts +12 -0
  56. package/dist/shared/{server.BW-nUGgA.mjs → server.TEVCLCFC.mjs} +3 -0
  57. package/dist/shared/server.UVMTOWrk.mjs +26 -0
  58. package/dist/shared/{server.DD2C4ujN.d.mts → server.qKsRrdxW.d.mts} +14 -13
  59. package/dist/shared/{server.DD2C4ujN.d.ts → server.qKsRrdxW.d.ts} +14 -13
  60. package/dist/shared/server.yoEB3Fx4.d.ts +32 -0
  61. package/package.json +34 -13
  62. package/dist/shared/server.BPAWobQg.d.ts +0 -12
  63. package/dist/shared/server.Bd52nNaH.d.mts +0 -12
  64. package/dist/shared/server.BliFSTnG.d.mts +0 -10
  65. package/dist/shared/server.IG2MjhrD.d.ts +0 -10
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter, fallbackContractConfig } from '@orpc/contract';
2
- export { ValidationError, eventIterator, type } 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.DLJzqnSX.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, w as resolveContractProcedures, t as traverseContractProcedures, x as unlazyRouter, v as validateORPCError } from './shared/server.DLJzqnSX.mjs';
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';
5
5
  import { toORPCError } from '@orpc/client';
6
6
  export { ORPCError, isDefinedError, safe } from '@orpc/client';
7
- import { resolveMaybeOptionalOptions } from '@orpc/shared';
8
- export { EventPublisher, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
7
+ import { isObject, resolveMaybeOptionalOptions } from '@orpc/shared';
8
+ export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
9
9
  export { getEventMeta, withEventMeta } from '@orpc/standard-server';
10
10
 
11
11
  const DEFAULT_CONFIG = {
@@ -21,7 +21,7 @@ function fallbackConfig(key, value) {
21
21
  }
22
22
 
23
23
  function decorateMiddleware(middleware) {
24
- const decorated = (...args) => middleware(...args);
24
+ const decorated = ((...args) => middleware(...args));
25
25
  decorated.mapInput = (mapInput) => {
26
26
  const mapped = decorateMiddleware(
27
27
  (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
@@ -54,6 +54,9 @@ function createActionableClient(client) {
54
54
  if (error instanceof Error && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_")) {
55
55
  throw error;
56
56
  }
57
+ if (error instanceof Response && "options" in error && isObject(error.options) || isObject(error) && error.isNotFound === true) {
58
+ throw error;
59
+ }
57
60
  return [toORPCError(error).toJSON(), void 0];
58
61
  }
59
62
  };
@@ -65,7 +68,7 @@ class DecoratedProcedure extends Procedure {
65
68
  * Adds type-safe custom errors.
66
69
  * The provided errors are spared-merged with any existing errors.
67
70
  *
68
- * @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}
69
72
  */
70
73
  errors(errors) {
71
74
  return new DecoratedProcedure({
@@ -77,7 +80,7 @@ class DecoratedProcedure extends Procedure {
77
80
  * Sets or updates the metadata.
78
81
  * The provided metadata is spared-merged with any existing metadata.
79
82
  *
80
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
83
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
81
84
  */
82
85
  meta(meta) {
83
86
  return new DecoratedProcedure({
@@ -90,8 +93,8 @@ class DecoratedProcedure extends Procedure {
90
93
  * The provided route is spared-merged with any existing route.
91
94
  * This option is typically relevant when integrating with OpenAPI.
92
95
  *
93
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
94
- * @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}
95
98
  */
96
99
  route(route) {
97
100
  return new DecoratedProcedure({
@@ -109,7 +112,7 @@ class DecoratedProcedure extends Procedure {
109
112
  /**
110
113
  * Make this procedure callable (works like a function while still being a procedure).
111
114
  *
112
- * @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}
113
116
  */
114
117
  callable(...rest) {
115
118
  const client = createProcedureClient(this, ...rest);
@@ -125,7 +128,7 @@ class DecoratedProcedure extends Procedure {
125
128
  /**
126
129
  * Make this procedure compatible with server action.
127
130
  *
128
- * @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
131
+ * @see {@link https://orpc.dev/docs/server-action Server Action Docs}
129
132
  */
130
133
  actionable(...rest) {
131
134
  const action = createActionableClient(createProcedureClient(this, ...rest));
@@ -151,8 +154,8 @@ class Builder {
151
154
  /**
152
155
  * Sets or overrides the config.
153
156
  *
154
- * @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
155
- * @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}
156
159
  */
157
160
  $config(config) {
158
161
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
@@ -168,7 +171,7 @@ class Builder {
168
171
  /**
169
172
  * Set or override the initial context.
170
173
  *
171
- * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
174
+ * @see {@link https://orpc.dev/docs/context Context Docs}
172
175
  */
173
176
  $context() {
174
177
  return new Builder({
@@ -181,7 +184,7 @@ class Builder {
181
184
  /**
182
185
  * Sets or overrides the initial meta.
183
186
  *
184
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
187
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
185
188
  */
186
189
  $meta(initialMeta) {
187
190
  return new Builder({
@@ -193,8 +196,8 @@ class Builder {
193
196
  * Sets or overrides the initial route.
194
197
  * This option is typically relevant when integrating with OpenAPI.
195
198
  *
196
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
197
- * @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}
198
201
  */
199
202
  $route(initialRoute) {
200
203
  return new Builder({
@@ -205,7 +208,7 @@ class Builder {
205
208
  /**
206
209
  * Sets or overrides the initial input schema.
207
210
  *
208
- * @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}
209
212
  */
210
213
  $input(initialInputSchema) {
211
214
  return new Builder({
@@ -216,7 +219,7 @@ class Builder {
216
219
  /**
217
220
  * Creates a middleware.
218
221
  *
219
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
222
+ * @see {@link https://orpc.dev/docs/middleware Middleware Docs}
220
223
  */
221
224
  middleware(middleware) {
222
225
  return decorateMiddleware(middleware);
@@ -225,7 +228,7 @@ class Builder {
225
228
  * Adds type-safe custom errors.
226
229
  * The provided errors are spared-merged with any existing errors.
227
230
  *
228
- * @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}
229
232
  */
230
233
  errors(errors) {
231
234
  return new Builder({
@@ -244,7 +247,7 @@ class Builder {
244
247
  * Sets or updates the metadata.
245
248
  * The provided metadata is spared-merged with any existing metadata.
246
249
  *
247
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
250
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
248
251
  */
249
252
  meta(meta) {
250
253
  return new Builder({
@@ -257,8 +260,8 @@ class Builder {
257
260
  * The provided route is spared-merged with any existing route.
258
261
  * This option is typically relevant when integrating with OpenAPI.
259
262
  *
260
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
261
- * @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}
262
265
  */
263
266
  route(route) {
264
267
  return new Builder({
@@ -269,7 +272,7 @@ class Builder {
269
272
  /**
270
273
  * Defines the input validation schema.
271
274
  *
272
- * @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}
273
276
  */
274
277
  input(schema) {
275
278
  return new Builder({
@@ -281,7 +284,7 @@ class Builder {
281
284
  /**
282
285
  * Defines the output validation schema.
283
286
  *
284
- * @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}
285
288
  */
286
289
  output(schema) {
287
290
  return new Builder({
@@ -293,7 +296,7 @@ class Builder {
293
296
  /**
294
297
  * Defines the handler of the procedure.
295
298
  *
296
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
299
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
297
300
  */
298
301
  handler(handler) {
299
302
  return new DecoratedProcedure({
@@ -307,7 +310,7 @@ class Builder {
307
310
  *
308
311
  * @note This option does not affect procedures that do not define a path in their route definition.
309
312
  *
310
- * @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}
311
314
  */
312
315
  prefix(prefix) {
313
316
  return new Builder({
@@ -319,7 +322,7 @@ class Builder {
319
322
  * Adds tags to all procedures in the router.
320
323
  * This helpful when you want to group procedures together in the OpenAPI specification.
321
324
  *
322
- * @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}
323
326
  */
324
327
  tag(...tags) {
325
328
  return new Builder({
@@ -330,7 +333,7 @@ class Builder {
330
333
  /**
331
334
  * Applies all of the previously defined options to the specified router.
332
335
  *
333
- * @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}
334
337
  */
335
338
  router(router) {
336
339
  return enhanceRouter(router, this["~orpc"]);
@@ -339,7 +342,7 @@ class Builder {
339
342
  * Create a lazy router
340
343
  * And applies all of the previously defined options to the specified router.
341
344
  *
342
- * @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}
343
346
  */
344
347
  lazy(loader) {
345
348
  return enhanceRouter(lazy(loader), this["~orpc"]);
@@ -462,11 +465,12 @@ function inferRPCMethodFromRouter(router) {
462
465
  }
463
466
 
464
467
  function createRouterClient(router, ...rest) {
468
+ const options = resolveMaybeOptionalOptions(rest);
465
469
  if (isProcedure(router)) {
466
- const caller = createProcedureClient(router, resolveMaybeOptionalOptions(rest));
470
+ const caller = createProcedureClient(router, options);
467
471
  return caller;
468
472
  }
469
- const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), resolveMaybeOptionalOptions(rest)) : {};
473
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
470
474
  const recursive = new Proxy(procedureCaller, {
471
475
  get(target, key) {
472
476
  if (typeof key !== "string") {
@@ -1,8 +1,8 @@
1
1
  import { Value, Promisable } from '@orpc/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
3
  import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
- import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.Dq8xr7PQ.mjs';
5
- import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DD2C4ujN.mjs';
4
+ import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.BqadksTP.mjs';
5
+ import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.qKsRrdxW.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;
@@ -69,6 +69,19 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
69
69
  init(options: StandardHandlerOptions<T>): void;
70
70
  }
71
71
 
72
+ interface RequestHeadersPluginContext {
73
+ reqHeaders?: Headers;
74
+ }
75
+ /**
76
+ * The Request Headers Plugin injects a `reqHeaders` instance into the context,
77
+ * allowing access to request headers in oRPC.
78
+ *
79
+ * @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
80
+ */
81
+ declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
82
+ init(options: StandardHandlerOptions<T>): void;
83
+ }
84
+
72
85
  interface ResponseHeadersPluginContext {
73
86
  resHeaders?: Headers;
74
87
  }
@@ -76,7 +89,7 @@ interface ResponseHeadersPluginContext {
76
89
  * The Response Headers Plugin allows you to set response headers in oRPC.
77
90
  * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
78
91
  *
79
- * @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}
80
93
  */
81
94
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
82
95
  init(options: StandardHandlerOptions<T>): void;
@@ -118,7 +131,7 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
118
131
  * It helps ensure that requests to your procedures originate from JavaScript code,
119
132
  * not from other sources like standard HTML forms or direct browser navigation.
120
133
  *
121
- * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
134
+ * @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
122
135
  */
123
136
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
124
137
  private readonly headerName;
@@ -143,14 +156,17 @@ interface StrictGetMethodPluginOptions {
143
156
  * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
144
157
  * Cross-Site Request Forgery (CSRF) attacks.
145
158
  *
146
- * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
159
+ * @see {@link https://orpc.dev/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
147
160
  */
148
161
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
149
162
  private readonly error;
163
+ /**
164
+ * make sure execute before batch plugin to get real method
165
+ */
150
166
  order: number;
151
167
  constructor(options?: StrictGetMethodPluginOptions);
152
168
  init(options: StandardHandlerOptions<T>): void;
153
169
  }
154
170
 
155
- export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
156
- export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
171
+ export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
172
+ export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
@@ -1,8 +1,8 @@
1
1
  import { Value, Promisable } from '@orpc/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
3
  import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
- import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.-ACo36I0.js';
5
- import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DD2C4ujN.js';
4
+ import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.7cEtMB30.js';
5
+ import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.qKsRrdxW.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;
@@ -69,6 +69,19 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
69
69
  init(options: StandardHandlerOptions<T>): void;
70
70
  }
71
71
 
72
+ interface RequestHeadersPluginContext {
73
+ reqHeaders?: Headers;
74
+ }
75
+ /**
76
+ * The Request Headers Plugin injects a `reqHeaders` instance into the context,
77
+ * allowing access to request headers in oRPC.
78
+ *
79
+ * @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
80
+ */
81
+ declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
82
+ init(options: StandardHandlerOptions<T>): void;
83
+ }
84
+
72
85
  interface ResponseHeadersPluginContext {
73
86
  resHeaders?: Headers;
74
87
  }
@@ -76,7 +89,7 @@ interface ResponseHeadersPluginContext {
76
89
  * The Response Headers Plugin allows you to set response headers in oRPC.
77
90
  * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
78
91
  *
79
- * @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}
80
93
  */
81
94
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
82
95
  init(options: StandardHandlerOptions<T>): void;
@@ -118,7 +131,7 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
118
131
  * It helps ensure that requests to your procedures originate from JavaScript code,
119
132
  * not from other sources like standard HTML forms or direct browser navigation.
120
133
  *
121
- * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
134
+ * @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
122
135
  */
123
136
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
124
137
  private readonly headerName;
@@ -143,14 +156,17 @@ interface StrictGetMethodPluginOptions {
143
156
  * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
144
157
  * Cross-Site Request Forgery (CSRF) attacks.
145
158
  *
146
- * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
159
+ * @see {@link https://orpc.dev/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
147
160
  */
148
161
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
149
162
  private readonly error;
163
+ /**
164
+ * make sure execute before batch plugin to get real method
165
+ */
150
166
  order: number;
151
167
  constructor(options?: StrictGetMethodPluginOptions);
152
168
  init(options: StandardHandlerOptions<T>): void;
153
169
  }
154
170
 
155
- export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
156
- export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
171
+ export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
172
+ export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
@@ -1,8 +1,9 @@
1
- import { value, isAsyncIteratorObject, clone } from '@orpc/shared';
1
+ import { runWithSpan, value, setSpanError, isAsyncIteratorObject, AsyncIteratorClass, clone } from '@orpc/shared';
2
2
  import { flattenHeader } from '@orpc/standard-server';
3
3
  import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
4
+ import { toFetchHeaders } from '@orpc/standard-server-fetch';
4
5
  import { ORPCError } from '@orpc/client';
5
- export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
6
+ export { S as StrictGetMethodPlugin } from '../shared/server.TEVCLCFC.mjs';
6
7
  import '@orpc/contract';
7
8
 
8
9
  class BatchHandlerPlugin {
@@ -32,65 +33,76 @@ class BatchHandlerPlugin {
32
33
  }
33
34
  let isParsing = false;
34
35
  try {
35
- isParsing = true;
36
- const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
37
- isParsing = false;
38
- const maxSize = await value(this.maxSize, options2);
39
- if (parsed.length > maxSize) {
40
- return {
41
- matched: true,
42
- response: {
43
- status: 413,
44
- headers: {},
45
- body: "Batch request size exceeds the maximum allowed size"
46
- }
47
- };
48
- }
49
- const responses = parsed.map(
50
- (request, index) => {
51
- const mapped = this.mapRequestItem(request, options2);
52
- return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
53
- if (matched) {
54
- if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
55
- return {
56
- index,
57
- status: 500,
58
- headers: {},
59
- body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
60
- };
61
- }
62
- return { ...response2, index };
36
+ return await runWithSpan({ name: "handle_batch_request" }, async (span) => {
37
+ const mode = xHeader === "buffered" ? "buffered" : "streaming";
38
+ isParsing = true;
39
+ const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
40
+ isParsing = false;
41
+ span?.setAttribute("batch.mode", mode);
42
+ span?.setAttribute("batch.size", parsed.length);
43
+ const maxSize = await value(this.maxSize, options2);
44
+ if (parsed.length > maxSize) {
45
+ const message = "Batch request size exceeds the maximum allowed size";
46
+ setSpanError(span, message);
47
+ return {
48
+ matched: true,
49
+ response: {
50
+ status: 413,
51
+ headers: {},
52
+ body: message
63
53
  }
64
- return { index, status: 404, headers: {}, body: "No procedure matched" };
65
- }).catch(() => {
66
- return { index, status: 500, headers: {}, body: "Internal server error" };
67
- });
54
+ };
68
55
  }
69
- );
70
- await Promise.race(responses);
71
- const status = await value(this.successStatus, responses, options2);
72
- const headers = await value(this.headers, responses, options2);
73
- const response = await toBatchResponse({
74
- status,
75
- headers,
76
- mode: xHeader === "buffered" ? "buffered" : "streaming",
77
- body: async function* () {
78
- const promises = [...responses];
79
- while (true) {
80
- const handling = promises.filter((p) => p !== void 0);
81
- if (handling.length === 0) {
82
- return;
83
- }
84
- const result = await Promise.race(handling);
85
- promises[result.index] = void 0;
86
- yield result;
56
+ const responses = parsed.map(
57
+ (request, index) => {
58
+ const mapped = this.mapRequestItem(request, options2);
59
+ return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
60
+ span?.addEvent(`response.${index}.${matched ? "success" : "not_matched"}`);
61
+ if (matched) {
62
+ if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
63
+ return {
64
+ index,
65
+ status: 500,
66
+ headers: {},
67
+ body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
68
+ };
69
+ }
70
+ return { ...response2, index };
71
+ }
72
+ return { index, status: 404, headers: {}, body: "No procedure matched" };
73
+ }).catch((err) => {
74
+ Promise.reject(err);
75
+ return { index, status: 500, headers: {}, body: "Internal server error" };
76
+ });
87
77
  }
88
- }()
78
+ );
79
+ await Promise.race(responses);
80
+ const status = await value(this.successStatus, responses, options2);
81
+ const headers = await value(this.headers, responses, options2);
82
+ const promises = [...responses];
83
+ const response = await toBatchResponse({
84
+ status,
85
+ headers,
86
+ mode,
87
+ body: new AsyncIteratorClass(
88
+ async () => {
89
+ const handling = promises.filter((p) => p !== void 0);
90
+ if (handling.length <= 0) {
91
+ return { done: true, value: void 0 };
92
+ }
93
+ const value2 = await Promise.race(handling);
94
+ promises[value2.index] = void 0;
95
+ return { done: false, value: value2 };
96
+ },
97
+ async () => {
98
+ }
99
+ )
100
+ });
101
+ return {
102
+ matched: true,
103
+ response
104
+ };
89
105
  });
90
- return {
91
- matched: true,
92
- response
93
- };
94
106
  } catch (cause) {
95
107
  if (isParsing) {
96
108
  return {
@@ -177,6 +189,22 @@ class CORSPlugin {
177
189
  }
178
190
  }
179
191
 
192
+ class RequestHeadersPlugin {
193
+ init(options) {
194
+ options.rootInterceptors ??= [];
195
+ options.rootInterceptors.push((interceptorOptions) => {
196
+ const reqHeaders = interceptorOptions.context.reqHeaders ?? toFetchHeaders(interceptorOptions.request.headers);
197
+ return interceptorOptions.next({
198
+ ...interceptorOptions,
199
+ context: {
200
+ ...interceptorOptions.context,
201
+ reqHeaders
202
+ }
203
+ });
204
+ });
205
+ }
206
+ }
207
+
180
208
  class ResponseHeadersPlugin {
181
209
  init(options) {
182
210
  options.rootInterceptors ??= [];
@@ -256,4 +284,4 @@ class SimpleCsrfProtectionHandlerPlugin {
256
284
  }
257
285
  }
258
286
 
259
- export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
287
+ export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
@@ -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, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions } from './server.DD2C4ujN.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;
@@ -70,5 +70,5 @@ declare class StandardHandler<T extends Context> {
70
70
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
71
71
  }
72
72
 
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 };
73
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as f };
74
+ export type { StandardCodec as S, StandardParams as a, StandardHandleOptions as b, StandardHandleResult as c, StandardHandlerInterceptorOptions as d, StandardHandlerOptions as e, StandardHandlerPlugin as g, StandardMatchResult as h, StandardMatcher as i };
@@ -0,0 +1,12 @@
1
+ import { C as Context } from './server.qKsRrdxW.mjs';
2
+ import { b as StandardHandleOptions } from './server.BqadksTP.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
+ declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
10
+
11
+ export { resolveFriendlyStandardHandleOptions as r };
12
+ export type { FriendlyStandardHandleOptions as F };
@@ -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, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions } from './server.DD2C4ujN.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;
@@ -70,5 +70,5 @@ declare class StandardHandler<T extends Context> {
70
70
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
71
71
  }
72
72
 
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 };
73
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as f };
74
+ export type { StandardCodec as S, StandardParams as a, StandardHandleOptions as b, StandardHandleResult as c, StandardHandlerInterceptorOptions as d, StandardHandlerOptions as e, StandardHandlerPlugin as g, StandardMatchResult as h, StandardMatcher as i };