@orpc/server 0.0.0-next.172fe95 → 0.0.0-next.180f017
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 +128 -0
- 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 +45 -0
- package/dist/adapters/fetch/index.d.mts +124 -0
- package/dist/adapters/fetch/index.d.ts +124 -0
- package/dist/adapters/fetch/index.mjs +180 -0
- 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 +39 -0
- package/dist/adapters/node/index.d.mts +99 -0
- package/dist/adapters/node/index.d.ts +99 -0
- package/dist/adapters/node/index.mjs +152 -0
- package/dist/adapters/standard/index.d.mts +21 -0
- package/dist/adapters/standard/index.d.ts +21 -0
- package/dist/adapters/standard/index.mjs +8 -0
- package/dist/adapters/standard-peer/index.d.mts +18 -0
- package/dist/adapters/standard-peer/index.d.ts +18 -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 +67 -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 +37 -0
- package/dist/helpers/index.d.mts +134 -0
- package/dist/helpers/index.d.ts +134 -0
- package/dist/helpers/index.mjs +188 -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 +803 -0
- package/dist/index.d.ts +803 -0
- package/dist/index.mjs +489 -0
- package/dist/plugins/index.d.mts +169 -0
- package/dist/plugins/index.d.ts +169 -0
- package/dist/plugins/index.mjs +285 -0
- package/dist/shared/server.7jWaIryJ.mjs +416 -0
- package/dist/shared/server.B7b2w3_i.d.ts +12 -0
- package/dist/shared/server.BEFBl-Cb.d.mts +12 -0
- package/dist/shared/server.BHZCyRuJ.mjs +219 -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.CYNGeoCm.d.mts +194 -0
- package/dist/shared/server.CYNGeoCm.d.ts +194 -0
- 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.UVMTOWrk.mjs +26 -0
- package/dist/shared/server.gqRxT-yN.d.mts +74 -0
- package/dist/shared/server.jMTkVNIb.d.ts +42 -0
- package/package.json +85 -36
- package/dist/chunk-EDQKEHUX.js +0 -377
- package/dist/chunk-JLUA7RBC.js +0 -319
- package/dist/chunk-KX7JRBQ4.js +0 -145
- package/dist/chunk-XFBAK67J.js +0 -128
- package/dist/fetch.js +0 -16
- package/dist/hono.js +0 -40
- package/dist/index.js +0 -404
- package/dist/next.js +0 -37
- package/dist/node.js +0 -170
- package/dist/plugins.js +0 -11
- package/dist/src/adapters/fetch/index.d.ts +0 -4
- package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -10
- package/dist/src/adapters/fetch/types.d.ts +0 -13
- package/dist/src/adapters/fetch/utils.d.ts +0 -5
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -13
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -20
- package/dist/src/adapters/node/index.d.ts +0 -4
- package/dist/src/adapters/node/rpc-handler.d.ts +0 -10
- package/dist/src/adapters/node/types.d.ts +0 -21
- package/dist/src/adapters/node/utils.d.ts +0 -5
- package/dist/src/adapters/standard/handler.d.ts +0 -51
- package/dist/src/adapters/standard/index.d.ts +0 -7
- package/dist/src/adapters/standard/rpc-codec.d.ts +0 -15
- 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/rpc-serializer.d.ts +0 -16
- package/dist/src/adapters/standard/types.d.ts +0 -44
- package/dist/src/builder-variants.d.ts +0 -74
- package/dist/src/builder.d.ts +0 -57
- package/dist/src/config.d.ts +0 -6
- package/dist/src/context.d.ts +0 -9
- package/dist/src/hidden.d.ts +0 -8
- package/dist/src/implementer-procedure.d.ts +0 -30
- package/dist/src/implementer-variants.d.ts +0 -17
- package/dist/src/implementer.d.ts +0 -28
- package/dist/src/index.d.ts +0 -23
- 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 -10
- package/dist/src/middleware-utils.d.ts +0 -5
- package/dist/src/middleware.d.ts +0 -37
- package/dist/src/plugins/base.d.ts +0 -13
- 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 -31
- package/dist/src/procedure-decorated.d.ts +0 -21
- package/dist/src/procedure-utils.d.ts +0 -17
- package/dist/src/procedure.d.ts +0 -29
- package/dist/src/router-accessible-lazy.d.ts +0 -8
- package/dist/src/router-client.d.ts +0 -11
- package/dist/src/router.d.ts +0 -29
- package/dist/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -17
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { HTTPPath, ORPCError } from '@orpc/client';
|
|
2
|
+
import { Meta } from '@orpc/contract';
|
|
3
|
+
import { Interceptor } from '@orpc/shared';
|
|
4
|
+
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
|
5
|
+
import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.CYNGeoCm.mjs';
|
|
6
|
+
|
|
7
|
+
interface StandardHandlerPlugin<T extends Context> {
|
|
8
|
+
order?: number;
|
|
9
|
+
init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
|
10
|
+
}
|
|
11
|
+
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
|
12
|
+
protected readonly plugins: TPlugin[];
|
|
13
|
+
constructor(plugins?: readonly TPlugin[]);
|
|
14
|
+
init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type StandardParams = Record<string, string>;
|
|
18
|
+
type StandardMatchResult = {
|
|
19
|
+
path: readonly string[];
|
|
20
|
+
procedure: AnyProcedure;
|
|
21
|
+
params?: StandardParams;
|
|
22
|
+
} | undefined;
|
|
23
|
+
interface StandardMatcher {
|
|
24
|
+
init(router: AnyRouter): void;
|
|
25
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
26
|
+
}
|
|
27
|
+
interface StandardCodec {
|
|
28
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
29
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
30
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface StandardHandleOptions<T extends Context> {
|
|
34
|
+
prefix?: HTTPPath;
|
|
35
|
+
context: T;
|
|
36
|
+
}
|
|
37
|
+
type StandardHandleResult = {
|
|
38
|
+
matched: true;
|
|
39
|
+
response: StandardResponse;
|
|
40
|
+
} | {
|
|
41
|
+
matched: false;
|
|
42
|
+
response: undefined;
|
|
43
|
+
};
|
|
44
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
|
45
|
+
request: StandardLazyRequest;
|
|
46
|
+
}
|
|
47
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
|
48
|
+
plugins?: StandardHandlerPlugin<TContext>[];
|
|
49
|
+
/**
|
|
50
|
+
* Interceptors at the request level, helpful when you want catch errors
|
|
51
|
+
*/
|
|
52
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
|
|
53
|
+
/**
|
|
54
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
|
55
|
+
*/
|
|
56
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* Interceptors for procedure client.
|
|
60
|
+
*/
|
|
61
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
|
|
62
|
+
}
|
|
63
|
+
declare class StandardHandler<T extends Context> {
|
|
64
|
+
private readonly matcher;
|
|
65
|
+
private readonly codec;
|
|
66
|
+
private readonly interceptors;
|
|
67
|
+
private readonly clientInterceptors;
|
|
68
|
+
private readonly rootInterceptors;
|
|
69
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
|
70
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as f };
|
|
74
|
+
export type { StandardCodec as S, StandardParams as a, StandardHandleOptions as b, StandardHandleResult as c, StandardHandlerInterceptorOptions as d, StandardHandlerOptions as e, StandardHandlerPlugin as g, StandardMatchResult as h, StandardMatcher as i };
|
|
@@ -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.js';
|
|
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 };
|
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.180f017",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,63 +15,112 @@
|
|
|
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
|
+
"./helpers": {
|
|
23
|
+
"types": "./dist/helpers/index.d.mts",
|
|
24
|
+
"import": "./dist/helpers/index.mjs",
|
|
25
|
+
"default": "./dist/helpers/index.mjs"
|
|
21
26
|
},
|
|
22
27
|
"./plugins": {
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"import": "./dist/plugins.
|
|
25
|
-
"default": "./dist/plugins.
|
|
28
|
+
"types": "./dist/plugins/index.d.mts",
|
|
29
|
+
"import": "./dist/plugins/index.mjs",
|
|
30
|
+
"default": "./dist/plugins/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./hibernation": {
|
|
33
|
+
"types": "./dist/hibernation/index.d.mts",
|
|
34
|
+
"import": "./dist/hibernation/index.mjs",
|
|
35
|
+
"default": "./dist/hibernation/index.mjs"
|
|
26
36
|
},
|
|
27
37
|
"./standard": {
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/standard.
|
|
30
|
-
"default": "./dist/standard.
|
|
38
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/standard/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/standard/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./standard-peer": {
|
|
43
|
+
"types": "./dist/adapters/standard-peer/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/standard-peer/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/standard-peer/index.mjs"
|
|
31
46
|
},
|
|
32
47
|
"./fetch": {
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/fetch.
|
|
35
|
-
"default": "./dist/fetch.
|
|
48
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
49
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
50
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
36
51
|
},
|
|
37
|
-
"./
|
|
38
|
-
"types": "./dist/
|
|
39
|
-
"import": "./dist/
|
|
40
|
-
"default": "./dist/
|
|
52
|
+
"./node": {
|
|
53
|
+
"types": "./dist/adapters/node/index.d.mts",
|
|
54
|
+
"import": "./dist/adapters/node/index.mjs",
|
|
55
|
+
"default": "./dist/adapters/node/index.mjs"
|
|
41
56
|
},
|
|
42
|
-
"./
|
|
43
|
-
"types": "./dist/
|
|
44
|
-
"import": "./dist/
|
|
45
|
-
"default": "./dist/
|
|
57
|
+
"./aws-lambda": {
|
|
58
|
+
"types": "./dist/adapters/aws-lambda/index.d.mts",
|
|
59
|
+
"import": "./dist/adapters/aws-lambda/index.mjs",
|
|
60
|
+
"default": "./dist/adapters/aws-lambda/index.mjs"
|
|
46
61
|
},
|
|
47
|
-
"./
|
|
48
|
-
"types": "./dist/
|
|
49
|
-
"import": "./dist/
|
|
50
|
-
"default": "./dist/
|
|
62
|
+
"./websocket": {
|
|
63
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
64
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
65
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
66
|
+
},
|
|
67
|
+
"./crossws": {
|
|
68
|
+
"types": "./dist/adapters/crossws/index.d.mts",
|
|
69
|
+
"import": "./dist/adapters/crossws/index.mjs",
|
|
70
|
+
"default": "./dist/adapters/crossws/index.mjs"
|
|
51
71
|
},
|
|
52
|
-
"
|
|
53
|
-
"types": "./dist/
|
|
72
|
+
"./ws": {
|
|
73
|
+
"types": "./dist/adapters/ws/index.d.mts",
|
|
74
|
+
"import": "./dist/adapters/ws/index.mjs",
|
|
75
|
+
"default": "./dist/adapters/ws/index.mjs"
|
|
76
|
+
},
|
|
77
|
+
"./bun-ws": {
|
|
78
|
+
"types": "./dist/adapters/bun-ws/index.d.mts",
|
|
79
|
+
"import": "./dist/adapters/bun-ws/index.mjs",
|
|
80
|
+
"default": "./dist/adapters/bun-ws/index.mjs"
|
|
81
|
+
},
|
|
82
|
+
"./message-port": {
|
|
83
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
84
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
85
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
54
86
|
}
|
|
55
87
|
},
|
|
56
88
|
"files": [
|
|
57
|
-
"!**/*.map",
|
|
58
|
-
"!**/*.tsbuildinfo",
|
|
59
89
|
"dist"
|
|
60
90
|
],
|
|
61
91
|
"peerDependencies": {
|
|
62
|
-
"
|
|
63
|
-
"
|
|
92
|
+
"crossws": ">=0.3.4",
|
|
93
|
+
"ws": ">=8.18.1"
|
|
94
|
+
},
|
|
95
|
+
"peerDependenciesMeta": {
|
|
96
|
+
"crossws": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"ws": {
|
|
100
|
+
"optional": true
|
|
101
|
+
}
|
|
64
102
|
},
|
|
65
103
|
"dependencies": {
|
|
66
|
-
"
|
|
67
|
-
"@orpc/
|
|
68
|
-
"@orpc/
|
|
104
|
+
"cookie": "^1.0.2",
|
|
105
|
+
"@orpc/client": "0.0.0-next.180f017",
|
|
106
|
+
"@orpc/contract": "0.0.0-next.180f017",
|
|
107
|
+
"@orpc/interop": "0.0.0-next.180f017",
|
|
108
|
+
"@orpc/shared": "0.0.0-next.180f017",
|
|
109
|
+
"@orpc/standard-server": "0.0.0-next.180f017",
|
|
110
|
+
"@orpc/standard-server-aws-lambda": "0.0.0-next.180f017",
|
|
111
|
+
"@orpc/standard-server-fetch": "0.0.0-next.180f017",
|
|
112
|
+
"@orpc/standard-server-node": "0.0.0-next.180f017",
|
|
113
|
+
"@orpc/standard-server-peer": "0.0.0-next.180f017"
|
|
69
114
|
},
|
|
70
115
|
"devDependencies": {
|
|
71
|
-
"
|
|
116
|
+
"@types/ws": "^8.18.1",
|
|
117
|
+
"crossws": "^0.4.1",
|
|
118
|
+
"next": "^15.5.0",
|
|
119
|
+
"supertest": "^7.1.4",
|
|
120
|
+
"ws": "^8.18.3"
|
|
72
121
|
},
|
|
73
122
|
"scripts": {
|
|
74
|
-
"build": "
|
|
123
|
+
"build": "unbuild",
|
|
75
124
|
"build:watch": "pnpm run build --watch",
|
|
76
125
|
"type:check": "tsc -b"
|
|
77
126
|
}
|
package/dist/chunk-EDQKEHUX.js
DELETED
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
// src/lazy.ts
|
|
2
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
|
3
|
-
function lazy(loader) {
|
|
4
|
-
return {
|
|
5
|
-
[LAZY_LOADER_SYMBOL]: loader
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
function isLazy(item) {
|
|
9
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
|
10
|
-
}
|
|
11
|
-
function unlazy(lazied) {
|
|
12
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/procedure.ts
|
|
16
|
-
import { isContractProcedure } from "@orpc/contract";
|
|
17
|
-
var Procedure = class {
|
|
18
|
-
"~orpc";
|
|
19
|
-
constructor(def) {
|
|
20
|
-
this["~orpc"] = def;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
function isProcedure(item) {
|
|
24
|
-
if (item instanceof Procedure) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/lazy-utils.ts
|
|
31
|
-
function flatLazy(lazied) {
|
|
32
|
-
const flattenLoader = async () => {
|
|
33
|
-
let current = await unlazy(lazied);
|
|
34
|
-
while (true) {
|
|
35
|
-
if (!isLazy(current.default)) {
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
current = await unlazy(current.default);
|
|
39
|
-
}
|
|
40
|
-
return current;
|
|
41
|
-
};
|
|
42
|
-
return lazy(flattenLoader);
|
|
43
|
-
}
|
|
44
|
-
function createLazyProcedureFormAnyLazy(lazied) {
|
|
45
|
-
const lazyProcedure = lazy(async () => {
|
|
46
|
-
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
|
47
|
-
if (!isProcedure(maybeProcedure)) {
|
|
48
|
-
throw new Error(`
|
|
49
|
-
Expected a lazy<procedure> but got lazy<unknown>.
|
|
50
|
-
This should be caught by TypeScript compilation.
|
|
51
|
-
Please report this issue if this makes you feel uncomfortable.
|
|
52
|
-
`);
|
|
53
|
-
}
|
|
54
|
-
return { default: maybeProcedure };
|
|
55
|
-
});
|
|
56
|
-
return lazyProcedure;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/middleware.ts
|
|
60
|
-
function middlewareOutputFn(output) {
|
|
61
|
-
return { output, context: {} };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// src/procedure-client.ts
|
|
65
|
-
import { createORPCErrorConstructorMap, ORPCError, validateORPCError, ValidationError } from "@orpc/contract";
|
|
66
|
-
import { intercept, toError, value } from "@orpc/shared";
|
|
67
|
-
function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
68
|
-
return async (...[input, callerOptions]) => {
|
|
69
|
-
const path = options?.path ?? [];
|
|
70
|
-
const { default: procedure } = await unlazy(lazyableProcedure);
|
|
71
|
-
const context = await value(options?.context ?? {}, callerOptions?.context);
|
|
72
|
-
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
|
|
73
|
-
try {
|
|
74
|
-
return await intercept(
|
|
75
|
-
options?.interceptors ?? [],
|
|
76
|
-
{
|
|
77
|
-
context,
|
|
78
|
-
input,
|
|
79
|
-
// input only optional when it undefinable so we can safely cast it
|
|
80
|
-
errors,
|
|
81
|
-
path,
|
|
82
|
-
procedure,
|
|
83
|
-
signal: callerOptions?.signal
|
|
84
|
-
},
|
|
85
|
-
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
|
86
|
-
);
|
|
87
|
-
} catch (e) {
|
|
88
|
-
if (!(e instanceof ORPCError)) {
|
|
89
|
-
throw toError(e);
|
|
90
|
-
}
|
|
91
|
-
const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
|
|
92
|
-
throw validated;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
async function validateInput(procedure, input) {
|
|
97
|
-
const schema = procedure["~orpc"].inputSchema;
|
|
98
|
-
if (!schema) {
|
|
99
|
-
return input;
|
|
100
|
-
}
|
|
101
|
-
const result = await schema["~standard"].validate(input);
|
|
102
|
-
if (result.issues) {
|
|
103
|
-
throw new ORPCError("BAD_REQUEST", {
|
|
104
|
-
message: "Input validation failed",
|
|
105
|
-
data: {
|
|
106
|
-
issues: result.issues
|
|
107
|
-
},
|
|
108
|
-
cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return result.value;
|
|
112
|
-
}
|
|
113
|
-
async function validateOutput(procedure, output) {
|
|
114
|
-
const schema = procedure["~orpc"].outputSchema;
|
|
115
|
-
if (!schema) {
|
|
116
|
-
return output;
|
|
117
|
-
}
|
|
118
|
-
const result = await schema["~standard"].validate(output);
|
|
119
|
-
if (result.issues) {
|
|
120
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
121
|
-
message: "Output validation failed",
|
|
122
|
-
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return result.value;
|
|
126
|
-
}
|
|
127
|
-
async function executeProcedureInternal(procedure, options) {
|
|
128
|
-
const middlewares = procedure["~orpc"].middlewares;
|
|
129
|
-
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
|
130
|
-
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
|
131
|
-
let currentIndex = 0;
|
|
132
|
-
let currentContext = options.context;
|
|
133
|
-
let currentInput = options.input;
|
|
134
|
-
const next = async (...[nextOptions]) => {
|
|
135
|
-
const index = currentIndex;
|
|
136
|
-
currentIndex += 1;
|
|
137
|
-
currentContext = { ...currentContext, ...nextOptions?.context };
|
|
138
|
-
if (index === inputValidationIndex) {
|
|
139
|
-
currentInput = await validateInput(procedure, currentInput);
|
|
140
|
-
}
|
|
141
|
-
const mid = middlewares[index];
|
|
142
|
-
const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
|
|
143
|
-
if (index === outputValidationIndex) {
|
|
144
|
-
const validatedOutput = await validateOutput(procedure, result.output);
|
|
145
|
-
return {
|
|
146
|
-
...result,
|
|
147
|
-
output: validatedOutput
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
return result;
|
|
151
|
-
};
|
|
152
|
-
return (await next({})).output;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// src/hidden.ts
|
|
156
|
-
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
|
157
|
-
function setRouterContract(obj, contract) {
|
|
158
|
-
return new Proxy(obj, {
|
|
159
|
-
get(target, key) {
|
|
160
|
-
if (key === ROUTER_CONTRACT_SYMBOL) {
|
|
161
|
-
return contract;
|
|
162
|
-
}
|
|
163
|
-
return Reflect.get(target, key);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
function getRouterContract(obj) {
|
|
168
|
-
return obj[ROUTER_CONTRACT_SYMBOL];
|
|
169
|
-
}
|
|
170
|
-
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
|
171
|
-
function deepSetLazyRouterPrefix(router, prefix) {
|
|
172
|
-
return new Proxy(router, {
|
|
173
|
-
get(target, key) {
|
|
174
|
-
if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
|
|
175
|
-
const val = Reflect.get(target, key);
|
|
176
|
-
if (isLazy(val)) {
|
|
177
|
-
return deepSetLazyRouterPrefix(val, prefix);
|
|
178
|
-
}
|
|
179
|
-
return val;
|
|
180
|
-
}
|
|
181
|
-
return prefix;
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
function getLazyRouterPrefix(obj) {
|
|
186
|
-
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// src/router.ts
|
|
190
|
-
import { adaptRoute, mergeErrorMap, mergePrefix } from "@orpc/contract";
|
|
191
|
-
|
|
192
|
-
// src/middleware-utils.ts
|
|
193
|
-
function dedupeMiddlewares(compare, middlewares) {
|
|
194
|
-
let min = 0;
|
|
195
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
196
|
-
const index = compare.indexOf(middlewares[i], min);
|
|
197
|
-
if (index === -1) {
|
|
198
|
-
return middlewares.slice(i);
|
|
199
|
-
}
|
|
200
|
-
min = index + 1;
|
|
201
|
-
}
|
|
202
|
-
return [];
|
|
203
|
-
}
|
|
204
|
-
function mergeMiddlewares(first, second) {
|
|
205
|
-
return [...first, ...dedupeMiddlewares(first, second)];
|
|
206
|
-
}
|
|
207
|
-
function addMiddleware(middlewares, addition) {
|
|
208
|
-
return [...middlewares, addition];
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// src/router.ts
|
|
212
|
-
function adaptRouter(router, options) {
|
|
213
|
-
if (isLazy(router)) {
|
|
214
|
-
const adapted2 = lazy(async () => {
|
|
215
|
-
const unlaziedRouter = (await unlazy(router)).default;
|
|
216
|
-
const adapted3 = adaptRouter(unlaziedRouter, options);
|
|
217
|
-
return { default: adapted3 };
|
|
218
|
-
});
|
|
219
|
-
const accessible = createAccessibleLazyRouter(adapted2);
|
|
220
|
-
const currentPrefix = getLazyRouterPrefix(router);
|
|
221
|
-
const prefix = currentPrefix ? mergePrefix(options.prefix, currentPrefix) : options.prefix;
|
|
222
|
-
if (prefix) {
|
|
223
|
-
return deepSetLazyRouterPrefix(accessible, prefix);
|
|
224
|
-
}
|
|
225
|
-
return accessible;
|
|
226
|
-
}
|
|
227
|
-
if (isProcedure(router)) {
|
|
228
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
|
|
229
|
-
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
|
230
|
-
const adapted2 = new Procedure({
|
|
231
|
-
...router["~orpc"],
|
|
232
|
-
route: adaptRoute(router["~orpc"].route, options),
|
|
233
|
-
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
234
|
-
middlewares: newMiddlewares,
|
|
235
|
-
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
236
|
-
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
|
237
|
-
});
|
|
238
|
-
return adapted2;
|
|
239
|
-
}
|
|
240
|
-
const adapted = {};
|
|
241
|
-
for (const key in router) {
|
|
242
|
-
adapted[key] = adaptRouter(router[key], options);
|
|
243
|
-
}
|
|
244
|
-
return adapted;
|
|
245
|
-
}
|
|
246
|
-
function getRouterChild(router, ...path) {
|
|
247
|
-
let current = router;
|
|
248
|
-
for (let i = 0; i < path.length; i++) {
|
|
249
|
-
const segment = path[i];
|
|
250
|
-
if (!current) {
|
|
251
|
-
return void 0;
|
|
252
|
-
}
|
|
253
|
-
if (isProcedure(current)) {
|
|
254
|
-
return void 0;
|
|
255
|
-
}
|
|
256
|
-
if (!isLazy(current)) {
|
|
257
|
-
current = current[segment];
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
const lazied = current;
|
|
261
|
-
const rest = path.slice(i);
|
|
262
|
-
const newLazy = lazy(async () => {
|
|
263
|
-
const unwrapped = await unlazy(lazied);
|
|
264
|
-
if (!unwrapped.default) {
|
|
265
|
-
return unwrapped;
|
|
266
|
-
}
|
|
267
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
|
268
|
-
return { default: next };
|
|
269
|
-
});
|
|
270
|
-
return flatLazy(newLazy);
|
|
271
|
-
}
|
|
272
|
-
return current;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// src/router-accessible-lazy.ts
|
|
276
|
-
function createAccessibleLazyRouter(lazied) {
|
|
277
|
-
const flattenLazy = flatLazy(lazied);
|
|
278
|
-
const recursive = new Proxy(flattenLazy, {
|
|
279
|
-
get(target, key) {
|
|
280
|
-
if (typeof key !== "string") {
|
|
281
|
-
return Reflect.get(target, key);
|
|
282
|
-
}
|
|
283
|
-
const next = getRouterChild(flattenLazy, key);
|
|
284
|
-
return createAccessibleLazyRouter(next);
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
return recursive;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// src/utils.ts
|
|
291
|
-
import { isContractProcedure as isContractProcedure2 } from "@orpc/contract";
|
|
292
|
-
function eachContractProcedure(options, callback, laziedOptions = []) {
|
|
293
|
-
const hiddenContract = getRouterContract(options.router);
|
|
294
|
-
if (hiddenContract) {
|
|
295
|
-
return eachContractProcedure(
|
|
296
|
-
{
|
|
297
|
-
router: hiddenContract,
|
|
298
|
-
path: options.path
|
|
299
|
-
},
|
|
300
|
-
callback,
|
|
301
|
-
laziedOptions
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
if (isLazy(options.router)) {
|
|
305
|
-
laziedOptions.push({
|
|
306
|
-
lazied: options.router,
|
|
307
|
-
path: options.path
|
|
308
|
-
});
|
|
309
|
-
} else if (isContractProcedure2(options.router)) {
|
|
310
|
-
callback({
|
|
311
|
-
contract: options.router,
|
|
312
|
-
path: options.path
|
|
313
|
-
});
|
|
314
|
-
} else {
|
|
315
|
-
for (const key in options.router) {
|
|
316
|
-
eachContractProcedure(
|
|
317
|
-
{
|
|
318
|
-
router: options.router[key],
|
|
319
|
-
path: [...options.path, key]
|
|
320
|
-
},
|
|
321
|
-
callback,
|
|
322
|
-
laziedOptions
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return laziedOptions;
|
|
327
|
-
}
|
|
328
|
-
async function eachAllContractProcedure(options, callback) {
|
|
329
|
-
const pending = [options];
|
|
330
|
-
for (const item of pending) {
|
|
331
|
-
const lazies = eachContractProcedure(item, callback);
|
|
332
|
-
for (const lazy2 of lazies) {
|
|
333
|
-
const { default: router } = await unlazy(lazy2.lazied);
|
|
334
|
-
pending.push({
|
|
335
|
-
path: lazy2.path,
|
|
336
|
-
router
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
function convertPathToHttpPath(path) {
|
|
342
|
-
return `/${path.map(encodeURIComponent).join("/")}`;
|
|
343
|
-
}
|
|
344
|
-
function createContractedProcedure(contract, procedure) {
|
|
345
|
-
return new Procedure({
|
|
346
|
-
...procedure["~orpc"],
|
|
347
|
-
errorMap: contract["~orpc"].errorMap,
|
|
348
|
-
route: contract["~orpc"].route,
|
|
349
|
-
meta: contract["~orpc"].meta
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
export {
|
|
354
|
-
LAZY_LOADER_SYMBOL,
|
|
355
|
-
lazy,
|
|
356
|
-
isLazy,
|
|
357
|
-
unlazy,
|
|
358
|
-
Procedure,
|
|
359
|
-
isProcedure,
|
|
360
|
-
flatLazy,
|
|
361
|
-
createLazyProcedureFormAnyLazy,
|
|
362
|
-
addMiddleware,
|
|
363
|
-
middlewareOutputFn,
|
|
364
|
-
createProcedureClient,
|
|
365
|
-
setRouterContract,
|
|
366
|
-
getRouterContract,
|
|
367
|
-
deepSetLazyRouterPrefix,
|
|
368
|
-
getLazyRouterPrefix,
|
|
369
|
-
createAccessibleLazyRouter,
|
|
370
|
-
adaptRouter,
|
|
371
|
-
getRouterChild,
|
|
372
|
-
eachContractProcedure,
|
|
373
|
-
eachAllContractProcedure,
|
|
374
|
-
convertPathToHttpPath,
|
|
375
|
-
createContractedProcedure
|
|
376
|
-
};
|
|
377
|
-
//# sourceMappingURL=chunk-EDQKEHUX.js.map
|