@orpc/server 2.0.0-beta.5 → 2.0.0-beta.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -102
- package/dist/adapters/aws-lambda/handler.d.ts +27 -0
- package/dist/adapters/aws-lambda/handler.js +24 -0
- package/dist/adapters/aws-lambda/index.d.ts +4 -0
- package/dist/adapters/aws-lambda/index.js +2 -0
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +19 -0
- package/dist/adapters/aws-lambda/rpc-handler.js +21 -0
- package/dist/adapters/crossws/handler.d.ts +47 -0
- package/dist/adapters/crossws/handler.js +53 -0
- package/dist/adapters/crossws/index.d.ts +3 -54
- package/dist/adapters/crossws/index.js +2 -0
- package/dist/adapters/crossws/rpc-handler.d.ts +16 -0
- package/dist/adapters/crossws/rpc-handler.js +18 -0
- package/dist/adapters/fastify/handler.d.ts +23 -0
- package/dist/adapters/fastify/handler.js +20 -0
- package/dist/adapters/fastify/index.d.ts +3 -0
- package/dist/adapters/fastify/index.js +2 -0
- package/dist/adapters/fastify/rpc-handler.d.ts +15 -0
- package/dist/adapters/fastify/rpc-handler.js +17 -0
- package/dist/adapters/fetch/handler.d.ts +25 -0
- package/dist/adapters/fetch/handler.js +22 -0
- package/dist/adapters/fetch/index.d.ts +4 -140
- package/dist/adapters/fetch/index.js +3 -0
- package/dist/adapters/fetch/rpc-handler.d.ts +17 -0
- package/dist/adapters/fetch/rpc-handler.js +19 -0
- package/dist/adapters/message-port/handler.d.ts +62 -0
- package/dist/adapters/message-port/handler.js +72 -0
- package/dist/adapters/message-port/index.d.ts +3 -74
- package/dist/adapters/message-port/index.js +2 -0
- package/dist/adapters/message-port/rpc-handler.d.ts +16 -0
- package/dist/adapters/message-port/rpc-handler.js +18 -0
- package/dist/adapters/node/handler.d.ts +23 -0
- package/dist/adapters/node/handler.js +20 -0
- package/dist/adapters/node/index.d.ts +4 -121
- package/dist/adapters/node/index.js +3 -0
- package/dist/adapters/node/rpc-handler.d.ts +16 -0
- package/dist/adapters/node/rpc-handler.js +18 -0
- package/dist/adapters/standard/codec.d.ts +16 -0
- package/dist/adapters/standard/handler.d.ts +68 -0
- package/dist/adapters/standard/handler.js +205 -0
- package/dist/adapters/standard/index.d.ts +7 -19
- package/dist/adapters/standard/index.js +4 -0
- package/dist/adapters/standard/plugin.d.ts +26 -0
- package/dist/adapters/standard/plugin.js +14 -0
- package/dist/adapters/standard/rpc-handler-codec.d.ts +42 -0
- package/dist/adapters/standard/rpc-handler-codec.js +50 -0
- package/dist/adapters/standard/rpc-matcher.d.ts +53 -0
- package/dist/adapters/standard/rpc-matcher.js +106 -0
- package/dist/adapters/standard/utils.d.ts +10 -0
- package/dist/adapters/standard/utils.js +8 -0
- package/dist/adapters/standard-peer/index.d.ts +2 -16
- package/dist/adapters/standard-peer/index.js +1 -0
- package/dist/adapters/standard-peer/utils.d.ts +6 -0
- package/dist/adapters/standard-peer/utils.js +13 -0
- package/dist/adapters/websocket/handler.d.ts +61 -0
- package/dist/adapters/websocket/handler.js +75 -0
- package/dist/adapters/websocket/index.d.ts +3 -61
- package/dist/adapters/websocket/index.js +2 -0
- package/dist/adapters/websocket/rpc-handler.d.ts +16 -0
- package/dist/adapters/websocket/rpc-handler.js +18 -0
- package/dist/builder-variants.d.ts +226 -0
- package/dist/builder.d.ts +126 -0
- package/dist/builder.js +200 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +4 -0
- package/dist/context.d.ts +6 -0
- package/dist/extensions/callable.d.ts +11 -10
- package/dist/extensions/callable.js +8 -0
- package/dist/helpers/base64url.d.ts +31 -0
- package/dist/helpers/base64url.js +48 -0
- package/dist/helpers/cookie.d.ts +50 -0
- package/dist/helpers/cookie.js +62 -0
- package/dist/helpers/encryption.d.ts +28 -0
- package/dist/helpers/encryption.js +90 -0
- package/dist/helpers/index.d.ts +5 -149
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/signing.d.ts +50 -0
- package/dist/helpers/signing.js +78 -0
- package/dist/implementer-procedure.d.ts +15 -0
- package/dist/implementer-procedure.js +37 -0
- package/dist/implementer-router.d.ts +34 -0
- package/dist/implementer-router.js +98 -0
- package/dist/implementer.d.ts +16 -0
- package/dist/implementer.js +30 -0
- package/dist/index.d.ts +22 -196
- package/dist/index.js +16 -0
- package/dist/lazy.d.ts +20 -0
- package/dist/lazy.js +20 -0
- package/dist/middleware-decorated.d.ts +9 -0
- package/dist/middleware-decorated.js +67 -0
- package/dist/middleware.d.ts +54 -0
- package/dist/plugins/batch.d.ts +102 -0
- package/dist/plugins/batch.js +371 -0
- package/dist/plugins/cors.d.ts +69 -0
- package/dist/plugins/cors.js +119 -0
- package/dist/plugins/get-method-csrf-protection.d.ts +25 -0
- package/dist/plugins/get-method-csrf-protection.js +48 -0
- package/dist/plugins/head-method.d.ts +25 -0
- package/dist/plugins/head-method.js +107 -0
- package/dist/plugins/index.d.ts +15 -197
- package/dist/plugins/index.js +14 -0
- package/dist/plugins/method-override.d.ts +40 -0
- package/dist/plugins/method-override.js +54 -0
- package/dist/plugins/request-compression.d.ts +18 -0
- package/dist/plugins/request-compression.js +55 -0
- package/dist/plugins/request-headers.d.ts +24 -0
- package/dist/plugins/request-headers.js +28 -0
- package/dist/plugins/request-limit.d.ts +32 -0
- package/dist/plugins/request-limit.js +61 -0
- package/dist/plugins/response-compression.d.ts +62 -0
- package/dist/plugins/response-compression.js +157 -0
- package/dist/plugins/response-headers.d.ts +32 -0
- package/dist/plugins/response-headers.js +44 -0
- package/dist/plugins/rethrow.d.ts +35 -0
- package/dist/plugins/rethrow.js +47 -0
- package/dist/plugins/signal-sync.d.ts +15 -0
- package/dist/plugins/signal-sync.js +76 -0
- package/dist/plugins/timeout.d.ts +39 -0
- package/dist/plugins/timeout.js +62 -0
- package/dist/procedure-client.d.ts +18 -0
- package/dist/procedure-client.js +158 -0
- package/dist/procedure-decorated.d.ts +10 -0
- package/dist/procedure-decorated.js +36 -0
- package/dist/procedure-utils.d.ts +21 -0
- package/dist/procedure-utils.js +48 -0
- package/dist/procedure.d.ts +72 -0
- package/dist/procedure.js +18 -0
- package/dist/router-client.d.ts +21 -0
- package/dist/router-client.js +35 -0
- package/dist/router-hidden.js +12 -0
- package/dist/router-utils.d.ts +31 -0
- package/dist/router-utils.js +157 -0
- package/dist/router.d.ts +58 -0
- package/package.json +95 -63
- package/dist/adapters/crossws/index.d.mts +0 -54
- package/dist/adapters/crossws/index.mjs +0 -64
- package/dist/adapters/fetch/index.d.mts +0 -140
- package/dist/adapters/fetch/index.mjs +0 -204
- package/dist/adapters/message-port/index.d.mts +0 -74
- package/dist/adapters/message-port/index.mjs +0 -90
- package/dist/adapters/node/index.d.mts +0 -121
- package/dist/adapters/node/index.mjs +0 -179
- package/dist/adapters/standard/index.d.mts +0 -19
- package/dist/adapters/standard/index.mjs +0 -8
- package/dist/adapters/standard-peer/index.d.mts +0 -16
- package/dist/adapters/standard-peer/index.mjs +0 -2
- package/dist/adapters/websocket/index.d.mts +0 -61
- package/dist/adapters/websocket/index.mjs +0 -76
- package/dist/extensions/callable.d.mts +0 -10
- package/dist/extensions/callable.mjs +0 -11
- package/dist/helpers/index.d.mts +0 -149
- package/dist/helpers/index.mjs +0 -198
- package/dist/index.d.mts +0 -196
- package/dist/index.mjs +0 -385
- package/dist/plugins/index.d.mts +0 -197
- package/dist/plugins/index.mjs +0 -357
- package/dist/shared/server.BL22TloH.d.mts +0 -184
- package/dist/shared/server.BL22TloH.d.ts +0 -184
- package/dist/shared/server.BsNNjG5J.d.mts +0 -61
- package/dist/shared/server.BwHnWUuN.mjs +0 -222
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.Cj5lgPuG.d.mts +0 -66
- package/dist/shared/server.CjOb6ItT.mjs +0 -41
- package/dist/shared/server.CrlKQucM.mjs +0 -233
- package/dist/shared/server.DBANIheG.d.ts +0 -104
- package/dist/shared/server.DJIkub_t.d.mts +0 -104
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.GDpX6Df8.mjs +0 -271
- package/dist/shared/server.Pa0F03f_.d.ts +0 -61
- package/dist/shared/server.W91HSRkE.mjs +0 -9
- package/dist/shared/server.d_2NS3g5.d.ts +0 -66
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { toArray, sortPlugins, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { ORPCError } from '@orpc/client';
|
|
3
|
-
import { toStandardLazyRequest, toFetchResponse } from '@standardserver/fetch';
|
|
4
|
-
import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
|
|
5
|
-
import { C as CSRFGuardHandlerPlugin } from '../../shared/server.D_QauotT.mjs';
|
|
6
|
-
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.GDpX6Df8.mjs';
|
|
7
|
-
import '@standardserver/core';
|
|
8
|
-
import '../../shared/server.CrlKQucM.mjs';
|
|
9
|
-
import '@orpc/contract';
|
|
10
|
-
import '../../shared/server.BwHnWUuN.mjs';
|
|
11
|
-
|
|
12
|
-
const ORDERED_SUPPORTED_ENCODINGS = ["gzip", "deflate"];
|
|
13
|
-
class BodyCompressionHandlerPlugin {
|
|
14
|
-
name = "~body-compression";
|
|
15
|
-
encodings;
|
|
16
|
-
threshold;
|
|
17
|
-
filter;
|
|
18
|
-
constructor(options = {}) {
|
|
19
|
-
this.encodings = options.encodings ?? ORDERED_SUPPORTED_ENCODINGS;
|
|
20
|
-
this.threshold = options.threshold ?? 1024;
|
|
21
|
-
this.filter = (request, response) => {
|
|
22
|
-
const hasContentDisposition = response.headers.has("content-disposition");
|
|
23
|
-
const contentType = response.headers.get("content-type");
|
|
24
|
-
if (!hasContentDisposition && contentType?.startsWith("text/event-stream")) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
return options.filter ? options.filter(request, response) : isCompressibleContentType(contentType);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
initFetchHandlerOptions(options) {
|
|
31
|
-
return {
|
|
32
|
-
...options,
|
|
33
|
-
fetchInterceptors: [
|
|
34
|
-
async (interceptorOptions) => {
|
|
35
|
-
const result = await interceptorOptions.next();
|
|
36
|
-
if (!result.matched) {
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
const response = result.response;
|
|
40
|
-
if (response.headers.has("content-encoding") || response.headers.has("transfer-encoding") || isNoTransformCacheControl(response.headers.get("cache-control"))) {
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
const contentLength = response.headers.get("content-length");
|
|
44
|
-
if (contentLength && Number(contentLength) < this.threshold) {
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
const acceptEncoding = interceptorOptions.request.headers.get("accept-encoding")?.split(",").map((enc) => enc.trim().split(";")[0]);
|
|
48
|
-
const encoding = this.encodings.find((enc) => acceptEncoding?.includes(enc));
|
|
49
|
-
if (!response.body || encoding === void 0) {
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
if (!this.filter(interceptorOptions.request, response)) {
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
const compressedBody = response.body.pipeThrough(new CompressionStream(encoding));
|
|
56
|
-
const compressedHeaders = new Headers(response.headers);
|
|
57
|
-
compressedHeaders.delete("content-length");
|
|
58
|
-
compressedHeaders.set("content-encoding", encoding);
|
|
59
|
-
return {
|
|
60
|
-
...result,
|
|
61
|
-
response: new Response(compressedBody, {
|
|
62
|
-
status: response.status,
|
|
63
|
-
statusText: response.statusText,
|
|
64
|
-
headers: compressedHeaders
|
|
65
|
-
})
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
...toArray(options.fetchInterceptors)
|
|
69
|
-
]
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
74
|
-
function isCompressibleContentType(contentType) {
|
|
75
|
-
if (contentType === null) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
return COMPRESSIBLE_CONTENT_TYPE_REGEX.test(contentType);
|
|
79
|
-
}
|
|
80
|
-
const CACHE_CONTROL_NO_TRANSFORM_REGEX = /(?:^|,)\s*no-transform\s*(?:,|$)/i;
|
|
81
|
-
function isNoTransformCacheControl(cacheControl) {
|
|
82
|
-
if (cacheControl === null) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
return CACHE_CONTROL_NO_TRANSFORM_REGEX.test(cacheControl);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
class BodyLimitHandlerPlugin {
|
|
89
|
-
name = "~body-limit";
|
|
90
|
-
maxBodySize;
|
|
91
|
-
constructor(options) {
|
|
92
|
-
this.maxBodySize = options.maxBodySize;
|
|
93
|
-
}
|
|
94
|
-
initFetchHandlerOptions(options) {
|
|
95
|
-
return {
|
|
96
|
-
...options,
|
|
97
|
-
fetchInterceptors: [
|
|
98
|
-
async (interceptorOptions) => {
|
|
99
|
-
if (!interceptorOptions.request.body) {
|
|
100
|
-
return interceptorOptions.next();
|
|
101
|
-
}
|
|
102
|
-
let currentBodySize = 0;
|
|
103
|
-
const rawReader = interceptorOptions.request.body.getReader();
|
|
104
|
-
const body = new ReadableStream({
|
|
105
|
-
start: async (controller) => {
|
|
106
|
-
const reject = async (error) => {
|
|
107
|
-
controller.error(error);
|
|
108
|
-
await rawReader.cancel(error);
|
|
109
|
-
};
|
|
110
|
-
const contentLength = interceptorOptions.request.headers.get("content-length");
|
|
111
|
-
if (contentLength && Number(contentLength) > this.maxBodySize) {
|
|
112
|
-
await reject(new ORPCError("PAYLOAD_TOO_LARGE"));
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
while (true) {
|
|
116
|
-
const { done, value } = await rawReader.read();
|
|
117
|
-
if (done) {
|
|
118
|
-
controller.close();
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
currentBodySize += value.length;
|
|
122
|
-
if (currentBodySize > this.maxBodySize) {
|
|
123
|
-
await reject(new ORPCError("PAYLOAD_TOO_LARGE"));
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
controller.enqueue(value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
const requestInit = { body, duplex: "half" };
|
|
131
|
-
return interceptorOptions.next({
|
|
132
|
-
...interceptorOptions,
|
|
133
|
-
request: new Request(interceptorOptions.request, requestInit)
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
...toArray(options.fetchInterceptors)
|
|
137
|
-
]
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
class CompositeFetchHandlerPlugin {
|
|
143
|
-
name = "~composite/fetch-handler";
|
|
144
|
-
plugins;
|
|
145
|
-
constructor(plugins = []) {
|
|
146
|
-
this.plugins = sortPlugins(plugins);
|
|
147
|
-
}
|
|
148
|
-
initFetchHandlerOptions(options) {
|
|
149
|
-
for (const plugin of this.plugins) {
|
|
150
|
-
if (plugin.initFetchHandlerOptions) {
|
|
151
|
-
options = plugin.initFetchHandlerOptions(options);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return options;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
class FetchHandler {
|
|
159
|
-
constructor(standardHandler, options = {}) {
|
|
160
|
-
this.standardHandler = standardHandler;
|
|
161
|
-
options = new CompositeFetchHandlerPlugin(options.plugins).initFetchHandlerOptions(options);
|
|
162
|
-
this.fetchInterceptors = options.fetchInterceptors;
|
|
163
|
-
this.toFetchResponseOptions = options.toFetchResponse;
|
|
164
|
-
}
|
|
165
|
-
toFetchResponseOptions;
|
|
166
|
-
fetchInterceptors;
|
|
167
|
-
async handle(request, ...rest) {
|
|
168
|
-
return intercept(
|
|
169
|
-
this.fetchInterceptors,
|
|
170
|
-
{
|
|
171
|
-
...resolveFriendlyStandardHandlerHandleOptions(resolveMaybeOptionalOptions(rest)),
|
|
172
|
-
request,
|
|
173
|
-
toFetchResponseOptions: this.toFetchResponseOptions
|
|
174
|
-
},
|
|
175
|
-
async ({ request: request2, toFetchResponseOptions, ...options }) => {
|
|
176
|
-
const standardRequest = toStandardLazyRequest(request2);
|
|
177
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
|
178
|
-
if (!result.matched) {
|
|
179
|
-
return result;
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
matched: true,
|
|
183
|
-
response: toFetchResponse(result.response, toFetchResponseOptions)
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
class RPCHandler extends FetchHandler {
|
|
191
|
-
constructor(router, options = {}) {
|
|
192
|
-
if (options.csrfGuardHandlerPlugin?.enabled !== false) {
|
|
193
|
-
options = {
|
|
194
|
-
...options,
|
|
195
|
-
plugins: [...toArray(options.plugins), new CSRFGuardHandlerPlugin()]
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
const codec = new RPCHandlerCodec(router, options);
|
|
199
|
-
const handler = new StandardHandler(codec, options);
|
|
200
|
-
super(handler, options);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export { BodyCompressionHandlerPlugin, BodyLimitHandlerPlugin, CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { SupportedMessagePort } from '@orpc/client/message-port';
|
|
2
|
-
import { Value, Promisable, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
-
import { ServerPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
4
|
-
import { C as Context } from '../../shared/server.BL22TloH.mjs';
|
|
5
|
-
import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DJIkub_t.mjs';
|
|
6
|
-
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
|
|
7
|
-
import { R as Router } from '../../shared/server.BsNNjG5J.mjs';
|
|
8
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.Cj5lgPuG.mjs';
|
|
9
|
-
import '@orpc/client';
|
|
10
|
-
import '@orpc/contract';
|
|
11
|
-
import '@standardserver/core';
|
|
12
|
-
|
|
13
|
-
type DecodedResponseMessage = ConstructorParameters<typeof ServerPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
|
|
14
|
-
interface MessagePortHandlerOptions<_T extends Context> {
|
|
15
|
-
/**
|
|
16
|
-
* By default, oRPC encodes peer messages as strings or binary data before sending them over the message port.
|
|
17
|
-
* Use this option to bypass encoding and leverage the full capabilities of the
|
|
18
|
-
* [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
|
|
19
|
-
* such as transferring object ownership or supporting non-serializable objects like `OffscreenCanvas` or improving performance.
|
|
20
|
-
*
|
|
21
|
-
* @remarks
|
|
22
|
-
* - Returning `null` or `undefined` disables this feature.
|
|
23
|
-
*
|
|
24
|
-
* @warning Ensure your message port implementation supports `transferable` objects before enabling this.
|
|
25
|
-
*/
|
|
26
|
-
experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedResponseMessage, port: SupportedMessagePort]>;
|
|
27
|
-
/**
|
|
28
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
29
|
-
*/
|
|
30
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
33
|
-
*/
|
|
34
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
35
|
-
}
|
|
36
|
-
declare class MessagePortHandler<T extends Context> {
|
|
37
|
-
private readonly handler;
|
|
38
|
-
private readonly peers;
|
|
39
|
-
private readonly transfer;
|
|
40
|
-
private readonly encodePeerMessageOptions;
|
|
41
|
-
private readonly decodePeerMessageOptions;
|
|
42
|
-
constructor(handler: StandardHandler<T>, options?: NoInfer<MessagePortHandlerOptions<T>>);
|
|
43
|
-
/**
|
|
44
|
-
* Attaches necessary event listeners to a message port to handle incoming messages and peer management.
|
|
45
|
-
*/
|
|
46
|
-
upgrade(port: SupportedMessagePort, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
47
|
-
/**
|
|
48
|
-
* Handles a single message received from a message port.
|
|
49
|
-
*
|
|
50
|
-
* @warning AVOID calling this method directly if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
51
|
-
*
|
|
52
|
-
* @param port The message port instance, require consistent instance across messages for proper peer management
|
|
53
|
-
*/
|
|
54
|
-
message(port: SupportedMessagePort, data: any, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
|
|
55
|
-
matched: boolean;
|
|
56
|
-
}>;
|
|
57
|
-
/**
|
|
58
|
-
* Called when a message port is closed, to clean up any associated peer state.
|
|
59
|
-
*
|
|
60
|
-
* @warning AVOID calling this method directly if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
61
|
-
*
|
|
62
|
-
* @param port The message port instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
63
|
-
*/
|
|
64
|
-
close(port: SupportedMessagePort): Promise<void>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, MessagePortHandlerOptions<T> {
|
|
68
|
-
}
|
|
69
|
-
declare class RPCHandler<T extends Context> extends MessagePortHandler<T> {
|
|
70
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { MessagePortHandler, RPCHandler };
|
|
74
|
-
export type { MessagePortHandlerOptions, RPCHandlerOptions };
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { onMessagePortMessage, onMessagePortClose, postMessagePortMessage } from '@orpc/client/message-port';
|
|
2
|
-
import { value, isPlainObject, resolveMaybeOptionalOptions, toStringOrBytes } from '@orpc/shared';
|
|
3
|
-
import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@standardserver/peer';
|
|
4
|
-
import { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
|
|
5
|
-
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.GDpX6Df8.mjs';
|
|
6
|
-
import '@orpc/client';
|
|
7
|
-
import '@standardserver/core';
|
|
8
|
-
import '../../shared/server.CrlKQucM.mjs';
|
|
9
|
-
import '@orpc/contract';
|
|
10
|
-
import '../../shared/server.BwHnWUuN.mjs';
|
|
11
|
-
|
|
12
|
-
class MessagePortHandler {
|
|
13
|
-
constructor(handler, options = {}) {
|
|
14
|
-
this.handler = handler;
|
|
15
|
-
this.transfer = options.experimental_transfer;
|
|
16
|
-
this.encodePeerMessageOptions = options.encodePeerMessage;
|
|
17
|
-
this.decodePeerMessageOptions = options.decodePeerMessage;
|
|
18
|
-
}
|
|
19
|
-
peers = /* @__PURE__ */ new WeakMap();
|
|
20
|
-
transfer;
|
|
21
|
-
encodePeerMessageOptions;
|
|
22
|
-
decodePeerMessageOptions;
|
|
23
|
-
/**
|
|
24
|
-
* Attaches necessary event listeners to a message port to handle incoming messages and peer management.
|
|
25
|
-
*/
|
|
26
|
-
upgrade(port, ...rest) {
|
|
27
|
-
onMessagePortMessage(port, (message) => this.message(port, message, ...rest));
|
|
28
|
-
onMessagePortClose(port, () => this.close(port));
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Handles a single message received from a message port.
|
|
32
|
-
*
|
|
33
|
-
* @warning AVOID calling this method directly if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
34
|
-
*
|
|
35
|
-
* @param port The message port instance, require consistent instance across messages for proper peer management
|
|
36
|
-
*/
|
|
37
|
-
async message(port, data, ...rest) {
|
|
38
|
-
let peer = this.peers.get(port);
|
|
39
|
-
if (!peer) {
|
|
40
|
-
this.peers.set(port, peer = new ServerPeer(async (message2) => {
|
|
41
|
-
const transfer = await value(this.transfer, message2, port);
|
|
42
|
-
if (transfer) {
|
|
43
|
-
postMessagePortMessage(port, message2, transfer);
|
|
44
|
-
} else {
|
|
45
|
-
postMessagePortMessage(port, await encodePeerMessage(message2, this.encodePeerMessageOptions));
|
|
46
|
-
}
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
if (isPlainObject(data)) {
|
|
50
|
-
await peer.message(
|
|
51
|
-
data,
|
|
52
|
-
createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
|
|
53
|
-
);
|
|
54
|
-
return { matched: true };
|
|
55
|
-
}
|
|
56
|
-
const message = await toStringOrBytes(data);
|
|
57
|
-
const result = decodePeerMessage(message, this.decodePeerMessageOptions);
|
|
58
|
-
if (result.matched && isClientPeerSendMessage(result.message)) {
|
|
59
|
-
await peer.message(
|
|
60
|
-
result.message,
|
|
61
|
-
createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Called when a message port is closed, to clean up any associated peer state.
|
|
68
|
-
*
|
|
69
|
-
* @warning AVOID calling this method directly if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
70
|
-
*
|
|
71
|
-
* @param port The message port instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
72
|
-
*/
|
|
73
|
-
async close(port) {
|
|
74
|
-
const peer = this.peers.get(port);
|
|
75
|
-
if (peer) {
|
|
76
|
-
await peer.close();
|
|
77
|
-
this.peers.delete(port);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
class RPCHandler extends MessagePortHandler {
|
|
83
|
-
constructor(router, options = {}) {
|
|
84
|
-
const codec = new RPCHandlerCodec(router, options);
|
|
85
|
-
const handler = new StandardHandler(codec, options);
|
|
86
|
-
super(handler, options);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export { MessagePortHandler, RPCHandler };
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@standardserver/node';
|
|
2
|
-
import { C as Context } from '../../shared/server.BL22TloH.mjs';
|
|
3
|
-
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
4
|
-
import { e as StandardHandlerPlugin, b as StandardHandlerHandleOptions, S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DJIkub_t.mjs';
|
|
5
|
-
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
|
|
6
|
-
import compression from '@orpc/interop/compression';
|
|
7
|
-
import { R as Router } from '../../shared/server.BsNNjG5J.mjs';
|
|
8
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.Cj5lgPuG.mjs';
|
|
9
|
-
import '@orpc/client';
|
|
10
|
-
import '@orpc/contract';
|
|
11
|
-
import '@standardserver/core';
|
|
12
|
-
|
|
13
|
-
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
14
|
-
/**
|
|
15
|
-
* Initializes the plugin and returns new node HTTP handler options.
|
|
16
|
-
* Called once per plugin instance during composition.
|
|
17
|
-
*
|
|
18
|
-
* This method allows plugins to wrap, extend, or transform node HTTP handler options
|
|
19
|
-
* such as interceptors, or other configuration.
|
|
20
|
-
*
|
|
21
|
-
* @param options - The current handler options from previous plugins or base configuration
|
|
22
|
-
* @returns Transformed handler options with plugin's modifications applied
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* initNodeHttpHandlerOptions(options) {
|
|
27
|
-
* return {
|
|
28
|
-
* ...options,
|
|
29
|
-
* nodeHttpInterceptors: [...(options.nodeHttpInterceptors || []), myInterceptor]
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
initNodeHttpHandlerOptions?(options: NodeHttpHandlerOptions<T>): NodeHttpHandlerOptions<T>;
|
|
35
|
-
}
|
|
36
|
-
declare class CompositeNodeHttpHandlerPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
|
37
|
-
readonly name = "~composite/node-http-handler";
|
|
38
|
-
protected readonly plugins: NodeHttpHandlerPlugin<T>[];
|
|
39
|
-
constructor(plugins?: NodeHttpHandlerPlugin<T>[]);
|
|
40
|
-
initNodeHttpHandlerOptions(options: NodeHttpHandlerOptions<T>): NodeHttpHandlerOptions<T>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type NodeHttpHandlerHandleResult = {
|
|
44
|
-
matched: true;
|
|
45
|
-
} | {
|
|
46
|
-
matched: false;
|
|
47
|
-
};
|
|
48
|
-
interface NodeHttpHandlerNodeHttpInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
|
|
49
|
-
request: NodeHttpRequest;
|
|
50
|
-
response: NodeHttpResponse;
|
|
51
|
-
sendStandardResponseOptions: SendStandardResponseOptions | undefined;
|
|
52
|
-
}
|
|
53
|
-
type NodeHttpHandlerNodeHttpInterceptor<T extends Context> = Interceptor<NodeHttpHandlerNodeHttpInterceptorOptions<T>, Promise<NodeHttpHandlerHandleResult>>;
|
|
54
|
-
interface NodeHttpHandlerOptions<T extends Context> {
|
|
55
|
-
/**
|
|
56
|
-
* Custom options for `sendStandardResponse`, used to send a `Standard Response`
|
|
57
|
-
*/
|
|
58
|
-
sendStandardResponse?: SendStandardResponseOptions | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* Interceptors that run before the mapping between the Standard API and Node HTTP API,
|
|
61
|
-
* useful for extending Node HTTP request/response before handling, ...
|
|
62
|
-
*/
|
|
63
|
-
nodeHttpInterceptors?: NodeHttpHandlerNodeHttpInterceptor<T>[] | undefined;
|
|
64
|
-
plugins?: NodeHttpHandlerPlugin<T>[] | undefined;
|
|
65
|
-
}
|
|
66
|
-
declare class NodeHttpHandler<T extends Context> {
|
|
67
|
-
private readonly standardHandler;
|
|
68
|
-
private readonly sendStandardResponseOptions;
|
|
69
|
-
private readonly nodeHttpInterceptors;
|
|
70
|
-
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<NodeHttpHandlerOptions<T>>);
|
|
71
|
-
handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<NodeHttpHandlerHandleResult>;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
interface BodyCompressionHandlerPluginOptions extends compression.CompressionOptions {
|
|
75
|
-
/**
|
|
76
|
-
* Override the default content-type filter used to determine which responses should be compressed.
|
|
77
|
-
*
|
|
78
|
-
* @warning Event stream responses are never compressed, regardless of this filter's return value.
|
|
79
|
-
* @default only responses with compressible content types are compressed.
|
|
80
|
-
*/
|
|
81
|
-
filter?: (request: NodeHttpRequest, response: NodeHttpResponse) => boolean;
|
|
82
|
-
}
|
|
83
|
-
declare class BodyCompressionHandlerPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
|
84
|
-
name: string;
|
|
85
|
-
private readonly compressionHandler;
|
|
86
|
-
constructor(options?: BodyCompressionHandlerPluginOptions);
|
|
87
|
-
initNodeHttpHandlerOptions(options: NodeHttpHandlerOptions<T>): NodeHttpHandlerOptions<T>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interface BodyLimitHandlerPluginOptions {
|
|
91
|
-
/**
|
|
92
|
-
* The maximum size of the body in bytes.
|
|
93
|
-
*/
|
|
94
|
-
maxBodySize: number;
|
|
95
|
-
}
|
|
96
|
-
declare class BodyLimitHandlerPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
|
97
|
-
name: string;
|
|
98
|
-
private readonly maxBodySize;
|
|
99
|
-
constructor(options: BodyLimitHandlerPluginOptions);
|
|
100
|
-
initNodeHttpHandlerOptions(options: NodeHttpHandlerOptions<T>): NodeHttpHandlerOptions<T>;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
interface RPCHandlerOptions<T extends Context> extends NodeHttpHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
|
|
104
|
-
/**
|
|
105
|
-
* Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
|
|
106
|
-
*/
|
|
107
|
-
csrfGuardPlugin?: {
|
|
108
|
-
/**
|
|
109
|
-
* If `false`, this plugin is disabled.
|
|
110
|
-
*
|
|
111
|
-
* @default true
|
|
112
|
-
*/
|
|
113
|
-
enabled?: boolean;
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
|
117
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { BodyCompressionHandlerPlugin, BodyLimitHandlerPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
|
|
121
|
-
export type { BodyCompressionHandlerPluginOptions, BodyLimitHandlerPluginOptions, NodeHttpHandlerHandleResult, NodeHttpHandlerNodeHttpInterceptor, NodeHttpHandlerNodeHttpInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin, RPCHandlerOptions };
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import compression from '@orpc/interop/compression';
|
|
2
|
-
import { toArray, sortPlugins, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
-
import { ORPCError } from '@orpc/client';
|
|
4
|
-
import { toStandardLazyRequest, sendStandardResponse } from '@standardserver/node';
|
|
5
|
-
import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
|
|
6
|
-
import { C as CSRFGuardHandlerPlugin } from '../../shared/server.D_QauotT.mjs';
|
|
7
|
-
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.GDpX6Df8.mjs';
|
|
8
|
-
import '@standardserver/core';
|
|
9
|
-
import '../../shared/server.CrlKQucM.mjs';
|
|
10
|
-
import '@orpc/contract';
|
|
11
|
-
import '../../shared/server.BwHnWUuN.mjs';
|
|
12
|
-
|
|
13
|
-
class BodyCompressionHandlerPlugin {
|
|
14
|
-
name = "~body-compression";
|
|
15
|
-
compressionHandler;
|
|
16
|
-
constructor(options = {}) {
|
|
17
|
-
this.compressionHandler = compression({
|
|
18
|
-
...options,
|
|
19
|
-
filter: (request, response) => {
|
|
20
|
-
const hasContentDisposition = response.hasHeader("content-disposition");
|
|
21
|
-
const contentType = response.getHeader("content-type")?.toString();
|
|
22
|
-
if (!hasContentDisposition && contentType?.startsWith("text/event-stream")) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
return options.filter ? options.filter(request, response) : compression.filter(request, response);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
initNodeHttpHandlerOptions(options) {
|
|
30
|
-
return {
|
|
31
|
-
...options,
|
|
32
|
-
nodeHttpInterceptors: [
|
|
33
|
-
async (interceptorOptions) => {
|
|
34
|
-
let resolve;
|
|
35
|
-
let reject;
|
|
36
|
-
const promise = new Promise((res, rej) => {
|
|
37
|
-
resolve = res;
|
|
38
|
-
reject = rej;
|
|
39
|
-
});
|
|
40
|
-
const originalWrite = interceptorOptions.response.write;
|
|
41
|
-
const originalEnd = interceptorOptions.response.end;
|
|
42
|
-
const originalOn = interceptorOptions.response.on;
|
|
43
|
-
this.compressionHandler(
|
|
44
|
-
interceptorOptions.request,
|
|
45
|
-
interceptorOptions.response,
|
|
46
|
-
async (error) => {
|
|
47
|
-
if (error) {
|
|
48
|
-
reject(error);
|
|
49
|
-
} else {
|
|
50
|
-
try {
|
|
51
|
-
resolve(await interceptorOptions.next(interceptorOptions));
|
|
52
|
-
} catch (nextError) {
|
|
53
|
-
reject(nextError);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
try {
|
|
59
|
-
return await promise;
|
|
60
|
-
} finally {
|
|
61
|
-
interceptorOptions.response.write = originalWrite;
|
|
62
|
-
interceptorOptions.response.end = originalEnd;
|
|
63
|
-
interceptorOptions.response.on = originalOn;
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
...toArray(options.nodeHttpInterceptors)
|
|
67
|
-
]
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
class BodyLimitHandlerPlugin {
|
|
73
|
-
name = "~body-limit";
|
|
74
|
-
maxBodySize;
|
|
75
|
-
constructor(options) {
|
|
76
|
-
this.maxBodySize = options.maxBodySize;
|
|
77
|
-
}
|
|
78
|
-
initNodeHttpHandlerOptions(options) {
|
|
79
|
-
return {
|
|
80
|
-
...options,
|
|
81
|
-
nodeHttpInterceptors: [
|
|
82
|
-
async (interceptorOptions) => {
|
|
83
|
-
let isHeaderChecked = false;
|
|
84
|
-
const checkHeader = () => {
|
|
85
|
-
if (isHeaderChecked) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
isHeaderChecked = true;
|
|
89
|
-
const contentLength = interceptorOptions.request.headers["content-length"];
|
|
90
|
-
if (contentLength && Number(contentLength) > this.maxBodySize) {
|
|
91
|
-
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const originalEmit = interceptorOptions.request.emit;
|
|
95
|
-
let currentBodySize = 0;
|
|
96
|
-
interceptorOptions.request.emit = (event, ...args) => {
|
|
97
|
-
if (event === "data") {
|
|
98
|
-
checkHeader();
|
|
99
|
-
currentBodySize += args[0]?.length ?? 0;
|
|
100
|
-
if (currentBodySize > this.maxBodySize) {
|
|
101
|
-
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return originalEmit.call(interceptorOptions.request, event, ...args);
|
|
105
|
-
};
|
|
106
|
-
try {
|
|
107
|
-
return await interceptorOptions.next(interceptorOptions);
|
|
108
|
-
} finally {
|
|
109
|
-
interceptorOptions.request.emit = originalEmit;
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
...toArray(options.nodeHttpInterceptors)
|
|
113
|
-
]
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
class CompositeNodeHttpHandlerPlugin {
|
|
119
|
-
name = "~composite/node-http-handler";
|
|
120
|
-
plugins;
|
|
121
|
-
constructor(plugins = []) {
|
|
122
|
-
this.plugins = sortPlugins(plugins);
|
|
123
|
-
}
|
|
124
|
-
initNodeHttpHandlerOptions(options) {
|
|
125
|
-
for (const plugin of this.plugins) {
|
|
126
|
-
if (plugin.initNodeHttpHandlerOptions) {
|
|
127
|
-
options = plugin.initNodeHttpHandlerOptions(options);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return options;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
class NodeHttpHandler {
|
|
135
|
-
constructor(standardHandler, options = {}) {
|
|
136
|
-
this.standardHandler = standardHandler;
|
|
137
|
-
options = new CompositeNodeHttpHandlerPlugin(options.plugins).initNodeHttpHandlerOptions(options);
|
|
138
|
-
this.nodeHttpInterceptors = options.nodeHttpInterceptors;
|
|
139
|
-
this.sendStandardResponseOptions = options.sendStandardResponse;
|
|
140
|
-
}
|
|
141
|
-
sendStandardResponseOptions;
|
|
142
|
-
nodeHttpInterceptors;
|
|
143
|
-
async handle(request, response, ...rest) {
|
|
144
|
-
return intercept(
|
|
145
|
-
this.nodeHttpInterceptors,
|
|
146
|
-
{
|
|
147
|
-
...resolveFriendlyStandardHandlerHandleOptions(resolveMaybeOptionalOptions(rest)),
|
|
148
|
-
request,
|
|
149
|
-
response,
|
|
150
|
-
sendStandardResponseOptions: this.sendStandardResponseOptions
|
|
151
|
-
},
|
|
152
|
-
async ({ request: request2, response: response2, sendStandardResponseOptions, ...options }) => {
|
|
153
|
-
const standardRequest = toStandardLazyRequest(request2, response2);
|
|
154
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
|
155
|
-
if (!result.matched) {
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
|
-
await sendStandardResponse(response2, result.response, sendStandardResponseOptions);
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
class RPCHandler extends NodeHttpHandler {
|
|
166
|
-
constructor(router, options = {}) {
|
|
167
|
-
if (options.csrfGuardPlugin?.enabled !== false) {
|
|
168
|
-
options = {
|
|
169
|
-
...options,
|
|
170
|
-
plugins: [...toArray(options.plugins), new CSRFGuardHandlerPlugin()]
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
const codec = new RPCHandlerCodec(router, options);
|
|
174
|
-
const handler = new StandardHandler(codec, options);
|
|
175
|
-
super(handler, options);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export { BodyCompressionHandlerPlugin, BodyLimitHandlerPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
|