@orpc/server 2.0.0-beta.48 → 2.0.0-beta.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +4 -4
  2. package/dist/adapters/aws-lambda/handler.d.ts +25 -0
  3. package/dist/adapters/aws-lambda/handler.js +24 -0
  4. package/dist/adapters/aws-lambda/index.d.ts +16 -0
  5. package/dist/adapters/aws-lambda/index.js +2 -0
  6. package/dist/adapters/aws-lambda/rpc-handler.d.ts +19 -0
  7. package/dist/adapters/aws-lambda/rpc-handler.js +18 -0
  8. package/dist/adapters/crossws/handler.d.ts +45 -0
  9. package/dist/adapters/crossws/handler.js +60 -0
  10. package/dist/adapters/crossws/index.d.ts +2 -0
  11. package/dist/adapters/crossws/index.js +2 -0
  12. package/dist/adapters/crossws/rpc-handler.d.ts +16 -0
  13. package/dist/adapters/crossws/rpc-handler.js +15 -0
  14. package/dist/adapters/fastify/handler.d.ts +21 -0
  15. package/dist/adapters/fastify/handler.js +20 -0
  16. package/dist/adapters/fastify/index.d.ts +2 -0
  17. package/dist/adapters/fastify/index.js +2 -0
  18. package/dist/adapters/fastify/rpc-handler.d.ts +15 -0
  19. package/dist/adapters/fastify/rpc-handler.js +14 -0
  20. package/dist/adapters/fetch/handler.d.ts +23 -0
  21. package/dist/adapters/fetch/handler.js +22 -0
  22. package/dist/adapters/fetch/index.d.ts +7 -0
  23. package/dist/adapters/fetch/index.js +7 -0
  24. package/dist/adapters/fetch/rpc-handler.d.ts +17 -0
  25. package/dist/adapters/fetch/rpc-handler.js +16 -0
  26. package/dist/adapters/message-port/handler.d.ts +64 -0
  27. package/dist/adapters/message-port/handler.js +86 -0
  28. package/dist/adapters/message-port/index.d.ts +2 -0
  29. package/dist/adapters/message-port/index.js +2 -0
  30. package/dist/adapters/message-port/rpc-handler.d.ts +16 -0
  31. package/dist/adapters/message-port/rpc-handler.js +15 -0
  32. package/dist/adapters/node/handler.d.ts +21 -0
  33. package/dist/adapters/node/handler.js +20 -0
  34. package/dist/adapters/node/index.d.ts +7 -0
  35. package/dist/adapters/node/index.js +7 -0
  36. package/dist/adapters/node/rpc-handler.d.ts +16 -0
  37. package/dist/adapters/node/rpc-handler.js +15 -0
  38. package/dist/adapters/standard/codec.d.ts +16 -0
  39. package/dist/adapters/standard/handler.d.ts +68 -0
  40. package/dist/adapters/standard/handler.js +205 -0
  41. package/dist/adapters/standard/index.d.ts +6 -0
  42. package/dist/adapters/standard/index.js +5 -0
  43. package/dist/adapters/standard/plugin.d.ts +32 -0
  44. package/dist/adapters/standard/plugin.js +16 -0
  45. package/dist/adapters/standard/rpc-handler-codec.d.ts +46 -0
  46. package/dist/adapters/standard/rpc-handler-codec.js +51 -0
  47. package/dist/adapters/standard/rpc-matcher.d.ts +53 -0
  48. package/dist/adapters/standard/rpc-matcher.js +152 -0
  49. package/dist/adapters/standard/utils.d.ts +10 -0
  50. package/dist/adapters/standard/utils.js +6 -0
  51. package/dist/adapters/standard-peer/index.d.ts +1 -0
  52. package/dist/adapters/standard-peer/index.js +1 -0
  53. package/dist/adapters/standard-peer/{utils.d.mts → utils.d.ts} +3 -3
  54. package/dist/adapters/standard-peer/utils.js +7 -0
  55. package/dist/adapters/websocket/handler.d.ts +59 -0
  56. package/dist/adapters/websocket/handler.js +85 -0
  57. package/dist/adapters/websocket/index.d.ts +2 -0
  58. package/dist/adapters/websocket/index.js +2 -0
  59. package/dist/adapters/websocket/rpc-handler.d.ts +16 -0
  60. package/dist/adapters/websocket/rpc-handler.js +15 -0
  61. package/dist/builder-variants.d.ts +226 -0
  62. package/dist/builder.d.ts +127 -0
  63. package/dist/builder.js +226 -0
  64. package/dist/context.d.ts +6 -0
  65. package/dist/extensions/callable.d.ts +11 -0
  66. package/dist/extensions/callable.js +7 -0
  67. package/dist/helpers/base64url.d.ts +31 -0
  68. package/dist/helpers/base64url.js +53 -0
  69. package/dist/helpers/cookie.d.ts +51 -0
  70. package/dist/helpers/cookie.js +69 -0
  71. package/dist/helpers/encryption.d.ts +28 -0
  72. package/dist/helpers/encryption.js +80 -0
  73. package/dist/helpers/index.d.ts +4 -0
  74. package/dist/helpers/index.js +4 -0
  75. package/dist/helpers/signing.d.ts +50 -0
  76. package/dist/helpers/signing.js +88 -0
  77. package/dist/implementer-procedure.d.ts +16 -0
  78. package/dist/implementer-procedure.js +44 -0
  79. package/dist/implementer-router.d.ts +40 -0
  80. package/dist/implementer-router.js +117 -0
  81. package/dist/implementer.d.ts +16 -0
  82. package/dist/implementer.js +37 -0
  83. package/dist/index.d.ts +61 -0
  84. package/dist/index.js +48 -0
  85. package/dist/lazy.d.ts +20 -0
  86. package/dist/lazy.js +31 -0
  87. package/dist/middleware-decorated.d.ts +10 -0
  88. package/dist/middleware-decorated.js +71 -0
  89. package/dist/middleware.d.ts +54 -0
  90. package/dist/plugins/batch.d.ts +102 -0
  91. package/dist/plugins/batch.js +405 -0
  92. package/dist/plugins/cors.d.ts +73 -0
  93. package/dist/plugins/cors.js +112 -0
  94. package/dist/plugins/get-method-csrf-protection.d.ts +23 -0
  95. package/dist/plugins/get-method-csrf-protection.js +64 -0
  96. package/dist/plugins/head-method.d.ts +23 -0
  97. package/dist/plugins/head-method.js +104 -0
  98. package/dist/plugins/index.d.ts +39 -0
  99. package/dist/plugins/index.js +29 -0
  100. package/dist/plugins/method-override.d.ts +38 -0
  101. package/dist/plugins/method-override.js +50 -0
  102. package/dist/plugins/request-compression.d.ts +16 -0
  103. package/dist/plugins/request-compression.js +82 -0
  104. package/dist/plugins/request-headers.d.ts +22 -0
  105. package/dist/plugins/request-headers.js +30 -0
  106. package/dist/plugins/request-limit.d.ts +30 -0
  107. package/dist/plugins/request-limit.js +68 -0
  108. package/dist/plugins/response-compression.d.ts +59 -0
  109. package/dist/plugins/response-compression.js +209 -0
  110. package/dist/plugins/response-headers.d.ts +30 -0
  111. package/dist/plugins/response-headers.js +47 -0
  112. package/dist/plugins/rethrow.d.ts +33 -0
  113. package/dist/plugins/rethrow.js +59 -0
  114. package/dist/plugins/signal-sync.d.ts +13 -0
  115. package/dist/plugins/signal-sync.js +91 -0
  116. package/dist/plugins/timeout.d.ts +37 -0
  117. package/dist/plugins/timeout.js +59 -0
  118. package/dist/procedure-client.d.ts +19 -0
  119. package/dist/procedure-client.js +175 -0
  120. package/dist/procedure-decorated.d.ts +10 -0
  121. package/dist/procedure-decorated.js +44 -0
  122. package/dist/procedure-utils.d.ts +41 -0
  123. package/dist/procedure-utils.js +49 -0
  124. package/dist/procedure.d.ts +72 -0
  125. package/dist/procedure.js +24 -0
  126. package/dist/router-client.d.ts +23 -0
  127. package/dist/router-client.js +43 -0
  128. package/dist/{router-hidden.d.mts → router-hidden.d.ts} +3 -3
  129. package/dist/router-hidden.js +14 -0
  130. package/dist/router-utils.d.ts +48 -0
  131. package/dist/router-utils.js +202 -0
  132. package/dist/router.d.ts +72 -0
  133. package/package.json +84 -86
  134. package/dist/adapters/aws-lambda/handler.d.mts +0 -25
  135. package/dist/adapters/aws-lambda/handler.mjs +0 -21
  136. package/dist/adapters/aws-lambda/index.d.mts +0 -16
  137. package/dist/adapters/aws-lambda/index.mjs +0 -2
  138. package/dist/adapters/aws-lambda/rpc-handler.d.mts +0 -18
  139. package/dist/adapters/aws-lambda/rpc-handler.mjs +0 -10
  140. package/dist/adapters/crossws/handler.d.mts +0 -41
  141. package/dist/adapters/crossws/handler.mjs +0 -38
  142. package/dist/adapters/crossws/index.d.mts +0 -2
  143. package/dist/adapters/crossws/index.mjs +0 -2
  144. package/dist/adapters/crossws/rpc-handler.d.mts +0 -15
  145. package/dist/adapters/crossws/rpc-handler.mjs +0 -10
  146. package/dist/adapters/fastify/handler.d.mts +0 -21
  147. package/dist/adapters/fastify/handler.mjs +0 -20
  148. package/dist/adapters/fastify/index.d.mts +0 -2
  149. package/dist/adapters/fastify/index.mjs +0 -2
  150. package/dist/adapters/fastify/rpc-handler.d.mts +0 -14
  151. package/dist/adapters/fastify/rpc-handler.mjs +0 -10
  152. package/dist/adapters/fetch/handler.d.mts +0 -23
  153. package/dist/adapters/fetch/handler.mjs +0 -22
  154. package/dist/adapters/fetch/index.d.mts +0 -7
  155. package/dist/adapters/fetch/index.mjs +0 -5
  156. package/dist/adapters/fetch/rpc-handler.d.mts +0 -16
  157. package/dist/adapters/fetch/rpc-handler.mjs +0 -10
  158. package/dist/adapters/message-port/handler.d.mts +0 -57
  159. package/dist/adapters/message-port/handler.mjs +0 -62
  160. package/dist/adapters/message-port/index.d.mts +0 -2
  161. package/dist/adapters/message-port/index.mjs +0 -2
  162. package/dist/adapters/message-port/rpc-handler.d.mts +0 -15
  163. package/dist/adapters/message-port/rpc-handler.mjs +0 -10
  164. package/dist/adapters/node/handler.d.mts +0 -21
  165. package/dist/adapters/node/handler.mjs +0 -20
  166. package/dist/adapters/node/index.d.mts +0 -7
  167. package/dist/adapters/node/index.mjs +0 -5
  168. package/dist/adapters/node/rpc-handler.d.mts +0 -15
  169. package/dist/adapters/node/rpc-handler.mjs +0 -10
  170. package/dist/adapters/standard/codec.d.mts +0 -16
  171. package/dist/adapters/standard/handler.d.mts +0 -68
  172. package/dist/adapters/standard/handler.mjs +0 -185
  173. package/dist/adapters/standard/index.d.mts +0 -6
  174. package/dist/adapters/standard/index.mjs +0 -5
  175. package/dist/adapters/standard/plugin.d.mts +0 -32
  176. package/dist/adapters/standard/plugin.mjs +0 -16
  177. package/dist/adapters/standard/rpc-handler-codec.d.mts +0 -42
  178. package/dist/adapters/standard/rpc-handler-codec.mjs +0 -51
  179. package/dist/adapters/standard/rpc-matcher.d.mts +0 -53
  180. package/dist/adapters/standard/rpc-matcher.mjs +0 -140
  181. package/dist/adapters/standard/utils.d.mts +0 -10
  182. package/dist/adapters/standard/utils.mjs +0 -6
  183. package/dist/adapters/standard-peer/index.d.mts +0 -1
  184. package/dist/adapters/standard-peer/index.mjs +0 -1
  185. package/dist/adapters/standard-peer/utils.mjs +0 -11
  186. package/dist/adapters/websocket/handler.d.mts +0 -55
  187. package/dist/adapters/websocket/handler.mjs +0 -55
  188. package/dist/adapters/websocket/index.d.mts +0 -2
  189. package/dist/adapters/websocket/index.mjs +0 -2
  190. package/dist/adapters/websocket/rpc-handler.d.mts +0 -15
  191. package/dist/adapters/websocket/rpc-handler.mjs +0 -10
  192. package/dist/builder-variants.d.mts +0 -267
  193. package/dist/builder.d.mts +0 -141
  194. package/dist/builder.mjs +0 -145
  195. package/dist/context.d.mts +0 -13
  196. package/dist/extensions/callable.d.mts +0 -17
  197. package/dist/extensions/callable.mjs +0 -7
  198. package/dist/helpers/base64url.d.mts +0 -31
  199. package/dist/helpers/base64url.mjs +0 -25
  200. package/dist/helpers/cookie.d.mts +0 -50
  201. package/dist/helpers/cookie.mjs +0 -35
  202. package/dist/helpers/encryption.d.mts +0 -28
  203. package/dist/helpers/encryption.mjs +0 -62
  204. package/dist/helpers/index.d.mts +0 -4
  205. package/dist/helpers/index.mjs +0 -4
  206. package/dist/helpers/signing.d.mts +0 -50
  207. package/dist/helpers/signing.mjs +0 -43
  208. package/dist/implementer-procedure.d.mts +0 -36
  209. package/dist/implementer-procedure.mjs +0 -38
  210. package/dist/implementer-router.d.mts +0 -78
  211. package/dist/implementer-router.mjs +0 -77
  212. package/dist/implementer.d.mts +0 -22
  213. package/dist/implementer.mjs +0 -30
  214. package/dist/index.d.mts +0 -57
  215. package/dist/index.mjs +0 -30
  216. package/dist/lazy.d.mts +0 -20
  217. package/dist/lazy.mjs +0 -22
  218. package/dist/middleware-decorated.d.mts +0 -27
  219. package/dist/middleware-decorated.mjs +0 -65
  220. package/dist/middleware.d.mts +0 -70
  221. package/dist/plugins/batch.d.mts +0 -104
  222. package/dist/plugins/batch.mjs +0 -373
  223. package/dist/plugins/cors.d.mts +0 -67
  224. package/dist/plugins/cors.mjs +0 -134
  225. package/dist/plugins/get-method-csrf-protection.d.mts +0 -23
  226. package/dist/plugins/get-method-csrf-protection.mjs +0 -45
  227. package/dist/plugins/head-method.d.mts +0 -23
  228. package/dist/plugins/head-method.mjs +0 -95
  229. package/dist/plugins/index.d.mts +0 -39
  230. package/dist/plugins/index.mjs +0 -23
  231. package/dist/plugins/method-override.d.mts +0 -38
  232. package/dist/plugins/method-override.mjs +0 -50
  233. package/dist/plugins/request-compression.d.mts +0 -16
  234. package/dist/plugins/request-compression.mjs +0 -67
  235. package/dist/plugins/request-headers.d.mts +0 -22
  236. package/dist/plugins/request-headers.mjs +0 -21
  237. package/dist/plugins/request-limit.d.mts +0 -30
  238. package/dist/plugins/request-limit.mjs +0 -53
  239. package/dist/plugins/response-compression.d.mts +0 -59
  240. package/dist/plugins/response-compression.mjs +0 -172
  241. package/dist/plugins/response-headers.d.mts +0 -30
  242. package/dist/plugins/response-headers.mjs +0 -34
  243. package/dist/plugins/rethrow.d.mts +0 -33
  244. package/dist/plugins/rethrow.mjs +0 -46
  245. package/dist/plugins/signal-sync.d.mts +0 -13
  246. package/dist/plugins/signal-sync.mjs +0 -84
  247. package/dist/plugins/timeout.d.mts +0 -37
  248. package/dist/plugins/timeout.mjs +0 -56
  249. package/dist/procedure-client.d.mts +0 -41
  250. package/dist/procedure-client.mjs +0 -157
  251. package/dist/procedure-decorated.d.mts +0 -20
  252. package/dist/procedure-decorated.mjs +0 -41
  253. package/dist/procedure-utils.d.mts +0 -52
  254. package/dist/procedure-utils.mjs +0 -33
  255. package/dist/procedure.d.mts +0 -93
  256. package/dist/procedure.mjs +0 -20
  257. package/dist/router-client.d.mts +0 -27
  258. package/dist/router-client.mjs +0 -35
  259. package/dist/router-hidden.mjs +0 -12
  260. package/dist/router-utils.d.mts +0 -59
  261. package/dist/router-utils.mjs +0 -191
  262. package/dist/router.d.mts +0 -61
  263. /package/dist/adapters/standard/{codec.mjs → codec.js} +0 -0
  264. /package/dist/{builder-variants.mjs → builder-variants.js} +0 -0
  265. /package/dist/{constants.d.mts → constants.d.ts} +0 -0
  266. /package/dist/{constants.mjs → constants.js} +0 -0
  267. /package/dist/{context.mjs → context.js} +0 -0
  268. /package/dist/{middleware.mjs → middleware.js} +0 -0
  269. /package/dist/{router.mjs → router.js} +0 -0
@@ -1,95 +0,0 @@
1
- import { isAsyncIteratorObject, toArray } from "@orpc/shared";
2
- import { cancelStandardBody, getRequiredStandardBodyHint } from "@standard-server/core";
3
- import { toFetchBody } from "@standard-server/fetch";
4
- const textEncoder = /* @__PURE__ */ new TextEncoder();
5
-
6
- export class HeadMethodHandlerPlugin {
7
- name = "~head-method";
8
-
9
- after = ["~response-compression"];
10
- init(options) {
11
- const bodyInterceptor = async ({ next, request }) => {
12
- if (request.method !== "HEAD") {
13
- return next();
14
- }
15
- const result = await next();
16
- if (!result.matched) {
17
- return result;
18
- }
19
- return {
20
- ...result,
21
- response: toHeadResponse(result.response)
22
- };
23
- };
24
-
25
- const fallbackInterceptor = async (interceptorOptions) => {
26
- const { next, request } = interceptorOptions;
27
- if (request.method !== "HEAD") {
28
- return next();
29
- }
30
- const result = await next();
31
- if (result.matched) {
32
- return result;
33
- }
34
- return next({
35
- ...interceptorOptions,
36
- request: {
37
- ...request,
38
- method: "GET"
39
- }
40
- });
41
- };
42
- return {
43
- ...options,
44
- routingInterceptors: [
45
- bodyInterceptor,
46
- ...toArray(options.routingInterceptors),
47
- fallbackInterceptor
48
- ]
49
- };
50
- }
51
- }
52
-
53
- function toHeadResponse(response) {
54
- const { body } = response;
55
- if (body === undefined) {
56
- return response;
57
- }
58
- if (isAsyncIteratorObject(body)) {
59
- discardBody(body);
60
- const headers = {
61
- ...response.headers,
62
- "content-length": undefined
63
- };
64
- headers["content-type"] ??= "text/event-stream";
65
- headers["standard-server"] = getRequiredStandardBodyHint("event-stream", headers) ?? [];
66
- return {
67
- ...response,
68
- headers,
69
- body: createEmptyStream()
70
- };
71
- }
72
- const [encoded, headers] = toFetchBody(body, response.headers);
73
- if (encoded instanceof ReadableStream) {
74
- discardBody(encoded);
75
- } else if (encoded instanceof FormData) {
76
-
77
- headers["standard-server"] = [];
78
- headers["content-type"] = new Response(encoded).headers.get("content-type");
79
- } else if (typeof encoded === "string" || encoded instanceof URLSearchParams) {
80
- headers["standard-server"] ??= [];
81
- headers["content-length"] = textEncoder.encode(encoded.toString()).byteLength.toString();
82
- }
83
- return {
84
- ...response,
85
- headers,
86
- body: createEmptyStream()
87
- };
88
- }
89
- function createEmptyStream() {
90
- return new ReadableStream({ start: (controller) => controller.close() });
91
- }
92
-
93
- function discardBody(body) {
94
- cancelStandardBody(body).catch(() => {});
95
- }
@@ -1,39 +0,0 @@
1
- export * from "./batch.mjs";
2
- export * from "./cors.mjs";
3
- export {
4
- /**
5
- * @deprecated Use `CORSHandlerPlugin` instead.
6
- */
7
- CORSHandlerPlugin as CORSPlugin } from "./cors.mjs";
8
- export * from "./get-method-csrf-protection.mjs";
9
- export * from "./head-method.mjs";
10
- export * from "./method-override.mjs";
11
- export * from "./request-compression.mjs";
12
- export * from "./request-headers.mjs";
13
- export {
14
- /**
15
- * @deprecated Use `RequestHeadersHandlerPlugin` instead.
16
- */
17
- RequestHeadersHandlerPlugin as RequestHeadersPlugin } from "./request-headers.mjs";
18
- export type {
19
- /**
20
- * @deprecated Use `RequestHeadersHandlerPluginContext` instead.
21
- */
22
- RequestHeadersHandlerPluginContext as RequestHeadersPluginContext } from "./request-headers.mjs";
23
- export * from "./request-limit.mjs";
24
- export * from "./response-compression.mjs";
25
- export * from "./response-headers.mjs";
26
- export {
27
- /**
28
- * @deprecated Use `ResponseHeadersHandlerPlugin` instead.
29
- */
30
- ResponseHeadersHandlerPlugin as ResponseHeadersPlugin } from "./response-headers.mjs";
31
- export type {
32
- /**
33
- * @deprecated Use `ResponseHeadersHandlerPluginContext` instead.
34
- */
35
- ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext } from "./response-headers.mjs";
36
- export * from "./rethrow.mjs";
37
- export * from "./signal-sync.mjs";
38
- export * from "./timeout.mjs";
39
- export { BATCH_HEADER, DEFAULT_BATCH_MAX_SIZE } from "@orpc/client/plugins";
@@ -1,23 +0,0 @@
1
- export * from "./batch.mjs";
2
- export * from "./cors.mjs";
3
- export {
4
-
5
- CORSHandlerPlugin as CORSPlugin } from "./cors.mjs";
6
- export * from "./get-method-csrf-protection.mjs";
7
- export * from "./head-method.mjs";
8
- export * from "./method-override.mjs";
9
- export * from "./request-compression.mjs";
10
- export * from "./request-headers.mjs";
11
- export {
12
-
13
- RequestHeadersHandlerPlugin as RequestHeadersPlugin } from "./request-headers.mjs";
14
- export * from "./request-limit.mjs";
15
- export * from "./response-compression.mjs";
16
- export * from "./response-headers.mjs";
17
- export {
18
-
19
- ResponseHeadersHandlerPlugin as ResponseHeadersPlugin } from "./response-headers.mjs";
20
- export * from "./rethrow.mjs";
21
- export * from "./signal-sync.mjs";
22
- export * from "./timeout.mjs";
23
- export { BATCH_HEADER, DEFAULT_BATCH_MAX_SIZE } from "@orpc/client/plugins";
@@ -1,38 +0,0 @@
1
- import type { StandardMethod } from "@standard-server/core";
2
- import type { StandardHandlerOptions, StandardHandlerPlugin } from "../adapters/standard/index.mjs";
3
- import type { Context } from "../context.mjs";
4
- export interface MethodOverrideHandlerPluginOptions {
5
- /**
6
- * The query parameter carrying the override method.
7
- *
8
- * @default 'method'
9
- */
10
- param?: string | undefined;
11
- /**
12
- * The methods a POST request may be overridden to.
13
- *
14
- * GET and HEAD are excluded by default because they switch input decoding
15
- * from the request body to the query string and widen the CSRF surface.
16
- *
17
- * @default ['PUT', 'PATCH', 'DELETE']
18
- */
19
- methods?: readonly StandardMethod[] | undefined;
20
- }
21
- /**
22
- * Overrides the HTTP method of a POST request based on a query parameter,
23
- * so HTML forms (which only support GET and POST) can invoke procedures
24
- * routed as PUT, PATCH, or DELETE.
25
- *
26
- * @see {@link https://orpc.dev/docs/plugins/method-override | Method Override Plugin}
27
- */
28
- export declare class MethodOverrideHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
29
- name: string;
30
- /**
31
- * Should override batch sub-request methods, not the original batch request.
32
- */
33
- before: string[];
34
- private readonly param;
35
- private readonly methods;
36
- constructor(options?: MethodOverrideHandlerPluginOptions);
37
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
38
- }
@@ -1,50 +0,0 @@
1
- import { toArray } from "@orpc/shared";
2
- import { parseStandardUrl } from "@standard-server/core";
3
-
4
- export class MethodOverrideHandlerPlugin {
5
- name = "~method-override";
6
-
7
- before = ["~batch"];
8
- param;
9
- methods;
10
- constructor(options = {}) {
11
- this.param = options.param ?? "method";
12
- this.methods = new Set((options.methods ?? [
13
- "PUT",
14
- "PATCH",
15
- "DELETE"
16
- ]).map((method) => method.toUpperCase()));
17
- }
18
- init(options) {
19
- const routingInterceptor = async ({ next, ...interceptorOptions }) => {
20
- const { request } = interceptorOptions;
21
- if (request.method !== "POST") {
22
- return next();
23
- }
24
- const [pathname, search, hash] = parseStandardUrl(request.url);
25
- const params = new URLSearchParams(search);
26
- const raw = params.getAll(this.param).at(-1);
27
- if (raw === undefined) {
28
- return next();
29
- }
30
- const method = raw.toUpperCase();
31
- if (!this.methods.has(method)) {
32
- return next();
33
- }
34
- params.delete(this.param);
35
- const url = `${pathname}${params.size ? `?${params}` : ""}${hash ?? ""}`;
36
- return next({
37
- ...interceptorOptions,
38
- request: {
39
- ...request,
40
- method,
41
- url
42
- }
43
- });
44
- };
45
- return {
46
- ...options,
47
- routingInterceptors: [routingInterceptor, ...toArray(options.routingInterceptors)]
48
- };
49
- }
50
- }
@@ -1,16 +0,0 @@
1
- import type { StandardHandlerOptions, StandardHandlerPlugin } from "../adapters/standard/index.mjs";
2
- import type { Context } from "../context.mjs";
3
- /**
4
- * Decompresses incoming request bodies based on the Content-Encoding header,
5
- * supporting gzip, deflate, and deflate-raw.
6
- *
7
- * @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
8
- */
9
- export declare class RequestCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
10
- name: string;
11
- /**
12
- * Should decompress the original batch request body instead of sub-requests.
13
- */
14
- after: string[];
15
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
16
- }
@@ -1,67 +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
- const MAX_CONTENT_ENCODINGS = 5;
7
-
8
- export class RequestCompressionHandlerPlugin {
9
- name = "~request-compression";
10
-
11
- after = ["~batch"];
12
- init(options) {
13
- const routingInterceptor = async ({ next, ...interceptorOptions }) => {
14
- const encodings = parseContentEncodings(flattenStandardHeader(interceptorOptions.request.headers["content-encoding"]));
15
- if (encodings.length === 0 || !encodings.every(isSupportedEncoding)) {
16
- return next();
17
- }
18
- const decompressedHeaders = {
19
- ...interceptorOptions.request.headers,
20
- "content-length": undefined,
21
- "content-encoding": undefined
22
- };
23
- return next({
24
- ...interceptorOptions,
25
- request: {
26
- ...interceptorOptions.request,
27
- headers: decompressedHeaders,
28
- async resolveBody(hint) {
29
- const stream = await interceptorOptions.request.resolveBody("octet-stream");
30
-
31
- if (!(stream instanceof ReadableStream)) {
32
- return stream;
33
- }
34
- if (encodings.length > MAX_CONTENT_ENCODINGS) {
35
- throw new ORPCError("UNSUPPORTED_MEDIA_TYPE", { message: "Too many content encodings." });
36
- }
37
- let decompressedStream = stream;
38
- for (let i = encodings.length - 1; i >= 0; i--) {
39
- decompressedStream = decompressedStream.pipeThrough(new DecompressionStream(encodings[i]));
40
- }
41
- const response = new Response(decompressedStream, { headers: toFetchHeaders(decompressedHeaders) });
42
- return toStandardBody(response, { hint });
43
- }
44
- }
45
- });
46
- };
47
- return {
48
- ...options,
49
- routingInterceptors: [routingInterceptor, ...toArray(options.routingInterceptors)]
50
- };
51
- }
52
- }
53
- const SUPPORTED_ENCODINGS = [
54
- "gzip",
55
- "deflate",
56
- "deflate-raw"
57
- ];
58
- function isSupportedEncoding(encoding) {
59
- return SUPPORTED_ENCODINGS.includes(encoding);
60
- }
61
-
62
- function parseContentEncodings(header) {
63
- if (header === undefined) {
64
- return [];
65
- }
66
- return header.split(",").map((part) => part.trim().toLowerCase());
67
- }
@@ -1,22 +0,0 @@
1
- import type { StandardHandlerOptions, StandardHandlerPlugin } from "../adapters/standard/index.mjs";
2
- /**
3
- * The context shape into which the Request Headers Plugin injects `reqHeaders`.
4
- *
5
- * @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
6
- */
7
- export interface RequestHeadersHandlerPluginContext {
8
- /**
9
- * Request headers as a Headers instance. This is injected by the Request Headers Plugin.
10
- */
11
- reqHeaders?: Headers | undefined;
12
- }
13
- /**
14
- * The Request Headers Plugin injects a `reqHeaders` instance into the context,
15
- * allowing access to request headers in oRPC.
16
- *
17
- * @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
18
- */
19
- export declare class RequestHeadersHandlerPlugin<T extends RequestHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
20
- name: string;
21
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
22
- }
@@ -1,21 +0,0 @@
1
- import { toArray } from "@orpc/shared";
2
- import { toFetchHeaders } from "@standard-server/fetch";
3
-
4
- export class RequestHeadersHandlerPlugin {
5
- name = "~request-headers";
6
- init(options) {
7
- return {
8
- ...options,
9
- interceptors: [(interceptorOptions) => {
10
- const reqHeaders = interceptorOptions.context.reqHeaders ?? toFetchHeaders(interceptorOptions.request.headers);
11
- return interceptorOptions.next({
12
- ...interceptorOptions,
13
- context: {
14
- ...interceptorOptions.context,
15
- reqHeaders
16
- }
17
- });
18
- }, ...toArray(options.interceptors)]
19
- };
20
- }
21
- }
@@ -1,30 +0,0 @@
1
- import type { StandardHandlerOptions, StandardHandlerPlugin } from "../adapters/standard/index.mjs";
2
- import type { Context } from "../context.mjs";
3
- export interface RequestLimitHandlerPluginOptions {
4
- /**
5
- * The maximum allowed request body size in bytes.
6
- */
7
- maxBodySize: number;
8
- }
9
- /**
10
- * Rejects requests whose body exceeds `maxBodySize`.
11
- *
12
- * When used with the request compression plugin, the limit applies to the
13
- * decompressed payload rather than the compressed wire size.
14
- *
15
- * @see {@link https://orpc.dev/docs/plugins/request-limit | Request Limit Plugin}
16
- */
17
- export declare class RequestLimitHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
18
- name: string;
19
- /**
20
- * Should limit the original batch request body instead of sub-requests.
21
- */
22
- after: string[];
23
- /**
24
- * Should limit the final body size instead of the compressed one.
25
- */
26
- before: string[];
27
- private readonly maxBodySize;
28
- constructor(options: RequestLimitHandlerPluginOptions);
29
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
30
- }
@@ -1,53 +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
- export class RequestLimitHandlerPlugin {
7
- name = "~request-limit";
8
-
9
- after = ["~batch"];
10
-
11
- before = ["~request-compression"];
12
- maxBodySize;
13
- constructor(options) {
14
- this.maxBodySize = options.maxBodySize;
15
- }
16
- init(options) {
17
- const maxBodySize = this.maxBodySize;
18
- const routingInterceptor = async ({ next, ...interceptorOptions }) => {
19
- return next({
20
- ...interceptorOptions,
21
- request: {
22
- ...interceptorOptions.request,
23
- async resolveBody(hint) {
24
- const contentLength = Number(flattenStandardHeader(interceptorOptions.request.headers["content-length"]));
25
- if (Number.isFinite(contentLength) && contentLength > maxBodySize) {
26
- throw new ORPCError("PAYLOAD_TOO_LARGE");
27
- }
28
- const stream = await interceptorOptions.request.resolveBody("octet-stream");
29
-
30
- if (!(stream instanceof ReadableStream)) {
31
- return stream;
32
- }
33
- let currentBodySize = 0;
34
- const limitedStream = stream.pipeThrough(new TransformStream({ transform(chunk, controller) {
35
- currentBodySize += chunk.byteLength;
36
- if (currentBodySize > maxBodySize) {
37
- controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
38
- return;
39
- }
40
- controller.enqueue(chunk);
41
- } }));
42
- const response = new Response(limitedStream, { headers: toFetchHeaders(interceptorOptions.request.headers) });
43
- return toStandardBody(response, { hint });
44
- }
45
- }
46
- });
47
- };
48
- return {
49
- ...options,
50
- routingInterceptors: [routingInterceptor, ...toArray(options.routingInterceptors)]
51
- };
52
- }
53
- }
@@ -1,59 +0,0 @@
1
- import type { StandardHeaders, StandardResponse } from "@standard-server/core";
2
- import type { StandardHandlerOptions, StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions } from "../adapters/standard/index.mjs";
3
- import type { Context } from "../context.mjs";
4
- export interface ResponseCompressionHandlerPluginOptions<T extends Context> {
5
- /**
6
- * The compression schemes to use for response compression.
7
- * Schemes are prioritized by their order in this array and
8
- * only applied if the client supports them (via Accept-Encoding).
9
- *
10
- * @default ['gzip', 'deflate']
11
- */
12
- encodings?: readonly ("gzip" | "deflate" | "deflate-raw")[] | undefined;
13
- /**
14
- * The minimum response size in bytes required to trigger compression.
15
- * Responses smaller than this threshold will not be compressed to avoid overhead.
16
- * If the response size cannot be determined, compression will still be applied.
17
- *
18
- * @default 1024 (1KB)
19
- */
20
- threshold?: number | undefined;
21
- /**
22
- * Determines whether a response with the given Content-Type should be compressed.
23
- * Only consulted for binary transfers (streams, files, and file form-data parts).
24
- * Also receives the routing interceptor options for per-request decisions.
25
- *
26
- * @default isCompressibleContentType (covers common text-based formats)
27
- */
28
- isCompressibleContentType?: ((contentType: string | null | undefined, options: StandardHandlerRoutingInterceptorOptions<T>) => boolean) | undefined;
29
- }
30
- /**
31
- * Compresses response bodies based on the client's Accept-Encoding header.
32
- * Works at the standard handler level, so it supports all adapters.
33
- *
34
- * @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
35
- */
36
- export declare class ResponseCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
37
- name: string;
38
- /**
39
- * Compression should be done after batching, to compress the final response.
40
- * Compression should also be done after response headers are set, to access final headers like Content-Type and Cache-Control.
41
- */
42
- after: string[];
43
- private readonly encodings;
44
- private readonly threshold;
45
- private readonly isCompressibleContentType;
46
- constructor(options?: ResponseCompressionHandlerPluginOptions<T>);
47
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
48
- }
49
- /**
50
- * Picks the first of `encodings` the client accepts, or `undefined` when the response
51
- * must be sent as is because it is already encoded, partial, or forbids transforms.
52
- * Shared by the response compression plugins so they agree on when to compress.
53
- */
54
- export declare function negotiateResponseCompressionEncoding<TEncoding extends string>(response: StandardResponse, requestHeaders: StandardHeaders, encodings: readonly TEncoding[]): TEncoding | undefined;
55
- /**
56
- * The headers of a response whose body is compressed with `encoding`.
57
- * Shared by the response compression plugins so compressed responses carry the same headers.
58
- */
59
- export declare function toCompressedHeaders(headers: StandardHeaders, encoding: string): StandardHeaders;