@orpc/server 0.43.0 → 0.45.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 +1 -1
- package/dist/adapters/fetch/index.d.mts +27 -0
- package/dist/adapters/fetch/index.d.ts +27 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +20 -0
- package/dist/adapters/hono/index.d.ts +20 -0
- package/dist/{hono.js → adapters/hono/index.mjs} +11 -13
- package/dist/adapters/next/index.d.mts +27 -0
- package/dist/adapters/next/index.d.ts +27 -0
- package/dist/{next.js → adapters/next/index.mjs} +11 -13
- package/dist/adapters/node/index.d.mts +35 -0
- package/dist/adapters/node/index.d.ts +35 -0
- package/dist/adapters/node/index.mjs +28 -0
- package/dist/adapters/standard/index.d.mts +29 -0
- package/dist/adapters/standard/index.d.ts +29 -0
- package/dist/adapters/standard/index.mjs +7 -0
- package/dist/index.d.mts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/{index.js → index.mjs} +33 -113
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/{chunk-TXHKQO7N.js → plugins/index.mjs} +11 -28
- package/dist/{chunk-TV5DRAST.js → shared/server.BBGuTxHE.mjs} +12 -31
- package/dist/shared/server.B_cAGti1.d.mts +9 -0
- package/dist/{chunk-WDY5PTME.js → shared/server.CUE4Aija.mjs} +8 -16
- package/dist/shared/server.Cn9ybJtE.d.mts +152 -0
- package/dist/shared/server.Cn9ybJtE.d.ts +152 -0
- package/dist/shared/server.CynXWJja.d.ts +9 -0
- package/dist/shared/server.D86dtDX_.d.mts +77 -0
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/dist/{chunk-MHVECKBC.js → shared/server.V6zT5iYQ.mjs} +48 -90
- package/dist/shared/server.dPmfqnQI.d.ts +77 -0
- package/package.json +29 -34
- package/dist/fetch.js +0 -10
- package/dist/node.js +0 -31
- package/dist/plugins.js +0 -11
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/fetch/types.d.ts +0 -14
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -12
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -19
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/node/types.d.ts +0 -22
- package/dist/src/adapters/standard/handler.d.ts +0 -53
- package/dist/src/adapters/standard/index.d.ts +0 -6
- package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
- package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
- package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
- package/dist/src/adapters/standard/types.d.ts +0 -21
- package/dist/src/builder-variants.d.ts +0 -75
- package/dist/src/builder.d.ts +0 -58
- package/dist/src/config.d.ts +0 -6
- package/dist/src/context.d.ts +0 -8
- package/dist/src/error.d.ts +0 -12
- package/dist/src/hidden.d.ts +0 -8
- package/dist/src/implementer-procedure.d.ts +0 -33
- package/dist/src/implementer-variants.d.ts +0 -18
- package/dist/src/implementer.d.ts +0 -29
- package/dist/src/index.d.ts +0 -25
- package/dist/src/lazy-utils.d.ts +0 -6
- package/dist/src/lazy.d.ts +0 -22
- package/dist/src/middleware-decorated.d.ts +0 -11
- package/dist/src/middleware-utils.d.ts +0 -5
- package/dist/src/middleware.d.ts +0 -38
- package/dist/src/plugins/base.d.ts +0 -11
- package/dist/src/plugins/cors.d.ts +0 -19
- package/dist/src/plugins/index.d.ts +0 -4
- package/dist/src/plugins/response-headers.d.ts +0 -10
- package/dist/src/procedure-client.d.ts +0 -33
- package/dist/src/procedure-decorated.d.ts +0 -24
- package/dist/src/procedure-utils.d.ts +0 -19
- package/dist/src/procedure.d.ts +0 -31
- package/dist/src/router-accessible-lazy.d.ts +0 -8
- package/dist/src/router-client.d.ts +0 -12
- package/dist/src/router.d.ts +0 -30
- package/dist/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -13
@@ -0,0 +1,152 @@
|
|
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 };
|
@@ -0,0 +1,152 @@
|
|
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 };
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { C as Context } from './server.Cn9ybJtE.js';
|
2
|
+
import { a as StandardHandlerOptions, b as StandardMatcher, c as StandardCodec } from './server.dPmfqnQI.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 };
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { HTTPPath, Schema, Meta, SchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { StandardResponse, StandardRequest } from '@orpc/standard-server';
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.Cn9ybJtE.mjs';
|
5
|
+
import { ORPCError } from '@orpc/client';
|
6
|
+
|
7
|
+
type StandardParams = Record<string, string>;
|
8
|
+
type StandardMatchResult = {
|
9
|
+
path: string[];
|
10
|
+
procedure: AnyProcedure;
|
11
|
+
params?: StandardParams;
|
12
|
+
} | undefined;
|
13
|
+
interface StandardMatcher {
|
14
|
+
init(router: AnyRouter): void;
|
15
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
16
|
+
}
|
17
|
+
interface StandardCodec {
|
18
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
19
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
|
+
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
|
+
}
|
22
|
+
|
23
|
+
type StandardHandleOptions<T extends Context> = {
|
24
|
+
prefix?: HTTPPath;
|
25
|
+
} & (Record<never, never> extends T ? {
|
26
|
+
context?: T;
|
27
|
+
} : {
|
28
|
+
context: T;
|
29
|
+
});
|
30
|
+
type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
31
|
+
context: T;
|
32
|
+
};
|
33
|
+
type StandardHandleResult = {
|
34
|
+
matched: true;
|
35
|
+
response: StandardResponse;
|
36
|
+
} | {
|
37
|
+
matched: false;
|
38
|
+
response: undefined;
|
39
|
+
};
|
40
|
+
type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
|
41
|
+
request: StandardRequest;
|
42
|
+
};
|
43
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
44
|
+
plugins?: Plugin<TContext>[];
|
45
|
+
/**
|
46
|
+
* Interceptors at the request level, helpful when you want catch errors
|
47
|
+
*/
|
48
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
49
|
+
/**
|
50
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
51
|
+
*/
|
52
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
53
|
+
/**
|
54
|
+
*
|
55
|
+
* Interceptors for procedure client.
|
56
|
+
*/
|
57
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Schema, Record<never, never>, Meta>, SchemaOutput<Schema, unknown>, ErrorFromErrorMap<Record<never, never>>>[];
|
58
|
+
}
|
59
|
+
declare class StandardHandler<T extends Context> {
|
60
|
+
private readonly matcher;
|
61
|
+
private readonly codec;
|
62
|
+
private readonly options;
|
63
|
+
private readonly plugin;
|
64
|
+
constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
|
65
|
+
handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
66
|
+
}
|
67
|
+
|
68
|
+
interface Plugin<TContext extends Context> {
|
69
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
70
|
+
}
|
71
|
+
declare class CompositePlugin<TContext extends Context> implements Plugin<TContext> {
|
72
|
+
private readonly plugins;
|
73
|
+
constructor(plugins?: Plugin<TContext>[]);
|
74
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
75
|
+
}
|
76
|
+
|
77
|
+
export { CompositePlugin as C, type Plugin as P, type StandardHandleOptions as S, type WellStandardHandleOptions as W, type StandardHandlerOptions as a, type StandardMatcher as b, type StandardCodec as c, type StandardHandlerInterceptorOptions as d, type StandardParams as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
|
2
|
+
import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, adaptRoute } from '@orpc/contract';
|
3
|
+
import { value, intercept, toError } from '@orpc/shared';
|
4
|
+
|
5
|
+
const LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
3
6
|
function lazy(loader) {
|
4
7
|
return {
|
5
8
|
[LAZY_LOADER_SYMBOL]: loader
|
@@ -12,14 +15,12 @@ function unlazy(lazied) {
|
|
12
15
|
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
13
16
|
}
|
14
17
|
|
15
|
-
|
16
|
-
import { isContractProcedure } from "@orpc/contract";
|
17
|
-
var Procedure = class {
|
18
|
+
class Procedure {
|
18
19
|
"~orpc";
|
19
20
|
constructor(def) {
|
20
21
|
this["~orpc"] = def;
|
21
22
|
}
|
22
|
-
}
|
23
|
+
}
|
23
24
|
function isProcedure(item) {
|
24
25
|
if (item instanceof Procedure) {
|
25
26
|
return true;
|
@@ -27,7 +28,6 @@ function isProcedure(item) {
|
|
27
28
|
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
28
29
|
}
|
29
30
|
|
30
|
-
// src/lazy-utils.ts
|
31
31
|
function flatLazy(lazied) {
|
32
32
|
const flattenLoader = async () => {
|
33
33
|
let current = await unlazy(lazied);
|
@@ -56,18 +56,24 @@ function createLazyProcedureFormAnyLazy(lazied) {
|
|
56
56
|
return lazyProcedure;
|
57
57
|
}
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
function dedupeMiddlewares(compare, middlewares) {
|
60
|
+
let min = 0;
|
61
|
+
for (let i = 0; i < middlewares.length; i++) {
|
62
|
+
const index = compare.indexOf(middlewares[i], min);
|
63
|
+
if (index === -1) {
|
64
|
+
return middlewares.slice(i);
|
65
|
+
}
|
66
|
+
min = index + 1;
|
67
|
+
}
|
68
|
+
return [];
|
69
|
+
}
|
70
|
+
function mergeMiddlewares(first, second) {
|
71
|
+
return [...first, ...dedupeMiddlewares(first, second)];
|
72
|
+
}
|
73
|
+
function addMiddleware(middlewares, addition) {
|
74
|
+
return [...middlewares, addition];
|
62
75
|
}
|
63
76
|
|
64
|
-
// src/procedure-client.ts
|
65
|
-
import { ORPCError as ORPCError2 } from "@orpc/client";
|
66
|
-
import { ValidationError } from "@orpc/contract";
|
67
|
-
import { intercept, toError, value } from "@orpc/shared";
|
68
|
-
|
69
|
-
// src/error.ts
|
70
|
-
import { fallbackORPCErrorStatus, ORPCError } from "@orpc/client";
|
71
77
|
function createORPCErrorConstructorMap(errors) {
|
72
78
|
const proxy = new Proxy(errors, {
|
73
79
|
get(target, code) {
|
@@ -105,7 +111,10 @@ async function validateORPCError(map, error) {
|
|
105
111
|
return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
|
106
112
|
}
|
107
113
|
|
108
|
-
|
114
|
+
function middlewareOutputFn(output) {
|
115
|
+
return { output, context: {} };
|
116
|
+
}
|
117
|
+
|
109
118
|
function createProcedureClient(lazyableProcedure, ...[options]) {
|
110
119
|
return async (...[input, callerOptions]) => {
|
111
120
|
const path = options?.path ?? [];
|
@@ -129,7 +138,7 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
129
138
|
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
130
139
|
);
|
131
140
|
} catch (e) {
|
132
|
-
if (!(e instanceof
|
141
|
+
if (!(e instanceof ORPCError)) {
|
133
142
|
throw toError(e);
|
134
143
|
}
|
135
144
|
const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
|
@@ -144,7 +153,7 @@ async function validateInput(procedure, input) {
|
|
144
153
|
}
|
145
154
|
const result = await schema["~standard"].validate(input);
|
146
155
|
if (result.issues) {
|
147
|
-
throw new
|
156
|
+
throw new ORPCError("BAD_REQUEST", {
|
148
157
|
message: "Input validation failed",
|
149
158
|
data: {
|
150
159
|
issues: result.issues
|
@@ -161,7 +170,7 @@ async function validateOutput(procedure, output) {
|
|
161
170
|
}
|
162
171
|
const result = await schema["~standard"].validate(output);
|
163
172
|
if (result.issues) {
|
164
|
-
throw new
|
173
|
+
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
165
174
|
message: "Output validation failed",
|
166
175
|
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
167
176
|
});
|
@@ -196,8 +205,7 @@ async function executeProcedureInternal(procedure, options) {
|
|
196
205
|
return (await next({})).output;
|
197
206
|
}
|
198
207
|
|
199
|
-
|
200
|
-
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
208
|
+
const ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
201
209
|
function setRouterContract(obj, contract) {
|
202
210
|
return new Proxy(obj, {
|
203
211
|
get(target, key) {
|
@@ -211,7 +219,7 @@ function setRouterContract(obj, contract) {
|
|
211
219
|
function getRouterContract(obj) {
|
212
220
|
return obj[ROUTER_CONTRACT_SYMBOL];
|
213
221
|
}
|
214
|
-
|
222
|
+
const LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
215
223
|
function deepSetLazyRouterPrefix(router, prefix) {
|
216
224
|
return new Proxy(router, {
|
217
225
|
get(target, key) {
|
@@ -230,29 +238,20 @@ function getLazyRouterPrefix(obj) {
|
|
230
238
|
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
231
239
|
}
|
232
240
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
return middlewares.slice(i);
|
241
|
+
function createAccessibleLazyRouter(lazied) {
|
242
|
+
const flattenLazy = flatLazy(lazied);
|
243
|
+
const recursive = new Proxy(flattenLazy, {
|
244
|
+
get(target, key) {
|
245
|
+
if (typeof key !== "string") {
|
246
|
+
return Reflect.get(target, key);
|
247
|
+
}
|
248
|
+
const next = getRouterChild(flattenLazy, key);
|
249
|
+
return createAccessibleLazyRouter(next);
|
243
250
|
}
|
244
|
-
|
245
|
-
|
246
|
-
return [];
|
247
|
-
}
|
248
|
-
function mergeMiddlewares(first, second) {
|
249
|
-
return [...first, ...dedupeMiddlewares(first, second)];
|
250
|
-
}
|
251
|
-
function addMiddleware(middlewares, addition) {
|
252
|
-
return [...middlewares, addition];
|
251
|
+
});
|
252
|
+
return recursive;
|
253
253
|
}
|
254
254
|
|
255
|
-
// src/router.ts
|
256
255
|
function adaptRouter(router, options) {
|
257
256
|
if (isLazy(router)) {
|
258
257
|
const adapted2 = lazy(async () => {
|
@@ -316,23 +315,6 @@ function getRouterChild(router, ...path) {
|
|
316
315
|
return current;
|
317
316
|
}
|
318
317
|
|
319
|
-
// src/router-accessible-lazy.ts
|
320
|
-
function createAccessibleLazyRouter(lazied) {
|
321
|
-
const flattenLazy = flatLazy(lazied);
|
322
|
-
const recursive = new Proxy(flattenLazy, {
|
323
|
-
get(target, key) {
|
324
|
-
if (typeof key !== "string") {
|
325
|
-
return Reflect.get(target, key);
|
326
|
-
}
|
327
|
-
const next = getRouterChild(flattenLazy, key);
|
328
|
-
return createAccessibleLazyRouter(next);
|
329
|
-
}
|
330
|
-
});
|
331
|
-
return recursive;
|
332
|
-
}
|
333
|
-
|
334
|
-
// src/utils.ts
|
335
|
-
import { isContractProcedure as isContractProcedure2 } from "@orpc/contract";
|
336
318
|
function eachContractProcedure(options, callback, laziedOptions = []) {
|
337
319
|
const hiddenContract = getRouterContract(options.router);
|
338
320
|
if (hiddenContract) {
|
@@ -350,7 +332,7 @@ function eachContractProcedure(options, callback, laziedOptions = []) {
|
|
350
332
|
lazied: options.router,
|
351
333
|
path: options.path
|
352
334
|
});
|
353
|
-
} else if (
|
335
|
+
} else if (isContractProcedure(options.router)) {
|
354
336
|
callback({
|
355
337
|
contract: options.router,
|
356
338
|
path: options.path
|
@@ -373,10 +355,10 @@ async function eachAllContractProcedure(options, callback) {
|
|
373
355
|
const pending = [options];
|
374
356
|
for (const item of pending) {
|
375
357
|
const lazies = eachContractProcedure(item, callback);
|
376
|
-
for (const
|
377
|
-
const { default: router } = await unlazy(
|
358
|
+
for (const lazy of lazies) {
|
359
|
+
const { default: router } = await unlazy(lazy.lazied);
|
378
360
|
pending.push({
|
379
|
-
path:
|
361
|
+
path: lazy.path,
|
380
362
|
router
|
381
363
|
});
|
382
364
|
}
|
@@ -394,28 +376,4 @@ function createContractedProcedure(contract, procedure) {
|
|
394
376
|
});
|
395
377
|
}
|
396
378
|
|
397
|
-
export {
|
398
|
-
LAZY_LOADER_SYMBOL,
|
399
|
-
lazy,
|
400
|
-
isLazy,
|
401
|
-
unlazy,
|
402
|
-
Procedure,
|
403
|
-
isProcedure,
|
404
|
-
flatLazy,
|
405
|
-
createLazyProcedureFormAnyLazy,
|
406
|
-
addMiddleware,
|
407
|
-
middlewareOutputFn,
|
408
|
-
createProcedureClient,
|
409
|
-
setRouterContract,
|
410
|
-
getRouterContract,
|
411
|
-
deepSetLazyRouterPrefix,
|
412
|
-
getLazyRouterPrefix,
|
413
|
-
createAccessibleLazyRouter,
|
414
|
-
adaptRouter,
|
415
|
-
getRouterChild,
|
416
|
-
eachContractProcedure,
|
417
|
-
eachAllContractProcedure,
|
418
|
-
convertPathToHttpPath,
|
419
|
-
createContractedProcedure
|
420
|
-
};
|
421
|
-
//# sourceMappingURL=chunk-MHVECKBC.js.map
|
379
|
+
export { LAZY_LOADER_SYMBOL as L, Procedure as P, convertPathToHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, eachContractProcedure as e, adaptRouter as f, getRouterChild as g, flatLazy as h, isProcedure as i, isLazy as j, createLazyProcedureFormAnyLazy as k, lazy as l, getRouterContract as m, deepSetLazyRouterPrefix as n, getLazyRouterPrefix as o, middlewareOutputFn as p, createAccessibleLazyRouter as q, eachAllContractProcedure as r, setRouterContract as s, unlazy as u };
|