Skip to main content

Module publish

Module publish 

Source
Expand description

Publishing stored cells as the mesh (datumesh-mesh publish-stored): a JSON lines file of stored functions and their cells, signed with the mesh’s key, put in the store.

Each line is one of:

  • a descriptor (since 0.3.1, CONTRACT-1.7a H1): {"descriptor": <function descriptor>}: the descriptor is put with put_descriptor and binds nothing. Only a stored function is accepted (code.lang = stored, code.body = "", inputs = []); any other is refused at its line. A class later in the file (or in a later run) may name its hash as a method;
  • a function: {"function": "<ns>/<name>", "signature": {...}, "bound": "<instant>"}: the descriptor {"code": {"body": "", "lang": "stored"}, "inputs": [], "signature": ...} is put and the name bound to it from bound (unless it already is);
  • a formula function: {"formula": "<ns>/<name>", "source": "<formula>", "signature": {...}, "bound": "<instant>"}: defined with datumesh_formula::definition::define_function (its callees as bound at bound) and published (put_descriptor, bind_name from bound) unless the name is already bound to that function; its cells are evaluated on demand by the mesh;
  • a class (since 0.2.2, spec-0.5.0, 16.2): {"class": "<ns>/<name>", "descriptor": {...as written...}, "bound": "<instant>"}: defined with the formula crate’s define_class (core’s rules: the class is under one of the mesh’s own namespaces, else E_CLASS_OWNER; the method functions are those bound as of bound), put_class, and bind_class from bound unless the name is already bound to that class hash. Method functions come first in the file (or in an earlier one), bound later than theirs. A line with both class and descriptor is a class line;
  • a cell: {"cell": {"fn": "<ns>/<name>", "args": {<name>: <typed scalar>}}, "value": <typed scalar> or {"blob": "<file>", "media_type": "<type>"}, "tx"?, "asof"?, "issued"?, "licence", "summary"}: a blob’s file (relative to the JSON lines file) is put with put_blob and the value is <sha256>:<length>:<media type>; the receipt is signed with the mesh’s key (computed_by the mesh host, publisher the cell’s namespace, valid its valid-time arguments; issued defaults to the later of asof and the key’s start) and stored with put_receipt and put_version. tx and asof default to the run’s clock now (since 0.3.1, H4), each independently. A source object (since 0.4.0, spec-0.6.0 C2: name, url, retrieved, and optionally sha256 and takeover, nothing else) marks the value as relayed: the receipt signs it, and its trust is relayed; its rules are the receipt’s (retrieved no later than issued, a publisher that does not relay itself, https:// URLs), refused at the line.

The function of a cell is the one its name is bound to as of the cell’s tx. Re-running a file changes nothing (a cell line without tx whose latest version states the same thing is skipped, since 0.3.1): descriptors and blobs are content-addressed, signing is deterministic (the same receipt, the same hash), and a version already there is skipped. The key is never logged.

Rule A (since 0.3.0, CONTRACT-1.8b H1): no binding starts earlier than the mesh clock. The start of a binding (a name’s, a class’s, or a class method’s N/m) is its bound, or the clock’s now when bound is left out, and a start earlier than now is refused with PublishErrorKind::StartBeforeNow. A --backfill run (PublishOptions::backfill) lifts the start check, and is refused (PublishErrorKind::Backfill) when a name it would bind has a binding, or when a namespace of such a name has any binding (store 0.4.2’s has_bindings_under). A run that writes appends one line to the log: {"at": …, "namespaces": […], "starts": […]}, a JCS object.

No partial writes (since 0.3.1, CONTRACT-1.7a H2): the file is read in two passes. The first plans every write the second one makes, and checks each as the store will: a bind is refused when its start is not later than the latest binding of its name (the store’s, or one planned earlier in the file, W1b), when the name is of the other kind (a class or a function), or when its namespace is suspended; a cell’s function must be bound as of its tx (counting the earlier binds of the file), its blob must be readable, tx <= asof <= issued, and a version at or after its tx must be this receipt. Receipts are signed in the first pass (signing is deterministic), so their hashes are known. A file that the first pass refuses writes nothing.

Structs§

PublishError
Why a run stopped: the line, what was wrong, and its typed kind.
PublishOptions
How a run reads the clock and whether it backfills (CONTRACT-1.8b H1).
Published
What a run put.

Enums§

PublishErrorKind
Why a line (or the file, at line 0) was refused.

Functions§

publish_stored
Publishes the file at path into store as the mesh host signing with key (see the module documentation). The mesh’s own namespaces are host alone: see publish_stored_in. The clock is the system clock, and there is no backfill. The cells are written on one lane; see publish_stored_lanes for the parallel lanes.
publish_stored_checked
As publish_stored_with, with the public rule (Build 2 Part 3, D8: datumesh-http always enforces it; publish-stored calls this). A file that defines a computed function (formula) is refused unless the tests of the function (the file’s, and those already held for the same function hash) exercise every derived edge case and every branch, and all of the file’s tests pass: PublishErrorKind::TestsMissing at the function’s line, PublishErrorKind::TestsFailing at the failing test’s line. Stored functions are exempt. Nothing is written when refused.
publish_stored_checked_lanes
As publish_stored_lanes, with the public rule (see publish_stored_checked): the path of datumesh-mesh publish-stored (D8).
publish_stored_in
As publish_stored, for a mesh that owns the namespaces (hosts) owned (Config::namespaces): a class line is accepted for a class under one of them, and refused with E_CLASS_OWNER (in the PublishError::detail) under any other. Since 0.2.2. The system clock, and no backfill.
publish_stored_lanes
As publish_stored_with, with the cells written on parallel lanes (CONTRACT-perf H5, H6): DATUMESH_PUBLISH_LANES (a positive integer) if set, else min(4, available_parallelism()). The same receipts, versions and rows as one lane; only the order of the inserts across different cells differs. The variable is read once per run, before the file is read.
publish_stored_with
As publish_stored_in, with the run’s clock and backfill (CONTRACT-1.8b H1, rule A). The cells are written in file order on one lane, as in 0.3.2 (CONTRACT-perf H2).
receipt_json
The receipt JSON of a signed receipt: its payload’s members and sig.