@estiva-app/interop 0.64.0 → 0.65.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 +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/projection.d.ts +13 -0
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +113 -25
- package/dist/projection.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/projection.ts +113 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.0",
|
|
4
4
|
"description": "Render and act on another app's objects from its published NIP-89 manifest. The owner defines the projection; the consumer decides how it looks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
package/src/projection.ts
CHANGED
|
@@ -1438,7 +1438,7 @@ const BARE_FILE_MANIFEST: Manifest = {
|
|
|
1438
1438
|
/*
|
|
1439
1439
|
No `body`: a topic is a conversation and has no text (SPEC §6.7,
|
|
1440
1440
|
2026-10-19), so nothing draws one and no document app lists it.
|
|
1441
|
-
why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-
|
|
1441
|
+
why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-card-changes-what-a-files-app-shares.md
|
|
1442
1442
|
*/
|
|
1443
1443
|
// A bare file may hold bare files — a sub-topic under a topic. Children
|
|
1444
1444
|
// of *other* kinds are found the other way round, by their own `a`
|
|
@@ -2519,10 +2519,16 @@ function archiveOf(
|
|
|
2519
2519
|
/**
|
|
2520
2520
|
* The first archived ancestor of `address`, walking `parentOf`, with its archive.
|
|
2521
2521
|
*
|
|
2522
|
+
* SPEC §6.5's rule for a file archived with something above it, for an app
|
|
2523
|
+
* that folds its own files: the closest archived ancestor, with `with` its
|
|
2524
|
+
* address, so every app names the same thing to unarchive (PEEKM-2). A file
|
|
2525
|
+
* read through {@link resolveForeignObject}'s `archivedWith` is marked by the
|
|
2526
|
+
* same rule. `archiveAt` gives a file's own archive only.
|
|
2527
|
+
*
|
|
2522
2528
|
* Stops at a cycle rather than looping: `parentRef` is written by people, and
|
|
2523
2529
|
* two files each moved under the other is a state the relay accepts.
|
|
2524
2530
|
*/
|
|
2525
|
-
function archivedAncestorOf(
|
|
2531
|
+
export function archivedAncestorOf(
|
|
2526
2532
|
address: string,
|
|
2527
2533
|
parentOf: (address: string) => string | undefined,
|
|
2528
2534
|
archiveAt: (address: string) => Archive | undefined,
|
|
@@ -3521,7 +3527,7 @@ export async function resolveForeignObject(
|
|
|
3521
3527
|
const childOwners = await childOwnersOf(plan, answered, childChanges, query, cache)
|
|
3522
3528
|
const assembled = assembleObject(plan, answered, childChanges, childOwners)
|
|
3523
3529
|
if (assembled.object.unreachable) return assembled.object
|
|
3524
|
-
if (options.archivedWith) await markArchivedParents([{ object: assembled.object, manifest: resolved.manifest }], query)
|
|
3530
|
+
if (options.archivedWith) await markArchivedParents([{ object: assembled.object, manifest: resolved.manifest }], query, cache)
|
|
3525
3531
|
return withFiles(
|
|
3526
3532
|
withBorrowed(
|
|
3527
3533
|
withPeople(assembled, await (lookupPeople ?? peopleViaRelay(query))(peopleOf(assembled))),
|
|
@@ -3663,7 +3669,7 @@ export async function resolveForeignObjects(
|
|
|
3663
3669
|
built: assembleObject(plan, events, childChanges, ownerLists[i]),
|
|
3664
3670
|
}))
|
|
3665
3671
|
if (options.archivedWith) {
|
|
3666
|
-
await markArchivedParents(assembled.map(({ plan, built }) => ({ object: built.object, manifest: plan.resolved.manifest })), query)
|
|
3672
|
+
await markArchivedParents(assembled.map(({ plan, built }) => ({ object: built.object, manifest: plan.resolved.manifest })), query, cache)
|
|
3667
3673
|
}
|
|
3668
3674
|
const wanted = [...new Set(assembled.flatMap(({ built }) => peopleOf(built)))]
|
|
3669
3675
|
const reachable = assembled.some(({ built }) => !built.object.unreachable)
|
|
@@ -4004,31 +4010,114 @@ function withFiles(object: ForeignObject, files: ForeignObject[] | undefined): F
|
|
|
4004
4010
|
* rather than drawing live work. The cascade is computed here and never written
|
|
4005
4011
|
* to the issue, so unarchiving the project restores it exactly.
|
|
4006
4012
|
*
|
|
4007
|
-
* **
|
|
4008
|
-
*
|
|
4009
|
-
*
|
|
4010
|
-
*
|
|
4011
|
-
*
|
|
4013
|
+
* **The whole parent chain, the closest archived file named** (SPEC §6.5,
|
|
4014
|
+
* PEEKM-2): a page under a page under an archived page is archived with the
|
|
4015
|
+
* one nearest it, as a Folder listing reads it ({@link archivedAncestorOf}), so
|
|
4016
|
+
* every app closes the same box and names the same thing to unarchive. One
|
|
4017
|
+
* read per level for the whole set, and only while some file still has a
|
|
4018
|
+
* parent, so a topic page or a project page pays nothing.
|
|
4019
|
+
*
|
|
4020
|
+
* Each ancestor is read with its root, so its archive is folded by SPEC §6.2's
|
|
4021
|
+
* `h` rule like any other change, and its own parent is read by its own kind:
|
|
4022
|
+
* an issue's moved `project`, a page's `parent`. An ancestor whose root this
|
|
4023
|
+
* reader cannot see ends the walk there, as not archived. Stops at a cycle.
|
|
4012
4024
|
*
|
|
4013
|
-
*
|
|
4014
|
-
*
|
|
4015
|
-
*
|
|
4025
|
+
* Each ancestor's rule is its own app's: the child's when that app also draws
|
|
4026
|
+
* the ancestor's kind — a project is Ship's as its issue is — otherwise the
|
|
4027
|
+
* ancestor's manifest, read through `cache`.
|
|
4016
4028
|
*/
|
|
4017
4029
|
async function markArchivedParents(
|
|
4018
|
-
entries: { object: ForeignObject; manifest?:
|
|
4030
|
+
entries: { object: ForeignObject; manifest?: Manifest }[],
|
|
4019
4031
|
query: QueryFn,
|
|
4032
|
+
cache?: ProjectionCache,
|
|
4020
4033
|
): Promise<void> {
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4034
|
+
type Walk = { object: ForeignObject; manifest?: Manifest; at: string; seen: Set<string> }
|
|
4035
|
+
// An `naddr` parent names the same file as its plain address (FEE-2), and
|
|
4036
|
+
// only the plain one is what a change's target tag and `with` carry.
|
|
4037
|
+
const plain = (reference: string) => {
|
|
4038
|
+
const pointer = addressPointerOf(reference)
|
|
4039
|
+
return pointer ? `${pointer.kind}:${pointer.pubkey}:${pointer.identifier}` : undefined
|
|
4040
|
+
}
|
|
4041
|
+
let walking: Walk[] = entries
|
|
4042
|
+
.filter(({ object: o }) => !o.unreachable && !o.archived && o.parentRef && plain(o.parentRef))
|
|
4043
|
+
.map(({ object, manifest }) => ({
|
|
4044
|
+
object,
|
|
4045
|
+
manifest,
|
|
4046
|
+
at: plain(object.parentRef!)!,
|
|
4047
|
+
seen: new Set([plain(object.address ?? '') ?? '']),
|
|
4048
|
+
}))
|
|
4049
|
+
while (walking.length) {
|
|
4050
|
+
// Each child's ancestor is read by that child's app when it draws the
|
|
4051
|
+
// ancestor's kind — a project is Ship's as its issue is — and by the
|
|
4052
|
+
// ancestor's own manifest otherwise, so one file in a batch never sets the
|
|
4053
|
+
// rule another file's ancestor is read by.
|
|
4054
|
+
const drawnBy: Manifest[] = []
|
|
4055
|
+
const keyed = walking.map((walk) => {
|
|
4056
|
+
const own = walk.manifest?.projections?.[String(addressPointerOf(walk.at)!.kind)] ? walk.manifest : undefined
|
|
4057
|
+
if (own && !drawnBy.includes(own)) drawnBy.push(own)
|
|
4058
|
+
return { walk, key: `${walk.at}|${own ? drawnBy.indexOf(own) : ''}`, own }
|
|
4059
|
+
})
|
|
4060
|
+
// A manifest that cannot be read is an ancestor read by SPEC's rule with no
|
|
4061
|
+
// parent: the walk ends there rather than the whole open failing.
|
|
4062
|
+
const theirOwn = new Map<string, Promise<Manifest | undefined>>()
|
|
4063
|
+
const ancestors = await Promise.all(
|
|
4064
|
+
[...new Map(keyed.map((entry) => [entry.key, entry])).values()].map(async ({ key, walk, own }) => {
|
|
4065
|
+
const pointer = addressPointerOf(walk.at)!
|
|
4066
|
+
if (!own && !theirOwn.has(walk.at)) {
|
|
4067
|
+
theirOwn.set(walk.at, resolveManifest(pointer, query, cache).then((r) => r?.manifest, () => undefined))
|
|
4068
|
+
}
|
|
4069
|
+
return { key, address: walk.at, pointer, manifest: own ?? (await theirOwn.get(walk.at)) }
|
|
4070
|
+
}),
|
|
4071
|
+
)
|
|
4072
|
+
const rules = ancestors.map(({ manifest }) => archiveRuleOf(manifest))
|
|
4073
|
+
const addresses = [...new Set(ancestors.map(({ address }) => address))]
|
|
4074
|
+
const roots = new Map<string, { kinds: number[]; authors: string[]; '#d': string[] }>()
|
|
4075
|
+
for (const address of addresses) {
|
|
4076
|
+
const pointer = addressPointerOf(address)!
|
|
4077
|
+
const group = `${pointer.kind}:${pointer.pubkey}`
|
|
4078
|
+
const filter = roots.get(group) ?? { kinds: [pointer.kind], authors: [pointer.pubkey], '#d': [] }
|
|
4079
|
+
filter['#d'].push(pointer.identifier)
|
|
4080
|
+
roots.set(group, filter)
|
|
4081
|
+
}
|
|
4082
|
+
const filters = [
|
|
4083
|
+
...[...roots.values()].flatMap((filter) => {
|
|
4084
|
+
const groups: Record<string, unknown>[] = []
|
|
4085
|
+
for (let start = 0; start < filter['#d'].length; start += PARENT_ROOT_GROUP) {
|
|
4086
|
+
groups.push({ ...filter, '#d': filter['#d'].slice(start, start + PARENT_ROOT_GROUP) })
|
|
4087
|
+
}
|
|
4088
|
+
return groups
|
|
4089
|
+
}),
|
|
4090
|
+
...archiveFilters(addresses, rules),
|
|
4091
|
+
]
|
|
4092
|
+
const events = await queryChunked(filters, query)
|
|
4093
|
+
const read = new Map<string, { archive?: Archive; parent?: string; manifest?: Manifest }>()
|
|
4094
|
+
for (const [index, { key, address, pointer, manifest }] of ancestors.entries()) {
|
|
4095
|
+
const root = events
|
|
4096
|
+
.filter((e) => e.kind === pointer.kind && e.pubkey === pointer.pubkey && tagValue(e, 'd') === pointer.identifier)
|
|
4097
|
+
.sort(byOrder)
|
|
4098
|
+
.at(-1)
|
|
4099
|
+
// Not readable here: the walk ends, and nothing above it is claimed.
|
|
4100
|
+
if (!root) continue
|
|
4101
|
+
const parent = manifest?.projections?.[String(pointer.kind)]
|
|
4102
|
+
? parentRefOf(manifest, pointer.kind, root, foldOf(events, address, manifest, root))
|
|
4103
|
+
: undefined
|
|
4104
|
+
read.set(key, { archive: archiveOf(events, address, rules[index]!, root), parent, manifest })
|
|
4105
|
+
}
|
|
4106
|
+
const next: Walk[] = []
|
|
4107
|
+
for (const { walk, key } of keyed) {
|
|
4108
|
+
const found = read.get(key)
|
|
4109
|
+
if (!found) continue
|
|
4110
|
+
if (found.archive) {
|
|
4111
|
+
walk.object.archived = { ...found.archive, with: walk.at }
|
|
4112
|
+
continue
|
|
4113
|
+
}
|
|
4114
|
+
walk.seen.add(walk.at)
|
|
4115
|
+
const parent = found.parent && plain(found.parent)
|
|
4116
|
+
if (parent && !walk.seen.has(parent)) {
|
|
4117
|
+
next.push({ ...walk, manifest: found.manifest, at: parent })
|
|
4118
|
+
}
|
|
4119
|
+
}
|
|
4120
|
+
walking = next
|
|
4032
4121
|
}
|
|
4033
4122
|
}
|
|
4034
4123
|
|