Skip to content
Strata is pre-1.0. APIs, protocol, and storage format may change.

strata_document

strata_document is the optional typed CRDT layer for Strata applications. It targets Erlang and JavaScript.

Use it to:

  • declare phantom-typed fields with JSON encoders and decoders;
  • read and write whole records as independent per-key updates;
  • reject invalid values, unknown keys, or schema-version mismatches at reads;
  • merge remote ORMap state while maintaining a local logical clock;
  • tag a document id with its schema via DocId(tag), so a function that expects one document kind rejects another kind's id at compile time; and
  • encode the document state for strata_client.SendDelta.

The package does not enforce schemas on the server. Remote data remains untrusted, so typed reads return Result.

  • new(replica_id) -> Document(tag) creates an empty document.
  • replica_id, clock, and keys inspect document metadata.
  • get and get_required read one typed field.
  • set and delete change one field.
  • read and write use a record schema.
  • stamp writes the schema version marker.
  • merge, merge_json, and merge_encoded merge remote ORMap state.
  • to_json and encode serialize state.
  • doc_id and doc_id_to_string convert a typed document id.

DocumentError reports invalid document JSON, CRDT merge type mismatches, wrong CRDT value types, and reserved keys. FieldError reports missing values, invalid JSON, wrong CRDT types, schema version mismatches, unknown keys, and reserved keys.

Use schema.field to define a field. Use schema.record1 through schema.record9 to define record reads and writes. optional_prop deletes a field when its record value is None.

Use schema.sealed or schema.sealed_known to reject undeclared active keys. Use schema.versioned to check a stored schema version. An unstamped legacy document remains valid.

See Schema Design and Evolution before you change stored keys or versions.

strata_document has no UI dependency. A Document(tag) stores data and replication state only.

Applications can define a companion doc_view module for each doc_schema module. The companion module can export a default Lustre surface that accepts the typed document and host action functions. A host can call that surface or pass another renderer for a specific use site.

See Documents and Deltas for the module layout. See Composing Documents for typed action routing and renderer replacement.