@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.
Files changed (139) hide show
  1. package/dist/adapters/aws-lambda/handler.d.ts +17 -15
  2. package/dist/adapters/aws-lambda/handler.js +23 -23
  3. package/dist/adapters/aws-lambda/index.d.ts +4 -16
  4. package/dist/adapters/aws-lambda/index.js +2 -2
  5. package/dist/adapters/aws-lambda/rpc-handler.d.ts +9 -9
  6. package/dist/adapters/aws-lambda/rpc-handler.js +20 -17
  7. package/dist/adapters/crossws/handler.d.ts +44 -42
  8. package/dist/adapters/crossws/handler.js +53 -60
  9. package/dist/adapters/crossws/index.d.ts +3 -2
  10. package/dist/adapters/crossws/index.js +2 -2
  11. package/dist/adapters/crossws/rpc-handler.d.ts +10 -10
  12. package/dist/adapters/crossws/rpc-handler.js +17 -14
  13. package/dist/adapters/fastify/handler.d.ts +17 -15
  14. package/dist/adapters/fastify/handler.js +20 -20
  15. package/dist/adapters/fastify/index.d.ts +3 -2
  16. package/dist/adapters/fastify/index.js +2 -2
  17. package/dist/adapters/fastify/rpc-handler.d.ts +9 -9
  18. package/dist/adapters/fastify/rpc-handler.js +16 -13
  19. package/dist/adapters/fetch/handler.d.ts +19 -17
  20. package/dist/adapters/fetch/handler.js +22 -22
  21. package/dist/adapters/fetch/index.d.ts +4 -7
  22. package/dist/adapters/fetch/index.js +3 -7
  23. package/dist/adapters/fetch/rpc-handler.d.ts +9 -9
  24. package/dist/adapters/fetch/rpc-handler.js +18 -15
  25. package/dist/adapters/message-port/handler.d.ts +58 -60
  26. package/dist/adapters/message-port/handler.js +72 -86
  27. package/dist/adapters/message-port/index.d.ts +3 -2
  28. package/dist/adapters/message-port/index.js +2 -2
  29. package/dist/adapters/message-port/rpc-handler.d.ts +9 -9
  30. package/dist/adapters/message-port/rpc-handler.js +17 -14
  31. package/dist/adapters/node/handler.d.ts +17 -15
  32. package/dist/adapters/node/handler.js +20 -20
  33. package/dist/adapters/node/index.d.ts +4 -7
  34. package/dist/adapters/node/index.js +3 -7
  35. package/dist/adapters/node/rpc-handler.d.ts +9 -9
  36. package/dist/adapters/node/rpc-handler.js +17 -14
  37. package/dist/adapters/standard/codec.d.ts +13 -13
  38. package/dist/adapters/standard/handler.d.ts +49 -49
  39. package/dist/adapters/standard/handler.js +205 -205
  40. package/dist/adapters/standard/index.d.ts +7 -6
  41. package/dist/adapters/standard/index.js +4 -5
  42. package/dist/adapters/standard/plugin.d.ts +25 -31
  43. package/dist/adapters/standard/plugin.js +14 -16
  44. package/dist/adapters/standard/rpc-handler-codec.d.ts +39 -43
  45. package/dist/adapters/standard/rpc-handler-codec.js +50 -51
  46. package/dist/adapters/standard/rpc-matcher.d.ts +40 -40
  47. package/dist/adapters/standard/rpc-matcher.js +103 -149
  48. package/dist/adapters/standard/utils.d.ts +8 -8
  49. package/dist/adapters/standard/utils.js +7 -5
  50. package/dist/adapters/standard-peer/index.d.ts +2 -1
  51. package/dist/adapters/standard-peer/index.js +1 -1
  52. package/dist/adapters/standard-peer/utils.d.ts +6 -4
  53. package/dist/adapters/standard-peer/utils.js +12 -6
  54. package/dist/adapters/websocket/handler.d.ts +52 -50
  55. package/dist/adapters/websocket/handler.js +75 -85
  56. package/dist/adapters/websocket/index.d.ts +3 -2
  57. package/dist/adapters/websocket/index.js +2 -2
  58. package/dist/adapters/websocket/rpc-handler.d.ts +9 -9
  59. package/dist/adapters/websocket/rpc-handler.js +17 -14
  60. package/dist/builder-variants.d.ts +195 -195
  61. package/dist/builder.d.ts +103 -104
  62. package/dist/builder.js +198 -224
  63. package/dist/constants.d.ts +1 -1
  64. package/dist/constants.js +4 -2
  65. package/dist/context.d.ts +3 -3
  66. package/dist/extensions/callable.d.ts +11 -11
  67. package/dist/extensions/callable.js +6 -5
  68. package/dist/helpers/base64url.d.ts +1 -1
  69. package/dist/helpers/base64url.js +44 -49
  70. package/dist/helpers/cookie.d.ts +10 -11
  71. package/dist/helpers/cookie.js +56 -63
  72. package/dist/helpers/encryption.d.ts +1 -1
  73. package/dist/helpers/encryption.js +80 -70
  74. package/dist/helpers/index.d.ts +5 -4
  75. package/dist/helpers/index.js +4 -4
  76. package/dist/helpers/signing.d.ts +1 -1
  77. package/dist/helpers/signing.js +72 -82
  78. package/dist/implementer-procedure.d.ts +12 -13
  79. package/dist/implementer-procedure.js +37 -44
  80. package/dist/implementer-router.d.ts +30 -36
  81. package/dist/implementer-router.js +92 -111
  82. package/dist/implementer.d.ts +8 -8
  83. package/dist/implementer.js +28 -35
  84. package/dist/index.d.ts +22 -61
  85. package/dist/index.js +16 -48
  86. package/dist/lazy.d.ts +14 -14
  87. package/dist/lazy.js +19 -30
  88. package/dist/middleware-decorated.d.ts +8 -9
  89. package/dist/middleware-decorated.js +66 -70
  90. package/dist/middleware.d.ts +34 -34
  91. package/dist/plugins/batch.d.ts +75 -75
  92. package/dist/plugins/batch.js +345 -379
  93. package/dist/plugins/cors.d.ts +60 -64
  94. package/dist/plugins/cors.js +118 -111
  95. package/dist/plugins/get-method-csrf-protection.d.ts +8 -6
  96. package/dist/plugins/get-method-csrf-protection.js +47 -63
  97. package/dist/plugins/head-method.d.ts +11 -9
  98. package/dist/plugins/head-method.js +97 -94
  99. package/dist/plugins/index.d.ts +15 -39
  100. package/dist/plugins/index.js +14 -29
  101. package/dist/plugins/method-override.d.ts +30 -28
  102. package/dist/plugins/method-override.js +53 -49
  103. package/dist/plugins/request-compression.d.ts +11 -9
  104. package/dist/plugins/request-compression.js +52 -79
  105. package/dist/plugins/request-headers.d.ts +10 -8
  106. package/dist/plugins/request-headers.js +27 -29
  107. package/dist/plugins/request-limit.d.ts +21 -19
  108. package/dist/plugins/request-limit.js +60 -67
  109. package/dist/plugins/response-compression.d.ts +42 -39
  110. package/dist/plugins/response-compression.js +150 -202
  111. package/dist/plugins/response-headers.d.ts +15 -13
  112. package/dist/plugins/response-headers.js +43 -46
  113. package/dist/plugins/rethrow.d.ts +25 -23
  114. package/dist/plugins/rethrow.js +46 -58
  115. package/dist/plugins/signal-sync.d.ts +7 -5
  116. package/dist/plugins/signal-sync.js +71 -86
  117. package/dist/plugins/timeout.d.ts +29 -27
  118. package/dist/plugins/timeout.js +61 -58
  119. package/dist/procedure-client.d.ts +14 -15
  120. package/dist/procedure-client.js +149 -166
  121. package/dist/procedure-decorated.d.ts +9 -9
  122. package/dist/procedure-decorated.js +36 -44
  123. package/dist/procedure-utils.d.ts +10 -30
  124. package/dist/procedure-utils.js +39 -40
  125. package/dist/procedure.d.ts +60 -60
  126. package/dist/procedure.js +18 -24
  127. package/dist/router-client.d.ts +9 -11
  128. package/dist/router-client.js +33 -41
  129. package/dist/router-hidden.js +10 -12
  130. package/dist/router-utils.d.ts +13 -30
  131. package/dist/router-utils.js +146 -191
  132. package/dist/router.d.ts +12 -26
  133. package/package.json +10 -10
  134. package/dist/adapters/standard/codec.js +0 -1
  135. package/dist/builder-variants.js +0 -1
  136. package/dist/context.js +0 -1
  137. package/dist/middleware.js +0 -1
  138. package/dist/router-hidden.d.ts +0 -5
  139. package/dist/router.js +0 -1
@@ -1,104 +1,107 @@
1
- import { isAsyncIteratorObject, toArray } from '@orpc/shared';
2
- import { cancelStandardBody, getRequiredStandardBodyHint } from '@standard-server/core';
3
- import { toFetchBody } from '@standard-server/fetch';
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
- * Answers `HEAD` requests with the headers of the matching `GET` procedure, like Fastify's
7
- * `exposeHeadRoutes`, so clients can check a resource's existence, type, and size without
8
- * downloading it. A procedure routed as `HEAD` itself takes precedence over the `GET` one.
9
- *
10
- * @remarks
11
- * - `HEAD` responses never carry a body: the plugin discards it, cancelling streams and
12
- * event iterators, and keeps the headers it implies, such as `Content-Type`, and
13
- * `Content-Length` when its size is known up front.
14
- * - `GET` procedures still need to be reachable, so with `RPCHandler`, `GET` must be in `allowMethods`.
15
- *
16
- * @see {@link https://orpc.dev/docs/plugins/head-method | HEAD Method Plugin}
17
- */
18
- export class HeadMethodHandlerPlugin {
19
- name = '~head-method';
20
- /**
21
- * Discard the body after response compression, so `HEAD` reports the same `Content-Encoding` as `GET`.
22
- */
23
- after = ['~response-compression'];
24
- init(options) {
25
- // oxlint-disable-next-line unicorn/consistent-function-scoping
26
- const bodyInterceptor = async ({ next, request }) => {
27
- if (request.method !== 'HEAD') {
28
- return next();
29
- }
30
- const result = await next();
31
- if (!result.matched) {
32
- return result;
33
- }
34
- return { ...result, response: toHeadResponse(result.response) };
35
- };
36
- /**
37
- * Placed last, so falling back to `GET` repeats routing rather than the routing interceptors before this one.
38
- */
39
- // oxlint-disable-next-line unicorn/consistent-function-scoping
40
- const fallbackInterceptor = async (interceptorOptions) => {
41
- const { next, request } = interceptorOptions;
42
- if (request.method !== 'HEAD') {
43
- return next();
44
- }
45
- const result = await next();
46
- if (result.matched) {
47
- return result;
48
- }
49
- return next({
50
- ...interceptorOptions,
51
- request: { ...request, method: 'GET' },
52
- });
53
- };
54
- return {
55
- ...options,
56
- routingInterceptors: [
57
- bodyInterceptor,
58
- ...toArray(options.routingInterceptors),
59
- fallbackInterceptor,
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
- * Replaces the body with an empty stream, keeping the headers adapters derive from it.
66
- * An empty stream rather than no body, because adapters drop `Content-Type` and `Content-Length` when the body is `undefined`,
67
- * and an empty `Standard-Server` hint rather than none, so they do not hint the stream as `octet-stream`.
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
- const { body } = response;
71
- if (body === undefined) {
72
- return response;
73
- }
74
- if (isAsyncIteratorObject(body)) {
75
- discardBody(body);
76
- const headers = { ...response.headers, 'content-length': undefined };
77
- headers['content-type'] ??= 'text/event-stream';
78
- headers['standard-server'] = getRequiredStandardBodyHint('event-stream', headers) ?? [];
79
- return { ...response, headers, body: createEmptyStream() };
80
- }
81
- const [encoded, headers] = toFetchBody(body, response.headers);
82
- if (encoded instanceof ReadableStream) {
83
- discardBody(encoded);
84
- }
85
- else if (encoded instanceof FormData) {
86
- // The encoded body is never cancelled, since undici rejects unhandled when cancelled mid-serialization
87
- headers['standard-server'] = [];
88
- headers['content-type'] = new Response(encoded).headers.get('content-type');
89
- }
90
- else if (typeof encoded === 'string' || encoded instanceof URLSearchParams) {
91
- headers['standard-server'] ??= [];
92
- headers['content-length'] = textEncoder.encode(encoded.toString()).byteLength.toString();
93
- }
94
- return { ...response, headers, body: createEmptyStream() };
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
- return new ReadableStream({ start: (controller) => controller.close() });
99
+ return new ReadableStream({ start: (controller) => controller.close() });
98
100
  }
99
101
  /**
100
- * Nothing reads the body anymore, so a failure to cancel it has nowhere to go.
101
- */
102
+ * Nothing reads the body anymore, so a failure to cancel it has nowhere to go.
103
+ */
102
104
  function discardBody(body) {
103
- cancelStandardBody(body).catch(() => { });
105
+ cancelStandardBody(body).catch(() => {});
104
106
  }
107
+ export { HeadMethodHandlerPlugin };
@@ -1,39 +1,15 @@
1
- export * from './batch.ts';
2
- export * from './cors.ts';
3
- export {
4
- /**
5
- * @deprecated Use `CORSHandlerPlugin` instead.
6
- */
7
- CORSHandlerPlugin as CORSPlugin, } from './cors.ts';
8
- export * from './get-method-csrf-protection.ts';
9
- export * from './head-method.ts';
10
- export * from './method-override.ts';
11
- export * from './request-compression.ts';
12
- export * from './request-headers.ts';
13
- export {
14
- /**
15
- * @deprecated Use `RequestHeadersHandlerPlugin` instead.
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 };
@@ -1,29 +1,14 @@
1
- export * from './batch.js';
2
- export * from './cors.js';
3
- export {
4
- /**
5
- * @deprecated Use `CORSHandlerPlugin` instead.
6
- */
7
- CORSHandlerPlugin as CORSPlugin, } from './cors.js';
8
- export * from './get-method-csrf-protection.js';
9
- export * from './head-method.js';
10
- export * from './method-override.js';
11
- export * from './request-compression.js';
12
- export * from './request-headers.js';
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 type { StandardMethod } from '@standard-server/core';
2
- import type { StandardHandlerOptions, StandardHandlerPlugin } from '../adapters/standard/index.ts';
3
- import type { Context } from '../context.ts';
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
- * 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;
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
- 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
- }
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 '@orpc/shared';
2
- import { parseStandardUrl } from '@standard-server/core';
1
+ import { toArray } from "@orpc/shared";
2
+ import { parseStandardUrl } from "@standard-server/core";
3
+ // src/plugins/method-override.ts
3
4
  /**
4
- * Overrides the HTTP method of a POST request based on a query parameter,
5
- * so HTML forms (which only support GET and POST) can invoke procedures
6
- * routed as PUT, PATCH, or DELETE.
7
- *
8
- * @see {@link https://orpc.dev/docs/plugins/method-override | Method Override Plugin}
9
- */
10
- export class MethodOverrideHandlerPlugin {
11
- name = '~method-override';
12
- /**
13
- * Should override batch sub-request methods, not the original batch request.
14
- */
15
- before = ['~batch'];
16
- param;
17
- methods;
18
- constructor(options = {}) {
19
- this.param = options.param ?? 'method';
20
- this.methods = new Set((options.methods ?? ['PUT', 'PATCH', 'DELETE']).map((method) => method.toUpperCase()));
21
- }
22
- init(options) {
23
- const routingInterceptor = async ({ next, ...interceptorOptions }) => {
24
- const { request } = interceptorOptions;
25
- if (request.method !== 'POST') {
26
- return next();
27
- }
28
- const [pathname, search, hash] = parseStandardUrl(request.url);
29
- const params = new URLSearchParams(search);
30
- const raw = params.getAll(this.param).at(-1);
31
- if (raw === undefined) {
32
- return next();
33
- }
34
- const method = raw.toUpperCase();
35
- if (!this.methods.has(method)) {
36
- return next();
37
- }
38
- params.delete(this.param);
39
- const url = `${pathname}${params.size ? `?${params}` : ''}${hash ?? ''}`;
40
- return next({
41
- ...interceptorOptions,
42
- request: { ...request, method, url },
43
- });
44
- };
45
- return {
46
- ...options,
47
- routingInterceptors: [routingInterceptor, ...toArray(options.routingInterceptors)],
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 type { StandardHandlerOptions, StandardHandlerPlugin } from '../adapters/standard/index.ts';
2
- import type { Context } from '../context.ts';
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
- 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
- }
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
+ }