Crdt.Model_codec_sidecar

crdt · API reference

Sidecar document codec (view + metadata separation)

Sidecar document codec.

The sidecar format separates the JSON view from CRDT metadata:

  • View: Plain JSON/CBOR that any system can read
  • Metadata: CRDT info stored separately (node IDs, timestamps, etc.) This is useful for:
  • Compatibility with non-CRDT systems (they just read the view)
  • Debugging (human-readable JSON view)
  • Storage optimization (view can be cached/indexed separately) Format:
  • view: Plain JSON value (recursive structure)
  • meta: Object containing:
  • clock: Array of sid, time pairs
  • paths: Object mapping JSON Pointer paths to node metadata
  • Each path entry: { id: [sid, time], type: "str" | "obj" | "arr" | ... }
module J = Simdjsont.Json
val escape_component : string -> string
type node_meta = {
  node_id : Clock.timestamp;
  node_type : string;
  chunks : chunk_meta list option;
}
and chunk_meta = {
  chunk_id : Clock.timestamp;
  chunk_span : int;
  chunk_deleted : bool;
}
type sidecar = {
  view : Value.t;
  clock : Clock.clock_vector;
  paths : (string * node_meta) list;
}
val encode_timestamp : Clock.timestamp -> J.t
val encode_clock_vector : Clock.clock_vector -> J.t
val encode_chunk_meta : chunk_meta -> J.t
val encode_node_meta : node_meta -> J.t
val collect_meta : Model.t -> Node.t -> string -> (string * node_meta) list
val encode : Model.t -> sidecar
val to_json : sidecar -> J.t
val encode_string : ?minify:bool -> Model.t -> string
val encode_bigstring : 
  ?minify:bool ->
  Model.t ->
  (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t * int
val decode_timestamp : J.t -> Clock.timestamp option
val decode_clock_vector : J.t -> Clock.clock_vector option
val get_member : string -> (string * J.t) list -> J.t option
val decode_chunk_meta : J.t -> chunk_meta option
val decode_node_meta : J.t -> node_meta option
val decode_paths : J.t -> (string * node_meta) list
val from_json : J.t -> sidecar option
val decode : sidecar -> Model.t
val decode_string : string -> Model.t option
val decode_bigstring : 
  (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
  len:int ->
  Model.t option
val view_only : Model.t -> Value.t
val view_only_string : ?minify:bool -> Model.t -> string
val view_only_bigstring : 
  ?minify:bool ->
  Model.t ->
  (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t * int