@cratestack/link-batch 0.5.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stephane Segning
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @cratestack/link-batch
2
+
3
+ A [batshit](https://github.com/yornaath/batshit)-style automatic batch scheduler for CrateStack's
4
+ generated TypeScript RPC client (`transport rpc` schemas), shipped as an
5
+ [`RpcLink`](https://github.com/cratestack/cratestack/blob/main/packages/cratestack-ts-types)
6
+ ([issue #182](https://github.com/cratestack/cratestack/issues/182)) rather than a `fetch`
7
+ override — so it composes with `@cratestack/link-logger`, a retry link, or an auth-refresh link
8
+ instead of clobbering them.
9
+
10
+ Multiple unary calls issued in the same tick collapse into a single `POST /rpc/batch` request
11
+ instead of firing one `POST /rpc/{op_id}` each.
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { createBatchLink } from "@cratestack/link-batch";
17
+ import { CratestackRpcRuntime } from "./generated/runtime"; // your project's generated client
18
+
19
+ const runtime = new CratestackRpcRuntime("https://api.example.com", {
20
+ links: [createBatchLink()],
21
+ });
22
+ const client = new MyGeneratedClient(runtime);
23
+
24
+ // These three calls, if issued in the same tick, become ONE /rpc/batch request:
25
+ const [a, b, c] = await Promise.all([
26
+ client.widgets.get(1),
27
+ client.widgets.get(2),
28
+ client.widgets.get(3),
29
+ ]);
30
+ ```
31
+
32
+ ## Batching semantics
33
+
34
+ - **Window**: defaults to `queueMicrotask` — calls fired synchronously in the same tick (e.g.
35
+ inside `Promise.all`) collapse. Pass `windowMs` to widen the window across ticks.
36
+ - **Dedup**: only calls sharing an explicit `idempotencyKey` are collapsed into one request frame
37
+ by default — that's already the caller's own signal that the call is a safe repeat. Calls with
38
+ no idempotency key are never auto-collapsed, since the server does no dedup of its own and
39
+ silently merging two textually-identical but unmarked mutations would be unsafe. Pass a custom
40
+ `dedupe` for full value-based collapsing, or `() => null` to disable dedup and only batch.
41
+ - **Correlation**: results are fanned back out by matching each response frame's `id`, not array
42
+ position — the server's `/rpc/batch` contract already guarantees order (see
43
+ `docs/design/rpc-transport.md` §3.2), but id-based matching is strictly more robust and mirrors
44
+ the repo's own Rust client-side batch debouncer (`examples/rpc-batch-debounce`).
45
+
46
+ ### Known limitations
47
+
48
+ - The synthesized `/rpc/batch` request reuses the **first** queued call's `headers`/`fetchFn`/
49
+ `codec` for the whole flush — per-call custom headers on later calls in the same window are not
50
+ applied to the aggregate request. Pass shared headers via the runtime's own `headers` option
51
+ rather than per-call `CratestackRpcCallOptions.headers` when using this link.
52
+ - Aborting an individual call's `AbortSignal` only cancels it if its batch hasn't been sent yet —
53
+ it does not cancel an in-flight `/rpc/batch` request.
@@ -0,0 +1,51 @@
1
+ import type { RpcLink, RpcLinkRequest } from "@cratestack/ts-types";
2
+ export interface BatchLinkOptions {
3
+ /** Scheduling window. Omitted (default) uses `queueMicrotask` — calls
4
+ * fired synchronously in the same tick (e.g. inside `Promise.all`)
5
+ * collapse into one `/rpc/batch` request. Pass a millisecond value to
6
+ * widen the window across ticks (e.g. debounce bursts from unrelated
7
+ * components). */
8
+ windowMs?: number;
9
+ /** Maximum requests per flushed `/rpc/batch` call. Default: unbounded
10
+ * — the server enforces no size limit either (see
11
+ * `docs/design/rpc-transport.md` §3.2), but a huge fan-in may still
12
+ * be worth capping client-side. */
13
+ maxBatchSize?: number;
14
+ /** Returns a dedupe key for a queued call, or `null` to never
15
+ * collapse it with anything else. Two calls in the same flush that
16
+ * return the same non-null key become ONE `/rpc/batch` frame, and
17
+ * every caller resolves from that single result.
18
+ *
19
+ * Default: only collapse calls that share an explicit
20
+ * `idempotencyKey` — that's already the caller's own signal that the
21
+ * call is safe to treat as a repeat. Calls with no idempotency key
22
+ * are never auto-collapsed, since the server does no dedup of its
23
+ * own and silently merging two textually-identical but unmarked
24
+ * mutations would be unsafe. Pass a custom `dedupe` for full
25
+ * value-based batshit-style collapsing (e.g.
26
+ * `req => \`${req.opId}:${JSON.stringify(req.input)}\``), or
27
+ * `() => null` to disable dedup entirely and only batch.
28
+ */
29
+ dedupe?: (request: RpcLinkRequest) => string | null;
30
+ }
31
+ /** A batshit-style (github.com/yornaath/batshit) automatic batch
32
+ * scheduler, shipped as an `RpcLink` (issue #182's composition
33
+ * mechanism) rather than a `fetch` override — so it composes with a
34
+ * logger, retry, or auth-refresh link instead of clobbering them.
35
+ *
36
+ * Terminal in practice: for `kind: "unary"` calls it never invokes
37
+ * `next` — it queues the call and later performs its own single
38
+ * `POST /rpc/batch`. An explicit `runtime.batch()` call (`kind:
39
+ * "batch"`) passes straight through via `next`, since it's already
40
+ * the shape this link would otherwise build.
41
+ *
42
+ * Known limitation: the synthesized `/rpc/batch` request reuses the
43
+ * first queued call's `headers`/`fetchFn`/`codec` for the whole flush
44
+ * — per-call custom headers on later calls in the same window are not
45
+ * applied to the aggregate request. Pass shared headers via the
46
+ * runtime's own `headers` option rather than per-call
47
+ * `CratestackRpcCallOptions.headers` when using this link. Similarly,
48
+ * aborting an individual call's `AbortSignal` only cancels it if the
49
+ * flush hasn't been sent yet — it does not cancel an in-flight batch. */
50
+ export declare function createBatchLink(options?: BatchLinkOptions): RpcLink;
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,OAAO,EACP,cAAc,EAIf,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,gBAAgB;IAC/B;;;;uBAImB;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;wCAGoC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,MAAM,GAAG,IAAI,CAAC;CACrD;AAgBD;;;;;;;;;;;;;;;;;;0EAkB0E;AAC1E,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAyGvE"}
package/dist/index.js ADDED
@@ -0,0 +1,187 @@
1
+ const defaultDedupe = (request) => request.idempotencyKey !== undefined ? `idem:${request.idempotencyKey}` : null;
2
+ /** A batshit-style (github.com/yornaath/batshit) automatic batch
3
+ * scheduler, shipped as an `RpcLink` (issue #182's composition
4
+ * mechanism) rather than a `fetch` override — so it composes with a
5
+ * logger, retry, or auth-refresh link instead of clobbering them.
6
+ *
7
+ * Terminal in practice: for `kind: "unary"` calls it never invokes
8
+ * `next` — it queues the call and later performs its own single
9
+ * `POST /rpc/batch`. An explicit `runtime.batch()` call (`kind:
10
+ * "batch"`) passes straight through via `next`, since it's already
11
+ * the shape this link would otherwise build.
12
+ *
13
+ * Known limitation: the synthesized `/rpc/batch` request reuses the
14
+ * first queued call's `headers`/`fetchFn`/`codec` for the whole flush
15
+ * — per-call custom headers on later calls in the same window are not
16
+ * applied to the aggregate request. Pass shared headers via the
17
+ * runtime's own `headers` option rather than per-call
18
+ * `CratestackRpcCallOptions.headers` when using this link. Similarly,
19
+ * aborting an individual call's `AbortSignal` only cancels it if the
20
+ * flush hasn't been sent yet — it does not cancel an in-flight batch. */
21
+ export function createBatchLink(options = {}) {
22
+ const maxBatchSize = options.maxBatchSize ?? Number.POSITIVE_INFINITY;
23
+ const dedupe = options.dedupe ?? defaultDedupe;
24
+ const windowMs = options.windowMs;
25
+ const queue = [];
26
+ let flushScheduled = false;
27
+ function scheduleFlush() {
28
+ if (flushScheduled) {
29
+ return;
30
+ }
31
+ flushScheduled = true;
32
+ const run = () => {
33
+ flushScheduled = false;
34
+ flush();
35
+ };
36
+ if (windowMs === undefined) {
37
+ queueMicrotask(run);
38
+ }
39
+ else {
40
+ setTimeout(run, windowMs);
41
+ }
42
+ }
43
+ function flush() {
44
+ if (queue.length === 0) {
45
+ return;
46
+ }
47
+ const size = Math.max(1, maxBatchSize);
48
+ const batch = queue.splice(0, size);
49
+ if (queue.length > 0) {
50
+ scheduleFlush();
51
+ }
52
+ void runBatch(batch);
53
+ }
54
+ async function runBatch(entries) {
55
+ const groups = groupByDedupeKey(entries, dedupe);
56
+ const leader = entries[0].request;
57
+ const requests = groups.map((group, id) => {
58
+ const request = group.entries[0].request;
59
+ const frame = { id, op: request.opId, input: request.input };
60
+ if (request.idempotencyKey !== undefined) {
61
+ frame.idem = request.idempotencyKey;
62
+ }
63
+ return frame;
64
+ });
65
+ try {
66
+ const response = await leader.fetchFn(leader.urls.batch(), {
67
+ method: "POST",
68
+ headers: leader.headers,
69
+ body: leader.codec.encode(requests),
70
+ signal: null,
71
+ });
72
+ if (!response.ok) {
73
+ const bytes = new Uint8Array(await response.arrayBuffer().catch(() => new ArrayBuffer(0)));
74
+ for (const group of groups) {
75
+ for (const entry of group.entries) {
76
+ entry.resolve({ response: new Response(bytes, { status: response.status }) });
77
+ }
78
+ }
79
+ return;
80
+ }
81
+ const bytes = new Uint8Array(await response.arrayBuffer());
82
+ const frames = leader.codec.decode(bytes);
83
+ resolveGroups(groups, frames);
84
+ }
85
+ catch (error) {
86
+ for (const group of groups) {
87
+ for (const entry of group.entries) {
88
+ entry.reject(error);
89
+ }
90
+ }
91
+ }
92
+ }
93
+ return async (request, next) => {
94
+ if (request.kind === "batch") {
95
+ return next(request);
96
+ }
97
+ return new Promise((resolve, reject) => {
98
+ if (request.signal?.aborted) {
99
+ reject(request.signal.reason ?? new Error("aborted"));
100
+ return;
101
+ }
102
+ const entry = { request, resolve, reject };
103
+ request.signal?.addEventListener("abort", () => {
104
+ const index = queue.indexOf(entry);
105
+ // No-op once already flushed — cancelling one call after its
106
+ // batch has been sent does not cancel the network request.
107
+ if (index !== -1) {
108
+ queue.splice(index, 1);
109
+ reject(request.signal.reason ?? new Error("aborted"));
110
+ }
111
+ });
112
+ queue.push(entry);
113
+ scheduleFlush();
114
+ });
115
+ };
116
+ }
117
+ function groupByDedupeKey(entries, dedupe) {
118
+ const groups = [];
119
+ const indexByKey = new Map();
120
+ for (const entry of entries) {
121
+ const key = dedupe(entry.request);
122
+ if (key === null) {
123
+ groups.push({ key: null, entries: [entry] });
124
+ continue;
125
+ }
126
+ const existingIndex = indexByKey.get(key);
127
+ if (existingIndex === undefined) {
128
+ indexByKey.set(key, groups.length);
129
+ groups.push({ key, entries: [entry] });
130
+ }
131
+ else {
132
+ groups[existingIndex].entries.push(entry);
133
+ }
134
+ }
135
+ return groups;
136
+ }
137
+ function resolveGroups(groups, frames) {
138
+ // Correlate by `id`, not array position — the server contract
139
+ // guarantees order (docs/design/rpc-transport.md §3.2), but matching
140
+ // by id is strictly more robust and is the pattern the repo's own
141
+ // Rust client-side batch debouncer already establishes
142
+ // (examples/rpc-batch-debounce/src/lib.rs's `responders` map).
143
+ const frameById = new Map(frames.map((frame) => [frame.id, frame]));
144
+ groups.forEach((group, id) => {
145
+ const frame = frameById.get(id);
146
+ if (!frame) {
147
+ const error = new Error(`batch response is missing frame id ${id}`);
148
+ for (const entry of group.entries) {
149
+ entry.reject(error);
150
+ }
151
+ return;
152
+ }
153
+ const hasError = frame.error !== undefined;
154
+ for (const entry of group.entries) {
155
+ if (!hasError && frame.output === undefined) {
156
+ // Mirrors the unary path's `response.status === 204` shortcut
157
+ // (void-returning calls resolve `undefined`, not a decoded null).
158
+ entry.resolve({ response: new Response(null, { status: 204 }) });
159
+ continue;
160
+ }
161
+ const body = hasError ? frame.error : frame.output;
162
+ entry.resolve({
163
+ response: new Response(entry.request.codec.encode(body), {
164
+ status: hasError ? errorStatus(frame.error.code) : 200,
165
+ }),
166
+ });
167
+ }
168
+ });
169
+ }
170
+ function errorStatus(code) {
171
+ switch (code) {
172
+ case "invalid_argument":
173
+ case "failed_precondition":
174
+ return 400;
175
+ case "unauthenticated":
176
+ return 401;
177
+ case "permission_denied":
178
+ return 403;
179
+ case "not_found":
180
+ return 404;
181
+ case "conflict":
182
+ return 409;
183
+ default:
184
+ return 500;
185
+ }
186
+ }
187
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkDA,MAAM,aAAa,GAAG,CAAC,OAAuB,EAAiB,EAAE,CAC/D,OAAO,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAEjF;;;;;;;;;;;;;;;;;;0EAkB0E;AAC1E,MAAM,UAAU,eAAe,CAAC,UAA4B,EAAE;IAC5D,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,MAAM,CAAC,iBAAiB,CAAC;IACtE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC;IAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAElC,MAAM,KAAK,GAAi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AkB,CAAC;QACxB,KAAK,qBAAqB;YACxB,OAAO,GAAG,CAAC;QACb,KAAK,iBAAiB;YACpB,OAAO,GAAG,CAAC;QACb,KAAK,mBAAmB;YACtB,OAAO,GAAG,CAAC;QACb,KAAK,WAAW;YACd,OAAO,GAAG,CAAC;QACb,KAAK,UAAU;YACb,OAAO,GAAG,CAAC;QACb;YACE,OAAO,GAAG,CAAC;IACf,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@cratestack/link-batch",
3
+ "version": "0.5.2",
4
+ "description": "A batshit-style automatic batch scheduler for CrateStack's generated TypeScript RPC client, shipped as an RpcLink.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/cratestack/cratestack.git",
9
+ "directory": "packages/cratestack-link-batch"
10
+ },
11
+ "homepage": "https://cratestack.dev",
12
+ "bugs": "https://github.com/cratestack/cratestack/issues",
13
+ "keywords": ["cratestack", "cstack", "rpc", "batching", "trpc-links"],
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": ["dist", "README.md", "LICENSE"],
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.json",
27
+ "test": "vitest run",
28
+ "lint": "biome check ."
29
+ },
30
+ "dependencies": {
31
+ "@cratestack/ts-types": "0.5.2"
32
+ },
33
+ "devDependencies": {
34
+ "typescript": "^5.7.0",
35
+ "vitest": "^3.0.0"
36
+ },
37
+ "engines": {
38
+ "node": ">=18"
39
+ }
40
+ }