@orpc/server 2.0.0-beta.49 → 2.0.0-beta.50
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/dist/adapters/aws-lambda/handler.d.ts +17 -15
- package/dist/adapters/aws-lambda/handler.js +23 -23
- package/dist/adapters/aws-lambda/index.d.ts +4 -16
- package/dist/adapters/aws-lambda/index.js +2 -2
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +9 -9
- package/dist/adapters/aws-lambda/rpc-handler.js +20 -17
- package/dist/adapters/crossws/handler.d.ts +44 -42
- package/dist/adapters/crossws/handler.js +53 -60
- package/dist/adapters/crossws/index.d.ts +3 -2
- package/dist/adapters/crossws/index.js +2 -2
- package/dist/adapters/crossws/rpc-handler.d.ts +10 -10
- package/dist/adapters/crossws/rpc-handler.js +17 -14
- package/dist/adapters/fastify/handler.d.ts +17 -15
- package/dist/adapters/fastify/handler.js +20 -20
- package/dist/adapters/fastify/index.d.ts +3 -2
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/fastify/rpc-handler.d.ts +9 -9
- package/dist/adapters/fastify/rpc-handler.js +16 -13
- package/dist/adapters/fetch/handler.d.ts +19 -17
- package/dist/adapters/fetch/handler.js +22 -22
- package/dist/adapters/fetch/index.d.ts +4 -7
- package/dist/adapters/fetch/index.js +3 -7
- package/dist/adapters/fetch/rpc-handler.d.ts +9 -9
- package/dist/adapters/fetch/rpc-handler.js +18 -15
- package/dist/adapters/message-port/handler.d.ts +58 -60
- package/dist/adapters/message-port/handler.js +72 -86
- package/dist/adapters/message-port/index.d.ts +3 -2
- package/dist/adapters/message-port/index.js +2 -2
- package/dist/adapters/message-port/rpc-handler.d.ts +9 -9
- package/dist/adapters/message-port/rpc-handler.js +17 -14
- package/dist/adapters/node/handler.d.ts +17 -15
- package/dist/adapters/node/handler.js +20 -20
- package/dist/adapters/node/index.d.ts +4 -7
- package/dist/adapters/node/index.js +3 -7
- package/dist/adapters/node/rpc-handler.d.ts +9 -9
- package/dist/adapters/node/rpc-handler.js +17 -14
- package/dist/adapters/standard/codec.d.ts +13 -13
- package/dist/adapters/standard/handler.d.ts +49 -49
- package/dist/adapters/standard/handler.js +205 -205
- package/dist/adapters/standard/index.d.ts +7 -6
- package/dist/adapters/standard/index.js +4 -5
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-handler-codec.d.ts +39 -43
- package/dist/adapters/standard/rpc-handler-codec.js +50 -51
- package/dist/adapters/standard/rpc-matcher.d.ts +40 -40
- package/dist/adapters/standard/rpc-matcher.js +103 -149
- package/dist/adapters/standard/utils.d.ts +8 -8
- package/dist/adapters/standard/utils.js +7 -5
- package/dist/adapters/standard-peer/index.d.ts +2 -1
- package/dist/adapters/standard-peer/index.js +1 -1
- package/dist/adapters/standard-peer/utils.d.ts +6 -4
- package/dist/adapters/standard-peer/utils.js +12 -6
- package/dist/adapters/websocket/handler.d.ts +52 -50
- package/dist/adapters/websocket/handler.js +75 -85
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-handler.d.ts +9 -9
- package/dist/adapters/websocket/rpc-handler.js +17 -14
- package/dist/builder-variants.d.ts +195 -195
- package/dist/builder.d.ts +103 -104
- package/dist/builder.js +198 -224
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +4 -2
- package/dist/context.d.ts +3 -3
- package/dist/extensions/callable.d.ts +11 -11
- package/dist/extensions/callable.js +6 -5
- package/dist/helpers/base64url.d.ts +1 -1
- package/dist/helpers/base64url.js +44 -49
- package/dist/helpers/cookie.d.ts +10 -11
- package/dist/helpers/cookie.js +56 -63
- package/dist/helpers/encryption.d.ts +1 -1
- package/dist/helpers/encryption.js +80 -70
- package/dist/helpers/index.d.ts +5 -4
- package/dist/helpers/index.js +4 -4
- package/dist/helpers/signing.d.ts +1 -1
- package/dist/helpers/signing.js +72 -82
- package/dist/implementer-procedure.d.ts +12 -13
- package/dist/implementer-procedure.js +37 -44
- package/dist/implementer-router.d.ts +30 -36
- package/dist/implementer-router.js +92 -111
- package/dist/implementer.d.ts +8 -8
- package/dist/implementer.js +28 -35
- package/dist/index.d.ts +22 -61
- package/dist/index.js +16 -48
- package/dist/lazy.d.ts +14 -14
- package/dist/lazy.js +19 -30
- package/dist/middleware-decorated.d.ts +8 -9
- package/dist/middleware-decorated.js +66 -70
- package/dist/middleware.d.ts +34 -34
- package/dist/plugins/batch.d.ts +75 -75
- package/dist/plugins/batch.js +345 -379
- package/dist/plugins/cors.d.ts +60 -64
- package/dist/plugins/cors.js +118 -111
- package/dist/plugins/get-method-csrf-protection.d.ts +8 -6
- package/dist/plugins/get-method-csrf-protection.js +47 -63
- package/dist/plugins/head-method.d.ts +11 -9
- package/dist/plugins/head-method.js +97 -94
- package/dist/plugins/index.d.ts +15 -39
- package/dist/plugins/index.js +14 -29
- package/dist/plugins/method-override.d.ts +30 -28
- package/dist/plugins/method-override.js +53 -49
- package/dist/plugins/request-compression.d.ts +11 -9
- package/dist/plugins/request-compression.js +52 -79
- package/dist/plugins/request-headers.d.ts +10 -8
- package/dist/plugins/request-headers.js +27 -29
- package/dist/plugins/request-limit.d.ts +21 -19
- package/dist/plugins/request-limit.js +60 -67
- package/dist/plugins/response-compression.d.ts +42 -39
- package/dist/plugins/response-compression.js +150 -202
- package/dist/plugins/response-headers.d.ts +15 -13
- package/dist/plugins/response-headers.js +43 -46
- package/dist/plugins/rethrow.d.ts +25 -23
- package/dist/plugins/rethrow.js +46 -58
- package/dist/plugins/signal-sync.d.ts +7 -5
- package/dist/plugins/signal-sync.js +71 -86
- package/dist/plugins/timeout.d.ts +29 -27
- package/dist/plugins/timeout.js +61 -58
- package/dist/procedure-client.d.ts +14 -15
- package/dist/procedure-client.js +149 -166
- package/dist/procedure-decorated.d.ts +9 -9
- package/dist/procedure-decorated.js +36 -44
- package/dist/procedure-utils.d.ts +10 -30
- package/dist/procedure-utils.js +39 -40
- package/dist/procedure.d.ts +60 -60
- package/dist/procedure.js +18 -24
- package/dist/router-client.d.ts +9 -11
- package/dist/router-client.js +33 -41
- package/dist/router-hidden.js +10 -12
- package/dist/router-utils.d.ts +13 -30
- package/dist/router-utils.js +146 -191
- package/dist/router.d.ts +12 -26
- package/package.json +10 -10
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/builder-variants.js +0 -1
- package/dist/context.js +0 -1
- package/dist/middleware.js +0 -1
- package/dist/router-hidden.d.ts +0 -5
- package/dist/router.js +0 -1
package/dist/lazy.js
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
import { getConstructor, isNonPrimitive } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return (isNonPrimitive(instance) &&
|
|
20
|
-
isNonPrimitive(instance['~orpc']) &&
|
|
21
|
-
isNonPrimitive(instance['~orpc'].meta) &&
|
|
22
|
-
(instance['~orpc'].metaPlugins === undefined ||
|
|
23
|
-
Array.isArray(instance['~orpc'].metaPlugins)) &&
|
|
24
|
-
typeof instance['~orpc'].loader === 'function');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export function unlazy(maybeLazy) {
|
|
28
|
-
return maybeLazy instanceof Lazy
|
|
29
|
-
? maybeLazy['~orpc'].loader()
|
|
30
|
-
: Promise.resolve({ default: maybeLazy });
|
|
1
|
+
import { getConstructor, isNonPrimitive } from "@orpc/shared";
|
|
2
|
+
// src/lazy.ts
|
|
3
|
+
var Lazy = class Lazy {
|
|
4
|
+
"~orpc";
|
|
5
|
+
"constructor"(def) {
|
|
6
|
+
this["~orpc"] = def;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Checks if the given instance satisfies the {@link Lazy} class/interface.
|
|
10
|
+
*/
|
|
11
|
+
static [Symbol.hasInstance](instance) {
|
|
12
|
+
if (this !== Lazy) return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
13
|
+
if (getConstructor(instance) === Lazy) return true;
|
|
14
|
+
return isNonPrimitive(instance) && isNonPrimitive(instance["~orpc"]) && isNonPrimitive(instance["~orpc"].meta) && (instance["~orpc"].metaPlugins === void 0 || Array.isArray(instance["~orpc"].metaPlugins)) && typeof instance["~orpc"].loader === "function";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function unlazy(maybeLazy) {
|
|
18
|
+
return maybeLazy instanceof Lazy ? maybeLazy["~orpc"].loader() : Promise.resolve({ default: maybeLazy });
|
|
31
19
|
}
|
|
20
|
+
export { Lazy, unlazy };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { Context, MergedContext, MergedInitialContext } from "./context.js";
|
|
2
|
+
import { Middleware } from "./middleware.js";
|
|
3
|
+
import { ErrorMap, MergedErrorMap } from "@orpc/contract";
|
|
4
|
+
import { IntersectPick } from "@orpc/shared";
|
|
5
5
|
export interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorMap> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
export declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorMap>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorMap>;
|
|
6
|
+
adaptInput<T>(adapt: (input: T) => TInput): DecoratedMiddleware<TInContext, TOutContext, T, TOutput, TErrorMap>;
|
|
7
|
+
errors<T extends ErrorMap>(errors: T): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, MergedErrorMap<TErrorMap, T>>;
|
|
8
|
+
use<$OutContext extends IntersectPick<MergedContext<TInContext, TOutContext>, $OutContext>, $Input extends TInput, $InContext extends Context = MergedContext<TInContext, TOutContext>, $ErrorMap extends ErrorMap = TErrorMap>(middleware: Middleware<$InContext | MergedContext<TInContext, TOutContext>, $OutContext, $Input, TOutput, $ErrorMap>): DecoratedMiddleware<MergedInitialContext<TInContext, TOutContext, $InContext>, MergedContext<TOutContext, $OutContext>, $Input, TOutput, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
9
|
+
}
|
|
@@ -1,71 +1,67 @@
|
|
|
1
|
-
import { mergeErrorMap } from
|
|
2
|
-
import { toArray } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
value: `${decorated.name} + ${usedMiddleware.name}`,
|
|
67
|
-
});
|
|
68
|
-
return merged;
|
|
69
|
-
};
|
|
70
|
-
return decorated;
|
|
1
|
+
import { mergeErrorMap } from "@orpc/contract";
|
|
2
|
+
import { toArray } from "@orpc/shared";
|
|
3
|
+
// src/middleware-decorated.ts
|
|
4
|
+
function decorateMiddleware(middleware) {
|
|
5
|
+
const decorated = ((...args) => middleware(...args));
|
|
6
|
+
decorated["~orpc"] = middleware["~orpc"];
|
|
7
|
+
Object.defineProperty(decorated, "name", { value: middleware.name });
|
|
8
|
+
decorated.adaptInput = (adapt) => {
|
|
9
|
+
const mapped = decorateMiddleware((opts, input, ...args) => {
|
|
10
|
+
return middleware(opts, adapt(input), ...args);
|
|
11
|
+
});
|
|
12
|
+
mapped["~orpc"] = decorated["~orpc"];
|
|
13
|
+
Object.defineProperty(mapped, "name", { value: decorated.name });
|
|
14
|
+
return mapped;
|
|
15
|
+
};
|
|
16
|
+
decorated.errors = (errors) => {
|
|
17
|
+
const newMiddleware = decorateMiddleware(decorated);
|
|
18
|
+
newMiddleware["~orpc"] = {
|
|
19
|
+
...decorated["~orpc"],
|
|
20
|
+
errorMap: mergeErrorMap(decorated["~orpc"]?.errorMap, errors)
|
|
21
|
+
};
|
|
22
|
+
return newMiddleware;
|
|
23
|
+
};
|
|
24
|
+
decorated.use = (usedMiddleware) => {
|
|
25
|
+
const merged = decorateMiddleware((opts, ...args) => {
|
|
26
|
+
return middleware({
|
|
27
|
+
...opts,
|
|
28
|
+
async next(nextOpts1) {
|
|
29
|
+
const signal = nextOpts1?.signal ?? opts.signal;
|
|
30
|
+
const result = await usedMiddleware({
|
|
31
|
+
...opts,
|
|
32
|
+
context: {
|
|
33
|
+
...opts.context,
|
|
34
|
+
...nextOpts1?.context
|
|
35
|
+
},
|
|
36
|
+
signal,
|
|
37
|
+
next(nextOpts2, ...args) {
|
|
38
|
+
return opts.next({
|
|
39
|
+
context: {
|
|
40
|
+
...nextOpts1?.context,
|
|
41
|
+
...nextOpts2?.context
|
|
42
|
+
},
|
|
43
|
+
signal: nextOpts2?.signal ?? signal
|
|
44
|
+
}, ...args);
|
|
45
|
+
}
|
|
46
|
+
}, ...args);
|
|
47
|
+
return {
|
|
48
|
+
...result,
|
|
49
|
+
context: {
|
|
50
|
+
...nextOpts1?.context,
|
|
51
|
+
...result.context
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}, ...args);
|
|
56
|
+
});
|
|
57
|
+
merged["~orpc"] = {
|
|
58
|
+
...decorated["~orpc"],
|
|
59
|
+
errorMap: mergeErrorMap(usedMiddleware["~orpc"]?.errorMap, decorated["~orpc"]?.errorMap),
|
|
60
|
+
metaPlugins: [...toArray(decorated["~orpc"]?.metaPlugins), ...toArray(usedMiddleware["~orpc"]?.metaPlugins)]
|
|
61
|
+
};
|
|
62
|
+
Object.defineProperty(merged, "name", { value: `${decorated.name} + ${usedMiddleware.name}` });
|
|
63
|
+
return merged;
|
|
64
|
+
};
|
|
65
|
+
return decorated;
|
|
71
66
|
}
|
|
67
|
+
export { decorateMiddleware };
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { Context } from "./context.js";
|
|
2
|
+
import { AnyProcedure } from "./procedure.js";
|
|
3
|
+
import { AnyMetaPlugin, ErrorMap, ORPCErrorConstructorMap } from "@orpc/contract";
|
|
4
|
+
import { MaybeOptionalOptions, Promisable } from "@orpc/shared";
|
|
5
5
|
export type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
output: TOutput;
|
|
7
|
+
context: TOutContext;
|
|
8
8
|
}>;
|
|
9
9
|
export type MiddlewareNextOptions<TOutContext extends Context> = (object extends TOutContext ? {
|
|
10
|
-
|
|
10
|
+
context?: TOutContext | undefined;
|
|
11
11
|
} : {
|
|
12
|
-
|
|
12
|
+
context: TOutContext;
|
|
13
13
|
}) & {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/** Overrides the signal for the rest of the chain. */
|
|
15
|
+
signal?: AbortSignal | undefined;
|
|
16
16
|
};
|
|
17
17
|
export interface MiddlewareNext<TOutput> {
|
|
18
|
-
|
|
18
|
+
<T extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<T>>): MiddlewareResult<T, TOutput>;
|
|
19
19
|
}
|
|
20
20
|
export type MiddlewareDoneOptions<TOutContext, TOutput> = (object extends TOutContext ? {
|
|
21
|
-
|
|
21
|
+
context?: TOutContext | undefined;
|
|
22
22
|
} : {
|
|
23
|
-
|
|
23
|
+
context: TOutContext;
|
|
24
24
|
}) & {
|
|
25
|
-
|
|
25
|
+
output: TOutput;
|
|
26
26
|
};
|
|
27
27
|
export interface MiddlewareDone<TOutput> {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Create a successful result and terminate the middleware chain early.
|
|
30
|
+
*/
|
|
31
|
+
<TOutContext extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareDoneOptions<TOutContext, TOutput>>): MiddlewareResult<TOutContext, TOutput>;
|
|
32
32
|
}
|
|
33
33
|
export interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
context: TInContext;
|
|
35
|
+
path: string[];
|
|
36
|
+
procedure: AnyProcedure;
|
|
37
|
+
signal?: AbortSignal | undefined;
|
|
38
|
+
lastEventId: string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Invoke to continue the middleware chain.
|
|
41
|
+
*/
|
|
42
|
+
next: MiddlewareNext<TOutput>;
|
|
43
|
+
errors: TErrorConstructorMap;
|
|
44
44
|
}
|
|
45
45
|
export interface MiddlewareDefinition<TErrorMap extends ErrorMap> {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
errorMap?: TErrorMap | undefined;
|
|
47
|
+
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
48
48
|
}
|
|
49
49
|
export interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
/** this property should be optional to support inline middleware */
|
|
51
|
+
"~orpc"?: MiddlewareDefinition<TErrorMap> | undefined;
|
|
52
|
+
(opts: MiddlewareOptions<TInContext, TOutput, ORPCErrorConstructorMap<TErrorMap>>, input: TInput, done: MiddlewareDone<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
53
53
|
}
|
|
54
|
-
export type AnyMiddleware = Middleware<any, any, any, any, any>;
|
|
54
|
+
export type AnyMiddleware = Middleware<any, any, any, any, any>;
|
package/dist/plugins/batch.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import "../adapters/standard/index.js";
|
|
2
|
+
import { StandardHandlerPlugin } from "../adapters/standard/plugin.js";
|
|
3
|
+
import { StandardHandlerOptions, StandardHandlerRoutingInterceptorOptions } from "../adapters/standard/handler.js";
|
|
4
|
+
import { Context } from "../context.js";
|
|
5
|
+
import { Promisable, Value } from "@orpc/shared";
|
|
6
|
+
import { StandardHeaders, StandardLazyRequest, StandardResponse } from "@standard-server/core";
|
|
5
7
|
/**
|
|
6
8
|
* Content type for batch responses that use the length-prefixed binary framing,
|
|
7
9
|
* which they do in `streaming` mode, or when any sub-response contains binary or is a stream.
|
|
@@ -11,64 +13,62 @@ import type { Context } from '../context.ts';
|
|
|
11
13
|
*/
|
|
12
14
|
export declare const BATCH_CONTENT_TYPE = "application/vnd.orpc.batch";
|
|
13
15
|
export interface BatchHandlerPluginOptions<T extends Context> {
|
|
16
|
+
/**
|
|
17
|
+
* The max size of the batch allowed. Larger batches are rejected with a `413`,
|
|
18
|
+
* so keep the client Batch Link Plugin's `maxSize` at or below it.
|
|
19
|
+
*
|
|
20
|
+
* @default DEFAULT_BATCH_MAX_SIZE (10)
|
|
21
|
+
* @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
|
|
22
|
+
*/
|
|
23
|
+
maxSize?: Value<Promisable<number>, [options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Map each subrequest in the batch before it is processed.
|
|
26
|
+
*
|
|
27
|
+
* @default merges the batch request headers into the subrequest, giving them priority over
|
|
28
|
+
* the subrequest headers, and removes the `orpc-batch` header to prevent nested batching
|
|
29
|
+
*/
|
|
30
|
+
mapSubrequest?: ((subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest) | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Map each sub-response in the batch before it is sent.
|
|
33
|
+
*
|
|
34
|
+
* @default removes the headers the batch response already has with the same value, which the client
|
|
35
|
+
* merges back, and `set-cookie`, which the browser ignores there and JavaScript could read
|
|
36
|
+
*/
|
|
37
|
+
mapSubresponse?: ((subresponse: StandardResponse, partialBatchResponse: Pick<StandardResponse, "status" | "headers">, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardResponse) | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Success batch response status code.
|
|
40
|
+
*
|
|
41
|
+
* @default 207
|
|
42
|
+
*/
|
|
43
|
+
successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Success batch response headers.
|
|
46
|
+
*
|
|
47
|
+
* In `buffered` mode, the batch response also gets the cookies its sub-responses set, and the headers they all share.
|
|
48
|
+
* In `streaming` mode, it gets only the cookies of the first sub-response to be ready.
|
|
49
|
+
* Headers set here win, and setting one to `undefined` keeps it off, except `set-cookie` and `vary`, which merge.
|
|
50
|
+
*
|
|
51
|
+
* @default {}
|
|
52
|
+
*/
|
|
53
|
+
headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Keep-alive frames for batch responses that stream.
|
|
56
|
+
*
|
|
57
|
+
* A zero-length length-prefixed frame is sent periodically while the stream is idle
|
|
58
|
+
* (no message sent for `interval` ms). Clients ignore these frames.
|
|
59
|
+
*
|
|
60
|
+
* `false` disables it, an object customizes it.
|
|
61
|
+
*
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
keepAlive?: boolean | {
|
|
14
65
|
/**
|
|
15
|
-
*
|
|
16
|
-
* so keep the client Batch Link Plugin's `maxSize` at or below it.
|
|
66
|
+
* Interval (in milliseconds) between keep-alive frames after the last message.
|
|
17
67
|
*
|
|
18
|
-
* @default
|
|
19
|
-
* @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
|
|
68
|
+
* @default 15000
|
|
20
69
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* Map each subrequest in the batch before it is processed.
|
|
24
|
-
*
|
|
25
|
-
* @default merges the batch request headers into the subrequest, giving them priority over
|
|
26
|
-
* the subrequest headers, and removes the `orpc-batch` header to prevent nested batching
|
|
27
|
-
*/
|
|
28
|
-
mapSubrequest?: ((subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest) | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Map each sub-response in the batch before it is sent.
|
|
31
|
-
*
|
|
32
|
-
* @default removes the headers the batch response already has with the same value, which the client
|
|
33
|
-
* merges back, and `set-cookie`, which the browser ignores there and JavaScript could read
|
|
34
|
-
*/
|
|
35
|
-
mapSubresponse?: ((subresponse: StandardResponse, partialBatchResponse: Pick<StandardResponse, 'status' | 'headers'>, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardResponse) | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Success batch response status code.
|
|
38
|
-
*
|
|
39
|
-
* @default 207
|
|
40
|
-
*/
|
|
41
|
-
successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Success batch response headers.
|
|
44
|
-
*
|
|
45
|
-
* In `buffered` mode, the batch response also gets the cookies its sub-responses set, and the headers they all share.
|
|
46
|
-
* In `streaming` mode, it gets only the cookies of the first sub-response to be ready.
|
|
47
|
-
* Headers set here win, and setting one to `undefined` keeps it off, except `set-cookie` and `vary`, which merge.
|
|
48
|
-
*
|
|
49
|
-
* @default {}
|
|
50
|
-
*/
|
|
51
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
52
|
-
batchOptions: StandardHandlerRoutingInterceptorOptions<T>
|
|
53
|
-
]> | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* Keep-alive frames for batch responses that stream.
|
|
56
|
-
*
|
|
57
|
-
* A zero-length length-prefixed frame is sent periodically while the stream is idle
|
|
58
|
-
* (no message sent for `interval` ms). Clients ignore these frames.
|
|
59
|
-
*
|
|
60
|
-
* `false` disables it, an object customizes it.
|
|
61
|
-
*
|
|
62
|
-
* @default true
|
|
63
|
-
*/
|
|
64
|
-
keepAlive?: boolean | {
|
|
65
|
-
/**
|
|
66
|
-
* Interval (in milliseconds) between keep-alive frames after the last message.
|
|
67
|
-
*
|
|
68
|
-
* @default 15000
|
|
69
|
-
*/
|
|
70
|
-
interval?: number | undefined;
|
|
71
|
-
} | undefined;
|
|
70
|
+
interval?: number | undefined;
|
|
71
|
+
} | undefined;
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Handles batch requests sent by the client Batch Link Plugin, splitting each
|
|
@@ -84,19 +84,19 @@ export interface BatchHandlerPluginOptions<T extends Context> {
|
|
|
84
84
|
* @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
|
|
85
85
|
*/
|
|
86
86
|
export declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
87
|
+
name: string;
|
|
88
|
+
/**
|
|
89
|
+
* Run batch interceptors inside the tracing interceptors
|
|
90
|
+
* so each subrequest gets its own span instead of sharing one batch-level span.
|
|
91
|
+
*/
|
|
92
|
+
after: string[];
|
|
93
|
+
private readonly maxSize;
|
|
94
|
+
private readonly mapSubrequest;
|
|
95
|
+
private readonly mapSubresponse;
|
|
96
|
+
private readonly successStatus;
|
|
97
|
+
private readonly headers;
|
|
98
|
+
private readonly keepAliveEnabled;
|
|
99
|
+
private readonly keepAliveInterval;
|
|
100
|
+
constructor(options?: BatchHandlerPluginOptions<T>);
|
|
101
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
102
|
+
}
|