@estiva-app/interop 0.70.1 → 0.71.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.
@@ -0,0 +1,131 @@
1
+ /**
2
+ * A topic's list of files — SPEC §6.14 "A file's list of other files"; record
3
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-topic-keeps-its-own-list-of-files.md
4
+ *
5
+ * A topic lists files from any Folder, one entry per file, by the file's id.
6
+ * An entry is a `kind:1851` change on the topic: `a` and `O` name the topic,
7
+ * `field` is `lists:<d>`, `value` is `true` or `false`, `h` is the topic's
8
+ * Folder, then `ts`, then `["o", <d>]` naming the listed file. The newest
9
+ * entry per topic and file counts (§6.3).
10
+ *
11
+ * `O` is the file the change is about and `o` another file it points at
12
+ * (why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-change-is-about-its-file-as-a-comment-is.md),
13
+ * so `#o` asks which topics list a file and `#O` asks what changed on a topic,
14
+ * and a file's own changes never include a topic's entry about it.
15
+ *
16
+ * Here rather than in each app because Peek, Ship and Leaf all add, remove
17
+ * and read entries, and a reader rule kept in one of them only is a list that
18
+ * reads differently in the next.
19
+ *
20
+ * ## What a listing is not
21
+ *
22
+ * It grants nothing: who reads the listed file is its own Folder's rule. It is
23
+ * not a mention, not a parent and not a Folder's listing, so Mentioned in, the
24
+ * archive chain and a Folder move all ignore it. It carries no `p`, so it adds
25
+ * nobody to the file (§11.8).
26
+ */
27
+ import { type SignedEvent, type UnsignedEvent } from '@estiva-app/protocol';
28
+ import { type QueryFn } from './projection.js';
29
+ /**
30
+ * The file kinds a listed id is looked for under by default: topic, document,
31
+ * project, issue. Never a bare `#d`, since a Folder's `kind:39000` shares its
32
+ * uuid (§11.1). An app that knows more kinds from manifests passes them.
33
+ */
34
+ export declare const LISTED_FILE_KINDS: readonly number[];
35
+ /** The field an entry for `file` sets: `lists:<d>`. */
36
+ export declare function listsField(file: string): string;
37
+ /** The file a list carries entries on, as a write needs it. */
38
+ export interface ListHolder {
39
+ /** Its address, `<kind>:<pubkey>:<d>`. */
40
+ address: string;
41
+ /** Its Folder, read from its root (`folderOf`), never the Folder it was opened from (§6.2). */
42
+ folder: string;
43
+ }
44
+ /**
45
+ * Put a file on a topic's list: `[kind:1851 lists:<d> = true]`, signed by
46
+ * whoever adds it. `file` is the listed file's id (its `d`), from any Folder.
47
+ */
48
+ export declare function planListInTopic(pubkey: string, createdAtMs: number, args: {
49
+ topic: ListHolder;
50
+ file: string;
51
+ note?: string;
52
+ }): UnsignedEvent[];
53
+ /** Take a file off a topic's list: `[kind:1851 lists:<d> = false]`. {@link planListInTopic} in reverse. */
54
+ export declare function planRemoveFromTopic(pubkey: string, createdAtMs: number, args: {
55
+ topic: ListHolder;
56
+ file: string;
57
+ note?: string;
58
+ }): UnsignedEvent[];
59
+ /** Which topics list a file: every entry naming its id in `o`. Fold with {@link listEntries}. */
60
+ export declare function topicsOfFileFilter(file: string): Record<string, unknown>;
61
+ /** A topic's changes, its list entries among them: `#O` on its id. Fold with {@link listEntries}. */
62
+ export declare function topicListFilter(topic: string): Record<string, unknown>;
63
+ /** The newest entry for one list and one file. */
64
+ export interface ListEntry {
65
+ /** The address of the file keeping the list (a topic). */
66
+ list: string;
67
+ /** The listed file's id. */
68
+ file: string;
69
+ /** The entry's Folder: its first `h` with a value. */
70
+ folder: string;
71
+ /** `true` when the newest entry lists the file. */
72
+ listed: boolean;
73
+ event: SignedEvent;
74
+ }
75
+ /**
76
+ * The newest entry per list and file, from any mix of changes: the reader
77
+ * rules of §6.14. A change counts as an entry only when its field is
78
+ * `lists:<d>`, one of its `o` tags is that same `<d>` (an `o` the field does
79
+ * not name is some other relation, a move's new parent for one), its `a`
80
+ * names a file whose `d` is its `O`, `<d>` is not that file itself, and it
81
+ * names a Folder. Anything else is skipped, not folded, so a malformed entry
82
+ * never hides a good one. A `value` other than exactly `true` does not list
83
+ * the file.
84
+ *
85
+ * `folderOfList` is §6.2's Folder check against each list's root, applied
86
+ * before the fold: an entry filed in any other Folder must not become the
87
+ * newest and hide the good one before it. A list it answers no Folder for (an
88
+ * unread root, or one naming none) keeps no entry. Without it the check is the
89
+ * caller's; {@link topicsOfFile} and {@link topicList} pass it.
90
+ */
91
+ export declare function listEntries(events: readonly SignedEvent[], folderOfList?: (list: string) => string | null | undefined): ListEntry[];
92
+ /** A topic that lists a file. */
93
+ export interface FileTopic {
94
+ /** The topic's address. */
95
+ address: string;
96
+ /** The topic's root, as the reader read it. */
97
+ root: SignedEvent;
98
+ entry: ListEntry;
99
+ }
100
+ /**
101
+ * Which topics list a file — `{kinds:[1851], "#o":[<d>]}`, folded per topic.
102
+ *
103
+ * Keeps an entry only when its newest value lists the file, it is on a topic
104
+ * (only topics' lists are read, Miky 2026-10-30), the topic's root is one the
105
+ * reader can read (a deleted or unreadable topic drops out), and the entry is
106
+ * filed in the topic's own Folder (§6.2). Two reads: the entries, then the
107
+ * topics' roots.
108
+ */
109
+ export declare function topicsOfFile(query: QueryFn, file: string): Promise<FileTopic[]>;
110
+ /** A file on a topic's list. */
111
+ export interface ListedFile {
112
+ /** The listed file's id. */
113
+ file: string;
114
+ /** Its address when exactly one file the reader can read holds the id, else `null`: not drawn, not counted. */
115
+ address: string | null;
116
+ entry: ListEntry;
117
+ }
118
+ /**
119
+ * A topic's list, by the topic's address: its entries whose newest value
120
+ * lists the file, filed in the Folder the topic's root names (§6.2; read here,
121
+ * never taken from the caller), in no promised order (sort as the design
122
+ * says; `entry.event` carries the time), each id resolved over `fileKinds` by
123
+ * `#d`. A topic the reader cannot read, or whose root names no Folder, lists
124
+ * nothing. An id held by none the reader can read, or by two, resolves to
125
+ * `null`: a consumer draws and counts only the resolved ones (§3.2, the count
126
+ * is the disclosure).
127
+ */
128
+ export declare function topicList(query: QueryFn, topic: string, options?: {
129
+ fileKinds?: readonly number[];
130
+ }): Promise<ListedFile[]>;
131
+ //# sourceMappingURL=topics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topics.d.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1D,IAAI,EAAE,MAAM,CAAA;IACZ,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAA;IACd,mDAAmD;IACnD,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,WAAW,CAAA;CACnB;AAWD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,GACzD,SAAS,EAAE,CAsBb;AAyBD,iCAAiC;AACjC,MAAM,WAAW,SAAS;IACxB,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,+CAA+C;IAC/C,IAAI,EAAE,WAAW,CAAA;IACjB,KAAK,EAAE,SAAS,CAAA;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAarF;AAED,gCAAgC;AAChC,MAAM,WAAW,UAAU;IACzB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,+GAA+G;IAC/G,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,KAAK,EAAE,SAAS,CAAA;CACjB;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAO,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CA6BvB"}
package/dist/topics.js ADDED
@@ -0,0 +1,241 @@
1
+ /**
2
+ * A topic's list of files — SPEC §6.14 "A file's list of other files"; record
3
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-topic-keeps-its-own-list-of-files.md
4
+ *
5
+ * A topic lists files from any Folder, one entry per file, by the file's id.
6
+ * An entry is a `kind:1851` change on the topic: `a` and `O` name the topic,
7
+ * `field` is `lists:<d>`, `value` is `true` or `false`, `h` is the topic's
8
+ * Folder, then `ts`, then `["o", <d>]` naming the listed file. The newest
9
+ * entry per topic and file counts (§6.3).
10
+ *
11
+ * `O` is the file the change is about and `o` another file it points at
12
+ * (why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-change-is-about-its-file-as-a-comment-is.md),
13
+ * so `#o` asks which topics list a file and `#O` asks what changed on a topic,
14
+ * and a file's own changes never include a topic's entry about it.
15
+ *
16
+ * Here rather than in each app because Peek, Ship and Leaf all add, remove
17
+ * and read entries, and a reader rule kept in one of them only is a list that
18
+ * reads differently in the next.
19
+ *
20
+ * ## What a listing is not
21
+ *
22
+ * It grants nothing: who reads the listed file is its own Folder's rule. It is
23
+ * not a mention, not a parent and not a Folder's listing, so Mentioned in, the
24
+ * archive chain and a Folder move all ignore it. It carries no `p`, so it adds
25
+ * nobody to the file (§11.8).
26
+ */
27
+ import {} from '@estiva-app/protocol';
28
+ import { byOrder } from '@estiva-app/conversation';
29
+ import { folderOf } from './projection.js';
30
+ const KIND_CHANGE = 1851;
31
+ /** The topic (bare file) kind: the only lists this stage reads (Miky, 2026-10-30). */
32
+ const KIND_TOPIC = 30840;
33
+ const KIND_FOLDER = 39000;
34
+ /** Listed ids resolved per request: 2 × this stays under a relay's usual `limit` cap. */
35
+ const RESOLVE_BATCH = 100;
36
+ /**
37
+ * The file kinds a listed id is looked for under by default: topic, document,
38
+ * project, issue. Never a bare `#d`, since a Folder's `kind:39000` shares its
39
+ * uuid (§11.1). An app that knows more kinds from manifests passes them.
40
+ */
41
+ export const LISTED_FILE_KINDS = [30840, 30842, 30850, 30851];
42
+ const ADDRESS = /^(\d+):([0-9a-f]{64}):(.+)$/;
43
+ const FIELD_PREFIX = 'lists:';
44
+ /** The field an entry for `file` sets: `lists:<d>`. */
45
+ export function listsField(file) {
46
+ return `${FIELD_PREFIX}${file}`;
47
+ }
48
+ function entry(pubkey, createdAtMs, args) {
49
+ const holder = ADDRESS.exec(args.list.address);
50
+ if (!holder)
51
+ throw new Error(`not a file address: ${JSON.stringify(args.list.address)}`);
52
+ if (!args.list.folder)
53
+ throw new Error('a list entry names the Folder of the file that keeps the list');
54
+ if (!args.file || /\s/.test(args.file))
55
+ throw new Error(`not a file id: ${JSON.stringify(args.file)}`);
56
+ // A reader ignores a file on its own list (§6.14): refuse it here rather than publish an entry that shows nothing.
57
+ if (args.file === holder[3])
58
+ throw new Error('a file is not on its own list');
59
+ if (!Number.isSafeInteger(createdAtMs) || createdAtMs < 0)
60
+ throw new Error(`not epoch milliseconds: ${createdAtMs}`);
61
+ return {
62
+ pubkey,
63
+ created_at: Math.floor(createdAtMs / 1000),
64
+ kind: KIND_CHANGE,
65
+ tags: [
66
+ ['a', args.list.address],
67
+ ['O', holder[3]],
68
+ ['field', listsField(args.file)],
69
+ ['value', args.listed ? 'true' : 'false'],
70
+ ['h', args.list.folder],
71
+ ['ts', String(createdAtMs)],
72
+ ['o', args.file],
73
+ ],
74
+ // Empty unless the person wrote a note: each app says "added" and "removed" in its own words (§6.14).
75
+ content: args.note ?? '',
76
+ };
77
+ }
78
+ /**
79
+ * Put a file on a topic's list: `[kind:1851 lists:<d> = true]`, signed by
80
+ * whoever adds it. `file` is the listed file's id (its `d`), from any Folder.
81
+ */
82
+ export function planListInTopic(pubkey, createdAtMs, args) {
83
+ return [entry(pubkey, createdAtMs, { list: args.topic, file: args.file, listed: true, note: args.note })];
84
+ }
85
+ /** Take a file off a topic's list: `[kind:1851 lists:<d> = false]`. {@link planListInTopic} in reverse. */
86
+ export function planRemoveFromTopic(pubkey, createdAtMs, args) {
87
+ return [entry(pubkey, createdAtMs, { list: args.topic, file: args.file, listed: false, note: args.note })];
88
+ }
89
+ /** Which topics list a file: every entry naming its id in `o`. Fold with {@link listEntries}. */
90
+ export function topicsOfFileFilter(file) {
91
+ return { kinds: [KIND_CHANGE], '#o': [file] };
92
+ }
93
+ /** A topic's changes, its list entries among them: `#O` on its id. Fold with {@link listEntries}. */
94
+ export function topicListFilter(topic) {
95
+ const holder = ADDRESS.exec(topic);
96
+ return { kinds: [KIND_CHANGE], '#O': [holder ? holder[3] : topic] };
97
+ }
98
+ const tagOf = (event, name) => event.tags.find((t) => t[0] === name && t[1])?.[1];
99
+ /** The file an entry lists: the `<d>` of its `lists:<d>` field, or `null` for any other change. */
100
+ const listedIn = (event) => {
101
+ const field = tagOf(event, 'field');
102
+ return field?.startsWith(FIELD_PREFIX) ? field.slice(FIELD_PREFIX.length) || null : null;
103
+ };
104
+ /**
105
+ * The newest entry per list and file, from any mix of changes: the reader
106
+ * rules of §6.14. A change counts as an entry only when its field is
107
+ * `lists:<d>`, one of its `o` tags is that same `<d>` (an `o` the field does
108
+ * not name is some other relation, a move's new parent for one), its `a`
109
+ * names a file whose `d` is its `O`, `<d>` is not that file itself, and it
110
+ * names a Folder. Anything else is skipped, not folded, so a malformed entry
111
+ * never hides a good one. A `value` other than exactly `true` does not list
112
+ * the file.
113
+ *
114
+ * `folderOfList` is §6.2's Folder check against each list's root, applied
115
+ * before the fold: an entry filed in any other Folder must not become the
116
+ * newest and hide the good one before it. A list it answers no Folder for (an
117
+ * unread root, or one naming none) keeps no entry. Without it the check is the
118
+ * caller's; {@link topicsOfFile} and {@link topicList} pass it.
119
+ */
120
+ export function listEntries(events, folderOfList) {
121
+ const newest = new Map();
122
+ for (const event of events) {
123
+ if (event.kind !== KIND_CHANGE)
124
+ continue;
125
+ const file = listedIn(event);
126
+ if (!file || !event.tags.some((t) => t[0] === 'o' && t[1] === file))
127
+ continue;
128
+ const list = tagOf(event, 'a');
129
+ const holder = list ? ADDRESS.exec(list) : null;
130
+ const folder = tagOf(event, 'h');
131
+ if (!holder || tagOf(event, 'O') !== holder[3] || file === holder[3] || !folder)
132
+ continue;
133
+ if (folderOfList && folderOfList(list) !== folder)
134
+ continue;
135
+ const key = `${list}\n${file}`;
136
+ const seen = newest.get(key);
137
+ if (!seen || byOrder(seen.event, event) < 0)
138
+ newest.set(key, { event, file });
139
+ }
140
+ return [...newest.values()].map(({ event, file }) => ({
141
+ list: tagOf(event, 'a'),
142
+ file,
143
+ folder: tagOf(event, 'h'),
144
+ listed: event.tags.find((t) => t[0] === 'value')?.[1] === 'true',
145
+ event,
146
+ }));
147
+ }
148
+ /** The roots of the given list addresses that the reader can read, by address. */
149
+ async function rootsOf(query, addresses) {
150
+ const byKindAuthor = new Map();
151
+ for (const address of addresses) {
152
+ const [, kind, pubkey, d] = ADDRESS.exec(address) ?? [];
153
+ if (!d)
154
+ continue;
155
+ const key = `${kind}:${pubkey}`;
156
+ const group = byKindAuthor.get(key) ?? { kind: Number(kind), pubkey, ds: [] };
157
+ group.ds.push(d);
158
+ byKindAuthor.set(key, group);
159
+ }
160
+ if (byKindAuthor.size === 0)
161
+ return new Map();
162
+ const filters = [...byKindAuthor.values()].map(({ kind, pubkey, ds }) => ({ kinds: [kind], authors: [pubkey], '#d': ds, limit: ds.length }));
163
+ const roots = new Map();
164
+ for (const root of await query(filters)) {
165
+ const address = `${root.kind}:${root.pubkey}:${tagOf(root, 'd') ?? ''}`;
166
+ const held = roots.get(address);
167
+ // Two versions of one record: NIP-01's later created_at, then the lower id (§6.3).
168
+ if (!held || root.created_at > held.created_at || (root.created_at === held.created_at && root.id < held.id))
169
+ roots.set(address, root);
170
+ }
171
+ return roots;
172
+ }
173
+ /**
174
+ * Which topics list a file — `{kinds:[1851], "#o":[<d>]}`, folded per topic.
175
+ *
176
+ * Keeps an entry only when its newest value lists the file, it is on a topic
177
+ * (only topics' lists are read, Miky 2026-10-30), the topic's root is one the
178
+ * reader can read (a deleted or unreadable topic drops out), and the entry is
179
+ * filed in the topic's own Folder (§6.2). Two reads: the entries, then the
180
+ * topics' roots.
181
+ */
182
+ export async function topicsOfFile(query, file) {
183
+ const isTopic = (entry) => entry.file === file && entry.list.startsWith(`${KIND_TOPIC}:`);
184
+ const events = await query([topicsOfFileFilter(file)]);
185
+ const lists = [...new Set(listEntries(events).filter(isTopic).map((entry) => entry.list))];
186
+ if (lists.length === 0)
187
+ return [];
188
+ const roots = await rootsOf(query, lists);
189
+ const folderOfList = (list) => {
190
+ const root = roots.get(list);
191
+ return root ? folderOf(root) : null;
192
+ };
193
+ return listEntries(events, folderOfList)
194
+ .filter((entry) => entry.listed && isTopic(entry))
195
+ .map((entry) => ({ address: entry.list, root: roots.get(entry.list), entry }));
196
+ }
197
+ /**
198
+ * A topic's list, by the topic's address: its entries whose newest value
199
+ * lists the file, filed in the Folder the topic's root names (§6.2; read here,
200
+ * never taken from the caller), in no promised order (sort as the design
201
+ * says; `entry.event` carries the time), each id resolved over `fileKinds` by
202
+ * `#d`. A topic the reader cannot read, or whose root names no Folder, lists
203
+ * nothing. An id held by none the reader can read, or by two, resolves to
204
+ * `null`: a consumer draws and counts only the resolved ones (§3.2, the count
205
+ * is the disclosure).
206
+ */
207
+ export async function topicList(query, topic, options = {}) {
208
+ const [roots, events] = await Promise.all([rootsOf(query, [topic]), query([topicListFilter(topic)])]);
209
+ const root = roots.get(topic);
210
+ const folder = root ? folderOf(root) : null;
211
+ if (!folder)
212
+ return [];
213
+ const entries = listEntries(events, (list) => (list === topic ? folder : null))
214
+ .filter((entry) => entry.listed)
215
+ .sort((a, b) => byOrder(a.event, b.event));
216
+ if (entries.length === 0)
217
+ return [];
218
+ const ids = [...new Set(entries.map((entry) => entry.file))];
219
+ // Never a Folder's `39000`, which shares its uuid (§11.1): an id only a Folder holds resolves to nothing.
220
+ const kinds = (options.fileKinds ?? LISTED_FILE_KINDS).filter((kind) => kind !== KIND_FOLDER);
221
+ // Room for a second holder of every id, so two holders are seen as two; in
222
+ // batches, so a relay's cap on `limit` cannot cut a long list short.
223
+ const batches = [];
224
+ for (let i = 0; i < ids.length; i += RESOLVE_BATCH)
225
+ batches.push(ids.slice(i, i + RESOLVE_BATCH));
226
+ const found = (await Promise.all(batches.map((batch) => query([{ kinds, '#d': batch, limit: batch.length * 2 }])))).flat();
227
+ const holders = new Map();
228
+ for (const event of found) {
229
+ const d = tagOf(event, 'd');
230
+ if (!d || !kinds.includes(event.kind))
231
+ continue;
232
+ const set = holders.get(d) ?? new Set();
233
+ set.add(`${event.kind}:${event.pubkey}`);
234
+ holders.set(d, set);
235
+ }
236
+ return entries.map((entry) => {
237
+ const set = holders.get(entry.file);
238
+ return { file: entry.file, address: set?.size === 1 ? `${[...set][0]}:${entry.file}` : null, entry };
239
+ });
240
+ }
241
+ //# sourceMappingURL=topics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topics.js","sourceRoot":"","sources":["../src/topics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAwC,MAAM,sBAAsB,CAAA;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAgB,MAAM,iBAAiB,CAAA;AAExD,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,sFAAsF;AACtF,MAAM,UAAU,GAAG,KAAK,CAAA;AACxB,MAAM,WAAW,GAAG,KAAK,CAAA;AACzB,yFAAyF;AACzF,MAAM,aAAa,GAAG,GAAG,CAAA;AACzB;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;AAEhF,MAAM,OAAO,GAAG,6BAA6B,CAAA;AAC7C,MAAM,YAAY,GAAG,QAAQ,CAAA;AAE7B,uDAAuD;AACvD,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,GAAG,YAAY,GAAG,IAAI,EAAE,CAAA;AACjC,CAAC;AAUD,SAAS,KAAK,CACZ,MAAc,EACd,WAAmB,EACnB,IAAwE;IAExE,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC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AC/C,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;QACxC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACrB,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACnC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAA;IACtG,CAAC,CAAC,CAAA;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/interop",
3
- "version": "0.70.1",
3
+ "version": "0.71.0",
4
4
  "description": "Render and act on another app's objects from its published NIP-89 manifest. The owner defines the projection; the consumer decides how it looks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -147,6 +147,27 @@ export {
147
147
  type MoveRefusal,
148
148
  } from './folders.js'
149
149
 
150
+ /**
151
+ * SPEC §6.14: a topic's list of files from any Folder, one `kind:1851` entry
152
+ * per file by its id. Plan an entry, read a topic's list, and ask which topics
153
+ * list a file (`#o`); a file's own changes (`#O`) never hold an entry.
154
+ */
155
+ export {
156
+ planListInTopic,
157
+ planRemoveFromTopic,
158
+ topicsOfFile,
159
+ topicList,
160
+ topicsOfFileFilter,
161
+ topicListFilter,
162
+ listEntries,
163
+ listsField,
164
+ LISTED_FILE_KINDS,
165
+ type ListHolder,
166
+ type ListEntry,
167
+ type FileTopic,
168
+ type ListedFile,
169
+ } from './topics.js'
170
+
150
171
  /**
151
172
  * What an app link names, and where a file is mentioned — once for every app
152
173
  * (SPEC §7.7, §13.1, §6.8; PEEKM-7). Each app passes its relay read; none
package/src/projection.ts CHANGED
@@ -3538,7 +3538,7 @@ export async function resolveForeignObject(
3538
3538
  const followUp = childChangeFilters(plan, answered)
3539
3539
  const childChanges = followUp.length ? await queryChunked(followUp, query) : []
3540
3540
  const childOwners = await childOwnersOf(plan, answered, childChanges, query, cache)
3541
- const assembled = assembleObject(plan, answered, childChanges, childOwners)
3541
+ const assembled = assembleObject(plan, answered, childChanges, childOwners, options.archivedChildren)
3542
3542
  if (assembled.object.unreachable) return assembled.object
3543
3543
  if (options.archivedWith) await markArchivedParents([{ object: assembled.object, manifest: resolved.manifest }], query, cache)
3544
3544
  return withFiles(
@@ -3679,7 +3679,7 @@ export async function resolveForeignObjects(
3679
3679
  const assembled = plans.map(({ reference, plan }, i) => ({
3680
3680
  reference,
3681
3681
  plan,
3682
- built: assembleObject(plan, events, childChanges, ownerLists[i]),
3682
+ built: assembleObject(plan, events, childChanges, ownerLists[i], options.archivedChildren),
3683
3683
  }))
3684
3684
  if (options.archivedWith) {
3685
3685
  await markArchivedParents(assembled.map(({ plan, built }) => ({ object: built.object, manifest: plan.resolved.manifest })), query, cache)
@@ -3990,6 +3990,15 @@ export interface ArchiveReadOptions {
3990
3990
  * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/folders-belong-to-the-protocol.md
3991
3991
  */
3992
3992
  folderFiles?: boolean
3993
+ /**
3994
+ * Keep the children archived themselves, each with its own `archived`, where
3995
+ * every other read leaves them out (FOL-46): what {@link resolveFolderContents}'s
3996
+ * `includeArchived` is for a Folder, for a file's `list`. For an archive view,
3997
+ * which draws an archived issue of a live project — a file no Folder lists,
3998
+ * so no Folder read can find it (PEE-58). Costs nothing more: the children's
3999
+ * changes are read either way.
4000
+ */
4001
+ archivedChildren?: boolean
3993
4002
  }
3994
4003
 
3995
4004
  /**
@@ -4330,6 +4339,8 @@ function assembleObject(
4330
4339
  answered: SignedEvent[],
4331
4340
  childChanges: SignedEvent[] = [],
4332
4341
  childOwners: Set<string> = new Set(),
4342
+ /** {@link ArchiveReadOptions}' `archivedChildren`. */
4343
+ archivedChildren = false,
4333
4344
  ): AssembledObject {
4334
4345
  const { naddr, pointer, address, resolved, projection, commentKinds, childFilter, openUrl } = plan
4335
4346
  const { manifest, viaRecommendation } = resolved
@@ -4423,6 +4434,7 @@ function assembleObject(
4423
4434
  viaRecommendation,
4424
4435
  childChanges,
4425
4436
  childOwners,
4437
+ archivedChildren,
4426
4438
  })
4427
4439
 
4428
4440
  return { object, ...(children ? { children } : {}) }
@@ -4689,8 +4701,19 @@ function childrenFrom(args: {
4689
4701
  childChanges?: SignedEvent[]
4690
4702
  /** What {@link childOwnersOf} answered: the authors whose children carry actions. */
4691
4703
  childOwners?: Set<string>
4704
+ /** Keep a child archived itself, marked, rather than drop it — {@link ArchiveReadOptions}' `archivedChildren`. */
4705
+ archivedChildren?: boolean
4692
4706
  }): ForeignObject[] | undefined {
4693
- const { events, childFilter, manifest, webTemplate, viaRecommendation, childChanges = [], childOwners = new Set() } = args
4707
+ const {
4708
+ events,
4709
+ childFilter,
4710
+ manifest,
4711
+ webTemplate,
4712
+ viaRecommendation,
4713
+ childChanges = [],
4714
+ childOwners = new Set(),
4715
+ archivedChildren = false,
4716
+ } = args
4694
4717
  if (childFilter === undefined) return undefined
4695
4718
  if (childFilter === null) return []
4696
4719
 
@@ -4727,7 +4750,8 @@ function childrenFrom(args: {
4727
4750
  that names no parent at all, is not this parent either. Only a folded
4728
4751
  value counts: without one the `via` tag is the parent, and that is what
4729
4752
  found the child.
4730
- - **hidden** by the app's own `hiddenWhen`, or **archived** (FOL-46).
4753
+ - **hidden** by the app's own `hiddenWhen`, or **archived** (FOL-46) —
4754
+ unless `archivedChildren` asks for those too, marked.
4731
4755
 
4732
4756
  - **moved in** and since moved on, or never really here — FOL-45. A
4733
4757
  child found by its move's `MOVED_TO_TAG` has no `via` naming this
@@ -4737,8 +4761,12 @@ function childrenFrom(args: {
4737
4761
  const folded = address ? foldOf(childChanges, address, manifest, event) : {}
4738
4762
  if (movedBy && folded[movedBy] && folded[movedBy].value !== childFilter.parent) return []
4739
4763
  if (address && movedIn.has(address) && folded[movedBy!]?.value !== childFilter.parent) return []
4740
- if (records.hiddenWhen && folded[records.hiddenWhen.field]?.value === records.hiddenWhen.equals) return []
4741
- if (address && manifest.records && archiveOf(childChanges, address, records, event)) return []
4764
+ // Hidden for a reason of the app's own is gone either way; hidden because archived, as Ship's issues
4765
+ // are, is an archive, kept on request — the rule the Folder listing reads `hiddenWhen` by.
4766
+ const archived = address && manifest.records ? archiveOf(childChanges, address, records, event) : undefined
4767
+ const hidden = !!records.hiddenWhen && folded[records.hiddenWhen.field]?.value === records.hiddenWhen.equals
4768
+ if (hidden && !archived) return []
4769
+ if (archived && !archivedChildren) return []
4742
4770
  return [
4743
4771
  buildChildObject({
4744
4772
  root: event,
@@ -4749,6 +4777,7 @@ function childrenFrom(args: {
4749
4777
  viaRecommendation,
4750
4778
  folded,
4751
4779
  ownsKind: childOwners.has(event.pubkey),
4780
+ archived,
4752
4781
  }),
4753
4782
  ]
4754
4783
  })
@@ -4909,8 +4938,10 @@ function buildChildObject(args: {
4909
4938
  * as {@link childOwnersOf} found. Its actions are offered only then.
4910
4939
  */
4911
4940
  ownsKind?: boolean
4941
+ /** The child's own archive, for a child kept archived (`archivedChildren`). */
4942
+ archived?: Archive
4912
4943
  }): ForeignObject {
4913
- const { root, manifest, projection, webTemplate, viaRecommendation, nevent, folded = {}, ownsKind = false } = args
4944
+ const { root, manifest, projection, webTemplate, viaRecommendation, nevent, folded = {}, ownsKind = false, archived } = args
4914
4945
  const identifier = tagValue(root, 'd')
4915
4946
  const addressable = identifier !== undefined
4916
4947
  const pointer: AddressPointer = {
@@ -4962,6 +4993,7 @@ function buildChildObject(args: {
4962
4993
  actions: addressable && !nevent && ownsKind ? actionsOfFile(manifest, projection, root, folded) : [],
4963
4994
  viaRecommendation,
4964
4995
  changedAt: changedAtOf(root, folded),
4996
+ ...(archived ? { archived } : {}),
4965
4997
  }
4966
4998
  }
4967
4999