@orpc/server 0.47.0 → 0.49.0
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 +5 -1
- package/dist/adapters/fetch/index.d.mts +5 -3
- package/dist/adapters/fetch/index.d.ts +5 -3
- package/dist/adapters/fetch/index.mjs +4 -4
- package/dist/adapters/hono/index.d.mts +4 -2
- package/dist/adapters/hono/index.d.ts +4 -2
- package/dist/adapters/hono/index.mjs +4 -4
- package/dist/adapters/next/index.d.mts +4 -2
- package/dist/adapters/next/index.d.ts +4 -2
- package/dist/adapters/next/index.mjs +4 -4
- package/dist/adapters/node/index.d.mts +5 -3
- package/dist/adapters/node/index.d.ts +5 -3
- package/dist/adapters/node/index.mjs +8 -7
- package/dist/adapters/standard/index.d.mts +10 -9
- package/dist/adapters/standard/index.d.ts +10 -9
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +140 -117
- package/dist/index.d.ts +140 -117
- package/dist/index.mjs +55 -46
- package/dist/plugins/index.d.mts +12 -12
- package/dist/plugins/index.d.ts +12 -12
- package/dist/plugins/index.mjs +2 -2
- package/dist/shared/server.B52eKaNe.d.mts +8 -0
- package/dist/shared/server.BA-onDGB.d.ts +8 -0
- package/dist/shared/{server.DKrKGnk2.mjs → server.BY9sDlwl.mjs} +13 -16
- package/dist/shared/server.BYTulgUc.d.mts +144 -0
- package/dist/shared/server.BYTulgUc.d.ts +144 -0
- package/dist/shared/{server.V6zT5iYQ.mjs → server.BtxZnWJ9.mjs} +155 -160
- package/dist/shared/{server.Drm1Lma3.d.ts → server.CDzXh8DM.d.mts} +12 -14
- package/dist/shared/{server.CtBp-i4f.d.mts → server.CkGvC2T0.d.ts} +12 -14
- package/dist/shared/{server.Q6ZmnTgO.mjs → server.Dba3Iiyp.mjs} +2 -2
- package/dist/shared/{server.BHIDiY4a.mjs → server.Del5OmaY.mjs} +6 -5
- package/package.json +7 -7
- package/dist/shared/server.ptXwNGQr.d.mts +0 -158
- package/dist/shared/server.ptXwNGQr.d.ts +0 -158
@@ -1,12 +1,12 @@
|
|
1
|
-
import { HTTPPath,
|
1
|
+
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
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.
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.js';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
8
8
|
type StandardMatchResult = {
|
9
|
-
path: string[];
|
9
|
+
path: readonly string[];
|
10
10
|
procedure: AnyProcedure;
|
11
11
|
params?: StandardParams;
|
12
12
|
} | undefined;
|
@@ -27,9 +27,6 @@ type StandardHandleOptions<T extends Context> = {
|
|
27
27
|
} : {
|
28
28
|
context: T;
|
29
29
|
});
|
30
|
-
type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
31
|
-
context: T;
|
32
|
-
};
|
33
30
|
type StandardHandleResult = {
|
34
31
|
matched: true;
|
35
32
|
response: StandardResponse;
|
@@ -37,11 +34,12 @@ type StandardHandleResult = {
|
|
37
34
|
matched: false;
|
38
35
|
response: undefined;
|
39
36
|
};
|
40
|
-
type StandardHandlerInterceptorOptions<
|
37
|
+
type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
|
38
|
+
context: T;
|
41
39
|
request: StandardLazyRequest;
|
42
40
|
};
|
43
41
|
interface StandardHandlerOptions<TContext extends Context> {
|
44
|
-
plugins?:
|
42
|
+
plugins?: HandlerPlugin<TContext>[];
|
45
43
|
/**
|
46
44
|
* Interceptors at the request level, helpful when you want catch errors
|
47
45
|
*/
|
@@ -54,24 +52,24 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
54
52
|
*
|
55
53
|
* Interceptors for procedure client.
|
56
54
|
*/
|
57
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext,
|
55
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
58
56
|
}
|
59
57
|
declare class StandardHandler<T extends Context> {
|
60
58
|
private readonly matcher;
|
61
59
|
private readonly codec;
|
62
60
|
private readonly options;
|
63
61
|
private readonly plugin;
|
64
|
-
constructor(router: Router<
|
62
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
65
63
|
handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
66
64
|
}
|
67
65
|
|
68
|
-
interface
|
66
|
+
interface HandlerPlugin<TContext extends Context> {
|
69
67
|
init?(options: StandardHandlerOptions<TContext>): void;
|
70
68
|
}
|
71
|
-
declare class
|
69
|
+
declare class CompositeHandlerPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
72
70
|
private readonly plugins;
|
73
|
-
constructor(plugins?:
|
71
|
+
constructor(plugins?: HandlerPlugin<TContext>[]);
|
74
72
|
init(options: StandardHandlerOptions<TContext>): void;
|
75
73
|
}
|
76
74
|
|
77
|
-
export {
|
75
|
+
export { CompositeHandlerPlugin 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 };
|
@@ -1,13 +1,14 @@
|
|
1
|
-
import {
|
1
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
2
|
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
-
import { S as StandardHandler,
|
3
|
+
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.BY9sDlwl.mjs';
|
4
4
|
|
5
5
|
class RPCHandler {
|
6
6
|
standardHandler;
|
7
7
|
constructor(router, options = {}) {
|
8
|
-
const
|
9
|
-
const
|
10
|
-
const
|
8
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
9
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
10
|
+
const matcher = new StandardRPCMatcher();
|
11
|
+
const codec = new StandardRPCCodec(serializer);
|
11
12
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
12
13
|
}
|
13
14
|
async handle(request, ...[
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.49.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -58,12 +58,12 @@
|
|
58
58
|
"next": ">=14.0.0"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@orpc/client": "0.
|
62
|
-
"@orpc/contract": "0.
|
63
|
-
"@orpc/
|
64
|
-
"@orpc/
|
65
|
-
"@orpc/standard-server-node": "0.
|
66
|
-
"@orpc/standard-server-fetch": "0.
|
61
|
+
"@orpc/client": "0.49.0",
|
62
|
+
"@orpc/contract": "0.49.0",
|
63
|
+
"@orpc/shared": "0.49.0",
|
64
|
+
"@orpc/standard-server": "0.49.0",
|
65
|
+
"@orpc/standard-server-node": "0.49.0",
|
66
|
+
"@orpc/standard-server-fetch": "0.49.0"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
69
|
"light-my-request": "^6.5.1"
|
@@ -1,158 +0,0 @@
|
|
1
|
-
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
-
import { IsNever, MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
-
import { ErrorMap, ErrorMapItem, SchemaInput, HTTPPath, Meta, Schema, ContractProcedureDef, SchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure, MergedErrorMap } from '@orpc/contract';
|
4
|
-
|
5
|
-
type Context = Record<string, any>;
|
6
|
-
type MergedContext<T extends Context, U extends Context> = T & U;
|
7
|
-
declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
|
8
|
-
type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
9
|
-
[K in keyof T]: IsNever<T[K]>;
|
10
|
-
}[keyof T] ? never : unknown;
|
11
|
-
|
12
|
-
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
13
|
-
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
14
|
-
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
15
|
-
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
|
16
|
-
};
|
17
|
-
|
18
|
-
declare const LAZY_LOADER_SYMBOL: unique symbol;
|
19
|
-
interface LazyMeta {
|
20
|
-
prefix?: HTTPPath;
|
21
|
-
}
|
22
|
-
interface Lazy<T> {
|
23
|
-
[LAZY_LOADER_SYMBOL](): Promise<{
|
24
|
-
default: T;
|
25
|
-
}>;
|
26
|
-
}
|
27
|
-
type Lazyable<T> = T | Lazy<T>;
|
28
|
-
interface LazyOptions {
|
29
|
-
prefix?: HTTPPath;
|
30
|
-
}
|
31
|
-
declare function lazy<T>(loader: () => Promise<{
|
32
|
-
default: T;
|
33
|
-
}>): Lazy<T>;
|
34
|
-
declare function isLazy(item: unknown): item is Lazy<any>;
|
35
|
-
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
36
|
-
default: T extends Lazy<infer U> ? U : T;
|
37
|
-
}>;
|
38
|
-
|
39
|
-
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
40
|
-
output: TOutput;
|
41
|
-
context: TOutContext;
|
42
|
-
}>;
|
43
|
-
type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
44
|
-
context?: TOutContext;
|
45
|
-
} : {
|
46
|
-
context: TOutContext;
|
47
|
-
};
|
48
|
-
interface MiddlewareNextFn<TInContext extends Context, TOutput> {
|
49
|
-
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
50
|
-
}
|
51
|
-
interface MiddlewareOutputFn<TOutput> {
|
52
|
-
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
53
|
-
}
|
54
|
-
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
55
|
-
context: TInContext;
|
56
|
-
path: string[];
|
57
|
-
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
58
|
-
signal?: AbortSignal;
|
59
|
-
lastEventId: string | undefined;
|
60
|
-
next: MiddlewareNextFn<TInContext, TOutput>;
|
61
|
-
errors: TErrorConstructorMap;
|
62
|
-
}
|
63
|
-
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
64
|
-
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
65
|
-
}
|
66
|
-
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
67
|
-
interface MapInputMiddleware<TInput, TMappedInput> {
|
68
|
-
(input: TInput): TMappedInput;
|
69
|
-
}
|
70
|
-
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
71
|
-
|
72
|
-
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
73
|
-
context: TCurrentContext;
|
74
|
-
input: TInput;
|
75
|
-
path: string[];
|
76
|
-
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
77
|
-
signal?: AbortSignal;
|
78
|
-
lastEventId: string | undefined;
|
79
|
-
errors: TErrorConstructorMap;
|
80
|
-
}
|
81
|
-
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
82
|
-
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
83
|
-
}
|
84
|
-
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
85
|
-
__initialContext?: (type: TInitialContext) => unknown;
|
86
|
-
middlewares: AnyMiddleware[];
|
87
|
-
inputValidationIndex: number;
|
88
|
-
outputValidationIndex: number;
|
89
|
-
handler: ProcedureHandler<TCurrentContext, any, THandlerOutput, any, any>;
|
90
|
-
}
|
91
|
-
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
92
|
-
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
93
|
-
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>);
|
94
|
-
}
|
95
|
-
type AnyProcedure = Procedure<any, any, any, any, any, any, any>;
|
96
|
-
declare function isProcedure(item: unknown): item is AnyProcedure;
|
97
|
-
|
98
|
-
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
99
|
-
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
100
|
-
context: TInitialContext;
|
101
|
-
input: SchemaInput<TInputSchema>;
|
102
|
-
errors: ORPCErrorConstructorMap<TErrorMap>;
|
103
|
-
path: string[];
|
104
|
-
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
105
|
-
signal?: AbortSignal;
|
106
|
-
lastEventId: string | undefined;
|
107
|
-
}
|
108
|
-
/**
|
109
|
-
* Options for creating a procedure caller with comprehensive type safety
|
110
|
-
*/
|
111
|
-
type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
112
|
-
/**
|
113
|
-
* This is helpful for logging and analytics.
|
114
|
-
*/
|
115
|
-
path?: string[];
|
116
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>[];
|
117
|
-
} & (Record<never, never> extends TInitialContext ? {
|
118
|
-
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
119
|
-
} : {
|
120
|
-
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
121
|
-
});
|
122
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
123
|
-
|
124
|
-
type AccessibleLazyRouter<T extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : Lazy<T> & (T extends AnyProcedure | undefined ? unknown : {
|
125
|
-
[K in keyof T]: T[K] extends AnyRouter ? AccessibleLazyRouter<T[K]> : never;
|
126
|
-
});
|
127
|
-
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
128
|
-
|
129
|
-
type Router<TInitialContext extends Context, TContract extends AnyContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap, UMeta> : {
|
130
|
-
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
|
131
|
-
}>;
|
132
|
-
type AnyRouter = Router<any, any>;
|
133
|
-
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer UInitialContext, any> ? UInitialContext : never;
|
134
|
-
type InferRouterInitialContexts<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : T extends Procedure<infer UInitialContext, any, any, any, any, any, any> ? UInitialContext : {
|
135
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInitialContexts<T[K]> : never;
|
136
|
-
};
|
137
|
-
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : T extends Procedure<any, infer UCurrentContext, any, any, any, any, any> ? UCurrentContext : {
|
138
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterCurrentContexts<T[K]> : never;
|
139
|
-
};
|
140
|
-
type InferRouterInputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
|
141
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
142
|
-
};
|
143
|
-
type InferRouterOutputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
144
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
145
|
-
};
|
146
|
-
type AdaptedRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap> = TRouter extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<AdaptedRouter<U, TInitialContext, TErrorMap>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
147
|
-
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
148
|
-
};
|
149
|
-
interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
150
|
-
middlewares: AnyMiddleware[];
|
151
|
-
tags?: readonly string[];
|
152
|
-
prefix?: HTTPPath;
|
153
|
-
errorMap: TErrorMap;
|
154
|
-
}
|
155
|
-
declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
156
|
-
declare function getRouterChild<T extends AnyRouter | Lazy<undefined>>(router: T, ...path: string[]): T extends Lazy<any> ? Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter>> | Lazy<undefined> : AnyRouter | Lazy<undefined> | undefined;
|
157
|
-
|
158
|
-
export { type AnyProcedure as A, type ProcedureDef as B, type Context as C, isProcedure as D, createProcedureClient as E, type InferRouterInitialContexts as F, type InferRouterCurrentContexts as G, type InferRouterInputs as H, type InferRouterInitialContext as I, type InferRouterOutputs as J, adaptRouter as K, type Lazy as L, type Middleware as M, getRouterChild as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type AccessibleLazyRouter as Q, type Router as R, createAccessibleLazyRouter as S, type AnyRouter as a, Procedure as b, type ConflictContextGuard as c, type MergedContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type ProcedureHandler as h, type AdaptRouterOptions as i, type AdaptedRouter as j, type AnyMiddleware as k, type Lazyable as l, mergeContext as m, LAZY_LOADER_SYMBOL as n, type LazyMeta as o, type LazyOptions as p, lazy as q, isLazy as r, type MiddlewareResult as s, type MiddlewareNextFnOptions as t, unlazy as u, type MiddlewareNextFn as v, type MiddlewareOutputFn as w, type MiddlewareOptions as x, middlewareOutputFn as y, type ProcedureHandlerOptions as z };
|
@@ -1,158 +0,0 @@
|
|
1
|
-
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
-
import { IsNever, MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
-
import { ErrorMap, ErrorMapItem, SchemaInput, HTTPPath, Meta, Schema, ContractProcedureDef, SchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure, MergedErrorMap } from '@orpc/contract';
|
4
|
-
|
5
|
-
type Context = Record<string, any>;
|
6
|
-
type MergedContext<T extends Context, U extends Context> = T & U;
|
7
|
-
declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
|
8
|
-
type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
9
|
-
[K in keyof T]: IsNever<T[K]>;
|
10
|
-
}[keyof T] ? never : unknown;
|
11
|
-
|
12
|
-
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
13
|
-
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
14
|
-
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
15
|
-
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
|
16
|
-
};
|
17
|
-
|
18
|
-
declare const LAZY_LOADER_SYMBOL: unique symbol;
|
19
|
-
interface LazyMeta {
|
20
|
-
prefix?: HTTPPath;
|
21
|
-
}
|
22
|
-
interface Lazy<T> {
|
23
|
-
[LAZY_LOADER_SYMBOL](): Promise<{
|
24
|
-
default: T;
|
25
|
-
}>;
|
26
|
-
}
|
27
|
-
type Lazyable<T> = T | Lazy<T>;
|
28
|
-
interface LazyOptions {
|
29
|
-
prefix?: HTTPPath;
|
30
|
-
}
|
31
|
-
declare function lazy<T>(loader: () => Promise<{
|
32
|
-
default: T;
|
33
|
-
}>): Lazy<T>;
|
34
|
-
declare function isLazy(item: unknown): item is Lazy<any>;
|
35
|
-
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
36
|
-
default: T extends Lazy<infer U> ? U : T;
|
37
|
-
}>;
|
38
|
-
|
39
|
-
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
40
|
-
output: TOutput;
|
41
|
-
context: TOutContext;
|
42
|
-
}>;
|
43
|
-
type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
44
|
-
context?: TOutContext;
|
45
|
-
} : {
|
46
|
-
context: TOutContext;
|
47
|
-
};
|
48
|
-
interface MiddlewareNextFn<TInContext extends Context, TOutput> {
|
49
|
-
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
50
|
-
}
|
51
|
-
interface MiddlewareOutputFn<TOutput> {
|
52
|
-
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
53
|
-
}
|
54
|
-
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
55
|
-
context: TInContext;
|
56
|
-
path: string[];
|
57
|
-
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
58
|
-
signal?: AbortSignal;
|
59
|
-
lastEventId: string | undefined;
|
60
|
-
next: MiddlewareNextFn<TInContext, TOutput>;
|
61
|
-
errors: TErrorConstructorMap;
|
62
|
-
}
|
63
|
-
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
64
|
-
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
65
|
-
}
|
66
|
-
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
67
|
-
interface MapInputMiddleware<TInput, TMappedInput> {
|
68
|
-
(input: TInput): TMappedInput;
|
69
|
-
}
|
70
|
-
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
71
|
-
|
72
|
-
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
73
|
-
context: TCurrentContext;
|
74
|
-
input: TInput;
|
75
|
-
path: string[];
|
76
|
-
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
77
|
-
signal?: AbortSignal;
|
78
|
-
lastEventId: string | undefined;
|
79
|
-
errors: TErrorConstructorMap;
|
80
|
-
}
|
81
|
-
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
82
|
-
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
83
|
-
}
|
84
|
-
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
85
|
-
__initialContext?: (type: TInitialContext) => unknown;
|
86
|
-
middlewares: AnyMiddleware[];
|
87
|
-
inputValidationIndex: number;
|
88
|
-
outputValidationIndex: number;
|
89
|
-
handler: ProcedureHandler<TCurrentContext, any, THandlerOutput, any, any>;
|
90
|
-
}
|
91
|
-
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
92
|
-
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
93
|
-
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>);
|
94
|
-
}
|
95
|
-
type AnyProcedure = Procedure<any, any, any, any, any, any, any>;
|
96
|
-
declare function isProcedure(item: unknown): item is AnyProcedure;
|
97
|
-
|
98
|
-
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
99
|
-
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
100
|
-
context: TInitialContext;
|
101
|
-
input: SchemaInput<TInputSchema>;
|
102
|
-
errors: ORPCErrorConstructorMap<TErrorMap>;
|
103
|
-
path: string[];
|
104
|
-
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
105
|
-
signal?: AbortSignal;
|
106
|
-
lastEventId: string | undefined;
|
107
|
-
}
|
108
|
-
/**
|
109
|
-
* Options for creating a procedure caller with comprehensive type safety
|
110
|
-
*/
|
111
|
-
type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
112
|
-
/**
|
113
|
-
* This is helpful for logging and analytics.
|
114
|
-
*/
|
115
|
-
path?: string[];
|
116
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>[];
|
117
|
-
} & (Record<never, never> extends TInitialContext ? {
|
118
|
-
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
119
|
-
} : {
|
120
|
-
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
121
|
-
});
|
122
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
123
|
-
|
124
|
-
type AccessibleLazyRouter<T extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : Lazy<T> & (T extends AnyProcedure | undefined ? unknown : {
|
125
|
-
[K in keyof T]: T[K] extends AnyRouter ? AccessibleLazyRouter<T[K]> : never;
|
126
|
-
});
|
127
|
-
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
128
|
-
|
129
|
-
type Router<TInitialContext extends Context, TContract extends AnyContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap, UMeta> : {
|
130
|
-
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
|
131
|
-
}>;
|
132
|
-
type AnyRouter = Router<any, any>;
|
133
|
-
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer UInitialContext, any> ? UInitialContext : never;
|
134
|
-
type InferRouterInitialContexts<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : T extends Procedure<infer UInitialContext, any, any, any, any, any, any> ? UInitialContext : {
|
135
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInitialContexts<T[K]> : never;
|
136
|
-
};
|
137
|
-
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : T extends Procedure<any, infer UCurrentContext, any, any, any, any, any> ? UCurrentContext : {
|
138
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterCurrentContexts<T[K]> : never;
|
139
|
-
};
|
140
|
-
type InferRouterInputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
|
141
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
142
|
-
};
|
143
|
-
type InferRouterOutputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
144
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
145
|
-
};
|
146
|
-
type AdaptedRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap> = TRouter extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<AdaptedRouter<U, TInitialContext, TErrorMap>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
147
|
-
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
148
|
-
};
|
149
|
-
interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
150
|
-
middlewares: AnyMiddleware[];
|
151
|
-
tags?: readonly string[];
|
152
|
-
prefix?: HTTPPath;
|
153
|
-
errorMap: TErrorMap;
|
154
|
-
}
|
155
|
-
declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
156
|
-
declare function getRouterChild<T extends AnyRouter | Lazy<undefined>>(router: T, ...path: string[]): T extends Lazy<any> ? Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter>> | Lazy<undefined> : AnyRouter | Lazy<undefined> | undefined;
|
157
|
-
|
158
|
-
export { type AnyProcedure as A, type ProcedureDef as B, type Context as C, isProcedure as D, createProcedureClient as E, type InferRouterInitialContexts as F, type InferRouterCurrentContexts as G, type InferRouterInputs as H, type InferRouterInitialContext as I, type InferRouterOutputs as J, adaptRouter as K, type Lazy as L, type Middleware as M, getRouterChild as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type AccessibleLazyRouter as Q, type Router as R, createAccessibleLazyRouter as S, type AnyRouter as a, Procedure as b, type ConflictContextGuard as c, type MergedContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type ProcedureHandler as h, type AdaptRouterOptions as i, type AdaptedRouter as j, type AnyMiddleware as k, type Lazyable as l, mergeContext as m, LAZY_LOADER_SYMBOL as n, type LazyMeta as o, type LazyOptions as p, lazy as q, isLazy as r, type MiddlewareResult as s, type MiddlewareNextFnOptions as t, unlazy as u, type MiddlewareNextFn as v, type MiddlewareOutputFn as w, type MiddlewareOptions as x, middlewareOutputFn as y, type ProcedureHandlerOptions as z };
|