@estiva-app/protocol 0.14.0 → 0.15.0

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/CHANGELOG.md CHANGED
@@ -4,6 +4,56 @@ Every entry answers the wire question explicitly, including when the answer is
4
4
  nothing (ADR 0002 §4b). A change to the bytes an app publishes is a MAJOR — in
5
5
  `0.x`, a MINOR — even when no TypeScript signature moved.
6
6
 
7
+ ## 0.15.0 — 2026-09-07
8
+
9
+ **Wire behaviour: unchanged.** Nothing about what an app publishes moves, and
10
+ `queryAll`'s answer is element-for-element what it was. This is a change to how
11
+ many HTTP requests a read costs, and to nothing else.
12
+
13
+ - **New: `queryAll` asks for every filter's first page in one request.**
14
+
15
+ Ship's workspace read was **39 requests and 1015 ms** warm, measured against
16
+ production 2026-09-07 — and every one of those requests was a first page:
17
+ nothing was paging at all. Buzz meters `POST /query` per *call*
18
+ (`enforce_http_admission` runs before the filters are parsed) at 300 a minute
19
+ per pubkey, shared across every app one person has open, so the request count
20
+ was the entire cost.
21
+
22
+ The same read is now **3 requests and 568 ms**, with the folded state
23
+ byte-identical — 2,376,942 characters either way.
24
+
25
+ Three measured facts make this a transport change rather than a semantic one:
26
+ `limit` clamps **per filter** (10 filters at `limit: 5` returned 48 events,
27
+ not 5); responses **concatenate rather than dedupe** (the same filter twice in
28
+ one POST returned 236, not 118); and runs come back **grouped in filter
29
+ order**, element-for-element identical to reading them singly. `queryAll`'s
30
+ contract has always been that the answer is the serial concatenation — a
31
+ batched response simply *is* that concatenation.
32
+
33
+ - **A filter is only settled by the batch when its own run can be identified.**
34
+
35
+ Deciding "can this filter have more?" needs that filter's run length, and a
36
+ flat response only yields it when the events can be attributed. Two exact
37
+ discriminators, and between them they cover every batched read in the suite:
38
+ distinct single `#h` values (the workspace read) and pairwise-disjoint `kinds`
39
+ (the discovery pair). Anything else pages the old way, and a batch that could
40
+ prove nothing is not even sent — a cold read of unattributable filters costs
41
+ exactly what it did before.
42
+
43
+ The bar is certainty rather than likelihood: a wrong attribution would
44
+ under-count a run, call a clamped filter complete, and silently drop the rest
45
+ of a Folder. That is SHA-8, which this read path exists to prevent.
46
+
47
+ - **New: `MAX_FILTERS_PER_QUERY`, and it is measured.** 128 accepted, 129
48
+ refused with `too many explicit channels`, by binary search against production.
49
+ The relay counts filter occurrences, not distinct Folders. Batches are chunked
50
+ below it; a refused batch **fails the read** rather than being retried one
51
+ filter at a time, because the likeliest reason for a refusal is the quota and
52
+ the worst answer to that is thirty-six more requests.
53
+
54
+ - **New: `QueryAllOptions.batch`.** `false` restores the pre-0.15 shape, one
55
+ request per filter.
56
+
7
57
  ## 0.13.0 — 2026-09-03
8
58
 
9
59
  **Wire behaviour: unchanged.** Two readers over the resolved tree; nothing
package/dist/bridge.d.ts CHANGED
@@ -37,6 +37,19 @@ export interface PublishResult {
37
37
  * is the relay's real ceiling — see its note on why.
38
38
  */
39
39
  export declare const RELAY_PAGE_CEILING = 1000;
40
+ /**
41
+ * The most filters one `POST /query` will carry.
42
+ *
43
+ * Measured against production 2026-09-07 by binary search: **128 accepted, 129
44
+ * refused** with `too many explicit channels`. The relay counts filter
45
+ * *occurrences*, not distinct Folders — 300 filters over 36 Folders is refused
46
+ * just the same — so the bound is on the array's length and nothing else.
47
+ *
48
+ * Like {@link RELAY_PAGE_CEILING} this is a property of the relay rather than
49
+ * of this client, and it is a *page size, not a promise*: a batch that is
50
+ * refused falls back rather than assuming this number is still right.
51
+ */
52
+ export declare const MAX_FILTERS_PER_QUERY = 128;
40
53
  /**
41
54
  * How many of a {@link Relay.queryAll} call's filters may be in flight at once.
42
55
  *
@@ -78,6 +91,14 @@ export interface QueryAllOptions {
78
91
  maxPages?: number;
79
92
  /** Filters in flight at once. Defaults to {@link DEFAULT_QUERY_CONCURRENCY}; 1 is serial. */
80
93
  concurrency?: number;
94
+ /**
95
+ * Ask for every filter's first page in one request. On by default.
96
+ *
97
+ * `false` restores the pre-PER-1 shape — one request per filter — which is
98
+ * what the paging tests drive, and what a caller wants if it has reason to
99
+ * distrust the relay's per-filter clamp.
100
+ */
101
+ batch?: boolean;
81
102
  }
82
103
  export declare function parsePublishResponse(status: number, text: string): PublishResult;
83
104
  export interface QueryResult {
@@ -125,13 +146,6 @@ export interface RelayOptions {
125
146
  /** Override the transport. Defaults to the runtime's `fetch`. */
126
147
  fetch?: FetchLike;
127
148
  }
128
- /**
129
- * A relay client that signs its own NIP-98 auth.
130
- *
131
- * Takes a {@link Signer} rather than a key or a token, which is what lets the
132
- * same class serve a script holding a secret key and a browser signing through a
133
- * remote service.
134
- */
135
149
  export declare class Relay {
136
150
  private readonly url;
137
151
  private readonly signer;
@@ -199,6 +213,31 @@ export declare class Relay {
199
213
  * lowest-indexed filter's error rather than whichever lost the race.
200
214
  */
201
215
  queryAll(filters: Record<string, unknown>[], options?: QueryAllOptions): Promise<SignedEvent[]>;
216
+ /**
217
+ * Every filter's first page, in as few requests as the relay will allow.
218
+ *
219
+ * Fills `perFilter` for each filter it can prove complete and removes it from
220
+ * `unresolved`; everything else is left for {@link Relay.pageFilter}, which is
221
+ * unchanged and remains the only thing that pages.
222
+ *
223
+ * **Proving a filter complete needs its own run's length**, and a flat
224
+ * response only yields that if the events can be attributed. Two ways, and
225
+ * the code takes whichever applies:
226
+ *
227
+ * 1. **By `h` tag**, when every filter in the chunk names exactly one Folder
228
+ * and no two name the same one. Exact — an event carries the Folder it is
229
+ * in — and it is the shape every workspace read in the suite actually
230
+ * sends.
231
+ * 2. **By the total**, otherwise. If the whole chunk came back under the
232
+ * largest page this relay has ever produced, no single run reached that
233
+ * bound either, so none was clamped. Weaker, and it cannot fire on a cold
234
+ * `Relay` that has no evidence yet — deliberately, per SHA-15.
235
+ *
236
+ * When neither applies the chunk is simply left unresolved: one request is
237
+ * spent and the old path runs, which is a cost in requests and never in
238
+ * correctness.
239
+ */
240
+ private batchFirstPages;
202
241
  /**
203
242
  * One filter, paged to exhaustion. The sequential half, and it has to be:
204
243
  * `until` is a cursor, so page N+1's request is not known until page N has
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,OAAO,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,wDAAwD;IACxD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;;GAQG;AACH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,yBAAyB,IAAI,CAAA;AAE1C,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,6FAA6F;IAC7F,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAehF;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAA;IACX,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,wDAAwD;AACxD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAgB5E;AAED;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,CACtB,GAAG,EAAE,M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CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAOvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACG,QAAQ,CACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAClC,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,WAAW,EAAE,CAAC;IA0GzB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;YACW,eAAe;IA+E7B;;;;;OAKG;YACW,UAAU;CA2EzB"}
package/dist/bridge.js CHANGED
@@ -53,6 +53,19 @@ import { authorizationHeader } from './nip98.js';
53
53
  * is the relay's real ceiling — see its note on why.
54
54
  */
55
55
  export const RELAY_PAGE_CEILING = 1000;
56
+ /**
57
+ * The most filters one `POST /query` will carry.
58
+ *
59
+ * Measured against production 2026-09-07 by binary search: **128 accepted, 129
60
+ * refused** with `too many explicit channels`. The relay counts filter
61
+ * *occurrences*, not distinct Folders — 300 filters over 36 Folders is refused
62
+ * just the same — so the bound is on the array's length and nothing else.
63
+ *
64
+ * Like {@link RELAY_PAGE_CEILING} this is a property of the relay rather than
65
+ * of this client, and it is a *page size, not a promise*: a batch that is
66
+ * refused falls back rather than assuming this number is still right.
67
+ */
68
+ export const MAX_FILTERS_PER_QUERY = 128;
56
69
  /**
57
70
  * How many of a {@link Relay.queryAll} call's filters may be in flight at once.
58
71
  *
@@ -124,13 +137,60 @@ export function parseQueryResponse(status, text) {
124
137
  return { ok: false, events: [], reason: `unparseable response: ${text.slice(0, 200)}`, httpStatus: status };
125
138
  }
126
139
  }
127
- /**
128
- * A relay client that signs its own NIP-98 auth.
129
- *
130
- * Takes a {@link Signer} rather than a key or a token, which is what lets the
131
- * same class serve a script holding a secret key and a browser signing through a
132
- * remote service.
133
- */
140
+ function byFolder(filters) {
141
+ const slot = new Map();
142
+ for (const [index, filter] of filters.entries()) {
143
+ const h = filter['#h'];
144
+ if (!Array.isArray(h) || h.length !== 1 || typeof h[0] !== 'string')
145
+ return null;
146
+ if (slot.has(h[0]))
147
+ return null;
148
+ slot.set(h[0], index);
149
+ }
150
+ return (event) => {
151
+ let found = null;
152
+ for (const tag of event.tags) {
153
+ if (tag[0] !== 'h' || typeof tag[1] !== 'string')
154
+ continue;
155
+ const candidate = slot.get(tag[1]);
156
+ if (candidate === undefined)
157
+ continue;
158
+ // Two `h` tags naming two different filters: no answer exists.
159
+ if (found !== null && found !== candidate)
160
+ return null;
161
+ found = candidate;
162
+ }
163
+ return found;
164
+ };
165
+ }
166
+ function byKind(filters) {
167
+ const slot = new Map();
168
+ for (const [index, filter] of filters.entries()) {
169
+ const kinds = filter.kinds;
170
+ if (!Array.isArray(kinds) || kinds.length === 0)
171
+ return null;
172
+ for (const kind of kinds) {
173
+ if (typeof kind !== 'number' || slot.has(kind))
174
+ return null;
175
+ slot.set(kind, index);
176
+ }
177
+ }
178
+ return (event) => slot.get(event.kind) ?? null;
179
+ }
180
+ function discriminate(filters) {
181
+ return byFolder(filters) ?? byKind(filters);
182
+ }
183
+ /** The batched response split into one run per filter, or `null` if any event is unclaimed. */
184
+ function splitRuns(count, events, which) {
185
+ const runs = Array.from({ length: count }, () => []);
186
+ for (const event of events) {
187
+ const index = which(event);
188
+ if (index === null)
189
+ return null;
190
+ runs[index].push(event);
191
+ }
192
+ return runs;
193
+ }
134
194
  export class Relay {
135
195
  url;
136
196
  signer;
@@ -253,6 +313,44 @@ export class Relay {
253
313
  */
254
314
  const perFilter = new Array(filters.length);
255
315
  const failures = new Array(filters.length);
316
+ /*
317
+ One request for every filter's first page, before any of them is paged.
318
+
319
+ The old shape spent one HTTP request per filter, and that is the unit the
320
+ relay meters: `enforce_http_admission` runs on the *call*, before the
321
+ filters are even parsed, at 300 a minute shared across every app one
322
+ person has open. Measured on Ship's `loadAll` against production
323
+ 2026-09-07: **39 requests and 1015 ms warm, 2.83 MiB down**, of which
324
+ every single request was a first page — nothing was paging at all.
325
+
326
+ What makes this safe rather than merely cheaper is that `POST /query`
327
+ **concatenates per filter, in filter order, and clamps `limit` per
328
+ filter** — all three measured, not assumed:
329
+
330
+ - 10 filters at `limit: 5` returned 48 events, not 5.
331
+ - The same filter twice in one POST returned 236 events, not 118: the
332
+ relay does not dedupe across filters, so a run's length is its own.
333
+ - Three Folder filters batched came back element-for-element identical to
334
+ the same three read one at a time.
335
+
336
+ That last one is the whole argument. `queryAll`'s contract is that the
337
+ answer is the serial concatenation; a batched response *is* that
338
+ concatenation, so this is a transport change and not a semantic one.
339
+ */
340
+ const unresolved = new Set(filters.map((_, index) => index));
341
+ /*
342
+ A filter the batch could not settle keeps its first page anyway: it is
343
+ handed back as a seed so `pageFilter` resumes from that page's cursor
344
+ instead of asking for it a second time. Without this the widest filter —
345
+ which ties its own bound on every read and so is never settled — would pay
346
+ for its first page twice, and the widest filter is the one every workspace
347
+ read has.
348
+ */
349
+ const seeds = new Array(filters.length);
350
+ if (options.batch !== false && filters.length > 1) {
351
+ await this.batchFirstPages(filters, pageSize, perFilter, unresolved, seeds);
352
+ }
353
+ const remaining = [...unresolved];
256
354
  let next = 0;
257
355
  let failed = false;
258
356
  const worker = async () => {
@@ -262,11 +360,12 @@ export class Relay {
262
360
  // a broken read from firing the whole remaining queue at the relay.
263
361
  if (failed)
264
362
  return;
265
- const index = next++;
266
- if (index >= filters.length)
363
+ const slot = next++;
364
+ if (slot >= remaining.length)
267
365
  return;
366
+ const index = remaining[slot];
268
367
  try {
269
- perFilter[index] = await this.pageFilter(filters[index], pageSize, maxPages);
368
+ perFilter[index] = await this.pageFilter(filters[index], pageSize, maxPages, seeds[index]);
270
369
  }
271
370
  catch (error) {
272
371
  failures[index] = error;
@@ -275,7 +374,7 @@ export class Relay {
275
374
  }
276
375
  }
277
376
  };
278
- await Promise.all(Array.from({ length: Math.min(concurrency, filters.length) }, () => worker()));
377
+ await Promise.all(Array.from({ length: Math.min(concurrency, remaining.length) }, () => worker()));
279
378
  /*
280
379
  The lowest-indexed failure, not the first to reject in wall-clock time.
281
380
 
@@ -299,15 +398,124 @@ export class Relay {
299
398
  }
300
399
  return out;
301
400
  }
401
+ /**
402
+ * Every filter's first page, in as few requests as the relay will allow.
403
+ *
404
+ * Fills `perFilter` for each filter it can prove complete and removes it from
405
+ * `unresolved`; everything else is left for {@link Relay.pageFilter}, which is
406
+ * unchanged and remains the only thing that pages.
407
+ *
408
+ * **Proving a filter complete needs its own run's length**, and a flat
409
+ * response only yields that if the events can be attributed. Two ways, and
410
+ * the code takes whichever applies:
411
+ *
412
+ * 1. **By `h` tag**, when every filter in the chunk names exactly one Folder
413
+ * and no two name the same one. Exact — an event carries the Folder it is
414
+ * in — and it is the shape every workspace read in the suite actually
415
+ * sends.
416
+ * 2. **By the total**, otherwise. If the whole chunk came back under the
417
+ * largest page this relay has ever produced, no single run reached that
418
+ * bound either, so none was clamped. Weaker, and it cannot fire on a cold
419
+ * `Relay` that has no evidence yet — deliberately, per SHA-15.
420
+ *
421
+ * When neither applies the chunk is simply left unresolved: one request is
422
+ * spent and the old path runs, which is a cost in requests and never in
423
+ * correctness.
424
+ */
425
+ async batchFirstPages(filters, pageSize, perFilter, unresolved, seeds) {
426
+ for (let start = 0; start < filters.length; start += MAX_FILTERS_PER_QUERY) {
427
+ const indices = filters
428
+ .slice(start, start + MAX_FILTERS_PER_QUERY)
429
+ .map((_, offset) => start + offset);
430
+ if (indices.length < 2)
431
+ continue;
432
+ /*
433
+ Do not spend a request on a batch whose answer could not be used.
434
+
435
+ Both proofs can be checked before asking: attribution is a property of
436
+ the filters alone, and the total rule needs a ceiling this `Relay` has
437
+ actually observed. With neither available the batch would cost one
438
+ request and resolve nothing — a real regression for a cold read of
439
+ filters that carry no `#h`, which is Ship's own discovery pair.
440
+ */
441
+ const which = discriminate(indices.map((i) => filters[i]));
442
+ if (!which && this.observedPageCeiling === 0)
443
+ continue;
444
+ /*
445
+ A refused batch fails the whole read. It is **not** caught and retried
446
+ one filter at a time.
447
+
448
+ Falling back would be the friendlier-looking choice and it is the wrong
449
+ one: the most likely reason a batch is refused is the quota, and the
450
+ single worst response to being told to slow down is to turn one request
451
+ into another thirty-six. `queryAll` already refuses to fire the rest of
452
+ a queue once a filter has failed; this is that same rule for the batch.
453
+
454
+ The cost is error *identity* — a caller sees the batch's error rather
455
+ than the lowest-indexed filter's. For a transport refusal, which is
456
+ what this path actually meets, those are the same error.
457
+ */
458
+ const events = await this.query(indices.map((i) => ({ ...filters[i], limit: pageSize })));
459
+ const runs = which ? splitRuns(indices.length, events, which) : null;
460
+ if (runs) {
461
+ /*
462
+ Update the observed ceiling from each run *before* testing it, exactly
463
+ as `pageFilter` does — so the widest filter ties its own bound and is
464
+ left to confirm itself rather than being declared complete.
465
+
466
+ Never from the chunk total. That number is the sum of several runs,
467
+ and a bound raised above what the relay actually produced would make a
468
+ genuinely clamped page look short — SHA-8, reintroduced through the
469
+ back door.
470
+ */
471
+ for (const run of runs) {
472
+ if (run.length > this.observedPageCeiling)
473
+ this.observedPageCeiling = run.length;
474
+ }
475
+ for (const [offset, run] of runs.entries()) {
476
+ if (run.length < pageSize && run.length < this.observedPageCeiling) {
477
+ perFilter[indices[offset]] = run;
478
+ unresolved.delete(indices[offset]);
479
+ }
480
+ else {
481
+ seeds[indices[offset]] = run;
482
+ }
483
+ }
484
+ continue;
485
+ }
486
+ if (events.length < pageSize && events.length < this.observedPageCeiling) {
487
+ // No run can exceed the total, so no run reached the ceiling. The
488
+ // response is already the serial concatenation, so it can be adopted
489
+ // whole: the first slot carries it and the rest are empty, which
490
+ // concatenates to exactly the same array.
491
+ perFilter[indices[0]] = events;
492
+ for (const index of indices.slice(1))
493
+ perFilter[index] = [];
494
+ for (const index of indices)
495
+ unresolved.delete(index);
496
+ }
497
+ }
498
+ }
302
499
  /**
303
500
  * One filter, paged to exhaustion. The sequential half, and it has to be:
304
501
  * `until` is a cursor, so page N+1's request is not known until page N has
305
502
  * answered. Only the filters are independent, which is why they are the
306
503
  * axis {@link Relay.queryAll} parallelises.
307
504
  */
308
- async pageFilter(filter, pageSize, maxPages) {
505
+ async pageFilter(filter, pageSize, maxPages, seed) {
309
506
  const out = [];
310
507
  let until;
508
+ /*
509
+ `seed` is this filter's first page, already fetched in the batch and
510
+ already judged inconclusive there — so the completeness test is not
511
+ repeated here, only the cursor is taken from it. The request that produced
512
+ it is the one this loop would otherwise make first: same filter, same
513
+ `limit`, no `until`.
514
+ */
515
+ if (seed && seed.length > 0) {
516
+ out.push(...seed);
517
+ until = Math.min(...seed.map((e) => e.created_at));
518
+ }
311
519
  for (let page = 0;; page++) {
312
520
  if (page >= maxPages) {
313
521
  throw new Error(`queryAll: gave up after ${maxPages} pages — refusing to return a partial set`);
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAchD;;;;;;;;GAQG;AACH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAA;AAW1C,MAAM,UAAU,oBAAoB,CAAC,MAAc,EAAE,IAAY;IAC/D,IAAI,MAAmF,CAAA;IACvF,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,yBAAyB,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;IACjG,CAAC;IACD,IAAI,MAAM,GAAG,GAAG,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC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K,EAAE,QAAQ,EAAE,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;aAC1E,CAAC,CAAA;YACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,MAAK;YAC9B,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAA;YAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;cA2BE;YACF,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,mBAAmB;gBAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAA;YACtF,IAAI,MAAM,CAAC,MAAM,GAAG,QAAQ,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,mBAAmB;gBAAE,MAAK;YAE/E,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;YAC3D,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;gBAC3C,IAAI,MAAM,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CACb,uBAAuB,QAAQ,4BAA4B,KAAK,iCAAiC,CAClG,CAAA;gBACH,CAAC;gBACD,MAAK;YACP,CAAC;YACD,KAAK,GAAG,MAAM,CAAA;QAChB,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -46,12 +46,12 @@
46
46
  /** Bumped by hand with the version in package.json — `test/version.test.ts`
47
47
  * pins the two together. It exists so "the upgrade reached the app" can be
48
48
  * checked by grepping a built bundle rather than by trusting a lockfile. */
49
- export declare const PROTOCOL_VERSION = "0.14.0";
49
+ export declare const PROTOCOL_VERSION = "0.15.0";
50
50
  export { type NostrTag, type UnsignedEvent, type SignedEvent, type Profile, type ThreadRef, type ChannelVisibility, type ChannelKind, type MemberRole, type Label, type ResolutionAction, KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE, computeEventId, toNostrSeconds, canonicalChannelName, threadTags, addr, relayAuthUrl, buildProfile, parseProfile, buildCreateChannel, buildDeleteChannel, buildEditChannelMetadata, buildAddMember, buildReaction, buildDeletion, buildEdit, buildMessage, buildResolution, buildFile, buildComponent, buildHighlight, buildUnsignedRelayAuthEvent, } from './events.js';
51
51
  export { type AddressPointer, type EventPointer, encodeNevent, decodeNevent, convertBits, bech32Encode, bech32Decode, encodeNaddr, decodeNaddr, pointerToAddress, addressToPointer, addrToNaddr, naddrToAddr, referenceToPointer, NADDR_RE, findNaddrs, stripNaddrs, encodeNpub, decodeNpub, NOSTR_URI_RE, findNostrUris, } from './nip19.js';
52
52
  export { type AuthEventArgs, TIMESTAMP_TOLERANCE_SECS, normalizeUrl, buildUnsignedAuthEvent, base64, authorizationHeaderFor, authorizationHeader, } from './nip98.js';
53
53
  export { type Signer, type SignerKind, publicKeyFromSecret, signEvent, secretKeySigner, } from './sign.js';
54
- export { type PublishResult, type QueryResult, type RelayHeaders, type RelayOptions, type FetchLike, type QueryAllOptions, parsePublishResponse, parseQueryResponse, RELAY_PAGE_CEILING, DEFAULT_QUERY_CONCURRENCY, Relay, } from './bridge.js';
54
+ export { type PublishResult, type QueryResult, type RelayHeaders, type RelayOptions, type FetchLike, type QueryAllOptions, parsePublishResponse, parseQueryResponse, RELAY_PAGE_CEILING, DEFAULT_QUERY_CONCURRENCY, MAX_FILTERS_PER_QUERY, Relay, } from './bridge.js';
55
55
  export { type RelayState, type SocketLike, type RelayCredential, type LiveRelayOptions, type Subscription, type LiveRelay, toWebSocketUrl, parseFrame, createLiveRelay, } from './live.js';
56
56
  export { type ChannelEventHandler, type ChannelSubscription, type ChannelSubscriptions, createChannelSubscriptions, } from './subscriptions.js';
57
57
  export { type InlineMark, type InlineMarkSpan, type BodySegment, type InlineMarkNode, type InlineTextNode, parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, markersToInlineNodes, inlineNodesToMarkers, inlineNodesToText, } from './content.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,gBAAgB,EAErB,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAEjB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY,EAEZ,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,aAAa,EACb,SAAS,EACT,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,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,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,KAAK,WAAW,EAChB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,gBAAgB,EAErB,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAEjB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY,EAEZ,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,aAAa,EACb,SAAS,EACT,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EAC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AkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,KAAK,WAAW,EAChB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@
46
46
  /** Bumped by hand with the version in package.json — `test/version.test.ts`
47
47
  * pins the two together. It exists so "the upgrade reached the app" can be
48
48
  * checked by grepping a built bundle rather than by trusting a lockfile. */
49
- export const PROTOCOL_VERSION = '0.14.0';
49
+ export const PROTOCOL_VERSION = '0.15.0';
50
50
  export {
51
51
  // constants
52
52
  KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE,
@@ -57,7 +57,7 @@ buildProfile, parseProfile, buildCreateChannel, buildDeleteChannel, buildEditCha
57
57
  export { encodeNevent, decodeNevent, convertBits, bech32Encode, bech32Decode, encodeNaddr, decodeNaddr, pointerToAddress, addressToPointer, addrToNaddr, naddrToAddr, referenceToPointer, NADDR_RE, findNaddrs, stripNaddrs, encodeNpub, decodeNpub, NOSTR_URI_RE, findNostrUris, } from './nip19.js';
58
58
  export { TIMESTAMP_TOLERANCE_SECS, normalizeUrl, buildUnsignedAuthEvent, base64, authorizationHeaderFor, authorizationHeader, } from './nip98.js';
59
59
  export { publicKeyFromSecret, signEvent, secretKeySigner, } from './sign.js';
60
- export { parsePublishResponse, parseQueryResponse, RELAY_PAGE_CEILING, DEFAULT_QUERY_CONCURRENCY, Relay, } from './bridge.js';
60
+ export { parsePublishResponse, parseQueryResponse, RELAY_PAGE_CEILING, DEFAULT_QUERY_CONCURRENCY, MAX_FILTERS_PER_QUERY, Relay, } from './bridge.js';
61
61
  export { toWebSocketUrl, parseFrame, createLiveRelay, } from './live.js';
62
62
  export { createChannelSubscriptions, } from './subscriptions.js';
63
63
  export { parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, markersToInlineNodes, inlineNodesToMarkers, inlineNodesToText, } from './content.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAA;AAExC,OAAO;AAYL,YAAY;AACZ,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB;AACjB,8CAA8C;AAC9C,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY;AACZ,WAAW;AACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,aAAa,EACb,SAAS,EACT,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EAGL,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,GACd,MAAM,YAAY,CAAA;AAEnB,OAAO,EAEL,wBAAwB,EACxB,YAAY,EACZ,sBAAsB,EACtB,MAAM,EACN,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAGL,mBAAmB,EACnB,SAAS,EACT,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EAOL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,KAAK,GACN,MAAM,aAAa,CAAA;AAEpB,OAAO,EAOL,cAAc,EACd,UAAU,EACV,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EAIL,0BAA0B,GAC3B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAML,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EAIL,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EAKL,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;A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AiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EAIL,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EAKL,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/protocol",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "The Estiva wire format: Buzz-shaped Nostr event builders, NIP-01 ids, NIP-19 naddr, NIP-98 HTTP auth, and the relay clients. Speaks the protocol; interprets nothing.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/bridge.ts CHANGED
@@ -67,6 +67,20 @@ export interface PublishResult {
67
67
  */
68
68
  export const RELAY_PAGE_CEILING = 1000
69
69
 
70
+ /**
71
+ * The most filters one `POST /query` will carry.
72
+ *
73
+ * Measured against production 2026-09-07 by binary search: **128 accepted, 129
74
+ * refused** with `too many explicit channels`. The relay counts filter
75
+ * *occurrences*, not distinct Folders — 300 filters over 36 Folders is refused
76
+ * just the same — so the bound is on the array's length and nothing else.
77
+ *
78
+ * Like {@link RELAY_PAGE_CEILING} this is a property of the relay rather than
79
+ * of this client, and it is a *page size, not a promise*: a batch that is
80
+ * refused falls back rather than assuming this number is still right.
81
+ */
82
+ export const MAX_FILTERS_PER_QUERY = 128
83
+
70
84
  /**
71
85
  * How many of a {@link Relay.queryAll} call's filters may be in flight at once.
72
86
  *
@@ -109,6 +123,14 @@ export interface QueryAllOptions {
109
123
  maxPages?: number
110
124
  /** Filters in flight at once. Defaults to {@link DEFAULT_QUERY_CONCURRENCY}; 1 is serial. */
111
125
  concurrency?: number
126
+ /**
127
+ * Ask for every filter's first page in one request. On by default.
128
+ *
129
+ * `false` restores the pre-PER-1 shape — one request per filter — which is
130
+ * what the paging tests drive, and what a caller wants if it has reason to
131
+ * distrust the relay's per-filter clamp.
132
+ */
133
+ batch?: boolean
112
134
  }
113
135
 
114
136
  export function parsePublishResponse(status: number, text: string): PublishResult {
@@ -200,6 +222,83 @@ export interface RelayOptions {
200
222
  * same class serve a script holding a secret key and a browser signing through a
201
223
  * remote service.
202
224
  */
225
+ /**
226
+ * A function saying which filter of a batch an event came from, or `null` when
227
+ * that cannot be decided with certainty.
228
+ *
229
+ * Two discriminators, both exact, and between them they cover every batched
230
+ * read the suite performs:
231
+ *
232
+ * - **`#h`**, when every filter names exactly one Folder and no two name the
233
+ * same. A filter asking for Folder A cannot match an event that is not in A,
234
+ * so the event's own `h` tag is the answer. This is the workspace read.
235
+ * - **`kinds`**, when every filter names a non-empty kind list and no kind
236
+ * appears in two of them. Then the event's `kind` is the answer, whatever
237
+ * else the filters constrain — extra constraints only ever narrow a filter,
238
+ * they cannot make it match a kind it did not ask for. This is the discovery
239
+ * pair, `{kinds:[30850]}` and `{kinds:[30851]}`.
240
+ *
241
+ * Anything else returns `null` and the chunk is paged the old way. The bar is
242
+ * "certain", not "usually right": a wrong attribution under-counts a run,
243
+ * declares a clamped filter complete, and silently drops the rest of a Folder —
244
+ * the exact bug this read path exists to prevent.
245
+ */
246
+ type Discriminator = (event: SignedEvent) => number | null
247
+
248
+ function byFolder(filters: Record<string, unknown>[]): Discriminator | null {
249
+ const slot = new Map<string, number>()
250
+ for (const [index, filter] of filters.entries()) {
251
+ const h = filter['#h']
252
+ if (!Array.isArray(h) || h.length !== 1 || typeof h[0] !== 'string') return null
253
+ if (slot.has(h[0])) return null
254
+ slot.set(h[0], index)
255
+ }
256
+ return (event) => {
257
+ let found: number | null = null
258
+ for (const tag of event.tags) {
259
+ if (tag[0] !== 'h' || typeof tag[1] !== 'string') continue
260
+ const candidate = slot.get(tag[1])
261
+ if (candidate === undefined) continue
262
+ // Two `h` tags naming two different filters: no answer exists.
263
+ if (found !== null && found !== candidate) return null
264
+ found = candidate
265
+ }
266
+ return found
267
+ }
268
+ }
269
+
270
+ function byKind(filters: Record<string, unknown>[]): Discriminator | null {
271
+ const slot = new Map<number, number>()
272
+ for (const [index, filter] of filters.entries()) {
273
+ const kinds = filter.kinds
274
+ if (!Array.isArray(kinds) || kinds.length === 0) return null
275
+ for (const kind of kinds) {
276
+ if (typeof kind !== 'number' || slot.has(kind)) return null
277
+ slot.set(kind, index)
278
+ }
279
+ }
280
+ return (event) => slot.get(event.kind) ?? null
281
+ }
282
+
283
+ function discriminate(filters: Record<string, unknown>[]): Discriminator | null {
284
+ return byFolder(filters) ?? byKind(filters)
285
+ }
286
+
287
+ /** The batched response split into one run per filter, or `null` if any event is unclaimed. */
288
+ function splitRuns(
289
+ count: number,
290
+ events: SignedEvent[],
291
+ which: Discriminator,
292
+ ): SignedEvent[][] | null {
293
+ const runs: SignedEvent[][] = Array.from({ length: count }, () => [])
294
+ for (const event of events) {
295
+ const index = which(event)
296
+ if (index === null) return null
297
+ runs[index].push(event)
298
+ }
299
+ return runs
300
+ }
301
+
203
302
  export class Relay {
204
303
  private readonly url: string
205
304
  private readonly signer: Signer
@@ -331,6 +430,45 @@ export class Relay {
331
430
  const perFilter: SignedEvent[][] = new Array(filters.length)
332
431
  const failures: unknown[] = new Array(filters.length)
333
432
 
433
+ /*
434
+ One request for every filter's first page, before any of them is paged.
435
+
436
+ The old shape spent one HTTP request per filter, and that is the unit the
437
+ relay meters: `enforce_http_admission` runs on the *call*, before the
438
+ filters are even parsed, at 300 a minute shared across every app one
439
+ person has open. Measured on Ship's `loadAll` against production
440
+ 2026-09-07: **39 requests and 1015 ms warm, 2.83 MiB down**, of which
441
+ every single request was a first page — nothing was paging at all.
442
+
443
+ What makes this safe rather than merely cheaper is that `POST /query`
444
+ **concatenates per filter, in filter order, and clamps `limit` per
445
+ filter** — all three measured, not assumed:
446
+
447
+ - 10 filters at `limit: 5` returned 48 events, not 5.
448
+ - The same filter twice in one POST returned 236 events, not 118: the
449
+ relay does not dedupe across filters, so a run's length is its own.
450
+ - Three Folder filters batched came back element-for-element identical to
451
+ the same three read one at a time.
452
+
453
+ That last one is the whole argument. `queryAll`'s contract is that the
454
+ answer is the serial concatenation; a batched response *is* that
455
+ concatenation, so this is a transport change and not a semantic one.
456
+ */
457
+ const unresolved = new Set<number>(filters.map((_, index) => index))
458
+ /*
459
+ A filter the batch could not settle keeps its first page anyway: it is
460
+ handed back as a seed so `pageFilter` resumes from that page's cursor
461
+ instead of asking for it a second time. Without this the widest filter —
462
+ which ties its own bound on every read and so is never settled — would pay
463
+ for its first page twice, and the widest filter is the one every workspace
464
+ read has.
465
+ */
466
+ const seeds: (SignedEvent[] | undefined)[] = new Array(filters.length)
467
+ if (options.batch !== false && filters.length > 1) {
468
+ await this.batchFirstPages(filters, pageSize, perFilter, unresolved, seeds)
469
+ }
470
+
471
+ const remaining = [...unresolved]
334
472
  let next = 0
335
473
  let failed = false
336
474
 
@@ -340,10 +478,11 @@ export class Relay {
340
478
  // reached them at all; this is as close as a fan-out gets, and it keeps
341
479
  // a broken read from firing the whole remaining queue at the relay.
342
480
  if (failed) return
343
- const index = next++
344
- if (index >= filters.length) return
481
+ const slot = next++
482
+ if (slot >= remaining.length) return
483
+ const index = remaining[slot]
345
484
  try {
346
- perFilter[index] = await this.pageFilter(filters[index], pageSize, maxPages)
485
+ perFilter[index] = await this.pageFilter(filters[index], pageSize, maxPages, seeds[index])
347
486
  } catch (error) {
348
487
  failures[index] = error
349
488
  failed = true
@@ -353,7 +492,7 @@ export class Relay {
353
492
  }
354
493
 
355
494
  await Promise.all(
356
- Array.from({ length: Math.min(concurrency, filters.length) }, () => worker()),
495
+ Array.from({ length: Math.min(concurrency, remaining.length) }, () => worker()),
357
496
  )
358
497
 
359
498
  /*
@@ -379,6 +518,109 @@ export class Relay {
379
518
  return out
380
519
  }
381
520
 
521
+ /**
522
+ * Every filter's first page, in as few requests as the relay will allow.
523
+ *
524
+ * Fills `perFilter` for each filter it can prove complete and removes it from
525
+ * `unresolved`; everything else is left for {@link Relay.pageFilter}, which is
526
+ * unchanged and remains the only thing that pages.
527
+ *
528
+ * **Proving a filter complete needs its own run's length**, and a flat
529
+ * response only yields that if the events can be attributed. Two ways, and
530
+ * the code takes whichever applies:
531
+ *
532
+ * 1. **By `h` tag**, when every filter in the chunk names exactly one Folder
533
+ * and no two name the same one. Exact — an event carries the Folder it is
534
+ * in — and it is the shape every workspace read in the suite actually
535
+ * sends.
536
+ * 2. **By the total**, otherwise. If the whole chunk came back under the
537
+ * largest page this relay has ever produced, no single run reached that
538
+ * bound either, so none was clamped. Weaker, and it cannot fire on a cold
539
+ * `Relay` that has no evidence yet — deliberately, per SHA-15.
540
+ *
541
+ * When neither applies the chunk is simply left unresolved: one request is
542
+ * spent and the old path runs, which is a cost in requests and never in
543
+ * correctness.
544
+ */
545
+ private async batchFirstPages(
546
+ filters: Record<string, unknown>[],
547
+ pageSize: number,
548
+ perFilter: SignedEvent[][],
549
+ unresolved: Set<number>,
550
+ seeds: (SignedEvent[] | undefined)[],
551
+ ): Promise<void> {
552
+ for (let start = 0; start < filters.length; start += MAX_FILTERS_PER_QUERY) {
553
+ const indices = filters
554
+ .slice(start, start + MAX_FILTERS_PER_QUERY)
555
+ .map((_, offset) => start + offset)
556
+ if (indices.length < 2) continue
557
+
558
+ /*
559
+ Do not spend a request on a batch whose answer could not be used.
560
+
561
+ Both proofs can be checked before asking: attribution is a property of
562
+ the filters alone, and the total rule needs a ceiling this `Relay` has
563
+ actually observed. With neither available the batch would cost one
564
+ request and resolve nothing — a real regression for a cold read of
565
+ filters that carry no `#h`, which is Ship's own discovery pair.
566
+ */
567
+ const which = discriminate(indices.map((i) => filters[i]))
568
+ if (!which && this.observedPageCeiling === 0) continue
569
+
570
+ /*
571
+ A refused batch fails the whole read. It is **not** caught and retried
572
+ one filter at a time.
573
+
574
+ Falling back would be the friendlier-looking choice and it is the wrong
575
+ one: the most likely reason a batch is refused is the quota, and the
576
+ single worst response to being told to slow down is to turn one request
577
+ into another thirty-six. `queryAll` already refuses to fire the rest of
578
+ a queue once a filter has failed; this is that same rule for the batch.
579
+
580
+ The cost is error *identity* — a caller sees the batch's error rather
581
+ than the lowest-indexed filter's. For a transport refusal, which is
582
+ what this path actually meets, those are the same error.
583
+ */
584
+ const events = await this.query(indices.map((i) => ({ ...filters[i], limit: pageSize })))
585
+
586
+ const runs = which ? splitRuns(indices.length, events, which) : null
587
+ if (runs) {
588
+ /*
589
+ Update the observed ceiling from each run *before* testing it, exactly
590
+ as `pageFilter` does — so the widest filter ties its own bound and is
591
+ left to confirm itself rather than being declared complete.
592
+
593
+ Never from the chunk total. That number is the sum of several runs,
594
+ and a bound raised above what the relay actually produced would make a
595
+ genuinely clamped page look short — SHA-8, reintroduced through the
596
+ back door.
597
+ */
598
+ for (const run of runs) {
599
+ if (run.length > this.observedPageCeiling) this.observedPageCeiling = run.length
600
+ }
601
+ for (const [offset, run] of runs.entries()) {
602
+ if (run.length < pageSize && run.length < this.observedPageCeiling) {
603
+ perFilter[indices[offset]] = run
604
+ unresolved.delete(indices[offset])
605
+ } else {
606
+ seeds[indices[offset]] = run
607
+ }
608
+ }
609
+ continue
610
+ }
611
+
612
+ if (events.length < pageSize && events.length < this.observedPageCeiling) {
613
+ // No run can exceed the total, so no run reached the ceiling. The
614
+ // response is already the serial concatenation, so it can be adopted
615
+ // whole: the first slot carries it and the rest are empty, which
616
+ // concatenates to exactly the same array.
617
+ perFilter[indices[0]] = events
618
+ for (const index of indices.slice(1)) perFilter[index] = []
619
+ for (const index of indices) unresolved.delete(index)
620
+ }
621
+ }
622
+ }
623
+
382
624
  /**
383
625
  * One filter, paged to exhaustion. The sequential half, and it has to be:
384
626
  * `until` is a cursor, so page N+1's request is not known until page N has
@@ -389,9 +631,21 @@ export class Relay {
389
631
  filter: Record<string, unknown>,
390
632
  pageSize: number,
391
633
  maxPages: number,
634
+ seed?: SignedEvent[],
392
635
  ): Promise<SignedEvent[]> {
393
636
  const out: SignedEvent[] = []
394
637
  let until: number | undefined
638
+ /*
639
+ `seed` is this filter's first page, already fetched in the batch and
640
+ already judged inconclusive there — so the completeness test is not
641
+ repeated here, only the cursor is taken from it. The request that produced
642
+ it is the one this loop would otherwise make first: same filter, same
643
+ `limit`, no `until`.
644
+ */
645
+ if (seed && seed.length > 0) {
646
+ out.push(...seed)
647
+ until = Math.min(...seed.map((e) => e.created_at))
648
+ }
395
649
  for (let page = 0; ; page++) {
396
650
  if (page >= maxPages) {
397
651
  throw new Error(
package/src/index.ts CHANGED
@@ -47,7 +47,7 @@
47
47
  /** Bumped by hand with the version in package.json — `test/version.test.ts`
48
48
  * pins the two together. It exists so "the upgrade reached the app" can be
49
49
  * checked by grepping a built bundle rather than by trusting a lockfile. */
50
- export const PROTOCOL_VERSION = '0.14.0'
50
+ export const PROTOCOL_VERSION = '0.15.0'
51
51
 
52
52
  export {
53
53
  // types
@@ -147,6 +147,7 @@ export {
147
147
  parseQueryResponse,
148
148
  RELAY_PAGE_CEILING,
149
149
  DEFAULT_QUERY_CONCURRENCY,
150
+ MAX_FILTERS_PER_QUERY,
150
151
  Relay,
151
152
  } from './bridge.js'
152
153