@estiva-app/interop 0.81.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/src/projection.ts CHANGED
@@ -1524,7 +1524,7 @@ const BARE_FILE_MANIFEST: Manifest = {
1524
1524
  id: 'comment',
1525
1525
  label: 'Comment',
1526
1526
  description:
1527
- 'Say something about this file. The comment lands in the Folder the file lives in, ' +
1527
+ 'Say something about this file. The comment lands in the team the file lives in, ' +
1528
1528
  'and is what every reader of the file sees under it.',
1529
1529
  effect: 'writes',
1530
1530
  appliesTo: [String(KIND_BARE_FILE)],
@@ -1535,7 +1535,7 @@ const BARE_FILE_MANIFEST: Manifest = {
1535
1535
  id: 'rename',
1536
1536
  label: 'Rename',
1537
1537
  description:
1538
- 'Give this file a new title. A change event, so anyone in the Folder may, and every app ' +
1538
+ 'Give this file a new title. A change event, so anyone in the team may, and every app ' +
1539
1539
  'reading the file folds it into the title.',
1540
1540
  effect: 'writes',
1541
1541
  appliesTo: [String(KIND_BARE_FILE)],
@@ -1553,7 +1553,7 @@ const BARE_FILE_MANIFEST: Manifest = {
1553
1553
  label: 'Summary',
1554
1554
  description:
1555
1555
  "Set this file's summary: one or two sentences of plain text, about 240 characters, shown under its " +
1556
- 'title wherever it is met in one line. A change event, so anyone in the Folder may; an empty value clears it.',
1556
+ 'title wherever it is met in one line. A change event, so anyone in the team may; an empty value clears it.',
1557
1557
  effect: 'writes',
1558
1558
  appliesTo: [String(KIND_BARE_FILE)],
1559
1559
  emits: { kind: 1851, field: SUMMARY_FIELD },
@@ -1570,8 +1570,8 @@ const BARE_FILE_MANIFEST: Manifest = {
1570
1570
  id: 'move',
1571
1571
  label: 'Move',
1572
1572
  description:
1573
- "Put this file under another file in the same Folder, or back at the top. A change event, so anyone in " +
1574
- 'the Folder may; who can read the file does not change.',
1573
+ "Put this file under another file in the same team, or back at the top. A change event, so anyone in " +
1574
+ 'the team may; who can read the file does not change.',
1575
1575
  effect: 'writes',
1576
1576
  appliesTo: [String(KIND_BARE_FILE)],
1577
1577
  emits: { kind: 1851, field: 'parent' },
@@ -1660,8 +1660,8 @@ export const FOLDER_ACTIONS_ADDRESS = 'spec:3.2'
1660
1660
  */
1661
1661
  const FOLDER_CREATOR: ResolvedManifest = {
1662
1662
  manifest: {
1663
- name: 'Folder',
1664
- about: 'What every app may do in a Folder, whichever app made it.',
1663
+ name: 'Team',
1664
+ about: 'What every app may do in a team, whichever app made it.',
1665
1665
  projections: {
1666
1666
  [String(KIND_BARE_FILE)]: BARE_FILE_MANIFEST.projections![String(KIND_BARE_FILE)],
1667
1667
  [String(KIND_MESSAGE)]: BARE_FILE_MANIFEST.projections![String(KIND_MESSAGE)],
@@ -1671,8 +1671,8 @@ const FOLDER_CREATOR: ResolvedManifest = {
1671
1671
  id: 'create-file',
1672
1672
  label: 'New file',
1673
1673
  description:
1674
- 'Put a new file in this Folder: a title and, if you have one, a short summary. Everyone who can read the Folder can read ' +
1675
- 'it, and the Folder lists it straight away. The app opening files calls it by its own word — Peek says topic.',
1674
+ 'Put a new file in this team: a title and, if you have one, a short summary. Everyone who can read the team can read ' +
1675
+ 'it, and the team lists it straight away. The app opening files calls it by its own word — Peek says topic.',
1676
1676
  effect: 'writes',
1677
1677
  appliesTo: String(KIND_CHANNEL_METADATA),
1678
1678
  emits: { kind: KIND_BARE_FILE, listed: true },
@@ -1694,9 +1694,9 @@ const FOLDER_CREATOR: ResolvedManifest = {
1694
1694
  id: 'start-a-conversation',
1695
1695
  label: 'Start a conversation',
1696
1696
  description:
1697
- 'Start a new conversation in this Folder, as a root message that people can then reply to. ' +
1697
+ 'Start a new conversation in this team, as a root message that people can then reply to. ' +
1698
1698
  'Use when something is worth its own thread rather than an answer inside an existing one — ' +
1699
- 'this cannot reply to a message. Everyone who can read the Folder reads it.',
1699
+ 'this cannot reply to a message. Everyone who can read the team reads it.',
1700
1700
  effect: 'writes',
1701
1701
  appliesTo: String(KIND_CHANNEL_METADATA),
1702
1702
  emits: { kind: KIND_MESSAGE, toAddressOf: 'self' },
@@ -1719,7 +1719,8 @@ const FOLDER_CREATOR: ResolvedManifest = {
1719
1719
  * No app owns a Folder, so no `kind:31990` may claim `39000`; until this
1720
1720
  * release Peek's did, and every app learned a Folder's name from it. The title
1721
1721
  * is the channel record's `name`, the subtitle its `about` (the built-in
1722
- * subtitle, {@link defaultSubtitle}), and the noun "folder".
1722
+ * subtitle, {@link defaultSubtitle}), and the noun "team" (SPEC §3.2; it was
1723
+ * "folder" until every app renamed on the same day, TEA-8).
1723
1724
  *
1724
1725
  * **No `list` slot.** What a Folder holds is what its relay-signed `30890`
1725
1726
  * names, which no `children` declaration can say, and it is read by
@@ -1737,12 +1738,12 @@ const FOLDER_CREATOR: ResolvedManifest = {
1737
1738
  * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/folders-belong-to-the-protocol.md
1738
1739
  */
1739
1740
  const FOLDER_MANIFEST: Manifest = {
1740
- name: 'Folder',
1741
- about: 'A Folder no app owns: its name, its one-liner, and the files its state lists.',
1741
+ name: 'Team',
1742
+ about: 'A team no app owns: its name, its one-liner, and the files its state lists.',
1742
1743
  projections: {
1743
1744
  [String(KIND_CHANNEL_METADATA)]: {
1744
1745
  widget: 'card',
1745
- noun: 'folder',
1746
+ noun: 'team',
1746
1747
  // The cut Peek's claim made, so no card grows when the claim goes.
1747
1748
  slots: { title: { tag: 'name' }, subtitle: { tag: 'about', truncate: 120 } },
1748
1749
  },
@@ -2774,14 +2775,14 @@ export function actionProblems(declared: unknown): string[] {
2774
2775
  if (emits?.placement !== undefined && !(creates && PLACEMENTS.includes(emits.placement as string))) {
2775
2776
  problems.push(
2776
2777
  creates
2777
- ? `${name} places its object with ${JSON.stringify(emits.placement)}, and a Folder is named by ${PLACEMENTS.join(' or ')} — a consumer refuses the action.`
2778
- : `${name} declares a placement and creates nothing; only a new root names its Folder, so it is ignored.`,
2778
+ ? `${name} places its object with ${JSON.stringify(emits.placement)}, and a team is named by ${PLACEMENTS.join(' or ')} — a consumer refuses the action.`
2779
+ : `${name} declares a placement and creates nothing; only a new root names its team, so it is ignored.`,
2779
2780
  )
2780
2781
  }
2781
2782
  if (emits?.listed !== undefined && emits.listed !== true) {
2782
2783
  problems.push(`${name} declares listed ${JSON.stringify(emits.listed)}; the only value is true.`)
2783
2784
  } else if (emits?.listed === true && !creates && emits.kind !== KIND_DELETION) {
2784
- problems.push(`${name} declares listed on an action that neither creates nor deletes, so no Folder command follows it.`)
2785
+ problems.push(`${name} declares listed on an action that neither creates nor deletes, so no team command follows it.`)
2785
2786
  }
2786
2787
  const formats: [string, unknown, boolean][] = [
2787
2788
  // A scalar format means something on a change only: a comment's body is
@@ -3853,8 +3854,13 @@ export async function resolveForeignRoots(
3853
3854
  references: readonly string[],
3854
3855
  query: QueryFn,
3855
3856
  cache?: ProjectionCache,
3856
- /** `archivedWith` marks a file archived with an archived parent, as {@link resolveForeignObject}'s does (SHIPS-2). */
3857
- options: Pick<ArchiveReadOptions, 'archivedWith'> = {},
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 } = {},
3858
3864
  ): Promise<ForeignObject[]> {
3859
3865
  const pointers = new Map<string, AddressPointer>()
3860
3866
  for (const reference of references) {
@@ -3862,32 +3868,38 @@ export async function resolveForeignRoots(
3862
3868
  if (pointer) pointers.set(`${pointer.kind}:${pointer.pubkey}:${pointer.identifier}`, pointer)
3863
3869
  }
3864
3870
  if (pointers.size === 0) return []
3865
-
3866
- const manifests = new Map<string, ResolvedManifest>()
3867
- const byApp = new Map<string, AddressPointer>()
3868
- for (const pointer of pointers.values()) byApp.set(manifestKeyOf(pointer), pointer)
3869
- await Promise.all(
3870
- [...byApp].map(async ([key, pointer]) => {
3871
- const resolved = await resolveManifest(pointer, query, cache)
3872
- if (resolved) manifests.set(key, resolved)
3873
- }),
3874
- )
3871
+ const manifests = await manifestsOf(pointers.values(), query, cache)
3875
3872
 
3876
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[] }>()
3877
3876
  for (const [address, pointer] of pointers) {
3878
3877
  const resolved = manifests.get(manifestKeyOf(pointer))
3879
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 }
3880
3887
  // A manifest without `records` folds by a placeholder kind 0, never sent.
3881
3888
  const changeKinds = new Set(
3882
3889
  [foldRuleOf(resolved.manifest).changeKind, archiveRuleOf(resolved.manifest).changeKind].filter((k) => k !== 0),
3883
3890
  )
3884
- filters.push(
3885
- { kinds: [pointer.kind], authors: [pointer.pubkey], '#d': [pointer.identifier], limit: 1 },
3886
- { kinds: [...changeKinds], '#a': [address], limit: 500 },
3887
- )
3891
+ filters.push(root, { kinds: [...changeKinds], '#a': [address], limit: 500 })
3888
3892
  }
3889
- if (filters.length === 0) return []
3890
- const events = await queryChunked(filters, query)
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()
3891
3903
  const objects = projectEvents(events, (pointer) => manifests.get(manifestKeyOf(pointer)))
3892
3904
  if (options.archivedWith) {
3893
3905
  const manifestOf = (object: ForeignObject) => {
@@ -3899,6 +3911,37 @@ export async function resolveForeignRoots(
3899
3911
  return objects
3900
3912
  }
3901
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
+
3902
3945
  /**
3903
3946
  * The parent each file sits under, and nothing else — FOL-50.
3904
3947
  *
@@ -5799,7 +5842,7 @@ function buildCreationEvent(args: {
5799
5842
 
5800
5843
  const placement = declared.emits.placement ?? 'h'
5801
5844
  if (!PLACEMENTS.includes(placement)) {
5802
- return `"${declared.label}" places its object with "${placement}", and a Folder is named by ${PLACEMENTS.join(' or ')}.`
5845
+ return `"${declared.label}" places its object with "${placement}", and a team is named by ${PLACEMENTS.join(' or ')}.`
5803
5846
  }
5804
5847
 
5805
5848
  // Only the content field can be prose, so only its value is ever tagged.
@@ -5954,7 +5997,7 @@ export interface ActionEventArgs {
5954
5997
  export function buildActionEvent(args: ActionEventArgs): UnsignedActionEvent | string {
5955
5998
  const declared = args.manifest.actions?.find((a) => a.id === args.actionId)
5956
5999
  if (declared?.emits.listed === true && (declared.emits.kind === KIND_DELETION || isCreationAction(declared))) {
5957
- return `"${declared.label}" is followed by a Folder command, so it is built with buildActionEvents.`
6000
+ return `"${declared.label}" is followed by a team command, so it is built with buildActionEvents.`
5958
6001
  }
5959
6002
  return buildOneActionEvent(args)
5960
6003
  }
@@ -5994,7 +6037,7 @@ export function buildActionEvents(
5994
6037
  if (declared.emits.listed !== true) return [first]
5995
6038
 
5996
6039
  if (declared.emits.kind === KIND_DELETION) {
5997
- if (!args.listedIn) return `"${declared.label}" unlists what it deletes, and needs the Folders that list it.`
6040
+ if (!args.listedIn) return `"${declared.label}" unlists what it deletes, and needs the teams that list it.`
5998
6041
  // One remove per Folder, however many reads it came back from.
5999
6042
  const folders = [...new Map(args.listedIn.map((listing) => [listing.id, listing])).values()]
6000
6043
  return [
@@ -6006,7 +6049,7 @@ export function buildActionEvents(
6006
6049
  }
6007
6050
  if (isCreationAction(declared)) {
6008
6051
  if (args.folderHasState === undefined) {
6009
- return `"${declared.label}" lists what it creates, and needs to know whether the Folder has state.`
6052
+ return `"${declared.label}" lists what it creates, and needs to know whether the team has state.`
6010
6053
  }
6011
6054
  // A listing names addresses, and an object with no `d` has none.
6012
6055
  const identifier = first.tags.find((t) => t[0] === 'd')?.[1]
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: Object.keys(REFERENCE_FILE_TYPES).map(Number), ...asked },
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
- if (!address || !typeOf(Number(address.split(':')[0]))) continue
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
+ }
package/src/topics.ts CHANGED
@@ -88,7 +88,7 @@ function entry(
88
88
  ): UnsignedEvent {
89
89
  const holder = ADDRESS.exec(args.list.address)
90
90
  if (!holder) throw new Error(`not a file address: ${JSON.stringify(args.list.address)}`)
91
- if (!args.list.folder) throw new Error('a list entry names the Folder of the file that keeps the list')
91
+ if (!args.list.folder) throw new Error('a list entry names the team of the file that keeps the list')
92
92
  if (!args.file || /\s/.test(args.file)) throw new Error(`not a file id: ${JSON.stringify(args.file)}`)
93
93
  // A reader ignores a file on its own list (§6.14): refuse it here rather than publish an entry that shows nothing.
94
94
  if (args.file === holder[3]) throw new Error('a file is not on its own list')