@orpc/server 2.0.0-beta.47 → 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 +6 -7
- 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 +10 -45
- 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 -63
- 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 -42
- 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 +5 -45
- 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/{index.d.mts → handler.d.ts} +17 -30
- package/dist/adapters/message-port/handler.js +86 -0
- package/dist/adapters/message-port/index.d.ts +2 -77
- 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 +5 -42
- 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/codec.js +1 -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 -95
- 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 -11
- package/dist/adapters/standard-peer/index.js +1 -0
- package/dist/adapters/standard-peer/utils.d.ts +4 -0
- package/dist/adapters/standard-peer/utils.js +7 -0
- package/dist/adapters/websocket/{index.d.mts → handler.d.ts} +11 -29
- package/dist/adapters/websocket/handler.js +85 -0
- package/dist/adapters/websocket/index.d.ts +2 -77
- 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-variants.js +1 -0
- package/dist/builder.d.ts +127 -0
- package/dist/builder.js +226 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/context.d.ts +6 -0
- package/dist/context.js +1 -0
- package/dist/extensions/callable.d.ts +6 -5
- 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 -167
- 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 +45 -460
- 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/middleware.js +1 -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 +29 -422
- 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/{shared/server.CgBF3Vj1.d.ts → plugins/request-limit.d.ts} +4 -8
- 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.ts +5 -0
- package/dist/router-hidden.js +14 -0
- package/dist/router-utils.d.ts +48 -0
- package/dist/router-utils.js +202 -0
- package/dist/{shared/server.Dz7j9BEh.d.ts → router.d.ts} +14 -15
- package/dist/router.js +1 -0
- package/package.json +84 -86
- package/dist/adapters/aws-lambda/index.d.mts +0 -51
- package/dist/adapters/aws-lambda/index.mjs +0 -39
- package/dist/adapters/crossws/index.d.mts +0 -63
- package/dist/adapters/crossws/index.mjs +0 -68
- package/dist/adapters/fastify/index.d.mts +0 -42
- package/dist/adapters/fastify/index.mjs +0 -39
- package/dist/adapters/fetch/index.d.mts +0 -47
- package/dist/adapters/fetch/index.mjs +0 -42
- package/dist/adapters/message-port/index.mjs +0 -87
- package/dist/adapters/node/index.d.mts +0 -44
- package/dist/adapters/node/index.mjs +0 -41
- package/dist/adapters/standard/index.d.mts +0 -95
- package/dist/adapters/standard/index.mjs +0 -8
- package/dist/adapters/standard-peer/index.d.mts +0 -11
- package/dist/adapters/standard-peer/index.mjs +0 -10
- package/dist/adapters/websocket/index.mjs +0 -87
- package/dist/extensions/callable.d.mts +0 -10
- package/dist/extensions/callable.mjs +0 -11
- package/dist/helpers/index.d.mts +0 -167
- package/dist/helpers/index.mjs +0 -200
- package/dist/index.d.mts +0 -476
- package/dist/index.mjs +0 -463
- package/dist/plugins/index.d.mts +0 -432
- package/dist/plugins/index.mjs +0 -965
- package/dist/shared/server.1ExWFMze.mjs +0 -69
- package/dist/shared/server.9B1jEm5a.d.mts +0 -105
- package/dist/shared/server.BB464y-6.mjs +0 -207
- package/dist/shared/server.BC5BIu02.d.mts +0 -73
- package/dist/shared/server.BSYGskId.d.ts +0 -14
- package/dist/shared/server.BvG3boBj.d.mts +0 -14
- package/dist/shared/server.CTV_mC2P.d.mts +0 -34
- package/dist/shared/server.CYbIpHbH.mjs +0 -239
- package/dist/shared/server.Chq5FpXf.mjs +0 -353
- package/dist/shared/server.DFPxP2v3.d.mts +0 -166
- package/dist/shared/server.DFPxP2v3.d.ts +0 -166
- package/dist/shared/server.DOg7ke6y.d.ts +0 -105
- package/dist/shared/server.W91HSRkE.mjs +0 -9
- package/dist/shared/server.sBQSgqK3.mjs +0 -41
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ORPCError } from '@orpc/client';
|
|
2
|
-
import { toArray } from '@orpc/shared';
|
|
3
|
-
import { flattenStandardHeader } from '@standard-server/core';
|
|
4
|
-
import { toFetchHeaders, toStandardBody } from '@standard-server/fetch';
|
|
5
|
-
|
|
6
|
-
class RequestLimitHandlerPlugin {
|
|
7
|
-
name = "~request-limit";
|
|
8
|
-
/**
|
|
9
|
-
* Should limit the original batch request body instead of sub-requests.
|
|
10
|
-
*/
|
|
11
|
-
after = ["~batch"];
|
|
12
|
-
/**
|
|
13
|
-
* Should limit the final body size instead of the compressed one.
|
|
14
|
-
*/
|
|
15
|
-
before = ["~request-compression"];
|
|
16
|
-
maxBodySize;
|
|
17
|
-
constructor(options) {
|
|
18
|
-
this.maxBodySize = options.maxBodySize;
|
|
19
|
-
}
|
|
20
|
-
init(options) {
|
|
21
|
-
const maxBodySize = this.maxBodySize;
|
|
22
|
-
const routingInterceptor = async ({ next, ...interceptorOptions }) => {
|
|
23
|
-
return next({
|
|
24
|
-
...interceptorOptions,
|
|
25
|
-
request: {
|
|
26
|
-
...interceptorOptions.request,
|
|
27
|
-
async resolveBody(hint) {
|
|
28
|
-
const contentLength = Number(
|
|
29
|
-
flattenStandardHeader(interceptorOptions.request.headers["content-length"])
|
|
30
|
-
);
|
|
31
|
-
if (Number.isFinite(contentLength) && contentLength > maxBodySize) {
|
|
32
|
-
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
|
33
|
-
}
|
|
34
|
-
const stream = await interceptorOptions.request.resolveBody("octet-stream");
|
|
35
|
-
if (!(stream instanceof ReadableStream)) {
|
|
36
|
-
return stream;
|
|
37
|
-
}
|
|
38
|
-
let currentBodySize = 0;
|
|
39
|
-
const limitedStream = stream.pipeThrough(
|
|
40
|
-
new TransformStream({
|
|
41
|
-
transform(chunk, controller) {
|
|
42
|
-
currentBodySize += chunk.byteLength;
|
|
43
|
-
if (currentBodySize > maxBodySize) {
|
|
44
|
-
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
controller.enqueue(chunk);
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
const response = new Response(limitedStream, {
|
|
52
|
-
headers: toFetchHeaders(interceptorOptions.request.headers)
|
|
53
|
-
});
|
|
54
|
-
return toStandardBody(response, { hint });
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
return {
|
|
60
|
-
...options,
|
|
61
|
-
routingInterceptors: [
|
|
62
|
-
routingInterceptor,
|
|
63
|
-
...toArray(options.routingInterceptors)
|
|
64
|
-
]
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export { RequestLimitHandlerPlugin as R };
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { OrderablePlugin, Value, Promisable, Interceptor } from '@orpc/shared';
|
|
3
|
-
import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
|
|
4
|
-
import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.DFPxP2v3.mjs';
|
|
5
|
-
import { Schema, ErrorMap } from '@orpc/contract';
|
|
6
|
-
|
|
7
|
-
interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the plugin and returns new handler options.
|
|
10
|
-
* Called once per plugin instance during composition.
|
|
11
|
-
*
|
|
12
|
-
* This method allows plugins to wrap, extend, or transform handler options
|
|
13
|
-
* such as interceptors, or configuration.
|
|
14
|
-
*
|
|
15
|
-
* @param options - The current handler options from previous plugins or base configuration
|
|
16
|
-
* @returns Transformed handler options with plugin's modifications applied
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* init(options) {
|
|
21
|
-
* return {
|
|
22
|
-
* ...options,
|
|
23
|
-
* interceptors: [...(options.interceptors || []), myInterceptor]
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
init?(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface StandardHandlerHandleOptions<T extends Context> {
|
|
32
|
-
prefix?: `/${string}` | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* The initial context, or a function (sync or async) that receives the request and returns it.
|
|
35
|
-
* The function only runs once the request passes the prefix check.
|
|
36
|
-
*/
|
|
37
|
-
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* `StandardHandlerHandleOptions` after the context has been resolved,
|
|
41
|
-
* this is what interceptors and codecs receive.
|
|
42
|
-
*/
|
|
43
|
-
interface ResolvedStandardHandlerHandleOptions<T extends Context> extends Omit<StandardHandlerHandleOptions<T>, 'context'> {
|
|
44
|
-
context: T;
|
|
45
|
-
}
|
|
46
|
-
type StandardHandlerHandleResult = {
|
|
47
|
-
matched: true;
|
|
48
|
-
response: StandardResponse;
|
|
49
|
-
} | {
|
|
50
|
-
matched: false;
|
|
51
|
-
response?: undefined;
|
|
52
|
-
};
|
|
53
|
-
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure, ResolvedStandardHandlerHandleOptions<T> {
|
|
54
|
-
request: StandardLazyRequest;
|
|
55
|
-
}
|
|
56
|
-
type StandardHandlerInterceptor<T extends Context> = Interceptor<StandardHandlerInterceptorOptions<T>, Promise<StandardResponse>>;
|
|
57
|
-
interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends ResolvedStandardHandlerHandleOptions<T> {
|
|
58
|
-
request: StandardLazyRequest;
|
|
59
|
-
}
|
|
60
|
-
type StandardHandlerRoutingInterceptor<T extends Context> = Interceptor<StandardHandlerRoutingInterceptorOptions<T>, Promise<StandardHandlerHandleResult>>;
|
|
61
|
-
interface StandardHandlerOptions<TContext extends Context> {
|
|
62
|
-
/**
|
|
63
|
-
* Fired on every request before routing, useful when you want
|
|
64
|
-
* to intercept all requests regardless of whether they match a procedure or not.
|
|
65
|
-
*
|
|
66
|
-
* @examples
|
|
67
|
-
* - batch plugins - separate one request into multiple and call multiple next
|
|
68
|
-
* - openapi spec plugin - to intercept a request and early response
|
|
69
|
-
*/
|
|
70
|
-
routingInterceptors?: StandardHandlerRoutingInterceptor<TContext>[] | undefined;
|
|
71
|
-
/**
|
|
72
|
-
* interceptor run after routing and before error handler,
|
|
73
|
-
* useful for error handling, logging, metrics, etc.
|
|
74
|
-
*/
|
|
75
|
-
interceptors?: StandardHandlerInterceptor<TContext>[] | undefined;
|
|
76
|
-
/**
|
|
77
|
-
*
|
|
78
|
-
* ClientInterceptor equivalent with createRouterClient.interceptors / createProcedure.interceptors
|
|
79
|
-
* useful for error handling, logging, metrics, etc. (not counting encoding/decoding)
|
|
80
|
-
*/
|
|
81
|
-
clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap>[] | undefined;
|
|
82
|
-
plugins?: StandardHandlerPlugin<TContext>[] | undefined;
|
|
83
|
-
}
|
|
84
|
-
declare class StandardHandler<T extends Context> {
|
|
85
|
-
private readonly codec;
|
|
86
|
-
private readonly routingInterceptors;
|
|
87
|
-
private readonly interceptors;
|
|
88
|
-
private readonly clientInterceptors;
|
|
89
|
-
constructor(codec: StandardHandlerCodec<T>, options: StandardHandlerOptions<T>);
|
|
90
|
-
handle(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerHandleResult>;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
interface StandardHandlerCodecResolvedProcedure {
|
|
94
|
-
path: string[];
|
|
95
|
-
procedure: AnyProcedure;
|
|
96
|
-
decodeInput: () => Promise<unknown>;
|
|
97
|
-
}
|
|
98
|
-
interface StandardHandlerCodec<T extends Context> {
|
|
99
|
-
resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
100
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
101
|
-
encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export { StandardHandler as S };
|
|
105
|
-
export type { ResolvedStandardHandlerHandleOptions as R, StandardHandlerHandleOptions as a, StandardHandlerPlugin as b, StandardHandlerOptions as c, StandardHandlerRoutingInterceptorOptions as d, StandardHandlerInterceptorOptions as e, StandardHandlerCodec as f, StandardHandlerCodecResolvedProcedure as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { wrapAsyncIteratorPreservingEventMeta, ORPCError } from '@orpc/client';
|
|
2
|
-
import { createORPCErrorConstructorMap, reconcileORPCError, ValidationError, ProcedureContract } from '@orpc/contract';
|
|
3
|
-
import { getConstructor, isTypescriptObject, resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, override, getTracer, traceAsyncIterator, traceReadableStream, mergeTwoLevels } from '@orpc/shared';
|
|
4
|
-
|
|
5
|
-
class Lazy {
|
|
6
|
-
"~orpc";
|
|
7
|
-
constructor(def) {
|
|
8
|
-
this["~orpc"] = def;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Checks if the given instance satisfies the {@link Lazy} class/interface.
|
|
12
|
-
*/
|
|
13
|
-
static [Symbol.hasInstance](instance) {
|
|
14
|
-
if (this !== Lazy) {
|
|
15
|
-
return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
16
|
-
}
|
|
17
|
-
const constructor = getConstructor(instance);
|
|
18
|
-
if (constructor === Lazy) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
return isTypescriptObject(instance) && isTypescriptObject(instance["~orpc"]) && isTypescriptObject(instance["~orpc"].meta) && (instance["~orpc"].metaPlugins === void 0 || Array.isArray(instance["~orpc"].metaPlugins)) && typeof instance["~orpc"].loader === "function";
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function unlazy(maybeLazy) {
|
|
25
|
-
return maybeLazy instanceof Lazy ? maybeLazy["~orpc"].loader() : Promise.resolve({ default: maybeLazy });
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function createProcedureClient(lazyableProcedure, ...rest) {
|
|
29
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
30
|
-
return async (...[input, callerOptions]) => {
|
|
31
|
-
const path = toArray(options.path);
|
|
32
|
-
const { default: procedure } = await unlazy(lazyableProcedure);
|
|
33
|
-
const clientContext = callerOptions?.context ?? {};
|
|
34
|
-
const context = await value(options.context, clientContext) ?? {};
|
|
35
|
-
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
|
|
36
|
-
const reconcileError = async (e) => {
|
|
37
|
-
if (e instanceof ORPCError) {
|
|
38
|
-
return await reconcileORPCError(procedure["~orpc"].errorMap, e);
|
|
39
|
-
}
|
|
40
|
-
return e;
|
|
41
|
-
};
|
|
42
|
-
try {
|
|
43
|
-
const output = await runWithSpan("call_procedure", (span) => {
|
|
44
|
-
span?.setAttribute("procedure.path", path);
|
|
45
|
-
return intercept(
|
|
46
|
-
options.interceptors,
|
|
47
|
-
{
|
|
48
|
-
context,
|
|
49
|
-
// input can be optional if it is undefinable
|
|
50
|
-
input,
|
|
51
|
-
errors,
|
|
52
|
-
path,
|
|
53
|
-
procedure,
|
|
54
|
-
signal: callerOptions?.signal,
|
|
55
|
-
lastEventId: callerOptions?.lastEventId
|
|
56
|
-
},
|
|
57
|
-
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
if (isAsyncIteratorObject(output)) {
|
|
61
|
-
return override(output, wrapAsyncIteratorPreservingEventMeta(
|
|
62
|
-
getTracer() ? traceAsyncIterator("consume_async_iterator_object_output", output) : output,
|
|
63
|
-
{ mapError: reconcileError }
|
|
64
|
-
));
|
|
65
|
-
} else if (getTracer() && output instanceof ReadableStream) {
|
|
66
|
-
return override(output, traceReadableStream("consume_octet_stream_output", output));
|
|
67
|
-
}
|
|
68
|
-
return output;
|
|
69
|
-
} catch (e) {
|
|
70
|
-
throw await reconcileError(e);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
async function validateInput(i, schema, input) {
|
|
75
|
-
return runWithSpan(`validate_input.${i}`, async (span) => {
|
|
76
|
-
span?.setAttribute("input_schema.index", i);
|
|
77
|
-
const result = await schema["~standard"].validate(input);
|
|
78
|
-
if (result.issues) {
|
|
79
|
-
throw new ORPCError("BAD_REQUEST", {
|
|
80
|
-
message: "Input validation failed",
|
|
81
|
-
data: {
|
|
82
|
-
issues: result.issues
|
|
83
|
-
},
|
|
84
|
-
cause: new ValidationError({
|
|
85
|
-
message: "Input validation failed",
|
|
86
|
-
issues: result.issues,
|
|
87
|
-
invalidData: input
|
|
88
|
-
})
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return result.value;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
async function validateOutput(i, schema, output) {
|
|
95
|
-
return runWithSpan(`validate_output.${i}`, async (span) => {
|
|
96
|
-
span?.setAttribute("output_schema.index", i);
|
|
97
|
-
const result = await schema["~standard"].validate(output);
|
|
98
|
-
if (result.issues) {
|
|
99
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
100
|
-
message: "Output validation failed",
|
|
101
|
-
cause: new ValidationError({
|
|
102
|
-
message: "Output validation failed",
|
|
103
|
-
issues: result.issues,
|
|
104
|
-
invalidData: output
|
|
105
|
-
})
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return result.value;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const middlewareDone = (...rest) => {
|
|
112
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
113
|
-
return {
|
|
114
|
-
output: options.output,
|
|
115
|
-
// context can be undefined when all field is optional
|
|
116
|
-
context: options.context ?? {}
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
async function executeProcedureInternal(procedure, options) {
|
|
120
|
-
const inputSchemas = toArray(procedure["~orpc"].inputSchemas);
|
|
121
|
-
const outputSchemas = toArray(procedure["~orpc"].outputSchemas);
|
|
122
|
-
const orderedMiddlewares = procedure["~orpc"].orderedMiddlewares;
|
|
123
|
-
const next = async (midIndex, context, input, signal) => {
|
|
124
|
-
let currentInput = input;
|
|
125
|
-
let middlewareInput = input;
|
|
126
|
-
const startInputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].inputSchemasLengthAtUse ?? 0;
|
|
127
|
-
const endInputIndex = midIndex === orderedMiddlewares.length ? inputSchemas.length : orderedMiddlewares[midIndex].inputSchemasLengthAtUse ?? 0;
|
|
128
|
-
if (!procedure["~orpc"].disableInputValidation) {
|
|
129
|
-
for (let i = startInputIndex; i < endInputIndex; i++) {
|
|
130
|
-
const validated = await validateInput(
|
|
131
|
-
i,
|
|
132
|
-
inputSchemas[i],
|
|
133
|
-
i !== 0 ? mergeTwoLevels(options.input, currentInput) : currentInput
|
|
134
|
-
);
|
|
135
|
-
currentInput = i !== 0 ? mergeTwoLevels(currentInput, validated) : validated;
|
|
136
|
-
}
|
|
137
|
-
middlewareInput = endInputIndex > 0 && endInputIndex < inputSchemas.length ? mergeTwoLevels(options.input, currentInput) : currentInput;
|
|
138
|
-
}
|
|
139
|
-
let currentOutput;
|
|
140
|
-
let currentContext = context;
|
|
141
|
-
if (midIndex < orderedMiddlewares.length) {
|
|
142
|
-
const { middleware } = orderedMiddlewares[midIndex];
|
|
143
|
-
const result = await runWithSpan(`middleware.${middleware.name}`, async (span) => {
|
|
144
|
-
span?.setAttribute("middleware.index", midIndex);
|
|
145
|
-
return await middleware(
|
|
146
|
-
{
|
|
147
|
-
...options,
|
|
148
|
-
context,
|
|
149
|
-
signal,
|
|
150
|
-
next: (...rest) => {
|
|
151
|
-
const nextOptions = resolveMaybeOptionalOptions(rest);
|
|
152
|
-
const nextContext = nextOptions.context ?? {};
|
|
153
|
-
return next(
|
|
154
|
-
midIndex + 1,
|
|
155
|
-
{ ...context, ...nextContext },
|
|
156
|
-
currentInput,
|
|
157
|
-
nextOptions.signal ?? signal
|
|
158
|
-
);
|
|
159
|
-
},
|
|
160
|
-
lastEventId: options.lastEventId
|
|
161
|
-
},
|
|
162
|
-
middlewareInput,
|
|
163
|
-
middlewareDone
|
|
164
|
-
);
|
|
165
|
-
});
|
|
166
|
-
currentOutput = result.output;
|
|
167
|
-
currentContext = { ...context, ...result.context };
|
|
168
|
-
} else {
|
|
169
|
-
currentOutput = await runWithSpan(
|
|
170
|
-
"handler",
|
|
171
|
-
() => procedure["~orpc"].handler({ ...options, context, input: currentInput, signal }, currentInput)
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
const startOutputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].outputSchemasLengthAtUse ?? 0;
|
|
175
|
-
const endOutputIndex = midIndex === orderedMiddlewares.length ? outputSchemas.length : orderedMiddlewares[midIndex].outputSchemasLengthAtUse ?? 0;
|
|
176
|
-
if (!procedure["~orpc"].disableOutputValidation) {
|
|
177
|
-
for (let i = endOutputIndex - 1; i >= startOutputIndex; i--) {
|
|
178
|
-
currentOutput = await validateOutput(i, outputSchemas[i], currentOutput);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return { output: currentOutput, context: currentContext };
|
|
182
|
-
};
|
|
183
|
-
const { output } = await next(0, options.context, options.input, options.signal);
|
|
184
|
-
return output;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
class Procedure {
|
|
188
|
-
"~orpc";
|
|
189
|
-
constructor(def) {
|
|
190
|
-
this["~orpc"] = def;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Checks if the given instance satisfies the {@link Procedure} class/interface.
|
|
194
|
-
*/
|
|
195
|
-
static [Symbol.hasInstance](instance) {
|
|
196
|
-
if (this !== Procedure) {
|
|
197
|
-
return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
198
|
-
}
|
|
199
|
-
const constructor = getConstructor(instance);
|
|
200
|
-
if (constructor === Procedure) {
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
return instance instanceof ProcedureContract && Array.isArray(instance["~orpc"].orderedMiddlewares) && typeof instance["~orpc"].handler === "function";
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export { Lazy as L, Procedure as P, createProcedureClient as c, unlazy as u };
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { RouterContract, ProcedureContract, ORPCErrorFromErrorMap, ThrowableError, InferSchemaInput, InferSchemaOutput } from '@orpc/contract';
|
|
2
|
-
import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.DFPxP2v3.mjs';
|
|
3
|
-
|
|
4
|
-
type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any> | {
|
|
5
|
-
[k: string]: Lazyable<Router<TInitialContext>>;
|
|
6
|
-
};
|
|
7
|
-
type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap> : {
|
|
8
|
-
[K in keyof T]: T[K] extends RouterContract ? Lazyable<ContractedRouter<T[K], TInitialContext>> : never;
|
|
9
|
-
};
|
|
10
|
-
type AnyRouter = Router<any>;
|
|
11
|
-
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $> ? $ : never;
|
|
12
|
-
/**
|
|
13
|
-
* Infer all initial context of the router.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* **Note**: A procedure is a router too.
|
|
17
|
-
*
|
|
18
|
-
* @see {@link https://orpc.dev/docs/router#infer-router-initial-contexts | Router - Infer Router Initial Contexts}
|
|
19
|
-
*/
|
|
20
|
-
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
|
|
21
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Infer all current context of the router.
|
|
25
|
-
*
|
|
26
|
-
* @remarks
|
|
27
|
-
* **Note**: A procedure is a router too.
|
|
28
|
-
*
|
|
29
|
-
* @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts}
|
|
30
|
-
*/
|
|
31
|
-
type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
|
|
32
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Infer all router inputs.
|
|
36
|
-
*
|
|
37
|
-
* @remarks
|
|
38
|
-
* **Note**: A procedure is a router too.
|
|
39
|
-
*
|
|
40
|
-
* @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs}
|
|
41
|
-
*/
|
|
42
|
-
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
43
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Infer all router outputs.
|
|
47
|
-
*
|
|
48
|
-
* @remarks
|
|
49
|
-
* **Note**: A procedure is a router too.
|
|
50
|
-
*
|
|
51
|
-
* @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs}
|
|
52
|
-
*/
|
|
53
|
-
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
54
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Infer the union of throwable errors for entire router.
|
|
58
|
-
*
|
|
59
|
-
* @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error}
|
|
60
|
-
*/
|
|
61
|
-
type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
62
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never;
|
|
63
|
-
}[keyof T];
|
|
64
|
-
/**
|
|
65
|
-
* Infer throwable errors for each procedure, preserving the router shape.
|
|
66
|
-
*
|
|
67
|
-
* @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors}
|
|
68
|
-
*/
|
|
69
|
-
type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
70
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterFinalContexts as a, InferRouterError as b, InferRouterErrors as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
-
import { StandardLazyRequest } from '@standard-server/core';
|
|
3
|
-
import { C as Context } from './server.DFPxP2v3.js';
|
|
4
|
-
import { a as StandardHandlerHandleOptions } from './server.DOg7ke6y.js';
|
|
5
|
-
|
|
6
|
-
type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
|
|
7
|
-
context?: Value<Promisable<T>, [request: StandardLazyRequest]> | undefined;
|
|
8
|
-
} : {
|
|
9
|
-
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
10
|
-
});
|
|
11
|
-
declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
|
|
12
|
-
|
|
13
|
-
export { resolveFriendlyStandardHandlerHandleOptions as r };
|
|
14
|
-
export type { FriendlyStandardHandlerHandleOptions as F };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
-
import { StandardLazyRequest } from '@standard-server/core';
|
|
3
|
-
import { C as Context } from './server.DFPxP2v3.mjs';
|
|
4
|
-
import { a as StandardHandlerHandleOptions } from './server.9B1jEm5a.mjs';
|
|
5
|
-
|
|
6
|
-
type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
|
|
7
|
-
context?: Value<Promisable<T>, [request: StandardLazyRequest]> | undefined;
|
|
8
|
-
} : {
|
|
9
|
-
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
10
|
-
});
|
|
11
|
-
declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
|
|
12
|
-
|
|
13
|
-
export { resolveFriendlyStandardHandlerHandleOptions as r };
|
|
14
|
-
export type { FriendlyStandardHandlerHandleOptions as F };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { C as Context } from './server.DFPxP2v3.mjs';
|
|
2
|
-
import { b as StandardHandlerPlugin, c as StandardHandlerOptions } from './server.9B1jEm5a.mjs';
|
|
3
|
-
|
|
4
|
-
interface RequestLimitHandlerPluginOptions {
|
|
5
|
-
/**
|
|
6
|
-
* The maximum allowed request body size in bytes.
|
|
7
|
-
*/
|
|
8
|
-
maxBodySize: number;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Rejects requests whose body exceeds `maxBodySize`.
|
|
12
|
-
*
|
|
13
|
-
* When used with the request compression plugin, the limit applies to the
|
|
14
|
-
* decompressed payload rather than the compressed wire size.
|
|
15
|
-
*
|
|
16
|
-
* @see {@link https://orpc.dev/docs/plugins/request-limit | Request Limit Plugin}
|
|
17
|
-
*/
|
|
18
|
-
declare class RequestLimitHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
19
|
-
name: string;
|
|
20
|
-
/**
|
|
21
|
-
* Should limit the original batch request body instead of sub-requests.
|
|
22
|
-
*/
|
|
23
|
-
after: string[];
|
|
24
|
-
/**
|
|
25
|
-
* Should limit the final body size instead of the compressed one.
|
|
26
|
-
*/
|
|
27
|
-
before: string[];
|
|
28
|
-
private readonly maxBodySize;
|
|
29
|
-
constructor(options: RequestLimitHandlerPluginOptions);
|
|
30
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { RequestLimitHandlerPlugin as R };
|
|
34
|
-
export type { RequestLimitHandlerPluginOptions as a };
|