@estiva-app/interop 0.62.0 → 0.63.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/projection.d.ts.map +1 -1
- package/dist/projection.js +93 -37
- package/dist/projection.js.map +1 -1
- package/package.json +1 -1
- package/src/projection.ts +122 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.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/projection.ts
CHANGED
|
@@ -3315,28 +3315,6 @@ function buildObject(args: {
|
|
|
3315
3315
|
const { root, pointer, manifest, projection, folded } = args
|
|
3316
3316
|
const naddr = encodeNaddr(pointer)
|
|
3317
3317
|
const { slots, meta } = resolveSlots(projection, root, folded, manifest)
|
|
3318
|
-
|
|
3319
|
-
/**
|
|
3320
|
-
* What each field holds now, however it got there.
|
|
3321
|
-
*
|
|
3322
|
-
* `resolveActions` reads the fold alone, which is right for a field that only
|
|
3323
|
-
* ever exists as a change — but a project's lead is seeded by a tag on the
|
|
3324
|
-
* root event. Without this, the assign control on a project nobody has
|
|
3325
|
-
* reassigned reads "Assign to me" while a lead is plainly set, and the one
|
|
3326
|
-
* control that is supposed to both report and set the field (PEEK-18) reports
|
|
3327
|
-
* nothing.
|
|
3328
|
-
*/
|
|
3329
|
-
const held: Record<string, string> = {}
|
|
3330
|
-
// The built-in subtitle too, or a summary seeded at creation shows on the
|
|
3331
|
-
// card while `summarize` offers a blank to edit (SPEC §6.12).
|
|
3332
|
-
for (const spec of Object.values(withDefaultSubtitle(projection.slots, root.kind)).flat()) {
|
|
3333
|
-
// `tag` may name several spellings (see `SlotSpec`); the field this slot
|
|
3334
|
-
// *is* keyed on is the first, which is the one the app writes today. The
|
|
3335
|
-
// rest are only there to keep older records rendering.
|
|
3336
|
-
const field = spec.fold ?? (Array.isArray(spec.tag) ? spec.tag[0] : spec.tag)
|
|
3337
|
-
const raw = field ? rawSlotValue(spec, root, folded, false)?.value : undefined
|
|
3338
|
-
if (field && raw !== undefined) held[field] = raw
|
|
3339
|
-
}
|
|
3340
3318
|
const objectAddress = pointerToAddress(pointer)
|
|
3341
3319
|
return {
|
|
3342
3320
|
// An addressable object's `ref` is its address: stable across the author
|
|
@@ -3360,16 +3338,45 @@ function buildObject(args: {
|
|
|
3360
3338
|
// Substituted here rather than in the component: `<bech32>` is a NIP-89
|
|
3361
3339
|
// detail, and the widget's job is to draw a link, not to know the spec.
|
|
3362
3340
|
openUrl: args.webTemplate?.replace('<bech32>', naddr),
|
|
3363
|
-
actions:
|
|
3364
|
-
action.current === undefined && action.field
|
|
3365
|
-
? { ...action, current: held[action.field] }
|
|
3366
|
-
: action,
|
|
3367
|
-
),
|
|
3341
|
+
actions: actionsOfFile(manifest, projection, root, folded),
|
|
3368
3342
|
viaRecommendation: args.viaRecommendation,
|
|
3369
3343
|
...(args.archived ? { archived: args.archived } : {}),
|
|
3370
3344
|
}
|
|
3371
3345
|
}
|
|
3372
3346
|
|
|
3347
|
+
/**
|
|
3348
|
+
* An addressable file's actions, each with what its field holds now, however
|
|
3349
|
+
* it got there.
|
|
3350
|
+
*
|
|
3351
|
+
* `resolveActions` reads the fold alone, which is right for a field that only
|
|
3352
|
+
* ever exists as a change — but a project's lead is seeded by a tag on the
|
|
3353
|
+
* root event. Without this, the assign control on a project nobody has
|
|
3354
|
+
* reassigned reads "Assign to me" while a lead is plainly set, and the one
|
|
3355
|
+
* control that is supposed to both report and set the field (PEEK-18) reports
|
|
3356
|
+
* nothing.
|
|
3357
|
+
*/
|
|
3358
|
+
function actionsOfFile(
|
|
3359
|
+
manifest: Manifest,
|
|
3360
|
+
projection: Projection,
|
|
3361
|
+
root: SignedEvent,
|
|
3362
|
+
folded: Record<string, { value: string; format?: ContentFormat }>,
|
|
3363
|
+
): ResolvedAction[] {
|
|
3364
|
+
const held: Record<string, string> = {}
|
|
3365
|
+
// The built-in subtitle too, or a summary seeded at creation shows on the
|
|
3366
|
+
// card while `summarize` offers a blank to edit (SPEC §6.12).
|
|
3367
|
+
for (const spec of Object.values(withDefaultSubtitle(projection.slots, root.kind)).flat()) {
|
|
3368
|
+
// `tag` may name several spellings (see `SlotSpec`); the field this slot
|
|
3369
|
+
// *is* keyed on is the first, which is the one the app writes today. The
|
|
3370
|
+
// rest are only there to keep older records rendering.
|
|
3371
|
+
const field = spec.fold ?? (Array.isArray(spec.tag) ? spec.tag[0] : spec.tag)
|
|
3372
|
+
const raw = field ? rawSlotValue(spec, root, folded, false)?.value : undefined
|
|
3373
|
+
if (field && raw !== undefined) held[field] = raw
|
|
3374
|
+
}
|
|
3375
|
+
return resolveActions(manifest, root.kind, folded).map((action) =>
|
|
3376
|
+
action.current === undefined && action.field ? { ...action, current: held[action.field] } : action,
|
|
3377
|
+
)
|
|
3378
|
+
}
|
|
3379
|
+
|
|
3373
3380
|
/**
|
|
3374
3381
|
* Resolve a `nostr:naddr…` into a renderable widget.
|
|
3375
3382
|
*
|
|
@@ -3494,7 +3501,9 @@ export async function resolveForeignObject(
|
|
|
3494
3501
|
: undefined,
|
|
3495
3502
|
])
|
|
3496
3503
|
const followUp = childChangeFilters(plan, answered)
|
|
3497
|
-
const
|
|
3504
|
+
const childChanges = followUp.length ? await queryChunked(followUp, query) : []
|
|
3505
|
+
const childOwners = await childOwnersOf(plan, answered, childChanges, query, cache)
|
|
3506
|
+
const assembled = assembleObject(plan, answered, childChanges, childOwners)
|
|
3498
3507
|
if (assembled.object.unreachable) return assembled.object
|
|
3499
3508
|
if (options.archivedWith) await markArchivedParents([{ object: assembled.object, manifest: resolved.manifest }], query)
|
|
3500
3509
|
return withFiles(
|
|
@@ -3630,11 +3639,12 @@ export async function resolveForeignObjects(
|
|
|
3630
3639
|
followUp.push(...childChangeFilters(plan, events))
|
|
3631
3640
|
}
|
|
3632
3641
|
const childChanges = followUp.length ? await queryChunked(followUp, query) : []
|
|
3642
|
+
const ownerLists = await Promise.all(plans.map(({ plan }) => childOwnersOf(plan, events, childChanges, query, cache)))
|
|
3633
3643
|
|
|
3634
|
-
const assembled = plans.map(({ reference, plan }) => ({
|
|
3644
|
+
const assembled = plans.map(({ reference, plan }, i) => ({
|
|
3635
3645
|
reference,
|
|
3636
3646
|
plan,
|
|
3637
|
-
built: assembleObject(plan, events, childChanges),
|
|
3647
|
+
built: assembleObject(plan, events, childChanges, ownerLists[i]),
|
|
3638
3648
|
}))
|
|
3639
3649
|
if (options.archivedWith) {
|
|
3640
3650
|
await markArchivedParents(assembled.map(({ plan, built }) => ({ object: built.object, manifest: plan.resolved.manifest })), query)
|
|
@@ -4173,7 +4183,12 @@ interface AssembledObject {
|
|
|
4173
4183
|
* filters match — a comment naming two files in the set, a `kind:9` that is a
|
|
4174
4184
|
* Topic's child and its comment — would otherwise be drawn twice.
|
|
4175
4185
|
*/
|
|
4176
|
-
function assembleObject(
|
|
4186
|
+
function assembleObject(
|
|
4187
|
+
plan: ObjectPlan,
|
|
4188
|
+
answered: SignedEvent[],
|
|
4189
|
+
childChanges: SignedEvent[] = [],
|
|
4190
|
+
childOwners: Set<string> = new Set(),
|
|
4191
|
+
): AssembledObject {
|
|
4177
4192
|
const { naddr, pointer, address, resolved, projection, commentKinds, childFilter, openUrl } = plan
|
|
4178
4193
|
const { manifest, viaRecommendation } = resolved
|
|
4179
4194
|
const seen = new Set<string>()
|
|
@@ -4265,6 +4280,7 @@ function assembleObject(plan: ObjectPlan, answered: SignedEvent[], childChanges:
|
|
|
4265
4280
|
webTemplate: resolved.webTemplate,
|
|
4266
4281
|
viaRecommendation,
|
|
4267
4282
|
childChanges,
|
|
4283
|
+
childOwners,
|
|
4268
4284
|
})
|
|
4269
4285
|
|
|
4270
4286
|
return { object, ...(children ? { children } : {}) }
|
|
@@ -4529,8 +4545,10 @@ function childrenFrom(args: {
|
|
|
4529
4545
|
viaRecommendation: boolean
|
|
4530
4546
|
/** What {@link childChangeFilters} asked for; empty when it asked nothing. */
|
|
4531
4547
|
childChanges?: SignedEvent[]
|
|
4548
|
+
/** What {@link childOwnersOf} answered: the authors whose children carry actions. */
|
|
4549
|
+
childOwners?: Set<string>
|
|
4532
4550
|
}): ForeignObject[] | undefined {
|
|
4533
|
-
const { events, childFilter, manifest, webTemplate, viaRecommendation, childChanges = [] } = args
|
|
4551
|
+
const { events, childFilter, manifest, webTemplate, viaRecommendation, childChanges = [], childOwners = new Set() } = args
|
|
4534
4552
|
if (childFilter === undefined) return undefined
|
|
4535
4553
|
if (childFilter === null) return []
|
|
4536
4554
|
|
|
@@ -4580,11 +4598,64 @@ function childrenFrom(args: {
|
|
|
4580
4598
|
if (records.hiddenWhen && folded[records.hiddenWhen.field]?.value === records.hiddenWhen.equals) return []
|
|
4581
4599
|
if (address && manifest.records && archiveOf(childChanges, address, records, event)) return []
|
|
4582
4600
|
return [
|
|
4583
|
-
buildChildObject({
|
|
4601
|
+
buildChildObject({
|
|
4602
|
+
root: event,
|
|
4603
|
+
manifest,
|
|
4604
|
+
projection: childProjection,
|
|
4605
|
+
records,
|
|
4606
|
+
webTemplate,
|
|
4607
|
+
viaRecommendation,
|
|
4608
|
+
folded,
|
|
4609
|
+
ownsKind: childOwners.has(event.pubkey),
|
|
4610
|
+
}),
|
|
4584
4611
|
]
|
|
4585
4612
|
})
|
|
4586
4613
|
}
|
|
4587
4614
|
|
|
4615
|
+
/**
|
|
4616
|
+
* The authors of a card's children whose kind the card's own app owns — the
|
|
4617
|
+
* only children that carry actions (LTX-2).
|
|
4618
|
+
*
|
|
4619
|
+
* A child is drawn through its parent's manifest, and that need not be the
|
|
4620
|
+
* manifest its kind resolves to: an outside app may list Ship's issues under a
|
|
4621
|
+
* kind of its own and declare text actions on them that Ship keeps to itself.
|
|
4622
|
+
* Offered on the child, they would tell Leaf it may write a field Ship never
|
|
4623
|
+
* shared, with no `declaredBy` to say whose they are. So a child carries
|
|
4624
|
+
* actions only when its kind, resolved for its author as a file read on its
|
|
4625
|
+
* own is, lands on the parent's manifest. Per author, because an author's
|
|
4626
|
+
* recommendation is part of that answer, and through the cache, so a project's
|
|
4627
|
+
* issues by three people cost three lookups once. Nothing is asked when the
|
|
4628
|
+
* parent's app declares no action on the child's kind, and only for authors of
|
|
4629
|
+
* roots that came back: a move naming the parent is anyone's to write, and the
|
|
4630
|
+
* addresses it lists would otherwise cost a lookup each, root or not.
|
|
4631
|
+
*/
|
|
4632
|
+
async function childOwnersOf(
|
|
4633
|
+
plan: ObjectPlan,
|
|
4634
|
+
answered: SignedEvent[],
|
|
4635
|
+
childChanges: SignedEvent[],
|
|
4636
|
+
query: QueryFn,
|
|
4637
|
+
cache?: ProjectionCache,
|
|
4638
|
+
): Promise<Set<string>> {
|
|
4639
|
+
const { childFilter, resolved } = plan
|
|
4640
|
+
if (!childFilter || resolveActions(resolved.manifest, childFilter.kind, {}).length === 0) return new Set()
|
|
4641
|
+
const movedIn = new Set(movedInAddressesOf(answered, childFilter, resolved.manifest.records))
|
|
4642
|
+
const authors = new Set([
|
|
4643
|
+
...childRootsOf(answered, childFilter).map((e) => e.pubkey),
|
|
4644
|
+
...childChanges
|
|
4645
|
+
.filter((e) => e.kind === childFilter.kind && movedIn.has(childAddressOf(e) ?? ''))
|
|
4646
|
+
.map((e) => e.pubkey),
|
|
4647
|
+
])
|
|
4648
|
+
const owners = await Promise.all(
|
|
4649
|
+
[...authors].map(async (pubkey) => {
|
|
4650
|
+
const owner = await resolveManifest({ kind: childFilter.kind, pubkey, identifier: '', relays: [] }, query, cache).catch(
|
|
4651
|
+
() => null,
|
|
4652
|
+
)
|
|
4653
|
+
return owner?.address === resolved.address ? [pubkey] : []
|
|
4654
|
+
}),
|
|
4655
|
+
)
|
|
4656
|
+
return new Set(owners.flat())
|
|
4657
|
+
}
|
|
4658
|
+
|
|
4588
4659
|
/** The child roots a `list` filter asked for, picked back out of a pooled answer on its own criteria. */
|
|
4589
4660
|
function childRootsOf(events: SignedEvent[], childFilter: NonNullable<ReturnType<typeof childFilterFor>>): SignedEvent[] {
|
|
4590
4661
|
return events
|
|
@@ -4661,9 +4732,14 @@ const CHILD_CHANGE_GROUP = 10
|
|
|
4661
4732
|
* event id. That is the whole of PRO-6's finding (6), and it is why `ref` and
|
|
4662
4733
|
* `eventId` exist alongside `address`.
|
|
4663
4734
|
*
|
|
4664
|
-
*
|
|
4665
|
-
*
|
|
4666
|
-
*
|
|
4735
|
+
* A regular event carries **no actions**, and that is correct rather than a
|
|
4736
|
+
* limitation: an action emits a change carrying an `a` tag naming what it
|
|
4737
|
+
* changes, and a regular event cannot be named that way. An addressable child —
|
|
4738
|
+
* a Ship issue read under its project — carries the actions its own app
|
|
4739
|
+
* declares for its kind, as it does when read on its own, so whether its app
|
|
4740
|
+
* shares its text is the same answer either way (LTX-2) — when the parent's app
|
|
4741
|
+
* is that app; listed by another, it carries none (`childOwnersOf`). Borrowed creations
|
|
4742
|
+
* (`declaredBy`) are added only on a file read on its own.
|
|
4667
4743
|
*/
|
|
4668
4744
|
function buildChildObject(args: {
|
|
4669
4745
|
root: SignedEvent
|
|
@@ -4686,8 +4762,13 @@ function buildChildObject(args: {
|
|
|
4686
4762
|
* (MAN-7). Empty for a regular event, which nothing can change by address.
|
|
4687
4763
|
*/
|
|
4688
4764
|
folded?: Record<string, { value: string; format?: ContentFormat }>
|
|
4765
|
+
/**
|
|
4766
|
+
* Whether `manifest` is the one this child's kind resolves to for its author,
|
|
4767
|
+
* as {@link childOwnersOf} found. Its actions are offered only then.
|
|
4768
|
+
*/
|
|
4769
|
+
ownsKind?: boolean
|
|
4689
4770
|
}): ForeignObject {
|
|
4690
|
-
const { root, manifest, projection, webTemplate, viaRecommendation, nevent, folded = {} } = args
|
|
4771
|
+
const { root, manifest, projection, webTemplate, viaRecommendation, nevent, folded = {}, ownsKind = false } = args
|
|
4691
4772
|
const identifier = tagValue(root, 'd')
|
|
4692
4773
|
const addressable = identifier !== undefined
|
|
4693
4774
|
const pointer: AddressPointer = {
|
|
@@ -4733,8 +4814,10 @@ function buildChildObject(args: {
|
|
|
4733
4814
|
single template serve both, and what stops a message linking to nothing.
|
|
4734
4815
|
*/
|
|
4735
4816
|
openUrl: (naddr ?? nevent) ? webTemplate?.replace('<bech32>', (naddr ?? nevent) as string) : undefined,
|
|
4736
|
-
// See the note above: nothing can be declared to act on a regular event
|
|
4737
|
-
|
|
4817
|
+
// See the note above: nothing can be declared to act on a regular event, and an event read by its id
|
|
4818
|
+
// (`nevent`) may be an older version of its file, its changes unread, so it is offered none either.
|
|
4819
|
+
// A child drawn through an app that does not own its kind gets none: they are not its owner's (`childOwnersOf`).
|
|
4820
|
+
actions: addressable && !nevent && ownsKind ? actionsOfFile(manifest, projection, root, folded) : [],
|
|
4738
4821
|
viaRecommendation,
|
|
4739
4822
|
}
|
|
4740
4823
|
}
|