@orpc/server 0.0.0-next.4e27480 → 0.0.0-next.4f28b69
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 +179 -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 +91 -28
- package/dist/chunk-GK2Z6B6W.js +0 -230
- package/dist/chunk-SXUFCJBY.js +0 -301
- package/dist/chunk-WUOGVGWG.js +0 -1
- package/dist/fetch.js +0 -15
- package/dist/hono.js +0 -30
- package/dist/index.js +0 -1043
- package/dist/next.js +0 -36
- package/dist/node.js +0 -87
- package/dist/src/adapters/fetch/index.d.ts +0 -6
- package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/adapters/fetch/super-json.d.ts +0 -12
- package/dist/src/adapters/fetch/types.d.ts +0 -21
- 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 -5
- package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
- package/dist/src/adapters/node/request-listener.d.ts +0 -28
- package/dist/src/adapters/node/types.d.ts +0 -22
- package/dist/src/builder-with-errors-middlewares.d.ts +0 -51
- package/dist/src/builder-with-errors.d.ts +0 -52
- package/dist/src/builder-with-middlewares.d.ts +0 -48
- package/dist/src/builder.d.ts +0 -49
- package/dist/src/config.d.ts +0 -6
- package/dist/src/context.d.ts +0 -11
- package/dist/src/error.d.ts +0 -10
- package/dist/src/hidden.d.ts +0 -6
- package/dist/src/implementer-chainable.d.ts +0 -14
- package/dist/src/index.d.ts +0 -26
- package/dist/src/lazy-decorated.d.ts +0 -7
- package/dist/src/lazy-utils.d.ts +0 -4
- package/dist/src/lazy.d.ts +0 -18
- package/dist/src/middleware-decorated.d.ts +0 -10
- package/dist/src/middleware.d.ts +0 -36
- package/dist/src/procedure-builder-with-input.d.ts +0 -34
- package/dist/src/procedure-builder-with-output.d.ts +0 -33
- package/dist/src/procedure-builder.d.ts +0 -27
- package/dist/src/procedure-client.d.ts +0 -22
- package/dist/src/procedure-decorated.d.ts +0 -26
- package/dist/src/procedure-implementer.d.ts +0 -22
- package/dist/src/procedure-utils.d.ts +0 -17
- package/dist/src/procedure.d.ts +0 -45
- package/dist/src/router-builder.d.ts +0 -33
- package/dist/src/router-client.d.ts +0 -26
- package/dist/src/router-implementer.d.ts +0 -22
- package/dist/src/router.d.ts +0 -16
- package/dist/src/types.d.ts +0 -14
- package/dist/src/utils.d.ts +0 -3
|
@@ -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.4f28b69",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,49 +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
21
|
},
|
|
22
|
-
"./
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"import": "./dist/
|
|
25
|
-
"default": "./dist/
|
|
22
|
+
"./helpers": {
|
|
23
|
+
"types": "./dist/helpers/index.d.mts",
|
|
24
|
+
"import": "./dist/helpers/index.mjs",
|
|
25
|
+
"default": "./dist/helpers/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./plugins": {
|
|
28
|
+
"types": "./dist/plugins/index.d.mts",
|
|
29
|
+
"import": "./dist/plugins/index.mjs",
|
|
30
|
+
"default": "./dist/plugins/index.mjs"
|
|
26
31
|
},
|
|
27
|
-
"./
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/
|
|
30
|
-
"default": "./dist/
|
|
32
|
+
"./hibernation": {
|
|
33
|
+
"types": "./dist/hibernation/index.d.mts",
|
|
34
|
+
"import": "./dist/hibernation/index.mjs",
|
|
35
|
+
"default": "./dist/hibernation/index.mjs"
|
|
31
36
|
},
|
|
32
|
-
"./
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/
|
|
35
|
-
"default": "./dist/
|
|
37
|
+
"./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"
|
|
46
|
+
},
|
|
47
|
+
"./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
52
|
"./node": {
|
|
38
|
-
"types": "./dist/
|
|
39
|
-
"import": "./dist/node.
|
|
40
|
-
"default": "./dist/node.
|
|
53
|
+
"types": "./dist/adapters/node/index.d.mts",
|
|
54
|
+
"import": "./dist/adapters/node/index.mjs",
|
|
55
|
+
"default": "./dist/adapters/node/index.mjs"
|
|
56
|
+
},
|
|
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"
|
|
61
|
+
},
|
|
62
|
+
"./websocket": {
|
|
63
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
64
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
65
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
41
66
|
},
|
|
42
|
-
"
|
|
43
|
-
"types": "./dist/
|
|
67
|
+
"./crossws": {
|
|
68
|
+
"types": "./dist/adapters/crossws/index.d.mts",
|
|
69
|
+
"import": "./dist/adapters/crossws/index.mjs",
|
|
70
|
+
"default": "./dist/adapters/crossws/index.mjs"
|
|
71
|
+
},
|
|
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"
|
|
44
86
|
}
|
|
45
87
|
},
|
|
46
88
|
"files": [
|
|
47
|
-
"!**/*.map",
|
|
48
|
-
"!**/*.tsbuildinfo",
|
|
49
89
|
"dist"
|
|
50
90
|
],
|
|
51
91
|
"peerDependencies": {
|
|
52
|
-
"
|
|
53
|
-
"
|
|
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
|
+
}
|
|
54
102
|
},
|
|
55
103
|
"dependencies": {
|
|
56
|
-
"
|
|
57
|
-
"@orpc/
|
|
104
|
+
"cookie": "^1.0.2",
|
|
105
|
+
"@orpc/client": "0.0.0-next.4f28b69",
|
|
106
|
+
"@orpc/contract": "0.0.0-next.4f28b69",
|
|
107
|
+
"@orpc/interop": "0.0.0-next.4f28b69",
|
|
108
|
+
"@orpc/shared": "0.0.0-next.4f28b69",
|
|
109
|
+
"@orpc/standard-server": "0.0.0-next.4f28b69",
|
|
110
|
+
"@orpc/standard-server-aws-lambda": "0.0.0-next.4f28b69",
|
|
111
|
+
"@orpc/standard-server-node": "0.0.0-next.4f28b69",
|
|
112
|
+
"@orpc/standard-server-fetch": "0.0.0-next.4f28b69",
|
|
113
|
+
"@orpc/standard-server-peer": "0.0.0-next.4f28b69"
|
|
114
|
+
},
|
|
115
|
+
"devDependencies": {
|
|
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"
|
|
58
121
|
},
|
|
59
122
|
"scripts": {
|
|
60
|
-
"build": "
|
|
123
|
+
"build": "unbuild",
|
|
61
124
|
"build:watch": "pnpm run build --watch",
|
|
62
125
|
"type:check": "tsc -b"
|
|
63
126
|
}
|
package/dist/chunk-GK2Z6B6W.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// src/utils.ts
|
|
8
|
-
function mergeContext(a, b) {
|
|
9
|
-
if (!a)
|
|
10
|
-
return b;
|
|
11
|
-
if (!b)
|
|
12
|
-
return a;
|
|
13
|
-
return {
|
|
14
|
-
...a,
|
|
15
|
-
...b
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// src/procedure.ts
|
|
20
|
-
import { isContractProcedure } from "@orpc/contract";
|
|
21
|
-
var Procedure = class {
|
|
22
|
-
"~type" = "Procedure";
|
|
23
|
-
"~orpc";
|
|
24
|
-
constructor(def) {
|
|
25
|
-
this["~orpc"] = def;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
function isProcedure(item) {
|
|
29
|
-
if (item instanceof Procedure) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "Procedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "contract" in item["~orpc"] && isContractProcedure(item["~orpc"].contract) && "handler" in item["~orpc"] && typeof item["~orpc"].handler === "function";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/error.ts
|
|
36
|
-
import { ORPCError } from "@orpc/contract";
|
|
37
|
-
function createORPCErrorConstructorMap(errors) {
|
|
38
|
-
const constructors = {};
|
|
39
|
-
for (const code in errors) {
|
|
40
|
-
const config = errors[code];
|
|
41
|
-
if (!config) {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const constructor = (...[options]) => {
|
|
45
|
-
return new ORPCError({
|
|
46
|
-
code,
|
|
47
|
-
defined: true,
|
|
48
|
-
status: config.status,
|
|
49
|
-
message: options?.message ?? config.message,
|
|
50
|
-
data: options?.data,
|
|
51
|
-
cause: options?.cause
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
constructors[code] = constructor;
|
|
55
|
-
}
|
|
56
|
-
return constructors;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/lazy.ts
|
|
60
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
|
61
|
-
function lazy(loader) {
|
|
62
|
-
return {
|
|
63
|
-
[LAZY_LOADER_SYMBOL]: loader
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function isLazy(item) {
|
|
67
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
|
68
|
-
}
|
|
69
|
-
function unlazy(lazied) {
|
|
70
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
|
71
|
-
}
|
|
72
|
-
function flatLazy(lazied) {
|
|
73
|
-
const flattenLoader = async () => {
|
|
74
|
-
let current = await unlazy(lazied);
|
|
75
|
-
while (true) {
|
|
76
|
-
if (!isLazy(current.default)) {
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
current = await unlazy(current.default);
|
|
80
|
-
}
|
|
81
|
-
return current;
|
|
82
|
-
};
|
|
83
|
-
return lazy(flattenLoader);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// src/middleware.ts
|
|
87
|
-
function middlewareOutputFn(output) {
|
|
88
|
-
return { output, context: void 0 };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/procedure-client.ts
|
|
92
|
-
import { ORPCError as ORPCError2, validateORPCError, ValidationError } from "@orpc/contract";
|
|
93
|
-
import { executeWithHooks, toError, value } from "@orpc/shared";
|
|
94
|
-
function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
95
|
-
return async (...[input, callerOptions]) => {
|
|
96
|
-
const path = options?.path ?? [];
|
|
97
|
-
const { default: procedure } = await unlazy(lazyableProcedure);
|
|
98
|
-
const context = await value(options?.context, callerOptions?.context);
|
|
99
|
-
const errors = createORPCErrorConstructorMap(procedure["~orpc"].contract["~orpc"].errorMap);
|
|
100
|
-
const executeOptions = {
|
|
101
|
-
input,
|
|
102
|
-
context,
|
|
103
|
-
errors,
|
|
104
|
-
path,
|
|
105
|
-
procedure,
|
|
106
|
-
signal: callerOptions?.signal
|
|
107
|
-
};
|
|
108
|
-
try {
|
|
109
|
-
const output = await executeWithHooks({
|
|
110
|
-
hooks: options,
|
|
111
|
-
input,
|
|
112
|
-
context,
|
|
113
|
-
meta: executeOptions,
|
|
114
|
-
execute: () => executeProcedureInternal(procedure, executeOptions)
|
|
115
|
-
});
|
|
116
|
-
return output;
|
|
117
|
-
} catch (e) {
|
|
118
|
-
if (!(e instanceof ORPCError2)) {
|
|
119
|
-
throw toError(e);
|
|
120
|
-
}
|
|
121
|
-
const validated = await validateORPCError(procedure["~orpc"].contract["~orpc"].errorMap, e);
|
|
122
|
-
throw validated;
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
async function validateInput(procedure, input) {
|
|
127
|
-
const schema = procedure["~orpc"].contract["~orpc"].InputSchema;
|
|
128
|
-
if (!schema)
|
|
129
|
-
return input;
|
|
130
|
-
const result = await schema["~standard"].validate(input);
|
|
131
|
-
if (result.issues) {
|
|
132
|
-
throw new ORPCError2({
|
|
133
|
-
message: "Input validation failed",
|
|
134
|
-
code: "BAD_REQUEST",
|
|
135
|
-
data: {
|
|
136
|
-
issues: result.issues
|
|
137
|
-
},
|
|
138
|
-
cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
return result.value;
|
|
142
|
-
}
|
|
143
|
-
async function validateOutput(procedure, output) {
|
|
144
|
-
const schema = procedure["~orpc"].contract["~orpc"].OutputSchema;
|
|
145
|
-
if (!schema)
|
|
146
|
-
return output;
|
|
147
|
-
const result = await schema["~standard"].validate(output);
|
|
148
|
-
if (result.issues) {
|
|
149
|
-
throw new ORPCError2({
|
|
150
|
-
message: "Output validation failed",
|
|
151
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
152
|
-
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
return result.value;
|
|
156
|
-
}
|
|
157
|
-
async function executeProcedureInternal(procedure, options) {
|
|
158
|
-
const middlewares = procedure["~orpc"].middlewares;
|
|
159
|
-
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
|
160
|
-
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
|
161
|
-
let currentIndex = 0;
|
|
162
|
-
let currentContext = options.context;
|
|
163
|
-
let currentInput = options.input;
|
|
164
|
-
const next = async (nextOptions) => {
|
|
165
|
-
const index = currentIndex;
|
|
166
|
-
currentIndex += 1;
|
|
167
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
|
168
|
-
if (index === inputValidationIndex) {
|
|
169
|
-
currentInput = await validateInput(procedure, currentInput);
|
|
170
|
-
}
|
|
171
|
-
const mid = middlewares[index];
|
|
172
|
-
const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
|
|
173
|
-
if (index === outputValidationIndex) {
|
|
174
|
-
const validatedOutput = await validateOutput(procedure, result.output);
|
|
175
|
-
return {
|
|
176
|
-
...result,
|
|
177
|
-
output: validatedOutput
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
return result;
|
|
181
|
-
};
|
|
182
|
-
return (await next({})).output;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// src/router.ts
|
|
186
|
-
function getRouterChild(router, ...path) {
|
|
187
|
-
let current = router;
|
|
188
|
-
for (let i = 0; i < path.length; i++) {
|
|
189
|
-
const segment = path[i];
|
|
190
|
-
if (!current) {
|
|
191
|
-
return void 0;
|
|
192
|
-
}
|
|
193
|
-
if (isProcedure(current)) {
|
|
194
|
-
return void 0;
|
|
195
|
-
}
|
|
196
|
-
if (!isLazy(current)) {
|
|
197
|
-
current = current[segment];
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
const lazied = current;
|
|
201
|
-
const rest = path.slice(i);
|
|
202
|
-
const newLazy = lazy(async () => {
|
|
203
|
-
const unwrapped = await unlazy(lazied);
|
|
204
|
-
if (!unwrapped.default) {
|
|
205
|
-
return unwrapped;
|
|
206
|
-
}
|
|
207
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
|
208
|
-
return { default: next };
|
|
209
|
-
});
|
|
210
|
-
return flatLazy(newLazy);
|
|
211
|
-
}
|
|
212
|
-
return current;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export {
|
|
216
|
-
__export,
|
|
217
|
-
mergeContext,
|
|
218
|
-
Procedure,
|
|
219
|
-
isProcedure,
|
|
220
|
-
createORPCErrorConstructorMap,
|
|
221
|
-
LAZY_LOADER_SYMBOL,
|
|
222
|
-
lazy,
|
|
223
|
-
isLazy,
|
|
224
|
-
unlazy,
|
|
225
|
-
flatLazy,
|
|
226
|
-
middlewareOutputFn,
|
|
227
|
-
createProcedureClient,
|
|
228
|
-
getRouterChild
|
|
229
|
-
};
|
|
230
|
-
//# sourceMappingURL=chunk-GK2Z6B6W.js.map
|