@estiva-app/interop 0.73.0 → 0.74.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 +27 -0
- package/README.md +12 -12
- package/dist/folders.d.ts +54 -36
- package/dist/folders.d.ts.map +1 -1
- package/dist/folders.js +60 -37
- 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 +6 -0
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +3 -0
- package/dist/projection.js.map +1 -1
- package/package.json +3 -3
- package/src/folders.ts +80 -46
- package/src/index.ts +1 -0
- package/src/projection.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.74.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.20.0",
|
|
51
|
-
"@estiva-app/protocol": ">=0.
|
|
51
|
+
"@estiva-app/protocol": ">=0.49.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@estiva-app/conversation": ">=0.20.0",
|
|
55
|
-
"@estiva-app/protocol": ">=0.
|
|
55
|
+
"@estiva-app/protocol": ">=0.49.0",
|
|
56
56
|
"typescript": "~5.9.3"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/src/folders.ts
CHANGED
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
buildDeleteChannel,
|
|
51
51
|
buildEditChannelMetadata,
|
|
52
52
|
buildFolderCommand,
|
|
53
|
+
KIND,
|
|
53
54
|
type ChannelVisibility,
|
|
54
55
|
type UnsignedEvent,
|
|
55
56
|
} from '@estiva-app/protocol'
|
|
@@ -64,6 +65,12 @@ export interface FolderRef {
|
|
|
64
65
|
* `["private"]`. Only a move *into* the Folder reads it.
|
|
65
66
|
*/
|
|
66
67
|
private?: boolean
|
|
68
|
+
/**
|
|
69
|
+
* `FolderSummary.company`: the relay marks it the Company team (§3.4). Only
|
|
70
|
+
* {@link planMoveFromFolders} reads it, as the home of a topic made outside
|
|
71
|
+
* any team.
|
|
72
|
+
*/
|
|
73
|
+
company?: boolean
|
|
67
74
|
/**
|
|
68
75
|
* `FolderSummary.addresses`: what its state lists. Only
|
|
69
76
|
* {@link planMoveFromFolders} reads it, to know a source lists the moved
|
|
@@ -244,8 +251,11 @@ export interface MovableFile {
|
|
|
244
251
|
* `target-is-private`: the target's `kind:39000` is private and a moved file's
|
|
245
252
|
* `h` names any other channel, or none. A listing never changes who can read a
|
|
246
253
|
* file (§3.1), so the file would look private in the target and not be.
|
|
254
|
+
*
|
|
255
|
+
* `target-is-not-home`: a topic no team lists goes only to its home, the team
|
|
256
|
+
* its `h` names or else the Company team (§3.3).
|
|
247
257
|
*/
|
|
248
|
-
export type MoveRefusal = 'source-has-no-state' | 'target-has-no-state' | 'target-is-private'
|
|
258
|
+
export type MoveRefusal = 'source-has-no-state' | 'target-has-no-state' | 'target-is-private' | 'target-is-not-home'
|
|
249
259
|
|
|
250
260
|
export type MovePlan =
|
|
251
261
|
| {
|
|
@@ -297,31 +307,27 @@ export function listedBeneath<T extends MovableFile>(listing: readonly T[], file
|
|
|
297
307
|
}
|
|
298
308
|
|
|
299
309
|
/**
|
|
300
|
-
* Move a file to another Folder, with everything listed beneath it:
|
|
301
|
-
* `
|
|
310
|
+
* Move a file to another Folder, with everything listed beneath it: one
|
|
311
|
+
* `kind:1852 move` in the target naming the source in `from` — SPEC §3.3.
|
|
302
312
|
*
|
|
303
|
-
* **One command
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* moved only when the source lists it — a Ship issue is listed by no Folder,
|
|
309
|
-
* its project is. The file's `h` does not change.
|
|
313
|
+
* **One command, naming the whole set.** `listing` is the source Folder's
|
|
314
|
+
* files (`FolderContents.files`); the file moves with every file listed
|
|
315
|
+
* beneath it ({@link listedBeneath}), so a subtree moves whole. The file
|
|
316
|
+
* itself is moved only when the source lists it — a Ship issue is listed by
|
|
317
|
+
* no Folder, its project is. The file's `h` does not change.
|
|
310
318
|
*
|
|
311
319
|
* `listing` is required, and `null` says "nothing can be listed beneath this
|
|
312
320
|
* file", making the file the whole set. A move that silently left its
|
|
313
321
|
* sub-files behind is the bug this planner exists to end, so omitting the
|
|
314
322
|
* listing is a type error rather than a quiet single-file move.
|
|
315
323
|
*
|
|
316
|
-
* **
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
324
|
+
* **Both lists or neither.** The relay changes the source's and the target's
|
|
325
|
+
* list in one write, after checking the mover may change each; refused,
|
|
326
|
+
* nothing has changed, so a topic is never on no list (record
|
|
327
|
+
* a-topic-always-has-a-team-and-moves-in-one-action).
|
|
320
328
|
*
|
|
321
|
-
* **Refused unless both Folders have state.**
|
|
322
|
-
*
|
|
323
|
-
* it disappears; a `remove` from one emits state listing nothing, and the
|
|
324
|
-
* whole source disappears.
|
|
329
|
+
* **Refused unless both Folders have state.** The relay refuses a move
|
|
330
|
+
* between Folders that do not both hold a listing.
|
|
325
331
|
*
|
|
326
332
|
* **Refused into a private Folder** when any moved file's `h` is another
|
|
327
333
|
* channel or absent (`target-is-private`, §3.1).
|
|
@@ -329,6 +335,7 @@ export function listedBeneath<T extends MovableFile>(listing: readonly T[], file
|
|
|
329
335
|
* A move to the same Folder, or of a set the source does not list, plans nothing.
|
|
330
336
|
*
|
|
331
337
|
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/moving-a-file-never-changes-who-can-read-it.md
|
|
338
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-topic-always-has-a-team-and-moves-in-one-action.md
|
|
332
339
|
*/
|
|
333
340
|
export function planMoveFile(
|
|
334
341
|
pubkey: string,
|
|
@@ -348,10 +355,7 @@ export function planMoveFile(
|
|
|
348
355
|
if (!moved.length) return { ok: true, events: [], moved }
|
|
349
356
|
return {
|
|
350
357
|
ok: true,
|
|
351
|
-
events: [
|
|
352
|
-
buildFolderCommand(pubkey, createdAtMs, { folder: args.to.id, op: 'add', addresses: moved }),
|
|
353
|
-
buildFolderCommand(pubkey, createdAtMs, { folder: args.from.id, op: 'remove', addresses: moved }),
|
|
354
|
-
],
|
|
358
|
+
events: [buildFolderCommand(pubkey, createdAtMs, { folder: args.to.id, op: 'move', from: args.from.id, addresses: moved })],
|
|
355
359
|
moved,
|
|
356
360
|
}
|
|
357
361
|
}
|
|
@@ -360,33 +364,31 @@ export type MoveFromFoldersPlan =
|
|
|
360
364
|
| {
|
|
361
365
|
ok: true
|
|
362
366
|
/**
|
|
363
|
-
* The
|
|
364
|
-
*
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* A `remove` for each source that lists part of the set, naming what that
|
|
369
|
-
* source lists. Publish them once the add has landed; a refused one leaves
|
|
370
|
-
* its Folder listing the set as well, which moving again fixes.
|
|
367
|
+
* The commands to publish, in order, stopping at the first the relay
|
|
368
|
+
* refuses: a `kind:1852 move` from each source that lists part of the
|
|
369
|
+
* set, or one `add` when no source lists any of it. Empty when there is
|
|
370
|
+
* nothing to send.
|
|
371
371
|
*/
|
|
372
|
-
|
|
373
|
-
/** Every address the
|
|
372
|
+
events: UnsignedEvent[]
|
|
373
|
+
/** Every address the commands put in the target. */
|
|
374
374
|
moved: string[]
|
|
375
375
|
}
|
|
376
376
|
| { ok: false; reason: MoveRefusal }
|
|
377
377
|
|
|
378
378
|
/**
|
|
379
379
|
* Move a file out of every Folder that lists it, with everything listed
|
|
380
|
-
* beneath it in each: one `kind:1852
|
|
381
|
-
*
|
|
380
|
+
* beneath it in each: one `kind:1852 move` from each source into the target
|
|
381
|
+
* — SPEC §3.3.
|
|
382
382
|
*
|
|
383
383
|
* {@link planMoveFile} for each source, and what every consumer did around it
|
|
384
384
|
* (Ship's "Move to Folder…", Peek's Move, the agent's `move-project`), so it is
|
|
385
385
|
* done once:
|
|
386
386
|
*
|
|
387
|
-
* - **One
|
|
388
|
-
*
|
|
389
|
-
*
|
|
387
|
+
* - **One move per source.** A file two Folders list can have a different set
|
|
388
|
+
* beneath it in each; each move names what its source lists. Each changes
|
|
389
|
+
* both of its lists or neither, so no step leaves the file on no list, and a
|
|
390
|
+
* refusal halfway leaves it where the earlier moves put it (in the target
|
|
391
|
+
* and the sources not yet moved from), which moving again finishes.
|
|
390
392
|
* - **The file is in a source whose state names it** (`from[i].addresses`),
|
|
391
393
|
* even when its row is missing from that source's listing. A row that did
|
|
392
394
|
* not resolve is still what is being moved.
|
|
@@ -414,8 +416,8 @@ export function planMoveFromFolders(
|
|
|
414
416
|
): MoveFromFoldersPlan {
|
|
415
417
|
const { file, to } = args
|
|
416
418
|
const sources = args.from.filter((folder) => folder.id !== to.id)
|
|
417
|
-
if (sources.length === 0 && args.from.length > 0) return { ok: true,
|
|
418
|
-
const
|
|
419
|
+
if (sources.length === 0 && args.from.length > 0) return { ok: true, events: [], moved: [] }
|
|
420
|
+
const events: UnsignedEvent[] = []
|
|
419
421
|
const moved = new Set<string>()
|
|
420
422
|
for (const from of sources) {
|
|
421
423
|
const listing = args.listings.get(from.id) ?? null
|
|
@@ -430,16 +432,48 @@ export function planMoveFromFolders(
|
|
|
430
432
|
})
|
|
431
433
|
if (!plan.ok) return plan
|
|
432
434
|
for (const address of plan.moved) moved.add(address)
|
|
433
|
-
|
|
434
|
-
if (remove) removes.push({ folder: from.id, event: remove })
|
|
435
|
+
events.push(...plan.events)
|
|
435
436
|
}
|
|
436
437
|
if (!to.hasState) return { ok: false, reason: 'target-has-no-state' }
|
|
437
438
|
if (moved.size === 0) {
|
|
438
439
|
if (to.private && file.scopedTo !== to.id) return { ok: false, reason: 'target-is-private' }
|
|
439
|
-
if (!file.address) return { ok: true,
|
|
440
|
-
|
|
441
|
-
|
|
440
|
+
if (!file.address) return { ok: true, events: [], moved: [] }
|
|
441
|
+
// A topic on no list goes home: its `h` team, or the Company team when its `h` is no team. Which `h`
|
|
442
|
+
// is a team is the relay's to know, so the Company team is let through here and the relay decides.
|
|
443
|
+
if (file.address.startsWith(`${KIND.FILE}:`) &&file.scopedTo !== to.id && !to.company) return { ok: false, reason: 'target-is-not-home' }
|
|
444
|
+
return { ok: true, events: planPlaceFile(pubkey, createdAtMs, { folder: to.id, address: file.address, hasState: true }), moved: [file.address] }
|
|
442
445
|
}
|
|
443
|
-
|
|
444
|
-
|
|
446
|
+
return { ok: true, events, moved: [...moved] }
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* What a refusal of `events[index]` from {@link planMoveFromFolders} means,
|
|
451
|
+
* so an app says it in its own words and never shows the relay's text.
|
|
452
|
+
*
|
|
453
|
+
* - `why`: `team-archived` (a team it leaves or enters is archived),
|
|
454
|
+
* `not-a-member` (moving a space needs a member of each team it changes),
|
|
455
|
+
* `changed-meanwhile` (a list changed since it was read: the team no longer
|
|
456
|
+
* lists it, or another team now does), or `refused`.
|
|
457
|
+
* - `nothingMoved`: the first command was refused, so nothing changed.
|
|
458
|
+
* - `notMovedFrom`: otherwise, the Folders that still list it besides the
|
|
459
|
+
* target — the refused command's `from` and every later one's.
|
|
460
|
+
*/
|
|
461
|
+
export function readMoveRefusal(
|
|
462
|
+
events: readonly UnsignedEvent[],
|
|
463
|
+
index: number,
|
|
464
|
+
reason: string | undefined,
|
|
465
|
+
): { why: 'team-archived' | 'not-a-member' | 'changed-meanwhile' | 'refused'; nothingMoved: boolean; notMovedFrom: string[] } {
|
|
466
|
+
const text = reason ?? ''
|
|
467
|
+
const why = /archived/i.test(text)
|
|
468
|
+
? 'team-archived'
|
|
469
|
+
: /only the team's members/i.test(text)
|
|
470
|
+
? 'not-a-member'
|
|
471
|
+
: /does not list|lists none of|listed by one team/i.test(text)
|
|
472
|
+
? 'changed-meanwhile'
|
|
473
|
+
: 'refused'
|
|
474
|
+
const nothingMoved = index <= 0
|
|
475
|
+
const notMovedFrom = nothingMoved
|
|
476
|
+
? []
|
|
477
|
+
: events.slice(index).flatMap((event) => event.tags.filter((tag) => tag[0] === 'from').map((tag) => tag[1]!))
|
|
478
|
+
return { why, nothingMoved, notMovedFrom }
|
|
445
479
|
}
|
package/src/index.ts
CHANGED
package/src/projection.ts
CHANGED
|
@@ -6302,6 +6302,12 @@ export interface FolderSummary {
|
|
|
6302
6302
|
* (NIP-29). What `planMoveFile` reads as `FolderRef.private`.
|
|
6303
6303
|
*/
|
|
6304
6304
|
private?: true
|
|
6305
|
+
/**
|
|
6306
|
+
* Present when the relay marks it the Company team: its `kind:39000`
|
|
6307
|
+
* carries `["company"]` (§3.4). What `planMoveFromFolders` reads as
|
|
6308
|
+
* `FolderRef.company`.
|
|
6309
|
+
*/
|
|
6310
|
+
company?: true
|
|
6305
6311
|
/**
|
|
6306
6312
|
* Who may rename and archive it: the owners and admins on its relay-signed
|
|
6307
6313
|
* `kind:39001`. Offer Archive only to them — a reader ignores an archive from
|
|
@@ -6533,6 +6539,7 @@ async function readFolderRecords(query: QueryFn): Promise<{ events: SignedEvent[
|
|
|
6533
6539
|
const name = nameOf(channel)
|
|
6534
6540
|
if (name !== undefined) folder.name = name
|
|
6535
6541
|
if (channel.tags.some((tag) => tag[0] === 'private')) folder.private = true
|
|
6542
|
+
if (channel.tags.some((tag) => tag[0] === 'company')) folder.company = true
|
|
6536
6543
|
const admins = folderAdminsOf(adminsOf.get(id), channel)
|
|
6537
6544
|
if (admins.length) folder.admins = admins
|
|
6538
6545
|
folder.channel = pointerToAddress({ kind: KIND_CHANNEL, pubkey: channel.pubkey, identifier: id, relays: [] })
|
|
@@ -6962,6 +6969,7 @@ export async function resolveFolderContents(
|
|
|
6962
6969
|
name: nameOf(channel),
|
|
6963
6970
|
hasState: !!state,
|
|
6964
6971
|
...(channel?.tags.some((tag) => tag[0] === 'private') ? { private: true as const } : {}),
|
|
6972
|
+
...(channel?.tags.some((tag) => tag[0] === 'company') ? { company: true as const } : {}),
|
|
6965
6973
|
...(admins.length ? { admins } : {}),
|
|
6966
6974
|
...(channelAddress ? { channel: channelAddress } : {}),
|
|
6967
6975
|
...(state
|