@orpc/server 0.0.0-next.c7f8b1d → 0.0.0-next.c81407e

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 (63) hide show
  1. package/README.md +23 -23
  2. package/dist/adapters/aws-lambda/index.d.mts +46 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +46 -0
  4. package/dist/adapters/aws-lambda/index.mjs +42 -0
  5. package/dist/adapters/bun-ws/index.d.mts +36 -0
  6. package/dist/adapters/bun-ws/index.d.ts +36 -0
  7. package/dist/adapters/bun-ws/index.mjs +47 -0
  8. package/dist/adapters/crossws/index.d.mts +33 -0
  9. package/dist/adapters/crossws/index.d.ts +33 -0
  10. package/dist/adapters/crossws/index.mjs +45 -0
  11. package/dist/adapters/fetch/index.d.mts +74 -9
  12. package/dist/adapters/fetch/index.d.ts +74 -9
  13. package/dist/adapters/fetch/index.mjs +80 -5
  14. package/dist/adapters/message-port/index.d.mts +31 -0
  15. package/dist/adapters/message-port/index.d.ts +31 -0
  16. package/dist/adapters/message-port/index.mjs +39 -0
  17. package/dist/adapters/node/index.d.mts +50 -9
  18. package/dist/adapters/node/index.d.ts +50 -9
  19. package/dist/adapters/node/index.mjs +76 -14
  20. package/dist/adapters/standard/index.d.mts +8 -13
  21. package/dist/adapters/standard/index.d.ts +8 -13
  22. package/dist/adapters/standard/index.mjs +5 -5
  23. package/dist/adapters/standard-peer/index.d.mts +18 -0
  24. package/dist/adapters/standard-peer/index.d.ts +18 -0
  25. package/dist/adapters/standard-peer/index.mjs +7 -0
  26. package/dist/adapters/websocket/index.d.mts +56 -0
  27. package/dist/adapters/websocket/index.d.ts +56 -0
  28. package/dist/adapters/websocket/index.mjs +67 -0
  29. package/dist/adapters/ws/index.d.mts +31 -0
  30. package/dist/adapters/ws/index.d.ts +31 -0
  31. package/dist/adapters/ws/index.mjs +37 -0
  32. package/dist/helpers/index.d.mts +149 -0
  33. package/dist/helpers/index.d.ts +149 -0
  34. package/dist/helpers/index.mjs +198 -0
  35. package/dist/hibernation/index.d.mts +44 -0
  36. package/dist/hibernation/index.d.ts +44 -0
  37. package/dist/hibernation/index.mjs +65 -0
  38. package/dist/index.d.mts +563 -52
  39. package/dist/index.d.ts +563 -52
  40. package/dist/index.mjs +142 -13
  41. package/dist/plugins/index.d.mts +60 -13
  42. package/dist/plugins/index.d.ts +60 -13
  43. package/dist/plugins/index.mjs +102 -67
  44. package/dist/shared/{server.BVHsfJ99.d.mts → server.B4BGqy3Y.d.mts} +60 -11
  45. package/dist/shared/{server.BVHsfJ99.d.ts → server.B4BGqy3Y.d.ts} +60 -11
  46. package/dist/shared/{server.DFuJLDuo.mjs → server.Bxx6tqNe.mjs} +80 -51
  47. package/dist/shared/server.COL12UTb.d.ts +32 -0
  48. package/dist/shared/server.CVKCo60T.d.mts +12 -0
  49. package/dist/shared/server.Cb6yD7DZ.d.ts +42 -0
  50. package/dist/shared/server.Ck-gOLzq.d.mts +32 -0
  51. package/dist/shared/{server.CaWivVk3.d.ts → server.DBCUJijK.d.mts} +11 -11
  52. package/dist/shared/server.DNtJ-p60.d.ts +12 -0
  53. package/dist/shared/{server.B1oIHH_j.d.mts → server.DPIFWpxG.d.ts} +11 -11
  54. package/dist/shared/{server.BVwwTHyO.mjs → server.DZ5BIITo.mjs} +1 -1
  55. package/dist/shared/{server.C37gDhSZ.mjs → server.Ds4HPpvH.mjs} +119 -74
  56. package/dist/shared/server.DzV1hr3z.d.mts +42 -0
  57. package/dist/shared/{server.BW-nUGgA.mjs → server.TEVCLCFC.mjs} +3 -0
  58. package/dist/shared/server.UVMTOWrk.mjs +26 -0
  59. package/package.json +74 -8
  60. package/dist/shared/server.BuLPHTX1.d.mts +0 -18
  61. package/dist/shared/server.DMhSfHk1.d.ts +0 -10
  62. package/dist/shared/server.D_vpYits.d.ts +0 -18
  63. package/dist/shared/server.Dwnm6cSk.d.mts +0 -10
package/dist/index.mjs CHANGED
@@ -1,10 +1,11 @@
1
- import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } 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, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure, g as getRouter } from './shared/server.C37gDhSZ.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, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.C37gDhSZ.mjs';
1
+ import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter, fallbackContractConfig } from '@orpc/contract';
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
- export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
7
+ import { isObject, resolveMaybeOptionalOptions } from '@orpc/shared';
8
+ export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
8
9
  export { getEventMeta, withEventMeta } from '@orpc/standard-server';
9
10
 
10
11
  const DEFAULT_CONFIG = {
@@ -20,7 +21,7 @@ function fallbackConfig(key, value) {
20
21
  }
21
22
 
22
23
  function decorateMiddleware(middleware) {
23
- const decorated = (...args) => middleware(...args);
24
+ const decorated = ((...args) => middleware(...args));
24
25
  decorated.mapInput = (mapInput) => {
25
26
  const mapped = decorateMiddleware(
26
27
  (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
@@ -50,6 +51,12 @@ function createActionableClient(client) {
50
51
  try {
51
52
  return [null, await client(input)];
52
53
  } catch (error) {
54
+ if (error instanceof Error && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_")) {
55
+ throw error;
56
+ }
57
+ if (error instanceof Response && "options" in error && isObject(error.options) || isObject(error) && error.isNotFound === true) {
58
+ throw error;
59
+ }
53
60
  return [toORPCError(error).toJSON(), void 0];
54
61
  }
55
62
  };
@@ -57,18 +64,38 @@ function createActionableClient(client) {
57
64
  }
58
65
 
59
66
  class DecoratedProcedure extends Procedure {
67
+ /**
68
+ * Adds type-safe custom errors.
69
+ * The provided errors are spared-merged with any existing errors.
70
+ *
71
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
72
+ */
60
73
  errors(errors) {
61
74
  return new DecoratedProcedure({
62
75
  ...this["~orpc"],
63
76
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
64
77
  });
65
78
  }
79
+ /**
80
+ * Sets or updates the metadata.
81
+ * The provided metadata is spared-merged with any existing metadata.
82
+ *
83
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
84
+ */
66
85
  meta(meta) {
67
86
  return new DecoratedProcedure({
68
87
  ...this["~orpc"],
69
88
  meta: mergeMeta(this["~orpc"].meta, meta)
70
89
  });
71
90
  }
91
+ /**
92
+ * Sets or updates the route definition.
93
+ * The provided route is spared-merged with any existing route.
94
+ * This option is typically relevant when integrating with OpenAPI.
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}
98
+ */
72
99
  route(route) {
73
100
  return new DecoratedProcedure({
74
101
  ...this["~orpc"],
@@ -84,6 +111,8 @@ class DecoratedProcedure extends Procedure {
84
111
  }
85
112
  /**
86
113
  * Make this procedure callable (works like a function while still being a procedure).
114
+ *
115
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
87
116
  */
88
117
  callable(...rest) {
89
118
  const client = createProcedureClient(this, ...rest);
@@ -98,6 +127,8 @@ class DecoratedProcedure extends Procedure {
98
127
  }
99
128
  /**
100
129
  * Make this procedure compatible with server action.
130
+ *
131
+ * @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
101
132
  */
102
133
  actionable(...rest) {
103
134
  const action = createActionableClient(createProcedureClient(this, ...rest));
@@ -113,12 +144,18 @@ class DecoratedProcedure extends Procedure {
113
144
  }
114
145
 
115
146
  class Builder {
147
+ /**
148
+ * This property holds the defined options.
149
+ */
116
150
  "~orpc";
117
151
  constructor(def) {
118
152
  this["~orpc"] = def;
119
153
  }
120
154
  /**
121
- * Reset config
155
+ * Sets or overrides the config.
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}
122
159
  */
123
160
  $config(config) {
124
161
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
@@ -132,7 +169,9 @@ class Builder {
132
169
  });
133
170
  }
134
171
  /**
135
- * Reset initial context
172
+ * Set or override the initial context.
173
+ *
174
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
136
175
  */
137
176
  $context() {
138
177
  return new Builder({
@@ -143,7 +182,9 @@ class Builder {
143
182
  });
144
183
  }
145
184
  /**
146
- * Reset initial meta
185
+ * Sets or overrides the initial meta.
186
+ *
187
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
147
188
  */
148
189
  $meta(initialMeta) {
149
190
  return new Builder({
@@ -152,7 +193,11 @@ class Builder {
152
193
  });
153
194
  }
154
195
  /**
155
- * Reset initial route
196
+ * Sets or overrides the initial route.
197
+ * This option is typically relevant when integrating with OpenAPI.
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}
156
201
  */
157
202
  $route(initialRoute) {
158
203
  return new Builder({
@@ -160,15 +205,31 @@ class Builder {
160
205
  route: initialRoute
161
206
  });
162
207
  }
208
+ /**
209
+ * Sets or overrides the initial input schema.
210
+ *
211
+ * @see {@link https://orpc.unnoq.com/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
212
+ */
163
213
  $input(initialInputSchema) {
164
214
  return new Builder({
165
215
  ...this["~orpc"],
166
216
  inputSchema: initialInputSchema
167
217
  });
168
218
  }
219
+ /**
220
+ * Creates a middleware.
221
+ *
222
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
223
+ */
169
224
  middleware(middleware) {
170
225
  return decorateMiddleware(middleware);
171
226
  }
227
+ /**
228
+ * Adds type-safe custom errors.
229
+ * The provided errors are spared-merged with any existing errors.
230
+ *
231
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
232
+ */
172
233
  errors(errors) {
173
234
  return new Builder({
174
235
  ...this["~orpc"],
@@ -182,18 +243,37 @@ class Builder {
182
243
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
183
244
  });
184
245
  }
246
+ /**
247
+ * Sets or updates the metadata.
248
+ * The provided metadata is spared-merged with any existing metadata.
249
+ *
250
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
251
+ */
185
252
  meta(meta) {
186
253
  return new Builder({
187
254
  ...this["~orpc"],
188
255
  meta: mergeMeta(this["~orpc"].meta, meta)
189
256
  });
190
257
  }
258
+ /**
259
+ * Sets or updates the route definition.
260
+ * The provided route is spared-merged with any existing route.
261
+ * This option is typically relevant when integrating with OpenAPI.
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}
265
+ */
191
266
  route(route) {
192
267
  return new Builder({
193
268
  ...this["~orpc"],
194
269
  route: mergeRoute(this["~orpc"].route, route)
195
270
  });
196
271
  }
272
+ /**
273
+ * Defines the input validation schema.
274
+ *
275
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
276
+ */
197
277
  input(schema) {
198
278
  return new Builder({
199
279
  ...this["~orpc"],
@@ -201,6 +281,11 @@ class Builder {
201
281
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
202
282
  });
203
283
  }
284
+ /**
285
+ * Defines the output validation schema.
286
+ *
287
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
288
+ */
204
289
  output(schema) {
205
290
  return new Builder({
206
291
  ...this["~orpc"],
@@ -208,27 +293,57 @@ class Builder {
208
293
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
209
294
  });
210
295
  }
296
+ /**
297
+ * Defines the handler of the procedure.
298
+ *
299
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
300
+ */
211
301
  handler(handler) {
212
302
  return new DecoratedProcedure({
213
303
  ...this["~orpc"],
214
304
  handler
215
305
  });
216
306
  }
307
+ /**
308
+ * Prefixes all procedures in the router.
309
+ * The provided prefix is post-appended to any existing router prefix.
310
+ *
311
+ * @note This option does not affect procedures that do not define a path in their route definition.
312
+ *
313
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
314
+ */
217
315
  prefix(prefix) {
218
316
  return new Builder({
219
317
  ...this["~orpc"],
220
318
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
221
319
  });
222
320
  }
321
+ /**
322
+ * Adds tags to all procedures in the router.
323
+ * This helpful when you want to group procedures together in the OpenAPI specification.
324
+ *
325
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
326
+ */
223
327
  tag(...tags) {
224
328
  return new Builder({
225
329
  ...this["~orpc"],
226
330
  tags: mergeTags(this["~orpc"].tags, tags)
227
331
  });
228
332
  }
333
+ /**
334
+ * Applies all of the previously defined options to the specified router.
335
+ *
336
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
337
+ */
229
338
  router(router) {
230
339
  return enhanceRouter(router, this["~orpc"]);
231
340
  }
341
+ /**
342
+ * Create a lazy router
343
+ * And applies all of the previously defined options to the specified router.
344
+ *
345
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
346
+ */
232
347
  lazy(loader) {
233
348
  return enhanceRouter(lazy(loader), this["~orpc"]);
234
349
  }
@@ -336,12 +451,26 @@ function implement(contract, config = {}) {
336
451
  return impl;
337
452
  }
338
453
 
454
+ function inferRPCMethodFromRouter(router) {
455
+ return async (_, path) => {
456
+ const { default: procedure } = await unlazy(getRouter(router, path));
457
+ if (!isProcedure(procedure)) {
458
+ throw new Error(
459
+ `[inferRPCMethodFromRouter] No valid procedure found at path "${path.join(".")}". This may happen when the router is not properly configured.`
460
+ );
461
+ }
462
+ const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
463
+ return method === "HEAD" ? "GET" : method;
464
+ };
465
+ }
466
+
339
467
  function createRouterClient(router, ...rest) {
468
+ const options = resolveMaybeOptionalOptions(rest);
340
469
  if (isProcedure(router)) {
341
- const caller = createProcedureClient(router, ...rest);
470
+ const caller = createProcedureClient(router, options);
342
471
  return caller;
343
472
  }
344
- const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), ...rest) : {};
473
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
345
474
  const recursive = new Proxy(procedureCaller, {
346
475
  get(target, key) {
347
476
  if (typeof key !== "string") {
@@ -360,4 +489,4 @@ function createRouterClient(router, ...rest) {
360
489
  return recursive;
361
490
  }
362
491
 
363
- export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
492
+ export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isLazy, isProcedure, lazy, os, setHiddenRouterContract, unlazy };
@@ -1,8 +1,8 @@
1
- import { Value } from '@orpc/shared';
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.B1oIHH_j.mjs';
5
- import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.BVHsfJ99.mjs';
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';
6
6
  import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
7
  import { ORPCError } from '@orpc/client';
8
8
 
@@ -12,7 +12,7 @@ interface BatchHandlerOptions<T extends Context> {
12
12
  *
13
13
  * @default 10
14
14
  */
15
- maxSize?: Value<number, [StandardHandlerInterceptorOptions<T>]>;
15
+ maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
16
16
  /**
17
17
  * Map the request before processing it.
18
18
  *
@@ -24,14 +24,20 @@ interface BatchHandlerOptions<T extends Context> {
24
24
  *
25
25
  * @default 207
26
26
  */
27
- successStatus?: Value<number, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
27
+ successStatus?: Value<Promisable<number>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
28
28
  /**
29
29
  * success batch response headers.
30
30
  *
31
31
  * @default {}
32
32
  */
33
- headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
33
+ headers?: Value<Promisable<StandardHeaders>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
34
34
  }
35
+ /**
36
+ * The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
37
+ * reducing the overhead of sending each one separately.
38
+ *
39
+ * @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
40
+ */
35
41
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
42
  private readonly maxSize;
37
43
  private readonly mapRequestItem;
@@ -43,14 +49,19 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
43
49
  }
44
50
 
45
51
  interface CORSOptions<T extends Context> {
46
- origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
47
- timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
52
+ origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
53
+ timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
48
54
  allowMethods?: readonly string[];
49
55
  allowHeaders?: readonly string[];
50
56
  maxAge?: number;
51
57
  credentials?: boolean;
52
58
  exposeHeaders?: readonly string[];
53
59
  }
60
+ /**
61
+ * CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
62
+ *
63
+ * @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
64
+ */
54
65
  declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
55
66
  private readonly options;
56
67
  order: number;
@@ -58,9 +69,28 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
58
69
  init(options: StandardHandlerOptions<T>): void;
59
70
  }
60
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.unnoq.com/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
+
61
85
  interface ResponseHeadersPluginContext {
62
86
  resHeaders?: Headers;
63
87
  }
88
+ /**
89
+ * The Response Headers Plugin allows you to set response headers in oRPC.
90
+ * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
91
+ *
92
+ * @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
93
+ */
64
94
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
65
95
  init(options: StandardHandlerOptions<T>): void;
66
96
  }
@@ -71,21 +101,21 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
71
101
  *
72
102
  * @default 'x-csrf-token'
73
103
  */
74
- headerName?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
104
+ headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
75
105
  /**
76
106
  * The value of the header to check.
77
107
  *
78
108
  * @default 'orpc'
79
109
  *
80
110
  */
81
- headerValue?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
111
+ headerValue?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
82
112
  /**
83
113
  * Exclude a procedure from the plugin.
84
114
  *
85
115
  * @default false
86
116
  *
87
117
  */
88
- exclude?: Value<boolean, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
118
+ exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
89
119
  /**
90
120
  * The error thrown when the CSRF token is invalid.
91
121
  *
@@ -96,6 +126,13 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
96
126
  */
97
127
  error?: InstanceType<typeof ORPCError>;
98
128
  }
129
+ /**
130
+ * This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
131
+ * It helps ensure that requests to your procedures originate from JavaScript code,
132
+ * not from other sources like standard HTML forms or direct browser navigation.
133
+ *
134
+ * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
135
+ */
99
136
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
100
137
  private readonly headerName;
101
138
  private readonly headerValue;
@@ -114,12 +151,22 @@ interface StrictGetMethodPluginOptions {
114
151
  */
115
152
  error?: InstanceType<typeof ORPCError$1>;
116
153
  }
154
+ /**
155
+ * This plugin enhances security by ensuring only procedures explicitly marked to accept GET requests
156
+ * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
157
+ * Cross-Site Request Forgery (CSRF) attacks.
158
+ *
159
+ * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
160
+ */
117
161
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
118
162
  private readonly error;
163
+ /**
164
+ * make sure execute before batch plugin to get real method
165
+ */
119
166
  order: number;
120
167
  constructor(options?: StrictGetMethodPluginOptions);
121
168
  init(options: StandardHandlerOptions<T>): void;
122
169
  }
123
170
 
124
- export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
125
- 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
- import { Value } from '@orpc/shared';
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.CaWivVk3.js';
5
- import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.BVHsfJ99.js';
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';
6
6
  import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
7
  import { ORPCError } from '@orpc/client';
8
8
 
@@ -12,7 +12,7 @@ interface BatchHandlerOptions<T extends Context> {
12
12
  *
13
13
  * @default 10
14
14
  */
15
- maxSize?: Value<number, [StandardHandlerInterceptorOptions<T>]>;
15
+ maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
16
16
  /**
17
17
  * Map the request before processing it.
18
18
  *
@@ -24,14 +24,20 @@ interface BatchHandlerOptions<T extends Context> {
24
24
  *
25
25
  * @default 207
26
26
  */
27
- successStatus?: Value<number, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
27
+ successStatus?: Value<Promisable<number>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
28
28
  /**
29
29
  * success batch response headers.
30
30
  *
31
31
  * @default {}
32
32
  */
33
- headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
33
+ headers?: Value<Promisable<StandardHeaders>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
34
34
  }
35
+ /**
36
+ * The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
37
+ * reducing the overhead of sending each one separately.
38
+ *
39
+ * @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
40
+ */
35
41
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
42
  private readonly maxSize;
37
43
  private readonly mapRequestItem;
@@ -43,14 +49,19 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
43
49
  }
44
50
 
45
51
  interface CORSOptions<T extends Context> {
46
- origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
47
- timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
52
+ origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
53
+ timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
48
54
  allowMethods?: readonly string[];
49
55
  allowHeaders?: readonly string[];
50
56
  maxAge?: number;
51
57
  credentials?: boolean;
52
58
  exposeHeaders?: readonly string[];
53
59
  }
60
+ /**
61
+ * CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
62
+ *
63
+ * @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
64
+ */
54
65
  declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
55
66
  private readonly options;
56
67
  order: number;
@@ -58,9 +69,28 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
58
69
  init(options: StandardHandlerOptions<T>): void;
59
70
  }
60
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.unnoq.com/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
+
61
85
  interface ResponseHeadersPluginContext {
62
86
  resHeaders?: Headers;
63
87
  }
88
+ /**
89
+ * The Response Headers Plugin allows you to set response headers in oRPC.
90
+ * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
91
+ *
92
+ * @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
93
+ */
64
94
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
65
95
  init(options: StandardHandlerOptions<T>): void;
66
96
  }
@@ -71,21 +101,21 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
71
101
  *
72
102
  * @default 'x-csrf-token'
73
103
  */
74
- headerName?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
104
+ headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
75
105
  /**
76
106
  * The value of the header to check.
77
107
  *
78
108
  * @default 'orpc'
79
109
  *
80
110
  */
81
- headerValue?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
111
+ headerValue?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
82
112
  /**
83
113
  * Exclude a procedure from the plugin.
84
114
  *
85
115
  * @default false
86
116
  *
87
117
  */
88
- exclude?: Value<boolean, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
118
+ exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
89
119
  /**
90
120
  * The error thrown when the CSRF token is invalid.
91
121
  *
@@ -96,6 +126,13 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
96
126
  */
97
127
  error?: InstanceType<typeof ORPCError>;
98
128
  }
129
+ /**
130
+ * This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
131
+ * It helps ensure that requests to your procedures originate from JavaScript code,
132
+ * not from other sources like standard HTML forms or direct browser navigation.
133
+ *
134
+ * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
135
+ */
99
136
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
100
137
  private readonly headerName;
101
138
  private readonly headerValue;
@@ -114,12 +151,22 @@ interface StrictGetMethodPluginOptions {
114
151
  */
115
152
  error?: InstanceType<typeof ORPCError$1>;
116
153
  }
154
+ /**
155
+ * This plugin enhances security by ensuring only procedures explicitly marked to accept GET requests
156
+ * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
157
+ * Cross-Site Request Forgery (CSRF) attacks.
158
+ *
159
+ * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
160
+ */
117
161
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
118
162
  private readonly error;
163
+ /**
164
+ * make sure execute before batch plugin to get real method
165
+ */
119
166
  order: number;
120
167
  constructor(options?: StrictGetMethodPluginOptions);
121
168
  init(options: StandardHandlerOptions<T>): void;
122
169
  }
123
170
 
124
- export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
125
- export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
171
+ export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
172
+ export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };