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.
Document functions
Section titled “Document functions”new(replica_id) -> Document(tag)creates an empty document.replica_id,clock, andkeysinspect document metadata.getandget_requiredread one typed field.setanddeletechange one field.readandwriteuse a record schema.stampwrites the schema version marker.merge,merge_json, andmerge_encodedmerge remote ORMap state.to_jsonandencodeserialize state.doc_idanddoc_id_to_stringconvert 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.
Schema functions
Section titled “Schema functions”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.
Presentation
Section titled “Presentation”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.