@orpc/server 1.14.11 → 1.14.13
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 +98 -52
- package/dist/adapters/aws-lambda/index.d.mts +46 -0
- package/dist/adapters/aws-lambda/index.d.ts +46 -0
- package/dist/adapters/aws-lambda/index.mjs +40 -0
- package/dist/adapters/bun-ws/index.d.mts +36 -0
- package/dist/adapters/bun-ws/index.d.ts +36 -0
- package/dist/adapters/bun-ws/index.mjs +47 -0
- package/dist/adapters/crossws/index.d.mts +21 -45
- package/dist/adapters/crossws/index.d.ts +21 -45
- package/dist/adapters/crossws/index.mjs +18 -40
- package/dist/adapters/fastify/index.d.mts +53 -0
- package/dist/adapters/fastify/index.d.ts +53 -0
- package/dist/adapters/fastify/index.mjs +52 -0
- package/dist/adapters/fetch/index.d.mts +96 -64
- package/dist/adapters/fetch/index.d.ts +96 -64
- package/dist/adapters/fetch/index.mjs +139 -34
- package/dist/adapters/message-port/index.d.mts +34 -49
- package/dist/adapters/message-port/index.d.ts +34 -49
- package/dist/adapters/message-port/index.mjs +37 -68
- package/dist/adapters/node/index.d.mts +71 -63
- package/dist/adapters/node/index.d.ts +71 -63
- package/dist/adapters/node/index.mjs +113 -36
- package/dist/adapters/standard/index.d.mts +18 -16
- package/dist/adapters/standard/index.d.ts +18 -16
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/standard-peer/index.d.mts +14 -12
- package/dist/adapters/standard-peer/index.d.ts +14 -12
- package/dist/adapters/standard-peer/index.mjs +21 -2
- package/dist/adapters/websocket/index.d.mts +38 -53
- package/dist/adapters/websocket/index.d.ts +38 -53
- package/dist/adapters/websocket/index.mjs +42 -59
- package/dist/adapters/ws/index.d.mts +31 -0
- package/dist/adapters/ws/index.d.ts +31 -0
- package/dist/adapters/ws/index.mjs +41 -0
- package/dist/helpers/index.d.mts +4 -4
- package/dist/helpers/index.d.ts +4 -4
- package/dist/helpers/index.mjs +5 -13
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +770 -166
- package/dist/index.d.ts +770 -166
- package/dist/index.mjs +399 -306
- package/dist/plugins/index.d.mts +121 -214
- package/dist/plugins/index.d.ts +121 -214
- package/dist/plugins/index.mjs +214 -576
- package/dist/shared/server.7cEtMB30.d.ts +74 -0
- package/dist/shared/server.B8gYOD5g.d.mts +12 -0
- package/dist/shared/server.BqadksTP.d.mts +74 -0
- package/dist/shared/server.C8_sRzQB.d.mts +42 -0
- package/dist/shared/server.CMf4nKky.mjs +230 -0
- package/dist/shared/server.ChyoA9XY.d.ts +42 -0
- package/dist/shared/server.D8IXzfqT.d.ts +32 -0
- package/dist/shared/server.DEBcqOjg.mjs +418 -0
- package/dist/shared/{server.W91HSRkE.mjs → server.DZ5BIITo.mjs} +2 -2
- package/dist/shared/server.DzE6WeuY.d.mts +32 -0
- package/dist/shared/server.EfTOZ2Q7.d.ts +12 -0
- package/dist/shared/server.TEVCLCFC.mjs +39 -0
- package/dist/shared/server.qKsRrdxW.d.mts +193 -0
- package/dist/shared/server.qKsRrdxW.d.ts +193 -0
- package/package.json +56 -26
- package/dist/extensions/callable.d.mts +0 -10
- package/dist/extensions/callable.d.ts +0 -10
- package/dist/extensions/callable.mjs +0 -11
- package/dist/shared/server.15O7oC1p.d.mts +0 -61
- package/dist/shared/server.B4BnEWWm.d.mts +0 -67
- package/dist/shared/server.BhsVw7m7.d.ts +0 -104
- package/dist/shared/server.BoiFpNT7.mjs +0 -224
- package/dist/shared/server.COPVXhDG.mjs +0 -271
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.CcR4kgje.d.mts +0 -206
- package/dist/shared/server.CcR4kgje.d.ts +0 -206
- package/dist/shared/server.CnN50DHH.d.ts +0 -67
- package/dist/shared/server.DBs0rrf9.mjs +0 -41
- package/dist/shared/server.DDFizwfU.d.mts +0 -104
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.DofEOwf-.mjs +0 -237
- package/dist/shared/server.m3szVJGU.d.ts +0 -61
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, AnyORPCError, ClientContext, Client } from '@orpc/client';
|
|
2
|
-
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnyMetaPlugin, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
|
|
3
|
-
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
|
|
4
|
-
|
|
5
|
-
interface Context {
|
|
6
|
-
[key: PropertyKey]: any;
|
|
7
|
-
}
|
|
8
|
-
type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & Omit<TInContext, keyof TInitial | keyof TOutContext>;
|
|
9
|
-
type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : Omit<TCurrent, keyof TOutContext> & TOutContext;
|
|
10
|
-
|
|
11
|
-
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
|
|
12
|
-
interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
13
|
-
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
14
|
-
}
|
|
15
|
-
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
16
|
-
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Creates a map of ORPC error constructors.
|
|
20
|
-
*
|
|
21
|
-
* The returned object is a `Proxy` that allows access to arbitrary error codes:
|
|
22
|
-
* - If the code exists in the provided `errorMap`, the corresponding constructor
|
|
23
|
-
* will create a **defined** `ORPCError`.
|
|
24
|
-
* - If the code does not exist, a fallback `ORPCError` constructor is returned.
|
|
25
|
-
*
|
|
26
|
-
* The `in` operator can be used to check whether an error code is explicitly
|
|
27
|
-
* defined in the map.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* const errorMap = createORPCErrorConstructorMap({
|
|
32
|
-
* NOT_FOUND: {
|
|
33
|
-
* status: 404,
|
|
34
|
-
* message: 'Not Found',
|
|
35
|
-
* },
|
|
36
|
-
* })
|
|
37
|
-
*
|
|
38
|
-
* if ('NOT_FOUND' in errorMap) {
|
|
39
|
-
* const error = errorMap.NOT_FOUND()
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
|
44
|
-
|
|
45
|
-
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
46
|
-
output: TOutput;
|
|
47
|
-
context: TOutContext;
|
|
48
|
-
}>;
|
|
49
|
-
type MiddlewareNextOptions<TOutContext extends Context> = object extends TOutContext ? {
|
|
50
|
-
context?: TOutContext;
|
|
51
|
-
} : {
|
|
52
|
-
context: TOutContext;
|
|
53
|
-
};
|
|
54
|
-
interface MiddlewareNext<TOutput> {
|
|
55
|
-
<T extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<T>>): MiddlewareResult<T, TOutput>;
|
|
56
|
-
}
|
|
57
|
-
type MiddlewareDoneOptions<TOutContext, TOutput> = (object extends TOutContext ? {
|
|
58
|
-
context?: TOutContext;
|
|
59
|
-
} : {
|
|
60
|
-
context: TOutContext;
|
|
61
|
-
}) & {
|
|
62
|
-
output: TOutput;
|
|
63
|
-
};
|
|
64
|
-
interface MiddlewareDone<TOutput> {
|
|
65
|
-
/**
|
|
66
|
-
* Create a successful result and terminate the middleware chain early.
|
|
67
|
-
*/
|
|
68
|
-
<TOutContext extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareDoneOptions<TOutContext, TOutput>>): MiddlewareResult<TOutContext, TOutput>;
|
|
69
|
-
}
|
|
70
|
-
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
71
|
-
context: TInContext;
|
|
72
|
-
path: string[];
|
|
73
|
-
procedure: AnyProcedure;
|
|
74
|
-
signal?: AbortSignal | undefined;
|
|
75
|
-
lastEventId: string | undefined;
|
|
76
|
-
/**
|
|
77
|
-
* Invoke to continue the middleware chain.
|
|
78
|
-
*/
|
|
79
|
-
next: MiddlewareNext<TOutput>;
|
|
80
|
-
errors: TErrorConstructorMap;
|
|
81
|
-
}
|
|
82
|
-
interface MiddlewareDefinition<TErrorMap extends ErrorMap> {
|
|
83
|
-
errorMap?: TErrorMap | undefined;
|
|
84
|
-
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
85
|
-
}
|
|
86
|
-
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> {
|
|
87
|
-
/** this property should be optional to support inline middleware */
|
|
88
|
-
'~orpc'?: MiddlewareDefinition<TErrorMap> | undefined;
|
|
89
|
-
(opts: MiddlewareOptions<TInContext, TOutput, ORPCErrorConstructorMap<TErrorMap>>, input: TInput, done: MiddlewareDone<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
90
|
-
}
|
|
91
|
-
type AnyMiddleware = Middleware<any, any, any, any, any>;
|
|
92
|
-
|
|
93
|
-
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
94
|
-
context: TCurrentContext;
|
|
95
|
-
input: TInput;
|
|
96
|
-
path: string[];
|
|
97
|
-
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, any>;
|
|
98
|
-
signal?: AbortSignal | undefined;
|
|
99
|
-
lastEventId?: string | undefined;
|
|
100
|
-
errors: TErrorConstructorMap;
|
|
101
|
-
}
|
|
102
|
-
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
103
|
-
(opts: ProcedureHandlerOptions<TCurrentContext, TInput, TErrorConstructorMap>, input: TInput): Promisable<THandlerOutput>;
|
|
104
|
-
}
|
|
105
|
-
interface OrderedMiddleware {
|
|
106
|
-
/**
|
|
107
|
-
* Snapshot of `inputSchemas.length`
|
|
108
|
-
* at the time this middleware was used.
|
|
109
|
-
*
|
|
110
|
-
* @default 0
|
|
111
|
-
*/
|
|
112
|
-
inputSchemasLengthAtUse?: number | undefined;
|
|
113
|
-
/**
|
|
114
|
-
* Snapshot of `outputSchemas.length`
|
|
115
|
-
* at the time this middleware was used.
|
|
116
|
-
*
|
|
117
|
-
* @default 0
|
|
118
|
-
*/
|
|
119
|
-
outputSchemasLengthAtUse?: number | undefined;
|
|
120
|
-
middleware: AnyMiddleware;
|
|
121
|
-
}
|
|
122
|
-
interface ProcedureConfig {
|
|
123
|
-
/**
|
|
124
|
-
* When enabled, input schemas are not validated at runtime.
|
|
125
|
-
* Schemas are still used for type inference and OpenAPI generation.
|
|
126
|
-
*
|
|
127
|
-
* @warning Do not disable validation for schemas that transform values.
|
|
128
|
-
*
|
|
129
|
-
* @default false
|
|
130
|
-
*/
|
|
131
|
-
disableInputValidation?: boolean | undefined;
|
|
132
|
-
/**
|
|
133
|
-
* When enabled, output schemas are not validated at runtime.
|
|
134
|
-
* Schemas are still used for type inference and OpenAPI generation.
|
|
135
|
-
*
|
|
136
|
-
* Useful when output schemas exist only for specification generation.
|
|
137
|
-
*
|
|
138
|
-
* @warning Do not disable validation for schemas that transform values.
|
|
139
|
-
*
|
|
140
|
-
* @default false
|
|
141
|
-
*/
|
|
142
|
-
disableOutputValidation?: boolean | undefined;
|
|
143
|
-
}
|
|
144
|
-
interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>, ProcedureConfig {
|
|
145
|
-
__TInitialContext?: (type: TInitialContext) => unknown;
|
|
146
|
-
__TInjectedContext?: (type: TInjectedContext) => unknown;
|
|
147
|
-
__TReturnedError?: () => TReturnedError;
|
|
148
|
-
/**
|
|
149
|
-
* When enabled, errors returned (not thrown) by the handler are passed through as-is,
|
|
150
|
-
* rather than being transformed into inferrable errors.
|
|
151
|
-
*
|
|
152
|
-
* This is intended for the contract-first approach, where the procedure adheres to an
|
|
153
|
-
* external contract and returned errors should not affect the inferred contract types.
|
|
154
|
-
*
|
|
155
|
-
* @default false
|
|
156
|
-
*/
|
|
157
|
-
opaqueReturnedErrors?: boolean | undefined;
|
|
158
|
-
orderedMiddlewares: OrderedMiddleware[];
|
|
159
|
-
handler: ProcedureHandler<any, any, any, any>;
|
|
160
|
-
}
|
|
161
|
-
declare class Procedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> {
|
|
162
|
-
'~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
163
|
-
constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>);
|
|
164
|
-
/**
|
|
165
|
-
* Checks if the given instance satisfies the {@see Procedure} class/interface.
|
|
166
|
-
*/
|
|
167
|
-
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
168
|
-
}
|
|
169
|
-
type AnyProcedure = Procedure<any, any, any, any, any, any>;
|
|
170
|
-
|
|
171
|
-
interface LazyDefinition<T> {
|
|
172
|
-
meta: Meta;
|
|
173
|
-
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
174
|
-
loader: () => Promise<{
|
|
175
|
-
default: T;
|
|
176
|
-
}>;
|
|
177
|
-
}
|
|
178
|
-
declare class Lazy<T> {
|
|
179
|
-
'~orpc': LazyDefinition<T>;
|
|
180
|
-
constructor(def: LazyDefinition<T>);
|
|
181
|
-
/**
|
|
182
|
-
* Checks if the given instance satisfies the {@see Lazy} class/interface.
|
|
183
|
-
*/
|
|
184
|
-
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
185
|
-
}
|
|
186
|
-
type Lazyable<T> = T | Lazy<T>;
|
|
187
|
-
declare function unlazy<T extends Lazyable<any>>(maybeLazy: T): Promise<{
|
|
188
|
-
default: T extends Lazy<infer U> ? U : T;
|
|
189
|
-
}>;
|
|
190
|
-
|
|
191
|
-
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedORPCError extends AnyORPCError> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | TReturnedORPCError | ThrowableError>;
|
|
192
|
-
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap> extends ProcedureHandlerOptions<TInitialContext, unknown, ORPCErrorConstructorMap<TErrorMap>> {
|
|
193
|
-
}
|
|
194
|
-
type ProcedureClientInterceptor<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> = Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | TReturnedError | ThrowableError>>;
|
|
195
|
-
type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError, TClientContext extends ClientContext> = {
|
|
196
|
-
path?: string[];
|
|
197
|
-
interceptors?: ProcedureClientInterceptor<TInitialContext, TOutputSchema, TErrorMap, TReturnedError>[];
|
|
198
|
-
} & (object extends TInitialContext ? {
|
|
199
|
-
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
200
|
-
} : {
|
|
201
|
-
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
202
|
-
});
|
|
203
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
204
|
-
|
|
205
|
-
export { Procedure as a, Lazy as h, createORPCErrorConstructorMap as x, createProcedureClient as y, unlazy as z };
|
|
206
|
-
export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, ORPCErrorConstructorMap as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, OrderedMiddleware as j, LazyDefinition as k, MiddlewareDefinition as l, MiddlewareDone as m, MiddlewareDoneOptions as n, MiddlewareNext as o, MiddlewareNextOptions as p, MiddlewareOptions as q, MiddlewareResult as r, ORPCErrorConstructorMapItem as s, ORPCErrorConstructorMapItemOptions as t, ProcedureClientInterceptorOptions as u, ProcedureDefinition as v, ProcedureHandlerOptions as w };
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, AnyORPCError, ClientContext, Client } from '@orpc/client';
|
|
2
|
-
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnyMetaPlugin, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
|
|
3
|
-
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
|
|
4
|
-
|
|
5
|
-
interface Context {
|
|
6
|
-
[key: PropertyKey]: any;
|
|
7
|
-
}
|
|
8
|
-
type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & Omit<TInContext, keyof TInitial | keyof TOutContext>;
|
|
9
|
-
type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : Omit<TCurrent, keyof TOutContext> & TOutContext;
|
|
10
|
-
|
|
11
|
-
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
|
|
12
|
-
interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
13
|
-
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
14
|
-
}
|
|
15
|
-
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
16
|
-
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Creates a map of ORPC error constructors.
|
|
20
|
-
*
|
|
21
|
-
* The returned object is a `Proxy` that allows access to arbitrary error codes:
|
|
22
|
-
* - If the code exists in the provided `errorMap`, the corresponding constructor
|
|
23
|
-
* will create a **defined** `ORPCError`.
|
|
24
|
-
* - If the code does not exist, a fallback `ORPCError` constructor is returned.
|
|
25
|
-
*
|
|
26
|
-
* The `in` operator can be used to check whether an error code is explicitly
|
|
27
|
-
* defined in the map.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* const errorMap = createORPCErrorConstructorMap({
|
|
32
|
-
* NOT_FOUND: {
|
|
33
|
-
* status: 404,
|
|
34
|
-
* message: 'Not Found',
|
|
35
|
-
* },
|
|
36
|
-
* })
|
|
37
|
-
*
|
|
38
|
-
* if ('NOT_FOUND' in errorMap) {
|
|
39
|
-
* const error = errorMap.NOT_FOUND()
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
|
44
|
-
|
|
45
|
-
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
46
|
-
output: TOutput;
|
|
47
|
-
context: TOutContext;
|
|
48
|
-
}>;
|
|
49
|
-
type MiddlewareNextOptions<TOutContext extends Context> = object extends TOutContext ? {
|
|
50
|
-
context?: TOutContext;
|
|
51
|
-
} : {
|
|
52
|
-
context: TOutContext;
|
|
53
|
-
};
|
|
54
|
-
interface MiddlewareNext<TOutput> {
|
|
55
|
-
<T extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<T>>): MiddlewareResult<T, TOutput>;
|
|
56
|
-
}
|
|
57
|
-
type MiddlewareDoneOptions<TOutContext, TOutput> = (object extends TOutContext ? {
|
|
58
|
-
context?: TOutContext;
|
|
59
|
-
} : {
|
|
60
|
-
context: TOutContext;
|
|
61
|
-
}) & {
|
|
62
|
-
output: TOutput;
|
|
63
|
-
};
|
|
64
|
-
interface MiddlewareDone<TOutput> {
|
|
65
|
-
/**
|
|
66
|
-
* Create a successful result and terminate the middleware chain early.
|
|
67
|
-
*/
|
|
68
|
-
<TOutContext extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareDoneOptions<TOutContext, TOutput>>): MiddlewareResult<TOutContext, TOutput>;
|
|
69
|
-
}
|
|
70
|
-
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
71
|
-
context: TInContext;
|
|
72
|
-
path: string[];
|
|
73
|
-
procedure: AnyProcedure;
|
|
74
|
-
signal?: AbortSignal | undefined;
|
|
75
|
-
lastEventId: string | undefined;
|
|
76
|
-
/**
|
|
77
|
-
* Invoke to continue the middleware chain.
|
|
78
|
-
*/
|
|
79
|
-
next: MiddlewareNext<TOutput>;
|
|
80
|
-
errors: TErrorConstructorMap;
|
|
81
|
-
}
|
|
82
|
-
interface MiddlewareDefinition<TErrorMap extends ErrorMap> {
|
|
83
|
-
errorMap?: TErrorMap | undefined;
|
|
84
|
-
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
85
|
-
}
|
|
86
|
-
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap> {
|
|
87
|
-
/** this property should be optional to support inline middleware */
|
|
88
|
-
'~orpc'?: MiddlewareDefinition<TErrorMap> | undefined;
|
|
89
|
-
(opts: MiddlewareOptions<TInContext, TOutput, ORPCErrorConstructorMap<TErrorMap>>, input: TInput, done: MiddlewareDone<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
90
|
-
}
|
|
91
|
-
type AnyMiddleware = Middleware<any, any, any, any, any>;
|
|
92
|
-
|
|
93
|
-
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
94
|
-
context: TCurrentContext;
|
|
95
|
-
input: TInput;
|
|
96
|
-
path: string[];
|
|
97
|
-
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, any>;
|
|
98
|
-
signal?: AbortSignal | undefined;
|
|
99
|
-
lastEventId?: string | undefined;
|
|
100
|
-
errors: TErrorConstructorMap;
|
|
101
|
-
}
|
|
102
|
-
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
|
103
|
-
(opts: ProcedureHandlerOptions<TCurrentContext, TInput, TErrorConstructorMap>, input: TInput): Promisable<THandlerOutput>;
|
|
104
|
-
}
|
|
105
|
-
interface OrderedMiddleware {
|
|
106
|
-
/**
|
|
107
|
-
* Snapshot of `inputSchemas.length`
|
|
108
|
-
* at the time this middleware was used.
|
|
109
|
-
*
|
|
110
|
-
* @default 0
|
|
111
|
-
*/
|
|
112
|
-
inputSchemasLengthAtUse?: number | undefined;
|
|
113
|
-
/**
|
|
114
|
-
* Snapshot of `outputSchemas.length`
|
|
115
|
-
* at the time this middleware was used.
|
|
116
|
-
*
|
|
117
|
-
* @default 0
|
|
118
|
-
*/
|
|
119
|
-
outputSchemasLengthAtUse?: number | undefined;
|
|
120
|
-
middleware: AnyMiddleware;
|
|
121
|
-
}
|
|
122
|
-
interface ProcedureConfig {
|
|
123
|
-
/**
|
|
124
|
-
* When enabled, input schemas are not validated at runtime.
|
|
125
|
-
* Schemas are still used for type inference and OpenAPI generation.
|
|
126
|
-
*
|
|
127
|
-
* @warning Do not disable validation for schemas that transform values.
|
|
128
|
-
*
|
|
129
|
-
* @default false
|
|
130
|
-
*/
|
|
131
|
-
disableInputValidation?: boolean | undefined;
|
|
132
|
-
/**
|
|
133
|
-
* When enabled, output schemas are not validated at runtime.
|
|
134
|
-
* Schemas are still used for type inference and OpenAPI generation.
|
|
135
|
-
*
|
|
136
|
-
* Useful when output schemas exist only for specification generation.
|
|
137
|
-
*
|
|
138
|
-
* @warning Do not disable validation for schemas that transform values.
|
|
139
|
-
*
|
|
140
|
-
* @default false
|
|
141
|
-
*/
|
|
142
|
-
disableOutputValidation?: boolean | undefined;
|
|
143
|
-
}
|
|
144
|
-
interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>, ProcedureConfig {
|
|
145
|
-
__TInitialContext?: (type: TInitialContext) => unknown;
|
|
146
|
-
__TInjectedContext?: (type: TInjectedContext) => unknown;
|
|
147
|
-
__TReturnedError?: () => TReturnedError;
|
|
148
|
-
/**
|
|
149
|
-
* When enabled, errors returned (not thrown) by the handler are passed through as-is,
|
|
150
|
-
* rather than being transformed into inferrable errors.
|
|
151
|
-
*
|
|
152
|
-
* This is intended for the contract-first approach, where the procedure adheres to an
|
|
153
|
-
* external contract and returned errors should not affect the inferred contract types.
|
|
154
|
-
*
|
|
155
|
-
* @default false
|
|
156
|
-
*/
|
|
157
|
-
opaqueReturnedErrors?: boolean | undefined;
|
|
158
|
-
orderedMiddlewares: OrderedMiddleware[];
|
|
159
|
-
handler: ProcedureHandler<any, any, any, any>;
|
|
160
|
-
}
|
|
161
|
-
declare class Procedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> {
|
|
162
|
-
'~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
163
|
-
constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>);
|
|
164
|
-
/**
|
|
165
|
-
* Checks if the given instance satisfies the {@see Procedure} class/interface.
|
|
166
|
-
*/
|
|
167
|
-
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
168
|
-
}
|
|
169
|
-
type AnyProcedure = Procedure<any, any, any, any, any, any>;
|
|
170
|
-
|
|
171
|
-
interface LazyDefinition<T> {
|
|
172
|
-
meta: Meta;
|
|
173
|
-
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
174
|
-
loader: () => Promise<{
|
|
175
|
-
default: T;
|
|
176
|
-
}>;
|
|
177
|
-
}
|
|
178
|
-
declare class Lazy<T> {
|
|
179
|
-
'~orpc': LazyDefinition<T>;
|
|
180
|
-
constructor(def: LazyDefinition<T>);
|
|
181
|
-
/**
|
|
182
|
-
* Checks if the given instance satisfies the {@see Lazy} class/interface.
|
|
183
|
-
*/
|
|
184
|
-
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
185
|
-
}
|
|
186
|
-
type Lazyable<T> = T | Lazy<T>;
|
|
187
|
-
declare function unlazy<T extends Lazyable<any>>(maybeLazy: T): Promise<{
|
|
188
|
-
default: T extends Lazy<infer U> ? U : T;
|
|
189
|
-
}>;
|
|
190
|
-
|
|
191
|
-
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedORPCError extends AnyORPCError> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | TReturnedORPCError | ThrowableError>;
|
|
192
|
-
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap> extends ProcedureHandlerOptions<TInitialContext, unknown, ORPCErrorConstructorMap<TErrorMap>> {
|
|
193
|
-
}
|
|
194
|
-
type ProcedureClientInterceptor<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> = Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | TReturnedError | ThrowableError>>;
|
|
195
|
-
type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError, TClientContext extends ClientContext> = {
|
|
196
|
-
path?: string[];
|
|
197
|
-
interceptors?: ProcedureClientInterceptor<TInitialContext, TOutputSchema, TErrorMap, TReturnedError>[];
|
|
198
|
-
} & (object extends TInitialContext ? {
|
|
199
|
-
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
200
|
-
} : {
|
|
201
|
-
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
202
|
-
});
|
|
203
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
204
|
-
|
|
205
|
-
export { Procedure as a, Lazy as h, createORPCErrorConstructorMap as x, createProcedureClient as y, unlazy as z };
|
|
206
|
-
export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, ORPCErrorConstructorMap as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, OrderedMiddleware as j, LazyDefinition as k, MiddlewareDefinition as l, MiddlewareDone as m, MiddlewareDoneOptions as n, MiddlewareNext as o, MiddlewareNextOptions as p, MiddlewareOptions as q, MiddlewareResult as r, ORPCErrorConstructorMapItem as s, ORPCErrorConstructorMapItemOptions as t, ProcedureClientInterceptorOptions as u, ProcedureDefinition as v, ProcedureHandlerOptions as w };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { RPCSerializer, AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { Value, Promisable } from '@orpc/shared';
|
|
3
|
-
import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standardserver/core';
|
|
4
|
-
import { A as AnyProcedure, C as Context } from './server.CcR4kgje.js';
|
|
5
|
-
import { A as AnyRouter } from './server.m3szVJGU.js';
|
|
6
|
-
import { AnyProcedureContract } from '@orpc/contract';
|
|
7
|
-
import { b as StandardHandlerHandleOptions, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure } from './server.BhsVw7m7.js';
|
|
8
|
-
|
|
9
|
-
interface RPCMatcherOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Filter which procedures are exposed for matching. Return `false` to exclude.
|
|
12
|
-
*
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
|
|
16
|
-
}
|
|
17
|
-
declare class RPCMatcher {
|
|
18
|
-
private readonly filter;
|
|
19
|
-
private readonly rootRouter;
|
|
20
|
-
private readonly tree;
|
|
21
|
-
private pendingLazyRouters;
|
|
22
|
-
constructor(router: AnyRouter, options?: RPCMatcherOptions);
|
|
23
|
-
private index;
|
|
24
|
-
match(_method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
|
|
25
|
-
path: string[];
|
|
26
|
-
procedure: AnyProcedure;
|
|
27
|
-
} | undefined>;
|
|
28
|
-
private matchPathname;
|
|
29
|
-
private resolvePendingLazyRouters;
|
|
30
|
-
private resolveProcedure;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
|
|
34
|
-
/**
|
|
35
|
-
* Override the default RPC serializer.
|
|
36
|
-
*/
|
|
37
|
-
serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
|
|
38
|
-
/**
|
|
39
|
-
* Resolve HTTP status for encoded successful outputs.
|
|
40
|
-
*
|
|
41
|
-
* Value should be in the `2xx` range and must be less than `400`.
|
|
42
|
-
* Return `undefined` or `null` to fallback to default
|
|
43
|
-
*
|
|
44
|
-
* @default DEFAULT_SUCCESS_STATUS (200)
|
|
45
|
-
*/
|
|
46
|
-
outputStatus?: Value<number | undefined | null, [output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>]>;
|
|
47
|
-
/**
|
|
48
|
-
* Mapping ORPCError Code -> HTTP Status Code
|
|
49
|
-
* The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
|
|
50
|
-
*
|
|
51
|
-
* @default COMMON_ERROR_STATUS_MAP
|
|
52
|
-
*/
|
|
53
|
-
errorStatusMap?: Record<string, number> | undefined;
|
|
54
|
-
}
|
|
55
|
-
declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec<T> {
|
|
56
|
-
private readonly matcher;
|
|
57
|
-
private readonly serializer;
|
|
58
|
-
private readonly errorStatusMap;
|
|
59
|
-
private readonly outputStatus;
|
|
60
|
-
constructor(router: AnyRouter, options?: RPCHandlerCodecOptions<T>);
|
|
61
|
-
resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
62
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
63
|
-
encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { RPCHandlerCodec as a, RPCMatcher as b };
|
|
67
|
-
export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { resolveMetaPlugins, mergeErrorMap, getHiddenMetaPlugins } from '@orpc/contract';
|
|
2
|
-
import { P as Procedure } from './server.DofEOwf-.mjs';
|
|
3
|
-
|
|
4
|
-
class DecoratedProcedure extends Procedure {
|
|
5
|
-
meta(...plugins) {
|
|
6
|
-
const [meta, metaPlugins] = resolveMetaPlugins(this["~orpc"].meta, this["~orpc"].metaPlugins, plugins);
|
|
7
|
-
return new DecoratedProcedure({
|
|
8
|
-
...this["~orpc"],
|
|
9
|
-
meta,
|
|
10
|
-
metaPlugins
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
errors(errors) {
|
|
14
|
-
let procedure = new DecoratedProcedure({
|
|
15
|
-
...this["~orpc"],
|
|
16
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
17
|
-
});
|
|
18
|
-
const plugins = getHiddenMetaPlugins(errors);
|
|
19
|
-
if (plugins) {
|
|
20
|
-
procedure = procedure.meta(...plugins);
|
|
21
|
-
}
|
|
22
|
-
return procedure;
|
|
23
|
-
}
|
|
24
|
-
use(middleware) {
|
|
25
|
-
let procedure = new DecoratedProcedure({
|
|
26
|
-
...this["~orpc"],
|
|
27
|
-
errorMap: mergeErrorMap(middleware["~orpc"]?.errorMap, this["~orpc"].errorMap),
|
|
28
|
-
orderedMiddlewares: [...this["~orpc"].orderedMiddlewares, {
|
|
29
|
-
middleware,
|
|
30
|
-
inputSchemasLengthAtUse: this["~orpc"].inputSchemas?.length,
|
|
31
|
-
outputSchemasLengthAtUse: this["~orpc"].outputSchemas?.length
|
|
32
|
-
}]
|
|
33
|
-
});
|
|
34
|
-
if (middleware["~orpc"]?.metaPlugins) {
|
|
35
|
-
procedure = procedure.meta(...middleware["~orpc"]?.metaPlugins);
|
|
36
|
-
}
|
|
37
|
-
return procedure;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { DecoratedProcedure as D };
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { OrderablePlugin, Interceptor, Promisable } from '@orpc/shared';
|
|
3
|
-
import { StandardLazyRequest, StandardResponse } from '@standardserver/core';
|
|
4
|
-
import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.CcR4kgje.mjs';
|
|
5
|
-
import { Schema, ErrorMap } from '@orpc/contract';
|
|
6
|
-
|
|
7
|
-
interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the plugin and returns new handler options.
|
|
10
|
-
* Called once per plugin instance during composition.
|
|
11
|
-
*
|
|
12
|
-
* This method allows plugins to wrap, extend, or transform handler options
|
|
13
|
-
* such as interceptors, or configuration.
|
|
14
|
-
*
|
|
15
|
-
* @param options - The current handler options from previous plugins or base configuration
|
|
16
|
-
* @returns Transformed handler options with plugin's modifications applied
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* init(options) {
|
|
21
|
-
* return {
|
|
22
|
-
* ...options,
|
|
23
|
-
* interceptors: [...(options.interceptors || []), myInterceptor]
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
init?(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
29
|
-
}
|
|
30
|
-
declare class CompositeStandardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
31
|
-
readonly name = "~composite";
|
|
32
|
-
protected readonly plugins: StandardHandlerPlugin<T>[];
|
|
33
|
-
constructor(plugins?: StandardHandlerPlugin<T>[]);
|
|
34
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface StandardHandlerHandleOptions<T extends Context> {
|
|
38
|
-
prefix?: `/${string}` | undefined;
|
|
39
|
-
context: T;
|
|
40
|
-
}
|
|
41
|
-
type StandardHandlerHandleResult = {
|
|
42
|
-
matched: true;
|
|
43
|
-
response: StandardResponse;
|
|
44
|
-
} | {
|
|
45
|
-
matched: false;
|
|
46
|
-
response?: undefined;
|
|
47
|
-
};
|
|
48
|
-
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure, StandardHandlerHandleOptions<T> {
|
|
49
|
-
request: StandardLazyRequest;
|
|
50
|
-
}
|
|
51
|
-
type StandardHandlerInterceptor<T extends Context> = Interceptor<StandardHandlerInterceptorOptions<T>, Promise<StandardResponse>>;
|
|
52
|
-
interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
|
|
53
|
-
request: StandardLazyRequest;
|
|
54
|
-
}
|
|
55
|
-
type StandardHandlerRoutingInterceptor<T extends Context> = Interceptor<StandardHandlerRoutingInterceptorOptions<T>, Promise<StandardHandlerHandleResult>>;
|
|
56
|
-
interface StandardHandlerOptions<TContext extends Context> {
|
|
57
|
-
/**
|
|
58
|
-
* Fired on every request before routing, useful when you want
|
|
59
|
-
* to intercept all requests regardless of whether they match a procedure or not.
|
|
60
|
-
*
|
|
61
|
-
* @examples
|
|
62
|
-
* - batch plugins - separate one request into multiple and call multiple next
|
|
63
|
-
* - openapi spec plugin - to intercept a request and early response
|
|
64
|
-
*/
|
|
65
|
-
routingInterceptors?: StandardHandlerRoutingInterceptor<TContext>[];
|
|
66
|
-
/**
|
|
67
|
-
* interceptor run after routing and before error handler,
|
|
68
|
-
* useful for error handling, logging, metrics, etc.
|
|
69
|
-
*/
|
|
70
|
-
interceptors?: StandardHandlerInterceptor<TContext>[];
|
|
71
|
-
/**
|
|
72
|
-
*
|
|
73
|
-
* ClientInterceptor equivalent with createRouterClient.interceptors / createProcedure.interceptors
|
|
74
|
-
* useful for error handling, logging, metrics, etc. (not counting encoding/decoding)
|
|
75
|
-
*/
|
|
76
|
-
clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap, any>[];
|
|
77
|
-
plugins?: StandardHandlerPlugin<TContext>[];
|
|
78
|
-
}
|
|
79
|
-
declare class StandardHandler<T extends Context> {
|
|
80
|
-
private readonly codec;
|
|
81
|
-
private readonly routingInterceptors;
|
|
82
|
-
private readonly interceptors;
|
|
83
|
-
private readonly clientInterceptors;
|
|
84
|
-
constructor(codec: StandardHandlerCodec<T>, options: StandardHandlerOptions<T>);
|
|
85
|
-
handle(request: StandardLazyRequest, { context, prefix }: StandardHandlerHandleOptions<T>): Promise<StandardHandlerHandleResult>;
|
|
86
|
-
}
|
|
87
|
-
declare class OtelHandlerPlugin implements StandardHandlerPlugin<any> {
|
|
88
|
-
name: string;
|
|
89
|
-
init(options: StandardHandlerOptions<any>): StandardHandlerOptions<any>;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
interface StandardHandlerCodecResolvedProcedure {
|
|
93
|
-
path: string[];
|
|
94
|
-
procedure: AnyProcedure;
|
|
95
|
-
decodeInput: () => Promise<unknown>;
|
|
96
|
-
}
|
|
97
|
-
interface StandardHandlerCodec<T extends Context> {
|
|
98
|
-
resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promisable<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
99
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
100
|
-
encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, StandardHandler as S };
|
|
104
|
-
export type { StandardHandlerOptions as a, StandardHandlerHandleOptions as b, StandardHandlerCodec as c, StandardHandlerCodecResolvedProcedure as d, StandardHandlerPlugin as e, StandardHandlerRoutingInterceptorOptions as f, StandardHandlerInterceptorOptions as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ORPCError } from '@orpc/client';
|
|
2
|
-
import { toArray } from '@orpc/shared';
|
|
3
|
-
import { flattenStandardHeader } from '@standardserver/core';
|
|
4
|
-
|
|
5
|
-
class CSRFGuardHandlerPlugin {
|
|
6
|
-
name = "~csrf-guard";
|
|
7
|
-
init(options) {
|
|
8
|
-
const interceptor = async (interceptorOptions) => {
|
|
9
|
-
const mode = flattenStandardHeader(
|
|
10
|
-
interceptorOptions.request.headers["sec-fetch-mode"]
|
|
11
|
-
)?.toLowerCase();
|
|
12
|
-
if (mode === void 0) {
|
|
13
|
-
return interceptorOptions.next();
|
|
14
|
-
}
|
|
15
|
-
if (mode === "cors" || mode === "same-origin") {
|
|
16
|
-
return interceptorOptions.next();
|
|
17
|
-
}
|
|
18
|
-
throw new ORPCError("FORBIDDEN", {
|
|
19
|
-
message: "Request blocked by CSRF protection."
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
...options,
|
|
24
|
-
// appended last so user's interceptors can catch ORPCError
|
|
25
|
-
interceptors: [...toArray(options.interceptors), interceptor]
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { CSRFGuardHandlerPlugin as C };
|