@estiva-app/interop 0.46.0 → 0.48.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 +49 -0
- package/README.md +43 -15
- 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 +148 -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 +175 -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
|
|
@@ -4883,6 +4899,15 @@ function buildCreationEvent(args: {
|
|
|
4883
4899
|
}
|
|
4884
4900
|
}
|
|
4885
4901
|
|
|
4902
|
+
// A person property is checked as a person change is (SPEC §7.3, SHA-28).
|
|
4903
|
+
const people: string[] = []
|
|
4904
|
+
for (const [name, held] of Object.entries(value)) {
|
|
4905
|
+
if (properties[name]?.type !== 'pubkey') continue
|
|
4906
|
+
const problem = personKeyProblem(declared.label, held)
|
|
4907
|
+
if (problem) return problem
|
|
4908
|
+
if (held !== '' && !people.includes(held)) people.push(held)
|
|
4909
|
+
}
|
|
4910
|
+
|
|
4886
4911
|
if (isAddressableKind(declared.emits.kind) && !newId) {
|
|
4887
4912
|
return `Creating a kind ${declared.emits.kind} needs an identifier, and none was supplied.`
|
|
4888
4913
|
}
|
|
@@ -4929,6 +4954,9 @@ function buildCreationEvent(args: {
|
|
|
4929
4954
|
tags.push([declared.emits.setTag, address])
|
|
4930
4955
|
}
|
|
4931
4956
|
tags.push([placement, folder], ...prose)
|
|
4957
|
+
// Each person the new root names, once, where the relay indexes them — the
|
|
4958
|
+
// property's own tag is not indexed (SPEC §11.8, decided 2026-10-05).
|
|
4959
|
+
for (const person of people) tags.push(['p', person])
|
|
4932
4960
|
|
|
4933
4961
|
return {
|
|
4934
4962
|
pubkey: args.pubkey,
|
|
@@ -4939,6 +4967,21 @@ function buildCreationEvent(args: {
|
|
|
4939
4967
|
}
|
|
4940
4968
|
}
|
|
4941
4969
|
|
|
4970
|
+
/**
|
|
4971
|
+
* A person's key as an input of `type: "pubkey"` takes it — SPEC §7.3, SHA-28.
|
|
4972
|
+
* The `p` a writer adds must be what `#p` matches, so an npub or upper-case hex
|
|
4973
|
+
* is refused rather than converted: the person picking it saw something else.
|
|
4974
|
+
*/
|
|
4975
|
+
const PERSON_KEY = /^[0-9a-f]{64}$/
|
|
4976
|
+
|
|
4977
|
+
/** Why `value` is neither `''` nor a person's key, or undefined when it is one. */
|
|
4978
|
+
function personKeyProblem(label: string, value: string): string | undefined {
|
|
4979
|
+
if (value === '' || PERSON_KEY.test(value)) return undefined
|
|
4980
|
+
// A consumer shows this to the person, whose picker went wrong upstream; the
|
|
4981
|
+
// rule for developers is SPEC §7.3's, not theirs to act on.
|
|
4982
|
+
return `"${label}" needs a person picked from the list, so nothing was changed.`
|
|
4983
|
+
}
|
|
4984
|
+
|
|
4942
4985
|
/** What {@link buildActionEvent} and {@link buildActionEvents} are handed. */
|
|
4943
4986
|
export interface ActionEventArgs {
|
|
4944
4987
|
manifest: { records?: RecordsRule; actions?: ManifestAction[]; vocabularies?: Manifest['vocabularies'] }
|
|
@@ -5167,6 +5210,15 @@ function buildOneActionEvent(args: ActionEventArgs): UnsignedActionEvent | strin
|
|
|
5167
5210
|
}
|
|
5168
5211
|
}
|
|
5169
5212
|
|
|
5213
|
+
// A change whose input is a person names them (SPEC §7.3's `pubkey`, SHA-28).
|
|
5214
|
+
// `''` clears it and names nobody; anything else that is not a key would fold
|
|
5215
|
+
// as the field's value and make nobody a member, so it is refused here.
|
|
5216
|
+
const namesPerson = !!declared.emits.field && declared.input?.type === 'pubkey'
|
|
5217
|
+
if (namesPerson) {
|
|
5218
|
+
const problem = personKeyProblem(declared.label, value)
|
|
5219
|
+
if (problem) return problem
|
|
5220
|
+
}
|
|
5221
|
+
|
|
5170
5222
|
// A prose value's `content-format` and `imeta` — a change only, per the
|
|
5171
5223
|
// refusal above. Ship's order: the tag before `ts`, the files after it.
|
|
5172
5224
|
const prose = declared.emits.field
|
|
@@ -5212,6 +5264,10 @@ function buildOneActionEvent(args: ActionEventArgs): UnsignedActionEvent | strin
|
|
|
5212
5264
|
// depending on which app you asked (FRICTION.md A6).
|
|
5213
5265
|
if (records.order?.includes('ts')) tags.push(['ts', String(args.createdAtMs)])
|
|
5214
5266
|
tags.push(...files)
|
|
5267
|
+
// The person, where the relay indexes them: `value` is not indexed, so
|
|
5268
|
+
// without this `#p` never finds the change and §11.8 makes nobody a member.
|
|
5269
|
+
// After `ts`, where Ship's own builder has put it since FOL-30.
|
|
5270
|
+
if (namesPerson && value !== '') tags.push(['p', value])
|
|
5215
5271
|
// A move also names its new parent where a relay indexes it (SPEC §7.2, FOL-45):
|
|
5216
5272
|
// `value` is not indexed, so without this no read by the new parent finds a
|
|
5217
5273
|
// child moved in. Only for the field the kind declares as `movedBy`, and only
|
|
@@ -5272,15 +5328,46 @@ export const KIND_FOLDER_STATE = 30890
|
|
|
5272
5328
|
/**
|
|
5273
5329
|
* NIP-29 group metadata — the Folder's channel.
|
|
5274
5330
|
*
|
|
5275
|
-
* Named here for two unrelated jobs: it carries the
|
|
5276
|
-
*
|
|
5277
|
-
* like any other (§5.2).
|
|
5331
|
+
* Named here for two unrelated jobs: it carries the Folder's title — its
|
|
5332
|
+
* `name`, and only that (SPEC §3.2) — and its own address is what makes a Peek
|
|
5333
|
+
* topic a file like any other (§5.2).
|
|
5278
5334
|
*/
|
|
5279
5335
|
const KIND_CHANNEL = 39000
|
|
5280
5336
|
|
|
5337
|
+
/** NIP-29 group admins — the relay's list of who holds which role in a channel. */
|
|
5338
|
+
const KIND_CHANNEL_ADMINS = 39001
|
|
5339
|
+
|
|
5340
|
+
/** The roles on a `kind:39001` that may rename a Folder, and so archive it (SPEC §3.2). */
|
|
5341
|
+
const FOLDER_ADMIN_ROLES = new Set(['owner', 'admin'])
|
|
5342
|
+
|
|
5281
5343
|
/** The `name` tag, when there is an event to read it off at all. */
|
|
5282
5344
|
const nameOf = (event: SignedEvent | undefined) => (event ? tagValue(event, 'name') : undefined)
|
|
5283
5345
|
|
|
5346
|
+
/**
|
|
5347
|
+
* The owners and admins a `kind:39001` lists — kept only when the channel's own
|
|
5348
|
+
* signer, the relay, signed it: anybody can publish an event of that shape.
|
|
5349
|
+
*/
|
|
5350
|
+
function folderAdminsOf(admins: SignedEvent | undefined, channel: SignedEvent | undefined): string[] {
|
|
5351
|
+
if (!admins || !channel || admins.pubkey !== channel.pubkey) return []
|
|
5352
|
+
return [
|
|
5353
|
+
...new Set(
|
|
5354
|
+
admins.tags
|
|
5355
|
+
.filter((tag) => tag[0] === 'p' && tag[1] && tag.slice(2).some((role) => FOLDER_ADMIN_ROLES.has(role)))
|
|
5356
|
+
.map((tag) => tag[1]),
|
|
5357
|
+
),
|
|
5358
|
+
]
|
|
5359
|
+
}
|
|
5360
|
+
|
|
5361
|
+
/**
|
|
5362
|
+
* A Folder's own archive (SPEC §3.2): the `archived` changes on its channel's
|
|
5363
|
+
* address, counting only one carrying the Folder's own `h` whose author the
|
|
5364
|
+
* relay lists as its owner or admin. From anybody else the relay accepts the
|
|
5365
|
+
* change, and it means nothing.
|
|
5366
|
+
*/
|
|
5367
|
+
function folderArchiveOf(changes: SignedEvent[], folder: Pick<FolderSummary, 'id' | 'channel' | 'admins'>): Archive | undefined {
|
|
5368
|
+
return folder.channel ? archiveOf(changes, folder.channel, ARCHIVE_RULE, new Set(folder.admins ?? [])) : undefined
|
|
5369
|
+
}
|
|
5370
|
+
|
|
5284
5371
|
/** One folder, enough to draw a sidebar row. */
|
|
5285
5372
|
export interface FolderSummary {
|
|
5286
5373
|
/**
|
|
@@ -5289,17 +5376,33 @@ export interface FolderSummary {
|
|
|
5289
5376
|
* measured across all of production's channels).
|
|
5290
5377
|
*/
|
|
5291
5378
|
id: string
|
|
5379
|
+
/**
|
|
5380
|
+
* The title: its `kind:39000`'s `name`, and only that (SPEC §3.2). A `name`
|
|
5381
|
+
* an older `kind:1852` left on the state is never read — any member may send
|
|
5382
|
+
* one, and only owners and admins may rename the channel.
|
|
5383
|
+
*/
|
|
5292
5384
|
name?: string
|
|
5293
5385
|
/** True once the relay maintains state for it, rather than it being a bare channel. */
|
|
5294
5386
|
hasState: boolean
|
|
5387
|
+
/**
|
|
5388
|
+
* Present when the Folder's relay-signed `kind:39000` carries `["private"]`
|
|
5389
|
+
* (NIP-29). What `planMoveFile` reads as `FolderRef.private`.
|
|
5390
|
+
*/
|
|
5391
|
+
private?: true
|
|
5392
|
+
/**
|
|
5393
|
+
* Who may rename and archive it: the owners and admins on its relay-signed
|
|
5394
|
+
* `kind:39001`. Offer Archive only to them — a reader ignores an archive from
|
|
5395
|
+
* anybody else (§3.2). Absent when the relay returned no admin list.
|
|
5396
|
+
*/
|
|
5397
|
+
admins?: string[]
|
|
5295
5398
|
/**
|
|
5296
5399
|
* The folders whose state lists this one as a file — present only when there
|
|
5297
5400
|
* are any.
|
|
5298
5401
|
*
|
|
5299
5402
|
* A channel is addressable (§5.2), so a folder can be placed inside another
|
|
5300
5403
|
* 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
|
|
5404
|
+
* listed by its Folder's state. A sidebar that drew every channel as a top-level
|
|
5405
|
+
* folder would show the Folder and, beside it, every topic in it. This is what
|
|
5303
5406
|
* lets a consumer tell the two apart without reading any folder's contents:
|
|
5304
5407
|
* `listFolders` already holds every state, so the answer is free.
|
|
5305
5408
|
*/
|
|
@@ -5311,7 +5414,7 @@ export interface FolderSummary {
|
|
|
5311
5414
|
* `listedIn` in the other direction, and free for the same reason: the
|
|
5312
5415
|
* states are already in hand. It is the unresolved list — a row that names
|
|
5313
5416
|
* 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
|
|
5417
|
+
* draws one app's own records under a folder (Ship's projects under a Folder,
|
|
5315
5418
|
* FOL-5) intersects it with the records it holds, and a consumer that draws
|
|
5316
5419
|
* another app's files resolves them with {@link resolveFolderContents}.
|
|
5317
5420
|
*/
|
|
@@ -5349,7 +5452,7 @@ export interface FolderSummary {
|
|
|
5349
5452
|
* never gets; and a folder another one lists (`listedIn`) is a row inside
|
|
5350
5453
|
* that one, not a section beside it.
|
|
5351
5454
|
*
|
|
5352
|
-
* Not a list of ids: a new
|
|
5455
|
+
* Not a list of ids: a new Folder is a folder somebody creates, not a code
|
|
5353
5456
|
* change. Moved here from Peek and Ship, which each held the same line.
|
|
5354
5457
|
*
|
|
5355
5458
|
* An archived Folder is not navigated by (FOL-46), and a listing that has not
|
|
@@ -5394,8 +5497,8 @@ export interface FolderContents extends FolderSummary {
|
|
|
5394
5497
|
* Every folder this identity can see, for a sidebar.
|
|
5395
5498
|
*
|
|
5396
5499
|
* 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
|
-
*
|
|
5500
|
+
* channels that have none yet. A channel with state appears once, titled by its
|
|
5501
|
+
* `kind:39000` (SPEC §3.2), with the owners and admins its `kind:39001` lists.
|
|
5399
5502
|
*
|
|
5400
5503
|
* **A direct route, deliberately.** §4.2's post-mortem on REW-11 is that
|
|
5401
5504
|
* discovering children only through their parent loses them when the parent
|
|
@@ -5406,27 +5509,36 @@ export async function listFolders(query: QueryFn): Promise<FolderSummary[]> {
|
|
|
5406
5509
|
const events = await query([
|
|
5407
5510
|
{ kinds: [KIND_FOLDER_STATE], limit: 500 },
|
|
5408
5511
|
{ kinds: [KIND_CHANNEL], limit: 500 },
|
|
5512
|
+
{ kinds: [KIND_CHANNEL_ADMINS], limit: 500 },
|
|
5409
5513
|
])
|
|
5410
5514
|
const byId = new Map<string, FolderSummary>()
|
|
5515
|
+
const channelOf = new Map<string, SignedEvent>()
|
|
5516
|
+
const adminsOf = new Map<string, SignedEvent>()
|
|
5411
5517
|
for (const event of events) {
|
|
5412
5518
|
const id = tagValue(event, 'd')
|
|
5413
5519
|
if (!id) continue
|
|
5520
|
+
if (event.kind === KIND_CHANNEL) channelOf.set(id, event)
|
|
5521
|
+
if (event.kind === KIND_CHANNEL_ADMINS) adminsOf.set(id, event)
|
|
5522
|
+
if (event.kind !== KIND_FOLDER_STATE && event.kind !== KIND_CHANNEL) continue
|
|
5414
5523
|
const state = event.kind === KIND_FOLDER_STATE
|
|
5415
5524
|
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]) : []
|
|
5525
|
+
const addresses = state ? event.tags.filter((tag) => tag[0] === 'a' && tag[1]).map((tag) => tag[1]) : (existing?.addresses ?? [])
|
|
5419
5526
|
byId.set(id, {
|
|
5420
5527
|
id,
|
|
5421
|
-
name: tagValue(event, 'name') ?? existing?.name,
|
|
5422
5528
|
hasState: state || (existing?.hasState ?? false),
|
|
5423
5529
|
...(addresses.length ? { addresses } : {}),
|
|
5424
5530
|
})
|
|
5425
5531
|
}
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
const
|
|
5429
|
-
if (
|
|
5532
|
+
// The title, privacy and admins are the channel's (§3.2), whichever order the events arrived.
|
|
5533
|
+
for (const [id, folder] of byId) {
|
|
5534
|
+
const channel = channelOf.get(id)
|
|
5535
|
+
if (!channel) continue
|
|
5536
|
+
const name = nameOf(channel)
|
|
5537
|
+
if (name !== undefined) folder.name = name
|
|
5538
|
+
if (channel.tags.some((tag) => tag[0] === 'private')) folder.private = true
|
|
5539
|
+
const admins = folderAdminsOf(adminsOf.get(id), channel)
|
|
5540
|
+
if (admins.length) folder.admins = admins
|
|
5541
|
+
folder.channel = pointerToAddress({ kind: KIND_CHANNEL, pubkey: channel.pubkey, identifier: id, relays: [] })
|
|
5430
5542
|
}
|
|
5431
5543
|
/*
|
|
5432
5544
|
A folder listed in another folder's state is a file there. Read off the
|
|
@@ -5463,13 +5575,13 @@ export async function listFolders(query: QueryFn): Promise<FolderSummary[]> {
|
|
|
5463
5575
|
*
|
|
5464
5576
|
* A Folder is archived by a change naming its channel's address, the way any
|
|
5465
5577
|
* 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
|
|
5578
|
+
* with its record, so an archived project's channel stops lighting its Folder's
|
|
5467
5579
|
* dot the way the project stopped being listed — only when every record naming
|
|
5468
5580
|
* the channel is archived, since two projects may share one. Its own archive
|
|
5469
5581
|
* wins when it has one.
|
|
5470
5582
|
*
|
|
5471
5583
|
* A refused read throws before this, like the reads beside it: a listing that
|
|
5472
|
-
* silently reported every Folder live would put archived
|
|
5584
|
+
* silently reported every Folder live would put archived Folders back in
|
|
5473
5585
|
* everyone's sidebar.
|
|
5474
5586
|
*/
|
|
5475
5587
|
function markArchivedFolders(
|
|
@@ -5478,7 +5590,7 @@ function markArchivedFolders(
|
|
|
5478
5590
|
changes: SignedEvent[],
|
|
5479
5591
|
): void {
|
|
5480
5592
|
for (const folder of byId.values()) {
|
|
5481
|
-
const own =
|
|
5593
|
+
const own = folderArchiveOf(changes, folder)
|
|
5482
5594
|
if (own) {
|
|
5483
5595
|
folder.archived = own
|
|
5484
5596
|
continue
|
|
@@ -5651,13 +5763,13 @@ async function countLiveChildren(
|
|
|
5651
5763
|
* names the channel its conversation lives in with {@link folderOf}'s tags. No
|
|
5652
5764
|
* state lists that channel, so without this `listFolders` reports it placed
|
|
5653
5765
|
* nowhere, and a consumer folding an unread verdict into the containers of a
|
|
5654
|
-
* channel (Peek's
|
|
5766
|
+
* channel (Peek's Folder dot) has nowhere to fold it: correct, and drawn
|
|
5655
5767
|
* nowhere. Measured on production 2026-09-22: of the 43 records the six
|
|
5656
5768
|
* states list, 23 name a channel other than the state's own and no state lists
|
|
5657
5769
|
* any of them. This places 21 channels and moves no top-level Folder.
|
|
5658
5770
|
*
|
|
5659
5771
|
* Derived rather than published, so it cannot drift: a `kind:1852` adding each
|
|
5660
|
-
* channel to its
|
|
5772
|
+
* channel to its Folder would have to be repeated by every app that places a
|
|
5661
5773
|
* record, and would stay wrong the first time one did not.
|
|
5662
5774
|
*
|
|
5663
5775
|
* Both of `folderOf`'s spellings, because production has both — about half of
|
|
@@ -5682,7 +5794,7 @@ async function countLiveChildren(
|
|
|
5682
5794
|
* production that was the bug it was meant to prevent: Peek reads the listing
|
|
5683
5795
|
* once per page load, the load is when the relay's budget is most contested,
|
|
5684
5796
|
* and one refused read on 2026-09-22 left a project's channel unplaced for the
|
|
5685
|
-
* whole session — the
|
|
5797
|
+
* whole session — the Folder's dot dark, and nothing anywhere saying why. A
|
|
5686
5798
|
* listing missing placements looks exactly like a correct one, so only the
|
|
5687
5799
|
* caller can recover, and only if it is told. Keeping the last good listing
|
|
5688
5800
|
* and retrying is the caller's to do.
|
|
@@ -5762,7 +5874,7 @@ async function placeRecordChannels(
|
|
|
5762
5874
|
const channel = root && folderOf(root)
|
|
5763
5875
|
if (!channel || byId.get(channel)?.hasState) continue
|
|
5764
5876
|
// A file published into the Folder that lists it names that Folder, and
|
|
5765
|
-
// does not own it: a topic's `h` is its
|
|
5877
|
+
// does not own it: a topic's `h` is its Folder's.
|
|
5766
5878
|
if (!containers.includes(channel)) recordsOf.set(channel, [...(recordsOf.get(channel) ?? []), key])
|
|
5767
5879
|
for (const container of containers) {
|
|
5768
5880
|
if (container === channel) continue
|
|
@@ -5838,17 +5950,24 @@ export async function resolveFolderContents(
|
|
|
5838
5950
|
const identity = await query([
|
|
5839
5951
|
{ kinds: [KIND_FOLDER_STATE], '#d': [folder], limit: 1 },
|
|
5840
5952
|
{ kinds: [KIND_CHANNEL], '#d': [folder], limit: 1 },
|
|
5953
|
+
{ kinds: [KIND_CHANNEL_ADMINS], '#d': [folder], limit: 1 },
|
|
5841
5954
|
])
|
|
5842
5955
|
const state = identity.find((e) => e.kind === KIND_FOLDER_STATE && tagValue(e, 'd') === folder)
|
|
5843
5956
|
const channel = identity.find((e) => e.kind === KIND_CHANNEL && tagValue(e, 'd') === folder)
|
|
5957
|
+
const admins = folderAdminsOf(
|
|
5958
|
+
identity.find((e) => e.kind === KIND_CHANNEL_ADMINS && tagValue(e, 'd') === folder),
|
|
5959
|
+
channel,
|
|
5960
|
+
)
|
|
5844
5961
|
const channelAddress = channel
|
|
5845
5962
|
? pointerToAddress({ kind: KIND_CHANNEL, pubkey: channel.pubkey, identifier: folder, relays: [] })
|
|
5846
5963
|
: undefined
|
|
5847
5964
|
|
|
5848
5965
|
const summary: FolderSummary & { address?: string } = {
|
|
5849
5966
|
id: folder,
|
|
5850
|
-
name: nameOf(
|
|
5967
|
+
name: nameOf(channel),
|
|
5851
5968
|
hasState: !!state,
|
|
5969
|
+
...(channel?.tags.some((tag) => tag[0] === 'private') ? { private: true as const } : {}),
|
|
5970
|
+
...(admins.length ? { admins } : {}),
|
|
5852
5971
|
...(channelAddress ? { channel: channelAddress } : {}),
|
|
5853
5972
|
...(state
|
|
5854
5973
|
? { address: pointerToAddress({ kind: state.kind, pubkey: state.pubkey, identifier: folder, relays: [] }) }
|
|
@@ -5867,9 +5986,7 @@ export async function resolveFolderContents(
|
|
|
5867
5986
|
if (addresses.length === 0) {
|
|
5868
5987
|
// Nothing listed, so no change query to ride on: the Folder's own archive
|
|
5869
5988
|
// is one small read of its own.
|
|
5870
|
-
const archived = channelAddress
|
|
5871
|
-
? archiveOf(await readArchiveChanges([channelAddress], query), channelAddress, ARCHIVE_RULE)
|
|
5872
|
-
: undefined
|
|
5989
|
+
const archived = channelAddress ? folderArchiveOf(await readArchiveChanges([channelAddress], query), summary) : undefined
|
|
5873
5990
|
return { ...summary, ...(archived ? { archived } : {}), files: [], source: state ? 'state' : 'channel' }
|
|
5874
5991
|
}
|
|
5875
5992
|
|
|
@@ -5919,6 +6036,7 @@ export async function resolveFolderContents(
|
|
|
5919
6036
|
...[...manifests.values()].flatMap((r) => (r.manifest.records ? [r.manifest.records.changeKind] : [])),
|
|
5920
6037
|
]),
|
|
5921
6038
|
]
|
|
6039
|
+
const nestedFolderIds = pointers.filter(({ pointer }) => pointer.kind === KIND_CHANNEL).map(({ pointer }) => pointer.identifier)
|
|
5922
6040
|
const events = await query([
|
|
5923
6041
|
...[...groups.values()].map(({ pointer, addresses: group }) => ({
|
|
5924
6042
|
kinds: [pointer.kind],
|
|
@@ -5932,8 +6050,10 @@ export async function resolveFolderContents(
|
|
|
5932
6050
|
// changes for every file together, and one Folder has already had 688.
|
|
5933
6051
|
// Same request.
|
|
5934
6052
|
...archiveFilters(channelAddress ? [...addresses, channelAddress] : addresses),
|
|
6053
|
+
// A Folder listed here counts its archive only from its own admins (§3.2). Same request.
|
|
6054
|
+
...(nestedFolderIds.length ? [{ kinds: [KIND_CHANNEL_ADMINS], '#d': nestedFolderIds, limit: nestedFolderIds.length }] : []),
|
|
5935
6055
|
])
|
|
5936
|
-
const ownArchive =
|
|
6056
|
+
const ownArchive = folderArchiveOf(events, summary)
|
|
5937
6057
|
if (ownArchive) summary.archived = ownArchive
|
|
5938
6058
|
|
|
5939
6059
|
// 4. Build each file, in the order the folder listed them. Archived files are
|
|
@@ -5960,7 +6080,16 @@ export async function resolveFolderContents(
|
|
|
5960
6080
|
events.filter((e) => e.kind === records.changeKind && hasTagValue(e, records.targetTag, address)),
|
|
5961
6081
|
records,
|
|
5962
6082
|
)
|
|
5963
|
-
const
|
|
6083
|
+
const nestedAdmins =
|
|
6084
|
+
pointer.kind === KIND_CHANNEL
|
|
6085
|
+
? new Set(
|
|
6086
|
+
folderAdminsOf(
|
|
6087
|
+
events.find((e) => e.kind === KIND_CHANNEL_ADMINS && tagValue(e, 'd') === pointer.identifier),
|
|
6088
|
+
root,
|
|
6089
|
+
),
|
|
6090
|
+
)
|
|
6091
|
+
: undefined
|
|
6092
|
+
const archive = archiveOf(events, address, archiveRuleOf(resolved.manifest), nestedAdmins)
|
|
5964
6093
|
archiveByAddress.set(address, archive)
|
|
5965
6094
|
const parent = parentRefOf(resolved.manifest, pointer.kind, root, folded)
|
|
5966
6095
|
parentByAddress.set(address, parent)
|
|
@@ -5981,7 +6110,7 @@ export async function resolveFolderContents(
|
|
|
5981
6110
|
the file is here; if the fold has moved on, somebody has since placed it
|
|
5982
6111
|
somewhere else and this folder is holding a statement that has been
|
|
5983
6112
|
superseded, which an append-only stream cannot retract. Ship linking a
|
|
5984
|
-
project to a second
|
|
6113
|
+
project to a second Folder is the case: the first Folder keeps the
|
|
5985
6114
|
old statement for ever, and without this check would list the project
|
|
5986
6115
|
for ever.
|
|
5987
6116
|
|
|
@@ -6081,17 +6210,17 @@ export async function resolveFolderContents(
|
|
|
6081
6210
|
*
|
|
6082
6211
|
* A folder lists the files whose `h` it is **and** the files placed in it.
|
|
6083
6212
|
* An event cannot change its own `h`, so a project filed in one Folder and
|
|
6084
|
-
* later linked to a
|
|
6213
|
+
* later linked to a Folder keeps the `h` it was born with, and the only thing
|
|
6085
6214
|
* that can say "it belongs over there now" is a change event. Ship publishes
|
|
6086
6215
|
* 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
|
|
6216
|
+
* being linked*: a `kind:1851` carried by the Folder's `h`, targeting the
|
|
6217
|
+
* project, whose value is the Folder itself. The second copy is the
|
|
6089
6218
|
* placement, and it is what this reads.
|
|
6090
6219
|
*
|
|
6091
6220
|
* {@link resolveFolderProject} has read the same statement since PEEK-24 to
|
|
6092
6221
|
* 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
|
|
6222
|
+
* half of it, and it is the rule the tidy-up rests on: five Folders,
|
|
6223
|
+
* fourteen projects linked into them and none re-created, so a Folder
|
|
6095
6224
|
* whose `h` is on nothing lists its projects anyway.
|
|
6096
6225
|
*
|
|
6097
6226
|
* App-neutral by the same discipline as everything else here. The change
|