@orpc/server 2.0.0-beta.49 → 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/dist/adapters/aws-lambda/handler.d.ts +17 -15
- package/dist/adapters/aws-lambda/handler.js +23 -23
- package/dist/adapters/aws-lambda/index.d.ts +4 -16
- package/dist/adapters/aws-lambda/index.js +2 -2
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +9 -9
- package/dist/adapters/aws-lambda/rpc-handler.js +20 -17
- package/dist/adapters/crossws/handler.d.ts +44 -42
- package/dist/adapters/crossws/handler.js +53 -60
- package/dist/adapters/crossws/index.d.ts +3 -2
- package/dist/adapters/crossws/index.js +2 -2
- package/dist/adapters/crossws/rpc-handler.d.ts +10 -10
- package/dist/adapters/crossws/rpc-handler.js +17 -14
- package/dist/adapters/fastify/handler.d.ts +17 -15
- package/dist/adapters/fastify/handler.js +20 -20
- package/dist/adapters/fastify/index.d.ts +3 -2
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/fastify/rpc-handler.d.ts +9 -9
- package/dist/adapters/fastify/rpc-handler.js +16 -13
- package/dist/adapters/fetch/handler.d.ts +19 -17
- package/dist/adapters/fetch/handler.js +22 -22
- package/dist/adapters/fetch/index.d.ts +4 -7
- package/dist/adapters/fetch/index.js +3 -7
- package/dist/adapters/fetch/rpc-handler.d.ts +9 -9
- package/dist/adapters/fetch/rpc-handler.js +18 -15
- package/dist/adapters/message-port/handler.d.ts +58 -60
- package/dist/adapters/message-port/handler.js +72 -86
- package/dist/adapters/message-port/index.d.ts +3 -2
- package/dist/adapters/message-port/index.js +2 -2
- package/dist/adapters/message-port/rpc-handler.d.ts +9 -9
- package/dist/adapters/message-port/rpc-handler.js +17 -14
- package/dist/adapters/node/handler.d.ts +17 -15
- package/dist/adapters/node/handler.js +20 -20
- package/dist/adapters/node/index.d.ts +4 -7
- package/dist/adapters/node/index.js +3 -7
- package/dist/adapters/node/rpc-handler.d.ts +9 -9
- package/dist/adapters/node/rpc-handler.js +17 -14
- package/dist/adapters/standard/codec.d.ts +13 -13
- package/dist/adapters/standard/handler.d.ts +49 -49
- package/dist/adapters/standard/handler.js +205 -205
- package/dist/adapters/standard/index.d.ts +7 -6
- package/dist/adapters/standard/index.js +4 -5
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-handler-codec.d.ts +39 -43
- package/dist/adapters/standard/rpc-handler-codec.js +50 -51
- package/dist/adapters/standard/rpc-matcher.d.ts +40 -40
- package/dist/adapters/standard/rpc-matcher.js +103 -149
- package/dist/adapters/standard/utils.d.ts +8 -8
- package/dist/adapters/standard/utils.js +7 -5
- package/dist/adapters/standard-peer/index.d.ts +2 -1
- package/dist/adapters/standard-peer/index.js +1 -1
- package/dist/adapters/standard-peer/utils.d.ts +6 -4
- package/dist/adapters/standard-peer/utils.js +12 -6
- package/dist/adapters/websocket/handler.d.ts +52 -50
- package/dist/adapters/websocket/handler.js +75 -85
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-handler.d.ts +9 -9
- package/dist/adapters/websocket/rpc-handler.js +17 -14
- package/dist/builder-variants.d.ts +195 -195
- package/dist/builder.d.ts +103 -104
- package/dist/builder.js +198 -224
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +4 -2
- package/dist/context.d.ts +3 -3
- package/dist/extensions/callable.d.ts +11 -11
- package/dist/extensions/callable.js +6 -5
- package/dist/helpers/base64url.d.ts +1 -1
- package/dist/helpers/base64url.js +44 -49
- package/dist/helpers/cookie.d.ts +10 -11
- package/dist/helpers/cookie.js +56 -63
- package/dist/helpers/encryption.d.ts +1 -1
- package/dist/helpers/encryption.js +80 -70
- package/dist/helpers/index.d.ts +5 -4
- package/dist/helpers/index.js +4 -4
- package/dist/helpers/signing.d.ts +1 -1
- package/dist/helpers/signing.js +72 -82
- package/dist/implementer-procedure.d.ts +12 -13
- package/dist/implementer-procedure.js +37 -44
- package/dist/implementer-router.d.ts +30 -36
- package/dist/implementer-router.js +92 -111
- package/dist/implementer.d.ts +8 -8
- package/dist/implementer.js +28 -35
- package/dist/index.d.ts +22 -61
- package/dist/index.js +16 -48
- package/dist/lazy.d.ts +14 -14
- package/dist/lazy.js +19 -30
- package/dist/middleware-decorated.d.ts +8 -9
- package/dist/middleware-decorated.js +66 -70
- package/dist/middleware.d.ts +34 -34
- package/dist/plugins/batch.d.ts +75 -75
- package/dist/plugins/batch.js +345 -379
- package/dist/plugins/cors.d.ts +60 -64
- package/dist/plugins/cors.js +118 -111
- package/dist/plugins/get-method-csrf-protection.d.ts +8 -6
- package/dist/plugins/get-method-csrf-protection.js +47 -63
- package/dist/plugins/head-method.d.ts +11 -9
- package/dist/plugins/head-method.js +97 -94
- package/dist/plugins/index.d.ts +15 -39
- package/dist/plugins/index.js +14 -29
- package/dist/plugins/method-override.d.ts +30 -28
- package/dist/plugins/method-override.js +53 -49
- package/dist/plugins/request-compression.d.ts +11 -9
- package/dist/plugins/request-compression.js +52 -79
- package/dist/plugins/request-headers.d.ts +10 -8
- package/dist/plugins/request-headers.js +27 -29
- package/dist/plugins/request-limit.d.ts +21 -19
- package/dist/plugins/request-limit.js +60 -67
- package/dist/plugins/response-compression.d.ts +42 -39
- package/dist/plugins/response-compression.js +150 -202
- package/dist/plugins/response-headers.d.ts +15 -13
- package/dist/plugins/response-headers.js +43 -46
- package/dist/plugins/rethrow.d.ts +25 -23
- package/dist/plugins/rethrow.js +46 -58
- package/dist/plugins/signal-sync.d.ts +7 -5
- package/dist/plugins/signal-sync.js +71 -86
- package/dist/plugins/timeout.d.ts +29 -27
- package/dist/plugins/timeout.js +61 -58
- package/dist/procedure-client.d.ts +14 -15
- package/dist/procedure-client.js +149 -166
- package/dist/procedure-decorated.d.ts +9 -9
- package/dist/procedure-decorated.js +36 -44
- package/dist/procedure-utils.d.ts +10 -30
- package/dist/procedure-utils.js +39 -40
- package/dist/procedure.d.ts +60 -60
- package/dist/procedure.js +18 -24
- package/dist/router-client.d.ts +9 -11
- package/dist/router-client.js +33 -41
- package/dist/router-hidden.js +10 -12
- package/dist/router-utils.d.ts +13 -30
- package/dist/router-utils.js +146 -191
- package/dist/router.d.ts +12 -26
- package/package.json +10 -10
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/builder-variants.js +0 -1
- package/dist/context.js +0 -1
- package/dist/middleware.js +0 -1
- package/dist/router-hidden.d.ts +0 -5
- package/dist/router.js +0 -1
|
@@ -1,104 +1,107 @@
|
|
|
1
|
-
import { isAsyncIteratorObject, toArray } from
|
|
2
|
-
import { cancelStandardBody, getRequiredStandardBodyHint } from
|
|
3
|
-
import { toFetchBody } from
|
|
1
|
+
import { isAsyncIteratorObject, toArray } from "@orpc/shared";
|
|
2
|
+
import { cancelStandardBody, getRequiredStandardBodyHint } from "@standard-server/core";
|
|
3
|
+
import { toFetchBody } from "@standard-server/fetch";
|
|
4
|
+
// src/plugins/head-method.ts
|
|
4
5
|
const textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
],
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
7
|
+
* Answers `HEAD` requests with the headers of the matching `GET` procedure, like Fastify's
|
|
8
|
+
* `exposeHeadRoutes`, so clients can check a resource's existence, type, and size without
|
|
9
|
+
* downloading it. A procedure routed as `HEAD` itself takes precedence over the `GET` one.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* - `HEAD` responses never carry a body: the plugin discards it, cancelling streams and
|
|
13
|
+
* event iterators, and keeps the headers it implies, such as `Content-Type`, and
|
|
14
|
+
* `Content-Length` when its size is known up front.
|
|
15
|
+
* - `GET` procedures still need to be reachable, so with `RPCHandler`, `GET` must be in `allowMethods`.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://orpc.dev/docs/plugins/head-method | HEAD Method Plugin}
|
|
18
|
+
*/
|
|
19
|
+
var HeadMethodHandlerPlugin = class {
|
|
20
|
+
name = "~head-method";
|
|
21
|
+
/**
|
|
22
|
+
* Discard the body after response compression, so `HEAD` reports the same `Content-Encoding` as `GET`.
|
|
23
|
+
*/
|
|
24
|
+
after = ["~response-compression"];
|
|
25
|
+
init(options) {
|
|
26
|
+
const bodyInterceptor = async ({ next, request }) => {
|
|
27
|
+
if (request.method !== "HEAD") return next();
|
|
28
|
+
const result = await next();
|
|
29
|
+
if (!result.matched) return result;
|
|
30
|
+
return {
|
|
31
|
+
...result,
|
|
32
|
+
response: toHeadResponse(result.response)
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Placed last, so falling back to `GET` repeats routing rather than the routing interceptors before this one.
|
|
37
|
+
*/
|
|
38
|
+
const fallbackInterceptor = async (interceptorOptions) => {
|
|
39
|
+
const { next, request } = interceptorOptions;
|
|
40
|
+
if (request.method !== "HEAD") return next();
|
|
41
|
+
const result = await next();
|
|
42
|
+
if (result.matched) return result;
|
|
43
|
+
return next({
|
|
44
|
+
...interceptorOptions,
|
|
45
|
+
request: {
|
|
46
|
+
...request,
|
|
47
|
+
method: "GET"
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
...options,
|
|
53
|
+
routingInterceptors: [
|
|
54
|
+
bodyInterceptor,
|
|
55
|
+
...toArray(options.routingInterceptors),
|
|
56
|
+
fallbackInterceptor
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
64
61
|
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
* Replaces the body with an empty stream, keeping the headers adapters derive from it.
|
|
63
|
+
* An empty stream rather than no body, because adapters drop `Content-Type` and `Content-Length` when the body is `undefined`,
|
|
64
|
+
* and an empty `Standard-Server` hint rather than none, so they do not hint the stream as `octet-stream`.
|
|
65
|
+
*/
|
|
69
66
|
function toHeadResponse(response) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
67
|
+
const { body } = response;
|
|
68
|
+
if (body === void 0) return response;
|
|
69
|
+
if (isAsyncIteratorObject(body)) {
|
|
70
|
+
discardBody(body);
|
|
71
|
+
const headers = {
|
|
72
|
+
...response.headers,
|
|
73
|
+
"content-length": void 0
|
|
74
|
+
};
|
|
75
|
+
headers["content-type"] ??= "text/event-stream";
|
|
76
|
+
headers["standard-server"] = getRequiredStandardBodyHint("event-stream", headers) ?? [];
|
|
77
|
+
return {
|
|
78
|
+
...response,
|
|
79
|
+
headers,
|
|
80
|
+
body: createEmptyStream()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const [encoded, headers] = toFetchBody(body, response.headers);
|
|
84
|
+
if (encoded instanceof ReadableStream) discardBody(encoded);
|
|
85
|
+
else if (encoded instanceof FormData) {
|
|
86
|
+
headers["standard-server"] = [];
|
|
87
|
+
headers["content-type"] = new Response(encoded).headers.get("content-type");
|
|
88
|
+
} else if (typeof encoded === "string" || encoded instanceof URLSearchParams) {
|
|
89
|
+
headers["standard-server"] ??= [];
|
|
90
|
+
headers["content-length"] = textEncoder.encode(encoded.toString()).byteLength.toString();
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...response,
|
|
94
|
+
headers,
|
|
95
|
+
body: createEmptyStream()
|
|
96
|
+
};
|
|
95
97
|
}
|
|
96
98
|
function createEmptyStream() {
|
|
97
|
-
|
|
99
|
+
return new ReadableStream({ start: (controller) => controller.close() });
|
|
98
100
|
}
|
|
99
101
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
* Nothing reads the body anymore, so a failure to cancel it has nowhere to go.
|
|
103
|
+
*/
|
|
102
104
|
function discardBody(body) {
|
|
103
|
-
|
|
105
|
+
cancelStandardBody(body).catch(() => {});
|
|
104
106
|
}
|
|
107
|
+
export { HeadMethodHandlerPlugin };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,39 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
RequestHeadersHandlerPlugin as RequestHeadersPlugin, } from './request-headers.ts';
|
|
18
|
-
export type {
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Use `RequestHeadersHandlerPluginContext` instead.
|
|
21
|
-
*/
|
|
22
|
-
RequestHeadersHandlerPluginContext as RequestHeadersPluginContext, } from './request-headers.ts';
|
|
23
|
-
export * from './request-limit.ts';
|
|
24
|
-
export * from './response-compression.ts';
|
|
25
|
-
export * from './response-headers.ts';
|
|
26
|
-
export {
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated Use `ResponseHeadersHandlerPlugin` instead.
|
|
29
|
-
*/
|
|
30
|
-
ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, } from './response-headers.ts';
|
|
31
|
-
export type {
|
|
32
|
-
/**
|
|
33
|
-
* @deprecated Use `ResponseHeadersHandlerPluginContext` instead.
|
|
34
|
-
*/
|
|
35
|
-
ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext, } from './response-headers.ts';
|
|
36
|
-
export * from './rethrow.ts';
|
|
37
|
-
export * from './signal-sync.ts';
|
|
38
|
-
export * from './timeout.ts';
|
|
39
|
-
export { BATCH_HEADER, DEFAULT_BATCH_MAX_SIZE } from '@orpc/client/plugins';
|
|
1
|
+
import { BATCH_CONTENT_TYPE, BatchHandlerPlugin, BatchHandlerPluginOptions } from "./batch.js";
|
|
2
|
+
import { CORSHandlerPlugin, CORSHandlerPluginOptions } from "./cors.js";
|
|
3
|
+
import { GetMethodCsrfProtectionHandlerPlugin } from "./get-method-csrf-protection.js";
|
|
4
|
+
import { HeadMethodHandlerPlugin } from "./head-method.js";
|
|
5
|
+
import { MethodOverrideHandlerPlugin, MethodOverrideHandlerPluginOptions } from "./method-override.js";
|
|
6
|
+
import { RequestCompressionHandlerPlugin } from "./request-compression.js";
|
|
7
|
+
import { RequestHeadersHandlerPlugin, RequestHeadersHandlerPluginContext } from "./request-headers.js";
|
|
8
|
+
import { RequestLimitHandlerPlugin, RequestLimitHandlerPluginOptions } from "./request-limit.js";
|
|
9
|
+
import { ResponseCompressionHandlerPlugin, ResponseCompressionHandlerPluginOptions, negotiateResponseCompressionEncoding, toCompressedHeaders } from "./response-compression.js";
|
|
10
|
+
import { ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPluginContext } from "./response-headers.js";
|
|
11
|
+
import { RethrowHandlerPlugin, RethrowHandlerPluginOptions } from "./rethrow.js";
|
|
12
|
+
import { SignalSyncHandlerPlugin } from "./signal-sync.js";
|
|
13
|
+
import { TimeoutHandlerPlugin, TimeoutHandlerPluginOptions } from "./timeout.js";
|
|
14
|
+
import { BATCH_HEADER, DEFAULT_BATCH_MAX_SIZE } from "@orpc/client/plugins";
|
|
15
|
+
export { BATCH_CONTENT_TYPE, BATCH_HEADER, BatchHandlerPlugin, BatchHandlerPluginOptions, CORSHandlerPlugin, CORSHandlerPluginOptions, CORSHandlerPlugin as CORSPlugin, DEFAULT_BATCH_MAX_SIZE, GetMethodCsrfProtectionHandlerPlugin, HeadMethodHandlerPlugin, MethodOverrideHandlerPlugin, MethodOverrideHandlerPluginOptions, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPluginContext, RequestHeadersHandlerPlugin as RequestHeadersPlugin, type RequestHeadersHandlerPluginContext as RequestHeadersPluginContext, RequestLimitHandlerPlugin, RequestLimitHandlerPluginOptions, ResponseCompressionHandlerPlugin, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPluginContext, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, type ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext, RethrowHandlerPlugin, RethrowHandlerPluginOptions, SignalSyncHandlerPlugin, TimeoutHandlerPlugin, TimeoutHandlerPluginOptions, negotiateResponseCompressionEncoding, toCompressedHeaders };
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
* @deprecated Use `RequestHeadersHandlerPlugin` instead.
|
|
16
|
-
*/
|
|
17
|
-
RequestHeadersHandlerPlugin as RequestHeadersPlugin, } from './request-headers.js';
|
|
18
|
-
export * from './request-limit.js';
|
|
19
|
-
export * from './response-compression.js';
|
|
20
|
-
export * from './response-headers.js';
|
|
21
|
-
export {
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated Use `ResponseHeadersHandlerPlugin` instead.
|
|
24
|
-
*/
|
|
25
|
-
ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, } from './response-headers.js';
|
|
26
|
-
export * from './rethrow.js';
|
|
27
|
-
export * from './signal-sync.js';
|
|
28
|
-
export * from './timeout.js';
|
|
29
|
-
export { BATCH_HEADER, DEFAULT_BATCH_MAX_SIZE } from '@orpc/client/plugins';
|
|
1
|
+
export { BATCH_CONTENT_TYPE, BatchHandlerPlugin } from "./batch.js";
|
|
2
|
+
export { CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin } from "./cors.js";
|
|
3
|
+
export { GetMethodCsrfProtectionHandlerPlugin } from "./get-method-csrf-protection.js";
|
|
4
|
+
export { HeadMethodHandlerPlugin } from "./head-method.js";
|
|
5
|
+
export { MethodOverrideHandlerPlugin } from "./method-override.js";
|
|
6
|
+
export { RequestCompressionHandlerPlugin } from "./request-compression.js";
|
|
7
|
+
export { RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin } from "./request-headers.js";
|
|
8
|
+
export { RequestLimitHandlerPlugin } from "./request-limit.js";
|
|
9
|
+
export { ResponseCompressionHandlerPlugin, negotiateResponseCompressionEncoding, toCompressedHeaders } from "./response-compression.js";
|
|
10
|
+
export { ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin } from "./response-headers.js";
|
|
11
|
+
export { RethrowHandlerPlugin } from "./rethrow.js";
|
|
12
|
+
export { SignalSyncHandlerPlugin } from "./signal-sync.js";
|
|
13
|
+
export { TimeoutHandlerPlugin } from "./timeout.js";
|
|
14
|
+
export { BATCH_HEADER, DEFAULT_BATCH_MAX_SIZE } from "@orpc/client/plugins";
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import "../adapters/standard/index.js";
|
|
2
|
+
import { StandardHandlerPlugin } from "../adapters/standard/plugin.js";
|
|
3
|
+
import { StandardHandlerOptions } from "../adapters/standard/handler.js";
|
|
4
|
+
import { Context } from "../context.js";
|
|
5
|
+
import { StandardMethod } from "@standard-server/core";
|
|
4
6
|
export interface MethodOverrideHandlerPluginOptions {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The query parameter carrying the override method.
|
|
9
|
+
*
|
|
10
|
+
* @default 'method'
|
|
11
|
+
*/
|
|
12
|
+
param?: string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The methods a POST request may be overridden to.
|
|
15
|
+
*
|
|
16
|
+
* GET and HEAD are excluded by default because they switch input decoding
|
|
17
|
+
* from the request body to the query string and widen the CSRF surface.
|
|
18
|
+
*
|
|
19
|
+
* @default ['PUT', 'PATCH', 'DELETE']
|
|
20
|
+
*/
|
|
21
|
+
methods?: readonly StandardMethod[] | undefined;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* Overrides the HTTP method of a POST request based on a query parameter,
|
|
@@ -26,13 +28,13 @@ export interface MethodOverrideHandlerPluginOptions {
|
|
|
26
28
|
* @see {@link https://orpc.dev/docs/plugins/method-override | Method Override Plugin}
|
|
27
29
|
*/
|
|
28
30
|
export declare class MethodOverrideHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
31
|
+
name: string;
|
|
32
|
+
/**
|
|
33
|
+
* Should override batch sub-request methods, not the original batch request.
|
|
34
|
+
*/
|
|
35
|
+
before: string[];
|
|
36
|
+
private readonly param;
|
|
37
|
+
private readonly methods;
|
|
38
|
+
constructor(options?: MethodOverrideHandlerPluginOptions);
|
|
39
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
40
|
+
}
|
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
import { toArray } from
|
|
2
|
-
import { parseStandardUrl } from
|
|
1
|
+
import { toArray } from "@orpc/shared";
|
|
2
|
+
import { parseStandardUrl } from "@standard-server/core";
|
|
3
|
+
// src/plugins/method-override.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
5
|
+
* Overrides the HTTP method of a POST request based on a query parameter,
|
|
6
|
+
* so HTML forms (which only support GET and POST) can invoke procedures
|
|
7
|
+
* routed as PUT, PATCH, or DELETE.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://orpc.dev/docs/plugins/method-override | Method Override Plugin}
|
|
10
|
+
*/
|
|
11
|
+
var MethodOverrideHandlerPlugin = class {
|
|
12
|
+
name = "~method-override";
|
|
13
|
+
/**
|
|
14
|
+
* Should override batch sub-request methods, not the original batch request.
|
|
15
|
+
*/
|
|
16
|
+
before = ["~batch"];
|
|
17
|
+
param;
|
|
18
|
+
methods;
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
this.param = options.param ?? "method";
|
|
21
|
+
this.methods = new Set((options.methods ?? [
|
|
22
|
+
"PUT",
|
|
23
|
+
"PATCH",
|
|
24
|
+
"DELETE"
|
|
25
|
+
]).map((method) => method.toUpperCase()));
|
|
26
|
+
}
|
|
27
|
+
init(options) {
|
|
28
|
+
const routingInterceptor = async ({ next, ...interceptorOptions }) => {
|
|
29
|
+
const { request } = interceptorOptions;
|
|
30
|
+
if (request.method !== "POST") return next();
|
|
31
|
+
const [pathname, search, hash] = parseStandardUrl(request.url);
|
|
32
|
+
const params = new URLSearchParams(search);
|
|
33
|
+
const raw = params.getAll(this.param).at(-1);
|
|
34
|
+
if (raw === void 0) return next();
|
|
35
|
+
const method = raw.toUpperCase();
|
|
36
|
+
if (!this.methods.has(method)) return next();
|
|
37
|
+
params.delete(this.param);
|
|
38
|
+
const url = `${pathname}${params.size ? `?${params}` : ""}${hash ?? ""}`;
|
|
39
|
+
return next({
|
|
40
|
+
...interceptorOptions,
|
|
41
|
+
request: {
|
|
42
|
+
...request,
|
|
43
|
+
method,
|
|
44
|
+
url
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
...options,
|
|
50
|
+
routingInterceptors: [routingInterceptor, ...toArray(options.routingInterceptors)]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export { MethodOverrideHandlerPlugin };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import "../adapters/standard/index.js";
|
|
2
|
+
import { StandardHandlerPlugin } from "../adapters/standard/plugin.js";
|
|
3
|
+
import { StandardHandlerOptions } from "../adapters/standard/handler.js";
|
|
4
|
+
import { Context } from "../context.js";
|
|
3
5
|
/**
|
|
4
6
|
* Decompresses incoming request bodies based on the Content-Encoding header,
|
|
5
7
|
* supporting gzip, deflate, and deflate-raw.
|
|
@@ -7,10 +9,10 @@ import type { Context } from '../context.ts';
|
|
|
7
9
|
* @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
|
|
8
10
|
*/
|
|
9
11
|
export declare class RequestCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Should decompress the original batch request body instead of sub-requests.
|
|
15
|
+
*/
|
|
16
|
+
after: string[];
|
|
17
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
18
|
+
}
|