@estiva-app/interop 0.107.0 → 0.108.1
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 +13 -0
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +14 -3
- package/dist/fields.js.map +1 -1
- package/dist/projection.d.ts +31 -0
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +6 -3
- package/dist/projection.js.map +1 -1
- package/package.json +2 -1
- package/src/fields.ts +14 -3
- package/src/projection.ts +6 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.108.1",
|
|
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",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@estiva-app/conversation": ">=0.34.0",
|
|
55
55
|
"@estiva-app/protocol": ">=0.60.0",
|
|
56
|
+
"fast-check": "4.10.2",
|
|
56
57
|
"typescript": "~5.9.3"
|
|
57
58
|
}
|
|
58
59
|
}
|
package/src/fields.ts
CHANGED
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
type UnsignedEvent,
|
|
33
33
|
} from '@estiva-app/protocol'
|
|
34
34
|
import { refusalCode } from './folders.js'
|
|
35
|
-
import {
|
|
35
|
+
import { SUMMARY_FIELD, inTargetFolder, targetFolders, type QueryFn } from './projection.js'
|
|
36
36
|
|
|
37
37
|
/** The change event every Estiva app writes (SPEC §6.2). */
|
|
38
38
|
const KIND_CHANGE = 1851
|
|
@@ -113,7 +113,11 @@ export function filesOf(events: readonly SignedEvent[], options: { withText?: bo
|
|
|
113
113
|
if (event.kind === KIND_CHANGE || tagValue(event, 'd') === undefined) continue
|
|
114
114
|
const address = addressOfRoot(event)
|
|
115
115
|
const held = roots.get(address)
|
|
116
|
-
|
|
116
|
+
// Two versions of one record: the later `created_at`, then the lower id (§6.3, NIP-01), so
|
|
117
|
+
// the file is the same whichever version arrived first, and the same as `projectEvents` reads.
|
|
118
|
+
if (!held || event.created_at > held.created_at || (event.created_at === held.created_at && event.id < held.id)) {
|
|
119
|
+
roots.set(address, event)
|
|
120
|
+
}
|
|
117
121
|
}
|
|
118
122
|
const files = new Map<string, FileFields>()
|
|
119
123
|
for (const [address, root] of roots) files.set(address, { root, address, fields: {}, events: [root] })
|
|
@@ -124,9 +128,16 @@ export function filesOf(events: readonly SignedEvent[], options: { withText?: bo
|
|
|
124
128
|
if (!file) continue
|
|
125
129
|
const O = tagValue(event, 'O')
|
|
126
130
|
if (O !== undefined && O !== tagValue(file.root, 'd')) continue
|
|
127
|
-
|
|
131
|
+
// A root that names no team cannot be checked, and §6.2 folds its changes
|
|
132
|
+
// as before — but never a summary (§6.12) or a delete (§6.5), which need a
|
|
133
|
+
// team. `projectEvents` reads them the same way, by the same check; this
|
|
134
|
+
// read dropped every such change, so a renamed bare file listed its first
|
|
135
|
+
// title (TES-2).
|
|
136
|
+
const folders = targetFolders(file.root)
|
|
137
|
+
if (!inTargetFolder(event, folders)) continue
|
|
128
138
|
for (const set of fieldsSetBy(event)) {
|
|
129
139
|
if (set.field === TEXT_FIELD && !options.withText) continue
|
|
140
|
+
if (!folders && (set.field === SUMMARY_FIELD || set.field === DELETED_FIELD)) continue
|
|
130
141
|
const held = file.fields[set.field]
|
|
131
142
|
if (held && !newer(event, held.event)) continue
|
|
132
143
|
file.fields[set.field] = { ...set, id: event.id, pubkey: event.pubkey, at: changedAt(event), event }
|
package/src/projection.ts
CHANGED
|
@@ -2385,7 +2385,7 @@ type FoldedField = { value: string; format?: ContentFormat; stage?: Stage }
|
|
|
2385
2385
|
*
|
|
2386
2386
|
* Built once per root, and asked once per change.
|
|
2387
2387
|
*/
|
|
2388
|
-
function targetFolders(root: SignedEvent | undefined): ReadonlySet<string> | undefined {
|
|
2388
|
+
export function targetFolders(root: SignedEvent | undefined): ReadonlySet<string> | undefined {
|
|
2389
2389
|
if (!root) return undefined
|
|
2390
2390
|
const folders = new Set(PLACEMENTS.flatMap((name) => root.tags.filter((t) => t[0] === name && t[1]).map((t) => t[1]!)))
|
|
2391
2391
|
if (root.kind === KIND_CHANNEL_METADATA) {
|
|
@@ -2395,7 +2395,7 @@ function targetFolders(root: SignedEvent | undefined): ReadonlySet<string> | und
|
|
|
2395
2395
|
return folders.size ? folders : undefined
|
|
2396
2396
|
}
|
|
2397
2397
|
|
|
2398
|
-
function inTargetFolder(change: SignedEvent, folders: ReadonlySet<string> | undefined): boolean {
|
|
2398
|
+
export function inTargetFolder(change: SignedEvent, folders: ReadonlySet<string> | undefined): boolean {
|
|
2399
2399
|
if (!folders) return true
|
|
2400
2400
|
// The first `h` with a value, as the relay reads it: an empty `["h"]` ahead
|
|
2401
2401
|
// of a real one must not make this read a different Folder from the one the
|
|
@@ -2595,7 +2595,10 @@ function archiveOf(
|
|
|
2595
2595
|
root: SignedEvent | undefined,
|
|
2596
2596
|
folderAdmins?: ReadonlySet<string>,
|
|
2597
2597
|
): Archive | undefined {
|
|
2598
|
-
|
|
2598
|
+
// The `d` is everything after the pubkey: an id may hold a colon, and cutting
|
|
2599
|
+
// it there dropped every archive whose `O` named the whole id (TES-2).
|
|
2600
|
+
const [kind, , ...rest] = address.split(':')
|
|
2601
|
+
const identifier = rest.join(':')
|
|
2599
2602
|
if (Number(kind) === KIND_CHANNEL) {
|
|
2600
2603
|
if (!folderAdmins?.size) return undefined
|
|
2601
2604
|
changes = changes.filter((change) => tagValue(change, 'h') === identifier && folderAdmins.has(change.pubkey))
|