~/bend-docscommunity

src/ContentObject.bend fails

raw source on the hub · import ber-core-store@0.1.1.0/src/ContentObject.bend as ContentObject

7 imports
import Base
import ./ContentHash.bend as ContentHash
import ./LogicalKey.bend as LogicalKey
import ./JsonAdapter.bend as JsonAdapter
import ./Value.bend as Value
import ./Store.bend as Store
import bend-kit-json@0.3.0.0/json.bend as Json

Types

type ContentObject source · line 16 · raw

Data

Addressable payload with content hash and references.

Definitions

def encode_each_reference source · line 20 · raw

@references:List<&2, String> -> List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val>

Encodes each reference string as a JSON string.

def encode_reference_list source · line 28 · raw

@payload:0xf481b310e24036f2ebffda42e94b3b4c/src/Value.Value -> @references:List<&2, String> -> List<&2, Sigma<&2, &2, String, _ => 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val>>

Builds the payload/references field list.

def canonical_content source · line 32 · raw

@payload:0xf481b310e24036f2ebffda42e94b3b4c/src/Value.Value -> @references:List<&2, String> -> String

Canonical text of a content object; the hashed bytes.

def finish_store source · line 36 · raw

@+content_hash:String -> @+canonical_text:String -> 0xf481b310e24036f2ebffda42e94b3b4c/src/Store.Op<&2, String>

Persists the text under its hash and returns the hash.

def wrap_store source · line 42 · raw

@+canonical_text:String -> 0xf481b310e24036f2ebffda42e94b3b4c/src/Store.Op<&2, String>

Hashes the text, then stores it.

def store_content_object source · line 46 · raw

@payload:0xf481b310e24036f2ebffda42e94b3b4c/src/Value.Value -> @references:List<&2, String> -> 0xf481b310e24036f2ebffda42e94b3b4c/src/Store.Op<&2, String>

SHA-256 of the canonical text; the address consumers store and load by.

def prepend_tail_text source · line 50 · raw

@head_text:String -> @parsed_tail:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>

Conses decoded text onto the tail, failing closed on None.

def prepend_string_value source · line 58 · raw

@head_maybe:Maybe<&2, String> -> @parsed_tail:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>

Unwraps the head string, then prepends.

def prepend_string source · line 66 · raw

@head_item:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> @parsed_tail:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>

Decodes one JSON array item as a string.

def extract_each_string source · line 70 · raw

@json_items:List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, List<&2, String>>

Decodes a JSON string array; None on any non-string.

def wrap_reference_texts source · line 78 · raw

@content_hash:String -> @payload_value:0xf481b310e24036f2ebffda42e94b3b4c/src/Value.Value -> @texts_maybe:Maybe<&2, List<&2, String>> -> Maybe<&2, ContentObject>

Reassembles the object once references decode.

def finish_object source · line 86 · raw

@content_hash:String -> @payload_value:0xf481b310e24036f2ebffda42e94b3b4c/src/Value.Value -> @references_maybe:Maybe<&2, List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val>> -> Maybe<&2, ContentObject>

Unwraps the references array, then reassembles.

def extract_with_references source · line 94 · raw

@content_hash:String -> @payload_value:0xf481b310e24036f2ebffda42e94b3b4c/src/Value.Value -> @references_maybe:Maybe<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, ContentObject>

Unwraps the references field, then finishes.

def extract_with_payload_value source · line 102 · raw

@content_hash:String -> @payload_value_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Value.Value> -> @references_maybe:Maybe<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, ContentObject>

Unwraps the payload value, then continues.

def extract_with_payload source · line 110 · raw

@content_hash:String -> @+document:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> @payload_maybe:Maybe<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, ContentObject>

Unwraps the payload field, then continues.

def object_from_parse_result source · line 118 · raw

@content_hash:String -> @parse_result:Maybe<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, ContentObject>

Builds the object from parsed JSON; None on malformed input.

def parse_canonical_object source · line 126 · raw

@content_hash:String -> @stored_text:String -> Maybe<&2, ContentObject>

Parses stored canonical text into an object.

def parse_loaded_object source · line 130 · raw

@content_hash:String -> @stored_maybe:Maybe<&2, String> -> Maybe<&2, ContentObject>

Parses loaded text; missing storage reads as None.

def load_content_object source · line 138 · raw

@+content_hash:String -> 0xf481b310e24036f2ebffda42e94b3b4c/src/Store.Op<&2, Maybe<&2, ContentObject>>

None on missing or malformed stored text; never returns a corrupt object.

def object_payload_of source · line 144 · raw

@content_object:ContentObject -> 0xf481b310e24036f2ebffda42e94b3b4c/src/Value.Value

Projects the payload out of an object.