@estiva-app/interop 0.28.1 → 0.30.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 +35 -0
- package/README.md +17 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/nesting.d.ts +62 -0
- package/dist/nesting.d.ts.map +1 -0
- package/dist/nesting.js +103 -0
- package/dist/nesting.js.map +1 -0
- package/dist/projection.d.ts +28 -2
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +63 -11
- package/dist/projection.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/nesting.ts +132 -0
- package/src/projection.ts +86 -12
package/src/projection.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* thing the whole exercise argues against.
|
|
14
14
|
*/
|
|
15
15
|
import { decodeNaddr, decodeNevent, encodeNaddr, encodeNevent, findNaddrs, pointerToAddress, referenceToPointer, type AddressPointer, type EventPointer } from '@estiva-app/protocol'
|
|
16
|
-
import { parseProfile, type Profile, type SignedEvent } from '@estiva-app/protocol'
|
|
16
|
+
import { imetaOf, parseProfile, type Imeta, type Profile, type SignedEvent } from '@estiva-app/protocol'
|
|
17
17
|
import { MAX_FILTERS_PER_QUERY, RELAY_PAGE_CEILING } from '@estiva-app/protocol'
|
|
18
18
|
|
|
19
19
|
/** Query the relay. Returns matching events; shape mirrors the HTTP bridge. */
|
|
@@ -465,8 +465,21 @@ export interface CommentDecoration {
|
|
|
465
465
|
* The newest `kind:40003` — the body to show, and when. RFC 0.4 §7.2.1: a
|
|
466
466
|
* reader MUST be told the body changed, so this is kept beside the original
|
|
467
467
|
* rather than folded over it; the consumer draws the marker.
|
|
468
|
+
*
|
|
469
|
+
* When the caller passes the target's `body`, `at` and `by` are those of the
|
|
470
|
+
* last edit that **changed** the body — content not byte-identical to the
|
|
471
|
+
* body it replaced — and `edit` is absent when none did (§7.2.1, amended
|
|
472
|
+
* 2026-09-23, CON-5: the mark is about the body). `body` is always the newest
|
|
473
|
+
* edit's content. Without `body` it is the newest edit, as before.
|
|
468
474
|
*/
|
|
469
475
|
edit?: { body: string; at: number; by: string }
|
|
476
|
+
/**
|
|
477
|
+
* The `imeta` set of the newest edit that carries at least one — RFC 0.4
|
|
478
|
+
* §7.2.1 as amended 2026-09-23 (CON-5). A set replaces the target's own; it
|
|
479
|
+
* does not append. Absent when no edit carries one, in which case the
|
|
480
|
+
* target's own attachments stand: an edit with no `imeta` means "unchanged".
|
|
481
|
+
*/
|
|
482
|
+
attachments?: Imeta[]
|
|
470
483
|
/** Every reaction found, in the order the relay holds them. Empty inside the horizon means none. */
|
|
471
484
|
reactions: CommentReaction[]
|
|
472
485
|
/** Oldest first; the last one is the current state. Empty means never resolved. */
|
|
@@ -509,7 +522,8 @@ const DECORATION_TARGETS_PER_FILTER = 100
|
|
|
509
522
|
* Three rules, each from the ticket that established it:
|
|
510
523
|
*
|
|
511
524
|
* - **Edits fold newest-wins** (CON-8). The original stays on the relay and so
|
|
512
|
-
* does every edit; the fold is the reader's, and this is it.
|
|
525
|
+
* does every edit; the fold is the reader's, and this is it. Attachments
|
|
526
|
+
* fold separately (CON-5): the newest edit carrying `imeta` sets them.
|
|
513
527
|
* - **Reactions have a horizon of {@link REACTION_HORIZON} targets** (SPEC
|
|
514
528
|
* §6.6, CON-1) — the *newest* targets by `at`, one budget across whatever
|
|
515
529
|
* id spaces the caller mixes, and the number left out is reported. Edits
|
|
@@ -523,7 +537,7 @@ const DECORATION_TARGETS_PER_FILTER = 100
|
|
|
523
537
|
* relay adjudicates writes; a `40003` it stored is one it accepted.
|
|
524
538
|
*/
|
|
525
539
|
export async function commentDecorationsOf(
|
|
526
|
-
targets: readonly { id: string; at: number }[],
|
|
540
|
+
targets: readonly { id: string; at: number; body?: string }[],
|
|
527
541
|
query: QueryFn,
|
|
528
542
|
): Promise<CommentDecorations> {
|
|
529
543
|
const byId: Record<string, CommentDecoration> = {}
|
|
@@ -555,7 +569,9 @@ export async function commentDecorationsOf(
|
|
|
555
569
|
}
|
|
556
570
|
|
|
557
571
|
const seen = new Set<string>()
|
|
558
|
-
const edits = new Map<string, SignedEvent>()
|
|
572
|
+
const edits = new Map<string, SignedEvent[]>()
|
|
573
|
+
const bodies = new Map<string, string>()
|
|
574
|
+
for (const t of targets) if (t.body !== undefined && !bodies.has(t.id)) bodies.set(t.id, t.body)
|
|
559
575
|
for (let start = 0; start < filters.length; start += MAX_FILTERS_PER_QUERY) {
|
|
560
576
|
const events = await query(filters.slice(start, start + MAX_FILTERS_PER_QUERY))
|
|
561
577
|
for (const event of events) {
|
|
@@ -570,8 +586,7 @@ export async function commentDecorationsOf(
|
|
|
570
586
|
if (!target) continue
|
|
571
587
|
const into = byId[target]
|
|
572
588
|
if (event.kind === KIND_MESSAGE_EDIT) {
|
|
573
|
-
|
|
574
|
-
if (!current || byOrder(current, event) < 0) edits.set(target, event)
|
|
589
|
+
edits.set(target, [...(edits.get(target) ?? []), event])
|
|
575
590
|
} else if (event.kind === KIND_REACTION) {
|
|
576
591
|
if (!forReactions.includes(target)) continue
|
|
577
592
|
into.reactions.push({ id: event.id, emoji: event.content, by: event.pubkey, at: event.created_at })
|
|
@@ -591,8 +606,30 @@ export async function commentDecorationsOf(
|
|
|
591
606
|
}
|
|
592
607
|
}
|
|
593
608
|
}
|
|
594
|
-
for (const [target,
|
|
595
|
-
|
|
609
|
+
for (const [target, list] of edits) {
|
|
610
|
+
const ordered = [...list].sort(byOrder)
|
|
611
|
+
const into = byId[target]
|
|
612
|
+
const newest = ordered[ordered.length - 1]
|
|
613
|
+
let body = bodies.get(target)
|
|
614
|
+
if (body === undefined) {
|
|
615
|
+
into.edit = { body: newest.content, at: newest.created_at, by: newest.pubkey }
|
|
616
|
+
} else {
|
|
617
|
+
// Replayed from the target's own body, so "byte-identical to the body it
|
|
618
|
+
// replaces" is judged against the body as it then stood.
|
|
619
|
+
let changed: SignedEvent | undefined
|
|
620
|
+
for (const edit of ordered) {
|
|
621
|
+
if (edit.content !== body) changed = edit
|
|
622
|
+
body = edit.content
|
|
623
|
+
}
|
|
624
|
+
if (changed) into.edit = { body: newest.content, at: changed.created_at, by: changed.pubkey }
|
|
625
|
+
}
|
|
626
|
+
for (let i = ordered.length - 1; i >= 0; i--) {
|
|
627
|
+
const set = imetaOf(ordered[i])
|
|
628
|
+
if (set.length > 0) {
|
|
629
|
+
into.attachments = set
|
|
630
|
+
break
|
|
631
|
+
}
|
|
632
|
+
}
|
|
596
633
|
}
|
|
597
634
|
const oldestFirst = (a: { at: number; id: string }, b: { at: number; id: string }) =>
|
|
598
635
|
a.at - b.at || (a.id < b.id ? -1 : 1)
|
|
@@ -1246,6 +1283,9 @@ export const KIND_BARE_FILE = 30840
|
|
|
1246
1283
|
*/
|
|
1247
1284
|
export const BARE_FILE_MANIFEST_ADDRESS = 'spec:6.7'
|
|
1248
1285
|
|
|
1286
|
+
/** The field a bare file's `kind:1851` re-parent sets (SPEC §6.7). */
|
|
1287
|
+
const BARE_FILE_PARENT_FIELD = 'parent'
|
|
1288
|
+
|
|
1249
1289
|
const BARE_FILE_MANIFEST: Manifest = {
|
|
1250
1290
|
name: 'File',
|
|
1251
1291
|
about: 'A file no app owns. Its conversation is what every file has; its type adds nothing.',
|
|
@@ -1289,8 +1329,8 @@ const BARE_FILE_MANIFEST: Manifest = {
|
|
|
1289
1329
|
},
|
|
1290
1330
|
},
|
|
1291
1331
|
/*
|
|
1292
|
-
|
|
1293
|
-
of them (FOL-33). A Peek page offering Rename and Delete on a bare file and
|
|
1332
|
+
Four actions, and the manifest is the only place a consumer learns of any
|
|
1333
|
+
of them (FOL-33; `move` from FOL-4). A Peek page offering Rename and Delete on a bare file and
|
|
1294
1334
|
nothing on a Ship issue does so because *this* list says `rename` and
|
|
1295
1335
|
`delete` and Ship's does not — never because the kind is 30840. The rule is
|
|
1296
1336
|
the one FOL-31 set for `comment`: a control is drawn from a declaration.
|
|
@@ -1327,6 +1367,24 @@ const BARE_FILE_MANIFEST: Manifest = {
|
|
|
1327
1367
|
emits: { kind: 1851, field: 'title' },
|
|
1328
1368
|
input: { type: 'string' },
|
|
1329
1369
|
},
|
|
1370
|
+
/*
|
|
1371
|
+
`move` is the `parent` field SPEC §6.7 already defines, declared so a
|
|
1372
|
+
consumer draws the control from here as it draws Rename (FOL-4). The value
|
|
1373
|
+
is the new parent's address, or empty for the top of the team. A move
|
|
1374
|
+
never changes `h`: nesting organises and never grants access, so a file
|
|
1375
|
+
moved under another stays readable by exactly the team it was.
|
|
1376
|
+
*/
|
|
1377
|
+
{
|
|
1378
|
+
id: 'move',
|
|
1379
|
+
label: 'Move',
|
|
1380
|
+
description:
|
|
1381
|
+
"Put this file under another file in the same team, or back at the top. A change event, so anyone in " +
|
|
1382
|
+
'the team may; who can read the file does not change.',
|
|
1383
|
+
effect: 'writes',
|
|
1384
|
+
appliesTo: [String(KIND_BARE_FILE)],
|
|
1385
|
+
emits: { kind: 1851, field: BARE_FILE_PARENT_FIELD },
|
|
1386
|
+
input: { type: 'string' },
|
|
1387
|
+
},
|
|
1330
1388
|
{
|
|
1331
1389
|
id: 'delete',
|
|
1332
1390
|
label: 'Delete',
|
|
@@ -2221,6 +2279,17 @@ export interface ForeignObject {
|
|
|
2221
2279
|
* address cannot be built from it without inventing a pubkey.
|
|
2222
2280
|
*/
|
|
2223
2281
|
parentRef?: string
|
|
2282
|
+
/**
|
|
2283
|
+
* The folded field that re-parents this object, when there is one — `parent`
|
|
2284
|
+
* on a bare file (SPEC §6.7), absent for every other kind today (FOL-4).
|
|
2285
|
+
*
|
|
2286
|
+
* **For a consumer that draws field-setting actions as property rows.** The
|
|
2287
|
+
* action setting this field is a move, and its value is an address: drawn as
|
|
2288
|
+
* a text box under a card it asks a person to type `30840:<hex>:<uuid>`. It
|
|
2289
|
+
* is the tree's control, offered where the tree is — the same step aside the
|
|
2290
|
+
* title's rename takes, matched on the field for the same reason.
|
|
2291
|
+
*/
|
|
2292
|
+
parentField?: string
|
|
2224
2293
|
kind: number
|
|
2225
2294
|
/**
|
|
2226
2295
|
* The layout hint the owner declared — **a type or an ordered chain of them.**
|
|
@@ -2349,6 +2418,7 @@ function buildObject(args: {
|
|
|
2349
2418
|
comments: args.comments ?? [],
|
|
2350
2419
|
listsChildren: listsChildrenOf(projection, manifest),
|
|
2351
2420
|
parentRef: parentRefOf(manifest, pointer.kind, root, folded),
|
|
2421
|
+
...(pointer.kind === KIND_BARE_FILE ? { parentField: BARE_FILE_PARENT_FIELD } : {}),
|
|
2352
2422
|
folder: tagValue(root, 'h'),
|
|
2353
2423
|
// Substituted here rather than in the component: `<bech32>` is a NIP-89
|
|
2354
2424
|
// detail, and the widget's job is to draw a link, not to know the spec.
|
|
@@ -2680,8 +2750,11 @@ function parentRefOf(
|
|
|
2680
2750
|
issue's `project` field works (SPEC §6.7).
|
|
2681
2751
|
*/
|
|
2682
2752
|
if (kind === KIND_BARE_FILE) {
|
|
2683
|
-
|
|
2684
|
-
|
|
2753
|
+
// A folded empty value is a move to the top, not an absence: falling back
|
|
2754
|
+
// to the root tag would put the file straight back under the parent it
|
|
2755
|
+
// was moved out of (FOL-4).
|
|
2756
|
+
const moved = folded[BARE_FILE_PARENT_FIELD]
|
|
2757
|
+
if (moved) return moved.value || undefined
|
|
2685
2758
|
return root.tags.find((t) => t[0] === 'a' && t[1] && /^\d+:[0-9a-f]{64}:/.test(t[1]))?.[1]
|
|
2686
2759
|
}
|
|
2687
2760
|
for (const [parentKind, projection] of Object.entries(manifest.projections ?? {})) {
|
|
@@ -2835,6 +2908,7 @@ function buildChildObject(args: {
|
|
|
2835
2908
|
// an inconsistent shape is what makes a consumer defensive about a value it
|
|
2836
2909
|
// should be able to trust.
|
|
2837
2910
|
parentRef: parentRefOf(manifest, root.kind, root),
|
|
2911
|
+
...(root.kind === KIND_BARE_FILE ? { parentField: BARE_FILE_PARENT_FIELD } : {}),
|
|
2838
2912
|
folder: tagValue(root, 'h'),
|
|
2839
2913
|
/*
|
|
2840
2914
|
`<bech32>` is whichever form this object actually has.
|