You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7604f11
Browse filesBrowse the repository at this point in the historyBrowse files
refactor(rpc): export batch constants and improve documentation (#2290)
## Summary
Extracts batch-related constants (`BATCH_HEADER` and
`DEFAULT_BATCH_MAX_SIZE`) into shared exports and improves documentation
around batch request handling, particularly regarding header
preservation and size limits.
## Key Changes
- **New exports**: Added `BATCH_HEADER` ('orpc-batch') and
`DEFAULT_BATCH_MAX_SIZE` (10) constants to `@orpc/client/plugins` and
re-exported from `@orpc/server/plugins` for consistency across client
and server
- **Updated batch plugins**: Both `BatchLinkPlugin` and
`BatchHandlerPlugin` now use the exported constants instead of hardcoded
values
- **Improved documentation**:
- Clarified the warning about batch header preservation (CORS, proxies,
etc.)
- Added new "Max Size" section with code examples showing how to
configure `maxSize` on both client and server
- Enhanced JSDoc comments explaining the relationship between client and
server `maxSize` limits and the 413 rejection behavior
- **Consistent header handling**: Updated all references to the batch
header string to use the `BATCH_HEADER` constant across client and
server implementations
- **Test updates**: Added assertions verifying the new constants are
properly exported
## Implementation Details
The constants are defined in `@orpc/client/plugins/batch.ts` and
re-exported from the server plugins index, ensuring a single source of
truth. This makes it easier for users to reference the exact header name
and default size limit in their configurations.
https://claude.ai/code/session_01RmF7F7emDsPDYH5ZGrUumt
<!-- Macroscope's pull request summary starts here -->
<!-- Macroscope will only edit the content between these invisible
markers, and the markers themselves will not be visible in the GitHub
rendered markdown. -->
<!-- If you delete either of the start / end markers from your PR's
description, Macroscope will append its summary at the bottom of the
description. -->
> [!NOTE]
> ### Export `BATCH_HEADER` and `DEFAULT_BATCH_MAX_SIZE` constants for
batch plugins
> - Adds exported shared constants `BATCH_HEADER` ("orpc-batch") and
`DEFAULT_BATCH_MAX_SIZE` (10) in the client plugins module, and
re-exports them from the server plugins entrypoint. Client and server
batch plugins now use these constants instead of inline literals. Values
are unchanged.
> - Updates `maxSize` docs on both `BatchLinkPluginOptions` and
`BatchHandlerPluginOptions` to explain client splitting and the server
`413` response, and rewrites
[batch.mdx](https://github.com/middleapi/orpc/pull/2290/files#diff-c0c938d06b5d63227600731a917541aeb24b4901a7d05eb20c550dc142290238)
with a Max Size section and clarified `BATCH_HEADER` warning.
> - Extends plugin export tests in the client and server packages to
assert the new constants.
> - Behavioral Change: none — default batch size stays 10 and the header
name stays "orpc-batch"; this only moves them to shared constants.
>
> <!-- Macroscope's review summary starts here -->
>
> <sup><a href="https://app.macroscope.com">Macroscope</a> summarized
1bd08c8.</sup>
> <!-- Macroscope's review summary ends here -->
>
<!-- Macroscope's pull request summary ends here -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: apps/content/docs/plugins/batch.mdx
+33-5Lines changed: 33 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,15 +46,43 @@ const link = new RPCLink({
46
46
</CodeGroup>
47
47
48
48
:::warning
49
-
`BatchHandlerPlugin` detects batch requests by checking for the `orpc-batch` header, so cross-origin batch requests need CORS to allow it. The [CORS Plugin](/docs/plugins/cors) allows requested headers by default. If you set `allowHeaders` or configure CORS elsewhere, include `orpc-batch` along with `Content-Type` and any other headers your clients send:
49
+
`BatchHandlerPlugin` recognizes batch requests by the `orpc-batch` header (exported as `BATCH_HEADER`), so make sure nothing between the client and server blocks or strips it, such as a CORS policy or proxy. This is usually fine by default, as the [CORS Plugin](/docs/plugins/cors) allows the headers a request asks for.
50
+
:::
50
51
51
-
```ts
52
-
const cors =newCORSHandlerPlugin({
53
-
allowHeaders: ['Content-Type', 'orpc-batch'],
52
+
## Max Size
53
+
54
+
Both plugins limit how many requests a batch holds with `maxSize`, and each side defaults to `DEFAULT_BATCH_MAX_SIZE` (10) independently. The client splits a larger group into several batches, while the server rejects a larger batch with a `413` for every request in it, so keep the client limit at or below the server's.
0 commit comments