@estiva-app/interop 0.61.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 +47 -0
- package/dist/objectUrl.d.ts +43 -9
- package/dist/objectUrl.d.ts.map +1 -1
- package/dist/objectUrl.js +94 -19
- package/dist/objectUrl.js.map +1 -1
- 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/objectUrl.ts +105 -17
- 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/objectUrl.ts
CHANGED
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
* That second sentence is the amended one. §7.2 used to say a consumer MUST
|
|
31
31
|
* ignore *everything* before the final uuid, which contradicted the paragraph
|
|
32
32
|
* above it and, read literally, resolves `evil.example.com/issue/<uuid>` as a
|
|
33
|
-
* Ship issue. The
|
|
34
|
-
*
|
|
35
|
-
* corrected rule.
|
|
33
|
+
* Ship issue. The `<type>` segment is what selects the kind, and the host must
|
|
34
|
+
* be one some app declares; only the slug is decoration. `matchObjectUrl`
|
|
35
|
+
* implements the corrected rule.
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -139,11 +139,27 @@ export interface UrlPattern {
|
|
|
139
139
|
kind?: number
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* The `urls` shapes a manifest event declares, on its own origin.
|
|
144
|
+
*
|
|
145
|
+
* **A manifest declares `urls` only on its own origin** (SPEC §7.7, LTX-6): a
|
|
146
|
+
* shape whose scheme, host and port are not those of one of the manifest's
|
|
147
|
+
* `web` templates is dropped, and a manifest with no `web` declares none.
|
|
148
|
+
* Every declared origin is one some manifest serves from, which is what lets
|
|
149
|
+
* {@link matchObjectUrl} read a path on any of them.
|
|
150
|
+
*
|
|
151
|
+
* That keeps declarations consistent; it is not authentication. A reader
|
|
152
|
+
* trusts a manifest's hosts as far as it trusts the manifest.
|
|
153
|
+
*
|
|
154
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-files-path-is-the-same-on-every-apps-host.md
|
|
155
|
+
*/
|
|
143
156
|
export function urlPatternsOf(event: { tags: string[][] }): UrlPattern[] {
|
|
157
|
+
const own = new Set(event.tags.filter((tag) => tag[0] === 'web' && tag[1]).map((tag) => originOfUrl(tag[1])))
|
|
144
158
|
const out: UrlPattern[] = []
|
|
145
159
|
for (const tag of event.tags) {
|
|
146
160
|
if (tag[0] !== 'urls' || !tag[1]) continue
|
|
161
|
+
const origin = originOfUrl(tag[1])
|
|
162
|
+
if (origin === null || !own.has(origin)) continue
|
|
147
163
|
const kind = tag[2] ? Number(tag[2]) : undefined
|
|
148
164
|
out.push({ pattern: tag[1], ...(Number.isInteger(kind) ? { kind } : {}) })
|
|
149
165
|
}
|
|
@@ -165,6 +181,13 @@ export interface MatchedObjectUrl {
|
|
|
165
181
|
by: 'd' | 'id'
|
|
166
182
|
/** Present only when the matched pattern named one. */
|
|
167
183
|
kind?: number
|
|
184
|
+
/**
|
|
185
|
+
* The kinds to resolve under when shapes on other origins claim the path for
|
|
186
|
+
* different kinds (SPEC §7.7, LTX-6); `kind` is then absent. One author must
|
|
187
|
+
* hold the identity across all of them, so a second app's claim to the same
|
|
188
|
+
* word turns the link plain rather than taking it over.
|
|
189
|
+
*/
|
|
190
|
+
kinds?: number[]
|
|
168
191
|
/**
|
|
169
192
|
* The object the path names, when the identity came from the query — the
|
|
170
193
|
* topic a `?thread=<id>` link opens, read off `/topic/<slug>-<d>`. Absent
|
|
@@ -186,12 +209,26 @@ export interface MatchedObjectUrl {
|
|
|
186
209
|
const BLOCK_PLACEHOLDER = '<block>'
|
|
187
210
|
|
|
188
211
|
/**
|
|
189
|
-
* Match a pasted URL against
|
|
212
|
+
* Match a pasted URL against the shapes every manifest declares.
|
|
213
|
+
*
|
|
214
|
+
* **The `<type>` segment is significant; the slug is not.** That is §7.2 as
|
|
215
|
+
* amended: a consumer that matched on the trailing uuid alone would resolve
|
|
216
|
+
* any URL from anywhere as some app's object.
|
|
217
|
+
*
|
|
218
|
+
* **The path is the same on every declared host** (SPEC §7.7, LTX-6). A link
|
|
219
|
+
* whose origin (scheme, host and port) is one some shape is written on matches
|
|
220
|
+
* every path shape by its path and query, whatever origin the shape is on, so
|
|
221
|
+
* `leaf.estiva.app/issue/<slug>-<d>` is Ship's issue as `ship.estiva.app`'s is.
|
|
222
|
+
* A link on no declared origin matches nothing. A fragment route
|
|
223
|
+
* (`/#/issue/<d>`) matches only on its own origin, since no other app serves
|
|
224
|
+
* it, and so does a shape that names no kind.
|
|
225
|
+
* A match on the link's own origin wins whatever the specificity of others.
|
|
226
|
+
* On either side, when shapes claim the path for different kinds, the match
|
|
227
|
+
* carries all of them in `kinds`, and the reader's one-author rule decides.
|
|
228
|
+
* Pass the shapes of every manifest, each read through {@link urlPatternsOf}
|
|
229
|
+
* so that a manifest adds only its own origin.
|
|
190
230
|
*
|
|
191
|
-
*
|
|
192
|
-
* is §7.2 as amended, and it is the whole of the security story here: a
|
|
193
|
-
* consumer that matched on the trailing uuid alone would resolve any URL from
|
|
194
|
-
* anywhere as that app's object.
|
|
231
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-files-path-is-the-same-on-every-apps-host.md
|
|
195
232
|
*
|
|
196
233
|
* **A query parameter may carry the identity too** (FOL-38). Peek opens a
|
|
197
234
|
* thread as `/topic/<slug>-<d>?thread=<id>`: the path names the topic, the
|
|
@@ -211,14 +248,23 @@ const BLOCK_PLACEHOLDER = '<block>'
|
|
|
211
248
|
export function matchObjectUrl(url: string, patterns: UrlPattern[]): MatchedObjectUrl | null {
|
|
212
249
|
const target = splitUrl(url)
|
|
213
250
|
if (!target) return null
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
for (const { pattern, kind } of patterns) {
|
|
251
|
+
const origin = `${target.scheme}://${target.host}`
|
|
252
|
+
const shapes = patterns.flatMap(({ pattern, kind }) => {
|
|
217
253
|
const shape = splitUrl(pattern)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
254
|
+
return shape ? [{ shape, kind, own: `${shape.scheme}://${shape.host}` === origin }] : []
|
|
255
|
+
})
|
|
256
|
+
// A link on an origin no shape is written on names nothing, whatever its path.
|
|
257
|
+
if (!shapes.some(({ own }) => own)) return null
|
|
258
|
+
|
|
259
|
+
const onOwn: Candidate[] = []
|
|
260
|
+
const elsewhere: Candidate[] = []
|
|
261
|
+
for (const { shape, kind, own } of shapes) {
|
|
262
|
+
// A fragment route and a path route are different shapes, not one. Off its
|
|
263
|
+
// own origin a shape matches only as a path route that names its kind: no
|
|
264
|
+
// other app serves a fragment route, and a kindless shape would let any
|
|
265
|
+
// manifest turn every swapped link of its word into a bare `#d` lookup.
|
|
221
266
|
if (shape.fragmented !== target.fragmented) continue
|
|
267
|
+
if (!own && (shape.fragmented || kind === undefined)) continue
|
|
222
268
|
|
|
223
269
|
// The pattern's path up to its final segment: `/issue/` out of
|
|
224
270
|
// `/issue/<slug>-<d>`. Compared literally and at equal depth, so `/issues`
|
|
@@ -267,9 +313,51 @@ export function matchObjectUrl(url: string, patterns: UrlPattern[]): MatchedObje
|
|
|
267
313
|
// A filled `<block>` breaks a tie, so an app that declares the block shape
|
|
268
314
|
// beside its older shape loses no block to declaration order.
|
|
269
315
|
const specificity = declared.length * 2 + (block === undefined ? 0 : 1)
|
|
270
|
-
|
|
316
|
+
;(own ? onOwn : elsewhere).push({ specificity, match })
|
|
271
317
|
}
|
|
272
|
-
return
|
|
318
|
+
return onOwn.length > 0 ? chosen(onOwn) : chosen(elsewhere)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
interface Candidate {
|
|
322
|
+
specificity: number
|
|
323
|
+
match: MatchedObjectUrl
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* The match a link earns from the shapes that read it on one side: its own
|
|
328
|
+
* origin, or, when none does, the others.
|
|
329
|
+
*
|
|
330
|
+
* The most specific reading names the object. Its kind is not trusted alone:
|
|
331
|
+
* every shape that reads the same identity adds its kind, whatever its
|
|
332
|
+
* specificity and whatever order the manifests came in, so a second manifest
|
|
333
|
+
* that claims a word — with a `<block>` fragment the owner's shape lacks, say
|
|
334
|
+
* — can only widen the lookup, where the one-author rule turns the link plain.
|
|
335
|
+
* Two equally specific readings of different identities name nothing. A shape
|
|
336
|
+
* that names no kind (only ever on its own origin) leaves the kinds open.
|
|
337
|
+
*/
|
|
338
|
+
function chosen(candidates: Candidate[]): MatchedObjectUrl | null {
|
|
339
|
+
if (candidates.length === 0) return null
|
|
340
|
+
const top = Math.max(...candidates.map((c) => c.specificity))
|
|
341
|
+
const [first, ...rest] = candidates.filter((c) => c.specificity === top).map((c) => c.match)
|
|
342
|
+
if (rest.some((match) => identityOf(match) !== identityOf(first))) return null
|
|
343
|
+
|
|
344
|
+
const same = candidates.map((c) => c.match).filter((match) => identityOf(match) === identityOf(first))
|
|
345
|
+
const named: MatchedObjectUrl = { ...first }
|
|
346
|
+
delete named.kind
|
|
347
|
+
if (same.some((match) => match.kind === undefined)) return named
|
|
348
|
+
const kinds = [...new Set(same.map((match) => match.kind as number))].sort((a, b) => a - b)
|
|
349
|
+
return kinds.length === 1 ? { ...named, kind: kinds[0] } : { ...named, kinds }
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** What a match names, apart from its kind and block. */
|
|
353
|
+
function identityOf(match: MatchedObjectUrl): string {
|
|
354
|
+
return [match.by, match.identifier, match.within?.by ?? '', match.within?.identifier ?? ''].join(' ')
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** `scheme://host[:port]` of a URL or a pattern, lowercased; null when it has none. */
|
|
358
|
+
function originOfUrl(raw: string): string | null {
|
|
359
|
+
const parts = splitUrl(raw)
|
|
360
|
+
return parts ? `${parts.scheme}://${parts.host}` : null
|
|
273
361
|
}
|
|
274
362
|
|
|
275
363
|
/**
|
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
|
}
|