@estiva-app/interop 0.79.0 → 0.81.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 +28 -0
- package/dist/folders.d.ts +22 -0
- package/dist/folders.d.ts.map +1 -1
- package/dist/folders.js +20 -1
- package/dist/folders.js.map +1 -1
- 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 +25 -0
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +51 -23
- package/dist/projection.js.map +1 -1
- package/package.json +3 -3
- package/src/folders.ts +34 -3
- package/src/index.ts +1 -0
- package/src/projection.ts +73 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.81.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",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@estiva-app/conversation": ">=0.27.0",
|
|
51
|
-
"@estiva-app/protocol": ">=0.
|
|
51
|
+
"@estiva-app/protocol": ">=0.52.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@estiva-app/conversation": ">=0.27.0",
|
|
55
|
-
"@estiva-app/protocol": ">=0.
|
|
55
|
+
"@estiva-app/protocol": ">=0.52.0",
|
|
56
56
|
"typescript": "~5.9.3"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/src/folders.ts
CHANGED
|
@@ -165,6 +165,23 @@ export function planPlaceFile(
|
|
|
165
165
|
return [buildFolderCommand(pubkey, createdAtMs, { folder: args.folder, op: 'add', addresses: [listedAs(args.address, args.inOrder)] })]
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Mark a topic one of a team's spaces, or take the mark off: one `kind:1852
|
|
170
|
+
* add` naming it, with the `space` role or without it (§3.3). An `add` naming
|
|
171
|
+
* an entry already listed replaces its role. Only the team's members may send
|
|
172
|
+
* it; the relay refuses anyone else, and a topic another team lists.
|
|
173
|
+
*
|
|
174
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-space-is-the-teams-own-mark-on-a-topic-it-lists.md
|
|
175
|
+
*/
|
|
176
|
+
export function planMarkSpace(
|
|
177
|
+
pubkey: string,
|
|
178
|
+
createdAtMs: number,
|
|
179
|
+
args: { team: string; address: string; space: boolean; inOrder?: readonly string[] },
|
|
180
|
+
): UnsignedEvent {
|
|
181
|
+
const entry = listedAs(args.address, args.inOrder)
|
|
182
|
+
return buildFolderCommand(pubkey, createdAtMs, { folder: args.team, op: 'add', addresses: [entry], spaces: args.space ? [entry] : [] })
|
|
183
|
+
}
|
|
184
|
+
|
|
168
185
|
/**
|
|
169
186
|
* How a command names a file: by its id once the relay keeps its type in
|
|
170
187
|
* order (`RelayFileReads.inOrder`, §3.3 "lists by `o` once every app reading
|
|
@@ -402,13 +419,18 @@ export function listedBeneath<T extends MovableFile>(listing: readonly T[], file
|
|
|
402
419
|
*
|
|
403
420
|
* A move to the same Folder, or of a set the source does not list, plans nothing.
|
|
404
421
|
*
|
|
422
|
+
* **A space's mark does not travel.** The target's entry for the file carries
|
|
423
|
+
* the `space` role only with `keepSpace` — the mover ticked "Keep it a space
|
|
424
|
+
* in <team>" — and only the file itself, never one listed beneath it (§3.3).
|
|
425
|
+
*
|
|
405
426
|
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/moving-a-file-never-changes-who-can-read-it.md
|
|
406
427
|
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-topic-always-has-a-team-and-moves-in-one-action.md
|
|
428
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-space-is-the-teams-own-mark-on-a-topic-it-lists.md
|
|
407
429
|
*/
|
|
408
430
|
export function planMoveFile(
|
|
409
431
|
pubkey: string,
|
|
410
432
|
createdAtMs: number,
|
|
411
|
-
args: { file: MovableFile; from: FolderRef; to: FolderRef; listing: readonly MovableFile[] | null },
|
|
433
|
+
args: { file: MovableFile; from: FolderRef; to: FolderRef; listing: readonly MovableFile[] | null; keepSpace?: boolean },
|
|
412
434
|
): MovePlan {
|
|
413
435
|
if (args.from.id === args.to.id) return { ok: true, events: [], moved: [] }
|
|
414
436
|
if (!args.from.hasState) return { ok: false, reason: 'source-has-no-state' }
|
|
@@ -421,9 +443,10 @@ export function planMoveFile(
|
|
|
421
443
|
if (args.to.private && moving.some((candidate) => candidate.scopedTo !== args.to.id)) return { ok: false, reason: 'target-is-private' }
|
|
422
444
|
const moved = [...new Set(moving.map((candidate) => candidate.address!))]
|
|
423
445
|
if (!moved.length) return { ok: true, events: [], moved }
|
|
446
|
+
const kept = args.keepSpace && file.address && moved.includes(file.address) ? [file.address] : []
|
|
424
447
|
return {
|
|
425
448
|
ok: true,
|
|
426
|
-
events: [buildFolderCommand(pubkey, createdAtMs, { folder: args.to.id, op: 'move', from: args.from.id, addresses: moved })],
|
|
449
|
+
events: [buildFolderCommand(pubkey, createdAtMs, { folder: args.to.id, op: 'move', from: args.from.id, addresses: moved, spaces: kept })],
|
|
427
450
|
moved,
|
|
428
451
|
}
|
|
429
452
|
}
|
|
@@ -480,7 +503,14 @@ export type MoveFromFoldersPlan =
|
|
|
480
503
|
export function planMoveFromFolders(
|
|
481
504
|
pubkey: string,
|
|
482
505
|
createdAtMs: number,
|
|
483
|
-
args: {
|
|
506
|
+
args: {
|
|
507
|
+
file: MovableFile
|
|
508
|
+
from: readonly FolderRef[]
|
|
509
|
+
to: FolderRef
|
|
510
|
+
listings: ReadonlyMap<string, readonly MovableFile[] | null>
|
|
511
|
+
/** The mover ticked "Keep it a space in <team>": the target's entry for the file carries the `space` role ({@link planMoveFile}). */
|
|
512
|
+
keepSpace?: boolean
|
|
513
|
+
},
|
|
484
514
|
): MoveFromFoldersPlan {
|
|
485
515
|
const { file, to } = args
|
|
486
516
|
const sources = args.from.filter((folder) => folder.id !== to.id)
|
|
@@ -497,6 +527,7 @@ export function planMoveFromFolders(
|
|
|
497
527
|
to,
|
|
498
528
|
// By its address, so the walk finds what the listing draws beneath it.
|
|
499
529
|
listing: unresolved ? [{ ...file, ref: file.address! }, ...listing] : listing,
|
|
530
|
+
keepSpace: args.keepSpace,
|
|
500
531
|
})
|
|
501
532
|
if (!plan.ok) return plan
|
|
502
533
|
for (const address of plan.moved) moved.add(address)
|
package/src/index.ts
CHANGED
package/src/projection.ts
CHANGED
|
@@ -6499,6 +6499,19 @@ export async function listFolders(
|
|
|
6499
6499
|
* records alone were 0.9 s.
|
|
6500
6500
|
*/
|
|
6501
6501
|
recordChannels?: boolean
|
|
6502
|
+
/**
|
|
6503
|
+
* The relay offers the list read (NIP-11 `file_list`, `relayFileReadsOf`'s
|
|
6504
|
+
* `list`): each listed file is read as its first record and its fields'
|
|
6505
|
+
* current changes (§6.13), so finding which are archived costs about a
|
|
6506
|
+
* change a field instead of every change ever made to them, a text save
|
|
6507
|
+
* being a whole document. A deleted file is not in that answer, so its
|
|
6508
|
+
* channel is neither placed nor archived with it. Only where the relay advertises it: one that does
|
|
6509
|
+
* not answers the read as a plain one, with no changes at all.
|
|
6510
|
+
*
|
|
6511
|
+
* Measured on production 29 Oct: 25.7 MB of a cold Ship load was every
|
|
6512
|
+
* change to every project, read here and by Ship's own load (ALO-5).
|
|
6513
|
+
*/
|
|
6514
|
+
listRead?: boolean
|
|
6502
6515
|
} = {},
|
|
6503
6516
|
): Promise<FolderSummary[]> {
|
|
6504
6517
|
const { events, byId } = await readFolderRecords(query)
|
|
@@ -6532,7 +6545,7 @@ export async function listFolders(
|
|
|
6532
6545
|
),
|
|
6533
6546
|
rootOf: new Map<string, SignedEvent>(),
|
|
6534
6547
|
}
|
|
6535
|
-
: await placeRecordChannels(events, byId, listedIn, query)
|
|
6548
|
+
: await placeRecordChannels(events, byId, listedIn, query, options.listRead === true)
|
|
6536
6549
|
for (const [id, containers] of listedIn) {
|
|
6537
6550
|
const folder = byId.get(id)
|
|
6538
6551
|
if (folder) folder.listedIn = containers
|
|
@@ -6849,6 +6862,8 @@ async function placeRecordChannels(
|
|
|
6849
6862
|
byId: Map<string, FolderSummary>,
|
|
6850
6863
|
listedIn: Map<string, string[]>,
|
|
6851
6864
|
query: QueryFn,
|
|
6865
|
+
/** {@link listFolders}' `listRead`: each record's current changes come with its root, so none is read by `#a`. */
|
|
6866
|
+
listRead: boolean,
|
|
6852
6867
|
): Promise<{ recordsOf: Map<string, string[]>; archives: SignedEvent[]; rootOf: Map<string, SignedEvent> }> {
|
|
6853
6868
|
const containersOf = new Map<string, { pointer: AddressPointer; containers: string[] }>()
|
|
6854
6869
|
const states = events.filter((event) => event.kind === KIND_FOLDER_STATE)
|
|
@@ -6876,8 +6891,12 @@ async function placeRecordChannels(
|
|
|
6876
6891
|
// Every Folder's archive, and every listed record's, ride with the roots
|
|
6877
6892
|
// (FOL-46): the channel addresses are in hand from the listing and the
|
|
6878
6893
|
// record addresses are the keys above, so neither needs the roots first.
|
|
6894
|
+
// With the list read, a file's archive is among its current changes, which
|
|
6895
|
+
// come with its root below; only the Folders' own, and any other kind's, are
|
|
6896
|
+
// read by `#a`.
|
|
6879
6897
|
const channels = [...byId.values()].flatMap((folder) => (folder.channel ? [folder.channel] : []))
|
|
6880
|
-
const
|
|
6898
|
+
const changesAsked = [...containersOf].flatMap(([key, { pointer }]) => (listRead && FILE_KINDS.includes(pointer.kind) ? [] : [key]))
|
|
6899
|
+
const archiveAsk = archiveFilters([...new Set([...channels, ...changesAsked])])
|
|
6881
6900
|
if (containersOf.size === 0) {
|
|
6882
6901
|
const archives: SignedEvent[] = []
|
|
6883
6902
|
for (let start = 0; start < archiveAsk.length; start += MAX_FILTERS_PER_QUERY) {
|
|
@@ -6894,17 +6913,19 @@ async function placeRecordChannels(
|
|
|
6894
6913
|
groups.set(key, group)
|
|
6895
6914
|
}
|
|
6896
6915
|
const filters: Record<string, unknown>[] = []
|
|
6916
|
+
const listed: Record<string, unknown>[] = []
|
|
6897
6917
|
for (const { kind, pubkey, identifiers } of groups.values()) {
|
|
6898
6918
|
for (let start = 0; start < identifiers.length; start += RELAY_PAGE_CEILING) {
|
|
6899
6919
|
const chunk = identifiers.slice(start, start + RELAY_PAGE_CEILING)
|
|
6900
|
-
|
|
6920
|
+
const filter = { kinds: [kind], authors: [pubkey], '#d': chunk, limit: chunk.length }
|
|
6921
|
+
// `limit` counts first records in a list read, not the changes beside them.
|
|
6922
|
+
if (listRead && FILE_KINDS.includes(kind)) listed.push({ ...filter, fields: 'newest' })
|
|
6923
|
+
else filters.push(filter)
|
|
6901
6924
|
}
|
|
6902
6925
|
}
|
|
6903
6926
|
filters.push(...archiveAsk)
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
answered.push(...(await query(filters.slice(start, start + MAX_FILTERS_PER_QUERY))))
|
|
6907
|
-
}
|
|
6927
|
+
// A relay refuses a request mixing list reads with plain ones, so each goes on its own.
|
|
6928
|
+
const answered = (await Promise.all([queryChunked(filters, query), queryChunked(listed, query)])).flat()
|
|
6908
6929
|
// A state lists files, never change events, so the kind tells them apart.
|
|
6909
6930
|
const archives = answered.filter((e) => e.kind === ARCHIVE_RULE.changeKind)
|
|
6910
6931
|
const roots = answered.filter((e) => e.kind !== ARCHIVE_RULE.changeKind)
|
|
@@ -7010,6 +7031,18 @@ export async function resolveFolderContents(
|
|
|
7010
7031
|
* of it project descriptions.
|
|
7011
7032
|
*/
|
|
7012
7033
|
kinds?: readonly number[]
|
|
7034
|
+
/**
|
|
7035
|
+
* The relay offers the list read (as {@link listFolders}' `listRead`):
|
|
7036
|
+
* each file is read as its first record and its fields' current changes
|
|
7037
|
+
* (§6.13) rather than every change ever made to it. The text is not in
|
|
7038
|
+
* that answer, so a slot drawing a file's `description` is empty, and a
|
|
7039
|
+
* deleted file is left out. Nested Folders are read as before.
|
|
7040
|
+
*
|
|
7041
|
+
* Each field is the relay's newest change by §6.3's order: where an app's
|
|
7042
|
+
* fold would refuse that change, the field reads as its first record's,
|
|
7043
|
+
* not as the change before it.
|
|
7044
|
+
*/
|
|
7045
|
+
listRead?: boolean
|
|
7013
7046
|
} = {},
|
|
7014
7047
|
): Promise<FolderContents> {
|
|
7015
7048
|
// 1. The folder itself. Both kinds in one trip: the state is the model and
|
|
@@ -7115,22 +7148,34 @@ export async function resolveFolderContents(
|
|
|
7115
7148
|
// for it here only repeated them: its 500 newest are among each group's page
|
|
7116
7149
|
// (APP-2, where it was most of a second copy of every change).
|
|
7117
7150
|
const otherChangeKinds = changeKinds.filter((kind) => kind !== ARCHIVE_RULE.changeKind)
|
|
7151
|
+
// With the list read, a file's current changes come with its root. The relay
|
|
7152
|
+
// keeps only its file kinds that way, so a nested Folder, or any other kind,
|
|
7153
|
+
// is read as before.
|
|
7154
|
+
const byFields = (kind: number) => options.listRead === true && FILE_KINDS.includes(kind)
|
|
7155
|
+
const changesAsked = addresses.filter((address) => !byFields(addressPointerOf(address)?.kind ?? NaN))
|
|
7156
|
+
const rootFilters = [...groups.values()].map(({ pointer, addresses: group }) => ({
|
|
7157
|
+
kinds: [pointer.kind],
|
|
7158
|
+
authors: [pointer.pubkey],
|
|
7159
|
+
'#d': group.map((a) => referenceToPointer(a).identifier),
|
|
7160
|
+
limit: group.length,
|
|
7161
|
+
...(byFields(pointer.kind) ? { fields: 'newest' } : {}),
|
|
7162
|
+
}))
|
|
7118
7163
|
// Chunked: at ten addresses per archive filter, a Folder of about 1,200 files
|
|
7119
|
-
// would pass the relay's filters-per-request ceiling in one request.
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
'#
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7164
|
+
// would pass the relay's filters-per-request ceiling in one request. A relay
|
|
7165
|
+
// refuses a request mixing list reads with plain ones, so those go on their own.
|
|
7166
|
+
const [plainEvents, listedEvents] = await Promise.all([
|
|
7167
|
+
queryChunked([
|
|
7168
|
+
...rootFilters.filter((filter) => !('fields' in filter)),
|
|
7169
|
+
...(otherChangeKinds.length ? [{ kinds: otherChangeKinds, '#a': addresses, limit: 500 }] : []),
|
|
7170
|
+
// Every change, in groups small enough that a busy Folder's changes cannot
|
|
7171
|
+
// push one file's off the page — one Folder has already had 688. Same request.
|
|
7172
|
+
...archiveFilters(channelAddress ? [...changesAsked, channelAddress] : changesAsked),
|
|
7173
|
+
// A Folder listed here counts its archive only from its own admins (§3.2). Same request.
|
|
7174
|
+
...(nestedFolderIds.length ? [{ kinds: [KIND_CHANNEL_ADMINS], '#d': nestedFolderIds, limit: nestedFolderIds.length }] : []),
|
|
7175
|
+
], query),
|
|
7176
|
+
queryChunked(rootFilters.filter((filter) => 'fields' in filter), query),
|
|
7177
|
+
])
|
|
7178
|
+
const events = [...plainEvents, ...listedEvents]
|
|
7134
7179
|
const ownArchive = folderArchiveOf(events, summary)
|
|
7135
7180
|
if (ownArchive) summary.archived = ownArchive
|
|
7136
7181
|
|
|
@@ -7159,6 +7204,12 @@ export async function resolveFolderContents(
|
|
|
7159
7204
|
records,
|
|
7160
7205
|
root,
|
|
7161
7206
|
)
|
|
7207
|
+
// The list read carries no text (§6.13), and a change that set it with
|
|
7208
|
+
// other fields may be stale: the text is unread, never the seed the file
|
|
7209
|
+
// was created with drawn as if it were current.
|
|
7210
|
+
if (byFields(pointer.kind)) {
|
|
7211
|
+
folded.description = { value: '', by: root.pubkey, at: root.created_at, format: 'marker' }
|
|
7212
|
+
}
|
|
7162
7213
|
const nestedAdmins =
|
|
7163
7214
|
pointer.kind === KIND_CHANNEL
|
|
7164
7215
|
? new Set(
|