Expand description
Compact JSON records read and written with the incumbent’s JSON semantics.
What:
Reading and writing the compact JSON records both wrappers share,
with the
incumbent’s JSON.parse and JSON.stringify semantics.
Why:
Lock,
owner,
journal and capture records written by either wrapper are read by the
other.
A record must be read the way the incumbent reads it (numbers are doubles,
a
whole number in safe-integer range is an integer,
the last duplicate key wins) and
written with the same field order and escaping.
In TS you’d write (pseudocode):
const value: unknown = JSON.parse(text); const bytes = `${JSON.stringify(record)}\n`;Structs§
- Object
Writer - What:
Builder of one compact JSON object in insertion order,
as
JSON.stringifywrites it. Astructgroups named fields; this one holds the text written so far. Why: Records must list their fields in the incumbent’s order so the bytes match for the same values; escaping comes fromserde_json, which escapes the same charactersJSON.stringifydoes.
Constants§
- MAX_
SAFE_ INTEGER - The largest whole number a double holds exactly,
JavaScript’s
Number.MAX_SAFE_INTEGER.
Functions§
- decode_
fatal - What:
Decode record bytes the way a
fatalTextDecoderdoes: valid UTF-8 only, with one leading byte-order mark removed. Why: The incumbent decodes owner and journal records withnew TextDecoder('utf-8', { fatal: true }), which rejects invalid bytes and drops a leading mark. - number_
equals - What:
Whether a field holds exactly the JSON number
expected. Why:value.schemaVersion !== 1compares doubles, so1.0matches1. - parse_
object - What:
Parse record text into a JSON object,
or nothing for any other document.
Option<Map<String, Value>>is “an object, or nothing”. Why: Every record is an object; an array, a scalar or text that is not JSON is malformed. - quote
- What:
Quote text as a JSON string literal.
Why:
serde_jsonescapes",\and control characters asJSON.stringifydoes; serializing a&strcannot fail. - safe_
integer - What: The safe-integer reading of one JSON value. Why: Shared by object fields and array items.
- safe_
integer_ field - What:
Read a field as a JavaScript safe integer,
or nothing.
i64is a signed 64-bit integer. Why:typeof value === 'number' && Number.isSafeInteger(value)accepts1,1.0and1e0alike, because JavaScript has only doubles; anything with a fraction or beyond 2^53 - 1 is refused. - string_
array - What: A JSON array of text items. Why: Pathspec and path lists in journal records.
- string_
field - What:
Read a field as text,
or nothing when it is absent or not a string.
Why:
typeof value.key === 'string'is the incumbent’s check.