@estiva-app/interop 0.72.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 CHANGED
@@ -6,6 +6,66 @@ how a declaration is read, is a MAJOR — in `0.x`, a MINOR — even when no
6
6
  TypeScript signature moved. A consumer upgrading must be able to tell whether
7
7
  manifests already published still mean what they meant.
8
8
 
9
+ ## 0.74.0 — 2026-11-02
10
+
11
+ **Manifest: nothing. Wire: a move is one `kind:1852 op: move` per source,
12
+ not an add and a remove** (TEA-3; SPEC §3.3; record
13
+ [a-topic-always-has-a-team-and-moves-in-one-action](https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-topic-always-has-a-team-and-moves-in-one-action.md)).
14
+ Needs protocol 0.49.0 and a relay that knows `move`.
15
+
16
+ - `planMoveFile` returns one event, the `move` in the target naming the
17
+ source in `from`. The relay changes both lists or neither, so a topic is
18
+ never on no list between the two halves.
19
+ - **Breaking:** `planMoveFromFolders` returns `{ ok: true, events, moved }`,
20
+ like `planMoveFile`, in place of `add` and `removes`. `events` holds one
21
+ `move` per source that lists part of the set, each naming what that source
22
+ lists, or one `add` when no source lists any of it. Publish them in order
23
+ and stop at the first refusal: each changes both its lists or neither, so
24
+ what landed stands, and moving again finishes it. Callers that published
25
+ `add` then each `removes[i].event` publish `events` in order instead.
26
+ - A topic no team lists is placed only at home: in the team its `h` names,
27
+ or in the Company team. Anywhere else `planMoveFromFolders` refuses with
28
+ `target-is-not-home`, and the relay refuses it too.
29
+ - `FolderSummary.company` (and `FolderRef.company`): the relay marks the
30
+ Company team with `["company"]` on its `kind:39000` (§3.4).
31
+ - `readMoveRefusal(events, index, reason)`: what a refused command means
32
+ (`team-archived`, `not-a-member`, `changed-meanwhile` or `refused`),
33
+ whether anything moved, and which sources still list the file, so an app
34
+ says it in its own words rather than showing the relay's.
35
+
36
+ ## 0.73.0 — 2026-11-02
37
+
38
+ **Manifest: nothing. Wire: every change now names its file in `O`, and a
39
+ change can name the one it follows** (ALO-7; SPEC §6.2, §6.13, §13.3; records
40
+ [a-file-is-its-fields-each-kept-in-order-by-the-relay](https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-its-fields-each-kept-in-order-by-the-relay.md),
41
+ [opening-a-file-reads-its-current-text-not-its-history](https://github.com/estiva-app/estiva-docs/blob/main/decisions/opening-a-file-reads-its-current-text-not-its-history.md),
42
+ [merging-two-changes-to-one-text-never-loses-words](https://github.com/estiva-app/estiva-docs/blob/main/decisions/merging-two-changes-to-one-text-never-loses-words.md)).
43
+
44
+ - `buildActionEvent`'s change writes `["O", <d>]` after `a` (and
45
+ `planArchiveFolder` the same), takes `prev` (written after `ts`; refused on
46
+ anything that is not a change, or that is not an event id), and writes
47
+ `["stage", <field>, <stage>]` last when the chosen option of an `enum`
48
+ carries one of the four stages. The relay only checks that `O` is the `a`'s
49
+ `d`, so a change to any kind takes it.
50
+ - New: `listFiles` and `openFile`, the relay's list read (`"fields": "newest"`)
51
+ and its opening read (`"text": true` beside `#d`), folded by `filesOf` into
52
+ each file's current change per field, whose id is the field's next `prev`. A
53
+ list never carries the text. For a relay whose NIP-11 advertises `file_list`
54
+ (`relayFileReadsOf`, protocol 0.48.0); `text` only where it says so.
55
+ - New: `writeChange`, the change writer that answers `conflict:` as §6.2 says.
56
+ A field set again after a stale `prev` follows the current change and
57
+ stands; a text merges by §13.3 (`mergeTexts`) onto the current one and says
58
+ whose it merged onto, or sends nothing and returns the blocks that ask and
59
+ theirs; a change stamped before its `prev` goes 1 ms after it; `invalid:` is
60
+ never sent again; four tries, then the relay's last answer.
61
+ - Needs `@estiva-app/protocol` 0.48.0.
62
+
63
+ Checked on production as QA-1 and QA-2 (2026-11-02): a text change to another
64
+ block merged onto QA-1's and kept both people's words; one to the same block
65
+ asked and left QA-1's text current; a status set from an older copy stood, with
66
+ both in its history; a writer whose clock was two minutes behind was stamped
67
+ 1 ms after its `prev` and accepted.
68
+
9
69
  ## 0.72.0 — 2026-11-02
10
70
 
11
71
  **Manifest: nothing.** Many topics' lists in one go, for Peek's Topics screen
package/README.md CHANGED
@@ -699,27 +699,27 @@ The planners are SPEC §3.3's operations — `planCreateFolder`,
699
699
  `planUnlistFile`, `planMoveFile` and `planMoveFromFolders` — and return **unsigned** events in publish
700
700
  order. Signing and publishing stay yours.
701
701
 
702
- A move is one `kind:1852 add` in the target naming the file and every file
703
- listed beneath it (`listedBeneath`), then one `remove` naming the same set in
704
- the source, so a failure between the two leaves the whole subtree in both
705
- Folders and never splits it. Into a private Folder it is refused when any moved
706
- file's `h` is another channel, or absent: a listing never changes who can read
707
- a file (§3.1).
702
+ A move is one `kind:1852 move` in the target, naming the source in `from` and
703
+ the file with every file listed beneath it (`listedBeneath`). The relay changes
704
+ both lists in one write or neither, so the subtree is never split and a topic is
705
+ never on no list. Into a private Folder it is refused when any moved file's `h`
706
+ is another channel, or absent: a listing never changes who can read a file
707
+ (§3.1).
708
708
 
709
709
  A file can be listed in more than one Folder. To move it out of all of them,
710
710
  use `planMoveFromFolders`, which takes every Folder that lists it and each one's
711
- listing. It plans **one** add naming everything from all of them, so the add
712
- lands whole or not at all, and then one remove per source. A file listed nowhere
713
- is placed instead. Read those listings with `includeArchived`, or an archived
714
- file beneath the one you move stays behind:
711
+ listing. It plans one move per source, each naming what that source lists. A
712
+ file listed nowhere is placed instead, with one add. Publish the events in order
713
+ and stop at the first refusal; what landed stands, and moving again finishes it.
714
+ Read those listings with `includeArchived`, or an archived file beneath the one
715
+ you move stays behind:
715
716
 
716
717
  ```ts
717
718
  const listings = new Map(await Promise.all(sources.map(async (folder) =>
718
719
  [folder.id, (await resolveFolderContents(folder.id, query, noPeople, cache, { includeArchived: true })).files] as const)))
719
720
  const plan = planMoveFromFolders(me, Date.now(), { file, from: sources, to, listings }) // sources: FolderSummary[], with addresses
720
721
  if (!plan.ok) return plan.reason
721
- if (plan.add && !(await publish(await sign(plan.add))).ok) return 'nothing moved'
722
- for (const { folder, event } of plan.removes) await publish(await sign(event)) // a refusal: still listed in `folder` too
722
+ for (const event of plan.events) if (!(await publish(await sign(event))).ok) return 'refused' // the relay's reason says why
723
723
  ```
724
724
 
725
725
  No command carries a name: the title is the `kind:39000`'s, so a rename is the
@@ -0,0 +1,205 @@
1
+ /**
2
+ * A file as its fields, each kept in order by the relay — SPEC §6.2, §6.13.
3
+ *
4
+ * Two halves, both for any type the relay keeps:
5
+ *
6
+ * - **Reading** a list or one file with the relay's list read
7
+ * (`"fields": "newest"`), which answers each file's first record and, for
8
+ * each field, only its current change: a list never carries the text, and
9
+ * opening one file (`"text": true` beside `#d`) carries its current text and
10
+ * none of its history. Each change's id is that field's next `prev`.
11
+ * - **Writing** a change that names the one it follows, and answering the
12
+ * relay's `conflict:` as §6.2 says: a field set again keeps the later, and a
13
+ * text merges by §13.3's rule, or stops and asks when a block was changed by
14
+ * both or edited against a delete. It never writes over someone's newer
15
+ * words.
16
+ *
17
+ * Only for a relay whose NIP-11 advertises `file_list` (`relayFileReadsOf` in
18
+ * `@estiva-app/protocol`), and `"text"` only where it says `text`: a relay
19
+ * without them answers these reads as if they were plain ones.
20
+ *
21
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-its-fields-each-kept-in-order-by-the-relay.md
22
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/opening-a-file-reads-its-current-text-not-its-history.md
23
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/merging-two-changes-to-one-text-never-loses-words.md
24
+ */
25
+ import { type MergeAsk, type MergeText, type SignedEvent, type UnsignedEvent } from '@estiva-app/protocol';
26
+ import { type QueryFn } from './projection.js';
27
+ /** The field that holds a file's text (§6.10): the one field that merges rather than re-sets. */
28
+ export declare const TEXT_FIELD = "description";
29
+ /** One field's current value, and the change that set it. */
30
+ export interface CurrentField {
31
+ value: string;
32
+ /** The value's `content-format`, for the text; absent for marker text. */
33
+ format?: string;
34
+ /** The change's id: the field's next `prev`. */
35
+ id: string;
36
+ /** Who set it. */
37
+ pubkey: string;
38
+ /** When, in ms: `ts` where it agrees with `created_at` to the second (§6.2), else `created_at`. */
39
+ at: number;
40
+ event: SignedEvent;
41
+ }
42
+ /** A file read by its fields. */
43
+ export interface FileFields {
44
+ root: SignedEvent;
45
+ /** `<kind>:<pubkey>:<d>`. */
46
+ address: string;
47
+ /** Each field's current change. The text is here only when the file was opened with it. */
48
+ fields: Record<string, CurrentField>;
49
+ /** The root and each current change, as signed — what a fold of every change would read the same. */
50
+ events: SignedEvent[];
51
+ }
52
+ /** When a change happened, in ms, by §6.3's order. */
53
+ export declare function changedAt(event: SignedEvent): number;
54
+ /**
55
+ * The fields one change sets, with their values: one `field`/`value`, or one
56
+ * per `set` (§6.2). A change setting the text carries its `content-format`.
57
+ */
58
+ export declare function fieldsSetBy(event: {
59
+ tags: string[][];
60
+ }): {
61
+ field: string;
62
+ value: string;
63
+ format?: string;
64
+ }[];
65
+ /**
66
+ * Each file the events hold, by its first record and the current change of each
67
+ * of its fields.
68
+ *
69
+ * A change counts only where §6.2 says a reader folds it: its `a` names the
70
+ * file, its `O` (if any) is the file's id, and its `h` is the file's home. The
71
+ * text counts only when `withText`: a list never takes the text from a change
72
+ * that set several fields, since a later text-only change may have replaced it
73
+ * (§6.13).
74
+ */
75
+ export declare function filesOf(events: readonly SignedEvent[], options?: {
76
+ withText?: boolean;
77
+ }): FileFields[];
78
+ /**
79
+ * A list of files by the relay's list read: each first record the filter picks,
80
+ * with its fields' current changes and never its text (§6.13).
81
+ *
82
+ * `filter` picks first records, as §6.13 says: `#h` for a Folder's issues,
83
+ * `kinds` alone for the workspace's projects, `#d` for named ones, `search`
84
+ * for typing. Only for a relay advertising `file_list`.
85
+ */
86
+ export declare function listFiles(query: QueryFn, filter: Record<string, unknown>): Promise<FileFields[]>;
87
+ /**
88
+ * One file, opened: its first record, its fields' current changes and, where
89
+ * the relay says `file_list.text`, its current text — one text however long
90
+ * its history (§6.13, C40). Undefined when the relay holds no such file the
91
+ * reader may read.
92
+ *
93
+ * Without `text` the answer has no text field at all, which is not "the text
94
+ * was never changed": a caller that needs it reads it the old way.
95
+ */
96
+ export declare function openFile(query: QueryFn, file: {
97
+ kind: number;
98
+ pubkey: string;
99
+ d: string;
100
+ }, options: {
101
+ text: boolean;
102
+ }): Promise<FileFields | undefined>;
103
+ /**
104
+ * The text a change or first record holds: a change's `description`, or a
105
+ * first record's seed — a project's `description` tag, then its `content`
106
+ * (§6.2, §7.2).
107
+ */
108
+ export declare function textOf(event: SignedEvent): MergeText | undefined;
109
+ /** What a `conflict:` refusal says (§6.2), as the relay words it. */
110
+ export type Conflict = {
111
+ kind: 'stale';
112
+ field: string;
113
+ current?: string;
114
+ } | {
115
+ kind: 'sorts-before';
116
+ field: string;
117
+ } | {
118
+ kind: 'other';
119
+ };
120
+ export declare function conflictOf(reason: string): Conflict | undefined;
121
+ /** What {@link writeChange} is handed. */
122
+ export interface WriteChangeArgs {
123
+ field: string;
124
+ /** The value to set; for the text, mine. */
125
+ value: string;
126
+ /** The text's `content-format`, when it is one. */
127
+ format?: string;
128
+ /**
129
+ * The change this one follows, as the writer read it: the field's current
130
+ * change, or the first record's id for its first change. For the text it is
131
+ * also the base a merge starts from — the version the person, or the agent,
132
+ * last read.
133
+ */
134
+ prev: string;
135
+ /**
136
+ * The unsigned change for this value, `prev` and time — `buildActionEvent`
137
+ * bound to the field's action, so the manifest decides its shape and every
138
+ * attempt carries the same tags.
139
+ */
140
+ build: (input: {
141
+ value: string;
142
+ format?: string;
143
+ prev: string;
144
+ createdAtMs: number;
145
+ }) => UnsignedEvent | string;
146
+ sign: (event: UnsignedEvent) => Promise<SignedEvent>;
147
+ publish: (event: SignedEvent) => Promise<{
148
+ ok: boolean;
149
+ reason?: string;
150
+ eventId?: string;
151
+ }>;
152
+ /** Reads events by id, and the field's current change when a refusal names none. */
153
+ query: QueryFn;
154
+ /** The field's current change, read again: {@link openFile}'s, for this field. */
155
+ current: (field: string) => Promise<SignedEvent | undefined>;
156
+ /** The clock, in ms. */
157
+ now?: () => number;
158
+ /** How many sends before giving up; 4 unless said. */
159
+ tries?: number;
160
+ }
161
+ export type WriteChangeResult = {
162
+ ok: true;
163
+ /** The id the relay accepted: the field's next `prev`. */
164
+ id: string;
165
+ event: SignedEvent;
166
+ /** Set when the text was merged onto someone's newer change, which it names. */
167
+ mergedOnto?: SignedEvent;
168
+ } | {
169
+ ok: true;
170
+ /** Nothing was sent: mine, merged onto theirs, says nothing theirs does not. */
171
+ unchanged: true;
172
+ id: string;
173
+ mergedOnto: SignedEvent;
174
+ } | {
175
+ ok: false;
176
+ /** Why nothing was saved, in the relay's words or the builder's. */
177
+ refused: string;
178
+ } | {
179
+ ok: false;
180
+ /** The text asks: these blocks were changed by both, or edited against a delete. Nothing was saved. */
181
+ asks: MergeAsk[];
182
+ /** The change now current, whose words must be kept. */
183
+ theirs: SignedEvent;
184
+ };
185
+ /**
186
+ * Write one field's change, naming the one it follows, and answer a
187
+ * `conflict:` as §6.2 says.
188
+ *
189
+ * - **Stale `prev`, a field other than the text**: read the current change
190
+ * (by the id the relay named, or {@link WriteChangeArgs.current} when it
191
+ * named none) and set the value again after it. Two setting one field is not
192
+ * a conflict to show: the later stands.
193
+ * - **Stale `prev`, the text**: merge mine onto the current text by §13.3,
194
+ * with the text `prev` named as the base, and send the merge after it. When
195
+ * a block asks, nothing is sent and the answer carries the blocks and
196
+ * theirs. Refused again, it merges again with what it last sent as mine and
197
+ * what it merged onto as the base.
198
+ * - **Does not sort after its `prev`**: the clock is behind; stamp it 1 ms
199
+ * after `prev`, `ts` and `created_at` agreeing.
200
+ * - **Anything else** (`invalid:` and the rest) is never sent again.
201
+ *
202
+ * A few tries, then it stops with the relay's last answer.
203
+ */
204
+ export declare function writeChange(args: WriteChangeArgs): Promise<WriteChangeResult>;
205
+ //# sourceMappingURL=fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA;;;;;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OAAO,CAAC,iBAAiB,CAAC,CAsDnF"}
package/dist/fields.js ADDED
@@ -0,0 +1,250 @@
1
+ /**
2
+ * A file as its fields, each kept in order by the relay — SPEC §6.2, §6.13.
3
+ *
4
+ * Two halves, both for any type the relay keeps:
5
+ *
6
+ * - **Reading** a list or one file with the relay's list read
7
+ * (`"fields": "newest"`), which answers each file's first record and, for
8
+ * each field, only its current change: a list never carries the text, and
9
+ * opening one file (`"text": true` beside `#d`) carries its current text and
10
+ * none of its history. Each change's id is that field's next `prev`.
11
+ * - **Writing** a change that names the one it follows, and answering the
12
+ * relay's `conflict:` as §6.2 says: a field set again keeps the later, and a
13
+ * text merges by §13.3's rule, or stops and asks when a block was changed by
14
+ * both or edited against a delete. It never writes over someone's newer
15
+ * words.
16
+ *
17
+ * Only for a relay whose NIP-11 advertises `file_list` (`relayFileReadsOf` in
18
+ * `@estiva-app/protocol`), and `"text"` only where it says `text`: a relay
19
+ * without them answers these reads as if they were plain ones.
20
+ *
21
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-its-fields-each-kept-in-order-by-the-relay.md
22
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/opening-a-file-reads-its-current-text-not-its-history.md
23
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/merging-two-changes-to-one-text-never-loses-words.md
24
+ */
25
+ import { CONTENT_FORMAT_TAG, mergeTexts, } from '@estiva-app/protocol';
26
+ import { folderOf } from './projection.js';
27
+ /** The change event every Estiva app writes (SPEC §6.2). */
28
+ const KIND_CHANGE = 1851;
29
+ /** The field that holds a file's text (§6.10): the one field that merges rather than re-sets. */
30
+ export const TEXT_FIELD = 'description';
31
+ const tagValue = (event, name) => event.tags.find((t) => t[0] === name)?.[1];
32
+ /** When a change happened, in ms, by §6.3's order. */
33
+ export function changedAt(event) {
34
+ const ts = Number(tagValue(event, 'ts'));
35
+ return Number.isFinite(ts) && Math.floor(ts / 1000) === event.created_at ? ts : event.created_at * 1000;
36
+ }
37
+ /** Newer first by §6.3: time, then `created_at`, then id. */
38
+ function newer(a, b) {
39
+ const at = changedAt(a) - changedAt(b);
40
+ if (at !== 0)
41
+ return at > 0;
42
+ if (a.created_at !== b.created_at)
43
+ return a.created_at > b.created_at;
44
+ return a.id > b.id;
45
+ }
46
+ /**
47
+ * The fields one change sets, with their values: one `field`/`value`, or one
48
+ * per `set` (§6.2). A change setting the text carries its `content-format`.
49
+ */
50
+ export function fieldsSetBy(event) {
51
+ const format = tagValue(event, CONTENT_FORMAT_TAG);
52
+ const withFormat = (field, value) => field === TEXT_FIELD && format ? { field, value, format } : { field, value };
53
+ const sets = event.tags.filter((t) => t[0] === 'set' && typeof t[1] === 'string');
54
+ if (sets.length)
55
+ return sets.map((t) => withFormat(t[1], t[2] ?? ''));
56
+ const field = tagValue(event, 'field');
57
+ return field === undefined ? [] : [withFormat(field, tagValue(event, 'value') ?? '')];
58
+ }
59
+ const addressOfRoot = (root) => `${root.kind}:${root.pubkey}:${tagValue(root, 'd') ?? ''}`;
60
+ /**
61
+ * Each file the events hold, by its first record and the current change of each
62
+ * of its fields.
63
+ *
64
+ * A change counts only where §6.2 says a reader folds it: its `a` names the
65
+ * file, its `O` (if any) is the file's id, and its `h` is the file's home. The
66
+ * text counts only when `withText`: a list never takes the text from a change
67
+ * that set several fields, since a later text-only change may have replaced it
68
+ * (§6.13).
69
+ */
70
+ export function filesOf(events, options = {}) {
71
+ const roots = new Map();
72
+ for (const event of events) {
73
+ if (event.kind === KIND_CHANGE || tagValue(event, 'd') === undefined)
74
+ continue;
75
+ const address = addressOfRoot(event);
76
+ const held = roots.get(address);
77
+ if (!held || event.created_at > held.created_at)
78
+ roots.set(address, event);
79
+ }
80
+ const files = new Map();
81
+ for (const [address, root] of roots)
82
+ files.set(address, { root, address, fields: {}, events: [root] });
83
+ for (const event of events) {
84
+ if (event.kind !== KIND_CHANGE)
85
+ continue;
86
+ const file = files.get(tagValue(event, 'a') ?? '');
87
+ if (!file)
88
+ continue;
89
+ const O = tagValue(event, 'O');
90
+ if (O !== undefined && O !== tagValue(file.root, 'd'))
91
+ continue;
92
+ if (tagValue(event, 'h') !== (folderOf(file.root) ?? undefined))
93
+ continue;
94
+ for (const set of fieldsSetBy(event)) {
95
+ if (set.field === TEXT_FIELD && !options.withText)
96
+ continue;
97
+ const held = file.fields[set.field];
98
+ if (held && !newer(event, held.event))
99
+ continue;
100
+ file.fields[set.field] = { ...set, id: event.id, pubkey: event.pubkey, at: changedAt(event), event };
101
+ }
102
+ }
103
+ // The root and each change some field still points at, once.
104
+ for (const file of files.values()) {
105
+ const current = new Map(Object.values(file.fields).map((f) => [f.id, f.event]));
106
+ file.events = [file.root, ...current.values()];
107
+ }
108
+ return [...files.values()];
109
+ }
110
+ /**
111
+ * A list of files by the relay's list read: each first record the filter picks,
112
+ * with its fields' current changes and never its text (§6.13).
113
+ *
114
+ * `filter` picks first records, as §6.13 says: `#h` for a Folder's issues,
115
+ * `kinds` alone for the workspace's projects, `#d` for named ones, `search`
116
+ * for typing. Only for a relay advertising `file_list`.
117
+ */
118
+ export async function listFiles(query, filter) {
119
+ if ('text' in filter)
120
+ throw new Error('A list never carries text; open one file to read it.');
121
+ const events = await query([{ ...filter, fields: 'newest' }]);
122
+ return filesOf(events);
123
+ }
124
+ /**
125
+ * One file, opened: its first record, its fields' current changes and, where
126
+ * the relay says `file_list.text`, its current text — one text however long
127
+ * its history (§6.13, C40). Undefined when the relay holds no such file the
128
+ * reader may read.
129
+ *
130
+ * Without `text` the answer has no text field at all, which is not "the text
131
+ * was never changed": a caller that needs it reads it the old way.
132
+ */
133
+ export async function openFile(query, file, options) {
134
+ // By `#d` alone, the shape §6.13 names; the author is checked below.
135
+ const filter = { fields: 'newest', kinds: [file.kind], '#d': [file.d] };
136
+ if (options.text)
137
+ filter.text = true;
138
+ const events = await query([filter]);
139
+ const address = `${file.kind}:${file.pubkey}:${file.d}`;
140
+ return filesOf(events, { withText: options.text }).find((f) => f.address === address);
141
+ }
142
+ /**
143
+ * The text a change or first record holds: a change's `description`, or a
144
+ * first record's seed — a project's `description` tag, then its `content`
145
+ * (§6.2, §7.2).
146
+ */
147
+ export function textOf(event) {
148
+ if (event.kind === KIND_CHANGE) {
149
+ const set = fieldsSetBy(event).find((f) => f.field === TEXT_FIELD);
150
+ return set ? { value: set.value, ...(set.format ? { format: set.format } : {}) } : undefined;
151
+ }
152
+ const format = tagValue(event, CONTENT_FORMAT_TAG);
153
+ const value = tagValue(event, TEXT_FIELD) ?? event.content;
154
+ return { value, ...(format ? { format } : {}) };
155
+ }
156
+ export function conflictOf(reason) {
157
+ if (!reason.startsWith('conflict:'))
158
+ return undefined;
159
+ const sorts = /^conflict: (\S+) does not sort after its prev\b/.exec(reason);
160
+ if (sorts)
161
+ return { kind: 'sorts-before', field: sorts[1] };
162
+ const follows = /^conflict: (\S+) follows ([0-9a-f]{64})\s*$/.exec(reason);
163
+ if (follows)
164
+ return { kind: 'stale', field: follows[1], current: follows[2] };
165
+ // A signer who cannot read the file's home is told only the field.
166
+ const bare = /^conflict: (\S+)\s*$/.exec(reason);
167
+ if (bare)
168
+ return { kind: 'stale', field: bare[1] };
169
+ return { kind: 'other' };
170
+ }
171
+ const byId = async (query, id) => (await query([{ ids: [id] }])).find((e) => e.id === id);
172
+ /**
173
+ * Write one field's change, naming the one it follows, and answer a
174
+ * `conflict:` as §6.2 says.
175
+ *
176
+ * - **Stale `prev`, a field other than the text**: read the current change
177
+ * (by the id the relay named, or {@link WriteChangeArgs.current} when it
178
+ * named none) and set the value again after it. Two setting one field is not
179
+ * a conflict to show: the later stands.
180
+ * - **Stale `prev`, the text**: merge mine onto the current text by §13.3,
181
+ * with the text `prev` named as the base, and send the merge after it. When
182
+ * a block asks, nothing is sent and the answer carries the blocks and
183
+ * theirs. Refused again, it merges again with what it last sent as mine and
184
+ * what it merged onto as the base.
185
+ * - **Does not sort after its `prev`**: the clock is behind; stamp it 1 ms
186
+ * after `prev`, `ts` and `created_at` agreeing.
187
+ * - **Anything else** (`invalid:` and the rest) is never sent again.
188
+ *
189
+ * A few tries, then it stops with the relay's last answer.
190
+ */
191
+ export async function writeChange(args) {
192
+ const now = args.now ?? Date.now;
193
+ const tries = args.tries ?? 4;
194
+ const isText = args.field === TEXT_FIELD;
195
+ let prev = args.prev;
196
+ let after = 0;
197
+ let mine = { value: args.value, ...(args.format ? { format: args.format } : {}) };
198
+ let base;
199
+ let mergedOnto;
200
+ let last = '';
201
+ for (let attempt = 0; attempt < tries; attempt++) {
202
+ const built = args.build({ value: mine.value, format: mine.format, prev, createdAtMs: Math.max(now(), after) });
203
+ if (typeof built === 'string')
204
+ return { ok: false, refused: built };
205
+ const signed = await args.sign(built);
206
+ const answer = await args.publish(signed);
207
+ if (answer.ok)
208
+ return { ok: true, id: answer.eventId ?? signed.id, event: signed, ...(mergedOnto ? { mergedOnto } : {}) };
209
+ last = answer.reason ?? 'refused with no reason';
210
+ const conflict = conflictOf(last);
211
+ if (!conflict || conflict.kind === 'other' || conflict.field !== args.field)
212
+ return { ok: false, refused: last };
213
+ if (conflict.kind === 'sorts-before') {
214
+ const followed = await byId(args.query, prev);
215
+ if (!followed)
216
+ return { ok: false, refused: last };
217
+ after = changedAt(followed) + 1;
218
+ continue;
219
+ }
220
+ const head = conflict.current ? await byId(args.query, conflict.current) : await args.current(args.field);
221
+ if (!head)
222
+ return { ok: false, refused: last };
223
+ after = changedAt(head) + 1;
224
+ if (!isText) {
225
+ prev = head.id;
226
+ continue;
227
+ }
228
+ if (!base) {
229
+ const followed = await byId(args.query, prev);
230
+ base = followed && textOf(followed);
231
+ if (!base)
232
+ return { ok: false, refused: `${last} (the text it followed, ${prev}, could not be read to merge onto)` };
233
+ }
234
+ const theirs = textOf(head);
235
+ if (!theirs)
236
+ return { ok: false, refused: last };
237
+ const merge = mergeTexts(base, theirs, mine);
238
+ if (merge.asks)
239
+ return { ok: false, asks: merge.asks, theirs: head };
240
+ mergedOnto = head;
241
+ if (merge.merged.value === theirs.value && (merge.merged.format ?? '') === (theirs.format ?? '')) {
242
+ return { ok: true, unchanged: true, id: head.id, mergedOnto: head };
243
+ }
244
+ base = theirs;
245
+ mine = merge.merged;
246
+ prev = head.id;
247
+ }
248
+ return { ok: false, refused: `still refused after ${tries} tries: ${last}` };
249
+ }
250
+ //# sourceMappingURL=fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.js","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EACL,kBAAkB,EAClB,UAAU,GAKX,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAgB,MAAM,iBAAiB,CAAA;AAExD,4DAA4D;AAC5D,MAAM,WAAW,GAAG,IAAI,CAAA;AAExB,iGAAiG;AACjG,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAA;AA2BvC,MAAM,QAAQ,GAAG,CAAC,KAA2B,EAAE,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAE1G,sDAAsD;AACtD,MAAM,UAAU,SAAS,CAAC,KAAkB;IAC1C,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;IACxC,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAA;AACzG,CAAC;AAED,6DAA6D;AAC7D,SAAS,KAAK,CAAC,CAAc,EAAE,CAAc;IAC3C,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CA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