@orpc/server 0.46.0 → 1.0.0-beta.1
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 +3 -1
- package/dist/adapters/fetch/index.d.mts +5 -4
- package/dist/adapters/fetch/index.d.ts +5 -4
- package/dist/adapters/fetch/index.mjs +4 -4
- package/dist/adapters/hono/index.d.mts +4 -3
- package/dist/adapters/hono/index.d.ts +4 -3
- package/dist/adapters/hono/index.mjs +4 -4
- package/dist/adapters/next/index.d.mts +4 -3
- package/dist/adapters/next/index.d.ts +4 -3
- package/dist/adapters/next/index.mjs +4 -4
- package/dist/adapters/node/index.d.mts +5 -4
- package/dist/adapters/node/index.d.ts +5 -4
- package/dist/adapters/node/index.mjs +8 -6
- package/dist/adapters/standard/index.d.mts +10 -13
- package/dist/adapters/standard/index.d.ts +10 -13
- package/dist/adapters/standard/index.mjs +2 -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 +1 -1
- package/dist/shared/{server.B-ewprcf.d.ts → server.B3Tm0IXY.d.ts} +12 -14
- package/dist/shared/server.BYTulgUc.d.mts +144 -0
- package/dist/shared/server.BYTulgUc.d.ts +144 -0
- package/dist/shared/{server.DJrh0Ceu.d.mts → server.BeJithK4.d.mts} +12 -14
- package/dist/shared/{server.V6zT5iYQ.mjs → server.BtxZnWJ9.mjs} +155 -160
- package/dist/shared/server.Bz_xNBjz.d.mts +8 -0
- package/dist/shared/{server.KwueCzFr.mjs → server.DoP20NVH.mjs} +7 -4
- package/dist/shared/server.EhgR_5_I.d.ts +8 -0
- package/dist/shared/{server.BBGuTxHE.mjs → server.jG7ZuX3S.mjs} +14 -19
- package/package.json +7 -7
- package/dist/shared/server.CA-o8cUY.d.mts +0 -9
- package/dist/shared/server.Cn9ybJtE.d.mts +0 -152
- package/dist/shared/server.Cn9ybJtE.d.ts +0 -152
- package/dist/shared/server.DPQt9YYq.d.ts +0 -9
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.BYTulgUc.js';
|
3
|
+
import { a as StandardHandlerOptions } from './server.B3Tm0IXY.js';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import { ORPCError, toORPCError } from '@orpc/client';
|
2
2
|
import { intercept, trim, parseEmptyableJSON } from '@orpc/shared';
|
3
3
|
import { C as CompositePlugin } from './server.Q6ZmnTgO.mjs';
|
4
|
-
import { c as createProcedureClient,
|
5
|
-
import { RPCSerializer } from '@orpc/client/standard';
|
4
|
+
import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.BtxZnWJ9.mjs';
|
6
5
|
|
7
6
|
class StandardHandler {
|
8
|
-
constructor(router, matcher, codec, options
|
7
|
+
constructor(router, matcher, codec, options) {
|
9
8
|
this.matcher = matcher;
|
10
9
|
this.codec = codec;
|
11
10
|
this.options = options;
|
@@ -70,10 +69,9 @@ class StandardHandler {
|
|
70
69
|
}
|
71
70
|
}
|
72
71
|
|
73
|
-
class
|
74
|
-
serializer
|
75
|
-
|
76
|
-
this.serializer = options.serializer ?? new RPCSerializer();
|
72
|
+
class StandardRPCCodec {
|
73
|
+
constructor(serializer) {
|
74
|
+
this.serializer = serializer;
|
77
75
|
}
|
78
76
|
async decode(request, _params, _procedure) {
|
79
77
|
const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
|
@@ -95,15 +93,12 @@ class RPCCodec {
|
|
95
93
|
}
|
96
94
|
}
|
97
95
|
|
98
|
-
class
|
96
|
+
class StandardRPCMatcher {
|
99
97
|
tree = {};
|
100
98
|
pendingRouters = [];
|
101
99
|
init(router, path = []) {
|
102
|
-
const laziedOptions =
|
103
|
-
|
104
|
-
path
|
105
|
-
}, ({ path: path2, contract }) => {
|
106
|
-
const httpPath = convertPathToHttpPath(path2);
|
100
|
+
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
101
|
+
const httpPath = toHttpPath(path2);
|
107
102
|
if (isProcedure(contract)) {
|
108
103
|
this.tree[httpPath] = {
|
109
104
|
path: path2,
|
@@ -123,7 +118,7 @@ class RPCMatcher {
|
|
123
118
|
});
|
124
119
|
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
125
120
|
...option,
|
126
|
-
httpPathPrefix:
|
121
|
+
httpPathPrefix: toHttpPath(option.path)
|
127
122
|
})));
|
128
123
|
}
|
129
124
|
async match(_method, pathname) {
|
@@ -131,7 +126,7 @@ class RPCMatcher {
|
|
131
126
|
const newPendingRouters = [];
|
132
127
|
for (const pendingRouter of this.pendingRouters) {
|
133
128
|
if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
134
|
-
const { default: router } = await unlazy(pendingRouter.
|
129
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
135
130
|
this.init(router, pendingRouter.path);
|
136
131
|
} else {
|
137
132
|
newPendingRouters.push(pendingRouter);
|
@@ -144,14 +139,14 @@ class RPCMatcher {
|
|
144
139
|
return void 0;
|
145
140
|
}
|
146
141
|
if (!match.procedure) {
|
147
|
-
const { default: maybeProcedure } = await unlazy(
|
142
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
|
148
143
|
if (!isProcedure(maybeProcedure)) {
|
149
144
|
throw new Error(`
|
150
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${
|
145
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
|
151
146
|
Ensure that the procedure is correctly defined and matches the expected contract.
|
152
147
|
`);
|
153
148
|
}
|
154
|
-
match.procedure = createContractedProcedure(match.contract
|
149
|
+
match.procedure = createContractedProcedure(maybeProcedure, match.contract);
|
155
150
|
}
|
156
151
|
return {
|
157
152
|
path: match.path,
|
@@ -160,4 +155,4 @@ class RPCMatcher {
|
|
160
155
|
}
|
161
156
|
}
|
162
157
|
|
163
|
-
export {
|
158
|
+
export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "1.0.0-beta.1",
|
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/
|
63
|
-
"@orpc/standard-server": "0.
|
64
|
-
"@orpc/standard-server-fetch": "0.
|
65
|
-
"@orpc/
|
66
|
-
"@orpc/
|
61
|
+
"@orpc/client": "1.0.0-beta.1",
|
62
|
+
"@orpc/shared": "1.0.0-beta.1",
|
63
|
+
"@orpc/standard-server": "1.0.0-beta.1",
|
64
|
+
"@orpc/standard-server-fetch": "1.0.0-beta.1",
|
65
|
+
"@orpc/standard-server-node": "1.0.0-beta.1",
|
66
|
+
"@orpc/contract": "1.0.0-beta.1"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
69
|
"light-my-request": "^6.5.1"
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import { C as Context } from './server.Cn9ybJtE.mjs';
|
2
|
-
import { a as StandardHandlerOptions, b as StandardMatcher, c as StandardCodec } from './server.DJrh0Ceu.mjs';
|
3
|
-
|
4
|
-
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
|
5
|
-
matcher?: StandardMatcher;
|
6
|
-
codec?: StandardCodec;
|
7
|
-
}
|
8
|
-
|
9
|
-
export type { RPCHandlerOptions as R };
|
@@ -1,152 +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 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> : {
|
135
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
136
|
-
};
|
137
|
-
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> : {
|
138
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
139
|
-
};
|
140
|
-
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> : {
|
141
|
-
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
142
|
-
};
|
143
|
-
interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
144
|
-
middlewares: AnyMiddleware[];
|
145
|
-
tags?: readonly string[];
|
146
|
-
prefix?: HTTPPath;
|
147
|
-
errorMap: TErrorMap;
|
148
|
-
}
|
149
|
-
declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
150
|
-
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;
|
151
|
-
|
152
|
-
export { type AnyProcedure as A, type ProcedureDef as B, type Context as C, isProcedure as D, createProcedureClient as E, type InferRouterInputs as F, type InferRouterOutputs as G, adaptRouter as H, type InferRouterInitialContext as I, getRouterChild as J, type AccessibleLazyRouter as K, type Lazy as L, type Middleware as M, createAccessibleLazyRouter as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, 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,152 +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 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> : {
|
135
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
136
|
-
};
|
137
|
-
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> : {
|
138
|
-
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
139
|
-
};
|
140
|
-
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> : {
|
141
|
-
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
142
|
-
};
|
143
|
-
interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
144
|
-
middlewares: AnyMiddleware[];
|
145
|
-
tags?: readonly string[];
|
146
|
-
prefix?: HTTPPath;
|
147
|
-
errorMap: TErrorMap;
|
148
|
-
}
|
149
|
-
declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
150
|
-
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;
|
151
|
-
|
152
|
-
export { type AnyProcedure as A, type ProcedureDef as B, type Context as C, isProcedure as D, createProcedureClient as E, type InferRouterInputs as F, type InferRouterOutputs as G, adaptRouter as H, type InferRouterInitialContext as I, getRouterChild as J, type AccessibleLazyRouter as K, type Lazy as L, type Middleware as M, createAccessibleLazyRouter as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, 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,9 +0,0 @@
|
|
1
|
-
import { C as Context } from './server.Cn9ybJtE.js';
|
2
|
-
import { a as StandardHandlerOptions, b as StandardMatcher, c as StandardCodec } from './server.B-ewprcf.js';
|
3
|
-
|
4
|
-
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
|
5
|
-
matcher?: StandardMatcher;
|
6
|
-
codec?: StandardCodec;
|
7
|
-
}
|
8
|
-
|
9
|
-
export type { RPCHandlerOptions as R };
|