@orpc/server 0.0.0-next.15d9202 → 0.0.0-next.16739f4
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.
- package/README.md +24 -17
- package/dist/adapters/fetch/index.d.mts +54 -10
- package/dist/adapters/fetch/index.d.ts +54 -10
- package/dist/adapters/fetch/index.mjs +104 -8
- package/dist/adapters/node/index.d.mts +56 -21
- package/dist/adapters/node/index.d.ts +56 -21
- package/dist/adapters/node/index.mjs +82 -23
- package/dist/adapters/standard/index.d.mts +11 -10
- package/dist/adapters/standard/index.d.ts +11 -10
- package/dist/adapters/standard/index.mjs +6 -4
- package/dist/index.d.mts +602 -51
- package/dist/index.d.ts +602 -51
- package/dist/index.mjs +144 -19
- package/dist/plugins/index.d.mts +140 -15
- package/dist/plugins/index.d.ts +140 -15
- package/dist/plugins/index.mjs +156 -7
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.CN0534_m.d.mts +18 -0
- package/dist/shared/server.CjlA3NKP.d.ts +10 -0
- package/dist/shared/server.CuD15qZB.d.ts +18 -0
- package/dist/shared/{server.CL84X8p4.d.mts → server.D5fBlF9j.d.ts} +28 -29
- package/dist/shared/{server.B_5ZADvP.mjs → server.DG7Tamti.mjs} +26 -22
- package/dist/shared/{server.DnmJuN02.d.mts → server.DPWk5pjW.d.mts} +61 -13
- package/dist/shared/{server.DnmJuN02.d.ts → server.DPWk5pjW.d.ts} +61 -13
- package/dist/shared/{server.hqPWnakL.d.ts → server.DY7OKEoj.d.mts} +28 -29
- package/dist/shared/server.DjgtLwKi.d.mts +10 -0
- package/dist/shared/{server.3mOimouH.mjs → server.qf03T-Xn.mjs} +62 -30
- package/package.json +8 -22
- package/dist/adapters/hono/index.d.mts +0 -19
- package/dist/adapters/hono/index.d.ts +0 -19
- package/dist/adapters/hono/index.mjs +0 -32
- package/dist/adapters/next/index.d.mts +0 -26
- package/dist/adapters/next/index.d.ts +0 -26
- package/dist/adapters/next/index.mjs +0 -29
- package/dist/shared/server.BgDZnmUZ.mjs +0 -28
- package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
package/dist/index.mjs
CHANGED
@@ -1,7 +1,8 @@
|
|
1
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,
|
4
|
-
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter,
|
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';
|
@@ -44,19 +45,50 @@ function decorateMiddleware(middleware) {
|
|
44
45
|
return decorated;
|
45
46
|
}
|
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
|
+
|
47
59
|
class DecoratedProcedure extends Procedure {
|
60
|
+
/**
|
61
|
+
* Adds type-safe custom errors.
|
62
|
+
* The provided errors are spared-merged with any existing errors.
|
63
|
+
*
|
64
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
65
|
+
*/
|
48
66
|
errors(errors) {
|
49
67
|
return new DecoratedProcedure({
|
50
68
|
...this["~orpc"],
|
51
69
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
52
70
|
});
|
53
71
|
}
|
72
|
+
/**
|
73
|
+
* Sets or updates the metadata.
|
74
|
+
* The provided metadata is spared-merged with any existing metadata.
|
75
|
+
*
|
76
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
77
|
+
*/
|
54
78
|
meta(meta) {
|
55
79
|
return new DecoratedProcedure({
|
56
80
|
...this["~orpc"],
|
57
81
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
58
82
|
});
|
59
83
|
}
|
84
|
+
/**
|
85
|
+
* Sets or updates the route definition.
|
86
|
+
* The provided route is spared-merged with any existing route.
|
87
|
+
* This option is typically relevant when integrating with OpenAPI.
|
88
|
+
*
|
89
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
90
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
91
|
+
*/
|
60
92
|
route(route) {
|
61
93
|
return new DecoratedProcedure({
|
62
94
|
...this["~orpc"],
|
@@ -72,9 +104,12 @@ class DecoratedProcedure extends Procedure {
|
|
72
104
|
}
|
73
105
|
/**
|
74
106
|
* Make this procedure callable (works like a function while still being a procedure).
|
107
|
+
*
|
108
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
75
109
|
*/
|
76
110
|
callable(...rest) {
|
77
|
-
|
111
|
+
const client = createProcedureClient(this, ...rest);
|
112
|
+
return new Proxy(client, {
|
78
113
|
get: (target, key) => {
|
79
114
|
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
80
115
|
},
|
@@ -84,20 +119,36 @@ class DecoratedProcedure extends Procedure {
|
|
84
119
|
});
|
85
120
|
}
|
86
121
|
/**
|
87
|
-
* Make this procedure compatible with server action
|
122
|
+
* Make this procedure compatible with server action.
|
123
|
+
*
|
124
|
+
* @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
|
88
125
|
*/
|
89
126
|
actionable(...rest) {
|
90
|
-
|
127
|
+
const action = createActionableClient(createProcedureClient(this, ...rest));
|
128
|
+
return new Proxy(action, {
|
129
|
+
get: (target, key) => {
|
130
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
131
|
+
},
|
132
|
+
has: (target, key) => {
|
133
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
134
|
+
}
|
135
|
+
});
|
91
136
|
}
|
92
137
|
}
|
93
138
|
|
94
139
|
class Builder {
|
140
|
+
/**
|
141
|
+
* This property holds the defined options.
|
142
|
+
*/
|
95
143
|
"~orpc";
|
96
144
|
constructor(def) {
|
97
145
|
this["~orpc"] = def;
|
98
146
|
}
|
99
147
|
/**
|
100
|
-
*
|
148
|
+
* Sets or overrides the config.
|
149
|
+
*
|
150
|
+
* @see {@link https://orpc.unnoq.com/docs/lifecycle#middlewares-order Middlewares Order Docs}
|
151
|
+
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
101
152
|
*/
|
102
153
|
$config(config) {
|
103
154
|
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
@@ -111,7 +162,9 @@ class Builder {
|
|
111
162
|
});
|
112
163
|
}
|
113
164
|
/**
|
114
|
-
*
|
165
|
+
* Set or override the initial context.
|
166
|
+
*
|
167
|
+
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
115
168
|
*/
|
116
169
|
$context() {
|
117
170
|
return new Builder({
|
@@ -122,7 +175,9 @@ class Builder {
|
|
122
175
|
});
|
123
176
|
}
|
124
177
|
/**
|
125
|
-
*
|
178
|
+
* Sets or overrides the initial meta.
|
179
|
+
*
|
180
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
126
181
|
*/
|
127
182
|
$meta(initialMeta) {
|
128
183
|
return new Builder({
|
@@ -131,7 +186,11 @@ class Builder {
|
|
131
186
|
});
|
132
187
|
}
|
133
188
|
/**
|
134
|
-
*
|
189
|
+
* Sets or overrides the initial route.
|
190
|
+
* This option is typically relevant when integrating with OpenAPI.
|
191
|
+
*
|
192
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
193
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
135
194
|
*/
|
136
195
|
$route(initialRoute) {
|
137
196
|
return new Builder({
|
@@ -139,15 +198,31 @@ class Builder {
|
|
139
198
|
route: initialRoute
|
140
199
|
});
|
141
200
|
}
|
201
|
+
/**
|
202
|
+
* Sets or overrides the initial input schema.
|
203
|
+
*
|
204
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
205
|
+
*/
|
142
206
|
$input(initialInputSchema) {
|
143
207
|
return new Builder({
|
144
208
|
...this["~orpc"],
|
145
209
|
inputSchema: initialInputSchema
|
146
210
|
});
|
147
211
|
}
|
212
|
+
/**
|
213
|
+
* Creates a middleware.
|
214
|
+
*
|
215
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
216
|
+
*/
|
148
217
|
middleware(middleware) {
|
149
218
|
return decorateMiddleware(middleware);
|
150
219
|
}
|
220
|
+
/**
|
221
|
+
* Adds type-safe custom errors.
|
222
|
+
* The provided errors are spared-merged with any existing errors.
|
223
|
+
*
|
224
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
225
|
+
*/
|
151
226
|
errors(errors) {
|
152
227
|
return new Builder({
|
153
228
|
...this["~orpc"],
|
@@ -161,18 +236,37 @@ class Builder {
|
|
161
236
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
162
237
|
});
|
163
238
|
}
|
239
|
+
/**
|
240
|
+
* Sets or updates the metadata.
|
241
|
+
* The provided metadata is spared-merged with any existing metadata.
|
242
|
+
*
|
243
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
244
|
+
*/
|
164
245
|
meta(meta) {
|
165
246
|
return new Builder({
|
166
247
|
...this["~orpc"],
|
167
248
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
168
249
|
});
|
169
250
|
}
|
251
|
+
/**
|
252
|
+
* Sets or updates the route definition.
|
253
|
+
* The provided route is spared-merged with any existing route.
|
254
|
+
* This option is typically relevant when integrating with OpenAPI.
|
255
|
+
*
|
256
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
257
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
258
|
+
*/
|
170
259
|
route(route) {
|
171
260
|
return new Builder({
|
172
261
|
...this["~orpc"],
|
173
262
|
route: mergeRoute(this["~orpc"].route, route)
|
174
263
|
});
|
175
264
|
}
|
265
|
+
/**
|
266
|
+
* Defines the input validation schema.
|
267
|
+
*
|
268
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
269
|
+
*/
|
176
270
|
input(schema) {
|
177
271
|
return new Builder({
|
178
272
|
...this["~orpc"],
|
@@ -180,6 +274,11 @@ class Builder {
|
|
180
274
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
181
275
|
});
|
182
276
|
}
|
277
|
+
/**
|
278
|
+
* Defines the output validation schema.
|
279
|
+
*
|
280
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
281
|
+
*/
|
183
282
|
output(schema) {
|
184
283
|
return new Builder({
|
185
284
|
...this["~orpc"],
|
@@ -187,27 +286,57 @@ class Builder {
|
|
187
286
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
188
287
|
});
|
189
288
|
}
|
289
|
+
/**
|
290
|
+
* Defines the handler of the procedure.
|
291
|
+
*
|
292
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
293
|
+
*/
|
190
294
|
handler(handler) {
|
191
295
|
return new DecoratedProcedure({
|
192
296
|
...this["~orpc"],
|
193
297
|
handler
|
194
298
|
});
|
195
299
|
}
|
300
|
+
/**
|
301
|
+
* Prefixes all procedures in the router.
|
302
|
+
* The provided prefix is post-appended to any existing router prefix.
|
303
|
+
*
|
304
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
305
|
+
*
|
306
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
307
|
+
*/
|
196
308
|
prefix(prefix) {
|
197
309
|
return new Builder({
|
198
310
|
...this["~orpc"],
|
199
311
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
200
312
|
});
|
201
313
|
}
|
314
|
+
/**
|
315
|
+
* Adds tags to all procedures in the router.
|
316
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
317
|
+
*
|
318
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
319
|
+
*/
|
202
320
|
tag(...tags) {
|
203
321
|
return new Builder({
|
204
322
|
...this["~orpc"],
|
205
323
|
tags: mergeTags(this["~orpc"].tags, tags)
|
206
324
|
});
|
207
325
|
}
|
326
|
+
/**
|
327
|
+
* Applies all of the previously defined options to the specified router.
|
328
|
+
*
|
329
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
330
|
+
*/
|
208
331
|
router(router) {
|
209
332
|
return enhanceRouter(router, this["~orpc"]);
|
210
333
|
}
|
334
|
+
/**
|
335
|
+
* Create a lazy router
|
336
|
+
* And applies all of the previously defined options to the specified router.
|
337
|
+
*
|
338
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
339
|
+
*/
|
211
340
|
lazy(loader) {
|
212
341
|
return enhanceRouter(lazy(loader), this["~orpc"]);
|
213
342
|
}
|
@@ -223,10 +352,6 @@ const os = new Builder({
|
|
223
352
|
dedupeLeadingMiddlewares: true
|
224
353
|
});
|
225
354
|
|
226
|
-
function mergeCurrentContext(context, other) {
|
227
|
-
return { ...context, ...other };
|
228
|
-
}
|
229
|
-
|
230
355
|
function implementerInternal(contract, config, middlewares) {
|
231
356
|
if (isContractProcedure(contract)) {
|
232
357
|
const impl2 = new Builder({
|
@@ -319,12 +444,12 @@ function implement(contract, config = {}) {
|
|
319
444
|
return impl;
|
320
445
|
}
|
321
446
|
|
322
|
-
function createRouterClient(router, ...
|
447
|
+
function createRouterClient(router, ...rest) {
|
323
448
|
if (isProcedure(router)) {
|
324
|
-
const caller = createProcedureClient(router,
|
449
|
+
const caller = createProcedureClient(router, ...rest);
|
325
450
|
return caller;
|
326
451
|
}
|
327
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router),
|
452
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), ...rest) : {};
|
328
453
|
const recursive = new Proxy(procedureCaller, {
|
329
454
|
get(target, key) {
|
330
455
|
if (typeof key !== "string") {
|
@@ -335,12 +460,12 @@ function createRouterClient(router, ...[options]) {
|
|
335
460
|
return Reflect.get(target, key);
|
336
461
|
}
|
337
462
|
return createRouterClient(next, {
|
338
|
-
...
|
339
|
-
path: [...
|
463
|
+
...rest[0],
|
464
|
+
path: [...rest[0]?.path ?? [], key]
|
340
465
|
});
|
341
466
|
}
|
342
467
|
});
|
343
468
|
return recursive;
|
344
469
|
}
|
345
470
|
|
346
|
-
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy,
|
471
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,31 +1,156 @@
|
|
1
|
-
import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CL84X8p4.mjs';
|
2
|
-
export { C as CompositePlugin } from '../shared/server.CL84X8p4.mjs';
|
3
1
|
import { Value } from '@orpc/shared';
|
4
|
-
import {
|
5
|
-
import '@orpc/
|
6
|
-
import '
|
7
|
-
import '
|
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.DY7OKEoj.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
|
10
|
-
|
11
|
-
|
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>]>;
|
12
54
|
allowMethods?: readonly string[];
|
13
55
|
allowHeaders?: readonly string[];
|
14
56
|
maxAge?: number;
|
15
57
|
credentials?: boolean;
|
16
58
|
exposeHeaders?: readonly string[];
|
17
59
|
}
|
18
|
-
|
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
|
-
|
21
|
-
|
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
|
-
|
28
|
-
|
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 {
|
155
|
+
export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
|
156
|
+
export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,31 +1,156 @@
|
|
1
|
-
import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.hqPWnakL.js';
|
2
|
-
export { C as CompositePlugin } from '../shared/server.hqPWnakL.js';
|
3
1
|
import { Value } from '@orpc/shared';
|
4
|
-
import {
|
5
|
-
import '@orpc/
|
6
|
-
import '
|
7
|
-
import '
|
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.D5fBlF9j.js';
|
5
|
+
import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DPWk5pjW.js';
|
6
|
+
import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
|
7
|
+
import { ORPCError } from '@orpc/client';
|
8
8
|
|
9
|
-
interface
|
10
|
-
|
11
|
-
|
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>]>;
|
12
54
|
allowMethods?: readonly string[];
|
13
55
|
allowHeaders?: readonly string[];
|
14
56
|
maxAge?: number;
|
15
57
|
credentials?: boolean;
|
16
58
|
exposeHeaders?: readonly string[];
|
17
59
|
}
|
18
|
-
|
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
|
-
|
21
|
-
|
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
|
-
|
28
|
-
|
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 {
|
155
|
+
export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
|
156
|
+
export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
|