@estiva-app/interop 0.82.0 → 0.83.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 +21 -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 +15 -2
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +59 -13
- 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 +1 -0
- package/src/projection.ts +60 -18
- 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;IAC7G,OAAO,CAAC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AAsB,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,YAAY,GAAG,K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,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.83.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
|
@@ -3854,8 +3854,13 @@ export async function resolveForeignRoots(
|
|
|
3854
3854
|
references: readonly string[],
|
|
3855
3855
|
query: QueryFn,
|
|
3856
3856
|
cache?: ProjectionCache,
|
|
3857
|
-
/**
|
|
3858
|
-
|
|
3857
|
+
/**
|
|
3858
|
+
* `archivedWith` marks a file archived with an archived parent, as {@link resolveForeignObject}'s does (SHIPS-2).
|
|
3859
|
+
* `listRead`, where the relay offers the list read (NIP-11 `file_list`), reads each file of the relay's file kinds
|
|
3860
|
+
* as its first record and its fields' current changes (§6.13), not every change ever made to it: no text, and a
|
|
3861
|
+
* deleted file is absent. Other kinds are read as before.
|
|
3862
|
+
*/
|
|
3863
|
+
options: Pick<ArchiveReadOptions, 'archivedWith'> & { listRead?: boolean } = {},
|
|
3859
3864
|
): Promise<ForeignObject[]> {
|
|
3860
3865
|
const pointers = new Map<string, AddressPointer>()
|
|
3861
3866
|
for (const reference of references) {
|
|
@@ -3863,32 +3868,38 @@ export async function resolveForeignRoots(
|
|
|
3863
3868
|
if (pointer) pointers.set(`${pointer.kind}:${pointer.pubkey}:${pointer.identifier}`, pointer)
|
|
3864
3869
|
}
|
|
3865
3870
|
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
|
-
)
|
|
3871
|
+
const manifests = await manifestsOf(pointers.values(), query, cache)
|
|
3876
3872
|
|
|
3877
3873
|
const filters: Record<string, unknown>[] = []
|
|
3874
|
+
// One list read per author and kind: `limit` counts first records there, not the changes beside them.
|
|
3875
|
+
const listedBy = new Map<string, { kind: number; pubkey: string; identifiers: string[] }>()
|
|
3878
3876
|
for (const [address, pointer] of pointers) {
|
|
3879
3877
|
const resolved = manifests.get(manifestKeyOf(pointer))
|
|
3880
3878
|
if (!resolved?.manifest.projections?.[String(pointer.kind)]) continue
|
|
3879
|
+
if (options.listRead && FILE_KINDS.includes(pointer.kind)) {
|
|
3880
|
+
const key = `${pointer.kind}:${pointer.pubkey}`
|
|
3881
|
+
const group = listedBy.get(key) ?? { kind: pointer.kind, pubkey: pointer.pubkey, identifiers: [] }
|
|
3882
|
+
group.identifiers.push(pointer.identifier)
|
|
3883
|
+
listedBy.set(key, group)
|
|
3884
|
+
continue
|
|
3885
|
+
}
|
|
3886
|
+
const root = { kinds: [pointer.kind], authors: [pointer.pubkey], '#d': [pointer.identifier], limit: 1 }
|
|
3881
3887
|
// A manifest without `records` folds by a placeholder kind 0, never sent.
|
|
3882
3888
|
const changeKinds = new Set(
|
|
3883
3889
|
[foldRuleOf(resolved.manifest).changeKind, archiveRuleOf(resolved.manifest).changeKind].filter((k) => k !== 0),
|
|
3884
3890
|
)
|
|
3885
|
-
filters.push(
|
|
3886
|
-
{ kinds: [pointer.kind], authors: [pointer.pubkey], '#d': [pointer.identifier], limit: 1 },
|
|
3887
|
-
{ kinds: [...changeKinds], '#a': [address], limit: 500 },
|
|
3888
|
-
)
|
|
3891
|
+
filters.push(root, { kinds: [...changeKinds], '#a': [address], limit: 500 })
|
|
3889
3892
|
}
|
|
3890
|
-
|
|
3891
|
-
const
|
|
3893
|
+
const listed: Record<string, unknown>[] = []
|
|
3894
|
+
for (const { kind, pubkey, identifiers } of listedBy.values()) {
|
|
3895
|
+
for (let start = 0; start < identifiers.length; start += RELAY_PAGE_CEILING) {
|
|
3896
|
+
const chunk = identifiers.slice(start, start + RELAY_PAGE_CEILING)
|
|
3897
|
+
listed.push({ kinds: [kind], authors: [pubkey], '#d': chunk, limit: chunk.length, fields: 'newest' })
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
if (filters.length === 0 && listed.length === 0) return []
|
|
3901
|
+
// A relay refuses a request mixing list reads with plain ones, so each goes on its own.
|
|
3902
|
+
const events = (await Promise.all([queryChunked(filters, query), queryChunked(listed, query)])).flat()
|
|
3892
3903
|
const objects = projectEvents(events, (pointer) => manifests.get(manifestKeyOf(pointer)))
|
|
3893
3904
|
if (options.archivedWith) {
|
|
3894
3905
|
const manifestOf = (object: ForeignObject) => {
|
|
@@ -3900,6 +3911,37 @@ export async function resolveForeignRoots(
|
|
|
3900
3911
|
return objects
|
|
3901
3912
|
}
|
|
3902
3913
|
|
|
3914
|
+
/** The manifest each pointer's author reads it through, one read per `kind:pubkey`. */
|
|
3915
|
+
async function manifestsOf(pointers: Iterable<AddressPointer>, query: QueryFn, cache?: ProjectionCache): Promise<Map<string, ResolvedManifest>> {
|
|
3916
|
+
const manifests = new Map<string, ResolvedManifest>()
|
|
3917
|
+
const byApp = new Map<string, AddressPointer>()
|
|
3918
|
+
for (const pointer of pointers) byApp.set(manifestKeyOf(pointer), pointer)
|
|
3919
|
+
await Promise.all(
|
|
3920
|
+
[...byApp].map(async ([key, pointer]) => {
|
|
3921
|
+
const resolved = await resolveManifest(pointer, query, cache)
|
|
3922
|
+
if (resolved) manifests.set(key, resolved)
|
|
3923
|
+
}),
|
|
3924
|
+
)
|
|
3925
|
+
return manifests
|
|
3926
|
+
}
|
|
3927
|
+
|
|
3928
|
+
/**
|
|
3929
|
+
* The files a list read answered (§6.13) — each first record with its fields'
|
|
3930
|
+
* current changes — folded through their apps' manifests as
|
|
3931
|
+
* {@link resolveForeignRoots} folds them. Nothing more is read but the manifests.
|
|
3932
|
+
*/
|
|
3933
|
+
export async function projectListedFiles(events: readonly SignedEvent[], query: QueryFn, cache?: ProjectionCache): Promise<ForeignObject[]> {
|
|
3934
|
+
const pointers: AddressPointer[] = []
|
|
3935
|
+
for (const event of events) {
|
|
3936
|
+
// A change names its file by `a` and carries no `d`.
|
|
3937
|
+
const identifier = tagValue(event, 'd')
|
|
3938
|
+
if (identifier !== undefined) pointers.push({ kind: event.kind, pubkey: event.pubkey, identifier, relays: [] })
|
|
3939
|
+
}
|
|
3940
|
+
if (pointers.length === 0) return []
|
|
3941
|
+
const manifests = await manifestsOf(pointers, query, cache)
|
|
3942
|
+
return projectEvents(events, (pointer) => manifests.get(manifestKeyOf(pointer)))
|
|
3943
|
+
}
|
|
3944
|
+
|
|
3903
3945
|
/**
|
|
3904
3946
|
* The parent each file sits under, and nothing else — FOL-50.
|
|
3905
3947
|
*
|
package/src/references.ts
CHANGED
|
@@ -25,12 +25,13 @@ import {
|
|
|
25
25
|
import {
|
|
26
26
|
isClosedStatus,
|
|
27
27
|
KIND_BARE_FILE,
|
|
28
|
+
projectListedFiles,
|
|
28
29
|
resolveForeignRoots,
|
|
29
30
|
type ForeignObject,
|
|
30
31
|
type ProjectionCache,
|
|
31
32
|
type QueryFn,
|
|
32
33
|
} from './projection.js'
|
|
33
|
-
import { fileIdFormOf } from '@estiva-app/protocol'
|
|
34
|
+
import { fileIdFormOf, type SearchMatch, type SignedEvent } from '@estiva-app/protocol'
|
|
34
35
|
|
|
35
36
|
const KIND_PROJECT = 30850
|
|
36
37
|
const KIND_ISSUE = 30851
|
|
@@ -81,6 +82,8 @@ export interface FileCandidatesOptions {
|
|
|
81
82
|
inOrder?: readonly string[]
|
|
82
83
|
/** 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. */
|
|
83
84
|
projectOrigin?: string
|
|
85
|
+
/** The relay offers the list read: an issue's project, read for its caption, is read by its current fields (`resolveForeignRoots`). */
|
|
86
|
+
listRead?: boolean
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
/** Where Ship serves projects (§13.1, decided 2026-11-03): one link for a project, whichever app picked it. */
|
|
@@ -116,7 +119,7 @@ export async function fileCandidates(
|
|
|
116
119
|
objects: readonly (ForeignObject | null | undefined)[],
|
|
117
120
|
tier: number,
|
|
118
121
|
query: QueryFn,
|
|
119
|
-
{ cache, at, inOrder, projectOrigin }: FileCandidatesOptions = {},
|
|
122
|
+
{ cache, at, inOrder, projectOrigin, listRead }: FileCandidatesOptions = {},
|
|
120
123
|
): Promise<ReferenceCandidate[]> {
|
|
121
124
|
const files = objects.filter(offerable)
|
|
122
125
|
const parents = new Map<string, ForeignObject>()
|
|
@@ -125,7 +128,7 @@ export async function fileCandidates(
|
|
|
125
128
|
...new Set(files.flatMap((o) => (o.kind === KIND_ISSUE && o.parentRef && !parents.has(o.parentRef) ? [o.parentRef] : []))),
|
|
126
129
|
]
|
|
127
130
|
if (missing.length) {
|
|
128
|
-
const read = await resolveForeignRoots(missing, query, cache).catch(() => [])
|
|
131
|
+
const read = await resolveForeignRoots(missing, query, cache, { listRead }).catch(() => [])
|
|
129
132
|
for (const parent of read) if (parent.address) parents.set(parent.address, parent)
|
|
130
133
|
}
|
|
131
134
|
return files.map((o) => {
|
|
@@ -150,9 +153,24 @@ export async function fileCandidates(
|
|
|
150
153
|
})
|
|
151
154
|
}
|
|
152
155
|
|
|
156
|
+
/** A `/query` that keeps what a `search` found besides its events (protocol's `Relay.queryWithMatches`). */
|
|
157
|
+
export type SearchQueryFn = (filters: Record<string, unknown>[]) => Promise<{ events: SignedEvent[]; matches: readonly SearchMatch[] }>
|
|
158
|
+
|
|
153
159
|
export interface SearchFileReferencesOptions extends Omit<FileCandidatesOptions, 'at'> {
|
|
154
160
|
/** How many roots, and separately how many renames, the relay is asked for. Default 32. */
|
|
155
161
|
limit?: number
|
|
162
|
+
/**
|
|
163
|
+
* The kinds the relay finds by the words of their current fields (NIP-11
|
|
164
|
+
* `file_search`, `RelayFileReads.search`), and the read that asks it. Those
|
|
165
|
+
* kinds are found by their summary, key and text too, through the list read;
|
|
166
|
+
* every other kind by its title as before.
|
|
167
|
+
*/
|
|
168
|
+
byFields?: {
|
|
169
|
+
kinds: readonly number[]
|
|
170
|
+
query: SearchQueryFn
|
|
171
|
+
/** The relay's `file_search.max_page_size`, which refuses a larger page. Default 20, production's. */
|
|
172
|
+
limit?: number
|
|
173
|
+
}
|
|
156
174
|
}
|
|
157
175
|
|
|
158
176
|
const tagOf = (event: { tags: string[][] }, name: string) => event.tags.find((t) => t[0] === name)?.[1]
|
|
@@ -181,17 +199,38 @@ const searchedChange = (field: string | undefined, address: string | undefined)
|
|
|
181
199
|
* still sent for a relay from before that rule. A relay that indexes none of these
|
|
182
200
|
* kinds answers nothing, and so does this. A failed read rejects, for
|
|
183
201
|
* `referenceSearch` to answer no hits for a while.
|
|
202
|
+
*
|
|
203
|
+
* With `byFields`, its kinds are found by the words of their current fields
|
|
204
|
+
* instead, ahead of the title hits (`searchByFields`).
|
|
184
205
|
*/
|
|
185
206
|
export async function searchFileReferences(
|
|
186
207
|
text: string,
|
|
187
208
|
query: QueryFn,
|
|
188
|
-
{ limit = 32, ...options }: SearchFileReferencesOptions = {},
|
|
209
|
+
{ limit = 32, byFields, ...options }: SearchFileReferencesOptions = {},
|
|
189
210
|
): Promise<ReferenceCandidate[]> {
|
|
190
211
|
const wanted = text.trim()
|
|
191
212
|
if (!wanted) return []
|
|
213
|
+
const fieldKinds = new Set(byFields?.kinds.filter((kind) => typeOf(kind)) ?? [])
|
|
214
|
+
const [byTitle, found] = await Promise.all([
|
|
215
|
+
searchByTitle(wanted, query, limit, fieldKinds, options),
|
|
216
|
+
byFields && fieldKinds.size ? searchByFields(wanted, byFields.query, [...fieldKinds], byFields.limit ?? 20, query, options) : [],
|
|
217
|
+
])
|
|
218
|
+
return [...found, ...byTitle]
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** The files of every kind but `skip` whose current title or ref holds `wanted`. */
|
|
222
|
+
async function searchByTitle(
|
|
223
|
+
wanted: string,
|
|
224
|
+
query: QueryFn,
|
|
225
|
+
limit: number,
|
|
226
|
+
skip: ReadonlySet<number>,
|
|
227
|
+
options: Omit<FileCandidatesOptions, 'at'>,
|
|
228
|
+
): Promise<ReferenceCandidate[]> {
|
|
229
|
+
const kinds = Object.keys(REFERENCE_FILE_TYPES).map(Number).filter((kind) => !skip.has(kind))
|
|
230
|
+
if (!kinds.length) return []
|
|
192
231
|
const asked = { search: wanted, search_mode: 'prefix', limit }
|
|
193
232
|
const hits = await query([
|
|
194
|
-
{ kinds
|
|
233
|
+
{ kinds, ...asked },
|
|
195
234
|
{ kinds: [KIND_CHANGE], ...asked },
|
|
196
235
|
])
|
|
197
236
|
const at = new Map<string, number>()
|
|
@@ -200,7 +239,8 @@ export async function searchFileReferences(
|
|
|
200
239
|
hit.kind === KIND_CHANGE
|
|
201
240
|
? searchedChange(tagOf(hit, 'field'), tagOf(hit, 'a'))
|
|
202
241
|
: typeOf(hit.kind) && `${hit.kind}:${hit.pubkey}:${tagOf(hit, 'd') ?? ''}`
|
|
203
|
-
|
|
242
|
+
const kind = Number(address?.split(':')[0])
|
|
243
|
+
if (!address || !typeOf(kind) || skip.has(kind)) continue
|
|
204
244
|
at.set(address, Math.max(at.get(address) ?? 0, hit.created_at))
|
|
205
245
|
}
|
|
206
246
|
if (at.size === 0) return []
|
|
@@ -208,3 +248,39 @@ export async function searchFileReferences(
|
|
|
208
248
|
const matching = objects.filter((o) => (o.slots.title && referenceMatch(o.slots.title.value, wanted) > 0) || refMatch(refOf(o), wanted) > 0)
|
|
209
249
|
return fileCandidates(matching, FILE_TIER.search, query, { ...options, at })
|
|
210
250
|
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The files of `kinds` whose current title, summary, key or text holds
|
|
254
|
+
* `wanted`, by the relay's list read with `search` (§6.13): each hit is its
|
|
255
|
+
* first record and its fields' current changes, so nothing is folded from its
|
|
256
|
+
* history and nothing older than its current values matches. A hit found only
|
|
257
|
+
* in its text shows the words around the match as its second line.
|
|
258
|
+
*
|
|
259
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/search-finds-a-file-by-the-words-of-its-current-fields.md
|
|
260
|
+
*/
|
|
261
|
+
async function searchByFields(
|
|
262
|
+
wanted: string,
|
|
263
|
+
search: SearchQueryFn,
|
|
264
|
+
kinds: readonly number[],
|
|
265
|
+
limit: number,
|
|
266
|
+
query: QueryFn,
|
|
267
|
+
options: Omit<FileCandidatesOptions, 'at'>,
|
|
268
|
+
): Promise<ReferenceCandidate[]> {
|
|
269
|
+
const { events, matches } = await search([{ kinds, search: wanted, limit, fields: 'newest' }])
|
|
270
|
+
const why = new Map(matches.map((m) => [m.a, m.match]))
|
|
271
|
+
const at = new Map<string, number>()
|
|
272
|
+
const objects = (await projectListedFiles(events, query, options.cache)).filter((o) => o.address && why.has(o.address))
|
|
273
|
+
for (const event of events) {
|
|
274
|
+
const address = event.kind === KIND_CHANGE ? tagOf(event, 'a') : `${event.kind}:${event.pubkey}:${tagOf(event, 'd') ?? ''}`
|
|
275
|
+
if (address && why.has(address)) at.set(address, Math.max(at.get(address) ?? 0, event.created_at))
|
|
276
|
+
}
|
|
277
|
+
const rank = new Map(matches.map((m, i) => [m.a, i]))
|
|
278
|
+
objects.sort((a, b) => rank.get(a.address!)! - rank.get(b.address!)!)
|
|
279
|
+
const rows = await fileCandidates(objects, FILE_TIER.search, query, { ...options, at })
|
|
280
|
+
return rows.map((row) => {
|
|
281
|
+
const match = why.get(row.id)!
|
|
282
|
+
const around = match.fields[0] === 'text' ? match.around?.replace(/\s+/g, ' ').trim() : undefined
|
|
283
|
+
// "…" marks words from inside the text, not the file's own summary; the relay does not say where they start.
|
|
284
|
+
return { ...row, matched: match.fields, ...(around ? { summary: `…${around}` } : {}) }
|
|
285
|
+
})
|
|
286
|
+
}
|