barrel_design_manifest (barrel_design v0.1.0)

View Source

Design manifests: validation, normalization and view signatures.

A design is plain data: a name, a version and named views. A view selects documents with a BQL predicate, builds rows with either a native projection (key and value paths) or a Wasm map, and may total them with _sum, _count or a Wasm reducer run at read time (#{module, export, value}). Keys of the input may be atoms or binaries, so a manifest read from JSON normalizes the same way.

The signature of a view hashes its selector, key and value specs, reducer, map module digest, ABI, export, fields, the limits that bound a map and the key encoding version. Titles, build and the read-time limits do not count, so a caption edit keeps the index and a view stored by an earlier release keeps its signature.

Summary

Functions

Module digests the design's views reference.

Whether a document (with its id) passes a compiled selector.

Compile a stored selector: SELECT * FROM db WHERE ... over one document, with no parameters, ordering, limits, projection or unnest.

SHA-256 of the canonical semantic form of a normalized view.

A normalized design as JSON values: binary keys, texts, numbers, lists; digests as lowercase hex. normalize/1 gives the design back.

The modules one view runs: its map's and its reducer's.

Types

design/0

-type design() ::
          #{name := binary(),
            version := pos_integer(),
            views := #{binary() => view()},
            title => binary()}.

view/0

-type view() :: map().

Functions

canonical(M)

-spec canonical(term()) -> term().

default_limits()

-spec default_limits() -> map().

modules(_)

-spec modules(design()) -> [binary()].

Module digests the design's views reference.

normalize(Design)

-spec normalize(map()) -> {ok, design()} | {error, term()}.

selected(_, Doc)

-spec selected(map(), map()) -> boolean().

Whether a document (with its id) passes a compiled selector.

selector(Bql)

-spec selector(binary()) -> {ok, map()} | {error, term()}.

Compile a stored selector: SELECT * FROM db WHERE ... over one document, with no parameters, ordering, limits, projection or unnest.

signature(View)

-spec signature(view()) -> binary().

SHA-256 of the canonical semantic form of a normalized view.

to_json(D)

-spec to_json(design()) -> map().

A normalized design as JSON values: binary keys, texts, numbers, lists; digests as lowercase hex. normalize/1 gives the design back.

view_modules(View)

-spec view_modules(view()) -> [binary()].

The modules one view runs: its map's and its reducer's.