@estiva-app/protocol 0.6.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 +45 -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 +24 -0
- package/dist/content.d.ts.map +1 -1
- package/dist/content.js +30 -0
- package/dist/content.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/blocks.ts +276 -0
- package/src/content.ts +56 -0
- package/src/index.ts +23 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,51 @@ Every entry answers the wire question explicitly, including when the answer is
|
|
|
4
4
|
nothing (ADR 0002 §4b). A change to the bytes an app publishes is a MAJOR — in
|
|
5
5
|
`0.x`, a MINOR — even when no TypeScript signature moved.
|
|
6
6
|
|
|
7
|
+
## 0.7.0 — 2026-09-02
|
|
8
|
+
|
|
9
|
+
**Wire behaviour: unchanged.** No builder, tag layout, id computation or
|
|
10
|
+
signature input moved. This release adds a second content model — the one SPEC
|
|
11
|
+
§13.3 specifies for a rich text field — and nothing yet publishes one.
|
|
12
|
+
|
|
13
|
+
- **New: `blocks.ts` — the rich text field, SPEC §13.3.** `parseBlockDocument`,
|
|
14
|
+
`serializeBlockDocument`, `validateBlockDocument`, `newBlockId`,
|
|
15
|
+
`assignMissingBlockIds`, `blockIds`, `findBlock`, `inlineTextOf`,
|
|
16
|
+
`documentText`.
|
|
17
|
+
|
|
18
|
+
**`assignMissingBlockIds` mints only what is missing**, and that is the whole
|
|
19
|
+
point rather than an optimisation. An editor rebuilds its document on every
|
|
20
|
+
keystroke; a rebuild that re-mints ids detaches every anchored comment on the
|
|
21
|
+
next edit, and nothing reports it. A block id is what RFC 0.4 §6 anchoring
|
|
22
|
+
binds to, so the function makes the safe path the easy one. There is a test
|
|
23
|
+
that fails if it is changed to mint unconditionally.
|
|
24
|
+
|
|
25
|
+
- **New: the inline vocabulary's second serialisation** (§13.1) —
|
|
26
|
+
`markersToInlineNodes`, `inlineNodesToMarkers`, `inlineNodesToText`. Held back
|
|
27
|
+
from 0.6.0 on purpose: it had no consumer until the block model existed.
|
|
28
|
+
|
|
29
|
+
Mark order in the JSON encoding is **deterministic**, because two encoders
|
|
30
|
+
disagreeing about array order produce documents that differ byte-for-byte
|
|
31
|
+
while meaning the same thing, and every equality check downstream — a diff, a
|
|
32
|
+
dedupe, a cache key — is then wrong about it.
|
|
33
|
+
|
|
34
|
+
- **An unknown block type is not an error anywhere in this module.** §13.3
|
|
35
|
+
requires a reader to draw its inline text and forbids dropping it silently,
|
|
36
|
+
the same discipline §7.5 applies to widgets and for the same reason:
|
|
37
|
+
consumers upgrade at different times. `validateBlockDocument` passes it,
|
|
38
|
+
round-tripping preserves it whole, and `inlineTextOf` reads its text by shape
|
|
39
|
+
rather than by name.
|
|
40
|
+
|
|
41
|
+
- **The `content-format` tag is deliberately NOT defined here.** §13.4's read
|
|
42
|
+
rule is `contentFormatOf` in `@estiva-app/interop`, added in #26, because it
|
|
43
|
+
is a question about an event and its slot rather than about a document.
|
|
44
|
+
A second copy of `'estiva-blocks-1'` in this package is precisely the
|
|
45
|
+
divergence this package exists to prevent, so `blocks.ts` never names it.
|
|
46
|
+
|
|
47
|
+
- **Tests: the claim §13 makes, checked rather than asserted.** The 152 real
|
|
48
|
+
published bodies from 0.6.0 now go through both encodings, and no character
|
|
49
|
+
changes its marks. Two controls were run against it — dropping `code` from
|
|
50
|
+
the JSON encoding fails 4 tests, re-minting ids unconditionally fails 2.
|
|
51
|
+
|
|
7
52
|
## 0.6.0 — 2026-09-02
|
|
8
53
|
|
|
9
54
|
**Wire behaviour: unchanged.** No builder, tag layout, id computation or
|
package/dist/blocks.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type InlineTextNode } from './content.js';
|
|
2
|
+
/**
|
|
3
|
+
* The block types §13.3 names.
|
|
4
|
+
*
|
|
5
|
+
* **Open, not closed.** An unknown type is not an error at any point in this
|
|
6
|
+
* module — §13.3 requires a reader to render its inline text and forbids
|
|
7
|
+
* dropping it silently, which is the same fallback discipline §7.5 applies to
|
|
8
|
+
* widgets and for the same reason: consumers upgrade at different times, and a
|
|
9
|
+
* block that vanishes is indistinguishable from one you may not read.
|
|
10
|
+
*/
|
|
11
|
+
export declare const KNOWN_BLOCK_TYPES: readonly ["paragraph", "heading", "bulletList", "orderedList", "listItem", "blockquote", "codeBlock", "table", "horizontalRule", "attachment", "widget"];
|
|
12
|
+
export type KnownBlockType = (typeof KNOWN_BLOCK_TYPES)[number];
|
|
13
|
+
export interface Block {
|
|
14
|
+
/** A {@link KnownBlockType}, or anything a later version publishes. */
|
|
15
|
+
type: string;
|
|
16
|
+
/** Unique within the document, and stable across edits that do not replace it. */
|
|
17
|
+
id: string;
|
|
18
|
+
attrs?: Record<string, unknown>;
|
|
19
|
+
/** Inline runs, or child blocks. A leaf like `horizontalRule` has neither. */
|
|
20
|
+
content?: InlineTextNode[] | Block[];
|
|
21
|
+
}
|
|
22
|
+
export interface BlockDocument {
|
|
23
|
+
type: 'doc';
|
|
24
|
+
content: Block[];
|
|
25
|
+
}
|
|
26
|
+
/** Thrown by {@link parseBlockDocument}; `problems` is {@link validateBlockDocument}'s list. */
|
|
27
|
+
export declare class BlockDocumentError extends Error {
|
|
28
|
+
readonly problems: string[];
|
|
29
|
+
constructor(problems: string[]);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Every way a value fails to be a block document, rather than the first.
|
|
33
|
+
*
|
|
34
|
+
* A validator that stops at the first problem makes fixing a document a
|
|
35
|
+
* sequence of round trips, and this one is read by authors of *other* apps.
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateBlockDocument(value: unknown): string[];
|
|
38
|
+
/**
|
|
39
|
+
* A block document from JSON text, or from an already-parsed value.
|
|
40
|
+
*
|
|
41
|
+
* **Throws rather than returning a partial document.** A caller that cannot
|
|
42
|
+
* tell "this is not a block document" from "this is an empty one" would render
|
|
43
|
+
* a blank field for a body that is really there — and §13.4 is explicit that a
|
|
44
|
+
* body's model is decided by its event's tag, so arriving here with something
|
|
45
|
+
* that is not a document means the tag was wrong, which is worth an error and
|
|
46
|
+
* not a shrug.
|
|
47
|
+
*/
|
|
48
|
+
export declare function parseBlockDocument(input: string | unknown): BlockDocument;
|
|
49
|
+
/** JSON text for the wire. §12.3's 256 KiB ingest cap applies to this string. */
|
|
50
|
+
export declare function serializeBlockDocument(doc: BlockDocument): string;
|
|
51
|
+
/**
|
|
52
|
+
* A fresh block id.
|
|
53
|
+
*
|
|
54
|
+
* Short on purpose: ids repeat in every anchor and every serialisation, the
|
|
55
|
+
* document has a 256 KiB ceiling, and uniqueness is only required *within one
|
|
56
|
+
* document* (§13.3) rather than globally. 12 hex characters is far more than
|
|
57
|
+
* that needs, and {@link assignMissingBlockIds} checks for a collision anyway
|
|
58
|
+
* rather than trusting the arithmetic.
|
|
59
|
+
*/
|
|
60
|
+
export declare function newBlockId(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Ids for blocks that have none, **leaving every existing id alone**.
|
|
63
|
+
*
|
|
64
|
+
* This is the id-stability rule (§13.3) as a function. An editor rebuilds a
|
|
65
|
+
* document on every keystroke; if that rebuild re-mints ids, every anchored
|
|
66
|
+
* comment detaches on the next edit and the anchoring feature is silently
|
|
67
|
+
* worthless. Assigning only what is missing makes the safe path the easy one.
|
|
68
|
+
*
|
|
69
|
+
* Returns a new document; the input is not mutated.
|
|
70
|
+
*/
|
|
71
|
+
export declare function assignMissingBlockIds(doc: BlockDocument): BlockDocument;
|
|
72
|
+
/** Every block id in document order, nested blocks included. */
|
|
73
|
+
export declare function blockIds(doc: BlockDocument): string[];
|
|
74
|
+
/** The block an anchor points at, or `undefined` if it is gone. */
|
|
75
|
+
export declare function findBlock(doc: BlockDocument, id: string): Block | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* A block's text, including its children's.
|
|
78
|
+
*
|
|
79
|
+
* This is what §13.3 requires a reader to draw for a block type it does not
|
|
80
|
+
* know — *"render that block's inline text rather than dropping it"*. It works
|
|
81
|
+
* on an unknown type for the same reason it works on a known one: it reads the
|
|
82
|
+
* shape, never the name.
|
|
83
|
+
*/
|
|
84
|
+
export declare function inlineTextOf(block: Block): string;
|
|
85
|
+
/** The whole document as plain text — previews, search, and the last-resort render. */
|
|
86
|
+
export declare function documentText(doc: BlockDocument): string;
|
|
87
|
+
//# sourceMappingURL=blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,cAAc,CAAA;AAErE;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,0JAYpB,CAAA;AAEV,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/D,MAAM,WAAW,KAAK;IACpB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;IACZ,kFAAkF;IAClF,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,8EAA8E;IAC9E,OAAO,CAAC,EAAE,cAAc,EAAE,GAAG,KAAK,EAAE,CAAA;CACrC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,KAAK,CAAA;IACX,OAAO,EAAE,KAAK,EAAE,CAAA;CACjB;AAED,gGAAgG;AAChG,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;gBACf,QAAQ,EAAE,MAAM,EAAE;CAK/B;AAQD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAgE9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,aAAa,CAYzE;AAED,iFAAiF;AACjF,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAEjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAKnC;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,aAAa,GAAG,aAAa,CAkBvE;AAED,gEAAgE;AAChE,wBAAgB,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,EAAE,CAUrD;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAY3E;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAIjD;AAED,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAEvD"}
|
package/dist/blocks.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
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 { inlineNodesToText } from './content.js';
|
|
27
|
+
/**
|
|
28
|
+
* The block types §13.3 names.
|
|
29
|
+
*
|
|
30
|
+
* **Open, not closed.** An unknown type is not an error at any point in this
|
|
31
|
+
* module — §13.3 requires a reader to render its inline text and forbids
|
|
32
|
+
* dropping it silently, which is the same fallback discipline §7.5 applies to
|
|
33
|
+
* widgets and for the same reason: consumers upgrade at different times, and a
|
|
34
|
+
* block that vanishes is indistinguishable from one you may not read.
|
|
35
|
+
*/
|
|
36
|
+
export const KNOWN_BLOCK_TYPES = [
|
|
37
|
+
'paragraph',
|
|
38
|
+
'heading',
|
|
39
|
+
'bulletList',
|
|
40
|
+
'orderedList',
|
|
41
|
+
'listItem',
|
|
42
|
+
'blockquote',
|
|
43
|
+
'codeBlock',
|
|
44
|
+
'table',
|
|
45
|
+
'horizontalRule',
|
|
46
|
+
'attachment',
|
|
47
|
+
'widget',
|
|
48
|
+
];
|
|
49
|
+
/** Thrown by {@link parseBlockDocument}; `problems` is {@link validateBlockDocument}'s list. */
|
|
50
|
+
export class BlockDocumentError extends Error {
|
|
51
|
+
problems;
|
|
52
|
+
constructor(problems) {
|
|
53
|
+
super(`not a block document: ${problems.join('; ')}`);
|
|
54
|
+
this.name = 'BlockDocumentError';
|
|
55
|
+
this.problems = problems;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
59
|
+
const isInlineRun = (content) => Array.isArray(content) && content.every((n) => isObject(n) && n.type === 'text');
|
|
60
|
+
/**
|
|
61
|
+
* Every way a value fails to be a block document, rather than the first.
|
|
62
|
+
*
|
|
63
|
+
* A validator that stops at the first problem makes fixing a document a
|
|
64
|
+
* sequence of round trips, and this one is read by authors of *other* apps.
|
|
65
|
+
*/
|
|
66
|
+
export function validateBlockDocument(value) {
|
|
67
|
+
const problems = [];
|
|
68
|
+
if (!isObject(value))
|
|
69
|
+
return ['root is not an object'];
|
|
70
|
+
if (value.type !== 'doc')
|
|
71
|
+
problems.push(`root type is ${JSON.stringify(value.type)}, expected "doc"`);
|
|
72
|
+
if (!Array.isArray(value.content)) {
|
|
73
|
+
problems.push('root has no content array');
|
|
74
|
+
return problems;
|
|
75
|
+
}
|
|
76
|
+
const seen = new Set();
|
|
77
|
+
const walk = (blocks, path) => {
|
|
78
|
+
blocks.forEach((block, i) => {
|
|
79
|
+
const at = `${path}[${i}]`;
|
|
80
|
+
if (!isObject(block)) {
|
|
81
|
+
problems.push(`${at} is not an object`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (typeof block.type !== 'string' || block.type === '') {
|
|
85
|
+
problems.push(`${at} has no type`);
|
|
86
|
+
}
|
|
87
|
+
// §13.3: every block, not only the ones an app happens to know.
|
|
88
|
+
if (typeof block.id !== 'string' || block.id === '') {
|
|
89
|
+
problems.push(`${at} has no id`);
|
|
90
|
+
}
|
|
91
|
+
else if (seen.has(block.id)) {
|
|
92
|
+
problems.push(`${at} repeats the id ${JSON.stringify(block.id)}`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
seen.add(block.id);
|
|
96
|
+
}
|
|
97
|
+
if (block.type === 'heading') {
|
|
98
|
+
const level = isObject(block.attrs) ? block.attrs.level : undefined;
|
|
99
|
+
if (typeof level !== 'number' || !Number.isInteger(level) || level < 1 || level > 3) {
|
|
100
|
+
problems.push(`${at} is a heading with level ${JSON.stringify(level)}, expected 1–3`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (block.content === undefined)
|
|
104
|
+
return;
|
|
105
|
+
if (!Array.isArray(block.content)) {
|
|
106
|
+
problems.push(`${at} has a content that is not an array`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (isInlineRun(block.content)) {
|
|
110
|
+
block.content.forEach((node, j) => {
|
|
111
|
+
const nodeAt = `${at}.content[${j}]`;
|
|
112
|
+
if (typeof node.text !== 'string') {
|
|
113
|
+
problems.push(`${nodeAt} has no text`);
|
|
114
|
+
}
|
|
115
|
+
const marks = node.marks;
|
|
116
|
+
if (marks === undefined)
|
|
117
|
+
return;
|
|
118
|
+
if (!Array.isArray(marks)) {
|
|
119
|
+
problems.push(`${nodeAt} has marks that are not an array`);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
for (const mark of marks) {
|
|
123
|
+
if (!isObject(mark) || typeof mark.type !== 'string') {
|
|
124
|
+
problems.push(`${nodeAt} has a mark with no type`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
walk(block.content, `${at}.content`);
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
walk(value.content, 'content');
|
|
134
|
+
return problems;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A block document from JSON text, or from an already-parsed value.
|
|
138
|
+
*
|
|
139
|
+
* **Throws rather than returning a partial document.** A caller that cannot
|
|
140
|
+
* tell "this is not a block document" from "this is an empty one" would render
|
|
141
|
+
* a blank field for a body that is really there — and §13.4 is explicit that a
|
|
142
|
+
* body's model is decided by its event's tag, so arriving here with something
|
|
143
|
+
* that is not a document means the tag was wrong, which is worth an error and
|
|
144
|
+
* not a shrug.
|
|
145
|
+
*/
|
|
146
|
+
export function parseBlockDocument(input) {
|
|
147
|
+
let value = input;
|
|
148
|
+
if (typeof input === 'string') {
|
|
149
|
+
try {
|
|
150
|
+
value = JSON.parse(input);
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
throw new BlockDocumentError([`content is not JSON: ${e.message}`]);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const problems = validateBlockDocument(value);
|
|
157
|
+
if (problems.length)
|
|
158
|
+
throw new BlockDocumentError(problems);
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
/** JSON text for the wire. §12.3's 256 KiB ingest cap applies to this string. */
|
|
162
|
+
export function serializeBlockDocument(doc) {
|
|
163
|
+
return JSON.stringify(doc);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A fresh block id.
|
|
167
|
+
*
|
|
168
|
+
* Short on purpose: ids repeat in every anchor and every serialisation, the
|
|
169
|
+
* document has a 256 KiB ceiling, and uniqueness is only required *within one
|
|
170
|
+
* document* (§13.3) rather than globally. 12 hex characters is far more than
|
|
171
|
+
* that needs, and {@link assignMissingBlockIds} checks for a collision anyway
|
|
172
|
+
* rather than trusting the arithmetic.
|
|
173
|
+
*/
|
|
174
|
+
export function newBlockId() {
|
|
175
|
+
// `@noble/hashes`' randomBytes, the same source `nip98.ts` draws its nonce
|
|
176
|
+
// from — one CSPRNG seam for the package rather than a direct `globalThis`
|
|
177
|
+
// reach that types differently under DOM and node libs.
|
|
178
|
+
return bytesToHex(randomBytes(6));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Ids for blocks that have none, **leaving every existing id alone**.
|
|
182
|
+
*
|
|
183
|
+
* This is the id-stability rule (§13.3) as a function. An editor rebuilds a
|
|
184
|
+
* document on every keystroke; if that rebuild re-mints ids, every anchored
|
|
185
|
+
* comment detaches on the next edit and the anchoring feature is silently
|
|
186
|
+
* worthless. Assigning only what is missing makes the safe path the easy one.
|
|
187
|
+
*
|
|
188
|
+
* Returns a new document; the input is not mutated.
|
|
189
|
+
*/
|
|
190
|
+
export function assignMissingBlockIds(doc) {
|
|
191
|
+
const taken = new Set(blockIds(doc));
|
|
192
|
+
const fresh = () => {
|
|
193
|
+
let id = newBlockId();
|
|
194
|
+
while (taken.has(id))
|
|
195
|
+
id = newBlockId();
|
|
196
|
+
taken.add(id);
|
|
197
|
+
return id;
|
|
198
|
+
};
|
|
199
|
+
const walk = (blocks) => blocks.map((block) => {
|
|
200
|
+
const id = typeof block.id === 'string' && block.id !== '' ? block.id : fresh();
|
|
201
|
+
const content = Array.isArray(block.content) && !isInlineRun(block.content)
|
|
202
|
+
? walk(block.content)
|
|
203
|
+
: block.content;
|
|
204
|
+
return { ...block, id, ...(content === undefined ? {} : { content }) };
|
|
205
|
+
});
|
|
206
|
+
return { ...doc, content: walk(doc.content) };
|
|
207
|
+
}
|
|
208
|
+
/** Every block id in document order, nested blocks included. */
|
|
209
|
+
export function blockIds(doc) {
|
|
210
|
+
const out = [];
|
|
211
|
+
const walk = (blocks) => {
|
|
212
|
+
for (const block of blocks) {
|
|
213
|
+
if (typeof block.id === 'string' && block.id !== '')
|
|
214
|
+
out.push(block.id);
|
|
215
|
+
if (Array.isArray(block.content) && !isInlineRun(block.content))
|
|
216
|
+
walk(block.content);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
walk(doc.content);
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
/** The block an anchor points at, or `undefined` if it is gone. */
|
|
223
|
+
export function findBlock(doc, id) {
|
|
224
|
+
const walk = (blocks) => {
|
|
225
|
+
for (const block of blocks) {
|
|
226
|
+
if (block.id === id)
|
|
227
|
+
return block;
|
|
228
|
+
if (Array.isArray(block.content) && !isInlineRun(block.content)) {
|
|
229
|
+
const hit = walk(block.content);
|
|
230
|
+
if (hit)
|
|
231
|
+
return hit;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
};
|
|
236
|
+
return walk(doc.content);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* A block's text, including its children's.
|
|
240
|
+
*
|
|
241
|
+
* This is what §13.3 requires a reader to draw for a block type it does not
|
|
242
|
+
* know — *"render that block's inline text rather than dropping it"*. It works
|
|
243
|
+
* on an unknown type for the same reason it works on a known one: it reads the
|
|
244
|
+
* shape, never the name.
|
|
245
|
+
*/
|
|
246
|
+
export function inlineTextOf(block) {
|
|
247
|
+
if (!Array.isArray(block.content))
|
|
248
|
+
return '';
|
|
249
|
+
if (isInlineRun(block.content))
|
|
250
|
+
return inlineNodesToText(block.content);
|
|
251
|
+
return block.content.map(inlineTextOf).join('\n');
|
|
252
|
+
}
|
|
253
|
+
/** The whole document as plain text — previews, search, and the last-resort render. */
|
|
254
|
+
export function documentText(doc) {
|
|
255
|
+
return doc.content.map(inlineTextOf).filter((t) => t !== '').join('\n');
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.js","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,EAAuB,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAErE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,WAAW;IACX,SAAS;IACT,YAAY;IACZ,aAAa;IACb,UAAU;IACV,YAAY;IACZ,WAAW;IACX,OAAO;IACP,gBAAgB;IAChB,YAAY;IACZ,QAAQ;CACA,CAAA;AAmBV,gGAAgG;AAChG,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,QAAQ,CAAU;IAC3B,YAAY,QAAkB;QAC5B,KAAK,CAAC,yBAAyB,QAAQ,CAAC,IAAI,CAAC,IAAI,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;AAED,uFAAuF;AACvF,MAAM,UAAU,YAAY,CAAC,GAAkB;IAC7C,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzE,CAAC"}
|
package/dist/content.d.ts
CHANGED
|
@@ -80,4 +80,28 @@ export declare function wrapInlineMarks(text: string, markNames: ReadonlySet<str
|
|
|
80
80
|
*/
|
|
81
81
|
export declare function parseBodySegments(body: string): BodySegment[];
|
|
82
82
|
export declare function stripInlineFormatting(text: string): string;
|
|
83
|
+
/** A mark on an inline run, in the JSON encoding. */
|
|
84
|
+
export type InlineMarkNode = {
|
|
85
|
+
type: InlineMark;
|
|
86
|
+
};
|
|
87
|
+
/** One run of text and its marks — §13.3's `{"type":"text","text":…,"marks":[…]}`. */
|
|
88
|
+
export interface InlineTextNode {
|
|
89
|
+
type: 'text';
|
|
90
|
+
text: string;
|
|
91
|
+
marks?: InlineMarkNode[];
|
|
92
|
+
}
|
|
93
|
+
/** Marker text → inline JSON nodes. */
|
|
94
|
+
export declare function markersToInlineNodes(text: string): InlineTextNode[];
|
|
95
|
+
/**
|
|
96
|
+
* Inline JSON nodes → marker text.
|
|
97
|
+
*
|
|
98
|
+
* The inverse of {@link markersToInlineNodes} for every mark the dialect can
|
|
99
|
+
* spell, which is all four of them. Whitespace at a run's edges is hoisted
|
|
100
|
+
* outside the markers by `wrapInlineMarks`, because §13.2 rule 1 would not
|
|
101
|
+
* parse it back otherwise — so this round-trips the *marks on each character*
|
|
102
|
+
* rather than the span boundaries. See the corpus tests.
|
|
103
|
+
*/
|
|
104
|
+
export declare function inlineNodesToMarkers(nodes: readonly InlineTextNode[]): string;
|
|
105
|
+
/** The plain text of a run of inline nodes, marks discarded. */
|
|
106
|
+
export declare function inlineNodesToText(nodes: readonly InlineTextNode[]): string;
|
|
83
107
|
//# sourceMappingURL=content.d.ts.map
|
package/dist/content.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,yFAAyF;AACzF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAA;AAEjE,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,oDAAoD;AACpD,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AAwFxD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAE/D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,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CAAA;AAwFxD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAE/D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,CAiBpF;AAqBD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAoE7D;AAuBD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1D;AAcD,qDAAqD;AACrD,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAA;AAEjD,sFAAsF;AACtF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;CACzB;AAQD,uCAAuC;AACvC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAKnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAI7E;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAE1E"}
|
package/dist/content.js
CHANGED
|
@@ -278,4 +278,34 @@ export function stripInlineFormatting(text) {
|
|
|
278
278
|
.map((line) => parseInlineMarks(stripLinePrefixes(line)).map((s) => s.text).join(''))
|
|
279
279
|
.join('\n');
|
|
280
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
|
+
}
|
|
281
311
|
//# sourceMappingURL=content.js.map
|
package/dist/content.js.map
CHANGED
|
@@ -1 +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,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,CA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AAC,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,5 +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, parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, } from './content.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';
|
|
58
59
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,iBAAi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R,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,5 +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, } from './content.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';
|
|
64
65
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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BAAqB,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
|
+
}
|
package/src/content.ts
CHANGED
|
@@ -292,3 +292,59 @@ export function stripInlineFormatting(text: string): string {
|
|
|
292
292
|
.map((line) => parseInlineMarks(stripLinePrefixes(line)).map((s) => s.text).join(''))
|
|
293
293
|
.join('\n')
|
|
294
294
|
}
|
|
295
|
+
|
|
296
|
+
// ── The inline vocabulary's second serialisation — SPEC §13.1 ──
|
|
297
|
+
//
|
|
298
|
+
// The same marks, encoded as JSON nodes instead of markers, because a block
|
|
299
|
+
// document's inline content is an array of these (§13.3). RIC-4 shipped the
|
|
300
|
+
// marker side and deliberately stopped there: this half had no consumer until
|
|
301
|
+
// the block model existed, and designing an encoding against no caller is how
|
|
302
|
+
// you get one nobody can use.
|
|
303
|
+
//
|
|
304
|
+
// **The vocabulary is shared; the encoding is not.** That is the whole shape of
|
|
305
|
+
// SPEC §13 — a message and a paragraph mean the same thing by "bold", and agree
|
|
306
|
+
// about nothing else.
|
|
307
|
+
|
|
308
|
+
/** A mark on an inline run, in the JSON encoding. */
|
|
309
|
+
export type InlineMarkNode = { type: InlineMark }
|
|
310
|
+
|
|
311
|
+
/** One run of text and its marks — §13.3's `{"type":"text","text":…,"marks":[…]}`. */
|
|
312
|
+
export interface InlineTextNode {
|
|
313
|
+
type: 'text'
|
|
314
|
+
text: string
|
|
315
|
+
marks?: InlineMarkNode[]
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Deterministic order, so the same marks always serialise to the same JSON.
|
|
319
|
+
* Two encoders disagreeing about array order would produce documents that
|
|
320
|
+
* differ byte-for-byte while meaning the same thing, and every equality check
|
|
321
|
+
* downstream — a diff, a dedupe, a cache key — would be wrong about it. */
|
|
322
|
+
const MARK_ORDER: InlineMark[] = ['bold', 'italic', 'underline', 'code']
|
|
323
|
+
|
|
324
|
+
/** Marker text → inline JSON nodes. */
|
|
325
|
+
export function markersToInlineNodes(text: string): InlineTextNode[] {
|
|
326
|
+
return parseInlineMarks(text).map((span) => {
|
|
327
|
+
const marks = MARK_ORDER.filter((m) => span[m]).map((type) => ({ type }))
|
|
328
|
+
return marks.length ? { type: 'text' as const, text: span.text, marks } : { type: 'text' as const, text: span.text }
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Inline JSON nodes → marker text.
|
|
334
|
+
*
|
|
335
|
+
* The inverse of {@link markersToInlineNodes} for every mark the dialect can
|
|
336
|
+
* spell, which is all four of them. Whitespace at a run's edges is hoisted
|
|
337
|
+
* outside the markers by `wrapInlineMarks`, because §13.2 rule 1 would not
|
|
338
|
+
* parse it back otherwise — so this round-trips the *marks on each character*
|
|
339
|
+
* rather than the span boundaries. See the corpus tests.
|
|
340
|
+
*/
|
|
341
|
+
export function inlineNodesToMarkers(nodes: readonly InlineTextNode[]): string {
|
|
342
|
+
return nodes
|
|
343
|
+
.map((node) => wrapInlineMarks(node.text, new Set((node.marks ?? []).map((m) => m.type))))
|
|
344
|
+
.join('')
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** The plain text of a run of inline nodes, marks discarded. */
|
|
348
|
+
export function inlineNodesToText(nodes: readonly InlineTextNode[]): string {
|
|
349
|
+
return nodes.map((n) => n.text).join('')
|
|
350
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
48
48
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
49
49
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
50
|
-
export const PROTOCOL_VERSION = '0.
|
|
50
|
+
export const PROTOCOL_VERSION = '0.7.0'
|
|
51
51
|
|
|
52
52
|
export {
|
|
53
53
|
// types
|
|
@@ -168,8 +168,30 @@ export {
|
|
|
168
168
|
type InlineMark,
|
|
169
169
|
type InlineMarkSpan,
|
|
170
170
|
type BodySegment,
|
|
171
|
+
type InlineMarkNode,
|
|
172
|
+
type InlineTextNode,
|
|
171
173
|
parseInlineMarks,
|
|
172
174
|
wrapInlineMarks,
|
|
173
175
|
parseBodySegments,
|
|
174
176
|
stripInlineFormatting,
|
|
177
|
+
markersToInlineNodes,
|
|
178
|
+
inlineNodesToMarkers,
|
|
179
|
+
inlineNodesToText,
|
|
175
180
|
} from './content.js'
|
|
181
|
+
|
|
182
|
+
export {
|
|
183
|
+
type Block,
|
|
184
|
+
type BlockDocument,
|
|
185
|
+
type KnownBlockType,
|
|
186
|
+
KNOWN_BLOCK_TYPES,
|
|
187
|
+
BlockDocumentError,
|
|
188
|
+
validateBlockDocument,
|
|
189
|
+
parseBlockDocument,
|
|
190
|
+
serializeBlockDocument,
|
|
191
|
+
newBlockId,
|
|
192
|
+
assignMissingBlockIds,
|
|
193
|
+
blockIds,
|
|
194
|
+
findBlock,
|
|
195
|
+
inlineTextOf,
|
|
196
|
+
documentText,
|
|
197
|
+
} from './blocks.js'
|