@estiva-app/interop 0.93.0 → 0.95.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 +44 -0
- package/dist/folders.d.ts +22 -6
- package/dist/folders.d.ts.map +1 -1
- package/dist/folders.js +39 -12
- package/dist/folders.js.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/topicArrangement.d.ts +164 -0
- package/dist/topicArrangement.d.ts.map +1 -0
- package/dist/topicArrangement.js +314 -0
- package/dist/topicArrangement.js.map +1 -0
- package/dist/topics.d.ts +21 -12
- package/dist/topics.d.ts.map +1 -1
- package/dist/topics.js +67 -7
- package/dist/topics.js.map +1 -1
- package/package.json +1 -1
- package/src/folders.ts +46 -13
- package/src/index.ts +26 -0
- package/src/topicArrangement.ts +396 -0
- package/src/topics.ts +85 -13
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { byOrder } from '@estiva-app/conversation';
|
|
2
|
+
import { changedAt, combineChanges, conflictOf, fieldsSetBy } from './fields.js';
|
|
3
|
+
const KIND_CHANGE = 1851;
|
|
4
|
+
const ADDRESS = /^(\d+):([0-9a-f]{64}):(.+)$/;
|
|
5
|
+
const ORDER = 'order:';
|
|
6
|
+
const LOOK = 'look:';
|
|
7
|
+
/** The field a file's place on a topic is kept in: `order:<d>`. */
|
|
8
|
+
export const orderField = (file) => `${ORDER}${file}`;
|
|
9
|
+
/** The field a file's look on a topic is kept in: `look:<d>`. */
|
|
10
|
+
export const lookField = (file) => `${LOOK}${file}`;
|
|
11
|
+
/** Digits in byte order: `0`–`9`, `A`–`Z`, `a`–`z`. */
|
|
12
|
+
const DIGITS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
13
|
+
const KEY = /^[0-9A-Za-z]*[1-9A-Za-z]$/;
|
|
14
|
+
/** The longest key a reader takes (§6.14); a planner whose key would pass it places every file afresh. */
|
|
15
|
+
export const MAX_PLACE_KEY = 64;
|
|
16
|
+
/** A place §6.14 reads: 1 to 64 of `0-9A-Za-z`, not ending in `0`. Anything else is no place. */
|
|
17
|
+
export const isPlaceKey = (key) => typeof key === 'string' && key.length <= MAX_PLACE_KEY && KEY.test(key);
|
|
18
|
+
/** `n` keys, evenly spread and as short as `n` allows, in order: every file placed afresh. */
|
|
19
|
+
function evenKeys(n) {
|
|
20
|
+
let width = 1;
|
|
21
|
+
while (DIGITS.length ** width < (n + 1) * 2)
|
|
22
|
+
width++;
|
|
23
|
+
const span = DIGITS.length ** width;
|
|
24
|
+
return Array.from({ length: n }, (_, i) => {
|
|
25
|
+
let value = Math.floor(((i + 1) * span) / (n + 1));
|
|
26
|
+
let key = '';
|
|
27
|
+
for (let w = 0; w < width; w++) {
|
|
28
|
+
key = DIGITS[value % DIGITS.length] + key;
|
|
29
|
+
value = Math.floor(value / DIGITS.length);
|
|
30
|
+
}
|
|
31
|
+
// Never ending in `0`: a trailing `1` still sorts after this key and before the next.
|
|
32
|
+
return key.endsWith('0') ? `${key}1` : key;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Byte-wise, as §6.14 compares keys (never `localeCompare`). */
|
|
36
|
+
const compareKeys = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
37
|
+
/**
|
|
38
|
+
* A key that sorts strictly between `before` and `after`, either left out for
|
|
39
|
+
* an open end. Each must be a valid key and `before` sort before `after`.
|
|
40
|
+
* Pure, so two people dropping files between the same neighbours get the same
|
|
41
|
+
* key; the file's id breaks that tie.
|
|
42
|
+
*/
|
|
43
|
+
export function keyBetween(before, after) {
|
|
44
|
+
if (before !== undefined && !isPlaceKey(before))
|
|
45
|
+
throw new Error(`not a place key: ${JSON.stringify(before)}`);
|
|
46
|
+
if (after !== undefined && !isPlaceKey(after))
|
|
47
|
+
throw new Error(`not a place key: ${JSON.stringify(after)}`);
|
|
48
|
+
if (before !== undefined && after !== undefined && compareKeys(before, after) >= 0) {
|
|
49
|
+
throw new Error(`${JSON.stringify(before)} does not sort before ${JSON.stringify(after)}`);
|
|
50
|
+
}
|
|
51
|
+
return midpoint(before ?? '', after);
|
|
52
|
+
}
|
|
53
|
+
/** Between `a` (possibly empty) and `b` (absent: no upper end), neither ending in `0`. */
|
|
54
|
+
function midpoint(a, b) {
|
|
55
|
+
if (b !== undefined) {
|
|
56
|
+
// A shared start stays; the rest is placed between what follows it.
|
|
57
|
+
let n = 0;
|
|
58
|
+
while ((a[n] ?? '0') === b[n])
|
|
59
|
+
n++;
|
|
60
|
+
if (n > 0)
|
|
61
|
+
return b.slice(0, n) + midpoint(a.slice(n), b.slice(n));
|
|
62
|
+
}
|
|
63
|
+
const low = a ? DIGITS.indexOf(a[0]) : 0;
|
|
64
|
+
const high = b !== undefined ? DIGITS.indexOf(b[0]) : DIGITS.length;
|
|
65
|
+
if (high - low > 1)
|
|
66
|
+
return DIGITS[Math.round((low + high) / 2)];
|
|
67
|
+
// Adjacent digits: a longer `b` has room under its first digit; otherwise go one digit deeper after `a`'s.
|
|
68
|
+
if (b !== undefined && b.length > 1)
|
|
69
|
+
return b.slice(0, 1);
|
|
70
|
+
return DIGITS[low] + midpoint(a.slice(1), undefined);
|
|
71
|
+
}
|
|
72
|
+
const tagOf = (event, name) => event.tags.find((t) => t[0] === name && t[1])?.[1];
|
|
73
|
+
const isArrangeField = (field) => field.startsWith(ORDER) || field.startsWith(LOOK);
|
|
74
|
+
/** The listed file a per-file field of a list names — `lists:`, `order:` or `look:` — or `null` for any other field. */
|
|
75
|
+
export const fileOfListField = (field) => /^(lists|order|look):./.test(field) ? field.slice(field.indexOf(':') + 1) : null;
|
|
76
|
+
const fileOfField = (field) => fileOfListField(field) ?? '';
|
|
77
|
+
/**
|
|
78
|
+
* Whether a change setting `field` on `list` is one a reader folds (§6.14's
|
|
79
|
+
* skip rules, for `lists:`, `order:` and `look:` alike): one of its `o` tags
|
|
80
|
+
* is the field's `<d>`, its `a` is the list, its `O` the list's id, the `<d>`
|
|
81
|
+
* is not the list itself, and its `h` is the list's team.
|
|
82
|
+
*/
|
|
83
|
+
export function readsAs(event, field, list, team) {
|
|
84
|
+
const holder = ADDRESS.exec(list);
|
|
85
|
+
const file = fileOfField(field);
|
|
86
|
+
return (!!holder &&
|
|
87
|
+
!!file &&
|
|
88
|
+
event.tags.some((t) => t[0] === 'o' && t[1] === file) &&
|
|
89
|
+
tagOf(event, 'a') === list &&
|
|
90
|
+
tagOf(event, 'O') === holder[3] &&
|
|
91
|
+
file !== holder[3] &&
|
|
92
|
+
!!team &&
|
|
93
|
+
tagOf(event, 'h') === team);
|
|
94
|
+
}
|
|
95
|
+
/** The `order:` and `look:` changes per list, newest good and newest of any. */
|
|
96
|
+
export function arrangementHeads(events, teamOfList) {
|
|
97
|
+
const out = new Map();
|
|
98
|
+
for (const event of events) {
|
|
99
|
+
if (event.kind !== KIND_CHANGE)
|
|
100
|
+
continue;
|
|
101
|
+
const list = tagOf(event, 'a');
|
|
102
|
+
if (!list)
|
|
103
|
+
continue;
|
|
104
|
+
for (const { field } of fieldsSetBy(event)) {
|
|
105
|
+
if (!isArrangeField(field))
|
|
106
|
+
continue;
|
|
107
|
+
const heads = out.get(list) ?? { good: new Map(), any: new Map() };
|
|
108
|
+
out.set(list, heads);
|
|
109
|
+
const held = heads.any.get(field);
|
|
110
|
+
if (!held || byOrder(held, event) < 0)
|
|
111
|
+
heads.any.set(field, event);
|
|
112
|
+
if (!readsAs(event, field, list, teamOfList(list)))
|
|
113
|
+
continue;
|
|
114
|
+
const good = heads.good.get(field);
|
|
115
|
+
if (!good || byOrder(good, event) < 0)
|
|
116
|
+
heads.good.set(field, event);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
const valueIn = (event, field) => fieldsSetBy(event).find((f) => f.field === field)?.value;
|
|
122
|
+
/**
|
|
123
|
+
* One file's arrangement on a list, from {@link arrangementHeads}: `listed`
|
|
124
|
+
* is the file's newest `lists:<d>` = `true` entry, `root` the list's first
|
|
125
|
+
* record (the first `prev`).
|
|
126
|
+
*/
|
|
127
|
+
export function arrangementOf(heads, file, listed, root) {
|
|
128
|
+
const placed = heads?.good.get(orderField(file));
|
|
129
|
+
const key = placed && byOrder(placed, listed) >= 0 ? valueIn(placed, orderField(file)) : undefined;
|
|
130
|
+
const looked = heads?.good.get(lookField(file));
|
|
131
|
+
const look = looked ? valueIn(looked, lookField(file)) : undefined;
|
|
132
|
+
const orderHead = heads?.any.get(orderField(file));
|
|
133
|
+
const lookHead = heads?.any.get(lookField(file));
|
|
134
|
+
return {
|
|
135
|
+
...(isPlaceKey(key) ? { order: key } : {}),
|
|
136
|
+
...(look === 'row' || look === 'card' ? { look } : {}),
|
|
137
|
+
prev: { order: orderHead?.id ?? root.id, look: lookHead?.id ?? root.id },
|
|
138
|
+
prevAt: Math.max(changedAt(root), orderHead ? changedAt(orderHead) : 0, lookHead ? changedAt(lookHead) : 0),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* §6.14's order, stable: placed files by key (equal keys by the lower id),
|
|
143
|
+
* then the rest in the order given, which is oldest listed first.
|
|
144
|
+
*/
|
|
145
|
+
export function sortArranged(files) {
|
|
146
|
+
const placed = files.filter((f) => f.order !== undefined);
|
|
147
|
+
const rest = files.filter((f) => f.order === undefined);
|
|
148
|
+
placed.sort((a, b) => compareKeys(a.order, b.order) || compareKeys(a.file, b.file));
|
|
149
|
+
return [...placed, ...rest];
|
|
150
|
+
}
|
|
151
|
+
/** One field's change on the topic: §6.2's one-field tag order, then `o`. */
|
|
152
|
+
function fieldChange(pubkey, createdAtMs, topic, field, value, prev) {
|
|
153
|
+
const holder = ADDRESS.exec(topic.address);
|
|
154
|
+
if (!holder)
|
|
155
|
+
throw new Error(`not a file address: ${JSON.stringify(topic.address)}`);
|
|
156
|
+
if (!topic.folder)
|
|
157
|
+
throw new Error("a change names the team of the file it is on");
|
|
158
|
+
const file = fileOfField(field);
|
|
159
|
+
if (file === holder[3])
|
|
160
|
+
throw new Error('a file is not on its own list');
|
|
161
|
+
return {
|
|
162
|
+
pubkey,
|
|
163
|
+
created_at: Math.floor(createdAtMs / 1000),
|
|
164
|
+
kind: KIND_CHANGE,
|
|
165
|
+
tags: [
|
|
166
|
+
['a', topic.address],
|
|
167
|
+
['O', holder[3]],
|
|
168
|
+
['field', field],
|
|
169
|
+
['value', value],
|
|
170
|
+
['h', topic.folder],
|
|
171
|
+
['ts', String(createdAtMs)],
|
|
172
|
+
['prev', prev],
|
|
173
|
+
['o', file],
|
|
174
|
+
],
|
|
175
|
+
content: '',
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Stamped after every change it follows, so a clock that is behind is not refused. */
|
|
179
|
+
const stamp = (createdAtMs, files) => Math.max(createdAtMs, ...files.map((f) => f.prevAt + 1));
|
|
180
|
+
/**
|
|
181
|
+
* Move `file` to just after `after` (`null`: first) in `files`, which is the
|
|
182
|
+
* topic's files in the order drawn. One change: the moved file's place, and
|
|
183
|
+
* where it lands among files with no place, the places of those above it too,
|
|
184
|
+
* since unplaced files follow placed ones; files tied on one key with the one
|
|
185
|
+
* it lands before are placed again after it. Several places go in one change,
|
|
186
|
+
* taken whole or refused whole. `null` when the file is already there.
|
|
187
|
+
*/
|
|
188
|
+
export function planMoveInTopic(pubkey, createdAtMs, args) {
|
|
189
|
+
// In the topic's own order, whatever order the app draws them in (Ship groups by kind).
|
|
190
|
+
const files = sortArranged(args.files);
|
|
191
|
+
const moved = files.find((f) => f.file === args.file);
|
|
192
|
+
if (!moved)
|
|
193
|
+
throw new Error(`${args.file} is not on the topic's list`);
|
|
194
|
+
const rest = files.filter((f) => f.file !== args.file);
|
|
195
|
+
const to = args.after === null ? 0 : rest.findIndex((f) => f.file === args.after) + 1;
|
|
196
|
+
if (args.after !== null && to === 0)
|
|
197
|
+
throw new Error(`${args.after} is not on the topic's list`);
|
|
198
|
+
// Already there: nothing to write.
|
|
199
|
+
if (files.indexOf(moved) === to)
|
|
200
|
+
return null;
|
|
201
|
+
const before = rest.slice(0, to);
|
|
202
|
+
const after = rest.slice(to);
|
|
203
|
+
const writes = [];
|
|
204
|
+
const unplaced = before.findIndex((f) => f.order === undefined);
|
|
205
|
+
let low = (unplaced < 0 ? before.at(-1) : before[unplaced - 1])?.order;
|
|
206
|
+
const place = (file, high) => {
|
|
207
|
+
const key = keyBetween(low, high);
|
|
208
|
+
writes.push({ file, key });
|
|
209
|
+
low = key;
|
|
210
|
+
};
|
|
211
|
+
if (unplaced >= 0) {
|
|
212
|
+
// Everything after an unplaced file is unplaced too: nothing bounds the keys above.
|
|
213
|
+
for (const f of before.slice(unplaced))
|
|
214
|
+
place(f);
|
|
215
|
+
place(moved);
|
|
216
|
+
}
|
|
217
|
+
else if (after[0]?.order !== undefined && after[0].order === low) {
|
|
218
|
+
// It lands between two files sharing one key: place it, and the tied ones after it, below the next key.
|
|
219
|
+
let j = 0;
|
|
220
|
+
while (after[j]?.order === low)
|
|
221
|
+
j++;
|
|
222
|
+
const high = after[j]?.order;
|
|
223
|
+
place(moved, high);
|
|
224
|
+
for (const f of after.slice(0, j))
|
|
225
|
+
place(f, high);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
place(moved, after[0]?.order);
|
|
229
|
+
}
|
|
230
|
+
if (writes.some((w) => w.key.length > MAX_PLACE_KEY)) {
|
|
231
|
+
// Keys grew too long (many moves to one spot): place every placed file, and the moved one, afresh.
|
|
232
|
+
const placed = [...before, moved, ...after].filter((f) => f === moved || f.order !== undefined || before.includes(f));
|
|
233
|
+
const keys = evenKeys(placed.length);
|
|
234
|
+
writes.splice(0, writes.length, ...placed.map((file, i) => ({ file, key: keys[i] })));
|
|
235
|
+
}
|
|
236
|
+
const at = stamp(createdAtMs, writes.map((w) => w.file));
|
|
237
|
+
const changes = writes.map((w) => fieldChange(pubkey, at, args.topic, orderField(w.file.file), w.key, w.file.prev.order));
|
|
238
|
+
if (changes.length === 1)
|
|
239
|
+
return changes[0];
|
|
240
|
+
const combined = combineChanges(changes);
|
|
241
|
+
if (typeof combined === 'string')
|
|
242
|
+
throw new Error(combined);
|
|
243
|
+
return combined;
|
|
244
|
+
}
|
|
245
|
+
/** Show `file` as a row or a card: one `look:<d>` change. */
|
|
246
|
+
export function planLookInTopic(pubkey, createdAtMs, args) {
|
|
247
|
+
return fieldChange(pubkey, stamp(createdAtMs, [args.file]), args.topic, lookField(args.file.file), args.look, args.file.prev.look);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Undo of Remove: put `file` back on the list, then back in the place it had
|
|
251
|
+
* — just after `after` (`null`: first). Its look stays: a listing never
|
|
252
|
+
* resets it. Publish `relist`, then send `move` with {@link writeArrangement}
|
|
253
|
+
* over the list read again, so a refusal plans the move again rather than
|
|
254
|
+
* leaving the file back but last. The move is stamped after the listing, so
|
|
255
|
+
* its place is not older than it.
|
|
256
|
+
*/
|
|
257
|
+
export function planPutBackInTopic(pubkey, createdAtMs, args) {
|
|
258
|
+
const listedAt = stamp(createdAtMs, [args.file]);
|
|
259
|
+
const holder = ADDRESS.exec(args.topic.address);
|
|
260
|
+
if (!holder)
|
|
261
|
+
throw new Error(`not a file address: ${JSON.stringify(args.topic.address)}`);
|
|
262
|
+
const relist = {
|
|
263
|
+
pubkey,
|
|
264
|
+
created_at: Math.floor(listedAt / 1000),
|
|
265
|
+
kind: KIND_CHANGE,
|
|
266
|
+
tags: [
|
|
267
|
+
['a', args.topic.address],
|
|
268
|
+
['O', holder[3]],
|
|
269
|
+
['field', `lists:${args.file.file}`],
|
|
270
|
+
['value', 'true'],
|
|
271
|
+
['h', args.topic.folder],
|
|
272
|
+
['ts', String(listedAt)],
|
|
273
|
+
['o', args.file.file],
|
|
274
|
+
],
|
|
275
|
+
content: '',
|
|
276
|
+
};
|
|
277
|
+
const move = (files, ms) => {
|
|
278
|
+
// Back on the list it has no place yet; a list read before the listing landed does not hold it.
|
|
279
|
+
const held = files.find((f) => f.file === args.file.file);
|
|
280
|
+
const back = { ...(held ?? args.file), order: undefined, prevAt: Math.max((held ?? args.file).prevAt, listedAt) };
|
|
281
|
+
const rest = files.filter((f) => f.file !== back.file);
|
|
282
|
+
return planMoveInTopic(pubkey, Math.max(ms, listedAt + 1), { topic: args.topic, files: [...rest, back], file: back.file, after: args.after });
|
|
283
|
+
};
|
|
284
|
+
return { relist, move };
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Send an arrangement change, and answer a `conflict:` by reading the topic
|
|
288
|
+
* again and planning the change again on what is there now — never by sending
|
|
289
|
+
* the same places again. A place the planner added for a file nobody had
|
|
290
|
+
* placed would otherwise write over a move someone made since; a look or a
|
|
291
|
+
* single move planned again is §6.2's "set it again after the current one".
|
|
292
|
+
*/
|
|
293
|
+
export async function writeArrangement(args) {
|
|
294
|
+
const now = args.now ?? Date.now;
|
|
295
|
+
const tries = args.tries ?? 3;
|
|
296
|
+
let files = args.files;
|
|
297
|
+
let last = '';
|
|
298
|
+
for (let attempt = 0; attempt < tries; attempt++) {
|
|
299
|
+
const change = args.plan(files, now());
|
|
300
|
+
if (!change)
|
|
301
|
+
return { ok: true };
|
|
302
|
+
const signed = await args.sign(change);
|
|
303
|
+
const answer = await args.publish(signed);
|
|
304
|
+
if (answer.ok)
|
|
305
|
+
return { ok: true, event: signed };
|
|
306
|
+
last = answer.reason ?? 'refused with no reason';
|
|
307
|
+
const conflict = conflictOf(last);
|
|
308
|
+
if (!conflict || conflict.kind === 'other')
|
|
309
|
+
return { ok: false, refused: last };
|
|
310
|
+
files = await args.read();
|
|
311
|
+
}
|
|
312
|
+
return { ok: false, refused: `still refused after ${tries} tries: ${last}` };
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=topicArrangement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topicArrangement.js","sourceRoot":"","sources":["../src/topicArrangement.ts"],"names":[],"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M,EAAE,CAAA;QACjD,IAAI,GAAG,MAAM,CAAC,MAAM,IAAI,wBAAwB,CAAA;QAChD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;QACjC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;QAC/E,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;IAC3B,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,uBAAuB,KAAK,WAAW,IAAI,EAAE,EAAE,CAAA;AAC9E,CAAC"}
|
package/dist/topics.d.ts
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
import { type SignedEvent, type UnsignedEvent } from '@estiva-app/protocol';
|
|
28
28
|
import { type Following, type MembershipRead } from '@estiva-app/conversation';
|
|
29
29
|
import { type ForeignObject, type ProjectionCache, type QueryFn } from './projection.js';
|
|
30
|
+
import { type FileArrangement } from './topicArrangement.js';
|
|
30
31
|
/**
|
|
31
32
|
* The file kinds a listed id is looked for under by default: topic, document,
|
|
32
33
|
* project, issue. Never a bare `#d`, since a Folder's `kind:39000` shares its
|
|
@@ -108,8 +109,8 @@ export interface FileTopic {
|
|
|
108
109
|
* topics' roots.
|
|
109
110
|
*/
|
|
110
111
|
export declare function topicsOfFile(query: QueryFn, file: string): Promise<FileTopic[]>;
|
|
111
|
-
/** A file on a topic's list. */
|
|
112
|
-
export interface ListedFile {
|
|
112
|
+
/** A file on a topic's list, with its place and look there (§6.14). */
|
|
113
|
+
export interface ListedFile extends FileArrangement {
|
|
113
114
|
/** The listed file's id. */
|
|
114
115
|
file: string;
|
|
115
116
|
/** Its address when exactly one file the reader can read holds the id, else `null`: not drawn, not counted. */
|
|
@@ -118,19 +119,30 @@ export interface ListedFile {
|
|
|
118
119
|
folder: string | null;
|
|
119
120
|
entry: ListEntry;
|
|
120
121
|
}
|
|
122
|
+
/** How a topic's list is read. */
|
|
123
|
+
export interface ListReadOptions {
|
|
124
|
+
/** The file kinds a listed id resolves over (§6.14 "A listed id resolves"). */
|
|
125
|
+
fileKinds?: readonly number[];
|
|
126
|
+
/**
|
|
127
|
+
* The relay offers the list read (NIP-11 `file_list.newest`): read each
|
|
128
|
+
* topic's fields as their current changes, at most three per file however
|
|
129
|
+
* often its files were moved, not every change ever made (§6.13). Without
|
|
130
|
+
* it, every change by `#O`, which grows with each move.
|
|
131
|
+
*/
|
|
132
|
+
listRead?: boolean;
|
|
133
|
+
}
|
|
121
134
|
/**
|
|
122
135
|
* A topic's list, by the topic's address: its entries whose newest value
|
|
123
136
|
* lists the file, filed in the Folder the topic's root names (§6.2; read here,
|
|
124
|
-
* never taken from the caller), in
|
|
125
|
-
*
|
|
137
|
+
* never taken from the caller), in the topic's order (§6.14: placed files by
|
|
138
|
+
* key, then the rest oldest listed first), each with its look and the `prev`
|
|
139
|
+
* its next arrangement follows, each id resolved over `fileKinds` by
|
|
126
140
|
* `#d`. A topic the reader cannot read, or whose root names no Folder, lists
|
|
127
141
|
* nothing. An id held by none the reader can read, or by two, resolves to
|
|
128
142
|
* `null`: a consumer draws and counts only the resolved ones (§3.2, the count
|
|
129
143
|
* is the disclosure).
|
|
130
144
|
*/
|
|
131
|
-
export declare function topicList(query: QueryFn, topic: string, options?:
|
|
132
|
-
fileKinds?: readonly number[];
|
|
133
|
-
}): Promise<ListedFile[]>;
|
|
145
|
+
export declare function topicList(query: QueryFn, topic: string, options?: ListReadOptions): Promise<ListedFile[]>;
|
|
134
146
|
/**
|
|
135
147
|
* Many topics' lists at once, by address (TOP-4, Peek's Topics screen): the
|
|
136
148
|
* rules of {@link topicList} for each, in three requests whatever the number
|
|
@@ -140,9 +152,7 @@ export declare function topicList(query: QueryFn, topic: string, options?: {
|
|
|
140
152
|
* limit at a few dozen topics. Every address asked for is a key; one that
|
|
141
153
|
* lists nothing, or that the reader cannot read, maps to `[]`.
|
|
142
154
|
*/
|
|
143
|
-
export declare function topicLists(query: QueryFn, topics: readonly string[], options?:
|
|
144
|
-
fileKinds?: readonly number[];
|
|
145
|
-
}): Promise<Map<string, ListedFile[]>>;
|
|
155
|
+
export declare function topicLists(query: QueryFn, topics: readonly string[], options?: ListReadOptions): Promise<Map<string, ListedFile[]>>;
|
|
146
156
|
/** A topic as {@link readTopics} reads it. */
|
|
147
157
|
export interface ReadTopic {
|
|
148
158
|
address: string;
|
|
@@ -228,9 +238,8 @@ export declare function readAll(query: QueryFn, filters: readonly Record<string,
|
|
|
228
238
|
*
|
|
229
239
|
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-topic-keeps-its-own-list-of-files.md
|
|
230
240
|
*/
|
|
231
|
-
export declare function readTopics(query: QueryFn, me: string, options?: {
|
|
241
|
+
export declare function readTopics(query: QueryFn, me: string, options?: ListReadOptions & {
|
|
232
242
|
cache?: ProjectionCache;
|
|
233
|
-
fileKinds?: readonly number[];
|
|
234
243
|
nowSeconds?: number;
|
|
235
244
|
parentsListRead?: boolean;
|
|
236
245
|
}): Promise<TopicsRead>;
|
package/dist/topics.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topics.d.ts","sourceRoot":"","sources":["../src/topics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAc,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEvF,OAAO,EAWL,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAOL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,OAAO,EACb,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"topics.d.ts","sourceRoot":"","sources":["../src/topics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OA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C,CA6CzC"}
|
package/dist/topics.js
CHANGED
|
@@ -28,6 +28,8 @@ import { encodeNpub } from '@estiva-app/protocol';
|
|
|
28
28
|
import { RELAY_PAGE_CEILING } from '@estiva-app/protocol';
|
|
29
29
|
import { byOrder, candidateFilesOf, fileContext, foldMemberships, followingOf, HORIZON_SECONDS, isUnreadOnPlace, mentions, REPLY_FLOOR_CONTEXT, THREAD_RULE_FROM, } from '@estiva-app/conversation';
|
|
30
30
|
import { conversationsOf, folderOf, isArchived, KIND_FOLDER_STATE, resolveForeignRoots, rootOf, } from './projection.js';
|
|
31
|
+
import { fieldsSetBy } from './fields.js';
|
|
32
|
+
import { arrangementHeads, arrangementOf, fileOfListField, readsAs, sortArranged } from './topicArrangement.js';
|
|
31
33
|
const KIND_CHANGE = 1851;
|
|
32
34
|
/** The topic (bare file) kind: the only lists this stage reads (Miky, 2026-10-30). */
|
|
33
35
|
const KIND_TOPIC = 30840;
|
|
@@ -183,7 +185,8 @@ async function rootsOf(query, addresses) {
|
|
|
183
185
|
*/
|
|
184
186
|
export async function topicsOfFile(query, file) {
|
|
185
187
|
const isTopic = (entry) => entry.file === file && entry.list.startsWith(`${KIND_TOPIC}:`);
|
|
186
|
-
|
|
188
|
+
// Paged: `#o` also returns every `order:` and `look:` change on the file (§6.14), one per move.
|
|
189
|
+
const events = await readAll(query, [topicsOfFileFilter(file)]);
|
|
187
190
|
const lists = [...new Set(listEntries(events).filter(isTopic).map((entry) => entry.list))];
|
|
188
191
|
if (lists.length === 0)
|
|
189
192
|
return [];
|
|
@@ -199,8 +202,9 @@ export async function topicsOfFile(query, file) {
|
|
|
199
202
|
/**
|
|
200
203
|
* A topic's list, by the topic's address: its entries whose newest value
|
|
201
204
|
* lists the file, filed in the Folder the topic's root names (§6.2; read here,
|
|
202
|
-
* never taken from the caller), in
|
|
203
|
-
*
|
|
205
|
+
* never taken from the caller), in the topic's order (§6.14: placed files by
|
|
206
|
+
* key, then the rest oldest listed first), each with its look and the `prev`
|
|
207
|
+
* its next arrangement follows, each id resolved over `fileKinds` by
|
|
204
208
|
* `#d`. A topic the reader cannot read, or whose root names no Folder, lists
|
|
205
209
|
* nothing. An id held by none the reader can read, or by two, resolves to
|
|
206
210
|
* `null`: a consumer draws and counts only the resolved ones (§3.2, the count
|
|
@@ -227,24 +231,79 @@ export async function topicLists(query, topics, options = {}) {
|
|
|
227
231
|
/** {@link topicLists} with the roots already asked for: {@link readTopics} reads them once for everything. */
|
|
228
232
|
async function listsOf(query, asked, rootsRead, options) {
|
|
229
233
|
const out = new Map(asked.map((topic) => [topic, []]));
|
|
230
|
-
//
|
|
231
|
-
const [roots, events] = await Promise.all([rootsRead, query(asked.map(topicListFilter))]);
|
|
234
|
+
// Paged without the list read: every move adds a change to a topic's `#O`, and an unpaged read would lose its oldest entries.
|
|
235
|
+
const [roots, events] = await Promise.all([rootsRead, options.listRead ? newestChanges(query, asked) : readAll(query, asked.map(topicListFilter))]);
|
|
232
236
|
const folderOfList = (list) => {
|
|
233
237
|
const root = out.has(list) ? roots.get(list) : undefined;
|
|
234
238
|
return root ? folderOf(root) : null;
|
|
235
239
|
};
|
|
240
|
+
if (options.listRead)
|
|
241
|
+
events.push(...(await skippedAgain(query, events, folderOfList)));
|
|
236
242
|
const entries = listEntries(events, folderOfList)
|
|
237
243
|
.filter((entry) => entry.listed)
|
|
238
244
|
.sort((a, b) => byOrder(a.event, b.event));
|
|
239
245
|
if (entries.length === 0)
|
|
240
246
|
return out;
|
|
247
|
+
const heads = arrangementHeads(events, folderOfList);
|
|
241
248
|
const resolved = await resolveIds(query, [...new Set(entries.map((entry) => entry.file))], options.fileKinds);
|
|
242
249
|
for (const entry of entries) {
|
|
243
250
|
const held = resolved.get(entry.file);
|
|
244
|
-
|
|
251
|
+
const arranged = arrangementOf(heads.get(entry.list), entry.file, entry.event, roots.get(entry.list));
|
|
252
|
+
out.get(entry.list).push({ file: entry.file, address: held?.address ?? null, folder: held?.folder ?? null, entry, ...arranged });
|
|
245
253
|
}
|
|
254
|
+
for (const [list, files] of out)
|
|
255
|
+
out.set(list, sortArranged(files));
|
|
246
256
|
return out;
|
|
247
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Each topic's fields as their current changes, by the list read (§6.13):
|
|
260
|
+
* one filter per topic, all in one request, so a relay's cap on an answer
|
|
261
|
+
* cuts no more than it would for that topic alone, as the `#O` read does.
|
|
262
|
+
*/
|
|
263
|
+
async function newestChanges(query, topics) {
|
|
264
|
+
const filters = topics.flatMap((topic) => {
|
|
265
|
+
const [, kind, , d] = ADDRESS.exec(topic) ?? [];
|
|
266
|
+
return d ? [{ fields: 'newest', kinds: [Number(kind)], '#d': [d] }] : [];
|
|
267
|
+
});
|
|
268
|
+
return filters.length ? query(filters) : [];
|
|
269
|
+
}
|
|
270
|
+
/** The most files per topic the list read asks about again. */
|
|
271
|
+
const SKIPPED_READ_CAP = 100;
|
|
272
|
+
/**
|
|
273
|
+
* The list read answers each field's newest change, a malformed one too (a
|
|
274
|
+
* wrong `o` the relay takes), so the good change before it is not in the
|
|
275
|
+
* answer. For each file where that happened, read its changes on that topic
|
|
276
|
+
* again (`#O` and `#o`), so it folds as a whole `#O` read would.
|
|
277
|
+
*/
|
|
278
|
+
async function skippedAgain(query, events, folderOfList) {
|
|
279
|
+
const skipped = new Map();
|
|
280
|
+
for (const event of events) {
|
|
281
|
+
if (event.kind !== KIND_CHANGE)
|
|
282
|
+
continue;
|
|
283
|
+
const list = tagOf(event, 'a');
|
|
284
|
+
// Only a list asked for and readable: a change on another author's same-id topic folds nowhere anyway.
|
|
285
|
+
if (!list || !folderOfList(list))
|
|
286
|
+
continue;
|
|
287
|
+
for (const { field } of fieldsSetBy(event)) {
|
|
288
|
+
const file = fileOfListField(field);
|
|
289
|
+
// A list entry is read only in the one-field form (§6.14): one set in a `set` is skipped too.
|
|
290
|
+
const entryInSet = field.startsWith('lists:') && tagOf(event, 'field') === undefined;
|
|
291
|
+
if (!file || (!entryInSet && readsAs(event, field, list, folderOfList(list))))
|
|
292
|
+
continue;
|
|
293
|
+
const holder = ADDRESS.exec(list);
|
|
294
|
+
if (!holder)
|
|
295
|
+
continue;
|
|
296
|
+
const files = skipped.get(holder[3]) ?? new Set();
|
|
297
|
+
// Bounded: a change setting hundreds of junk fields asks again about the first few only.
|
|
298
|
+
if (files.size < SKIPPED_READ_CAP)
|
|
299
|
+
files.add(file);
|
|
300
|
+
skipped.set(holder[3], files);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (skipped.size === 0)
|
|
304
|
+
return [];
|
|
305
|
+
return readAll(query, [...skipped].map(([topic, files]) => ({ kinds: [KIND_CHANGE], '#O': [topic], '#o': [...files] })));
|
|
306
|
+
}
|
|
248
307
|
/** The role on a team list's entry that marks a topic one of the team's spaces (§3.3). */
|
|
249
308
|
const SPACE_ROLE = 'space';
|
|
250
309
|
/**
|
|
@@ -377,7 +436,8 @@ export async function readTopics(query, me, options = {}) {
|
|
|
377
436
|
return { me, topics: [], membership: foldMemberships(me, [], nowSeconds), mentionedIn: new Set(), inConversations: new Map() };
|
|
378
437
|
const [objects, lists, part, states] = await Promise.all([
|
|
379
438
|
resolveForeignRoots(addresses, query, options.cache, { archivedWith: true, parentsListRead: options.parentsListRead }),
|
|
380
|
-
|
|
439
|
+
// The relay that offers the list read for the parents offers it for the topics' own lists.
|
|
440
|
+
listsOf(query, addresses, Promise.resolve(roots), { ...options, listRead: options.listRead ?? options.parentsListRead }),
|
|
381
441
|
// Held once each, though one comment can answer two of the filters: the folds count events.
|
|
382
442
|
readAll(query, personInFilesFilters(me, addresses)),
|
|
383
443
|
// The team lists naming a topic, for which of them are spaces.
|