@orpc/server 0.0.0-next.aac73c2 → 0.0.0-next.ac2c329
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/fetch/index.d.mts +14 -10
- package/dist/adapters/fetch/index.d.ts +14 -10
- package/dist/adapters/fetch/index.mjs +104 -8
- package/dist/adapters/node/index.d.mts +14 -10
- package/dist/adapters/node/index.d.ts +14 -10
- package/dist/adapters/node/index.mjs +17 -12
- package/dist/adapters/standard/index.d.mts +4 -4
- package/dist/adapters/standard/index.d.ts +4 -4
- package/dist/adapters/standard/index.mjs +6 -4
- package/dist/index.d.mts +27 -27
- package/dist/index.d.ts +27 -27
- package/dist/index.mjs +7 -7
- package/dist/plugins/index.d.mts +100 -6
- package/dist/plugins/index.d.ts +100 -6
- package/dist/plugins/index.mjs +147 -2
- package/dist/shared/server.B5yVxwZh.d.mts +17 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.By38lRwX.d.ts +17 -0
- package/dist/shared/{server.CjWkNG6l.mjs → server.C37gDhSZ.mjs} +18 -24
- package/dist/shared/{server.DNoBYd3E.d.ts → server.ClO23hLW.d.mts} +15 -8
- package/dist/shared/{server.CBh2jYIX.d.mts → server.Cqam9L0P.d.mts} +2 -2
- package/dist/shared/{server.B0kTII1X.d.ts → server.CuXY46Yy.d.ts} +2 -2
- package/dist/shared/{server.D9QduY95.mjs → server.DFuJLDuo.mjs} +43 -14
- package/dist/shared/{server.CYBq7eu_.d.mts → server.DQJX4Gnf.d.mts} +2 -2
- package/dist/shared/{server.CYBq7eu_.d.ts → server.DQJX4Gnf.d.ts} +2 -2
- package/dist/shared/{server.DHBkTokD.d.mts → server.DsVSuKTu.d.ts} +15 -8
- package/package.json +7 -21
- package/dist/adapters/hono/index.d.mts +0 -22
- package/dist/adapters/hono/index.d.ts +0 -22
- package/dist/adapters/hono/index.mjs +0 -32
- package/dist/adapters/next/index.d.mts +0 -29
- package/dist/adapters/next/index.d.ts +0 -29
- package/dist/adapters/next/index.mjs +0 -29
- package/dist/shared/server.DatI0acO.d.mts +0 -8
- package/dist/shared/server.Et1O6Bm7.mjs +0 -98
- package/dist/shared/server.uEHRR3Pg.d.ts +0 -8
package/dist/index.d.ts
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, ClientPromiseResult } from '@orpc/client';
|
2
|
-
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
2
|
+
export { ClientContext, HTTPMethod, HTTPPath, ORPCError, isDefinedError, safe } from '@orpc/client';
|
3
3
|
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta } from '@orpc/contract';
|
4
|
-
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
5
|
-
import {
|
6
|
-
export {
|
7
|
-
import {
|
8
|
-
export {
|
4
|
+
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
5
|
+
import { ThrowableError, IntersectPick, MaybeOptionalOptions } from '@orpc/shared';
|
6
|
+
export { IntersectPick, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
|
+
import { C as Context, P as Procedure, M as Middleware, O as ORPCErrorConstructorMap, a as MergedInitialContext, b as MergedCurrentContext, c as MapInputMiddleware, d as CreateProcedureClientOptions, e as ProcedureClient, A as AnyMiddleware, L as Lazyable, f as AnyRouter, g as Lazy, h as AnyProcedure, i as ProcedureHandler, R as Router, I as InferRouterInitialContext } from './shared/server.DQJX4Gnf.js';
|
8
|
+
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, n as LAZY_SYMBOL, o as LazyMeta, w as MiddlewareNextFn, t as MiddlewareNextFnOptions, y as MiddlewareOptions, x as MiddlewareOutputFn, s as MiddlewareResult, k as ORPCErrorConstructorMapItem, j as ORPCErrorConstructorMapItemOptions, F as ProcedureClientInterceptorOptions, D as ProcedureDef, B as ProcedureHandlerOptions, l as createORPCErrorConstructorMap, G as createProcedureClient, r as getLazyMeta, q as isLazy, E as isProcedure, p as lazy, m as mergeCurrentContext, z as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.DQJX4Gnf.js';
|
9
9
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
10
10
|
|
11
|
-
type ActionableError<T
|
11
|
+
type ActionableError<T> = T extends ORPCError<infer U, infer V> ? ORPCErrorJSON<U, V> & {
|
12
12
|
defined: true;
|
13
13
|
} : ORPCErrorJSON<string, unknown> & {
|
14
14
|
defined: false;
|
15
15
|
};
|
16
16
|
type UnactionableError<T> = T extends {
|
17
17
|
defined: true;
|
18
|
-
} & ORPCErrorJSON<infer U, infer V> ? ORPCError<U, V> :
|
18
|
+
} & ORPCErrorJSON<infer U, infer V> ? ORPCError<U, V> : ThrowableError;
|
19
19
|
type ActionableClientRest<TInput> = [input: TInput] | (undefined extends TInput ? [input?: TInput] : [input: TInput]);
|
20
20
|
type ActionableClientResult<TOutput, TError extends ORPCErrorJSON<any, any>> = [error: null, data: TOutput] | [error: TError, data: undefined];
|
21
21
|
interface ActionableClient<TInput, TOutput, TError extends ORPCErrorJSON<any, any>> {
|
22
22
|
(...rest: ActionableClientRest<TInput>): Promise<ActionableClientResult<TOutput, TError>>;
|
23
23
|
}
|
24
24
|
type ProcedureActionableClient<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = ActionableClient<InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ActionableError<ErrorFromErrorMap<TErrorMap>>>;
|
25
|
-
declare function createActionableClient<TInput, TOutput, TError
|
25
|
+
declare function createActionableClient<TInput, TOutput, TError>(client: Client<Record<never, never>, TInput, TOutput, TError>): ActionableClient<TInput, TOutput, ActionableError<TError>>;
|
26
26
|
|
27
27
|
declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
28
28
|
errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
@@ -76,7 +76,7 @@ declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedR
|
|
76
76
|
interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
77
77
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
78
78
|
'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
79
|
-
'use'<UOutContext extends
|
79
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
80
80
|
'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
81
81
|
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
82
82
|
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -92,7 +92,7 @@ interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContex
|
|
92
92
|
interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
93
93
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
94
94
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
95
|
-
'use'<UOutContext extends
|
95
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
96
96
|
'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
97
97
|
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
98
98
|
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -102,8 +102,8 @@ interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext exte
|
|
102
102
|
interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
103
103
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
104
104
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
105
|
-
'use'<UOutContext extends
|
106
|
-
'use'<UOutContext extends
|
105
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
106
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
107
107
|
'meta'(meta: TMeta): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
108
108
|
'route'(route: Route): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
109
109
|
'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
@@ -112,7 +112,7 @@ interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentCon
|
|
112
112
|
interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
113
113
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
114
114
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
115
|
-
'use'<UOutContext extends
|
115
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
116
116
|
'meta'(meta: TMeta): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
117
117
|
'route'(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
118
118
|
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -121,8 +121,8 @@ interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentCo
|
|
121
121
|
interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
122
122
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
123
123
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
124
|
-
'use'<UOutContext extends
|
125
|
-
'use'<UOutContext extends
|
124
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
125
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
126
126
|
'meta'(meta: TMeta): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
127
127
|
'route'(route: Route): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
128
128
|
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -130,7 +130,7 @@ interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurr
|
|
130
130
|
interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
131
131
|
'~orpc': EnhanceRouterOptions<TErrorMap>;
|
132
132
|
'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
|
133
|
-
'use'<UOutContext extends
|
133
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): RouterBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
|
134
134
|
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
135
135
|
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
136
136
|
'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
@@ -141,8 +141,8 @@ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends
|
|
141
141
|
|
142
142
|
interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta> {
|
143
143
|
mapInput<UInput>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
144
|
-
concat<UOutContext extends
|
145
|
-
concat<UOutContext extends
|
144
|
+
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
|
145
|
+
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UMappedInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<TInput, UMappedInput>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
|
146
146
|
}
|
147
147
|
declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>;
|
148
148
|
|
@@ -177,10 +177,10 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
177
177
|
*/
|
178
178
|
$route(initialRoute: Route): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
179
179
|
$input<U extends AnySchema>(initialInputSchema?: U): Builder<TInitialContext, TCurrentContext, U, TOutputSchema, TErrorMap, TMeta>;
|
180
|
-
middleware<UOutContext extends
|
180
|
+
middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
181
181
|
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
|
182
182
|
errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
183
|
-
use<UOutContext extends
|
183
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
184
184
|
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
185
185
|
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
186
186
|
input<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -222,13 +222,13 @@ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext
|
|
222
222
|
*/
|
223
223
|
interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
224
224
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
225
|
-
'use'<UOutContext extends
|
226
|
-
'use'<UOutContext extends
|
225
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
226
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
227
227
|
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
228
228
|
}
|
229
229
|
|
230
230
|
interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
231
|
-
use<UOutContext extends
|
231
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
|
232
232
|
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
233
233
|
lazy<U extends Router<T, TInitialContext>>(loader: () => Promise<{
|
234
234
|
default: U;
|
@@ -239,9 +239,9 @@ type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TIn
|
|
239
239
|
});
|
240
240
|
|
241
241
|
interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
242
|
-
middleware<UOutContext extends
|
242
|
+
middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
243
243
|
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, InferContractRouterMeta<T>>;
|
244
|
-
use<UOutContext extends
|
244
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
|
245
245
|
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
246
246
|
lazy<U extends Router<T, TCurrentContext>>(loader: () => Promise<{
|
247
247
|
default: U;
|
@@ -283,7 +283,7 @@ declare function call<TInitialContext extends Context, TInputSchema extends AnyS
|
|
283
283
|
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
284
284
|
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
285
285
|
};
|
286
|
-
declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...
|
286
|
+
declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): RouterClient<T, TClientContext>;
|
287
287
|
|
288
288
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
289
289
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
package/dist/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
|
2
2
|
export { ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
-
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure, g as getRouter } from './shared/server.
|
4
|
-
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.
|
3
|
+
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure, g as getRouter } from './shared/server.C37gDhSZ.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.C37gDhSZ.mjs';
|
5
5
|
import { toORPCError } from '@orpc/client';
|
6
6
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
7
7
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
@@ -336,12 +336,12 @@ function implement(contract, config = {}) {
|
|
336
336
|
return impl;
|
337
337
|
}
|
338
338
|
|
339
|
-
function createRouterClient(router, ...
|
339
|
+
function createRouterClient(router, ...rest) {
|
340
340
|
if (isProcedure(router)) {
|
341
|
-
const caller = createProcedureClient(router,
|
341
|
+
const caller = createProcedureClient(router, ...rest);
|
342
342
|
return caller;
|
343
343
|
}
|
344
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router),
|
344
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), ...rest) : {};
|
345
345
|
const recursive = new Proxy(procedureCaller, {
|
346
346
|
get(target, key) {
|
347
347
|
if (typeof key !== "string") {
|
@@ -352,8 +352,8 @@ function createRouterClient(router, ...[options]) {
|
|
352
352
|
return Reflect.get(target, key);
|
353
353
|
}
|
354
354
|
return createRouterClient(next, {
|
355
|
-
...
|
356
|
-
path: [...
|
355
|
+
...rest[0],
|
356
|
+
path: [...rest[0]?.path ?? [], key]
|
357
357
|
});
|
358
358
|
}
|
359
359
|
});
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,9 +1,46 @@
|
|
1
|
-
import { b as StandardHandlerInterceptorOptions, c as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DHBkTokD.mjs';
|
2
1
|
import { Value } from '@orpc/shared';
|
3
|
-
import {
|
4
|
-
import '@orpc/
|
5
|
-
import '
|
6
|
-
import '
|
2
|
+
import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
|
3
|
+
import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.ClO23hLW.mjs';
|
5
|
+
import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DQJX4Gnf.mjs';
|
6
|
+
import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
|
7
|
+
import { ORPCError } from '@orpc/client';
|
8
|
+
|
9
|
+
interface BatchHandlerOptions<T extends Context> {
|
10
|
+
/**
|
11
|
+
* The max size of the batch allowed.
|
12
|
+
*
|
13
|
+
* @default 10
|
14
|
+
*/
|
15
|
+
maxSize?: Value<number, [StandardHandlerInterceptorOptions<T>]>;
|
16
|
+
/**
|
17
|
+
* Map the request before processing it.
|
18
|
+
*
|
19
|
+
* @default merged back batch request headers into the request
|
20
|
+
*/
|
21
|
+
mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
|
22
|
+
/**
|
23
|
+
* Success batch response status code.
|
24
|
+
*
|
25
|
+
* @default 207
|
26
|
+
*/
|
27
|
+
successStatus?: Value<number, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
28
|
+
/**
|
29
|
+
* success batch response headers.
|
30
|
+
*
|
31
|
+
* @default {}
|
32
|
+
*/
|
33
|
+
headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
34
|
+
}
|
35
|
+
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
36
|
+
private readonly maxSize;
|
37
|
+
private readonly mapRequestItem;
|
38
|
+
private readonly successStatus;
|
39
|
+
private readonly headers;
|
40
|
+
order: number;
|
41
|
+
constructor(options?: BatchHandlerOptions<T>);
|
42
|
+
init(options: StandardHandlerOptions<T>): void;
|
43
|
+
}
|
7
44
|
|
8
45
|
interface CORSOptions<T extends Context> {
|
9
46
|
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
@@ -16,6 +53,7 @@ interface CORSOptions<T extends Context> {
|
|
16
53
|
}
|
17
54
|
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
18
55
|
private readonly options;
|
56
|
+
order: number;
|
19
57
|
constructor(options?: CORSOptions<T>);
|
20
58
|
init(options: StandardHandlerOptions<T>): void;
|
21
59
|
}
|
@@ -27,4 +65,60 @@ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> impl
|
|
27
65
|
init(options: StandardHandlerOptions<T>): void;
|
28
66
|
}
|
29
67
|
|
30
|
-
|
68
|
+
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
69
|
+
/**
|
70
|
+
* The name of the header to check.
|
71
|
+
*
|
72
|
+
* @default 'x-csrf-token'
|
73
|
+
*/
|
74
|
+
headerName?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
|
75
|
+
/**
|
76
|
+
* The value of the header to check.
|
77
|
+
*
|
78
|
+
* @default 'orpc'
|
79
|
+
*
|
80
|
+
*/
|
81
|
+
headerValue?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
|
82
|
+
/**
|
83
|
+
* Exclude a procedure from the plugin.
|
84
|
+
*
|
85
|
+
* @default false
|
86
|
+
*
|
87
|
+
*/
|
88
|
+
exclude?: Value<boolean, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
|
89
|
+
/**
|
90
|
+
* The error thrown when the CSRF token is invalid.
|
91
|
+
*
|
92
|
+
* @default new ORPCError('CSRF_TOKEN_MISMATCH', {
|
93
|
+
* status: 403,
|
94
|
+
* message: 'Invalid CSRF token',
|
95
|
+
* })
|
96
|
+
*/
|
97
|
+
error?: InstanceType<typeof ORPCError>;
|
98
|
+
}
|
99
|
+
declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
100
|
+
private readonly headerName;
|
101
|
+
private readonly headerValue;
|
102
|
+
private readonly exclude;
|
103
|
+
private readonly error;
|
104
|
+
constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
|
105
|
+
order: number;
|
106
|
+
init(options: StandardHandlerOptions<T>): void;
|
107
|
+
}
|
108
|
+
|
109
|
+
interface StrictGetMethodPluginOptions {
|
110
|
+
/**
|
111
|
+
* The error thrown when a GET request is made to a procedure that doesn't allow GET.
|
112
|
+
*
|
113
|
+
* @default new ORPCError('METHOD_NOT_SUPPORTED')
|
114
|
+
*/
|
115
|
+
error?: InstanceType<typeof ORPCError$1>;
|
116
|
+
}
|
117
|
+
declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
118
|
+
private readonly error;
|
119
|
+
order: number;
|
120
|
+
constructor(options?: StrictGetMethodPluginOptions);
|
121
|
+
init(options: StandardHandlerOptions<T>): void;
|
122
|
+
}
|
123
|
+
|
124
|
+
export { type BatchHandlerOptions, BatchHandlerPlugin, type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPlugin, type SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPlugin, type StrictGetMethodPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,9 +1,46 @@
|
|
1
|
-
import { b as StandardHandlerInterceptorOptions, c as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DNoBYd3E.js';
|
2
1
|
import { Value } from '@orpc/shared';
|
3
|
-
import {
|
4
|
-
import '@orpc/
|
5
|
-
import '
|
6
|
-
import '
|
2
|
+
import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
|
3
|
+
import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.DsVSuKTu.js';
|
5
|
+
import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DQJX4Gnf.js';
|
6
|
+
import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
|
7
|
+
import { ORPCError } from '@orpc/client';
|
8
|
+
|
9
|
+
interface BatchHandlerOptions<T extends Context> {
|
10
|
+
/**
|
11
|
+
* The max size of the batch allowed.
|
12
|
+
*
|
13
|
+
* @default 10
|
14
|
+
*/
|
15
|
+
maxSize?: Value<number, [StandardHandlerInterceptorOptions<T>]>;
|
16
|
+
/**
|
17
|
+
* Map the request before processing it.
|
18
|
+
*
|
19
|
+
* @default merged back batch request headers into the request
|
20
|
+
*/
|
21
|
+
mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
|
22
|
+
/**
|
23
|
+
* Success batch response status code.
|
24
|
+
*
|
25
|
+
* @default 207
|
26
|
+
*/
|
27
|
+
successStatus?: Value<number, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
28
|
+
/**
|
29
|
+
* success batch response headers.
|
30
|
+
*
|
31
|
+
* @default {}
|
32
|
+
*/
|
33
|
+
headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
|
34
|
+
}
|
35
|
+
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
36
|
+
private readonly maxSize;
|
37
|
+
private readonly mapRequestItem;
|
38
|
+
private readonly successStatus;
|
39
|
+
private readonly headers;
|
40
|
+
order: number;
|
41
|
+
constructor(options?: BatchHandlerOptions<T>);
|
42
|
+
init(options: StandardHandlerOptions<T>): void;
|
43
|
+
}
|
7
44
|
|
8
45
|
interface CORSOptions<T extends Context> {
|
9
46
|
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
@@ -16,6 +53,7 @@ interface CORSOptions<T extends Context> {
|
|
16
53
|
}
|
17
54
|
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
18
55
|
private readonly options;
|
56
|
+
order: number;
|
19
57
|
constructor(options?: CORSOptions<T>);
|
20
58
|
init(options: StandardHandlerOptions<T>): void;
|
21
59
|
}
|
@@ -27,4 +65,60 @@ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> impl
|
|
27
65
|
init(options: StandardHandlerOptions<T>): void;
|
28
66
|
}
|
29
67
|
|
30
|
-
|
68
|
+
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
69
|
+
/**
|
70
|
+
* The name of the header to check.
|
71
|
+
*
|
72
|
+
* @default 'x-csrf-token'
|
73
|
+
*/
|
74
|
+
headerName?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
|
75
|
+
/**
|
76
|
+
* The value of the header to check.
|
77
|
+
*
|
78
|
+
* @default 'orpc'
|
79
|
+
*
|
80
|
+
*/
|
81
|
+
headerValue?: Value<string, [options: StandardHandlerInterceptorOptions<T>]>;
|
82
|
+
/**
|
83
|
+
* Exclude a procedure from the plugin.
|
84
|
+
*
|
85
|
+
* @default false
|
86
|
+
*
|
87
|
+
*/
|
88
|
+
exclude?: Value<boolean, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
|
89
|
+
/**
|
90
|
+
* The error thrown when the CSRF token is invalid.
|
91
|
+
*
|
92
|
+
* @default new ORPCError('CSRF_TOKEN_MISMATCH', {
|
93
|
+
* status: 403,
|
94
|
+
* message: 'Invalid CSRF token',
|
95
|
+
* })
|
96
|
+
*/
|
97
|
+
error?: InstanceType<typeof ORPCError>;
|
98
|
+
}
|
99
|
+
declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
100
|
+
private readonly headerName;
|
101
|
+
private readonly headerValue;
|
102
|
+
private readonly exclude;
|
103
|
+
private readonly error;
|
104
|
+
constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
|
105
|
+
order: number;
|
106
|
+
init(options: StandardHandlerOptions<T>): void;
|
107
|
+
}
|
108
|
+
|
109
|
+
interface StrictGetMethodPluginOptions {
|
110
|
+
/**
|
111
|
+
* The error thrown when a GET request is made to a procedure that doesn't allow GET.
|
112
|
+
*
|
113
|
+
* @default new ORPCError('METHOD_NOT_SUPPORTED')
|
114
|
+
*/
|
115
|
+
error?: InstanceType<typeof ORPCError$1>;
|
116
|
+
}
|
117
|
+
declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
118
|
+
private readonly error;
|
119
|
+
order: number;
|
120
|
+
constructor(options?: StrictGetMethodPluginOptions);
|
121
|
+
init(options: StandardHandlerOptions<T>): void;
|
122
|
+
}
|
123
|
+
|
124
|
+
export { type BatchHandlerOptions, BatchHandlerPlugin, type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPlugin, type SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPlugin, type StrictGetMethodPluginOptions };
|
package/dist/plugins/index.mjs
CHANGED
@@ -1,7 +1,109 @@
|
|
1
|
-
import { value } from '@orpc/shared';
|
1
|
+
import { value, isAsyncIteratorObject } from '@orpc/shared';
|
2
|
+
import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
|
3
|
+
import { ORPCError } from '@orpc/client';
|
4
|
+
export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
|
5
|
+
import '@orpc/contract';
|
6
|
+
|
7
|
+
class BatchHandlerPlugin {
|
8
|
+
maxSize;
|
9
|
+
mapRequestItem;
|
10
|
+
successStatus;
|
11
|
+
headers;
|
12
|
+
order = 5e6;
|
13
|
+
constructor(options = {}) {
|
14
|
+
this.maxSize = options.maxSize ?? 10;
|
15
|
+
this.mapRequestItem = options.mapRequestItem ?? ((request, { request: batchRequest }) => ({
|
16
|
+
...request,
|
17
|
+
headers: {
|
18
|
+
...batchRequest.headers,
|
19
|
+
...request.headers
|
20
|
+
}
|
21
|
+
}));
|
22
|
+
this.successStatus = options.successStatus ?? 207;
|
23
|
+
this.headers = options.headers ?? {};
|
24
|
+
}
|
25
|
+
init(options) {
|
26
|
+
options.rootInterceptors ??= [];
|
27
|
+
options.rootInterceptors.unshift(async (options2) => {
|
28
|
+
if (options2.request.headers["x-orpc-batch"] !== "1") {
|
29
|
+
return options2.next();
|
30
|
+
}
|
31
|
+
let isParsing = false;
|
32
|
+
try {
|
33
|
+
isParsing = true;
|
34
|
+
const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
|
35
|
+
isParsing = false;
|
36
|
+
const maxSize = await value(this.maxSize, options2);
|
37
|
+
if (parsed.length > maxSize) {
|
38
|
+
return {
|
39
|
+
matched: true,
|
40
|
+
response: {
|
41
|
+
status: 413,
|
42
|
+
headers: {},
|
43
|
+
body: "Batch request size exceeds the maximum allowed size"
|
44
|
+
}
|
45
|
+
};
|
46
|
+
}
|
47
|
+
const responses = parsed.map(
|
48
|
+
(request, index) => {
|
49
|
+
const mapped = this.mapRequestItem(request, options2);
|
50
|
+
return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
|
51
|
+
if (matched) {
|
52
|
+
if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
|
53
|
+
return {
|
54
|
+
index,
|
55
|
+
status: 500,
|
56
|
+
headers: {},
|
57
|
+
body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
|
58
|
+
};
|
59
|
+
}
|
60
|
+
return { ...response2, index };
|
61
|
+
}
|
62
|
+
return { index, status: 404, headers: {}, body: "No procedure matched" };
|
63
|
+
}).catch(() => {
|
64
|
+
return { index, status: 500, headers: {}, body: "Internal server error" };
|
65
|
+
});
|
66
|
+
}
|
67
|
+
);
|
68
|
+
await Promise.race(responses);
|
69
|
+
const status = await value(this.successStatus, responses, options2);
|
70
|
+
const headers = await value(this.headers, responses, options2);
|
71
|
+
const response = toBatchResponse({
|
72
|
+
status,
|
73
|
+
headers,
|
74
|
+
body: async function* () {
|
75
|
+
const promises = [...responses];
|
76
|
+
while (true) {
|
77
|
+
const handling = promises.filter((p) => p !== void 0);
|
78
|
+
if (handling.length === 0) {
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
const result = await Promise.race(handling);
|
82
|
+
promises[result.index] = void 0;
|
83
|
+
yield result;
|
84
|
+
}
|
85
|
+
}()
|
86
|
+
});
|
87
|
+
return {
|
88
|
+
matched: true,
|
89
|
+
response
|
90
|
+
};
|
91
|
+
} catch (cause) {
|
92
|
+
if (isParsing) {
|
93
|
+
return {
|
94
|
+
matched: true,
|
95
|
+
response: { status: 400, headers: {}, body: "Invalid batch request, this could be caused by a malformed request body or a missing header" }
|
96
|
+
};
|
97
|
+
}
|
98
|
+
throw cause;
|
99
|
+
}
|
100
|
+
});
|
101
|
+
}
|
102
|
+
}
|
2
103
|
|
3
104
|
class CORSPlugin {
|
4
105
|
options;
|
106
|
+
order = 9e6;
|
5
107
|
constructor(options = {}) {
|
6
108
|
const defaults = {
|
7
109
|
origin: (origin) => origin,
|
@@ -104,4 +206,47 @@ class ResponseHeadersPlugin {
|
|
104
206
|
}
|
105
207
|
}
|
106
208
|
|
107
|
-
|
209
|
+
const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
|
210
|
+
class SimpleCsrfProtectionHandlerPlugin {
|
211
|
+
headerName;
|
212
|
+
headerValue;
|
213
|
+
exclude;
|
214
|
+
error;
|
215
|
+
constructor(options = {}) {
|
216
|
+
this.headerName = options.headerName ?? "x-csrf-token";
|
217
|
+
this.headerValue = options.headerValue ?? "orpc";
|
218
|
+
this.exclude = options.exclude ?? false;
|
219
|
+
this.error = options.error ?? new ORPCError("CSRF_TOKEN_MISMATCH", {
|
220
|
+
status: 403,
|
221
|
+
message: "Invalid CSRF token"
|
222
|
+
});
|
223
|
+
}
|
224
|
+
order = 8e6;
|
225
|
+
init(options) {
|
226
|
+
options.rootInterceptors ??= [];
|
227
|
+
options.clientInterceptors ??= [];
|
228
|
+
options.rootInterceptors.unshift(async (options2) => {
|
229
|
+
const headerName = await value(this.headerName, options2);
|
230
|
+
const headerValue = await value(this.headerValue, options2);
|
231
|
+
return options2.next({
|
232
|
+
...options2,
|
233
|
+
context: {
|
234
|
+
...options2.context,
|
235
|
+
[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers[headerName] === headerValue
|
236
|
+
}
|
237
|
+
});
|
238
|
+
});
|
239
|
+
options.clientInterceptors.unshift(async (options2) => {
|
240
|
+
if (typeof options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL] !== "boolean") {
|
241
|
+
throw new TypeError("[SimpleCsrfProtectionHandlerPlugin] CSRF protection context has been corrupted or modified by another plugin or interceptor");
|
242
|
+
}
|
243
|
+
const excluded = await value(this.exclude, options2);
|
244
|
+
if (!excluded && !options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]) {
|
245
|
+
throw this.error;
|
246
|
+
}
|
247
|
+
return options2.next();
|
248
|
+
});
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
|