@estiva-app/interop 0.14.0 → 0.16.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 +115 -0
- package/README.md +60 -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 +164 -11
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +347 -13
- package/dist/projection.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/projection.ts +419 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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
|
@@ -29,6 +29,10 @@ export {
|
|
|
29
29
|
resolveForeignObject,
|
|
30
30
|
resolveForeignEvent,
|
|
31
31
|
resolveFolderProject,
|
|
32
|
+
resolveFolderContents,
|
|
33
|
+
listFolders,
|
|
34
|
+
KIND_FOLDER_STATE,
|
|
35
|
+
KIND_CHANNEL_METADATA,
|
|
32
36
|
commentKindsOf,
|
|
33
37
|
buildActionEvent,
|
|
34
38
|
pickWidget,
|
|
@@ -57,6 +61,8 @@ export {
|
|
|
57
61
|
type People,
|
|
58
62
|
type ForeignObject,
|
|
59
63
|
type FolderProject,
|
|
64
|
+
type FolderContents,
|
|
65
|
+
type FolderSummary,
|
|
60
66
|
type ResolvedSlot,
|
|
61
67
|
type ResolvedAction,
|
|
62
68
|
type ActionFormField,
|
package/src/projection.ts
CHANGED
|
@@ -556,6 +556,14 @@ function resolveActions(
|
|
|
556
556
|
return out
|
|
557
557
|
}
|
|
558
558
|
|
|
559
|
+
/**
|
|
560
|
+
* NIP-29 group metadata — the relay's own record for a channel.
|
|
561
|
+
*
|
|
562
|
+
* Named here because {@link folderOf} keys on it, and a bare `39000` in that
|
|
563
|
+
* one comparison would read as an app's kind rather than as the relay's.
|
|
564
|
+
*/
|
|
565
|
+
export const KIND_CHANNEL_METADATA = 39000
|
|
566
|
+
|
|
559
567
|
const tagValue = (e: SignedEvent, name: string) => e.tags.find((t) => t[0] === name)?.[1]
|
|
560
568
|
|
|
561
569
|
/**
|
|
@@ -569,20 +577,50 @@ const tagValue = (e: SignedEvent, name: string) => e.tags.find((t) => t[0] === n
|
|
|
569
577
|
* are the relay's and NIP-29's, so knowing them is not knowing what any app
|
|
570
578
|
* is.
|
|
571
579
|
*
|
|
572
|
-
* **0.13.0 had a third case and 0.14.0 withdrew it.** A
|
|
573
|
-
* `records.folder: "identifier"`, meaning *my objects
|
|
574
|
-
* Folder is the object's own `d`*.
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
580
|
+
* **0.13.0 had a third case as manifest vocabulary and 0.14.0 withdrew it.** A
|
|
581
|
+
* manifest could declare `records.folder: "identifier"`, meaning *my objects
|
|
582
|
+
* are containers, so the Folder is the object's own `d`*. The withdrawal was
|
|
583
|
+
* right and stands: its only instance was a Peek topic, RFC 0.5 §1 retires
|
|
584
|
+
* that shape, and a vocabulary field whose only instance is going away is one
|
|
585
|
+
* every future producer has to read and none can use.
|
|
586
|
+
*
|
|
587
|
+
* **What the withdrawal took with it was a working feature, and nothing
|
|
588
|
+
* noticed because nothing had declared the field yet** (INT-9). A channel
|
|
589
|
+
* record names no Folder by either tag above, so every write aimed at one is
|
|
590
|
+
* refused for having nowhere to go — which is why Peek can declare no action on
|
|
591
|
+
* a topic, four days after PRO-18 concluded a conversation had become
|
|
592
|
+
* declarable. Measured on production 2026-09-08: **0 of 40 `kind:39000` events
|
|
593
|
+
* carry `h` or `buzz-channel`, and 40 of 40 carry `d`.**
|
|
594
|
+
*
|
|
595
|
+
* So the third case comes back **as protocol rather than as vocabulary**, which
|
|
596
|
+
* is the distinction 0.14.0 was actually about. A `kind:39000` is NIP-29 group
|
|
597
|
+
* metadata, relay-signed, and its `d` *is* the channel id — buzz's `NOSTR.md`
|
|
598
|
+
* §"Group metadata" states it, `channel_info_from_event` reads it, and the
|
|
599
|
+
* relay's `h_grammar` is the same uuid. Nobody declares that and no producer
|
|
600
|
+
* can opt out of it, exactly like `h` and `buzz-channel` above. It asks nothing
|
|
601
|
+
* of any manifest, so it cannot be the field that every future producer reads
|
|
602
|
+
* and none can use.
|
|
603
|
+
*
|
|
604
|
+
* **It is the last of the three to fire, and it goes quiet on its own.** FOL-3
|
|
605
|
+
* makes a topic a file that carries an `h`; from that day the first clause
|
|
606
|
+
* answers and this one is unreachable. A shape retired by a model change should
|
|
607
|
+
* decay into dead code, not into a wrong answer — which is what the `??` order
|
|
608
|
+
* buys and what the "still resolves after FOL-3" test pins.
|
|
609
|
+
*
|
|
610
|
+
* Narrow on purpose: **`kind:39000` and nothing else.** Not "any addressable
|
|
611
|
+
* kind", which would hand every `30000`–`39999` record its own `d` as a Folder
|
|
612
|
+
* and put a consumer's write in a channel that may not exist. An addressable
|
|
613
|
+
* kind that is not the relay's channel record still answers `null` below, and a
|
|
614
|
+
* test holds that line.
|
|
615
|
+
*
|
|
616
|
+
* Returns `null` when nothing says — which is a real answer. An object with no
|
|
617
|
+
* Folder has nowhere for a write to go, and guessing at one publishes into
|
|
583
618
|
* somebody else's channel.
|
|
584
619
|
*/
|
|
585
620
|
export function folderOf(root: SignedEvent): string | null {
|
|
621
|
+
if (root.kind === KIND_CHANNEL_METADATA) {
|
|
622
|
+
return tagValue(root, 'h') ?? tagValue(root, 'buzz-channel') ?? tagValue(root, 'd') ?? null
|
|
623
|
+
}
|
|
586
624
|
return tagValue(root, 'h') ?? tagValue(root, 'buzz-channel') ?? null
|
|
587
625
|
}
|
|
588
626
|
|
|
@@ -2718,7 +2756,6 @@ export function buildActionEvent(args: {
|
|
|
2718
2756
|
const { manifest, kind, address, folder, actionId, value } = args
|
|
2719
2757
|
const records = manifest.records
|
|
2720
2758
|
const declared = manifest.actions?.find((a) => a.id === actionId)
|
|
2721
|
-
if (!records) return 'That app does not say how its records are written.'
|
|
2722
2759
|
if (!declared) return `This app does not offer "${actionId}".`
|
|
2723
2760
|
|
|
2724
2761
|
const appliesTo = Array.isArray(declared.appliesTo) ? declared.appliesTo : [declared.appliesTo]
|
|
@@ -2736,6 +2773,25 @@ export function buildActionEvent(args: {
|
|
|
2736
2773
|
return `"${declared.label}" takes a single value, not a form.`
|
|
2737
2774
|
}
|
|
2738
2775
|
|
|
2776
|
+
/*
|
|
2777
|
+
**A fold rule is needed to write a change, and only to write a change.**
|
|
2778
|
+
|
|
2779
|
+
This was the first line of the function, refusing every action of every app
|
|
2780
|
+
that declares no `records` — which read as a guard and was a gate on an
|
|
2781
|
+
unrelated feature. PRO-12 settled the principle on the read side: *"SPEC
|
|
2782
|
+
mandates `records`; the runtime correctly stopped requiring it."* The write
|
|
2783
|
+
side never followed, and the tags below are the only place it is used.
|
|
2784
|
+
|
|
2785
|
+
Found by INT-9 against production, and only there: Peek declares no fold
|
|
2786
|
+
rule, deliberately — *"a topic's name is a tag the relay wrote, and a
|
|
2787
|
+
message is immutable. A consumer that folded nothing would render both
|
|
2788
|
+
correctly."* So Peek's first action was refused with "That app does not say
|
|
2789
|
+
how its records are written", which is true, irrelevant, and impossible to
|
|
2790
|
+
act on. A creation reads nothing and folds nothing; there is nothing for a
|
|
2791
|
+
fold rule to say about it.
|
|
2792
|
+
*/
|
|
2793
|
+
if (!records) return 'That app does not say how its records are written.'
|
|
2794
|
+
|
|
2739
2795
|
// Validate against the manifest's own vocabulary. The owning app cannot
|
|
2740
2796
|
// enforce this — anyone can publish anything (RFC_UPDATES.md §3) — so a
|
|
2741
2797
|
// consumer that skips the check is the one putting junk in the shared record.
|
|
@@ -2798,3 +2854,354 @@ export function resolveFolderProjectSlotsForTest(
|
|
|
2798
2854
|
if (!projection) return undefined
|
|
2799
2855
|
return resolveSlots(projection, root, {}, manifest).slots.title?.value
|
|
2800
2856
|
}
|
|
2857
|
+
|
|
2858
|
+
// ── The folder read model — RFC 0.4 §4 and §5 ───────────────────────────────
|
|
2859
|
+
|
|
2860
|
+
/**
|
|
2861
|
+
* The Folder as the relay maintains it — RFC 0.4 §12.1.
|
|
2862
|
+
*
|
|
2863
|
+
* Relay-signed, addressable, and **global**. §4.2 is worth reading before
|
|
2864
|
+
* changing that last word: three of the four properties a folder must have are
|
|
2865
|
+
* impossible if its state carries an `h`, because `h` files it under a channel
|
|
2866
|
+
* and gates reads by access. Exploring folders you are not in, following one,
|
|
2867
|
+
* and a file having one home while being referenced from elsewhere all need an
|
|
2868
|
+
* address that resolves without membership. So the channel keeps doing access
|
|
2869
|
+
* and conversation, and the folder becomes a layer above it.
|
|
2870
|
+
*
|
|
2871
|
+
* **Read-only here.** A client changes a folder by publishing a `kind:1852`
|
|
2872
|
+
* command and the relay emits the new state (§4.1). A folder is not a
|
|
2873
|
+
* user-signed event because NIP-01 addressable events are single-signer by
|
|
2874
|
+
* construction — the address is `(pubkey, kind, d)`, so a second person adding
|
|
2875
|
+
* a file would not replace your folder, they would create a different one.
|
|
2876
|
+
*/
|
|
2877
|
+
export const KIND_FOLDER_STATE = 30890
|
|
2878
|
+
|
|
2879
|
+
/**
|
|
2880
|
+
* NIP-29 group metadata — the Folder's channel.
|
|
2881
|
+
*
|
|
2882
|
+
* Named here for two unrelated jobs: it carries the folder's `name` before any
|
|
2883
|
+
* folder state exists, and its own address is what makes a Peek topic a file
|
|
2884
|
+
* like any other (§5.2).
|
|
2885
|
+
*/
|
|
2886
|
+
const KIND_CHANNEL = 39000
|
|
2887
|
+
|
|
2888
|
+
/** The `name` tag, when there is an event to read it off at all. */
|
|
2889
|
+
const nameOf = (event: SignedEvent | undefined) => (event ? tagValue(event, 'name') : undefined)
|
|
2890
|
+
|
|
2891
|
+
/** One folder, enough to draw a sidebar row. */
|
|
2892
|
+
export interface FolderSummary {
|
|
2893
|
+
/**
|
|
2894
|
+
* The folder's uuid. **One uuid, three roles** — the channel id, the `h` on
|
|
2895
|
+
* everything in it, and the `d` on both its `39000` and its `30890` (§5.2,
|
|
2896
|
+
* measured across all of production's channels).
|
|
2897
|
+
*/
|
|
2898
|
+
id: string
|
|
2899
|
+
name?: string
|
|
2900
|
+
/** True once the relay maintains state for it, rather than it being a bare channel. */
|
|
2901
|
+
hasState: boolean
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
/** A folder and everything in it, each file drawn through its owner's manifest. */
|
|
2905
|
+
export interface FolderContents extends FolderSummary {
|
|
2906
|
+
/** The folder state's address, absent until a state event exists. */
|
|
2907
|
+
address?: string
|
|
2908
|
+
/**
|
|
2909
|
+
* The files this folder holds.
|
|
2910
|
+
*
|
|
2911
|
+
* **Peers by construction, not by special case.** A Peek topic and a Ship
|
|
2912
|
+
* project sit side by side because both are `a` tags in one list, and §5.2's
|
|
2913
|
+
* finding is exactly that one tag type is enough to name either: a channel
|
|
2914
|
+
* turned out to be addressable after all, so a topic needs no wrapper and no
|
|
2915
|
+
* second mechanism. Nothing in this function knows what either app is.
|
|
2916
|
+
*
|
|
2917
|
+
* Ordered as the folder lists them. A file that resolved to nothing is
|
|
2918
|
+
* **absent rather than marked** — see {@link resolveFolderContents}.
|
|
2919
|
+
*/
|
|
2920
|
+
files: ForeignObject[]
|
|
2921
|
+
/**
|
|
2922
|
+
* Where the list came from, because the two are not equivalent.
|
|
2923
|
+
*
|
|
2924
|
+
* `state` is the model. `channel` is the approximation available before a
|
|
2925
|
+
* folder has any state: containment inferred from `h`, which can list an
|
|
2926
|
+
* app's records and **can never list a topic**, because under `h` the topic
|
|
2927
|
+
* *is* the container rather than a thing inside it. A consumer that needs to
|
|
2928
|
+
* explain a short list is reading this field.
|
|
2929
|
+
*/
|
|
2930
|
+
source: 'state' | 'channel'
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
/**
|
|
2934
|
+
* Every folder this identity can see, for a sidebar.
|
|
2935
|
+
*
|
|
2936
|
+
* Both shapes in one pass: folders the relay maintains state for, and bare
|
|
2937
|
+
* channels that have none yet. A channel with state appears once, named by its
|
|
2938
|
+
* state — the folder's name is the folder's to say.
|
|
2939
|
+
*
|
|
2940
|
+
* **A direct route, deliberately.** §4.2's post-mortem on REW-11 is that
|
|
2941
|
+
* discovering children only through their parent loses them when the parent
|
|
2942
|
+
* goes; a sidebar built by walking something else would inherit exactly that.
|
|
2943
|
+
* This asks for folders by kind.
|
|
2944
|
+
*/
|
|
2945
|
+
export async function listFolders(query: QueryFn): Promise<FolderSummary[]> {
|
|
2946
|
+
const events = await query([
|
|
2947
|
+
{ kinds: [KIND_FOLDER_STATE], limit: 500 },
|
|
2948
|
+
{ kinds: [KIND_CHANNEL], limit: 500 },
|
|
2949
|
+
])
|
|
2950
|
+
const byId = new Map<string, FolderSummary>()
|
|
2951
|
+
for (const event of events) {
|
|
2952
|
+
const id = tagValue(event, 'd')
|
|
2953
|
+
if (!id) continue
|
|
2954
|
+
const state = event.kind === KIND_FOLDER_STATE
|
|
2955
|
+
const existing = byId.get(id)
|
|
2956
|
+
// State wins over the channel for the name, whichever order they arrived.
|
|
2957
|
+
if (existing && !state) continue
|
|
2958
|
+
byId.set(id, {
|
|
2959
|
+
id,
|
|
2960
|
+
name: tagValue(event, 'name') ?? existing?.name,
|
|
2961
|
+
hasState: state || (existing?.hasState ?? false),
|
|
2962
|
+
})
|
|
2963
|
+
}
|
|
2964
|
+
return [...byId.values()].sort((a, b) => (a.name ?? a.id).localeCompare(b.name ?? b.id))
|
|
2965
|
+
}
|
|
2966
|
+
|
|
2967
|
+
/**
|
|
2968
|
+
* Everything in one folder, resolved through the manifests of the apps that own it.
|
|
2969
|
+
*
|
|
2970
|
+
* The cross-app read the whole model rests on: given a folder id, list its
|
|
2971
|
+
* files whatever kind they are and whoever wrote them, so two apps drawing the
|
|
2972
|
+
* same folder show the same things. Both apps consume this rather than either
|
|
2973
|
+
* one owning it.
|
|
2974
|
+
*
|
|
2975
|
+
* ## A file the reader cannot see is absent, not "unavailable"
|
|
2976
|
+
*
|
|
2977
|
+
* The one rule here that is a product decision rather than a mechanism, and a
|
|
2978
|
+
* deliberate divergence from upstream's NIP-MP, whose fold requires the
|
|
2979
|
+
* opposite for public repositories. **The count is the disclosure**: a folder
|
|
2980
|
+
* that renders three rows and two greyed-out placeholders has told an outsider
|
|
2981
|
+
* how much they are missing, which for a folder named after a person is the
|
|
2982
|
+
* sensitive part. So an address that resolves to nothing is dropped, and
|
|
2983
|
+
* nothing in the return value counts what was dropped.
|
|
2984
|
+
*
|
|
2985
|
+
* This is why the batch below cannot use {@link resolveForeignObject}
|
|
2986
|
+
* unchanged: that returns `unreachable: true` so an inline reference can say
|
|
2987
|
+
* "you may not have access", which is right for one pasted link and wrong for
|
|
2988
|
+
* a list.
|
|
2989
|
+
*
|
|
2990
|
+
* ## Round trips do not grow with the folder
|
|
2991
|
+
*
|
|
2992
|
+
* **Flat in the number of files, linear in the number of apps.** The folder
|
|
2993
|
+
* itself, the handler sweep, the contents, one query for every root at once
|
|
2994
|
+
* and every change with it, and one for the people — then two more per
|
|
2995
|
+
* distinct `(kind, author)` for NIP-89 discovery, which {@link ProjectionCache}
|
|
2996
|
+
* memoises away.
|
|
2997
|
+
*
|
|
2998
|
+
* Measured against production, reading three folders through one cache:
|
|
2999
|
+
*
|
|
3000
|
+
* | folder | files | cold | warm |
|
|
3001
|
+
* | --- | --- | --- | --- |
|
|
3002
|
+
* | Shared foundation packages | 24 | 11 | 5 |
|
|
3003
|
+
* | Feedback on Peek | 25 | 9 | 5 |
|
|
3004
|
+
* | Folders | 9 | 6 | 4 |
|
|
3005
|
+
*
|
|
3006
|
+
* Twenty-five files and nine cost the same warm, which is the property worth
|
|
3007
|
+
* having. A resolve per file would have been four *each* against a relay that
|
|
3008
|
+
* meters reads at 300 a minute — a folder of twenty-five would not have loaded.
|
|
3009
|
+
*/
|
|
3010
|
+
export async function resolveFolderContents(
|
|
3011
|
+
folder: string,
|
|
3012
|
+
query: QueryFn,
|
|
3013
|
+
/** Defaults to asking the relay. The browser passes a cached lookup. */
|
|
3014
|
+
lookupPeople?: PeopleFn,
|
|
3015
|
+
/** See {@link ProjectionCache}. Omitting it is exactly the old behaviour. */
|
|
3016
|
+
cache?: ProjectionCache,
|
|
3017
|
+
): Promise<FolderContents> {
|
|
3018
|
+
// 1. The folder itself. Both kinds in one trip: the state is the model and
|
|
3019
|
+
// the channel is what names a folder that has none yet.
|
|
3020
|
+
const identity = await query([
|
|
3021
|
+
{ kinds: [KIND_FOLDER_STATE], '#d': [folder], limit: 1 },
|
|
3022
|
+
{ kinds: [KIND_CHANNEL], '#d': [folder], limit: 1 },
|
|
3023
|
+
])
|
|
3024
|
+
const state = identity.find((e) => e.kind === KIND_FOLDER_STATE && tagValue(e, 'd') === folder)
|
|
3025
|
+
const channel = identity.find((e) => e.kind === KIND_CHANNEL && tagValue(e, 'd') === folder)
|
|
3026
|
+
|
|
3027
|
+
const summary: FolderSummary & { address?: string } = {
|
|
3028
|
+
id: folder,
|
|
3029
|
+
name: nameOf(state) ?? nameOf(channel),
|
|
3030
|
+
hasState: !!state,
|
|
3031
|
+
...(state
|
|
3032
|
+
? { address: pointerToAddress({ kind: state.kind, pubkey: state.pubkey, identifier: folder, relays: [] }) }
|
|
3033
|
+
: {}),
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
const addresses = state
|
|
3037
|
+
? // §5.2: one tag type lists every file, topics included, with no special
|
|
3038
|
+
// case. The order is the folder's, so it is preserved rather than sorted.
|
|
3039
|
+
[...new Set(state.tags.filter((t) => t[0] === 'a' && t[1]).map((t) => t[1]))]
|
|
3040
|
+
: await addressesByContainment(folder, query)
|
|
3041
|
+
|
|
3042
|
+
if (addresses.length === 0) {
|
|
3043
|
+
return { ...summary, files: [], source: state ? 'state' : 'channel' }
|
|
3044
|
+
}
|
|
3045
|
+
|
|
3046
|
+
// 2. Group by (kind, author): one manifest answers for every file an app owns
|
|
3047
|
+
// in this folder, and the cache makes the second folder free.
|
|
3048
|
+
const pointers = addresses.flatMap((address) => {
|
|
3049
|
+
try {
|
|
3050
|
+
return [{ address, pointer: referenceToPointer(address) }]
|
|
3051
|
+
} catch {
|
|
3052
|
+
// An `a` tag nothing can parse is somebody else's bug and not worth a
|
|
3053
|
+
// whole folder. Dropped like any other unresolvable file.
|
|
3054
|
+
return []
|
|
3055
|
+
}
|
|
3056
|
+
})
|
|
3057
|
+
const groups = new Map<string, { pointer: AddressPointer; addresses: string[] }>()
|
|
3058
|
+
for (const { address, pointer } of pointers) {
|
|
3059
|
+
const key = `${pointer.kind}:${pointer.pubkey}`
|
|
3060
|
+
const group = groups.get(key)
|
|
3061
|
+
if (group) group.addresses.push(address)
|
|
3062
|
+
else groups.set(key, { pointer, addresses: [address] })
|
|
3063
|
+
}
|
|
3064
|
+
|
|
3065
|
+
const manifests = new Map<string, ResolvedManifest>()
|
|
3066
|
+
await Promise.all(
|
|
3067
|
+
[...groups].map(async ([key, { pointer }]) => {
|
|
3068
|
+
const resolved = await resolveManifest(pointer, query, cache)
|
|
3069
|
+
if (resolved) manifests.set(key, resolved)
|
|
3070
|
+
}),
|
|
3071
|
+
)
|
|
3072
|
+
|
|
3073
|
+
// 3. Every root, and every change against every address, in two filters.
|
|
3074
|
+
// Change kinds are a set because two apps may fold differently, and a kind
|
|
3075
|
+
// is a u16 — the relay refuses an out-of-range one outright, so an app
|
|
3076
|
+
// declaring no `records` contributes no filter rather than an empty one.
|
|
3077
|
+
const changeKinds = [
|
|
3078
|
+
...new Set(
|
|
3079
|
+
[...manifests.values()].flatMap((r) => (r.manifest.records ? [r.manifest.records.changeKind] : [])),
|
|
3080
|
+
),
|
|
3081
|
+
]
|
|
3082
|
+
const events = await query([
|
|
3083
|
+
...[...groups.values()].map(({ pointer, addresses: group }) => ({
|
|
3084
|
+
kinds: [pointer.kind],
|
|
3085
|
+
authors: [pointer.pubkey],
|
|
3086
|
+
'#d': group.map((a) => referenceToPointer(a).identifier),
|
|
3087
|
+
limit: group.length,
|
|
3088
|
+
})),
|
|
3089
|
+
...(changeKinds.length
|
|
3090
|
+
? [{ kinds: changeKinds, '#a': addresses, limit: 500 }]
|
|
3091
|
+
: []),
|
|
3092
|
+
])
|
|
3093
|
+
|
|
3094
|
+
// 4. Build each file, in the order the folder listed them.
|
|
3095
|
+
const files: ForeignObject[] = []
|
|
3096
|
+
for (const { address, pointer } of pointers) {
|
|
3097
|
+
const resolved = manifests.get(`${pointer.kind}:${pointer.pubkey}`)
|
|
3098
|
+
// No app claims this kind, so there is no projection to draw it with.
|
|
3099
|
+
if (!resolved) continue
|
|
3100
|
+
const projection = resolved.manifest.projections?.[String(pointer.kind)]
|
|
3101
|
+
if (!projection) continue
|
|
3102
|
+
const root = events.find(
|
|
3103
|
+
(e) => e.kind === pointer.kind && e.pubkey === pointer.pubkey && tagValue(e, 'd') === pointer.identifier,
|
|
3104
|
+
)
|
|
3105
|
+
// The disclosure rule. Absent, not "unavailable".
|
|
3106
|
+
if (!root) continue
|
|
3107
|
+
|
|
3108
|
+
const records = foldRuleOf(resolved.manifest)
|
|
3109
|
+
const folded = foldChanges(
|
|
3110
|
+
events.filter((e) => e.kind === records.changeKind && hasTagValue(e, records.targetTag, address)),
|
|
3111
|
+
records,
|
|
3112
|
+
)
|
|
3113
|
+
// An app hiding a record from its own lists is saying it is not part of the
|
|
3114
|
+
// folder any more. `hiddenWhen` is the app's own declaration of that.
|
|
3115
|
+
if (records.hiddenWhen && folded[records.hiddenWhen.field]?.value === records.hiddenWhen.equals) {
|
|
3116
|
+
continue
|
|
3117
|
+
}
|
|
3118
|
+
files.push(
|
|
3119
|
+
buildObject({
|
|
3120
|
+
root,
|
|
3121
|
+
pointer,
|
|
3122
|
+
manifest: resolved.manifest,
|
|
3123
|
+
projection,
|
|
3124
|
+
folded,
|
|
3125
|
+
viaRecommendation: resolved.viaRecommendation,
|
|
3126
|
+
webTemplate: resolved.webTemplate,
|
|
3127
|
+
}),
|
|
3128
|
+
)
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
const people = await (lookupPeople ?? peopleViaRelay(query))([
|
|
3132
|
+
...new Set(files.flatMap(pubkeysIn)),
|
|
3133
|
+
])
|
|
3134
|
+
return {
|
|
3135
|
+
...summary,
|
|
3136
|
+
files: files.map((file) => ({ ...file, people })),
|
|
3137
|
+
source: state ? 'state' : 'channel',
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3141
|
+
/**
|
|
3142
|
+
* The contents of a folder that has no state event — containment by `h`.
|
|
3143
|
+
*
|
|
3144
|
+
* **The approximation, and it is worth being precise about what it cannot do.**
|
|
3145
|
+
* Before folder state exists, the only thing on the wire saying a file is in a
|
|
3146
|
+
* folder is the file's own `h` (or `buzz-channel`, for a record published
|
|
3147
|
+
* globally — {@link folderOf} has both spellings and why). That lists an app's
|
|
3148
|
+
* records perfectly well and **cannot list a topic**: under `h` the topic is
|
|
3149
|
+
* the container, so it would have to be inside itself.
|
|
3150
|
+
*
|
|
3151
|
+
* Kept because both wire shapes coexist permanently — no migration is
|
|
3152
|
+
* available, and a reader that only understood folder state would show every
|
|
3153
|
+
* folder on production as empty.
|
|
3154
|
+
*
|
|
3155
|
+
* Two filters rather than one: an `#h` query does not return a record placed
|
|
3156
|
+
* globally, and reading only `h` was what made five of Ship's fifteen projects
|
|
3157
|
+
* unactionable before `folderOf` existed.
|
|
3158
|
+
*/
|
|
3159
|
+
async function addressesByContainment(folder: string, query: QueryFn): Promise<string[]> {
|
|
3160
|
+
// Which kinds could be files? Every kind any app declares a projection for.
|
|
3161
|
+
// The only non-app-specific source for a kind number is a published manifest.
|
|
3162
|
+
const handlers = await query([{ kinds: [KIND_HANDLER_INFORMATION], limit: 50 }])
|
|
3163
|
+
const kinds = [
|
|
3164
|
+
...new Set(
|
|
3165
|
+
handlers.flatMap((event) =>
|
|
3166
|
+
Object.keys(parseManifest(event)?.projections ?? {}).map(Number).filter(Number.isFinite),
|
|
3167
|
+
),
|
|
3168
|
+
),
|
|
3169
|
+
]
|
|
3170
|
+
if (kinds.length === 0) return []
|
|
3171
|
+
|
|
3172
|
+
const held = await query([
|
|
3173
|
+
{ '#h': [folder], kinds, limit: 500 },
|
|
3174
|
+
{ '#buzz-channel': [folder], kinds, limit: 500 },
|
|
3175
|
+
])
|
|
3176
|
+
return [
|
|
3177
|
+
...new Set(
|
|
3178
|
+
held
|
|
3179
|
+
.filter((event) => {
|
|
3180
|
+
const d = tagValue(event, 'd')
|
|
3181
|
+
/*
|
|
3182
|
+
Two exclusions, and both are about what a file *is*.
|
|
3183
|
+
|
|
3184
|
+
**A file is addressable** — RFC 0.4 §5, "anything with an address
|
|
3185
|
+
that a folder can list". A `kind:9` message carries no `d`, so it
|
|
3186
|
+
has no address, so it is conversation rather than contents. That is
|
|
3187
|
+
the whole discriminator and it needs no kind numbers.
|
|
3188
|
+
|
|
3189
|
+
**A folder is not a file inside itself.** A channel's own `39000`
|
|
3190
|
+
comes back from an `#h` query for that channel — the relay scopes a
|
|
3191
|
+
discovery event to the channel it describes, so it arrives with the
|
|
3192
|
+
contents. What marks it out is that its `d` *is* the folder uuid.
|
|
3193
|
+
*/
|
|
3194
|
+
return d !== undefined && d !== folder
|
|
3195
|
+
})
|
|
3196
|
+
.sort((a, b) => b.created_at - a.created_at)
|
|
3197
|
+
.map((event) =>
|
|
3198
|
+
pointerToAddress({
|
|
3199
|
+
kind: event.kind,
|
|
3200
|
+
pubkey: event.pubkey,
|
|
3201
|
+
identifier: tagValue(event, 'd') ?? '',
|
|
3202
|
+
relays: [],
|
|
3203
|
+
}),
|
|
3204
|
+
),
|
|
3205
|
+
),
|
|
3206
|
+
]
|
|
3207
|
+
}
|