@estiva-app/interop 0.82.0 → 0.84.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 +43 -0
- package/README.md +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/projection.d.ts +53 -2
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +143 -22
- package/dist/projection.js.map +1 -1
- package/dist/references.d.ts +25 -2
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +51 -6
- package/dist/references.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +2 -0
- package/src/projection.ts +181 -28
- package/src/references.ts +82 -6
package/dist/references.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { type ReferenceCandidate, type ReferenceType } from '@estiva-app/conversation';
|
|
17
17
|
import { type ForeignObject, type ProjectionCache, type QueryFn } from './projection.js';
|
|
18
|
+
import { type SearchMatch, type SignedEvent } from '@estiva-app/protocol';
|
|
18
19
|
/**
|
|
19
20
|
* The kinds `[` offers as files, and the type word each draws as. A Leaf page
|
|
20
21
|
* is offered in every app, beside topics, projects and issues (Miky, SUM-7
|
|
@@ -29,6 +30,8 @@ export interface FileCandidatesOptions {
|
|
|
29
30
|
inOrder?: readonly string[];
|
|
30
31
|
/** The host Ship serves projects from: a picked project's link is `<it>/project/<d>`. Ship's own unless said, so every app picks the same link. */
|
|
31
32
|
projectOrigin?: string;
|
|
33
|
+
/** The relay offers the list read: an issue's project, read for its caption, is read by its current fields (`resolveForeignRoots`). */
|
|
34
|
+
listRead?: boolean;
|
|
32
35
|
}
|
|
33
36
|
/** Where Ship serves projects (§13.1, decided 2026-11-03): one link for a project, whichever app picked it. */
|
|
34
37
|
export declare const SHIP_ORIGIN = "https://ship.estiva.app";
|
|
@@ -51,10 +54,27 @@ export declare function pickedFileUri(address: string, { inOrder, projectOrigin
|
|
|
51
54
|
* offerable — unreachable, untitled, or of a kind `[` does not offer — are
|
|
52
55
|
* left out.
|
|
53
56
|
*/
|
|
54
|
-
export declare function fileCandidates(objects: readonly (ForeignObject | null | undefined)[], tier: number, query: QueryFn, { cache, at, inOrder, projectOrigin }?: FileCandidatesOptions): Promise<ReferenceCandidate[]>;
|
|
57
|
+
export declare function fileCandidates(objects: readonly (ForeignObject | null | undefined)[], tier: number, query: QueryFn, { cache, at, inOrder, projectOrigin, listRead }?: FileCandidatesOptions): Promise<ReferenceCandidate[]>;
|
|
58
|
+
/** A `/query` that keeps what a `search` found besides its events (protocol's `Relay.queryWithMatches`). */
|
|
59
|
+
export type SearchQueryFn = (filters: Record<string, unknown>[]) => Promise<{
|
|
60
|
+
events: SignedEvent[];
|
|
61
|
+
matches: readonly SearchMatch[];
|
|
62
|
+
}>;
|
|
55
63
|
export interface SearchFileReferencesOptions extends Omit<FileCandidatesOptions, 'at'> {
|
|
56
64
|
/** How many roots, and separately how many renames, the relay is asked for. Default 32. */
|
|
57
65
|
limit?: number;
|
|
66
|
+
/**
|
|
67
|
+
* The kinds the relay finds by the words of their current fields (NIP-11
|
|
68
|
+
* `file_search`, `RelayFileReads.search`), and the read that asks it. Those
|
|
69
|
+
* kinds are found by their summary, key and text too, through the list read;
|
|
70
|
+
* every other kind by its title as before.
|
|
71
|
+
*/
|
|
72
|
+
byFields?: {
|
|
73
|
+
kinds: readonly number[];
|
|
74
|
+
query: SearchQueryFn;
|
|
75
|
+
/** The relay's `file_search.max_page_size`, which refuses a larger page. Default 20, production's. */
|
|
76
|
+
limit?: number;
|
|
77
|
+
};
|
|
58
78
|
}
|
|
59
79
|
/**
|
|
60
80
|
* The files whose **current** title — or, for an issue, current ref (CON-33)
|
|
@@ -73,6 +93,9 @@ export interface SearchFileReferencesOptions extends Omit<FileCandidatesOptions,
|
|
|
73
93
|
* still sent for a relay from before that rule. A relay that indexes none of these
|
|
74
94
|
* kinds answers nothing, and so does this. A failed read rejects, for
|
|
75
95
|
* `referenceSearch` to answer no hits for a while.
|
|
96
|
+
*
|
|
97
|
+
* With `byFields`, its kinds are found by the words of their current fields
|
|
98
|
+
* instead, ahead of the title hits (`searchByFields`).
|
|
76
99
|
*/
|
|
77
|
-
export declare function searchFileReferences(text: string, query: QueryFn, { limit, ...options }?: SearchFileReferencesOptions): Promise<ReferenceCandidate[]>;
|
|
100
|
+
export declare function searchFileReferences(text: string, query: QueryFn, { limit, byFields, ...options }?: SearchFileReferencesOptions): Promise<ReferenceCandidate[]>;
|
|
78
101
|
//# sourceMappingURL=references.d.ts.map
|
package/dist/references.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAA;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,OAAO,EACb,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAgB,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAMvF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAKxE,CAAA;AA2BD,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,eAAe,CAAA;IACvB,0FAA0F;IAC1F,EAAE,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,6GAA6G;IAC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GAoBG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,EAAE,KAAU,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,GAAE,2BAAgC,GACrE,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAS/B"}
|
package/dist/references.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* at the lowest priority, and so is an issue in an archived project.
|
|
15
15
|
*/
|
|
16
16
|
import { FILE_TIER, fileReference, KIND_CHANGE, referenceMatch, refMatch, } from '@estiva-app/conversation';
|
|
17
|
-
import { isClosedStatus, KIND_BARE_FILE, resolveForeignRoots, } from './projection.js';
|
|
17
|
+
import { isClosedStatus, KIND_BARE_FILE, projectListedFiles, resolveForeignRoots, } from './projection.js';
|
|
18
18
|
import { fileIdFormOf } from '@estiva-app/protocol';
|
|
19
19
|
const KIND_PROJECT = 30850;
|
|
20
20
|
const KIND_ISSUE = 30851;
|
|
@@ -71,7 +71,7 @@ export function pickedFileUri(address, { inOrder = [], projectOrigin = SHIP_ORIG
|
|
|
71
71
|
* offerable — unreachable, untitled, or of a kind `[` does not offer — are
|
|
72
72
|
* left out.
|
|
73
73
|
*/
|
|
74
|
-
export async function fileCandidates(objects, tier, query, { cache, at, inOrder, projectOrigin } = {}) {
|
|
74
|
+
export async function fileCandidates(objects, tier, query, { cache, at, inOrder, projectOrigin, listRead } = {}) {
|
|
75
75
|
const files = objects.filter(offerable);
|
|
76
76
|
const parents = new Map();
|
|
77
77
|
for (const o of objects)
|
|
@@ -81,7 +81,7 @@ export async function fileCandidates(objects, tier, query, { cache, at, inOrder,
|
|
|
81
81
|
...new Set(files.flatMap((o) => (o.kind === KIND_ISSUE && o.parentRef && !parents.has(o.parentRef) ? [o.parentRef] : []))),
|
|
82
82
|
];
|
|
83
83
|
if (missing.length) {
|
|
84
|
-
const read = await resolveForeignRoots(missing, query, cache).catch(() => []);
|
|
84
|
+
const read = await resolveForeignRoots(missing, query, cache, { listRead }).catch(() => []);
|
|
85
85
|
for (const parent of read)
|
|
86
86
|
if (parent.address)
|
|
87
87
|
parents.set(parent.address, parent);
|
|
@@ -130,14 +130,29 @@ const searchedChange = (field, address) => field === 'title' || (field === 'ref'
|
|
|
130
130
|
* still sent for a relay from before that rule. A relay that indexes none of these
|
|
131
131
|
* kinds answers nothing, and so does this. A failed read rejects, for
|
|
132
132
|
* `referenceSearch` to answer no hits for a while.
|
|
133
|
+
*
|
|
134
|
+
* With `byFields`, its kinds are found by the words of their current fields
|
|
135
|
+
* instead, ahead of the title hits (`searchByFields`).
|
|
133
136
|
*/
|
|
134
|
-
export async function searchFileReferences(text, query, { limit = 32, ...options } = {}) {
|
|
137
|
+
export async function searchFileReferences(text, query, { limit = 32, byFields, ...options } = {}) {
|
|
135
138
|
const wanted = text.trim();
|
|
136
139
|
if (!wanted)
|
|
137
140
|
return [];
|
|
141
|
+
const fieldKinds = new Set(byFields?.kinds.filter((kind) => typeOf(kind)) ?? []);
|
|
142
|
+
const [byTitle, found] = await Promise.all([
|
|
143
|
+
searchByTitle(wanted, query, limit, fieldKinds, options),
|
|
144
|
+
byFields && fieldKinds.size ? searchByFields(wanted, byFields.query, [...fieldKinds], byFields.limit ?? 20, query, options) : [],
|
|
145
|
+
]);
|
|
146
|
+
return [...found, ...byTitle];
|
|
147
|
+
}
|
|
148
|
+
/** The files of every kind but `skip` whose current title or ref holds `wanted`. */
|
|
149
|
+
async function searchByTitle(wanted, query, limit, skip, options) {
|
|
150
|
+
const kinds = Object.keys(REFERENCE_FILE_TYPES).map(Number).filter((kind) => !skip.has(kind));
|
|
151
|
+
if (!kinds.length)
|
|
152
|
+
return [];
|
|
138
153
|
const asked = { search: wanted, search_mode: 'prefix', limit };
|
|
139
154
|
const hits = await query([
|
|
140
|
-
{ kinds
|
|
155
|
+
{ kinds, ...asked },
|
|
141
156
|
{ kinds: [KIND_CHANGE], ...asked },
|
|
142
157
|
]);
|
|
143
158
|
const at = new Map();
|
|
@@ -145,7 +160,8 @@ export async function searchFileReferences(text, query, { limit = 32, ...options
|
|
|
145
160
|
const address = hit.kind === KIND_CHANGE
|
|
146
161
|
? searchedChange(tagOf(hit, 'field'), tagOf(hit, 'a'))
|
|
147
162
|
: typeOf(hit.kind) && `${hit.kind}:${hit.pubkey}:${tagOf(hit, 'd') ?? ''}`;
|
|
148
|
-
|
|
163
|
+
const kind = Number(address?.split(':')[0]);
|
|
164
|
+
if (!address || !typeOf(kind) || skip.has(kind))
|
|
149
165
|
continue;
|
|
150
166
|
at.set(address, Math.max(at.get(address) ?? 0, hit.created_at));
|
|
151
167
|
}
|
|
@@ -155,4 +171,33 @@ export async function searchFileReferences(text, query, { limit = 32, ...options
|
|
|
155
171
|
const matching = objects.filter((o) => (o.slots.title && referenceMatch(o.slots.title.value, wanted) > 0) || refMatch(refOf(o), wanted) > 0);
|
|
156
172
|
return fileCandidates(matching, FILE_TIER.search, query, { ...options, at });
|
|
157
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* The files of `kinds` whose current title, summary, key or text holds
|
|
176
|
+
* `wanted`, by the relay's list read with `search` (§6.13): each hit is its
|
|
177
|
+
* first record and its fields' current changes, so nothing is folded from its
|
|
178
|
+
* history and nothing older than its current values matches. A hit found only
|
|
179
|
+
* in its text shows the words around the match as its second line.
|
|
180
|
+
*
|
|
181
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/search-finds-a-file-by-the-words-of-its-current-fields.md
|
|
182
|
+
*/
|
|
183
|
+
async function searchByFields(wanted, search, kinds, limit, query, options) {
|
|
184
|
+
const { events, matches } = await search([{ kinds, search: wanted, limit, fields: 'newest' }]);
|
|
185
|
+
const why = new Map(matches.map((m) => [m.a, m.match]));
|
|
186
|
+
const at = new Map();
|
|
187
|
+
const objects = (await projectListedFiles(events, query, options.cache)).filter((o) => o.address && why.has(o.address));
|
|
188
|
+
for (const event of events) {
|
|
189
|
+
const address = event.kind === KIND_CHANGE ? tagOf(event, 'a') : `${event.kind}:${event.pubkey}:${tagOf(event, 'd') ?? ''}`;
|
|
190
|
+
if (address && why.has(address))
|
|
191
|
+
at.set(address, Math.max(at.get(address) ?? 0, event.created_at));
|
|
192
|
+
}
|
|
193
|
+
const rank = new Map(matches.map((m, i) => [m.a, i]));
|
|
194
|
+
objects.sort((a, b) => rank.get(a.address) - rank.get(b.address));
|
|
195
|
+
const rows = await fileCandidates(objects, FILE_TIER.search, query, { ...options, at });
|
|
196
|
+
return rows.map((row) => {
|
|
197
|
+
const match = why.get(row.id);
|
|
198
|
+
const around = match.fields[0] === 'text' ? match.around?.replace(/\s+/g, ' ').trim() : undefined;
|
|
199
|
+
// "…" marks words from inside the text, not the file's own summary; the relay does not say where they start.
|
|
200
|
+
return { ...row, matched: match.fields, ...(around ? { summary: `…${around}` } : {}) };
|
|
201
|
+
});
|
|
202
|
+
}
|
|
158
203
|
//# sourceMappingURL=references.js.map
|
package/dist/references.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.js","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,SAAS,EACT,aAAa,EACb,WAAW,EACX,cAAc,EACd,QAAQ,GAGT,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,cAAc,EACd,cAAc,EACd,mBAAmB,GAIpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"references.js","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,SAAS,EACT,aAAa,EACb,WAAW,EACX,cAAc,EACd,QAAQ,GAGT,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,mBAAmB,GAIpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,YAAY,EAAsC,MAAM,sBAAsB,CAAA;AAEvF,MAAM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AM,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;QACjG,6GAA6G;QAC7G,OAAO,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;IACxF,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.84.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",
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"prepublishOnly": "npm run build"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@estiva-app/conversation": ">=0.
|
|
50
|
+
"@estiva-app/conversation": ">=0.31.0",
|
|
51
51
|
"@estiva-app/protocol": ">=0.52.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@estiva-app/conversation": ">=0.
|
|
54
|
+
"@estiva-app/conversation": ">=0.31.0",
|
|
55
55
|
"@estiva-app/protocol": ">=0.52.0",
|
|
56
56
|
"typescript": "~5.9.3"
|
|
57
57
|
}
|
package/src/index.ts
CHANGED
package/src/projection.ts
CHANGED
|
@@ -186,6 +186,7 @@ function pubkeysIn(object: ForeignObject): string[] {
|
|
|
186
186
|
for (const action of object.actions) {
|
|
187
187
|
if (action.control === 'pubkey' && action.current) keys.push(action.current)
|
|
188
188
|
}
|
|
189
|
+
if (object.deleted) keys.push(object.deleted.by)
|
|
189
190
|
return keys
|
|
190
191
|
}
|
|
191
192
|
|
|
@@ -2391,7 +2392,7 @@ function inTargetFolder(change: SignedEvent, folders: ReadonlySet<string> | unde
|
|
|
2391
2392
|
* version where several are.
|
|
2392
2393
|
*/
|
|
2393
2394
|
function foldChanges(changes: SignedEvent[], rule: RecordsRule, root: SignedEvent | undefined) {
|
|
2394
|
-
const fields: Record<string, { value: string; by: string; at: number; format: ContentFormat }> = {}
|
|
2395
|
+
const fields: Record<string, { value: string; by: string; at: number; format: ContentFormat; id: string }> = {}
|
|
2395
2396
|
const folders = targetFolders(root)
|
|
2396
2397
|
const id = root && tagValue(root, 'd')
|
|
2397
2398
|
for (const change of [...changes].filter((c) => inTargetFolder(c, folders)).sort(byOrder)) {
|
|
@@ -2402,6 +2403,9 @@ function foldChanges(changes: SignedEvent[], rule: RecordsRule, root: SignedEven
|
|
|
2402
2403
|
// A summary is new, so it takes neither of §6.2's exceptions: a change the
|
|
2403
2404
|
// reader cannot check against the root's Folder is not read (SPEC §6.12).
|
|
2404
2405
|
if (field === SUMMARY_FIELD && !folders) continue
|
|
2406
|
+
// A delete is by "anyone who may write in the file's team" (SPEC §6.5), and
|
|
2407
|
+
// a root that names no team has none: no change can delete it.
|
|
2408
|
+
if (field === DELETED_FIELD && !folders) continue
|
|
2405
2409
|
// The format travels with the *winning* change, not with the object. SPEC
|
|
2406
2410
|
// §13.4: "an app MUST read the tag from the event it took the value from,
|
|
2407
2411
|
// never from the object's root" — a description created as marker text and
|
|
@@ -2411,6 +2415,7 @@ function foldChanges(changes: SignedEvent[], rule: RecordsRule, root: SignedEven
|
|
|
2411
2415
|
by: change.pubkey,
|
|
2412
2416
|
at: change.created_at,
|
|
2413
2417
|
format: contentFormatOf(change),
|
|
2418
|
+
id: change.id,
|
|
2414
2419
|
}
|
|
2415
2420
|
}
|
|
2416
2421
|
}
|
|
@@ -3352,6 +3357,33 @@ export interface ForeignObject {
|
|
|
3352
3357
|
* `created_at`. Absent on an unreachable stub, which has no root to read.
|
|
3353
3358
|
*/
|
|
3354
3359
|
changedAt?: number
|
|
3360
|
+
/**
|
|
3361
|
+
* Each changed field's current change id: the `prev` a change to that field
|
|
3362
|
+
* names (SPEC §6.2). A field never changed is absent, and its first change
|
|
3363
|
+
* names the first record — {@link prevOf} answers both. Absent on a regular
|
|
3364
|
+
* event and an unreachable stub. A file read by a list carries no text: its
|
|
3365
|
+
* text's entry is `''`, and {@link prevOf} answers undefined for it.
|
|
3366
|
+
*
|
|
3367
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-its-fields-each-kept-in-order-by-the-relay.md
|
|
3368
|
+
*/
|
|
3369
|
+
prevs?: Record<string, string>
|
|
3370
|
+
/**
|
|
3371
|
+
* Set when the file's newest `deleted` change is `true` (SPEC §6.5): who
|
|
3372
|
+
* deleted it and when, in seconds. A deleted file is still read by its id, for
|
|
3373
|
+
* the notice that says so and its Restore.
|
|
3374
|
+
*/
|
|
3375
|
+
deleted?: { by: string; at: number }
|
|
3376
|
+
}
|
|
3377
|
+
|
|
3378
|
+
/**
|
|
3379
|
+
* The change a change to `field` of `object` follows (SPEC §6.2): its current
|
|
3380
|
+
* change, else the first record. Undefined for the text of a file read by a
|
|
3381
|
+
* list, which carries no text: open it to write it.
|
|
3382
|
+
*/
|
|
3383
|
+
export function prevOf(object: Pick<ForeignObject, 'prevs' | 'eventId'>, field: string): string | undefined {
|
|
3384
|
+
const id = object.prevs?.[field]
|
|
3385
|
+
if (id === '') return undefined
|
|
3386
|
+
return id ?? object.eventId
|
|
3355
3387
|
}
|
|
3356
3388
|
|
|
3357
3389
|
/** The newest of a root's `created_at` and its folded fields' changes. */
|
|
@@ -3371,7 +3403,7 @@ function buildObject(args: {
|
|
|
3371
3403
|
pointer: AddressPointer
|
|
3372
3404
|
manifest: Manifest
|
|
3373
3405
|
projection: Projection
|
|
3374
|
-
folded: Record<string, { value: string; format?: ContentFormat; at?: number }>
|
|
3406
|
+
folded: Record<string, { value: string; format?: ContentFormat; at?: number; by?: string; id?: string }>
|
|
3375
3407
|
viaRecommendation: boolean
|
|
3376
3408
|
webTemplate?: string
|
|
3377
3409
|
comments?: ForeignObject['comments']
|
|
@@ -3381,6 +3413,9 @@ function buildObject(args: {
|
|
|
3381
3413
|
const naddr = encodeNaddr(pointer)
|
|
3382
3414
|
const { slots, meta } = resolveSlots(projection, root, folded, manifest)
|
|
3383
3415
|
const objectAddress = pointerToAddress(pointer)
|
|
3416
|
+
// A list read's text placeholder keeps its empty id: the text's `prev` is unknown there, not the first record.
|
|
3417
|
+
const prevs = Object.fromEntries(Object.entries(folded).flatMap(([field, f]) => (f.id !== undefined ? [[field, f.id]] : [])))
|
|
3418
|
+
const deleted = folded[DELETED_FIELD]
|
|
3384
3419
|
return {
|
|
3385
3420
|
// An addressable object's `ref` is its address: stable across the author
|
|
3386
3421
|
// replacing the event, which the event id is not.
|
|
@@ -3407,9 +3442,14 @@ function buildObject(args: {
|
|
|
3407
3442
|
viaRecommendation: args.viaRecommendation,
|
|
3408
3443
|
...(args.archived ? { archived: args.archived } : {}),
|
|
3409
3444
|
changedAt: changedAtOf(root, folded),
|
|
3445
|
+
...(Object.keys(prevs).length ? { prevs } : {}),
|
|
3446
|
+
...(deleted?.value === 'true' && deleted.by ? { deleted: { by: deleted.by, at: deleted.at ?? root.created_at } } : {}),
|
|
3410
3447
|
}
|
|
3411
3448
|
}
|
|
3412
3449
|
|
|
3450
|
+
/** The field a file is deleted by (SPEC §6.5): `true` deletes it, the empty value restores it. */
|
|
3451
|
+
const DELETED_FIELD = 'deleted'
|
|
3452
|
+
|
|
3413
3453
|
/**
|
|
3414
3454
|
* An addressable file's actions, each with what its field holds now, however
|
|
3415
3455
|
* it got there.
|
|
@@ -3553,19 +3593,21 @@ export async function resolveForeignObject(
|
|
|
3553
3593
|
if (!pointer) return null
|
|
3554
3594
|
const resolved = await resolveManifest(pointer, query, cache)
|
|
3555
3595
|
if (!resolved) return null
|
|
3556
|
-
const plan = planObject(naddr, pointer, resolved, depth)
|
|
3596
|
+
const plan = planObject(naddr, pointer, resolved, depth, options.openRead)
|
|
3557
3597
|
if (!plan) return null
|
|
3558
3598
|
|
|
3559
3599
|
// Beside the object's own read, not after it: the sweep is cached, and cold
|
|
3560
3600
|
// it would otherwise add a round trip to every resolve that pays for it.
|
|
3561
3601
|
// A Folder card's files too, for the same reason.
|
|
3562
|
-
const [
|
|
3602
|
+
const [read, opened, creators, files] = await Promise.all([
|
|
3563
3603
|
query(plan.filters),
|
|
3604
|
+
openedEvents([plan], query),
|
|
3564
3605
|
creatorsOrNone(pointer.kind, query, cache),
|
|
3565
3606
|
options.folderFiles && pointer.kind === KIND_CHANNEL_METADATA
|
|
3566
3607
|
? folderFilesOf(pointer.identifier, query, lookupPeople, cache)
|
|
3567
3608
|
: undefined,
|
|
3568
3609
|
])
|
|
3610
|
+
const answered = [...read, ...opened]
|
|
3569
3611
|
const followUp = childChangeFilters(plan, answered)
|
|
3570
3612
|
const childChanges = followUp.length ? await queryChunked(followUp, query) : []
|
|
3571
3613
|
const childOwners = await childOwnersOf(plan, answered, childChanges, query, cache)
|
|
@@ -3662,7 +3704,7 @@ export async function resolveForeignObjects(
|
|
|
3662
3704
|
|
|
3663
3705
|
const plans = asked.flatMap(({ reference, pointer }) => {
|
|
3664
3706
|
const resolved = manifests.get(manifestKeyOf(pointer))
|
|
3665
|
-
const plan = resolved && planObject(reference, pointer, resolved, 0)
|
|
3707
|
+
const plan = resolved && planObject(reference, pointer, resolved, 0, options.openRead)
|
|
3666
3708
|
return plan ? [{ reference, plan }] : []
|
|
3667
3709
|
})
|
|
3668
3710
|
if (plans.length === 0) return results
|
|
@@ -3687,11 +3729,13 @@ export async function resolveForeignObjects(
|
|
|
3687
3729
|
),
|
|
3688
3730
|
]
|
|
3689
3731
|
: []
|
|
3690
|
-
const [
|
|
3732
|
+
const [read, opened, creatorLists, fileLists] = await Promise.all([
|
|
3691
3733
|
queryChunked(filters, query),
|
|
3734
|
+
openedEvents(plans.map(({ plan }) => plan), query),
|
|
3692
3735
|
Promise.all(kinds.map((kind) => creatorsOrNone(kind, query, cache))),
|
|
3693
3736
|
Promise.all(folders.map((folder) => folderFilesOf(folder, query, lookupPeople, cache))),
|
|
3694
3737
|
])
|
|
3738
|
+
const events = [...read, ...opened]
|
|
3695
3739
|
const creatorsByKind = new Map(kinds.map((kind, i) => [kind, creatorLists[i]]))
|
|
3696
3740
|
const filesByFolder = new Map(folders.map((folder, i) => [folder, fileLists[i]]))
|
|
3697
3741
|
|
|
@@ -3854,8 +3898,13 @@ export async function resolveForeignRoots(
|
|
|
3854
3898
|
references: readonly string[],
|
|
3855
3899
|
query: QueryFn,
|
|
3856
3900
|
cache?: ProjectionCache,
|
|
3857
|
-
/**
|
|
3858
|
-
|
|
3901
|
+
/**
|
|
3902
|
+
* `archivedWith` marks a file archived with an archived parent, as {@link resolveForeignObject}'s does (SHIPS-2).
|
|
3903
|
+
* `listRead`, where the relay offers the list read (NIP-11 `file_list`), reads each file of the relay's file kinds
|
|
3904
|
+
* as its first record and its fields' current changes (§6.13), not every change ever made to it: no text, and a
|
|
3905
|
+
* deleted file is absent. Other kinds are read as before.
|
|
3906
|
+
*/
|
|
3907
|
+
options: Pick<ArchiveReadOptions, 'archivedWith'> & { listRead?: boolean } = {},
|
|
3859
3908
|
): Promise<ForeignObject[]> {
|
|
3860
3909
|
const pointers = new Map<string, AddressPointer>()
|
|
3861
3910
|
for (const reference of references) {
|
|
@@ -3863,33 +3912,40 @@ export async function resolveForeignRoots(
|
|
|
3863
3912
|
if (pointer) pointers.set(`${pointer.kind}:${pointer.pubkey}:${pointer.identifier}`, pointer)
|
|
3864
3913
|
}
|
|
3865
3914
|
if (pointers.size === 0) return []
|
|
3866
|
-
|
|
3867
|
-
const manifests = new Map<string, ResolvedManifest>()
|
|
3868
|
-
const byApp = new Map<string, AddressPointer>()
|
|
3869
|
-
for (const pointer of pointers.values()) byApp.set(manifestKeyOf(pointer), pointer)
|
|
3870
|
-
await Promise.all(
|
|
3871
|
-
[...byApp].map(async ([key, pointer]) => {
|
|
3872
|
-
const resolved = await resolveManifest(pointer, query, cache)
|
|
3873
|
-
if (resolved) manifests.set(key, resolved)
|
|
3874
|
-
}),
|
|
3875
|
-
)
|
|
3915
|
+
const manifests = await manifestsOf(pointers.values(), query, cache)
|
|
3876
3916
|
|
|
3877
3917
|
const filters: Record<string, unknown>[] = []
|
|
3918
|
+
// One list read per author and kind: `limit` counts first records there, not the changes beside them.
|
|
3919
|
+
const listedBy = new Map<string, { kind: number; pubkey: string; identifiers: string[] }>()
|
|
3878
3920
|
for (const [address, pointer] of pointers) {
|
|
3879
3921
|
const resolved = manifests.get(manifestKeyOf(pointer))
|
|
3880
3922
|
if (!resolved?.manifest.projections?.[String(pointer.kind)]) continue
|
|
3923
|
+
if (options.listRead && FILE_KINDS.includes(pointer.kind)) {
|
|
3924
|
+
const key = `${pointer.kind}:${pointer.pubkey}`
|
|
3925
|
+
const group = listedBy.get(key) ?? { kind: pointer.kind, pubkey: pointer.pubkey, identifiers: [] }
|
|
3926
|
+
group.identifiers.push(pointer.identifier)
|
|
3927
|
+
listedBy.set(key, group)
|
|
3928
|
+
continue
|
|
3929
|
+
}
|
|
3930
|
+
const root = { kinds: [pointer.kind], authors: [pointer.pubkey], '#d': [pointer.identifier], limit: 1 }
|
|
3881
3931
|
// A manifest without `records` folds by a placeholder kind 0, never sent.
|
|
3882
3932
|
const changeKinds = new Set(
|
|
3883
3933
|
[foldRuleOf(resolved.manifest).changeKind, archiveRuleOf(resolved.manifest).changeKind].filter((k) => k !== 0),
|
|
3884
3934
|
)
|
|
3885
|
-
filters.push(
|
|
3886
|
-
{ kinds: [pointer.kind], authors: [pointer.pubkey], '#d': [pointer.identifier], limit: 1 },
|
|
3887
|
-
{ kinds: [...changeKinds], '#a': [address], limit: 500 },
|
|
3888
|
-
)
|
|
3935
|
+
filters.push(root, { kinds: [...changeKinds], '#a': [address], limit: 500 })
|
|
3889
3936
|
}
|
|
3890
|
-
|
|
3891
|
-
const
|
|
3892
|
-
|
|
3937
|
+
const listed: Record<string, unknown>[] = []
|
|
3938
|
+
for (const { kind, pubkey, identifiers } of listedBy.values()) {
|
|
3939
|
+
for (let start = 0; start < identifiers.length; start += RELAY_PAGE_CEILING) {
|
|
3940
|
+
const chunk = identifiers.slice(start, start + RELAY_PAGE_CEILING)
|
|
3941
|
+
listed.push({ kinds: [kind], authors: [pubkey], '#d': chunk, limit: chunk.length, fields: 'newest' })
|
|
3942
|
+
}
|
|
3943
|
+
}
|
|
3944
|
+
if (filters.length === 0 && listed.length === 0) return []
|
|
3945
|
+
// A relay refuses a request mixing list reads with plain ones, so each goes on its own.
|
|
3946
|
+
const events = (await Promise.all([queryChunked(filters, query), queryChunked(listed, query)])).flat()
|
|
3947
|
+
const projected = projectEvents(events, (pointer) => manifests.get(manifestKeyOf(pointer)))
|
|
3948
|
+
const objects = options.listRead ? textUnread(projected) : projected
|
|
3893
3949
|
if (options.archivedWith) {
|
|
3894
3950
|
const manifestOf = (object: ForeignObject) => {
|
|
3895
3951
|
const pointer = object.address ? addressPointerOf(object.address) : undefined
|
|
@@ -3900,6 +3956,48 @@ export async function resolveForeignRoots(
|
|
|
3900
3956
|
return objects
|
|
3901
3957
|
}
|
|
3902
3958
|
|
|
3959
|
+
/** The manifest each pointer's author reads it through, one read per `kind:pubkey`. */
|
|
3960
|
+
async function manifestsOf(pointers: Iterable<AddressPointer>, query: QueryFn, cache?: ProjectionCache): Promise<Map<string, ResolvedManifest>> {
|
|
3961
|
+
const manifests = new Map<string, ResolvedManifest>()
|
|
3962
|
+
const byApp = new Map<string, AddressPointer>()
|
|
3963
|
+
for (const pointer of pointers) byApp.set(manifestKeyOf(pointer), pointer)
|
|
3964
|
+
await Promise.all(
|
|
3965
|
+
[...byApp].map(async ([key, pointer]) => {
|
|
3966
|
+
const resolved = await resolveManifest(pointer, query, cache)
|
|
3967
|
+
if (resolved) manifests.set(key, resolved)
|
|
3968
|
+
}),
|
|
3969
|
+
)
|
|
3970
|
+
return manifests
|
|
3971
|
+
}
|
|
3972
|
+
|
|
3973
|
+
/**
|
|
3974
|
+
* The files a list read answered (§6.13) — each first record with its fields'
|
|
3975
|
+
* current changes — folded through their apps' manifests as
|
|
3976
|
+
* {@link resolveForeignRoots} folds them. Nothing more is read but the manifests.
|
|
3977
|
+
*/
|
|
3978
|
+
export async function projectListedFiles(events: readonly SignedEvent[], query: QueryFn, cache?: ProjectionCache): Promise<ForeignObject[]> {
|
|
3979
|
+
const pointers: AddressPointer[] = []
|
|
3980
|
+
for (const event of events) {
|
|
3981
|
+
// A change names its file by `a` and carries no `d`.
|
|
3982
|
+
const identifier = tagValue(event, 'd')
|
|
3983
|
+
if (identifier !== undefined) pointers.push({ kind: event.kind, pubkey: event.pubkey, identifier, relays: [] })
|
|
3984
|
+
}
|
|
3985
|
+
if (pointers.length === 0) return []
|
|
3986
|
+
const manifests = await manifestsOf(pointers, query, cache)
|
|
3987
|
+
return textUnread(projectEvents(events, (pointer) => manifests.get(manifestKeyOf(pointer))))
|
|
3988
|
+
}
|
|
3989
|
+
|
|
3990
|
+
/**
|
|
3991
|
+
* Files read by a list carry no text (§6.13), and a change that set it with other
|
|
3992
|
+
* fields may be stale: the text's `prev` is unknown, `''`, so {@link prevOf}
|
|
3993
|
+
* answers nothing for it rather than an old change or the first record.
|
|
3994
|
+
*/
|
|
3995
|
+
function textUnread(objects: ForeignObject[]): ForeignObject[] {
|
|
3996
|
+
return objects.map((object) =>
|
|
3997
|
+
FILE_KINDS.includes(object.kind) ? { ...object, prevs: { ...object.prevs, description: '' } } : object,
|
|
3998
|
+
)
|
|
3999
|
+
}
|
|
4000
|
+
|
|
3903
4001
|
/**
|
|
3904
4002
|
* The parent each file sits under, and nothing else — FOL-50.
|
|
3905
4003
|
*
|
|
@@ -4040,6 +4138,19 @@ export interface ArchiveReadOptions {
|
|
|
4040
4138
|
* changes are read either way.
|
|
4041
4139
|
*/
|
|
4042
4140
|
archivedChildren?: boolean
|
|
4141
|
+
/**
|
|
4142
|
+
* The file kinds to open by the relay's open read (SPEC §6.13, "Opening a
|
|
4143
|
+
* file reads its current text too"): the first record, each field's current
|
|
4144
|
+
* change and the current text, however long its history — not every change by
|
|
4145
|
+
* `#a`. Pass it only where NIP-11's `file_list` says `text` (`relayFileReadsOf`
|
|
4146
|
+
* in `@estiva-app/protocol`), and only the kinds the app has switched; the rest
|
|
4147
|
+
* are read as before. A file the open read does not answer (deleted, or not
|
|
4148
|
+
* this reader's) is read as before too, so a deleted one still says who
|
|
4149
|
+
* deleted it.
|
|
4150
|
+
*
|
|
4151
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/opening-a-file-reads-its-current-text-not-its-history.md
|
|
4152
|
+
*/
|
|
4153
|
+
openRead?: readonly number[]
|
|
4043
4154
|
}
|
|
4044
4155
|
|
|
4045
4156
|
/**
|
|
@@ -4300,6 +4411,10 @@ interface ObjectPlan {
|
|
|
4300
4411
|
commentKinds: number[]
|
|
4301
4412
|
childFilter: ReturnType<typeof childFilterFor>
|
|
4302
4413
|
filters: Record<string, unknown>[]
|
|
4414
|
+
/** Read by the open read ({@link ArchiveReadOptions.openRead}), so `filters` holds neither its root nor its changes. */
|
|
4415
|
+
opened: boolean
|
|
4416
|
+
/** Its root and every change, as read before the open read: for a file that read does not answer. */
|
|
4417
|
+
history: Record<string, unknown>[]
|
|
4303
4418
|
openUrl?: string
|
|
4304
4419
|
}
|
|
4305
4420
|
|
|
@@ -4309,6 +4424,7 @@ function planObject(
|
|
|
4309
4424
|
pointer: AddressPointer,
|
|
4310
4425
|
resolved: ResolvedManifest,
|
|
4311
4426
|
depth: number,
|
|
4427
|
+
openRead?: readonly number[],
|
|
4312
4428
|
): ObjectPlan | null {
|
|
4313
4429
|
const { manifest } = resolved
|
|
4314
4430
|
const address = pointerToAddress(pointer)
|
|
@@ -4338,18 +4454,55 @@ function planObject(
|
|
|
4338
4454
|
one, and with the manifest memoised it is the whole cost of a tick.
|
|
4339
4455
|
*/
|
|
4340
4456
|
const childFilter = childFilterFor({ projection, manifest, pointer, depth })
|
|
4341
|
-
const
|
|
4457
|
+
const history = [
|
|
4342
4458
|
{ kinds: [pointer.kind], authors: [pointer.pubkey], '#d': [pointer.identifier], limit: 1 },
|
|
4343
4459
|
// Only when the app actually declares a change kind — see `foldRuleOf`.
|
|
4344
4460
|
...(manifest.records ? [{ kinds: [manifest.records.changeKind], '#a': [address], limit: 500 }] : []),
|
|
4345
4461
|
// Every file may be archived, including one whose app folds nothing
|
|
4346
4462
|
// (FOL-46). SPEC's change kind, when the app has not named its own.
|
|
4347
4463
|
...(manifest.records ? [] : [{ kinds: [ARCHIVE_RULE.changeKind], '#a': [address], limit: 500 }]),
|
|
4464
|
+
]
|
|
4465
|
+
const opened = !!openRead?.includes(pointer.kind) && FILE_KINDS.includes(pointer.kind)
|
|
4466
|
+
const filters = [
|
|
4467
|
+
...(opened ? [] : history),
|
|
4348
4468
|
{ kinds: commentKinds, '#a': [address], limit: CONVERSATION_LIMIT },
|
|
4349
4469
|
...(childFilter ? [childFilter.filter] : []),
|
|
4350
4470
|
...(childFilter?.movedIn ? [childFilter.movedIn] : []),
|
|
4351
4471
|
]
|
|
4352
|
-
return { naddr, pointer, address, resolved, projection, records, commentKinds, childFilter, filters, openUrl }
|
|
4472
|
+
return { naddr, pointer, address, resolved, projection, records, commentKinds, childFilter, filters, opened, history, openUrl }
|
|
4473
|
+
}
|
|
4474
|
+
|
|
4475
|
+
/**
|
|
4476
|
+
* What the open read answers for the planned files it opens (SPEC §6.13): one
|
|
4477
|
+
* read per author and kind, apart from the plain reads, since a relay refuses a
|
|
4478
|
+
* request mixing the two. A file it does not answer — deleted, or not this
|
|
4479
|
+
* reader's — has its root and every change read as before, so a deleted file
|
|
4480
|
+
* still says who deleted it and an unreadable one is still told apart from it.
|
|
4481
|
+
*/
|
|
4482
|
+
async function openedEvents(plans: readonly ObjectPlan[], query: QueryFn): Promise<SignedEvent[]> {
|
|
4483
|
+
const opened = new Map<string, ObjectPlan>()
|
|
4484
|
+
for (const plan of plans) if (plan.opened) opened.set(plan.address, plan)
|
|
4485
|
+
if (opened.size === 0) return []
|
|
4486
|
+
const groups = new Map<string, { kind: number; pubkey: string; identifiers: string[] }>()
|
|
4487
|
+
for (const { pointer } of opened.values()) {
|
|
4488
|
+
const key = `${pointer.kind}:${pointer.pubkey}`
|
|
4489
|
+
const group = groups.get(key) ?? { kind: pointer.kind, pubkey: pointer.pubkey, identifiers: [] }
|
|
4490
|
+
group.identifiers.push(pointer.identifier)
|
|
4491
|
+
groups.set(key, group)
|
|
4492
|
+
}
|
|
4493
|
+
const filters: Record<string, unknown>[] = []
|
|
4494
|
+
for (const { kind, pubkey, identifiers } of groups.values()) {
|
|
4495
|
+
for (let start = 0; start < identifiers.length; start += RELAY_PAGE_CEILING) {
|
|
4496
|
+
const chunk = identifiers.slice(start, start + RELAY_PAGE_CEILING)
|
|
4497
|
+
filters.push({ fields: 'newest', kinds: [kind], authors: [pubkey], '#d': chunk, limit: chunk.length, text: true })
|
|
4498
|
+
}
|
|
4499
|
+
}
|
|
4500
|
+
const answered = await queryChunked(filters, query)
|
|
4501
|
+
const unanswered = [...opened.values()].filter(
|
|
4502
|
+
({ pointer }) => !answered.some((e) => e.kind === pointer.kind && e.pubkey === pointer.pubkey && tagValue(e, 'd') === pointer.identifier),
|
|
4503
|
+
)
|
|
4504
|
+
const history = unanswered.length ? await queryChunked(unanswered.flatMap((plan) => plan.history), query) : []
|
|
4505
|
+
return [...answered, ...history]
|
|
4353
4506
|
}
|
|
4354
4507
|
|
|
4355
4508
|
/** An object and its children, before the people lookup that needs both. */
|
|
@@ -7209,7 +7362,7 @@ export async function resolveFolderContents(
|
|
|
7209
7362
|
// other fields may be stale: the text is unread, never the seed the file
|
|
7210
7363
|
// was created with drawn as if it were current.
|
|
7211
7364
|
if (byFields(pointer.kind)) {
|
|
7212
|
-
folded.description = { value: '', by: root.pubkey, at: root.created_at, format: 'marker' }
|
|
7365
|
+
folded.description = { value: '', by: root.pubkey, at: root.created_at, format: 'marker', id: '' }
|
|
7213
7366
|
}
|
|
7214
7367
|
const nestedAdmins =
|
|
7215
7368
|
pointer.kind === KIND_CHANNEL
|