@estiva-app/protocol 0.7.0 → 0.9.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
@@ -4,6 +4,74 @@ 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.9.0 — 2026-09-02
8
+
9
+ **Wire behaviour: unchanged.** Nothing about the bytes moved. One function and
10
+ two constants moved *between packages*, and `@estiva-app/interop` re-exports
11
+ them, so **no consumer of either package has to change anything.**
12
+
13
+ - **`contentFormatOf`, `CONTENT_FORMAT_TAG` and `BLOCK_DOCUMENT_FORMAT` move
14
+ here from `@estiva-app/interop`.** They were defined there because the
15
+ projection layer needed them first, and reading a tag off an event looked
16
+ like a question about a slot.
17
+
18
+ It is not — it is a question about an event, which is this package's subject.
19
+ **Two folds outside the projection layer now need it**: Ship's and the
20
+ agent's, which are one fold in two repositories held to a single recorded
21
+ state by a conformance fixture. Making either depend on the projection layer
22
+ to read a tag is the wrong direction, and a second copy of
23
+ `'estiva-blocks-1'` is what this package exists to prevent.
24
+
25
+ - **`ContentFormat` is the name; `RenderFormat` is now an alias for it.** 0.8.0
26
+ shipped `RenderFormat` and `interop` shipped `ContentFormat`, and they were
27
+ the same three-value union declared twice — a duplicate introduced by 0.8.0
28
+ and removed by this release. The old name still exports, so 0.8.0's consumers
29
+ keep compiling.
30
+
31
+ - `interop` is unchanged in behaviour and re-exports all three names, with its
32
+ 147 tests passing untouched. `BODY_SLOT` stays in `interop`: a *slot* is that
33
+ layer's subject, and this package has no opinion about which one carries a
34
+ body.
35
+
36
+ ## 0.8.0 — 2026-09-02
37
+
38
+ **Wire behaviour: unchanged.** No builder, tag layout, id computation or
39
+ signature input moved. This release adds a resolver, and a resolver reads what
40
+ somebody else published.
41
+
42
+ - **New: `render.ts` — one resolved tree, whichever model the body is in.**
43
+ `toRenderTree(value, format)` and `renderTreeText`. Marker text and a block
44
+ document both become the same `RenderBlock[]`, so a consumer writes one
45
+ mapper instead of two, and a block document's ids survive into it while
46
+ marker text correctly has none.
47
+
48
+ **This is what SPEC §13.5's "safe by construction" means in practice.** The
49
+ safety is not a component — it is that an app is never handed a string it has
50
+ to interpret. Marks are decided, blocks are decided, and there is nothing
51
+ left to parse, so an app that maps this tree *cannot* accidentally render
52
+ markup. There is a corpus test asserting every character of output came from
53
+ the input; making the resolver append four characters fails 4 tests.
54
+
55
+ - **A tree rather than a shared component, and not for the reason the ticket
56
+ said.** RIC-6 justified it as "Ship is vanilla `h()` and Peek is React". That
57
+ was true when the ticket was written and is no longer: Ship's UI is React +
58
+ Vite and both apps already depend on `@estiva-app/ui`, so a shared component
59
+ was available. It is still a tree, for a better reason — **how rich text
60
+ looks is the consumer's**, which is RFC 0.4 §13.1's rule for projections and
61
+ SPEC §10's line about sharing the wire and never the interpretation. A shared
62
+ component would make Ship and Peek look alike by construction, which nobody
63
+ asked for.
64
+
65
+ - **`'unknown'` is handled here rather than in each consumer.** A format
66
+ declared after this code was written becomes one unmarked paragraph of the
67
+ raw value, which §13.5 says is conformant. Leaving that to consumers is how
68
+ one of them ends up guessing.
69
+
70
+ - **A mis-tagged body degrades instead of throwing.** A `'blocks'` value that
71
+ is not a document renders as its own text. A reader that throws renders an
72
+ empty field, and an empty field is indistinguishable from a description
73
+ nobody wrote.
74
+
7
75
  ## 0.7.0 — 2026-09-02
8
76
 
9
77
  **Wire behaviour: unchanged.** No builder, tag layout, id computation or
@@ -1 +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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AED,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 CHANGED
@@ -10,13 +10,10 @@
10
10
  *
11
11
  * ## What is deliberately not here
12
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.
13
+ * **The `content-format` tag.** A document does not know its own tag — the tag
14
+ * is on the event that carries it, and SPEC §13.4's read rule is
15
+ * `contentFormatOf` in `render.ts`. (It lived in `@estiva-app/interop` until
16
+ * two folds outside the projection layer needed it; see that function's note.)
20
17
  *
21
18
  * **Rendering.** §13.5's safe renderer is RIC-6's, where Ship is the consumer
22
19
  * that needs it. What this module owes a renderer is {@link inlineTextOf}, so
@@ -1 +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,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AC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzE,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.7.0";
49
+ export declare const PROTOCOL_VERSION = "0.9.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';
@@ -56,4 +56,5 @@ export { type RelayState, type SocketLike, type RelayCredential, type LiveRelayO
56
56
  export { type ChannelEventHandler, type ChannelSubscription, type ChannelSubscriptions, createChannelSubscriptions, } from './subscriptions.js';
57
57
  export { type InlineMark, type InlineMarkSpan, type BodySegment, type InlineMarkNode, type InlineTextNode, parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, markersToInlineNodes, inlineNodesToMarkers, inlineNodesToText, } from './content.js';
58
58
  export { type Block, type BlockDocument, type KnownBlockType, KNOWN_BLOCK_TYPES, BlockDocumentError, validateBlockDocument, parseBlockDocument, serializeBlockDocument, newBlockId, assignMissingBlockIds, blockIds, findBlock, inlineTextOf, documentText, } from './blocks.js';
59
+ export { type RenderInline, type RenderBlock, type RenderFormat, type ContentFormat, CONTENT_FORMAT_TAG, BLOCK_DOCUMENT_FORMAT, contentFormatOf, toRenderTree, renderTreeText, } from './render.js';
59
60
  //# sourceMappingURL=index.d.ts.map
@@ -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,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,CAAA;AAEpB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ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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.7.0';
49
+ export const PROTOCOL_VERSION = '0.9.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,
@@ -62,4 +62,5 @@ export { toWebSocketUrl, parseFrame, createLiveRelay, } from './live.js';
62
62
  export { createChannelSubscriptions, } from './subscriptions.js';
63
63
  export { parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, markersToInlineNodes, inlineNodesToMarkers, inlineNodesToText, } from './content.js';
64
64
  export { KNOWN_BLOCK_TYPES, BlockDocumentError, validateBlockDocument, parseBlockDocument, serializeBlockDocument, newBlockId, assignMissingBlockIds, blockIds, findBlock, inlineTextOf, documentText, } from './blocks.js';
65
+ export { CONTENT_FORMAT_TAG, BLOCK_DOCUMENT_FORMAT, contentFormatOf, toRenderTree, renderTreeText, } from './render.js';
65
66
  //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAEvC,OAAO;AAYL,YAAY;AACZ,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB;AACjB,8CAA8C;AAC9C,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,E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,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;AAEpB,OAAO,EAKL,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,GACf,MAAM,aAAa,CAAA"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * One tree, whichever content model the body is in — SPEC §13.5.
3
+ *
4
+ * §13.5 asks for a renderer *"safe by construction"*, and the safety is not in
5
+ * a component: it is in never handing an app a string it has to interpret.
6
+ * What this module produces is a fully resolved tree — marks decided, blocks
7
+ * decided, nothing left to parse and nothing to interpolate — so the app's only
8
+ * remaining job is to create elements and set text. An app that maps this tree
9
+ * cannot accidentally render markup, because there is no markup in it.
10
+ *
11
+ * ## Why a tree rather than a shared component
12
+ *
13
+ * Not because the apps use different frameworks — Ship and Peek are both React
14
+ * and already share `@estiva-app/ui`, so a component was possible. Because
15
+ * **how rich text looks is the consumer's**, which is the same rule RFC 0.4
16
+ * §13.1 states for projections — *the owner defines the projection, the
17
+ * consumer decides how it looks* — and SPEC §10's line about apps sharing the
18
+ * wire and never the interpretation. A shared component would make Ship and
19
+ * Peek look alike by construction, which is not a property anybody asked for.
20
+ *
21
+ * So: one parse, one resolution, two designs.
22
+ *
23
+ * ## The three formats, including the one nobody has written yet
24
+ *
25
+ * `toRenderTree` takes the format from `contentFormatOf` in
26
+ * `@estiva-app/interop` — the tag, never the body (§13.4). `'unknown'` is the
27
+ * interesting one: a format declared after this code was written becomes a
28
+ * single unmarked paragraph of the raw value, which §13.5 says is conformant.
29
+ * Handling it here rather than in each consumer is what stops one app deciding
30
+ * to guess.
31
+ */
32
+ import { type InlineMark } from './content.js';
33
+ import type { SignedEvent } from './events.js';
34
+ /** A run of text and the marks on it. Nothing here needs escaping; it is text. */
35
+ export interface RenderInline {
36
+ text: string;
37
+ marks: InlineMark[];
38
+ }
39
+ /**
40
+ * A resolved block.
41
+ *
42
+ * **A `\n` inside `inline` text is a line break**, in both content models — it
43
+ * is how a marker-text paragraph carries its lines, and it keeps a consumer
44
+ * from needing two rules. Splitting on it is the consumer's whole obligation.
45
+ */
46
+ export interface RenderBlock {
47
+ type: 'paragraph' | 'heading' | 'bulletList' | 'orderedList' | 'listItem' | 'blockquote' | 'codeBlock' | 'table' | 'horizontalRule' | 'attachment' | 'widget' | 'unknown';
48
+ /** The block's address, from a block document. Marker text has no addressable
49
+ * sub-unit (§13.1), so it is absent — which is the difference that matters. */
50
+ id?: string;
51
+ level?: 1 | 2 | 3;
52
+ language?: string;
53
+ attrs?: Record<string, unknown>;
54
+ /** What the document actually called it, when `type` is `'unknown'`. */
55
+ typeName?: string;
56
+ inline?: RenderInline[];
57
+ children?: RenderBlock[];
58
+ }
59
+ /**
60
+ * What content model a body is written in — SPEC §13.4.
61
+ *
62
+ * Three values, not two, and not the raw tag string. A consumer makes a
63
+ * three-way decision and **must not guess the third**:
64
+ *
65
+ * - `marker` — the §13.2 dialect. The default, permanently. 731 published
66
+ * bodies carry no tag and none of them can be given one, so this is not a
67
+ * migration window that closes.
68
+ * - `blocks` — a §13.3 JSON block document.
69
+ * - `unknown` — a format declared after this runtime was written. Render the
70
+ * body as plain text; §13.5 says declining to format is conformant, and
71
+ * parsing it as either known model is what §13 forbids outright.
72
+ *
73
+ * Resolved in one place rather than per consumer for the reason `CLOSED_WIDGETS`
74
+ * is: two copies of `tag === undefined ? marker : tag === 'estiva-blocks-1' ?
75
+ * blocks : text` disagree the first time a third format exists, and the
76
+ * disagreement shows up as one app rendering JSON at a person.
77
+ */
78
+ export type ContentFormat = 'marker' | 'blocks' | 'unknown';
79
+ /**
80
+ * @deprecated The name this shipped under in 0.8.0. It is `ContentFormat`.
81
+ * Kept as an alias so 0.8.0's consumers keep compiling.
82
+ */
83
+ export type RenderFormat = ContentFormat;
84
+ /** The tag SPEC §13.4 defines. Absence is a declaration, not an omission. */
85
+ export declare const CONTENT_FORMAT_TAG = "content-format";
86
+ /** The one format §13.3 names today. */
87
+ export declare const BLOCK_DOCUMENT_FORMAT = "estiva-blocks-1";
88
+ /**
89
+ * The content model an event's body is in.
90
+ *
91
+ * **Decided by the tag alone.** §13.4 is explicit that a reader MUST NOT decide
92
+ * by inspecting the body: a legacy description that happens to begin with `{`
93
+ * is marker text, because it carries no tag.
94
+ *
95
+ * **Why this lives here and not in `@estiva-app/interop`, where it was born.**
96
+ * It arrived with the projection layer because that is what needed it first,
97
+ * and reading a tag off an event looked like a question about a slot. It is
98
+ * not — it is a question about an event, which is this package's subject. Two
99
+ * folds now need it and neither is a projection consumer: Ship's and the
100
+ * agent's, which are the same fold in two repositories held to one recorded
101
+ * state. Making either of them depend on the projection layer to read a tag
102
+ * would be the wrong direction, and a second copy of the rule is what this
103
+ * package exists to prevent. `interop` re-exports these, so nothing it
104
+ * published has moved.
105
+ */
106
+ export declare function contentFormatOf(event: SignedEvent): ContentFormat;
107
+ /**
108
+ * The body, resolved.
109
+ *
110
+ * `format` comes from the event's `content-format` tag — `contentFormatOf` in
111
+ * `@estiva-app/interop`. Do not infer it from `value`: §13.4 forbids it, and a
112
+ * legacy description that happens to begin with `{` is the case that proves
113
+ * why.
114
+ *
115
+ * A body in an unparseable state never throws here. A `'blocks'` value that is
116
+ * not a document degrades to one unmarked paragraph — the same outcome as
117
+ * `'unknown'` — because a reader that throws renders nothing at all, and a
118
+ * description that is present is better shown as its own text than as an empty
119
+ * field.
120
+ */
121
+ export declare function toRenderTree(value: string, format: RenderFormat): RenderBlock[];
122
+ /** Every character a reader would see, for previews and search. */
123
+ export declare function renderTreeText(blocks: readonly RenderBlock[]): string;
124
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version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,GAAG,aAAa,CAIjE;AAyFD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,WAAW,EAAE,CAY/E;AAMD,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CASrE"}
package/dist/render.js ADDED
@@ -0,0 +1,190 @@
1
+ /**
2
+ * One tree, whichever content model the body is in — SPEC §13.5.
3
+ *
4
+ * §13.5 asks for a renderer *"safe by construction"*, and the safety is not in
5
+ * a component: it is in never handing an app a string it has to interpret.
6
+ * What this module produces is a fully resolved tree — marks decided, blocks
7
+ * decided, nothing left to parse and nothing to interpolate — so the app's only
8
+ * remaining job is to create elements and set text. An app that maps this tree
9
+ * cannot accidentally render markup, because there is no markup in it.
10
+ *
11
+ * ## Why a tree rather than a shared component
12
+ *
13
+ * Not because the apps use different frameworks — Ship and Peek are both React
14
+ * and already share `@estiva-app/ui`, so a component was possible. Because
15
+ * **how rich text looks is the consumer's**, which is the same rule RFC 0.4
16
+ * §13.1 states for projections — *the owner defines the projection, the
17
+ * consumer decides how it looks* — and SPEC §10's line about apps sharing the
18
+ * wire and never the interpretation. A shared component would make Ship and
19
+ * Peek look alike by construction, which is not a property anybody asked for.
20
+ *
21
+ * So: one parse, one resolution, two designs.
22
+ *
23
+ * ## The three formats, including the one nobody has written yet
24
+ *
25
+ * `toRenderTree` takes the format from `contentFormatOf` in
26
+ * `@estiva-app/interop` — the tag, never the body (§13.4). `'unknown'` is the
27
+ * interesting one: a format declared after this code was written becomes a
28
+ * single unmarked paragraph of the raw value, which §13.5 says is conformant.
29
+ * Handling it here rather than in each consumer is what stops one app deciding
30
+ * to guess.
31
+ */
32
+ import { parseBodySegments, parseInlineMarks, } from './content.js';
33
+ import { parseBlockDocument, inlineTextOf } from './blocks.js';
34
+ /** The tag SPEC §13.4 defines. Absence is a declaration, not an omission. */
35
+ export const CONTENT_FORMAT_TAG = 'content-format';
36
+ /** The one format §13.3 names today. */
37
+ export const BLOCK_DOCUMENT_FORMAT = 'estiva-blocks-1';
38
+ /**
39
+ * The content model an event's body is in.
40
+ *
41
+ * **Decided by the tag alone.** §13.4 is explicit that a reader MUST NOT decide
42
+ * by inspecting the body: a legacy description that happens to begin with `{`
43
+ * is marker text, because it carries no tag.
44
+ *
45
+ * **Why this lives here and not in `@estiva-app/interop`, where it was born.**
46
+ * It arrived with the projection layer because that is what needed it first,
47
+ * and reading a tag off an event looked like a question about a slot. It is
48
+ * not — it is a question about an event, which is this package's subject. Two
49
+ * folds now need it and neither is a projection consumer: Ship's and the
50
+ * agent's, which are the same fold in two repositories held to one recorded
51
+ * state. Making either of them depend on the projection layer to read a tag
52
+ * would be the wrong direction, and a second copy of the rule is what this
53
+ * package exists to prevent. `interop` re-exports these, so nothing it
54
+ * published has moved.
55
+ */
56
+ export function contentFormatOf(event) {
57
+ const declared = event.tags.find((t) => t[0] === CONTENT_FORMAT_TAG)?.[1];
58
+ if (declared === undefined || declared === '')
59
+ return 'marker';
60
+ return declared === BLOCK_DOCUMENT_FORMAT ? 'blocks' : 'unknown';
61
+ }
62
+ const KNOWN = new Set([
63
+ 'paragraph', 'heading', 'bulletList', 'orderedList', 'listItem',
64
+ 'blockquote', 'codeBlock', 'table', 'horizontalRule', 'attachment', 'widget',
65
+ ]);
66
+ const marksOf = (span) => {
67
+ const out = [];
68
+ if (span.bold)
69
+ out.push('bold');
70
+ if (span.italic)
71
+ out.push('italic');
72
+ if (span.underline)
73
+ out.push('underline');
74
+ if (span.code)
75
+ out.push('code');
76
+ return out;
77
+ };
78
+ const inlineFromMarkers = (text) => parseInlineMarks(text).map((s) => ({ text: s.text, marks: marksOf(s) }));
79
+ /** One inline run per line, joined by the `\n` the interface documents. */
80
+ const inlineFromLines = (lines) => inlineFromMarkers(lines.join('\n'));
81
+ function blockFromSegment(seg) {
82
+ switch (seg.type) {
83
+ case 'heading':
84
+ return { type: 'heading', level: seg.level, inline: inlineFromMarkers(seg.text) };
85
+ case 'bullet':
86
+ return {
87
+ type: 'bulletList',
88
+ children: seg.items.map((item) => ({ type: 'listItem', inline: inlineFromMarkers(item) })),
89
+ };
90
+ case 'numbered':
91
+ return {
92
+ type: 'orderedList',
93
+ children: seg.items.map((item) => ({ type: 'listItem', inline: inlineFromMarkers(item) })),
94
+ };
95
+ case 'quote':
96
+ return { type: 'blockquote', inline: inlineFromLines(seg.lines) };
97
+ case 'code':
98
+ // A fence is literal by definition — its content is never mark-parsed.
99
+ return {
100
+ type: 'codeBlock',
101
+ ...(seg.language ? { language: seg.language } : {}),
102
+ inline: [{ text: seg.lines.join('\n'), marks: [] }],
103
+ };
104
+ case 'text':
105
+ return { type: 'paragraph', inline: inlineFromLines(seg.lines) };
106
+ }
107
+ }
108
+ const isInlineRun = (content) => Array.isArray(content) && content.every((n) => typeof n === 'object' && n !== null && n.type === 'text');
109
+ function blockFromDocument(block) {
110
+ const known = KNOWN.has(block.type);
111
+ const out = {
112
+ type: (known ? block.type : 'unknown'),
113
+ id: block.id,
114
+ ...(known ? {} : { typeName: block.type }),
115
+ ...(block.attrs ? { attrs: block.attrs } : {}),
116
+ };
117
+ const level = block.attrs?.level;
118
+ if (block.type === 'heading' && (level === 1 || level === 2 || level === 3))
119
+ out.level = level;
120
+ const language = block.attrs?.language;
121
+ if (block.type === 'codeBlock' && typeof language === 'string')
122
+ out.language = language;
123
+ if (Array.isArray(block.content)) {
124
+ if (isInlineRun(block.content)) {
125
+ out.inline = block.content.map((node) => ({
126
+ text: node.text,
127
+ marks: (node.marks ?? []).map((m) => m.type),
128
+ }));
129
+ }
130
+ else {
131
+ out.children = block.content.map(blockFromDocument);
132
+ }
133
+ }
134
+ /*
135
+ §13.3: a reader MUST render an unknown block's inline text and MUST NOT drop
136
+ it. A later version could nest content in a shape this code cannot walk, so
137
+ the fallback reads the text by shape rather than trusting the walk above to
138
+ have found it.
139
+ */
140
+ if (!known && !out.inline && !out.children) {
141
+ const text = inlineTextOf(block);
142
+ if (text)
143
+ out.inline = [{ text, marks: [] }];
144
+ }
145
+ return out;
146
+ }
147
+ /**
148
+ * The body, resolved.
149
+ *
150
+ * `format` comes from the event's `content-format` tag — `contentFormatOf` in
151
+ * `@estiva-app/interop`. Do not infer it from `value`: §13.4 forbids it, and a
152
+ * legacy description that happens to begin with `{` is the case that proves
153
+ * why.
154
+ *
155
+ * A body in an unparseable state never throws here. A `'blocks'` value that is
156
+ * not a document degrades to one unmarked paragraph — the same outcome as
157
+ * `'unknown'` — because a reader that throws renders nothing at all, and a
158
+ * description that is present is better shown as its own text than as an empty
159
+ * field.
160
+ */
161
+ export function toRenderTree(value, format) {
162
+ if (format === 'unknown')
163
+ return plainParagraph(value);
164
+ if (format === 'blocks') {
165
+ let doc;
166
+ try {
167
+ doc = parseBlockDocument(value);
168
+ }
169
+ catch {
170
+ return plainParagraph(value);
171
+ }
172
+ return doc.content.map(blockFromDocument);
173
+ }
174
+ return parseBodySegments(value).map(blockFromSegment);
175
+ }
176
+ function plainParagraph(value) {
177
+ return value === '' ? [] : [{ type: 'paragraph', inline: [{ text: value, marks: [] }] }];
178
+ }
179
+ /** Every character a reader would see, for previews and search. */
180
+ export function renderTreeText(blocks) {
181
+ return blocks
182
+ .map((b) => {
183
+ const own = (b.inline ?? []).map((i) => i.text).join('');
184
+ const kids = b.children ? renderTreeText(b.children) : '';
185
+ return [own, kids].filter((s) => s !== '').join('\n');
186
+ })
187
+ .filter((s) => s !== '')
188
+ .join('\n');
189
+ }
190
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAIL,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAkC,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AA4D9F,6E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AA;QACzD,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvD,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;SACvB,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/protocol",
3
- "version": "0.7.0",
3
+ "version": "0.9.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 CHANGED
@@ -10,13 +10,10 @@
10
10
  *
11
11
  * ## What is deliberately not here
12
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.
13
+ * **The `content-format` tag.** A document does not know its own tag — the tag
14
+ * is on the event that carries it, and SPEC §13.4's read rule is
15
+ * `contentFormatOf` in `render.ts`. (It lived in `@estiva-app/interop` until
16
+ * two folds outside the projection layer needed it; see that function's note.)
20
17
  *
21
18
  * **Rendering.** §13.5's safe renderer is RIC-6's, where Ship is the consumer
22
19
  * that needs it. What this module owes a renderer is {@link inlineTextOf}, so
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.7.0'
50
+ export const PROTOCOL_VERSION = '0.9.0'
51
51
 
52
52
  export {
53
53
  // types
@@ -195,3 +195,15 @@ export {
195
195
  inlineTextOf,
196
196
  documentText,
197
197
  } from './blocks.js'
198
+
199
+ export {
200
+ type RenderInline,
201
+ type RenderBlock,
202
+ type RenderFormat,
203
+ type ContentFormat,
204
+ CONTENT_FORMAT_TAG,
205
+ BLOCK_DOCUMENT_FORMAT,
206
+ contentFormatOf,
207
+ toRenderTree,
208
+ renderTreeText,
209
+ } from './render.js'
package/src/render.ts ADDED
@@ -0,0 +1,258 @@
1
+ /**
2
+ * One tree, whichever content model the body is in — SPEC §13.5.
3
+ *
4
+ * §13.5 asks for a renderer *"safe by construction"*, and the safety is not in
5
+ * a component: it is in never handing an app a string it has to interpret.
6
+ * What this module produces is a fully resolved tree — marks decided, blocks
7
+ * decided, nothing left to parse and nothing to interpolate — so the app's only
8
+ * remaining job is to create elements and set text. An app that maps this tree
9
+ * cannot accidentally render markup, because there is no markup in it.
10
+ *
11
+ * ## Why a tree rather than a shared component
12
+ *
13
+ * Not because the apps use different frameworks — Ship and Peek are both React
14
+ * and already share `@estiva-app/ui`, so a component was possible. Because
15
+ * **how rich text looks is the consumer's**, which is the same rule RFC 0.4
16
+ * §13.1 states for projections — *the owner defines the projection, the
17
+ * consumer decides how it looks* — and SPEC §10's line about apps sharing the
18
+ * wire and never the interpretation. A shared component would make Ship and
19
+ * Peek look alike by construction, which is not a property anybody asked for.
20
+ *
21
+ * So: one parse, one resolution, two designs.
22
+ *
23
+ * ## The three formats, including the one nobody has written yet
24
+ *
25
+ * `toRenderTree` takes the format from `contentFormatOf` in
26
+ * `@estiva-app/interop` — the tag, never the body (§13.4). `'unknown'` is the
27
+ * interesting one: a format declared after this code was written becomes a
28
+ * single unmarked paragraph of the raw value, which §13.5 says is conformant.
29
+ * Handling it here rather than in each consumer is what stops one app deciding
30
+ * to guess.
31
+ */
32
+ import {
33
+ type BodySegment,
34
+ type InlineMark,
35
+ type InlineTextNode,
36
+ parseBodySegments,
37
+ parseInlineMarks,
38
+ } from './content.js'
39
+ import { type Block, type BlockDocument, parseBlockDocument, inlineTextOf } from './blocks.js'
40
+ import type { SignedEvent } from './events.js'
41
+
42
+ /** A run of text and the marks on it. Nothing here needs escaping; it is text. */
43
+ export interface RenderInline {
44
+ text: string
45
+ marks: InlineMark[]
46
+ }
47
+
48
+ /**
49
+ * A resolved block.
50
+ *
51
+ * **A `\n` inside `inline` text is a line break**, in both content models — it
52
+ * is how a marker-text paragraph carries its lines, and it keeps a consumer
53
+ * from needing two rules. Splitting on it is the consumer's whole obligation.
54
+ */
55
+ export interface RenderBlock {
56
+ type:
57
+ | 'paragraph' | 'heading' | 'bulletList' | 'orderedList' | 'listItem'
58
+ | 'blockquote' | 'codeBlock' | 'table' | 'horizontalRule'
59
+ | 'attachment' | 'widget' | 'unknown'
60
+ /** The block's address, from a block document. Marker text has no addressable
61
+ * sub-unit (§13.1), so it is absent — which is the difference that matters. */
62
+ id?: string
63
+ level?: 1 | 2 | 3
64
+ language?: string
65
+ attrs?: Record<string, unknown>
66
+ /** What the document actually called it, when `type` is `'unknown'`. */
67
+ typeName?: string
68
+ inline?: RenderInline[]
69
+ children?: RenderBlock[]
70
+ }
71
+
72
+ /**
73
+ * What content model a body is written in — SPEC §13.4.
74
+ *
75
+ * Three values, not two, and not the raw tag string. A consumer makes a
76
+ * three-way decision and **must not guess the third**:
77
+ *
78
+ * - `marker` — the §13.2 dialect. The default, permanently. 731 published
79
+ * bodies carry no tag and none of them can be given one, so this is not a
80
+ * migration window that closes.
81
+ * - `blocks` — a §13.3 JSON block document.
82
+ * - `unknown` — a format declared after this runtime was written. Render the
83
+ * body as plain text; §13.5 says declining to format is conformant, and
84
+ * parsing it as either known model is what §13 forbids outright.
85
+ *
86
+ * Resolved in one place rather than per consumer for the reason `CLOSED_WIDGETS`
87
+ * is: two copies of `tag === undefined ? marker : tag === 'estiva-blocks-1' ?
88
+ * blocks : text` disagree the first time a third format exists, and the
89
+ * disagreement shows up as one app rendering JSON at a person.
90
+ */
91
+ export type ContentFormat = 'marker' | 'blocks' | 'unknown'
92
+
93
+ /**
94
+ * @deprecated The name this shipped under in 0.8.0. It is `ContentFormat`.
95
+ * Kept as an alias so 0.8.0's consumers keep compiling.
96
+ */
97
+ export type RenderFormat = ContentFormat
98
+
99
+ /** The tag SPEC §13.4 defines. Absence is a declaration, not an omission. */
100
+ export const CONTENT_FORMAT_TAG = 'content-format'
101
+
102
+ /** The one format §13.3 names today. */
103
+ export const BLOCK_DOCUMENT_FORMAT = 'estiva-blocks-1'
104
+
105
+ /**
106
+ * The content model an event's body is in.
107
+ *
108
+ * **Decided by the tag alone.** §13.4 is explicit that a reader MUST NOT decide
109
+ * by inspecting the body: a legacy description that happens to begin with `{`
110
+ * is marker text, because it carries no tag.
111
+ *
112
+ * **Why this lives here and not in `@estiva-app/interop`, where it was born.**
113
+ * It arrived with the projection layer because that is what needed it first,
114
+ * and reading a tag off an event looked like a question about a slot. It is
115
+ * not — it is a question about an event, which is this package's subject. Two
116
+ * folds now need it and neither is a projection consumer: Ship's and the
117
+ * agent's, which are the same fold in two repositories held to one recorded
118
+ * state. Making either of them depend on the projection layer to read a tag
119
+ * would be the wrong direction, and a second copy of the rule is what this
120
+ * package exists to prevent. `interop` re-exports these, so nothing it
121
+ * published has moved.
122
+ */
123
+ export function contentFormatOf(event: SignedEvent): ContentFormat {
124
+ const declared = event.tags.find((t) => t[0] === CONTENT_FORMAT_TAG)?.[1]
125
+ if (declared === undefined || declared === '') return 'marker'
126
+ return declared === BLOCK_DOCUMENT_FORMAT ? 'blocks' : 'unknown'
127
+ }
128
+
129
+ const KNOWN: ReadonlySet<string> = new Set([
130
+ 'paragraph', 'heading', 'bulletList', 'orderedList', 'listItem',
131
+ 'blockquote', 'codeBlock', 'table', 'horizontalRule', 'attachment', 'widget',
132
+ ])
133
+
134
+ const marksOf = (span: { bold?: boolean; italic?: boolean; underline?: boolean; code?: boolean }): InlineMark[] => {
135
+ const out: InlineMark[] = []
136
+ if (span.bold) out.push('bold')
137
+ if (span.italic) out.push('italic')
138
+ if (span.underline) out.push('underline')
139
+ if (span.code) out.push('code')
140
+ return out
141
+ }
142
+
143
+ const inlineFromMarkers = (text: string): RenderInline[] =>
144
+ parseInlineMarks(text).map((s) => ({ text: s.text, marks: marksOf(s) }))
145
+
146
+ /** One inline run per line, joined by the `\n` the interface documents. */
147
+ const inlineFromLines = (lines: string[]): RenderInline[] => inlineFromMarkers(lines.join('\n'))
148
+
149
+ function blockFromSegment(seg: BodySegment): RenderBlock {
150
+ switch (seg.type) {
151
+ case 'heading':
152
+ return { type: 'heading', level: seg.level, inline: inlineFromMarkers(seg.text) }
153
+ case 'bullet':
154
+ return {
155
+ type: 'bulletList',
156
+ children: seg.items.map((item) => ({ type: 'listItem' as const, inline: inlineFromMarkers(item) })),
157
+ }
158
+ case 'numbered':
159
+ return {
160
+ type: 'orderedList',
161
+ children: seg.items.map((item) => ({ type: 'listItem' as const, inline: inlineFromMarkers(item) })),
162
+ }
163
+ case 'quote':
164
+ return { type: 'blockquote', inline: inlineFromLines(seg.lines) }
165
+ case 'code':
166
+ // A fence is literal by definition — its content is never mark-parsed.
167
+ return {
168
+ type: 'codeBlock',
169
+ ...(seg.language ? { language: seg.language } : {}),
170
+ inline: [{ text: seg.lines.join('\n'), marks: [] }],
171
+ }
172
+ case 'text':
173
+ return { type: 'paragraph', inline: inlineFromLines(seg.lines) }
174
+ }
175
+ }
176
+
177
+ const isInlineRun = (content: unknown): content is InlineTextNode[] =>
178
+ Array.isArray(content) && content.every((n) => typeof n === 'object' && n !== null && (n as { type?: unknown }).type === 'text')
179
+
180
+ function blockFromDocument(block: Block): RenderBlock {
181
+ const known = KNOWN.has(block.type)
182
+ const out: RenderBlock = {
183
+ type: (known ? block.type : 'unknown') as RenderBlock['type'],
184
+ id: block.id,
185
+ ...(known ? {} : { typeName: block.type }),
186
+ ...(block.attrs ? { attrs: block.attrs } : {}),
187
+ }
188
+ const level = block.attrs?.level
189
+ if (block.type === 'heading' && (level === 1 || level === 2 || level === 3)) out.level = level
190
+ const language = block.attrs?.language
191
+ if (block.type === 'codeBlock' && typeof language === 'string') out.language = language
192
+
193
+ if (Array.isArray(block.content)) {
194
+ if (isInlineRun(block.content)) {
195
+ out.inline = block.content.map((node) => ({
196
+ text: node.text,
197
+ marks: (node.marks ?? []).map((m) => m.type),
198
+ }))
199
+ } else {
200
+ out.children = (block.content as Block[]).map(blockFromDocument)
201
+ }
202
+ }
203
+ /*
204
+ §13.3: a reader MUST render an unknown block's inline text and MUST NOT drop
205
+ it. A later version could nest content in a shape this code cannot walk, so
206
+ the fallback reads the text by shape rather than trusting the walk above to
207
+ have found it.
208
+ */
209
+ if (!known && !out.inline && !out.children) {
210
+ const text = inlineTextOf(block)
211
+ if (text) out.inline = [{ text, marks: [] }]
212
+ }
213
+ return out
214
+ }
215
+
216
+ /**
217
+ * The body, resolved.
218
+ *
219
+ * `format` comes from the event's `content-format` tag — `contentFormatOf` in
220
+ * `@estiva-app/interop`. Do not infer it from `value`: §13.4 forbids it, and a
221
+ * legacy description that happens to begin with `{` is the case that proves
222
+ * why.
223
+ *
224
+ * A body in an unparseable state never throws here. A `'blocks'` value that is
225
+ * not a document degrades to one unmarked paragraph — the same outcome as
226
+ * `'unknown'` — because a reader that throws renders nothing at all, and a
227
+ * description that is present is better shown as its own text than as an empty
228
+ * field.
229
+ */
230
+ export function toRenderTree(value: string, format: RenderFormat): RenderBlock[] {
231
+ if (format === 'unknown') return plainParagraph(value)
232
+ if (format === 'blocks') {
233
+ let doc: BlockDocument
234
+ try {
235
+ doc = parseBlockDocument(value)
236
+ } catch {
237
+ return plainParagraph(value)
238
+ }
239
+ return doc.content.map(blockFromDocument)
240
+ }
241
+ return parseBodySegments(value).map(blockFromSegment)
242
+ }
243
+
244
+ function plainParagraph(value: string): RenderBlock[] {
245
+ return value === '' ? [] : [{ type: 'paragraph', inline: [{ text: value, marks: [] }] }]
246
+ }
247
+
248
+ /** Every character a reader would see, for previews and search. */
249
+ export function renderTreeText(blocks: readonly RenderBlock[]): string {
250
+ return blocks
251
+ .map((b) => {
252
+ const own = (b.inline ?? []).map((i) => i.text).join('')
253
+ const kids = b.children ? renderTreeText(b.children) : ''
254
+ return [own, kids].filter((s) => s !== '').join('\n')
255
+ })
256
+ .filter((s) => s !== '')
257
+ .join('\n')
258
+ }