@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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { StandardHandlerOptions } from "./handler.js";
|
|
3
|
+
import { OrderablePlugin } from "@orpc/shared";
|
|
4
|
+
export interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
|
|
5
|
+
/**
|
|
6
|
+
* Initializes the plugin and returns new handler options.
|
|
7
|
+
* Called once per plugin instance during composition.
|
|
8
|
+
*
|
|
9
|
+
* This method allows plugins to wrap, extend, or transform handler options
|
|
10
|
+
* such as interceptors, or configuration.
|
|
11
|
+
*
|
|
12
|
+
* @param options - The current handler options from previous plugins or base configuration
|
|
13
|
+
* @returns Transformed handler options with plugin's modifications applied
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* init(options) {
|
|
18
|
+
* return {
|
|
19
|
+
* ...options,
|
|
20
|
+
* interceptors: [...(options.interceptors || []), myInterceptor]
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
init?(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { sortPlugins } from "@orpc/shared";
|
|
2
|
+
// src/adapters/standard/plugin.ts
|
|
3
|
+
var CompositeStandardHandlerPlugin = class {
|
|
4
|
+
name = "~composite";
|
|
5
|
+
plugins;
|
|
6
|
+
constructor(plugins = []) {
|
|
7
|
+
this.plugins = sortPlugins(plugins);
|
|
8
|
+
}
|
|
9
|
+
init(options) {
|
|
10
|
+
for (const plugin of this.plugins) if (plugin.init) options = plugin.init(options);
|
|
11
|
+
return options;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export { CompositeStandardHandlerPlugin };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { AnyProcedure } from "../../procedure.js";
|
|
3
|
+
import { ResolvedStandardHandlerHandleOptions } from "./handler.js";
|
|
4
|
+
import { StandardHandlerCodec, StandardHandlerCodecResolvedProcedure } from "./codec.js";
|
|
5
|
+
import { AnyRouter } from "../../router.js";
|
|
6
|
+
import "./index.js";
|
|
7
|
+
import { RPCMatcherOptions } from "./rpc-matcher.js";
|
|
8
|
+
import { Promisable, Public, Value } from "@orpc/shared";
|
|
9
|
+
import { AnyORPCError, RPCSerializer } from "@orpc/client";
|
|
10
|
+
import { StandardLazyRequest, StandardResponse } from "@standard-server/core";
|
|
11
|
+
export interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Override the default RPC serializer.
|
|
14
|
+
*/
|
|
15
|
+
serializer?: Public<RPCSerializer> | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve HTTP status for encoded successful outputs.
|
|
18
|
+
*
|
|
19
|
+
* Value should be in the `2xx` range and must be less than `400`.
|
|
20
|
+
*
|
|
21
|
+
* @default DEFAULT_SUCCESS_STATUS (200)
|
|
22
|
+
*/
|
|
23
|
+
outputStatus?: Value<number, [output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>]> | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Mapping ORPCError Code -> HTTP Status Code
|
|
26
|
+
* The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
|
|
27
|
+
* Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
|
|
28
|
+
*
|
|
29
|
+
* @default COMMON_ERROR_STATUS_MAP
|
|
30
|
+
*/
|
|
31
|
+
errorStatusMap?: Record<string, number> | undefined;
|
|
32
|
+
}
|
|
33
|
+
export declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec<T> {
|
|
34
|
+
private readonly matcher;
|
|
35
|
+
private readonly serializer;
|
|
36
|
+
private readonly errorStatusMap;
|
|
37
|
+
private readonly outputStatus;
|
|
38
|
+
constructor(router: AnyRouter, options?: RPCHandlerCodecOptions<T>);
|
|
39
|
+
resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
40
|
+
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
41
|
+
encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import "../../constants.js";
|
|
2
|
+
import { RPCMatcher } from "./rpc-matcher.js";
|
|
3
|
+
import { getOwn, parseEmptyableJSON, value } from "@orpc/shared";
|
|
4
|
+
import { COMMON_ERROR_STATUS_MAP, RPCSerializer } from "@orpc/client";
|
|
5
|
+
import { parseStandardUrl } from "@standard-server/core";
|
|
6
|
+
// src/adapters/standard/rpc-handler-codec.ts
|
|
7
|
+
var RPCHandlerCodec = class {
|
|
8
|
+
matcher;
|
|
9
|
+
serializer;
|
|
10
|
+
errorStatusMap;
|
|
11
|
+
outputStatus;
|
|
12
|
+
constructor(router, options = {}) {
|
|
13
|
+
this.matcher = new RPCMatcher(router, options);
|
|
14
|
+
this.serializer = options.serializer ?? new RPCSerializer();
|
|
15
|
+
this.errorStatusMap = options.errorStatusMap ?? COMMON_ERROR_STATUS_MAP;
|
|
16
|
+
this.outputStatus = options.outputStatus ?? 200;
|
|
17
|
+
}
|
|
18
|
+
async resolveProcedure(request, options) {
|
|
19
|
+
const [pathname, query] = parseStandardUrl(request.url);
|
|
20
|
+
const matched = await this.matcher.match(request.method, pathname, options.prefix);
|
|
21
|
+
if (!matched) return;
|
|
22
|
+
return {
|
|
23
|
+
procedure: matched.procedure,
|
|
24
|
+
path: matched.path,
|
|
25
|
+
decodeInput: async () => {
|
|
26
|
+
if (request.method === "GET") {
|
|
27
|
+
const dataString = new URLSearchParams(query).getAll("data").at(-1);
|
|
28
|
+
return this.serializer.deserialize(parseEmptyableJSON(dataString));
|
|
29
|
+
}
|
|
30
|
+
const body = await request.resolveBody();
|
|
31
|
+
return this.serializer.deserialize(body);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
encodeOutput(output, procedure, path, options) {
|
|
36
|
+
return {
|
|
37
|
+
headers: {},
|
|
38
|
+
status: value(this.outputStatus, output, procedure, path, options),
|
|
39
|
+
body: this.serializer.serialize(output)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
encodeError(error, _procedure, _path, _options) {
|
|
43
|
+
return {
|
|
44
|
+
headers: {},
|
|
45
|
+
status: getOwn(this.errorStatusMap, error.code) ?? 400,
|
|
46
|
+
body: this.serializer.serialize(error.toJSON())
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export { RPCHandlerCodec };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AnyProcedure } from "../../procedure.js";
|
|
2
|
+
import { AnyRouter } from "../../router.js";
|
|
3
|
+
import { AnyProcedureContract } from "@orpc/contract";
|
|
4
|
+
import { Value } from "@orpc/shared";
|
|
5
|
+
import { StandardMethod } from "@standard-server/core";
|
|
6
|
+
/**
|
|
7
|
+
* Methods that can invoke procedures by default. Browsers cannot trigger them
|
|
8
|
+
* cross-site without a CORS preflight or an HTML form, unlike `GET`, which a plain
|
|
9
|
+
* `<a>` click or redirect can trigger with `SameSite=Lax` cookies attached. Other
|
|
10
|
+
* methods (`HEAD`, `OPTIONS`, `QUERY`, ...) have safe semantics that should not
|
|
11
|
+
* invoke a procedure that can modify data.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
|
|
14
|
+
*/
|
|
15
|
+
export declare const RPC_DEFAULT_ALLOW_METHODS: readonly StandardMethod[];
|
|
16
|
+
export interface RPCMatcherOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Filter which procedures are exposed for matching. Return `false` to exclude.
|
|
19
|
+
*
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]> | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Restricts which HTTP methods can invoke procedures, either with a list of allowed
|
|
25
|
+
* methods or decided per request via a function. Requests using a disallowed method
|
|
26
|
+
* are treated as unmatched. `GET` is excluded by default because it is exposed to
|
|
27
|
+
* Cross-Site Request Forgery (CSRF) attacks.
|
|
28
|
+
*
|
|
29
|
+
* @default RPC_DEFAULT_ALLOW_METHODS (['POST', 'PUT', 'PATCH', 'DELETE'])
|
|
30
|
+
* @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
|
|
31
|
+
*/
|
|
32
|
+
allowMethods?: readonly StandardMethod[] | ((method: StandardMethod, procedure: AnyProcedure, path: string[]) => boolean) | undefined;
|
|
33
|
+
}
|
|
34
|
+
export declare class RPCMatcher {
|
|
35
|
+
private readonly filter;
|
|
36
|
+
private readonly allowMethodsSet;
|
|
37
|
+
private readonly allowMethodsFn;
|
|
38
|
+
private readonly rootRouter;
|
|
39
|
+
private readonly tree;
|
|
40
|
+
private readonly pendingLazyRouters;
|
|
41
|
+
/** segment count of the deepest pending key, never lowered so it stays an upper bound */
|
|
42
|
+
private maxPendingLazyRouterDepth;
|
|
43
|
+
constructor(router: AnyRouter, options?: RPCMatcherOptions);
|
|
44
|
+
private index;
|
|
45
|
+
match(method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
|
|
46
|
+
path: string[];
|
|
47
|
+
procedure: AnyProcedure;
|
|
48
|
+
} | undefined>;
|
|
49
|
+
private resolvePendingLazyRouters;
|
|
50
|
+
private loadPendingLazyRouter;
|
|
51
|
+
private indexPendingLazyRouter;
|
|
52
|
+
private resolveProcedure;
|
|
53
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { unlazy } from "../../lazy.js";
|
|
2
|
+
import { Procedure } from "../../procedure.js";
|
|
3
|
+
import { resolveContractProcedure, walkProcedureContractsSync } from "../../router-utils.js";
|
|
4
|
+
import { normalizeHttpPath, pathToHttpPath, stripHttpPathPrefix, value } from "@orpc/shared";
|
|
5
|
+
// src/adapters/standard/rpc-matcher.ts
|
|
6
|
+
/**
|
|
7
|
+
* Methods that can invoke procedures by default. Browsers cannot trigger them
|
|
8
|
+
* cross-site without a CORS preflight or an HTML form, unlike `GET`, which a plain
|
|
9
|
+
* `<a>` click or redirect can trigger with `SameSite=Lax` cookies attached. Other
|
|
10
|
+
* methods (`HEAD`, `OPTIONS`, `QUERY`, ...) have safe semantics that should not
|
|
11
|
+
* invoke a procedure that can modify data.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
|
|
14
|
+
*/
|
|
15
|
+
const RPC_DEFAULT_ALLOW_METHODS = [
|
|
16
|
+
"POST",
|
|
17
|
+
"PUT",
|
|
18
|
+
"PATCH",
|
|
19
|
+
"DELETE"
|
|
20
|
+
];
|
|
21
|
+
const NORMALIZABLE_PATHNAME_REGEX = /[^\w\-.!~*'()/]/;
|
|
22
|
+
var RPCMatcher = class {
|
|
23
|
+
filter;
|
|
24
|
+
allowMethodsSet;
|
|
25
|
+
allowMethodsFn;
|
|
26
|
+
rootRouter;
|
|
27
|
+
tree = /* @__PURE__ */ new Map();
|
|
28
|
+
pendingLazyRouters = /* @__PURE__ */ new Map();
|
|
29
|
+
/** segment count of the deepest pending key, never lowered so it stays an upper bound */
|
|
30
|
+
maxPendingLazyRouterDepth = 0;
|
|
31
|
+
constructor(router, options = {}) {
|
|
32
|
+
this.filter = options.filter ?? true;
|
|
33
|
+
const allowMethods = options.allowMethods ?? RPC_DEFAULT_ALLOW_METHODS;
|
|
34
|
+
if (typeof allowMethods !== "function") this.allowMethodsSet = new Set(allowMethods);
|
|
35
|
+
else this.allowMethodsFn = allowMethods;
|
|
36
|
+
this.rootRouter = router;
|
|
37
|
+
this.index(router);
|
|
38
|
+
}
|
|
39
|
+
index(router, path = []) {
|
|
40
|
+
const lazyResults = walkProcedureContractsSync(router, (procedure, procedurePath) => {
|
|
41
|
+
if (!value(this.filter, procedure, procedurePath)) return;
|
|
42
|
+
this.tree.set(pathToHttpPath(procedurePath), {
|
|
43
|
+
path: procedurePath,
|
|
44
|
+
contract: procedure,
|
|
45
|
+
procedure: procedure instanceof Procedure ? procedure : void 0
|
|
46
|
+
});
|
|
47
|
+
}, path);
|
|
48
|
+
for (const result of lazyResults) {
|
|
49
|
+
this.pendingLazyRouters.set(pathToHttpPath(result.path), result);
|
|
50
|
+
this.maxPendingLazyRouterDepth = Math.max(this.maxPendingLazyRouterDepth, result.path.length);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async match(method, pathname, prefix) {
|
|
54
|
+
if (this.allowMethodsSet && !this.allowMethodsSet.has(method)) return;
|
|
55
|
+
if (prefix) {
|
|
56
|
+
const stripped = stripHttpPathPrefix(pathname, prefix);
|
|
57
|
+
if (stripped === void 0) return;
|
|
58
|
+
pathname = stripped;
|
|
59
|
+
}
|
|
60
|
+
if (pathname.length > 1 && pathname.endsWith("/")) pathname = pathname.slice(0, -1);
|
|
61
|
+
const loading = this.resolvePendingLazyRouters(pathname);
|
|
62
|
+
if (loading !== void 0) await loading;
|
|
63
|
+
let entry = this.tree.get(pathname);
|
|
64
|
+
if (entry === void 0 && NORMALIZABLE_PATHNAME_REGEX.test(pathname)) {
|
|
65
|
+
const normalizedPathname = normalizeHttpPath(pathname);
|
|
66
|
+
const normalizedLoading = this.resolvePendingLazyRouters(normalizedPathname);
|
|
67
|
+
if (normalizedLoading !== void 0) await normalizedLoading;
|
|
68
|
+
entry = this.tree.get(normalizedPathname);
|
|
69
|
+
}
|
|
70
|
+
if (entry === void 0) return;
|
|
71
|
+
const procedure = entry.procedure ?? await this.resolveProcedure(entry);
|
|
72
|
+
if (this.allowMethodsFn && !this.allowMethodsFn(method, procedure, entry.path)) return;
|
|
73
|
+
return {
|
|
74
|
+
path: entry.path,
|
|
75
|
+
procedure
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
resolvePendingLazyRouters(pathname) {
|
|
79
|
+
if (this.pendingLazyRouters.size === 0) return;
|
|
80
|
+
let slashIndex = 0;
|
|
81
|
+
for (let depth = 1; slashIndex !== -1 && depth <= this.maxPendingLazyRouterDepth; depth++) {
|
|
82
|
+
const nextSlashIndex = pathname.indexOf("/", slashIndex + 1);
|
|
83
|
+
const httpPathPrefix = nextSlashIndex === -1 ? pathname : pathname.slice(0, nextSlashIndex);
|
|
84
|
+
const pending = this.pendingLazyRouters.get(httpPathPrefix);
|
|
85
|
+
if (pending !== void 0) return this.loadPendingLazyRouter(httpPathPrefix, pending).then(() => this.resolvePendingLazyRouters(pathname));
|
|
86
|
+
slashIndex = nextSlashIndex;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
loadPendingLazyRouter(httpPathPrefix, pending) {
|
|
90
|
+
if (pending.loading === void 0) pending.loading = this.indexPendingLazyRouter(httpPathPrefix, pending).catch((error) => {
|
|
91
|
+
pending.loading = void 0;
|
|
92
|
+
throw error;
|
|
93
|
+
});
|
|
94
|
+
return pending.loading;
|
|
95
|
+
}
|
|
96
|
+
async indexPendingLazyRouter(httpPathPrefix, pending) {
|
|
97
|
+
const { default: router } = await unlazy(pending.router);
|
|
98
|
+
this.index(router, pending.path);
|
|
99
|
+
this.pendingLazyRouters.delete(httpPathPrefix);
|
|
100
|
+
}
|
|
101
|
+
async resolveProcedure(entry) {
|
|
102
|
+
entry.procedure = await resolveContractProcedure(this.rootRouter, entry.contract, entry.path);
|
|
103
|
+
return entry.procedure;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
export { RPCMatcher, RPC_DEFAULT_ALLOW_METHODS };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { StandardHandlerHandleOptions } from "./handler.js";
|
|
3
|
+
import { Promisable, Value } from "@orpc/shared";
|
|
4
|
+
import { StandardLazyRequest } from "@standard-server/core";
|
|
5
|
+
export type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, "context"> & (object extends T ? {
|
|
6
|
+
context?: Value<Promisable<T>, [request: StandardLazyRequest]> | undefined;
|
|
7
|
+
} : {
|
|
8
|
+
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
9
|
+
});
|
|
10
|
+
export declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
|
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { C as Context } from '../../shared/server.BL22TloH.js';
|
|
4
|
-
import { b as StandardHandlerHandleOptions, S as StandardHandler } from '../../shared/server.DBANIheG.js';
|
|
5
|
-
import '@orpc/client';
|
|
6
|
-
import '@orpc/contract';
|
|
7
|
-
|
|
8
|
-
type StandardPeerRequestHandlerOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
9
|
-
context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
10
|
-
} : {
|
|
11
|
-
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
12
|
-
});
|
|
13
|
-
declare function createStandardPeerRequestHandler<T extends Context>(handler: StandardHandler<T>, options: StandardPeerRequestHandlerOptions<T>): (request: StandardLazyRequest) => Promise<StandardResponse>;
|
|
14
|
-
|
|
15
|
-
export { createStandardPeerRequestHandler };
|
|
16
|
-
export type { StandardPeerRequestHandlerOptions };
|
|
1
|
+
import { createStandardPeerRequestHandler } from "./utils.js";
|
|
2
|
+
export { createStandardPeerRequestHandler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createStandardPeerRequestHandler } from "./utils.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
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 { StandardLazyRequest, StandardResponse } from "@standard-server/core";
|
|
6
|
+
export declare function createStandardPeerRequestHandler<T extends Context>(handler: StandardHandler<T>, options: FriendlyStandardHandlerHandleOptions<T>): (request: StandardLazyRequest) => Promise<StandardResponse>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { resolveFriendlyStandardHandlerHandleOptions } from "../standard/utils.js";
|
|
2
|
+
// src/adapters/standard-peer/utils.ts
|
|
3
|
+
function createStandardPeerRequestHandler(handler, options) {
|
|
4
|
+
return async (request) => {
|
|
5
|
+
const { response } = await handler.handle(request, resolveFriendlyStandardHandlerHandleOptions(options));
|
|
6
|
+
return response ?? {
|
|
7
|
+
status: 404,
|
|
8
|
+
headers: {},
|
|
9
|
+
body: "No procedure matched"
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export { createStandardPeerRequestHandler };
|
|
@@ -0,0 +1,61 @@
|
|
|
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 { Arrayable, MaybeOptionalOptions } from "@orpc/shared";
|
|
6
|
+
import { DecodePeerMessageOptions, EncodePeerMessageOptions } from "@standard-server/peer";
|
|
7
|
+
/**
|
|
8
|
+
* Supports standard WebSocket instances, Bun ServerWebSocket, "ws" ServerWebSocket,
|
|
9
|
+
* Cloudflare WebSocket Hibernation, and similar implementations.
|
|
10
|
+
*/
|
|
11
|
+
export type WebSocketLike = {
|
|
12
|
+
send: (data: string | Uint8Array<ArrayBuffer>) => unknown;
|
|
13
|
+
};
|
|
14
|
+
export interface WebSocketHandlerOptions<_T extends Context> {
|
|
15
|
+
/**
|
|
16
|
+
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
17
|
+
*/
|
|
18
|
+
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
21
|
+
*/
|
|
22
|
+
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare class WebSocketHandler<T extends Context> {
|
|
25
|
+
private readonly handler;
|
|
26
|
+
/**
|
|
27
|
+
* `null` marks a closed socket, so late messages never create a new peer.
|
|
28
|
+
*/
|
|
29
|
+
private readonly peers;
|
|
30
|
+
private readonly encodePeerMessageOptions;
|
|
31
|
+
private readonly decodePeerMessageOptions;
|
|
32
|
+
constructor(handler: StandardHandler<T>, options?: NoInfer<WebSocketHandlerOptions<T>>);
|
|
33
|
+
/**
|
|
34
|
+
* Handles a single WebSocket message.
|
|
35
|
+
*
|
|
36
|
+
* Message order matters. Call this immediately after receiving a message,
|
|
37
|
+
* before any other async work, to preserve ordering.
|
|
38
|
+
*
|
|
39
|
+
* To avoid async Blob reads, configure `ws.binaryType` to return binary data
|
|
40
|
+
* directly (for example, `arraybuffer`).
|
|
41
|
+
*
|
|
42
|
+
* @param ws The WebSocket instance. Use the same instance for all messages.
|
|
43
|
+
* @param data The received message. Binary data should already be loaded (not a `Blob`).
|
|
44
|
+
*/
|
|
45
|
+
message(ws: WebSocketLike, data: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, "buffer" | "byteOffset" | "byteLength">>, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<{
|
|
46
|
+
matched: boolean;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Cleans up peer state for a closed WebSocket.
|
|
50
|
+
* Messages passed to `.message()` for this WebSocket afterwards are ignored.
|
|
51
|
+
*
|
|
52
|
+
* @param ws The same WebSocket instance passed to `.message()`.
|
|
53
|
+
*/
|
|
54
|
+
close(ws: WebSocketLike): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Attaches message, close, and error event listeners to a WebSocket.
|
|
57
|
+
*
|
|
58
|
+
* Prefer this over calling `.message()` and `.close()` manually.
|
|
59
|
+
*/
|
|
60
|
+
upgrade(ws: Pick<WebSocket, "send" | "addEventListener" | "removeEventListener">, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createStandardPeerRequestHandler } from "../standard-peer/utils.js";
|
|
2
|
+
import { loadBytes, resolveMaybeOptionalOptions, sequential, toStringOrBytes } from "@orpc/shared";
|
|
3
|
+
import { ServerPeer, decodePeerMessage, encodePeerMessage, isClientPeerSendMessage } from "@standard-server/peer";
|
|
4
|
+
// src/adapters/websocket/handler.ts
|
|
5
|
+
var WebSocketHandler = class {
|
|
6
|
+
handler;
|
|
7
|
+
/**
|
|
8
|
+
* `null` marks a closed socket, so late messages never create a new peer.
|
|
9
|
+
*/
|
|
10
|
+
peers = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
encodePeerMessageOptions;
|
|
12
|
+
decodePeerMessageOptions;
|
|
13
|
+
constructor(handler, options = {}) {
|
|
14
|
+
this.handler = handler;
|
|
15
|
+
this.encodePeerMessageOptions = options.encodePeerMessage;
|
|
16
|
+
this.decodePeerMessageOptions = options.decodePeerMessage;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Handles a single WebSocket message.
|
|
20
|
+
*
|
|
21
|
+
* Message order matters. Call this immediately after receiving a message,
|
|
22
|
+
* before any other async work, to preserve ordering.
|
|
23
|
+
*
|
|
24
|
+
* To avoid async Blob reads, configure `ws.binaryType` to return binary data
|
|
25
|
+
* directly (for example, `arraybuffer`).
|
|
26
|
+
*
|
|
27
|
+
* @param ws The WebSocket instance. Use the same instance for all messages.
|
|
28
|
+
* @param data The received message. Binary data should already be loaded (not a `Blob`).
|
|
29
|
+
*/
|
|
30
|
+
async message(ws, data, ...rest) {
|
|
31
|
+
/**
|
|
32
|
+
* Message order is important: loading -> decode -> .message.
|
|
33
|
+
* This flow must stay synchronous, or we need to use `sequential` helper
|
|
34
|
+
*/
|
|
35
|
+
const encoded = toStringOrBytes(data);
|
|
36
|
+
const result = decodePeerMessage(encoded, this.decodePeerMessageOptions);
|
|
37
|
+
let peer = this.peers.get(ws);
|
|
38
|
+
if (peer === null) return result;
|
|
39
|
+
if (!peer) this.peers.set(ws, peer = new ServerPeer(async (message) => {
|
|
40
|
+
const encoded = await encodePeerMessage(message, this.encodePeerMessageOptions);
|
|
41
|
+
await ws.send(encoded);
|
|
42
|
+
}));
|
|
43
|
+
if (result.matched && isClientPeerSendMessage(result.message)) await peer.message(result.message, createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest)));
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Cleans up peer state for a closed WebSocket.
|
|
48
|
+
* Messages passed to `.message()` for this WebSocket afterwards are ignored.
|
|
49
|
+
*
|
|
50
|
+
* @param ws The same WebSocket instance passed to `.message()`.
|
|
51
|
+
*/
|
|
52
|
+
async close(ws) {
|
|
53
|
+
const peer = this.peers.get(ws);
|
|
54
|
+
this.peers.set(ws, null);
|
|
55
|
+
await peer?.close();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Attaches message, close, and error event listeners to a WebSocket.
|
|
59
|
+
*
|
|
60
|
+
* Prefer this over calling `.message()` and `.close()` manually.
|
|
61
|
+
*/
|
|
62
|
+
upgrade(ws, ...rest) {
|
|
63
|
+
/**
|
|
64
|
+
* Message order is important: loading -> decode -> .message.
|
|
65
|
+
* This flow must stay synchronous, or we need to use `sequential` helper
|
|
66
|
+
*/
|
|
67
|
+
ws.addEventListener("message", sequential(async (event) => {
|
|
68
|
+
const data = event.data instanceof Blob ? await loadBytes(event.data) : event.data;
|
|
69
|
+
this.message(ws, data, ...rest);
|
|
70
|
+
}));
|
|
71
|
+
ws.addEventListener("close", () => this.close(ws));
|
|
72
|
+
ws.addEventListener("error", () => {});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
export { WebSocketHandler };
|
|
@@ -1,61 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DBANIheG.js';
|
|
5
|
-
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
|
|
6
|
-
import { R as Router } from '../../shared/server.Pa0F03f_.js';
|
|
7
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.d_2NS3g5.js';
|
|
8
|
-
import '@orpc/client';
|
|
9
|
-
import '@orpc/contract';
|
|
10
|
-
import '@standardserver/core';
|
|
11
|
-
|
|
12
|
-
type WebsocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send'>;
|
|
13
|
-
interface WebsocketHandlerOptions<_T extends Context> {
|
|
14
|
-
/**
|
|
15
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
16
|
-
*/
|
|
17
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
18
|
-
/**
|
|
19
|
-
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
20
|
-
*/
|
|
21
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
22
|
-
}
|
|
23
|
-
declare class WebsocketHandler<T extends Context> {
|
|
24
|
-
private readonly handler;
|
|
25
|
-
private readonly peers;
|
|
26
|
-
private readonly encodePeerMessageOptions;
|
|
27
|
-
private readonly decodePeerMessageOptions;
|
|
28
|
-
constructor(handler: StandardHandler<T>, options?: NoInfer<WebsocketHandlerOptions<T>>);
|
|
29
|
-
/**
|
|
30
|
-
* Attaches necessary event listeners to a WebSocket to handle incoming messages and peer management.
|
|
31
|
-
*/
|
|
32
|
-
upgrade(ws: WebsocketLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
33
|
-
/**
|
|
34
|
-
* Handles a single message received from a WebSocket.
|
|
35
|
-
*
|
|
36
|
-
* @warning AVOID calling this method, if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
37
|
-
*
|
|
38
|
-
* @param ws The WebSocket instance, require consistent instance across messages for proper peer management
|
|
39
|
-
* @param data The message data received from the WebSocket, can be string, ArrayBuffer, Blob, ...
|
|
40
|
-
*/
|
|
41
|
-
message(ws: WebsocketLike, data: string | ArrayBuffer | Blob | Exclude<ConstructorParameters<typeof Blob>[0], undefined>[0][] | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
|
|
42
|
-
matched: boolean;
|
|
43
|
-
}>;
|
|
44
|
-
/**
|
|
45
|
-
* Called when a websocket is closed, to clean up any associated peer state.
|
|
46
|
-
*
|
|
47
|
-
* @warning AVOID calling this method, if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
48
|
-
*
|
|
49
|
-
* @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
50
|
-
*/
|
|
51
|
-
close(ws: WebsocketLike): Promise<void>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebsocketHandlerOptions<T> {
|
|
55
|
-
}
|
|
56
|
-
declare class RPCHandler<T extends Context> extends WebsocketHandler<T> {
|
|
57
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { RPCHandler, WebsocketHandler };
|
|
61
|
-
export type { RPCHandlerOptions, WebsocketHandlerOptions, WebsocketLike };
|
|
1
|
+
import { WebSocketHandler, WebSocketHandlerOptions, WebSocketLike } from "./handler.js";
|
|
2
|
+
import { RPCHandler, RPCHandlerOptions } from "./rpc-handler.js";
|
|
3
|
+
export { RPCHandler, RPCHandlerOptions, WebSocketHandler, WebSocketHandlerOptions, WebSocketLike };
|
|
@@ -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 { WebSocketHandler, WebSocketHandlerOptions } from "./handler.js";
|
|
7
|
+
export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {}
|
|
8
|
+
/**
|
|
9
|
+
* Serves an oRPC router over the RPC protocol on a standard WebSocket
|
|
10
|
+
* connection (Deno, Bun, Cloudflare Durable Objects, and more).
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
|
|
13
|
+
*/
|
|
14
|
+
export declare class RPCHandler<T extends Context> extends WebSocketHandler<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 { WebSocketHandler } from "./handler.js";
|
|
4
|
+
// src/adapters/websocket/rpc-handler.ts
|
|
5
|
+
/**
|
|
6
|
+
* Serves an oRPC router over the RPC protocol on a standard WebSocket
|
|
7
|
+
* connection (Deno, Bun, Cloudflare Durable Objects, and more).
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
|
|
10
|
+
*/
|
|
11
|
+
var RPCHandler = class extends WebSocketHandler {
|
|
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 };
|