@orpc/server 2.0.0-beta.47 → 2.0.0-beta.49
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 +6 -7
- package/dist/adapters/aws-lambda/handler.d.ts +25 -0
- package/dist/adapters/aws-lambda/handler.js +24 -0
- package/dist/adapters/aws-lambda/index.d.ts +10 -45
- package/dist/adapters/aws-lambda/index.js +2 -0
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +19 -0
- package/dist/adapters/aws-lambda/rpc-handler.js +18 -0
- package/dist/adapters/crossws/handler.d.ts +45 -0
- package/dist/adapters/crossws/handler.js +60 -0
- package/dist/adapters/crossws/index.d.ts +2 -63
- package/dist/adapters/crossws/index.js +2 -0
- package/dist/adapters/crossws/rpc-handler.d.ts +16 -0
- package/dist/adapters/crossws/rpc-handler.js +15 -0
- package/dist/adapters/fastify/handler.d.ts +21 -0
- package/dist/adapters/fastify/handler.js +20 -0
- package/dist/adapters/fastify/index.d.ts +2 -42
- package/dist/adapters/fastify/index.js +2 -0
- package/dist/adapters/fastify/rpc-handler.d.ts +15 -0
- package/dist/adapters/fastify/rpc-handler.js +14 -0
- package/dist/adapters/fetch/handler.d.ts +23 -0
- package/dist/adapters/fetch/handler.js +22 -0
- package/dist/adapters/fetch/index.d.ts +5 -45
- package/dist/adapters/fetch/index.js +7 -0
- package/dist/adapters/fetch/rpc-handler.d.ts +17 -0
- package/dist/adapters/fetch/rpc-handler.js +16 -0
- package/dist/adapters/message-port/{index.d.mts → handler.d.ts} +17 -30
- package/dist/adapters/message-port/handler.js +86 -0
- package/dist/adapters/message-port/index.d.ts +2 -77
- package/dist/adapters/message-port/index.js +2 -0
- package/dist/adapters/message-port/rpc-handler.d.ts +16 -0
- package/dist/adapters/message-port/rpc-handler.js +15 -0
- package/dist/adapters/node/handler.d.ts +21 -0
- package/dist/adapters/node/handler.js +20 -0
- package/dist/adapters/node/index.d.ts +5 -42
- package/dist/adapters/node/index.js +7 -0
- package/dist/adapters/node/rpc-handler.d.ts +16 -0
- package/dist/adapters/node/rpc-handler.js +15 -0
- package/dist/adapters/standard/codec.d.ts +16 -0
- package/dist/adapters/standard/codec.js +1 -0
- package/dist/adapters/standard/handler.d.ts +68 -0
- package/dist/adapters/standard/handler.js +205 -0
- package/dist/adapters/standard/index.d.ts +6 -95
- package/dist/adapters/standard/index.js +5 -0
- package/dist/adapters/standard/plugin.d.ts +32 -0
- package/dist/adapters/standard/plugin.js +16 -0
- package/dist/adapters/standard/rpc-handler-codec.d.ts +46 -0
- package/dist/adapters/standard/rpc-handler-codec.js +51 -0
- package/dist/adapters/standard/rpc-matcher.d.ts +53 -0
- package/dist/adapters/standard/rpc-matcher.js +152 -0
- package/dist/adapters/standard/utils.d.ts +10 -0
- package/dist/adapters/standard/utils.js +6 -0
- package/dist/adapters/standard-peer/index.d.ts +1 -11
- package/dist/adapters/standard-peer/index.js +1 -0
- package/dist/adapters/standard-peer/utils.d.ts +4 -0
- package/dist/adapters/standard-peer/utils.js +7 -0
- package/dist/adapters/websocket/{index.d.mts → handler.d.ts} +11 -29
- package/dist/adapters/websocket/handler.js +85 -0
- package/dist/adapters/websocket/index.d.ts +2 -77
- package/dist/adapters/websocket/index.js +2 -0
- package/dist/adapters/websocket/rpc-handler.d.ts +16 -0
- package/dist/adapters/websocket/rpc-handler.js +15 -0
- package/dist/builder-variants.d.ts +226 -0
- package/dist/builder-variants.js +1 -0
- package/dist/builder.d.ts +127 -0
- package/dist/builder.js +226 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/context.d.ts +6 -0
- package/dist/context.js +1 -0
- package/dist/extensions/callable.d.ts +6 -5
- package/dist/extensions/callable.js +7 -0
- package/dist/helpers/base64url.d.ts +31 -0
- package/dist/helpers/base64url.js +53 -0
- package/dist/helpers/cookie.d.ts +51 -0
- package/dist/helpers/cookie.js +69 -0
- package/dist/helpers/encryption.d.ts +28 -0
- package/dist/helpers/encryption.js +80 -0
- package/dist/helpers/index.d.ts +4 -167
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/signing.d.ts +50 -0
- package/dist/helpers/signing.js +88 -0
- package/dist/implementer-procedure.d.ts +16 -0
- package/dist/implementer-procedure.js +44 -0
- package/dist/implementer-router.d.ts +40 -0
- package/dist/implementer-router.js +117 -0
- package/dist/implementer.d.ts +16 -0
- package/dist/implementer.js +37 -0
- package/dist/index.d.ts +45 -460
- package/dist/index.js +48 -0
- package/dist/lazy.d.ts +20 -0
- package/dist/lazy.js +31 -0
- package/dist/middleware-decorated.d.ts +10 -0
- package/dist/middleware-decorated.js +71 -0
- package/dist/middleware.d.ts +54 -0
- package/dist/middleware.js +1 -0
- package/dist/plugins/batch.d.ts +102 -0
- package/dist/plugins/batch.js +405 -0
- package/dist/plugins/cors.d.ts +73 -0
- package/dist/plugins/cors.js +112 -0
- package/dist/plugins/get-method-csrf-protection.d.ts +23 -0
- package/dist/plugins/get-method-csrf-protection.js +64 -0
- package/dist/plugins/head-method.d.ts +23 -0
- package/dist/plugins/head-method.js +104 -0
- package/dist/plugins/index.d.ts +29 -422
- package/dist/plugins/index.js +29 -0
- package/dist/plugins/method-override.d.ts +38 -0
- package/dist/plugins/method-override.js +50 -0
- package/dist/plugins/request-compression.d.ts +16 -0
- package/dist/plugins/request-compression.js +82 -0
- package/dist/plugins/request-headers.d.ts +22 -0
- package/dist/plugins/request-headers.js +30 -0
- package/dist/{shared/server.CgBF3Vj1.d.ts → plugins/request-limit.d.ts} +4 -8
- package/dist/plugins/request-limit.js +68 -0
- package/dist/plugins/response-compression.d.ts +59 -0
- package/dist/plugins/response-compression.js +209 -0
- package/dist/plugins/response-headers.d.ts +30 -0
- package/dist/plugins/response-headers.js +47 -0
- package/dist/plugins/rethrow.d.ts +33 -0
- package/dist/plugins/rethrow.js +59 -0
- package/dist/plugins/signal-sync.d.ts +13 -0
- package/dist/plugins/signal-sync.js +91 -0
- package/dist/plugins/timeout.d.ts +37 -0
- package/dist/plugins/timeout.js +59 -0
- package/dist/procedure-client.d.ts +19 -0
- package/dist/procedure-client.js +175 -0
- package/dist/procedure-decorated.d.ts +10 -0
- package/dist/procedure-decorated.js +44 -0
- package/dist/procedure-utils.d.ts +41 -0
- package/dist/procedure-utils.js +49 -0
- package/dist/procedure.d.ts +72 -0
- package/dist/procedure.js +24 -0
- package/dist/router-client.d.ts +23 -0
- package/dist/router-client.js +43 -0
- package/dist/router-hidden.d.ts +5 -0
- package/dist/router-hidden.js +14 -0
- package/dist/router-utils.d.ts +48 -0
- package/dist/router-utils.js +202 -0
- package/dist/{shared/server.Dz7j9BEh.d.ts → router.d.ts} +14 -15
- package/dist/router.js +1 -0
- package/package.json +84 -86
- package/dist/adapters/aws-lambda/index.d.mts +0 -51
- package/dist/adapters/aws-lambda/index.mjs +0 -39
- package/dist/adapters/crossws/index.d.mts +0 -63
- package/dist/adapters/crossws/index.mjs +0 -68
- package/dist/adapters/fastify/index.d.mts +0 -42
- package/dist/adapters/fastify/index.mjs +0 -39
- package/dist/adapters/fetch/index.d.mts +0 -47
- package/dist/adapters/fetch/index.mjs +0 -42
- package/dist/adapters/message-port/index.mjs +0 -87
- package/dist/adapters/node/index.d.mts +0 -44
- package/dist/adapters/node/index.mjs +0 -41
- package/dist/adapters/standard/index.d.mts +0 -95
- package/dist/adapters/standard/index.mjs +0 -8
- package/dist/adapters/standard-peer/index.d.mts +0 -11
- package/dist/adapters/standard-peer/index.mjs +0 -10
- package/dist/adapters/websocket/index.mjs +0 -87
- package/dist/extensions/callable.d.mts +0 -10
- package/dist/extensions/callable.mjs +0 -11
- package/dist/helpers/index.d.mts +0 -167
- package/dist/helpers/index.mjs +0 -200
- package/dist/index.d.mts +0 -476
- package/dist/index.mjs +0 -463
- package/dist/plugins/index.d.mts +0 -432
- package/dist/plugins/index.mjs +0 -965
- package/dist/shared/server.1ExWFMze.mjs +0 -69
- package/dist/shared/server.9B1jEm5a.d.mts +0 -105
- package/dist/shared/server.BB464y-6.mjs +0 -207
- package/dist/shared/server.BC5BIu02.d.mts +0 -73
- package/dist/shared/server.BSYGskId.d.ts +0 -14
- package/dist/shared/server.BvG3boBj.d.mts +0 -14
- package/dist/shared/server.CTV_mC2P.d.mts +0 -34
- package/dist/shared/server.CYbIpHbH.mjs +0 -239
- package/dist/shared/server.Chq5FpXf.mjs +0 -353
- package/dist/shared/server.DFPxP2v3.d.mts +0 -166
- package/dist/shared/server.DFPxP2v3.d.ts +0 -166
- package/dist/shared/server.DOg7ke6y.d.ts +0 -105
- package/dist/shared/server.W91HSRkE.mjs +0 -9
- package/dist/shared/server.sBQSgqK3.mjs +0 -41
package/dist/lazy.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnyMetaPlugin, Meta } from '@orpc/contract';
|
|
2
|
+
export interface LazyDefinition<T> {
|
|
3
|
+
meta: Meta;
|
|
4
|
+
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
5
|
+
loader: () => Promise<{
|
|
6
|
+
default: T;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export declare class Lazy<T> {
|
|
10
|
+
'~orpc': LazyDefinition<T>;
|
|
11
|
+
constructor(def: LazyDefinition<T>);
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the given instance satisfies the {@link Lazy} class/interface.
|
|
14
|
+
*/
|
|
15
|
+
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
16
|
+
}
|
|
17
|
+
export type Lazyable<T> = T | Lazy<T>;
|
|
18
|
+
export declare function unlazy<T extends Lazyable<any>>(maybeLazy: T): Promise<{
|
|
19
|
+
default: T extends Lazy<infer U> ? U : T;
|
|
20
|
+
}>;
|
package/dist/lazy.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getConstructor, isNonPrimitive } from '@orpc/shared';
|
|
2
|
+
export class Lazy {
|
|
3
|
+
'~orpc';
|
|
4
|
+
constructor(def) {
|
|
5
|
+
this['~orpc'] = def;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Checks if the given instance satisfies the {@link Lazy} class/interface.
|
|
9
|
+
*/
|
|
10
|
+
static [Symbol.hasInstance](instance) {
|
|
11
|
+
if (this !== Lazy) {
|
|
12
|
+
// fallback to default instanceof check if this is extended class
|
|
13
|
+
return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
14
|
+
}
|
|
15
|
+
const constructor = getConstructor(instance);
|
|
16
|
+
if (constructor === Lazy) {
|
|
17
|
+
return true;
|
|
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 });
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ErrorMap, MergedErrorMap } from '@orpc/contract';
|
|
2
|
+
import type { IntersectPick } from '@orpc/shared';
|
|
3
|
+
import type { Context, MergedContext, MergedInitialContext } from './context.ts';
|
|
4
|
+
import type { Middleware } from './middleware.ts';
|
|
5
|
+
export interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> extends Middleware<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
|
+
}
|
|
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>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { mergeErrorMap } from '@orpc/contract';
|
|
2
|
+
import { toArray } from '@orpc/shared';
|
|
3
|
+
export function decorateMiddleware(middleware) {
|
|
4
|
+
const decorated = ((...args) => middleware(...args));
|
|
5
|
+
decorated['~orpc'] = middleware['~orpc'];
|
|
6
|
+
Object.defineProperty(decorated, 'name', {
|
|
7
|
+
value: middleware.name,
|
|
8
|
+
});
|
|
9
|
+
decorated.adaptInput = (adapt) => {
|
|
10
|
+
const mapped = decorateMiddleware((opts, input, ...args) => {
|
|
11
|
+
return middleware(opts, adapt(input), ...args);
|
|
12
|
+
});
|
|
13
|
+
mapped['~orpc'] = decorated['~orpc'];
|
|
14
|
+
Object.defineProperty(mapped, 'name', {
|
|
15
|
+
value: decorated.name,
|
|
16
|
+
});
|
|
17
|
+
return mapped;
|
|
18
|
+
};
|
|
19
|
+
decorated.errors = (errors) => {
|
|
20
|
+
const newMiddleware = decorateMiddleware(decorated);
|
|
21
|
+
newMiddleware['~orpc'] = {
|
|
22
|
+
...decorated['~orpc'],
|
|
23
|
+
errorMap: mergeErrorMap(decorated['~orpc']?.errorMap, errors),
|
|
24
|
+
};
|
|
25
|
+
return newMiddleware;
|
|
26
|
+
};
|
|
27
|
+
decorated.use = (usedMiddleware) => {
|
|
28
|
+
const merged = decorateMiddleware((opts, ...args) => {
|
|
29
|
+
return middleware({
|
|
30
|
+
...opts,
|
|
31
|
+
async next(nextOpts1) {
|
|
32
|
+
const signal = nextOpts1?.signal ?? opts.signal;
|
|
33
|
+
const result = await usedMiddleware({
|
|
34
|
+
...opts,
|
|
35
|
+
context: { ...opts.context, ...nextOpts1?.context },
|
|
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: [
|
|
61
|
+
...toArray(decorated['~orpc']?.metaPlugins),
|
|
62
|
+
...toArray(usedMiddleware['~orpc']?.metaPlugins),
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
Object.defineProperty(merged, 'name', {
|
|
66
|
+
value: `${decorated.name} + ${usedMiddleware.name}`,
|
|
67
|
+
});
|
|
68
|
+
return merged;
|
|
69
|
+
};
|
|
70
|
+
return decorated;
|
|
71
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AnyMetaPlugin, ErrorMap, ORPCErrorConstructorMap } from '@orpc/contract';
|
|
2
|
+
import type { MaybeOptionalOptions, Promisable } from '@orpc/shared';
|
|
3
|
+
import type { Context } from './context.ts';
|
|
4
|
+
import type { AnyProcedure } from './procedure.ts';
|
|
5
|
+
export type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
6
|
+
output: TOutput;
|
|
7
|
+
context: TOutContext;
|
|
8
|
+
}>;
|
|
9
|
+
export type MiddlewareNextOptions<TOutContext extends Context> = (object extends TOutContext ? {
|
|
10
|
+
context?: TOutContext | undefined;
|
|
11
|
+
} : {
|
|
12
|
+
context: TOutContext;
|
|
13
|
+
}) & {
|
|
14
|
+
/** Overrides the signal for the rest of the chain. */
|
|
15
|
+
signal?: AbortSignal | undefined;
|
|
16
|
+
};
|
|
17
|
+
export interface MiddlewareNext<TOutput> {
|
|
18
|
+
<T extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<T>>): MiddlewareResult<T, TOutput>;
|
|
19
|
+
}
|
|
20
|
+
export type MiddlewareDoneOptions<TOutContext, TOutput> = (object extends TOutContext ? {
|
|
21
|
+
context?: TOutContext | undefined;
|
|
22
|
+
} : {
|
|
23
|
+
context: TOutContext;
|
|
24
|
+
}) & {
|
|
25
|
+
output: TOutput;
|
|
26
|
+
};
|
|
27
|
+
export interface MiddlewareDone<TOutput> {
|
|
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
|
+
}
|
|
33
|
+
export interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
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
|
+
}
|
|
45
|
+
export interface MiddlewareDefinition<TErrorMap extends ErrorMap> {
|
|
46
|
+
errorMap?: TErrorMap | undefined;
|
|
47
|
+
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
48
|
+
}
|
|
49
|
+
export interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> {
|
|
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
|
+
}
|
|
54
|
+
export type AnyMiddleware = Middleware<any, any, any, any, any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Promisable, Value } from '@orpc/shared';
|
|
2
|
+
import type { StandardHeaders, StandardLazyRequest, StandardResponse } from '@standard-server/core';
|
|
3
|
+
import type { StandardHandlerOptions, StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions } from '../adapters/standard/index.ts';
|
|
4
|
+
import type { Context } from '../context.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Content type for batch responses that use the length-prefixed binary framing,
|
|
7
|
+
* which they do in `streaming` mode, or when any sub-response contains binary or is a stream.
|
|
8
|
+
*
|
|
9
|
+
* Decoding is driven by the `standard-server` body hint, not this header,
|
|
10
|
+
* so it only serves to describe the payload to logs, proxies, and dev tools.
|
|
11
|
+
*/
|
|
12
|
+
export declare const BATCH_CONTENT_TYPE = "application/vnd.orpc.batch";
|
|
13
|
+
export interface BatchHandlerPluginOptions<T extends Context> {
|
|
14
|
+
/**
|
|
15
|
+
* The max size of the batch allowed. Larger batches are rejected with a `413`,
|
|
16
|
+
* so keep the client Batch Link Plugin's `maxSize` at or below it.
|
|
17
|
+
*
|
|
18
|
+
* @default DEFAULT_BATCH_MAX_SIZE (10)
|
|
19
|
+
* @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
|
|
20
|
+
*/
|
|
21
|
+
maxSize?: Value<Promisable<number>, [options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
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;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Handles batch requests sent by the client Batch Link Plugin, splitting each
|
|
75
|
+
* batch into sub-requests and sending their responses back together.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* The client Batch Link Plugin's `mode` picks how each batch responds: `buffered` (default) waits for every
|
|
79
|
+
* sub-response and carries their cookies and shared headers; `streaming` starts once the first is ready and
|
|
80
|
+
* carries only its cookies.
|
|
81
|
+
*
|
|
82
|
+
* **Note**: HTTP/2 and later already multiplex requests over a single connection, which often makes this plugin unnecessary.
|
|
83
|
+
*
|
|
84
|
+
* @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
|
|
85
|
+
*/
|
|
86
|
+
export declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
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
|
+
}
|