@estiva-app/interop 0.75.0 → 0.77.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 +68 -0
- package/dist/fields.d.ts +47 -0
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +159 -1
- package/dist/fields.js.map +1 -1
- package/dist/folders.d.ts +32 -0
- package/dist/folders.d.ts.map +1 -1
- package/dist/folders.js +68 -4
- package/dist/folders.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/links.d.ts +7 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +15 -6
- package/dist/links.js.map +1 -1
- package/dist/mentions.d.ts +7 -1
- package/dist/mentions.d.ts.map +1 -1
- package/dist/mentions.js +21 -8
- package/dist/mentions.js.map +1 -1
- package/dist/projection.d.ts +13 -0
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +115 -35
- package/dist/projection.js.map +1 -1
- package/dist/references.d.ts +15 -1
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +16 -2
- package/dist/references.js.map +1 -1
- package/package.json +5 -5
- package/src/fields.ts +171 -0
- package/src/folders.ts +73 -5
- package/src/index.ts +7 -0
- package/src/links.ts +20 -6
- package/src/mentions.ts +24 -8
- package/src/projection.ts +126 -31
- package/src/references.ts +25 -2
package/dist/references.d.ts
CHANGED
|
@@ -25,7 +25,21 @@ export interface FileCandidatesOptions {
|
|
|
25
25
|
cache?: ProjectionCache;
|
|
26
26
|
/** When each address was last written or read, in seconds — newer first within a tier. */
|
|
27
27
|
at?: ReadonlyMap<string, number>;
|
|
28
|
+
/** The types the relay keeps in order (`RelayFileReads.inOrder`): a project of one is picked as its link. */
|
|
29
|
+
inOrder?: readonly string[];
|
|
30
|
+
/** The host Ship serves projects from: a picked project's link is `<it>/project/<d>`. Ship's own unless said, so every app picks the same link. */
|
|
31
|
+
projectOrigin?: string;
|
|
28
32
|
}
|
|
33
|
+
/** Where Ship serves projects (§13.1, decided 2026-11-03): one link for a project, whichever app picked it. */
|
|
34
|
+
export declare const SHIP_ORIGIN = "https://ship.estiva.app";
|
|
35
|
+
/**
|
|
36
|
+
* How a picked file goes in the text (§13.1): a project whose type the relay
|
|
37
|
+
* keeps in order as Ship's path link with its id and no title, which every
|
|
38
|
+
* app's host answers; anything else as `nostr:naddr…`.
|
|
39
|
+
*
|
|
40
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-named-by-its-id-in-a-capital-and-small-tag.md
|
|
41
|
+
*/
|
|
42
|
+
export declare function pickedFileUri(address: string, { inOrder, projectOrigin }?: Pick<FileCandidatesOptions, 'inOrder' | 'projectOrigin'>): string;
|
|
29
43
|
/**
|
|
30
44
|
* Rows for resolved files, all in one tier.
|
|
31
45
|
*
|
|
@@ -37,7 +51,7 @@ export interface FileCandidatesOptions {
|
|
|
37
51
|
* offerable — unreachable, untitled, or of a kind `[` does not offer — are
|
|
38
52
|
* left out.
|
|
39
53
|
*/
|
|
40
|
-
export declare function fileCandidates(objects: readonly (ForeignObject | null | undefined)[], tier: number, query: QueryFn, { cache, at }?: FileCandidatesOptions): Promise<ReferenceCandidate[]>;
|
|
54
|
+
export declare function fileCandidates(objects: readonly (ForeignObject | null | undefined)[], tier: number, query: QueryFn, { cache, at, inOrder, projectOrigin }?: FileCandidatesOptions): Promise<ReferenceCandidate[]>;
|
|
41
55
|
export interface SearchFileReferencesOptions extends Omit<FileCandidatesOptions, 'at'> {
|
|
42
56
|
/** How many roots, and separately how many renames, the relay is asked for. Default 32. */
|
|
43
57
|
limit?: number;
|
package/dist/references.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK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0B,GAChE,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA+B/B;AAED,MAAM,WAAW,2BAA4B,SAAQ,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC;IACpF,2FAA2F;IAC3F,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAWD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,EAAE,KAAU,EAAE,GAAG,OAAO,EAAE,GAAE,2BAAgC,GAC3D,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAqB/B"}
|
package/dist/references.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { FILE_TIER, fileReference, KIND_CHANGE, referenceMatch, refMatch, } from '@estiva-app/conversation';
|
|
17
17
|
import { isClosedStatus, KIND_BARE_FILE, resolveForeignRoots, } from './projection.js';
|
|
18
|
+
import { fileIdFormOf } from '@estiva-app/protocol';
|
|
18
19
|
const KIND_PROJECT = 30850;
|
|
19
20
|
const KIND_ISSUE = 30851;
|
|
20
21
|
const KIND_DOCUMENT = 30842;
|
|
@@ -46,6 +47,19 @@ const offerable = (object) => !!object &&
|
|
|
46
47
|
* the `ref` field — so typing it finds the issue. Only an issue has one.
|
|
47
48
|
*/
|
|
48
49
|
const refOf = (object) => object.kind === KIND_ISSUE ? object.meta.find((slot) => slot.field === 'ref')?.value.trim() || undefined : undefined;
|
|
50
|
+
/** Where Ship serves projects (§13.1, decided 2026-11-03): one link for a project, whichever app picked it. */
|
|
51
|
+
export const SHIP_ORIGIN = 'https://ship.estiva.app';
|
|
52
|
+
/**
|
|
53
|
+
* How a picked file goes in the text (§13.1): a project whose type the relay
|
|
54
|
+
* keeps in order as Ship's path link with its id and no title, which every
|
|
55
|
+
* app's host answers; anything else as `nostr:naddr…`.
|
|
56
|
+
*
|
|
57
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-named-by-its-id-in-a-capital-and-small-tag.md
|
|
58
|
+
*/
|
|
59
|
+
export function pickedFileUri(address, { inOrder = [], projectOrigin = SHIP_ORIGIN } = {}) {
|
|
60
|
+
const byId = fileIdFormOf(inOrder, address);
|
|
61
|
+
return byId?.type === 'osnova.project' ? `${projectOrigin.replace(/\/+$/, '')}/project/${byId.id}` : fileReference(address);
|
|
62
|
+
}
|
|
49
63
|
/**
|
|
50
64
|
* Rows for resolved files, all in one tier.
|
|
51
65
|
*
|
|
@@ -57,7 +71,7 @@ const refOf = (object) => object.kind === KIND_ISSUE ? object.meta.find((slot) =
|
|
|
57
71
|
* offerable — unreachable, untitled, or of a kind `[` does not offer — are
|
|
58
72
|
* left out.
|
|
59
73
|
*/
|
|
60
|
-
export async function fileCandidates(objects, tier, query, { cache, at } = {}) {
|
|
74
|
+
export async function fileCandidates(objects, tier, query, { cache, at, inOrder, projectOrigin } = {}) {
|
|
61
75
|
const files = objects.filter(offerable);
|
|
62
76
|
const parents = new Map();
|
|
63
77
|
for (const o of objects)
|
|
@@ -78,7 +92,7 @@ export async function fileCandidates(objects, tier, query, { cache, at } = {}) {
|
|
|
78
92
|
const summary = summaryOf(o);
|
|
79
93
|
return {
|
|
80
94
|
id: o.address,
|
|
81
|
-
uri:
|
|
95
|
+
uri: pickedFileUri(o.address, { inOrder, projectOrigin }),
|
|
82
96
|
type: typeOf(o.kind),
|
|
83
97
|
kind: o.kind,
|
|
84
98
|
title: o.slots.title.value,
|
package/dist/references.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.js","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,SAAS,EACT,aAAa,EACb,WAAW,EACX,cAAc,EACd,QAAQ,GAGT,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,cAAc,EACd,cAAc,EACd,mBAAmB,GAIpB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{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CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,CAAA;QAC9E,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAAE,SAAQ;QAChE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAA;IACjE,CAAC;IACD,IAAI,EAAE,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAC5B,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAC/E,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IAC5I,OAAO,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAA;AAC9E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.77.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",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"prepublishOnly": "npm run build"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@estiva-app/conversation": ">=0.
|
|
51
|
-
"@estiva-app/protocol": ">=0.
|
|
50
|
+
"@estiva-app/conversation": ">=0.27.0",
|
|
51
|
+
"@estiva-app/protocol": ">=0.51.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@estiva-app/conversation": ">=0.
|
|
55
|
-
"@estiva-app/protocol": ">=0.
|
|
54
|
+
"@estiva-app/conversation": ">=0.27.0",
|
|
55
|
+
"@estiva-app/protocol": ">=0.51.0",
|
|
56
56
|
"typescript": "~5.9.3"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/src/fields.ts
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/merging-two-changes-to-one-text-never-loses-words.md
|
|
24
24
|
*/
|
|
25
25
|
import {
|
|
26
|
+
BASE_TYPE_OF_KIND,
|
|
26
27
|
CONTENT_FORMAT_TAG,
|
|
27
28
|
mergeTexts,
|
|
28
29
|
type MergeAsk,
|
|
@@ -344,3 +345,173 @@ export async function writeChange(args: WriteChangeArgs): Promise<WriteChangeRes
|
|
|
344
345
|
}
|
|
345
346
|
return { ok: false, refused: `still refused after ${tries} tries: ${last}` }
|
|
346
347
|
}
|
|
348
|
+
|
|
349
|
+
/** The tags of a one-field change that belong to its field, and so go after the `set` tags. */
|
|
350
|
+
const FIELD_OWN = new Set(['a', 'O', 'field', 'value', 'h', 'ts', 'prev', 'stage', CONTENT_FORMAT_TAG])
|
|
351
|
+
|
|
352
|
+
/** §6.2's order for the tags after the `set` tags; anything else after them. */
|
|
353
|
+
const AFTER_SETS = ['A', 'o', 'imeta', 'p']
|
|
354
|
+
const afterSetsRank = (name: string) => (AFTER_SETS.indexOf(name) + AFTER_SETS.length + 1) % (AFTER_SETS.length + 1)
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* One change setting several fields of one file (§6.2), from the one-field
|
|
358
|
+
* changes for each — `buildActionEvent`'s, each with its `prev`, so the
|
|
359
|
+
* manifest has checked every value and staged every status. Tag order: `a`,
|
|
360
|
+
* `O`, `h`, `ts`, one `["set", field, value, prev]` per field, then the
|
|
361
|
+
* text's `content-format`, any other tag once (`A`, `o`, `imeta`, `p`), then
|
|
362
|
+
* one `stage` per staged field. The relay takes it whole or refuses it whole.
|
|
363
|
+
*
|
|
364
|
+
* A string when they are not one file's changes in one Folder, when one sets
|
|
365
|
+
* no field or follows no change, when a field is named twice, or when the
|
|
366
|
+
* file has no id for the `O` a several-field change must carry.
|
|
367
|
+
*
|
|
368
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/one-change-may-set-several-fields-taken-whole-or-refused-whole.md
|
|
369
|
+
*/
|
|
370
|
+
export function combineChanges(changes: readonly UnsignedEvent[]): UnsignedEvent | string {
|
|
371
|
+
const [first] = changes
|
|
372
|
+
if (!first) return 'A change sets at least one field.'
|
|
373
|
+
const file = tagValue(first, 'a')
|
|
374
|
+
const id = tagValue(first, 'O')
|
|
375
|
+
const folder = tagValue(first, 'h')
|
|
376
|
+
if (!file || !folder) return 'A change names its file and its Folder.'
|
|
377
|
+
if (!id) return `${file} has no id, and a change setting several fields names its file by it.`
|
|
378
|
+
const sets: string[][] = []
|
|
379
|
+
const rest: string[][] = []
|
|
380
|
+
const stages: string[][] = []
|
|
381
|
+
let format: string[] | undefined
|
|
382
|
+
let ms = 0
|
|
383
|
+
for (const change of changes) {
|
|
384
|
+
if (change.kind !== KIND_CHANGE || tagValue(change, 'a') !== file || tagValue(change, 'O') !== id || tagValue(change, 'h') !== folder) {
|
|
385
|
+
return 'A change setting several fields sets them on one file, in its Folder.'
|
|
386
|
+
}
|
|
387
|
+
const field = tagValue(change, 'field')
|
|
388
|
+
const prev = tagValue(change, 'prev')
|
|
389
|
+
if (!field || !prev) return 'Each field of a several-field change names the change it follows.'
|
|
390
|
+
// Who is on a file is kept beside it, never in a `set` (§6.2, §11.8): the relay refuses one.
|
|
391
|
+
if (field.startsWith('member:') || field.startsWith('follow:')) return `${field} is never in a change setting several fields.`
|
|
392
|
+
if (sets.some((s) => s[1] === field)) return `A change names ${field} once.`
|
|
393
|
+
sets.push(['set', field, tagValue(change, 'value') ?? '', prev])
|
|
394
|
+
for (const tag of change.tags) {
|
|
395
|
+
if (tag[0] === 'stage') stages.push([...tag])
|
|
396
|
+
else if (tag[0] === CONTENT_FORMAT_TAG && field === TEXT_FIELD) format = [...tag]
|
|
397
|
+
else if (!FIELD_OWN.has(tag[0]) && !rest.some((t) => t.length === tag.length && t.every((v, i) => v === tag[i]))) rest.push([...tag])
|
|
398
|
+
}
|
|
399
|
+
ms = Math.max(ms, Number(tagValue(change, 'ts')) || change.created_at * 1000)
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
pubkey: first.pubkey,
|
|
403
|
+
created_at: Math.floor(ms / 1000),
|
|
404
|
+
kind: KIND_CHANGE,
|
|
405
|
+
tags: [
|
|
406
|
+
['a', file],
|
|
407
|
+
['O', id],
|
|
408
|
+
['h', folder],
|
|
409
|
+
['ts', String(ms)],
|
|
410
|
+
...sets,
|
|
411
|
+
...(format ? [format] : []),
|
|
412
|
+
...rest.sort((x, y) => afterSetsRank(x[0]) - afterSetsRank(y[0])),
|
|
413
|
+
...stages,
|
|
414
|
+
],
|
|
415
|
+
content: first.content,
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** One field of a several-field change, as {@link writeChanges} is handed it. */
|
|
420
|
+
export interface FieldWrite {
|
|
421
|
+
field: string
|
|
422
|
+
value: string
|
|
423
|
+
format?: string
|
|
424
|
+
/** As {@link WriteChangeArgs.prev}: this field's current change as the writer read it. */
|
|
425
|
+
prev: string
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** What {@link writeChanges} is handed: {@link WriteChangeArgs}, for several fields of one file. */
|
|
429
|
+
export interface WriteChangesArgs extends Omit<WriteChangeArgs, 'field' | 'value' | 'format' | 'prev' | 'build'> {
|
|
430
|
+
fields: readonly FieldWrite[]
|
|
431
|
+
/**
|
|
432
|
+
* The types the relay keeps in order (`RelayFileReads.inOrder`). A change
|
|
433
|
+
* setting several fields is sent only for one of them: a reader older than
|
|
434
|
+
* interop 0.76.0 folds nothing from a `set`, and the switch is what says
|
|
435
|
+
* every app reads it (record one-change-may-set-several-fields…).
|
|
436
|
+
*/
|
|
437
|
+
inOrder: readonly string[]
|
|
438
|
+
/** The unsigned one-field change for one field: `buildActionEvent` bound to that field's action. */
|
|
439
|
+
build: (input: FieldWrite & { createdAtMs: number }) => UnsignedEvent | string
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Write several fields of one file as one change, and answer a `conflict:` as
|
|
444
|
+
* §6.2 says for one: read every field's current change, set again each field
|
|
445
|
+
* other than the text that someone changed since, merge the text by §13.3,
|
|
446
|
+
* and send them again as one change. A text that asks stops it, and nothing is
|
|
447
|
+
* saved; a text whose merge says nothing theirs does not is left out of the
|
|
448
|
+
* change. Each attempt is landed whole or refused whole by the relay.
|
|
449
|
+
*/
|
|
450
|
+
export async function writeChanges(args: WriteChangesArgs): Promise<WriteChangeResult> {
|
|
451
|
+
const now = args.now ?? Date.now
|
|
452
|
+
const tries = args.tries ?? 4
|
|
453
|
+
let fields = args.fields.map((f) => ({ ...f, base: undefined as MergeText | undefined }))
|
|
454
|
+
let after = 0
|
|
455
|
+
let mergedOnto: SignedEvent | undefined
|
|
456
|
+
let last = ''
|
|
457
|
+
|
|
458
|
+
for (let attempt = 0; attempt < tries; attempt++) {
|
|
459
|
+
const createdAtMs = Math.max(now(), after)
|
|
460
|
+
const built: UnsignedEvent[] = []
|
|
461
|
+
for (const f of fields) {
|
|
462
|
+
const one = args.build({ field: f.field, value: f.value, ...(f.format ? { format: f.format } : {}), prev: f.prev, createdAtMs })
|
|
463
|
+
if (typeof one === 'string') return { ok: false, refused: one }
|
|
464
|
+
built.push(one)
|
|
465
|
+
}
|
|
466
|
+
const change = combineChanges(built)
|
|
467
|
+
if (typeof change === 'string') return { ok: false, refused: change }
|
|
468
|
+
const type = BASE_TYPE_OF_KIND[change.tags[0][1].split(':').map(Number)[0]]
|
|
469
|
+
if (!type || !args.inOrder.includes(type)) {
|
|
470
|
+
return { ok: false, refused: 'Several fields go in one change only once the relay keeps this type in order: write each with writeChange.' }
|
|
471
|
+
}
|
|
472
|
+
const signed = await args.sign(change)
|
|
473
|
+
const answer = await args.publish(signed)
|
|
474
|
+
if (answer.ok) return { ok: true, id: answer.eventId ?? signed.id, event: signed, ...(mergedOnto ? { mergedOnto } : {}) }
|
|
475
|
+
last = answer.reason ?? 'refused with no reason'
|
|
476
|
+
const conflict = conflictOf(last)
|
|
477
|
+
if (!conflict || conflict.kind === 'other' || !fields.some((f) => f.field === conflict.field)) return { ok: false, refused: last }
|
|
478
|
+
|
|
479
|
+
if (conflict.kind === 'sorts-before') {
|
|
480
|
+
// After every field's prev, not only the one named: the next field would be refused the same way.
|
|
481
|
+
const followed = await Promise.all(fields.map((f) => byId(args.query, f.prev)))
|
|
482
|
+
if (followed.some((e) => !e)) return { ok: false, refused: last }
|
|
483
|
+
after = Math.max(...followed.map((e) => changedAt(e!) + 1))
|
|
484
|
+
continue
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const heads = await Promise.all(
|
|
488
|
+
fields.map((f) => (f.field === conflict.field && conflict.current ? byId(args.query, conflict.current) : args.current(f.field))),
|
|
489
|
+
)
|
|
490
|
+
const next: typeof fields = []
|
|
491
|
+
for (const [i, f] of fields.entries()) {
|
|
492
|
+
const head = heads[i]
|
|
493
|
+
if (!head) return { ok: false, refused: last }
|
|
494
|
+
after = Math.max(after, changedAt(head) + 1)
|
|
495
|
+
if (head.id === f.prev) {
|
|
496
|
+
next.push(f)
|
|
497
|
+
continue
|
|
498
|
+
}
|
|
499
|
+
if (f.field !== TEXT_FIELD) {
|
|
500
|
+
next.push({ ...f, prev: head.id })
|
|
501
|
+
continue
|
|
502
|
+
}
|
|
503
|
+
const base = f.base ?? (await byId(args.query, f.prev).then((e) => e && textOf(e)))
|
|
504
|
+
if (!base) return { ok: false, refused: `${last} (the text it followed, ${f.prev}, could not be read to merge onto)` }
|
|
505
|
+
const theirs = textOf(head)
|
|
506
|
+
if (!theirs) return { ok: false, refused: last }
|
|
507
|
+
const merge = mergeTexts(base, theirs, { value: f.value, ...(f.format ? { format: f.format } : {}) })
|
|
508
|
+
if (merge.asks) return { ok: false, asks: merge.asks, theirs: head }
|
|
509
|
+
mergedOnto = head
|
|
510
|
+
if (merge.merged.value === theirs.value && (merge.merged.format ?? '') === (theirs.format ?? '')) continue
|
|
511
|
+
next.push({ field: f.field, value: merge.merged.value, ...(merge.merged.format ? { format: merge.merged.format } : {}), prev: head.id, base: theirs })
|
|
512
|
+
}
|
|
513
|
+
if (!next.length) return { ok: true, unchanged: true, id: mergedOnto!.id, mergedOnto: mergedOnto! }
|
|
514
|
+
fields = next
|
|
515
|
+
}
|
|
516
|
+
return { ok: false, refused: `still refused after ${tries} tries: ${last}` }
|
|
517
|
+
}
|
package/src/folders.ts
CHANGED
|
@@ -50,6 +50,8 @@ import {
|
|
|
50
50
|
buildDeleteChannel,
|
|
51
51
|
buildEditChannelMetadata,
|
|
52
52
|
buildFolderCommand,
|
|
53
|
+
fileIdFormOf,
|
|
54
|
+
isFileId,
|
|
53
55
|
KIND,
|
|
54
56
|
type ChannelVisibility,
|
|
55
57
|
type UnsignedEvent,
|
|
@@ -77,6 +79,8 @@ export interface FolderRef {
|
|
|
77
79
|
* file even when the file's row did not resolve.
|
|
78
80
|
*/
|
|
79
81
|
addresses?: readonly string[]
|
|
82
|
+
/** `FolderSummary.ids`: the files its state lists by id. Read with {@link listsFile}. */
|
|
83
|
+
ids?: readonly string[]
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
/**
|
|
@@ -155,10 +159,19 @@ export function planDeleteFolder(pubkey: string, createdAtMs: number, args: { fo
|
|
|
155
159
|
export function planPlaceFile(
|
|
156
160
|
pubkey: string,
|
|
157
161
|
createdAtMs: number,
|
|
158
|
-
args: { folder: string; address: string; hasState: boolean },
|
|
162
|
+
args: { folder: string; address: string; hasState: boolean; inOrder?: readonly string[] },
|
|
159
163
|
): UnsignedEvent[] {
|
|
160
164
|
if (!args.hasState) return []
|
|
161
|
-
return [buildFolderCommand(pubkey, createdAtMs, { folder: args.folder, op: 'add', addresses: [args.address] })]
|
|
165
|
+
return [buildFolderCommand(pubkey, createdAtMs, { folder: args.folder, op: 'add', addresses: [listedAs(args.address, args.inOrder)] })]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* How a command names a file: by its id once the relay keeps its type in
|
|
170
|
+
* order (`RelayFileReads.inOrder`, §3.3 "lists by `o` once every app reading
|
|
171
|
+
* the Folder reads both"), else by its address.
|
|
172
|
+
*/
|
|
173
|
+
function listedAs(address: string, inOrder: readonly string[] = []): string {
|
|
174
|
+
return fileIdFormOf(inOrder, address)?.id ?? address
|
|
162
175
|
}
|
|
163
176
|
|
|
164
177
|
/**
|
|
@@ -174,10 +187,10 @@ export function planPlaceFile(
|
|
|
174
187
|
export function planUnlistFile(
|
|
175
188
|
pubkey: string,
|
|
176
189
|
createdAtMs: number,
|
|
177
|
-
args: { folder: string; address: string; hasState: boolean },
|
|
190
|
+
args: { folder: string; address: string; hasState: boolean; inOrder?: readonly string[] },
|
|
178
191
|
): UnsignedEvent[] {
|
|
179
192
|
if (!args.hasState) return []
|
|
180
|
-
return [buildFolderCommand(pubkey, createdAtMs, { folder: args.folder, op: 'remove', addresses: [args.address] })]
|
|
193
|
+
return [buildFolderCommand(pubkey, createdAtMs, { folder: args.folder, op: 'remove', addresses: [listedAs(args.address, args.inOrder)] })]
|
|
181
194
|
}
|
|
182
195
|
|
|
183
196
|
/**
|
|
@@ -230,6 +243,61 @@ export function identifierOf(address: string): string | undefined {
|
|
|
230
243
|
return /^\d+:[0-9a-f]{64}:([^]*)$/.exec(address)?.[1]
|
|
231
244
|
}
|
|
232
245
|
|
|
246
|
+
/**
|
|
247
|
+
* A Folder state's entries (SPEC §3.3), each file once, at its first entry: an
|
|
248
|
+
* `a` by its address, an `o` by its id. A file's address and its id are one
|
|
249
|
+
* entry only when the address is the full address of the file holding the id
|
|
250
|
+
* (its kind, its first record's author, the id), so an `o` and an `a` with
|
|
251
|
+
* that `d` fold into the first of them only then.
|
|
252
|
+
*
|
|
253
|
+
* `holders` is each id's address as a reader resolved it (`addressesOfIds` in
|
|
254
|
+
* projection): an `a` folds with an `o` only when it is that address, so one
|
|
255
|
+
* with another kind or author is drawn beside the file. A reader that has
|
|
256
|
+
* not resolved them passes an empty map, which folds nothing: both entries
|
|
257
|
+
* stay, as §3.3 says of a reader that cannot tell.
|
|
258
|
+
*/
|
|
259
|
+
export function listedEntriesOf(
|
|
260
|
+
state: { tags: string[][] },
|
|
261
|
+
holders: ReadonlyMap<string, string>,
|
|
262
|
+
): { addresses: string[]; ids: string[]; order: string[] } {
|
|
263
|
+
const addresses: string[] = []
|
|
264
|
+
const ids: string[] = []
|
|
265
|
+
const order: string[] = []
|
|
266
|
+
const seenAddress = new Set<string>()
|
|
267
|
+
const seenId = new Set<string>()
|
|
268
|
+
const idsOfAddresses = new Set<string>()
|
|
269
|
+
const holds = (address: string, id: string) => holders.get(id)?.toLowerCase() === address.toLowerCase()
|
|
270
|
+
for (const [name, value] of state.tags) {
|
|
271
|
+
if (!value) continue
|
|
272
|
+
if (name === 'a') {
|
|
273
|
+
const id = identifierOf(value)
|
|
274
|
+
const folded = id !== undefined && seenId.has(id) && holds(value, id)
|
|
275
|
+
if (seenAddress.has(value) || folded) continue
|
|
276
|
+
seenAddress.add(value)
|
|
277
|
+
if (id !== undefined && holds(value, id)) idsOfAddresses.add(id)
|
|
278
|
+
addresses.push(value)
|
|
279
|
+
order.push(value)
|
|
280
|
+
} else if (name === 'o') {
|
|
281
|
+
// An `o` is a file's id; any other value names no file (§3.3).
|
|
282
|
+
if (!isFileId(value) || seenId.has(value) || idsOfAddresses.has(value)) continue
|
|
283
|
+
seenId.add(value)
|
|
284
|
+
ids.push(value)
|
|
285
|
+
order.push(value)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return { addresses, ids, order }
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Whether a Folder lists the file at `address`, by its address or by its id
|
|
293
|
+
* (`FolderSummary.addresses` and `.ids`, SPEC §3.3).
|
|
294
|
+
*/
|
|
295
|
+
export function listsFile(folder: { addresses?: readonly string[]; ids?: readonly string[] }, address: string): boolean {
|
|
296
|
+
if (folder.addresses?.includes(address)) return true
|
|
297
|
+
const id = identifierOf(address)
|
|
298
|
+
return id !== undefined && !!folder.ids?.includes(id)
|
|
299
|
+
}
|
|
300
|
+
|
|
233
301
|
/**
|
|
234
302
|
* A file as a move needs it. A `ForeignObject` from `resolveFolderContents` is
|
|
235
303
|
* one: `ref` is its identity, `parentRef` the file it is drawn beneath, and
|
|
@@ -422,7 +490,7 @@ export function planMoveFromFolders(
|
|
|
422
490
|
for (const from of sources) {
|
|
423
491
|
const listing = args.listings.get(from.id) ?? null
|
|
424
492
|
const unresolved =
|
|
425
|
-
!!listing && !!file.address &&
|
|
493
|
+
!!listing && !!file.address && listsFile(from, file.address) && !listing.some((candidate) => candidate.address === file.address)
|
|
426
494
|
const plan = planMoveFile(pubkey, createdAtMs, {
|
|
427
495
|
file,
|
|
428
496
|
from,
|
package/src/index.ts
CHANGED
|
@@ -118,6 +118,8 @@ export { createLoadQuery, type LoadQueryOptions } from './loadQuery.js'
|
|
|
118
118
|
*/
|
|
119
119
|
export {
|
|
120
120
|
fileCandidates,
|
|
121
|
+
pickedFileUri,
|
|
122
|
+
SHIP_ORIGIN,
|
|
121
123
|
REFERENCE_FILE_TYPES,
|
|
122
124
|
searchFileReferences,
|
|
123
125
|
type FileCandidatesOptions,
|
|
@@ -189,11 +191,15 @@ export {
|
|
|
189
191
|
openFile,
|
|
190
192
|
textOf,
|
|
191
193
|
conflictOf,
|
|
194
|
+
combineChanges,
|
|
192
195
|
writeChange,
|
|
196
|
+
writeChanges,
|
|
193
197
|
type CurrentField,
|
|
194
198
|
type FileFields,
|
|
195
199
|
type Conflict,
|
|
200
|
+
type FieldWrite,
|
|
196
201
|
type WriteChangeArgs,
|
|
202
|
+
type WriteChangesArgs,
|
|
197
203
|
type WriteChangeResult,
|
|
198
204
|
} from './fields.js'
|
|
199
205
|
|
|
@@ -216,6 +222,7 @@ export {
|
|
|
216
222
|
} from './links.js'
|
|
217
223
|
export {
|
|
218
224
|
mentionedInFilter,
|
|
225
|
+
mentionedInFilters,
|
|
219
226
|
mentionedInOf,
|
|
220
227
|
readMentionedIn,
|
|
221
228
|
MENTIONED_IN_LIMIT,
|
package/src/links.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/an-edit-says-what-the-message-links-now.md
|
|
25
25
|
*/
|
|
26
26
|
import { MAX_PARTS } from '@estiva-app/conversation'
|
|
27
|
-
import { partTag, valuesIn, type LinkResolver, type PartPointer, type RenderBlock } from '@estiva-app/protocol'
|
|
27
|
+
import { fileIdFormOf, partTag, valuesIn, type LinkResolver, type PartPointer, type RenderBlock } from '@estiva-app/protocol'
|
|
28
28
|
import { matchObjectUrl, urlPatternsOf, type UrlPattern } from './objectUrl.js'
|
|
29
29
|
import type { QueryFn } from './projection.js'
|
|
30
30
|
|
|
@@ -79,7 +79,11 @@ export interface LinkReader {
|
|
|
79
79
|
* first what its links name and waiting at most `waitMs` (default 5 s): a
|
|
80
80
|
* link not answered by then earns nothing, and the body keeps it.
|
|
81
81
|
*/
|
|
82
|
-
tagsFor(
|
|
82
|
+
tagsFor(
|
|
83
|
+
blocks: readonly RenderBlock[],
|
|
84
|
+
own: OwnPlace,
|
|
85
|
+
options?: { waitMs?: number; edit?: boolean; inOrder?: readonly string[] },
|
|
86
|
+
): Promise<string[][]>
|
|
83
87
|
/** {@link writtenOpenerOf} against the hosts the manifests read so far declare. */
|
|
84
88
|
opener(url: string | undefined, opens: string | undefined, origin: string): string | undefined
|
|
85
89
|
/** Every host an app declares its paths on, as the manifests read so far said. */
|
|
@@ -217,13 +221,13 @@ export function linkReader(options: LinkReaderOptions): LinkReader {
|
|
|
217
221
|
}
|
|
218
222
|
},
|
|
219
223
|
version: () => answered,
|
|
220
|
-
async tagsFor(blocks, own, { waitMs = 5000, edit = false } = {}) {
|
|
224
|
+
async tagsFor(blocks, own, { waitMs = 5000, edit = false, inOrder = [] } = {}) {
|
|
221
225
|
const urls = linksIn(blocks).slice(0, MAX_LINKS_ASKED)
|
|
222
226
|
const waiting = urls.filter((url) => !known.has(url))
|
|
223
227
|
if (waiting.length > 0) await within(Promise.allSettled(waiting.map(answerOf)), waitMs)
|
|
224
228
|
const first = new Set(urls)
|
|
225
229
|
const resolve: LinkResolver = (url) => (first.has(url) ? knownValue(url) : undefined)
|
|
226
|
-
return linkTagsOf(blocks, own, resolve, edit ? undefined : (url) => (first.has(url) ? knownBlock(url) : undefined))
|
|
230
|
+
return linkTagsOf(blocks, own, resolve, edit ? undefined : (url) => (first.has(url) ? knownBlock(url) : undefined), inOrder)
|
|
227
231
|
},
|
|
228
232
|
opener: (url, opens, origin) => writtenOpenerOf(url, opens, origin, origins),
|
|
229
233
|
declaredOrigins: () => origins,
|
|
@@ -256,13 +260,19 @@ export function linksIn(blocks: readonly RenderBlock[]): string[] {
|
|
|
256
260
|
* message links now. An edit carries no `part` (pass no `blockOf`), and a
|
|
257
261
|
* person is never here: `p` and `urgent` stay as the send wrote them.
|
|
258
262
|
*
|
|
263
|
+
* A file whose type the relay keeps in order (`inOrder`) is named by its id
|
|
264
|
+
* too: an `o` after its `a`, and its `part` by the id (§6.4, §13.6.1). An
|
|
265
|
+
* edit carries the `o` as a send does (§6.8).
|
|
266
|
+
*
|
|
259
267
|
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/an-edit-says-what-the-message-links-now.md
|
|
268
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-named-by-its-id-in-a-capital-and-small-tag.md
|
|
260
269
|
*/
|
|
261
270
|
export function linkTagsOf(
|
|
262
271
|
blocks: readonly RenderBlock[],
|
|
263
272
|
own: OwnPlace,
|
|
264
273
|
resolve: LinkResolver,
|
|
265
274
|
blockOf?: (url: string) => PartPointer | undefined,
|
|
275
|
+
inOrder: readonly string[] = [],
|
|
266
276
|
): string[][] {
|
|
267
277
|
const file = own.file && sameValue(own.file)
|
|
268
278
|
const parent = own.parent?.toLowerCase()
|
|
@@ -270,7 +280,11 @@ export function linkTagsOf(
|
|
|
270
280
|
for (const value of valuesIn(blocks, resolve)) {
|
|
271
281
|
if (EVENT_ID.test(value)) {
|
|
272
282
|
if (value !== parent) tags.push(['q', value])
|
|
273
|
-
} else if (value !== file)
|
|
283
|
+
} else if (value !== file) {
|
|
284
|
+
tags.push(['a', value])
|
|
285
|
+
const byId = fileIdFormOf(inOrder, value)
|
|
286
|
+
if (byId && !tags.some((t) => t[0] === 'o' && t[1] === byId.id)) tags.push(['o', byId.id])
|
|
287
|
+
}
|
|
274
288
|
}
|
|
275
289
|
if (blockOf) {
|
|
276
290
|
const parts = new Map<string, string>()
|
|
@@ -279,7 +293,7 @@ export function linkTagsOf(
|
|
|
279
293
|
if (part && sameValue(part.address) !== file && !parts.has(part.address)) parts.set(part.address, part.block)
|
|
280
294
|
}
|
|
281
295
|
// As many as a box shows under it (conversation's `boxLinksOf`): a part the box did not draw is not sent.
|
|
282
|
-
for (const [address, block] of [...parts].slice(0, MAX_PARTS)) tags.push(partTag(address, block))
|
|
296
|
+
for (const [address, block] of [...parts].slice(0, MAX_PARTS)) tags.push(partTag(fileIdFormOf(inOrder, address)?.id ?? address, block))
|
|
283
297
|
}
|
|
284
298
|
return tags
|
|
285
299
|
}
|
package/src/mentions.ts
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/an-edit-says-what-the-message-links-now.md
|
|
16
16
|
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/activity-lists-only-mentions-from-elsewhere.md
|
|
17
17
|
*/
|
|
18
|
-
import {
|
|
19
|
-
import { toRenderTree, valuesIn, type LinkResolver, type SignedEvent } from '@estiva-app/protocol'
|
|
18
|
+
import { editsByTarget, editTargetOf, isAbout, isCommentOn, isCrossedCommentOn, KIND_COMMENT, KIND_EDIT, KIND_MESSAGE } from '@estiva-app/conversation'
|
|
19
|
+
import { fileIdOf, toRenderTree, valuesIn, type LinkResolver, type SignedEvent } from '@estiva-app/protocol'
|
|
20
20
|
import { linksIn, within, MAX_LINKS_ASKED, type LinkReader } from './links.js'
|
|
21
21
|
import type { QueryFn } from './projection.js'
|
|
22
22
|
|
|
@@ -50,11 +50,25 @@ export const MAX_MENTIONED_IN_LINKS_ASKED = 64
|
|
|
50
50
|
*/
|
|
51
51
|
const linksNaming = (tree: ReturnType<typeof toRenderTree>) => linksIn(tree).slice(0, MAX_LINKS_ASKED)
|
|
52
52
|
|
|
53
|
-
/** The
|
|
53
|
+
/** The filter for the candidates pointing at the file by its address: every message, comment and edit with its `a`. */
|
|
54
54
|
export function mentionedInFilter(address: string, limit = MENTIONED_IN_LIMIT): Record<string, unknown> {
|
|
55
55
|
return { kinds: [KIND_COMMENT, KIND_MESSAGE, KIND_EDIT], '#a': [address], limit }
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Every filter for the candidates: {@link mentionedInFilter}, and the one
|
|
60
|
+
* asking by the file's id, since a mention names a file by `o` alone once its
|
|
61
|
+
* type's apps name it by id (§6.4). One request either way.
|
|
62
|
+
*/
|
|
63
|
+
export function mentionedInFilters(address: string, limit = MENTIONED_IN_LIMIT): Record<string, unknown>[] {
|
|
64
|
+
const id = fileIdOf(address)
|
|
65
|
+
return [mentionedInFilter(address, limit), ...(id ? [{ kinds: [KIND_COMMENT, KIND_MESSAGE, KIND_EDIT], '#o': [id], limit }] : [])]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Whether a tag points at the file: an `a` with its address, or an `o` with its id. */
|
|
69
|
+
const pointsAt = (t: readonly string[], address: string, id: string | undefined) =>
|
|
70
|
+
(t[0] === 'a' && t[1] === address) || (id !== undefined && t[0] === 'o' && t[1] === id)
|
|
71
|
+
|
|
58
72
|
const isMessage = (event: SignedEvent) => event.kind === KIND_COMMENT || event.kind === KIND_MESSAGE
|
|
59
73
|
|
|
60
74
|
/**
|
|
@@ -79,8 +93,9 @@ export function mentionedInOf(
|
|
|
79
93
|
for (const event of events) if (isMessage(event)) messages.set(event.id.toLowerCase(), event)
|
|
80
94
|
const edits = editsByTarget(events)
|
|
81
95
|
const pointed = new Set<string>()
|
|
96
|
+
const fileId = fileIdOf(address)
|
|
82
97
|
for (const event of events) {
|
|
83
|
-
if (!event.tags.some((t) => t
|
|
98
|
+
if (!event.tags.some((t) => pointsAt(t, address, fileId))) continue
|
|
84
99
|
const id = event.kind === KIND_EDIT ? editTargetOf(event) : isMessage(event) ? event.id.toLowerCase() : undefined
|
|
85
100
|
if (id) pointed.add(id)
|
|
86
101
|
}
|
|
@@ -88,13 +103,14 @@ export function mentionedInOf(
|
|
|
88
103
|
const out: MentionedIn[] = []
|
|
89
104
|
for (const id of pointed) {
|
|
90
105
|
const event = messages.get(id)
|
|
91
|
-
|
|
92
|
-
if (
|
|
106
|
+
// A comment whose root and `O` disagree is ignored under every file (§6.4), its body's links included.
|
|
107
|
+
if (!event || isCrossedCommentOn(event, address)) continue
|
|
108
|
+
if ((event.kind === KIND_COMMENT && isAbout(event, address)) || isCommentOn(event, address, commentKinds)) continue
|
|
93
109
|
// An edit by anyone but the author is not the message's (the relay refuses one; a reader does not trust that).
|
|
94
110
|
const edit = edits.get(id)?.filter((e) => e.pubkey === event.pubkey).at(-1)
|
|
95
111
|
const body = edit?.content ?? event.content
|
|
96
112
|
const tree = toRenderTree(body, 'marker')
|
|
97
|
-
const pointsNow = (edit ?? event).tags.some((t) => t
|
|
113
|
+
const pointsNow = (edit ?? event).tags.some((t) => pointsAt(t, address, fileId))
|
|
98
114
|
const first = linksNaming(tree)
|
|
99
115
|
const named = new Set(first)
|
|
100
116
|
const resolve: LinkResolver | undefined = resolveLink && ((url) => (named.has(url) ? resolveLink(url) : undefined))
|
|
@@ -116,7 +132,7 @@ export async function readMentionedIn(
|
|
|
116
132
|
address: string,
|
|
117
133
|
options: { links?: LinkReader; limit?: number; waitMs?: number; commentKinds?: readonly number[] } = {},
|
|
118
134
|
): Promise<MentionedIn[]> {
|
|
119
|
-
const candidates = await query(
|
|
135
|
+
const candidates = await query(mentionedInFilters(address, options.limit))
|
|
120
136
|
const held = new Set(candidates.filter(isMessage).map((e) => e.id.toLowerCase()))
|
|
121
137
|
const missing = [...new Set(candidates.filter((e) => e.kind === KIND_EDIT).map(editTargetOf))].filter((id): id is string => !!id && !held.has(id))
|
|
122
138
|
const targets = missing.length ? await query([{ ids: missing, kinds: [KIND_COMMENT, KIND_MESSAGE] }]) : []
|