@orpc/server 2.0.0-beta.48 → 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 +4 -4
- 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 +16 -0
- 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 -0
- 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 -0
- 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 +7 -0
- 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/handler.d.ts +64 -0
- package/dist/adapters/message-port/handler.js +86 -0
- package/dist/adapters/message-port/index.d.ts +2 -0
- 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 +7 -0
- 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/handler.d.ts +68 -0
- package/dist/adapters/standard/handler.js +205 -0
- package/dist/adapters/standard/index.d.ts +6 -0
- 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 -0
- package/dist/adapters/standard-peer/index.js +1 -0
- package/dist/adapters/standard-peer/{utils.d.mts → utils.d.ts} +3 -3
- package/dist/adapters/standard-peer/utils.js +7 -0
- package/dist/adapters/websocket/handler.d.ts +59 -0
- package/dist/adapters/websocket/handler.js +85 -0
- package/dist/adapters/websocket/index.d.ts +2 -0
- 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.d.ts +127 -0
- package/dist/builder.js +226 -0
- package/dist/context.d.ts +6 -0
- package/dist/extensions/callable.d.ts +11 -0
- 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 -0
- 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 +61 -0
- 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/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 +39 -0
- 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/plugins/request-limit.d.ts +30 -0
- 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.mts → router-hidden.d.ts} +3 -3
- package/dist/router-hidden.js +14 -0
- package/dist/router-utils.d.ts +48 -0
- package/dist/router-utils.js +202 -0
- package/dist/router.d.ts +72 -0
- package/package.json +84 -86
- package/dist/adapters/aws-lambda/handler.d.mts +0 -25
- package/dist/adapters/aws-lambda/handler.mjs +0 -21
- package/dist/adapters/aws-lambda/index.d.mts +0 -16
- package/dist/adapters/aws-lambda/index.mjs +0 -2
- package/dist/adapters/aws-lambda/rpc-handler.d.mts +0 -18
- package/dist/adapters/aws-lambda/rpc-handler.mjs +0 -10
- package/dist/adapters/crossws/handler.d.mts +0 -41
- package/dist/adapters/crossws/handler.mjs +0 -38
- package/dist/adapters/crossws/index.d.mts +0 -2
- package/dist/adapters/crossws/index.mjs +0 -2
- package/dist/adapters/crossws/rpc-handler.d.mts +0 -15
- package/dist/adapters/crossws/rpc-handler.mjs +0 -10
- package/dist/adapters/fastify/handler.d.mts +0 -21
- package/dist/adapters/fastify/handler.mjs +0 -20
- package/dist/adapters/fastify/index.d.mts +0 -2
- package/dist/adapters/fastify/index.mjs +0 -2
- package/dist/adapters/fastify/rpc-handler.d.mts +0 -14
- package/dist/adapters/fastify/rpc-handler.mjs +0 -10
- package/dist/adapters/fetch/handler.d.mts +0 -23
- package/dist/adapters/fetch/handler.mjs +0 -22
- package/dist/adapters/fetch/index.d.mts +0 -7
- package/dist/adapters/fetch/index.mjs +0 -5
- package/dist/adapters/fetch/rpc-handler.d.mts +0 -16
- package/dist/adapters/fetch/rpc-handler.mjs +0 -10
- package/dist/adapters/message-port/handler.d.mts +0 -57
- package/dist/adapters/message-port/handler.mjs +0 -62
- package/dist/adapters/message-port/index.d.mts +0 -2
- package/dist/adapters/message-port/index.mjs +0 -2
- package/dist/adapters/message-port/rpc-handler.d.mts +0 -15
- package/dist/adapters/message-port/rpc-handler.mjs +0 -10
- package/dist/adapters/node/handler.d.mts +0 -21
- package/dist/adapters/node/handler.mjs +0 -20
- package/dist/adapters/node/index.d.mts +0 -7
- package/dist/adapters/node/index.mjs +0 -5
- package/dist/adapters/node/rpc-handler.d.mts +0 -15
- package/dist/adapters/node/rpc-handler.mjs +0 -10
- package/dist/adapters/standard/codec.d.mts +0 -16
- package/dist/adapters/standard/handler.d.mts +0 -68
- package/dist/adapters/standard/handler.mjs +0 -185
- package/dist/adapters/standard/index.d.mts +0 -6
- package/dist/adapters/standard/index.mjs +0 -5
- package/dist/adapters/standard/plugin.d.mts +0 -32
- package/dist/adapters/standard/plugin.mjs +0 -16
- package/dist/adapters/standard/rpc-handler-codec.d.mts +0 -42
- package/dist/adapters/standard/rpc-handler-codec.mjs +0 -51
- package/dist/adapters/standard/rpc-matcher.d.mts +0 -53
- package/dist/adapters/standard/rpc-matcher.mjs +0 -140
- package/dist/adapters/standard/utils.d.mts +0 -10
- package/dist/adapters/standard/utils.mjs +0 -6
- package/dist/adapters/standard-peer/index.d.mts +0 -1
- package/dist/adapters/standard-peer/index.mjs +0 -1
- package/dist/adapters/standard-peer/utils.mjs +0 -11
- package/dist/adapters/websocket/handler.d.mts +0 -55
- package/dist/adapters/websocket/handler.mjs +0 -55
- package/dist/adapters/websocket/index.d.mts +0 -2
- package/dist/adapters/websocket/index.mjs +0 -2
- package/dist/adapters/websocket/rpc-handler.d.mts +0 -15
- package/dist/adapters/websocket/rpc-handler.mjs +0 -10
- package/dist/builder-variants.d.mts +0 -267
- package/dist/builder.d.mts +0 -141
- package/dist/builder.mjs +0 -145
- package/dist/context.d.mts +0 -13
- package/dist/extensions/callable.d.mts +0 -17
- package/dist/extensions/callable.mjs +0 -7
- package/dist/helpers/base64url.d.mts +0 -31
- package/dist/helpers/base64url.mjs +0 -25
- package/dist/helpers/cookie.d.mts +0 -50
- package/dist/helpers/cookie.mjs +0 -35
- package/dist/helpers/encryption.d.mts +0 -28
- package/dist/helpers/encryption.mjs +0 -62
- package/dist/helpers/index.d.mts +0 -4
- package/dist/helpers/index.mjs +0 -4
- package/dist/helpers/signing.d.mts +0 -50
- package/dist/helpers/signing.mjs +0 -43
- package/dist/implementer-procedure.d.mts +0 -36
- package/dist/implementer-procedure.mjs +0 -38
- package/dist/implementer-router.d.mts +0 -78
- package/dist/implementer-router.mjs +0 -77
- package/dist/implementer.d.mts +0 -22
- package/dist/implementer.mjs +0 -30
- package/dist/index.d.mts +0 -57
- package/dist/index.mjs +0 -30
- package/dist/lazy.d.mts +0 -20
- package/dist/lazy.mjs +0 -22
- package/dist/middleware-decorated.d.mts +0 -27
- package/dist/middleware-decorated.mjs +0 -65
- package/dist/middleware.d.mts +0 -70
- package/dist/plugins/batch.d.mts +0 -104
- package/dist/plugins/batch.mjs +0 -373
- package/dist/plugins/cors.d.mts +0 -67
- package/dist/plugins/cors.mjs +0 -134
- package/dist/plugins/get-method-csrf-protection.d.mts +0 -23
- package/dist/plugins/get-method-csrf-protection.mjs +0 -45
- package/dist/plugins/head-method.d.mts +0 -23
- package/dist/plugins/head-method.mjs +0 -95
- package/dist/plugins/index.d.mts +0 -39
- package/dist/plugins/index.mjs +0 -23
- package/dist/plugins/method-override.d.mts +0 -38
- package/dist/plugins/method-override.mjs +0 -50
- package/dist/plugins/request-compression.d.mts +0 -16
- package/dist/plugins/request-compression.mjs +0 -67
- package/dist/plugins/request-headers.d.mts +0 -22
- package/dist/plugins/request-headers.mjs +0 -21
- package/dist/plugins/request-limit.d.mts +0 -30
- package/dist/plugins/request-limit.mjs +0 -53
- package/dist/plugins/response-compression.d.mts +0 -59
- package/dist/plugins/response-compression.mjs +0 -172
- package/dist/plugins/response-headers.d.mts +0 -30
- package/dist/plugins/response-headers.mjs +0 -34
- package/dist/plugins/rethrow.d.mts +0 -33
- package/dist/plugins/rethrow.mjs +0 -46
- package/dist/plugins/signal-sync.d.mts +0 -13
- package/dist/plugins/signal-sync.mjs +0 -84
- package/dist/plugins/timeout.d.mts +0 -37
- package/dist/plugins/timeout.mjs +0 -56
- package/dist/procedure-client.d.mts +0 -41
- package/dist/procedure-client.mjs +0 -157
- package/dist/procedure-decorated.d.mts +0 -20
- package/dist/procedure-decorated.mjs +0 -41
- package/dist/procedure-utils.d.mts +0 -52
- package/dist/procedure-utils.mjs +0 -33
- package/dist/procedure.d.mts +0 -93
- package/dist/procedure.mjs +0 -20
- package/dist/router-client.d.mts +0 -27
- package/dist/router-client.mjs +0 -35
- package/dist/router-hidden.mjs +0 -12
- package/dist/router-utils.d.mts +0 -59
- package/dist/router-utils.mjs +0 -191
- package/dist/router.d.mts +0 -61
- /package/dist/adapters/standard/{codec.mjs → codec.js} +0 -0
- /package/dist/{builder-variants.mjs → builder-variants.js} +0 -0
- /package/dist/{constants.d.mts → constants.d.ts} +0 -0
- /package/dist/{constants.mjs → constants.js} +0 -0
- /package/dist/{context.mjs → context.js} +0 -0
- /package/dist/{middleware.mjs → middleware.js} +0 -0
- /package/dist/{router.mjs → router.js} +0 -0
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { ErrorMap, InferRouterContractErrorMap, RouterContract } from "@orpc/contract";
|
|
2
|
-
import type { IntersectPick, Public } from "@orpc/shared";
|
|
3
|
-
import type { Context, MergedContext, MergedInitialContext } from "./context.mjs";
|
|
4
|
-
import type { AnyMiddleware, Middleware } from "./middleware.mjs";
|
|
5
|
-
import type { DecoratedMiddleware } from "./middleware-decorated.mjs";
|
|
6
|
-
import type { ProcedureConfig } from "./procedure.mjs";
|
|
7
|
-
import type { ContractedRouter } from "./router.mjs";
|
|
8
|
-
import type { AugmentedRouterWithMiddlewares } from "./router-utils.mjs";
|
|
9
|
-
import { ProcedureContract } from "@orpc/contract";
|
|
10
|
-
import { ProcedureImplementer } from "./implementer-procedure.mjs";
|
|
11
|
-
import { Lazy } from "./lazy.mjs";
|
|
12
|
-
export declare class SharedRouterImplementer<
|
|
13
|
-
TContract extends RouterContract,
|
|
14
|
-
TInitialContext extends Context
|
|
15
|
-
> {
|
|
16
|
-
private readonly contract;
|
|
17
|
-
private readonly config;
|
|
18
|
-
private readonly middlewares;
|
|
19
|
-
private constructor();
|
|
20
|
-
static create<
|
|
21
|
-
TContract extends RouterContract,
|
|
22
|
-
TInitialContext extends Context
|
|
23
|
-
>(contract: TContract, config: ProcedureConfig): SharedRouterImplementer<TContract, TInitialContext>;
|
|
24
|
-
static create<
|
|
25
|
-
TContract extends RouterContract,
|
|
26
|
-
TInitialContext extends Context,
|
|
27
|
-
TInjectedContext extends Context
|
|
28
|
-
>(contract: TContract, config: ProcedureConfig, middlewares: AnyMiddleware[]): SharedRouterImplementerWithMiddlewares<TContract, TInitialContext, TInjectedContext>;
|
|
29
|
-
use<
|
|
30
|
-
$OutContext extends IntersectPick<TInitialContext, $OutContext>,
|
|
31
|
-
$InContext extends Context = TInitialContext,
|
|
32
|
-
$ErrorMap extends ErrorMap = InferRouterContractErrorMap<TContract>
|
|
33
|
-
>(middleware: Middleware<$InContext | TInitialContext, $OutContext, unknown, unknown, $ErrorMap>): RouterImplementerWithMiddlewares<TContract, MergedInitialContext<TInitialContext, object, $InContext>, $OutContext>;
|
|
34
|
-
middleware<
|
|
35
|
-
$OutContext extends IntersectPick<TInitialContext, $OutContext>,
|
|
36
|
-
$Input,
|
|
37
|
-
$InContext extends Context = TInitialContext,
|
|
38
|
-
$Output = any
|
|
39
|
-
>(middleware: Middleware<$InContext | TInitialContext, $OutContext, $Input, $Output, InferRouterContractErrorMap<TContract>>): DecoratedMiddleware<MergedInitialContext<TInitialContext, object, $InContext>, $OutContext, $Input, $Output, object>;
|
|
40
|
-
router<T extends ContractedRouter<TContract, any>>(router: T): T;
|
|
41
|
-
lazy<T extends ContractedRouter<TContract, any>>(loader: () => Promise<{
|
|
42
|
-
default: T;
|
|
43
|
-
}>): Lazy<T>;
|
|
44
|
-
}
|
|
45
|
-
export interface SharedRouterImplementerWithMiddlewares<
|
|
46
|
-
TContract extends RouterContract,
|
|
47
|
-
TInitialContext extends Context,
|
|
48
|
-
TInjectedContext extends Context
|
|
49
|
-
> {
|
|
50
|
-
use<
|
|
51
|
-
$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
|
|
52
|
-
$InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
|
|
53
|
-
$ErrorMap extends ErrorMap = InferRouterContractErrorMap<TContract>
|
|
54
|
-
>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, unknown, unknown, $ErrorMap>): RouterImplementerWithMiddlewares<TContract, MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>>;
|
|
55
|
-
middleware<
|
|
56
|
-
$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
|
|
57
|
-
$Input,
|
|
58
|
-
$InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
|
|
59
|
-
$Output = any
|
|
60
|
-
>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, $Input, $Output, InferRouterContractErrorMap<TContract>>): DecoratedMiddleware<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, $Input, $Output, object>;
|
|
61
|
-
router<T extends ContractedRouter<TContract, MergedContext<TInitialContext, TInjectedContext>>>(router: T): AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, object>;
|
|
62
|
-
lazy<T extends ContractedRouter<TContract, any>>(loader: () => Promise<{
|
|
63
|
-
default: T;
|
|
64
|
-
}>): Lazy<AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, object>>;
|
|
65
|
-
}
|
|
66
|
-
export type RouterImplementer<
|
|
67
|
-
TContract extends RouterContract,
|
|
68
|
-
TInitialContext extends Context
|
|
69
|
-
> = TContract extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? ProcedureImplementer<TInitialContext, object, $InputSchema, $OutputSchema, $ErrorMap> : Public<SharedRouterImplementer<TContract, TInitialContext>> & { [K in keyof TContract]: TContract[K] extends RouterContract ? RouterImplementer<TContract[K], TInitialContext> : never };
|
|
70
|
-
export type RouterImplementerWithMiddlewares<
|
|
71
|
-
TContract extends RouterContract,
|
|
72
|
-
TInitialContext extends Context,
|
|
73
|
-
TInjectedContext extends Context
|
|
74
|
-
> = TContract extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? ProcedureImplementer<TInitialContext, TInjectedContext, $InputSchema, $OutputSchema, $ErrorMap> : SharedRouterImplementerWithMiddlewares<TContract, TInitialContext, TInjectedContext> & { [K in keyof TContract]: TContract[K] extends RouterContract ? RouterImplementerWithMiddlewares<TContract[K], TInitialContext, TInjectedContext> : never };
|
|
75
|
-
export declare function createRouterImplementer<
|
|
76
|
-
TContract extends RouterContract,
|
|
77
|
-
TInitialContext extends Context
|
|
78
|
-
>(contract: TContract, config: ProcedureConfig): RouterImplementer<TContract, TInitialContext>;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { ProcedureContract } from "@orpc/contract";
|
|
2
|
-
import { bindMethods } from "@orpc/shared";
|
|
3
|
-
import { ProcedureImplementer } from "./implementer-procedure.mjs";
|
|
4
|
-
import { Lazy } from "./lazy.mjs";
|
|
5
|
-
import { decorateMiddleware } from "./middleware-decorated.mjs";
|
|
6
|
-
import { withHiddenRouterContract } from "./router-hidden.mjs";
|
|
7
|
-
import { augmentImplementedRouter } from "./router-utils.mjs";
|
|
8
|
-
export class SharedRouterImplementer {
|
|
9
|
-
contract;
|
|
10
|
-
config;
|
|
11
|
-
middlewares;
|
|
12
|
-
constructor(contract, config, middlewares) {
|
|
13
|
-
this.contract = contract;
|
|
14
|
-
this.config = config;
|
|
15
|
-
this.middlewares = middlewares;
|
|
16
|
-
}
|
|
17
|
-
static create(contract, config, middlewares = []) {
|
|
18
|
-
return new SharedRouterImplementer(contract, config, middlewares);
|
|
19
|
-
}
|
|
20
|
-
use(middleware) {
|
|
21
|
-
return createRouterImplementerInternal(this.contract, this.config, [...this.middlewares, middleware]);
|
|
22
|
-
}
|
|
23
|
-
middleware(middleware) {
|
|
24
|
-
const allMiddlewares = [...this.middlewares, middleware];
|
|
25
|
-
let current = decorateMiddleware(allMiddlewares.shift());
|
|
26
|
-
for (const mid of allMiddlewares) {
|
|
27
|
-
current = current.use(mid);
|
|
28
|
-
}
|
|
29
|
-
return current;
|
|
30
|
-
}
|
|
31
|
-
router(router) {
|
|
32
|
-
if (this.middlewares.length) {
|
|
33
|
-
router = augmentImplementedRouter(router, {
|
|
34
|
-
...this.config,
|
|
35
|
-
middlewares: this.middlewares
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return withHiddenRouterContract(router, this.contract);
|
|
39
|
-
}
|
|
40
|
-
lazy(loader) {
|
|
41
|
-
return new Lazy({
|
|
42
|
-
loader: async () => {
|
|
43
|
-
const { default: router } = await loader();
|
|
44
|
-
return { default: this.router(router) };
|
|
45
|
-
},
|
|
46
|
-
meta: {}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export function createRouterImplementer(contract, config) {
|
|
51
|
-
return createRouterImplementerInternal(contract, config, []);
|
|
52
|
-
}
|
|
53
|
-
function createRouterImplementerInternal(contract, config, middlewares) {
|
|
54
|
-
if (contract instanceof ProcedureContract) {
|
|
55
|
-
return new ProcedureImplementer({
|
|
56
|
-
...config,
|
|
57
|
-
...contract["~orpc"],
|
|
58
|
-
orderedMiddlewares: middlewares.map((middleware) => ({ middleware }))
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
const implementer = {};
|
|
62
|
-
for (const [key, child] of Object.entries(contract)) {
|
|
63
|
-
implementer[key] = createRouterImplementerInternal(child, config, middlewares);
|
|
64
|
-
}
|
|
65
|
-
const shared = bindMethods(SharedRouterImplementer.create(contract, config, middlewares));
|
|
66
|
-
for (const [key, method] of Object.entries(shared)) {
|
|
67
|
-
if (key in implementer) {
|
|
68
|
-
const child = implementer[key];
|
|
69
|
-
implementer[key] = new Proxy(method, { get(_, p) {
|
|
70
|
-
return Reflect.get(child, p);
|
|
71
|
-
} });
|
|
72
|
-
} else {
|
|
73
|
-
implementer[key] = method;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return implementer;
|
|
77
|
-
}
|
package/dist/implementer.d.mts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { RouterContract } from "@orpc/contract";
|
|
2
|
-
import type { DefaultInitialContext } from "./builder.mjs";
|
|
3
|
-
import type { Context } from "./context.mjs";
|
|
4
|
-
import type { RouterImplementer } from "./implementer-router.mjs";
|
|
5
|
-
import type { ProcedureConfig } from "./procedure.mjs";
|
|
6
|
-
export type Implementer<
|
|
7
|
-
TContract extends RouterContract,
|
|
8
|
-
TInitialContext extends Context
|
|
9
|
-
> = {
|
|
10
|
-
$context<T extends Context = DefaultInitialContext>(): Implementer<TContract, T & object>;
|
|
11
|
-
$config(config: ProcedureConfig): Implementer<TContract, TInitialContext>;
|
|
12
|
-
} & RouterImplementer<TContract, TInitialContext>;
|
|
13
|
-
/**
|
|
14
|
-
* Turns a contract into an implementer, used to implement the contract's
|
|
15
|
-
* procedures, routers, and middleware with full type safety.
|
|
16
|
-
*
|
|
17
|
-
* @see {@link https://orpc.dev/docs/contract/implementation#implementer | Contract Implementation - Implementer}
|
|
18
|
-
*/
|
|
19
|
-
export declare function implement<
|
|
20
|
-
TContract extends RouterContract,
|
|
21
|
-
TInitialContext extends Context = DefaultInitialContext
|
|
22
|
-
>(contract: TContract, config?: ProcedureConfig): Implementer<TContract, TInitialContext & object>;
|
package/dist/implementer.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { isTypescriptObject } from "@orpc/shared";
|
|
2
|
-
import { createRouterImplementer } from "./implementer-router.mjs";
|
|
3
|
-
|
|
4
|
-
export function implement(contract, config = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const routerImplementer = createRouterImplementer(contract, config);
|
|
8
|
-
const implementer = new Proxy(routerImplementer, { get(_, p) {
|
|
9
|
-
let method;
|
|
10
|
-
if (p === "$context") {
|
|
11
|
-
method = () => implementer;
|
|
12
|
-
} else if (p === "$config") {
|
|
13
|
-
method = (incoming) => implement(contract, {
|
|
14
|
-
...config,
|
|
15
|
-
...incoming
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const value = Reflect.get(routerImplementer, p);
|
|
19
|
-
if (method) {
|
|
20
|
-
if (!isTypescriptObject(value)) {
|
|
21
|
-
return method;
|
|
22
|
-
}
|
|
23
|
-
return new Proxy(method, { get(_, p) {
|
|
24
|
-
return Reflect.get(value, p);
|
|
25
|
-
} });
|
|
26
|
-
}
|
|
27
|
-
return value;
|
|
28
|
-
} });
|
|
29
|
-
return implementer;
|
|
30
|
-
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export * from "./builder.mjs";
|
|
2
|
-
export * from "./builder-variants.mjs";
|
|
3
|
-
export * from "./constants.mjs";
|
|
4
|
-
export * from "./context.mjs";
|
|
5
|
-
export * from "./implementer.mjs";
|
|
6
|
-
export * from "./implementer-procedure.mjs";
|
|
7
|
-
export { SharedRouterImplementer } from "./implementer-router.mjs";
|
|
8
|
-
export type { RouterImplementer, RouterImplementerWithMiddlewares, SharedRouterImplementerWithMiddlewares } from "./implementer-router.mjs";
|
|
9
|
-
export * from "./lazy.mjs";
|
|
10
|
-
export * from "./middleware.mjs";
|
|
11
|
-
export type { DecoratedMiddleware } from "./middleware-decorated.mjs";
|
|
12
|
-
export * from "./procedure.mjs";
|
|
13
|
-
export * from "./procedure-client.mjs";
|
|
14
|
-
export * from "./procedure-decorated.mjs";
|
|
15
|
-
export { call } from "./procedure-utils.mjs";
|
|
16
|
-
export type { CallOptions, CallRest } from "./procedure-utils.mjs";
|
|
17
|
-
export * from "./router.mjs";
|
|
18
|
-
export type {
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Use `InferRouterFinalContexts` instead.
|
|
21
|
-
*/
|
|
22
|
-
InferRouterFinalContexts as InferRouterCurrentContexts } from "./router.mjs";
|
|
23
|
-
export * from "./router-client.mjs";
|
|
24
|
-
export { getRouter, resolveContractProcedure, unlazyRouter, walkProcedureContractsAsync, walkProcedureContractsSync } from "./router-utils.mjs";
|
|
25
|
-
export type { AugmentedRouter, AugmentedRouterWithMiddlewares, UnlaziedRouter, WalkProcedureContractsLazyResult } from "./router-utils.mjs";
|
|
26
|
-
export type { AnyORPCError, AnyORPCErrorJSON, Client, ClientContext, ClientOptions, ClientRest, FriendlyClientOptions, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, RPCJsonSerialization, RPCJsonSerializationMeta, RPCJsonSerializerHandler, RPCJsonSerializerOptions, RPCSerializerOptions, RPCSerializerSerializeOptions, SafeResult } from "@orpc/client";
|
|
27
|
-
export { COMMON_ERROR_STATUS_MAP, isDefinedError, ORPCError, RPCJsonSerializer, RPCSerializer, safe, toORPCError } from "@orpc/client";
|
|
28
|
-
export type { AnyMetaPlugin, AnySchema, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InitialInputSchema, InitialOutputSchema, MergedErrorMap, MergedSchema, Meta, MetaPlugin, MetaPluginDefinition, ORPCErrorConstructorMap, ORPCErrorConstructorMapItem, ORPCErrorConstructorMapItemOptions, ORPCErrorFactory, ORPCErrorFactoryOptions, ORPCErrorFromErrorMap, ProcedureContract, ProcedureContractDefinition, RouterContract, Schema } from "@orpc/contract";
|
|
29
|
-
export { asyncIteratorObject, defineMeta, error, eventIterator, type, ValidationError } from "@orpc/contract";
|
|
30
|
-
export type { AsyncCleanupFn, AsyncIteratorClassNextFn, DistributiveOmit, IntersectPick, MaybeOptionalOptions, PromiseWithError, Public, Registry, ThrowableError } from "@orpc/shared";
|
|
31
|
-
export { AsyncIteratorClass, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream,
|
|
32
|
-
/**
|
|
33
|
-
* @deprecated Use `asyncIteratorToStream` instead.
|
|
34
|
-
*/
|
|
35
|
-
asyncIteratorToStream as eventIteratorToStream,
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated Use `asyncIteratorToUnproxiedDataStream` instead.
|
|
38
|
-
*/
|
|
39
|
-
asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject,
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated Use `streamToAsyncIteratorObject` instead.
|
|
42
|
-
*/
|
|
43
|
-
streamToAsyncIteratorObject as streamToEventIterator } from "@orpc/shared";
|
|
44
|
-
export type { EventMeta, StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from "@standard-server/core";
|
|
45
|
-
export { ErrorEvent,
|
|
46
|
-
/**
|
|
47
|
-
* Retrieves metadata attached to a single iterator event value.
|
|
48
|
-
*
|
|
49
|
-
* @see {@link https://orpc.dev/docs/helpers/publisher | Publisher Helpers}
|
|
50
|
-
*/
|
|
51
|
-
getEventMeta, unwrapEvent,
|
|
52
|
-
/**
|
|
53
|
-
* Returns a new iterator event value with attached, validated metadata.
|
|
54
|
-
*
|
|
55
|
-
* @see {@link https://orpc.dev/docs/async-iterator-object#last-event-id--event-metadata | AsyncIteratorObject (SSE) - Last Event ID & Event Metadata}
|
|
56
|
-
*/
|
|
57
|
-
withEventMeta } from "@standard-server/core";
|
package/dist/index.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export * from "./builder.mjs";
|
|
2
|
-
export * from "./builder-variants.mjs";
|
|
3
|
-
export * from "./constants.mjs";
|
|
4
|
-
export * from "./context.mjs";
|
|
5
|
-
export * from "./implementer.mjs";
|
|
6
|
-
export * from "./implementer-procedure.mjs";
|
|
7
|
-
export { SharedRouterImplementer } from "./implementer-router.mjs";
|
|
8
|
-
export * from "./lazy.mjs";
|
|
9
|
-
export * from "./middleware.mjs";
|
|
10
|
-
export * from "./procedure.mjs";
|
|
11
|
-
export * from "./procedure-client.mjs";
|
|
12
|
-
export * from "./procedure-decorated.mjs";
|
|
13
|
-
export { call } from "./procedure-utils.mjs";
|
|
14
|
-
export * from "./router.mjs";
|
|
15
|
-
export * from "./router-client.mjs";
|
|
16
|
-
export { getRouter, resolveContractProcedure, unlazyRouter, walkProcedureContractsAsync, walkProcedureContractsSync } from "./router-utils.mjs";
|
|
17
|
-
export { COMMON_ERROR_STATUS_MAP, isDefinedError, ORPCError, RPCJsonSerializer, RPCSerializer, safe, toORPCError } from "@orpc/client";
|
|
18
|
-
export { asyncIteratorObject, defineMeta, error, eventIterator, type, ValidationError } from "@orpc/contract";
|
|
19
|
-
export { AsyncIteratorClass, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream,
|
|
20
|
-
|
|
21
|
-
asyncIteratorToStream as eventIteratorToStream,
|
|
22
|
-
|
|
23
|
-
asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject,
|
|
24
|
-
|
|
25
|
-
streamToAsyncIteratorObject as streamToEventIterator } from "@orpc/shared";
|
|
26
|
-
export { ErrorEvent,
|
|
27
|
-
|
|
28
|
-
getEventMeta, unwrapEvent,
|
|
29
|
-
|
|
30
|
-
withEventMeta } from "@standard-server/core";
|
package/dist/lazy.d.mts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getConstructor, isTypescriptObject } from "@orpc/shared";
|
|
2
|
-
export class Lazy {
|
|
3
|
-
"~orpc";
|
|
4
|
-
constructor(def) {
|
|
5
|
-
this["~orpc"] = def;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
static [Symbol.hasInstance](instance) {
|
|
9
|
-
if (this !== Lazy) {
|
|
10
|
-
|
|
11
|
-
return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
12
|
-
}
|
|
13
|
-
const constructor = getConstructor(instance);
|
|
14
|
-
if (constructor === Lazy) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
return isTypescriptObject(instance) && isTypescriptObject(instance["~orpc"]) && isTypescriptObject(instance["~orpc"].meta) && (instance["~orpc"].metaPlugins === undefined || Array.isArray(instance["~orpc"].metaPlugins)) && typeof instance["~orpc"].loader === "function";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function unlazy(maybeLazy) {
|
|
21
|
-
return maybeLazy instanceof Lazy ? maybeLazy["~orpc"].loader() : Promise.resolve({ default: maybeLazy });
|
|
22
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ErrorMap, MergedErrorMap } from "@orpc/contract";
|
|
2
|
-
import type { IntersectPick } from "@orpc/shared";
|
|
3
|
-
import type { Context, MergedContext, MergedInitialContext } from "./context.mjs";
|
|
4
|
-
import type { Middleware } from "./middleware.mjs";
|
|
5
|
-
export interface DecoratedMiddleware<
|
|
6
|
-
TInContext extends Context,
|
|
7
|
-
TOutContext extends Context,
|
|
8
|
-
TInput,
|
|
9
|
-
TOutput,
|
|
10
|
-
TErrorMap extends ErrorMap
|
|
11
|
-
> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorMap> {
|
|
12
|
-
adaptInput<T>(adapt: (input: T) => TInput): DecoratedMiddleware<TInContext, TOutContext, T, TOutput, TErrorMap>;
|
|
13
|
-
errors<T extends ErrorMap>(errors: T): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, MergedErrorMap<TErrorMap, T>>;
|
|
14
|
-
use<
|
|
15
|
-
$OutContext extends IntersectPick<MergedContext<TInContext, TOutContext>, $OutContext>,
|
|
16
|
-
$Input extends TInput,
|
|
17
|
-
$InContext extends Context = MergedContext<TInContext, TOutContext>,
|
|
18
|
-
$ErrorMap extends ErrorMap = TErrorMap
|
|
19
|
-
>(middleware: Middleware<$InContext | MergedContext<TInContext, TOutContext>, $OutContext, $Input, TOutput, $ErrorMap>): DecoratedMiddleware<MergedInitialContext<TInContext, TOutContext, $InContext>, MergedContext<TOutContext, $OutContext>, $Input, TOutput, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
20
|
-
}
|
|
21
|
-
export declare function decorateMiddleware<
|
|
22
|
-
TInContext extends Context,
|
|
23
|
-
TOutContext extends Context,
|
|
24
|
-
TInput,
|
|
25
|
-
TOutput,
|
|
26
|
-
TErrorMap extends ErrorMap
|
|
27
|
-
>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorMap>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorMap>;
|
|
@@ -1,65 +0,0 @@
|
|
|
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", { value: middleware.name });
|
|
7
|
-
decorated.adaptInput = (adapt) => {
|
|
8
|
-
const mapped = decorateMiddleware((opts, input, ...args) => {
|
|
9
|
-
return middleware(opts, adapt(input), ...args);
|
|
10
|
-
});
|
|
11
|
-
mapped["~orpc"] = decorated["~orpc"];
|
|
12
|
-
Object.defineProperty(mapped, "name", { value: decorated.name });
|
|
13
|
-
return mapped;
|
|
14
|
-
};
|
|
15
|
-
decorated.errors = (errors) => {
|
|
16
|
-
const newMiddleware = decorateMiddleware(decorated);
|
|
17
|
-
newMiddleware["~orpc"] = {
|
|
18
|
-
...decorated["~orpc"],
|
|
19
|
-
errorMap: mergeErrorMap(decorated["~orpc"]?.errorMap, errors)
|
|
20
|
-
};
|
|
21
|
-
return newMiddleware;
|
|
22
|
-
};
|
|
23
|
-
decorated.use = (usedMiddleware) => {
|
|
24
|
-
const merged = decorateMiddleware((opts, ...args) => {
|
|
25
|
-
return middleware({
|
|
26
|
-
...opts,
|
|
27
|
-
async next(nextOpts1) {
|
|
28
|
-
const signal = nextOpts1?.signal ?? opts.signal;
|
|
29
|
-
const result = await usedMiddleware({
|
|
30
|
-
...opts,
|
|
31
|
-
context: {
|
|
32
|
-
...opts.context,
|
|
33
|
-
...nextOpts1?.context
|
|
34
|
-
},
|
|
35
|
-
signal,
|
|
36
|
-
next(nextOpts2, ...args) {
|
|
37
|
-
return opts.next({
|
|
38
|
-
context: {
|
|
39
|
-
...nextOpts1?.context,
|
|
40
|
-
...nextOpts2?.context
|
|
41
|
-
},
|
|
42
|
-
signal: nextOpts2?.signal ?? signal
|
|
43
|
-
}, ...args);
|
|
44
|
-
}
|
|
45
|
-
}, ...args);
|
|
46
|
-
return {
|
|
47
|
-
...result,
|
|
48
|
-
context: {
|
|
49
|
-
...nextOpts1?.context,
|
|
50
|
-
...result.context
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
}, ...args);
|
|
55
|
-
});
|
|
56
|
-
merged["~orpc"] = {
|
|
57
|
-
...decorated["~orpc"],
|
|
58
|
-
errorMap: mergeErrorMap(usedMiddleware["~orpc"]?.errorMap, decorated["~orpc"]?.errorMap),
|
|
59
|
-
metaPlugins: [...toArray(decorated["~orpc"]?.metaPlugins), ...toArray(usedMiddleware["~orpc"]?.metaPlugins)]
|
|
60
|
-
};
|
|
61
|
-
Object.defineProperty(merged, "name", { value: `${decorated.name} + ${usedMiddleware.name}` });
|
|
62
|
-
return merged;
|
|
63
|
-
};
|
|
64
|
-
return decorated;
|
|
65
|
-
}
|
package/dist/middleware.d.mts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { AnyMetaPlugin, ErrorMap, ORPCErrorConstructorMap } from "@orpc/contract";
|
|
2
|
-
import type { MaybeOptionalOptions, Promisable } from "@orpc/shared";
|
|
3
|
-
import type { Context } from "./context.mjs";
|
|
4
|
-
import type { AnyProcedure } from "./procedure.mjs";
|
|
5
|
-
export type MiddlewareResult<
|
|
6
|
-
TOutContext extends Context,
|
|
7
|
-
TOutput
|
|
8
|
-
> = Promisable<{
|
|
9
|
-
output: TOutput;
|
|
10
|
-
context: TOutContext;
|
|
11
|
-
}>;
|
|
12
|
-
export type MiddlewareNextOptions<TOutContext extends Context> = (object extends TOutContext ? {
|
|
13
|
-
context?: TOutContext | undefined;
|
|
14
|
-
} : {
|
|
15
|
-
context: TOutContext;
|
|
16
|
-
}) & {
|
|
17
|
-
/** Overrides the signal for the rest of the chain. */
|
|
18
|
-
signal?: AbortSignal | undefined;
|
|
19
|
-
};
|
|
20
|
-
export interface MiddlewareNext<TOutput> {
|
|
21
|
-
<T extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<T>>): MiddlewareResult<T, TOutput>;
|
|
22
|
-
}
|
|
23
|
-
export type MiddlewareDoneOptions<
|
|
24
|
-
TOutContext,
|
|
25
|
-
TOutput
|
|
26
|
-
> = (object extends TOutContext ? {
|
|
27
|
-
context?: TOutContext | undefined;
|
|
28
|
-
} : {
|
|
29
|
-
context: TOutContext;
|
|
30
|
-
}) & {
|
|
31
|
-
output: TOutput;
|
|
32
|
-
};
|
|
33
|
-
export interface MiddlewareDone<TOutput> {
|
|
34
|
-
/**
|
|
35
|
-
* Create a successful result and terminate the middleware chain early.
|
|
36
|
-
*/
|
|
37
|
-
<TOutContext extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareDoneOptions<TOutContext, TOutput>>): MiddlewareResult<TOutContext, TOutput>;
|
|
38
|
-
}
|
|
39
|
-
export interface MiddlewareOptions<
|
|
40
|
-
TInContext extends Context,
|
|
41
|
-
TOutput,
|
|
42
|
-
TErrorConstructorMap extends ORPCErrorConstructorMap<any>
|
|
43
|
-
> {
|
|
44
|
-
context: TInContext;
|
|
45
|
-
path: string[];
|
|
46
|
-
procedure: AnyProcedure;
|
|
47
|
-
signal?: AbortSignal | undefined;
|
|
48
|
-
lastEventId: string | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* Invoke to continue the middleware chain.
|
|
51
|
-
*/
|
|
52
|
-
next: MiddlewareNext<TOutput>;
|
|
53
|
-
errors: TErrorConstructorMap;
|
|
54
|
-
}
|
|
55
|
-
export interface MiddlewareDefinition<TErrorMap extends ErrorMap> {
|
|
56
|
-
errorMap?: TErrorMap | undefined;
|
|
57
|
-
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
58
|
-
}
|
|
59
|
-
export interface Middleware<
|
|
60
|
-
TInContext extends Context,
|
|
61
|
-
TOutContext extends Context,
|
|
62
|
-
TInput,
|
|
63
|
-
TOutput,
|
|
64
|
-
TErrorMap extends ErrorMap
|
|
65
|
-
> {
|
|
66
|
-
/** this property should be optional to support inline middleware */
|
|
67
|
-
"~orpc"?: MiddlewareDefinition<TErrorMap> | undefined;
|
|
68
|
-
(opts: MiddlewareOptions<TInContext, TOutput, ORPCErrorConstructorMap<TErrorMap>>, input: TInput, done: MiddlewareDone<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
69
|
-
}
|
|
70
|
-
export type AnyMiddleware = Middleware<any, any, any, any, any>;
|
package/dist/plugins/batch.d.mts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
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.mjs";
|
|
4
|
-
import type { Context } from "../context.mjs";
|
|
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>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* Keep-alive settings for batch responses that stream.
|
|
54
|
-
*
|
|
55
|
-
* When enabled, a zero-length length-prefixed frame is sent periodically while the
|
|
56
|
-
* stream is idle (no message sent for `interval` ms). Clients ignore these frames.
|
|
57
|
-
*
|
|
58
|
-
* @default { enabled: true, interval: 15000 }
|
|
59
|
-
*/
|
|
60
|
-
keepAlive?: {
|
|
61
|
-
/**
|
|
62
|
-
* If true, a keep-alive frame is sent periodically while the stream is idle.
|
|
63
|
-
*
|
|
64
|
-
* @default true
|
|
65
|
-
*/
|
|
66
|
-
enabled: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Interval (in milliseconds) between keep-alive frames after the last message.
|
|
69
|
-
*
|
|
70
|
-
* @default 15000
|
|
71
|
-
*/
|
|
72
|
-
interval?: number | undefined;
|
|
73
|
-
} | undefined;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Handles batch requests sent by the client Batch Link Plugin, splitting each
|
|
77
|
-
* batch into sub-requests and sending their responses back together.
|
|
78
|
-
*
|
|
79
|
-
* @remarks
|
|
80
|
-
* The client Batch Link Plugin's `mode` picks how each batch responds: `buffered` (default) waits for every
|
|
81
|
-
* sub-response and carries their cookies and shared headers; `streaming` starts once the first is ready and
|
|
82
|
-
* carries only its cookies.
|
|
83
|
-
*
|
|
84
|
-
* **Note**: HTTP/2 and later already multiplex requests over a single connection, which often makes this plugin unnecessary.
|
|
85
|
-
*
|
|
86
|
-
* @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
|
|
87
|
-
*/
|
|
88
|
-
export declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
89
|
-
name: string;
|
|
90
|
-
/**
|
|
91
|
-
* Run batch interceptors inside the tracing interceptors
|
|
92
|
-
* so each subrequest gets its own span instead of sharing one batch-level span.
|
|
93
|
-
*/
|
|
94
|
-
after: string[];
|
|
95
|
-
private readonly maxSize;
|
|
96
|
-
private readonly mapSubrequest;
|
|
97
|
-
private readonly mapSubresponse;
|
|
98
|
-
private readonly successStatus;
|
|
99
|
-
private readonly headers;
|
|
100
|
-
private readonly keepAliveEnabled;
|
|
101
|
-
private readonly keepAliveInterval;
|
|
102
|
-
constructor(options?: BatchHandlerPluginOptions<T>);
|
|
103
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
104
|
-
}
|