@orpc/server 0.0.0-next.c59d67c → 0.0.0-next.c72b962

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +131 -0
  2. package/dist/adapters/fetch/index.d.mts +58 -0
  3. package/dist/adapters/fetch/index.d.ts +58 -0
  4. package/dist/adapters/fetch/index.mjs +11 -0
  5. package/dist/adapters/hono/index.d.mts +22 -0
  6. package/dist/adapters/hono/index.d.ts +22 -0
  7. package/dist/adapters/hono/index.mjs +34 -0
  8. package/dist/adapters/next/index.d.mts +29 -0
  9. package/dist/adapters/next/index.d.ts +29 -0
  10. package/dist/adapters/next/index.mjs +31 -0
  11. package/dist/adapters/node/index.d.mts +57 -0
  12. package/dist/adapters/node/index.d.ts +57 -0
  13. package/dist/adapters/node/index.mjs +90 -0
  14. package/dist/adapters/standard/index.d.mts +26 -0
  15. package/dist/adapters/standard/index.d.ts +26 -0
  16. package/dist/adapters/standard/index.mjs +8 -0
  17. package/dist/index.d.mts +291 -0
  18. package/dist/index.d.ts +291 -0
  19. package/dist/index.mjs +363 -0
  20. package/dist/plugins/index.d.mts +124 -0
  21. package/dist/plugins/index.d.ts +124 -0
  22. package/dist/plugins/index.mjs +244 -0
  23. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  24. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  25. package/dist/shared/server.Bm0UqHzd.mjs +103 -0
  26. package/dist/shared/server.C37gDhSZ.mjs +364 -0
  27. package/dist/shared/server.C8NkqxHo.d.ts +17 -0
  28. package/dist/shared/server.CGCwEAt_.d.mts +10 -0
  29. package/dist/shared/server.DCQgF_JR.d.mts +17 -0
  30. package/dist/shared/server.DFFT_EZo.d.ts +73 -0
  31. package/dist/shared/server.DFuJLDuo.mjs +190 -0
  32. package/dist/shared/server.DLt5njUb.d.mts +143 -0
  33. package/dist/shared/server.DLt5njUb.d.ts +143 -0
  34. package/dist/shared/server.DOYDVeMX.d.mts +73 -0
  35. package/dist/shared/server._2UufoXA.d.ts +10 -0
  36. package/package.json +41 -18
  37. package/dist/chunk-TDFYNRZV.js +0 -190
  38. package/dist/fetch.js +0 -106
  39. package/dist/index.js +0 -394
  40. package/dist/src/builder.d.ts +0 -49
  41. package/dist/src/fetch/handle.d.ts +0 -7
  42. package/dist/src/fetch/handler.d.ts +0 -3
  43. package/dist/src/fetch/index.d.ts +0 -4
  44. package/dist/src/fetch/types.d.ts +0 -35
  45. package/dist/src/index.d.ts +0 -15
  46. package/dist/src/middleware.d.ts +0 -26
  47. package/dist/src/procedure-builder.d.ts +0 -31
  48. package/dist/src/procedure-caller.d.ts +0 -19
  49. package/dist/src/procedure-implementer.d.ts +0 -18
  50. package/dist/src/procedure.d.ts +0 -29
  51. package/dist/src/router-builder.d.ts +0 -22
  52. package/dist/src/router-caller.d.ts +0 -22
  53. package/dist/src/router-implementer.d.ts +0 -20
  54. package/dist/src/router.d.ts +0 -20
  55. package/dist/src/types.d.ts +0 -8
  56. package/dist/src/utils.d.ts +0 -3
package/dist/index.mjs ADDED
@@ -0,0 +1,363 @@
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';
5
+ import { toORPCError } from '@orpc/client';
6
+ export { ORPCError, isDefinedError, safe } from '@orpc/client';
7
+ export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
8
+ export { getEventMeta, withEventMeta } from '@orpc/standard-server';
9
+
10
+ const DEFAULT_CONFIG = {
11
+ initialInputValidationIndex: 0,
12
+ initialOutputValidationIndex: 0,
13
+ dedupeLeadingMiddlewares: true
14
+ };
15
+ function fallbackConfig(key, value) {
16
+ if (value === void 0) {
17
+ return DEFAULT_CONFIG[key];
18
+ }
19
+ return value;
20
+ }
21
+
22
+ function decorateMiddleware(middleware) {
23
+ const decorated = (...args) => middleware(...args);
24
+ decorated.mapInput = (mapInput) => {
25
+ const mapped = decorateMiddleware(
26
+ (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
27
+ );
28
+ return mapped;
29
+ };
30
+ decorated.concat = (concatMiddleware, mapInput) => {
31
+ const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
32
+ const concatted = decorateMiddleware((options, input, output, ...rest) => {
33
+ const merged = middleware({
34
+ ...options,
35
+ next: (...[nextOptions1]) => mapped({
36
+ ...options,
37
+ context: { ...options.context, ...nextOptions1?.context },
38
+ next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
39
+ }, input, output, ...rest)
40
+ }, input, output, ...rest);
41
+ return merged;
42
+ });
43
+ return concatted;
44
+ };
45
+ return decorated;
46
+ }
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
+
59
+ class DecoratedProcedure extends Procedure {
60
+ errors(errors) {
61
+ return new DecoratedProcedure({
62
+ ...this["~orpc"],
63
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
64
+ });
65
+ }
66
+ meta(meta) {
67
+ return new DecoratedProcedure({
68
+ ...this["~orpc"],
69
+ meta: mergeMeta(this["~orpc"].meta, meta)
70
+ });
71
+ }
72
+ route(route) {
73
+ return new DecoratedProcedure({
74
+ ...this["~orpc"],
75
+ route: mergeRoute(this["~orpc"].route, route)
76
+ });
77
+ }
78
+ use(middleware, mapInput) {
79
+ const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
80
+ return new DecoratedProcedure({
81
+ ...this["~orpc"],
82
+ middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
83
+ });
84
+ }
85
+ /**
86
+ * Make this procedure callable (works like a function while still being a procedure).
87
+ */
88
+ callable(...rest) {
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
+ }
97
+ });
98
+ }
99
+ /**
100
+ * Make this procedure compatible with server action.
101
+ */
102
+ actionable(...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
+ });
112
+ }
113
+ }
114
+
115
+ class Builder {
116
+ "~orpc";
117
+ constructor(def) {
118
+ this["~orpc"] = def;
119
+ }
120
+ /**
121
+ * Reset config
122
+ */
123
+ $config(config) {
124
+ const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
125
+ const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
126
+ return new Builder({
127
+ ...this["~orpc"],
128
+ config,
129
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
130
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
131
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
132
+ });
133
+ }
134
+ /**
135
+ * Reset initial context
136
+ */
137
+ $context() {
138
+ return new Builder({
139
+ ...this["~orpc"],
140
+ middlewares: [],
141
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
142
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
143
+ });
144
+ }
145
+ /**
146
+ * Reset initial meta
147
+ */
148
+ $meta(initialMeta) {
149
+ return new Builder({
150
+ ...this["~orpc"],
151
+ meta: initialMeta
152
+ });
153
+ }
154
+ /**
155
+ * Reset initial route
156
+ */
157
+ $route(initialRoute) {
158
+ return new Builder({
159
+ ...this["~orpc"],
160
+ route: initialRoute
161
+ });
162
+ }
163
+ $input(initialInputSchema) {
164
+ return new Builder({
165
+ ...this["~orpc"],
166
+ inputSchema: initialInputSchema
167
+ });
168
+ }
169
+ middleware(middleware) {
170
+ return decorateMiddleware(middleware);
171
+ }
172
+ errors(errors) {
173
+ return new Builder({
174
+ ...this["~orpc"],
175
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
176
+ });
177
+ }
178
+ use(middleware, mapInput) {
179
+ const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
180
+ return new Builder({
181
+ ...this["~orpc"],
182
+ middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
183
+ });
184
+ }
185
+ meta(meta) {
186
+ return new Builder({
187
+ ...this["~orpc"],
188
+ meta: mergeMeta(this["~orpc"].meta, meta)
189
+ });
190
+ }
191
+ route(route) {
192
+ return new Builder({
193
+ ...this["~orpc"],
194
+ route: mergeRoute(this["~orpc"].route, route)
195
+ });
196
+ }
197
+ input(schema) {
198
+ return new Builder({
199
+ ...this["~orpc"],
200
+ inputSchema: schema,
201
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
202
+ });
203
+ }
204
+ output(schema) {
205
+ return new Builder({
206
+ ...this["~orpc"],
207
+ outputSchema: schema,
208
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
209
+ });
210
+ }
211
+ handler(handler) {
212
+ return new DecoratedProcedure({
213
+ ...this["~orpc"],
214
+ handler
215
+ });
216
+ }
217
+ prefix(prefix) {
218
+ return new Builder({
219
+ ...this["~orpc"],
220
+ prefix: mergePrefix(this["~orpc"].prefix, prefix)
221
+ });
222
+ }
223
+ tag(...tags) {
224
+ return new Builder({
225
+ ...this["~orpc"],
226
+ tags: mergeTags(this["~orpc"].tags, tags)
227
+ });
228
+ }
229
+ router(router) {
230
+ return enhanceRouter(router, this["~orpc"]);
231
+ }
232
+ lazy(loader) {
233
+ return enhanceRouter(lazy(loader), this["~orpc"]);
234
+ }
235
+ }
236
+ const os = new Builder({
237
+ config: {},
238
+ route: {},
239
+ meta: {},
240
+ errorMap: {},
241
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
242
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
243
+ middlewares: [],
244
+ dedupeLeadingMiddlewares: true
245
+ });
246
+
247
+ function implementerInternal(contract, config, middlewares) {
248
+ if (isContractProcedure(contract)) {
249
+ const impl2 = new Builder({
250
+ ...contract["~orpc"],
251
+ config,
252
+ middlewares,
253
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
254
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
255
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
256
+ });
257
+ return impl2;
258
+ }
259
+ const impl = new Proxy(contract, {
260
+ get: (target, key) => {
261
+ if (typeof key !== "string") {
262
+ return Reflect.get(target, key);
263
+ }
264
+ let method;
265
+ if (key === "middleware") {
266
+ method = (mid) => decorateMiddleware(mid);
267
+ } else if (key === "use") {
268
+ method = (mid) => {
269
+ return implementerInternal(
270
+ contract,
271
+ config,
272
+ addMiddleware(middlewares, mid)
273
+ );
274
+ };
275
+ } else if (key === "router") {
276
+ method = (router) => {
277
+ const adapted = enhanceRouter(router, {
278
+ middlewares,
279
+ errorMap: {},
280
+ prefix: void 0,
281
+ tags: void 0,
282
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
283
+ });
284
+ return setHiddenRouterContract(adapted, contract);
285
+ };
286
+ } else if (key === "lazy") {
287
+ method = (loader) => {
288
+ const adapted = enhanceRouter(lazy(loader), {
289
+ middlewares,
290
+ errorMap: {},
291
+ prefix: void 0,
292
+ tags: void 0,
293
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
294
+ });
295
+ return setHiddenRouterContract(adapted, contract);
296
+ };
297
+ }
298
+ const next = getContractRouter(target, [key]);
299
+ if (!next) {
300
+ return method ?? next;
301
+ }
302
+ const nextImpl = implementerInternal(next, config, middlewares);
303
+ if (method) {
304
+ return new Proxy(method, {
305
+ get(_, key2) {
306
+ return Reflect.get(nextImpl, key2);
307
+ }
308
+ });
309
+ }
310
+ return nextImpl;
311
+ }
312
+ });
313
+ return impl;
314
+ }
315
+ function implement(contract, config = {}) {
316
+ const implInternal = implementerInternal(contract, config, []);
317
+ const impl = new Proxy(implInternal, {
318
+ get: (target, key) => {
319
+ let method;
320
+ if (key === "$context") {
321
+ method = () => impl;
322
+ } else if (key === "$config") {
323
+ method = (config2) => implement(contract, config2);
324
+ }
325
+ const next = Reflect.get(target, key);
326
+ if (!method || !next || typeof next !== "function" && typeof next !== "object") {
327
+ return method || next;
328
+ }
329
+ return new Proxy(method, {
330
+ get(_, key2) {
331
+ return Reflect.get(next, key2);
332
+ }
333
+ });
334
+ }
335
+ });
336
+ return impl;
337
+ }
338
+
339
+ function createRouterClient(router, ...[options]) {
340
+ if (isProcedure(router)) {
341
+ const caller = createProcedureClient(router, options);
342
+ return caller;
343
+ }
344
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
345
+ const recursive = new Proxy(procedureCaller, {
346
+ get(target, key) {
347
+ if (typeof key !== "string") {
348
+ return Reflect.get(target, key);
349
+ }
350
+ const next = getRouter(router, [key]);
351
+ if (!next) {
352
+ return Reflect.get(target, key);
353
+ }
354
+ return createRouterClient(next, {
355
+ ...options,
356
+ path: [...options?.path ?? [], key]
357
+ });
358
+ }
359
+ });
360
+ return recursive;
361
+ }
362
+
363
+ export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
@@ -0,0 +1,124 @@
1
+ import { Value } from '@orpc/shared';
2
+ import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
+ import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
+ import { h as StandardHandlerInterceptorOptions, i as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DOYDVeMX.mjs';
5
+ import { C as Context, P as ProcedureClientInterceptorOptions } from '../shared/server.DLt5njUb.mjs';
6
+ import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
+ import { ORPCError } from '@orpc/client';
8
+
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[];
50
+ maxAge?: number;
51
+ credentials?: boolean;
52
+ exposeHeaders?: readonly string[];
53
+ }
54
+ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
55
+ private readonly options;
56
+ order: number;
57
+ constructor(options?: CORSOptions<T>);
58
+ init(options: StandardHandlerOptions<T>): void;
59
+ }
60
+
61
+ interface ResponseHeadersPluginContext {
62
+ resHeaders?: Headers;
63
+ }
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;
122
+ }
123
+
124
+ export { type BatchHandlerOptions, BatchHandlerPlugin, type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPlugin, type SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPlugin, type StrictGetMethodPluginOptions };
@@ -0,0 +1,124 @@
1
+ import { Value } from '@orpc/shared';
2
+ import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
+ import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
+ import { h as StandardHandlerInterceptorOptions, i as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DFFT_EZo.js';
5
+ import { C as Context, P as ProcedureClientInterceptorOptions } from '../shared/server.DLt5njUb.js';
6
+ import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
+ import { ORPCError } from '@orpc/client';
8
+
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[];
50
+ maxAge?: number;
51
+ credentials?: boolean;
52
+ exposeHeaders?: readonly string[];
53
+ }
54
+ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
55
+ private readonly options;
56
+ order: number;
57
+ constructor(options?: CORSOptions<T>);
58
+ init(options: StandardHandlerOptions<T>): void;
59
+ }
60
+
61
+ interface ResponseHeadersPluginContext {
62
+ resHeaders?: Headers;
63
+ }
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;
122
+ }
123
+
124
+ export { type BatchHandlerOptions, BatchHandlerPlugin, type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPlugin, type SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPlugin, type StrictGetMethodPluginOptions };