@orpc/server 0.0.0-next.a8e421c → 0.0.0-next.a910d34
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 +27 -23
- package/dist/adapters/aws-lambda/index.d.mts +46 -0
- package/dist/adapters/aws-lambda/index.d.ts +46 -0
- package/dist/adapters/aws-lambda/index.mjs +42 -0
- package/dist/adapters/bun-ws/index.d.mts +36 -0
- package/dist/adapters/bun-ws/index.d.ts +36 -0
- package/dist/adapters/bun-ws/index.mjs +47 -0
- package/dist/adapters/crossws/index.d.mts +33 -0
- package/dist/adapters/crossws/index.d.ts +33 -0
- package/dist/adapters/crossws/index.mjs +47 -0
- package/dist/adapters/fetch/index.d.mts +62 -11
- package/dist/adapters/fetch/index.d.ts +62 -11
- package/dist/adapters/fetch/index.mjs +109 -8
- package/dist/adapters/message-port/index.d.mts +31 -0
- package/dist/adapters/message-port/index.d.ts +31 -0
- package/dist/adapters/message-port/index.mjs +41 -0
- package/dist/adapters/node/index.d.mts +64 -22
- package/dist/adapters/node/index.d.ts +64 -22
- package/dist/adapters/node/index.mjs +88 -24
- package/dist/adapters/standard/index.d.mts +8 -13
- package/dist/adapters/standard/index.d.ts +8 -13
- package/dist/adapters/standard/index.mjs +5 -3
- package/dist/adapters/standard-peer/index.d.mts +14 -0
- package/dist/adapters/standard-peer/index.d.ts +14 -0
- package/dist/adapters/standard-peer/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +54 -0
- package/dist/adapters/websocket/index.d.ts +54 -0
- package/dist/adapters/websocket/index.mjs +69 -0
- package/dist/adapters/ws/index.d.mts +31 -0
- package/dist/adapters/ws/index.d.ts +31 -0
- package/dist/adapters/ws/index.mjs +39 -0
- package/dist/helpers/index.d.mts +130 -0
- package/dist/helpers/index.d.ts +130 -0
- package/dist/helpers/index.mjs +182 -0
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +609 -84
- package/dist/index.d.ts +609 -84
- package/dist/index.mjs +162 -15
- package/dist/plugins/index.d.mts +154 -16
- package/dist/plugins/index.d.ts +154 -16
- package/dist/plugins/index.mjs +189 -16
- package/dist/shared/server.B7b2w3_i.d.ts +12 -0
- package/dist/shared/server.BEFBl-Cb.d.mts +12 -0
- package/dist/shared/server.BU4WI18A.d.mts +32 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.Bmh5xd4n.d.ts +74 -0
- package/dist/shared/server.C6Q5sqYw.mjs +20 -0
- package/dist/shared/{server.BY9sDlwl.mjs → server.CIL9uKTN.mjs} +66 -30
- package/dist/shared/{server.BYTulgUc.d.mts → server.CYNGeoCm.d.mts} +66 -16
- package/dist/shared/{server.BYTulgUc.d.ts → server.CYNGeoCm.d.ts} +66 -16
- package/dist/shared/server.D0H-iaY3.d.ts +32 -0
- package/dist/shared/server.DZ5BIITo.mjs +9 -0
- package/dist/shared/server.DhJj-1X9.d.mts +42 -0
- package/dist/shared/{server.BtxZnWJ9.mjs → server.NeumLVdS.mjs} +34 -38
- package/dist/shared/server.gqRxT-yN.d.mts +74 -0
- package/dist/shared/server.jMTkVNIb.d.ts +42 -0
- package/package.json +70 -20
- package/dist/adapters/hono/index.d.mts +0 -21
- package/dist/adapters/hono/index.d.ts +0 -21
- package/dist/adapters/hono/index.mjs +0 -32
- package/dist/adapters/next/index.d.mts +0 -28
- package/dist/adapters/next/index.d.ts +0 -28
- package/dist/adapters/next/index.mjs +0 -29
- package/dist/shared/server.B52eKaNe.d.mts +0 -8
- package/dist/shared/server.BA-onDGB.d.ts +0 -8
- package/dist/shared/server.CDzXh8DM.d.mts +0 -75
- package/dist/shared/server.CkGvC2T0.d.ts +0 -75
- package/dist/shared/server.Dba3Iiyp.mjs +0 -12
- package/dist/shared/server.Del5OmaY.mjs +0 -29
@@ -1,51 +1,69 @@
|
|
1
|
+
import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
1
2
|
import { ORPCError, toORPCError } from '@orpc/client';
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import { c as createProcedureClient, t as traverseContractProcedures,
|
3
|
+
import { toArray, intercept, parseEmptyableJSON, NullProtoObj, value } from '@orpc/shared';
|
4
|
+
import { flattenHeader } from '@orpc/standard-server';
|
5
|
+
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.NeumLVdS.mjs';
|
6
|
+
|
7
|
+
class CompositeStandardHandlerPlugin {
|
8
|
+
plugins;
|
9
|
+
constructor(plugins = []) {
|
10
|
+
this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
11
|
+
}
|
12
|
+
init(options, router) {
|
13
|
+
for (const plugin of this.plugins) {
|
14
|
+
plugin.init?.(options, router);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
5
18
|
|
6
19
|
class StandardHandler {
|
7
20
|
constructor(router, matcher, codec, options) {
|
8
21
|
this.matcher = matcher;
|
9
22
|
this.codec = codec;
|
10
|
-
|
11
|
-
|
12
|
-
this.
|
23
|
+
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
|
24
|
+
plugins.init(options, router);
|
25
|
+
this.interceptors = toArray(options.interceptors);
|
26
|
+
this.clientInterceptors = toArray(options.clientInterceptors);
|
27
|
+
this.rootInterceptors = toArray(options.rootInterceptors);
|
13
28
|
this.matcher.init(router);
|
14
29
|
}
|
15
|
-
|
16
|
-
|
30
|
+
interceptors;
|
31
|
+
clientInterceptors;
|
32
|
+
rootInterceptors;
|
33
|
+
async handle(request, options) {
|
34
|
+
const prefix = options.prefix?.replace(/\/$/, "") || void 0;
|
35
|
+
if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
|
36
|
+
return { matched: false, response: void 0 };
|
37
|
+
}
|
17
38
|
return intercept(
|
18
|
-
this.
|
19
|
-
{
|
20
|
-
request,
|
21
|
-
...options,
|
22
|
-
context: options?.context ?? {}
|
23
|
-
// context is optional only when all fields are optional so we can safely force it to have a context
|
24
|
-
},
|
39
|
+
this.rootInterceptors,
|
40
|
+
{ ...options, request, prefix },
|
25
41
|
async (interceptorOptions) => {
|
26
42
|
let isDecoding = false;
|
27
43
|
try {
|
28
44
|
return await intercept(
|
29
|
-
this.
|
45
|
+
this.interceptors,
|
30
46
|
interceptorOptions,
|
31
|
-
async (
|
32
|
-
const method =
|
33
|
-
const url =
|
34
|
-
const pathname =
|
35
|
-
const match = await this.matcher.match(method, pathname);
|
47
|
+
async ({ request: request2, context, prefix: prefix2 }) => {
|
48
|
+
const method = request2.method;
|
49
|
+
const url = request2.url;
|
50
|
+
const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
|
51
|
+
const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
|
36
52
|
if (!match) {
|
37
53
|
return { matched: false, response: void 0 };
|
38
54
|
}
|
39
55
|
const client = createProcedureClient(match.procedure, {
|
40
|
-
context
|
56
|
+
context,
|
41
57
|
path: match.path,
|
42
|
-
interceptors: this.
|
58
|
+
interceptors: this.clientInterceptors
|
43
59
|
});
|
44
60
|
isDecoding = true;
|
45
|
-
const input = await this.codec.decode(
|
61
|
+
const input = await this.codec.decode(request2, match.params, match.procedure);
|
46
62
|
isDecoding = false;
|
47
|
-
const
|
48
|
-
|
63
|
+
const output = await client(input, {
|
64
|
+
signal: request2.signal,
|
65
|
+
lastEventId: flattenHeader(request2.headers["last-event-id"])
|
66
|
+
});
|
49
67
|
const response = this.codec.encode(output, match.procedure);
|
50
68
|
return {
|
51
69
|
matched: true,
|
@@ -54,7 +72,7 @@ class StandardHandler {
|
|
54
72
|
}
|
55
73
|
);
|
56
74
|
} catch (e) {
|
57
|
-
const error = isDecoding ? new ORPCError("BAD_REQUEST", {
|
75
|
+
const error = isDecoding && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
|
58
76
|
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
59
77
|
cause: e
|
60
78
|
}) : toORPCError(e);
|
@@ -94,10 +112,18 @@ class StandardRPCCodec {
|
|
94
112
|
}
|
95
113
|
|
96
114
|
class StandardRPCMatcher {
|
97
|
-
|
115
|
+
filter;
|
116
|
+
tree = new NullProtoObj();
|
98
117
|
pendingRouters = [];
|
118
|
+
constructor(options = {}) {
|
119
|
+
this.filter = options.filter ?? true;
|
120
|
+
}
|
99
121
|
init(router, path = []) {
|
100
|
-
const laziedOptions = traverseContractProcedures({ router, path }, (
|
122
|
+
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
|
123
|
+
if (!value(this.filter, traverseOptions)) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
const { path: path2, contract } = traverseOptions;
|
101
127
|
const httpPath = toHttpPath(path2);
|
102
128
|
if (isProcedure(contract)) {
|
103
129
|
this.tree[httpPath] = {
|
@@ -155,4 +181,14 @@ class StandardRPCMatcher {
|
|
155
181
|
}
|
156
182
|
}
|
157
183
|
|
158
|
-
|
184
|
+
class StandardRPCHandler extends StandardHandler {
|
185
|
+
constructor(router, options = {}) {
|
186
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
187
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
188
|
+
const matcher = new StandardRPCMatcher(options);
|
189
|
+
const codec = new StandardRPCCodec(serializer);
|
190
|
+
super(router, matcher, codec, options);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardRPCCodec as a, StandardRPCHandler as b, StandardRPCMatcher as c };
|
@@ -1,12 +1,11 @@
|
|
1
|
-
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
-
import {
|
3
|
-
import {
|
1
|
+
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
|
2
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
3
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, Value } from '@orpc/shared';
|
4
4
|
|
5
|
-
type Context = Record<
|
5
|
+
type Context = Record<PropertyKey, any>;
|
6
6
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
7
7
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
8
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
9
|
|
11
10
|
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
12
11
|
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
@@ -29,6 +28,11 @@ interface Lazy<T> {
|
|
29
28
|
};
|
30
29
|
}
|
31
30
|
type Lazyable<T> = T | Lazy<T>;
|
31
|
+
/**
|
32
|
+
* Creates a lazy-loaded item.
|
33
|
+
*
|
34
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead.
|
35
|
+
*/
|
32
36
|
declare function lazy<T>(loader: () => Promise<{
|
33
37
|
default: T;
|
34
38
|
}>, meta?: LazyMeta): Lazy<T>;
|
@@ -57,7 +61,15 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
|
|
57
61
|
outputValidationIndex: number;
|
58
62
|
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
59
63
|
}
|
64
|
+
/**
|
65
|
+
* This class represents a procedure.
|
66
|
+
*
|
67
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
68
|
+
*/
|
60
69
|
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
70
|
+
/**
|
71
|
+
* This property holds the defined options.
|
72
|
+
*/
|
61
73
|
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
62
74
|
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
63
75
|
}
|
@@ -88,6 +100,11 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
|
|
88
100
|
next: MiddlewareNextFn<TOutput>;
|
89
101
|
errors: TErrorConstructorMap;
|
90
102
|
}
|
103
|
+
/**
|
104
|
+
* A function that represents a middleware.
|
105
|
+
*
|
106
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
107
|
+
*/
|
91
108
|
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
92
109
|
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
93
110
|
}
|
@@ -98,47 +115,80 @@ interface MapInputMiddleware<TInput, TMappedInput> {
|
|
98
115
|
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
99
116
|
|
100
117
|
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,
|
118
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
102
119
|
context: TInitialContext;
|
103
|
-
input:
|
120
|
+
input: unknown;
|
104
121
|
errors: ORPCErrorConstructorMap<TErrorMap>;
|
105
122
|
path: readonly string[];
|
106
123
|
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
107
124
|
signal?: AbortSignal;
|
108
125
|
lastEventId: string | undefined;
|
109
126
|
}
|
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> = {
|
127
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
114
128
|
/**
|
115
129
|
* This is helpful for logging and analytics.
|
116
130
|
*/
|
117
131
|
path?: readonly string[];
|
118
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext,
|
132
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
119
133
|
} & (Record<never, never> extends TInitialContext ? {
|
120
|
-
context?: Value<TInitialContext
|
134
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
121
135
|
} : {
|
122
|
-
context: Value<TInitialContext
|
136
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
123
137
|
});
|
124
|
-
|
138
|
+
/**
|
139
|
+
* Create Server-side client from a procedure.
|
140
|
+
*
|
141
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
142
|
+
*/
|
143
|
+
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>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
125
144
|
|
145
|
+
/**
|
146
|
+
* Represents a router, which defines a hierarchical structure of procedures.
|
147
|
+
*
|
148
|
+
* @info A procedure is a router too.
|
149
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
150
|
+
*/
|
126
151
|
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
152
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
128
153
|
};
|
129
154
|
type AnyRouter = Router<any, any>;
|
130
155
|
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
156
|
+
/**
|
157
|
+
* Infer all initial context of the router.
|
158
|
+
*
|
159
|
+
* @info A procedure is a router too.
|
160
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
161
|
+
*/
|
131
162
|
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
132
163
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
133
164
|
};
|
165
|
+
/**
|
166
|
+
* Infer all current context of the router.
|
167
|
+
*
|
168
|
+
* @info A procedure is a router too.
|
169
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
170
|
+
*/
|
134
171
|
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
135
172
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
136
173
|
};
|
174
|
+
/**
|
175
|
+
* Infer all router inputs
|
176
|
+
*
|
177
|
+
* @info A procedure is a router too.
|
178
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
179
|
+
*/
|
137
180
|
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
138
181
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
139
182
|
};
|
183
|
+
/**
|
184
|
+
* Infer all router outputs
|
185
|
+
*
|
186
|
+
* @info A procedure is a router too.
|
187
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
188
|
+
*/
|
140
189
|
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
141
190
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
142
191
|
};
|
143
192
|
|
144
|
-
export {
|
193
|
+
export { middlewareOutputFn as B, isProcedure as F, createProcedureClient as G, Procedure as P, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, validateORPCError as v };
|
194
|
+
export type { AnyProcedure as A, Context as C, ProcedureHandlerOptions as D, ProcedureDef as E, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, MergedInitialContext as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, AnyMiddleware as a, AnyRouter as b, Lazy as c, ProcedureClientInterceptorOptions as d, Middleware as e, MergedCurrentContext as f, MapInputMiddleware as g, CreateProcedureClientOptions as h, ProcedureClient as i, ProcedureHandler as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as t, MiddlewareNextFnOptions as w, MiddlewareNextFn as x, MiddlewareOutputFn as y, MiddlewareOptions as z };
|
@@ -1,12 +1,11 @@
|
|
1
|
-
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
-
import {
|
3
|
-
import {
|
1
|
+
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
|
2
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
3
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, Value } from '@orpc/shared';
|
4
4
|
|
5
|
-
type Context = Record<
|
5
|
+
type Context = Record<PropertyKey, any>;
|
6
6
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
7
7
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
8
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
9
|
|
11
10
|
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
12
11
|
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
@@ -29,6 +28,11 @@ interface Lazy<T> {
|
|
29
28
|
};
|
30
29
|
}
|
31
30
|
type Lazyable<T> = T | Lazy<T>;
|
31
|
+
/**
|
32
|
+
* Creates a lazy-loaded item.
|
33
|
+
*
|
34
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead.
|
35
|
+
*/
|
32
36
|
declare function lazy<T>(loader: () => Promise<{
|
33
37
|
default: T;
|
34
38
|
}>, meta?: LazyMeta): Lazy<T>;
|
@@ -57,7 +61,15 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
|
|
57
61
|
outputValidationIndex: number;
|
58
62
|
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
59
63
|
}
|
64
|
+
/**
|
65
|
+
* This class represents a procedure.
|
66
|
+
*
|
67
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
68
|
+
*/
|
60
69
|
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
70
|
+
/**
|
71
|
+
* This property holds the defined options.
|
72
|
+
*/
|
61
73
|
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
62
74
|
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
63
75
|
}
|
@@ -88,6 +100,11 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
|
|
88
100
|
next: MiddlewareNextFn<TOutput>;
|
89
101
|
errors: TErrorConstructorMap;
|
90
102
|
}
|
103
|
+
/**
|
104
|
+
* A function that represents a middleware.
|
105
|
+
*
|
106
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
107
|
+
*/
|
91
108
|
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
92
109
|
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
93
110
|
}
|
@@ -98,47 +115,80 @@ interface MapInputMiddleware<TInput, TMappedInput> {
|
|
98
115
|
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
99
116
|
|
100
117
|
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,
|
118
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
102
119
|
context: TInitialContext;
|
103
|
-
input:
|
120
|
+
input: unknown;
|
104
121
|
errors: ORPCErrorConstructorMap<TErrorMap>;
|
105
122
|
path: readonly string[];
|
106
123
|
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
107
124
|
signal?: AbortSignal;
|
108
125
|
lastEventId: string | undefined;
|
109
126
|
}
|
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> = {
|
127
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
114
128
|
/**
|
115
129
|
* This is helpful for logging and analytics.
|
116
130
|
*/
|
117
131
|
path?: readonly string[];
|
118
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext,
|
132
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
119
133
|
} & (Record<never, never> extends TInitialContext ? {
|
120
|
-
context?: Value<TInitialContext
|
134
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
121
135
|
} : {
|
122
|
-
context: Value<TInitialContext
|
136
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
123
137
|
});
|
124
|
-
|
138
|
+
/**
|
139
|
+
* Create Server-side client from a procedure.
|
140
|
+
*
|
141
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
142
|
+
*/
|
143
|
+
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>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
125
144
|
|
145
|
+
/**
|
146
|
+
* Represents a router, which defines a hierarchical structure of procedures.
|
147
|
+
*
|
148
|
+
* @info A procedure is a router too.
|
149
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
150
|
+
*/
|
126
151
|
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
152
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
128
153
|
};
|
129
154
|
type AnyRouter = Router<any, any>;
|
130
155
|
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
156
|
+
/**
|
157
|
+
* Infer all initial context of the router.
|
158
|
+
*
|
159
|
+
* @info A procedure is a router too.
|
160
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
161
|
+
*/
|
131
162
|
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
132
163
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
133
164
|
};
|
165
|
+
/**
|
166
|
+
* Infer all current context of the router.
|
167
|
+
*
|
168
|
+
* @info A procedure is a router too.
|
169
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
170
|
+
*/
|
134
171
|
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
135
172
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
136
173
|
};
|
174
|
+
/**
|
175
|
+
* Infer all router inputs
|
176
|
+
*
|
177
|
+
* @info A procedure is a router too.
|
178
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
179
|
+
*/
|
137
180
|
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
138
181
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
139
182
|
};
|
183
|
+
/**
|
184
|
+
* Infer all router outputs
|
185
|
+
*
|
186
|
+
* @info A procedure is a router too.
|
187
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
188
|
+
*/
|
140
189
|
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
141
190
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
142
191
|
};
|
143
192
|
|
144
|
-
export {
|
193
|
+
export { middlewareOutputFn as B, isProcedure as F, createProcedureClient as G, Procedure as P, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, validateORPCError as v };
|
194
|
+
export type { AnyProcedure as A, Context as C, ProcedureHandlerOptions as D, ProcedureDef as E, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, MergedInitialContext as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, AnyMiddleware as a, AnyRouter as b, Lazy as c, ProcedureClientInterceptorOptions as d, Middleware as e, MergedCurrentContext as f, MapInputMiddleware as g, CreateProcedureClientOptions as h, ProcedureClient as i, ProcedureHandler as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as t, MiddlewareNextFnOptions as w, MiddlewareNextFn as x, MiddlewareOutputFn as y, MiddlewareOptions as z };
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { b as AnyRouter, C as Context, R as Router } from './server.CYNGeoCm.js';
|
3
|
+
import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.Bmh5xd4n.js';
|
4
|
+
import { HTTPPath } from '@orpc/client';
|
5
|
+
import { Value } from '@orpc/shared';
|
6
|
+
import { T as TraverseContractProcedureCallbackOptions } from './server.jMTkVNIb.js';
|
7
|
+
|
8
|
+
interface StandardRPCMatcherOptions {
|
9
|
+
/**
|
10
|
+
* Filter procedures. Return `false` to exclude a procedure from matching.
|
11
|
+
*
|
12
|
+
* @default true
|
13
|
+
*/
|
14
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
15
|
+
}
|
16
|
+
declare class StandardRPCMatcher implements StandardMatcher {
|
17
|
+
private readonly filter;
|
18
|
+
private readonly tree;
|
19
|
+
private pendingRouters;
|
20
|
+
constructor(options?: StandardRPCMatcherOptions);
|
21
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
22
|
+
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
23
|
+
}
|
24
|
+
|
25
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions, StandardRPCMatcherOptions {
|
26
|
+
}
|
27
|
+
declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
|
28
|
+
constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
|
29
|
+
}
|
30
|
+
|
31
|
+
export { StandardRPCHandler as a, StandardRPCMatcher as c };
|
32
|
+
export type { StandardRPCHandlerOptions as S, StandardRPCMatcherOptions as b };
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { ErrorMap, EnhanceRouteOptions, MergedErrorMap, AnyContractRouter, AnyContractProcedure } from '@orpc/contract';
|
2
|
+
import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.CYNGeoCm.mjs';
|
3
|
+
|
4
|
+
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
5
|
+
type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
|
6
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
7
|
+
};
|
8
|
+
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
9
|
+
type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>> : T extends Procedure<infer UInitialContext, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
10
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
|
11
|
+
};
|
12
|
+
interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
13
|
+
middlewares: readonly AnyMiddleware[];
|
14
|
+
errorMap: TErrorMap;
|
15
|
+
dedupeLeadingMiddlewares: boolean;
|
16
|
+
}
|
17
|
+
declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap>(router: T, options: EnhanceRouterOptions<TErrorMap>): EnhancedRouter<T, TInitialContext, TCurrentContext, TErrorMap>;
|
18
|
+
interface TraverseContractProceduresOptions {
|
19
|
+
router: AnyContractRouter | AnyRouter;
|
20
|
+
path: readonly string[];
|
21
|
+
}
|
22
|
+
interface TraverseContractProcedureCallbackOptions {
|
23
|
+
contract: AnyContractProcedure | AnyProcedure;
|
24
|
+
path: readonly string[];
|
25
|
+
}
|
26
|
+
/**
|
27
|
+
* @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
|
28
|
+
*/
|
29
|
+
type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
|
30
|
+
interface LazyTraverseContractProceduresOptions {
|
31
|
+
router: Lazy<AnyRouter>;
|
32
|
+
path: readonly string[];
|
33
|
+
}
|
34
|
+
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
35
|
+
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
|
36
|
+
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
37
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
38
|
+
};
|
39
|
+
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
40
|
+
|
41
|
+
export { createAccessibleLazyRouter as c, enhanceRouter as e, getRouter as g, resolveContractProcedures as r, traverseContractProcedures as t, unlazyRouter as u };
|
42
|
+
export type { AccessibleLazyRouter as A, ContractProcedureCallbackOptions as C, EnhanceRouterOptions as E, LazyTraverseContractProceduresOptions as L, TraverseContractProcedureCallbackOptions as T, UnlaziedRouter as U, EnhancedRouter as a, TraverseContractProceduresOptions as b };
|