@orpc/server 0.0.0-next.3cb80cf → 0.0.0-next.3ee2e95
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 +131 -0
- package/dist/adapters/fetch/index.d.mts +58 -0
- package/dist/adapters/fetch/index.d.ts +58 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +22 -0
- package/dist/adapters/hono/index.d.ts +22 -0
- package/dist/{hono.js → adapters/hono/index.mjs} +11 -13
- package/dist/adapters/next/index.d.mts +29 -0
- package/dist/adapters/next/index.d.ts +29 -0
- package/dist/{next.js → adapters/next/index.mjs} +11 -13
- package/dist/adapters/node/index.d.mts +57 -0
- package/dist/adapters/node/index.d.ts +57 -0
- package/dist/adapters/node/index.mjs +92 -0
- package/dist/adapters/standard/index.d.mts +26 -0
- package/dist/adapters/standard/index.d.ts +26 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/index.d.mts +291 -0
- package/dist/index.d.ts +291 -0
- package/dist/{index.js → index.mjs} +107 -157
- package/dist/plugins/index.d.mts +124 -0
- package/dist/plugins/index.d.ts +124 -0
- package/dist/plugins/index.mjs +276 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/{chunk-MHVECKBC.js → shared/server.C37gDhSZ.mjs} +167 -224
- package/dist/shared/server.C56IpPNj.d.mts +10 -0
- package/dist/{chunk-LXOL226G.js → shared/server.C78d5yfh.mjs} +64 -73
- package/dist/shared/server.CSIDw0mq.mjs +106 -0
- package/dist/shared/server.CyrwhzzU.d.ts +8 -0
- package/dist/shared/server.DLt5njUb.d.mts +143 -0
- package/dist/shared/server.DLt5njUb.d.ts +143 -0
- package/dist/shared/server.DfyOFejj.d.ts +73 -0
- package/dist/shared/server.DgrNIRDf.d.mts +8 -0
- package/dist/shared/server.Dm5DEJl5.d.mts +73 -0
- package/dist/shared/server.DnuwaDJo.d.ts +10 -0
- package/package.json +30 -35
- package/dist/chunk-KPT6FDBK.js +0 -32
- package/dist/chunk-XI6WGCB3.js +0 -125
- package/dist/fetch.js +0 -10
- package/dist/node.js +0 -31
- package/dist/plugins.js +0 -11
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/fetch/types.d.ts +0 -14
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -12
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -19
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/node/types.d.ts +0 -22
- package/dist/src/adapters/standard/handler.d.ts +0 -51
- package/dist/src/adapters/standard/index.d.ts +0 -6
- package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
- package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
- package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
- package/dist/src/adapters/standard/types.d.ts +0 -21
- package/dist/src/builder-variants.d.ts +0 -75
- package/dist/src/builder.d.ts +0 -58
- package/dist/src/config.d.ts +0 -6
- package/dist/src/context.d.ts +0 -8
- package/dist/src/error.d.ts +0 -12
- package/dist/src/hidden.d.ts +0 -8
- package/dist/src/implementer-procedure.d.ts +0 -33
- package/dist/src/implementer-variants.d.ts +0 -18
- package/dist/src/implementer.d.ts +0 -29
- package/dist/src/index.d.ts +0 -25
- package/dist/src/lazy-utils.d.ts +0 -6
- package/dist/src/lazy.d.ts +0 -22
- package/dist/src/middleware-decorated.d.ts +0 -11
- package/dist/src/middleware-utils.d.ts +0 -5
- package/dist/src/middleware.d.ts +0 -38
- package/dist/src/plugins/base.d.ts +0 -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 -33
- package/dist/src/procedure-decorated.d.ts +0 -24
- package/dist/src/procedure-utils.d.ts +0 -19
- package/dist/src/procedure.d.ts +0 -31
- package/dist/src/router-accessible-lazy.d.ts +0 -8
- package/dist/src/router-client.d.ts +0 -12
- package/dist/src/router.d.ts +0 -30
- package/dist/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -13
@@ -0,0 +1,73 @@
|
|
1
|
+
import { HTTPPath, ORPCError } from '@orpc/client';
|
2
|
+
import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
|
3
|
+
import { Interceptor, ThrowableError } from '@orpc/shared';
|
4
|
+
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
5
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.js';
|
6
|
+
|
7
|
+
type StandardParams = Record<string, string>;
|
8
|
+
type StandardMatchResult = {
|
9
|
+
path: readonly 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
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
24
|
+
order?: number;
|
25
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
26
|
+
}
|
27
|
+
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
28
|
+
protected readonly plugins: TPlugin[];
|
29
|
+
constructor(plugins?: readonly TPlugin[]);
|
30
|
+
init(options: StandardHandlerOptions<T>): void;
|
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>, StandardHandleResult, ThrowableError>[];
|
53
|
+
/**
|
54
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
55
|
+
*/
|
56
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
57
|
+
/**
|
58
|
+
*
|
59
|
+
* Interceptors for procedure client.
|
60
|
+
*/
|
61
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
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, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardCodec as b, type StandardParams as c, type StandardMatcher as d, type StandardMatchResult as e, type StandardHandleResult as f, type StandardHandlerInterceptorOptions as g, StandardHandler as h, type StandardHandlerPlugin as i };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.DLt5njUb.mjs';
|
3
|
+
import { a as StandardHandlerOptions } from './server.Dm5DEJl5.mjs';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { HTTPPath, ORPCError } from '@orpc/client';
|
2
|
+
import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
|
3
|
+
import { Interceptor, ThrowableError } from '@orpc/shared';
|
4
|
+
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
5
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.mjs';
|
6
|
+
|
7
|
+
type StandardParams = Record<string, string>;
|
8
|
+
type StandardMatchResult = {
|
9
|
+
path: readonly 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
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
24
|
+
order?: number;
|
25
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
26
|
+
}
|
27
|
+
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
28
|
+
protected readonly plugins: TPlugin[];
|
29
|
+
constructor(plugins?: readonly TPlugin[]);
|
30
|
+
init(options: StandardHandlerOptions<T>): void;
|
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>, StandardHandleResult, ThrowableError>[];
|
53
|
+
/**
|
54
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
55
|
+
*/
|
56
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
57
|
+
/**
|
58
|
+
*
|
59
|
+
* Interceptors for procedure client.
|
60
|
+
*/
|
61
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
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, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardCodec as b, type StandardParams as c, type StandardMatcher as d, type StandardMatchResult as e, type StandardHandleResult as f, type StandardHandlerInterceptorOptions as g, StandardHandler as h, type StandardHandlerPlugin as i };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { C as Context } from './server.DLt5njUb.js';
|
2
|
+
import { S as StandardHandleOptions } from './server.DfyOFejj.js';
|
3
|
+
|
4
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
5
|
+
context?: T;
|
6
|
+
} : {
|
7
|
+
context: T;
|
8
|
+
});
|
9
|
+
|
10
|
+
export type { FriendlyStandardHandleOptions as F };
|
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.3ee2e95",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -15,47 +15,42 @@
|
|
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
22
|
"./plugins": {
|
23
|
-
"types": "./dist/
|
24
|
-
"import": "./dist/plugins.
|
25
|
-
"default": "./dist/plugins.
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
26
26
|
},
|
27
27
|
"./standard": {
|
28
|
-
"types": "./dist/
|
29
|
-
"import": "./dist/standard.
|
30
|
-
"default": "./dist/standard.
|
28
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
29
|
+
"import": "./dist/adapters/standard/index.mjs",
|
30
|
+
"default": "./dist/adapters/standard/index.mjs"
|
31
31
|
},
|
32
32
|
"./fetch": {
|
33
|
-
"types": "./dist/
|
34
|
-
"import": "./dist/fetch.
|
35
|
-
"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
36
|
},
|
37
37
|
"./hono": {
|
38
|
-
"types": "./dist/
|
39
|
-
"import": "./dist/hono.
|
40
|
-
"default": "./dist/hono.
|
38
|
+
"types": "./dist/adapters/hono/index.d.mts",
|
39
|
+
"import": "./dist/adapters/hono/index.mjs",
|
40
|
+
"default": "./dist/adapters/hono/index.mjs"
|
41
41
|
},
|
42
42
|
"./next": {
|
43
|
-
"types": "./dist/
|
44
|
-
"import": "./dist/next.
|
45
|
-
"default": "./dist/next.
|
43
|
+
"types": "./dist/adapters/next/index.d.mts",
|
44
|
+
"import": "./dist/adapters/next/index.mjs",
|
45
|
+
"default": "./dist/adapters/next/index.mjs"
|
46
46
|
},
|
47
47
|
"./node": {
|
48
|
-
"types": "./dist/
|
49
|
-
"import": "./dist/node.
|
50
|
-
"default": "./dist/node.
|
51
|
-
},
|
52
|
-
"./🔒/*": {
|
53
|
-
"types": "./dist/src/*.d.ts"
|
48
|
+
"types": "./dist/adapters/node/index.d.mts",
|
49
|
+
"import": "./dist/adapters/node/index.mjs",
|
50
|
+
"default": "./dist/adapters/node/index.mjs"
|
54
51
|
}
|
55
52
|
},
|
56
53
|
"files": [
|
57
|
-
"!**/*.map",
|
58
|
-
"!**/*.tsbuildinfo",
|
59
54
|
"dist"
|
60
55
|
],
|
61
56
|
"peerDependencies": {
|
@@ -63,18 +58,18 @@
|
|
63
58
|
"next": ">=14.0.0"
|
64
59
|
},
|
65
60
|
"dependencies": {
|
66
|
-
"@orpc/
|
67
|
-
"@orpc/
|
68
|
-
"@orpc/
|
69
|
-
"@orpc/
|
70
|
-
"@orpc/
|
71
|
-
"@orpc/
|
61
|
+
"@orpc/shared": "0.0.0-next.3ee2e95",
|
62
|
+
"@orpc/client": "0.0.0-next.3ee2e95",
|
63
|
+
"@orpc/standard-server": "0.0.0-next.3ee2e95",
|
64
|
+
"@orpc/standard-server-fetch": "0.0.0-next.3ee2e95",
|
65
|
+
"@orpc/standard-server-node": "0.0.0-next.3ee2e95",
|
66
|
+
"@orpc/contract": "0.0.0-next.3ee2e95"
|
72
67
|
},
|
73
68
|
"devDependencies": {
|
74
|
-
"
|
69
|
+
"supertest": "^7.0.0"
|
75
70
|
},
|
76
71
|
"scripts": {
|
77
|
-
"build": "
|
72
|
+
"build": "unbuild",
|
78
73
|
"build:watch": "pnpm run build --watch",
|
79
74
|
"type:check": "tsc -b"
|
80
75
|
}
|
package/dist/chunk-KPT6FDBK.js
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCCodec,
|
3
|
-
RPCMatcher,
|
4
|
-
StandardHandler
|
5
|
-
} from "./chunk-LXOL226G.js";
|
6
|
-
|
7
|
-
// src/adapters/fetch/rpc-handler.ts
|
8
|
-
import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
|
9
|
-
var RPCHandler = class {
|
10
|
-
standardHandler;
|
11
|
-
constructor(router, options) {
|
12
|
-
const matcher = options?.matcher ?? new RPCMatcher();
|
13
|
-
const codec = options?.codec ?? new RPCCodec();
|
14
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
15
|
-
}
|
16
|
-
async handle(request, ...rest) {
|
17
|
-
const standardRequest = toStandardRequest(request);
|
18
|
-
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
19
|
-
if (!result.matched) {
|
20
|
-
return result;
|
21
|
-
}
|
22
|
-
return {
|
23
|
-
matched: true,
|
24
|
-
response: toFetchResponse(result.response)
|
25
|
-
};
|
26
|
-
}
|
27
|
-
};
|
28
|
-
|
29
|
-
export {
|
30
|
-
RPCHandler
|
31
|
-
};
|
32
|
-
//# sourceMappingURL=chunk-KPT6FDBK.js.map
|
package/dist/chunk-XI6WGCB3.js
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
// src/plugins/base.ts
|
2
|
-
var CompositePlugin = class {
|
3
|
-
constructor(plugins = []) {
|
4
|
-
this.plugins = plugins;
|
5
|
-
}
|
6
|
-
init(options) {
|
7
|
-
for (const plugin of this.plugins) {
|
8
|
-
plugin.init?.(options);
|
9
|
-
}
|
10
|
-
}
|
11
|
-
beforeCreateProcedureClient(clientOptions, interceptorOptions) {
|
12
|
-
for (const plugin of this.plugins) {
|
13
|
-
plugin.beforeCreateProcedureClient?.(clientOptions, interceptorOptions);
|
14
|
-
}
|
15
|
-
}
|
16
|
-
};
|
17
|
-
|
18
|
-
// src/plugins/cors.ts
|
19
|
-
import { value } from "@orpc/shared";
|
20
|
-
var CORSPlugin = class {
|
21
|
-
options;
|
22
|
-
constructor(options) {
|
23
|
-
const defaults = {
|
24
|
-
origin: (origin) => origin,
|
25
|
-
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
26
|
-
};
|
27
|
-
this.options = {
|
28
|
-
...defaults,
|
29
|
-
...options
|
30
|
-
};
|
31
|
-
}
|
32
|
-
init(options) {
|
33
|
-
options.interceptorsRoot ??= [];
|
34
|
-
options.interceptorsRoot.unshift(async (interceptorOptions) => {
|
35
|
-
if (interceptorOptions.request.method === "OPTIONS") {
|
36
|
-
const resHeaders = {};
|
37
|
-
if (this.options.maxAge !== void 0) {
|
38
|
-
resHeaders["access-control-max-age"] = this.options.maxAge.toString();
|
39
|
-
}
|
40
|
-
if (this.options.allowMethods?.length) {
|
41
|
-
resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
|
42
|
-
}
|
43
|
-
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
44
|
-
if (Array.isArray(allowHeaders) && allowHeaders.length) {
|
45
|
-
resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
|
46
|
-
} else if (typeof allowHeaders === "string") {
|
47
|
-
resHeaders["access-control-allow-headers"] = allowHeaders;
|
48
|
-
}
|
49
|
-
return {
|
50
|
-
matched: true,
|
51
|
-
response: {
|
52
|
-
status: 204,
|
53
|
-
headers: resHeaders,
|
54
|
-
body: void 0
|
55
|
-
}
|
56
|
-
};
|
57
|
-
}
|
58
|
-
return interceptorOptions.next();
|
59
|
-
});
|
60
|
-
options.interceptorsRoot.unshift(async (interceptorOptions) => {
|
61
|
-
const result = await interceptorOptions.next();
|
62
|
-
if (!result.matched) {
|
63
|
-
return result;
|
64
|
-
}
|
65
|
-
const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
|
66
|
-
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
67
|
-
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
68
|
-
if (allowedOriginArr.includes("*")) {
|
69
|
-
result.response.headers["access-control-allow-origin"] = "*";
|
70
|
-
} else {
|
71
|
-
if (allowedOriginArr.includes(origin)) {
|
72
|
-
result.response.headers["access-control-allow-origin"] = origin;
|
73
|
-
}
|
74
|
-
result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
|
75
|
-
}
|
76
|
-
const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
|
77
|
-
const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
|
78
|
-
if (allowedTimingOriginArr.includes("*")) {
|
79
|
-
result.response.headers["timing-allow-origin"] = "*";
|
80
|
-
} else if (allowedTimingOriginArr.includes(origin)) {
|
81
|
-
result.response.headers["timing-allow-origin"] = origin;
|
82
|
-
}
|
83
|
-
if (this.options.credentials) {
|
84
|
-
result.response.headers["access-control-allow-credentials"] = "true";
|
85
|
-
}
|
86
|
-
if (this.options.exposeHeaders?.length) {
|
87
|
-
result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
|
88
|
-
}
|
89
|
-
return result;
|
90
|
-
});
|
91
|
-
}
|
92
|
-
};
|
93
|
-
|
94
|
-
// src/plugins/response-headers.ts
|
95
|
-
var ResponseHeadersPlugin = class {
|
96
|
-
init(options) {
|
97
|
-
options.interceptorsRoot ??= [];
|
98
|
-
options.interceptorsRoot.push(async (interceptorOptions) => {
|
99
|
-
const headers = new Headers();
|
100
|
-
interceptorOptions.context.resHeaders = headers;
|
101
|
-
const result = await interceptorOptions.next();
|
102
|
-
if (!result.matched) {
|
103
|
-
return result;
|
104
|
-
}
|
105
|
-
const responseHeaders = result.response.headers;
|
106
|
-
for (const [key, value2] of headers) {
|
107
|
-
if (Array.isArray(responseHeaders[key])) {
|
108
|
-
responseHeaders[key].push(value2);
|
109
|
-
} else if (responseHeaders[key] !== void 0) {
|
110
|
-
responseHeaders[key] = [responseHeaders[key], value2];
|
111
|
-
} else {
|
112
|
-
responseHeaders[key] = value2;
|
113
|
-
}
|
114
|
-
}
|
115
|
-
return result;
|
116
|
-
});
|
117
|
-
}
|
118
|
-
};
|
119
|
-
|
120
|
-
export {
|
121
|
-
CompositePlugin,
|
122
|
-
CORSPlugin,
|
123
|
-
ResponseHeadersPlugin
|
124
|
-
};
|
125
|
-
//# sourceMappingURL=chunk-XI6WGCB3.js.map
|
package/dist/fetch.js
DELETED
package/dist/node.js
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCCodec,
|
3
|
-
RPCMatcher,
|
4
|
-
StandardHandler
|
5
|
-
} from "./chunk-LXOL226G.js";
|
6
|
-
import "./chunk-MHVECKBC.js";
|
7
|
-
import "./chunk-XI6WGCB3.js";
|
8
|
-
|
9
|
-
// src/adapters/node/rpc-handler.ts
|
10
|
-
import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
|
11
|
-
var RPCHandler = class {
|
12
|
-
standardHandler;
|
13
|
-
constructor(router, options) {
|
14
|
-
const codec = options?.codec ?? new RPCCodec();
|
15
|
-
const matcher = options?.matcher ?? new RPCMatcher();
|
16
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
17
|
-
}
|
18
|
-
async handle(req, res, ...rest) {
|
19
|
-
const standardRequest = toStandardRequest(req, res);
|
20
|
-
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
21
|
-
if (!result.matched) {
|
22
|
-
return { matched: false };
|
23
|
-
}
|
24
|
-
await sendStandardResponse(res, result.response);
|
25
|
-
return { matched: true };
|
26
|
-
}
|
27
|
-
};
|
28
|
-
export {
|
29
|
-
RPCHandler
|
30
|
-
};
|
31
|
-
//# sourceMappingURL=node.js.map
|
package/dist/plugins.js
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { Router } from '../../router';
|
4
|
-
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
5
|
-
import type { FetchHandler, FetchHandleResult } from './types';
|
6
|
-
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
7
|
-
private readonly standardHandler;
|
8
|
-
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
9
|
-
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
10
|
-
}
|
11
|
-
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { StandardHandleOptions } from '../standard';
|
4
|
-
export type FetchHandleResult = {
|
5
|
-
matched: true;
|
6
|
-
response: Response;
|
7
|
-
} | {
|
8
|
-
matched: false;
|
9
|
-
response: undefined;
|
10
|
-
};
|
11
|
-
export interface FetchHandler<T extends Context> {
|
12
|
-
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
13
|
-
}
|
14
|
-
//# sourceMappingURL=types.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions, Value } from '@orpc/shared';
|
2
|
-
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
3
|
-
import type { Context } from '../../context';
|
4
|
-
import type { FetchHandler } from '../fetch';
|
5
|
-
import type { StandardHandleOptions } from '../standard';
|
6
|
-
export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
|
-
context?: Value<T, [HonoContext]>;
|
8
|
-
} : {
|
9
|
-
context: Value<T, [HonoContext]>;
|
10
|
-
});
|
11
|
-
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
12
|
-
//# sourceMappingURL=middleware.d.ts.map
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions, Value } from '@orpc/shared';
|
2
|
-
import type { NextRequest } from 'next/server';
|
3
|
-
import type { Context } from '../../context';
|
4
|
-
import type { FetchHandler } from '../fetch';
|
5
|
-
import type { StandardHandleOptions } from '../standard';
|
6
|
-
export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
|
-
context?: Value<T, [NextRequest]>;
|
8
|
-
} : {
|
9
|
-
context: Value<T, [NextRequest]>;
|
10
|
-
});
|
11
|
-
export interface ServeResult {
|
12
|
-
GET(req: NextRequest): Promise<Response>;
|
13
|
-
POST(req: NextRequest): Promise<Response>;
|
14
|
-
PUT(req: NextRequest): Promise<Response>;
|
15
|
-
PATCH(req: NextRequest): Promise<Response>;
|
16
|
-
DELETE(req: NextRequest): Promise<Response>;
|
17
|
-
}
|
18
|
-
export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
19
|
-
//# sourceMappingURL=serve.d.ts.map
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { Router } from '../../router';
|
4
|
-
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
5
|
-
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
|
6
|
-
export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
|
7
|
-
private readonly standardHandler;
|
8
|
-
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
9
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
10
|
-
}
|
11
|
-
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import type { IncomingMessage, ServerResponse } from 'node:http';
|
3
|
-
import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
4
|
-
import type { Context } from '../../context';
|
5
|
-
import type { StandardHandleOptions } from '../standard';
|
6
|
-
export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
7
|
-
/**
|
8
|
-
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
9
|
-
* This is useful for `express.js` middleware.
|
10
|
-
*/
|
11
|
-
originalUrl?: string;
|
12
|
-
};
|
13
|
-
export type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
14
|
-
export type NodeHttpHandleResult = {
|
15
|
-
matched: true;
|
16
|
-
} | {
|
17
|
-
matched: false;
|
18
|
-
};
|
19
|
-
export interface NodeHttpHandler<T extends Context> {
|
20
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
21
|
-
}
|
22
|
-
//# sourceMappingURL=types.d.ts.map
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import type { ErrorMap, HTTPPath, Meta, Schema } from '@orpc/contract';
|
2
|
-
import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
|
3
|
-
import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
-
import type { Context } from '../../context';
|
5
|
-
import type { Plugin } from '../../plugins';
|
6
|
-
import type { CreateProcedureClientOptions } from '../../procedure-client';
|
7
|
-
import type { Router } from '../../router';
|
8
|
-
import type { StandardCodec, StandardMatcher } from './types';
|
9
|
-
export type StandardHandleOptions<T extends Context> = {
|
10
|
-
prefix?: HTTPPath;
|
11
|
-
} & (Record<never, never> extends T ? {
|
12
|
-
context?: T;
|
13
|
-
} : {
|
14
|
-
context: T;
|
15
|
-
});
|
16
|
-
export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
17
|
-
context: T;
|
18
|
-
};
|
19
|
-
export type StandardHandleResult = {
|
20
|
-
matched: true;
|
21
|
-
response: StandardResponse;
|
22
|
-
} | {
|
23
|
-
matched: false;
|
24
|
-
response: undefined;
|
25
|
-
};
|
26
|
-
export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
|
27
|
-
request: StandardRequest;
|
28
|
-
};
|
29
|
-
export type WellCreateProcedureClientOptions<TContext extends Context> = CreateProcedureClientOptions<TContext, Schema, Schema, unknown, ErrorMap, Meta, Record<never, never>> & {
|
30
|
-
context: TContext;
|
31
|
-
};
|
32
|
-
export interface StandardHandlerOptions<TContext extends Context> {
|
33
|
-
plugins?: Plugin<TContext>[];
|
34
|
-
/**
|
35
|
-
* Interceptors at the request level, helpful when you want catch errors
|
36
|
-
*/
|
37
|
-
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
38
|
-
/**
|
39
|
-
* Interceptors at the root level, helpful when you want override the response
|
40
|
-
*/
|
41
|
-
interceptorsRoot?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
42
|
-
}
|
43
|
-
export declare class StandardHandler<T extends Context> {
|
44
|
-
private readonly matcher;
|
45
|
-
private readonly codec;
|
46
|
-
private readonly options;
|
47
|
-
private readonly plugin;
|
48
|
-
constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
|
49
|
-
handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
50
|
-
}
|
51
|
-
//# sourceMappingURL=handler.d.ts.map
|