@estiva-app/interop 0.63.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 +34 -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 +23 -0
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +119 -25
- package/dist/projection.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/projection.ts +132 -26
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,
|
|
@@ -3292,6 +3298,21 @@ export interface ForeignObject {
|
|
|
3292
3298
|
* See {@link Archive} and {@link isArchived}.
|
|
3293
3299
|
*/
|
|
3294
3300
|
archived?: Archive
|
|
3301
|
+
/**
|
|
3302
|
+
* When this file last changed, in seconds: the newest of its root's
|
|
3303
|
+
* `created_at` and every folded field's winning change (5ebf2756).
|
|
3304
|
+
*
|
|
3305
|
+
* For a card that lists some of a file's children rather than all of them —
|
|
3306
|
+
* a project's most recently changed issues. Its comments are not changes to
|
|
3307
|
+
* it. A regular event, which nothing changes by address, has its own
|
|
3308
|
+
* `created_at`. Absent on an unreachable stub, which has no root to read.
|
|
3309
|
+
*/
|
|
3310
|
+
changedAt?: number
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
/** The newest of a root's `created_at` and its folded fields' changes. */
|
|
3314
|
+
function changedAtOf(root: SignedEvent, folded: Record<string, { at?: number }>): number {
|
|
3315
|
+
return Math.max(root.created_at, ...Object.values(folded).map((f) => f.at ?? 0))
|
|
3295
3316
|
}
|
|
3296
3317
|
|
|
3297
3318
|
|
|
@@ -3306,7 +3327,7 @@ function buildObject(args: {
|
|
|
3306
3327
|
pointer: AddressPointer
|
|
3307
3328
|
manifest: Manifest
|
|
3308
3329
|
projection: Projection
|
|
3309
|
-
folded: Record<string, { value: string; format?: ContentFormat }>
|
|
3330
|
+
folded: Record<string, { value: string; format?: ContentFormat; at?: number }>
|
|
3310
3331
|
viaRecommendation: boolean
|
|
3311
3332
|
webTemplate?: string
|
|
3312
3333
|
comments?: ForeignObject['comments']
|
|
@@ -3341,6 +3362,7 @@ function buildObject(args: {
|
|
|
3341
3362
|
actions: actionsOfFile(manifest, projection, root, folded),
|
|
3342
3363
|
viaRecommendation: args.viaRecommendation,
|
|
3343
3364
|
...(args.archived ? { archived: args.archived } : {}),
|
|
3365
|
+
changedAt: changedAtOf(root, folded),
|
|
3344
3366
|
}
|
|
3345
3367
|
}
|
|
3346
3368
|
|
|
@@ -3505,7 +3527,7 @@ export async function resolveForeignObject(
|
|
|
3505
3527
|
const childOwners = await childOwnersOf(plan, answered, childChanges, query, cache)
|
|
3506
3528
|
const assembled = assembleObject(plan, answered, childChanges, childOwners)
|
|
3507
3529
|
if (assembled.object.unreachable) return assembled.object
|
|
3508
|
-
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)
|
|
3509
3531
|
return withFiles(
|
|
3510
3532
|
withBorrowed(
|
|
3511
3533
|
withPeople(assembled, await (lookupPeople ?? peopleViaRelay(query))(peopleOf(assembled))),
|
|
@@ -3647,7 +3669,7 @@ export async function resolveForeignObjects(
|
|
|
3647
3669
|
built: assembleObject(plan, events, childChanges, ownerLists[i]),
|
|
3648
3670
|
}))
|
|
3649
3671
|
if (options.archivedWith) {
|
|
3650
|
-
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)
|
|
3651
3673
|
}
|
|
3652
3674
|
const wanted = [...new Set(assembled.flatMap(({ built }) => peopleOf(built)))]
|
|
3653
3675
|
const reachable = assembled.some(({ built }) => !built.object.unreachable)
|
|
@@ -3988,31 +4010,114 @@ function withFiles(object: ForeignObject, files: ForeignObject[] | undefined): F
|
|
|
3988
4010
|
* rather than drawing live work. The cascade is computed here and never written
|
|
3989
4011
|
* to the issue, so unarchiving the project restores it exactly.
|
|
3990
4012
|
*
|
|
3991
|
-
* **
|
|
3992
|
-
*
|
|
3993
|
-
*
|
|
3994
|
-
*
|
|
3995
|
-
*
|
|
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.
|
|
3996
4024
|
*
|
|
3997
|
-
*
|
|
3998
|
-
*
|
|
3999
|
-
*
|
|
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`.
|
|
4000
4028
|
*/
|
|
4001
4029
|
async function markArchivedParents(
|
|
4002
|
-
entries: { object: ForeignObject; manifest?:
|
|
4030
|
+
entries: { object: ForeignObject; manifest?: Manifest }[],
|
|
4003
4031
|
query: QueryFn,
|
|
4032
|
+
cache?: ProjectionCache,
|
|
4004
4033
|
): Promise<void> {
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
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
|
|
4016
4121
|
}
|
|
4017
4122
|
}
|
|
4018
4123
|
|
|
@@ -4761,7 +4866,7 @@ function buildChildObject(args: {
|
|
|
4761
4866
|
* The child's own fold, when {@link childChangeFilters} read its changes
|
|
4762
4867
|
* (MAN-7). Empty for a regular event, which nothing can change by address.
|
|
4763
4868
|
*/
|
|
4764
|
-
folded?: Record<string, { value: string; format?: ContentFormat }>
|
|
4869
|
+
folded?: Record<string, { value: string; format?: ContentFormat; at?: number }>
|
|
4765
4870
|
/**
|
|
4766
4871
|
* Whether `manifest` is the one this child's kind resolves to for its author,
|
|
4767
4872
|
* as {@link childOwnersOf} found. Its actions are offered only then.
|
|
@@ -4819,6 +4924,7 @@ function buildChildObject(args: {
|
|
|
4819
4924
|
// A child drawn through an app that does not own its kind gets none: they are not its owner's (`childOwnersOf`).
|
|
4820
4925
|
actions: addressable && !nevent && ownsKind ? actionsOfFile(manifest, projection, root, folded) : [],
|
|
4821
4926
|
viaRecommendation,
|
|
4927
|
+
changedAt: changedAtOf(root, folded),
|
|
4822
4928
|
}
|
|
4823
4929
|
}
|
|
4824
4930
|
|