@estiva-app/protocol 0.5.0 → 0.7.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 +93 -0
- package/dist/blocks.d.ts +87 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +257 -0
- package/dist/blocks.js.map +1 -0
- package/dist/content.d.ts +107 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +311 -0
- package/dist/content.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/blocks.ts +276 -0
- package/src/content.ts +350 -0
- package/src/index.ts +33 -1
package/dist/content.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The message marker dialect — SPEC §13.1 and §13.2.
|
|
3
|
+
*
|
|
4
|
+
* ## Why content is in a package that "interprets nothing"
|
|
5
|
+
*
|
|
6
|
+
* `index.ts` draws the line at *interpretation*: the fold stays in the apps,
|
|
7
|
+
* because how an app turns events into current truth is where apps are supposed
|
|
8
|
+
* to differ. A body's formatting is on the other side of that line for the same
|
|
9
|
+
* reason the event id is — **it is wire-visible, and two apps disagreeing about
|
|
10
|
+
* it produces a divergence each copy is self-consistent about and nobody
|
|
11
|
+
* notices.** That is not a hypothetical: measured on production 2026-09-02,
|
|
12
|
+
* 261 of 548 published messages carry structure, Peek parses it, Ship renders
|
|
13
|
+
* it literally, and neither is wrong about its own behaviour.
|
|
14
|
+
*
|
|
15
|
+
* Being honest about the usual test: the relay would *not* notice if two apps
|
|
16
|
+
* disagreed here, so §10's question is a poor fit. What makes this belong is the
|
|
17
|
+
* failure shape rather than the arbiter — see RFC 0.4 §14.3, which put the
|
|
18
|
+
* inline layer here, and SPEC §13.1, which made it normative.
|
|
19
|
+
*
|
|
20
|
+
* **What is deliberately not here.** Mentions resolved against a directory,
|
|
21
|
+
* bracket references to an app's own objects, and anything that needs to know
|
|
22
|
+
* what a topic or a file is. Peek's `textParsing.ts` mixes those with the marks;
|
|
23
|
+
* only the marks moved. A `nostr:` reference is a mark and its *token* is in
|
|
24
|
+
* scope, but what a mention does is RIC-2's.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Longest token first so `***` is not consumed as `**` plus a dangling `*`.
|
|
28
|
+
*
|
|
29
|
+
* Order only decides ties at one index — the scanner walks left to right, so the
|
|
30
|
+
* leftmost opening delimiter wins regardless of what is listed first.
|
|
31
|
+
*/
|
|
32
|
+
const MARK_TOKENS = [
|
|
33
|
+
{ token: '***', keys: ['bold', 'italic'] },
|
|
34
|
+
{ token: '**', keys: ['bold'] },
|
|
35
|
+
{ token: '__', keys: ['underline'] },
|
|
36
|
+
{ token: '*', keys: ['italic'] },
|
|
37
|
+
{ token: '`', keys: ['code'], literal: true },
|
|
38
|
+
];
|
|
39
|
+
const isWordChar = (ch) => ch !== undefined && /[A-Za-z0-9]/.test(ch);
|
|
40
|
+
/**
|
|
41
|
+
* SPEC §13.2 rule 2 — a marker adjacent to an alphanumeric is not a marker, so
|
|
42
|
+
* `2*3*4` stays literal math.
|
|
43
|
+
*
|
|
44
|
+
* **It does not apply to a backtick.** Rule 2 resolves an ambiguity that only
|
|
45
|
+
* asymmetric prose markers have: `*` is multiplication and a glob, `_` is in
|
|
46
|
+
* identifiers. A backtick is not used as ordinary punctuation, so there is no
|
|
47
|
+
* ambiguity to resolve — and applying the fence anyway leaves `` `main`s ``
|
|
48
|
+
* literal, which is a code span followed by a plural or possessive. Measured
|
|
49
|
+
* against production 2026-09-02: 8 such spans in 6 published messages, and zero
|
|
50
|
+
* cases of the opening side needing the fence. CommonMark agrees.
|
|
51
|
+
*/
|
|
52
|
+
function findMarkClose(text, token, from, fenced) {
|
|
53
|
+
let idx = text.indexOf(token, from);
|
|
54
|
+
while (idx !== -1) {
|
|
55
|
+
if (!fenced || !isWordChar(text[idx + token.length]))
|
|
56
|
+
return idx;
|
|
57
|
+
idx = text.indexOf(token, idx + 1);
|
|
58
|
+
}
|
|
59
|
+
return -1;
|
|
60
|
+
}
|
|
61
|
+
function toMarkSpan(text, active) {
|
|
62
|
+
const span = { text };
|
|
63
|
+
for (const key of active)
|
|
64
|
+
span[key] = true;
|
|
65
|
+
return span;
|
|
66
|
+
}
|
|
67
|
+
function scanMarks(text, active) {
|
|
68
|
+
for (let i = 0; i < text.length; i++) {
|
|
69
|
+
for (const { token, keys, literal } of MARK_TOKENS) {
|
|
70
|
+
if (keys.some((k) => active.includes(k)))
|
|
71
|
+
continue;
|
|
72
|
+
if (!text.startsWith(token, i))
|
|
73
|
+
continue;
|
|
74
|
+
const fenced = !literal;
|
|
75
|
+
if (fenced && isWordChar(text[i - 1]))
|
|
76
|
+
continue;
|
|
77
|
+
const close = findMarkClose(text, token, i + token.length, fenced);
|
|
78
|
+
if (close === -1)
|
|
79
|
+
continue;
|
|
80
|
+
const inner = text.slice(i + token.length, close);
|
|
81
|
+
// SPEC §13.2 rule 1: whitespace at the inner edges means it is not a pair.
|
|
82
|
+
if (!inner || /^\s/.test(inner) || /\s$/.test(inner))
|
|
83
|
+
continue;
|
|
84
|
+
const spans = [];
|
|
85
|
+
const before = text.slice(0, i);
|
|
86
|
+
if (before)
|
|
87
|
+
spans.push(toMarkSpan(before, active));
|
|
88
|
+
if (literal) {
|
|
89
|
+
/*
|
|
90
|
+
SPEC §13.1: code MUST NOT combine with any other mark, and its content
|
|
91
|
+
MUST NOT be parsed for further marks. So the span carries `code` alone
|
|
92
|
+
even inside an enclosing bold — dropping the outer mark rather than
|
|
93
|
+
emitting a combination the spec forbids.
|
|
94
|
+
*/
|
|
95
|
+
spans.push({ text: inner, code: true });
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
spans.push(...scanMarks(inner, [...active, ...keys]));
|
|
99
|
+
}
|
|
100
|
+
spans.push(...scanMarks(text.slice(close + token.length), active));
|
|
101
|
+
return spans;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return text ? [toMarkSpan(text, active)] : [];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Parse one plain-text run into styled spans.
|
|
108
|
+
*
|
|
109
|
+
* Split mentions and app-specific references out first — this function knows
|
|
110
|
+
* about marks and nothing else.
|
|
111
|
+
*/
|
|
112
|
+
export function parseInlineMarks(text) {
|
|
113
|
+
return scanMarks(text, []);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Wrap a run of text in the markers for the marks it carries.
|
|
117
|
+
*
|
|
118
|
+
* Edge whitespace is hoisted outside the markers, because `**word **` would not
|
|
119
|
+
* parse back under rule 1 — so bolding "word " round-trips as `**word** `.
|
|
120
|
+
*
|
|
121
|
+
* `code` wins alone, for the same reason the parser never emits it combined.
|
|
122
|
+
*/
|
|
123
|
+
export function wrapInlineMarks(text, markNames) {
|
|
124
|
+
if (!text)
|
|
125
|
+
return text;
|
|
126
|
+
const bold = markNames.has('bold');
|
|
127
|
+
const italic = markNames.has('italic');
|
|
128
|
+
const underline = markNames.has('underline');
|
|
129
|
+
const code = markNames.has('code');
|
|
130
|
+
if (!bold && !italic && !underline && !code)
|
|
131
|
+
return text;
|
|
132
|
+
const m = text.match(/^(\s*)([\s\S]*?)(\s*)$/);
|
|
133
|
+
const [, lead, core, trail] = m;
|
|
134
|
+
if (!core)
|
|
135
|
+
return text;
|
|
136
|
+
if (code)
|
|
137
|
+
return `${lead}\`${core}\`${trail}`;
|
|
138
|
+
let out = core;
|
|
139
|
+
if (bold && italic)
|
|
140
|
+
out = `***${out}***`;
|
|
141
|
+
else if (bold)
|
|
142
|
+
out = `**${out}**`;
|
|
143
|
+
else if (italic)
|
|
144
|
+
out = `*${out}*`;
|
|
145
|
+
if (underline)
|
|
146
|
+
out = `__${out}__`;
|
|
147
|
+
return lead + out + trail;
|
|
148
|
+
}
|
|
149
|
+
const HEADING_LINE_RE = /^#{1,2}\s/;
|
|
150
|
+
/** `> ` with the space required — a bare `>` typed at a line start ("5 > 3")
|
|
151
|
+
* stays literal, the same conservatism as the inline markers. */
|
|
152
|
+
const QUOTE_LINE_RE = /^>\s/;
|
|
153
|
+
const FENCE_RE = /^```/;
|
|
154
|
+
/**
|
|
155
|
+
* Where the fence opened at `from` closes, or -1 if it never does.
|
|
156
|
+
*
|
|
157
|
+
* An unclosed fence is not a fence: SPEC §13.2 requires an unmatched marker to
|
|
158
|
+
* render literally, and swallowing the rest of the body because somebody typed
|
|
159
|
+
* three backticks is the opposite of that.
|
|
160
|
+
*/
|
|
161
|
+
function fenceCloses(lines, from) {
|
|
162
|
+
if (!FENCE_RE.test(lines[from]))
|
|
163
|
+
return -1;
|
|
164
|
+
for (let j = from + 1; j < lines.length; j++)
|
|
165
|
+
if (FENCE_RE.test(lines[j]))
|
|
166
|
+
return j;
|
|
167
|
+
return -1;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Split a body into block segments.
|
|
171
|
+
*
|
|
172
|
+
* Blank lines split runs of plain text into separate `text` segments. `# ` and
|
|
173
|
+
* `## ` become headings; three or more `#`s, and a `#123` reference with no
|
|
174
|
+
* space, stay plain text.
|
|
175
|
+
*/
|
|
176
|
+
export function parseBodySegments(body) {
|
|
177
|
+
const lines = body.split('\n');
|
|
178
|
+
const segments = [];
|
|
179
|
+
let i = 0;
|
|
180
|
+
while (i < lines.length) {
|
|
181
|
+
const line = lines[i];
|
|
182
|
+
const fenceEnd = fenceCloses(lines, i);
|
|
183
|
+
if (fenceEnd !== -1) {
|
|
184
|
+
const language = line.slice(3).trim();
|
|
185
|
+
segments.push({
|
|
186
|
+
type: 'code',
|
|
187
|
+
...(language ? { language } : {}),
|
|
188
|
+
lines: lines.slice(i + 1, fenceEnd),
|
|
189
|
+
});
|
|
190
|
+
i = fenceEnd + 1;
|
|
191
|
+
}
|
|
192
|
+
else if (HEADING_LINE_RE.test(line) && !line.startsWith('###')) {
|
|
193
|
+
segments.push({
|
|
194
|
+
type: 'heading',
|
|
195
|
+
level: line.startsWith('##') ? 2 : 1,
|
|
196
|
+
text: line.replace(HEADING_LINE_RE, ''),
|
|
197
|
+
});
|
|
198
|
+
i++;
|
|
199
|
+
}
|
|
200
|
+
else if (/^[-•]\s/.test(line)) {
|
|
201
|
+
const items = [];
|
|
202
|
+
while (i < lines.length && /^[-•]\s/.test(lines[i])) {
|
|
203
|
+
items.push(lines[i].replace(/^[-•]\s/, ''));
|
|
204
|
+
i++;
|
|
205
|
+
}
|
|
206
|
+
segments.push({ type: 'bullet', items });
|
|
207
|
+
}
|
|
208
|
+
else if (/^\d+\.\s/.test(line)) {
|
|
209
|
+
const items = [];
|
|
210
|
+
while (i < lines.length && /^\d+\.\s/.test(lines[i])) {
|
|
211
|
+
items.push(lines[i].replace(/^\d+\.\s/, ''));
|
|
212
|
+
i++;
|
|
213
|
+
}
|
|
214
|
+
segments.push({ type: 'numbered', items });
|
|
215
|
+
}
|
|
216
|
+
else if (QUOTE_LINE_RE.test(line)) {
|
|
217
|
+
const quoteLines = [];
|
|
218
|
+
while (i < lines.length && QUOTE_LINE_RE.test(lines[i])) {
|
|
219
|
+
quoteLines.push(lines[i].replace(QUOTE_LINE_RE, ''));
|
|
220
|
+
i++;
|
|
221
|
+
}
|
|
222
|
+
segments.push({ type: 'quote', lines: quoteLines });
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
const textLines = [];
|
|
226
|
+
while (i < lines.length &&
|
|
227
|
+
fenceCloses(lines, i) === -1 &&
|
|
228
|
+
!/^[-•]\s/.test(lines[i]) &&
|
|
229
|
+
!/^\d+\.\s/.test(lines[i]) &&
|
|
230
|
+
!QUOTE_LINE_RE.test(lines[i]) &&
|
|
231
|
+
!(HEADING_LINE_RE.test(lines[i]) && !lines[i].startsWith('###'))) {
|
|
232
|
+
textLines.push(lines[i]);
|
|
233
|
+
i++;
|
|
234
|
+
}
|
|
235
|
+
let chunk = [];
|
|
236
|
+
for (const l of textLines) {
|
|
237
|
+
if (l === '') {
|
|
238
|
+
if (chunk.length > 0) {
|
|
239
|
+
segments.push({ type: 'text', lines: chunk });
|
|
240
|
+
chunk = [];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
chunk.push(l);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (chunk.length > 0)
|
|
248
|
+
segments.push({ type: 'text', lines: chunk });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return segments;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Markers, heading prefixes and fences removed — for one-line previews that
|
|
255
|
+
* render body text raw, outside any renderer.
|
|
256
|
+
*
|
|
257
|
+
* **Prefixes stack, and the order they are removed in is not cosmetic.** The
|
|
258
|
+
* version this was extracted from removed the heading prefix first and the
|
|
259
|
+
* quote prefix second, so `> # Heading` — a quoted heading, which the corpus is
|
|
260
|
+
* full of because every project brief quotes one — came back as `# Heading` and
|
|
261
|
+
* a preview showed a stray `#`. Stripping until the line stops changing removes
|
|
262
|
+
* whatever order they were written in. Found by running this over 152 real
|
|
263
|
+
* published bodies, not by reading the code.
|
|
264
|
+
*/
|
|
265
|
+
function stripLinePrefixes(line) {
|
|
266
|
+
let out = line;
|
|
267
|
+
for (;;) {
|
|
268
|
+
const next = out.replace(/^>\s/, '').replace(/^#{1,2}\s/, '');
|
|
269
|
+
if (next === out)
|
|
270
|
+
return out;
|
|
271
|
+
out = next;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
export function stripInlineFormatting(text) {
|
|
275
|
+
return text
|
|
276
|
+
.split('\n')
|
|
277
|
+
.filter((line) => !FENCE_RE.test(line))
|
|
278
|
+
.map((line) => parseInlineMarks(stripLinePrefixes(line)).map((s) => s.text).join(''))
|
|
279
|
+
.join('\n');
|
|
280
|
+
}
|
|
281
|
+
/** Deterministic order, so the same marks always serialise to the same JSON.
|
|
282
|
+
* Two encoders disagreeing about array order would produce documents that
|
|
283
|
+
* differ byte-for-byte while meaning the same thing, and every equality check
|
|
284
|
+
* downstream — a diff, a dedupe, a cache key — would be wrong about it. */
|
|
285
|
+
const MARK_ORDER = ['bold', 'italic', 'underline', 'code'];
|
|
286
|
+
/** Marker text → inline JSON nodes. */
|
|
287
|
+
export function markersToInlineNodes(text) {
|
|
288
|
+
return parseInlineMarks(text).map((span) => {
|
|
289
|
+
const marks = MARK_ORDER.filter((m) => span[m]).map((type) => ({ type }));
|
|
290
|
+
return marks.length ? { type: 'text', text: span.text, marks } : { type: 'text', text: span.text };
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Inline JSON nodes → marker text.
|
|
295
|
+
*
|
|
296
|
+
* The inverse of {@link markersToInlineNodes} for every mark the dialect can
|
|
297
|
+
* spell, which is all four of them. Whitespace at a run's edges is hoisted
|
|
298
|
+
* outside the markers by `wrapInlineMarks`, because §13.2 rule 1 would not
|
|
299
|
+
* parse it back otherwise — so this round-trips the *marks on each character*
|
|
300
|
+
* rather than the span boundaries. See the corpus tests.
|
|
301
|
+
*/
|
|
302
|
+
export function inlineNodesToMarkers(nodes) {
|
|
303
|
+
return nodes
|
|
304
|
+
.map((node) => wrapInlineMarks(node.text, new Set((node.marks ?? []).map((m) => m.type))))
|
|
305
|
+
.join('');
|
|
306
|
+
}
|
|
307
|
+
/** The plain text of a run of inline nodes, marks discarded. */
|
|
308
|
+
export function inlineNodesToText(nodes) {
|
|
309
|
+
return nodes.map((n) => n.text).join('');
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAiCH;;;;;GAKG;AACH,MAAM,WAAW,GAAgB;IAC/B,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE;IAC1C,EAAE,KAA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,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAA;IACtH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAgC;IACnE,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACzF,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,iBAAiB,CAAC,KAAgC;IAChE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAC1C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
47
47
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
48
48
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
49
|
-
export declare const PROTOCOL_VERSION = "0.
|
|
49
|
+
export declare const PROTOCOL_VERSION = "0.7.0";
|
|
50
50
|
export { type NostrTag, type UnsignedEvent, type SignedEvent, type Profile, type ThreadRef, type ChannelVisibility, type ChannelKind, type MemberRole, type Label, type ResolutionAction, KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE, computeEventId, toNostrSeconds, canonicalChannelName, threadTags, addr, relayAuthUrl, buildProfile, parseProfile, buildCreateChannel, buildDeleteChannel, buildEditChannelMetadata, buildAddMember, buildReaction, buildDeletion, buildMessage, buildResolution, buildFile, buildComponent, buildHighlight, buildUnsignedRelayAuthEvent, } from './events.js';
|
|
51
51
|
export { type AddressPointer, type EventPointer, encodeNevent, decodeNevent, convertBits, bech32Encode, bech32Decode, encodeNaddr, decodeNaddr, pointerToAddress, addressToPointer, addrToNaddr, naddrToAddr, referenceToPointer, NADDR_RE, findNaddrs, stripNaddrs, } from './nip19.js';
|
|
52
52
|
export { type AuthEventArgs, TIMESTAMP_TOLERANCE_SECS, normalizeUrl, buildUnsignedAuthEvent, base64, authorizationHeaderFor, authorizationHeader, } from './nip98.js';
|
|
@@ -54,4 +54,6 @@ export { type Signer, type SignerKind, publicKeyFromSecret, signEvent, secretKey
|
|
|
54
54
|
export { type PublishResult, type QueryResult, type RelayHeaders, type RelayOptions, type FetchLike, type QueryAllOptions, parsePublishResponse, parseQueryResponse, RELAY_PAGE_CEILING, DEFAULT_QUERY_CONCURRENCY, Relay, } from './bridge.js';
|
|
55
55
|
export { type RelayState, type SocketLike, type RelayCredential, type LiveRelayOptions, type Subscription, type LiveRelay, toWebSocketUrl, parseFrame, createLiveRelay, } from './live.js';
|
|
56
56
|
export { type ChannelEventHandler, type ChannelSubscription, type ChannelSubscriptions, createChannelSubscriptions, } from './subscriptions.js';
|
|
57
|
+
export { type InlineMark, type InlineMarkSpan, type BodySegment, type InlineMarkNode, type InlineTextNode, parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, markersToInlineNodes, inlineNodesToMarkers, inlineNodesToText, } from './content.js';
|
|
58
|
+
export { type Block, type BlockDocument, type KnownBlockType, KNOWN_BLOCK_TYPES, BlockDocumentError, validateBlockDocument, parseBlockDocument, serializeBlockDocument, newBlockId, assignMissingBlockIds, blockIds, findBlock, inlineTextOf, documentText, } from './blocks.js';
|
|
57
59
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d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KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,KAAK,GACN,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,cAAc,EACd,UAAU,EACV,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,0BAA0B,GAC3B,MAAM,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,eAAO,MAAM,gBAAgB,UAAU,CAAA;AAEvC,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,gBAAgB,EAErB,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAEjB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY,EAEZ,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,GAC5B,MAAM,aAAa,CA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O,EACL,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
47
47
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
48
48
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
49
|
-
export const PROTOCOL_VERSION = '0.
|
|
49
|
+
export const PROTOCOL_VERSION = '0.7.0';
|
|
50
50
|
export {
|
|
51
51
|
// constants
|
|
52
52
|
KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE,
|
|
@@ -60,4 +60,6 @@ export { publicKeyFromSecret, signEvent, secretKeySigner, } from './sign.js';
|
|
|
60
60
|
export { parsePublishResponse, parseQueryResponse, RELAY_PAGE_CEILING, DEFAULT_QUERY_CONCURRENCY, Relay, } from './bridge.js';
|
|
61
61
|
export { toWebSocketUrl, parseFrame, createLiveRelay, } from './live.js';
|
|
62
62
|
export { createChannelSubscriptions, } from './subscriptions.js';
|
|
63
|
+
export { parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, markersToInlineNodes, inlineNodesToMarkers, inlineNodesToText, } from './content.js';
|
|
64
|
+
export { KNOWN_BLOCK_TYPES, BlockDocumentError, validateBlockDocument, parseBlockDocument, serializeBlockDocument, newBlockId, assignMissingBlockIds, blockIds, findBlock, inlineTextOf, documentText, } from './blocks.js';
|
|
63
65
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{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GAC3B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAML,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EAIL,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The Estiva wire format: Buzz-shaped Nostr event builders, NIP-01 ids, NIP-19 naddr, NIP-98 HTTP auth, and the relay clients. Speaks the protocol; interprets nothing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/blocks.ts
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rich text field — SPEC §13.3.
|
|
3
|
+
*
|
|
4
|
+
* A message is marker text (`content.ts`); a rich text field is this: a tree of
|
|
5
|
+
* blocks, each with an id, serialised as JSON. **The id is the entire reason
|
|
6
|
+
* this model is JSON rather than text.** A comment anchors to `<object address>
|
|
7
|
+
* + <block id>`, which is what RFC 0.4 §6 was waiting for, and an implementation
|
|
8
|
+
* that mints ids at render time has built a tree that is not addressable — the
|
|
9
|
+
* anchor has nothing to bind to and nobody finds out until it silently drifts.
|
|
10
|
+
*
|
|
11
|
+
* ## What is deliberately not here
|
|
12
|
+
*
|
|
13
|
+
* **The `content-format` tag.** SPEC §13.4's read rule already lives in
|
|
14
|
+
* `@estiva-app/interop` as `contentFormatOf`, alongside `CONTENT_FORMAT_TAG`
|
|
15
|
+
* and `BLOCK_DOCUMENT_FORMAT`, because it is a question about an *event and its
|
|
16
|
+
* slot* rather than about a document. Defining the same wire string here would
|
|
17
|
+
* be a second copy of exactly the kind this package exists to prevent, so this
|
|
18
|
+
* module never names it: a document does not know its own tag, and the reader
|
|
19
|
+
* that does is one layer up.
|
|
20
|
+
*
|
|
21
|
+
* **Rendering.** §13.5's safe renderer is RIC-6's, where Ship is the consumer
|
|
22
|
+
* that needs it. What this module owes a renderer is {@link inlineTextOf}, so
|
|
23
|
+
* an unknown block type can be drawn as its own text rather than dropped.
|
|
24
|
+
*/
|
|
25
|
+
import { bytesToHex, randomBytes } from '@noble/hashes/utils'
|
|
26
|
+
import { type InlineTextNode, inlineNodesToText } from './content.js'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The block types §13.3 names.
|
|
30
|
+
*
|
|
31
|
+
* **Open, not closed.** An unknown type is not an error at any point in this
|
|
32
|
+
* module — §13.3 requires a reader to render its inline text and forbids
|
|
33
|
+
* dropping it silently, which is the same fallback discipline §7.5 applies to
|
|
34
|
+
* widgets and for the same reason: consumers upgrade at different times, and a
|
|
35
|
+
* block that vanishes is indistinguishable from one you may not read.
|
|
36
|
+
*/
|
|
37
|
+
export const KNOWN_BLOCK_TYPES = [
|
|
38
|
+
'paragraph',
|
|
39
|
+
'heading',
|
|
40
|
+
'bulletList',
|
|
41
|
+
'orderedList',
|
|
42
|
+
'listItem',
|
|
43
|
+
'blockquote',
|
|
44
|
+
'codeBlock',
|
|
45
|
+
'table',
|
|
46
|
+
'horizontalRule',
|
|
47
|
+
'attachment',
|
|
48
|
+
'widget',
|
|
49
|
+
] as const
|
|
50
|
+
|
|
51
|
+
export type KnownBlockType = (typeof KNOWN_BLOCK_TYPES)[number]
|
|
52
|
+
|
|
53
|
+
export interface Block {
|
|
54
|
+
/** A {@link KnownBlockType}, or anything a later version publishes. */
|
|
55
|
+
type: string
|
|
56
|
+
/** Unique within the document, and stable across edits that do not replace it. */
|
|
57
|
+
id: string
|
|
58
|
+
attrs?: Record<string, unknown>
|
|
59
|
+
/** Inline runs, or child blocks. A leaf like `horizontalRule` has neither. */
|
|
60
|
+
content?: InlineTextNode[] | Block[]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface BlockDocument {
|
|
64
|
+
type: 'doc'
|
|
65
|
+
content: Block[]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Thrown by {@link parseBlockDocument}; `problems` is {@link validateBlockDocument}'s list. */
|
|
69
|
+
export class BlockDocumentError extends Error {
|
|
70
|
+
readonly problems: string[]
|
|
71
|
+
constructor(problems: string[]) {
|
|
72
|
+
super(`not a block document: ${problems.join('; ')}`)
|
|
73
|
+
this.name = 'BlockDocumentError'
|
|
74
|
+
this.problems = problems
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const isObject = (v: unknown): v is Record<string, unknown> =>
|
|
79
|
+
typeof v === 'object' && v !== null && !Array.isArray(v)
|
|
80
|
+
|
|
81
|
+
const isInlineRun = (content: unknown): content is InlineTextNode[] =>
|
|
82
|
+
Array.isArray(content) && content.every((n) => isObject(n) && n.type === 'text')
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Every way a value fails to be a block document, rather than the first.
|
|
86
|
+
*
|
|
87
|
+
* A validator that stops at the first problem makes fixing a document a
|
|
88
|
+
* sequence of round trips, and this one is read by authors of *other* apps.
|
|
89
|
+
*/
|
|
90
|
+
export function validateBlockDocument(value: unknown): string[] {
|
|
91
|
+
const problems: string[] = []
|
|
92
|
+
if (!isObject(value)) return ['root is not an object']
|
|
93
|
+
if (value.type !== 'doc') problems.push(`root type is ${JSON.stringify(value.type)}, expected "doc"`)
|
|
94
|
+
if (!Array.isArray(value.content)) {
|
|
95
|
+
problems.push('root has no content array')
|
|
96
|
+
return problems
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const seen = new Set<string>()
|
|
100
|
+
const walk = (blocks: unknown[], path: string) => {
|
|
101
|
+
blocks.forEach((block, i) => {
|
|
102
|
+
const at = `${path}[${i}]`
|
|
103
|
+
if (!isObject(block)) {
|
|
104
|
+
problems.push(`${at} is not an object`)
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
if (typeof block.type !== 'string' || block.type === '') {
|
|
108
|
+
problems.push(`${at} has no type`)
|
|
109
|
+
}
|
|
110
|
+
// §13.3: every block, not only the ones an app happens to know.
|
|
111
|
+
if (typeof block.id !== 'string' || block.id === '') {
|
|
112
|
+
problems.push(`${at} has no id`)
|
|
113
|
+
} else if (seen.has(block.id)) {
|
|
114
|
+
problems.push(`${at} repeats the id ${JSON.stringify(block.id)}`)
|
|
115
|
+
} else {
|
|
116
|
+
seen.add(block.id)
|
|
117
|
+
}
|
|
118
|
+
if (block.type === 'heading') {
|
|
119
|
+
const level = isObject(block.attrs) ? block.attrs.level : undefined
|
|
120
|
+
if (typeof level !== 'number' || !Number.isInteger(level) || level < 1 || level > 3) {
|
|
121
|
+
problems.push(`${at} is a heading with level ${JSON.stringify(level)}, expected 1–3`)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (block.content === undefined) return
|
|
125
|
+
if (!Array.isArray(block.content)) {
|
|
126
|
+
problems.push(`${at} has a content that is not an array`)
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
if (isInlineRun(block.content)) {
|
|
130
|
+
block.content.forEach((node, j) => {
|
|
131
|
+
const nodeAt = `${at}.content[${j}]`
|
|
132
|
+
if (typeof (node as { text?: unknown }).text !== 'string') {
|
|
133
|
+
problems.push(`${nodeAt} has no text`)
|
|
134
|
+
}
|
|
135
|
+
const marks = (node as { marks?: unknown }).marks
|
|
136
|
+
if (marks === undefined) return
|
|
137
|
+
if (!Array.isArray(marks)) {
|
|
138
|
+
problems.push(`${nodeAt} has marks that are not an array`)
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
for (const mark of marks) {
|
|
142
|
+
if (!isObject(mark) || typeof mark.type !== 'string') {
|
|
143
|
+
problems.push(`${nodeAt} has a mark with no type`)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
walk(block.content, `${at}.content`)
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
walk(value.content, 'content')
|
|
153
|
+
return problems
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A block document from JSON text, or from an already-parsed value.
|
|
158
|
+
*
|
|
159
|
+
* **Throws rather than returning a partial document.** A caller that cannot
|
|
160
|
+
* tell "this is not a block document" from "this is an empty one" would render
|
|
161
|
+
* a blank field for a body that is really there — and §13.4 is explicit that a
|
|
162
|
+
* body's model is decided by its event's tag, so arriving here with something
|
|
163
|
+
* that is not a document means the tag was wrong, which is worth an error and
|
|
164
|
+
* not a shrug.
|
|
165
|
+
*/
|
|
166
|
+
export function parseBlockDocument(input: string | unknown): BlockDocument {
|
|
167
|
+
let value: unknown = input
|
|
168
|
+
if (typeof input === 'string') {
|
|
169
|
+
try {
|
|
170
|
+
value = JSON.parse(input)
|
|
171
|
+
} catch (e) {
|
|
172
|
+
throw new BlockDocumentError([`content is not JSON: ${(e as Error).message}`])
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const problems = validateBlockDocument(value)
|
|
176
|
+
if (problems.length) throw new BlockDocumentError(problems)
|
|
177
|
+
return value as BlockDocument
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** JSON text for the wire. §12.3's 256 KiB ingest cap applies to this string. */
|
|
181
|
+
export function serializeBlockDocument(doc: BlockDocument): string {
|
|
182
|
+
return JSON.stringify(doc)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* A fresh block id.
|
|
187
|
+
*
|
|
188
|
+
* Short on purpose: ids repeat in every anchor and every serialisation, the
|
|
189
|
+
* document has a 256 KiB ceiling, and uniqueness is only required *within one
|
|
190
|
+
* document* (§13.3) rather than globally. 12 hex characters is far more than
|
|
191
|
+
* that needs, and {@link assignMissingBlockIds} checks for a collision anyway
|
|
192
|
+
* rather than trusting the arithmetic.
|
|
193
|
+
*/
|
|
194
|
+
export function newBlockId(): string {
|
|
195
|
+
// `@noble/hashes`' randomBytes, the same source `nip98.ts` draws its nonce
|
|
196
|
+
// from — one CSPRNG seam for the package rather than a direct `globalThis`
|
|
197
|
+
// reach that types differently under DOM and node libs.
|
|
198
|
+
return bytesToHex(randomBytes(6))
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Ids for blocks that have none, **leaving every existing id alone**.
|
|
203
|
+
*
|
|
204
|
+
* This is the id-stability rule (§13.3) as a function. An editor rebuilds a
|
|
205
|
+
* document on every keystroke; if that rebuild re-mints ids, every anchored
|
|
206
|
+
* comment detaches on the next edit and the anchoring feature is silently
|
|
207
|
+
* worthless. Assigning only what is missing makes the safe path the easy one.
|
|
208
|
+
*
|
|
209
|
+
* Returns a new document; the input is not mutated.
|
|
210
|
+
*/
|
|
211
|
+
export function assignMissingBlockIds(doc: BlockDocument): BlockDocument {
|
|
212
|
+
const taken = new Set(blockIds(doc))
|
|
213
|
+
const fresh = () => {
|
|
214
|
+
let id = newBlockId()
|
|
215
|
+
while (taken.has(id)) id = newBlockId()
|
|
216
|
+
taken.add(id)
|
|
217
|
+
return id
|
|
218
|
+
}
|
|
219
|
+
const walk = (blocks: Block[]): Block[] =>
|
|
220
|
+
blocks.map((block) => {
|
|
221
|
+
const id = typeof block.id === 'string' && block.id !== '' ? block.id : fresh()
|
|
222
|
+
const content =
|
|
223
|
+
Array.isArray(block.content) && !isInlineRun(block.content)
|
|
224
|
+
? walk(block.content as Block[])
|
|
225
|
+
: block.content
|
|
226
|
+
return { ...block, id, ...(content === undefined ? {} : { content }) } as Block
|
|
227
|
+
})
|
|
228
|
+
return { ...doc, content: walk(doc.content) }
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Every block id in document order, nested blocks included. */
|
|
232
|
+
export function blockIds(doc: BlockDocument): string[] {
|
|
233
|
+
const out: string[] = []
|
|
234
|
+
const walk = (blocks: Block[]) => {
|
|
235
|
+
for (const block of blocks) {
|
|
236
|
+
if (typeof block.id === 'string' && block.id !== '') out.push(block.id)
|
|
237
|
+
if (Array.isArray(block.content) && !isInlineRun(block.content)) walk(block.content as Block[])
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
walk(doc.content)
|
|
241
|
+
return out
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** The block an anchor points at, or `undefined` if it is gone. */
|
|
245
|
+
export function findBlock(doc: BlockDocument, id: string): Block | undefined {
|
|
246
|
+
const walk = (blocks: Block[]): Block | undefined => {
|
|
247
|
+
for (const block of blocks) {
|
|
248
|
+
if (block.id === id) return block
|
|
249
|
+
if (Array.isArray(block.content) && !isInlineRun(block.content)) {
|
|
250
|
+
const hit = walk(block.content as Block[])
|
|
251
|
+
if (hit) return hit
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return undefined
|
|
255
|
+
}
|
|
256
|
+
return walk(doc.content)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* A block's text, including its children's.
|
|
261
|
+
*
|
|
262
|
+
* This is what §13.3 requires a reader to draw for a block type it does not
|
|
263
|
+
* know — *"render that block's inline text rather than dropping it"*. It works
|
|
264
|
+
* on an unknown type for the same reason it works on a known one: it reads the
|
|
265
|
+
* shape, never the name.
|
|
266
|
+
*/
|
|
267
|
+
export function inlineTextOf(block: Block): string {
|
|
268
|
+
if (!Array.isArray(block.content)) return ''
|
|
269
|
+
if (isInlineRun(block.content)) return inlineNodesToText(block.content)
|
|
270
|
+
return (block.content as Block[]).map(inlineTextOf).join('\n')
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** The whole document as plain text — previews, search, and the last-resort render. */
|
|
274
|
+
export function documentText(doc: BlockDocument): string {
|
|
275
|
+
return doc.content.map(inlineTextOf).filter((t) => t !== '').join('\n')
|
|
276
|
+
}
|