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

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 (44) hide show
  1. package/README.md +14 -1
  2. package/dist/adapters/fetch/index.d.mts +43 -11
  3. package/dist/adapters/fetch/index.d.ts +43 -11
  4. package/dist/adapters/fetch/index.mjs +103 -7
  5. package/dist/adapters/node/index.d.mts +45 -22
  6. package/dist/adapters/node/index.d.ts +45 -22
  7. package/dist/adapters/node/index.mjs +81 -21
  8. package/dist/adapters/standard/index.d.mts +12 -15
  9. package/dist/adapters/standard/index.d.ts +12 -15
  10. package/dist/adapters/standard/index.mjs +6 -5
  11. package/dist/index.d.mts +161 -124
  12. package/dist/index.d.ts +161 -124
  13. package/dist/index.mjs +78 -48
  14. package/dist/plugins/index.d.mts +112 -18
  15. package/dist/plugins/index.d.ts +112 -18
  16. package/dist/plugins/index.mjs +157 -8
  17. package/dist/shared/server.B1oIHH_j.d.mts +74 -0
  18. package/dist/shared/server.BVHsfJ99.d.mts +144 -0
  19. package/dist/shared/server.BVHsfJ99.d.ts +144 -0
  20. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  21. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  22. package/dist/shared/server.BuLPHTX1.d.mts +18 -0
  23. package/dist/shared/{server.V6zT5iYQ.mjs → server.C37gDhSZ.mjs} +158 -173
  24. package/dist/shared/server.CaWivVk3.d.ts +74 -0
  25. package/dist/shared/server.DFuJLDuo.mjs +190 -0
  26. package/dist/shared/server.DMhSfHk1.d.ts +10 -0
  27. package/dist/shared/server.D_vpYits.d.ts +18 -0
  28. package/dist/shared/server.Dwnm6cSk.d.mts +10 -0
  29. package/package.json +8 -22
  30. package/dist/adapters/hono/index.d.mts +0 -20
  31. package/dist/adapters/hono/index.d.ts +0 -20
  32. package/dist/adapters/hono/index.mjs +0 -32
  33. package/dist/adapters/next/index.d.mts +0 -27
  34. package/dist/adapters/next/index.d.ts +0 -27
  35. package/dist/adapters/next/index.mjs +0 -29
  36. package/dist/shared/server.BBGuTxHE.mjs +0 -163
  37. package/dist/shared/server.BMaJxq9W.d.mts +0 -9
  38. package/dist/shared/server.BT-fqIEm.d.mts +0 -77
  39. package/dist/shared/server.DpdgHO1j.d.ts +0 -9
  40. package/dist/shared/server.KwueCzFr.mjs +0 -26
  41. package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
  42. package/dist/shared/server.ptXwNGQr.d.mts +0 -158
  43. package/dist/shared/server.ptXwNGQr.d.ts +0 -158
  44. 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.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';
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,6 +45,17 @@ 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
+ return [toORPCError(error).toJSON(), void 0];
54
+ }
55
+ };
56
+ return action;
57
+ }
58
+
46
59
  class DecoratedProcedure extends Procedure {
47
60
  errors(errors) {
48
61
  return new DecoratedProcedure({
@@ -73,16 +86,29 @@ class DecoratedProcedure extends Procedure {
73
86
  * Make this procedure callable (works like a function while still being a procedure).
74
87
  */
75
88
  callable(...rest) {
76
- return Object.assign(createProcedureClient(this, ...rest), {
77
- "~type": "Procedure",
78
- "~orpc": this["~orpc"]
89
+ const client = createProcedureClient(this, ...rest);
90
+ return new Proxy(client, {
91
+ get: (target, key) => {
92
+ return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
93
+ },
94
+ has: (target, key) => {
95
+ return Reflect.has(this, key) || Reflect.has(target, key);
96
+ }
79
97
  });
80
98
  }
81
99
  /**
82
- * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
100
+ * Make this procedure compatible with server action.
83
101
  */
84
102
  actionable(...rest) {
85
- return this.callable(...rest);
103
+ const action = createActionableClient(createProcedureClient(this, ...rest));
104
+ return new Proxy(action, {
105
+ get: (target, key) => {
106
+ return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
107
+ },
108
+ has: (target, key) => {
109
+ return Reflect.has(this, key) || Reflect.has(target, key);
110
+ }
111
+ });
86
112
  }
87
113
  }
88
114
 
@@ -100,6 +126,7 @@ class Builder {
100
126
  return new Builder({
101
127
  ...this["~orpc"],
102
128
  config,
129
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
103
130
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
104
131
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
105
132
  });
@@ -133,6 +160,12 @@ class Builder {
133
160
  route: initialRoute
134
161
  });
135
162
  }
163
+ $input(initialInputSchema) {
164
+ return new Builder({
165
+ ...this["~orpc"],
166
+ inputSchema: initialInputSchema
167
+ });
168
+ }
136
169
  middleware(middleware) {
137
170
  return decorateMiddleware(middleware);
138
171
  }
@@ -194,10 +227,10 @@ class Builder {
194
227
  });
195
228
  }
196
229
  router(router) {
197
- return adaptRouter(router, this["~orpc"]);
230
+ return enhanceRouter(router, this["~orpc"]);
198
231
  }
199
232
  lazy(loader) {
200
- return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
233
+ return enhanceRouter(lazy(loader), this["~orpc"]);
201
234
  }
202
235
  }
203
236
  const os = new Builder({
@@ -205,17 +238,12 @@ const os = new Builder({
205
238
  route: {},
206
239
  meta: {},
207
240
  errorMap: {},
208
- inputSchema: void 0,
209
- outputSchema: void 0,
210
241
  inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
211
242
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
212
- middlewares: []
243
+ middlewares: [],
244
+ dedupeLeadingMiddlewares: true
213
245
  });
214
246
 
215
- function mergeContext(context, other) {
216
- return { ...context, ...other };
217
- }
218
-
219
247
  function implementerInternal(contract, config, middlewares) {
220
248
  if (isContractProcedure(contract)) {
221
249
  const impl2 = new Builder({
@@ -223,12 +251,16 @@ function implementerInternal(contract, config, middlewares) {
223
251
  config,
224
252
  middlewares,
225
253
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
226
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
254
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
255
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
227
256
  });
228
257
  return impl2;
229
258
  }
230
259
  const impl = new Proxy(contract, {
231
260
  get: (target, key) => {
261
+ if (typeof key !== "string") {
262
+ return Reflect.get(target, key);
263
+ }
232
264
  let method;
233
265
  if (key === "middleware") {
234
266
  method = (mid) => decorateMiddleware(mid);
@@ -242,23 +274,29 @@ function implementerInternal(contract, config, middlewares) {
242
274
  };
243
275
  } else if (key === "router") {
244
276
  method = (router) => {
245
- const adapted = adaptRouter(router, {
277
+ const adapted = enhanceRouter(router, {
246
278
  middlewares,
247
- errorMap: {}
279
+ errorMap: {},
280
+ prefix: void 0,
281
+ tags: void 0,
282
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
248
283
  });
249
- return setRouterContract(adapted, contract);
284
+ return setHiddenRouterContract(adapted, contract);
250
285
  };
251
286
  } else if (key === "lazy") {
252
287
  method = (loader) => {
253
- const adapted = adaptRouter(flatLazy(lazy(loader)), {
288
+ const adapted = enhanceRouter(lazy(loader), {
254
289
  middlewares,
255
- errorMap: {}
290
+ errorMap: {},
291
+ prefix: void 0,
292
+ tags: void 0,
293
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
256
294
  });
257
- return setRouterContract(adapted, contract);
295
+ return setHiddenRouterContract(adapted, contract);
258
296
  };
259
297
  }
260
- const next = Reflect.get(target, key);
261
- if (!next || typeof next !== "function" && typeof next !== "object") {
298
+ const next = getContractRouter(target, [key]);
299
+ if (!next) {
262
300
  return method ?? next;
263
301
  }
264
302
  const nextImpl = implementerInternal(next, config, middlewares);
@@ -285,49 +323,41 @@ function implement(contract, config = {}) {
285
323
  method = (config2) => implement(contract, config2);
286
324
  }
287
325
  const next = Reflect.get(target, key);
288
- if (!next || typeof next !== "function" && typeof next !== "object") {
289
- return method ?? next;
290
- }
291
- if (method) {
292
- return new Proxy(method, {
293
- get(_, key2) {
294
- return Reflect.get(next, key2);
295
- }
296
- });
326
+ if (!method || !next || typeof next !== "function" && typeof next !== "object") {
327
+ return method || next;
297
328
  }
298
- return next;
329
+ return new Proxy(method, {
330
+ get(_, key2) {
331
+ return Reflect.get(next, key2);
332
+ }
333
+ });
299
334
  }
300
335
  });
301
336
  return impl;
302
337
  }
303
338
 
304
- function call(procedure, input, ...rest) {
305
- return createProcedureClient(procedure, ...rest)(input);
306
- }
307
-
308
339
  function createRouterClient(router, ...rest) {
309
340
  if (isProcedure(router)) {
310
341
  const caller = createProcedureClient(router, ...rest);
311
342
  return caller;
312
343
  }
313
- const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
344
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), ...rest) : {};
314
345
  const recursive = new Proxy(procedureCaller, {
315
346
  get(target, key) {
316
347
  if (typeof key !== "string") {
317
348
  return Reflect.get(target, key);
318
349
  }
319
- const next = getRouterChild(router, key);
350
+ const next = getRouter(router, [key]);
320
351
  if (!next) {
321
352
  return Reflect.get(target, key);
322
353
  }
323
- const [options] = rest;
324
354
  return createRouterClient(next, {
325
- ...options,
326
- path: [...options?.path ?? [], key]
355
+ ...rest[0],
356
+ path: [...rest[0]?.path ?? [], key]
327
357
  });
328
358
  }
329
359
  });
330
360
  return recursive;
331
361
  }
332
362
 
333
- export { Builder, DecoratedProcedure, Procedure, adaptRouter, call, createLazyProcedureFormAnyLazy, createProcedureClient, createRouterClient, decorateMiddleware, fallbackConfig, flatLazy, getRouterChild, implement, implementerInternal, isLazy, isProcedure, lazy, mergeContext, os, setRouterContract };
363
+ export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
@@ -1,31 +1,125 @@
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.B1oIHH_j.mjs';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.BVHsfJ99.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
+ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
+ private readonly maxSize;
37
+ private readonly mapRequestItem;
38
+ private readonly successStatus;
39
+ private readonly headers;
40
+ order: number;
41
+ constructor(options?: BatchHandlerOptions<T>);
42
+ init(options: StandardHandlerOptions<T>): void;
43
+ }
44
+
45
+ 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>]>;
48
+ allowMethods?: readonly string[];
49
+ allowHeaders?: readonly string[];
14
50
  maxAge?: number;
15
51
  credentials?: boolean;
16
- exposeHeaders?: string[];
52
+ exposeHeaders?: readonly string[];
17
53
  }
18
- declare class CORSPlugin<TContext extends Context> implements Plugin<TContext> {
54
+ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
19
55
  private readonly options;
20
- constructor(options?: Partial<CORSOptions<TContext>>);
21
- init(options: StandardHandlerOptions<TContext>): void;
56
+ order: number;
57
+ constructor(options?: CORSOptions<T>);
58
+ init(options: StandardHandlerOptions<T>): void;
22
59
  }
23
60
 
24
61
  interface ResponseHeadersPluginContext {
25
62
  resHeaders?: Headers;
26
63
  }
27
- declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements Plugin<TContext> {
28
- init(options: StandardHandlerOptions<TContext>): void;
64
+ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
65
+ init(options: StandardHandlerOptions<T>): void;
66
+ }
67
+
68
+ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
69
+ /**
70
+ * The name of the header to check.
71
+ *
72
+ * @default 'x-csrf-token'
73
+ */
74
+ headerName?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
75
+ /**
76
+ * The value of the header to check.
77
+ *
78
+ * @default 'orpc'
79
+ *
80
+ */
81
+ headerValue?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
82
+ /**
83
+ * Exclude a procedure from the plugin.
84
+ *
85
+ * @default false
86
+ *
87
+ */
88
+ exclude?: Value<boolean, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
89
+ /**
90
+ * The error thrown when the CSRF token is invalid.
91
+ *
92
+ * @default new ORPCError('CSRF_TOKEN_MISMATCH', {
93
+ * status: 403,
94
+ * message: 'Invalid CSRF token',
95
+ * })
96
+ */
97
+ error?: InstanceType<typeof ORPCError>;
98
+ }
99
+ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
100
+ private readonly headerName;
101
+ private readonly headerValue;
102
+ private readonly exclude;
103
+ private readonly error;
104
+ constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
105
+ order: number;
106
+ init(options: StandardHandlerOptions<T>): void;
107
+ }
108
+
109
+ interface StrictGetMethodPluginOptions {
110
+ /**
111
+ * The error thrown when a GET request is made to a procedure that doesn't allow GET.
112
+ *
113
+ * @default new ORPCError('METHOD_NOT_SUPPORTED')
114
+ */
115
+ error?: InstanceType<typeof ORPCError$1>;
116
+ }
117
+ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
118
+ private readonly error;
119
+ order: number;
120
+ constructor(options?: StrictGetMethodPluginOptions);
121
+ init(options: StandardHandlerOptions<T>): void;
29
122
  }
30
123
 
31
- export { type CORSOptions, CORSPlugin, Plugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
124
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
125
+ export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
@@ -1,31 +1,125 @@
1
- import { d as StandardHandlerInterceptorOptions, P as Plugin, a as StandardHandlerOptions } from '../shared/server.xL87pHsk.js';
2
- export { C as CompositePlugin } from '../shared/server.xL87pHsk.js';
3
1
  import { Value } from '@orpc/shared';
4
- import { C as Context } from '../shared/server.ptXwNGQr.js';
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.CaWivVk3.js';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.BVHsfJ99.js';
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
+ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
+ private readonly maxSize;
37
+ private readonly mapRequestItem;
38
+ private readonly successStatus;
39
+ private readonly headers;
40
+ order: number;
41
+ constructor(options?: BatchHandlerOptions<T>);
42
+ init(options: StandardHandlerOptions<T>): void;
43
+ }
44
+
45
+ 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>]>;
48
+ allowMethods?: readonly string[];
49
+ allowHeaders?: readonly string[];
14
50
  maxAge?: number;
15
51
  credentials?: boolean;
16
- exposeHeaders?: string[];
52
+ exposeHeaders?: readonly string[];
17
53
  }
18
- declare class CORSPlugin<TContext extends Context> implements Plugin<TContext> {
54
+ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
19
55
  private readonly options;
20
- constructor(options?: Partial<CORSOptions<TContext>>);
21
- init(options: StandardHandlerOptions<TContext>): void;
56
+ order: number;
57
+ constructor(options?: CORSOptions<T>);
58
+ init(options: StandardHandlerOptions<T>): void;
22
59
  }
23
60
 
24
61
  interface ResponseHeadersPluginContext {
25
62
  resHeaders?: Headers;
26
63
  }
27
- declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements Plugin<TContext> {
28
- init(options: StandardHandlerOptions<TContext>): void;
64
+ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
65
+ init(options: StandardHandlerOptions<T>): void;
66
+ }
67
+
68
+ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
69
+ /**
70
+ * The name of the header to check.
71
+ *
72
+ * @default 'x-csrf-token'
73
+ */
74
+ headerName?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
75
+ /**
76
+ * The value of the header to check.
77
+ *
78
+ * @default 'orpc'
79
+ *
80
+ */
81
+ headerValue?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
82
+ /**
83
+ * Exclude a procedure from the plugin.
84
+ *
85
+ * @default false
86
+ *
87
+ */
88
+ exclude?: Value<boolean, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
89
+ /**
90
+ * The error thrown when the CSRF token is invalid.
91
+ *
92
+ * @default new ORPCError('CSRF_TOKEN_MISMATCH', {
93
+ * status: 403,
94
+ * message: 'Invalid CSRF token',
95
+ * })
96
+ */
97
+ error?: InstanceType<typeof ORPCError>;
98
+ }
99
+ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
100
+ private readonly headerName;
101
+ private readonly headerValue;
102
+ private readonly exclude;
103
+ private readonly error;
104
+ constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
105
+ order: number;
106
+ init(options: StandardHandlerOptions<T>): void;
107
+ }
108
+
109
+ interface StrictGetMethodPluginOptions {
110
+ /**
111
+ * The error thrown when a GET request is made to a procedure that doesn't allow GET.
112
+ *
113
+ * @default new ORPCError('METHOD_NOT_SUPPORTED')
114
+ */
115
+ error?: InstanceType<typeof ORPCError$1>;
116
+ }
117
+ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
118
+ private readonly error;
119
+ order: number;
120
+ constructor(options?: StrictGetMethodPluginOptions);
121
+ init(options: StandardHandlerOptions<T>): void;
29
122
  }
30
123
 
31
- export { type CORSOptions, CORSPlugin, Plugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
124
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
125
+ export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };