@orpc/server 0.0.0-next.df024bb → 0.0.0-next.e000d9a

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 (55) hide show
  1. package/README.md +27 -17
  2. package/dist/adapters/bun-ws/index.d.mts +35 -0
  3. package/dist/adapters/bun-ws/index.d.ts +35 -0
  4. package/dist/adapters/bun-ws/index.mjs +51 -0
  5. package/dist/adapters/crossws/index.d.mts +30 -0
  6. package/dist/adapters/crossws/index.d.ts +30 -0
  7. package/dist/adapters/crossws/index.mjs +51 -0
  8. package/dist/adapters/fetch/index.d.mts +62 -11
  9. package/dist/adapters/fetch/index.d.ts +62 -11
  10. package/dist/adapters/fetch/index.mjs +108 -7
  11. package/dist/adapters/node/index.d.mts +64 -22
  12. package/dist/adapters/node/index.d.ts +64 -22
  13. package/dist/adapters/node/index.mjs +86 -21
  14. package/dist/adapters/standard/index.d.mts +12 -15
  15. package/dist/adapters/standard/index.d.ts +12 -15
  16. package/dist/adapters/standard/index.mjs +4 -4
  17. package/dist/adapters/websocket/index.d.mts +27 -0
  18. package/dist/adapters/websocket/index.d.ts +27 -0
  19. package/dist/adapters/websocket/index.mjs +38 -0
  20. package/dist/adapters/ws/index.d.mts +28 -0
  21. package/dist/adapters/ws/index.d.ts +28 -0
  22. package/dist/adapters/ws/index.mjs +38 -0
  23. package/dist/index.d.mts +701 -127
  24. package/dist/index.d.ts +701 -127
  25. package/dist/index.mjs +193 -52
  26. package/dist/plugins/index.d.mts +143 -18
  27. package/dist/plugins/index.d.ts +143 -18
  28. package/dist/plugins/index.mjs +163 -15
  29. package/dist/shared/{server.BBGuTxHE.mjs → server.4FnxLwwr.mjs} +68 -45
  30. package/dist/shared/server.BRoxSiSC.d.mts +12 -0
  31. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  32. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  33. package/dist/shared/server.BjiJH9Vo.d.ts +10 -0
  34. package/dist/shared/server.Cy1vfSiG.d.ts +12 -0
  35. package/dist/shared/{server.V6zT5iYQ.mjs → server.DG7Tamti.mjs} +161 -173
  36. package/dist/shared/server.DPWk5pjW.d.mts +192 -0
  37. package/dist/shared/server.DPWk5pjW.d.ts +192 -0
  38. package/dist/shared/server.QUe9N8P4.d.mts +10 -0
  39. package/dist/shared/server.YZzrREz9.d.ts +74 -0
  40. package/dist/shared/server.eWLxY3lq.d.mts +74 -0
  41. package/package.json +43 -20
  42. package/dist/adapters/hono/index.d.mts +0 -20
  43. package/dist/adapters/hono/index.d.ts +0 -20
  44. package/dist/adapters/hono/index.mjs +0 -32
  45. package/dist/adapters/next/index.d.mts +0 -27
  46. package/dist/adapters/next/index.d.ts +0 -27
  47. package/dist/adapters/next/index.mjs +0 -29
  48. package/dist/shared/server.BMaJxq9W.d.mts +0 -9
  49. package/dist/shared/server.BT-fqIEm.d.mts +0 -77
  50. package/dist/shared/server.DpdgHO1j.d.ts +0 -9
  51. package/dist/shared/server.KwueCzFr.mjs +0 -26
  52. package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
  53. package/dist/shared/server.ptXwNGQr.d.mts +0 -158
  54. package/dist/shared/server.ptXwNGQr.d.ts +0 -158
  55. package/dist/shared/server.xL87pHsk.d.ts +0 -77
package/dist/index.mjs CHANGED
@@ -1,14 +1,16 @@
1
- import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure } from '@orpc/contract';
1
+ import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
2
2
  export { ValidationError, eventIterator, type } from '@orpc/contract';
3
- import { P as Procedure, d as addMiddleware, c as createProcedureClient, f as adaptRouter, h as flatLazy, l as lazy, s as setRouterContract, i as isProcedure, j as isLazy, k as createLazyProcedureFormAnyLazy, g as getRouterChild } from './shared/server.V6zT5iYQ.mjs';
4
- export { L as LAZY_LOADER_SYMBOL, a as convertPathToHttpPath, q as createAccessibleLazyRouter, b as createContractedProcedure, n as deepSetLazyRouterPrefix, r as eachAllContractProcedure, e as eachContractProcedure, o as getLazyRouterPrefix, m as getRouterContract, p as middlewareOutputFn, u as unlazy } from './shared/server.V6zT5iYQ.mjs';
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.DG7Tamti.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.DG7Tamti.mjs';
5
+ import { toORPCError } from '@orpc/client';
5
6
  export { ORPCError, isDefinedError, safe } from '@orpc/client';
6
7
  export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
7
8
  export { getEventMeta, withEventMeta } from '@orpc/standard-server';
8
9
 
9
10
  const DEFAULT_CONFIG = {
10
11
  initialInputValidationIndex: 0,
11
- initialOutputValidationIndex: 0
12
+ initialOutputValidationIndex: 0,
13
+ dedupeLeadingMiddlewares: true
12
14
  };
13
15
  function fallbackConfig(key, value) {
14
16
  if (value === void 0) {
@@ -18,7 +20,7 @@ function fallbackConfig(key, value) {
18
20
  }
19
21
 
20
22
  function decorateMiddleware(middleware) {
21
- const decorated = middleware;
23
+ const decorated = (...args) => middleware(...args);
22
24
  decorated.mapInput = (mapInput) => {
23
25
  const mapped = decorateMiddleware(
24
26
  (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
@@ -43,19 +45,53 @@ function decorateMiddleware(middleware) {
43
45
  return decorated;
44
46
  }
45
47
 
48
+ function createActionableClient(client) {
49
+ const action = async (input) => {
50
+ try {
51
+ return [null, await client(input)];
52
+ } catch (error) {
53
+ if (error instanceof Error && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_")) {
54
+ throw error;
55
+ }
56
+ return [toORPCError(error).toJSON(), void 0];
57
+ }
58
+ };
59
+ return action;
60
+ }
61
+
46
62
  class DecoratedProcedure extends Procedure {
63
+ /**
64
+ * Adds type-safe custom errors.
65
+ * The provided errors are spared-merged with any existing errors.
66
+ *
67
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
68
+ */
47
69
  errors(errors) {
48
70
  return new DecoratedProcedure({
49
71
  ...this["~orpc"],
50
72
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
51
73
  });
52
74
  }
75
+ /**
76
+ * Sets or updates the metadata.
77
+ * The provided metadata is spared-merged with any existing metadata.
78
+ *
79
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
80
+ */
53
81
  meta(meta) {
54
82
  return new DecoratedProcedure({
55
83
  ...this["~orpc"],
56
84
  meta: mergeMeta(this["~orpc"].meta, meta)
57
85
  });
58
86
  }
87
+ /**
88
+ * Sets or updates the route definition.
89
+ * The provided route is spared-merged with any existing route.
90
+ * This option is typically relevant when integrating with OpenAPI.
91
+ *
92
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
93
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
94
+ */
59
95
  route(route) {
60
96
  return new DecoratedProcedure({
61
97
  ...this["~orpc"],
@@ -71,28 +107,51 @@ class DecoratedProcedure extends Procedure {
71
107
  }
72
108
  /**
73
109
  * Make this procedure callable (works like a function while still being a procedure).
110
+ *
111
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
74
112
  */
75
113
  callable(...rest) {
76
- return Object.assign(createProcedureClient(this, ...rest), {
77
- "~type": "Procedure",
78
- "~orpc": this["~orpc"]
114
+ const client = createProcedureClient(this, ...rest);
115
+ return new Proxy(client, {
116
+ get: (target, key) => {
117
+ return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
118
+ },
119
+ has: (target, key) => {
120
+ return Reflect.has(this, key) || Reflect.has(target, key);
121
+ }
79
122
  });
80
123
  }
81
124
  /**
82
- * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
125
+ * Make this procedure compatible with server action.
126
+ *
127
+ * @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
83
128
  */
84
129
  actionable(...rest) {
85
- return this.callable(...rest);
130
+ const action = createActionableClient(createProcedureClient(this, ...rest));
131
+ return new Proxy(action, {
132
+ get: (target, key) => {
133
+ return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
134
+ },
135
+ has: (target, key) => {
136
+ return Reflect.has(this, key) || Reflect.has(target, key);
137
+ }
138
+ });
86
139
  }
87
140
  }
88
141
 
89
142
  class Builder {
143
+ /**
144
+ * This property holds the defined options.
145
+ */
90
146
  "~orpc";
91
147
  constructor(def) {
92
148
  this["~orpc"] = def;
93
149
  }
94
150
  /**
95
- * Reset config
151
+ * Sets or overrides the config.
152
+ *
153
+ * @see {@link https://orpc.unnoq.com/docs/lifecycle#middlewares-order Middlewares Order Docs}
154
+ * @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
96
155
  */
97
156
  $config(config) {
98
157
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
@@ -100,12 +159,15 @@ class Builder {
100
159
  return new Builder({
101
160
  ...this["~orpc"],
102
161
  config,
162
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
103
163
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
104
164
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
105
165
  });
106
166
  }
107
167
  /**
108
- * Reset initial context
168
+ * Set or override the initial context.
169
+ *
170
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
109
171
  */
110
172
  $context() {
111
173
  return new Builder({
@@ -116,7 +178,9 @@ class Builder {
116
178
  });
117
179
  }
118
180
  /**
119
- * Reset initial meta
181
+ * Sets or overrides the initial meta.
182
+ *
183
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
120
184
  */
121
185
  $meta(initialMeta) {
122
186
  return new Builder({
@@ -125,7 +189,11 @@ class Builder {
125
189
  });
126
190
  }
127
191
  /**
128
- * Reset initial route
192
+ * Sets or overrides the initial route.
193
+ * This option is typically relevant when integrating with OpenAPI.
194
+ *
195
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
196
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
129
197
  */
130
198
  $route(initialRoute) {
131
199
  return new Builder({
@@ -133,9 +201,31 @@ class Builder {
133
201
  route: initialRoute
134
202
  });
135
203
  }
204
+ /**
205
+ * Sets or overrides the initial input schema.
206
+ *
207
+ * @see {@link https://orpc.unnoq.com/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
208
+ */
209
+ $input(initialInputSchema) {
210
+ return new Builder({
211
+ ...this["~orpc"],
212
+ inputSchema: initialInputSchema
213
+ });
214
+ }
215
+ /**
216
+ * Creates a middleware.
217
+ *
218
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
219
+ */
136
220
  middleware(middleware) {
137
221
  return decorateMiddleware(middleware);
138
222
  }
223
+ /**
224
+ * Adds type-safe custom errors.
225
+ * The provided errors are spared-merged with any existing errors.
226
+ *
227
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
228
+ */
139
229
  errors(errors) {
140
230
  return new Builder({
141
231
  ...this["~orpc"],
@@ -149,18 +239,37 @@ class Builder {
149
239
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
150
240
  });
151
241
  }
242
+ /**
243
+ * Sets or updates the metadata.
244
+ * The provided metadata is spared-merged with any existing metadata.
245
+ *
246
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
247
+ */
152
248
  meta(meta) {
153
249
  return new Builder({
154
250
  ...this["~orpc"],
155
251
  meta: mergeMeta(this["~orpc"].meta, meta)
156
252
  });
157
253
  }
254
+ /**
255
+ * Sets or updates the route definition.
256
+ * The provided route is spared-merged with any existing route.
257
+ * This option is typically relevant when integrating with OpenAPI.
258
+ *
259
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
260
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
261
+ */
158
262
  route(route) {
159
263
  return new Builder({
160
264
  ...this["~orpc"],
161
265
  route: mergeRoute(this["~orpc"].route, route)
162
266
  });
163
267
  }
268
+ /**
269
+ * Defines the input validation schema.
270
+ *
271
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
272
+ */
164
273
  input(schema) {
165
274
  return new Builder({
166
275
  ...this["~orpc"],
@@ -168,6 +277,11 @@ class Builder {
168
277
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
169
278
  });
170
279
  }
280
+ /**
281
+ * Defines the output validation schema.
282
+ *
283
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
284
+ */
171
285
  output(schema) {
172
286
  return new Builder({
173
287
  ...this["~orpc"],
@@ -175,29 +289,59 @@ class Builder {
175
289
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
176
290
  });
177
291
  }
292
+ /**
293
+ * Defines the handler of the procedure.
294
+ *
295
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
296
+ */
178
297
  handler(handler) {
179
298
  return new DecoratedProcedure({
180
299
  ...this["~orpc"],
181
300
  handler
182
301
  });
183
302
  }
303
+ /**
304
+ * Prefixes all procedures in the router.
305
+ * The provided prefix is post-appended to any existing router prefix.
306
+ *
307
+ * @note This option does not affect procedures that do not define a path in their route definition.
308
+ *
309
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
310
+ */
184
311
  prefix(prefix) {
185
312
  return new Builder({
186
313
  ...this["~orpc"],
187
314
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
188
315
  });
189
316
  }
317
+ /**
318
+ * Adds tags to all procedures in the router.
319
+ * This helpful when you want to group procedures together in the OpenAPI specification.
320
+ *
321
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
322
+ */
190
323
  tag(...tags) {
191
324
  return new Builder({
192
325
  ...this["~orpc"],
193
326
  tags: mergeTags(this["~orpc"].tags, tags)
194
327
  });
195
328
  }
329
+ /**
330
+ * Applies all of the previously defined options to the specified router.
331
+ *
332
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
333
+ */
196
334
  router(router) {
197
- return adaptRouter(router, this["~orpc"]);
335
+ return enhanceRouter(router, this["~orpc"]);
198
336
  }
337
+ /**
338
+ * Create a lazy router
339
+ * And applies all of the previously defined options to the specified router.
340
+ *
341
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
342
+ */
199
343
  lazy(loader) {
200
- return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
344
+ return enhanceRouter(lazy(loader), this["~orpc"]);
201
345
  }
202
346
  }
203
347
  const os = new Builder({
@@ -205,17 +349,12 @@ const os = new Builder({
205
349
  route: {},
206
350
  meta: {},
207
351
  errorMap: {},
208
- inputSchema: void 0,
209
- outputSchema: void 0,
210
352
  inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
211
353
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
212
- middlewares: []
354
+ middlewares: [],
355
+ dedupeLeadingMiddlewares: true
213
356
  });
214
357
 
215
- function mergeContext(context, other) {
216
- return { ...context, ...other };
217
- }
218
-
219
358
  function implementerInternal(contract, config, middlewares) {
220
359
  if (isContractProcedure(contract)) {
221
360
  const impl2 = new Builder({
@@ -223,12 +362,16 @@ function implementerInternal(contract, config, middlewares) {
223
362
  config,
224
363
  middlewares,
225
364
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
226
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
365
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
366
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
227
367
  });
228
368
  return impl2;
229
369
  }
230
370
  const impl = new Proxy(contract, {
231
371
  get: (target, key) => {
372
+ if (typeof key !== "string") {
373
+ return Reflect.get(target, key);
374
+ }
232
375
  let method;
233
376
  if (key === "middleware") {
234
377
  method = (mid) => decorateMiddleware(mid);
@@ -242,23 +385,29 @@ function implementerInternal(contract, config, middlewares) {
242
385
  };
243
386
  } else if (key === "router") {
244
387
  method = (router) => {
245
- const adapted = adaptRouter(router, {
388
+ const adapted = enhanceRouter(router, {
246
389
  middlewares,
247
- errorMap: {}
390
+ errorMap: {},
391
+ prefix: void 0,
392
+ tags: void 0,
393
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
248
394
  });
249
- return setRouterContract(adapted, contract);
395
+ return setHiddenRouterContract(adapted, contract);
250
396
  };
251
397
  } else if (key === "lazy") {
252
398
  method = (loader) => {
253
- const adapted = adaptRouter(flatLazy(lazy(loader)), {
399
+ const adapted = enhanceRouter(lazy(loader), {
254
400
  middlewares,
255
- errorMap: {}
401
+ errorMap: {},
402
+ prefix: void 0,
403
+ tags: void 0,
404
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
256
405
  });
257
- return setRouterContract(adapted, contract);
406
+ return setHiddenRouterContract(adapted, contract);
258
407
  };
259
408
  }
260
- const next = Reflect.get(target, key);
261
- if (!next || typeof next !== "function" && typeof next !== "object") {
409
+ const next = getContractRouter(target, [key]);
410
+ if (!next) {
262
411
  return method ?? next;
263
412
  }
264
413
  const nextImpl = implementerInternal(next, config, middlewares);
@@ -285,49 +434,41 @@ function implement(contract, config = {}) {
285
434
  method = (config2) => implement(contract, config2);
286
435
  }
287
436
  const next = Reflect.get(target, key);
288
- if (!next || typeof next !== "function" && typeof next !== "object") {
289
- return method ?? next;
437
+ if (!method || !next || typeof next !== "function" && typeof next !== "object") {
438
+ return method || next;
290
439
  }
291
- if (method) {
292
- return new Proxy(method, {
293
- get(_, key2) {
294
- return Reflect.get(next, key2);
295
- }
296
- });
297
- }
298
- return next;
440
+ return new Proxy(method, {
441
+ get(_, key2) {
442
+ return Reflect.get(next, key2);
443
+ }
444
+ });
299
445
  }
300
446
  });
301
447
  return impl;
302
448
  }
303
449
 
304
- function call(procedure, input, ...rest) {
305
- return createProcedureClient(procedure, ...rest)(input);
306
- }
307
-
308
450
  function createRouterClient(router, ...rest) {
309
451
  if (isProcedure(router)) {
310
452
  const caller = createProcedureClient(router, ...rest);
311
453
  return caller;
312
454
  }
313
- const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
455
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), ...rest) : {};
314
456
  const recursive = new Proxy(procedureCaller, {
315
457
  get(target, key) {
316
458
  if (typeof key !== "string") {
317
459
  return Reflect.get(target, key);
318
460
  }
319
- const next = getRouterChild(router, key);
461
+ const next = getRouter(router, [key]);
320
462
  if (!next) {
321
463
  return Reflect.get(target, key);
322
464
  }
323
- const [options] = rest;
324
465
  return createRouterClient(next, {
325
- ...options,
326
- path: [...options?.path ?? [], key]
466
+ ...rest[0],
467
+ path: [...rest[0]?.path ?? [], key]
327
468
  });
328
469
  }
329
470
  });
330
471
  return recursive;
331
472
  }
332
473
 
333
- export { Builder, DecoratedProcedure, Procedure, adaptRouter, call, createLazyProcedureFormAnyLazy, createProcedureClient, createRouterClient, decorateMiddleware, fallbackConfig, flatLazy, getRouterChild, implement, implementerInternal, isLazy, isProcedure, lazy, mergeContext, os, setRouterContract };
474
+ export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
@@ -1,31 +1,156 @@
1
- import { d as StandardHandlerInterceptorOptions, P as Plugin, a as StandardHandlerOptions } from '../shared/server.BT-fqIEm.mjs';
2
- export { C as CompositePlugin } from '../shared/server.BT-fqIEm.mjs';
3
1
  import { Value } from '@orpc/shared';
4
- import { C as Context } from '../shared/server.ptXwNGQr.mjs';
5
- import '@orpc/contract';
6
- import '@orpc/standard-server';
7
- import '@orpc/client';
2
+ import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
+ import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.eWLxY3lq.mjs';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DPWk5pjW.mjs';
6
+ import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
+ import { ORPCError } from '@orpc/client';
8
8
 
9
- interface CORSOptions<TContext extends Context> {
10
- origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
- timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
- allowMethods?: string[];
13
- allowHeaders?: string[];
9
+ interface BatchHandlerOptions<T extends Context> {
10
+ /**
11
+ * The max size of the batch allowed.
12
+ *
13
+ * @default 10
14
+ */
15
+ maxSize?: Value<number, [StandardHandlerInterceptorOptions<T>]>;
16
+ /**
17
+ * Map the request before processing it.
18
+ *
19
+ * @default merged back batch request headers into the request
20
+ */
21
+ mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
22
+ /**
23
+ * Success batch response status code.
24
+ *
25
+ * @default 207
26
+ */
27
+ successStatus?: Value<number, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
28
+ /**
29
+ * success batch response headers.
30
+ *
31
+ * @default {}
32
+ */
33
+ headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
34
+ }
35
+ /**
36
+ * The Batch Request/Response 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-request-response Batch Request/Response Plugin Docs}
40
+ */
41
+ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
42
+ private readonly maxSize;
43
+ private readonly mapRequestItem;
44
+ private readonly successStatus;
45
+ private readonly headers;
46
+ order: number;
47
+ constructor(options?: BatchHandlerOptions<T>);
48
+ init(options: StandardHandlerOptions<T>): void;
49
+ }
50
+
51
+ interface CORSOptions<T extends Context> {
52
+ origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
53
+ timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
54
+ allowMethods?: readonly string[];
55
+ allowHeaders?: readonly string[];
14
56
  maxAge?: number;
15
57
  credentials?: boolean;
16
- exposeHeaders?: string[];
58
+ exposeHeaders?: readonly string[];
17
59
  }
18
- declare class CORSPlugin<TContext extends Context> implements Plugin<TContext> {
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
+ */
65
+ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
19
66
  private readonly options;
20
- constructor(options?: Partial<CORSOptions<TContext>>);
21
- init(options: StandardHandlerOptions<TContext>): void;
67
+ order: number;
68
+ constructor(options?: CORSOptions<T>);
69
+ init(options: StandardHandlerOptions<T>): void;
22
70
  }
23
71
 
24
72
  interface ResponseHeadersPluginContext {
25
73
  resHeaders?: Headers;
26
74
  }
27
- declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements Plugin<TContext> {
28
- init(options: StandardHandlerOptions<TContext>): void;
75
+ /**
76
+ * The Response Headers Plugin allows you to set response headers in oRPC.
77
+ * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
78
+ *
79
+ * @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
80
+ */
81
+ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
82
+ init(options: StandardHandlerOptions<T>): void;
83
+ }
84
+
85
+ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
86
+ /**
87
+ * The name of the header to check.
88
+ *
89
+ * @default 'x-csrf-token'
90
+ */
91
+ headerName?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
92
+ /**
93
+ * The value of the header to check.
94
+ *
95
+ * @default 'orpc'
96
+ *
97
+ */
98
+ headerValue?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
99
+ /**
100
+ * Exclude a procedure from the plugin.
101
+ *
102
+ * @default false
103
+ *
104
+ */
105
+ exclude?: Value<boolean, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
106
+ /**
107
+ * The error thrown when the CSRF token is invalid.
108
+ *
109
+ * @default new ORPCError('CSRF_TOKEN_MISMATCH', {
110
+ * status: 403,
111
+ * message: 'Invalid CSRF token',
112
+ * })
113
+ */
114
+ error?: InstanceType<typeof ORPCError>;
115
+ }
116
+ /**
117
+ * This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
118
+ * It helps ensure that requests to your procedures originate from JavaScript code,
119
+ * not from other sources like standard HTML forms or direct browser navigation.
120
+ *
121
+ * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
122
+ */
123
+ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
124
+ private readonly headerName;
125
+ private readonly headerValue;
126
+ private readonly exclude;
127
+ private readonly error;
128
+ constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
129
+ order: number;
130
+ init(options: StandardHandlerOptions<T>): void;
131
+ }
132
+
133
+ interface StrictGetMethodPluginOptions {
134
+ /**
135
+ * The error thrown when a GET request is made to a procedure that doesn't allow GET.
136
+ *
137
+ * @default new ORPCError('METHOD_NOT_SUPPORTED')
138
+ */
139
+ error?: InstanceType<typeof ORPCError$1>;
140
+ }
141
+ /**
142
+ * This plugin enhances security by ensuring only procedures explicitly marked to accept GET requests
143
+ * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
144
+ * Cross-Site Request Forgery (CSRF) attacks.
145
+ *
146
+ * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
147
+ */
148
+ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
149
+ private readonly error;
150
+ order: number;
151
+ constructor(options?: StrictGetMethodPluginOptions);
152
+ init(options: StandardHandlerOptions<T>): void;
29
153
  }
30
154
 
31
- export { type CORSOptions, CORSPlugin, Plugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
155
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
156
+ export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };