@estiva-app/interop 0.47.0 → 0.49.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 +37 -0
- package/README.md +21 -2
- package/dist/folders.d.ts +66 -0
- package/dist/folders.d.ts.map +1 -1
- package/dist/folders.js +70 -0
- 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 +3 -1
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +43 -0
- package/dist/projection.js.map +1 -1
- package/package.json +1 -1
- package/src/folders.ts +94 -0
- package/src/index.ts +2 -0
- package/src/projection.ts +43 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.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/folders.ts
CHANGED
|
@@ -62,6 +62,12 @@ export interface FolderRef {
|
|
|
62
62
|
* `["private"]`. Only a move *into* the Folder reads it.
|
|
63
63
|
*/
|
|
64
64
|
private?: boolean
|
|
65
|
+
/**
|
|
66
|
+
* `FolderSummary.addresses`: what its state lists. Only
|
|
67
|
+
* {@link planMoveFromFolders} reads it, to know a source lists the moved
|
|
68
|
+
* file even when the file's row did not resolve.
|
|
69
|
+
*/
|
|
70
|
+
addresses?: readonly string[]
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
/**
|
|
@@ -336,3 +342,91 @@ export function planMoveFile(
|
|
|
336
342
|
moved,
|
|
337
343
|
}
|
|
338
344
|
}
|
|
345
|
+
|
|
346
|
+
export type MoveFromFoldersPlan =
|
|
347
|
+
| {
|
|
348
|
+
ok: true
|
|
349
|
+
/**
|
|
350
|
+
* The one `kind:1852 add` in the target, naming everything moved. Publish
|
|
351
|
+
* it first: refused, nothing has changed. Absent when there is nothing to send.
|
|
352
|
+
*/
|
|
353
|
+
add?: UnsignedEvent
|
|
354
|
+
/**
|
|
355
|
+
* A `remove` for each source that lists part of the set, naming what that
|
|
356
|
+
* source lists. Publish them once the add has landed; a refused one leaves
|
|
357
|
+
* its Folder listing the set as well, which moving again fixes.
|
|
358
|
+
*/
|
|
359
|
+
removes: { folder: string; event: UnsignedEvent }[]
|
|
360
|
+
/** Every address the add names. */
|
|
361
|
+
moved: string[]
|
|
362
|
+
}
|
|
363
|
+
| { ok: false; reason: MoveRefusal }
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Move a file out of every Folder that lists it, with everything listed
|
|
367
|
+
* beneath it in each: one `kind:1852 add` in the target naming the whole set,
|
|
368
|
+
* then a `remove` in each source — SPEC §3.3.
|
|
369
|
+
*
|
|
370
|
+
* {@link planMoveFile} for each source, and what every consumer did around it
|
|
371
|
+
* (Ship's "Move to Folder…", Peek's Move, the agent's `move-project`), so it is
|
|
372
|
+
* done once:
|
|
373
|
+
*
|
|
374
|
+
* - **One add, not one per source.** A file two Folders list can have a
|
|
375
|
+
* different set beneath it in each. One add naming the union lands whole or
|
|
376
|
+
* not at all, so a refusal never leaves part of the set in the target.
|
|
377
|
+
* - **The file is in a source whose state names it** (`from[i].addresses`),
|
|
378
|
+
* even when its row is missing from that source's listing. A row that did
|
|
379
|
+
* not resolve is still what is being moved.
|
|
380
|
+
* - **Placed, when no source lists any of it.** The file is listed nowhere, or
|
|
381
|
+
* only by containment in a Folder with state, so it is added to the target
|
|
382
|
+
* alone, as {@link planPlaceFile} does. Into a private Folder that is
|
|
383
|
+
* refused unless the file's `h` is that Folder. A project's root carries no
|
|
384
|
+
* `h`, so a project is always refused. A file no Folder should list itself (a
|
|
385
|
+
* Ship issue is listed by its project) is then added too, so only call this
|
|
386
|
+
* for one when something is listed beneath it.
|
|
387
|
+
*
|
|
388
|
+
* `from` is every Folder that lists the file now. The target is ignored if it
|
|
389
|
+
* is one of them, and a file that is already there and nowhere else plans
|
|
390
|
+
* nothing. `listings` holds each source's files (`FolderContents.files`). Read
|
|
391
|
+
* them with `includeArchived`, or an archived file beneath this one stays
|
|
392
|
+
* behind. A source with no entry moves the file alone.
|
|
393
|
+
*
|
|
394
|
+
* Refusals are {@link planMoveFile}'s, and nothing is planned if any source is
|
|
395
|
+
* refused.
|
|
396
|
+
*/
|
|
397
|
+
export function planMoveFromFolders(
|
|
398
|
+
pubkey: string,
|
|
399
|
+
createdAtMs: number,
|
|
400
|
+
args: { file: MovableFile; from: readonly FolderRef[]; to: FolderRef; listings: ReadonlyMap<string, readonly MovableFile[] | null> },
|
|
401
|
+
): MoveFromFoldersPlan {
|
|
402
|
+
const { file, to } = args
|
|
403
|
+
const sources = args.from.filter((folder) => folder.id !== to.id)
|
|
404
|
+
if (sources.length === 0 && args.from.length > 0) return { ok: true, removes: [], moved: [] }
|
|
405
|
+
const removes: { folder: string; event: UnsignedEvent }[] = []
|
|
406
|
+
const moved = new Set<string>()
|
|
407
|
+
for (const from of sources) {
|
|
408
|
+
const listing = args.listings.get(from.id) ?? null
|
|
409
|
+
const unresolved =
|
|
410
|
+
!!listing && !!file.address && !!from.addresses?.includes(file.address) && !listing.some((candidate) => candidate.address === file.address)
|
|
411
|
+
const plan = planMoveFile(pubkey, createdAtMs, {
|
|
412
|
+
file,
|
|
413
|
+
from,
|
|
414
|
+
to,
|
|
415
|
+
// By its address, so the walk finds what the listing draws beneath it.
|
|
416
|
+
listing: unresolved ? [{ ...file, ref: file.address! }, ...listing] : listing,
|
|
417
|
+
})
|
|
418
|
+
if (!plan.ok) return plan
|
|
419
|
+
for (const address of plan.moved) moved.add(address)
|
|
420
|
+
const remove = plan.events[1]
|
|
421
|
+
if (remove) removes.push({ folder: from.id, event: remove })
|
|
422
|
+
}
|
|
423
|
+
if (!to.hasState) return { ok: false, reason: 'target-has-no-state' }
|
|
424
|
+
if (moved.size === 0) {
|
|
425
|
+
if (to.private && file.folder !== to.id) return { ok: false, reason: 'target-is-private' }
|
|
426
|
+
if (!file.address) return { ok: true, removes: [], moved: [] }
|
|
427
|
+
const [add] = planPlaceFile(pubkey, createdAtMs, { folder: to.id, address: file.address, hasState: true })
|
|
428
|
+
return { ok: true, add, removes: [], moved: [file.address] }
|
|
429
|
+
}
|
|
430
|
+
const addresses = [...moved]
|
|
431
|
+
return { ok: true, add: buildFolderCommand(pubkey, createdAtMs, { folder: to.id, op: 'add', addresses }), removes, moved: addresses }
|
|
432
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -130,11 +130,13 @@ export {
|
|
|
130
130
|
planPlaceFile,
|
|
131
131
|
planUnlistFile,
|
|
132
132
|
planMoveFile,
|
|
133
|
+
planMoveFromFolders,
|
|
133
134
|
planArchiveFolder,
|
|
134
135
|
listedBeneath,
|
|
135
136
|
type FolderRef,
|
|
136
137
|
type MovableFile,
|
|
137
138
|
type MovePlan,
|
|
139
|
+
type MoveFromFoldersPlan,
|
|
138
140
|
type MoveRefusal,
|
|
139
141
|
} from './folders.js'
|
|
140
142
|
|
package/src/projection.ts
CHANGED
|
@@ -4899,6 +4899,15 @@ function buildCreationEvent(args: {
|
|
|
4899
4899
|
}
|
|
4900
4900
|
}
|
|
4901
4901
|
|
|
4902
|
+
// A person property is checked as a person change is (SPEC §7.3, SHA-28).
|
|
4903
|
+
const people: string[] = []
|
|
4904
|
+
for (const [name, held] of Object.entries(value)) {
|
|
4905
|
+
if (properties[name]?.type !== 'pubkey') continue
|
|
4906
|
+
const problem = personKeyProblem(declared.label, held)
|
|
4907
|
+
if (problem) return problem
|
|
4908
|
+
if (held !== '' && !people.includes(held)) people.push(held)
|
|
4909
|
+
}
|
|
4910
|
+
|
|
4902
4911
|
if (isAddressableKind(declared.emits.kind) && !newId) {
|
|
4903
4912
|
return `Creating a kind ${declared.emits.kind} needs an identifier, and none was supplied.`
|
|
4904
4913
|
}
|
|
@@ -4945,6 +4954,9 @@ function buildCreationEvent(args: {
|
|
|
4945
4954
|
tags.push([declared.emits.setTag, address])
|
|
4946
4955
|
}
|
|
4947
4956
|
tags.push([placement, folder], ...prose)
|
|
4957
|
+
// Each person the new root names, once, where the relay indexes them — the
|
|
4958
|
+
// property's own tag is not indexed (SPEC §11.8, decided 2026-10-05).
|
|
4959
|
+
for (const person of people) tags.push(['p', person])
|
|
4948
4960
|
|
|
4949
4961
|
return {
|
|
4950
4962
|
pubkey: args.pubkey,
|
|
@@ -4955,6 +4967,21 @@ function buildCreationEvent(args: {
|
|
|
4955
4967
|
}
|
|
4956
4968
|
}
|
|
4957
4969
|
|
|
4970
|
+
/**
|
|
4971
|
+
* A person's key as an input of `type: "pubkey"` takes it — SPEC §7.3, SHA-28.
|
|
4972
|
+
* The `p` a writer adds must be what `#p` matches, so an npub or upper-case hex
|
|
4973
|
+
* is refused rather than converted: the person picking it saw something else.
|
|
4974
|
+
*/
|
|
4975
|
+
const PERSON_KEY = /^[0-9a-f]{64}$/
|
|
4976
|
+
|
|
4977
|
+
/** Why `value` is neither `''` nor a person's key, or undefined when it is one. */
|
|
4978
|
+
function personKeyProblem(label: string, value: string): string | undefined {
|
|
4979
|
+
if (value === '' || PERSON_KEY.test(value)) return undefined
|
|
4980
|
+
// A consumer shows this to the person, whose picker went wrong upstream; the
|
|
4981
|
+
// rule for developers is SPEC §7.3's, not theirs to act on.
|
|
4982
|
+
return `"${label}" needs a person picked from the list, so nothing was changed.`
|
|
4983
|
+
}
|
|
4984
|
+
|
|
4958
4985
|
/** What {@link buildActionEvent} and {@link buildActionEvents} are handed. */
|
|
4959
4986
|
export interface ActionEventArgs {
|
|
4960
4987
|
manifest: { records?: RecordsRule; actions?: ManifestAction[]; vocabularies?: Manifest['vocabularies'] }
|
|
@@ -5183,6 +5210,15 @@ function buildOneActionEvent(args: ActionEventArgs): UnsignedActionEvent | strin
|
|
|
5183
5210
|
}
|
|
5184
5211
|
}
|
|
5185
5212
|
|
|
5213
|
+
// A change whose input is a person names them (SPEC §7.3's `pubkey`, SHA-28).
|
|
5214
|
+
// `''` clears it and names nobody; anything else that is not a key would fold
|
|
5215
|
+
// as the field's value and make nobody a member, so it is refused here.
|
|
5216
|
+
const namesPerson = !!declared.emits.field && declared.input?.type === 'pubkey'
|
|
5217
|
+
if (namesPerson) {
|
|
5218
|
+
const problem = personKeyProblem(declared.label, value)
|
|
5219
|
+
if (problem) return problem
|
|
5220
|
+
}
|
|
5221
|
+
|
|
5186
5222
|
// A prose value's `content-format` and `imeta` — a change only, per the
|
|
5187
5223
|
// refusal above. Ship's order: the tag before `ts`, the files after it.
|
|
5188
5224
|
const prose = declared.emits.field
|
|
@@ -5228,6 +5264,10 @@ function buildOneActionEvent(args: ActionEventArgs): UnsignedActionEvent | strin
|
|
|
5228
5264
|
// depending on which app you asked (FRICTION.md A6).
|
|
5229
5265
|
if (records.order?.includes('ts')) tags.push(['ts', String(args.createdAtMs)])
|
|
5230
5266
|
tags.push(...files)
|
|
5267
|
+
// The person, where the relay indexes them: `value` is not indexed, so
|
|
5268
|
+
// without this `#p` never finds the change and §11.8 makes nobody a member.
|
|
5269
|
+
// After `ts`, where Ship's own builder has put it since FOL-30.
|
|
5270
|
+
if (namesPerson && value !== '') tags.push(['p', value])
|
|
5231
5271
|
// A move also names its new parent where a relay indexes it (SPEC §7.2, FOL-45):
|
|
5232
5272
|
// `value` is not indexed, so without this no read by the new parent finds a
|
|
5233
5273
|
// child moved in. Only for the field the kind declares as `movedBy`, and only
|
|
@@ -5900,7 +5940,9 @@ export async function resolveFolderContents(
|
|
|
5900
5940
|
/**
|
|
5901
5941
|
* Return archived files — and files hidden with an archived parent — each
|
|
5902
5942
|
* carrying its {@link Archive}, instead of leaving them out. For a view
|
|
5903
|
-
* that lists what was archived
|
|
5943
|
+
* that lists what was archived, and for the listings a move plans from
|
|
5944
|
+
* (`planMoveFromFolders`): what is archived beneath a file moves with it.
|
|
5945
|
+
* Every other list wants the default.
|
|
5904
5946
|
*/
|
|
5905
5947
|
includeArchived?: boolean
|
|
5906
5948
|
} = {},
|