@estiva-app/interop 0.46.0 → 0.47.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 +32 -0
- package/README.md +39 -14
- package/dist/folders.d.ts +144 -67
- package/dist/folders.d.ts.map +1 -1
- package/dist/folders.js +162 -62
- package/dist/folders.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/projection.d.ts +23 -7
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +105 -45
- package/dist/projection.js.map +1 -1
- package/package.json +1 -1
- package/src/folders.ts +197 -72
- package/src/index.ts +8 -4
- package/src/projection.ts +135 -46
package/src/projection.ts
CHANGED
|
@@ -1244,7 +1244,7 @@ export interface ResolvedManifest {
|
|
|
1244
1244
|
/**
|
|
1245
1245
|
* The bare file — `kind:30840`, SPEC §6.7, decided in RFC 0.5 §10.7.
|
|
1246
1246
|
*
|
|
1247
|
-
* A file **no app owns**: a `d`, a `title`, the `h` of the
|
|
1247
|
+
* A file **no app owns**: a `d`, a `title`, the `h` of the Folder it lives in, at
|
|
1248
1248
|
* most one `a` naming the file it sits under, and a §13.3 block document (or
|
|
1249
1249
|
* nothing) for content. A Peek topic is one. Typed kinds — a project, an issue
|
|
1250
1250
|
* — add properties on top of this; the bare file adds none, which is exactly
|
|
@@ -1374,7 +1374,7 @@ const BARE_FILE_MANIFEST: Manifest = {
|
|
|
1374
1374
|
|
|
1375
1375
|
`rename` is a `kind:1851` change to the `title` field, not a re-publish of
|
|
1376
1376
|
the `30840`. The title slot already folds `title`, so a rename by anyone in
|
|
1377
|
-
the
|
|
1377
|
+
the Folder lands for every reader the way a re-parent does; a re-publish
|
|
1378
1378
|
could only ever be the author's, because a `30840` from another pubkey is a
|
|
1379
1379
|
different address and not a refusal. `delete` is NIP-09's `kind:5` naming
|
|
1380
1380
|
the address — the relay decides who may (the author, or the owner of an
|
|
@@ -1386,7 +1386,7 @@ const BARE_FILE_MANIFEST: Manifest = {
|
|
|
1386
1386
|
id: 'comment',
|
|
1387
1387
|
label: 'Comment',
|
|
1388
1388
|
description:
|
|
1389
|
-
'Say something about this file. The comment lands in the
|
|
1389
|
+
'Say something about this file. The comment lands in the Folder the file lives in, ' +
|
|
1390
1390
|
'and is what every reader of the file sees under it.',
|
|
1391
1391
|
effect: 'writes',
|
|
1392
1392
|
appliesTo: [String(KIND_BARE_FILE)],
|
|
@@ -1397,7 +1397,7 @@ const BARE_FILE_MANIFEST: Manifest = {
|
|
|
1397
1397
|
id: 'rename',
|
|
1398
1398
|
label: 'Rename',
|
|
1399
1399
|
description:
|
|
1400
|
-
'Give this file a new title. A change event, so anyone in the
|
|
1400
|
+
'Give this file a new title. A change event, so anyone in the Folder may, and every app ' +
|
|
1401
1401
|
'reading the file folds it into the title.',
|
|
1402
1402
|
effect: 'writes',
|
|
1403
1403
|
appliesTo: [String(KIND_BARE_FILE)],
|
|
@@ -1407,16 +1407,16 @@ const BARE_FILE_MANIFEST: Manifest = {
|
|
|
1407
1407
|
/*
|
|
1408
1408
|
`move` is the `parent` field SPEC §6.7 already defines, declared so a
|
|
1409
1409
|
consumer draws the control from here as it draws Rename (FOL-4). The value
|
|
1410
|
-
is the new parent's address, or empty for the top of the
|
|
1410
|
+
is the new parent's address, or empty for the top of the Folder. A move
|
|
1411
1411
|
never changes `h`: nesting organises and never grants access, so a file
|
|
1412
|
-
moved under another stays readable by exactly the
|
|
1412
|
+
moved under another stays readable by exactly the people it was.
|
|
1413
1413
|
*/
|
|
1414
1414
|
{
|
|
1415
1415
|
id: 'move',
|
|
1416
1416
|
label: 'Move',
|
|
1417
1417
|
description:
|
|
1418
|
-
"Put this file under another file in the same
|
|
1419
|
-
'the
|
|
1418
|
+
"Put this file under another file in the same Folder, or back at the top. A change event, so anyone in " +
|
|
1419
|
+
'the Folder may; who can read the file does not change.',
|
|
1420
1420
|
effect: 'writes',
|
|
1421
1421
|
appliesTo: [String(KIND_BARE_FILE)],
|
|
1422
1422
|
emits: { kind: 1851, field: 'parent' },
|
|
@@ -1425,7 +1425,7 @@ const BARE_FILE_MANIFEST: Manifest = {
|
|
|
1425
1425
|
/*
|
|
1426
1426
|
`archive` is the one field every file may carry (FOL-46): `true` hides the
|
|
1427
1427
|
file and everything under it from every list, an empty value brings it
|
|
1428
|
-
back. A change, so anyone in the
|
|
1428
|
+
back. A change, so anyone in the Folder may, and the archiving change's
|
|
1429
1429
|
`content` is the resolution summary a person gave (`ActionEventArgs.note`).
|
|
1430
1430
|
*/
|
|
1431
1431
|
{
|
|
@@ -2093,8 +2093,24 @@ export function isArchived(file: { archived?: Archive } | null | undefined): boo
|
|
|
2093
2093
|
* `changes` may hold any events; only this rule's change kind, naming this
|
|
2094
2094
|
* address, setting this field, is read. Last write wins, by the same order as
|
|
2095
2095
|
* every other field.
|
|
2096
|
+
*
|
|
2097
|
+
* **A Folder is the exception** (SPEC §3.2): on a `kind:39000` address only a
|
|
2098
|
+
* change in the Folder's own `h` by one of `folderAdmins` — the owners and
|
|
2099
|
+
* admins on its relay-signed `kind:39001` — counts. A caller that has not read
|
|
2100
|
+
* the admin list passes none, and then no change counts: a Folder shown live
|
|
2101
|
+
* when it is archived is recoverable, one any member could hide is not.
|
|
2096
2102
|
*/
|
|
2097
|
-
function archiveOf(
|
|
2103
|
+
function archiveOf(
|
|
2104
|
+
changes: SignedEvent[],
|
|
2105
|
+
address: string,
|
|
2106
|
+
rule: RecordsRule,
|
|
2107
|
+
folderAdmins?: ReadonlySet<string>,
|
|
2108
|
+
): Archive | undefined {
|
|
2109
|
+
const [kind, , folderId] = address.split(':')
|
|
2110
|
+
if (Number(kind) === KIND_CHANNEL) {
|
|
2111
|
+
if (!folderAdmins?.size) return undefined
|
|
2112
|
+
changes = changes.filter((change) => tagValue(change, 'h') === folderId && folderAdmins.has(change.pubkey))
|
|
2113
|
+
}
|
|
2098
2114
|
let last: SignedEvent | undefined
|
|
2099
2115
|
for (const change of changes) {
|
|
2100
2116
|
// The target is the first target tag, as every other fold reads it: a
|
|
@@ -5272,15 +5288,46 @@ export const KIND_FOLDER_STATE = 30890
|
|
|
5272
5288
|
/**
|
|
5273
5289
|
* NIP-29 group metadata — the Folder's channel.
|
|
5274
5290
|
*
|
|
5275
|
-
* Named here for two unrelated jobs: it carries the
|
|
5276
|
-
*
|
|
5277
|
-
* like any other (§5.2).
|
|
5291
|
+
* Named here for two unrelated jobs: it carries the Folder's title — its
|
|
5292
|
+
* `name`, and only that (SPEC §3.2) — and its own address is what makes a Peek
|
|
5293
|
+
* topic a file like any other (§5.2).
|
|
5278
5294
|
*/
|
|
5279
5295
|
const KIND_CHANNEL = 39000
|
|
5280
5296
|
|
|
5297
|
+
/** NIP-29 group admins — the relay's list of who holds which role in a channel. */
|
|
5298
|
+
const KIND_CHANNEL_ADMINS = 39001
|
|
5299
|
+
|
|
5300
|
+
/** The roles on a `kind:39001` that may rename a Folder, and so archive it (SPEC §3.2). */
|
|
5301
|
+
const FOLDER_ADMIN_ROLES = new Set(['owner', 'admin'])
|
|
5302
|
+
|
|
5281
5303
|
/** The `name` tag, when there is an event to read it off at all. */
|
|
5282
5304
|
const nameOf = (event: SignedEvent | undefined) => (event ? tagValue(event, 'name') : undefined)
|
|
5283
5305
|
|
|
5306
|
+
/**
|
|
5307
|
+
* The owners and admins a `kind:39001` lists — kept only when the channel's own
|
|
5308
|
+
* signer, the relay, signed it: anybody can publish an event of that shape.
|
|
5309
|
+
*/
|
|
5310
|
+
function folderAdminsOf(admins: SignedEvent | undefined, channel: SignedEvent | undefined): string[] {
|
|
5311
|
+
if (!admins || !channel || admins.pubkey !== channel.pubkey) return []
|
|
5312
|
+
return [
|
|
5313
|
+
...new Set(
|
|
5314
|
+
admins.tags
|
|
5315
|
+
.filter((tag) => tag[0] === 'p' && tag[1] && tag.slice(2).some((role) => FOLDER_ADMIN_ROLES.has(role)))
|
|
5316
|
+
.map((tag) => tag[1]),
|
|
5317
|
+
),
|
|
5318
|
+
]
|
|
5319
|
+
}
|
|
5320
|
+
|
|
5321
|
+
/**
|
|
5322
|
+
* A Folder's own archive (SPEC §3.2): the `archived` changes on its channel's
|
|
5323
|
+
* address, counting only one carrying the Folder's own `h` whose author the
|
|
5324
|
+
* relay lists as its owner or admin. From anybody else the relay accepts the
|
|
5325
|
+
* change, and it means nothing.
|
|
5326
|
+
*/
|
|
5327
|
+
function folderArchiveOf(changes: SignedEvent[], folder: Pick<FolderSummary, 'id' | 'channel' | 'admins'>): Archive | undefined {
|
|
5328
|
+
return folder.channel ? archiveOf(changes, folder.channel, ARCHIVE_RULE, new Set(folder.admins ?? [])) : undefined
|
|
5329
|
+
}
|
|
5330
|
+
|
|
5284
5331
|
/** One folder, enough to draw a sidebar row. */
|
|
5285
5332
|
export interface FolderSummary {
|
|
5286
5333
|
/**
|
|
@@ -5289,17 +5336,33 @@ export interface FolderSummary {
|
|
|
5289
5336
|
* measured across all of production's channels).
|
|
5290
5337
|
*/
|
|
5291
5338
|
id: string
|
|
5339
|
+
/**
|
|
5340
|
+
* The title: its `kind:39000`'s `name`, and only that (SPEC §3.2). A `name`
|
|
5341
|
+
* an older `kind:1852` left on the state is never read — any member may send
|
|
5342
|
+
* one, and only owners and admins may rename the channel.
|
|
5343
|
+
*/
|
|
5292
5344
|
name?: string
|
|
5293
5345
|
/** True once the relay maintains state for it, rather than it being a bare channel. */
|
|
5294
5346
|
hasState: boolean
|
|
5347
|
+
/**
|
|
5348
|
+
* Present when the Folder's relay-signed `kind:39000` carries `["private"]`
|
|
5349
|
+
* (NIP-29). What `planMoveFile` reads as `FolderRef.private`.
|
|
5350
|
+
*/
|
|
5351
|
+
private?: true
|
|
5352
|
+
/**
|
|
5353
|
+
* Who may rename and archive it: the owners and admins on its relay-signed
|
|
5354
|
+
* `kind:39001`. Offer Archive only to them — a reader ignores an archive from
|
|
5355
|
+
* anybody else (§3.2). Absent when the relay returned no admin list.
|
|
5356
|
+
*/
|
|
5357
|
+
admins?: string[]
|
|
5295
5358
|
/**
|
|
5296
5359
|
* The folders whose state lists this one as a file — present only when there
|
|
5297
5360
|
* are any.
|
|
5298
5361
|
*
|
|
5299
5362
|
* A channel is addressable (§5.2), so a folder can be placed inside another
|
|
5300
5363
|
* the way any file is, and Peek's topics are (FOL-22): each is a channel
|
|
5301
|
-
* listed by its
|
|
5302
|
-
* folder would show the
|
|
5364
|
+
* listed by its Folder's state. A sidebar that drew every channel as a top-level
|
|
5365
|
+
* folder would show the Folder and, beside it, every topic in it. This is what
|
|
5303
5366
|
* lets a consumer tell the two apart without reading any folder's contents:
|
|
5304
5367
|
* `listFolders` already holds every state, so the answer is free.
|
|
5305
5368
|
*/
|
|
@@ -5311,7 +5374,7 @@ export interface FolderSummary {
|
|
|
5311
5374
|
* `listedIn` in the other direction, and free for the same reason: the
|
|
5312
5375
|
* states are already in hand. It is the unresolved list — a row that names
|
|
5313
5376
|
* an archived or unreachable record is still here — so a consumer that
|
|
5314
|
-
* draws one app's own records under a folder (Ship's projects under a
|
|
5377
|
+
* draws one app's own records under a folder (Ship's projects under a Folder,
|
|
5315
5378
|
* FOL-5) intersects it with the records it holds, and a consumer that draws
|
|
5316
5379
|
* another app's files resolves them with {@link resolveFolderContents}.
|
|
5317
5380
|
*/
|
|
@@ -5349,7 +5412,7 @@ export interface FolderSummary {
|
|
|
5349
5412
|
* never gets; and a folder another one lists (`listedIn`) is a row inside
|
|
5350
5413
|
* that one, not a section beside it.
|
|
5351
5414
|
*
|
|
5352
|
-
* Not a list of ids: a new
|
|
5415
|
+
* Not a list of ids: a new Folder is a folder somebody creates, not a code
|
|
5353
5416
|
* change. Moved here from Peek and Ship, which each held the same line.
|
|
5354
5417
|
*
|
|
5355
5418
|
* An archived Folder is not navigated by (FOL-46), and a listing that has not
|
|
@@ -5394,8 +5457,8 @@ export interface FolderContents extends FolderSummary {
|
|
|
5394
5457
|
* Every folder this identity can see, for a sidebar.
|
|
5395
5458
|
*
|
|
5396
5459
|
* Both shapes in one pass: folders the relay maintains state for, and bare
|
|
5397
|
-
* channels that have none yet. A channel with state appears once,
|
|
5398
|
-
*
|
|
5460
|
+
* channels that have none yet. A channel with state appears once, titled by its
|
|
5461
|
+
* `kind:39000` (SPEC §3.2), with the owners and admins its `kind:39001` lists.
|
|
5399
5462
|
*
|
|
5400
5463
|
* **A direct route, deliberately.** §4.2's post-mortem on REW-11 is that
|
|
5401
5464
|
* discovering children only through their parent loses them when the parent
|
|
@@ -5406,27 +5469,36 @@ export async function listFolders(query: QueryFn): Promise<FolderSummary[]> {
|
|
|
5406
5469
|
const events = await query([
|
|
5407
5470
|
{ kinds: [KIND_FOLDER_STATE], limit: 500 },
|
|
5408
5471
|
{ kinds: [KIND_CHANNEL], limit: 500 },
|
|
5472
|
+
{ kinds: [KIND_CHANNEL_ADMINS], limit: 500 },
|
|
5409
5473
|
])
|
|
5410
5474
|
const byId = new Map<string, FolderSummary>()
|
|
5475
|
+
const channelOf = new Map<string, SignedEvent>()
|
|
5476
|
+
const adminsOf = new Map<string, SignedEvent>()
|
|
5411
5477
|
for (const event of events) {
|
|
5412
5478
|
const id = tagValue(event, 'd')
|
|
5413
5479
|
if (!id) continue
|
|
5480
|
+
if (event.kind === KIND_CHANNEL) channelOf.set(id, event)
|
|
5481
|
+
if (event.kind === KIND_CHANNEL_ADMINS) adminsOf.set(id, event)
|
|
5482
|
+
if (event.kind !== KIND_FOLDER_STATE && event.kind !== KIND_CHANNEL) continue
|
|
5414
5483
|
const state = event.kind === KIND_FOLDER_STATE
|
|
5415
5484
|
const existing = byId.get(id)
|
|
5416
|
-
|
|
5417
|
-
if (existing && !state) continue
|
|
5418
|
-
const addresses = state ? event.tags.filter((tag) => tag[0] === 'a' && tag[1]).map((tag) => tag[1]) : []
|
|
5485
|
+
const addresses = state ? event.tags.filter((tag) => tag[0] === 'a' && tag[1]).map((tag) => tag[1]) : (existing?.addresses ?? [])
|
|
5419
5486
|
byId.set(id, {
|
|
5420
5487
|
id,
|
|
5421
|
-
name: tagValue(event, 'name') ?? existing?.name,
|
|
5422
5488
|
hasState: state || (existing?.hasState ?? false),
|
|
5423
5489
|
...(addresses.length ? { addresses } : {}),
|
|
5424
5490
|
})
|
|
5425
5491
|
}
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
const
|
|
5429
|
-
if (
|
|
5492
|
+
// The title, privacy and admins are the channel's (§3.2), whichever order the events arrived.
|
|
5493
|
+
for (const [id, folder] of byId) {
|
|
5494
|
+
const channel = channelOf.get(id)
|
|
5495
|
+
if (!channel) continue
|
|
5496
|
+
const name = nameOf(channel)
|
|
5497
|
+
if (name !== undefined) folder.name = name
|
|
5498
|
+
if (channel.tags.some((tag) => tag[0] === 'private')) folder.private = true
|
|
5499
|
+
const admins = folderAdminsOf(adminsOf.get(id), channel)
|
|
5500
|
+
if (admins.length) folder.admins = admins
|
|
5501
|
+
folder.channel = pointerToAddress({ kind: KIND_CHANNEL, pubkey: channel.pubkey, identifier: id, relays: [] })
|
|
5430
5502
|
}
|
|
5431
5503
|
/*
|
|
5432
5504
|
A folder listed in another folder's state is a file there. Read off the
|
|
@@ -5463,13 +5535,13 @@ export async function listFolders(query: QueryFn): Promise<FolderSummary[]> {
|
|
|
5463
5535
|
*
|
|
5464
5536
|
* A Folder is archived by a change naming its channel's address, the way any
|
|
5465
5537
|
* file is. A record's channel — a Ship project's conversation — is archived
|
|
5466
|
-
* with its record, so an archived project's channel stops lighting its
|
|
5538
|
+
* with its record, so an archived project's channel stops lighting its Folder's
|
|
5467
5539
|
* dot the way the project stopped being listed — only when every record naming
|
|
5468
5540
|
* the channel is archived, since two projects may share one. Its own archive
|
|
5469
5541
|
* wins when it has one.
|
|
5470
5542
|
*
|
|
5471
5543
|
* A refused read throws before this, like the reads beside it: a listing that
|
|
5472
|
-
* silently reported every Folder live would put archived
|
|
5544
|
+
* silently reported every Folder live would put archived Folders back in
|
|
5473
5545
|
* everyone's sidebar.
|
|
5474
5546
|
*/
|
|
5475
5547
|
function markArchivedFolders(
|
|
@@ -5478,7 +5550,7 @@ function markArchivedFolders(
|
|
|
5478
5550
|
changes: SignedEvent[],
|
|
5479
5551
|
): void {
|
|
5480
5552
|
for (const folder of byId.values()) {
|
|
5481
|
-
const own =
|
|
5553
|
+
const own = folderArchiveOf(changes, folder)
|
|
5482
5554
|
if (own) {
|
|
5483
5555
|
folder.archived = own
|
|
5484
5556
|
continue
|
|
@@ -5651,13 +5723,13 @@ async function countLiveChildren(
|
|
|
5651
5723
|
* names the channel its conversation lives in with {@link folderOf}'s tags. No
|
|
5652
5724
|
* state lists that channel, so without this `listFolders` reports it placed
|
|
5653
5725
|
* nowhere, and a consumer folding an unread verdict into the containers of a
|
|
5654
|
-
* channel (Peek's
|
|
5726
|
+
* channel (Peek's Folder dot) has nowhere to fold it: correct, and drawn
|
|
5655
5727
|
* nowhere. Measured on production 2026-09-22: of the 43 records the six
|
|
5656
5728
|
* states list, 23 name a channel other than the state's own and no state lists
|
|
5657
5729
|
* any of them. This places 21 channels and moves no top-level Folder.
|
|
5658
5730
|
*
|
|
5659
5731
|
* Derived rather than published, so it cannot drift: a `kind:1852` adding each
|
|
5660
|
-
* channel to its
|
|
5732
|
+
* channel to its Folder would have to be repeated by every app that places a
|
|
5661
5733
|
* record, and would stay wrong the first time one did not.
|
|
5662
5734
|
*
|
|
5663
5735
|
* Both of `folderOf`'s spellings, because production has both — about half of
|
|
@@ -5682,7 +5754,7 @@ async function countLiveChildren(
|
|
|
5682
5754
|
* production that was the bug it was meant to prevent: Peek reads the listing
|
|
5683
5755
|
* once per page load, the load is when the relay's budget is most contested,
|
|
5684
5756
|
* and one refused read on 2026-09-22 left a project's channel unplaced for the
|
|
5685
|
-
* whole session — the
|
|
5757
|
+
* whole session — the Folder's dot dark, and nothing anywhere saying why. A
|
|
5686
5758
|
* listing missing placements looks exactly like a correct one, so only the
|
|
5687
5759
|
* caller can recover, and only if it is told. Keeping the last good listing
|
|
5688
5760
|
* and retrying is the caller's to do.
|
|
@@ -5762,7 +5834,7 @@ async function placeRecordChannels(
|
|
|
5762
5834
|
const channel = root && folderOf(root)
|
|
5763
5835
|
if (!channel || byId.get(channel)?.hasState) continue
|
|
5764
5836
|
// A file published into the Folder that lists it names that Folder, and
|
|
5765
|
-
// does not own it: a topic's `h` is its
|
|
5837
|
+
// does not own it: a topic's `h` is its Folder's.
|
|
5766
5838
|
if (!containers.includes(channel)) recordsOf.set(channel, [...(recordsOf.get(channel) ?? []), key])
|
|
5767
5839
|
for (const container of containers) {
|
|
5768
5840
|
if (container === channel) continue
|
|
@@ -5838,17 +5910,24 @@ export async function resolveFolderContents(
|
|
|
5838
5910
|
const identity = await query([
|
|
5839
5911
|
{ kinds: [KIND_FOLDER_STATE], '#d': [folder], limit: 1 },
|
|
5840
5912
|
{ kinds: [KIND_CHANNEL], '#d': [folder], limit: 1 },
|
|
5913
|
+
{ kinds: [KIND_CHANNEL_ADMINS], '#d': [folder], limit: 1 },
|
|
5841
5914
|
])
|
|
5842
5915
|
const state = identity.find((e) => e.kind === KIND_FOLDER_STATE && tagValue(e, 'd') === folder)
|
|
5843
5916
|
const channel = identity.find((e) => e.kind === KIND_CHANNEL && tagValue(e, 'd') === folder)
|
|
5917
|
+
const admins = folderAdminsOf(
|
|
5918
|
+
identity.find((e) => e.kind === KIND_CHANNEL_ADMINS && tagValue(e, 'd') === folder),
|
|
5919
|
+
channel,
|
|
5920
|
+
)
|
|
5844
5921
|
const channelAddress = channel
|
|
5845
5922
|
? pointerToAddress({ kind: KIND_CHANNEL, pubkey: channel.pubkey, identifier: folder, relays: [] })
|
|
5846
5923
|
: undefined
|
|
5847
5924
|
|
|
5848
5925
|
const summary: FolderSummary & { address?: string } = {
|
|
5849
5926
|
id: folder,
|
|
5850
|
-
name: nameOf(
|
|
5927
|
+
name: nameOf(channel),
|
|
5851
5928
|
hasState: !!state,
|
|
5929
|
+
...(channel?.tags.some((tag) => tag[0] === 'private') ? { private: true as const } : {}),
|
|
5930
|
+
...(admins.length ? { admins } : {}),
|
|
5852
5931
|
...(channelAddress ? { channel: channelAddress } : {}),
|
|
5853
5932
|
...(state
|
|
5854
5933
|
? { address: pointerToAddress({ kind: state.kind, pubkey: state.pubkey, identifier: folder, relays: [] }) }
|
|
@@ -5867,9 +5946,7 @@ export async function resolveFolderContents(
|
|
|
5867
5946
|
if (addresses.length === 0) {
|
|
5868
5947
|
// Nothing listed, so no change query to ride on: the Folder's own archive
|
|
5869
5948
|
// is one small read of its own.
|
|
5870
|
-
const archived = channelAddress
|
|
5871
|
-
? archiveOf(await readArchiveChanges([channelAddress], query), channelAddress, ARCHIVE_RULE)
|
|
5872
|
-
: undefined
|
|
5949
|
+
const archived = channelAddress ? folderArchiveOf(await readArchiveChanges([channelAddress], query), summary) : undefined
|
|
5873
5950
|
return { ...summary, ...(archived ? { archived } : {}), files: [], source: state ? 'state' : 'channel' }
|
|
5874
5951
|
}
|
|
5875
5952
|
|
|
@@ -5919,6 +5996,7 @@ export async function resolveFolderContents(
|
|
|
5919
5996
|
...[...manifests.values()].flatMap((r) => (r.manifest.records ? [r.manifest.records.changeKind] : [])),
|
|
5920
5997
|
]),
|
|
5921
5998
|
]
|
|
5999
|
+
const nestedFolderIds = pointers.filter(({ pointer }) => pointer.kind === KIND_CHANNEL).map(({ pointer }) => pointer.identifier)
|
|
5922
6000
|
const events = await query([
|
|
5923
6001
|
...[...groups.values()].map(({ pointer, addresses: group }) => ({
|
|
5924
6002
|
kinds: [pointer.kind],
|
|
@@ -5932,8 +6010,10 @@ export async function resolveFolderContents(
|
|
|
5932
6010
|
// changes for every file together, and one Folder has already had 688.
|
|
5933
6011
|
// Same request.
|
|
5934
6012
|
...archiveFilters(channelAddress ? [...addresses, channelAddress] : addresses),
|
|
6013
|
+
// A Folder listed here counts its archive only from its own admins (§3.2). Same request.
|
|
6014
|
+
...(nestedFolderIds.length ? [{ kinds: [KIND_CHANNEL_ADMINS], '#d': nestedFolderIds, limit: nestedFolderIds.length }] : []),
|
|
5935
6015
|
])
|
|
5936
|
-
const ownArchive =
|
|
6016
|
+
const ownArchive = folderArchiveOf(events, summary)
|
|
5937
6017
|
if (ownArchive) summary.archived = ownArchive
|
|
5938
6018
|
|
|
5939
6019
|
// 4. Build each file, in the order the folder listed them. Archived files are
|
|
@@ -5960,7 +6040,16 @@ export async function resolveFolderContents(
|
|
|
5960
6040
|
events.filter((e) => e.kind === records.changeKind && hasTagValue(e, records.targetTag, address)),
|
|
5961
6041
|
records,
|
|
5962
6042
|
)
|
|
5963
|
-
const
|
|
6043
|
+
const nestedAdmins =
|
|
6044
|
+
pointer.kind === KIND_CHANNEL
|
|
6045
|
+
? new Set(
|
|
6046
|
+
folderAdminsOf(
|
|
6047
|
+
events.find((e) => e.kind === KIND_CHANNEL_ADMINS && tagValue(e, 'd') === pointer.identifier),
|
|
6048
|
+
root,
|
|
6049
|
+
),
|
|
6050
|
+
)
|
|
6051
|
+
: undefined
|
|
6052
|
+
const archive = archiveOf(events, address, archiveRuleOf(resolved.manifest), nestedAdmins)
|
|
5964
6053
|
archiveByAddress.set(address, archive)
|
|
5965
6054
|
const parent = parentRefOf(resolved.manifest, pointer.kind, root, folded)
|
|
5966
6055
|
parentByAddress.set(address, parent)
|
|
@@ -5981,7 +6070,7 @@ export async function resolveFolderContents(
|
|
|
5981
6070
|
the file is here; if the fold has moved on, somebody has since placed it
|
|
5982
6071
|
somewhere else and this folder is holding a statement that has been
|
|
5983
6072
|
superseded, which an append-only stream cannot retract. Ship linking a
|
|
5984
|
-
project to a second
|
|
6073
|
+
project to a second Folder is the case: the first Folder keeps the
|
|
5985
6074
|
old statement for ever, and without this check would list the project
|
|
5986
6075
|
for ever.
|
|
5987
6076
|
|
|
@@ -6081,17 +6170,17 @@ export async function resolveFolderContents(
|
|
|
6081
6170
|
*
|
|
6082
6171
|
* A folder lists the files whose `h` it is **and** the files placed in it.
|
|
6083
6172
|
* An event cannot change its own `h`, so a project filed in one Folder and
|
|
6084
|
-
* later linked to a
|
|
6173
|
+
* later linked to a Folder keeps the `h` it was born with, and the only thing
|
|
6085
6174
|
* that can say "it belongs over there now" is a change event. Ship publishes
|
|
6086
6175
|
* that change twice — into the record's own Folder, and *into the Folder
|
|
6087
|
-
* being linked*: a `kind:1851` carried by the
|
|
6088
|
-
* project, whose value is the
|
|
6176
|
+
* being linked*: a `kind:1851` carried by the Folder's `h`, targeting the
|
|
6177
|
+
* project, whose value is the Folder itself. The second copy is the
|
|
6089
6178
|
* placement, and it is what this reads.
|
|
6090
6179
|
*
|
|
6091
6180
|
* {@link resolveFolderProject} has read the same statement since PEEK-24 to
|
|
6092
6181
|
* answer "which project is this topic paired with". This is the listing's
|
|
6093
|
-
* half of it, and it is the rule the tidy-up rests on: five
|
|
6094
|
-
* fourteen projects linked into them and none re-created, so a
|
|
6182
|
+
* half of it, and it is the rule the tidy-up rests on: five Folders,
|
|
6183
|
+
* fourteen projects linked into them and none re-created, so a Folder
|
|
6095
6184
|
* whose `h` is on nothing lists its projects anyway.
|
|
6096
6185
|
*
|
|
6097
6186
|
* App-neutral by the same discipline as everything else here. The change
|