@estiva-app/interop 0.69.0 → 0.70.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 +34 -0
- package/README.md +13 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loadQuery.d.ts +5 -1
- package/dist/loadQuery.d.ts.map +1 -1
- package/dist/loadQuery.js +130 -29
- package/dist/loadQuery.js.map +1 -1
- package/dist/mentions.d.ts +8 -0
- package/dist/mentions.d.ts.map +1 -1
- package/dist/mentions.js +24 -5
- package/dist/mentions.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +9 -2
- package/src/loadQuery.ts +139 -32
- package/src/mentions.ts +26 -5
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,40 @@ how a declaration is read, is a MAJOR — in `0.x`, a MINOR — even when no
|
|
|
6
6
|
TypeScript signature moved. A consumer upgrading must be able to tell whether
|
|
7
7
|
manifests already published still mean what they meant.
|
|
8
8
|
|
|
9
|
+
## 0.70.0 — 2026-10-28
|
|
10
|
+
|
|
11
|
+
**Manifest: nothing.** One load reads each change once when it also reads a
|
|
12
|
+
whole kind (APP-6).
|
|
13
|
+
|
|
14
|
+
- `createLoadQuery` counts a filter naming only kinds (`{ kinds: [1851] }`,
|
|
15
|
+
with or without a `limit`) as it counts one naming values: when it came back
|
|
16
|
+
whole, a later filter of one of its kinds, by any one tag, is answered from
|
|
17
|
+
it, and one asked while it is in flight waits for it. The agent's workspace
|
|
18
|
+
read every change whole and the Folder listing beside it read the same
|
|
19
|
+
changes again by `#a`: 41 MB, then 26 MB more, on production 28 Oct.
|
|
20
|
+
- `createLoadQuery(query, { paged: true })` is for a query that pages every
|
|
21
|
+
filter to its end, as `Relay.queryAll` does: every answer counts whatever its
|
|
22
|
+
size. Counting the page never counted a read longer than one page, which every
|
|
23
|
+
workspace read is. Without it, a whole-kind read counts only when it states
|
|
24
|
+
a `limit` and came back short of it, since a relay may give a filter with no
|
|
25
|
+
limit a smaller page. A one-page query's reads by value count as before.
|
|
26
|
+
|
|
27
|
+
## 0.69.1 — 2026-10-27
|
|
28
|
+
|
|
29
|
+
**Manifest: nothing.** A security fix in reading Mentioned in (PEEKM-7's
|
|
30
|
+
review); no manifest declaration or tag changes meaning.
|
|
31
|
+
|
|
32
|
+
- `readMentionedIn` asks about at most `MAX_MENTIONED_IN_LINKS_ASKED` (64)
|
|
33
|
+
links a read, newest messages first; one left over stays unanswered, so a
|
|
34
|
+
message pointing at the file keeps its row, and a later read asks the next
|
|
35
|
+
ones. Before, it asked about every link in up to 200 candidates at once, one
|
|
36
|
+
relay query each: one comment of hundreds of app links made every viewer of
|
|
37
|
+
the file fire that many and draw 429s.
|
|
38
|
+
- `mentionedInOf` and `readMentionedIn` read only a message's first
|
|
39
|
+
`MAX_LINKS_ASKED` (24) links, the ones a sender asks about before it tags. A
|
|
40
|
+
link past them names nothing and keeps no row, even one the reader already
|
|
41
|
+
knows.
|
|
42
|
+
|
|
9
43
|
## 0.69.0 — 2026-10-27
|
|
10
44
|
|
|
11
45
|
**Wire behaviour: a comment built from a manifest carries the `a`, `q` and
|
package/README.md
CHANGED
|
@@ -595,6 +595,19 @@ kept across loads, a live list would stop seeing changes. Measured as the agent
|
|
|
595
595
|
on production, 26 Oct: 70.7 MB and 39 requests became 23.9 MB and 31, the same
|
|
596
596
|
listing byte for byte.
|
|
597
597
|
|
|
598
|
+
A read of a whole kind, `{ kinds: [1851] }`, counts the same way: once it came
|
|
599
|
+
back whole, a later read of that kind by one tag is answered from it. A query
|
|
600
|
+
that pages every filter to its end, as `Relay.queryAll` does, says so, and then
|
|
601
|
+
every answer counts however long it is:
|
|
602
|
+
|
|
603
|
+
```ts
|
|
604
|
+
const load = createLoadQuery((filters) => relay.queryAll(filters), { paged: true })
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
Measured as the agent's `ship issues` on production, 28 Oct, with the workspace
|
|
608
|
+
read and the listing sharing one: 99.1 MB in 55 requests became 44.4 MB in 19,
|
|
609
|
+
each change read once and the output byte for byte the same.
|
|
610
|
+
|
|
598
611
|
### Only the kinds you draw
|
|
599
612
|
|
|
600
613
|
A reader that draws some kinds and no dots, such as a list of one app's files,
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export { resolveManifest, resolveActingManifest, resolveForeignObject, resolveFo
|
|
|
30
30
|
* breadcrumbs and move targets, with cycles cut. No requests.
|
|
31
31
|
*/
|
|
32
32
|
export { nestingOf, type Nestable, type Nesting } from './nesting.js';
|
|
33
|
-
export { createLoadQuery } from './loadQuery.js';
|
|
33
|
+
export { createLoadQuery, type LoadQueryOptions } from './loadQuery.js';
|
|
34
34
|
/**
|
|
35
35
|
* The files `[` offers (PEE-21): resolved objects as rows, and typed text as
|
|
36
36
|
* the search tier, both folded to the current title. conversation ranks them.
|
|
@@ -49,7 +49,7 @@ export { planCreateFolder, planRenameFolder, planDeleteFolder, planPlaceFile, pl
|
|
|
49
49
|
* keeps a resolver of its own.
|
|
50
50
|
*/
|
|
51
51
|
export { linkReader, linkTagsOf, linksIn, writtenOpenerOf, within, MAX_LINKS_ASKED, type LinkAnswer, type LinkReader, type LinkReaderOptions, type OwnPlace, } from './links.js';
|
|
52
|
-
export { mentionedInFilter, mentionedInOf, readMentionedIn, MENTIONED_IN_LIMIT, type MentionedIn } from './mentions.js';
|
|
52
|
+
export { mentionedInFilter, mentionedInOf, readMentionedIn, MENTIONED_IN_LIMIT, MAX_MENTIONED_IN_LINKS_ASKED, type MentionedIn, } from './mentions.js';
|
|
53
53
|
/**
|
|
54
54
|
* RFC 0.5 §7's URL grammar — how an object is named in an address bar, and how
|
|
55
55
|
* a pasted link is matched back to one.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;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AO,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,0BAA0B,EAC1B,sBAAsB,EACtB,OAAO,EACP,KAAK,MAAM,EACX,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,KAAK,mBAAmB,EACxB,SAAS,EACT,KAAK,OAAO,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,eAAe,EACpB,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,SAAS,EACT,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,aAAa,EAClB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK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}
|
package/dist/index.js
CHANGED
|
@@ -49,7 +49,7 @@ export { planCreateFolder, planRenameFolder, planDeleteFolder, planPlaceFile, pl
|
|
|
49
49
|
* keeps a resolver of its own.
|
|
50
50
|
*/
|
|
51
51
|
export { linkReader, linkTagsOf, linksIn, writtenOpenerOf, within, MAX_LINKS_ASKED, } from './links.js';
|
|
52
|
-
export { mentionedInFilter, mentionedInOf, readMentionedIn, MENTIONED_IN_LIMIT } from './mentions.js';
|
|
52
|
+
export { mentionedInFilter, mentionedInOf, readMentionedIn, MENTIONED_IN_LIMIT, MAX_MENTIONED_IN_LINKS_ASKED, } from './mentions.js';
|
|
53
53
|
/**
|
|
54
54
|
* RFC 0.5 §7's URL grammar — how an object is named in an address bar, and how
|
|
55
55
|
* a pasted link is matched back to one.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EAIb,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,0BAA0B,EAC1B,sBAAsB,EACtB,OAAO,EAEP,cAAc,EACd,oBAAoB,EACpB,eAAe,EAEf,SAAS,EAET,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAEjB,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,SAAS,EACT,kBAAkB,EAClB,qBAAqB,EAErB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EAmBnB,cAAc,GAEf,MAAM,iBAAiB,CAAA;AAExB;;;GAGG;AACH,OAAO,EAAE,SAAS,EAA+B,MAAM,cAAc,CAAA;AACrE,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EAIb,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,0BAA0B,EAC1B,sBAAsB,EACtB,OAAO,EAEP,cAAc,EACd,oBAAoB,EACpB,eAAe,EAEf,SAAS,EAET,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAEjB,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,SAAS,EACT,kBAAkB,EAClB,qBAAqB,EAErB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EAmBnB,cAAc,GAEf,MAAM,iBAAiB,CAAA;AAExB;;;GAGG;AACH,OAAO,EAAE,SAAS,EAA+B,MAAM,cAAc,CAAA;AACrE,OAAO,EAAE,eAAe,EAAyB,MAAM,gBAAgB,CAAA;AAEvE;;;GAGG;AACH,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,oBAAoB,GAGrB,MAAM,iBAAiB,CAAA;AAExB;;;;;GAKG;AACH,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GAMd,MAAM,cAAc,CAAA;AAErB;;;;GAIG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,OAAO,EACP,eAAe,EACf,MAAM,EACN,eAAe,GAKhB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,4BAA4B,GAE7B,MAAM,eAAe,CAAA;AAEtB;;;;;;;GAOG;AACH,OAAO,EACL,OAAO,EACP,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,UAAU,GAGX,MAAM,gBAAgB,CAAA"}
|
package/dist/loadQuery.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { QueryFn } from './projection.js';
|
|
2
|
+
export interface LoadQueryOptions {
|
|
3
|
+
/** The query answers every filter in full, paging past the relay's page (`Relay.queryAll`): see the module's note. */
|
|
4
|
+
paged?: boolean;
|
|
5
|
+
}
|
|
2
6
|
/** A query for one load: see the module's note. Make one per load and drop it after. */
|
|
3
|
-
export declare function createLoadQuery(query: QueryFn): QueryFn;
|
|
7
|
+
export declare function createLoadQuery(query: QueryFn, options?: LoadQueryOptions): QueryFn;
|
|
4
8
|
//# sourceMappingURL=loadQuery.d.ts.map
|
package/dist/loadQuery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadQuery.d.ts","sourceRoot":"","sources":["../src/loadQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadQuery.d.ts","sourceRoot":"","sources":["../src/loadQuery.ts"],"names":[],"mappings":"AA2CA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAqG9C,MAAM,WAAW,gBAAgB;IAC/B,sHAAsH;IACtH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAQD,wFAAwF;AACxF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CA2GvF"}
|
package/dist/loadQuery.js
CHANGED
|
@@ -15,9 +15,21 @@
|
|
|
15
15
|
* the relay's answer did not fill the page. A later filter in the same load
|
|
16
16
|
* naming such a value gets the events already read, and asks only for the
|
|
17
17
|
* rest.
|
|
18
|
+
* - **A read of a whole kind answers every later read of that kind** (APP-6).
|
|
19
|
+
* The agent's workspace reads every change with `{ kinds: [1851] }`, and
|
|
20
|
+
* `listFolders` beside it read the same changes again by `#a`: 37.6 MB, then
|
|
21
|
+
* 23.6 MB more, on production 27 Oct. A filter naming only kinds is complete
|
|
22
|
+
* on the same terms as one naming values, and a later filter of one of its
|
|
23
|
+
* kinds, by any one tag, is answered from it.
|
|
18
24
|
* - **A read in flight is joined, not repeated.** A value still being read is
|
|
19
25
|
* waited for, and an identical request still in flight shares its answer.
|
|
20
26
|
*
|
|
27
|
+
* **A query that pages every filter to its end** (`Relay.queryAll`, the
|
|
28
|
+
* agent's) says so with `{ paged: true }`. Its answer is whole whatever its
|
|
29
|
+
* size and whatever `limit` the filter carried, so every such read counts;
|
|
30
|
+
* counting the page would never count a read past one page, which every
|
|
31
|
+
* workspace read is.
|
|
32
|
+
*
|
|
21
33
|
* **One load, never longer.** What it holds is the relay's answer at the moment
|
|
22
34
|
* of the load: a refresh, a live update, or the next screen must read afresh,
|
|
23
35
|
* so the caller makes one per load and drops it after. Caching changes across
|
|
@@ -44,13 +56,62 @@ function byTagOf(filter) {
|
|
|
44
56
|
return null;
|
|
45
57
|
return { kind: kinds[0], tag: tagKeys[0].slice(1), values, limit };
|
|
46
58
|
}
|
|
59
|
+
function wholeKindsOf(filter, paged) {
|
|
60
|
+
const { kinds, limit, ...rest } = filter;
|
|
61
|
+
if (Object.keys(rest).length !== 0 || !Array.isArray(kinds) || kinds.length === 0)
|
|
62
|
+
return null;
|
|
63
|
+
if (!kinds.every((kind) => typeof kind === 'number'))
|
|
64
|
+
return null;
|
|
65
|
+
// A relay may give a filter with no limit a smaller page than its ceiling, so
|
|
66
|
+
// through one page only a stated limit says when the answer was cut short.
|
|
67
|
+
if (typeof limit !== 'number' && !(paged && limit === undefined))
|
|
68
|
+
return null;
|
|
69
|
+
return { kinds, limit: limit ?? RELAY_PAGE_CEILING };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The tags a whole read answers a later read by: the ones the relay matches as
|
|
73
|
+
* NIP-01 does, on every kind. Never `h`, which is a Folder's scope on the relay
|
|
74
|
+
* (the event's first `h`, its membership checked there), so a tag match would
|
|
75
|
+
* take in a change one member planted with a second `h` naming a Folder they
|
|
76
|
+
* cannot write to. Never `d` either: a Folder's own events (39000–39003) are
|
|
77
|
+
* reached by naming the Folder, and a read naming no Folder misses some.
|
|
78
|
+
*/
|
|
79
|
+
const WHOLE_READ_TAGS = new Set(['a', 'e']);
|
|
80
|
+
/** The events of a whole read naming each value of one tag, indexed once per read and tag. */
|
|
81
|
+
const indexes = new WeakMap();
|
|
82
|
+
function naming(events, tag, value) {
|
|
83
|
+
let byTag = indexes.get(events);
|
|
84
|
+
if (!byTag)
|
|
85
|
+
indexes.set(events, (byTag = new Map()));
|
|
86
|
+
let byValue = byTag.get(tag);
|
|
87
|
+
if (!byValue) {
|
|
88
|
+
byTag.set(tag, (byValue = new Map()));
|
|
89
|
+
for (const event of events) {
|
|
90
|
+
for (const [name, held] of event.tags) {
|
|
91
|
+
if (name !== tag)
|
|
92
|
+
continue;
|
|
93
|
+
const list = byValue.get(held) ?? [];
|
|
94
|
+
if (!list.includes(event))
|
|
95
|
+
list.push(event);
|
|
96
|
+
byValue.set(held, list);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return byValue.get(value) ?? [];
|
|
101
|
+
}
|
|
102
|
+
/** Every event of the read's kinds, if this answer holds them all: see {@link completeByValue}. */
|
|
103
|
+
function completeWhole(shape, answer, paged) {
|
|
104
|
+
const held = answer.filter((event) => shape.kinds.includes(event.kind));
|
|
105
|
+
return paged || held.length < Math.min(shape.limit, RELAY_PAGE_CEILING) ? held : null;
|
|
106
|
+
}
|
|
47
107
|
/**
|
|
48
108
|
* The events naming each of the filter's values, if this answer holds them
|
|
49
|
-
* all: fewer came back for the filter than its page
|
|
50
|
-
* everything in the pooled answer the filter matches,
|
|
51
|
-
* overcount — so a page is never taken as complete when it was
|
|
109
|
+
* all: fewer came back for the filter than its page, or the query pages to the
|
|
110
|
+
* end. The count is of everything in the pooled answer the filter matches,
|
|
111
|
+
* which can only overcount — so a page is never taken as complete when it was
|
|
112
|
+
* full.
|
|
52
113
|
*/
|
|
53
|
-
function completeByValue(shape, answer) {
|
|
114
|
+
function completeByValue(shape, answer, paged) {
|
|
54
115
|
const byValue = new Map(shape.values.map((value) => [value, []]));
|
|
55
116
|
let matched = 0;
|
|
56
117
|
for (const event of answer) {
|
|
@@ -67,15 +128,31 @@ function completeByValue(shape, answer) {
|
|
|
67
128
|
if (hit)
|
|
68
129
|
matched++;
|
|
69
130
|
}
|
|
70
|
-
return matched >= Math.min(shape.limit, RELAY_PAGE_CEILING) ? null : byValue;
|
|
131
|
+
return !paged && matched >= Math.min(shape.limit, RELAY_PAGE_CEILING) ? null : byValue;
|
|
71
132
|
}
|
|
72
133
|
/** A query for one load: see the module's note. Make one per load and drop it after. */
|
|
73
|
-
export function createLoadQuery(query) {
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
//
|
|
134
|
+
export function createLoadQuery(query, options = {}) {
|
|
135
|
+
const paged = options.paged === true;
|
|
136
|
+
// Only an ask with as large a limit as a held read would have got all it holds,
|
|
137
|
+
// so a smaller page goes to the relay. A paged read holds everything whatever its limit.
|
|
138
|
+
const answers = (held, limit) => !!held && (paged || held.limit <= limit);
|
|
139
|
+
// Per `<kind>:<tag>:<value>`: the events naming it.
|
|
77
140
|
const known = new Map();
|
|
141
|
+
// Per kind: every event of it, read by a filter naming only kinds.
|
|
142
|
+
const wholes = new Map();
|
|
78
143
|
const flights = new Map();
|
|
144
|
+
const remember = (memo, key, entry) => {
|
|
145
|
+
// A larger read of the same, in flight or done, is kept.
|
|
146
|
+
if ((memo.get(key)?.limit ?? -1) > entry.limit)
|
|
147
|
+
return;
|
|
148
|
+
memo.set(key, entry);
|
|
149
|
+
// Forget a refused read, and a page that came back full, so the next ask goes to the relay.
|
|
150
|
+
const forget = () => {
|
|
151
|
+
if (memo.get(key) === entry)
|
|
152
|
+
memo.delete(key);
|
|
153
|
+
};
|
|
154
|
+
entry.events.then((events) => events ?? forget(), forget);
|
|
155
|
+
};
|
|
79
156
|
const ask = (filters) => {
|
|
80
157
|
const key = JSON.stringify(filters);
|
|
81
158
|
const held = flights.get(key);
|
|
@@ -88,19 +165,39 @@ export function createLoadQuery(query) {
|
|
|
88
165
|
return async (filters) => {
|
|
89
166
|
const send = [];
|
|
90
167
|
const asked = [];
|
|
168
|
+
const askedWhole = [];
|
|
169
|
+
// Answered from a held read; `again` is what to ask if that read's page came back full.
|
|
91
170
|
const joined = [];
|
|
171
|
+
const joinedByTag = [];
|
|
92
172
|
for (const filter of filters) {
|
|
173
|
+
const whole = wholeKindsOf(filter, paged);
|
|
174
|
+
if (whole) {
|
|
175
|
+
const held = whole.kinds.map((kind) => wholes.get(kind));
|
|
176
|
+
if (held.every((entry) => answers(entry, whole.limit))) {
|
|
177
|
+
const parts = Promise.all(held.map((entry) => entry.events));
|
|
178
|
+
joined.push({ again: filter, entry: parts.then((all) => (all.includes(null) ? null : all.flat())) });
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
send.push(filter);
|
|
182
|
+
askedWhole.push(whole);
|
|
183
|
+
}
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
93
186
|
const shape = byTagOf(filter);
|
|
94
187
|
if (!shape) {
|
|
95
188
|
send.push(filter);
|
|
96
189
|
continue;
|
|
97
190
|
}
|
|
98
191
|
const fresh = [];
|
|
192
|
+
const read = WHOLE_READ_TAGS.has(shape.tag) ? wholes.get(shape.kind) : undefined;
|
|
99
193
|
for (const value of new Set(shape.values)) {
|
|
100
194
|
const entry = known.get(`${shape.kind}:${shape.tag}:${value}`);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
195
|
+
if (answers(read, shape.limit)) {
|
|
196
|
+
const events = read.events.then((all) => all && naming(all, shape.tag, value));
|
|
197
|
+
joinedByTag.push({ shape, value, entry: events });
|
|
198
|
+
}
|
|
199
|
+
else if (answers(entry, shape.limit))
|
|
200
|
+
joinedByTag.push({ shape, value, entry: entry.events });
|
|
104
201
|
else
|
|
105
202
|
fresh.push(value);
|
|
106
203
|
}
|
|
@@ -110,27 +207,30 @@ export function createLoadQuery(query) {
|
|
|
110
207
|
asked.push({ ...shape, values: fresh });
|
|
111
208
|
}
|
|
112
209
|
const answer = send.length ? ask(send) : Promise.resolve([]);
|
|
210
|
+
for (const shape of askedWhole) {
|
|
211
|
+
const split = answer.then((events) => completeWhole(shape, events, paged));
|
|
212
|
+
for (const kind of shape.kinds) {
|
|
213
|
+
remember(wholes, kind, { limit: shape.limit, events: split.then((events) => events && events.filter((event) => event.kind === kind)) });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
113
216
|
for (const shape of asked) {
|
|
114
|
-
const split = answer.then((events) => completeByValue(shape, events));
|
|
217
|
+
const split = answer.then((events) => completeByValue(shape, events, paged));
|
|
115
218
|
for (const value of shape.values) {
|
|
116
|
-
|
|
117
|
-
// A larger read of the same value, in flight or done, is kept.
|
|
118
|
-
if ((known.get(key)?.limit ?? -1) > shape.limit)
|
|
119
|
-
continue;
|
|
120
|
-
const entry = { limit: shape.limit, events: split.then((byValue) => byValue?.get(value) ?? null) };
|
|
121
|
-
known.set(key, entry);
|
|
122
|
-
// Forget a refused read, and a page that came back full, so the next ask goes to the relay.
|
|
123
|
-
const forget = () => {
|
|
124
|
-
if (known.get(key) === entry)
|
|
125
|
-
known.delete(key);
|
|
126
|
-
};
|
|
127
|
-
entry.events.then((events) => events ?? forget(), forget);
|
|
219
|
+
remember(known, `${shape.kind}:${shape.tag}:${value}`, { limit: shape.limit, events: split.then((byValue) => byValue?.get(value) ?? null) });
|
|
128
220
|
}
|
|
129
221
|
}
|
|
130
222
|
const out = [...(await answer)];
|
|
223
|
+
const again = [];
|
|
224
|
+
for (const { again: filter, entry } of joined) {
|
|
225
|
+
const events = await entry;
|
|
226
|
+
if (events)
|
|
227
|
+
out.push(...events);
|
|
228
|
+
else
|
|
229
|
+
again.push(filter);
|
|
230
|
+
}
|
|
131
231
|
// Per filter of the caller's, so a re-ask keeps the grouping it chose.
|
|
132
232
|
const unknown = new Map();
|
|
133
|
-
for (const { shape, value, entry } of
|
|
233
|
+
for (const { shape, value, entry } of joinedByTag) {
|
|
134
234
|
const events = await entry;
|
|
135
235
|
if (events)
|
|
136
236
|
out.push(...events);
|
|
@@ -138,9 +238,10 @@ export function createLoadQuery(query) {
|
|
|
138
238
|
else
|
|
139
239
|
unknown.set(shape, [...(unknown.get(shape) ?? []), value]);
|
|
140
240
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
241
|
+
for (const [shape, values] of unknown)
|
|
242
|
+
again.push({ kinds: [shape.kind], [`#${shape.tag}`]: values, limit: shape.limit });
|
|
243
|
+
if (again.length)
|
|
244
|
+
out.push(...(await ask(again)));
|
|
144
245
|
// One copy of each event, as one request to the relay answers.
|
|
145
246
|
const seen = new Set();
|
|
146
247
|
return out.filter((e) => !seen.has(e.id) && !!seen.add(e.id));
|
package/dist/loadQuery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadQuery.js","sourceRoot":"","sources":["../src/loadQuery.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loadQuery.js","sourceRoot":"","sources":["../src/loadQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAy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C,KAAK,CAAC,CAAC,CAAC,CAAA;QAEjD,+DAA+D;QAC/D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;QAC9B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/D,CAAC,CAAA;AACH,CAAC"}
|
package/dist/mentions.d.ts
CHANGED
|
@@ -12,6 +12,14 @@ export interface MentionedIn {
|
|
|
12
12
|
}
|
|
13
13
|
/** Enough for a list that is scanned, not read; the oldest pointers are what a cap drops. */
|
|
14
14
|
export declare const MENTIONED_IN_LIMIT = 200;
|
|
15
|
+
/**
|
|
16
|
+
* How many links one Mentioned-in read asks about in all, newest messages
|
|
17
|
+
* first. Each asked link is a relay query, and {@link MENTIONED_IN_LIMIT}
|
|
18
|
+
* candidates at {@link MAX_LINKS_ASKED} each would be 4,800 of them for one
|
|
19
|
+
* panel (PEEKM-7's review). A link left over stays unanswered, so a message
|
|
20
|
+
* pointing at the file keeps its row; a later read asks the next ones.
|
|
21
|
+
*/
|
|
22
|
+
export declare const MAX_MENTIONED_IN_LINKS_ASKED = 64;
|
|
15
23
|
/** The one filter for the candidates: every message, comment and edit pointing at the file. */
|
|
16
24
|
export declare function mentionedInFilter(address: string, limit?: number): Record<string, unknown>;
|
|
17
25
|
/**
|
package/dist/mentions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mentions.d.ts","sourceRoot":"","sources":["../src/mentions.ts"],"names":[],"mappings":"AAkBA,OAAO,EAA0B,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClG,OAAO,
|
|
1
|
+
{"version":3,"file":"mentions.d.ts","sourceRoot":"","sources":["../src/mentions.ts"],"names":[],"mappings":"AAk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
17
17
|
*/
|
|
18
18
|
import { anchorsOf, editsByTarget, editTargetOf, isCommentOn, KIND_COMMENT, KIND_EDIT, KIND_MESSAGE } from '@estiva-app/conversation';
|
|
19
19
|
import { toRenderTree, valuesIn } from '@estiva-app/protocol';
|
|
20
|
-
import { linksIn, within } from './links.js';
|
|
20
|
+
import { linksIn, within, MAX_LINKS_ASKED } from './links.js';
|
|
21
21
|
/** Enough for a list that is scanned, not read; the oldest pointers are what a cap drops. */
|
|
22
22
|
export const MENTIONED_IN_LIMIT = 200;
|
|
23
|
+
/**
|
|
24
|
+
* How many links one Mentioned-in read asks about in all, newest messages
|
|
25
|
+
* first. Each asked link is a relay query, and {@link MENTIONED_IN_LIMIT}
|
|
26
|
+
* candidates at {@link MAX_LINKS_ASKED} each would be 4,800 of them for one
|
|
27
|
+
* panel (PEEKM-7's review). A link left over stays unanswered, so a message
|
|
28
|
+
* pointing at the file keeps its row; a later read asks the next ones.
|
|
29
|
+
*/
|
|
30
|
+
export const MAX_MENTIONED_IN_LINKS_ASKED = 64;
|
|
31
|
+
/**
|
|
32
|
+
* The links of a message's words that can name the file: the first
|
|
33
|
+
* {@link MAX_LINKS_ASKED}, the ones a sender asks about before it tags. A link
|
|
34
|
+
* past them earned no `a`, so it is never asked about and keeps no row: a body
|
|
35
|
+
* of hundreds of links costs a reader no more than a sender.
|
|
36
|
+
*/
|
|
37
|
+
const linksNaming = (tree) => linksIn(tree).slice(0, MAX_LINKS_ASKED);
|
|
23
38
|
/** The one filter for the candidates: every message, comment and edit pointing at the file. */
|
|
24
39
|
export function mentionedInFilter(address, limit = MENTIONED_IN_LIMIT) {
|
|
25
40
|
return { kinds: [KIND_COMMENT, KIND_MESSAGE, KIND_EDIT], '#a': [address], limit };
|
|
@@ -63,7 +78,10 @@ export function mentionedInOf(events, address, resolveLink, commentKinds, unansw
|
|
|
63
78
|
const body = edit?.content ?? event.content;
|
|
64
79
|
const tree = toRenderTree(body, 'marker');
|
|
65
80
|
const pointsNow = (edit ?? event).tags.some((t) => t[0] === 'a' && t[1] === address);
|
|
66
|
-
|
|
81
|
+
const first = linksNaming(tree);
|
|
82
|
+
const named = new Set(first);
|
|
83
|
+
const resolve = resolveLink && ((url) => (named.has(url) ? resolveLink(url) : undefined));
|
|
84
|
+
if (!valuesIn(tree, resolve).includes(file) && !(pointsNow && first.some(unanswered)))
|
|
67
85
|
continue;
|
|
68
86
|
out.push(edit ? { event, body, edit } : { event, body });
|
|
69
87
|
}
|
|
@@ -87,9 +105,10 @@ export async function readMentionedIn(query, address, options = {}) {
|
|
|
87
105
|
const links = options.links;
|
|
88
106
|
if (!links)
|
|
89
107
|
return mentionedInOf(events, address, undefined, options.commentKinds, () => true);
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
const
|
|
108
|
+
// The links that can name the file in each candidate's latest words: read as if each named it, so each candidate holding one is kept to ask.
|
|
109
|
+
// At most MAX_MENTIONED_IN_LINKS_ASKED, newest messages first; one left over stays unanswered, so a message pointing at the file keeps its row.
|
|
110
|
+
const urls = [...new Set(mentionedInOf(events, address, () => address, options.commentKinds).flatMap((m) => linksNaming(toRenderTree(m.body, 'marker'))))];
|
|
111
|
+
const waiting = urls.filter((url) => !links.answered(url)).slice(0, MAX_MENTIONED_IN_LINKS_ASKED);
|
|
93
112
|
if (waiting.length)
|
|
94
113
|
await within(links.ask(waiting), options.waitMs ?? 5000);
|
|
95
114
|
return mentionedInOf(events, address, links.known, options.commentKinds, (url) => !links.answered(url));
|
package/dist/mentions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mentions.js","sourceRoot":"","sources":["../src/mentions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACrI,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAuC,MAAM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E,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;AACzG,CAAC;AAED,2CAA2C;AAC3C,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACpD,OAAO,GAAG,IAAI,IAAI,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;AACzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.70.0",
|
|
4
4
|
"description": "Render and act on another app's objects from its published NIP-89 manifest. The owner defines the projection; the consumer decides how it looks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -110,7 +110,7 @@ export {
|
|
|
110
110
|
* breadcrumbs and move targets, with cycles cut. No requests.
|
|
111
111
|
*/
|
|
112
112
|
export { nestingOf, type Nestable, type Nesting } from './nesting.js'
|
|
113
|
-
export { createLoadQuery } from './loadQuery.js'
|
|
113
|
+
export { createLoadQuery, type LoadQueryOptions } from './loadQuery.js'
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* The files `[` offers (PEE-21): resolved objects as rows, and typed text as
|
|
@@ -164,7 +164,14 @@ export {
|
|
|
164
164
|
type LinkReaderOptions,
|
|
165
165
|
type OwnPlace,
|
|
166
166
|
} from './links.js'
|
|
167
|
-
export {
|
|
167
|
+
export {
|
|
168
|
+
mentionedInFilter,
|
|
169
|
+
mentionedInOf,
|
|
170
|
+
readMentionedIn,
|
|
171
|
+
MENTIONED_IN_LIMIT,
|
|
172
|
+
MAX_MENTIONED_IN_LINKS_ASKED,
|
|
173
|
+
type MentionedIn,
|
|
174
|
+
} from './mentions.js'
|
|
168
175
|
|
|
169
176
|
/**
|
|
170
177
|
* RFC 0.5 §7's URL grammar — how an object is named in an address bar, and how
|
package/src/loadQuery.ts
CHANGED
|
@@ -15,9 +15,21 @@
|
|
|
15
15
|
* the relay's answer did not fill the page. A later filter in the same load
|
|
16
16
|
* naming such a value gets the events already read, and asks only for the
|
|
17
17
|
* rest.
|
|
18
|
+
* - **A read of a whole kind answers every later read of that kind** (APP-6).
|
|
19
|
+
* The agent's workspace reads every change with `{ kinds: [1851] }`, and
|
|
20
|
+
* `listFolders` beside it read the same changes again by `#a`: 37.6 MB, then
|
|
21
|
+
* 23.6 MB more, on production 27 Oct. A filter naming only kinds is complete
|
|
22
|
+
* on the same terms as one naming values, and a later filter of one of its
|
|
23
|
+
* kinds, by any one tag, is answered from it.
|
|
18
24
|
* - **A read in flight is joined, not repeated.** A value still being read is
|
|
19
25
|
* waited for, and an identical request still in flight shares its answer.
|
|
20
26
|
*
|
|
27
|
+
* **A query that pages every filter to its end** (`Relay.queryAll`, the
|
|
28
|
+
* agent's) says so with `{ paged: true }`. Its answer is whole whatever its
|
|
29
|
+
* size and whatever `limit` the filter carried, so every such read counts;
|
|
30
|
+
* counting the page would never count a read past one page, which every
|
|
31
|
+
* workspace read is.
|
|
32
|
+
*
|
|
21
33
|
* **One load, never longer.** What it holds is the relay's answer at the moment
|
|
22
34
|
* of the load: a refresh, a live update, or the next screen must read afresh,
|
|
23
35
|
* so the caller makes one per load and drops it after. Caching changes across
|
|
@@ -53,13 +65,66 @@ function byTagOf(filter: Filter): ByTag | null {
|
|
|
53
65
|
return { kind: kinds[0], tag: tagKeys[0].slice(1), values, limit }
|
|
54
66
|
}
|
|
55
67
|
|
|
68
|
+
/** `{ kinds: [...] }`, with or without a `limit`, and nothing else: every event of those kinds. */
|
|
69
|
+
interface WholeKinds {
|
|
70
|
+
kinds: number[]
|
|
71
|
+
limit: number
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function wholeKindsOf(filter: Filter, paged: boolean): WholeKinds | null {
|
|
75
|
+
const { kinds, limit, ...rest } = filter
|
|
76
|
+
if (Object.keys(rest).length !== 0 || !Array.isArray(kinds) || kinds.length === 0) return null
|
|
77
|
+
if (!kinds.every((kind) => typeof kind === 'number')) return null
|
|
78
|
+
// A relay may give a filter with no limit a smaller page than its ceiling, so
|
|
79
|
+
// through one page only a stated limit says when the answer was cut short.
|
|
80
|
+
if (typeof limit !== 'number' && !(paged && limit === undefined)) return null
|
|
81
|
+
return { kinds, limit: limit ?? RELAY_PAGE_CEILING }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The tags a whole read answers a later read by: the ones the relay matches as
|
|
86
|
+
* NIP-01 does, on every kind. Never `h`, which is a Folder's scope on the relay
|
|
87
|
+
* (the event's first `h`, its membership checked there), so a tag match would
|
|
88
|
+
* take in a change one member planted with a second `h` naming a Folder they
|
|
89
|
+
* cannot write to. Never `d` either: a Folder's own events (39000–39003) are
|
|
90
|
+
* reached by naming the Folder, and a read naming no Folder misses some.
|
|
91
|
+
*/
|
|
92
|
+
const WHOLE_READ_TAGS = new Set(['a', 'e'])
|
|
93
|
+
|
|
94
|
+
/** The events of a whole read naming each value of one tag, indexed once per read and tag. */
|
|
95
|
+
const indexes = new WeakMap<SignedEvent[], Map<string, Map<string, SignedEvent[]>>>()
|
|
96
|
+
function naming(events: SignedEvent[], tag: string, value: string): SignedEvent[] {
|
|
97
|
+
let byTag = indexes.get(events)
|
|
98
|
+
if (!byTag) indexes.set(events, (byTag = new Map()))
|
|
99
|
+
let byValue = byTag.get(tag)
|
|
100
|
+
if (!byValue) {
|
|
101
|
+
byTag.set(tag, (byValue = new Map()))
|
|
102
|
+
for (const event of events) {
|
|
103
|
+
for (const [name, held] of event.tags) {
|
|
104
|
+
if (name !== tag) continue
|
|
105
|
+
const list = byValue.get(held) ?? []
|
|
106
|
+
if (!list.includes(event)) list.push(event)
|
|
107
|
+
byValue.set(held, list)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return byValue.get(value) ?? []
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Every event of the read's kinds, if this answer holds them all: see {@link completeByValue}. */
|
|
115
|
+
function completeWhole(shape: WholeKinds, answer: SignedEvent[], paged: boolean): SignedEvent[] | null {
|
|
116
|
+
const held = answer.filter((event) => shape.kinds.includes(event.kind))
|
|
117
|
+
return paged || held.length < Math.min(shape.limit, RELAY_PAGE_CEILING) ? held : null
|
|
118
|
+
}
|
|
119
|
+
|
|
56
120
|
/**
|
|
57
121
|
* The events naming each of the filter's values, if this answer holds them
|
|
58
|
-
* all: fewer came back for the filter than its page
|
|
59
|
-
* everything in the pooled answer the filter matches,
|
|
60
|
-
* overcount — so a page is never taken as complete when it was
|
|
122
|
+
* all: fewer came back for the filter than its page, or the query pages to the
|
|
123
|
+
* end. The count is of everything in the pooled answer the filter matches,
|
|
124
|
+
* which can only overcount — so a page is never taken as complete when it was
|
|
125
|
+
* full.
|
|
61
126
|
*/
|
|
62
|
-
function completeByValue(shape: ByTag, answer: SignedEvent[]): Map<string, SignedEvent[]> | null {
|
|
127
|
+
function completeByValue(shape: ByTag, answer: SignedEvent[], paged: boolean): Map<string, SignedEvent[]> | null {
|
|
63
128
|
const byValue = new Map<string, SignedEvent[]>(shape.values.map((value) => [value, []]))
|
|
64
129
|
let matched = 0
|
|
65
130
|
for (const event of answer) {
|
|
@@ -74,17 +139,43 @@ function completeByValue(shape: ByTag, answer: SignedEvent[]): Map<string, Signe
|
|
|
74
139
|
}
|
|
75
140
|
if (hit) matched++
|
|
76
141
|
}
|
|
77
|
-
return matched >= Math.min(shape.limit, RELAY_PAGE_CEILING) ? null : byValue
|
|
142
|
+
return !paged && matched >= Math.min(shape.limit, RELAY_PAGE_CEILING) ? null : byValue
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface LoadQueryOptions {
|
|
146
|
+
/** The query answers every filter in full, paging past the relay's page (`Relay.queryAll`): see the module's note. */
|
|
147
|
+
paged?: boolean
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A read held for the load: what it found, `null` when its page was full, or the read still in flight — and the limit it was read with. */
|
|
151
|
+
interface Held {
|
|
152
|
+
limit: number
|
|
153
|
+
events: Promise<SignedEvent[] | null>
|
|
78
154
|
}
|
|
79
155
|
|
|
80
156
|
/** A query for one load: see the module's note. Make one per load and drop it after. */
|
|
81
|
-
export function createLoadQuery(query: QueryFn): QueryFn {
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
const
|
|
157
|
+
export function createLoadQuery(query: QueryFn, options: LoadQueryOptions = {}): QueryFn {
|
|
158
|
+
const paged = options.paged === true
|
|
159
|
+
// Only an ask with as large a limit as a held read would have got all it holds,
|
|
160
|
+
// so a smaller page goes to the relay. A paged read holds everything whatever its limit.
|
|
161
|
+
const answers = (held: Held | undefined, limit: number): held is Held => !!held && (paged || held.limit <= limit)
|
|
162
|
+
// Per `<kind>:<tag>:<value>`: the events naming it.
|
|
163
|
+
const known = new Map<string, Held>()
|
|
164
|
+
// Per kind: every event of it, read by a filter naming only kinds.
|
|
165
|
+
const wholes = new Map<number, Held>()
|
|
86
166
|
const flights = new Map<string, Promise<SignedEvent[]>>()
|
|
87
167
|
|
|
168
|
+
const remember = <K>(memo: Map<K, Held>, key: K, entry: Held) => {
|
|
169
|
+
// A larger read of the same, in flight or done, is kept.
|
|
170
|
+
if ((memo.get(key)?.limit ?? -1) > entry.limit) return
|
|
171
|
+
memo.set(key, entry)
|
|
172
|
+
// Forget a refused read, and a page that came back full, so the next ask goes to the relay.
|
|
173
|
+
const forget = () => {
|
|
174
|
+
if (memo.get(key) === entry) memo.delete(key)
|
|
175
|
+
}
|
|
176
|
+
entry.events.then((events) => events ?? forget(), forget)
|
|
177
|
+
}
|
|
178
|
+
|
|
88
179
|
const ask = (filters: Filter[]): Promise<SignedEvent[]> => {
|
|
89
180
|
const key = JSON.stringify(filters)
|
|
90
181
|
const held = flights.get(key)
|
|
@@ -97,18 +188,36 @@ export function createLoadQuery(query: QueryFn): QueryFn {
|
|
|
97
188
|
return async (filters) => {
|
|
98
189
|
const send: Filter[] = []
|
|
99
190
|
const asked: ByTag[] = []
|
|
100
|
-
const
|
|
191
|
+
const askedWhole: WholeKinds[] = []
|
|
192
|
+
// Answered from a held read; `again` is what to ask if that read's page came back full.
|
|
193
|
+
const joined: { again: Filter; entry: Promise<SignedEvent[] | null> }[] = []
|
|
194
|
+
const joinedByTag: { shape: ByTag; value: string; entry: Promise<SignedEvent[] | null> }[] = []
|
|
101
195
|
for (const filter of filters) {
|
|
196
|
+
const whole = wholeKindsOf(filter, paged)
|
|
197
|
+
if (whole) {
|
|
198
|
+
const held = whole.kinds.map((kind) => wholes.get(kind))
|
|
199
|
+
if (held.every((entry) => answers(entry, whole.limit))) {
|
|
200
|
+
const parts = Promise.all(held.map((entry) => entry!.events))
|
|
201
|
+
joined.push({ again: filter, entry: parts.then((all) => (all.includes(null) ? null : all.flat() as SignedEvent[])) })
|
|
202
|
+
} else {
|
|
203
|
+
send.push(filter)
|
|
204
|
+
askedWhole.push(whole)
|
|
205
|
+
}
|
|
206
|
+
continue
|
|
207
|
+
}
|
|
102
208
|
const shape = byTagOf(filter)
|
|
103
209
|
if (!shape) {
|
|
104
210
|
send.push(filter)
|
|
105
211
|
continue
|
|
106
212
|
}
|
|
107
213
|
const fresh: string[] = []
|
|
214
|
+
const read = WHOLE_READ_TAGS.has(shape.tag) ? wholes.get(shape.kind) : undefined
|
|
108
215
|
for (const value of new Set(shape.values)) {
|
|
109
216
|
const entry = known.get(`${shape.kind}:${shape.tag}:${value}`)
|
|
110
|
-
|
|
111
|
-
|
|
217
|
+
if (answers(read, shape.limit)) {
|
|
218
|
+
const events = read.events.then((all) => all && naming(all, shape.tag, value))
|
|
219
|
+
joinedByTag.push({ shape, value, entry: events })
|
|
220
|
+
} else if (answers(entry, shape.limit)) joinedByTag.push({ shape, value, entry: entry.events })
|
|
112
221
|
else fresh.push(value)
|
|
113
222
|
}
|
|
114
223
|
if (fresh.length === 0) continue
|
|
@@ -117,38 +226,36 @@ export function createLoadQuery(query: QueryFn): QueryFn {
|
|
|
117
226
|
}
|
|
118
227
|
|
|
119
228
|
const answer = send.length ? ask(send) : Promise.resolve([])
|
|
229
|
+
for (const shape of askedWhole) {
|
|
230
|
+
const split = answer.then((events) => completeWhole(shape, events, paged))
|
|
231
|
+
for (const kind of shape.kinds) {
|
|
232
|
+
remember(wholes, kind, { limit: shape.limit, events: split.then((events) => events && events.filter((event) => event.kind === kind)) })
|
|
233
|
+
}
|
|
234
|
+
}
|
|
120
235
|
for (const shape of asked) {
|
|
121
|
-
const split = answer.then((events) => completeByValue(shape, events))
|
|
236
|
+
const split = answer.then((events) => completeByValue(shape, events, paged))
|
|
122
237
|
for (const value of shape.values) {
|
|
123
|
-
|
|
124
|
-
// A larger read of the same value, in flight or done, is kept.
|
|
125
|
-
if ((known.get(key)?.limit ?? -1) > shape.limit) continue
|
|
126
|
-
const entry = { limit: shape.limit, events: split.then((byValue) => byValue?.get(value) ?? null) }
|
|
127
|
-
known.set(key, entry)
|
|
128
|
-
// Forget a refused read, and a page that came back full, so the next ask goes to the relay.
|
|
129
|
-
const forget = () => {
|
|
130
|
-
if (known.get(key) === entry) known.delete(key)
|
|
131
|
-
}
|
|
132
|
-
entry.events.then((events) => events ?? forget(), forget)
|
|
238
|
+
remember(known, `${shape.kind}:${shape.tag}:${value}`, { limit: shape.limit, events: split.then((byValue) => byValue?.get(value) ?? null) })
|
|
133
239
|
}
|
|
134
240
|
}
|
|
135
241
|
|
|
136
242
|
const out = [...(await answer)]
|
|
243
|
+
const again: Filter[] = []
|
|
244
|
+
for (const { again: filter, entry } of joined) {
|
|
245
|
+
const events = await entry
|
|
246
|
+
if (events) out.push(...events)
|
|
247
|
+
else again.push(filter)
|
|
248
|
+
}
|
|
137
249
|
// Per filter of the caller's, so a re-ask keeps the grouping it chose.
|
|
138
250
|
const unknown = new Map<ByTag, string[]>()
|
|
139
|
-
for (const { shape, value, entry } of
|
|
251
|
+
for (const { shape, value, entry } of joinedByTag) {
|
|
140
252
|
const events = await entry
|
|
141
253
|
if (events) out.push(...events)
|
|
142
254
|
// That read's page was full: ask for this value here, as the caller would have.
|
|
143
255
|
else unknown.set(shape, [...(unknown.get(shape) ?? []), value])
|
|
144
256
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
...(await ask(
|
|
148
|
-
[...unknown].map(([shape, values]) => ({ kinds: [shape.kind], [`#${shape.tag}`]: values, limit: shape.limit })),
|
|
149
|
-
)),
|
|
150
|
-
)
|
|
151
|
-
}
|
|
257
|
+
for (const [shape, values] of unknown) again.push({ kinds: [shape.kind], [`#${shape.tag}`]: values, limit: shape.limit })
|
|
258
|
+
if (again.length) out.push(...(await ask(again)))
|
|
152
259
|
|
|
153
260
|
// One copy of each event, as one request to the relay answers.
|
|
154
261
|
const seen = new Set<string>()
|
package/src/mentions.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { anchorsOf, editsByTarget, editTargetOf, isCommentOn, KIND_COMMENT, KIND_EDIT, KIND_MESSAGE } from '@estiva-app/conversation'
|
|
19
19
|
import { toRenderTree, valuesIn, type LinkResolver, type SignedEvent } from '@estiva-app/protocol'
|
|
20
|
-
import { linksIn, within, type LinkReader } from './links.js'
|
|
20
|
+
import { linksIn, within, MAX_LINKS_ASKED, type LinkReader } from './links.js'
|
|
21
21
|
import type { QueryFn } from './projection.js'
|
|
22
22
|
|
|
23
23
|
/** One message that mentions the file, as its latest words say. */
|
|
@@ -33,6 +33,23 @@ export interface MentionedIn {
|
|
|
33
33
|
/** Enough for a list that is scanned, not read; the oldest pointers are what a cap drops. */
|
|
34
34
|
export const MENTIONED_IN_LIMIT = 200
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* How many links one Mentioned-in read asks about in all, newest messages
|
|
38
|
+
* first. Each asked link is a relay query, and {@link MENTIONED_IN_LIMIT}
|
|
39
|
+
* candidates at {@link MAX_LINKS_ASKED} each would be 4,800 of them for one
|
|
40
|
+
* panel (PEEKM-7's review). A link left over stays unanswered, so a message
|
|
41
|
+
* pointing at the file keeps its row; a later read asks the next ones.
|
|
42
|
+
*/
|
|
43
|
+
export const MAX_MENTIONED_IN_LINKS_ASKED = 64
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The links of a message's words that can name the file: the first
|
|
47
|
+
* {@link MAX_LINKS_ASKED}, the ones a sender asks about before it tags. A link
|
|
48
|
+
* past them earned no `a`, so it is never asked about and keeps no row: a body
|
|
49
|
+
* of hundreds of links costs a reader no more than a sender.
|
|
50
|
+
*/
|
|
51
|
+
const linksNaming = (tree: ReturnType<typeof toRenderTree>) => linksIn(tree).slice(0, MAX_LINKS_ASKED)
|
|
52
|
+
|
|
36
53
|
/** The one filter for the candidates: every message, comment and edit pointing at the file. */
|
|
37
54
|
export function mentionedInFilter(address: string, limit = MENTIONED_IN_LIMIT): Record<string, unknown> {
|
|
38
55
|
return { kinds: [KIND_COMMENT, KIND_MESSAGE, KIND_EDIT], '#a': [address], limit }
|
|
@@ -78,7 +95,10 @@ export function mentionedInOf(
|
|
|
78
95
|
const body = edit?.content ?? event.content
|
|
79
96
|
const tree = toRenderTree(body, 'marker')
|
|
80
97
|
const pointsNow = (edit ?? event).tags.some((t) => t[0] === 'a' && t[1] === address)
|
|
81
|
-
|
|
98
|
+
const first = linksNaming(tree)
|
|
99
|
+
const named = new Set(first)
|
|
100
|
+
const resolve: LinkResolver | undefined = resolveLink && ((url) => (named.has(url) ? resolveLink(url) : undefined))
|
|
101
|
+
if (!valuesIn(tree, resolve).includes(file) && !(pointsNow && first.some(unanswered))) continue
|
|
82
102
|
out.push(edit ? { event, body, edit } : { event, body })
|
|
83
103
|
}
|
|
84
104
|
return out.sort((a, b) => b.event.created_at - a.event.created_at)
|
|
@@ -105,9 +125,10 @@ export async function readMentionedIn(
|
|
|
105
125
|
const events = [...candidates, ...targets, ...edits]
|
|
106
126
|
const links = options.links
|
|
107
127
|
if (!links) return mentionedInOf(events, address, undefined, options.commentKinds, () => true)
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
const
|
|
128
|
+
// The links that can name the file in each candidate's latest words: read as if each named it, so each candidate holding one is kept to ask.
|
|
129
|
+
// At most MAX_MENTIONED_IN_LINKS_ASKED, newest messages first; one left over stays unanswered, so a message pointing at the file keeps its row.
|
|
130
|
+
const urls = [...new Set(mentionedInOf(events, address, () => address, options.commentKinds).flatMap((m) => linksNaming(toRenderTree(m.body, 'marker'))))]
|
|
131
|
+
const waiting = urls.filter((url) => !links.answered(url)).slice(0, MAX_MENTIONED_IN_LINKS_ASKED)
|
|
111
132
|
if (waiting.length) await within(links.ask(waiting), options.waitMs ?? 5000)
|
|
112
133
|
return mentionedInOf(events, address, links.known, options.commentKinds, (url) => !links.answered(url))
|
|
113
134
|
}
|