@orpc/server 0.0.0-next.9b3a030 → 0.0.0-next.9dfcee8
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 +120 -0
- package/dist/adapters/fetch/index.d.mts +28 -0
- package/dist/adapters/fetch/index.d.ts +28 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +21 -0
- package/dist/adapters/hono/index.d.ts +21 -0
- package/dist/adapters/hono/index.mjs +32 -0
- package/dist/adapters/next/index.d.mts +28 -0
- package/dist/adapters/next/index.d.ts +28 -0
- package/dist/adapters/next/index.mjs +29 -0
- package/dist/adapters/node/index.d.mts +36 -0
- package/dist/adapters/node/index.d.ts +36 -0
- package/dist/adapters/node/index.mjs +32 -0
- package/dist/adapters/standard/index.d.mts +26 -0
- package/dist/adapters/standard/index.d.ts +26 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/index.d.mts +278 -0
- package/dist/index.d.ts +278 -0
- package/dist/index.mjs +342 -0
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/plugins/index.mjs +103 -0
- package/dist/shared/server.B3Tm0IXY.d.ts +75 -0
- package/dist/shared/server.BYTulgUc.d.mts +144 -0
- package/dist/shared/server.BYTulgUc.d.ts +144 -0
- package/dist/shared/server.BeJithK4.d.mts +75 -0
- package/dist/shared/server.BtxZnWJ9.mjs +374 -0
- package/dist/shared/server.Bz_xNBjz.d.mts +8 -0
- package/dist/shared/server.DoP20NVH.mjs +29 -0
- package/dist/shared/server.EhgR_5_I.d.ts +8 -0
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/dist/shared/server.jG7ZuX3S.mjs +158 -0
- package/package.json +36 -24
- package/dist/chunk-DNG2IB3R.js +0 -227
- package/dist/chunk-V3I7RIRY.js +0 -302
- package/dist/chunk-WUOGVGWG.js +0 -1
- package/dist/fetch.js +0 -15
- package/dist/hono.js +0 -30
- package/dist/index.js +0 -545
- package/dist/next.js +0 -36
- package/dist/node.js +0 -87
- package/dist/src/adapters/fetch/index.d.ts +0 -6
- package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/adapters/fetch/super-json.d.ts +0 -12
- package/dist/src/adapters/fetch/types.d.ts +0 -21
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -12
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -19
- package/dist/src/adapters/node/index.d.ts +0 -5
- package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
- package/dist/src/adapters/node/request-listener.d.ts +0 -28
- package/dist/src/adapters/node/types.d.ts +0 -22
- package/dist/src/builder.d.ts +0 -36
- package/dist/src/error.d.ts +0 -10
- package/dist/src/hidden.d.ts +0 -6
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/index.d.ts +0 -24
- package/dist/src/lazy-decorated.d.ts +0 -10
- package/dist/src/lazy-utils.d.ts +0 -4
- package/dist/src/lazy.d.ts +0 -18
- package/dist/src/middleware-decorated.d.ts +0 -9
- package/dist/src/middleware.d.ts +0 -35
- package/dist/src/procedure-builder.d.ts +0 -24
- package/dist/src/procedure-client.d.ts +0 -34
- package/dist/src/procedure-decorated.d.ts +0 -15
- package/dist/src/procedure-implementer.d.ts +0 -19
- package/dist/src/procedure.d.ts +0 -43
- package/dist/src/router-builder.d.ts +0 -29
- package/dist/src/router-client.d.ts +0 -25
- package/dist/src/router-implementer.d.ts +0 -21
- package/dist/src/router.d.ts +0 -16
- package/dist/src/types.d.ts +0 -14
- package/dist/src/utils.d.ts +0 -3
@@ -0,0 +1,31 @@
|
|
1
|
+
import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.BeJithK4.mjs';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.BeJithK4.mjs';
|
3
|
+
import { Value } from '@orpc/shared';
|
4
|
+
import { C as Context } from '../shared/server.BYTulgUc.mjs';
|
5
|
+
import '@orpc/contract';
|
6
|
+
import '@orpc/standard-server';
|
7
|
+
import '@orpc/client';
|
8
|
+
|
9
|
+
interface CORSOptions<TContext extends Context> {
|
10
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: readonly string[];
|
13
|
+
allowHeaders?: readonly string[];
|
14
|
+
maxAge?: number;
|
15
|
+
credentials?: boolean;
|
16
|
+
exposeHeaders?: readonly string[];
|
17
|
+
}
|
18
|
+
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
|
+
private readonly options;
|
20
|
+
constructor(options?: CORSOptions<TContext>);
|
21
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
22
|
+
}
|
23
|
+
|
24
|
+
interface ResponseHeadersPluginContext {
|
25
|
+
resHeaders?: Headers;
|
26
|
+
}
|
27
|
+
declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
|
28
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
29
|
+
}
|
30
|
+
|
31
|
+
export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.B3Tm0IXY.js';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.B3Tm0IXY.js';
|
3
|
+
import { Value } from '@orpc/shared';
|
4
|
+
import { C as Context } from '../shared/server.BYTulgUc.js';
|
5
|
+
import '@orpc/contract';
|
6
|
+
import '@orpc/standard-server';
|
7
|
+
import '@orpc/client';
|
8
|
+
|
9
|
+
interface CORSOptions<TContext extends Context> {
|
10
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: readonly string[];
|
13
|
+
allowHeaders?: readonly string[];
|
14
|
+
maxAge?: number;
|
15
|
+
credentials?: boolean;
|
16
|
+
exposeHeaders?: readonly string[];
|
17
|
+
}
|
18
|
+
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
|
+
private readonly options;
|
20
|
+
constructor(options?: CORSOptions<TContext>);
|
21
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
22
|
+
}
|
23
|
+
|
24
|
+
interface ResponseHeadersPluginContext {
|
25
|
+
resHeaders?: Headers;
|
26
|
+
}
|
27
|
+
declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
|
28
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
29
|
+
}
|
30
|
+
|
31
|
+
export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
@@ -0,0 +1,103 @@
|
|
1
|
+
export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
|
2
|
+
import { value } from '@orpc/shared';
|
3
|
+
|
4
|
+
class CORSPlugin {
|
5
|
+
options;
|
6
|
+
constructor(options = {}) {
|
7
|
+
const defaults = {
|
8
|
+
origin: (origin) => origin,
|
9
|
+
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
10
|
+
};
|
11
|
+
this.options = {
|
12
|
+
...defaults,
|
13
|
+
...options
|
14
|
+
};
|
15
|
+
}
|
16
|
+
init(options) {
|
17
|
+
options.rootInterceptors ??= [];
|
18
|
+
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
19
|
+
if (interceptorOptions.request.method === "OPTIONS") {
|
20
|
+
const resHeaders = {};
|
21
|
+
if (this.options.maxAge !== void 0) {
|
22
|
+
resHeaders["access-control-max-age"] = this.options.maxAge.toString();
|
23
|
+
}
|
24
|
+
if (this.options.allowMethods?.length) {
|
25
|
+
resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
|
26
|
+
}
|
27
|
+
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
28
|
+
if (Array.isArray(allowHeaders) && allowHeaders.length) {
|
29
|
+
resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
|
30
|
+
} else if (typeof allowHeaders === "string") {
|
31
|
+
resHeaders["access-control-allow-headers"] = allowHeaders;
|
32
|
+
}
|
33
|
+
return {
|
34
|
+
matched: true,
|
35
|
+
response: {
|
36
|
+
status: 204,
|
37
|
+
headers: resHeaders,
|
38
|
+
body: void 0
|
39
|
+
}
|
40
|
+
};
|
41
|
+
}
|
42
|
+
return interceptorOptions.next();
|
43
|
+
});
|
44
|
+
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
45
|
+
const result = await interceptorOptions.next();
|
46
|
+
if (!result.matched) {
|
47
|
+
return result;
|
48
|
+
}
|
49
|
+
const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
|
50
|
+
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
51
|
+
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
52
|
+
if (allowedOriginArr.includes("*")) {
|
53
|
+
result.response.headers["access-control-allow-origin"] = "*";
|
54
|
+
} else {
|
55
|
+
if (allowedOriginArr.includes(origin)) {
|
56
|
+
result.response.headers["access-control-allow-origin"] = origin;
|
57
|
+
}
|
58
|
+
result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
|
59
|
+
}
|
60
|
+
const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
|
61
|
+
const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
|
62
|
+
if (allowedTimingOriginArr.includes("*")) {
|
63
|
+
result.response.headers["timing-allow-origin"] = "*";
|
64
|
+
} else if (allowedTimingOriginArr.includes(origin)) {
|
65
|
+
result.response.headers["timing-allow-origin"] = origin;
|
66
|
+
}
|
67
|
+
if (this.options.credentials) {
|
68
|
+
result.response.headers["access-control-allow-credentials"] = "true";
|
69
|
+
}
|
70
|
+
if (this.options.exposeHeaders?.length) {
|
71
|
+
result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
|
72
|
+
}
|
73
|
+
return result;
|
74
|
+
});
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
class ResponseHeadersPlugin {
|
79
|
+
init(options) {
|
80
|
+
options.rootInterceptors ??= [];
|
81
|
+
options.rootInterceptors.push(async (interceptorOptions) => {
|
82
|
+
const headers = new Headers();
|
83
|
+
interceptorOptions.context.resHeaders = headers;
|
84
|
+
const result = await interceptorOptions.next();
|
85
|
+
if (!result.matched) {
|
86
|
+
return result;
|
87
|
+
}
|
88
|
+
const responseHeaders = result.response.headers;
|
89
|
+
for (const [key, value] of headers) {
|
90
|
+
if (Array.isArray(responseHeaders[key])) {
|
91
|
+
responseHeaders[key].push(value);
|
92
|
+
} else if (responseHeaders[key] !== void 0) {
|
93
|
+
responseHeaders[key] = [responseHeaders[key], value];
|
94
|
+
} else {
|
95
|
+
responseHeaders[key] = value;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
return result;
|
99
|
+
});
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
export { CORSPlugin, ResponseHeadersPlugin };
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.js';
|
5
|
+
import { ORPCError } from '@orpc/client';
|
6
|
+
|
7
|
+
type StandardParams = Record<string, string>;
|
8
|
+
type StandardMatchResult = {
|
9
|
+
path: readonly string[];
|
10
|
+
procedure: AnyProcedure;
|
11
|
+
params?: StandardParams;
|
12
|
+
} | undefined;
|
13
|
+
interface StandardMatcher {
|
14
|
+
init(router: AnyRouter): void;
|
15
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
16
|
+
}
|
17
|
+
interface StandardCodec {
|
18
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
19
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
|
+
}
|
22
|
+
|
23
|
+
type StandardHandleOptions<T extends Context> = {
|
24
|
+
prefix?: HTTPPath;
|
25
|
+
} & (Record<never, never> extends T ? {
|
26
|
+
context?: T;
|
27
|
+
} : {
|
28
|
+
context: T;
|
29
|
+
});
|
30
|
+
type StandardHandleResult = {
|
31
|
+
matched: true;
|
32
|
+
response: StandardResponse;
|
33
|
+
} | {
|
34
|
+
matched: false;
|
35
|
+
response: undefined;
|
36
|
+
};
|
37
|
+
type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
|
38
|
+
context: T;
|
39
|
+
request: StandardLazyRequest;
|
40
|
+
};
|
41
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
+
plugins?: HandlerPlugin<TContext>[];
|
43
|
+
/**
|
44
|
+
* Interceptors at the request level, helpful when you want catch errors
|
45
|
+
*/
|
46
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
47
|
+
/**
|
48
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
49
|
+
*/
|
50
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
* Interceptors for procedure client.
|
54
|
+
*/
|
55
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
56
|
+
}
|
57
|
+
declare class StandardHandler<T extends Context> {
|
58
|
+
private readonly matcher;
|
59
|
+
private readonly codec;
|
60
|
+
private readonly options;
|
61
|
+
private readonly plugin;
|
62
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
+
handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
64
|
+
}
|
65
|
+
|
66
|
+
interface HandlerPlugin<TContext extends Context> {
|
67
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
+
}
|
69
|
+
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
+
private readonly plugins;
|
71
|
+
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
73
|
+
}
|
74
|
+
|
75
|
+
export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
4
|
+
|
5
|
+
type Context = Record<string, any>;
|
6
|
+
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
7
|
+
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
8
|
+
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
9
|
+
type ContextExtendsGuard<T extends Context, U extends Context> = T extends U ? unknown : never;
|
10
|
+
|
11
|
+
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
12
|
+
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
13
|
+
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
14
|
+
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
15
|
+
};
|
16
|
+
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
17
|
+
declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
|
18
|
+
|
19
|
+
declare const LAZY_SYMBOL: unique symbol;
|
20
|
+
interface LazyMeta {
|
21
|
+
prefix?: HTTPPath;
|
22
|
+
}
|
23
|
+
interface Lazy<T> {
|
24
|
+
[LAZY_SYMBOL]: {
|
25
|
+
loader: () => Promise<{
|
26
|
+
default: T;
|
27
|
+
}>;
|
28
|
+
meta: LazyMeta;
|
29
|
+
};
|
30
|
+
}
|
31
|
+
type Lazyable<T> = T | Lazy<T>;
|
32
|
+
declare function lazy<T>(loader: () => Promise<{
|
33
|
+
default: T;
|
34
|
+
}>, meta?: LazyMeta): Lazy<T>;
|
35
|
+
declare function isLazy(item: unknown): item is Lazy<any>;
|
36
|
+
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
37
|
+
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
38
|
+
default: T extends Lazy<infer U> ? U : T;
|
39
|
+
}>;
|
40
|
+
|
41
|
+
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
42
|
+
context: TCurrentContext;
|
43
|
+
input: TInput;
|
44
|
+
path: readonly string[];
|
45
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
46
|
+
signal?: AbortSignal;
|
47
|
+
lastEventId: string | undefined;
|
48
|
+
errors: TErrorConstructorMap;
|
49
|
+
}
|
50
|
+
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
51
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
52
|
+
}
|
53
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
54
|
+
__initialContext?: (type: TInitialContext) => unknown;
|
55
|
+
middlewares: readonly AnyMiddleware[];
|
56
|
+
inputValidationIndex: number;
|
57
|
+
outputValidationIndex: number;
|
58
|
+
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
59
|
+
}
|
60
|
+
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
61
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
62
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
63
|
+
}
|
64
|
+
type AnyProcedure = Procedure<any, any, any, any, any, any>;
|
65
|
+
declare function isProcedure(item: unknown): item is AnyProcedure;
|
66
|
+
|
67
|
+
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
68
|
+
output: TOutput;
|
69
|
+
context: TOutContext;
|
70
|
+
}>;
|
71
|
+
type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
72
|
+
context?: TOutContext;
|
73
|
+
} : {
|
74
|
+
context: TOutContext;
|
75
|
+
};
|
76
|
+
interface MiddlewareNextFn<TOutput> {
|
77
|
+
<U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
78
|
+
}
|
79
|
+
interface MiddlewareOutputFn<TOutput> {
|
80
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
81
|
+
}
|
82
|
+
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
83
|
+
context: TInContext;
|
84
|
+
path: readonly string[];
|
85
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
86
|
+
signal?: AbortSignal;
|
87
|
+
lastEventId: string | undefined;
|
88
|
+
next: MiddlewareNextFn<TOutput>;
|
89
|
+
errors: TErrorConstructorMap;
|
90
|
+
}
|
91
|
+
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
92
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
93
|
+
}
|
94
|
+
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
95
|
+
interface MapInputMiddleware<TInput, TMappedInput> {
|
96
|
+
(input: TInput): TMappedInput;
|
97
|
+
}
|
98
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
99
|
+
|
100
|
+
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
101
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
102
|
+
context: TInitialContext;
|
103
|
+
input: InferSchemaInput<TInputSchema>;
|
104
|
+
errors: ORPCErrorConstructorMap<TErrorMap>;
|
105
|
+
path: readonly string[];
|
106
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
107
|
+
signal?: AbortSignal;
|
108
|
+
lastEventId: string | undefined;
|
109
|
+
}
|
110
|
+
/**
|
111
|
+
* Options for creating a procedure caller with comprehensive type safety
|
112
|
+
*/
|
113
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
114
|
+
/**
|
115
|
+
* This is helpful for logging and analytics.
|
116
|
+
*/
|
117
|
+
path?: readonly string[];
|
118
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
|
119
|
+
} & (Record<never, never> extends TInitialContext ? {
|
120
|
+
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
121
|
+
} : {
|
122
|
+
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
123
|
+
});
|
124
|
+
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
125
|
+
|
126
|
+
type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
|
127
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
128
|
+
};
|
129
|
+
type AnyRouter = Router<any, any>;
|
130
|
+
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
131
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
132
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
133
|
+
};
|
134
|
+
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
135
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
136
|
+
};
|
137
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
138
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
139
|
+
};
|
140
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
141
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
142
|
+
};
|
143
|
+
|
144
|
+
export { type AnyProcedure as A, type MiddlewareOptions as B, type Context as C, middlewareOutputFn as D, type ProcedureHandlerOptions as E, type ProcedureDef as F, isProcedure as G, createProcedureClient as H, type InferRouterInitialContext as I, type InferRouterInitialContexts as J, type InferRouterCurrentContexts as K, type Lazyable as L, type Middleware as M, type InferRouterInputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type InferRouterOutputs as Q, type Router as R, type AnyRouter as a, Procedure as b, type ContextExtendsGuard as c, type MergedCurrentContext as d, type MergedInitialContext as e, type MapInputMiddleware as f, type CreateProcedureClientOptions as g, type ProcedureClient as h, type AnyMiddleware as i, type Lazy as j, type ProcedureHandler as k, type ORPCErrorConstructorMapItemOptions as l, mergeCurrentContext as m, type ORPCErrorConstructorMapItem as n, createORPCErrorConstructorMap as o, LAZY_SYMBOL as p, type LazyMeta as q, lazy as r, isLazy as s, getLazyMeta as t, unlazy as u, validateORPCError as v, type MiddlewareResult as w, type MiddlewareNextFnOptions as x, type MiddlewareNextFn as y, type MiddlewareOutputFn as z };
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
4
|
+
|
5
|
+
type Context = Record<string, any>;
|
6
|
+
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
7
|
+
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
8
|
+
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
9
|
+
type ContextExtendsGuard<T extends Context, U extends Context> = T extends U ? unknown : never;
|
10
|
+
|
11
|
+
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
12
|
+
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
13
|
+
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
14
|
+
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
15
|
+
};
|
16
|
+
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
17
|
+
declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
|
18
|
+
|
19
|
+
declare const LAZY_SYMBOL: unique symbol;
|
20
|
+
interface LazyMeta {
|
21
|
+
prefix?: HTTPPath;
|
22
|
+
}
|
23
|
+
interface Lazy<T> {
|
24
|
+
[LAZY_SYMBOL]: {
|
25
|
+
loader: () => Promise<{
|
26
|
+
default: T;
|
27
|
+
}>;
|
28
|
+
meta: LazyMeta;
|
29
|
+
};
|
30
|
+
}
|
31
|
+
type Lazyable<T> = T | Lazy<T>;
|
32
|
+
declare function lazy<T>(loader: () => Promise<{
|
33
|
+
default: T;
|
34
|
+
}>, meta?: LazyMeta): Lazy<T>;
|
35
|
+
declare function isLazy(item: unknown): item is Lazy<any>;
|
36
|
+
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
37
|
+
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
38
|
+
default: T extends Lazy<infer U> ? U : T;
|
39
|
+
}>;
|
40
|
+
|
41
|
+
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
42
|
+
context: TCurrentContext;
|
43
|
+
input: TInput;
|
44
|
+
path: readonly string[];
|
45
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
46
|
+
signal?: AbortSignal;
|
47
|
+
lastEventId: string | undefined;
|
48
|
+
errors: TErrorConstructorMap;
|
49
|
+
}
|
50
|
+
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
51
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
52
|
+
}
|
53
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
54
|
+
__initialContext?: (type: TInitialContext) => unknown;
|
55
|
+
middlewares: readonly AnyMiddleware[];
|
56
|
+
inputValidationIndex: number;
|
57
|
+
outputValidationIndex: number;
|
58
|
+
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
59
|
+
}
|
60
|
+
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
61
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
62
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
63
|
+
}
|
64
|
+
type AnyProcedure = Procedure<any, any, any, any, any, any>;
|
65
|
+
declare function isProcedure(item: unknown): item is AnyProcedure;
|
66
|
+
|
67
|
+
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
68
|
+
output: TOutput;
|
69
|
+
context: TOutContext;
|
70
|
+
}>;
|
71
|
+
type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
72
|
+
context?: TOutContext;
|
73
|
+
} : {
|
74
|
+
context: TOutContext;
|
75
|
+
};
|
76
|
+
interface MiddlewareNextFn<TOutput> {
|
77
|
+
<U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
78
|
+
}
|
79
|
+
interface MiddlewareOutputFn<TOutput> {
|
80
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
81
|
+
}
|
82
|
+
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
83
|
+
context: TInContext;
|
84
|
+
path: readonly string[];
|
85
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
86
|
+
signal?: AbortSignal;
|
87
|
+
lastEventId: string | undefined;
|
88
|
+
next: MiddlewareNextFn<TOutput>;
|
89
|
+
errors: TErrorConstructorMap;
|
90
|
+
}
|
91
|
+
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
92
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
93
|
+
}
|
94
|
+
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
95
|
+
interface MapInputMiddleware<TInput, TMappedInput> {
|
96
|
+
(input: TInput): TMappedInput;
|
97
|
+
}
|
98
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
99
|
+
|
100
|
+
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
101
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
102
|
+
context: TInitialContext;
|
103
|
+
input: InferSchemaInput<TInputSchema>;
|
104
|
+
errors: ORPCErrorConstructorMap<TErrorMap>;
|
105
|
+
path: readonly string[];
|
106
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
107
|
+
signal?: AbortSignal;
|
108
|
+
lastEventId: string | undefined;
|
109
|
+
}
|
110
|
+
/**
|
111
|
+
* Options for creating a procedure caller with comprehensive type safety
|
112
|
+
*/
|
113
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
114
|
+
/**
|
115
|
+
* This is helpful for logging and analytics.
|
116
|
+
*/
|
117
|
+
path?: readonly string[];
|
118
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
|
119
|
+
} & (Record<never, never> extends TInitialContext ? {
|
120
|
+
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
121
|
+
} : {
|
122
|
+
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
123
|
+
});
|
124
|
+
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
125
|
+
|
126
|
+
type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
|
127
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
128
|
+
};
|
129
|
+
type AnyRouter = Router<any, any>;
|
130
|
+
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
131
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
132
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
133
|
+
};
|
134
|
+
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
135
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
136
|
+
};
|
137
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
138
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
139
|
+
};
|
140
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
141
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
142
|
+
};
|
143
|
+
|
144
|
+
export { type AnyProcedure as A, type MiddlewareOptions as B, type Context as C, middlewareOutputFn as D, type ProcedureHandlerOptions as E, type ProcedureDef as F, isProcedure as G, createProcedureClient as H, type InferRouterInitialContext as I, type InferRouterInitialContexts as J, type InferRouterCurrentContexts as K, type Lazyable as L, type Middleware as M, type InferRouterInputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type InferRouterOutputs as Q, type Router as R, type AnyRouter as a, Procedure as b, type ContextExtendsGuard as c, type MergedCurrentContext as d, type MergedInitialContext as e, type MapInputMiddleware as f, type CreateProcedureClientOptions as g, type ProcedureClient as h, type AnyMiddleware as i, type Lazy as j, type ProcedureHandler as k, type ORPCErrorConstructorMapItemOptions as l, mergeCurrentContext as m, type ORPCErrorConstructorMapItem as n, createORPCErrorConstructorMap as o, LAZY_SYMBOL as p, type LazyMeta as q, lazy as r, isLazy as s, getLazyMeta as t, unlazy as u, validateORPCError as v, type MiddlewareResult as w, type MiddlewareNextFnOptions as x, type MiddlewareNextFn as y, type MiddlewareOutputFn as z };
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.mjs';
|
5
|
+
import { ORPCError } from '@orpc/client';
|
6
|
+
|
7
|
+
type StandardParams = Record<string, string>;
|
8
|
+
type StandardMatchResult = {
|
9
|
+
path: readonly string[];
|
10
|
+
procedure: AnyProcedure;
|
11
|
+
params?: StandardParams;
|
12
|
+
} | undefined;
|
13
|
+
interface StandardMatcher {
|
14
|
+
init(router: AnyRouter): void;
|
15
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
16
|
+
}
|
17
|
+
interface StandardCodec {
|
18
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
19
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
|
+
}
|
22
|
+
|
23
|
+
type StandardHandleOptions<T extends Context> = {
|
24
|
+
prefix?: HTTPPath;
|
25
|
+
} & (Record<never, never> extends T ? {
|
26
|
+
context?: T;
|
27
|
+
} : {
|
28
|
+
context: T;
|
29
|
+
});
|
30
|
+
type StandardHandleResult = {
|
31
|
+
matched: true;
|
32
|
+
response: StandardResponse;
|
33
|
+
} | {
|
34
|
+
matched: false;
|
35
|
+
response: undefined;
|
36
|
+
};
|
37
|
+
type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
|
38
|
+
context: T;
|
39
|
+
request: StandardLazyRequest;
|
40
|
+
};
|
41
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
+
plugins?: HandlerPlugin<TContext>[];
|
43
|
+
/**
|
44
|
+
* Interceptors at the request level, helpful when you want catch errors
|
45
|
+
*/
|
46
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
47
|
+
/**
|
48
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
49
|
+
*/
|
50
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
* Interceptors for procedure client.
|
54
|
+
*/
|
55
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
56
|
+
}
|
57
|
+
declare class StandardHandler<T extends Context> {
|
58
|
+
private readonly matcher;
|
59
|
+
private readonly codec;
|
60
|
+
private readonly options;
|
61
|
+
private readonly plugin;
|
62
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
+
handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
64
|
+
}
|
65
|
+
|
66
|
+
interface HandlerPlugin<TContext extends Context> {
|
67
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
+
}
|
69
|
+
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
+
private readonly plugins;
|
71
|
+
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
73
|
+
}
|
74
|
+
|
75
|
+
export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|