@orpc/server 2.0.0-beta.5 → 2.0.0-beta.50
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 +137 -102
- package/dist/adapters/aws-lambda/handler.d.ts +27 -0
- package/dist/adapters/aws-lambda/handler.js +24 -0
- package/dist/adapters/aws-lambda/index.d.ts +4 -0
- package/dist/adapters/aws-lambda/index.js +2 -0
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +19 -0
- package/dist/adapters/aws-lambda/rpc-handler.js +21 -0
- package/dist/adapters/crossws/handler.d.ts +47 -0
- package/dist/adapters/crossws/handler.js +53 -0
- package/dist/adapters/crossws/index.d.ts +3 -54
- package/dist/adapters/crossws/index.js +2 -0
- package/dist/adapters/crossws/rpc-handler.d.ts +16 -0
- package/dist/adapters/crossws/rpc-handler.js +18 -0
- package/dist/adapters/fastify/handler.d.ts +23 -0
- package/dist/adapters/fastify/handler.js +20 -0
- package/dist/adapters/fastify/index.d.ts +3 -0
- package/dist/adapters/fastify/index.js +2 -0
- package/dist/adapters/fastify/rpc-handler.d.ts +15 -0
- package/dist/adapters/fastify/rpc-handler.js +17 -0
- package/dist/adapters/fetch/handler.d.ts +25 -0
- package/dist/adapters/fetch/handler.js +22 -0
- package/dist/adapters/fetch/index.d.ts +4 -140
- package/dist/adapters/fetch/index.js +3 -0
- package/dist/adapters/fetch/rpc-handler.d.ts +17 -0
- package/dist/adapters/fetch/rpc-handler.js +19 -0
- package/dist/adapters/message-port/handler.d.ts +62 -0
- package/dist/adapters/message-port/handler.js +72 -0
- package/dist/adapters/message-port/index.d.ts +3 -74
- package/dist/adapters/message-port/index.js +2 -0
- package/dist/adapters/message-port/rpc-handler.d.ts +16 -0
- package/dist/adapters/message-port/rpc-handler.js +18 -0
- package/dist/adapters/node/handler.d.ts +23 -0
- package/dist/adapters/node/handler.js +20 -0
- package/dist/adapters/node/index.d.ts +4 -121
- package/dist/adapters/node/index.js +3 -0
- package/dist/adapters/node/rpc-handler.d.ts +16 -0
- package/dist/adapters/node/rpc-handler.js +18 -0
- package/dist/adapters/standard/codec.d.ts +16 -0
- package/dist/adapters/standard/handler.d.ts +68 -0
- package/dist/adapters/standard/handler.js +205 -0
- package/dist/adapters/standard/index.d.ts +7 -19
- package/dist/adapters/standard/index.js +4 -0
- package/dist/adapters/standard/plugin.d.ts +26 -0
- package/dist/adapters/standard/plugin.js +14 -0
- package/dist/adapters/standard/rpc-handler-codec.d.ts +42 -0
- package/dist/adapters/standard/rpc-handler-codec.js +50 -0
- package/dist/adapters/standard/rpc-matcher.d.ts +53 -0
- package/dist/adapters/standard/rpc-matcher.js +106 -0
- package/dist/adapters/standard/utils.d.ts +10 -0
- package/dist/adapters/standard/utils.js +8 -0
- package/dist/adapters/standard-peer/index.d.ts +2 -16
- package/dist/adapters/standard-peer/index.js +1 -0
- package/dist/adapters/standard-peer/utils.d.ts +6 -0
- package/dist/adapters/standard-peer/utils.js +13 -0
- package/dist/adapters/websocket/handler.d.ts +61 -0
- package/dist/adapters/websocket/handler.js +75 -0
- package/dist/adapters/websocket/index.d.ts +3 -61
- package/dist/adapters/websocket/index.js +2 -0
- package/dist/adapters/websocket/rpc-handler.d.ts +16 -0
- package/dist/adapters/websocket/rpc-handler.js +18 -0
- package/dist/builder-variants.d.ts +226 -0
- package/dist/builder.d.ts +126 -0
- package/dist/builder.js +200 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +4 -0
- package/dist/context.d.ts +6 -0
- package/dist/extensions/callable.d.ts +11 -10
- package/dist/extensions/callable.js +8 -0
- package/dist/helpers/base64url.d.ts +31 -0
- package/dist/helpers/base64url.js +48 -0
- package/dist/helpers/cookie.d.ts +50 -0
- package/dist/helpers/cookie.js +62 -0
- package/dist/helpers/encryption.d.ts +28 -0
- package/dist/helpers/encryption.js +90 -0
- package/dist/helpers/index.d.ts +5 -149
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/signing.d.ts +50 -0
- package/dist/helpers/signing.js +78 -0
- package/dist/implementer-procedure.d.ts +15 -0
- package/dist/implementer-procedure.js +37 -0
- package/dist/implementer-router.d.ts +34 -0
- package/dist/implementer-router.js +98 -0
- package/dist/implementer.d.ts +16 -0
- package/dist/implementer.js +30 -0
- package/dist/index.d.ts +22 -196
- package/dist/index.js +16 -0
- package/dist/lazy.d.ts +20 -0
- package/dist/lazy.js +20 -0
- package/dist/middleware-decorated.d.ts +9 -0
- package/dist/middleware-decorated.js +67 -0
- package/dist/middleware.d.ts +54 -0
- package/dist/plugins/batch.d.ts +102 -0
- package/dist/plugins/batch.js +371 -0
- package/dist/plugins/cors.d.ts +69 -0
- package/dist/plugins/cors.js +119 -0
- package/dist/plugins/get-method-csrf-protection.d.ts +25 -0
- package/dist/plugins/get-method-csrf-protection.js +48 -0
- package/dist/plugins/head-method.d.ts +25 -0
- package/dist/plugins/head-method.js +107 -0
- package/dist/plugins/index.d.ts +15 -197
- package/dist/plugins/index.js +14 -0
- package/dist/plugins/method-override.d.ts +40 -0
- package/dist/plugins/method-override.js +54 -0
- package/dist/plugins/request-compression.d.ts +18 -0
- package/dist/plugins/request-compression.js +55 -0
- package/dist/plugins/request-headers.d.ts +24 -0
- package/dist/plugins/request-headers.js +28 -0
- package/dist/plugins/request-limit.d.ts +32 -0
- package/dist/plugins/request-limit.js +61 -0
- package/dist/plugins/response-compression.d.ts +62 -0
- package/dist/plugins/response-compression.js +157 -0
- package/dist/plugins/response-headers.d.ts +32 -0
- package/dist/plugins/response-headers.js +44 -0
- package/dist/plugins/rethrow.d.ts +35 -0
- package/dist/plugins/rethrow.js +47 -0
- package/dist/plugins/signal-sync.d.ts +15 -0
- package/dist/plugins/signal-sync.js +76 -0
- package/dist/plugins/timeout.d.ts +39 -0
- package/dist/plugins/timeout.js +62 -0
- package/dist/procedure-client.d.ts +18 -0
- package/dist/procedure-client.js +158 -0
- package/dist/procedure-decorated.d.ts +10 -0
- package/dist/procedure-decorated.js +36 -0
- package/dist/procedure-utils.d.ts +21 -0
- package/dist/procedure-utils.js +48 -0
- package/dist/procedure.d.ts +72 -0
- package/dist/procedure.js +18 -0
- package/dist/router-client.d.ts +21 -0
- package/dist/router-client.js +35 -0
- package/dist/router-hidden.js +12 -0
- package/dist/router-utils.d.ts +31 -0
- package/dist/router-utils.js +157 -0
- package/dist/router.d.ts +58 -0
- package/package.json +95 -63
- package/dist/adapters/crossws/index.d.mts +0 -54
- package/dist/adapters/crossws/index.mjs +0 -64
- package/dist/adapters/fetch/index.d.mts +0 -140
- package/dist/adapters/fetch/index.mjs +0 -204
- package/dist/adapters/message-port/index.d.mts +0 -74
- package/dist/adapters/message-port/index.mjs +0 -90
- package/dist/adapters/node/index.d.mts +0 -121
- package/dist/adapters/node/index.mjs +0 -179
- package/dist/adapters/standard/index.d.mts +0 -19
- package/dist/adapters/standard/index.mjs +0 -8
- package/dist/adapters/standard-peer/index.d.mts +0 -16
- package/dist/adapters/standard-peer/index.mjs +0 -2
- package/dist/adapters/websocket/index.d.mts +0 -61
- package/dist/adapters/websocket/index.mjs +0 -76
- package/dist/extensions/callable.d.mts +0 -10
- package/dist/extensions/callable.mjs +0 -11
- package/dist/helpers/index.d.mts +0 -149
- package/dist/helpers/index.mjs +0 -198
- package/dist/index.d.mts +0 -196
- package/dist/index.mjs +0 -385
- package/dist/plugins/index.d.mts +0 -197
- package/dist/plugins/index.mjs +0 -357
- package/dist/shared/server.BL22TloH.d.mts +0 -184
- package/dist/shared/server.BL22TloH.d.ts +0 -184
- package/dist/shared/server.BsNNjG5J.d.mts +0 -61
- package/dist/shared/server.BwHnWUuN.mjs +0 -222
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.Cj5lgPuG.d.mts +0 -66
- package/dist/shared/server.CjOb6ItT.mjs +0 -41
- package/dist/shared/server.CrlKQucM.mjs +0 -233
- package/dist/shared/server.DBANIheG.d.ts +0 -104
- package/dist/shared/server.DJIkub_t.d.mts +0 -104
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.GDpX6Df8.mjs +0 -271
- package/dist/shared/server.Pa0F03f_.d.ts +0 -61
- package/dist/shared/server.W91HSRkE.mjs +0 -9
- package/dist/shared/server.d_2NS3g5.d.ts +0 -66
|
@@ -1,74 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { C as Context } from '../../shared/server.BL22TloH.js';
|
|
5
|
-
import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DBANIheG.js';
|
|
6
|
-
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
|
|
7
|
-
import { R as Router } from '../../shared/server.Pa0F03f_.js';
|
|
8
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.d_2NS3g5.js';
|
|
9
|
-
import '@orpc/client';
|
|
10
|
-
import '@orpc/contract';
|
|
11
|
-
import '@standardserver/core';
|
|
12
|
-
|
|
13
|
-
type DecodedResponseMessage = ConstructorParameters<typeof ServerPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
|
|
14
|
-
interface MessagePortHandlerOptions<_T extends Context> {
|
|
15
|
-
/**
|
|
16
|
-
* By default, oRPC encodes peer messages as strings or binary data before sending them over the message port.
|
|
17
|
-
* Use this option to bypass encoding and leverage the full capabilities of the
|
|
18
|
-
* [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
|
|
19
|
-
* such as transferring object ownership or supporting non-serializable objects like `OffscreenCanvas` or improving performance.
|
|
20
|
-
*
|
|
21
|
-
* @remarks
|
|
22
|
-
* - Returning `null` or `undefined` disables this feature.
|
|
23
|
-
*
|
|
24
|
-
* @warning Ensure your message port implementation supports `transferable` objects before enabling this.
|
|
25
|
-
*/
|
|
26
|
-
experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedResponseMessage, port: SupportedMessagePort]>;
|
|
27
|
-
/**
|
|
28
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
29
|
-
*/
|
|
30
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
33
|
-
*/
|
|
34
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
35
|
-
}
|
|
36
|
-
declare class MessagePortHandler<T extends Context> {
|
|
37
|
-
private readonly handler;
|
|
38
|
-
private readonly peers;
|
|
39
|
-
private readonly transfer;
|
|
40
|
-
private readonly encodePeerMessageOptions;
|
|
41
|
-
private readonly decodePeerMessageOptions;
|
|
42
|
-
constructor(handler: StandardHandler<T>, options?: NoInfer<MessagePortHandlerOptions<T>>);
|
|
43
|
-
/**
|
|
44
|
-
* Attaches necessary event listeners to a message port to handle incoming messages and peer management.
|
|
45
|
-
*/
|
|
46
|
-
upgrade(port: SupportedMessagePort, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
47
|
-
/**
|
|
48
|
-
* Handles a single message received from a message port.
|
|
49
|
-
*
|
|
50
|
-
* @warning AVOID calling this method directly if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
51
|
-
*
|
|
52
|
-
* @param port The message port instance, require consistent instance across messages for proper peer management
|
|
53
|
-
*/
|
|
54
|
-
message(port: SupportedMessagePort, data: any, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
|
|
55
|
-
matched: boolean;
|
|
56
|
-
}>;
|
|
57
|
-
/**
|
|
58
|
-
* Called when a message port is closed, to clean up any associated peer state.
|
|
59
|
-
*
|
|
60
|
-
* @warning AVOID calling this method directly if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
61
|
-
*
|
|
62
|
-
* @param port The message port instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
63
|
-
*/
|
|
64
|
-
close(port: SupportedMessagePort): Promise<void>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, MessagePortHandlerOptions<T> {
|
|
68
|
-
}
|
|
69
|
-
declare class RPCHandler<T extends Context> extends MessagePortHandler<T> {
|
|
70
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { MessagePortHandler, RPCHandler };
|
|
74
|
-
export type { MessagePortHandlerOptions, RPCHandlerOptions };
|
|
1
|
+
import { MessagePortHandler, MessagePortHandlerOptions } from "./handler.js";
|
|
2
|
+
import { RPCHandler, RPCHandlerOptions } from "./rpc-handler.js";
|
|
3
|
+
export { MessagePortHandler, MessagePortHandlerOptions, RPCHandler, RPCHandlerOptions };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { StandardHandlerOptions } from "../standard/handler.js";
|
|
3
|
+
import { Router } from "../../router.js";
|
|
4
|
+
import { RPCHandlerCodecOptions } from "../standard/rpc-handler-codec.js";
|
|
5
|
+
import "../standard/index.js";
|
|
6
|
+
import { MessagePortHandler, MessagePortHandlerOptions } from "./handler.js";
|
|
7
|
+
export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, MessagePortHandlerOptions<T> {}
|
|
8
|
+
/**
|
|
9
|
+
* Serves an oRPC router over the RPC protocol on a message port,
|
|
10
|
+
* such as browser extensions, Electron, or worker threads.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
|
|
13
|
+
*/
|
|
14
|
+
export declare class RPCHandler<T extends Context> extends MessagePortHandler<T> {
|
|
15
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RPCHandlerCodec } from "../standard/rpc-handler-codec.js";
|
|
2
|
+
import { StandardHandler } from "../standard/handler.js";
|
|
3
|
+
import { MessagePortHandler } from "./handler.js";
|
|
4
|
+
// src/adapters/message-port/rpc-handler.ts
|
|
5
|
+
/**
|
|
6
|
+
* Serves an oRPC router over the RPC protocol on a message port,
|
|
7
|
+
* such as browser extensions, Electron, or worker threads.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
|
|
10
|
+
*/
|
|
11
|
+
var RPCHandler = class extends MessagePortHandler {
|
|
12
|
+
constructor(router, options = {}) {
|
|
13
|
+
const codec = new RPCHandlerCodec(router, options);
|
|
14
|
+
const handler = new StandardHandler(codec, options);
|
|
15
|
+
super(handler, options);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export { RPCHandler };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { StandardHandler } from "../standard/handler.js";
|
|
3
|
+
import { FriendlyStandardHandlerHandleOptions } from "../standard/utils.js";
|
|
4
|
+
import "../standard/index.js";
|
|
5
|
+
import { MaybeOptionalOptions } from "@orpc/shared";
|
|
6
|
+
import { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions } from "@standard-server/node";
|
|
7
|
+
export type NodeHttpHandlerHandleResult = {
|
|
8
|
+
matched: true;
|
|
9
|
+
} | {
|
|
10
|
+
matched: false;
|
|
11
|
+
};
|
|
12
|
+
export interface NodeHttpHandlerOptions<_T extends Context> {
|
|
13
|
+
/**
|
|
14
|
+
* Custom options for `sendStandardResponse`, used to send a `Standard Response`
|
|
15
|
+
*/
|
|
16
|
+
sendStandardResponse?: SendStandardResponseOptions | undefined;
|
|
17
|
+
}
|
|
18
|
+
export declare class NodeHttpHandler<T extends Context> {
|
|
19
|
+
private readonly standardHandler;
|
|
20
|
+
private readonly sendStandardResponseOptions;
|
|
21
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<NodeHttpHandlerOptions<T>>);
|
|
22
|
+
handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<NodeHttpHandlerHandleResult>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { resolveFriendlyStandardHandlerHandleOptions } from "../standard/utils.js";
|
|
2
|
+
import { resolveMaybeOptionalOptions } from "@orpc/shared";
|
|
3
|
+
import { sendStandardResponse, toStandardLazyRequest } from "@standard-server/node";
|
|
4
|
+
// src/adapters/node/handler.ts
|
|
5
|
+
var NodeHttpHandler = class {
|
|
6
|
+
standardHandler;
|
|
7
|
+
sendStandardResponseOptions;
|
|
8
|
+
constructor(standardHandler, options = {}) {
|
|
9
|
+
this.standardHandler = standardHandler;
|
|
10
|
+
this.sendStandardResponseOptions = options.sendStandardResponse;
|
|
11
|
+
}
|
|
12
|
+
async handle(request, response, ...rest) {
|
|
13
|
+
const standardRequest = toStandardLazyRequest(request, response);
|
|
14
|
+
const result = await this.standardHandler.handle(standardRequest, resolveFriendlyStandardHandlerHandleOptions(resolveMaybeOptionalOptions(rest)));
|
|
15
|
+
if (!result.matched) return result;
|
|
16
|
+
await sendStandardResponse(response, result.response, this.sendStandardResponseOptions);
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export { NodeHttpHandler };
|
|
@@ -1,121 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
|
|
6
|
-
import compression from '@orpc/interop/compression';
|
|
7
|
-
import { R as Router } from '../../shared/server.Pa0F03f_.js';
|
|
8
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.d_2NS3g5.js';
|
|
9
|
-
import '@orpc/client';
|
|
10
|
-
import '@orpc/contract';
|
|
11
|
-
import '@standardserver/core';
|
|
12
|
-
|
|
13
|
-
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
14
|
-
/**
|
|
15
|
-
* Initializes the plugin and returns new node HTTP handler options.
|
|
16
|
-
* Called once per plugin instance during composition.
|
|
17
|
-
*
|
|
18
|
-
* This method allows plugins to wrap, extend, or transform node HTTP handler options
|
|
19
|
-
* such as interceptors, or other configuration.
|
|
20
|
-
*
|
|
21
|
-
* @param options - The current handler options from previous plugins or base configuration
|
|
22
|
-
* @returns Transformed handler options with plugin's modifications applied
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* initNodeHttpHandlerOptions(options) {
|
|
27
|
-
* return {
|
|
28
|
-
* ...options,
|
|
29
|
-
* nodeHttpInterceptors: [...(options.nodeHttpInterceptors || []), myInterceptor]
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
initNodeHttpHandlerOptions?(options: NodeHttpHandlerOptions<T>): NodeHttpHandlerOptions<T>;
|
|
35
|
-
}
|
|
36
|
-
declare class CompositeNodeHttpHandlerPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
|
37
|
-
readonly name = "~composite/node-http-handler";
|
|
38
|
-
protected readonly plugins: NodeHttpHandlerPlugin<T>[];
|
|
39
|
-
constructor(plugins?: NodeHttpHandlerPlugin<T>[]);
|
|
40
|
-
initNodeHttpHandlerOptions(options: NodeHttpHandlerOptions<T>): NodeHttpHandlerOptions<T>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type NodeHttpHandlerHandleResult = {
|
|
44
|
-
matched: true;
|
|
45
|
-
} | {
|
|
46
|
-
matched: false;
|
|
47
|
-
};
|
|
48
|
-
interface NodeHttpHandlerNodeHttpInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
|
|
49
|
-
request: NodeHttpRequest;
|
|
50
|
-
response: NodeHttpResponse;
|
|
51
|
-
sendStandardResponseOptions: SendStandardResponseOptions | undefined;
|
|
52
|
-
}
|
|
53
|
-
type NodeHttpHandlerNodeHttpInterceptor<T extends Context> = Interceptor<NodeHttpHandlerNodeHttpInterceptorOptions<T>, Promise<NodeHttpHandlerHandleResult>>;
|
|
54
|
-
interface NodeHttpHandlerOptions<T extends Context> {
|
|
55
|
-
/**
|
|
56
|
-
* Custom options for `sendStandardResponse`, used to send a `Standard Response`
|
|
57
|
-
*/
|
|
58
|
-
sendStandardResponse?: SendStandardResponseOptions | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* Interceptors that run before the mapping between the Standard API and Node HTTP API,
|
|
61
|
-
* useful for extending Node HTTP request/response before handling, ...
|
|
62
|
-
*/
|
|
63
|
-
nodeHttpInterceptors?: NodeHttpHandlerNodeHttpInterceptor<T>[] | undefined;
|
|
64
|
-
plugins?: NodeHttpHandlerPlugin<T>[] | undefined;
|
|
65
|
-
}
|
|
66
|
-
declare class NodeHttpHandler<T extends Context> {
|
|
67
|
-
private readonly standardHandler;
|
|
68
|
-
private readonly sendStandardResponseOptions;
|
|
69
|
-
private readonly nodeHttpInterceptors;
|
|
70
|
-
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<NodeHttpHandlerOptions<T>>);
|
|
71
|
-
handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<NodeHttpHandlerHandleResult>;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
interface BodyCompressionHandlerPluginOptions extends compression.CompressionOptions {
|
|
75
|
-
/**
|
|
76
|
-
* Override the default content-type filter used to determine which responses should be compressed.
|
|
77
|
-
*
|
|
78
|
-
* @warning Event stream responses are never compressed, regardless of this filter's return value.
|
|
79
|
-
* @default only responses with compressible content types are compressed.
|
|
80
|
-
*/
|
|
81
|
-
filter?: (request: NodeHttpRequest, response: NodeHttpResponse) => boolean;
|
|
82
|
-
}
|
|
83
|
-
declare class BodyCompressionHandlerPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
|
84
|
-
name: string;
|
|
85
|
-
private readonly compressionHandler;
|
|
86
|
-
constructor(options?: BodyCompressionHandlerPluginOptions);
|
|
87
|
-
initNodeHttpHandlerOptions(options: NodeHttpHandlerOptions<T>): NodeHttpHandlerOptions<T>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interface BodyLimitHandlerPluginOptions {
|
|
91
|
-
/**
|
|
92
|
-
* The maximum size of the body in bytes.
|
|
93
|
-
*/
|
|
94
|
-
maxBodySize: number;
|
|
95
|
-
}
|
|
96
|
-
declare class BodyLimitHandlerPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
|
97
|
-
name: string;
|
|
98
|
-
private readonly maxBodySize;
|
|
99
|
-
constructor(options: BodyLimitHandlerPluginOptions);
|
|
100
|
-
initNodeHttpHandlerOptions(options: NodeHttpHandlerOptions<T>): NodeHttpHandlerOptions<T>;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
interface RPCHandlerOptions<T extends Context> extends NodeHttpHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
|
|
104
|
-
/**
|
|
105
|
-
* Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
|
|
106
|
-
*/
|
|
107
|
-
csrfGuardPlugin?: {
|
|
108
|
-
/**
|
|
109
|
-
* If `false`, this plugin is disabled.
|
|
110
|
-
*
|
|
111
|
-
* @default true
|
|
112
|
-
*/
|
|
113
|
-
enabled?: boolean;
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
|
117
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { BodyCompressionHandlerPlugin, BodyLimitHandlerPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
|
|
121
|
-
export type { BodyCompressionHandlerPluginOptions, BodyLimitHandlerPluginOptions, NodeHttpHandlerHandleResult, NodeHttpHandlerNodeHttpInterceptor, NodeHttpHandlerNodeHttpInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin, RPCHandlerOptions };
|
|
1
|
+
import { RequestLimitHandlerPlugin } from "../../plugins/request-limit.js";
|
|
2
|
+
import { NodeHttpHandler, NodeHttpHandlerHandleResult, NodeHttpHandlerOptions } from "./handler.js";
|
|
3
|
+
import { RPCHandler, RPCHandlerOptions } from "./rpc-handler.js";
|
|
4
|
+
export { RequestLimitHandlerPlugin as BodyLimitPlugin, NodeHttpHandler, NodeHttpHandlerHandleResult, NodeHttpHandlerOptions, RPCHandler, RPCHandlerOptions };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { StandardHandlerOptions } from "../standard/handler.js";
|
|
3
|
+
import { Router } from "../../router.js";
|
|
4
|
+
import { RPCHandlerCodecOptions } from "../standard/rpc-handler-codec.js";
|
|
5
|
+
import "../standard/index.js";
|
|
6
|
+
import { NodeHttpHandler, NodeHttpHandlerOptions } from "./handler.js";
|
|
7
|
+
export interface RPCHandlerOptions<T extends Context> extends NodeHttpHandlerOptions<T>, StandardHandlerOptions<T>, RPCHandlerCodecOptions<T> {}
|
|
8
|
+
/**
|
|
9
|
+
* Serves an oRPC router over the RPC protocol using Node.js built-in
|
|
10
|
+
* HTTP request/response objects.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/adapters/node-http | Node HTTP Adapter}
|
|
13
|
+
*/
|
|
14
|
+
export declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
|
15
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RPCHandlerCodec } from "../standard/rpc-handler-codec.js";
|
|
2
|
+
import { StandardHandler } from "../standard/handler.js";
|
|
3
|
+
import { NodeHttpHandler } from "./handler.js";
|
|
4
|
+
// src/adapters/node/rpc-handler.ts
|
|
5
|
+
/**
|
|
6
|
+
* Serves an oRPC router over the RPC protocol using Node.js built-in
|
|
7
|
+
* HTTP request/response objects.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://orpc.dev/docs/adapters/node-http | Node HTTP Adapter}
|
|
10
|
+
*/
|
|
11
|
+
var RPCHandler = class extends NodeHttpHandler {
|
|
12
|
+
constructor(router, options = {}) {
|
|
13
|
+
const codec = new RPCHandlerCodec(router, options);
|
|
14
|
+
const handler = new StandardHandler(codec, options);
|
|
15
|
+
super(handler, options);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export { RPCHandler };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { AnyProcedure } from "../../procedure.js";
|
|
3
|
+
import { ResolvedStandardHandlerHandleOptions } from "./handler.js";
|
|
4
|
+
import { Promisable } from "@orpc/shared";
|
|
5
|
+
import { AnyORPCError } from "@orpc/client";
|
|
6
|
+
import { StandardLazyRequest, StandardResponse } from "@standard-server/core";
|
|
7
|
+
export interface StandardHandlerCodecResolvedProcedure {
|
|
8
|
+
path: string[];
|
|
9
|
+
procedure: AnyProcedure;
|
|
10
|
+
decodeInput: () => Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface StandardHandlerCodec<T extends Context> {
|
|
13
|
+
resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
14
|
+
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
15
|
+
encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { ProcedureClientInterceptor } from "../../procedure-client.js";
|
|
3
|
+
import { StandardHandlerCodec, StandardHandlerCodecResolvedProcedure } from "./codec.js";
|
|
4
|
+
import { StandardHandlerPlugin } from "./plugin.js";
|
|
5
|
+
import { ErrorMap, Schema } from "@orpc/contract";
|
|
6
|
+
import { Interceptor, Promisable, Value } from "@orpc/shared";
|
|
7
|
+
import { StandardLazyRequest, StandardResponse } from "@standard-server/core";
|
|
8
|
+
export interface StandardHandlerHandleOptions<T extends Context> {
|
|
9
|
+
prefix?: `/${string}` | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The initial context, or a function (sync or async) that receives the request and returns it.
|
|
12
|
+
* The function only runs once the request passes the prefix check.
|
|
13
|
+
*/
|
|
14
|
+
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `StandardHandlerHandleOptions` after the context has been resolved,
|
|
18
|
+
* this is what interceptors and codecs receive.
|
|
19
|
+
*/
|
|
20
|
+
export interface ResolvedStandardHandlerHandleOptions<T extends Context> extends Omit<StandardHandlerHandleOptions<T>, "context"> {
|
|
21
|
+
context: T;
|
|
22
|
+
}
|
|
23
|
+
export type StandardHandlerHandleResult = {
|
|
24
|
+
matched: true;
|
|
25
|
+
response: StandardResponse;
|
|
26
|
+
} | {
|
|
27
|
+
matched: false;
|
|
28
|
+
response?: undefined;
|
|
29
|
+
};
|
|
30
|
+
export interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure, ResolvedStandardHandlerHandleOptions<T> {
|
|
31
|
+
request: StandardLazyRequest;
|
|
32
|
+
}
|
|
33
|
+
export type StandardHandlerInterceptor<T extends Context> = Interceptor<StandardHandlerInterceptorOptions<T>, Promise<StandardResponse>>;
|
|
34
|
+
export interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends ResolvedStandardHandlerHandleOptions<T> {
|
|
35
|
+
request: StandardLazyRequest;
|
|
36
|
+
}
|
|
37
|
+
export type StandardHandlerRoutingInterceptor<T extends Context> = Interceptor<StandardHandlerRoutingInterceptorOptions<T>, Promise<StandardHandlerHandleResult>>;
|
|
38
|
+
export interface StandardHandlerOptions<TContext extends Context> {
|
|
39
|
+
/**
|
|
40
|
+
* Fired on every request before routing, useful when you want
|
|
41
|
+
* to intercept all requests regardless of whether they match a procedure or not.
|
|
42
|
+
*
|
|
43
|
+
* @examples
|
|
44
|
+
* - batch plugins - separate one request into multiple and call multiple next
|
|
45
|
+
* - openapi spec plugin - to intercept a request and early response
|
|
46
|
+
*/
|
|
47
|
+
routingInterceptors?: StandardHandlerRoutingInterceptor<TContext>[] | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* interceptor run after routing and before error handler,
|
|
50
|
+
* useful for error handling, logging, metrics, etc.
|
|
51
|
+
*/
|
|
52
|
+
interceptors?: StandardHandlerInterceptor<TContext>[] | undefined;
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* ClientInterceptor equivalent with createRouterClient.interceptors / createProcedure.interceptors
|
|
56
|
+
* useful for error handling, logging, metrics, etc. (not counting encoding/decoding)
|
|
57
|
+
*/
|
|
58
|
+
clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap>[] | undefined;
|
|
59
|
+
plugins?: StandardHandlerPlugin<TContext>[] | undefined;
|
|
60
|
+
}
|
|
61
|
+
export declare class StandardHandler<T extends Context> {
|
|
62
|
+
private readonly codec;
|
|
63
|
+
private readonly routingInterceptors;
|
|
64
|
+
private readonly interceptors;
|
|
65
|
+
private readonly clientInterceptors;
|
|
66
|
+
constructor(codec: StandardHandlerCodec<T>, options: StandardHandlerOptions<T>);
|
|
67
|
+
handle(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerHandleResult>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { createProcedureClient } from "../../procedure-client.js";
|
|
2
|
+
import { CompositeStandardHandlerPlugin } from "./plugin.js";
|
|
3
|
+
import { ORPC_NAME, getTracer, intercept, isAsyncIteratorObject, matchesHttpPathPrefix, override, recordSpanError, runWithSpan, toArray, toTracingException, traceAsyncIterator, traceReadableStream, value, wrapAsyncIterator, wrapReadableStream } from "@orpc/shared";
|
|
4
|
+
import { ORPCError, toORPCError } from "@orpc/client";
|
|
5
|
+
import { EventStreamErrorEvent, flattenStandardHeader, parseStandardUrl } from "@standard-server/core";
|
|
6
|
+
// src/adapters/standard/handler.ts
|
|
7
|
+
var StandardHandler = class {
|
|
8
|
+
codec;
|
|
9
|
+
routingInterceptors;
|
|
10
|
+
interceptors;
|
|
11
|
+
clientInterceptors;
|
|
12
|
+
constructor(codec, options) {
|
|
13
|
+
this.codec = codec;
|
|
14
|
+
options = new CompositeStandardHandlerPlugin([...toArray(options.plugins), new TracingHandlerPlugin()]).init(options);
|
|
15
|
+
this.routingInterceptors = options.routingInterceptors;
|
|
16
|
+
this.interceptors = options.interceptors;
|
|
17
|
+
this.clientInterceptors = options.clientInterceptors;
|
|
18
|
+
}
|
|
19
|
+
async handle(request, options) {
|
|
20
|
+
const { prefix } = options;
|
|
21
|
+
if (prefix && !matchesHttpPathPrefix(request.url, prefix)) return {
|
|
22
|
+
matched: false,
|
|
23
|
+
response: void 0
|
|
24
|
+
};
|
|
25
|
+
const context = await value(options.context, request);
|
|
26
|
+
return intercept(this.routingInterceptors, {
|
|
27
|
+
context,
|
|
28
|
+
prefix,
|
|
29
|
+
request
|
|
30
|
+
}, async ({ context, prefix, request }) => {
|
|
31
|
+
const span = getTracer()?.getActiveSpan();
|
|
32
|
+
let step;
|
|
33
|
+
const matchedOrNot = await runWithSpan("find_procedure", () => this.codec.resolveProcedure(request, {
|
|
34
|
+
context,
|
|
35
|
+
prefix
|
|
36
|
+
}));
|
|
37
|
+
if (!matchedOrNot) {
|
|
38
|
+
/**
|
|
39
|
+
* [Semantic conventions for HTTP spans](https://opentelemetry.io/docs/specs/semconv/http/http-spans/)
|
|
40
|
+
*/
|
|
41
|
+
span?.updateName(`${ORPC_NAME}_no_match`);
|
|
42
|
+
span?.setAttribute("http.request.method", request.method);
|
|
43
|
+
span?.setAttribute("url.path", request.url);
|
|
44
|
+
return { matched: false };
|
|
45
|
+
}
|
|
46
|
+
const { path, procedure, decodeInput } = matchedOrNot;
|
|
47
|
+
/**
|
|
48
|
+
* [Semantic conventions for RPC spans](https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/)
|
|
49
|
+
*/
|
|
50
|
+
span?.updateName(`${ORPC_NAME}.${path.join("/")}`);
|
|
51
|
+
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
52
|
+
span?.setAttribute("rpc.method", path.join("."));
|
|
53
|
+
try {
|
|
54
|
+
return {
|
|
55
|
+
matched: true,
|
|
56
|
+
response: await intercept(this.interceptors, {
|
|
57
|
+
context,
|
|
58
|
+
prefix,
|
|
59
|
+
request,
|
|
60
|
+
path,
|
|
61
|
+
procedure,
|
|
62
|
+
decodeInput
|
|
63
|
+
}, async ({ context, prefix, request, path, procedure, decodeInput }) => {
|
|
64
|
+
step = "decode_input";
|
|
65
|
+
let input = await runWithSpan("decode_input", decodeInput);
|
|
66
|
+
step = void 0;
|
|
67
|
+
if (getTracer() && isAsyncIteratorObject(input))
|
|
68
|
+
/**
|
|
69
|
+
* @warning
|
|
70
|
+
* Remember use `override` for AsyncIteratorObject to remain other special properties
|
|
71
|
+
*/
|
|
72
|
+
input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
|
|
73
|
+
else if (getTracer() && input instanceof ReadableStream)
|
|
74
|
+
/**
|
|
75
|
+
* @warning
|
|
76
|
+
* Remember use `override` for ReadableStream to remain other special properties
|
|
77
|
+
*/
|
|
78
|
+
input = override(input, traceReadableStream("consume_octet_stream_input", input));
|
|
79
|
+
const client = createProcedureClient(procedure, {
|
|
80
|
+
context,
|
|
81
|
+
path,
|
|
82
|
+
interceptors: this.clientInterceptors
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* No need to use `runWithSpan` here, because the client already has its own span.
|
|
86
|
+
*/
|
|
87
|
+
step = "call_procedure";
|
|
88
|
+
const output = await client(input, {
|
|
89
|
+
signal: request.signal,
|
|
90
|
+
lastEventId: flattenStandardHeader(request.headers["last-event-id"])
|
|
91
|
+
});
|
|
92
|
+
step = void 0;
|
|
93
|
+
return await this.codec.encodeOutput(output, procedure, path, {
|
|
94
|
+
context,
|
|
95
|
+
prefix
|
|
96
|
+
});
|
|
97
|
+
})
|
|
98
|
+
};
|
|
99
|
+
} catch (e) {
|
|
100
|
+
/**
|
|
101
|
+
* Only errors that happen outside of the `call_procedure` step should be set as an error.
|
|
102
|
+
* Because a business logic error should not be considered as a protocol-level error.
|
|
103
|
+
*/
|
|
104
|
+
if (step !== "call_procedure") recordSpanError(span, e);
|
|
105
|
+
const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
|
|
106
|
+
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
|
107
|
+
cause: e
|
|
108
|
+
}) : toORPCError(e);
|
|
109
|
+
return {
|
|
110
|
+
matched: true,
|
|
111
|
+
response: await this.codec.encodeError(error, procedure, path, {
|
|
112
|
+
context,
|
|
113
|
+
prefix
|
|
114
|
+
})
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var TracingHandlerPlugin = class {
|
|
121
|
+
name = "~tracing";
|
|
122
|
+
init(options) {
|
|
123
|
+
return {
|
|
124
|
+
...options,
|
|
125
|
+
routingInterceptors: [async ({ next, request }) => {
|
|
126
|
+
const tracer = getTracer();
|
|
127
|
+
if (!tracer) return next();
|
|
128
|
+
const parent = tracer.extract?.(request.headers);
|
|
129
|
+
/**
|
|
130
|
+
* The search part is excluded because span names should have low cardinality.
|
|
131
|
+
* The name is replaced with the procedure path once the request is routed.
|
|
132
|
+
*/
|
|
133
|
+
const [pathname] = parseStandardUrl(request.url);
|
|
134
|
+
return tracer.startActiveSpan(`${request.method} ${pathname}`, parent, async (span) => {
|
|
135
|
+
try {
|
|
136
|
+
const result = await next();
|
|
137
|
+
if (!result.matched) {
|
|
138
|
+
span.end();
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
const body = result.response.body;
|
|
142
|
+
if (isAsyncIteratorObject(body)) return {
|
|
143
|
+
...result,
|
|
144
|
+
response: {
|
|
145
|
+
...result.response,
|
|
146
|
+
/**
|
|
147
|
+
* @remarks
|
|
148
|
+
* **Warning**: Remember use `override` for remaining special properties
|
|
149
|
+
*/
|
|
150
|
+
body: override(body, wrapAsyncIterator(body, {
|
|
151
|
+
runWith: (fn) => tracer.withActiveSpan(span, fn),
|
|
152
|
+
onError(error) {
|
|
153
|
+
/**
|
|
154
|
+
* Errors here are internal (interceptor/framework) failures,
|
|
155
|
+
* except `EventStreamErrorEvent`: a business error the protocol delivers
|
|
156
|
+
* inside the event stream, already logged by the client interceptor.
|
|
157
|
+
*/
|
|
158
|
+
if (!(error instanceof EventStreamErrorEvent)) span.recordException("error", toTracingException(error));
|
|
159
|
+
},
|
|
160
|
+
onFinish() {
|
|
161
|
+
span.end();
|
|
162
|
+
}
|
|
163
|
+
}))
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
if (body instanceof ReadableStream) return {
|
|
167
|
+
...result,
|
|
168
|
+
response: {
|
|
169
|
+
...result.response,
|
|
170
|
+
/**
|
|
171
|
+
* @remarks
|
|
172
|
+
* **Warning**: Remember use `override` for remaining special properties
|
|
173
|
+
*/
|
|
174
|
+
body: override(body, wrapReadableStream(body, {
|
|
175
|
+
runWith: (fn) => tracer.withActiveSpan(span, fn),
|
|
176
|
+
onError(error) {
|
|
177
|
+
/**
|
|
178
|
+
* Any error here is internal (interceptor/framework), not business logic.
|
|
179
|
+
* Indicates unexpected handler failure.
|
|
180
|
+
*/
|
|
181
|
+
span.recordException("error", toTracingException(error));
|
|
182
|
+
},
|
|
183
|
+
onFinish() {
|
|
184
|
+
span.end();
|
|
185
|
+
}
|
|
186
|
+
}))
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
span.end();
|
|
190
|
+
return result;
|
|
191
|
+
} catch (e) {
|
|
192
|
+
/**
|
|
193
|
+
* Any error here is internal (interceptor/framework), not business logic.
|
|
194
|
+
* Always recorded as an error, even when it is an abort error.
|
|
195
|
+
*/
|
|
196
|
+
span.recordException("error", toTracingException(e));
|
|
197
|
+
span.end();
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}, ...toArray(options.routingInterceptors)]
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
export { StandardHandler };
|
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import '@orpc/contract';
|
|
9
|
-
import '../../shared/server.Pa0F03f_.js';
|
|
10
|
-
|
|
11
|
-
type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
|
|
12
|
-
context?: T;
|
|
13
|
-
} : {
|
|
14
|
-
context: T;
|
|
15
|
-
});
|
|
16
|
-
declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
|
|
17
|
-
|
|
18
|
-
export { StandardHandlerHandleOptions, resolveFriendlyStandardHandlerHandleOptions };
|
|
19
|
-
export type { FriendlyStandardHandlerHandleOptions };
|
|
1
|
+
import { StandardHandlerCodec, StandardHandlerCodecResolvedProcedure } from "./codec.js";
|
|
2
|
+
import { ResolvedStandardHandlerHandleOptions, StandardHandler, StandardHandlerHandleOptions, StandardHandlerHandleResult, StandardHandlerInterceptor, StandardHandlerInterceptorOptions, StandardHandlerOptions, StandardHandlerRoutingInterceptor, StandardHandlerRoutingInterceptorOptions } from "./handler.js";
|
|
3
|
+
import { StandardHandlerPlugin } from "./plugin.js";
|
|
4
|
+
import { RPCHandlerCodec, RPCHandlerCodecOptions } from "./rpc-handler-codec.js";
|
|
5
|
+
import { RPCMatcher, RPCMatcherOptions, RPC_DEFAULT_ALLOW_METHODS } from "./rpc-matcher.js";
|
|
6
|
+
import { FriendlyStandardHandlerHandleOptions, resolveFriendlyStandardHandlerHandleOptions } from "./utils.js";
|
|
7
|
+
export { FriendlyStandardHandlerHandleOptions, RPCHandlerCodec, RPCHandlerCodecOptions, RPCMatcher, RPCMatcherOptions, RPC_DEFAULT_ALLOW_METHODS, ResolvedStandardHandlerHandleOptions, StandardHandler, StandardHandlerCodec, StandardHandlerCodecResolvedProcedure, StandardHandlerHandleOptions, StandardHandlerHandleResult, StandardHandlerInterceptor, StandardHandlerInterceptorOptions, StandardHandlerOptions, type StandardHandlerPlugin, StandardHandlerRoutingInterceptor, StandardHandlerRoutingInterceptorOptions, resolveFriendlyStandardHandlerHandleOptions };
|