@orpc/server 2.0.0-beta.48 → 2.0.0-beta.49
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 +4 -4
- package/dist/adapters/aws-lambda/handler.d.ts +25 -0
- package/dist/adapters/aws-lambda/handler.js +24 -0
- package/dist/adapters/aws-lambda/index.d.ts +16 -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 +18 -0
- package/dist/adapters/crossws/handler.d.ts +45 -0
- package/dist/adapters/crossws/handler.js +60 -0
- package/dist/adapters/crossws/index.d.ts +2 -0
- 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 +15 -0
- package/dist/adapters/fastify/handler.d.ts +21 -0
- package/dist/adapters/fastify/handler.js +20 -0
- package/dist/adapters/fastify/index.d.ts +2 -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 +14 -0
- package/dist/adapters/fetch/handler.d.ts +23 -0
- package/dist/adapters/fetch/handler.js +22 -0
- package/dist/adapters/fetch/index.d.ts +7 -0
- package/dist/adapters/fetch/index.js +7 -0
- package/dist/adapters/fetch/rpc-handler.d.ts +17 -0
- package/dist/adapters/fetch/rpc-handler.js +16 -0
- package/dist/adapters/message-port/handler.d.ts +64 -0
- package/dist/adapters/message-port/handler.js +86 -0
- package/dist/adapters/message-port/index.d.ts +2 -0
- 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 +15 -0
- package/dist/adapters/node/handler.d.ts +21 -0
- package/dist/adapters/node/handler.js +20 -0
- package/dist/adapters/node/index.d.ts +7 -0
- package/dist/adapters/node/index.js +7 -0
- package/dist/adapters/node/rpc-handler.d.ts +16 -0
- package/dist/adapters/node/rpc-handler.js +15 -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 +6 -0
- package/dist/adapters/standard/index.js +5 -0
- package/dist/adapters/standard/plugin.d.ts +32 -0
- package/dist/adapters/standard/plugin.js +16 -0
- package/dist/adapters/standard/rpc-handler-codec.d.ts +46 -0
- package/dist/adapters/standard/rpc-handler-codec.js +51 -0
- package/dist/adapters/standard/rpc-matcher.d.ts +53 -0
- package/dist/adapters/standard/rpc-matcher.js +152 -0
- package/dist/adapters/standard/utils.d.ts +10 -0
- package/dist/adapters/standard/utils.js +6 -0
- package/dist/adapters/standard-peer/index.d.ts +1 -0
- package/dist/adapters/standard-peer/index.js +1 -0
- package/dist/adapters/standard-peer/{utils.d.mts → utils.d.ts} +3 -3
- package/dist/adapters/standard-peer/utils.js +7 -0
- package/dist/adapters/websocket/handler.d.ts +59 -0
- package/dist/adapters/websocket/handler.js +85 -0
- package/dist/adapters/websocket/index.d.ts +2 -0
- 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 +15 -0
- package/dist/builder-variants.d.ts +226 -0
- package/dist/builder.d.ts +127 -0
- package/dist/builder.js +226 -0
- package/dist/context.d.ts +6 -0
- package/dist/extensions/callable.d.ts +11 -0
- package/dist/extensions/callable.js +7 -0
- package/dist/helpers/base64url.d.ts +31 -0
- package/dist/helpers/base64url.js +53 -0
- package/dist/helpers/cookie.d.ts +51 -0
- package/dist/helpers/cookie.js +69 -0
- package/dist/helpers/encryption.d.ts +28 -0
- package/dist/helpers/encryption.js +80 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/signing.d.ts +50 -0
- package/dist/helpers/signing.js +88 -0
- package/dist/implementer-procedure.d.ts +16 -0
- package/dist/implementer-procedure.js +44 -0
- package/dist/implementer-router.d.ts +40 -0
- package/dist/implementer-router.js +117 -0
- package/dist/implementer.d.ts +16 -0
- package/dist/implementer.js +37 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +48 -0
- package/dist/lazy.d.ts +20 -0
- package/dist/lazy.js +31 -0
- package/dist/middleware-decorated.d.ts +10 -0
- package/dist/middleware-decorated.js +71 -0
- package/dist/middleware.d.ts +54 -0
- package/dist/plugins/batch.d.ts +102 -0
- package/dist/plugins/batch.js +405 -0
- package/dist/plugins/cors.d.ts +73 -0
- package/dist/plugins/cors.js +112 -0
- package/dist/plugins/get-method-csrf-protection.d.ts +23 -0
- package/dist/plugins/get-method-csrf-protection.js +64 -0
- package/dist/plugins/head-method.d.ts +23 -0
- package/dist/plugins/head-method.js +104 -0
- package/dist/plugins/index.d.ts +39 -0
- package/dist/plugins/index.js +29 -0
- package/dist/plugins/method-override.d.ts +38 -0
- package/dist/plugins/method-override.js +50 -0
- package/dist/plugins/request-compression.d.ts +16 -0
- package/dist/plugins/request-compression.js +82 -0
- package/dist/plugins/request-headers.d.ts +22 -0
- package/dist/plugins/request-headers.js +30 -0
- package/dist/plugins/request-limit.d.ts +30 -0
- package/dist/plugins/request-limit.js +68 -0
- package/dist/plugins/response-compression.d.ts +59 -0
- package/dist/plugins/response-compression.js +209 -0
- package/dist/plugins/response-headers.d.ts +30 -0
- package/dist/plugins/response-headers.js +47 -0
- package/dist/plugins/rethrow.d.ts +33 -0
- package/dist/plugins/rethrow.js +59 -0
- package/dist/plugins/signal-sync.d.ts +13 -0
- package/dist/plugins/signal-sync.js +91 -0
- package/dist/plugins/timeout.d.ts +37 -0
- package/dist/plugins/timeout.js +59 -0
- package/dist/procedure-client.d.ts +19 -0
- package/dist/procedure-client.js +175 -0
- package/dist/procedure-decorated.d.ts +10 -0
- package/dist/procedure-decorated.js +44 -0
- package/dist/procedure-utils.d.ts +41 -0
- package/dist/procedure-utils.js +49 -0
- package/dist/procedure.d.ts +72 -0
- package/dist/procedure.js +24 -0
- package/dist/router-client.d.ts +23 -0
- package/dist/router-client.js +43 -0
- package/dist/{router-hidden.d.mts → router-hidden.d.ts} +3 -3
- package/dist/router-hidden.js +14 -0
- package/dist/router-utils.d.ts +48 -0
- package/dist/router-utils.js +202 -0
- package/dist/router.d.ts +72 -0
- package/package.json +84 -86
- package/dist/adapters/aws-lambda/handler.d.mts +0 -25
- package/dist/adapters/aws-lambda/handler.mjs +0 -21
- package/dist/adapters/aws-lambda/index.d.mts +0 -16
- package/dist/adapters/aws-lambda/index.mjs +0 -2
- package/dist/adapters/aws-lambda/rpc-handler.d.mts +0 -18
- package/dist/adapters/aws-lambda/rpc-handler.mjs +0 -10
- package/dist/adapters/crossws/handler.d.mts +0 -41
- package/dist/adapters/crossws/handler.mjs +0 -38
- package/dist/adapters/crossws/index.d.mts +0 -2
- package/dist/adapters/crossws/index.mjs +0 -2
- package/dist/adapters/crossws/rpc-handler.d.mts +0 -15
- package/dist/adapters/crossws/rpc-handler.mjs +0 -10
- package/dist/adapters/fastify/handler.d.mts +0 -21
- package/dist/adapters/fastify/handler.mjs +0 -20
- package/dist/adapters/fastify/index.d.mts +0 -2
- package/dist/adapters/fastify/index.mjs +0 -2
- package/dist/adapters/fastify/rpc-handler.d.mts +0 -14
- package/dist/adapters/fastify/rpc-handler.mjs +0 -10
- package/dist/adapters/fetch/handler.d.mts +0 -23
- package/dist/adapters/fetch/handler.mjs +0 -22
- package/dist/adapters/fetch/index.d.mts +0 -7
- package/dist/adapters/fetch/index.mjs +0 -5
- package/dist/adapters/fetch/rpc-handler.d.mts +0 -16
- package/dist/adapters/fetch/rpc-handler.mjs +0 -10
- package/dist/adapters/message-port/handler.d.mts +0 -57
- package/dist/adapters/message-port/handler.mjs +0 -62
- package/dist/adapters/message-port/index.d.mts +0 -2
- package/dist/adapters/message-port/index.mjs +0 -2
- package/dist/adapters/message-port/rpc-handler.d.mts +0 -15
- package/dist/adapters/message-port/rpc-handler.mjs +0 -10
- package/dist/adapters/node/handler.d.mts +0 -21
- package/dist/adapters/node/handler.mjs +0 -20
- package/dist/adapters/node/index.d.mts +0 -7
- package/dist/adapters/node/index.mjs +0 -5
- package/dist/adapters/node/rpc-handler.d.mts +0 -15
- package/dist/adapters/node/rpc-handler.mjs +0 -10
- package/dist/adapters/standard/codec.d.mts +0 -16
- package/dist/adapters/standard/handler.d.mts +0 -68
- package/dist/adapters/standard/handler.mjs +0 -185
- package/dist/adapters/standard/index.d.mts +0 -6
- package/dist/adapters/standard/index.mjs +0 -5
- package/dist/adapters/standard/plugin.d.mts +0 -32
- package/dist/adapters/standard/plugin.mjs +0 -16
- package/dist/adapters/standard/rpc-handler-codec.d.mts +0 -42
- package/dist/adapters/standard/rpc-handler-codec.mjs +0 -51
- package/dist/adapters/standard/rpc-matcher.d.mts +0 -53
- package/dist/adapters/standard/rpc-matcher.mjs +0 -140
- package/dist/adapters/standard/utils.d.mts +0 -10
- package/dist/adapters/standard/utils.mjs +0 -6
- package/dist/adapters/standard-peer/index.d.mts +0 -1
- package/dist/adapters/standard-peer/index.mjs +0 -1
- package/dist/adapters/standard-peer/utils.mjs +0 -11
- package/dist/adapters/websocket/handler.d.mts +0 -55
- package/dist/adapters/websocket/handler.mjs +0 -55
- package/dist/adapters/websocket/index.d.mts +0 -2
- package/dist/adapters/websocket/index.mjs +0 -2
- package/dist/adapters/websocket/rpc-handler.d.mts +0 -15
- package/dist/adapters/websocket/rpc-handler.mjs +0 -10
- package/dist/builder-variants.d.mts +0 -267
- package/dist/builder.d.mts +0 -141
- package/dist/builder.mjs +0 -145
- package/dist/context.d.mts +0 -13
- package/dist/extensions/callable.d.mts +0 -17
- package/dist/extensions/callable.mjs +0 -7
- package/dist/helpers/base64url.d.mts +0 -31
- package/dist/helpers/base64url.mjs +0 -25
- package/dist/helpers/cookie.d.mts +0 -50
- package/dist/helpers/cookie.mjs +0 -35
- package/dist/helpers/encryption.d.mts +0 -28
- package/dist/helpers/encryption.mjs +0 -62
- package/dist/helpers/index.d.mts +0 -4
- package/dist/helpers/index.mjs +0 -4
- package/dist/helpers/signing.d.mts +0 -50
- package/dist/helpers/signing.mjs +0 -43
- package/dist/implementer-procedure.d.mts +0 -36
- package/dist/implementer-procedure.mjs +0 -38
- package/dist/implementer-router.d.mts +0 -78
- package/dist/implementer-router.mjs +0 -77
- package/dist/implementer.d.mts +0 -22
- package/dist/implementer.mjs +0 -30
- package/dist/index.d.mts +0 -57
- package/dist/index.mjs +0 -30
- package/dist/lazy.d.mts +0 -20
- package/dist/lazy.mjs +0 -22
- package/dist/middleware-decorated.d.mts +0 -27
- package/dist/middleware-decorated.mjs +0 -65
- package/dist/middleware.d.mts +0 -70
- package/dist/plugins/batch.d.mts +0 -104
- package/dist/plugins/batch.mjs +0 -373
- package/dist/plugins/cors.d.mts +0 -67
- package/dist/plugins/cors.mjs +0 -134
- package/dist/plugins/get-method-csrf-protection.d.mts +0 -23
- package/dist/plugins/get-method-csrf-protection.mjs +0 -45
- package/dist/plugins/head-method.d.mts +0 -23
- package/dist/plugins/head-method.mjs +0 -95
- package/dist/plugins/index.d.mts +0 -39
- package/dist/plugins/index.mjs +0 -23
- package/dist/plugins/method-override.d.mts +0 -38
- package/dist/plugins/method-override.mjs +0 -50
- package/dist/plugins/request-compression.d.mts +0 -16
- package/dist/plugins/request-compression.mjs +0 -67
- package/dist/plugins/request-headers.d.mts +0 -22
- package/dist/plugins/request-headers.mjs +0 -21
- package/dist/plugins/request-limit.d.mts +0 -30
- package/dist/plugins/request-limit.mjs +0 -53
- package/dist/plugins/response-compression.d.mts +0 -59
- package/dist/plugins/response-compression.mjs +0 -172
- package/dist/plugins/response-headers.d.mts +0 -30
- package/dist/plugins/response-headers.mjs +0 -34
- package/dist/plugins/rethrow.d.mts +0 -33
- package/dist/plugins/rethrow.mjs +0 -46
- package/dist/plugins/signal-sync.d.mts +0 -13
- package/dist/plugins/signal-sync.mjs +0 -84
- package/dist/plugins/timeout.d.mts +0 -37
- package/dist/plugins/timeout.mjs +0 -56
- package/dist/procedure-client.d.mts +0 -41
- package/dist/procedure-client.mjs +0 -157
- package/dist/procedure-decorated.d.mts +0 -20
- package/dist/procedure-decorated.mjs +0 -41
- package/dist/procedure-utils.d.mts +0 -52
- package/dist/procedure-utils.mjs +0 -33
- package/dist/procedure.d.mts +0 -93
- package/dist/procedure.mjs +0 -20
- package/dist/router-client.d.mts +0 -27
- package/dist/router-client.mjs +0 -35
- package/dist/router-hidden.mjs +0 -12
- package/dist/router-utils.d.mts +0 -59
- package/dist/router-utils.mjs +0 -191
- package/dist/router.d.mts +0 -61
- /package/dist/adapters/standard/{codec.mjs → codec.js} +0 -0
- /package/dist/{builder-variants.mjs → builder-variants.js} +0 -0
- /package/dist/{constants.d.mts → constants.d.ts} +0 -0
- /package/dist/{constants.mjs → constants.js} +0 -0
- /package/dist/{context.mjs → context.js} +0 -0
- /package/dist/{middleware.mjs → middleware.js} +0 -0
- /package/dist/{router.mjs → router.js} +0 -0
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { ErrorMap, Schema } from "@orpc/contract";
|
|
2
|
-
import type { Interceptor, Promisable, Value } from "@orpc/shared";
|
|
3
|
-
import type { StandardLazyRequest, StandardResponse } from "@standard-server/core";
|
|
4
|
-
import type { Context } from "../../context.mjs";
|
|
5
|
-
import type { ProcedureClientInterceptor } from "../../procedure-client.mjs";
|
|
6
|
-
import type { StandardHandlerCodec, StandardHandlerCodecResolvedProcedure } from "./codec.mjs";
|
|
7
|
-
import type { StandardHandlerPlugin } from "./plugin.mjs";
|
|
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
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { ORPCError, toORPCError } from "@orpc/client";
|
|
2
|
-
import { getTracer, intercept, isAsyncIteratorObject, matchesHttpPathPrefix, ORPC_NAME, override, recordSpanError, runWithSpan, toArray, toTracingException, traceAsyncIterator, traceReadableStream, value, wrapAsyncIterator, wrapReadableStream } from "@orpc/shared";
|
|
3
|
-
import { ErrorEvent, flattenStandardHeader, parseStandardUrl } from "@standard-server/core";
|
|
4
|
-
import { createProcedureClient } from "../../procedure-client.mjs";
|
|
5
|
-
import { CompositeStandardHandlerPlugin } from "./plugin.mjs";
|
|
6
|
-
export class StandardHandler {
|
|
7
|
-
codec;
|
|
8
|
-
routingInterceptors;
|
|
9
|
-
interceptors;
|
|
10
|
-
clientInterceptors;
|
|
11
|
-
constructor(codec, options) {
|
|
12
|
-
this.codec = codec;
|
|
13
|
-
options = new CompositeStandardHandlerPlugin([...toArray(options.plugins), new TracingHandlerPlugin()]).init(options);
|
|
14
|
-
this.routingInterceptors = options.routingInterceptors;
|
|
15
|
-
this.interceptors = options.interceptors;
|
|
16
|
-
this.clientInterceptors = options.clientInterceptors;
|
|
17
|
-
}
|
|
18
|
-
async handle(request, options) {
|
|
19
|
-
const { prefix } = options;
|
|
20
|
-
if (prefix && !matchesHttpPathPrefix(request.url, prefix)) {
|
|
21
|
-
return {
|
|
22
|
-
matched: false,
|
|
23
|
-
response: undefined
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const context = await value(options.context, request);
|
|
27
|
-
return intercept(this.routingInterceptors, {
|
|
28
|
-
context,
|
|
29
|
-
prefix,
|
|
30
|
-
request
|
|
31
|
-
}, async ({ context, prefix, request }) => {
|
|
32
|
-
const span = getTracer()?.getActiveSpan();
|
|
33
|
-
let step;
|
|
34
|
-
const matchedOrNot = await runWithSpan("find_procedure", () => this.codec.resolveProcedure(request, {
|
|
35
|
-
context,
|
|
36
|
-
prefix
|
|
37
|
-
}));
|
|
38
|
-
if (!matchedOrNot) {
|
|
39
|
-
|
|
40
|
-
span?.updateName(`${ORPC_NAME}_no_match`);
|
|
41
|
-
span?.setAttribute("http.request.method", request.method);
|
|
42
|
-
span?.setAttribute("url.path", request.url);
|
|
43
|
-
return { matched: false };
|
|
44
|
-
}
|
|
45
|
-
const { path, procedure, decodeInput } = matchedOrNot;
|
|
46
|
-
|
|
47
|
-
span?.updateName(`${ORPC_NAME}.${path.join("/")}`);
|
|
48
|
-
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
49
|
-
span?.setAttribute("rpc.method", path.join("."));
|
|
50
|
-
try {
|
|
51
|
-
const response = await intercept(this.interceptors, {
|
|
52
|
-
context,
|
|
53
|
-
prefix,
|
|
54
|
-
request,
|
|
55
|
-
path,
|
|
56
|
-
procedure,
|
|
57
|
-
decodeInput
|
|
58
|
-
}, async ({ context, prefix, request, path, procedure, decodeInput }) => {
|
|
59
|
-
step = "decode_input";
|
|
60
|
-
let input = await runWithSpan("decode_input", decodeInput);
|
|
61
|
-
step = undefined;
|
|
62
|
-
if (getTracer() && isAsyncIteratorObject(input)) {
|
|
63
|
-
|
|
64
|
-
input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
|
|
65
|
-
} else if (getTracer() && input instanceof ReadableStream) {
|
|
66
|
-
|
|
67
|
-
input = override(input, traceReadableStream("consume_octet_stream_input", input));
|
|
68
|
-
}
|
|
69
|
-
const client = createProcedureClient(procedure, {
|
|
70
|
-
context,
|
|
71
|
-
path,
|
|
72
|
-
interceptors: this.clientInterceptors
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
step = "call_procedure";
|
|
76
|
-
const output = await client(input, {
|
|
77
|
-
signal: request.signal,
|
|
78
|
-
lastEventId: flattenStandardHeader(request.headers["last-event-id"])
|
|
79
|
-
});
|
|
80
|
-
step = undefined;
|
|
81
|
-
const response = await this.codec.encodeOutput(output, procedure, path, {
|
|
82
|
-
context,
|
|
83
|
-
prefix
|
|
84
|
-
});
|
|
85
|
-
return response;
|
|
86
|
-
});
|
|
87
|
-
return {
|
|
88
|
-
matched: true,
|
|
89
|
-
response
|
|
90
|
-
};
|
|
91
|
-
} catch (e) {
|
|
92
|
-
|
|
93
|
-
if (step !== "call_procedure") {
|
|
94
|
-
recordSpanError(span, e);
|
|
95
|
-
}
|
|
96
|
-
const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
|
|
97
|
-
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
|
98
|
-
cause: e
|
|
99
|
-
}) : toORPCError(e);
|
|
100
|
-
const response = await this.codec.encodeError(error, procedure, path, {
|
|
101
|
-
context,
|
|
102
|
-
prefix
|
|
103
|
-
});
|
|
104
|
-
return {
|
|
105
|
-
matched: true,
|
|
106
|
-
response
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
class TracingHandlerPlugin {
|
|
113
|
-
name = "~tracing";
|
|
114
|
-
init(options) {
|
|
115
|
-
return {
|
|
116
|
-
...options,
|
|
117
|
-
routingInterceptors: [async ({ next, request }) => {
|
|
118
|
-
const tracer = getTracer();
|
|
119
|
-
if (!tracer) {
|
|
120
|
-
return next();
|
|
121
|
-
}
|
|
122
|
-
const parent = tracer.extract?.(request.headers);
|
|
123
|
-
|
|
124
|
-
const [pathname] = parseStandardUrl(request.url);
|
|
125
|
-
return tracer.startActiveSpan(`${request.method} ${pathname}`, parent, async (span) => {
|
|
126
|
-
try {
|
|
127
|
-
const result = await next();
|
|
128
|
-
if (!result.matched) {
|
|
129
|
-
span.end();
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
const body = result.response.body;
|
|
133
|
-
if (isAsyncIteratorObject(body)) {
|
|
134
|
-
return {
|
|
135
|
-
...result,
|
|
136
|
-
response: {
|
|
137
|
-
...result.response,
|
|
138
|
-
|
|
139
|
-
body: override(body, wrapAsyncIterator(body, {
|
|
140
|
-
runWith: (fn) => tracer.withActiveSpan(span, fn),
|
|
141
|
-
onError(error) {
|
|
142
|
-
|
|
143
|
-
if (!(error instanceof ErrorEvent)) {
|
|
144
|
-
span.recordException("error", toTracingException(error));
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
onFinish() {
|
|
148
|
-
span.end();
|
|
149
|
-
}
|
|
150
|
-
}))
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
if (body instanceof ReadableStream) {
|
|
155
|
-
return {
|
|
156
|
-
...result,
|
|
157
|
-
response: {
|
|
158
|
-
...result.response,
|
|
159
|
-
|
|
160
|
-
body: override(body, wrapReadableStream(body, {
|
|
161
|
-
runWith: (fn) => tracer.withActiveSpan(span, fn),
|
|
162
|
-
onError(error) {
|
|
163
|
-
|
|
164
|
-
span.recordException("error", toTracingException(error));
|
|
165
|
-
},
|
|
166
|
-
onFinish() {
|
|
167
|
-
span.end();
|
|
168
|
-
}
|
|
169
|
-
}))
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
span.end();
|
|
174
|
-
return result;
|
|
175
|
-
} catch (e) {
|
|
176
|
-
|
|
177
|
-
span.recordException("error", toTracingException(e));
|
|
178
|
-
span.end();
|
|
179
|
-
throw e;
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}, ...toArray(options.routingInterceptors)]
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { OrderablePlugin } from "@orpc/shared";
|
|
2
|
-
import type { Context } from "../../context.mjs";
|
|
3
|
-
import type { StandardHandlerOptions } from "./handler.mjs";
|
|
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
|
-
}
|
|
27
|
-
export declare class CompositeStandardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
28
|
-
readonly name = "~composite";
|
|
29
|
-
protected readonly plugins: StandardHandlerPlugin<T>[];
|
|
30
|
-
constructor(plugins?: StandardHandlerPlugin<T>[]);
|
|
31
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
32
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { sortPlugins } from "@orpc/shared";
|
|
2
|
-
export class CompositeStandardHandlerPlugin {
|
|
3
|
-
name = "~composite";
|
|
4
|
-
plugins;
|
|
5
|
-
constructor(plugins = []) {
|
|
6
|
-
this.plugins = sortPlugins(plugins);
|
|
7
|
-
}
|
|
8
|
-
init(options) {
|
|
9
|
-
for (const plugin of this.plugins) {
|
|
10
|
-
if (plugin.init) {
|
|
11
|
-
options = plugin.init(options);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return options;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { AnyORPCError } from "@orpc/client";
|
|
2
|
-
import type { Promisable, Public, Value } from "@orpc/shared";
|
|
3
|
-
import type { StandardLazyRequest, StandardResponse } from "@standard-server/core";
|
|
4
|
-
import type { Context } from "../../context.mjs";
|
|
5
|
-
import type { AnyProcedure } from "../../procedure.mjs";
|
|
6
|
-
import type { AnyRouter } from "../../router.mjs";
|
|
7
|
-
import type { ResolvedStandardHandlerHandleOptions, StandardHandlerCodec, StandardHandlerCodecResolvedProcedure } from "./index.mjs";
|
|
8
|
-
import type { RPCMatcherOptions } from "./rpc-matcher.mjs";
|
|
9
|
-
import { RPCSerializer } from "@orpc/client";
|
|
10
|
-
export interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Override the default RPC serializer.
|
|
13
|
-
*/
|
|
14
|
-
serializer?: Public<RPCSerializer> | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* Resolve HTTP status for encoded successful outputs.
|
|
17
|
-
*
|
|
18
|
-
* Value should be in the `2xx` range and must be less than `400`.
|
|
19
|
-
* Return `undefined` or `null` to fallback to default
|
|
20
|
-
*
|
|
21
|
-
* @default DEFAULT_SUCCESS_STATUS (200)
|
|
22
|
-
*/
|
|
23
|
-
outputStatus?: Value<number | undefined | null, [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
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { COMMON_ERROR_STATUS_MAP, RPCSerializer } from "@orpc/client";
|
|
2
|
-
import { getOwn, parseEmptyableJSON, value } from "@orpc/shared";
|
|
3
|
-
import { parseStandardUrl } from "@standard-server/core";
|
|
4
|
-
import { DEFAULT_ERROR_STATUS, DEFAULT_SUCCESS_STATUS } from "../../constants.mjs";
|
|
5
|
-
import { RPCMatcher } from "./rpc-matcher.mjs";
|
|
6
|
-
export class RPCHandlerCodec {
|
|
7
|
-
matcher;
|
|
8
|
-
serializer;
|
|
9
|
-
errorStatusMap;
|
|
10
|
-
outputStatus;
|
|
11
|
-
constructor(router, options = {}) {
|
|
12
|
-
this.matcher = new RPCMatcher(router, options);
|
|
13
|
-
this.serializer = options.serializer ?? new RPCSerializer();
|
|
14
|
-
this.errorStatusMap = options.errorStatusMap ?? COMMON_ERROR_STATUS_MAP;
|
|
15
|
-
this.outputStatus = options.outputStatus;
|
|
16
|
-
}
|
|
17
|
-
async resolveProcedure(request, options) {
|
|
18
|
-
const [pathname, query] = parseStandardUrl(request.url);
|
|
19
|
-
const matched = await this.matcher.match(request.method, pathname, options.prefix);
|
|
20
|
-
if (!matched) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
procedure: matched.procedure,
|
|
25
|
-
path: matched.path,
|
|
26
|
-
decodeInput: async () => {
|
|
27
|
-
if (request.method === "GET") {
|
|
28
|
-
const dataString = new URLSearchParams(query).getAll("data").at(-1);
|
|
29
|
-
return this.serializer.deserialize(parseEmptyableJSON(dataString));
|
|
30
|
-
}
|
|
31
|
-
const body = await request.resolveBody();
|
|
32
|
-
return this.serializer.deserialize(body);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
encodeOutput(output, procedure, path, options) {
|
|
37
|
-
return {
|
|
38
|
-
headers: {},
|
|
39
|
-
status: value(this.outputStatus, output, procedure, path, options) ?? DEFAULT_SUCCESS_STATUS,
|
|
40
|
-
body: this.serializer.serialize(output)
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
encodeError(error, _procedure, _path, _options) {
|
|
44
|
-
const status = getOwn(this.errorStatusMap, error.code) ?? DEFAULT_ERROR_STATUS;
|
|
45
|
-
return {
|
|
46
|
-
headers: {},
|
|
47
|
-
status,
|
|
48
|
-
body: this.serializer.serialize(error.toJSON())
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { AnyProcedureContract } from "@orpc/contract";
|
|
2
|
-
import type { Value } from "@orpc/shared";
|
|
3
|
-
import type { StandardMethod } from "@standard-server/core";
|
|
4
|
-
import type { AnyProcedure } from "../../procedure.mjs";
|
|
5
|
-
import type { AnyRouter } from "../../router.mjs";
|
|
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
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { normalizeHttpPath, pathToHttpPath, value } from "@orpc/shared";
|
|
2
|
-
import { unlazy } from "../../lazy.mjs";
|
|
3
|
-
import { Procedure } from "../../procedure.mjs";
|
|
4
|
-
import { resolveContractProcedure, walkProcedureContractsSync } from "../../router-utils.mjs";
|
|
5
|
-
|
|
6
|
-
export const RPC_DEFAULT_ALLOW_METHODS = [
|
|
7
|
-
"POST",
|
|
8
|
-
"PUT",
|
|
9
|
-
"PATCH",
|
|
10
|
-
"DELETE"
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
const NORMALIZABLE_PATHNAME_REGEX = /[^\w\-.!~*'()/]/;
|
|
14
|
-
export class RPCMatcher {
|
|
15
|
-
filter;
|
|
16
|
-
allowMethodsSet;
|
|
17
|
-
allowMethodsFn;
|
|
18
|
-
rootRouter;
|
|
19
|
-
tree = new Map();
|
|
20
|
-
pendingLazyRouters = new Map();
|
|
21
|
-
|
|
22
|
-
maxPendingLazyRouterDepth = 0;
|
|
23
|
-
constructor(router, options = {}) {
|
|
24
|
-
this.filter = options.filter ?? true;
|
|
25
|
-
const allowMethods = options.allowMethods ?? RPC_DEFAULT_ALLOW_METHODS;
|
|
26
|
-
if (typeof allowMethods !== "function") {
|
|
27
|
-
this.allowMethodsSet = new Set(allowMethods);
|
|
28
|
-
} else {
|
|
29
|
-
this.allowMethodsFn = allowMethods;
|
|
30
|
-
}
|
|
31
|
-
this.rootRouter = router;
|
|
32
|
-
this.index(router);
|
|
33
|
-
}
|
|
34
|
-
index(router, path = []) {
|
|
35
|
-
const lazyResults = walkProcedureContractsSync(router, (procedure, procedurePath) => {
|
|
36
|
-
if (!value(this.filter, procedure, procedurePath)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
this.tree.set(pathToHttpPath(procedurePath), {
|
|
40
|
-
path: procedurePath,
|
|
41
|
-
contract: procedure,
|
|
42
|
-
|
|
43
|
-
procedure: procedure instanceof Procedure ? procedure : undefined
|
|
44
|
-
});
|
|
45
|
-
}, path);
|
|
46
|
-
for (const result of lazyResults) {
|
|
47
|
-
this.pendingLazyRouters.set(pathToHttpPath(result.path), result);
|
|
48
|
-
this.maxPendingLazyRouterDepth = Math.max(this.maxPendingLazyRouterDepth, result.path.length);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
async match(method, pathname, prefix) {
|
|
52
|
-
if (this.allowMethodsSet && !this.allowMethodsSet.has(method)) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
if (prefix) {
|
|
56
|
-
if (!pathname.startsWith(prefix)) {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
const charAfterPrefix = pathname[prefix.length];
|
|
60
|
-
if (charAfterPrefix === "/") {
|
|
61
|
-
pathname = pathname.slice(prefix.length);
|
|
62
|
-
} else if (charAfterPrefix === undefined) {
|
|
63
|
-
pathname = "/";
|
|
64
|
-
} else if (prefix[prefix.length - 1] === "/") {
|
|
65
|
-
pathname = pathname.slice(prefix.length - 1);
|
|
66
|
-
} else {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (pathname.length > 1 && pathname.endsWith("/")) {
|
|
71
|
-
pathname = pathname.slice(0, -1);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const loading = this.resolvePendingLazyRouters(pathname);
|
|
75
|
-
if (loading !== undefined) {
|
|
76
|
-
await loading;
|
|
77
|
-
}
|
|
78
|
-
let entry = this.tree.get(pathname);
|
|
79
|
-
if (entry === undefined && NORMALIZABLE_PATHNAME_REGEX.test(pathname)) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const normalizedPathname = normalizeHttpPath(pathname);
|
|
84
|
-
|
|
85
|
-
const normalizedLoading = this.resolvePendingLazyRouters(normalizedPathname);
|
|
86
|
-
if (normalizedLoading !== undefined) {
|
|
87
|
-
await normalizedLoading;
|
|
88
|
-
}
|
|
89
|
-
entry = this.tree.get(normalizedPathname);
|
|
90
|
-
}
|
|
91
|
-
if (entry === undefined) {
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
const procedure = entry.procedure ?? await this.resolveProcedure(entry);
|
|
95
|
-
if (this.allowMethodsFn && !this.allowMethodsFn(method, procedure, entry.path)) {
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
path: entry.path,
|
|
100
|
-
procedure
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
resolvePendingLazyRouters(pathname) {
|
|
104
|
-
if (this.pendingLazyRouters.size === 0) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
let slashIndex = 0;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
for (let depth = 1; slashIndex !== -1 && depth <= this.maxPendingLazyRouterDepth; depth++) {
|
|
111
|
-
const nextSlashIndex = pathname.indexOf("/", slashIndex + 1);
|
|
112
|
-
const httpPathPrefix = nextSlashIndex === -1 ? pathname : pathname.slice(0, nextSlashIndex);
|
|
113
|
-
const pending = this.pendingLazyRouters.get(httpPathPrefix);
|
|
114
|
-
if (pending !== undefined) {
|
|
115
|
-
return this.loadPendingLazyRouter(httpPathPrefix, pending).then(() => this.resolvePendingLazyRouters(pathname));
|
|
116
|
-
}
|
|
117
|
-
slashIndex = nextSlashIndex;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
loadPendingLazyRouter(httpPathPrefix, pending) {
|
|
121
|
-
if (pending.loading === undefined) {
|
|
122
|
-
pending.loading = this.indexPendingLazyRouter(httpPathPrefix, pending).catch((error) => {
|
|
123
|
-
pending.loading = undefined;
|
|
124
|
-
throw error;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
return pending.loading;
|
|
128
|
-
}
|
|
129
|
-
async indexPendingLazyRouter(httpPathPrefix, pending) {
|
|
130
|
-
const { default: router } = await unlazy(pending.router);
|
|
131
|
-
this.index(router, pending.path);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.pendingLazyRouters.delete(httpPathPrefix);
|
|
135
|
-
}
|
|
136
|
-
async resolveProcedure(entry) {
|
|
137
|
-
entry.procedure = await resolveContractProcedure(this.rootRouter, entry.contract, entry.path);
|
|
138
|
-
return entry.procedure;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Promisable, Value } from "@orpc/shared";
|
|
2
|
-
import type { StandardLazyRequest } from "@standard-server/core";
|
|
3
|
-
import type { Context } from "../../context.mjs";
|
|
4
|
-
import type { StandardHandlerHandleOptions } from "./handler.mjs";
|
|
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 +0,0 @@
|
|
|
1
|
-
export * from "./utils.mjs";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./utils.mjs";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { resolveFriendlyStandardHandlerHandleOptions } from "../standard/index.mjs";
|
|
2
|
-
export function createStandardPeerRequestHandler(handler, options) {
|
|
3
|
-
return async (request) => {
|
|
4
|
-
const { response } = await handler.handle(request, resolveFriendlyStandardHandlerHandleOptions(options));
|
|
5
|
-
return response ?? {
|
|
6
|
-
status: 404,
|
|
7
|
-
headers: {},
|
|
8
|
-
body: "No procedure matched"
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
}
|