@orpc/server 0.0.0-next.db1f26d → 0.0.0-next.df024bb
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 +118 -0
- 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/adapters/hono/index.mjs +32 -0
- package/dist/adapters/next/index.d.mts +27 -0
- package/dist/adapters/next/index.d.ts +27 -0
- package/dist/adapters/next/index.mjs +29 -0
- package/dist/adapters/node/index.d.mts +35 -0
- package/dist/adapters/node/index.d.ts +35 -0
- package/dist/adapters/node/index.mjs +30 -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.mjs +333 -0
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/plugins/index.mjs +103 -0
- package/dist/shared/server.BBGuTxHE.mjs +163 -0
- package/dist/shared/server.BMaJxq9W.d.mts +9 -0
- package/dist/shared/server.BT-fqIEm.d.mts +77 -0
- package/dist/shared/server.DpdgHO1j.d.ts +9 -0
- package/dist/shared/server.KwueCzFr.mjs +26 -0
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/dist/shared/server.V6zT5iYQ.mjs +379 -0
- package/dist/shared/server.ptXwNGQr.d.mts +158 -0
- package/dist/shared/server.ptXwNGQr.d.ts +158 -0
- package/dist/shared/server.xL87pHsk.d.ts +77 -0
- package/package.json +41 -18
- package/dist/chunk-FL4ZAGNE.js +0 -267
- package/dist/fetch.js +0 -107
- package/dist/index.js +0 -468
- package/dist/src/builder.d.ts +0 -53
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -35
- package/dist/src/index.d.ts +0 -17
- package/dist/src/lazy.d.ts +0 -23
- package/dist/src/middleware.d.ts +0 -26
- package/dist/src/procedure-builder.d.ts +0 -31
- package/dist/src/procedure-caller.d.ts +0 -20
- package/dist/src/procedure-implementer.d.ts +0 -22
- package/dist/src/procedure.d.ts +0 -32
- package/dist/src/router-builder.d.ts +0 -27
- package/dist/src/router-caller.d.ts +0 -22
- package/dist/src/router-implementer.d.ts +0 -24
- package/dist/src/router.d.ts +0 -21
- package/dist/src/types.d.ts +0 -8
- package/dist/src/utils.d.ts +0 -3
@@ -0,0 +1,158 @@
|
|
1
|
+
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
+
import { IsNever, MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
+
import { ErrorMap, ErrorMapItem, SchemaInput, HTTPPath, Meta, Schema, ContractProcedureDef, SchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure, MergedErrorMap } from '@orpc/contract';
|
4
|
+
|
5
|
+
type Context = Record<string, any>;
|
6
|
+
type MergedContext<T extends Context, U extends Context> = T & U;
|
7
|
+
declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
|
8
|
+
type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
9
|
+
[K in keyof T]: IsNever<T[K]>;
|
10
|
+
}[keyof T] ? never : unknown;
|
11
|
+
|
12
|
+
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
13
|
+
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
14
|
+
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
15
|
+
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
|
16
|
+
};
|
17
|
+
|
18
|
+
declare const LAZY_LOADER_SYMBOL: unique symbol;
|
19
|
+
interface LazyMeta {
|
20
|
+
prefix?: HTTPPath;
|
21
|
+
}
|
22
|
+
interface Lazy<T> {
|
23
|
+
[LAZY_LOADER_SYMBOL](): Promise<{
|
24
|
+
default: T;
|
25
|
+
}>;
|
26
|
+
}
|
27
|
+
type Lazyable<T> = T | Lazy<T>;
|
28
|
+
interface LazyOptions {
|
29
|
+
prefix?: HTTPPath;
|
30
|
+
}
|
31
|
+
declare function lazy<T>(loader: () => Promise<{
|
32
|
+
default: T;
|
33
|
+
}>): Lazy<T>;
|
34
|
+
declare function isLazy(item: unknown): item is Lazy<any>;
|
35
|
+
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
36
|
+
default: T extends Lazy<infer U> ? U : T;
|
37
|
+
}>;
|
38
|
+
|
39
|
+
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
40
|
+
output: TOutput;
|
41
|
+
context: TOutContext;
|
42
|
+
}>;
|
43
|
+
type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
44
|
+
context?: TOutContext;
|
45
|
+
} : {
|
46
|
+
context: TOutContext;
|
47
|
+
};
|
48
|
+
interface MiddlewareNextFn<TInContext extends Context, TOutput> {
|
49
|
+
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
50
|
+
}
|
51
|
+
interface MiddlewareOutputFn<TOutput> {
|
52
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
53
|
+
}
|
54
|
+
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
55
|
+
context: TInContext;
|
56
|
+
path: string[];
|
57
|
+
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
58
|
+
signal?: AbortSignal;
|
59
|
+
lastEventId: string | undefined;
|
60
|
+
next: MiddlewareNextFn<TInContext, TOutput>;
|
61
|
+
errors: TErrorConstructorMap;
|
62
|
+
}
|
63
|
+
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
64
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
65
|
+
}
|
66
|
+
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
67
|
+
interface MapInputMiddleware<TInput, TMappedInput> {
|
68
|
+
(input: TInput): TMappedInput;
|
69
|
+
}
|
70
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
71
|
+
|
72
|
+
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
73
|
+
context: TCurrentContext;
|
74
|
+
input: TInput;
|
75
|
+
path: string[];
|
76
|
+
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
77
|
+
signal?: AbortSignal;
|
78
|
+
lastEventId: string | undefined;
|
79
|
+
errors: TErrorConstructorMap;
|
80
|
+
}
|
81
|
+
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
82
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
83
|
+
}
|
84
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
85
|
+
__initialContext?: (type: TInitialContext) => unknown;
|
86
|
+
middlewares: AnyMiddleware[];
|
87
|
+
inputValidationIndex: number;
|
88
|
+
outputValidationIndex: number;
|
89
|
+
handler: ProcedureHandler<TCurrentContext, any, THandlerOutput, any, any>;
|
90
|
+
}
|
91
|
+
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
92
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
93
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>);
|
94
|
+
}
|
95
|
+
type AnyProcedure = Procedure<any, any, any, any, any, any, any>;
|
96
|
+
declare function isProcedure(item: unknown): item is AnyProcedure;
|
97
|
+
|
98
|
+
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
99
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
100
|
+
context: TInitialContext;
|
101
|
+
input: SchemaInput<TInputSchema>;
|
102
|
+
errors: ORPCErrorConstructorMap<TErrorMap>;
|
103
|
+
path: string[];
|
104
|
+
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
105
|
+
signal?: AbortSignal;
|
106
|
+
lastEventId: string | undefined;
|
107
|
+
}
|
108
|
+
/**
|
109
|
+
* Options for creating a procedure caller with comprehensive type safety
|
110
|
+
*/
|
111
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
112
|
+
/**
|
113
|
+
* This is helpful for logging and analytics.
|
114
|
+
*/
|
115
|
+
path?: string[];
|
116
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>[];
|
117
|
+
} & (Record<never, never> extends TInitialContext ? {
|
118
|
+
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
119
|
+
} : {
|
120
|
+
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
121
|
+
});
|
122
|
+
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
123
|
+
|
124
|
+
type AccessibleLazyRouter<T extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : Lazy<T> & (T extends AnyProcedure | undefined ? unknown : {
|
125
|
+
[K in keyof T]: T[K] extends AnyRouter ? AccessibleLazyRouter<T[K]> : never;
|
126
|
+
});
|
127
|
+
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
128
|
+
|
129
|
+
type Router<TInitialContext extends Context, TContract extends AnyContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap, UMeta> : {
|
130
|
+
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
|
131
|
+
}>;
|
132
|
+
type AnyRouter = Router<any, any>;
|
133
|
+
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer UInitialContext, any> ? UInitialContext : never;
|
134
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : T extends Procedure<infer UInitialContext, any, any, any, any, any, any> ? UInitialContext : {
|
135
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInitialContexts<T[K]> : never;
|
136
|
+
};
|
137
|
+
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : T extends Procedure<any, infer UCurrentContext, any, any, any, any, any> ? UCurrentContext : {
|
138
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterCurrentContexts<T[K]> : never;
|
139
|
+
};
|
140
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
|
141
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
142
|
+
};
|
143
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
144
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
145
|
+
};
|
146
|
+
type AdaptedRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap> = TRouter extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<AdaptedRouter<U, TInitialContext, TErrorMap>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
147
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
148
|
+
};
|
149
|
+
interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
150
|
+
middlewares: AnyMiddleware[];
|
151
|
+
tags?: readonly string[];
|
152
|
+
prefix?: HTTPPath;
|
153
|
+
errorMap: TErrorMap;
|
154
|
+
}
|
155
|
+
declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
156
|
+
declare function getRouterChild<T extends AnyRouter | Lazy<undefined>>(router: T, ...path: string[]): T extends Lazy<any> ? Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter>> | Lazy<undefined> : AnyRouter | Lazy<undefined> | undefined;
|
157
|
+
|
158
|
+
export { type AnyProcedure as A, type ProcedureDef as B, type Context as C, isProcedure as D, createProcedureClient as E, type InferRouterInitialContexts as F, type InferRouterCurrentContexts as G, type InferRouterInputs as H, type InferRouterInitialContext as I, type InferRouterOutputs as J, adaptRouter as K, type Lazy as L, type Middleware as M, getRouterChild as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type AccessibleLazyRouter as Q, type Router as R, createAccessibleLazyRouter as S, type AnyRouter as a, Procedure as b, type ConflictContextGuard as c, type MergedContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type ProcedureHandler as h, type AdaptRouterOptions as i, type AdaptedRouter as j, type AnyMiddleware as k, type Lazyable as l, mergeContext as m, LAZY_LOADER_SYMBOL as n, type LazyMeta as o, type LazyOptions as p, lazy as q, isLazy as r, type MiddlewareResult as s, type MiddlewareNextFnOptions as t, unlazy as u, type MiddlewareNextFn as v, type MiddlewareOutputFn as w, type MiddlewareOptions as x, middlewareOutputFn as y, type ProcedureHandlerOptions as z };
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { HTTPPath, Schema, Meta, SchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.ptXwNGQr.js';
|
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: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
|
+
}
|
22
|
+
|
23
|
+
type StandardHandleOptions<T extends Context> = {
|
24
|
+
prefix?: HTTPPath;
|
25
|
+
} & (Record<never, never> extends T ? {
|
26
|
+
context?: T;
|
27
|
+
} : {
|
28
|
+
context: T;
|
29
|
+
});
|
30
|
+
type 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: StandardLazyRequest;
|
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: StandardLazyRequest, ...[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 };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.df024bb",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -15,38 +15,61 @@
|
|
15
15
|
],
|
16
16
|
"exports": {
|
17
17
|
".": {
|
18
|
-
"types": "./dist/
|
19
|
-
"import": "./dist/index.
|
20
|
-
"default": "./dist/index.
|
18
|
+
"types": "./dist/index.d.mts",
|
19
|
+
"import": "./dist/index.mjs",
|
20
|
+
"default": "./dist/index.mjs"
|
21
|
+
},
|
22
|
+
"./plugins": {
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
26
|
+
},
|
27
|
+
"./standard": {
|
28
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
29
|
+
"import": "./dist/adapters/standard/index.mjs",
|
30
|
+
"default": "./dist/adapters/standard/index.mjs"
|
21
31
|
},
|
22
32
|
"./fetch": {
|
23
|
-
"types": "./dist/
|
24
|
-
"import": "./dist/fetch.
|
25
|
-
"default": "./dist/fetch.
|
33
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
34
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
35
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
36
|
+
},
|
37
|
+
"./hono": {
|
38
|
+
"types": "./dist/adapters/hono/index.d.mts",
|
39
|
+
"import": "./dist/adapters/hono/index.mjs",
|
40
|
+
"default": "./dist/adapters/hono/index.mjs"
|
41
|
+
},
|
42
|
+
"./next": {
|
43
|
+
"types": "./dist/adapters/next/index.d.mts",
|
44
|
+
"import": "./dist/adapters/next/index.mjs",
|
45
|
+
"default": "./dist/adapters/next/index.mjs"
|
26
46
|
},
|
27
|
-
"
|
28
|
-
"types": "./dist/
|
47
|
+
"./node": {
|
48
|
+
"types": "./dist/adapters/node/index.d.mts",
|
49
|
+
"import": "./dist/adapters/node/index.mjs",
|
50
|
+
"default": "./dist/adapters/node/index.mjs"
|
29
51
|
}
|
30
52
|
},
|
31
53
|
"files": [
|
32
|
-
"!**/*.map",
|
33
|
-
"!**/*.tsbuildinfo",
|
34
54
|
"dist"
|
35
55
|
],
|
36
56
|
"peerDependencies": {
|
37
|
-
"
|
38
|
-
"
|
57
|
+
"hono": ">=4.6.0",
|
58
|
+
"next": ">=14.0.0"
|
39
59
|
},
|
40
60
|
"dependencies": {
|
41
|
-
"@orpc/
|
42
|
-
"@orpc/shared": "0.0.0-next.
|
43
|
-
"@orpc/
|
61
|
+
"@orpc/client": "0.0.0-next.df024bb",
|
62
|
+
"@orpc/shared": "0.0.0-next.df024bb",
|
63
|
+
"@orpc/standard-server": "0.0.0-next.df024bb",
|
64
|
+
"@orpc/contract": "0.0.0-next.df024bb",
|
65
|
+
"@orpc/standard-server-fetch": "0.0.0-next.df024bb",
|
66
|
+
"@orpc/standard-server-node": "0.0.0-next.df024bb"
|
44
67
|
},
|
45
68
|
"devDependencies": {
|
46
|
-
"
|
69
|
+
"light-my-request": "^6.5.1"
|
47
70
|
},
|
48
71
|
"scripts": {
|
49
|
-
"build": "
|
72
|
+
"build": "unbuild",
|
50
73
|
"build:watch": "pnpm run build --watch",
|
51
74
|
"type:check": "tsc -b"
|
52
75
|
}
|
package/dist/chunk-FL4ZAGNE.js
DELETED
@@ -1,267 +0,0 @@
|
|
1
|
-
// src/utils.ts
|
2
|
-
function mergeContext(a, b) {
|
3
|
-
if (!a)
|
4
|
-
return b;
|
5
|
-
if (!b)
|
6
|
-
return a;
|
7
|
-
return {
|
8
|
-
...a,
|
9
|
-
...b
|
10
|
-
};
|
11
|
-
}
|
12
|
-
|
13
|
-
// src/middleware.ts
|
14
|
-
var decoratedMiddlewareSymbol = Symbol("\u{1F512}decoratedMiddleware");
|
15
|
-
function decorateMiddleware(middleware) {
|
16
|
-
if (Reflect.get(middleware, decoratedMiddlewareSymbol)) {
|
17
|
-
return middleware;
|
18
|
-
}
|
19
|
-
const concat = (concatMiddleware, mapInput2) => {
|
20
|
-
const concatMiddleware_ = mapInput2 ? decorateMiddleware(concatMiddleware).mapInput(mapInput2) : concatMiddleware;
|
21
|
-
return decorateMiddleware(async (input, context, meta, ...rest) => {
|
22
|
-
const input_ = input;
|
23
|
-
const context_ = context;
|
24
|
-
const meta_ = meta;
|
25
|
-
const next = async (options) => {
|
26
|
-
return concatMiddleware_(input_, mergeContext(context_, options.context), meta_, ...rest);
|
27
|
-
};
|
28
|
-
const m1 = await middleware(input_, context_, {
|
29
|
-
...meta_,
|
30
|
-
next
|
31
|
-
}, ...rest);
|
32
|
-
return m1;
|
33
|
-
});
|
34
|
-
};
|
35
|
-
const mapInput = (map) => {
|
36
|
-
return decorateMiddleware(
|
37
|
-
(input, ...rest) => middleware(map(input), ...rest)
|
38
|
-
);
|
39
|
-
};
|
40
|
-
return Object.assign(middleware, {
|
41
|
-
[decoratedMiddlewareSymbol]: true,
|
42
|
-
concat,
|
43
|
-
mapInput
|
44
|
-
});
|
45
|
-
}
|
46
|
-
|
47
|
-
// src/procedure-caller.ts
|
48
|
-
import { trim, value } from "@orpc/shared";
|
49
|
-
import { ORPCError } from "@orpc/shared/error";
|
50
|
-
import { OpenAPIDeserializer } from "@orpc/transformer";
|
51
|
-
|
52
|
-
// src/procedure.ts
|
53
|
-
import {
|
54
|
-
DecoratedContractProcedure,
|
55
|
-
isContractProcedure
|
56
|
-
} from "@orpc/contract";
|
57
|
-
var Procedure = class {
|
58
|
-
constructor(zz$p) {
|
59
|
-
this.zz$p = zz$p;
|
60
|
-
}
|
61
|
-
};
|
62
|
-
var DECORATED_PROCEDURE_SYMBOL = Symbol("DECORATED_PROCEDURE");
|
63
|
-
function decorateProcedure(procedure) {
|
64
|
-
if (DECORATED_PROCEDURE_SYMBOL in procedure) {
|
65
|
-
return procedure;
|
66
|
-
}
|
67
|
-
return Object.assign(createProcedureCaller({
|
68
|
-
procedure,
|
69
|
-
context: void 0
|
70
|
-
}), {
|
71
|
-
[DECORATED_PROCEDURE_SYMBOL]: true,
|
72
|
-
zz$p: procedure.zz$p,
|
73
|
-
prefix(prefix) {
|
74
|
-
return decorateProcedure({
|
75
|
-
zz$p: {
|
76
|
-
...procedure.zz$p,
|
77
|
-
contract: DecoratedContractProcedure.decorate(
|
78
|
-
procedure.zz$p.contract
|
79
|
-
).prefix(prefix)
|
80
|
-
}
|
81
|
-
});
|
82
|
-
},
|
83
|
-
route(opts) {
|
84
|
-
return decorateProcedure({
|
85
|
-
zz$p: {
|
86
|
-
...procedure.zz$p,
|
87
|
-
contract: DecoratedContractProcedure.decorate(
|
88
|
-
procedure.zz$p.contract
|
89
|
-
).route(opts)
|
90
|
-
}
|
91
|
-
});
|
92
|
-
},
|
93
|
-
use(middleware, mapInput) {
|
94
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
95
|
-
return decorateProcedure({
|
96
|
-
zz$p: {
|
97
|
-
...procedure.zz$p,
|
98
|
-
middlewares: [middleware_, ...procedure.zz$p.middlewares ?? []]
|
99
|
-
}
|
100
|
-
});
|
101
|
-
}
|
102
|
-
});
|
103
|
-
}
|
104
|
-
function isProcedure(item) {
|
105
|
-
if (item instanceof Procedure)
|
106
|
-
return true;
|
107
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "zz$p" in item && typeof item.zz$p === "object" && item.zz$p !== null && "contract" in item.zz$p && isContractProcedure(item.zz$p.contract) && "func" in item.zz$p && typeof item.zz$p.func === "function";
|
108
|
-
}
|
109
|
-
|
110
|
-
// src/procedure-caller.ts
|
111
|
-
function createProcedureCaller(options) {
|
112
|
-
const loadProcedure = async () => {
|
113
|
-
let procedure;
|
114
|
-
if (isLazy(options.procedure)) {
|
115
|
-
procedure = (await loadLazy(options.procedure)).default;
|
116
|
-
} else {
|
117
|
-
procedure = options.procedure;
|
118
|
-
}
|
119
|
-
if (!isProcedure(procedure)) {
|
120
|
-
throw new ORPCError({
|
121
|
-
code: "NOT_FOUND",
|
122
|
-
message: "Not found",
|
123
|
-
cause: new Error(trim(`
|
124
|
-
This error should be caught by the typescript compiler.
|
125
|
-
But if you still see this error, it means that you trying to call a lazy router (expected to be a lazy procedure).
|
126
|
-
`))
|
127
|
-
});
|
128
|
-
}
|
129
|
-
return procedure;
|
130
|
-
};
|
131
|
-
const caller = async (input) => {
|
132
|
-
const path = options.path ?? [];
|
133
|
-
const procedure = await loadProcedure();
|
134
|
-
const input_ = (() => {
|
135
|
-
if (!(input instanceof FormData)) {
|
136
|
-
return input;
|
137
|
-
}
|
138
|
-
const transformer = new OpenAPIDeserializer({
|
139
|
-
schema: procedure.zz$p.contract.zz$cp.InputSchema
|
140
|
-
});
|
141
|
-
return transformer.deserializeAsFormData(input);
|
142
|
-
})();
|
143
|
-
const validInput = (() => {
|
144
|
-
const schema = procedure.zz$p.contract.zz$cp.InputSchema;
|
145
|
-
if (!schema) {
|
146
|
-
return input_;
|
147
|
-
}
|
148
|
-
try {
|
149
|
-
return schema.parse(input_);
|
150
|
-
} catch (e) {
|
151
|
-
throw new ORPCError({
|
152
|
-
message: "Validation input failed",
|
153
|
-
code: "BAD_REQUEST",
|
154
|
-
cause: e
|
155
|
-
});
|
156
|
-
}
|
157
|
-
})();
|
158
|
-
const middlewares = procedure.zz$p.middlewares ?? [];
|
159
|
-
let currentMidIndex = 0;
|
160
|
-
let currentContext = await value(options.context);
|
161
|
-
const next = async (nextOptions) => {
|
162
|
-
const mid = middlewares[currentMidIndex];
|
163
|
-
currentMidIndex += 1;
|
164
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
165
|
-
if (mid) {
|
166
|
-
return await mid(validInput, currentContext, {
|
167
|
-
path,
|
168
|
-
procedure,
|
169
|
-
next,
|
170
|
-
output: (output2) => ({ output: output2, context: void 0 })
|
171
|
-
});
|
172
|
-
} else {
|
173
|
-
return {
|
174
|
-
output: await await procedure.zz$p.func(validInput, currentContext, {
|
175
|
-
path,
|
176
|
-
procedure
|
177
|
-
}),
|
178
|
-
context: currentContext
|
179
|
-
};
|
180
|
-
}
|
181
|
-
};
|
182
|
-
const output = (await next({})).output;
|
183
|
-
const validOutput = await (async () => {
|
184
|
-
const schema = procedure.zz$p.contract.zz$cp.OutputSchema;
|
185
|
-
if (!schema) {
|
186
|
-
return output;
|
187
|
-
}
|
188
|
-
const result = await schema.safeParseAsync(output);
|
189
|
-
if (result.error) {
|
190
|
-
throw new ORPCError({
|
191
|
-
message: "Validation output failed",
|
192
|
-
code: "INTERNAL_SERVER_ERROR",
|
193
|
-
cause: result.error
|
194
|
-
});
|
195
|
-
}
|
196
|
-
return result.data;
|
197
|
-
})();
|
198
|
-
return validOutput;
|
199
|
-
};
|
200
|
-
return caller;
|
201
|
-
}
|
202
|
-
|
203
|
-
// src/lazy.ts
|
204
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
205
|
-
function createLazy(loader) {
|
206
|
-
return {
|
207
|
-
[LAZY_LOADER_SYMBOL]: loader
|
208
|
-
};
|
209
|
-
}
|
210
|
-
function loadLazy(lazy) {
|
211
|
-
return lazy[LAZY_LOADER_SYMBOL]();
|
212
|
-
}
|
213
|
-
function isLazy(item) {
|
214
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
215
|
-
}
|
216
|
-
function createFlattenLazy(lazy) {
|
217
|
-
const flattenLoader = async () => {
|
218
|
-
let current = await loadLazy(lazy);
|
219
|
-
while (true) {
|
220
|
-
if (!isLazy(current.default)) {
|
221
|
-
break;
|
222
|
-
}
|
223
|
-
current = await loadLazy(current.default);
|
224
|
-
}
|
225
|
-
return current;
|
226
|
-
};
|
227
|
-
const flattenLazy = {
|
228
|
-
[LAZY_LOADER_SYMBOL]: flattenLoader
|
229
|
-
};
|
230
|
-
return flattenLazy;
|
231
|
-
}
|
232
|
-
function decorateLazy(lazy) {
|
233
|
-
const flattenLazy = createFlattenLazy(lazy);
|
234
|
-
const procedureCaller = createProcedureCaller({
|
235
|
-
procedure: flattenLazy,
|
236
|
-
context: void 0
|
237
|
-
});
|
238
|
-
Object.assign(procedureCaller, flattenLazy);
|
239
|
-
const recursive = new Proxy(procedureCaller, {
|
240
|
-
get(target, key) {
|
241
|
-
if (typeof key !== "string") {
|
242
|
-
return Reflect.get(target, key);
|
243
|
-
}
|
244
|
-
return decorateLazy(createLazy(async () => {
|
245
|
-
const current = await loadLazy(flattenLazy);
|
246
|
-
return { default: current.default[key] };
|
247
|
-
}));
|
248
|
-
}
|
249
|
-
});
|
250
|
-
return recursive;
|
251
|
-
}
|
252
|
-
|
253
|
-
export {
|
254
|
-
mergeContext,
|
255
|
-
decorateMiddleware,
|
256
|
-
LAZY_LOADER_SYMBOL,
|
257
|
-
createLazy,
|
258
|
-
loadLazy,
|
259
|
-
isLazy,
|
260
|
-
createFlattenLazy,
|
261
|
-
decorateLazy,
|
262
|
-
createProcedureCaller,
|
263
|
-
Procedure,
|
264
|
-
decorateProcedure,
|
265
|
-
isProcedure
|
266
|
-
};
|
267
|
-
//# sourceMappingURL=chunk-FL4ZAGNE.js.map
|