@estiva-app/interop 0.37.0 → 0.38.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 +46 -0
- package/README.md +3 -1
- package/dist/folders.d.ts +12 -4
- package/dist/folders.d.ts.map +1 -1
- package/dist/folders.js +12 -5
- package/dist/folders.js.map +1 -1
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +188 -50
- package/dist/projection.js.map +1 -1
- package/package.json +1 -1
- package/src/folders.ts +13 -6
- package/src/projection.ts +215 -56
package/src/projection.ts
CHANGED
|
@@ -2068,6 +2068,21 @@ function foldChanges(changes: SignedEvent[], rule: RecordsRule) {
|
|
|
2068
2068
|
return fields
|
|
2069
2069
|
}
|
|
2070
2070
|
|
|
2071
|
+
/**
|
|
2072
|
+
* One object's fold out of a pooled answer: its app's change kind, naming it as
|
|
2073
|
+
* the **first** target tag, as `archiveOf` reads it. Empty when the app declares
|
|
2074
|
+
* no change events — `foldRuleOf`'s substitute is never asked for.
|
|
2075
|
+
*/
|
|
2076
|
+
function foldOf(events: SignedEvent[], address: string, manifest: Manifest) {
|
|
2077
|
+
const records = foldRuleOf(manifest)
|
|
2078
|
+
return foldChanges(
|
|
2079
|
+
manifest.records
|
|
2080
|
+
? events.filter((e) => e.kind === records.changeKind && tagValue(e, records.targetTag) === address)
|
|
2081
|
+
: [],
|
|
2082
|
+
records,
|
|
2083
|
+
)
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2071
2086
|
/**
|
|
2072
2087
|
* How an `archived` change is read when the file's kind declares no rule of its
|
|
2073
2088
|
* own — a Folder, whose `kind:39000` no app owns, and a bare file. SPEC §7.1's
|
|
@@ -3018,9 +3033,11 @@ export async function resolveForeignObject(
|
|
|
3018
3033
|
const plan = planObject(naddr, pointer, resolved, depth)
|
|
3019
3034
|
if (!plan) return null
|
|
3020
3035
|
|
|
3021
|
-
const
|
|
3036
|
+
const answered = await query(plan.filters)
|
|
3037
|
+
const followUp = childChangeFilters(plan, answered)
|
|
3038
|
+
const assembled = assembleObject(plan, answered, followUp.length ? await queryChunked(followUp, query) : [])
|
|
3022
3039
|
if (assembled.object.unreachable) return assembled.object
|
|
3023
|
-
if (options.archivedWith) await markArchivedParents([assembled.object], query)
|
|
3040
|
+
if (options.archivedWith) await markArchivedParents([{ object: assembled.object, manifest: resolved.manifest }], query)
|
|
3024
3041
|
return withPeople(assembled, await (lookupPeople ?? peopleViaRelay(query))(peopleOf(assembled)))
|
|
3025
3042
|
}
|
|
3026
3043
|
|
|
@@ -3107,14 +3124,27 @@ export async function resolveForeignObjects(
|
|
|
3107
3124
|
planned.add(plan.address)
|
|
3108
3125
|
filters.push(...plan.filters)
|
|
3109
3126
|
}
|
|
3110
|
-
const
|
|
3111
|
-
|
|
3112
|
-
|
|
3127
|
+
const events = await queryChunked(filters, query)
|
|
3128
|
+
|
|
3129
|
+
// Every card's children's changes in one more read for the whole set, not
|
|
3130
|
+
// one per card (MAN-7) — and none at all when no card has a fold to read.
|
|
3131
|
+
const followUp: Record<string, unknown>[] = []
|
|
3132
|
+
const followed = new Set<string>()
|
|
3133
|
+
for (const { plan } of plans) {
|
|
3134
|
+
if (followed.has(plan.address)) continue
|
|
3135
|
+
followed.add(plan.address)
|
|
3136
|
+
followUp.push(...childChangeFilters(plan, events))
|
|
3113
3137
|
}
|
|
3114
|
-
const
|
|
3138
|
+
const childChanges = followUp.length ? await queryChunked(followUp, query) : []
|
|
3115
3139
|
|
|
3116
|
-
const assembled = plans.map(({ reference, plan }) => ({
|
|
3117
|
-
|
|
3140
|
+
const assembled = plans.map(({ reference, plan }) => ({
|
|
3141
|
+
reference,
|
|
3142
|
+
plan,
|
|
3143
|
+
built: assembleObject(plan, events, childChanges),
|
|
3144
|
+
}))
|
|
3145
|
+
if (options.archivedWith) {
|
|
3146
|
+
await markArchivedParents(assembled.map(({ plan, built }) => ({ object: built.object, manifest: plan.resolved.manifest })), query)
|
|
3147
|
+
}
|
|
3118
3148
|
const wanted = [...new Set(assembled.flatMap(({ built }) => peopleOf(built)))]
|
|
3119
3149
|
const reachable = assembled.some(({ built }) => !built.object.unreachable)
|
|
3120
3150
|
const people = reachable ? await (lookupPeople ?? peopleViaRelay(query))(wanted) : {}
|
|
@@ -3158,20 +3188,37 @@ export interface ArchiveReadOptions {
|
|
|
3158
3188
|
* container, and a deeper walk is a round trip per level. A Folder listing
|
|
3159
3189
|
* walks the whole chain it holds ({@link resolveFolderContents}).
|
|
3160
3190
|
*
|
|
3161
|
-
* The parent is folded by
|
|
3162
|
-
* parent
|
|
3191
|
+
* The parent is folded by the child's app's rule when that app also draws the
|
|
3192
|
+
* parent's kind — a project is Ship's as its issue is — and by SPEC's rule
|
|
3193
|
+
* otherwise, since the parent's own manifest is not in hand ({@link relatedRuleOf}).
|
|
3163
3194
|
*/
|
|
3164
|
-
async function markArchivedParents(
|
|
3165
|
-
|
|
3195
|
+
async function markArchivedParents(
|
|
3196
|
+
entries: { object: ForeignObject; manifest?: Pick<Manifest, 'records' | 'projections'> }[],
|
|
3197
|
+
query: QueryFn,
|
|
3198
|
+
): Promise<void> {
|
|
3199
|
+
const waiting = entries.filter(
|
|
3200
|
+
({ object: o }) => !o.unreachable && !o.archived && o.parentRef && addressPointerOf(o.parentRef),
|
|
3201
|
+
)
|
|
3166
3202
|
if (waiting.length === 0) return
|
|
3167
|
-
const
|
|
3168
|
-
const
|
|
3169
|
-
|
|
3170
|
-
|
|
3203
|
+
const rules = waiting.map(({ object, manifest }) => relatedRuleOf(manifest, object.parentRef!))
|
|
3204
|
+
const parents = [...new Set(waiting.map(({ object }) => object.parentRef!))]
|
|
3205
|
+
const changes = await readArchiveChanges(parents, query, rules)
|
|
3206
|
+
for (const [index, { object }] of waiting.entries()) {
|
|
3207
|
+
const archive = archiveOf(changes, object.parentRef!, rules[index]!)
|
|
3171
3208
|
if (archive) object.archived = { ...archive, with: object.parentRef! }
|
|
3172
3209
|
}
|
|
3173
3210
|
}
|
|
3174
3211
|
|
|
3212
|
+
/**
|
|
3213
|
+
* The rule another file's archive is read by, from an app known to hold it:
|
|
3214
|
+
* that app's own, when it draws the file's kind — an issue's project is Ship's,
|
|
3215
|
+
* a hive's inspection the hive log's — and SPEC's otherwise.
|
|
3216
|
+
*/
|
|
3217
|
+
function relatedRuleOf(manifest: Pick<Manifest, 'records' | 'projections'> | undefined, address: string): RecordsRule {
|
|
3218
|
+
const kind = addressPointerOf(address)?.kind
|
|
3219
|
+
return manifest && kind !== undefined && manifest.projections?.[String(kind)] ? archiveRuleOf(manifest) : ARCHIVE_RULE
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3175
3222
|
/**
|
|
3176
3223
|
* Addresses per filter when reading archive changes. A filter's `limit` caps
|
|
3177
3224
|
* every change naming its addresses — titles, statuses, moves — not only the
|
|
@@ -3180,24 +3227,42 @@ async function markArchivedParents(objects: ForeignObject[], query: QueryFn): Pr
|
|
|
3180
3227
|
*/
|
|
3181
3228
|
const ARCHIVE_READ_GROUP = 25
|
|
3182
3229
|
|
|
3183
|
-
/**
|
|
3184
|
-
|
|
3230
|
+
/**
|
|
3231
|
+
* The filters asking for every change naming these addresses, once per distinct
|
|
3232
|
+
* change shape among `rules` — SPEC's alone unless an app writes its own.
|
|
3233
|
+
*/
|
|
3234
|
+
function archiveFilters(
|
|
3235
|
+
addresses: readonly string[],
|
|
3236
|
+
rules: readonly RecordsRule[] = [ARCHIVE_RULE],
|
|
3237
|
+
groupSize = ARCHIVE_READ_GROUP,
|
|
3238
|
+
): Record<string, unknown>[] {
|
|
3239
|
+
const shapes = new Map(rules.map((rule) => [`${rule.changeKind}:${rule.targetTag}`, rule]))
|
|
3185
3240
|
const filters: Record<string, unknown>[] = []
|
|
3186
|
-
for (
|
|
3187
|
-
|
|
3188
|
-
|
|
3241
|
+
for (const rule of shapes.values()) {
|
|
3242
|
+
for (let start = 0; start < addresses.length; start += groupSize) {
|
|
3243
|
+
const group = addresses.slice(start, start + groupSize)
|
|
3244
|
+
filters.push({ kinds: [rule.changeKind], [`#${rule.targetTag}`]: group, limit: RELAY_PAGE_CEILING })
|
|
3245
|
+
}
|
|
3189
3246
|
}
|
|
3190
3247
|
return filters
|
|
3191
3248
|
}
|
|
3192
3249
|
|
|
3193
|
-
/** Every
|
|
3194
|
-
async function readArchiveChanges(
|
|
3195
|
-
|
|
3196
|
-
|
|
3250
|
+
/** Every change naming these addresses, in each of `rules`' shapes, in as few requests as the relay allows. */
|
|
3251
|
+
async function readArchiveChanges(
|
|
3252
|
+
addresses: readonly string[],
|
|
3253
|
+
query: QueryFn,
|
|
3254
|
+
rules?: readonly RecordsRule[],
|
|
3255
|
+
): Promise<SignedEvent[]> {
|
|
3256
|
+
return queryChunked(archiveFilters(addresses, rules), query)
|
|
3257
|
+
}
|
|
3258
|
+
|
|
3259
|
+
/** `filters` in as few POSTs as the relay takes, answers pooled. */
|
|
3260
|
+
async function queryChunked(filters: Record<string, unknown>[], query: QueryFn): Promise<SignedEvent[]> {
|
|
3261
|
+
const chunks: Record<string, unknown>[][] = []
|
|
3197
3262
|
for (let start = 0; start < filters.length; start += MAX_FILTERS_PER_QUERY) {
|
|
3198
|
-
|
|
3263
|
+
chunks.push(filters.slice(start, start + MAX_FILTERS_PER_QUERY))
|
|
3199
3264
|
}
|
|
3200
|
-
return
|
|
3265
|
+
return (await Promise.all(chunks.map((chunk) => query(chunk)))).flat()
|
|
3201
3266
|
}
|
|
3202
3267
|
|
|
3203
3268
|
/** An `naddr` or a `<kind>:<pubkey>:<d>`, or null for anything else. */
|
|
@@ -3303,8 +3368,8 @@ interface AssembledObject {
|
|
|
3303
3368
|
* filters match — a comment naming two files in the set, a `kind:9` that is a
|
|
3304
3369
|
* Topic's child and its comment — would otherwise be drawn twice.
|
|
3305
3370
|
*/
|
|
3306
|
-
function assembleObject(plan: ObjectPlan, answered: SignedEvent[]): AssembledObject {
|
|
3307
|
-
const { naddr, pointer, address, resolved, projection,
|
|
3371
|
+
function assembleObject(plan: ObjectPlan, answered: SignedEvent[], childChanges: SignedEvent[] = []): AssembledObject {
|
|
3372
|
+
const { naddr, pointer, address, resolved, projection, commentKinds, childFilter, openUrl } = plan
|
|
3308
3373
|
const { manifest, viaRecommendation } = resolved
|
|
3309
3374
|
const seen = new Set<string>()
|
|
3310
3375
|
const events = answered.filter((e) => !seen.has(e.id) && !!seen.add(e.id))
|
|
@@ -3339,12 +3404,7 @@ function assembleObject(plan: ObjectPlan, answered: SignedEvent[]): AssembledObj
|
|
|
3339
3404
|
}
|
|
3340
3405
|
}
|
|
3341
3406
|
|
|
3342
|
-
const folded =
|
|
3343
|
-
manifest.records
|
|
3344
|
-
? events.filter((e) => e.kind === records.changeKind && tagValue(e, records.targetTag) === address)
|
|
3345
|
-
: [],
|
|
3346
|
-
records,
|
|
3347
|
-
)
|
|
3407
|
+
const folded = foldOf(events, address, manifest)
|
|
3348
3408
|
|
|
3349
3409
|
/*
|
|
3350
3410
|
Matched on the comment filter's own criteria — the kind **and** the `a` tag.
|
|
@@ -3398,6 +3458,7 @@ function assembleObject(plan: ObjectPlan, answered: SignedEvent[]): AssembledObj
|
|
|
3398
3458
|
manifest,
|
|
3399
3459
|
webTemplate: resolved.webTemplate,
|
|
3400
3460
|
viaRecommendation,
|
|
3461
|
+
childChanges,
|
|
3401
3462
|
})
|
|
3402
3463
|
|
|
3403
3464
|
return { object, ...(children ? { children } : {}) }
|
|
@@ -3562,7 +3623,7 @@ function childFilterFor(args: {
|
|
|
3562
3623
|
manifest: Manifest
|
|
3563
3624
|
pointer: AddressPointer
|
|
3564
3625
|
depth: number
|
|
3565
|
-
}): { filter: Record<string, unknown>; kind: number; via: string; parent: string } | null | undefined {
|
|
3626
|
+
}): { filter: Record<string, unknown>; kind: number; via: string; parent: string; movedBy?: string } | null | undefined {
|
|
3566
3627
|
const { projection, manifest, pointer, depth } = args
|
|
3567
3628
|
const children = declaredChildSpec(projection)
|
|
3568
3629
|
if (!children) return undefined
|
|
@@ -3583,6 +3644,9 @@ function childFilterFor(args: {
|
|
|
3583
3644
|
kind: children.kind,
|
|
3584
3645
|
via: children.via,
|
|
3585
3646
|
parent,
|
|
3647
|
+
// This list's own, not whichever projection declares one for the kind — and
|
|
3648
|
+
// none on an identifier list, where a move's address never names the parent.
|
|
3649
|
+
...(children.movedBy && children.match !== 'identifier' ? { movedBy: children.movedBy } : {}),
|
|
3586
3650
|
}
|
|
3587
3651
|
}
|
|
3588
3652
|
|
|
@@ -3603,23 +3667,105 @@ function childrenFrom(args: {
|
|
|
3603
3667
|
manifest: Manifest
|
|
3604
3668
|
webTemplate?: string
|
|
3605
3669
|
viaRecommendation: boolean
|
|
3670
|
+
/** What {@link childChangeFilters} asked for; empty when it asked nothing. */
|
|
3671
|
+
childChanges?: SignedEvent[]
|
|
3606
3672
|
}): ForeignObject[] | undefined {
|
|
3607
|
-
const { events, childFilter, manifest, webTemplate, viaRecommendation } = args
|
|
3673
|
+
const { events, childFilter, manifest, webTemplate, viaRecommendation, childChanges = [] } = args
|
|
3608
3674
|
if (childFilter === undefined) return undefined
|
|
3609
3675
|
if (childFilter === null) return []
|
|
3610
3676
|
|
|
3611
3677
|
const childProjection = manifest.projections?.[String(childFilter.kind)]
|
|
3612
3678
|
if (!childProjection) return []
|
|
3613
3679
|
const records = foldRuleOf(manifest)
|
|
3680
|
+
const { movedBy } = childFilter
|
|
3681
|
+
|
|
3682
|
+
return childRootsOf(events, childFilter).flatMap((event) => {
|
|
3683
|
+
const address = childAddressOf(event)
|
|
3684
|
+
/*
|
|
3685
|
+
The child's own fold — MAN-7. Until this, a card's children were built
|
|
3686
|
+
from their roots alone, so a moved issue was drawn under the project it
|
|
3687
|
+
was created in, and its status was whatever the root said at creation.
|
|
3688
|
+
|
|
3689
|
+
Folded as the object itself is (`foldOf`, the first target tag), and
|
|
3690
|
+
dropped for the reasons the Folder listing drops a file:
|
|
3691
|
+
|
|
3692
|
+
- **moved away** — SPEC §7.2: a `#via` read finds the children created
|
|
3693
|
+
here, including the ones moved since, and a consumer MUST drop a child
|
|
3694
|
+
whose folded `movedBy` names another parent. An empty value, or one
|
|
3695
|
+
that names no parent at all, is not this parent either. Only a folded
|
|
3696
|
+
value counts: without one the `via` tag is the parent, and that is what
|
|
3697
|
+
found the child.
|
|
3698
|
+
- **hidden** by the app's own `hiddenWhen`, or **archived** (FOL-46).
|
|
3699
|
+
|
|
3700
|
+
A child moved *in* is not found here and cannot be: its new parent is in
|
|
3701
|
+
a `value`, which no relay indexes. SPEC §7.2 names the Folder listing as
|
|
3702
|
+
the only read that sees one.
|
|
3703
|
+
*/
|
|
3704
|
+
const folded = address ? foldOf(childChanges, address, manifest) : {}
|
|
3705
|
+
if (movedBy && folded[movedBy] && folded[movedBy].value !== childFilter.parent) return []
|
|
3706
|
+
if (records.hiddenWhen && folded[records.hiddenWhen.field]?.value === records.hiddenWhen.equals) return []
|
|
3707
|
+
if (address && manifest.records && archiveOf(childChanges, address, records)) return []
|
|
3708
|
+
return [
|
|
3709
|
+
buildChildObject({ root: event, manifest, projection: childProjection, records, webTemplate, viaRecommendation, folded }),
|
|
3710
|
+
]
|
|
3711
|
+
})
|
|
3712
|
+
}
|
|
3614
3713
|
|
|
3714
|
+
/** The child roots a `list` filter asked for, picked back out of a pooled answer on its own criteria. */
|
|
3715
|
+
function childRootsOf(events: SignedEvent[], childFilter: NonNullable<ReturnType<typeof childFilterFor>>): SignedEvent[] {
|
|
3615
3716
|
return events
|
|
3616
3717
|
.filter((e) => e.kind === childFilter.kind && hasTagValue(e, childFilter.via, childFilter.parent))
|
|
3617
3718
|
.sort(byOrder)
|
|
3618
|
-
.map((event) =>
|
|
3619
|
-
buildChildObject({ root: event, manifest, projection: childProjection, records, webTemplate, viaRecommendation }),
|
|
3620
|
-
)
|
|
3621
3719
|
}
|
|
3622
3720
|
|
|
3721
|
+
/** A child's address, or undefined for a regular event, which has none. */
|
|
3722
|
+
function childAddressOf(event: SignedEvent): string | undefined {
|
|
3723
|
+
const identifier = tagValue(event, 'd')
|
|
3724
|
+
return identifier === undefined
|
|
3725
|
+
? undefined
|
|
3726
|
+
: pointerToAddress({ kind: event.kind, pubkey: event.pubkey, identifier, relays: [] })
|
|
3727
|
+
}
|
|
3728
|
+
|
|
3729
|
+
/**
|
|
3730
|
+
* The second read a card's children need, or none — MAN-7.
|
|
3731
|
+
*
|
|
3732
|
+
* A child's changes name the child's address, which is not known until the
|
|
3733
|
+
* children are back, so this cannot ride in the object's own request the way
|
|
3734
|
+
* the children do (SHI-13). It is asked **only when there is a fold to read**:
|
|
3735
|
+
* the app declares change events (`records`) and the list holds at least one
|
|
3736
|
+
* addressable child. Peek's Topic lists `kind:9` messages, which nothing can
|
|
3737
|
+
* change by address, so a Topic card stays one request; a Ship project card
|
|
3738
|
+
* with issues is two.
|
|
3739
|
+
*
|
|
3740
|
+
* The alternative on the ticket — folding from a cached Folder read — was not
|
|
3741
|
+
* taken: interop's caches are the caller's (`ProjectionCache` holds manifests,
|
|
3742
|
+
* never objects), a card is pasted into Folders other than its own, and a stale
|
|
3743
|
+
* cached fold is the moved-issue bug again with a delay on it.
|
|
3744
|
+
*
|
|
3745
|
+
* Grouped as the archive reads are ({@link archiveFilters}), but smaller: a
|
|
3746
|
+
* filter's `limit` covers every change naming every address in it, and a relay
|
|
3747
|
+
* answers newest first, so a group whose changes overflow the page loses its
|
|
3748
|
+
* *oldest* — and a move made long ago is exactly what must not fall off. Ten
|
|
3749
|
+
* issues to a page of 1,000 is a hundred changes each; a card of 200 is twenty
|
|
3750
|
+
* filters, still one POST.
|
|
3751
|
+
*
|
|
3752
|
+
* Nothing when the root did not come back: the object is unreachable and its
|
|
3753
|
+
* children are never drawn, so their changes would be a request for nothing.
|
|
3754
|
+
*/
|
|
3755
|
+
function childChangeFilters(plan: ObjectPlan, answered: SignedEvent[]): Record<string, unknown>[] {
|
|
3756
|
+
const { childFilter, resolved, pointer } = plan
|
|
3757
|
+
const records = resolved.manifest.records
|
|
3758
|
+
if (!childFilter || !records) return []
|
|
3759
|
+
if (!answered.some((e) => e.kind === pointer.kind && e.pubkey === pointer.pubkey && tagValue(e, 'd') === pointer.identifier)) {
|
|
3760
|
+
return []
|
|
3761
|
+
}
|
|
3762
|
+
const addresses = [...new Set(childRootsOf(answered, childFilter).flatMap((e) => childAddressOf(e) ?? []))]
|
|
3763
|
+
return addresses.length ? archiveFilters(addresses, [records], CHILD_CHANGE_GROUP) : []
|
|
3764
|
+
}
|
|
3765
|
+
|
|
3766
|
+
/** Addresses per filter when reading a card's children's changes — see {@link childChangeFilters}. */
|
|
3767
|
+
const CHILD_CHANGE_GROUP = 10
|
|
3768
|
+
|
|
3623
3769
|
/**
|
|
3624
3770
|
* Build a `ForeignObject` from an event that may have no address of its own.
|
|
3625
3771
|
*
|
|
@@ -3648,8 +3794,13 @@ function buildChildObject(args: {
|
|
|
3648
3794
|
* `openUrl` at all, which is PRO-11's "its web link opens that message".
|
|
3649
3795
|
*/
|
|
3650
3796
|
nevent?: string
|
|
3797
|
+
/**
|
|
3798
|
+
* The child's own fold, when {@link childChangeFilters} read its changes
|
|
3799
|
+
* (MAN-7). Empty for a regular event, which nothing can change by address.
|
|
3800
|
+
*/
|
|
3801
|
+
folded?: Record<string, { value: string; format?: ContentFormat }>
|
|
3651
3802
|
}): ForeignObject {
|
|
3652
|
-
const { root, manifest, projection, webTemplate, viaRecommendation, nevent } = args
|
|
3803
|
+
const { root, manifest, projection, webTemplate, viaRecommendation, nevent, folded = {} } = args
|
|
3653
3804
|
const identifier = tagValue(root, 'd')
|
|
3654
3805
|
const addressable = identifier !== undefined
|
|
3655
3806
|
const pointer: AddressPointer = {
|
|
@@ -3660,7 +3811,7 @@ function buildChildObject(args: {
|
|
|
3660
3811
|
}
|
|
3661
3812
|
const address = addressable ? pointerToAddress(pointer) : undefined
|
|
3662
3813
|
const naddr = addressable ? encodeNaddr(pointer) : undefined
|
|
3663
|
-
const { slots, meta } = resolveSlots(projection, root,
|
|
3814
|
+
const { slots, meta } = resolveSlots(projection, root, folded, manifest)
|
|
3664
3815
|
|
|
3665
3816
|
return {
|
|
3666
3817
|
// A regular event's identity is its id; a replaceable one's is its address,
|
|
@@ -3680,7 +3831,7 @@ function buildChildObject(args: {
|
|
|
3680
3831
|
// way and not the other. A child already knows its parent contextually, but
|
|
3681
3832
|
// an inconsistent shape is what makes a consumer defensive about a value it
|
|
3682
3833
|
// should be able to trust.
|
|
3683
|
-
parentRef: parentRefOf(manifest, root.kind, root),
|
|
3834
|
+
parentRef: parentRefOf(manifest, root.kind, root, folded),
|
|
3684
3835
|
...parentFieldsOf(manifest, root.kind),
|
|
3685
3836
|
folder: tagValue(root, 'h'),
|
|
3686
3837
|
/*
|
|
@@ -5134,14 +5285,16 @@ async function countLiveChildren(
|
|
|
5134
5285
|
}),
|
|
5135
5286
|
)
|
|
5136
5287
|
const filters: Record<string, unknown>[] = []
|
|
5137
|
-
const wanted: { kind: number; via: string; parent: string }[] = []
|
|
5288
|
+
const wanted: { kind: number; via: string; parent: string; rule: RecordsRule }[] = []
|
|
5138
5289
|
for (const { address, pointer } of parents) {
|
|
5139
|
-
const
|
|
5290
|
+
const manifest = manifests.get(manifestKeyOf(pointer))?.manifest
|
|
5291
|
+
const projection = manifest?.projections?.[String(pointer.kind)]
|
|
5140
5292
|
const declared = projection && declaredChildSpec(projection)
|
|
5293
|
+
// A declared child is the parent's app's, and folds by its rule; a sub-topic is a bare file, SPEC's.
|
|
5141
5294
|
const specs = [
|
|
5142
|
-
...(declared ? [{ kind: declared.kind, via: declared.via }] : []),
|
|
5295
|
+
...(declared ? [{ kind: declared.kind, via: declared.via, rule: archiveRuleOf(manifest) }] : []),
|
|
5143
5296
|
// A sub-topic may sit under a file of any kind (SPEC §6.7).
|
|
5144
|
-
...(declared?.kind === KIND_BARE_FILE && declared.via === 'a' ? [] : [{ kind: KIND_BARE_FILE, via: 'a' }]),
|
|
5297
|
+
...(declared?.kind === KIND_BARE_FILE && declared.via === 'a' ? [] : [{ kind: KIND_BARE_FILE, via: 'a', rule: ARCHIVE_RULE }]),
|
|
5145
5298
|
]
|
|
5146
5299
|
for (const spec of specs) {
|
|
5147
5300
|
wanted.push({ ...spec, parent: address })
|
|
@@ -5152,18 +5305,19 @@ async function countLiveChildren(
|
|
|
5152
5305
|
for (let start = 0; start < filters.length; start += MAX_FILTERS_PER_QUERY) {
|
|
5153
5306
|
events.push(...(await query(filters.slice(start, start + MAX_FILTERS_PER_QUERY))))
|
|
5154
5307
|
}
|
|
5155
|
-
const children = new Map<string, number>()
|
|
5308
|
+
const children = new Map<string, { kind: number; rule: RecordsRule }>()
|
|
5156
5309
|
for (const event of events) {
|
|
5157
5310
|
const identifier = tagValue(event, 'd')
|
|
5158
5311
|
if (identifier === undefined) continue
|
|
5159
|
-
|
|
5312
|
+
const match = wanted.find((w) => w.kind === event.kind && hasTagValue(event, w.via, w.parent))
|
|
5313
|
+
if (!match) continue
|
|
5160
5314
|
const child = pointerToAddress({ kind: event.kind, pubkey: event.pubkey, identifier, relays: [] })
|
|
5161
|
-
if (!counted.has(child)) children.set(child, event.kind)
|
|
5315
|
+
if (!counted.has(child)) children.set(child, { kind: event.kind, rule: match.rule })
|
|
5162
5316
|
}
|
|
5163
5317
|
if (children.size === 0) return byKind
|
|
5164
|
-
const changes = await readArchiveChanges([...children.keys()], query)
|
|
5165
|
-
for (const [child, kind] of children) {
|
|
5166
|
-
if (archiveOf(changes, child,
|
|
5318
|
+
const changes = await readArchiveChanges([...children.keys()], query, [...children.values()].map((c) => c.rule))
|
|
5319
|
+
for (const [child, { kind, rule }] of children) {
|
|
5320
|
+
if (archiveOf(changes, child, rule)) continue
|
|
5167
5321
|
byKind.set(kind, (byKind.get(kind) ?? 0) + 1)
|
|
5168
5322
|
}
|
|
5169
5323
|
return byKind
|
|
@@ -5466,6 +5620,8 @@ export async function resolveFolderContents(
|
|
|
5466
5620
|
const listed: { file: ForeignObject; archive?: Archive }[] = []
|
|
5467
5621
|
const archiveByAddress = new Map<string, Archive | undefined>()
|
|
5468
5622
|
const parentByAddress = new Map<string, string | undefined>()
|
|
5623
|
+
// How a parent outside this listing is read: its child's app's rule when that app draws it.
|
|
5624
|
+
const parentRuleOf = new Map<string, RecordsRule>()
|
|
5469
5625
|
for (const { address, pointer } of pointers) {
|
|
5470
5626
|
const resolved = manifests.get(manifestKeyOf(pointer))
|
|
5471
5627
|
// No app claims this kind, so there is no projection to draw it with.
|
|
@@ -5485,7 +5641,9 @@ export async function resolveFolderContents(
|
|
|
5485
5641
|
)
|
|
5486
5642
|
const archive = archiveOf(events, address, archiveRuleOf(resolved.manifest))
|
|
5487
5643
|
archiveByAddress.set(address, archive)
|
|
5488
|
-
|
|
5644
|
+
const parent = parentRefOf(resolved.manifest, pointer.kind, root, folded)
|
|
5645
|
+
parentByAddress.set(address, parent)
|
|
5646
|
+
if (parent) parentRuleOf.set(parent, relatedRuleOf(resolved.manifest, parent))
|
|
5489
5647
|
// An app hiding a record from its own lists is saying it is not part of the
|
|
5490
5648
|
// folder any more. `hiddenWhen` is the app's own declaration of that — the
|
|
5491
5649
|
// archive above is the same statement for a kind whose app declared none.
|
|
@@ -5555,8 +5713,9 @@ export async function resolveFolderContents(
|
|
|
5555
5713
|
),
|
|
5556
5714
|
]
|
|
5557
5715
|
if (outside.length) {
|
|
5558
|
-
const
|
|
5559
|
-
|
|
5716
|
+
const ruleFor = (parent: string) => parentRuleOf.get(parent) ?? ARCHIVE_RULE
|
|
5717
|
+
const changes = await readArchiveChanges(outside, query, outside.map(ruleFor))
|
|
5718
|
+
for (const parent of outside) archiveByAddress.set(parent, archiveOf(changes, parent, ruleFor(parent)))
|
|
5560
5719
|
}
|
|
5561
5720
|
const files: ForeignObject[] = []
|
|
5562
5721
|
for (const { file, archive } of listed) {
|